Created
October 30, 2021 18:00
-
-
Save tanishqsh/98e02a6a5de8c6587737e9dd39ba842d to your computer and use it in GitHub Desktop.
A ERC20 Claimable smart contract to allow creator to deposit, set AllowList, Withdrawal Limits (Purely Experimental)
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: Unlicense | |
pragma solidity ^0.8.0; | |
import "hardhat/console.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
/** | |
How it works? | |
1. You deposit your ERC20 tokens in the smart contract | |
2. You can add a person into the allowList | |
3. You can update their withdraw limit | |
4. Anyone can try to claim the tokens | |
4.1 They will be rejected if they are not in the allowList | |
4.2 They will be rejected if they have exceeded their withdraw limit | |
5. The owner can update the dameAddress | |
*/ | |
contract ERC20Interface { | |
function transfer(address _to, uint256 _value) public returns (bool); | |
} | |
contract DameClaim is Ownable { | |
// have the interface address | |
address dameToken = 0x5337fB67d80B08344BbC31Fc3Db73798a98a8422; | |
// creating the interface for DameToken Transfer | |
ERC20Interface tokenInterface = ERC20Interface(dameToken); | |
// dame.eth | |
address dameAddress = 0x3B3525F60eeea4a1eF554df5425912c2a532875D; | |
// allowlist to be modified by owner only | |
mapping (address => bool) allowList; | |
// how much each address is allowed to withdraw | |
mapping (address => uint) withdrawLimit; | |
// the function that allows updating the allow list | |
function updateAllowList(address _address, bool _allow) public { | |
require(msg.sender == dameAddress, "You are not dame!"); | |
allowList[_address] = _allow; | |
} | |
// this is for the deployer to update the dameAddress in case jackson wants to make someone else manager | |
function updateDameAddress(address _address) onlyOwner public { | |
dameAddress = _address; | |
} | |
// claim function that allows the sender to transfer ERC20 token to the specified address if they are in the allowlist | |
function claim(address _to, uint256 _value) public { | |
require(allowList[msg.sender], "You are not in the allowlist!"); | |
// check if the value is greater than the withdraw limit | |
require(_value <= withdrawLimit[msg.sender], "You have exceeded your withdraw limit!"); | |
// call the interface's transfer function | |
tokenInterface.transfer(msg.sender, _value); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment