Created
July 15, 2023 10:07
-
-
Save ImanMousavi/f086432526b63e9124c50d2943edea68 to your computer and use it in GitHub Desktop.
This contract is designed to be used with the ERC20 standard USDT token, and it uses the IERC20 interface from the OpenZeppelin library to interact with the USDT token contract.
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
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | |
// This contract is written in Solidity and is designed to receive USDT tokens and aggregate them into a single address. The contract constructor takes in three parameters: the USDT token address, the collection address where the tokens will be sent, and the threshold value for the minimum amount of tokens to be collected before they are sent to the collection address. | |
// The receiveUSDT function is used to receive USDT tokens from users. When a user calls this function and sends USDT tokens to the contract, the transferFrom function of the USDT token contract is used to transfer the tokens to the contract. The function then checks the current balance of USDT tokens held by the contract, and if the balance is greater than or equal to the threshold value, all the tokens are transferred to the collection address using the transfer function of the USDT token contract. | |
contract USDTReceiver { | |
IERC20 private _usdt; | |
address payable private _collectionAddress; | |
uint256 private _threshold; | |
constructor(address usdtAddress, address payable collectionAddress, uint256 threshold) { | |
_usdt = IERC20(usdtAddress); | |
_collectionAddress = collectionAddress; | |
_threshold = threshold; | |
} | |
function receiveUSDT(uint256 amount) public { | |
_usdt.transferFrom(msg.sender, address(this), amount); | |
uint256 balance = _usdt.balanceOf(address(this)); | |
if (balance >= _threshold) { | |
_usdt.transfer(_collectionAddress, balance); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment