Address Contract Verified
Address
0xEdB723bBd2Ab6740ff66008539D0EaC0150E3a97
Balance
0 ETH
Nonce
1
Code Size
8120 bytes
Creator
0x895c64Fa...d51b at tx 0xad74164f...3a71ae
Indexed Transactions
0
Contract Bytecode
8120 bytes
0x608060405234801561001057600080fd5b50600436106101c45760003560e01c806377f52bef116100f9578063c065910811610097578063efeb5e5811610071578063efeb5e581461043e578063f119b25014610451578063f2fde38b14610464578063fc0c546a1461047757600080fd5b8063c0659108146103fc578063ef78d4fd14610404578063ef8b76511461042b57600080fd5b80639cfdbd5e116100d35780639cfdbd5e14610393578063a0e2e5f6146103a2578063a9610655146103c2578063be9a6555146103d557600080fd5b806377f52bef146103715780638da5cb5b14610379578063961325211461038a57600080fd5b80633ee660f3116101665780635b889e6e116101405780635b889e6e1461031a5780636209573514610341578063715018a61461034957806376272bdc1461035157600080fd5b80633ee660f3146102b557806351cff8d9146102c85780635760cc5d146102db57600080fd5b80631cf1bb72116101a25780631cf1bb72146102325780632b0f658c146102525780633163e3a8146102675780633c21e5951461028e57600080fd5b80630c6ffc29146101c95780630f1a6444146101e45780630fb5a6b41461020b575b600080fd5b6101d161049e565b6040519081526020015b60405180910390f35b6101d17f000000000000000000000000000000000000000000000000000000006236fb2081565b6101d17f000000000000000000000000000000000000000000000000000000000114db0081565b6101d1610240366004611a34565b60036020526000908152604090205481565b610265610260366004611c03565b61050a565b005b6101d17f00000000000000000000000000000000000000000000000000000000620f6e2081565b6101d17f000000000000000000000000000000000000000000000000000000000000000081565b6102656102c3366004611a34565b6107fb565b6102656102d6366004611a34565b610831565b6103027f000000000000000000000000895c64fa17ae0681b03923faa06cf9434478d51b81565b6040516001600160a01b0390911681526020016101db565b6101d17f00000000000000000000000000000000000000000000000002c68af0bb14000081565b6101d161092e565b610265610956565b6101d161035f366004611a34565b60026020526000908152604090205481565b61026561098c565b6000546001600160a01b0316610302565b6101d160045481565b6101d1670de0b6b3a764000081565b6101d16103b0366004611a34565b60016020526000908152604090205481565b6102656103d0366004611cd5565b610995565b6101d17f00000000000000000000000000000000000000000000000000000000620f6e2081565b6005546101d1565b6101d17f0000000000000000000000000000000000000000000000000000000000278d0081565b610265610439366004611d39565b610c32565b61030261044c366004611d89565b610e46565b6101d161045f366004611a34565b610e70565b610265610472366004611a34565b610ea2565b6103027f000000000000000000000000a350da05405cc204e551c4eed19c3039646528d581565b6000805b6005548110156105065760016000600583815481106104c3576104c3611da2565b60009182526020808320909101546001600160a01b031683528201929092526040019020546104f29083611dce565b9150806104fe81611de6565b9150506104a2565b5090565b8351855114801561051c575082518551145b8015610529575081518551145b8015610536575080518551145b6105785760405162461bcd60e51b815260206004820152600e60248201526d496e76616c696420706172616d7360901b60448201526064015b60405180910390fd5b6000805b86518110156107175785818151811061059757610597611da2565b6020026020010151826105aa9190611dce565b6040516370a0823160e01b81523060048201529092507f000000000000000000000000a350da05405cc204e551c4eed19c3039646528d56001600160a01b0316906370a0823190602401602060405180830381865afa158015610611573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106359190611e01565b82111561067b5760405162461bcd60e51b8152602060048201526014602482015273125b9d985b1a59081d1bdad95b88185b5bdd5b9d60621b604482015260640161056f565b61070587828151811061069057610690611da2565b60200260200101518783815181106106aa576106aa611da2565b60200260200101518784815181106106c4576106c4611da2565b60200260200101518785815181106106de576106de611da2565b60200260200101518786815181106106f8576106f8611da2565b6020026020010151610c32565b8061070f81611de6565b91505061057c565b506040516370a0823160e01b81523060048201527f000000000000000000000000a350da05405cc204e551c4eed19c3039646528d56001600160a01b0316906370a08231906024015b602060405180830381865afa15801561077d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107a19190611e01565b6107a961049e565b11156107f35760405162461bcd60e51b8152602060048201526019602482015278125b9cdd59999a58da595b9d081d1bdad95b88185b5bdd5b9d603a1b604482015260640161056f565b505050505050565b6000546001600160a01b031633146108255760405162461bcd60e51b815260040161056f90611e1a565b61082e81610f3a565b50565b6000546001600160a01b0316331461085b5760405162461bcd60e51b815260040161056f90611e1a565b6001600160a01b0381166108a757600080546040516001600160a01b03909116914780156108fc02929091818181858888f193505050501580156108a3573d6000803e3d6000fd5b5050565b6040516370a0823160e01b81523060048201526000906001600160a01b038316906370a0823190602401602060405180830381865afa1580156108ee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109129190611e01565b905080156108a3576108a36001600160a01b0383163383611032565b60405160200161093d90611e4f565b6040516020818303038152906040528051906020012081565b6000546001600160a01b031633146109805760405162461bcd60e51b815260040161056f90611e1a565b61098a6000611084565b565b61098a33610f3a565b6000546001600160a01b031633146109bf5760405162461bcd60e51b815260040161056f90611e1a565b8051825114610a015760405162461bcd60e51b815260206004820152600e60248201526d496e76616c696420706172616d7360901b604482015260640161056f565b6000805b8351811015610b5257828181518110610a2057610a20611da2565b602002602001015182610a339190611dce565b6040516370a0823160e01b81523060048201529092507f000000000000000000000000a350da05405cc204e551c4eed19c3039646528d56001600160a01b0316906370a0823190602401602060405180830381865afa158015610a9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610abe9190611e01565b821115610b045760405162461bcd60e51b8152602060048201526014602482015273125b9d985b1a59081d1bdad95b88185b5bdd5b9d60621b604482015260640161056f565b610b40848281518110610b1957610b19611da2565b6020026020010151848381518110610b3357610b33611da2565b60200260200101516110d4565b80610b4a81611de6565b915050610a05565b506040516370a0823160e01b81523060048201527f000000000000000000000000a350da05405cc204e551c4eed19c3039646528d56001600160a01b0316906370a0823190602401602060405180830381865afa158015610bb7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bdb9190611e01565b610be361049e565b1115610c2d5760405162461bcd60e51b8152602060048201526019602482015278125b9cdd59999a58da595b9d081d1bdad95b88185b5bdd5b9d603a1b604482015260640161056f565b505050565b6001600160a01b03851660009081526001602052604090205415610c8d5760405162461bcd60e51b8152602060048201526012602482015271155cd95c88185b1c9958591e48185919195960721b604482015260640161056f565b6000610c976112af565b604051602001610ca690611e4f565b60408051808303601f190181528282528051602091820120818401526001600160a01b038a168383015260608084018a90528251808503909101815260808401909252815191012061190160f01b60a083015260a282019290925260c281019190915260e20160408051601f1981840301815282825280516020918201206000845290830180835281905260ff871691830191909152606082018590526080820184905291506001600160a01b037f000000000000000000000000895c64fa17ae0681b03923faa06cf9434478d51b169060019060a0016020604051602081039080840390855afa158015610d9f573d6000803e3d6000fd5b505050602060405103516001600160a01b031614610df05760405162461bcd60e51b815260206004820152600e60248201526d24b73b30b634b21039b4b3b732b960911b604482015260640161056f565b610dfa86866110d4565b6040516370a0823160e01b81523060048201527f000000000000000000000000a350da05405cc204e551c4eed19c3039646528d56001600160a01b0316906370a0823190602401610760565b60058181548110610e5657600080fd5b6000918252602090912001546001600160a01b0316905081565b6001600160a01b038116600090815260036020526040812054610e92836113a2565b610e9c9190611e89565b92915050565b6000546001600160a01b03163314610ecc5760405162461bcd60e51b815260040161056f90611e1a565b6001600160a01b038116610f315760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161056f565b61082e81611084565b6001600160a01b03811660009081526001602090815260408083205460039092529091205410610fbf5760405162461bcd60e51b815260206004820152602a60248201527f5573657220616c72656164792072656c656173656420616c6c20617661696c61604482015269626c6520746f6b656e7360b01b606482015260840161056f565b6001600160a01b038116600090815260036020526040812054610fe1836113a2565b610feb9190611e89565b905080156108a35780600460008282546110059190611dce565b90915550611015905082826116db565b506001600160a01b03166000908152600260205260409020429055565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052610c2d908490611782565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b7f000000000000000000000000000000000000000000000000000000006236fb2042106111345760405162461bcd60e51b815260206004820152600e60248201526d496e76616c69642074696d696e6760901b604482015260640161056f565b6001600160a01b0382166111985760405162461bcd60e51b815260206004820152602560248201527f5468652062656e6566696369617279277320616464726573732063616e6e6f74604482015264020626520360dc1b606482015260840161056f565b600081116111e85760405162461bcd60e51b815260206004820152601f60248201527f416d6f756e742068617320746f2062652067726561746572207468616e203000604482015260640161056f565b6001600160a01b03821660009081526001602052604090205461125157600580546001810182556000919091527f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db00180546001600160a01b0319166001600160a01b0384161790555b6001600160a01b03821660009081526002602090815260408083207f00000000000000000000000000000000000000000000000000000000620f6e2090556001909152812080548392906112a6908490611dce565b90915550505050565b6000306001600160a01b037f000000000000000000000000edb723bbd2ab6740ff66008539d0eac0150e3a971614801561130857507f000000000000000000000000000000000000000000000000000000000000000146145b1561133257507f1983891cbb48b730a4064deb4e1db5f0861742a8f5d9cb55c5da375c8000cb7890565b61139d7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7f553a7fb8385303192b79b521dfb57dfda6342ce2c80b3996c5f913eed27b87217fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6611854565b905090565b60006113ee7f000000000000000000000000000000000000000000000000000000000114db007f00000000000000000000000000000000000000000000000000000000620f6e20611dce565b42111561141157506001600160a01b031660009081526001602052604090205490565b7f00000000000000000000000000000000000000000000000000000000620f6e2042101561144157506000919050565b60007f00000000000000000000000000000000000000000000000002c68af0bb140000156114c4576001600160a01b038316600090815260016020526040902054670de0b6b3a7640000906114b7907f00000000000000000000000000000000000000000000000002c68af0bb14000090611ea0565b6114c19190611ebf565b90505b7f000000000000000000000000000000000000000000000000000000006236fb204210156114f25792915050565b60007f000000000000000000000000000000000000000000000000000000000000000015611575576001600160a01b038416600090815260016020526040902054670de0b6b3a764000090611568907f000000000000000000000000000000000000000000000000000000000000000090611ea0565b6115729190611ebf565b90505b60007f0000000000000000000000000000000000000000000000000000000000278d006115c27f000000000000000000000000000000000000000000000000000000006236fb2042611e89565b6115cc9190611ebf565b9050806115e6576115dd8284611dce565b95945050505050565b7f0000000000000000000000000000000000000000000000000000000000278d006116517f00000000000000000000000000000000000000000000000000000000620f6e207f000000000000000000000000000000000000000000000000000000006236fb20611e89565b61167b907f000000000000000000000000000000000000000000000000000000000114db00611e89565b6116859190611ebf565b816116908486611dce565b6001600160a01b0388166000908152600160205260409020546116b39190611e89565b6116bd9190611ea0565b6116c79190611ebf565b6116d18385611dce565b6115dd9190611dce565b61170f6001600160a01b037f000000000000000000000000a350da05405cc204e551c4eed19c3039646528d5168383611032565b6001600160a01b03821660009081526003602052604081208054839290611737908490611dce565b9091555050604080516001600160a01b0384168152602081018390527fb21fb52d5749b80f3182f8c6992236b5e5576681880914484d7f4c9b062e619e910160405180910390a15050565b60006117d7826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661189e9092919063ffffffff16565b805190915015610c2d57808060200190518101906117f59190611ee1565b610c2d5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161056f565b6040805160208101859052908101839052606081018290524660808201523060a082015260009060c0016040516020818303038152906040528051906020012090505b9392505050565b60606118ad84846000856118b5565b949350505050565b6060824710156119165760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161056f565b6001600160a01b0385163b61196d5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161056f565b600080866001600160a01b031685876040516119899190611f33565b60006040518083038185875af1925050503d80600081146119c6576040519150601f19603f3d011682016040523d82523d6000602084013e6119cb565b606091505b50915091506119db8282866119e6565b979650505050505050565b606083156119f5575081611897565b825115611a055782518084602001fd5b8160405162461bcd60e51b815260040161056f9190611f4f565b6001600160a01b038116811461082e57600080fd5b600060208284031215611a4657600080fd5b813561189781611a1f565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715611a9057611a90611a51565b604052919050565b600067ffffffffffffffff821115611ab257611ab2611a51565b5060051b60200190565b600082601f830112611acd57600080fd5b81356020611ae2611add83611a98565b611a67565b82815260059290921b84018101918181019086841115611b0157600080fd5b8286015b84811015611b25578035611b1881611a1f565b8352918301918301611b05565b509695505050505050565b600082601f830112611b4157600080fd5b81356020611b51611add83611a98565b82815260059290921b84018101918181019086841115611b7057600080fd5b8286015b84811015611b255780358352918301918301611b74565b803560ff81168114611b9c57600080fd5b919050565b600082601f830112611bb257600080fd5b81356020611bc2611add83611a98565b82815260059290921b84018101918181019086841115611be157600080fd5b8286015b84811015611b2557611bf681611b8b565b8352918301918301611be5565b600080600080600060a08688031215611c1b57600080fd5b853567ffffffffffffffff80821115611c3357600080fd5b611c3f89838a01611abc565b96506020880135915080821115611c5557600080fd5b611c6189838a01611b30565b95506040880135915080821115611c7757600080fd5b611c8389838a01611ba1565b94506060880135915080821115611c9957600080fd5b611ca589838a01611b30565b93506080880135915080821115611cbb57600080fd5b50611cc888828901611b30565b9150509295509295909350565b60008060408385031215611ce857600080fd5b823567ffffffffffffffff80821115611d0057600080fd5b611d0c86838701611abc565b93506020850135915080821115611d2257600080fd5b50611d2f85828601611b30565b9150509250929050565b600080600080600060a08688031215611d5157600080fd5b8535611d5c81611a1f565b945060208601359350611d7160408701611b8b565b94979396509394606081013594506080013592915050565b600060208284031215611d9b57600080fd5b5035919050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60008219821115611de157611de1611db8565b500190565b6000600019821415611dfa57611dfa611db8565b5060010190565b600060208284031215611e1357600080fd5b5051919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b7f5573657228616464726573732062656e65666963696172792c75696e7432353681526720616d6f756e742960c01b602082015260280190565b600082821015611e9b57611e9b611db8565b500390565b6000816000190483118215151615611eba57611eba611db8565b500290565b600082611edc57634e487b7160e01b600052601260045260246000fd5b500490565b600060208284031215611ef357600080fd5b8151801515811461189757600080fd5b60005b83811015611f1e578181015183820152602001611f06565b83811115611f2d576000848401525b50505050565b60008251611f45818460208701611f03565b9190910192915050565b6020815260008251806020840152611f6e816040850160208701611f03565b601f01601f1916919091016040019291505056fea264697066735822122039650d5e671f3170f9981d4f4dbc7d9a2ea5d3ad502df37211f22adf71805aa764736f6c634300080a0033
Verified Source Code Full Match
Compiler: v0.8.10+commit.fc410830
EVM: london
Optimization: Yes (200 runs)
BLSVesting.sol 222 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
contract BLSVesting is Ownable, EIP712 {
using SafeERC20 for IERC20;
event Released(address beneficiary, uint256 amount);
IERC20 public immutable token;
uint256 public immutable tgeTime;
uint256 public immutable tgePercentage;
uint256 public immutable cliffTime;
uint256 public immutable cliffPercentage;
uint256 public immutable start;
uint256 public immutable duration;
uint256 public immutable period;
mapping (address => uint256) public tokenAmounts;
mapping (address => uint256) public lastReleaseDate;
mapping (address => uint256) public releasedAmount;
uint256 public released = 0;
uint256 public constant BP = 1e18;
address public immutable cSigner;
address[] public beneficiaries;
bytes32 public constant SIGNED_MESSAGE =
keccak256(abi.encodePacked("User(address beneficiary,uint256 amount)"));
constructor(
IERC20 _token,
uint256 _start,
uint256 _tgeTime, // time after vesting start to distribute tge
uint256 _tgePercentage, // tge % to be distributed at tge time
uint256 _cliffTime, // time after tge time to distribute cliff
uint256 _cliffPercentage, // cliff % to be distributed at cliff time
uint256 _duration, // total vesting duration since the vesting start
uint256 _period, // slice periods to distribute, 1 month, 3 months, 6 months, 1 year, any time
address _signer
) EIP712("Blocksport", "1") {
require(_cliffTime <= _duration, "Cliff has to be lower or equal to duration");
cSigner = _signer;
token = _token;
duration = _duration;
tgeTime = _start + _tgeTime;
tgePercentage = _tgePercentage;
cliffTime = tgeTime + _cliffTime;
cliffPercentage = _cliffPercentage;
start = _start;
period = _period;
}
function addBeneficiariesWithSign(
address[] memory _beneficiaries,
uint256[] memory _tokenAmounts,
uint8[] memory _v,
bytes32[] memory _r,
bytes32[] memory _s
) external {
require(
_beneficiaries.length == _tokenAmounts.length &&
_beneficiaries.length == _v.length &&
_beneficiaries.length == _r.length &&
_beneficiaries.length == _s.length
, "Invalid params"
);
uint256 totalToBeAdded;
for (uint i = 0; i <_beneficiaries.length; i++) {
totalToBeAdded += _tokenAmounts[i];
require(totalToBeAdded <= token.balanceOf(address(this)), "Invalid token amount");
addBeneficiaryWithSign(_beneficiaries[i], _tokenAmounts[i], _v[i], _r[i], _s[i]);
}
require(totalAmounts() <= token.balanceOf(address(this)), "Insufficient token amount"); // could be replaced with a storage variable, totalInVesting
}
function addBeneficiaryWithSign(
address _beneficiary,
uint256 _tokenAmount,
uint8 v,
bytes32 r,
bytes32 s
) public {
require(tokenAmounts[_beneficiary] == 0, "User already added");
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
_domainSeparatorV4(),
keccak256(
abi.encode(SIGNED_MESSAGE, _beneficiary, _tokenAmount)
)
)
);
require(ecrecover(digest, v, r, s) == cSigner, "Invalid signer");
addBeneficiary(_beneficiary, _tokenAmount);
require(totalAmounts() <= token.balanceOf(address(this)), "Insufficient token amount");
}
function addBeneficiaries(address[] memory _beneficiaries, uint256[] memory _tokenAmounts) public onlyOwner {
require(_beneficiaries.length == _tokenAmounts.length, "Invalid params");
uint256 totalToBeAdded;
for (uint i = 0; i <_beneficiaries.length; i++) {
totalToBeAdded += _tokenAmounts[i];
require(totalToBeAdded <= token.balanceOf(address(this)), "Invalid token amount");
addBeneficiary(_beneficiaries[i], _tokenAmounts[i]);
}
require(totalAmounts() <= token.balanceOf(address(this)), "Insufficient token amount");
}
function addBeneficiary(address _beneficiary, uint256 _tokenAmount) private {
require(block.timestamp < cliffTime, "Invalid timing"); // It is not allowed to include new beneficiaries after cliff time
require(_beneficiary != address(0), "The beneficiary's address cannot be 0");
require(_tokenAmount > 0, "Amount has to be greater than 0");
if (tokenAmounts[_beneficiary] == 0) {
beneficiaries.push(_beneficiary);
}
lastReleaseDate[_beneficiary] = tgeTime;
tokenAmounts[_beneficiary] += _tokenAmount;
}
function claimOwnTokens() public {
_claimTokens(msg.sender);
}
function claimBeneficiaryTokens(address _beneficiary) public onlyOwner {
_claimTokens(_beneficiary);
}
function _claimTokens(address _beneficiary) private {
require(releasedAmount[_beneficiary] < tokenAmounts[_beneficiary], "User already released all available tokens");
uint256 unreleased = releasableAmount(_beneficiary) - releasedAmount[_beneficiary];
if (unreleased > 0) {
released += unreleased;
release(_beneficiary, unreleased);
lastReleaseDate[_beneficiary] = block.timestamp;
}
}
function userReleasableAmount(address _beneficiary) public view returns (uint256) {
return releasableAmount(_beneficiary) - releasedAmount[_beneficiary];
}
function releasableAmount(address _account) private view returns (uint256) {
if(block.timestamp > (start + duration)) return tokenAmounts[_account]; // Calling when vesting ended
// Return 0 if time is before tgeTime
if (block.timestamp < tgeTime) return 0; // TODO: check this part
// ================== TGE CALCULATION ==================
// Continue if time is after tge time
uint256 tgePayment;
if (tgePercentage > 0) {
// Calculate tge payment
tgePayment = (tokenAmounts[_account] * tgePercentage) / BP;
}
// Time in before cliff time
if(block.timestamp < cliffTime) return tgePayment;
// ================== CLIFF CALCULATION ==================
uint256 cliffPayment;
if (cliffPercentage > 0) {
// Calculate cliff payment
cliffPayment = (tokenAmounts[_account] * cliffPercentage) / BP;
}
// ================== VESTING PERIODS CALCULATION ==================
uint256 periodsPassed = (block.timestamp - cliffTime) / period; // Periods passed after cliff end
if(periodsPassed == 0) return tgePayment + cliffPayment;
return tgePayment + cliffPayment + (tokenAmounts[_account] - (tgePayment + cliffPayment)) * periodsPassed / ((duration - (cliffTime - start))/ period);
}
function totalAmounts() public view returns (uint256 sum) {
for (uint i = 0; i < beneficiaries.length; i++) {
sum += tokenAmounts[beneficiaries[i]];
}
}
function release(address _beneficiary, uint256 _amount) private {
token.safeTransfer(_beneficiary, _amount);
releasedAmount[_beneficiary] += _amount;
emit Released(_beneficiary, _amount);
}
function beneficiariesLength() public view returns (uint256){
return beneficiaries.length;
}
function withdraw(IERC20 _token) external onlyOwner {
if (_token == IERC20(address(0))) {
// allow to rescue ether
payable(owner()).transfer(address(this).balance);
} else {
uint256 withdrawAmount = _token.balanceOf(address(this));
if (withdrawAmount > 0) {
_token.safeTransfer(address(msg.sender), withdrawAmount);
}
}
}
}
Address.sol 222 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
Strings.sol 67 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
Ownable.sol 76 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
ECDSA.sol 230 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../Strings.sol";
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
} else if (error == RecoverError.InvalidSignatureV) {
revert("ECDSA: invalid signature 'v' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
// Check the signature length
// - case 65: r,s,v signature (standard)
// - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else if (signature.length == 64) {
bytes32 r;
bytes32 vs;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
vs := mload(add(signature, 0x40))
}
return tryRecover(hash, r, vs);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
if (v != 27 && v != 28) {
return (address(0), RecoverError.InvalidSignatureV);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
/**
* @dev Returns an Ethereum Signed Message, created from `s`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}
SafeERC20.sol 99 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
draft-EIP712.sol 104 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/cryptography/draft-EIP712.sol)
pragma solidity ^0.8.0;
import "./ECDSA.sol";
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
*
* The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
* thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
* they need in their contracts using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* _Available since v3.4._
*/
abstract contract EIP712 {
/* solhint-disable var-name-mixedcase */
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
// invalidate the cached domain separator if the chain id changes.
bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
uint256 private immutable _CACHED_CHAIN_ID;
address private immutable _CACHED_THIS;
bytes32 private immutable _HASHED_NAME;
bytes32 private immutable _HASHED_VERSION;
bytes32 private immutable _TYPE_HASH;
/* solhint-enable var-name-mixedcase */
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
bytes32 hashedName = keccak256(bytes(name));
bytes32 hashedVersion = keccak256(bytes(version));
bytes32 typeHash = keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
);
_HASHED_NAME = hashedName;
_HASHED_VERSION = hashedVersion;
_CACHED_CHAIN_ID = block.chainid;
_CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
_CACHED_THIS = address(this);
_TYPE_HASH = typeHash;
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (address(this) == _CACHED_THIS && block.chainid == _CACHED_CHAIN_ID) {
return _CACHED_DOMAIN_SEPARATOR;
} else {
return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
}
}
function _buildDomainSeparator(
bytes32 typeHash,
bytes32 nameHash,
bytes32 versionHash
) private view returns (bytes32) {
return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
}
}
Read Contract
BP 0x9cfdbd5e → uint256
SIGNED_MESSAGE 0x62095735 → bytes32
beneficiaries 0xefeb5e58 → address
beneficiariesLength 0xc0659108 → uint256
cSigner 0x5760cc5d → address
cliffPercentage 0x3c21e595 → uint256
cliffTime 0x0f1a6444 → uint256
duration 0x0fb5a6b4 → uint256
lastReleaseDate 0x76272bdc → uint256
owner 0x8da5cb5b → address
period 0xef78d4fd → uint256
released 0x96132521 → uint256
releasedAmount 0x1cf1bb72 → uint256
start 0xbe9a6555 → uint256
tgePercentage 0x5b889e6e → uint256
tgeTime 0x3163e3a8 → uint256
token 0xfc0c546a → address
tokenAmounts 0xa0e2e5f6 → uint256
totalAmounts 0x0c6ffc29 → uint256
userReleasableAmount 0xf119b250 → uint256
Write Contract 8 functions
These functions modify contract state and require a wallet transaction to execute.
addBeneficiaries 0xa9610655
address[] _beneficiaries
uint256[] _tokenAmounts
addBeneficiariesWithSign 0x2b0f658c
address[] _beneficiaries
uint256[] _tokenAmounts
uint8[] _v
bytes32[] _r
bytes32[] _s
addBeneficiaryWithSign 0xef8b7651
address _beneficiary
uint256 _tokenAmount
uint8 v
bytes32 r
bytes32 s
claimBeneficiaryTokens 0x3ee660f3
address _beneficiary
claimOwnTokens 0x77f52bef
No parameters
renounceOwnership 0x715018a6
No parameters
transferOwnership 0xf2fde38b
address newOwner
withdraw 0x51cff8d9
address _token
Recent Transactions
No transactions found for this address