Address Contract Verified
Address
0x496cd2FD1a59Eb7325925067b49f2244e7c26A1b
Balance
0 ETH
Nonce
1
Code Size
7646 bytes
Creator
0x5B5d43Fc...ac79 at tx 0x8ea41e71...503d54
Indexed Transactions
0
Contract Bytecode
7646 bytes
0x60806040526004361061019c575f3560e01c806397bc1e1b116100dc578063bf7e214f11610087578063efbe1c1c11610062578063efbe1c1c146104d7578063f2fde38b146104eb578063f322957014610508578063fbccedae14610527575f80fd5b8063bf7e214f14610479578063c4f15e3b14610495578063c7de66e5146104b8575f80fd5b8063ad3cb1cc116100b7578063ad3cb1cc146103cf578063bcbe03df14610424578063be9a655514610443575f80fd5b806397bc1e1b146103425780639852595c1461037c578063a3f8eace146103b0575f80fd5b806352d1902d11610147578063810ec23b11610122578063810ec23b146102bf57806386d1a69f146102de5780638da5cb5b146102f2578063961325211461032e575f80fd5b806352d1902d14610281578063611fa67614610295578063715018a6146102b4575f80fd5b806338812e581161017757806338812e581461021857806338af3eed146102375780634f1ef2861461026e575f80fd5b80630a17b06b146101a75780630fb5a6b4146101d957806319165587146101f7575f80fd5b366101a357005b5f80fd5b3480156101b2575f80fd5b506101c66101c1366004611a8c565b61053b565b6040519081526020015b60405180910390f35b3480156101e4575f80fd5b5060015467ffffffffffffffff166101c6565b348015610202575f80fd5b50610216610211366004611abb565b61054b565b005b348015610223575f80fd5b50610216610232366004611a8c565b6105e0565b348015610242575f80fd5b50600454610256906001600160a01b031681565b6040516001600160a01b0390911681526020016101d0565b61021661027c366004611b01565b6106d8565b34801561028c575f80fd5b506101c66106f3565b3480156102a0575f80fd5b506102166102af366004611abb565b610721565b348015610216575f80fd5b3480156102ca575f80fd5b506101c66102d9366004611bdb565b61084b565b3480156102e9575f80fd5b5061021661085d565b3480156102fd575f80fd5b507f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300546001600160a01b0316610256565b348015610339575f80fd5b506002546101c6565b34801561034d575f80fd5b505f5474010000000000000000000000000000000000000000900460ff165b60405190151581526020016101d0565b348015610387575f80fd5b506101c6610396366004611abb565b6001600160a01b03165f9081526003602052604090205490565b3480156103bb575f80fd5b506101c66103ca366004611abb565b6108c7565b3480156103da575f80fd5b506104176040518060400160405280600581526020017f352e302e3000000000000000000000000000000000000000000000000000000081525081565b6040516101d09190611c0c565b34801561042f575f80fd5b5061021661043e366004611c5f565b6108d1565b34801561044e575f80fd5b505f547501000000000000000000000000000000000000000000900467ffffffffffffffff166101c6565b348015610484575f80fd5b505f546001600160a01b0316610256565b3480156104a0575f80fd5b5060015468010000000000000000900460ff1661036c565b3480156104c3575f80fd5b50600554610256906001600160a01b031681565b3480156104e2575f80fd5b506101c6610b5e565b3480156104f6575f80fd5b50610216610505366004611abb565b50565b348015610513575f80fd5b50610216610522366004611abb565b610be9565b348015610532575f80fd5b506101c6610d07565b5f61054582610d10565b92915050565b5f610555826108c7565b6001600160a01b0383165f90815260036020526040812080549293508392909190610581908490611ccc565b90915550506040518181526001600160a01b038316907fc0e523490dd523c33b1878c9eb14ff46991e3f5b2cd33710918618f2a39cba1b9060200160405180910390a26004546105dc9083906001600160a01b031683610d2d565b5050565b61060d335f357fffffffff0000000000000000000000000000000000000000000000000000000016610db2565b610643576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60015468010000000000000000900460ff161561068c576040517f436c986a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8067ffffffffffffffff165f036106cf576040517fb290253c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61050581610e7f565b6106e0610f34565b6106e982611004565b6105dc8282611067565b5f6106fc61118b565b507f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc90565b6107296111ed565b6005546001600160a01b03828116911614610770576040517f8da11b8c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6005546001600160a01b03166107b2576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6004546001600160a01b03166107c782611261565b600480546001600160a01b038481167fffffffffffffffffffffffff000000000000000000000000000000000000000092831681179093556005805490921690915560408051918416825260208201929092527fb2dd754949b6948c51a4e91fc033d29282507537f289bc1b091150aac0e4bf6b910160405180910390a15050565b565b5f61085683836112e9565b9392505050565b5f610866610d07565b90508060025f8282546108799190611ccc565b90915550506040518181527fae34c4c83f51b75c0b34a10cfbf2eaffb275323f90bf57c5196c95ab8a1187a39060200160405180910390a1600454610505906001600160a01b03168261138e565b5f6105458261145a565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000810460ff16159067ffffffffffffffff165f8115801561091b5750825b90505f8267ffffffffffffffff1660011480156109375750303b155b905081158015610945575080155b1561097c576040517ff92ee8a900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b84547fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000016600117855583156109dd5784547fffffffffffffffffffffffffffffffffffffffffffffff00ffffffffffffffff16680100000000000000001785555b6109e5611486565b6109ee8861148e565b6109f78661149f565b622819a08767ffffffffffffffff161015610a3e576040517f25c3636700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610a55622819a067ffffffffffffffff8916611d0c565b15610a8c576040517f7616640100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600180547fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000001667ffffffffffffffff8916179055600480547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b038a161790558315610b545784547fffffffffffffffffffffffffffffffffffffffffffffff00ffffffffffffffff168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b5050505050505050565b6001545f9068010000000000000000900460ff16610ba8576040517f376aab0100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60015467ffffffffffffffff165f547501000000000000000000000000000000000000000000900467ffffffffffffffff16610be49190611ccc565b905090565b610c16335f357fffffffff0000000000000000000000000000000000000000000000000000000016610db2565b610c4c576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038116610c8c576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600580547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b038381169182179092556004546040805191909316815260208101919091527f63107f679aff067027746e26eb27d706c6d7989c3c10a4b20676be14087a79a591015b60405180910390a150565b5f610be46115ac565b5f610545610d1d60025490565b610d279047611ccc565b836115c9565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052610dad9084906116ce565b505050565b5f80546001600160a01b03168015801590610e7757506040517fb70096130000000000000000000000000000000000000000000000000000000081526001600160a01b0385811660048301523060248301527fffffffff000000000000000000000000000000000000000000000000000000008516604483015282169063b700961390606401602060405180830381865afa158015610e53573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e779190611d1f565b949350505050565b5f805467ffffffffffffffff8316750100000000000000000000000000000000000000000081027fffffff0000000000000000ffffffffffffffffffffffffffffffffffffffffff90921691909117909155600180547fffffffffffffffffffffffffffffffffffffffffffffff00ffffffffffffffff16680100000000000000001790556040519081527fe3c351d7cac4a6b839aea469ce332625d837928d68de4f30e6d65584f3363fb190602001610cfc565b306001600160a01b037f000000000000000000000000496cd2fd1a59eb7325925067b49f2244e7c26a1b161480610fcd57507f000000000000000000000000496cd2fd1a59eb7325925067b49f2244e7c26a1b6001600160a01b0316610fc17f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b6001600160a01b031614155b15610849576040517fe07c8dba00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611031335f357fffffffff0000000000000000000000000000000000000000000000000000000016610db2565b610505576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156110df575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682019092526110dc91810190611d3e565b60015b611125576040517f4c9c8ce30000000000000000000000000000000000000000000000000000000081526001600160a01b03831660048201526024015b60405180910390fd5b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8114611181576040517faa1d49a40000000000000000000000000000000000000000000000000000000081526004810182905260240161111c565b610dad8383611759565b306001600160a01b037f000000000000000000000000496cd2fd1a59eb7325925067b49f2244e7c26a1b1614610849576040517fe07c8dba00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b3361121f7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300546001600160a01b031690565b6001600160a01b031614610849576040517f118cdaa700000000000000000000000000000000000000000000000000000000815233600482015260240161111c565b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930080547fffffffffffffffffffffffff000000000000000000000000000000000000000081166001600160a01b03848116918217845560405192169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a3505050565b6001600160a01b0382165f90815260036020526040812054610856906040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038616906370a0823190602401602060405180830381865afa158015611360573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113849190611d3e565b610d279190611ccc565b804710156113d1576040517fcf4791810000000000000000000000000000000000000000000000000000000081524760048201526024810182905260440161111c565b5f826001600160a01b0316826040515f6040518083038185875af1925050503d805f811461141a576040519150601f19603f3d011682016040523d82523d5f602084013e61141f565b606091505b5050905080610dad576040517fd6bda27500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b0381165f9081526003602052604081205461147c83426112e9565b6105459190611d55565b6108496117ae565b6114966117ae565b61050581611815565b6001600160a01b0381166114df576040517fbafc8d9800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f5474010000000000000000000000000000000000000000900460ff1615611533576040517fb5e03caf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f80547fffffffffffffffffffffff000000000000000000000000000000000000000000166001600160a01b03831690811774010000000000000000000000000000000000000000178255604051909130917f527a9fd75bf1f15c7a46f5f0c60885544e77fa6d74e1097a29dbccf268e475899190a350565b5f6115b660025490565b6115bf42610d10565b610be49190611d55565b6001545f9068010000000000000000900460ff16158061161657505f547501000000000000000000000000000000000000000000900467ffffffffffffffff168267ffffffffffffffff16105b1561162257505f610545565b61162a610b5e565b8267ffffffffffffffff1610611641575081610545565b5f8054622819a0907501000000000000000000000000000000000000000000900467ffffffffffffffff166116809067ffffffffffffffff8616611d55565b61168a9190611d68565b90505f622819a06116a460015467ffffffffffffffff1690565b6116ae9190611d68565b9050806116bb8387611d7b565b6116c59190611d68565b92505050610545565b5f8060205f8451602086015f885af1806116ed576040513d5f823e3d81fd5b50505f513d91508115611704578060011415611711565b6001600160a01b0384163b155b15611753576040517f5274afe70000000000000000000000000000000000000000000000000000000081526001600160a01b038516600482015260240161111c565b50505050565b61176282611868565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a28051156117a657610dad828261190f565b6105dc611981565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005468010000000000000000900460ff16610849576040517fd7e6bcf800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61181d6117ae565b6001600160a01b03811661185f576040517f1e4fbdf70000000000000000000000000000000000000000000000000000000081525f600482015260240161111c565b61050581611261565b806001600160a01b03163b5f036118b6576040517f4c9c8ce30000000000000000000000000000000000000000000000000000000081526001600160a01b038216600482015260240161111c565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0392909216919091179055565b60605f80846001600160a01b03168460405161192b9190611d92565b5f60405180830381855af49150503d805f8114611963576040519150601f19603f3d011682016040523d82523d5f602084013e611968565b606091505b50915091506119788583836119b9565b95945050505050565b3415610849576040517fb398979f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6060826119ce576119c982611a2e565b610856565b81511580156119e557506001600160a01b0384163b155b15611a27576040517f9996b3150000000000000000000000000000000000000000000000000000000081526001600160a01b038516600482015260240161111c565b5092915050565b805115611a3e5780518082602001fd5b6040517fd6bda27500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b803567ffffffffffffffff81168114611a87575f80fd5b919050565b5f60208284031215611a9c575f80fd5b61085682611a70565b80356001600160a01b0381168114611a87575f80fd5b5f60208284031215611acb575f80fd5b61085682611aa5565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f8060408385031215611b12575f80fd5b611b1b83611aa5565b9150602083013567ffffffffffffffff80821115611b37575f80fd5b818501915085601f830112611b4a575f80fd5b813581811115611b5c57611b5c611ad4565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908382118183101715611ba257611ba2611ad4565b81604052828152886020848701011115611bba575f80fd5b826020860160208301375f6020848301015280955050505050509250929050565b5f8060408385031215611bec575f80fd5b611bf583611aa5565b9150611c0360208401611a70565b90509250929050565b602081525f82518060208401528060208501604085015e5f6040828501015260407fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f83011684010191505092915050565b5f805f60608486031215611c71575f80fd5b611c7a84611aa5565b9250611c8860208501611a70565b9150611c9660408501611aa5565b90509250925092565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b8082018082111561054557610545611c9f565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f82611d1a57611d1a611cdf565b500690565b5f60208284031215611d2f575f80fd5b81518015158114610856575f80fd5b5f60208284031215611d4e575f80fd5b5051919050565b8181038181111561054557610545611c9f565b5f82611d7657611d76611cdf565b500490565b808202811582820484141761054557610545611c9f565b5f82518060208501845e5f92019182525091905056fea2646970667358221220b524f718e5874c6e60b00464b4493688e63cc997491258010bcab7fe2cc85e3164736f6c63430008190033
Verified Source Code Full Match
Compiler: v0.8.25+commit.b61c2a91
EVM: cancun
Optimization: Yes (10000 runs)
VestingWallet.sol 265 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
/*
Built with ♥ by
░██╗░░░░░░░██╗░█████╗░███╗░░██╗██████╗░███████╗██████╗░██╗░░░░░░█████╗░███╗░░██╗██████╗░
░██║░░██╗░░██║██╔══██╗████╗░██║██╔══██╗██╔════╝██╔══██╗██║░░░░░██╔══██╗████╗░██║██╔══██╗
░╚██╗████╗██╔╝██║░░██║██╔██╗██║██║░░██║█████╗░░██████╔╝██║░░░░░███████║██╔██╗██║██║░░██║
░░████╔═████║░██║░░██║██║╚████║██║░░██║██╔══╝░░██╔══██╗██║░░░░░██╔══██║██║╚████║██║░░██║
░░╚██╔╝░╚██╔╝░╚█████╔╝██║░╚███║██████╔╝███████╗██║░░██║███████╗██║░░██║██║░╚███║██████╔╝
░░░╚═╝░░░╚═╝░░░╚════╝░╚═╝░░╚══╝╚═════╝░╚══════╝╚═╝░░╚═╝╚══════╝╚═╝░░╚═╝╚═╝░░╚══╝╚═════╝░
https://defi.sucks
*/
import {AuthNoOwner} from 'contracts/AuthNoOwner.sol';
import {IVestingWallet} from 'interfaces/IVestingWallet.sol';
import {OwnableUpgradeable} from 'openzeppelin-upgradeable/access/OwnableUpgradeable.sol';
import {Initializable} from 'openzeppelin-upgradeable/proxy/utils/Initializable.sol';
import {UUPSUpgradeable} from 'openzeppelin-upgradeable/proxy/utils/UUPSUpgradeable.sol';
import {IERC20} from 'openzeppelin/token/ERC20/IERC20.sol';
import {SafeERC20} from 'openzeppelin/token/ERC20/utils/SafeERC20.sol';
import {Address} from 'openzeppelin/utils/Address.sol';
contract VestingWallet is Initializable, UUPSUpgradeable, OwnableUpgradeable, AuthNoOwner, IVestingWallet {
/**
* @notice Length of a standardized month in seconds (30.4167 days)
*/
uint256 private constant SECONDS_PER_MONTH = 2_628_000;
/**
* @notice Start timestamp of the vesting.
*/
uint64 internal _start;
/**
* @notice Duration of the vesting
*/
uint64 internal _duration;
/**
* @notice Whether the start time has been set
*/
bool internal _startTimeSet;
/**
* @notice Amount of native currency released.
*/
uint256 internal _released;
/**
* @notice Amount of ERC-20 tokens released
*/
mapping(address _token => uint256 _released) internal _erc20Released;
/// @inheritdoc IVestingWallet
address public beneficiary;
/// @inheritdoc IVestingWallet
address public proposedBeneficiary;
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
/**
* @dev The contract should be able to receive Eth.
*/
receive() external payable virtual {}
/// @inheritdoc IVestingWallet
function initialize(address _beneficiary, uint64 _durationSeconds, address _authority) external initializer {
__UUPSUpgradeable_init();
__Ownable_init(_beneficiary);
_initializeAuthority(_authority);
// Ensure duration is at least one month
if (_durationSeconds < SECONDS_PER_MONTH) revert DurationTooShort();
// Ensure duration is a multiple of months
if (_durationSeconds % SECONDS_PER_MONTH != 0) revert InvalidDuration();
_duration = _durationSeconds;
beneficiary = _beneficiary;
}
/// @inheritdoc IVestingWallet
function proposeBeneficiary(address _newBeneficiary) external requiresAuth {
if (_newBeneficiary == address(0)) revert ZeroAddress();
proposedBeneficiary = _newBeneficiary;
emit BeneficiaryProposed(beneficiary, _newBeneficiary);
}
/// @inheritdoc IVestingWallet
function acceptBeneficiary(address _proposedBeneficiary) external onlyOwner {
// Check that the proposed beneficiary is the same as the one proposed, prevent front-running
if (proposedBeneficiary != _proposedBeneficiary) revert NotProposedBeneficiary();
if (proposedBeneficiary == address(0)) revert ZeroAddress();
address _oldBeneficiary = beneficiary;
_transferOwnership(_proposedBeneficiary);
beneficiary = _proposedBeneficiary;
proposedBeneficiary = address(0);
emit BeneficiaryAccepted(_oldBeneficiary, _proposedBeneficiary);
}
/// @inheritdoc IVestingWallet
function release() public virtual {
uint256 amount = releasable();
_released += amount;
emit NativeCurrencyReleased(amount);
Address.sendValue(payable(beneficiary), amount);
}
/// @inheritdoc IVestingWallet
function release(address token) public virtual {
uint256 amount = releasable(token);
_erc20Released[token] += amount;
emit ERC20Released(token, amount);
SafeERC20.safeTransfer(IERC20(token), beneficiary, amount);
}
/// @inheritdoc OwnableUpgradeable
function transferOwnership(address) public override {}
/// @inheritdoc OwnableUpgradeable
function renounceOwnership() public override {}
/// @inheritdoc IVestingWallet
function startTimeSet() public view virtual returns (bool) {
return _startTimeSet;
}
/// @inheritdoc IVestingWallet
function start() public view virtual returns (uint256) {
return _start;
}
/// @inheritdoc IVestingWallet
function duration() public view virtual returns (uint256) {
return _duration;
}
/// @inheritdoc IVestingWallet
function end() public view virtual returns (uint256) {
if (!startTimeSet()) revert StartTimeNotSet();
return start() + duration();
}
/// @inheritdoc IVestingWallet
function released() public view virtual returns (uint256) {
return _released;
}
/// @inheritdoc IVestingWallet
function released(address token) public view virtual returns (uint256) {
return _erc20Released[token];
}
/// @inheritdoc IVestingWallet
function releasable() public view virtual returns (uint256) {
return _releaseable();
}
/// @inheritdoc IVestingWallet
function releasable(address token) public view virtual returns (uint256) {
return _releaseable(token);
}
/// @inheritdoc IVestingWallet
function vestedAmount(uint64 timestamp) public view virtual returns (uint256) {
return _vestedAmount(timestamp);
}
/// @inheritdoc IVestingWallet
function vestedAmount(address token, uint64 timestamp) public view virtual returns (uint256) {
return _vestedAmount(token, timestamp);
}
/// @inheritdoc UUPSUpgradeable
function _authorizeUpgrade(address _newImplementation) internal virtual override requiresAuth {}
/**
* @notice Sets the start time for vesting. Can only be called once and before vesting begins.
* @param _startTimestamp The timestamp when vesting begins
*/
function setStartTime(uint64 _startTimestamp) external requiresAuth {
if (_startTimeSet) revert StartTimeAlreadySet();
if (_startTimestamp == 0) revert InvalidStartTime();
_setStartTime(_startTimestamp);
}
/**
* @dev Internal function to set start time and mark it as set
*/
function _setStartTime(uint64 _startTimestamp) internal {
_start = _startTimestamp;
_startTimeSet = true;
emit StartTimeSet(_startTimestamp);
}
/**
* @dev Modified vesting schedule that releases tokens in monthly steps
* @param totalAllocation The total allocation of the asset
* @param timestamp The timestamp to calculate vesting for
*/
function _vestingSchedule(uint256 totalAllocation, uint64 timestamp) internal view virtual returns (uint256) {
if (!startTimeSet() || timestamp < start()) {
return 0;
} else if (timestamp >= end()) {
return totalAllocation;
} else {
// Calculate number of complete months since start
uint256 monthsElapsed = (timestamp - start()) / SECONDS_PER_MONTH;
uint256 totalMonths = duration() / SECONDS_PER_MONTH;
// Release tokens per completed month
return (totalAllocation * monthsElapsed) / totalMonths;
}
}
/**
* @dev Calculate the amount of native currency that can be released.
* @return _amount The amount of native currency that can be released.
*/
function _releaseable() internal view virtual returns (uint256 _amount) {
_amount = _vestedAmount(uint64(block.timestamp)) - released();
}
/**
* @dev Calculate the amount of ERC-20 tokens that can be released.
* @param _token The address of the ERC-20 token.
* @return _amount The amount of ERC-20 tokens that can be released.
*/
function _releaseable(address _token) internal view virtual returns (uint256 _amount) {
_amount = _vestedAmount(_token, uint64(block.timestamp)) - released(_token);
}
/**
* @dev Calculate the amount of native currency that has been vested.
* @param _timestamp The timestamp to calculate.
* @return _amount The amount of native currency that has been vested.
*/
function _vestedAmount(uint64 _timestamp) internal view virtual returns (uint256 _amount) {
_amount = _vestingSchedule(address(this).balance + released(), _timestamp);
}
/**
* @dev Calculate the amount of ERC-20 tokens that has been vested.
* @param _token The address of the ERC-20 token.
* @param _timestamp The timestamp to calculate.
* @return _amount The amount of ERC-20 tokens that has been vested.
*/
function _vestedAmount(address _token, uint64 _timestamp) internal view virtual returns (uint256 _amount) {
_amount = _vestingSchedule(IERC20(_token).balanceOf(address(this)) + released(_token), _timestamp);
}
}
AuthNoOwner.sol 66 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.25;
import {IAuthNoOwner} from 'interfaces/IAuthNoOwner.sol';
import {IAuthority} from 'interfaces/IAuthority.sol';
contract AuthNoOwner is IAuthNoOwner {
/// @notice The authority contract.
IAuthority private _authority;
/// @notice Whether the authority has been initialized.
bool private _authorityInitialized;
/// @notice Modifier to require caller authorization for function execution.
modifier requiresAuth() virtual {
if (!_isAuthorized(msg.sender, msg.sig)) {
revert Unauthorized();
}
_;
}
/// @inheritdoc IAuthNoOwner
function authority() public view returns (IAuthority _currentAuthority) {
return _authority;
}
/// @inheritdoc IAuthNoOwner
function authorityInitialized() public view returns (bool _initialized) {
return _authorityInitialized;
}
/**
* @notice Changed constructor to initialize to allow flexibility of constructor vs initializer use.
* @notice sets authorityInitialized flag to ensure only one use of it.
* @param _newAuthority The address of the new authority contract.
*/
function _initializeAuthority(address _newAuthority) internal virtual {
if (_newAuthority == address(0)) {
revert AuthorityZeroAddress();
}
if (_authorityInitialized) {
revert AuthorityAlreadyInitialized();
}
_authority = IAuthority(_newAuthority);
_authorityInitialized = true;
emit AuthoritySet(address(this), IAuthority(_newAuthority));
}
/**
* @notice Determines if a user is authorized to call a specific function.
* @dev Memoizes the authority instance to save gas and checks if the authority allows the call.
* @param _user The address of the user attempting to call the function.
* @param _functionSig The signature of the function being called.
* @return _authorized bool Returns true if the user is authorized to call the function, false otherwise.
*/
function _isAuthorized(address _user, bytes4 _functionSig) internal view virtual returns (bool _authorized) {
IAuthority auth = _authority; // Memoizing authority saves us a warm SLOAD, around 100 gas.
// Checking if the caller is the owner only after calling the authority saves gas in most cases, but be
// aware that this makes protected functions uncallable even to the owner if the authority is out of order.
_authorized = (address(auth) != address(0) && auth.canCall(_user, address(this), _functionSig));
}
}
IVestingWallet.sol 213 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
/**
* @title IVestingWallet
* @author Wonderland (https://defi.sucks)
* @notice A vesting wallet is a contract that can receive native currency and ERC-20 tokens, and release these
* assets to the beneficiary wallet, according to a vesting schedule.
*
* NOTE: This contract is based on the Open Zeppelin implementation of a vesting wallet. The original contract is
* found at: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/ffca4122992719614c64368861269cc6a87d16f6/contracts/finance/VestingWallet.sol
*/
interface IVestingWallet {
/*///////////////////////////////////////////////////////////////
EVENTS
///////////////////////////////////////////////////////////////*/
/**
* @notice Emitted when native tokens are released.
* @param amount The amount of tokens released.
*/
event NativeCurrencyReleased(uint256 amount);
/**
* @notice Emitted when ERC20 tokens are released.
* @param token The token address.
* @param amount The amount of tokens released.
*/
event ERC20Released(address indexed token, uint256 amount);
/**
* @notice Emitted when the beneficiary is proposed by the owner.
* @param _oldBeneficiary The old beneficiary
* @param _newBeneficiary The new beneficiary
*/
event BeneficiaryProposed(address _oldBeneficiary, address _newBeneficiary);
/**
* @notice Emitted when the proposed beneficiary is accepted by the current beneficiary.
* @param _oldBeneficiary The old beneficiary.
* @param _newBeneficiary The new beneficiary.
*/
event BeneficiaryAccepted(address _oldBeneficiary, address _newBeneficiary);
/**
* @notice Emitted when the start time is set.
* @param _startTimestamp The start timestamp.
*/
event StartTimeSet(uint64 _startTimestamp);
/*///////////////////////////////////////////////////////////////
ERRORS
///////////////////////////////////////////////////////////////*/
/**
* @notice Throws when the sent proposed beneficiary does not match.
*/
error NotProposedBeneficiary();
/**
* @notice Throws when attempting to accept the proposed beneficiary when it is the zero address.
*/
error ZeroAddress();
/**
* @notice Throws when attempting to set start time when it's already set.
*/
error StartTimeAlreadySet();
/**
* @notice Throws when attempting to set an invalid start time (zero).
*/
error InvalidStartTime();
/**
* @notice Throws when attempting to perform an operation that requires start time to be set.
*/
error StartTimeNotSet();
/**
* @notice Error when duration is not a multiple of months
*/
error InvalidDuration();
/**
* @notice Error when duration is less than one month
*/
error DurationTooShort();
/*///////////////////////////////////////////////////////////////
VARIABLES
///////////////////////////////////////////////////////////////*/
/**
* @notice Returns the current beneficiary.
* @return _beneficiary The beneficiary.
*/
function beneficiary() external view returns (address _beneficiary);
/**
* @notice Returns the proposed beneficiary.
* @return _proposedBeneficiary The proposed beneficiary.
*/
function proposedBeneficiary() external view returns (address _proposedBeneficiary);
/**
* @notice Returns whether the start timestamp has been set.
* @return _startTimeSet Whether the start timestamp has been set.
*/
function startTimeSet() external view returns (bool _startTimeSet);
/**
* @notice Returns the start timestamp for the vesting.
* @return _start The start timestamp.
*/
function start() external view returns (uint256 _start);
/**
* @notice Returns the duration of the vesting.
* @return _duration The duration.
*/
function duration() external view returns (uint256 _duration);
/**
* @notice Returns the end timestamp for the vesting.
* @dev If the start time is not set, the end timestamp will revert.
* @return _end The end timestamp.
*/
function end() external view returns (uint256 _end);
/**
* @notice Returns the total amount of native tokens released.
* @return _released The total amount of native tokens released.
*/
function released() external view returns (uint256 _released);
/**
* @notice Returns the total amount of ERC20 tokens released.
* @param token The token address.
* @return _released The total amount of ERC20 tokens released.
*/
function released(address token) external view returns (uint256 _released);
/**
* @notice Returns the total amount of native tokens releasable.
* @return _amount The total amount of native tokens releasable.
*/
function releasable() external view returns (uint256 _amount);
/**
* @notice Returns the total amount of ERC20 tokens releasable.
* @param token The token address.
* @return _amount The total amount of ERC20 tokens releasable.
*/
function releasable(address token) external view returns (uint256 _amount);
/**
* @notice Returns the total amount of native tokens vested at a given timestamp. Default implementation is a linear vesting curve.
* @param timestamp The timestamp
* @return _amount The total amount of native tokens vested
*/
function vestedAmount(uint64 timestamp) external view returns (uint256 _amount);
/**
* @notice Returns the total amount of ERC20 tokens vested at a given timestamp.
* @param token The token address.
* @param timestamp The timestamp.
* @return _amount The total amount of ERC20 tokens vested.
*/
function vestedAmount(address token, uint64 timestamp) external view returns (uint256 _amount);
/*///////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
///////////////////////////////////////////////////////////////*/
/**
* @notice Initializes the vesting contract.
* @param _beneficiary The beneficiary.
* @param _durationSeconds The duration of the vesting.
* @param _authority The authority contract.
*/
function initialize(address _beneficiary, uint64 _durationSeconds, address _authority) external;
/**
* @notice Proposes a new beneficiary, the caller must be authorized.
* @param _newBeneficiary The new beneficiary.
*/
function proposeBeneficiary(address _newBeneficiary) external;
/**
* @notice Accepts the proposed beneficiary. This can only be called by the current beneficiary.
* @dev The function will also transfer the roles from the current beneficiary to the new beneficiary.
* @param _proposedBeneficiary The proposed beneficiary
*/
function acceptBeneficiary(address _proposedBeneficiary) external;
/**
* @notice Releases the releasable native tokens.
*/
function release() external;
/**
* @notice Releases the releasable ERC20 tokens.
* @param token The token address
*/
function release(address token) external;
/**
* @notice Sets the start time for the vesting.
* @param _startTimestamp The start timestamp.
*/
function setStartTime(uint64 _startTimestamp) external;
}
OwnableUpgradeable.sol 119 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.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 OwnableUpgradeable is Initializable, ContextUpgradeable {
/// @custom:storage-location erc7201:openzeppelin.storage.Ownable
struct OwnableStorage {
address _owner;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;
function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
assembly {
$.slot := OwnableStorageLocation
}
}
/**
* @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.
*/
function __Ownable_init(address initialOwner) internal onlyInitializing {
__Ownable_init_unchained(initialOwner);
}
function __Ownable_init_unchained(address initialOwner) internal onlyInitializing {
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) {
OwnableStorage storage $ = _getOwnableStorage();
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 {
OwnableStorage storage $ = _getOwnableStorage();
address oldOwner = $._owner;
$._owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Initializable.sol 228 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reininitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._initialized = version;
$._initializing = true;
_;
$._initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
assembly {
$.slot := INITIALIZABLE_STORAGE
}
}
}
UUPSUpgradeable.sol 153 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.20;
import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*/
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address private immutable __self = address(this);
/**
* @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
* and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
* while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
* If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
* be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
* during an upgrade.
*/
string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";
/**
* @dev The call is from an unauthorized context.
*/
error UUPSUnauthorizedCallContext();
/**
* @dev The storage `slot` is unsupported as a UUID.
*/
error UUPSUnsupportedProxiableUUID(bytes32 slot);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC-1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC-1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
_checkProxy();
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
_checkNotDelegated();
_;
}
function __UUPSUpgradeable_init() internal onlyInitializing {
}
function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
}
/**
* @dev Implementation of the ERC-1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate the implementation's compatibility when performing an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual notDelegated returns (bytes32) {
return ERC1967Utils.IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data);
}
/**
* @dev Reverts if the execution is not performed via delegatecall or the execution
* context is not of a proxy with an ERC-1967 compliant implementation pointing to self.
* See {_onlyProxy}.
*/
function _checkProxy() internal view virtual {
if (
address(this) == __self || // Must be called through delegatecall
ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
) {
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Reverts if the execution is performed via delegatecall.
* See {notDelegated}.
*/
function _checkNotDelegated() internal view virtual {
if (address(this) != __self) {
// Must not be called through delegatecall
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
/**
* @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
*
* As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
* is expected to be the implementation slot in ERC-1967.
*
* Emits an {IERC1967-Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
revert UUPSUnsupportedProxiableUUID(slot);
}
ERC1967Utils.upgradeToAndCall(newImplementation, data);
} catch {
// The implementation is not UUPS
revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
}
}
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
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);
}
SafeERC20.sol 199 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 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 {
/**
* @dev An operation with an ERC-20 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.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
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.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
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.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
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 Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
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 {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
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 silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}
Address.sol 150 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @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 Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert Errors.FailedCall();
}
}
/**
* @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
* {Errors.FailedCall} 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 Errors.InsufficientBalance(address(this).balance, value);
}
(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 {Errors.FailedCall}) 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 {Errors.FailedCall} 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 {Errors.FailedCall}.
*/
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
assembly ("memory-safe") {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert Errors.FailedCall();
}
}
}
IAuthNoOwner.sol 57 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
import {IAuthority} from 'interfaces/IAuthority.sol';
/**
* @notice Provides a flexible and updatable auth pattern which is completely separate from application logic.
* @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol).
* @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol).
* @author Modified to fit DeFi Wonderland standards.
*/
interface IAuthNoOwner {
/*///////////////////////////////////////////////////////////////
EVENTS
///////////////////////////////////////////////////////////////*/
/**
* @notice Emitted when the authority contract is set.
* @param _currentContract the current contract.
* @param _newAuthority the authority contract address.
*/
event AuthoritySet(address indexed _currentContract, IAuthority indexed _newAuthority);
/*///////////////////////////////////////////////////////////////
ERRORS
///////////////////////////////////////////////////////////////*/
/**
* @notice Emitted when the caller is not authorized to execute a function.
*/
error Unauthorized();
/**
* @notice Emitted when the authority address is set to the zero address.
*/
error AuthorityZeroAddress();
/**
* @notice Emitted when the authority has already been initialized.
*/
error AuthorityAlreadyInitialized();
/*///////////////////////////////////////////////////////////////
VARIABLES
///////////////////////////////////////////////////////////////*/
/**
* @notice Returns the authority contract that controls access permissions.
* @return _currentAuthority The Authority contract instance.
*/
function authority() external view returns (IAuthority _currentAuthority);
/**
* @notice Returns a boolean with the status of the initialization.
* @notice The authority can only be initialized once.
* @return _initialized bool Returns true if the authority has been initialized, false otherwise.
*/
function authorityInitialized() external view returns (bool _initialized);
}
IAuthority.sol 35 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
interface IAuthority {
/*///////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
///////////////////////////////////////////////////////////////*/
/**
* @notice Determines if a user is authorized to call a specific function.
* @param _user the address of the user attempting to call the function.
* @param _target the contract address of the function being called.
* @param _functionSig the signature of the function being called.
* @return _canCall bool returns true if the user is authorized to call the function, false otherwise.
*/
function canCall(address _user, address _target, bytes4 _functionSig) external view returns (bool _canCall);
/**
* @notice Grants or revokes a specified role's ability to call a function on a target.
* @notice If the capability is already public or has been burned, this function will have no effect.
* @param _role The role ID to update the capability for.
* @param _target The address of the contract where the function signature resides.
* @param _functionSig The function signature to update the capability for.
* @param _enabled True to grant the capability, false to revoke it.
*/
function setRoleCapability(uint8 _role, address _target, bytes4 _functionSig, bool _enabled) external;
/**
* @notice Assigns or removes a role for an address.
* @param _user The address of the user to assign/remove the role to/from.
* @param _role The role ID to assign/remove.
* @param _enabled True to assign the role, false to remove it.
*/
function setUserRole(address _user, uint8 _role, bool _enabled) external;
}
ContextUpgradeable.sol 34 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @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 ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
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;
}
}
draft-IERC1822.sol 20 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.20;
/**
* @dev ERC-1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822Proxiable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}
ERC1967Utils.sol 177 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (proxy/ERC1967/ERC1967Utils.sol)
pragma solidity ^0.8.21;
import {IBeacon} from "../beacon/IBeacon.sol";
import {IERC1967} from "../../interfaces/IERC1967.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";
/**
* @dev This library provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] slots.
*/
library ERC1967Utils {
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev The `implementation` of the proxy is invalid.
*/
error ERC1967InvalidImplementation(address implementation);
/**
* @dev The `admin` of the proxy is invalid.
*/
error ERC1967InvalidAdmin(address admin);
/**
* @dev The `beacon` of the proxy is invalid.
*/
error ERC1967InvalidBeacon(address beacon);
/**
* @dev An upgrade function sees `msg.value > 0` that may be lost.
*/
error ERC1967NonPayable();
/**
* @dev Returns the current implementation address.
*/
function getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the ERC-1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
if (newImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(newImplementation);
}
StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Performs implementation upgrade with additional setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-Upgraded} event.
*/
function upgradeToAndCall(address newImplementation, bytes memory data) internal {
_setImplementation(newImplementation);
emit IERC1967.Upgraded(newImplementation);
if (data.length > 0) {
Address.functionDelegateCall(newImplementation, data);
} else {
_checkNonPayable();
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*
* TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
* the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
*/
function getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the ERC-1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
if (newAdmin == address(0)) {
revert ERC1967InvalidAdmin(address(0));
}
StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {IERC1967-AdminChanged} event.
*/
function changeAdmin(address newAdmin) internal {
emit IERC1967.AdminChanged(getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the ERC-1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
if (newBeacon.code.length == 0) {
revert ERC1967InvalidBeacon(newBeacon);
}
StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;
address beaconImplementation = IBeacon(newBeacon).implementation();
if (beaconImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(beaconImplementation);
}
}
/**
* @dev Change the beacon and trigger a setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-BeaconUpgraded} event.
*
* CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
* it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
* efficiency.
*/
function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
_setBeacon(newBeacon);
emit IERC1967.BeaconUpgraded(newBeacon);
if (data.length > 0) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
} else {
_checkNonPayable();
}
}
/**
* @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
* if an upgrade doesn't perform an initialization call.
*/
function _checkNonPayable() private {
if (msg.value > 0) {
revert ERC1967NonPayable();
}
}
}
IERC1363.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
Errors.sol 34 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}
IBeacon.sol 16 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.20;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {UpgradeableBeacon} will check that this address is a contract.
*/
function implementation() external view returns (address);
}
IERC1967.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1967.sol)
pragma solidity ^0.8.20;
/**
* @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
*/
interface IERC1967 {
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Emitted when the beacon is changed.
*/
event BeaconUpgraded(address indexed beacon);
}
StorageSlot.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC-1967 implementation slot:
* ```solidity
* contract ERC1967 {
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct Int256Slot {
int256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Int256Slot` with member `value` located at `slot`.
*/
function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
/**
* @dev Returns a `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
}
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Read Contract
UPGRADE_INTERFACE_VERSION 0xad3cb1cc → string
authority 0xbf7e214f → address
authorityInitialized 0x97bc1e1b → bool
beneficiary 0x38af3eed → address
duration 0x0fb5a6b4 → uint256
end 0xefbe1c1c → uint256
owner 0x8da5cb5b → address
proposedBeneficiary 0xc7de66e5 → address
proxiableUUID 0x52d1902d → bytes32
releasable 0xa3f8eace → uint256
releasable 0xfbccedae → uint256
released 0x96132521 → uint256
released 0x9852595c → uint256
start 0xbe9a6555 → uint256
startTimeSet 0xc4f15e3b → bool
vestedAmount 0x0a17b06b → uint256
vestedAmount 0x810ec23b → uint256
Write Contract 9 functions
These functions modify contract state and require a wallet transaction to execute.
acceptBeneficiary 0x611fa676
address _proposedBeneficiary
initialize 0xbcbe03df
address _beneficiary
uint64 _durationSeconds
address _authority
proposeBeneficiary 0xf3229570
address _newBeneficiary
release 0x19165587
address token
release 0x86d1a69f
No parameters
renounceOwnership 0x715018a6
No parameters
setStartTime 0x38812e58
uint64 _startTimestamp
transferOwnership 0xf2fde38b
address
upgradeToAndCall 0x4f1ef286
address newImplementation
bytes data
Recent Transactions
No transactions found for this address