Forkchoice Ethereum Mainnet

Address Contract Verified

Address 0x29ac7D0C763c4903358872Fd3326B3d0468104F9
Balance 0.004356 ETH ($8.55)
Nonce 1
Code Size 10475 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

10475 bytes
0x6080604052600436101561001257600080fd5b60003560e01c80630668a15314611e565780631a55cc48146115a15780632957b839146115655780633ce1d699146112105780634f078a471461111c57806364f0d35e146110ca578063698a5897146110785780636a41043214610f82578063715018a614610ebe57806379ba509714610db05780637faad16f14610b2c5780638d977672146109fc5780638da5cb5b146109aa5780639bb3e4ae1461092b578063a08e31931461055a578063aad2b7231461043c578063b202416c146103cf578063b931666b146102fc578063cc32d176146102c0578063d22c81e514610284578063e30c397814610232578063f25f4b56146101e05763f2fde38b1461011957600080fd5b346101db5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5760043573ffffffffffffffffffffffffffffffffffffffff81168091036101db576101716123a2565b807fffffffffffffffffffffffff0000000000000000000000000000000000000000600154161760015573ffffffffffffffffffffffffffffffffffffffff600054167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e22700600080a3005b600080fd5b346101db5760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db57602073ffffffffffffffffffffffffffffffffffffffff60055416604051908152f35b346101db5760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db57602073ffffffffffffffffffffffffffffffffffffffff60015416604051908152f35b346101db5760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576020600454604051908152f35b346101db5760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576020600754604051908152f35b346101db5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576004356103366123a2565b80156103a55760075481811461037b5760407f77952d80680a32b88518cb8568afaa79f18db1b1239e2dc29350a2094e8a6a79918151908152836020820152a1600755005b7f2620eb3a0000000000000000000000000000000000000000000000000000000060005260046000fd5b7f7c946ed70000000000000000000000000000000000000000000000000000000060005260046000fd5b346101db5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5760043573ffffffffffffffffffffffffffffffffffffffff81168091036101db576000526002602052602060ff604060002054166040519015158152f35b346101db5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5760043573ffffffffffffffffffffffffffffffffffffffff8116908181036101db5781156105305761049b6123a2565b60095473ffffffffffffffffffffffffffffffffffffffff811683811461037b576040805173ffffffffffffffffffffffffffffffffffffffff92831681529390911660208401527fffffffffffffffffffffffff0000000000000000000000000000000000000000927f2d025324f0a785e8c12d0a0d91a9caa49df4ef20ff87e0df7213a1d4f3157beb9190a11617600955005b7fd92e233d0000000000000000000000000000000000000000000000000000000060005260046000fd5b346101db576105683661206f565b916105716123c3565b6004548110156109015780600052600a6020526040600020916040519061059782612114565b6105a084612172565b82526105ae60018501612172565b60208301526002840154946040830195865273ffffffffffffffffffffffffffffffffffffffff600386015416946060840195865260048101549073ffffffffffffffffffffffffffffffffffffffff8216608086015260a085019060ff8360a01c1615158252610140600760ff8560a81c161515928360c08a015260ff60e08a019660b01c161515865273ffffffffffffffffffffffffffffffffffffffff6005820154166101008a015260068101546101208a0152015496019586526108d757516108ad57516108835761072e61072573ffffffffffffffffffffffffffffffffffffffff9261071f84600954169560405160208101903360601b82528a60348201527f02000000000000000000000000000000000000000000000000000000000000006054820152603581526106e8605582612131565b5190207f19457468657265756d205369676e6564204d6573736167653a0a333200000000600052601c52603c60002092369161232c565b90612678565b909291926126b4565b1603610859577fe374130ee21046a04f5d6be14c752d412f721aecf1e8a04109b0634279cac0a69360209383600052600a855260046040600020017601000000000000000000000000000000000000000000007fffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffffff82541617905573ffffffffffffffffffffffffffffffffffffffff81511673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee811460001461081d57505061080861080f9273ffffffffffffffffffffffffffffffffffffffff6006541690519061242e565b513361242e565b604051908152a16001600355005b9061084873ffffffffffffffffffffffffffffffffffffffff9261085495846006541690519161257d565b5116905190339061257d565b61080f565b7f8baa579f0000000000000000000000000000000000000000000000000000000060005260046000fd5b7f941fe5390000000000000000000000000000000000000000000000000000000060005260046000fd5b7fe6ac7a630000000000000000000000000000000000000000000000000000000060005260046000fd5b7fd23dbb8b0000000000000000000000000000000000000000000000000000000060005260046000fd5b7f0531bbb10000000000000000000000000000000000000000000000000000000060005260046000fd5b346101db5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576004356109656123a2565b80156103a55760085481811461037b5760407f7ae909339e4db8cbb6eb3bddbf737f3c84d885e21e5d544d5e44dadc4f1aab4e918151908152836020820152a1600855005b346101db5760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db57602073ffffffffffffffffffffffffffffffffffffffff60005416604051908152f35b346101db5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db57600435600052600a602052610abc6040600020610a4781612172565b90610a5460018201612172565b60028201549173ffffffffffffffffffffffffffffffffffffffff60038201541660ff600483015473ffffffffffffffffffffffffffffffffffffffff60058501541692610aca60076006870154960154966040519a8b9a6101608c526101608c0190612234565b908a820360208c0152612234565b966040890152606088015273ffffffffffffffffffffffffffffffffffffffff81166080880152818160a01c16151560a0880152818160a81c16151560c088015260b01c16151560e08601526101008501526101208401526101408301520390f35b346101db57610b3a3661206f565b91610b436123c3565b6004548110156109015780600052600a60205260406000209160405190610b6982612114565b610b7284612172565b8252610b8060018501612172565b60208301526002840154946040830195865273ffffffffffffffffffffffffffffffffffffffff60038601541694606084019586526004810154608085019173ffffffffffffffffffffffffffffffffffffffff8216835260a086019060ff8360a01c1615158252610140600760ff8560a81c161515928360c08b015260ff60e08b019660b01c161515865273ffffffffffffffffffffffffffffffffffffffff6005820154166101008b015260068101546101208b0152015497019687526108d757516108ad5751610883575173ffffffffffffffffffffffffffffffffffffffff16330361090157610cd861072573ffffffffffffffffffffffffffffffffffffffff9261071f84600954169560405160208101903360601b82528a60348201527f01000000000000000000000000000000000000000000000000000000000000006054820152603581526106e8605582612131565b1603610859577fd64a3a9649695b08ea7b2b94945f064a42f94cc9a8003eacee8b26940b4c40179360209383600052600a85526004604060002001740100000000000000000000000000000000000000007fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff82541617905573ffffffffffffffffffffffffffffffffffffffff81511673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee811460001461081d57505061080861080f9273ffffffffffffffffffffffffffffffffffffffff6006541690519061242e565b346101db5760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db573373ffffffffffffffffffffffffffffffffffffffff6001541603610e90577fffffffffffffffffffffffff000000000000000000000000000000000000000060015416600155600054337fffffffffffffffffffffffff000000000000000000000000000000000000000082161760005573ffffffffffffffffffffffffffffffffffffffff3391167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3005b7f118cdaa7000000000000000000000000000000000000000000000000000000006000523360045260246000fd5b346101db5760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db57610ef56123a2565b7fffffffffffffffffffffffff000000000000000000000000000000000000000060015416600155600073ffffffffffffffffffffffffffffffffffffffff81547fffffffffffffffffffffffff000000000000000000000000000000000000000081168355167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b346101db5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5760043573ffffffffffffffffffffffffffffffffffffffff8116908181036101db57811561053057610fe16123a2565b6006548273ffffffffffffffffffffffffffffffffffffffff82161461037b576005546040805173ffffffffffffffffffffffffffffffffffffffff92831681529390911660208401527fffffffffffffffffffffffff0000000000000000000000000000000000000000927fe8957b4589282a0d6a117680560373d2e1009f2447c50e290fe887d8563dbf069190a11617600655005b346101db5760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db57602073ffffffffffffffffffffffffffffffffffffffff60065416604051908152f35b346101db5760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db57602073ffffffffffffffffffffffffffffffffffffffff60095416604051908152f35b346101db5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5760043573ffffffffffffffffffffffffffffffffffffffff8116908181036101db5781156105305761117b6123a2565b60055473ffffffffffffffffffffffffffffffffffffffff811683811461037b576040805173ffffffffffffffffffffffffffffffffffffffff92831681529390911660208401527fffffffffffffffffffffffff0000000000000000000000000000000000000000927fc5065ba5231fe8774c6784caa5132387839a243a190cb7bef85dbc34f264d45e9190a11617600555005b346101db5760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5760043560243567ffffffffffffffff81116101db57611262903690600401612041565b9160443567ffffffffffffffff81116101db57611283903690600401612041565b939061128d6123c3565b6004548310156109015782600052600a602052604060002094604051926112b384612114565b6112bc87612172565b84526112ca60018801612172565b60208501526002870154926040850193845273ffffffffffffffffffffffffffffffffffffffff60038901541692606086019384526004890154608087019973ffffffffffffffffffffffffffffffffffffffff82168b5260a088019060ff8360a01c1615158252610140600760ff8560a81c161515928360c08d015260ff60e08d019660b01c161515865273ffffffffffffffffffffffffffffffffffffffff6005820154166101008d015260068101546101208d0152015499019889526108d757516108ad57516108835773ffffffffffffffffffffffffffffffffffffffff895116331461153b576113ff60409861141f9473ffffffffffffffffffffffffffffffffffffffff7f9453a145616fa2162feb3e3314cf5b6be415bced91b2589d51474a3e91e87d769c5116918a612528565b73ffffffffffffffffffffffffffffffffffffffff600954169187612528565b6000848152600a60205285812060040180547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff16750100000000000000000000000000000000000000000017905585902060050180547fffffffffffffffffffffffff00000000000000000000000000000000000000001633179055805173ffffffffffffffffffffffffffffffffffffffff1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee810361150b5750506108086114f89273ffffffffffffffffffffffffffffffffffffffff6006541690519061242e565b8151908152336020820152a16001600355005b9061084873ffffffffffffffffffffffffffffffffffffffff9261153695846006541690519161257d565b6114f8565b7fd8546cf10000000000000000000000000000000000000000000000000000000060005260046000fd5b346101db5760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576020600854604051908152f35b60807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5760043567ffffffffffffffff81116101db576115eb903690600401612041565b9060243567ffffffffffffffff81116101db5761160c903690600401612041565b9290916064359173ffffffffffffffffffffffffffffffffffffffff831683036101db576116386123c3565b604435156103a55773ffffffffffffffffffffffffffffffffffffffff8316600052600260205260ff6040600020541615611e2c57600454927fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8414611dfd57600184016004556103e86116b06007546044356122d2565b04956103e86116c36008546044356122d2565b046116d0886044356122e5565b8173ffffffffffffffffffffffffffffffffffffffff851673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee14611da2578161171261173b933033896124bc565b6117368b73ffffffffffffffffffffffffffffffffffffffff6005541633896124bc565b6122e5565b97604051986117498a612114565b60608a52606060208b0152600060408b0152600060608b0152600060808b0152600060a08b0152600060c08b0152600060e08b015260006101008b015260006101208b015260006101408b01526117a136878961232c565b8a526117ae36858b61232c565b60208b015260408a015273ffffffffffffffffffffffffffffffffffffffff841660608a01523360808a0152600060c08a015261012089015261014088015284600052600a6020526040600020875180519067ffffffffffffffff8211611c7657819061181b84546120c1565b601f8111611d4f575b50602090601f8311600114611cb057600092611ca5575b50507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8260011b9260031b1c19161781555b602088015197885167ffffffffffffffff8111611c765761189160018401546120c1565b99601f8b11611c2f575b60209a508a90601f8311600114611b24576101407f40804bd49c1295dc284d8a966b21efe0a86fa541892521d90c9f8a7e663c66f99a9b948473ffffffffffffffffffffffffffffffffffffffff9895611aee9895600795600092611b19575b50507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8260011b9260031b1c19161760018501555b6040810151600285015587606082015116886003860191167fffffffffffffffffffffffff0000000000000000000000000000000000000000825416179055600484018880608084015116167fffffffffffffffffffffffff000000000000000000000000000000000000000082541617815560a082015115157fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff74ff000000000000000000000000000000000000000083549260a01b16911617815560c082015115157fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff75ff00000000000000000000000000000000000000000083549260a81b16911617815560e082015115157fffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffffff76ff0000000000000000000000000000000000000000000083549260b01b1691161790558761010082015116886005860191167fffffffffffffffffffffffff000000000000000000000000000000000000000082541617905561012081015160068501550151910155611ae160405197889760c0895260c0890191612363565b918683038b880152612363565b9160443560408501521660608301523360808301528460a08301520390a16001600355604051908152f35b0151905038806118fb565b9060018501600052806000209160005b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe085168110611c1857507f40804bd49c1295dc284d8a966b21efe0a86fa541892521d90c9f8a7e663c66f99a9b94600185611aee989560079561014095837fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe073ffffffffffffffffffffffffffffffffffffffff9e9b1610611be1575b505050811b016001850155611930565b01517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60f88460031b161c19169055388080611bd1565b91928d600181928685015181550194019201611b34565b600184016000526020600020601f830160051c810160208410611c6f575b601f8d0160051c82018110611c6357505061189b565b60008155600101611c4d565b5080611c4d565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b015190508a8061183b565b6000858152828120937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016905b818110611d375750908460019594939210611d00575b505050811b01815561186d565b01517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60f88460031b161c191690558a8080611cf3565b92936020600181928786015181550195019301611cdd565b909150836000526020600020601f840160051c81019160208510611d98575b90601f859493920160051c01905b818110611d895750611824565b60008155849350600101611d7c565b9091508190611d6e565b506044353403611dd3578161173b916117368b73ffffffffffffffffffffffffffffffffffffffff6005541661242e565b7f4caf25380000000000000000000000000000000000000000000000000000000060005260046000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7fdfde86710000000000000000000000000000000000000000000000000000000060005260046000fd5b346101db5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5760043567ffffffffffffffff81116101db57611ea5903690600401612010565b60243567ffffffffffffffff81116101db57611ec5903690600401612010565b611ed09291926123a2565b8115611fe657808203611fbc5760005b828110611ee957005b611ef4818386612293565b35908115158092036101db57611f0b818588612293565b359173ffffffffffffffffffffffffffffffffffffffff83168093036101db5782600052600260205260ff604060002054168315610530571515811461037b576001927fe9558fdab6b1decc19016dabb526a3f24cb6b4190ad2e8ad9d3f7c77a92ac91260408051838152846020820152a1600052600260205260406000209060ff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00835416911617905501611ee0565b7fa24a13a60000000000000000000000000000000000000000000000000000000060005260046000fd5b7f0f59b9ff0000000000000000000000000000000000000000000000000000000060005260046000fd5b9181601f840112156101db5782359167ffffffffffffffff83116101db576020808501948460051b0101116101db57565b9181601f840112156101db5782359167ffffffffffffffff83116101db57602083818601950101116101db57565b9060407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc8301126101db57600435916024359067ffffffffffffffff82116101db576120bd91600401612041565b9091565b90600182811c9216801561210a575b60208310146120db57565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b91607f16916120d0565b610160810190811067ffffffffffffffff821117611c7657604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff821117611c7657604052565b9060405191826000825492612186846120c1565b80845293600181169081156121f457506001146121ad575b506121ab92500383612131565b565b90506000929192526020600020906000915b8183106121d85750509060206121ab928201013861219e565b60209193508060019154838589010152019101909184926121bf565b602093506121ab9592507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0091501682840152151560051b8201013861219e565b919082519283825260005b84811061227e5750507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8460006020809697860101520116010190565b8060208092840101518282860101520161223f565b91908110156122a35760051b0190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b81810292918115918404141715611dfd57565b91908203918211611dfd57565b67ffffffffffffffff8111611c7657601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b929192612338826122f2565b916123466040519384612131565b8294818452818301116101db578281602093846000960137010152565b601f82602094937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0938186528686013760008582860101520116010190565b73ffffffffffffffffffffffffffffffffffffffff600054163303610e9057565b6002600354146123d4576002600355565b7f3ee5aeb50000000000000000000000000000000000000000000000000000000060005260046000fd5b3d15612429573d9061240f826122f2565b9161241d6040519384612131565b82523d6000602084013e565b606090565b81471061248e57600080809373ffffffffffffffffffffffffffffffffffffffff8294165af161245c6123fe565b501561246457565b7f1425ea420000000000000000000000000000000000000000000000000000000060005260046000fd5b7fcd786059000000000000000000000000000000000000000000000000000000006000523060045260246000fd5b90919273ffffffffffffffffffffffffffffffffffffffff6121ab9481604051957f23b872dd000000000000000000000000000000000000000000000000000000006020880152166024860152166044840152606483015260648252612523608483612131565b6125da565b61072573ffffffffffffffffffffffffffffffffffffffff9361071f85946125739460405160208101913360601b8352603482015260006054820152603581526106e8605582612131565b1691160361085957565b6121ab9273ffffffffffffffffffffffffffffffffffffffff604051937fa9059cbb000000000000000000000000000000000000000000000000000000006020860152166024840152604483015260448252612523606483612131565b60008073ffffffffffffffffffffffffffffffffffffffff61261193169360208151910182865af161260a6123fe565b90836127a0565b8051908115159182612654575b50506126275750565b7f5274afe70000000000000000000000000000000000000000000000000000000060005260045260246000fd5b81925090602091810103126101db57602001518015908115036101db57388061261e565b81519190604183036126a9576126a292506020820151906060604084015193015160001a90612813565b9192909190565b505060009160029190565b919091600481101561277157806126ca57509050565b6000600182036126fe577ff645eedf0000000000000000000000000000000000000000000000000000000060005260046000fd5b506002810361273557827ffce698f70000000000000000000000000000000000000000000000000000000060005260045260246000fd5b9091600360009214612745575050565b602492507fd78bce0c000000000000000000000000000000000000000000000000000000008252600452fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b906127b5575080511561246457805190602001fd5b8151158061280a575b6127c6575090565b73ffffffffffffffffffffffffffffffffffffffff907f9996b315000000000000000000000000000000000000000000000000000000006000521660045260246000fd5b50803b156127be565b91907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a084116128a9579160209360809260ff60009560405194855216868401526040830152606082015282805260015afa1561289d5760005173ffffffffffffffffffffffffffffffffffffffff8116156128915790600090600090565b50600090600190600090565b6040513d6000823e3d90fd5b5050506000916003919056fea2646970667358221220e547725e39959d0975b4b5304ee991bc20f3b744f9ee55473bae7c1d49cd6b6d64736f6c634300081c0033

