Address Contract Partially Verified
Address
0x89131C4b35533D277F7D4eEBE6f99a9298f548E4
Balance
0 ETH
Nonce
1
Code Size
5399 bytes
Creator
0xb8143bB7...b98e at tx 0x8d47bef1...85d5d3
Indexed Transactions
0
Contract Bytecode
5399 bytes
0x6080604052600436106101015760003560e01c80638da5cb5b1161008f578063ea1bb3d511610061578063ea1bb3d5146102e2578063f2fde38b14610302578063f51321d714610322578063f7c469f014610342578063f9079b371461036257005b80638da5cb5b1461026d57806390be10cc1461028d5780639ef346b4146102a2578063b75c7dc6146102c257005b806348deb471116100d357806348deb471146101b55780635a7bb69a146101ca57806366afd8ef146102005780637e913dc6146102205780638af104da1461024d57005b8063130836171461010a57806317e289e91461012e57806321df0da71461014e5780632e1a7d4d1461019557005b3661010857005b005b34801561011657600080fd5b506002545b6040519081526020015b60405180910390f35b34801561013a57600080fd5b506101086101493660046112a0565b610382565b34801561015a57600080fd5b507f000000000000000000000000b435a47ecea7f5366b2520e45b9bed7e01d2ffae5b6040516001600160a01b039091168152602001610125565b3480156101a157600080fd5b506101086101b036600461130c565b6106df565b3480156101c157600080fd5b5060045461011b565b3480156101d657600080fd5b5061011b6101e5366004611325565b6001600160a01b031660009081526005602052604090205490565b34801561020c57600080fd5b5061010861021b366004611340565b6107ea565b34801561022c57600080fd5b5061024061023b366004611325565b610a97565b6040516101259190611362565b34801561025957600080fd5b5061011b6102683660046113ed565b610b6f565b34801561027957600080fd5b5060005461017d906001600160a01b031681565b34801561029957600080fd5b5061011b610bb7565b3480156102ae57600080fd5b506102406102bd36600461130c565b610c57565b3480156102ce57600080fd5b506101086102dd36600461130c565b610cfe565b3480156102ee57600080fd5b5061011b6102fd36600461130c565b610eb6565b34801561030e57600080fd5b5061010861031d366004611325565b610f9b565b34801561032e57600080fd5b5061024061033d3660046113ed565b611010565b34801561034e57600080fd5b5061011b61035d366004611325565b61102c565b34801561036e57600080fd5b5061011b61037d36600461130c565b611050565b6000546001600160a01b031633146103b55760405162461bcd60e51b81526004016103ac90611417565b60405180910390fd5b806103be610bb7565b10156104455760405162461bcd60e51b815260206004820152604a60248201527f546f6b656e56657374696e673a2063616e6e6f7420637265617465207665737460448201527f696e67207363686564756c652062656361757365206e6f742073756666696369606482015269656e7420746f6b656e7360b01b608482015260a4016103ac565b600081116104955760405162461bcd60e51b815260206004820181905260248201527f546f6b656e56657374696e673a20616d6f756e74206d757374206265203e203060448201526064016103ac565b60018310156104fc5760405162461bcd60e51b815260206004820152602d60248201527f546f6b656e56657374696e673a20736c696365506572696f645365636f6e647360448201526c206d757374206265203e3d203160981b60648201526084016103ac565b60006105078861102c565b905060006105158789611453565b90506040518061014001604052806001151581526020018a6001600160a01b03168152602001828152602001898152602001878152602001868152602001851515815260200184815260200160008152602001600015158152506003600084815260200190815260200160002060008201518160000160006101000a81548160ff02191690831515021790555060208201518160000160016101000a8154816001600160a01b0302191690836001600160a01b0316021790555060408201518160010155606082015181600201556080820151816003015560a0820151816004015560c08201518160050160006101000a81548160ff02191690831515021790555060e0820151816006015561010082015181600701556101208201518160080160006101000a81548160ff0219169083151502179055509050508260045461065e9190611453565b6004556002805460018181019092557f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace018390556001600160a01b038a16600090815260056020526040902054906106b7908290611453565b6001600160a01b03909a16600090815260056020526040902099909955505050505050505050565b60015460011461071e5760405162461bcd60e51b815260206004820152600a6024820152695245454e5452414e435960b01b60448201526064016103ac565b60026001556000546001600160a01b0316331461074d5760405162461bcd60e51b81526004016103ac90611417565b80610756610bb7565b10156107b85760405162461bcd60e51b815260206004820152602b60248201527f546f6b656e56657374696e673a206e6f7420656e6f756768207769746864726160448201526a7761626c652066756e647360a81b60648201526084016103ac565b6107e37f000000000000000000000000b435a47ecea7f5366b2520e45b9bed7e01d2ffae33836110d8565b5060018055565b6001546001146108295760405162461bcd60e51b815260206004820152600a6024820152695245454e5452414e435960b01b60448201526064016103ac565b6002600155600082815260036020526040902054829060ff1661084b57600080fd5b60008181526003602052604090206008015460ff161561086a57600080fd5b6000838152600360205260408120805491549091336001600160a01b03610100909204821681149290911614818061089f5750805b61091c5760405162461bcd60e51b815260206004820152604260248201527f546f6b656e56657374696e673a206f6e6c792062656e6566696369617279206160448201527f6e64206f776e65722063616e2072656c656173652076657374656420746f6b656064820152616e7360f01b608482015260a4016103ac565b6040805161014081018252845460ff808216151583526001600160a01b03610100928390041660208401526001870154938301939093526002860154606083015260038601546080830152600486015460a083015260058601548316151560c0830152600686015460e0830152600786015490820152600885015490911615156101208201526000906109ae90611156565b905085811015610a265760405162461bcd60e51b815260206004820152603d60248201527f546f6b656e56657374696e673a2063616e6e6f742072656c6561736520746f6b60448201527f656e732c206e6f7420656e6f7567682076657374656420746f6b656e7300000060648201526084016103ac565b858460070154610a369190611453565b600785015583546004546101009091046001600160a01b031690610a5b908890611466565b600455610a897f000000000000000000000000b435a47ecea7f5366b2520e45b9bed7e01d2ffae82896110d8565b505060018055505050505050565b610a9f611222565b6001600160a01b03821660009081526005602052604081205460039190610ace90859061026890600190611466565b81526020808201929092526040908101600020815161014081018352815460ff808216151583526001600160a01b036101009283900416958301959095526001830154938201939093526002820154606082015260038201546080820152600482015460a082015260058201548416151560c0820152600682015460e082015260078201549281019290925260080154909116151561012082015292915050565b6040516bffffffffffffffffffffffff19606084901b166020820152603481018290526000906054016040516020818303038152906040528051906020012090505b92915050565b600480546040516370a0823160e01b815230928101929092526000917f000000000000000000000000b435a47ecea7f5366b2520e45b9bed7e01d2ffae6001600160a01b0316906370a0823190602401602060405180830381865afa158015610c24573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c489190611479565b610c529190611466565b905090565b610c5f611222565b50600090815260036020818152604092839020835161014081018552815460ff808216151583526001600160a01b0361010092839004169483019490945260018301549582019590955260028201546060820152928101546080840152600481015460a084015260058101548216151560c0840152600681015460e0840152600781015493830193909352600890920154909116151561012082015290565b6000546001600160a01b03163314610d285760405162461bcd60e51b81526004016103ac90611417565b600081815260036020526040902054819060ff16610d4557600080fd5b60008181526003602052604090206008015460ff1615610d6457600080fd5b6000828152600360205260409020600581015460ff16610dd55760405162461bcd60e51b815260206004820152602660248201527f546f6b656e56657374696e673a2076657374696e67206973206e6f74207265766044820152656f6361626c6560d01b60648201526084016103ac565b6040805161014081018252825460ff808216151583526001600160a01b03610100928390041660208401526001850154938301939093526002840154606083015260038401546080830152600484015460a083015260058401548316151560c0830152600684015460e083015260078401549082015260088301549091161515610120820152600090610e6790611156565b90508015610e7957610e7984826107ea565b600082600701548360060154610e8f9190611466565b905080600454610e9f9190611466565b6004555050600801805460ff191660011790555050565b600081815260036020526040812054829060ff16610ed357600080fd5b60008181526003602052604090206008015460ff1615610ef257600080fd5b600083815260036020818152604092839020835161014081018552815460ff808216151583526001600160a01b0361010092839004169483019490945260018301549582019590955260028201546060820152928101546080840152600481015460a084015260058101548216151560c0840152600681015460e08401526007810154938301939093526008830154161515610120820152610f9390611156565b949350505050565b6000546001600160a01b03163314610fc55760405162461bcd60e51b81526004016103ac90611417565b600080546001600160a01b0319166001600160a01b0383169081178255604051909133917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a350565b611018611222565b6110256102bd8484610b6f565b9392505050565b6001600160a01b038116600090815260056020526040812054610bb1908390610b6f565b600061105b60025490565b82106110b35760405162461bcd60e51b815260206004820152602160248201527f546f6b656e56657374696e673a20696e646578206f7574206f6620626f756e646044820152607360f81b60648201526084016103ac565b600282815481106110c6576110c6611492565b90600052602060002001549050919050565b600060405163a9059cbb60e01b8152836004820152826024820152602060006044836000895af13d15601f3d11600160005114161716915050806111505760405162461bcd60e51b815260206004820152600f60248201526e1514905394d1915497d19052531151608a1b60448201526064016103ac565b50505050565b6040810151600090429081108061116f57508261012001515b1561117d5750600092915050565b826080015183604001516111919190611453565b81106111ac578261010001518360e001516110259190611466565b60008360400151826111be9190611466565b60a085015190915060006111d282846114a8565b905060006111e083836114ca565b905060008760800151828960e001516111f991906114ca565b61120391906114a8565b9050876101000151816112169190611466565b98975050505050505050565b60405180610140016040528060001515815260200160006001600160a01b031681526020016000815260200160008152602001600081526020016000815260200160001515815260200160008152602001600081526020016000151581525090565b80356001600160a01b038116811461129b57600080fd5b919050565b600080600080600080600060e0888a0312156112bb57600080fd5b6112c488611284565b96506020880135955060408801359450606088013593506080880135925060a088013580151581146112f557600080fd5b8092505060c0880135905092959891949750929550565b60006020828403121561131e57600080fd5b5035919050565b60006020828403121561133757600080fd5b61102582611284565b6000806040838503121561135357600080fd5b50508035926020909101359150565b8151151581526101408101602083015161138760208401826001600160a01b03169052565b5060408301516040830152606083015160608301526080830151608083015260a083015160a083015260c08301516113c360c084018215159052565b5060e083810151908301526101008084015190830152610120928301511515929091019190915290565b6000806040838503121561140057600080fd5b61140983611284565b946020939093013593505050565b6020808252600c908201526b15539055551213d49256915160a21b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b80820180821115610bb157610bb161143d565b81810381811115610bb157610bb161143d565b60006020828403121561148b57600080fd5b5051919050565b634e487b7160e01b600052603260045260246000fd5b6000826114c557634e487b7160e01b600052601260045260246000fd5b500490565b8082028115828204841417610bb157610bb161143d56fea26469706673582212207eb9bcf26374d984282241a3261601fea8e49593232d42a4c10aba172978e1a064736f6c63430008130033
Verified Source Code Partial Match
Compiler: v0.8.19+commit.7dd6d404
EVM: paris
Optimization: Yes (200 runs)
TokenVesting.sol 375 lines
// contracts/TokenVesting.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.19;
// OpenZeppelin dependencies
import {ERC20} from "lib/solmate/src/tokens/ERC20.sol";
import {Owned} from "lib/solmate/src/auth/Owned.sol";
import {SafeTransferLib} from "lib/solmate/src/utils/SafeTransferLib.sol";
import {ReentrancyGuard} from "lib/solmate/src/utils/ReentrancyGuard.sol";
/**
* @title TokenVesting
*/
contract TokenVesting is Owned, ReentrancyGuard {
struct VestingSchedule {
bool initialized;
// beneficiary of tokens after they are released
address beneficiary;
// cliff period in seconds
uint256 cliff;
// start time of the vesting period
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;
}
// address of the ERC20 token
ERC20 private immutable _token;
bytes32[] private vestingSchedulesIds;
mapping(bytes32 => VestingSchedule) private vestingSchedules;
uint256 private vestingSchedulesTotalAmount;
mapping(address => uint256) private holdersVestingCount;
/**
* @dev Reverts if the vesting schedule does not exist or has been revoked.
*/
modifier onlyIfVestingScheduleNotRevoked(bytes32 vestingScheduleId) {
require(vestingSchedules[vestingScheduleId].initialized);
require(!vestingSchedules[vestingScheduleId].revoked);
_;
}
/**
* @dev Creates a vesting contract.
* @param token_ address of the ERC20 token contract
*/
constructor(address token_) Owned(msg.sender) {
// Check that the token address is not 0x0.
require(token_ != address(0x0));
// Set the token address.
_token = ERC20(token_);
}
/**
* @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 {}
/**
* @notice Creates a new vesting schedule for a beneficiary.
* @param _beneficiary address of the beneficiary to whom vested tokens are transferred
* @param _start start time of the vesting period
* @param _cliff duration in seconds of the cliff in which tokens will begin to vest
* @param _duration duration in seconds of the period in which the tokens will vest
* @param _slicePeriodSeconds duration of a slice period for the vesting in seconds
* @param _revocable whether the vesting is revocable or not
* @param _amount total amount of tokens to be released at the end of the vesting
*/
function createVestingSchedule(
address _beneficiary,
uint256 _start,
uint256 _cliff,
uint256 _duration,
uint256 _slicePeriodSeconds,
bool _revocable,
uint256 _amount
) external onlyOwner {
require(
getWithdrawableAmount() >= _amount,
"TokenVesting: cannot create vesting schedule because not sufficient tokens"
);
require(_duration >= 0, "TokenVesting: duration must be >= 0"); //redundant
require(_amount > 0, "TokenVesting: amount must be > 0");
require(
_slicePeriodSeconds >= 1,
"TokenVesting: slicePeriodSeconds must be >= 1"
);
bytes32 vestingScheduleId = computeNextVestingScheduleIdForHolder(
_beneficiary
);
uint256 cliff = _start + _cliff;
vestingSchedules[vestingScheduleId] = VestingSchedule(
true,
_beneficiary,
cliff,
_start,
_duration,
_slicePeriodSeconds,
_revocable,
_amount,
0,
false
);
vestingSchedulesTotalAmount = vestingSchedulesTotalAmount + _amount;
vestingSchedulesIds.push(vestingScheduleId);
uint256 currentVestingCount = holdersVestingCount[_beneficiary];
holdersVestingCount[_beneficiary] = currentVestingCount + 1;
}
/**
* @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
*/
SafeTransferLib.safeTransfer(_token, 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;
SafeTransferLib.safeTransfer(_token, beneficiaryPayable, amount);
}
/**
* @dev Returns the number of vesting schedules associated to a beneficiary.
* @return the number of vesting schedules
*/
function getVestingSchedulesCountByBeneficiary(
address _beneficiary
) external view returns (uint256) {
return holdersVestingCount[_beneficiary];
}
/**
* @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 and index.
* @return the vesting schedule structure information
*/
function getVestingScheduleByAddressAndIndex(
address holder,
uint256 index
) external view returns (VestingSchedule memory) {
return
getVestingSchedule(
computeVestingScheduleIdForAddressAndIndex(holder, index)
);
}
/**
* @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 view returns (bytes32) {
return
computeVestingScheduleIdForAddressAndIndex(
holder,
holdersVestingCount[holder]
);
}
/**
* @dev Returns the last vesting schedule for a given holder address.
*/
function getLastVestingScheduleForHolder(
address holder
) external view returns (VestingSchedule memory) {
return
vestingSchedules[
computeVestingScheduleIdForAddressAndIndex(
holder,
holdersVestingCount[holder] - 1
)
];
}
/**
* @dev Computes the vesting schedule identifier for an address and an index.
*/
function computeVestingScheduleIdForAddressAndIndex(
address holder,
uint256 index
) public pure returns (bytes32) {
return keccak256(abi.encodePacked(holder, index));
}
/**
* @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;
}
}
Owned.sol 44 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Simple single owner authorization mixin.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Owned.sol)
abstract contract Owned {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event OwnershipTransferred(address indexed user, address indexed newOwner);
/*//////////////////////////////////////////////////////////////
OWNERSHIP STORAGE
//////////////////////////////////////////////////////////////*/
address public owner;
modifier onlyOwner() virtual {
require(msg.sender == owner, "UNAUTHORIZED");
_;
}
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(address _owner) {
owner = _owner;
emit OwnershipTransferred(address(0), _owner);
}
/*//////////////////////////////////////////////////////////////
OWNERSHIP LOGIC
//////////////////////////////////////////////////////////////*/
function transferOwnership(address newOwner) public virtual onlyOwner {
owner = newOwner;
emit OwnershipTransferred(msg.sender, newOwner);
}
}
ERC20.sol 206 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
/*//////////////////////////////////////////////////////////////
METADATA STORAGE
//////////////////////////////////////////////////////////////*/
string public name;
string public symbol;
uint8 public immutable decimals;
/*//////////////////////////////////////////////////////////////
ERC20 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
/*//////////////////////////////////////////////////////////////
EIP-2612 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 internal immutable INITIAL_CHAIN_ID;
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
mapping(address => uint256) public nonces;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
INITIAL_CHAIN_ID = block.chainid;
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
}
/*//////////////////////////////////////////////////////////////
ERC20 LOGIC
//////////////////////////////////////////////////////////////*/
function approve(address spender, uint256 amount) public virtual returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transfer(address to, uint256 amount) public virtual returns (bool) {
balanceOf[msg.sender] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual returns (bool) {
uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.
if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
balanceOf[from] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
/*//////////////////////////////////////////////////////////////
EIP-2612 LOGIC
//////////////////////////////////////////////////////////////*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");
// Unchecked because the only math done is incrementing
// the owner's nonce which cannot realistically overflow.
unchecked {
address recoveredAddress = ecrecover(
keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
),
owner,
spender,
value,
nonces[owner]++,
deadline
)
)
)
),
v,
r,
s
);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");
allowance[recoveredAddress][spender] = value;
}
emit Approval(owner, spender, value);
}
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
}
function computeDomainSeparator() internal view virtual returns (bytes32) {
return
keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}
/*//////////////////////////////////////////////////////////////
INTERNAL MINT/BURN LOGIC
//////////////////////////////////////////////////////////////*/
function _mint(address to, uint256 amount) internal virtual {
totalSupply += amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(address(0), to, amount);
}
function _burn(address from, uint256 amount) internal virtual {
balanceOf[from] -= amount;
// Cannot underflow because a user's balance
// will never be larger than the total supply.
unchecked {
totalSupply -= amount;
}
emit Transfer(from, address(0), amount);
}
}
ReentrancyGuard.sol 19 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Gas optimized reentrancy protection for smart contracts.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/ReentrancyGuard.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/ReentrancyGuard.sol)
abstract contract ReentrancyGuard {
uint256 private locked = 1;
modifier nonReentrant() virtual {
require(locked == 1, "REENTRANCY");
locked = 2;
_;
locked = 1;
}
}
SafeTransferLib.sol 128 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
import {ERC20} from "../tokens/ERC20.sol";
/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
/// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.
library SafeTransferLib {
/*//////////////////////////////////////////////////////////////
ETH OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferETH(address to, uint256 amount) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Transfer the ETH and store if it succeeded or not.
success := call(gas(), to, amount, 0, 0, 0, 0)
}
require(success, "ETH_TRANSFER_FAILED");
}
/*//////////////////////////////////////////////////////////////
ERC20 OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferFrom(
ERC20 token,
address from,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), from) // Append the "from" argument.
mstore(add(freeMemoryPointer, 36), to) // Append the "to" argument.
mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)
)
}
require(success, "TRANSFER_FROM_FAILED");
}
function safeTransfer(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "TRANSFER_FAILED");
}
function safeApprove(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "APPROVE_FAILED");
}
}
Token.sol 15 lines
// contracts/Token.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.19;
import {ERC20} from "lib/solmate/src/tokens/ERC20.sol";
contract Token is ERC20 {
constructor(
string memory name,
string memory symbol,
uint256 initialSupply
) ERC20(name, symbol, 18) {
_mint(msg.sender, initialSupply);
}
}
MockTokenVesting.sol 23 lines
// contracts/TokenVesting.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.19;
import "./TokenVesting.sol";
/**
* @title MockTokenVesting
* WARNING: use only for testing and debugging purpose
*/
contract MockTokenVesting is TokenVesting {
uint256 mockTime = 0;
constructor(address token_) TokenVesting(token_) {}
function setCurrentTime(uint256 _time) external {
mockTime = _time;
}
function getCurrentTime() internal view virtual override returns (uint256) {
return mockTime;
}
}
Read Contract
computeNextVestingScheduleIdForHolder 0xf7c469f0 → bytes32
computeReleasableAmount 0xea1bb3d5 → uint256
computeVestingScheduleIdForAddressAndIndex 0x8af104da → bytes32
getLastVestingScheduleForHolder 0x7e913dc6 → tuple
getToken 0x21df0da7 → address
getVestingIdAtIndex 0xf9079b37 → bytes32
getVestingSchedule 0x9ef346b4 → tuple
getVestingScheduleByAddressAndIndex 0xf51321d7 → tuple
getVestingSchedulesCount 0x13083617 → uint256
getVestingSchedulesCountByBeneficiary 0x5a7bb69a → uint256
getVestingSchedulesTotalAmount 0x48deb471 → uint256
getWithdrawableAmount 0x90be10cc → uint256
owner 0x8da5cb5b → address
Write Contract 5 functions
These functions modify contract state and require a wallet transaction to execute.
createVestingSchedule 0x17e289e9
address _beneficiary
uint256 _start
uint256 _cliff
uint256 _duration
uint256 _slicePeriodSeconds
bool _revocable
uint256 _amount
release 0x66afd8ef
bytes32 vestingScheduleId
uint256 amount
revoke 0xb75c7dc6
bytes32 vestingScheduleId
transferOwnership 0xf2fde38b
address newOwner
withdraw 0x2e1a7d4d
uint256 amount
Recent Transactions
No transactions found for this address