Address Contract Verified
Address
0xCd0f64b43D21DcC494c039c32089385dcE1C7B99
Balance
0 ETH
Nonce
1
Code Size
9869 bytes
Creator
0x091Bd5f2...6381 at tx 0xbb8af802...034a60
Indexed Transactions
0
Contract Bytecode
9869 bytes
0x6080604052600436106101445760003560e01c80638da5cb5b116100b6578063c1f606061161006f578063c1f6060614610430578063e99d28661461046d578063ea1bb3d514610496578063f2fde38b146104d3578063f7c469f0146104fc578063f9079b37146105395761014b565b80638da5cb5b1461031e57806390be10cc146103495780639ef346b414610374578063b75c7dc6146103b1578063b87592f2146103da578063ba9a061a146104055761014b565b80633bedde7d116101085780633bedde7d1461022257806348deb4711461025f57806366afd8ef1461028a5780636a3dfb63146102b3578063715018a6146102de5780638c5233ab146102f55761014b565b806308551a531461014d57806313083617146101785780631be05289146101a357806321df0da7146101ce5780632e1a7d4d146101f95761014b565b3661014b57005b005b34801561015957600080fd5b50610162610576565b60405161016f9190611b32565b60405180910390f35b34801561018457600080fd5b5061018d61059c565b60405161019a9190611b66565b60405180910390f35b3480156101af57600080fd5b506101b86105a9565b6040516101c59190611b66565b60405180910390f35b3480156101da57600080fd5b506101e36105af565b6040516101f09190611b32565b60405180910390f35b34801561020557600080fd5b50610220600480360381019061021b9190611bb2565b6105d7565b005b34801561022e57600080fd5b5061024960048036038101906102449190611c0b565b610687565b6040516102569190611d28565b60405180910390f35b34801561026b57600080fd5b506102746106a7565b6040516102819190611b66565b60405180910390f35b34801561029657600080fd5b506102b160048036038101906102ac9190611d7a565b6106b1565b005b3480156102bf57600080fd5b506102c86109ae565b6040516102d59190611b66565b60405180910390f35b3480156102ea57600080fd5b506102f36109b4565b005b34801561030157600080fd5b5061031c60048036038101906103179190611de6565b6109c8565b005b34801561032a57600080fd5b50610333610ec0565b6040516103409190611b32565b60405180910390f35b34801561035557600080fd5b5061035e610ee9565b60405161036b9190611b66565b60405180910390f35b34801561038057600080fd5b5061039b60048036038101906103969190611e39565b610f97565b6040516103a89190611d28565b60405180910390f35b3480156103bd57600080fd5b506103d860048036038101906103d39190611e39565b61108d565b005b3480156103e657600080fd5b506103ef611271565b6040516103fc9190611b66565b60405180910390f35b34801561041157600080fd5b5061041a611277565b6040516104279190611b66565b60405180910390f35b34801561043c57600080fd5b5061045760048036038101906104529190611c0b565b61127d565b6040516104649190611e75565b60405180910390f35b34801561047957600080fd5b50610494600480360381019061048f9190611c0b565b6112ad565b005b3480156104a257600080fd5b506104bd60048036038101906104b89190611e39565b6112f9565b6040516104ca9190611b66565b60405180910390f35b3480156104df57600080fd5b506104fa60048036038101906104f59190611c0b565b611427565b005b34801561050857600080fd5b50610523600480360381019061051e9190611c0b565b6114ad565b6040516105309190611e75565b60405180910390f35b34801561054557600080fd5b50610560600480360381019061055b9190611bb2565b6114bf565b60405161056d9190611e75565b60405180910390f35b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600280549050905090565b60075481565b60007f0000000000000000000000000e7375c46a0552520ce6c976dc268ae1b341f45f905090565b6105df611530565b6105e7611576565b806105f0610ee9565b1015610631576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161062890611f13565b60405180910390fd5b61067c33827f0000000000000000000000000e7375c46a0552520ce6c976dc268ae1b341f45f73ffffffffffffffffffffffffffffffffffffffff166115fd9092919063ffffffff16565b61068461167c565b50565b61068f611a8b565b6106a061069b8361127d565b610f97565b9050919050565b6000600454905090565b6106b9611530565b816003600082815260200190815260200160002060080160009054906101000a900460ff16156106e857600080fd5b600060036000858152602001908152602001600020905060008160000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161490506000610760610ec0565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614905081806107995750805b6107d8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107cf90611fcb565b60405180910390fd5b60006108b784604051806101200160405290816000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001600182015481526020016002820154815260200160038201548152602001600482015481526020016005820160009054906101000a900460ff1615151515815260200160068201548152602001600782015481526020016008820160009054906101000a900460ff161515151581525050611685565b9050858110156108fc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108f39061205d565b60405180910390fd5b85846007015461090c91906120ac565b846007018190555060008460000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508660045461094b91906120e0565b60048190555061099c81887f0000000000000000000000000e7375c46a0552520ce6c976dc268ae1b341f45f73ffffffffffffffffffffffffffffffffffffffff166115fd9092919063ffffffff16565b5050505050506109aa61167c565b5050565b60095481565b6109bc611576565b6109c66000611769565b565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161480610a565750610a27610ec0565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b610a95576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a8c90612186565b60405180910390fd5b81610a9e610ee9565b1015610adf576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ad69061223e565b60405180910390fd5b60008211610b22576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b19906122aa565b60405180910390fd5b6000610b2d846114ad565b9050600060036000838152602001908152602001600020604051806101200160405290816000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001600182015481526020016002820154815260200160038201548152602001600482015481526020016005820160009054906101000a900460ff1615151515815260200160068201548152602001600782015481526020016008820160009054906101000a900460ff161515151581525050905060008160c0015103610ca4576000600854600654610c3891906120ac565b90506040518061012001604052808773ffffffffffffffffffffffffffffffffffffffff16815260200182815260200160065481526020016007548152602001600954815260200185151581526020018681526020016000815260200160001515815250915050610cbe565b838160c00151610cb491906120ac565b8160c00181815250505b806003600084815260200190815260200160002060008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506020820151816001015560408201518160020155606082015181600301556080820151816004015560a08201518160050160006101000a81548160ff02191690831515021790555060c0820151816006015560e082015181600701556101008201518160080160006101000a81548160ff02191690831515021790555090505083600454610da791906120ac565b60048190555060028290806001815401808255809150506001900390600052602060002001600090919091909150556000600560008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050600181610e2791906120ac565b600560008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508573ffffffffffffffffffffffffffffffffffffffff167f969705509595726740fe60cc30769bbd53c883efff4d8e70108a82817e0392a986604051610eb09190611b66565b60405180910390a2505050505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60006004547f0000000000000000000000000e7375c46a0552520ce6c976dc268ae1b341f45f73ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401610f479190611b32565b602060405180830381865afa158015610f64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f8891906122df565b610f9291906120e0565b905090565b610f9f611a8b565b60036000838152602001908152602001600020604051806101200160405290816000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001600182015481526020016002820154815260200160038201548152602001600482015481526020016005820160009054906101000a900460ff1615151515815260200160068201548152602001600782015481526020016008820160009054906101000a900460ff1615151515815250509050919050565b611095611576565b806003600082815260200190815260200160002060080160009054906101000a900460ff16156110c457600080fd5b60006003600084815260200190815260200160002090508060050160009054906101000a900460ff1661112c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111239061237e565b60405180910390fd5b600061120b82604051806101200160405290816000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001600182015481526020016002820154815260200160038201548152602001600482015481526020016005820160009054906101000a900460ff1615151515815260200160068201548152602001600782015481526020016008820160009054906101000a900460ff161515151581525050611685565b905060008111156112215761122084826106b1565b5b60008260070154836006015461123791906120e0565b90508060045461124791906120e0565b60048190555060018360080160006101000a81548160ff0219169083151502179055505050505050565b60085481565b60065481565b60008160405160200161129091906123e6565b604051602081830303815290604052805190602001209050919050565b6112b5611576565b80600a60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000816003600082815260200190815260200160002060080160009054906101000a900460ff161561132a57600080fd5b600060036000858152602001908152602001600020905061141e81604051806101200160405290816000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001600182015481526020016002820154815260200160038201548152602001600482015481526020016005820160009054906101000a900460ff1615151515815260200160068201548152602001600782015481526020016008820160009054906101000a900460ff161515151581525050611685565b92505050919050565b61142f611576565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16036114a15760006040517f1e4fbdf70000000000000000000000000000000000000000000000000000000081526004016114989190611b32565b60405180910390fd5b6114aa81611769565b50565b60006114b88261127d565b9050919050565b60006114c961059c565b821061150a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161150190612473565b60405180910390fd5b6002828154811061151e5761151d612493565b5b90600052602060002001549050919050565b60026001540361156c576040517f3ee5aeb500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6002600181905550565b61157e61182d565b73ffffffffffffffffffffffffffffffffffffffff1661159c610ec0565b73ffffffffffffffffffffffffffffffffffffffff16146115fb576115bf61182d565b6040517f118cdaa70000000000000000000000000000000000000000000000000000000081526004016115f29190611b32565b60405180910390fd5b565b611677838473ffffffffffffffffffffffffffffffffffffffff1663a9059cbb85856040516024016116309291906124c2565b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050611835565b505050565b60018081905550565b6000806116906118cc565b905082602001518110806116a657508261010001515b156116b5576000915050611764565b826060015183602001516116c991906120ac565b81106116eb578260e001518360c001516116e391906120e0565b915050611764565b60008360200151826116fd91906120e0565b905060008460800151905060008183611716919061251a565b905060008282611726919061254b565b905060008760600151828960c0015161173f919061254b565b611749919061251a565b90508760e001518161175b91906120e0565b96505050505050505b919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600033905090565b6000611860828473ffffffffffffffffffffffffffffffffffffffff166118d490919063ffffffff16565b9050600081511415801561188557508080602001905181019061188391906125a2565b155b156118c757826040517f5274afe70000000000000000000000000000000000000000000000000000000081526004016118be9190611b32565b60405180910390fd5b505050565b600042905090565b60606118e2838360006118ea565b905092915050565b60608147101561193157306040517fcd7860590000000000000000000000000000000000000000000000000000000081526004016119289190611b32565b60405180910390fd5b6000808573ffffffffffffffffffffffffffffffffffffffff16848660405161195a9190612640565b60006040518083038185875af1925050503d8060008114611997576040519150601f19603f3d011682016040523d82523d6000602084013e61199c565b606091505b50915091506119ac8683836119b7565b925050509392505050565b6060826119cc576119c782611a46565b611a3e565b600082511480156119f4575060008473ffffffffffffffffffffffffffffffffffffffff163b145b15611a3657836040517f9996b315000000000000000000000000000000000000000000000000000000008152600401611a2d9190611b32565b60405180910390fd5b819050611a3f565b5b9392505050565b600081511115611a595780518082602001fd5b6040517f1425ea4200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b604051806101200160405280600073ffffffffffffffffffffffffffffffffffffffff1681526020016000815260200160008152602001600081526020016000815260200160001515815260200160008152602001600081526020016000151581525090565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000611b1c82611af1565b9050919050565b611b2c81611b11565b82525050565b6000602082019050611b476000830184611b23565b92915050565b6000819050919050565b611b6081611b4d565b82525050565b6000602082019050611b7b6000830184611b57565b92915050565b600080fd5b611b8f81611b4d565b8114611b9a57600080fd5b50565b600081359050611bac81611b86565b92915050565b600060208284031215611bc857611bc7611b81565b5b6000611bd684828501611b9d565b91505092915050565b611be881611b11565b8114611bf357600080fd5b50565b600081359050611c0581611bdf565b92915050565b600060208284031215611c2157611c20611b81565b5b6000611c2f84828501611bf6565b91505092915050565b611c4181611b11565b82525050565b611c5081611b4d565b82525050565b60008115159050919050565b611c6b81611c56565b82525050565b61012082016000820151611c886000850182611c38565b506020820151611c9b6020850182611c47565b506040820151611cae6040850182611c47565b506060820151611cc16060850182611c47565b506080820151611cd46080850182611c47565b5060a0820151611ce760a0850182611c62565b5060c0820151611cfa60c0850182611c47565b5060e0820151611d0d60e0850182611c47565b50610100820151611d22610100850182611c62565b50505050565b600061012082019050611d3e6000830184611c71565b92915050565b6000819050919050565b611d5781611d44565b8114611d6257600080fd5b50565b600081359050611d7481611d4e565b92915050565b60008060408385031215611d9157611d90611b81565b5b6000611d9f85828601611d65565b9250506020611db085828601611b9d565b9150509250929050565b611dc381611c56565b8114611dce57600080fd5b50565b600081359050611de081611dba565b92915050565b600080600060608486031215611dff57611dfe611b81565b5b6000611e0d86828701611bf6565b9350506020611e1e86828701611b9d565b9250506040611e2f86828701611dd1565b9150509250925092565b600060208284031215611e4f57611e4e611b81565b5b6000611e5d84828501611d65565b91505092915050565b611e6f81611d44565b82525050565b6000602082019050611e8a6000830184611e66565b92915050565b600082825260208201905092915050565b7f546f6b656e56657374696e673a206e6f7420656e6f756768207769746864726160008201527f7761626c652066756e6473000000000000000000000000000000000000000000602082015250565b6000611efd602b83611e90565b9150611f0882611ea1565b604082019050919050565b60006020820190508181036000830152611f2c81611ef0565b9050919050565b7f546f6b656e56657374696e673a206f6e6c792062656e6566696369617279206160008201527f6e64206f776e65722063616e2072656c656173652076657374656420746f6b6560208201527f6e73000000000000000000000000000000000000000000000000000000000000604082015250565b6000611fb5604283611e90565b9150611fc082611f33565b606082019050919050565b60006020820190508181036000830152611fe481611fa8565b9050919050565b7f546f6b656e56657374696e673a2063616e6e6f742072656c6561736520746f6b60008201527f656e732c206e6f7420656e6f7567682076657374656420746f6b656e73000000602082015250565b6000612047603d83611e90565b915061205282611feb565b604082019050919050565b600060208201905081810360008301526120768161203a565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006120b782611b4d565b91506120c283611b4d565b92508282019050808211156120da576120d961207d565b5b92915050565b60006120eb82611b4d565b91506120f683611b4d565b925082820390508181111561210e5761210d61207d565b5b92915050565b7f4f6e6c792073656c6c6572206f72206f776e65722063616e206372656174652060008201527f76657374696e67207363686564756c6500000000000000000000000000000000602082015250565b6000612170603083611e90565b915061217b82612114565b604082019050919050565b6000602082019050818103600083015261219f81612163565b9050919050565b7f546f6b656e56657374696e673a2063616e6e6f7420637265617465207665737460008201527f696e67207363686564756c652062656361757365206e6f74207375666669636960208201527f656e7420746f6b656e7300000000000000000000000000000000000000000000604082015250565b6000612228604a83611e90565b9150612233826121a6565b606082019050919050565b600060208201905081810360008301526122578161221b565b9050919050565b7f546f6b656e56657374696e673a20616d6f756e74206d757374206265203e2030600082015250565b6000612294602083611e90565b915061229f8261225e565b602082019050919050565b600060208201905081810360008301526122c381612287565b9050919050565b6000815190506122d981611b86565b92915050565b6000602082840312156122f5576122f4611b81565b5b6000612303848285016122ca565b91505092915050565b7f546f6b656e56657374696e673a2076657374696e67206973206e6f742072657660008201527f6f6361626c650000000000000000000000000000000000000000000000000000602082015250565b6000612368602683611e90565b91506123738261230c565b604082019050919050565b600060208201905081810360008301526123978161235b565b9050919050565b60008160601b9050919050565b60006123b68261239e565b9050919050565b60006123c8826123ab565b9050919050565b6123e06123db82611b11565b6123bd565b82525050565b60006123f282846123cf565b60148201915081905092915050565b7f546f6b656e56657374696e673a20696e646578206f7574206f6620626f756e6460008201527f7300000000000000000000000000000000000000000000000000000000000000602082015250565b600061245d602183611e90565b915061246882612401565b604082019050919050565b6000602082019050818103600083015261248c81612450565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60006040820190506124d76000830185611b23565b6124e46020830184611b57565b9392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600061252582611b4d565b915061253083611b4d565b9250826125405761253f6124eb565b5b828204905092915050565b600061255682611b4d565b915061256183611b4d565b925082820261256f81611b4d565b915082820484148315176125865761258561207d565b5b5092915050565b60008151905061259c81611dba565b92915050565b6000602082840312156125b8576125b7611b81565b5b60006125c68482850161258d565b91505092915050565b600081519050919050565b600081905092915050565b60005b838110156126035780820151818401526020810190506125e8565b60008484015250505050565b600061261a826125cf565b61262481856125da565b93506126348185602086016125e5565b80840191505092915050565b600061264c828461260f565b91508190509291505056fea2646970667358221220243c2d2f32755b7c81416db8a2cceb55c16c222cc753d6fef13defa221a7ea3364736f6c63430008180033
Verified Source Code Full Match
Compiler: v0.8.24+commit.e11b9ed9
EVM: paris
Optimization: No
TokenVesting.sol 371 lines
// contracts/TokenVesting.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.24;
// OpenZeppelin dependencies
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
using SafeERC20 for IERC20;
/**
* @title TokenVesting
*/
contract TokenVesting is Ownable, ReentrancyGuard {
struct VestingSchedule {
// beneficiary of tokens after they are released
address beneficiary;
// cliff time of the vesting start in seconds since the UNIX epoch
uint256 cliff;
// start time of the vesting period in seconds since the UNIX epoch
uint256 start;
// duration of the vesting period in seconds
uint256 duration;
// duration of a slice period for the vesting in seconds
uint256 slicePeriodSeconds;
// whether or not the vesting is revocable
bool revocable;
// total amount of tokens to be released at the end of the vesting
uint256 amountTotal;
// amount of tokens released
uint256 released;
// whether or not the vesting has been revoked
bool revoked;
}
event VestingScheduleCreated(address indexed beneficiary, uint256 amount);
// address of the ERC20 token
IERC20 private immutable _token;
bytes32[] private vestingSchedulesIds;
mapping(bytes32 => VestingSchedule) private vestingSchedules;
uint256 private vestingSchedulesTotalAmount;
mapping(address => uint256) private holdersVestingCount;
uint256 public START;
uint256 public DURATION;
uint256 public CLIFF;
uint256 public SLICE_PERIOD;
address public seller;
/**
* @dev Reverts if the vesting schedule does not exist or has been revoked.
*/
modifier onlyIfVestingScheduleNotRevoked(bytes32 vestingScheduleId) {
require(!vestingSchedules[vestingScheduleId].revoked);
_;
}
/**
* @dev Creates a vesting contract.
* @param token_ address of the ERC20 token contract
*/
constructor(address token_, uint256 _start, uint256 _duration, uint256 _cliff, uint256 _slicePeriodSeconds) Ownable(msg.sender) {
// Check that the token address is not 0x0.
require(token_ != address(0x0));
require(_duration > 0, "TokenVesting: duration must be > 0");
require(
_slicePeriodSeconds >= 1,
"TokenVesting: slicePeriodSeconds must be >= 1"
);
require(_duration >= _cliff, "TokenVesting: duration must be >= cliff");
// Set the token address.
_token = IERC20(token_);
START = _start;
DURATION = _duration;
CLIFF = _cliff;
SLICE_PERIOD = _slicePeriodSeconds;
}
/**
* @dev This function is called for plain Ether transfers, i.e. for every call with empty calldata.
*/
receive() external payable {}
/**
* @dev Fallback function is executed if none of the other functions match the function
* identifier or no data was provided with the function call.
*/
fallback() external payable {}
function setSeller(address _seller) external onlyOwner {
seller = _seller;
}
/**
* @notice Creates a new vesting schedule for a beneficiary.
* @param _beneficiary address of the beneficiary to whom vested tokens are transferred
* @param _amount total amount of tokens to be released at the end of the vesting
* @param _revocable whether the vesting is revocable or not
*/
function createVestingSchedule(
address _beneficiary,
uint256 _amount,
bool _revocable
) external {
require(msg.sender == seller || msg.sender == owner(), "Only seller or owner can create vesting schedule");
require(
getWithdrawableAmount() >= _amount,
"TokenVesting: cannot create vesting schedule because not sufficient tokens"
);
require(_amount > 0, "TokenVesting: amount must be > 0");
bytes32 vestingScheduleId = computeNextVestingScheduleIdForHolder(
_beneficiary
);
VestingSchedule memory vestingSchedule = vestingSchedules[vestingScheduleId];
if(vestingSchedule.amountTotal == 0) {
uint256 cliff = START + CLIFF;
vestingSchedule = VestingSchedule(
_beneficiary,
cliff,
START,
DURATION,
SLICE_PERIOD,
_revocable,
_amount,
0,
false
);
} else {
vestingSchedule.amountTotal = vestingSchedule.amountTotal + _amount;
}
vestingSchedules[vestingScheduleId] = vestingSchedule;
vestingSchedulesTotalAmount = vestingSchedulesTotalAmount + _amount;
vestingSchedulesIds.push(vestingScheduleId);
uint256 currentVestingCount = holdersVestingCount[_beneficiary];
holdersVestingCount[_beneficiary] = currentVestingCount + 1;
emit VestingScheduleCreated(_beneficiary, _amount);
}
/**
* @notice Revokes the vesting schedule for given identifier.
* @param vestingScheduleId the vesting schedule identifier
*/
function revoke(
bytes32 vestingScheduleId
) external onlyOwner onlyIfVestingScheduleNotRevoked(vestingScheduleId) {
VestingSchedule storage vestingSchedule = vestingSchedules[
vestingScheduleId
];
require(
vestingSchedule.revocable,
"TokenVesting: vesting is not revocable"
);
uint256 vestedAmount = _computeReleasableAmount(vestingSchedule);
if (vestedAmount > 0) {
release(vestingScheduleId, vestedAmount);
}
uint256 unreleased = vestingSchedule.amountTotal -
vestingSchedule.released;
vestingSchedulesTotalAmount = vestingSchedulesTotalAmount - unreleased;
vestingSchedule.revoked = true;
}
/**
* @notice Withdraw the specified amount if possible.
* @param amount the amount to withdraw
*/
function withdraw(uint256 amount) external nonReentrant onlyOwner {
require(
getWithdrawableAmount() >= amount,
"TokenVesting: not enough withdrawable funds"
);
/*
* @dev Replaced owner() with msg.sender => address of WITHDRAWER_ROLE
*/
_token.safeTransfer(msg.sender, amount);
}
/**
* @notice Release vested amount of tokens.
* @param vestingScheduleId the vesting schedule identifier
* @param amount the amount to release
*/
function release(
bytes32 vestingScheduleId,
uint256 amount
) public nonReentrant onlyIfVestingScheduleNotRevoked(vestingScheduleId) {
VestingSchedule storage vestingSchedule = vestingSchedules[
vestingScheduleId
];
bool isBeneficiary = msg.sender == vestingSchedule.beneficiary;
bool isReleasor = (msg.sender == owner());
require(
isBeneficiary || isReleasor,
"TokenVesting: only beneficiary and owner can release vested tokens"
);
uint256 vestedAmount = _computeReleasableAmount(vestingSchedule);
require(
vestedAmount >= amount,
"TokenVesting: cannot release tokens, not enough vested tokens"
);
vestingSchedule.released = vestingSchedule.released + amount;
address payable beneficiaryPayable = payable(
vestingSchedule.beneficiary
);
vestingSchedulesTotalAmount = vestingSchedulesTotalAmount - amount;
_token.safeTransfer(beneficiaryPayable, amount);
}
/**
* @dev Returns the vesting schedule id at the given index.
* @return the vesting id
*/
function getVestingIdAtIndex(
uint256 index
) external view returns (bytes32) {
require(
index < getVestingSchedulesCount(),
"TokenVesting: index out of bounds"
);
return vestingSchedulesIds[index];
}
/**
* @notice Returns the vesting schedule information for a given holder.
* @return the vesting schedule structure information
*/
function getVestingScheduleByAddress(
address holder
) external view returns (VestingSchedule memory) {
return
getVestingSchedule(
computeVestingScheduleIdForAddress(holder)
);
}
/**
* @notice Returns the total amount of vesting schedules.
* @return the total amount of vesting schedules
*/
function getVestingSchedulesTotalAmount() external view returns (uint256) {
return vestingSchedulesTotalAmount;
}
/**
* @dev Returns the address of the ERC20 token managed by the vesting contract.
*/
function getToken() external view returns (address) {
return address(_token);
}
/**
* @dev Returns the number of vesting schedules managed by this contract.
* @return the number of vesting schedules
*/
function getVestingSchedulesCount() public view returns (uint256) {
return vestingSchedulesIds.length;
}
/**
* @notice Computes the vested amount of tokens for the given vesting schedule identifier.
* @return the vested amount
*/
function computeReleasableAmount(
bytes32 vestingScheduleId
)
external
view
onlyIfVestingScheduleNotRevoked(vestingScheduleId)
returns (uint256)
{
VestingSchedule storage vestingSchedule = vestingSchedules[
vestingScheduleId
];
return _computeReleasableAmount(vestingSchedule);
}
/**
* @notice Returns the vesting schedule information for a given identifier.
* @return the vesting schedule structure information
*/
function getVestingSchedule(
bytes32 vestingScheduleId
) public view returns (VestingSchedule memory) {
return vestingSchedules[vestingScheduleId];
}
/**
* @dev Returns the amount of tokens that can be withdrawn by the owner.
* @return the amount of tokens
*/
function getWithdrawableAmount() public view returns (uint256) {
return _token.balanceOf(address(this)) - vestingSchedulesTotalAmount;
}
/**
* @dev Computes the next vesting schedule identifier for a given holder address.
*/
function computeNextVestingScheduleIdForHolder(
address holder
) public pure returns (bytes32) {
return
computeVestingScheduleIdForAddress(
holder
);
}
/**
* @dev Computes the vesting schedule identifier for an address and an index.
*/
function computeVestingScheduleIdForAddress(
address holder
) public pure returns (bytes32) {
return keccak256(abi.encodePacked(holder));
}
/**
* @dev Computes the releasable amount of tokens for a vesting schedule.
* @return the amount of releasable tokens
*/
function _computeReleasableAmount(
VestingSchedule memory vestingSchedule
) internal view returns (uint256) {
// Retrieve the current time.
uint256 currentTime = getCurrentTime();
// If the current time is before the cliff, no tokens are releasable.
if ((currentTime < vestingSchedule.cliff) || vestingSchedule.revoked) {
return 0;
}
// If the current time is after the vesting period, all tokens are releasable,
// minus the amount already released.
else if (
currentTime >= vestingSchedule.cliff + vestingSchedule.duration
) {
return vestingSchedule.amountTotal - vestingSchedule.released;
}
// Otherwise, some tokens are releasable.
else {
// Compute the number of full vesting periods that have elapsed.
uint256 timeFromStart = currentTime - vestingSchedule.cliff;
uint256 secondsPerSlice = vestingSchedule.slicePeriodSeconds;
uint256 vestedSlicePeriods = timeFromStart / secondsPerSlice;
uint256 vestedSeconds = vestedSlicePeriods * secondsPerSlice;
// Compute the amount of tokens that are vested.
uint256 vestedAmount = (vestingSchedule.amountTotal *
vestedSeconds) / vestingSchedule.duration;
// Subtract the amount already released and return.
return vestedAmount - vestingSchedule.released;
}
}
/**
* @dev Returns the current time.
* @return the current timestamp in seconds.
*/
function getCurrentTime() internal view virtual returns (uint256) {
return block.timestamp;
}
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @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://consensys.net/diligence/blog/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.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @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 or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* 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.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @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`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// 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
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @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;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../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.
*
* The initial owner is set to the address provided by the deployer. 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;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling 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 {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_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 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @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);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` 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 value) external returns (bool);
}
ReentrancyGuard.sol 84 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
SafeERC20.sol 118 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../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;
/**
* @dev An operation with an ERC20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @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);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @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).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// 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 cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
Read Contract
CLIFF 0xb87592f2 → uint256
DURATION 0x1be05289 → uint256
SLICE_PERIOD 0x6a3dfb63 → uint256
START 0xba9a061a → uint256
computeNextVestingScheduleIdForHolder 0xf7c469f0 → bytes32
computeReleasableAmount 0xea1bb3d5 → uint256
computeVestingScheduleIdForAddress 0xc1f60606 → bytes32
getToken 0x21df0da7 → address
getVestingIdAtIndex 0xf9079b37 → bytes32
getVestingSchedule 0x9ef346b4 → tuple
getVestingScheduleByAddress 0x3bedde7d → tuple
getVestingSchedulesCount 0x13083617 → uint256
getVestingSchedulesTotalAmount 0x48deb471 → uint256
getWithdrawableAmount 0x90be10cc → uint256
owner 0x8da5cb5b → address
seller 0x08551a53 → address
Write Contract 7 functions
These functions modify contract state and require a wallet transaction to execute.
createVestingSchedule 0x8c5233ab
address _beneficiary
uint256 _amount
bool _revocable
release 0x66afd8ef
bytes32 vestingScheduleId
uint256 amount
renounceOwnership 0x715018a6
No parameters
revoke 0xb75c7dc6
bytes32 vestingScheduleId
setSeller 0xe99d2866
address _seller
transferOwnership 0xf2fde38b
address newOwner
withdraw 0x2e1a7d4d
uint256 amount
Recent Transactions
No transactions found for this address