Verified Source Code Full Match

Compiler: v0.8.28+commit.7893614a EVM: paris Optimization: Yes (1000000 runs)
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
Ownable2Step.sol 59 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol)

pragma solidity ^0.8.20;

import {Ownable} from "./Ownable.sol";

/**
 * @dev Contract module which provides access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is specified at deployment time in the constructor for `Ownable`. This
 * can later be changed with {transferOwnership} and {acceptOwnership}.
 *
 * This module is used through inheritance. It will make available all functions
 * from parent (Ownable).
 */
abstract contract Ownable2Step is Ownable {
    address private _pendingOwner;

    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Returns the address of the pending owner.
     */
    function pendingOwner() public view virtual returns (address) {
        return _pendingOwner;
    }

    /**
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual override onlyOwner {
        _pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner(), newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual override {
        delete _pendingOwner;
        super._transferOwnership(newOwner);
    }

    /**
     * @dev The new owner accepts the ownership transfer.
     */
    function acceptOwnership() public virtual {
        address sender = _msgSender();
        if (pendingOwner() != sender) {
            revert OwnableUnauthorizedAccount(sender);
        }
        _transferOwnership(sender);
    }
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}
SafeERC20.sol 118 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    /**
     * @dev An operation with an ERC20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
    }
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
ECDSA.sol 174 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.20;

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS
    }

    /**
     * @dev The signature derives the `address(0)`.
     */
    error ECDSAInvalidSignature();

    /**
     * @dev The signature has an invalid length.
     */
    error ECDSAInvalidSignatureLength(uint256 length);

    /**
     * @dev The signature has an S value that is in the upper half order.
     */
    error ECDSAInvalidSignatureS(bytes32 s);

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
     * return address(0) without also returning an error description. Errors are documented using an enum (error type)
     * and a bytes32 providing additional information about the error.
     *
     * If no error is returned, then the address can be used for verification purposes.
     *
     * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     */
    function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
        unchecked {
            bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
            // We do not check for an overflow here since the shift operation results in 0 or 1.
            uint8 v = uint8((uint256(vs) >> 255) + 27);
            return tryRecover(hash, v, r, s);
        }
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     */
    function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError, bytes32) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS, s);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature, bytes32(0));
        }

        return (signer, RecoverError.NoError, bytes32(0));
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
     */
    function _throwError(RecoverError error, bytes32 errorArg) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert ECDSAInvalidSignature();
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert ECDSAInvalidSignatureLength(uint256(errorArg));
        } else if (error == RecoverError.InvalidSignatureS) {
            revert ECDSAInvalidSignatureS(errorArg);
        }
    }
}
MessageHashUtils.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol)

