-
Notifications
You must be signed in to change notification settings - Fork 1
/
input.json
33 lines (33 loc) · 3.64 KB
/
input.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{
"language": "Solidity",
"sources": {
"contracts/ethereum/TimeLockContract.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface IERC20 {\n function transfer(address to, uint256 amount) external returns (bool);\n function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\n function balanceOf(address account) external view returns (uint256);\n}\n\ncontract TimeLockContract {\n address public beneficiary;\n uint256 public releaseTime;\n\n // Store the locked token balance for an account in `lockedBalanceOf[account][token]`\n // `token = 0x0` means ETH\n mapping(address => mapping(address => uint256)) public lockedBalanceOf;\n\n // Constructor sets the beneficiary address and release time (in Unix timestamp)\n // `beneficiary` is a multi-sig address\n constructor(address _beneficiary, uint256 _releaseTime) {\n require(_releaseTime > block.timestamp, \"Release time must be in the future\");\n require(_releaseTime < block.timestamp + 90 days, \"Release time must be within 3 months\");\n beneficiary = _beneficiary;\n releaseTime = _releaseTime;\n }\n\n // TODO: extend release time\n\n // Function to receive ETH deposits\n receive() external payable {\n uint256 amount = msg.value;\n require(amount > 0, \"Deposit amount must be greater than zero\");\n\n lockedBalanceOf[msg.sender][address(0x0)] += amount;\n emit TokenLocked(msg.sender, address(0x0), amount);\n }\n\n // Function to receive ERC20 tokens\n function lockERC20(address token, uint256 amount) public {\n require(amount > 0, \"Deposit amount must be greater than zero\");\n\n lockedBalanceOf[msg.sender][token] += amount;\n IERC20(token).transferFrom(msg.sender, address(this), amount);\n emit TokenLocked(msg.sender, token, amount);\n }\n\n // Function to withdraw ETH, only available after release time and only to the beneficiary\n function withdrawETH(uint256 amount) public {\n require(block.timestamp >= releaseTime, \"Current time is before release time\");\n require(msg.sender == beneficiary, \"Only beneficiary can withdraw\");\n\n uint256 balance = address(this).balance;\n require(balance >= amount, \"Insufficient ETH balance\");\n\n payable(beneficiary).transfer(amount);\n emit TokenWithdrawn(address(0x0), amount);\n }\n\n // Function to withdraw ERC20 tokens, only available after release time and only to the beneficiary\n function withdrawERC20(address token, uint256 amount) public {\n require(block.timestamp >= releaseTime, \"Current time is before release time\");\n require(msg.sender == beneficiary, \"Only beneficiary can withdraw\");\n\n IERC20 tokenContract = IERC20(token);\n uint256 balance = tokenContract.balanceOf(address(this));\n require(balance >= amount, \"Insufficient token balance\");\n\n tokenContract.transfer(beneficiary, amount);\n emit TokenWithdrawn(token, amount);\n }\n\n event TokenLocked(address indexed account, address token, uint256 amount);\n event TokenWithdrawn(address token, uint256 amount);\n}\n"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"evmVersion": "shanghai",
"viaIR": true,
"metadata": {
"bytecodeHash": "none"
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
"metadata"
],
"": [
"ast"
]
}
}
}
}