Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xB107140C5737Bfa6dBBe46db6b359Caf6e51524D
Balance 3.9133 ETH
Nonce 1
Code Size 11154 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

11154 bytes
0x60a080604052600436101561001d575b50361561001b57600080fd5b005b60003560e01c90816301ffc9a71461218c57508063054a68ad146120f2578063248a9ca3146120a55780632f2ff15d1461204857806336568abe14611fbe5780633999924714611f59578063461c48cd14611df457806352b25efa14611d155780635f91d40614611cbb57806364f0d35e14611c6957806365263303146115e55780637188cb35146115055780637457b00114610d6c57806375b238fc14610d135780637934471414610c4257806391d1485414610bc9578063a217fddf14610b8f578063a24e178814610960578063aad2b7231461082c578063cabb4549146107d3578063d012a5a814610781578063d547741f14610724578063f85920d8146102eb578063fdea8e0b146102995763ff93be031461013d573861000f565b346102945760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610294576101746122a1565b60243567ffffffffffffffff8111610294576101949036906004016122d5565b9161019d6125fd565b6101a681612638565b336000526020600560205263ffffffff604060002092169182600052602052604060002060005b8581106101da5760018055005b80846101f16101ec6001948a8a612306565b612316565b73ffffffffffffffffffffffffffffffffffffffff81166000528486526040600020805490811561028b577f4978506686bd9ae370ab4cd6b1b3093dad6682e7840df229a6534e9dc4ba5223916000610281925561025081338661278c565b6040519182913395836020909392919373ffffffffffffffffffffffffffffffffffffffff60408201951681520152565b0390a35b016101cd565b50505050610285565b600080fd5b346102945760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261029457602073ffffffffffffffffffffffffffffffffffffffff60025416604051908152f35b34610294576020807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261029457600435906103276125fd565b336000526006815260406000208260005280825260406000209060405161034d81612358565b73ffffffffffffffffffffffffffffffffffffffff91828454168252600184015493858301948552600281015490604084019182526004856003830154169160608601928352015485811680608087015263ffffffff8260a01c1660a087015260ff8260c01c16151560c087015260ff60e087019260c81c161515825233036106fa57516106d05784600354166040517f4a8c1fb40000000000000000000000000000000000000000000000000000000081528881600481855afa908115610650576000916106a3575b5015610679578582511690610480898551604051809381927f26184e150000000000000000000000000000000000000000000000000000000097888452600484016020909392919373ffffffffffffffffffffffffffffffffffffffff60408201951681520152565b0381855afa9081156106505760009161065c575b5060038110156105f4576104cc5760046040517f4a61fb30000000000000000000000000000000000000000000000000000000008152fd5b9151925160405191825292861673ffffffffffffffffffffffffffffffffffffffff16600482015260248101929092528690829081806044810103915afa90811561065057600091610623575b5060038110156105f4576001036105ca5761053b83835116855190339061278c565b85600052845260046040600020017901000000000000000000000000000000000000000000000000007fffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffff825416179055511690519160405193845283015260408201527fded355a1cb9a51166ec4af4cae2650c92b84521935c3b1f660205c7a2743354f60603392a260018055005b60046040517fc7bc740f000000000000000000000000000000000000000000000000000000008152fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b6106439150863d8811610649575b61063b8183612375565b810190612418565b87610519565b503d610631565b6040513d6000823e3d90fd5b61067391508a3d8c116106495761063b8183612375565b8b610494565b60046040517fd583e5ef000000000000000000000000000000000000000000000000000000008152fd5b6106c39150893d8b116106c9575b6106bb8183612375565b810190612400565b8a610417565b503d6106b1565b60046040517f646cf558000000000000000000000000000000000000000000000000000000008152fd5b60046040517fe3943568000000000000000000000000000000000000000000000000000000008152fd5b346102945760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102945761001b60043561076161226b565b9080600052600060205261077c60016040600020015461248c565b61255c565b346102945760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261029457602073ffffffffffffffffffffffffffffffffffffffff60035416604051908152f35b346102945760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102945760206040517f28d695c7dfc0dc20c36b38cc22e861d8a3c0da73ef3975e85a4bf12193642a5c8152f35b346102945760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261029457610863612248565b61086b612430565b60045473ffffffffffffffffffffffffffffffffffffffff808316929190811683156109365783811461090c576040805173ffffffffffffffffffffffffffffffffffffffff92831681529390911660208401527fffffffffffffffffffffffff0000000000000000000000000000000000000000927f2d025324f0a785e8c12d0a0d91a9caa49df4ef20ff87e0df7213a1d4f3157beb9190a11617600455005b60046040517f2620eb3a000000000000000000000000000000000000000000000000000000008152fd5b60046040517fd92e233d000000000000000000000000000000000000000000000000000000008152fd5b346102945760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102945760043567ffffffffffffffff8111610294576109af9036906004016122d5565b906109b8612430565b60005b8281106109c457005b6109d26101ec828585612306565b9073ffffffffffffffffffffffffffffffffffffffff600254166040517f095ea7b30000000000000000000000000000000000000000000000000000000060208201528160248201527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60448201526044815280608081011067ffffffffffffffff608083011117610b23576080810160405273ffffffffffffffffffffffffffffffffffffffff841660008083516020850182855af190610a926128a6565b82610b5d575b5081610b52575b5015610ab2575b505060019150016109bb565b604051917f095ea7b300000000000000000000000000000000000000000000000000000000602084015260248301526000604483015260448252608082019382851067ffffffffffffffff861117610b2357610b17610b1c9360019660405282612904565b612904565b8480610aa6565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b90503b151587610a9f565b80519192508115918215610b75575b50509088610a98565b610b889250602080918301019101612400565b8880610b6c565b346102945760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261029457602060405160008152f35b346102945760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261029457610c0061226b565b600435600052600060205273ffffffffffffffffffffffffffffffffffffffff60406000209116600052602052602060ff604060002054166040519015158152f35b346102945760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261029457610100610c7c612248565b73ffffffffffffffffffffffffffffffffffffffff8091166000526006602052604060002060243560005260205260ff604060002082815416926001820154916002810154600483600384015416920154936040519687526020870152604086015260608501528116608084015263ffffffff8160a01c1660a0840152818160c01c16151560c084015260c81c16151560e0820152f35b346102945760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102945760206040517fdf8b4c520ffe197c5343c6f5aec59570151ef9a492f2c624fd45ddde6135ec428152f35b346102945760c07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102945760043567ffffffffffffffff811161029457610dbb9036906004016122d5565b90610dc461228e565b9167ffffffffffffffff60443511610294573660236044350112156102945767ffffffffffffffff6044356004013511610294573660246044356004013560061b604435010111610294576064351515606435036102945773ffffffffffffffffffffffffffffffffffffffff60843516608435036102945773ffffffffffffffffffffffffffffffffffffffff6002541633036114db5773ffffffffffffffffffffffffffffffffffffffff60843516156109365763ffffffff8316600052600860205260ff604060002054166114b15780156114875760443560040135810361145d5760005b818110610eb557005b610ec0818385612306565b359073ffffffffffffffffffffffffffffffffffffffff821682036102945773ffffffffffffffffffffffffffffffffffffffff8216156109365773ffffffffffffffffffffffffffffffffffffffff82166000526005602052604060002063ffffffff86166000526020526040600020916044356004013582101561142e5760407fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc8360061b60443501360301126102945760405180604081011067ffffffffffffffff604083011117610b235760408101604052610fa960248460061b60443501016122b4565b80825260448460061b8135010135908160208401526064356000146113f7575050602081015193620493e09085828102048214861517156113c85773ffffffffffffffffffffffffffffffffffffffff8351166000526020526040600020611019620f42408388020482546123f3565b905573ffffffffffffffffffffffffffffffffffffffff831660005260076020526040600020908154957fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff87146113c85786620f4240936001809901905560e073ffffffffffffffffffffffffffffffffffffffff8651166110a386868602046020890151612337565b604051916110b083612358565b8252602082015260a435604082015273ffffffffffffffffffffffffffffffffffffffff60843516606082015273ffffffffffffffffffffffffffffffffffffffff8816608082015263ffffffff8d1660a0820152606435151560c082015260008282015273ffffffffffffffffffffffffffffffffffffffff881660005260066020526040600020836000526020526004604060002073ffffffffffffffffffffffffffffffffffffffff8351167fffffffffffffffffffffffff0000000000000000000000000000000000000000908183541617825560208401518d83015560408401516002830155600382019073ffffffffffffffffffffffffffffffffffffffff606086015116908254161790550173ffffffffffffffffffffffffffffffffffffffff60808301511681549077ffffffff000000000000000000000000000000000000000060a085015160a01b1678ff00000000000000000000000000000000000000000000000060c0860151151560c01b16917fffffffffffff000000000000000000000000000000000000000000000000000079ff0000000000000000000000000000000000000000000000000088880151151560c81b16941617171717905560405192835273ffffffffffffffffffffffffffffffffffffffff8151166020840152602081015160408401526040810151606084015273ffffffffffffffffffffffffffffffffffffffff606082015116608084015273ffffffffffffffffffffffffffffffffffffffff60808201511660a084015263ffffffff60a08201511660c084015260c0810151151582840152015115156101008201527fb553473e6ca683f7cd71c7abd078d8fe7984e4f7b475c96d7e2fad4244d0adf161012073ffffffffffffffffffffffffffffffffffffffff881692a2020460208201525b60206040519173ffffffffffffffffffffffffffffffffffffffff8151168352015160208201527fe58012850783f5239c792b9394f0264e9c95cf3882980249ae8efc411a921dee604073ffffffffffffffffffffffffffffffffffffffff63ffffffff8a16941692a301610eac565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b9473ffffffffffffffffffffffffffffffffffffffff6001961660005260205261142760406000209182546123f3565b9055611358565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60046040517fa24a13a6000000000000000000000000000000000000000000000000000000008152fd5b60046040517f5cb045db000000000000000000000000000000000000000000000000000000008152fd5b60046040517f2f516035000000000000000000000000000000000000000000000000000000008152fd5b60046040517f92ed0e81000000000000000000000000000000000000000000000000000000008152fd5b346102945760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102945760043573ffffffffffffffffffffffffffffffffffffffff8082168092036102945761155e612430565b8115610936576002549081169082821461090c576040805173ffffffffffffffffffffffffffffffffffffffff938416815292841660208401527fffffffffffffffffffffffff0000000000000000000000000000000000000000927f42e6b4d0f422db8acba71d0435d0dd4e46fadb4a2d99683b66eded85126fb2859190a11617600255005b34610294576101607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102945760243567ffffffffffffffff8111610294576116359036906004016122d5565b9060443567ffffffffffffffff8111610294576116569036906004016122d5565b6080529160643567ffffffffffffffff81116102945761167a9036906004016122d5565b92909160843567ffffffffffffffff81116102945761169d9036906004016122d5565b939060a43567ffffffffffffffff8111610294576116bf9036906004016122d5565b92909663ffffffff60c4351660c435036102945760e43567ffffffffffffffff8111610294576116f39036906004016122d5565b94909560ff610104351661010435036102945761170e6125fd565b61171960c435612638565b8515611c3f57888614801590611c35575b8015611c2b575b8015611c21575b61145d576040513360601b60208201527fffffffff0000000000000000000000000000000000000000000000000000000060c43560e01b166034820152611783603882018b88612758565b889060005b898110611bfb575060209150600435815201818c60005b868110611bc45750506117b66117e292858d612758565b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101835282612375565b6020815191012073ffffffffffffffffffffffffffffffffffffffff60045416907f19457468657265756d205369676e6564204d6573736167653a0a333200000000600052601c5273ffffffffffffffffffffffffffffffffffffffff61186461185b610144356101243561010435603c60002061299d565b90929192612a2e565b1603611b9a57336000526005602052604060002063ffffffff60c4351660005260205260406000209560005b83811061189d5760018055005b6118ab6101ec82868f612306565b906118b781858d612306565b35916118c482858d612306565b359060ff82168203610294578f938b8f938c906118e2878d8f612306565b359273ffffffffffffffffffffffffffffffffffffffff861660005260205260406000208054908115611b8957818611611b8957611924916000879255612337565b9573ffffffffffffffffffffffffffffffffffffffff600254169273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee73ffffffffffffffffffffffffffffffffffffffff881614600014611ab3575050813b156102945760009360ff916119fa6040519a8b96879586947fade1721e00000000000000000000000000000000000000000000000000000000865273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee60048701528a6024870152166044850152846064850152608484015261010060a4840152610104830190608051906123b6565b3360c483015263ffffffff60c4351660e483015203925af193841561065057600194611aa4575b505b81611a32575b50505b01611890565b611a3d82338361278c565b7f4978506686bd9ae370ab4cd6b1b3093dad6682e7840df229a6534e9dc4ba522360405180611a9a63ffffffff60c43516953395836020909392919373ffffffffffffffffffffffffffffffffffffffff60408201951681520152565b0390a38e80611a29565b611aad90612344565b38611a21565b611ac39189919a9596939a612306565b3592823b156102945785611b4d60009692879373ffffffffffffffffffffffffffffffffffffffff9560ff6040519e8f9a8b998a987fade1721e000000000000000000000000000000000000000000000000000000008a5216600489015260248801521660448601526064850152608484015261010060a4840152610104830190608051906123b6565b3360c483015263ffffffff60c4351660e483015203925af193841561065057600194611b7a575b50611a23565b611b8390612344565b38611b74565b505050505050505060019150611a2c565b60046040517f8baa579f000000000000000000000000000000000000000000000000000000008152fd5b91509160208060019273ffffffffffffffffffffffffffffffffffffffff611beb876122b4565b168152019301910190839161179f565b9082359060ff821682036102945760ff9190911681526020928301920190600101611788565b5082811415611738565b5080821415611731565b508189141561172a565b60046040517f0f59b9ff000000000000000000000000000000000000000000000000000000008152fd5b346102945760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261029457602073ffffffffffffffffffffffffffffffffffffffff60045416604051908152f35b346102945760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102945763ffffffff611cf76122a1565b166000526008602052602060ff604060002054166040519015158152f35b346102945760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102945760043573ffffffffffffffffffffffffffffffffffffffff80821680920361029457611d6e612430565b8115610936576003549081169082821461090c576040805173ffffffffffffffffffffffffffffffffffffffff938416815292841660208401527fffffffffffffffffffffffff0000000000000000000000000000000000000000927e417c05d994b1f17cbd0a35478a8d12a4dee347b83ac2ee18d52add18e0b0619190a11617600355005b346102945760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261029457611e2b6122a1565b60243590811515809203610294573360009081527f344c38c63afa63cc0790d03fd9f5e1b1e0cb81e2f69d7bd71f512be2ba8de6de60205260409020547f28d695c7dfc0dc20c36b38cc22e861d8a3c0da73ef3975e85a4bf12193642a5c9060ff1615611f22575063ffffffff1680600052600860205260ff60406000205416151582811461090c5760407f747f56458041cea2ada41de00c95f1a8dc602dfa334765aafe548611948502d2918151908152846020820152a1600052600860205260406000209060ff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008354169116179055600080f35b604490604051907fe2517d3f0000000000000000000000000000000000000000000000000000000082523360048301526024820152fd5b346102945760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102945773ffffffffffffffffffffffffffffffffffffffff611fa5612248565b1660005260076020526020604060002054604051908152f35b346102945760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261029457611ff561226b565b3373ffffffffffffffffffffffffffffffffffffffff82160361201e5761001b9060043561255c565b60046040517f6697b232000000000000000000000000000000000000000000000000000000008152fd5b346102945760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102945761001b60043561208561226b565b908060005260006020526120a060016040600020015461248c565b6124b2565b346102945760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102945760043560005260006020526020600160406000200154604051908152f35b346102945760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261029457612129612248565b61213161228e565b6044359173ffffffffffffffffffffffffffffffffffffffff908184168094036102945716600052600560205263ffffffff604060002091166000526020526040600020906000526020526020604060002054604051908152f35b346102945760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261029457600435907fffffffff00000000000000000000000000000000000000000000000000000000821680920361029457817f7965db0b000000000000000000000000000000000000000000000000000000006020931490811561221e575b5015158152f35b7f01ffc9a70000000000000000000000000000000000000000000000000000000091501483612217565b6004359073ffffffffffffffffffffffffffffffffffffffff8216820361029457565b6024359073ffffffffffffffffffffffffffffffffffffffff8216820361029457565b6024359063ffffffff8216820361029457565b6004359063ffffffff8216820361029457565b359073ffffffffffffffffffffffffffffffffffffffff8216820361029457565b9181601f840112156102945782359167ffffffffffffffff8311610294576020808501948460051b01011161029457565b919081101561142e5760051b0190565b3573ffffffffffffffffffffffffffffffffffffffff811681036102945790565b919082039182116113c857565b67ffffffffffffffff8111610b2357604052565b610100810190811067ffffffffffffffff821117610b2357604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff821117610b2357604052565b90918281527f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83116102945760209260051b809284830137010190565b919082018092116113c857565b90816020910312610294575180151581036102945790565b90816020910312610294575160038110156102945790565b3360009081527f5cbfc8ee58ca47855df7bcf648dd304ddb6b932f9b87878bdf6318d7ec7ee5b760205260409020547fdf8b4c520ffe197c5343c6f5aec59570151ef9a492f2c624fd45ddde6135ec429060ff1615611f225750565b80600052600060205260406000203360005260205260ff6040600020541615611f225750565b906000918083528260205273ffffffffffffffffffffffffffffffffffffffff6040842092169182845260205260ff604084205416156000146125575780835282602052604083208284526020526040832060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008254161790557f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d339380a4600190565b505090565b906000918083528260205273ffffffffffffffffffffffffffffffffffffffff6040842092169182845260205260ff604084205416600014612557578083528260205260408320828452602052604083207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0081541690557ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b339380a4600190565b60026001541461260e576002600155565b60046040517f3ee5aeb5000000000000000000000000000000000000000000000000000000008152fd5b63ffffffff16600090808252600860205260ff6040832054161561272e57606073ffffffffffffffffffffffffffffffffffffffff60025416916024604051809481937f79a6d51f00000000000000000000000000000000000000000000000000000000835260048301525afa9182156127225780926126e7575b505042106126bd57565b60046040517fc43172d2000000000000000000000000000000000000000000000000000000008152fd5b9091506060823d60601161271a575b8161270360609383612375565b8101031261271757506020015138806126b3565b80fd5b3d91506126f6565b604051903d90823e3d90fd5b60046040517fde699550000000000000000000000000000000000000000000000000000000008152fd5b91907f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116102945760051b809282370190565b90919073ffffffffffffffffffffffffffffffffffffffff9081811673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee03612840575081471061281057600092839283928392165af16127de6128a6565b50156127e657565b60046040517f1425ea42000000000000000000000000000000000000000000000000000000008152fd5b60246040517fcd786059000000000000000000000000000000000000000000000000000000008152306004820152fd5b6040517fa9059cbb00000000000000000000000000000000000000000000000000000000602082015273ffffffffffffffffffffffffffffffffffffffff949094166024850152604480850193909352918352506128a49190610b17606483612375565b565b3d156128ff573d9067ffffffffffffffff8211610b2357604051916128f360207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8401160184612375565b82523d6000602084013e565b606090565b60008073ffffffffffffffffffffffffffffffffffffffff61293b93169360208151910182865af16129346128a6565b9083612ae6565b8051908115159182612982575b50506129515750565b602490604051907f5274afe70000000000000000000000000000000000000000000000000000000082526004820152fd5b6129959250602080918301019101612400565b153880612948565b91907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08411612a2257926020929160ff608095604051948552168484015260408301526060820152600092839182805260015afa1561272257805173ffffffffffffffffffffffffffffffffffffffff811615612a1957918190565b50809160019190565b50505060009160039190565b60048110156105f45780612a40575050565b60018103612a725760046040517ff645eedf000000000000000000000000000000000000000000000000000000008152fd5b60028103612aab57602482604051907ffce698f70000000000000000000000000000000000000000000000000000000082526004820152fd5b600314612ab55750565b602490604051907fd78bce0c0000000000000000000000000000000000000000000000000000000082526004820152fd5b90612afb57508051156127e657805190602001fd5b81511580612b53575b612b0c575090565b60249073ffffffffffffffffffffffffffffffffffffffff604051917f9996b315000000000000000000000000000000000000000000000000000000008352166004820152fd5b50803b15612b0456fea2646970667358221220bdc96206e754b6c45ca73f8f01069b03ddbb5faa2fde29dda0d05f8ce89b92f464736f6c63430008190033

Verified Source Code Full Match

Compiler: v0.8.25+commit.b61c2a91 EVM: paris Optimization: Yes (1000000 runs)
AccessControl.sol 209 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)

pragma solidity ^0.8.20;

import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```solidity
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```solidity
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
 * to enforce additional security measures for this role.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address account => bool) hasRole;
        bytes32 adminRole;
    }

    mapping(bytes32 role => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with an {AccessControlUnauthorizedAccount} error including the required role.
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual returns (bool) {
        return _roles[role].hasRole[account];
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
     * is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
     * is missing `role`.
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert AccessControlUnauthorizedAccount(account, role);
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address callerConfirmation) public virtual {
        if (callerConfirmation != _msgSender()) {
            revert AccessControlBadConfirmation();
        }

        _revokeRole(role, callerConfirmation);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
        if (!hasRole(role, account)) {
            _roles[role].hasRole[account] = true;
            emit RoleGranted(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
        if (hasRole(role, account)) {
            _roles[role].hasRole[account] = false;
            emit RoleRevoked(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }
}
IAccessControl.sol 98 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/IAccessControl.sol)

pragma solidity ^0.8.20;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev The `account` is missing a role.
     */
    error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);

    /**
     * @dev The caller of a function is not the expected one.
     *
     * NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
     */
    error AccessControlBadConfirmation();

    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     */
    function renounceRole(bytes32 role, address callerConfirmation) external;
}
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)
        }
    }
}
ERC165.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
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));
    }
}
Claims.sol 452 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import { IERC20, SafeERC20, Token } from "./Library/Token.sol";
import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.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";

import { IPreSale } from "./ILockup.sol";
import { IClaims, ClaimInfo } from "../contracts/IClaims.sol";
import { IInsurance, Status } from "./IInsurance.sol";

import { ETH, AlreadyClaimed, InvalidData, ArrayLengthMismatch, ZeroAddress, IdenticalValue, ZeroLengthArray, InvalidSignature, PPM, OnlyPresale, THIRTY_PERCENT_PPM } from "./Common.sol";

/// @title Claims contract
/// @notice Implements the claiming of the leader's commissions
contract Claims is IClaims, AccessControl, ReentrancyGuard {
    using SafeERC20 for IERC20;
    using Token for IERC20;

    /// @member token The token address
    /// @member amount The token amount
    /// @member buyerIndex The index of the user who purchases insurance
    /// @member buyer The  user who purchases insurance
    /// @member leader The leader address
    /// @member isInsured The status of insurance
    /// @member isClaimed The access status of insurance Whether the insurance has been claimed or not
    struct Info {
        IERC20 token;
        uint256 amount;
        uint256 buyerIndex;
        address buyer;
        address leader;
        uint32 round;
        bool isInsured;
        bool isClaimed;
    }

    /// @notice Returns the identifier of the COMMISSIONS_MANAGER role
    bytes32 public constant COMMISSIONS_MANAGER = keccak256("COMMISSIONS_MANAGER");

    /// @notice Returns the identifier of the ADMIN_ROLE role
    bytes32 public constant ADMIN_ROLE = keccak256("ADMIN");

    /// @notice Returns the address of the presale contract
    IPreSale public presale;

    /// @notice Returns the address of the insurance contract
    IInsurance public insuranceContract;

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

    /// @notice Stores the claim amount of token in a round of the user
    mapping(address => mapping(uint32 => mapping(IERC20 => uint256))) public pendingClaims;

    /// @notice Stores the claim amount of token against the index of the user
    mapping(address => mapping(uint256 => Info)) public pendingClaimsInsurance;

    /// @notice Gives us leader insurance index
    mapping(address => uint256) public leaderIndex;

    /// @notice Stores the enabled/disabled status of a round
    mapping(uint32 => bool) public isEnabled;

    /// @dev Emitted when claim amount is set for the addresses
    event ClaimSet(address indexed to, uint32 indexed round, ClaimInfo claimInfo);

    /// @dev Emitted when claim amount is claimed
    event FundsClaimed(address indexed by, uint32 indexed round, IERC20 token, uint256 amount);

    /// @dev Emitted when claim amount is claimed
    event TokensClaimed(address indexed by, uint32 indexed round, IERC20 token, uint256 amount);

    /// @dev Emitted when claim amount is claimed
    event InsuranceClaimed(address indexed by, uint32 indexed round, IERC20 token, uint256 amount);

    /// @dev Emitted when insurance claim amount is set for the addresses
    event ClaimSetInsurance(address indexed to, uint256 index, Info claimInfo);

    /// @dev Emitted when claim access changes for the round
    event RoundEnableUpdated(bool oldAccess, bool newAccess);

    /// @dev Emitted when token presale contract is updated
    event PresaleUpdated(address prevAddress, address newAddress);

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

    /// @dev Emitted when insurance funds are claimed
    event FundsClaimedInsurance(address indexed by, uint256 index, IERC20 token, uint256 amount);

    /// @dev Emitted when insurance funds are claimed
    event InsuranceContractUpdated(address prevAddress, address newAddress);

    /// @notice Thrown when claiming before round ends
    error RoundNotEnded();

    /// @notice Thrown when round is not Enabled
    error RoundNotEnabled();

    /// @notice Thrown when caller is not a leader
    error CallerNotLeader();

    /// @notice Thrown when insurance is not activated
    error InsuranceNotActivated();

    /// @notice Thrown when buyer has not claimed insurance or tokens
    error BuyerHasNotClaimedInsuranceOrTokens();

    /// @notice Thrown when commissions manager wants to set claim while claim enable
    error WaitForRoundDisable();

    /// @notice Thrown when buyer has claimed insurance
    error BuyerClaimedInsurance();

    /// @dev Constructor
    /// @param signerAddress The signer wallet
    constructor(address signerAddress) {
        if (signerAddress == address(0)) {
            revert ZeroAddress();
        }

        signerWallet = signerAddress;
        _setRoleAdmin(ADMIN_ROLE, ADMIN_ROLE);
        _setRoleAdmin(COMMISSIONS_MANAGER, ADMIN_ROLE);
        _grantRole(ADMIN_ROLE, msg.sender);
    }

    /// @inheritdoc IClaims
    function addClaimInfo(
        address[] calldata to,
        uint32 round,
        ClaimInfo[] calldata claims,
        bool isInsured,
        address buyer,
        uint256 insuranceIndex
    ) external {
        if (msg.sender != address(presale)) {
            revert OnlyPresale();
        }

        if (buyer == address(0)) {
            revert ZeroAddress();
        }

        if (isEnabled[round]) {
            revert WaitForRoundDisable();
        }

        uint256 toLength = to.length;

        if (toLength == 0) {
            revert InvalidData();
        }

        if (toLength != claims.length) {
            revert ArrayLengthMismatch();
        }
        for (uint256 i; i < toLength; ++i) {
            address leader = to[i];

            if (leader == address(0)) {
                revert ZeroAddress();
            }

            mapping(IERC20 => uint256) storage claimInfo = pendingClaims[leader][round];
            ClaimInfo[] calldata toClaim = claims;
            ClaimInfo memory amount = toClaim[i];

            if (isInsured) {
                uint256 leadersCommision = (amount.amount * THIRTY_PERCENT_PPM) / PPM;
                claimInfo[amount.token] += leadersCommision;

                uint256 index = leaderIndex[leader]++;
                Info memory info = Info({
                    token: amount.token,
                    amount: amount.amount - leadersCommision,
                    isInsured: isInsured,
                    buyer: buyer,
                    leader: leader,
                    buyerIndex: insuranceIndex,
                    round: round,
                    isClaimed: false
                });

                pendingClaimsInsurance[leader][index] = info;
                emit ClaimSetInsurance({ to: leader, index: index, claimInfo: info });
                amount.amount = leadersCommision;
            } else {
                claimInfo[amount.token] += amount.amount;
            }

            emit ClaimSet({ to: leader, round: round, claimInfo: amount });
        }
    }

    /// @notice Changes presale contract address
    /// @param newPresale The address of the new PreSale contract
    function updatePreSaleAddress(IPreSale newPresale) external onlyRole(ADMIN_ROLE) {
        if (address(newPresale) == address(0)) {
            revert ZeroAddress();
        }
        if (presale == newPresale) {
            revert IdenticalValue();
        }
        emit PresaleUpdated({ prevAddress: address(presale), newAddress: address(newPresale) });
        presale = newPresale;
    }

    /// @notice Updates insurance contract address
    /// @param insuranceAddress The address of the insurance contract
    function updateInsuranceContract(IInsurance insuranceAddress) external onlyRole(ADMIN_ROLE) {
        if (address(insuranceAddress) == address(0)) {
            revert ZeroAddress();
        }

        if (insuranceContract == insuranceAddress) {
            revert IdenticalValue();
        }

        emit InsuranceContractUpdated({
            prevAddress: address(insuranceContract),
            newAddress: address(insuranceAddress)
        });
        insuranceContract = insuranceAddress;
    }

    /// @notice Changes the claim access of the contract
    /// @param round The round number of which access is changed
    /// @param status The access status of the round
    function enableClaims(uint32 round, bool status) external onlyRole(COMMISSIONS_MANAGER) {
        bool oldAccess = isEnabled[round];
        if (oldAccess == status) {
            revert IdenticalValue();
        }
        emit RoundEnableUpdated({ oldAccess: oldAccess, newAccess: status });
        isEnabled[round] = status;
    }

    /// @notice Gives max allowance of tokens to presale contract
    /// @param tokens List of tokens to approve
    function approveAllowance(IERC20[] calldata tokens) external onlyRole(ADMIN_ROLE) {
        uint256 tokensLength = tokens.length;
        for (uint256 i; i < tokensLength; ++i) {
            tokens[i].forceApprove(address(presale), type(uint256).max);
        }
    }

    /// @notice Claims the amount in a given round
    /// @param round The round in which you want to claim
    /// @param tokens The addresses of the token to be claimed
    function claim(uint32 round, IERC20[] calldata tokens) external nonReentrant {
        _checkRoundAndTime(round);
        mapping(IERC20 => uint256) storage claimInfo = pendingClaims[msg.sender][round];
        uint256 tokensLength = tokens.length;
        for (uint256 i; i < tokensLength; ++i) {
            IERC20 token = tokens[i];
            uint256 amount = claimInfo[token];
            if (amount == 0) {
                continue;
            }
            delete claimInfo[token];
            token.checkTokenAndTransferAmount(msg.sender, amount);
            emit FundsClaimed({ by: msg.sender, round: round, token: token, amount: amount });
        }
    }

    /// @notice Claims the amount against the given index
    /// @param index The index you want to claim
    function claimInsurance(uint256 index) external nonReentrant {
        mapping(uint256 => Info) storage pendingClaim = pendingClaimsInsurance[msg.sender];
        Info memory info = pendingClaim[index];

        if (msg.sender != info.leader) {
            revert CallerNotLeader();
        }

        if (info.isClaimed) {
            revert AlreadyClaimed();
        }

        if (!insuranceContract.isActivated()) {
            revert InsuranceNotActivated();
        }

        if (insuranceContract.isInsuranceClaimed(info.buyer, info.buyerIndex) == Status.Pending) {
            revert BuyerHasNotClaimedInsuranceOrTokens();
        } else if (insuranceContract.isInsuranceClaimed(info.buyer, info.buyerIndex) == Status.TokensClaimed) {
            info.token.checkTokenAndTransferAmount(msg.sender, info.amount);
        } else {
            revert BuyerClaimedInsurance();
        }

        pendingClaim[index].isClaimed = true;

        emit FundsClaimedInsurance({ by: msg.sender, index: index, token: info.token, amount: info.amount });
    }

    /// @notice Purchases presale token with claim amounts
    /// @param deadline The signature deadline
    /// @param amounts The purchase amounts
    /// @param indexes The indexes at which user has locked tokens
    /// @param minAmountsToken The minimum amounts of tokens recipient will get
    /// @param tokenPrices The current prices of the tokens in 10 decimals
    /// @param tokens The addresses of the tokens
    /// @param round The round in which user will purchase
    /// @param normalizationFactors The values to handle decimals
    /// @param v The `v` signature parameter
    /// @param r The `r` signature parameter
    /// @param s The `s` signature parameter
    function purchaseWithClaim(
        uint256 deadline,
        uint256[] calldata amounts,
        uint256[] calldata indexes,
        uint256[] calldata minAmountsToken,
        uint256[] calldata tokenPrices,
        IERC20[] calldata tokens,
        uint32 round,
        uint8[] calldata normalizationFactors,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external nonReentrant {
        _checkRoundAndTime(round);
        if (normalizationFactors.length == 0) {
            revert ZeroLengthArray();
        }
        uint256 tokensLength = tokens.length;
        if (
            normalizationFactors.length != tokenPrices.length ||
            tokenPrices.length != tokensLength ||
            tokensLength != amounts.length ||
            amounts.length != minAmountsToken.length
        ) {
            revert ArrayLengthMismatch();
        }
        _verifyPurchaseWithClaim(
            msg.sender,
            round,
            deadline,
            tokenPrices,
            normalizationFactors,
            tokens,
            amounts,
            v,
            r,
            s
        );

        mapping(IERC20 => uint256) storage claimInfo = pendingClaims[msg.sender][round];
        for (uint256 i; i < tokensLength; ++i) {
            IERC20 token = tokens[i];
            uint256 amountToPurchase = amounts[i];
            uint8 normalizationFactor = normalizationFactors[i];
            uint256 minAmountToken = minAmountsToken[i];
            uint256 amount = claimInfo[token];
            if (amount == 0) {
                continue;
            }
            if (amountToPurchase > amount) {
                continue;
            }
            delete claimInfo[token];
            uint256 remainingAmount = amount - amountToPurchase;
            IPreSale sale = presale;
            if (token == ETH) {
                sale.purchaseWithClaim{ value: amountToPurchase }(
                    ETH,
                    0,
                    normalizationFactor,
                    amountToPurchase,
                    minAmountToken,
                    indexes,
                    msg.sender,
                    round
                );
            } else {
                sale.purchaseWithClaim(
                    token,
                    tokenPrices[i],
                    normalizationFactor,
                    amountToPurchase,
                    minAmountToken,
                    indexes,
                    msg.sender,
                    round
                );
            }
            if (remainingAmount > 0) {
                token.checkTokenAndTransferAmount(msg.sender, remainingAmount);
                emit FundsClaimed({ by: msg.sender, round: round, token: token, amount: remainingAmount });
            }
        }
    }

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

    /// @dev Verifies round and time
    function _checkRoundAndTime(uint32 round) private view {
        if (!isEnabled[round]) {
            revert RoundNotEnabled();
        }
        (, uint256 endTime, ) = presale.rounds(round);
        if (block.timestamp < endTime) {
            revert RoundNotEnded();
        }
    }

    /// @dev Verifies the address that signed a hashed message (`hash`) with
    /// `signature`
    function _verifyMessage(bytes32 encodedMessageHash, uint8 v, bytes32 r, bytes32 s) private view {
        if (signerWallet != ECDSA.recover(MessageHashUtils.toEthSignedMessageHash(encodedMessageHash), v, r, s)) {
            revert InvalidSignature();
        }
    }

    /// @dev The tokenPrices,tokens are provided externally and therefore have to be verified by the trusted presale contract
    function _verifyPurchaseWithClaim(
        address by,
        uint32 round,
        uint256 deadline,
        uint256[] calldata tokenPrices,
        uint8[] calldata normalizationFactors,
        IERC20[] calldata tokens,
        uint256[] calldata amounts,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) private view {
        bytes32 encodedMessageHash = keccak256(
            abi.encodePacked(by, round, tokenPrices, normalizationFactors, deadline, tokens, amounts)
        );
        _verifyMessage(encodedMessageHash, v, r, s);
    }

    // This function is executed when a contract receives plain Ether (without data)
    receive() external payable {}
}
Common.sol 41 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

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

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

/// @dev The constant value helps in calculating percentages
uint256 constant PPM = 1_000_000;

/// @dev The constant value helps in calculating values
uint256 constant THIRTY_PERCENT_PPM = 300_000;

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

/// @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();

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

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

/// @notice Thrown when insurance is not activated
error InsuranceNotActivated();

/// @notice Thrown when user has already claimed insurance
error AlreadyClaimed();

/// @notice Thrown when caller is not presale contract
error OnlyPresale();

IClaims.sol 24 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/// @member token The token address
/// @member amount The token amount
struct ClaimInfo {
    IERC20 token;
    uint256 amount;
}

interface IClaims {
    /// @notice Sets claim token and amount in the given round
    /// @param to The address of the leader
    /// @param claims The claim token and amount of the leader
    function addClaimInfo(
        address[] calldata to,
        uint32 round,
        ClaimInfo[] calldata claims,
        bool inInsured,
        address buyer,
        uint256 insuranceIndex
    ) external;
}
IInsurance.sol 41 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/// @member token The token used to purchase
/// @member amount The amount purchased
/// @member presaleTokenAmount The token purchased
/// @member pendingCommissionLeader The pending commission leader amount, only released when user will claims insurance or tokens
/// @member pendingCommissionPlatform The pending commission platform amount, only released when user will claims insurance or tokens
struct InsuranceInfo {
    IERC20 token;
    uint256 amount;
    uint256 presaleTokenAmount;
    uint256 pendingCommissionLeader;
    uint256 pendingCommissionPlatform;
}

/// @member Pending The user claim is pending
/// @member TokensClaimed The user claimed tokens
/// @member InsuranceClaimed The user claimed insurance
enum Status {
    Pending,
    TokensClaimed,
    InsuranceClaimed
}

interface IInsurance {
    /// @notice Sets insurance token and token amount
    /// @param user The address of the user
    /// @param insuranceInfo The insurance token and amount of the user
    /// @return The insurance index for the user
    function addInsuranceInfo(address user, InsuranceInfo calldata insuranceInfo) external returns (uint256);

    /// @notice checks the status of the insurance
    function isActivated() external view returns (bool);

    /// @notice Sets insurance token and token amount
    /// @param user The address of the user
    /// @param index The index you want to claim
    function isInsuranceClaimed(address user, uint256 index) external view returns (Status);
}
ILockup.sol 40 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

interface ILockup {
    /// @notice Returns locked amount of user at given index
    /// @param user The address of the user
    /// @param index The index number at which user has locked amount
    function stakes(address user, uint256 index) external view returns (uint256 amount, uint256 endTime);
}

interface IPreSale is IRounds {
    /// @notice Purchases token with claim amount
    /// @param token The purchase token
    /// @param tokenPrice The current price of token in 10 decimals
    /// @param referenceNormalizationFactor The value to handle decimals
    /// @param amount The purchase amount
    /// @param minAmountToken The minimum amount of token recipient will get
    /// @param indexes The indexes at which user has locked tokens
    /// @param recipient The address of the recipient
    /// @param round The round in which user will purchase
    function purchaseWithClaim(
        IERC20 token,
        uint256 tokenPrice,
        uint8 referenceNormalizationFactor,
        uint256 amount,
        uint256 minAmountToken,
        uint256[] calldata indexes,
        address recipient,
        uint32 round
    ) external payable;

    /// @notice The address of the project wallet
    function projectWallet() external view returns (address);

    /// @notice The address of the platform wallet
    function platformWallet() external view returns (address);
}
IRounds.sol 7 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

interface IRounds {
    /// @notice Returns the round details of the round
    function rounds(uint32 round) external view returns (uint256 startTime, uint256 endTime, uint256 price);
}
Token.sol 36 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

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

import { ETH } from "../Common.sol";

library Token {
    using SafeERC20 for IERC20;
    using Address for address payable;

    /// @dev Transfers `amount` of 'ETH' or `token`. If `ETH` is transferring, the `amount`
    /// will be transferred from `this` contract instead of `from`.
    /// For `token`, it transferFrom 'amount' from `from` to `to`.
    function checkTokenAndTransferFromAmount(IERC20 token, address from, address to, uint256 amount) internal {
        // ETH is transferred
        if (token == ETH) {
            payable(to).sendValue(amount);
        } else {
            // ERC20 tokens are transferred
            token.safeTransferFrom(from, to, amount);
        }
    }

    /// @dev Transfers `amount` amount of `token` from the calling contract to `to`.
    function checkTokenAndTransferAmount(IERC20 token, address to, uint256 amount) internal {
        if (token == ETH) {
            payable(to).sendValue(amount);
        } else {
            token.safeTransfer(to, amount);
        }
    }
}

Read Contract

ADMIN_ROLE 0x75b238fc → bytes32
COMMISSIONS_MANAGER 0xcabb4549 → bytes32
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
insuranceContract 0xd012a5a8 → address
isEnabled 0x5f91d406 → bool
leaderIndex 0x39999247 → uint256
pendingClaims 0x054a68ad → uint256
pendingClaimsInsurance 0x79344714 → address, uint256, uint256, address, address, uint32, bool, bool
presale 0xfdea8e0b → address
signerWallet 0x64f0d35e → address
supportsInterface 0x01ffc9a7 → bool

Write Contract 12 functions

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

addClaimInfo 0xc6c70d96
address[] to
uint32 round
tuple[] claims
bool isInsured
address buyer
uint256 insuranceIndex
approveAllowance 0xa24e1788
address[] tokens
changeSigner 0xaad2b723
address newSigner
claim 0xff93be03
uint32 round
address[] tokens
claimInsurance 0xf85920d8
uint256 index
enableClaims 0x461c48cd
uint32 round
bool status
grantRole 0x2f2ff15d
bytes32 role
address account
purchaseWithClaim 0x65263303
uint256 deadline
uint256[] amounts
uint256[] indexes
uint256[] minAmountsToken
uint256[] tokenPrices
address[] tokens
uint32 round
uint8[] normalizationFactors
uint8 v
bytes32 r
bytes32 s
renounceRole 0x36568abe
bytes32 role
address callerConfirmation
revokeRole 0xd547741f
bytes32 role
address account
updateInsuranceContract 0x52b25efa
address insuranceAddress
updatePreSaleAddress 0x7188cb35
address newPresale

Recent Transactions

No transactions found for this address