pragma solidity ^0.8.20;

import {Strings} from "../Strings.sol";

/**
 * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
 *
 * The library provides methods for generating a hash of a message that conforms to the
 * https://eips.ethereum.org/EIPS/eip-191[EIP 191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
 * specifications.
 */
library MessageHashUtils {
    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x45` (`personal_sign` messages).
     *
     * The digest is calculated by prefixing a bytes32 `messageHash` with
     * `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
     * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
     *
     * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
     * keccak256, although any bytes32 value can be safely used because the final digest will
     * be re-hashed.
     *
     * See {ECDSA-recover}.
     */
    function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
            mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
            digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
        }
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x45` (`personal_sign` messages).
     *
     * The digest is calculated by prefixing an arbitrary `message` with
     * `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
     * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
     *
     * See {ECDSA-recover}.
     */
    function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
        return
            keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x00` (data with intended validator).
     *
     * The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
     * `validator` address. Then hashing the result.
     *
     * See {ECDSA-recover}.
     */
    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked(hex"19_00", validator, data));
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-712 typed data (EIP-191 version `0x01`).
     *
     * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
     * `\x19\x01` and hashing the result. It corresponds to the hash signed by the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
     *
     * See {ECDSA-recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, hex"19_01")
            mstore(add(ptr, 0x02), domainSeparator)
            mstore(add(ptr, 0x22), structHash)
            digest := keccak256(ptr, 0x42)
        }
    }
}
Math.sol 415 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Muldiv operation overflow.
     */
    error MathOverflowedMulDiv();

    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds towards infinity instead
     * of rounding towards zero.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            return a / b;
        }

        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
     * denominator == 0.
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
     * Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0 = x * y; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            if (denominator <= prod1) {
                revert MathOverflowedMulDiv();
            }

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator.
            // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.

            uint256 twos = denominator & (0 - denominator);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
            // works in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
     * towards zero.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
        }
    }

    /**
     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
     */
    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
        return uint8(rounding) % 2 == 1;
    }
}
SignedMath.sol 43 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}
ReentrancyGuard.sol 84 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant NOT_ENTERED = 1;
    uint256 private constant ENTERED = 2;

    uint256 private _status;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    constructor() {
        _status = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        _status = ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == ENTERED;
    }
}
Strings.sol 94 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)

pragma solidity ^0.8.20;

import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant HEX_DIGITS = "0123456789abcdef";
    uint8 private constant ADDRESS_LENGTH = 20;

    /**
     * @dev The `value` string doesn't fit in the specified `length`.
     */
    error StringsInsufficientHexLength(uint256 value, uint256 length);

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toStringSigned(int256 value) internal pure returns (string memory) {
        return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        uint256 localValue = value;
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = HEX_DIGITS[localValue & 0xf];
            localValue >>= 4;
        }
        if (localValue != 0) {
            revert StringsInsufficientHexLength(value, length);
        }
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
     * representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
    }

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
    }
}
Common.sol 24 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/// @dev The address of the Ethereum
IERC20 constant ETH = IERC20(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);

uint256 constant DIVISOR = 1000;

/// @notice Thrown when updating an address with zero address
error ZeroAddress();

/// @notice Thrown when updating an address with zero address
error ZeroValue();

/// @notice Thrown when updating with an array of no values
error ZeroLengthArray();

/// @notice Thrown when updating with the same value as previously stored
error IdenticalValue();

/// @notice Thrown when two array lengths does not match
error ArrayLengthMismatch();
TaskManager.sol 463 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import { TokenRegistry, Ownable2Step, Ownable } from "./TokenRegistry.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IdenticalValue, ZeroAddress, ETH, ZeroValue, DIVISOR } from "./Common.sol";

import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";

import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";

contract TaskManager is TokenRegistry, ReentrancyGuard {
    using SafeERC20 for IERC20;
    using Address for address payable;

    /// @member title The title of the task
    /// @member description The description of the task describing complete requirements
    /// @member reward The amount of reward given to the person who completes the task
    /// @member rewardToken The currecny in which the rewards is given
    /// @member creator The address of the wallet which created the task
    /// @member refunded A boolean value representing whether the task has been refunded or not
    /// @member redeemed A boolean value representing whether the task has been completed and redeemed
    /// @member redeemed A boolean value representing whether the task has been disputed
    /// @member redeemer The address of the wallet which redemeed the task and earned reward
    /// @member feeTreasury The amount of fee allocated for setting up the task
    /// @member feeDao The amount of fee allocated for the dao
    struct Task {
        string title;
        string description;
        uint256 reward;
        IERC20 rewardToken;
        address creator;
        bool refunded;
        bool redeemed;
        bool disputed;
        address redeemer;
        uint256 feeTreasury;
        uint256 feeDao;
    }

    /// @member Redeem Representing whether the signarure generated is intented to redeem the task
    /// @member Refund Representing whether the signarure generated is intented to Refund the task
    /// @member Dispute Representing whether the signarure generated is intented to resolve the Dispute of the task
    enum SignatureType {
        Redeem,
        Refund,
        Dispute
    }

    /// @notice The count of total tasks created thus far
    uint256 public totalTasks;

    /// @notice The address where the treasury fee per task will be sent
    address public feeWallet;

    /// @notice The address where the dao fee per task will be sent
    address public daoWallet;

    /// @notice The percentage of treasury fee deducted per task
    uint256 public treasuryFee;

    /// @notice The percentage of dao fee deducted in case of dispute on a task
    uint256 public daoFee;

    /// @notice The address of signer wallet
    address public signerWallet;

    /// @notice Gives task info of every task created
    mapping(uint256 => Task) public tasks;

    /// @dev Emitted when treasury fee wallet is changed
    event TreasuryFeeWalletChanged(address oldWallet, address newWallet);

    /// @dev Emitted when treasury fee wallet is changed
    event DaoFeeWalletChanged(address oldWallet, address newWallet);

    /// @dev Emitted when treasury fee is changed
    event TreasuryFeeChanged(uint256 oldFee, uint256 newFee);

    /// @dev Emitted when dao fee wallet is changed
    event DaoFeeChanged(uint256 oldFee, uint256 newFee);

    /// @dev Emitted when a new task is created
    event TaskCreated(
        string title,
        string description,
        uint256 reward,
        IERC20 rewardingToken,
        address creator,
        uint256 taskId
    );

    /// @dev Emitted when a task is redeemed
    event TaskRedeemed(uint256 taskId, address redeemer);

    /// @dev Emitted when a task is refunded back to creator
    event TaskRefunded(uint256 taskId);

    /// @dev Emitted when a task is disputed
    event TaskDisputed(uint256 taskId);

    /// @dev Emitted when address of signer is updated
    event SignerUpdated(address oldSigner, address newSigner);

    /// @notice Thrown when sign is invalid
    error InvalidSignature();

    /// @notice Thrown when input array length is zero
    error InvalidData();

    /// @notice Thrown when deadline is wrong
    error InvalidDeadline();

    /// @notice Thrown when reward token is not supported by contract
    error InvalidRewardToken();

    /// @notice Thrown when taskId doesn't exists or not created by caller
    error InvalidTask();

    /// @notice Thrown when task is already redeemed
    error TaskAlreadyRedeemed();

    /// @notice Thrown when task is already refunded
    error TaskAlreadyRefunded();

    /// @notice Thrown when task is already disputed
    error TaskAlreadyDisputed();

    /// @notice Thrown when task creator is trying to redeem task or trying to refund someone's else task
    error InvalidRedeemer();

    /// @notice Thrown when msg.value is less than reward value while creating task
    error InvalidPayableValue();

    /// @notice Restricts when updating wallet/contract address with zero address
    modifier checkAddressZero(address which) {
        if (which == address(0)) {
            revert ZeroAddress();
        }
        _;
    }

    /// @dev Constructor
    /// @param initialOwner The addresses of the owner of the contract
    /// @param treasuryFeeWalletAddress The address of the wallet treasury fee wil be sent to
    /// @param daoFeeWalletAddress The address of the wallet dao fee wil be sent to
    /// @param signer The address of signer wallet
    /// @param treasuryFeePercentage The percentage
    /// @param daoFeePercentage The last round created
    constructor(
        address initialOwner,
        address treasuryFeeWalletAddress,
        address daoFeeWalletAddress,
        address signer,
        uint256 treasuryFeePercentage,
        uint256 daoFeePercentage
    ) Ownable(initialOwner) {
        if (
            initialOwner == address(0) ||
            treasuryFeeWalletAddress == address(0) ||
            daoFeeWalletAddress == address(0) ||
            signer == address(0)
        ) {
            revert ZeroAddress();
        }

        if (treasuryFeePercentage == 0 || daoFeePercentage == 0) {
            revert ZeroValue();
        }

        feeWallet = treasuryFeeWalletAddress;
        daoWallet = daoFeeWalletAddress;
        treasuryFee = treasuryFeePercentage;
        daoFee = daoFeePercentage;
        signerWallet = signer;
    }

    /// @notice Changes treasury fee wallet
    /// @param newFeeWalletAddress The address of the new treasury fee wallet
    function changeTreasuryFeeWallet(
        address newFeeWalletAddress
    ) external checkAddressZero(newFeeWalletAddress) onlyOwner {
        if (feeWallet == newFeeWalletAddress) {
            revert IdenticalValue();
        }

        emit TreasuryFeeWalletChanged({ oldWallet: feeWallet, newWallet: newFeeWalletAddress });
        feeWallet = newFeeWalletAddress;
    }

    /// @notice Changes dao fee wallet
    /// @param newFeeWalletAddress The address of the new dao fee wallet
    function changeDaoFeeWallet(address newFeeWalletAddress) external checkAddressZero(newFeeWalletAddress) onlyOwner {
        if (daoWallet == newFeeWalletAddress) {
            revert IdenticalValue();
        }

        emit DaoFeeWalletChanged({ oldWallet: feeWallet, newWallet: newFeeWalletAddress });
        daoWallet = newFeeWalletAddress;
    }

    /// @notice Changes treasury fee
    /// @param newTreasuryFee The new percentage of treasury fee
    function changeTreasuryFee(uint256 newTreasuryFee) external onlyOwner {
        if (newTreasuryFee == 0) {
            revert ZeroValue();
        }

        if (treasuryFee == newTreasuryFee) {
            revert IdenticalValue();
        }

        emit TreasuryFeeChanged({ oldFee: treasuryFee, newFee: newTreasuryFee });
        treasuryFee = newTreasuryFee;
    }

    /// @notice Changes dai fee
    /// @param newDaoFee The new percentage of dao fee
    function changeDaoFee(uint256 newDaoFee) external onlyOwner {
        if (newDaoFee == 0) {
            revert ZeroValue();
        }

        if (daoFee == newDaoFee) {
            revert IdenticalValue();
        }

        emit DaoFeeChanged({ oldFee: daoFee, newFee: newDaoFee });
        daoFee = newDaoFee;
    }

    /// @notice Changes signer wallet address
    /// @param newSigner The address of the new signer wallet
    function changeSigner(address newSigner) external checkAddressZero(newSigner) onlyOwner {
        address oldSigner = signerWallet;
        if (oldSigner == newSigner) {
            revert IdenticalValue();
        }
        emit SignerUpdated({ oldSigner: oldSigner, newSigner: newSigner });
        signerWallet = newSigner;
    }

    /// @notice Created a new task
    /// @param title The title of the task
    /// @param description The description of the task
    /// @param reward The reward to be given to the person who completes the task
    /// @param token The currency in which reward is given
    function createTask(
        string calldata title,
        string calldata description,
        uint256 reward,
        IERC20 token
    ) external payable nonReentrant returns (uint256) {
        if (reward == 0) {
            revert ZeroValue();
        }

        if (!acceptableTokens[token]) {
            revert InvalidRewardToken();
        }

        uint256 taskId = totalTasks++;
        address taskCreator = msg.sender;

        uint256 feeTreasury = ((reward * treasuryFee) / DIVISOR);
        uint256 feeDao = ((reward * daoFee) / DIVISOR);

        uint256 amount = reward - feeTreasury;

        if (token != ETH) {
            token.safeTransferFrom(msg.sender, address(this), amount);
            token.safeTransferFrom(msg.sender, feeWallet, feeTreasury);
        } else {
            if (msg.value != reward) {
                revert InvalidPayableValue();
            }
            payable(feeWallet).sendValue(feeTreasury);
        }

        amount -= feeDao;

        Task memory newTask;

        newTask.title = title;
        newTask.description = description;
        newTask.reward = amount;
        newTask.rewardToken = token;
        newTask.creator = taskCreator;
        newTask.redeemed = false;
        newTask.feeTreasury = feeTreasury;
        newTask.feeDao = feeDao;

        tasks[taskId] = newTask;

        emit TaskCreated({
            title: title,
            description: description,
            reward: reward,
            rewardingToken: token,
            creator: taskCreator,
            taskId: taskId
        });

        return taskId;
    }

    /// @notice Created a new task
    /// @param taskId The id of the task to be redeemed
    /// @param creatorSignature The signature of the creator indicating he chose this person
    /// @param signerSignature The signature of the platform indicating all off chain requirements met
    function redeemTask(
        uint256 taskId,
        bytes calldata creatorSignature,
        bytes calldata signerSignature
    ) external nonReentrant {
        if (taskId >= totalTasks) {
            revert InvalidTask();
        }

        Task memory task = tasks[taskId];

        if (task.redeemed) {
            revert TaskAlreadyRedeemed();
        }

        if (task.refunded) {
            revert TaskAlreadyRefunded();
        }

        if (task.disputed) {
            revert TaskAlreadyDisputed();
        }

        address redeemer = msg.sender;

        if (redeemer == task.creator) {
            revert InvalidRedeemer();
        }

        _verifySignature(taskId, SignatureType.Redeem, creatorSignature, task.creator);
        _verifySignature(taskId, SignatureType.Redeem, signerSignature, signerWallet);

        tasks[taskId].redeemed = true;
        tasks[taskId].redeemer = redeemer;

        if (task.rewardToken == ETH) {
            payable(daoWallet).sendValue(task.feeDao);
            payable(redeemer).sendValue(task.reward);
        } else {
            task.rewardToken.safeTransfer(daoWallet, task.feeDao);
            task.rewardToken.safeTransfer(redeemer, task.reward);
        }

        emit TaskRedeemed({ taskId: taskId, redeemer: redeemer });
    }

    /// @notice Created a new task
    /// @param taskId The id of the task to be redeemed
    /// @param signerSignature The signature of the platform indicating all off chain requirements met
    function refundTask(uint256 taskId, bytes calldata signerSignature) external nonReentrant {
        if (taskId >= totalTasks) {
            revert InvalidTask();
        }

        Task memory task = tasks[taskId];

        if (task.redeemed) {
            revert TaskAlreadyRedeemed();
        }

        if (task.refunded) {
            revert TaskAlreadyRefunded();
        }

        if (task.disputed) {
            revert TaskAlreadyDisputed();
        }

        address refundTo = msg.sender;

        if (refundTo != task.creator) {
            revert InvalidTask();
        }

        _verifySignature(taskId, SignatureType.Refund, signerSignature, signerWallet);

        tasks[taskId].refunded = true;

        if (task.rewardToken == ETH) {
            payable(daoWallet).sendValue(task.feeDao);
            payable(refundTo).sendValue(task.reward);
        } else {
            task.rewardToken.safeTransfer(daoWallet, task.feeDao);
            task.rewardToken.safeTransfer(refundTo, task.reward);
        }

        emit TaskRefunded({ taskId: taskId });
    }

    /// @notice Created a new task
    /// @param taskId The id of the task to be redeemed
    /// @param signerSignature The signature of the platform indicating all off chain requirements met
    function disputeTask(uint256 taskId, bytes calldata signerSignature) external nonReentrant {
        if (taskId >= totalTasks) {
            revert InvalidTask();
        }

        Task memory task = tasks[taskId];

        if (task.redeemed) {
            revert TaskAlreadyRedeemed();
        }

        if (task.refunded) {
            revert TaskAlreadyRefunded();
        }

        if (task.disputed) {
            revert TaskAlreadyDisputed();
        }

        address disputeTo = msg.sender;

        _verifySignature(taskId, SignatureType.Dispute, signerSignature, signerWallet);

        tasks[taskId].disputed = true;

        if (task.rewardToken == ETH) {
            payable(daoWallet).sendValue(task.feeDao);
            payable(disputeTo).sendValue(task.reward);
        } else {
            task.rewardToken.safeTransfer(daoWallet, task.feeDao);
            task.rewardToken.safeTransfer(disputeTo, task.reward);
        }

        emit TaskDisputed({ taskId: taskId });
    }

    /// @dev The helper function which verifies signature, signed by intended signer, reverts if Invalid
    function _verifySignature(
        uint256 taskId,
        SignatureType sigType,
        bytes calldata signature,
        address signatureSigner
    ) private view {
        bytes32 encodedMessageHash = keccak256(abi.encodePacked(msg.sender, taskId, sigType));
        _verifyMessage(encodedMessageHash, signature, signatureSigner);
    }

    /// @dev Verifies the address that signed a hashed message (`hash`) with `signature`
    function _verifyMessage(
        bytes32 encodedMessageHash,
        bytes calldata signature,
        address signatureSigner
    ) private pure {
        if (signatureSigner != ECDSA.recover(MessageHashUtils.toEthSignedMessageHash(encodedMessageHash), signature)) {
            revert InvalidSignature();
        }
    }
}
TokenRegistry.sol 44 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Ownable, Ownable2Step } from "@openzeppelin/contracts/access/Ownable2Step.sol";

import { ZeroAddress, ArrayLengthMismatch, ZeroLengthArray, IdenticalValue } from "./Common.sol";

/// @title Tokens Registry contract
/// @notice Implements the states of the tokens

abstract contract TokenRegistry is Ownable2Step {
    /// @notice Gives us onchain state whether token is accepted or not
    mapping(IERC20 => bool) public acceptableTokens;

    /// @dev Emitted when token state is changed
    event TokenDataAdded(IERC20 token, bool state);

    /// @notice Sets token is accepted or not
    /// @param tokens The addresses of the tokens
    /// @param states Contains the state of token
    function changeTokenState(IERC20[] calldata tokens, bool[] calldata states) external onlyOwner {
        uint256 tokensLength = tokens.length;
        if (tokensLength == 0) {
            revert ZeroLengthArray();
        }
        if (tokensLength != states.length) {
            revert ArrayLengthMismatch();
        }
        for (uint256 i = 0; i < tokensLength; ++i) {
            bool state = states[i];
            IERC20 token = tokens[i];
            bool currentState = acceptableTokens[token];
            if (address(token) == address(0)) {
                revert ZeroAddress();
            }
            if (currentState == state) {
                revert IdenticalValue();
            }
            emit TokenDataAdded({ token: token, state: state });
            acceptableTokens[token] = state;
        }
    }
}

Read Contract

acceptableTokens 0xb202416c → bool
daoFee 0x2957b839 → uint256
daoWallet 0x698a5897 → address
feeWallet 0xf25f4b56 → address
owner 0x8da5cb5b → address
pendingOwner 0xe30c3978 → address
signerWallet 0x64f0d35e → address
tasks 0x8d977672 → string, string, uint256, address, address, bool, bool, bool, address, uint256, uint256
totalTasks 0xd22c81e5 → uint256
treasuryFee 0xcc32d176 → uint256

Write Contract 13 functions

These functions modify contract state and require a wallet transaction to execute.

acceptOwnership 0x79ba5097
No parameters
changeDaoFee 0x9bb3e4ae
uint256 newDaoFee
changeDaoFeeWallet 0x6a410432
address newFeeWalletAddress
changeSigner 0xaad2b723
address newSigner
changeTokenState 0x0668a153
address[] tokens
bool[] states
changeTreasuryFee 0xb931666b
uint256 newTreasuryFee
changeTreasuryFeeWallet 0x4f078a47
address newFeeWalletAddress
createTask 0x1a55cc48
string title
string description
uint256 reward
address token
returns: uint256
disputeTask 0xa08e3193
uint256 taskId
bytes signerSignature
redeemTask 0x3ce1d699
uint256 taskId
bytes creatorSignature
bytes signerSignature
refundTask 0x7faad16f
uint256 taskId
bytes signerSignature
renounceOwnership 0x715018a6
No parameters
transferOwnership 0xf2fde38b
address newOwner

Recent Transactions

No transactions found for this address