Created
August 22, 2024 20:05
-
-
Save AmanRaj1608/1f0c6a10b4fb2c34eca293a208d16ad7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol"; | |
contract Faucet { | |
address public owner; | |
// USDC token contract interface | |
IERC20 public usdc; | |
// USDT token contract interface | |
IERC20 public usdt; | |
// timestamp of last token send | |
uint256 public lastSend; | |
// mapping of users and last drip time | |
mapping(address => uint256) public lastDrip; | |
// constructor sets token contract addresses and lastSend to current time | |
constructor(address _usdcAddress, address _usdtAddress) { | |
owner = msg.sender; | |
usdc = IERC20(_usdcAddress); | |
usdt = IERC20(_usdtAddress); | |
lastSend = block.timestamp; | |
} | |
// send tokens to user if 24 hours have elapsed since last drip | |
function drip() public { | |
require(block.timestamp >= lastDrip[msg.sender] + 1 days, "24 hours have not elapsed since last drip"); | |
require(usdc.balanceOf(address(this)) >= 25e6, "USDC balance insufficient"); | |
require(usdt.balanceOf(address(this)) >= 25e18, "USDT balance insufficient"); | |
require(usdc.transfer(msg.sender, 25e6), "USDC transfer failed"); | |
require(usdt.transfer(msg.sender, 25e18), "USDT transfer failed"); | |
lastDrip[msg.sender] = block.timestamp; | |
} | |
// allow users to deposit USDC tokens | |
function depositUSDC(uint256 amount) public { | |
require(usdc.transferFrom(msg.sender, address(this), amount), "USDC transfer failed"); | |
} | |
// allow users to deposit USDT tokens | |
function depositUSDT(uint256 amount) public { | |
require(usdt.transferFrom(msg.sender, address(this), amount), "USDT transfer failed"); | |
} | |
// allow owner to withdraw all tokens from the contract | |
function withdrawAll() public { | |
require(msg.sender == owner, "Only the owner can withdraw tokens"); | |
uint256 usdcBalance = usdc.balanceOf(address(this)); | |
uint256 usdtBalance = usdt.balanceOf(address(this)); | |
usdc.transfer(msg.sender, usdcBalance); | |
usdt.transfer(msg.sender, usdtBalance); | |
} | |
// get the balance of both USDC and USDT tokens | |
function getBalance() public view returns (uint256 usdcBalance, uint256 usdtBalance) { | |
return (usdc.balanceOf(address(this)), usdt.balanceOf(address(this))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment