Last active
March 17, 2023 19:14
-
-
Save shobhitic/fc9bbf44da69652f111704efb97eb271 to your computer and use it in GitHub Desktop.
Simple Timelock and Vesting Smart Contract - https://www.youtube.com/watch?v=Z8dLFoREfWE
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.4; | |
import "@openzeppelin/contracts@4.7.3/token/ERC20/ERC20.sol"; | |
contract MyToken is ERC20 { | |
constructor() ERC20("MyToken", "MTK") { | |
_mint(msg.sender, 10000 * 10 ** decimals()); | |
} | |
} |
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.4; | |
import "@openzeppelin/contracts@4.7.3/token/ERC20/IERC20.sol"; | |
contract Vesting { | |
IERC20 public token; | |
address public receiver; | |
uint256 public amount; | |
uint256 public expiry; | |
bool public locked = false; | |
bool public claimed = false; | |
constructor (address _token) { | |
token = IERC20(_token); | |
} | |
function lock(address _from, address _receiver, uint256 _amount, uint256 _expiry) external { | |
require(!locked, "We have already locked tokens."); | |
token.transferFrom(_from, address(this), _amount); | |
receiver = _receiver; | |
amount = _amount; | |
expiry = _expiry; | |
locked = true; | |
} | |
function withdraw() external { | |
require(locked, "Funds have not been locked"); | |
require(block.timestamp > expiry, "Tokens have not been unlocked"); | |
require(!claimed, "Tokens have already been claimed"); | |
claimed = true; | |
token.transfer(receiver, amount); | |
} | |
function getTime() external view returns (uint256) { | |
return block.timestamp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment