Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x337C017BFaf42f91fd41d08f50C4b6102f3a0964
Balance 0 ETH
Nonce 1
Code Size 16206 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

16206 bytes
0x6080604052600436106102115760003560e01c8063086ce9b11461021d578063136021d9146102545780631dc7bf1a14610276578063254800d4146102a45780632897e742146102ba5780632c65169e146102d05780633197cbb6146102e357806333f76178146102f95780633f4ba83a1461032d5780634886f62c146103425780634c0f8054146103575780634e71d92d1461037757806353b7a59b1461038c5780635c975abb146103cd5780636059bcab146103f257806363b201171461041257806367ee767e146104285780636da185521461043d5780636ff1c9bc1461045d578063715018a61461047d578063762c8a801461049257806378e97925146104b25780637a01e2bd146104c85780637f6fb253146104e95780638456cb59146104ff578063845ddcb214610514578063855902b7146105565780638da5cb5b146105765780638e15f4731461058b578063a0a6e940146105a0578063a5917baf146105b5578063a694fc3a146105d5578063a91468ba146105f5578063a98ad46c14610615578063aee59ef514610649578063c2f403a314610669578063c7b7e92f14610689578063cff805ab146106a9578063d13782a7146106bf578063df46bf2f146106df578063e6242fe6146106ff578063e985e3671461071f578063eadd94ec14610753578063f2fde38b14610769578063f9fc5b2014610789578063ffa06b2a1461079e57600080fd5b3661021857005b600080fd5b34801561022957600080fd5b506102326107be565b6040805193151584526020840192909252908201526060015b60405180910390f35b34801561026057600080fd5b5061027461026f36600461365f565b610900565b005b34801561028257600080fd5b5061029661029136600461368f565b610a5d565b60405190815260200161024b565b3480156102b057600080fd5b5061029660085481565b3480156102c657600080fd5b50610296600c5481565b6102746102de36600461365f565b610bea565b3480156102ef57600080fd5b5061029660045481565b34801561030557600080fd5b506102967f0000000000000000000000000000000000000000000000000de0b6b3a764000081565b34801561033957600080fd5b50610274610d5c565b34801561034e57600080fd5b50610274610d6e565b34801561036357600080fd5b506102746103723660046136f3565b610db9565b34801561038357600080fd5b506102746110ab565b34801561039857600080fd5b506103c07f0000000000000000000000002c96e1a9da8c6bb74417741302725959df4d6bdc81565b60405161024b9190613796565b3480156103d957600080fd5b506103e261116d565b604051901515815260200161024b565b3480156103fe57600080fd5b5061027461040d3660046137aa565b61117d565b34801561041e57600080fd5b5061029660025481565b34801561043457600080fd5b50600c54610296565b34801561044957600080fd5b5061029661045836600461368f565b6114e8565b34801561046957600080fd5b5061027461047836600461383d565b611509565b34801561048957600080fd5b506102746115de565b34801561049e57600080fd5b506102746104ad36600461385f565b6115f0565b3480156104be57600080fd5b5061029660035481565b3480156104d457600080fd5b506010546103e290600160a01b900460ff1681565b3480156104f557600080fd5b5061029660075481565b34801561050b57600080fd5b50610274611830565b34801561052057600080fd5b5061053461052f36600461368f565b611840565b604080519485526020850193909352918301521515606082015260800161024b565b34801561056257600080fd5b50600f546103c0906001600160a01b031681565b34801561058257600080fd5b506103c061187d565b34801561059757600080fd5b5061029661188c565b3480156105ac57600080fd5b506102746119bf565b3480156105c157600080fd5b506010546103c0906001600160a01b031681565b3480156105e157600080fd5b506102746105f036600461368f565b611a40565b34801561060157600080fd5b5061027461061036600461383d565b611cc6565b34801561062157600080fd5b506103c07f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec781565b34801561065557600080fd5b5061029661066436600461368f565b611d69565b34801561067557600080fd5b5061027461068436600461383d565b611de8565b34801561069557600080fd5b506103c06106a436600461368f565b611e4f565b3480156106b557600080fd5b5061029660055481565b3480156106cb57600080fd5b506102746106da366004613914565b611e79565b3480156106eb57600080fd5b506102966106fa36600461368f565b612087565b34801561070b57600080fd5b5061027461071a366004613940565b612224565b34801561072b57600080fd5b506103c07f0000000000000000000000000524ce2aeae1b2add14b0f1ca99be51be813554581565b34801561075f57600080fd5b5061029660065481565b34801561077557600080fd5b5061027461078436600461383d565b6123c8565b34801561079557600080fd5b50610274612403565b3480156107aa57600080fd5b506102966107b936600461383d565b612579565b6000806000806107cc6125f1565b6009549091506107de906001906139c5565b81106107f1576000949093508492509050565b6107fc8160016139d8565b925060098381548110610811576108116139eb565b90600052602060002090600402016002015442106108a8576000818152600d6020526040902054600980548390811061084c5761084c6139eb565b906000526020600020906004020160000154811061086b57600061089b565b806009838154811061087f5761087f6139eb565b90600052602060002090600402016000015461089b91906139c5565b9250600194505050909192565b6000818152600d602052604090205460098054839081106108cb576108cb6139eb565b90600052602060002090600402016000015481106108f25750600194929350600092915050565b506000949093508492509050565b610908612760565b61091061278a565b600354421080610921575060045442115b1561093f5760405163b7b2409760e01b815260040160405180910390fd5b600061094a83610a5d565b9050600061095a600660126139c5565b61096590600a613ae8565b61096f9083613af4565b9050807f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec76001600160a01b031663dd62ed3e33306040518363ffffffff1660e01b81526004016109c0929190613b16565b602060405180830381865afa1580156109dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a019190613b30565b1015610a20576040516313be252b60e01b815260040160405180910390fd5b610a4d848483857f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec76127b0565b5050610a596001600055565b5050565b600081600003610a6f57506000919050565b60008281610a7b6125f1565b9050805b60095481108015610a905750600083115b15610bc157600060098281548110610aaa57610aaa6139eb565b60009182526020918290206040805160808101825260049093029091018054835260018101549383019390935260028301549082015260039091015460ff16151560608201819052909150610aff5750610bc1565b6000828152600d602052604081205482519091908210610b20576000610b2d565b8251610b2d9083906139c5565b905080600003610b3f57505050610baf565b6000818711610b4e5786610b50565b815b905060007f0000000000000000000000000000000000000000000000000de0b6b3a7640000856020015183610b859190613b49565b610b8f9190613af4565b9050610b9b818a6139d8565b9850610ba782896139c5565b975050505050505b80610bb981613b60565b915050610a7f565b508115610be15760405163162908e360e11b815260040160405180910390fd5b50909392505050565b610bf2612760565b610bfa61278a565b600354421080610c0b575060045442115b15610c295760405163b7b2409760e01b815260040160405180910390fd5b6000610c3483610a5d565b90506000610c4061188c565b9050600081610c516008600a613ae8565b610c5b9085613b49565b610c659190613af4565b905080341015610c8857604051631e9acf1760e31b815260040160405180910390fd5b610c968585838660006127b0565b80341115610d4f57600033610cab83346139c5565b604051600081818185875af1925050503d8060008114610ce7576040519150601f19603f3d011682016040523d82523d6000602084013e610cec565b606091505b5050905080610d0e576040516312171d8360e31b815260040160405180910390fd5b6000337fbed981748bbefb8366f3b5b6fae02e6299dfedfdd62ece2bc77ebb540b4727e7610d3c85346139c5565b60405190815260200160405180910390a3505b505050610a596001600055565b610d64612c77565b610d6c612ca9565b565b610d76612c77565b6010805460ff60a01b19169055610d8b6125f1565b600c556040517fd54b6ad1fb1b396d056c6d670ae90d40d49ad3253a6387dc5120c45bfc51453490600090a1565b610dc1612c77565b8483141580610dd05750828114155b15610dee5760405163162908e360e11b815260040160405180910390fd5b8460005b818110156110a157878782818110610e0c57610e0c6139eb565b9050602002013560001480610e395750858582818110610e2e57610e2e6139eb565b905060200201356000145b15610e575760405163162908e360e11b815260040160405180910390fd5b601054600160a01b900460ff16610f645742848483818110610e7b57610e7b6139eb565b9050602002013511610ea0576040516337bf561360e11b815260040160405180910390fd5b600954151580610eb05750600081115b15610f645760095460009015610ef95760098054610ed0906001906139c5565b81548110610ee057610ee06139eb565b9060005260206000209060040201600201549050610f1f565b8484610f066001856139c5565b818110610f1557610f156139eb565b9050602002013590505b610f2b610e10826139d8565b858584818110610f3d57610f3d6139eb565b9050602002013511610f62576040516337bf561360e11b815260040160405180910390fd5b505b600960405180608001604052808a8a85818110610f8357610f836139eb565b905060200201358152602001888885818110610fa157610fa16139eb565b905060200201358152602001868685818110610fbf57610fbf6139eb565b60209081029290920135835250600191810182905283548083018555600094855293819020835160049095020193845582015183820155604082015160028401556060909101516003909201805460ff19169215159290921790915560095461102891906139c5565b600080516020613eb9833981519152898984818110611049576110496139eb565b90506020020135888885818110611062576110626139eb565b9050602002013587878681811061107b5761107b6139eb565b9050602002013560405161109193929190613b79565b60405180910390a2600101610df2565b5050505050505050565b6110b3612760565b6110bb61278a565b6010546040805163e74f3fbb60e01b815290516000926001600160a01b03169163e74f3fbb916004808301926020929190829003018187875af1158015611106573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061112a9190613b30565b60405181815290915033907f896e034966eaaf1adc54acc0f257056febbd300c9e47182cf761982cf1f5e4309060200160405180910390a250610d6c6001600055565b600154600160a01b900460ff1690565b611185612c77565b601054600160a01b900460ff166111b75760405162461bcd60e51b81526004016111ae90613b8f565b60405180910390fd5b8382146112055760405162461bcd60e51b815260206004820152601c60248201527b084c2e8c6d040c2e4e4c2f2e640d8cadccee8d040dad2e6dac2e8c6d60231b60448201526064016111ae565b6010546001600160a01b031661122d5760405162461bcd60e51b81526004016111ae90613bc4565b600f546001600160a01b031661127f5760405162461bcd60e51b815260206004820152601760248201527614dd185ada5b99c81a185b991b195c881b9bdd081cd95d604a1b60448201526064016111ae565b60005b848110156114e05736600087878481811061129f5761129f6139eb565b90506020028101906112b19190613bf3565b915091503660008787868181106112ca576112ca6139eb565b90506020028101906112dc9190613bf3565b90925090508281146113005760405162461bcd60e51b81526004016111ae90613c3c565b60005b8381101561143a57600083838381811061131f5761131f6139eb565b9050602002013511156114325760105461138e906001600160a01b031684848481811061134e5761134e6139eb565b905060200201357f0000000000000000000000000524ce2aeae1b2add14b0f1ca99be51be81355456001600160a01b0316612cf89092919063ffffffff16565b6010546001600160a01b031663db72686f8686848181106113b1576113b16139eb565b90506020020160208101906113c6919061383d565b8585858181106113d8576113d86139eb565b9050602002013560016040518463ffffffff1660e01b81526004016113ff93929190613c6c565b600060405180830381600087803b15801561141957600080fd5b505af115801561142d573d6000803e3d6000fd5b505050505b600101611303565b50600080516020613ef98339815191528484848460405161145e9493929190613d09565b60405180910390a1600f546040516324b1f95d60e11b81526001600160a01b0390911690634963f2ba9061149e9087908790879087908d90600401613d3b565b600060405180830381600087803b1580156114b857600080fd5b505af11580156114cc573d6000803e3d6000fd5b505060019096019550611282945050505050565b505050505050565b600b81815481106114f857600080fd5b600091825260209091200154905081565b611511612c77565b6040516370a0823160e01b81526000906001600160a01b038316906370a0823190611540903090600401613796565b602060405180830381865afa15801561155d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115819190613b30565b90506115976001600160a01b0383163383612cf8565b816001600160a01b03167f5fafa99d0643513820be26656b45130b01e1c03062e1266bf36f88cbd3bd9695826040516115d291815260200190565b60405180910390a25050565b6115e6612c77565b610d6c6000612d55565b6115f8612c77565b601054600160a01b900460ff166116475760405162461bcd60e51b8152602060048201526013602482015272135a59dc985d1a5bdb8818dbdb5c1b195d1959606a1b60448201526064016111ae565b601080546001600160a01b0319166001600160a01b038c811691909117909155611696907f0000000000000000000000000524ce2aeae1b2add14b0f1ca99be51be8135545168b600019612da7565b6040516001600160a01b038b1690600080516020613e9983398151915290600090a2600f80546001600160a01b0319166001600160a01b038b16908117909155604051600080516020613ed983398151915290600090a286851461172e5760405162461bcd60e51b815260206004820152600f60248201526e098cadccee8d040dad2e6dac2e8c6d608b1b60448201526064016111ae565b60005b8781101561178a5786868281811061174b5761174b6139eb565b90506020020135600d60008b8b85818110611768576117686139eb565b6020908102929092013583525081019190915260400160002055600101611731565b507ffafb36bfc70fec5847d08cd4fe706e1b61acde99ce8a3539952683dcffeac382888888886040516117c09493929190613d75565b60405180910390a1600283905560068290556007819055600c8490556040805185815260208101859052908101839052606081018290527f1b8b1b6153efb08ce0c97e32b54551f89add96668adc8a89d8cd3f52681dca939060800160405180910390a150505050505050505050565b611838612c77565b610d6c612e2f565b6009818154811061185057600080fd5b60009182526020909120600490910201805460018201546002830154600390930154919350919060ff1684565b6001546001600160a01b031690565b60008060008060007f0000000000000000000000005f4ec3df9cbd43714fe2740f5e3616155c5b84196001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa1580156118f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119169190613da0565b9450945050935093506000831361193f5760405162bfc92160e01b815260040160405180910390fd5b8160000361196057604051630cd5fa0760e11b815260040160405180910390fd5b836001600160501b0316816001600160501b0316101561199357604051630cd5fa0760e11b815260040160405180910390fd5b610e106119a083426139c5565b1115610be157604051630cd5fa0760e11b815260040160405180910390fd5b6119c7612c77565b4260048190556008556010546001600160a01b031615610d6c5760105460405163126f854d60e01b81524260048201526001600160a01b039091169063126f854d90602401600060405180830381600087803b158015611a2657600080fd5b505af1158015611a3a573d6000803e3d6000fd5b50505050565b611a48612760565b611a5061278a565b80600003611a715760405163162908e360e11b815260040160405180910390fd5b600f546001600160a01b0316611a995760405162461bcd60e51b81526004016111ae90613df2565b6010546001600160a01b0316611ac15760405162461bcd60e51b81526004016111ae90613bc4565b60105460405163ba3f7dd560e01b81526000916001600160a01b03169063ba3f7dd590611af2903390600401613796565b602060405180830381865afa158015611b0f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b339190613b30565b905081811015611b5657604051631e9acf1760e31b815260040160405180910390fd5b6010546040516356addb6760e11b81526000916001600160a01b03169063ad5bb6ce90611b899033908790600401613e22565b6020604051808303816000875af1158015611ba8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bcc9190613e3b565b905080611c195760405162461bcd60e51b815260206004820152601b60248201527a11985a5b1959081d1bc818dbdb9d995c9d081d1bc81cdd185ad959602a1b60448201526064016111ae565b600f54604051635f2c16a160e01b81526001600160a01b0390911690635f2c16a190611c4b9033908790600401613e22565b600060405180830381600087803b158015611c6557600080fd5b505af1158015611c79573d6000803e3d6000fd5b505050508260076000828254611c8f91906139d8565b90915550506040518381523390600080516020613e798339815191529060200160405180910390a25050611cc36001600055565b50565b611cce612c77565b6001600160a01b038116611cf55760405163e6c4247b60e01b815260040160405180910390fd5b601080546001600160a01b0319166001600160a01b0383811691909117909155611d44907f0000000000000000000000000524ce2aeae1b2add14b0f1ca99be51be81355451682600019612da7565b6040516001600160a01b03821690600080516020613e9983398151915290600090a250565b6009546000908210611d8e5760405163e82a532960e01b815260040160405180910390fd5b60098281548110611da157611da16139eb565b600091825260209091206003600490920201015460ff16611dd55760405163e82a532960e01b815260040160405180910390fd5b506000908152600d602052604090205490565b611df0612c77565b6001600160a01b038116611e175760405163e6c4247b60e01b815260040160405180910390fd5b600f80546001600160a01b0319166001600160a01b038316908117909155604051600080516020613ed983398151915290600090a250565b600a8181548110611e5f57600080fd5b6000918252602090912001546001600160a01b0316905081565b611e81612c77565b821580611e8c575081155b15611eaa5760405163162908e360e11b815260040160405180910390fd5b428111611eca576040516337bf561360e11b815260040160405180910390fd5b60095415611f6e576009805460009190611ee6906001906139c5565b81548110611ef657611ef66139eb565b600091825260209182902060408051608081018252600490930290910180548352600181015493830193909352600283015490820181905260039092015460ff16151560608201529150611f4d90610e10906139d8565b8211611f6c576040516337bf561360e11b815260040160405180910390fd5b505b6040805160808101825284815260208101848152918101838152600160608301818152600980548084018255600082905294517f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af60049096029586015594517f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7b085015591517f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7b184015590517f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7b2909201805460ff191692151592909217909155905461205991906139c5565b600080516020613eb983398151915284848460405161207a93929190613b79565b60405180910390a2505050565b60008160000361209957506000919050565b600082816120a56125f1565b9050805b600954811080156120ba5750600083115b15610bc1576000600982815481106120d4576120d46139eb565b60009182526020918290206040805160808101825260049093029091018054835260018101549383019390935260028301549082015260039091015460ff161515606082018190529091506121295750610bc1565b6000828152600d602052604081205482519091906121489083906139c5565b90508060000361215a57505050612212565b60007f0000000000000000000000000000000000000000000000000de0b6b3a764000084602001518361218d9190613b49565b6121979190613af4565b90508087106121bd576121aa82896139d8565b97506121b681886139c5565b965061220d565b60208401516000906121ef7f0000000000000000000000000000000000000000000000000de0b6b3a76400008a613b49565b6121f99190613af4565b9050612205818a6139d8565b985060009750505b505050505b8061221c81613b60565b9150506120a9565b61222c612c77565b601054600160a01b900460ff166122555760405162461bcd60e51b81526004016111ae90613b8f565b8281146122745760405162461bcd60e51b81526004016111ae90613c3c565b6010546001600160a01b031661229c5760405162461bcd60e51b81526004016111ae90613bc4565b60005b838110156123965760008383838181106122bb576122bb6139eb565b90506020020135111561238e576010546122ea906001600160a01b031684848481811061134e5761134e6139eb565b6010546001600160a01b031663db72686f86868481811061230d5761230d6139eb565b9050602002016020810190612322919061383d565b858585818110612334576123346139eb565b9050602002013560016040518463ffffffff1660e01b815260040161235b93929190613c6c565b600060405180830381600087803b15801561237557600080fd5b505af1158015612389573d6000803e3d6000fd5b505050505b60010161229f565b50600080516020613ef9833981519152848484846040516123ba9493929190613d09565b60405180910390a150505050565b6123d0612c77565b6001600160a01b0381166123fa576000604051631e4fbdf760e01b81526004016111ae9190613796565b611cc381612d55565b61240b612c77565b60006124156125f1565b9050806000036124385760405163e82a532960e01b815260040160405180910390fd5b60006124456001836139c5565b905060006009828154811061245c5761245c6139eb565b60009182526020808320600490920290910154848352600d90915260408220549092509081831161248e576000612498565b61249882846139c5565b905080156125725780600986815481106124b4576124b46139eb565b906000526020600020906004020160000160008282546124d491906139d8565b9250508190555084600080516020613e59833981519152600987815481106124fe576124fe6139eb565b90600052602060002090600402016000015460098881548110612523576125236139eb565b90600052602060002090600402016001015460098981548110612548576125486139eb565b90600052602060002090600402016002015460405161256993929190613b79565b60405180910390a25b5050505050565b60105460405163e12f3a6160e01b81526000916001600160a01b03169063e12f3a61906125aa908590600401613796565b602060405180830381865afa1580156125c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125eb9190613b30565b92915050565b6000805b60095481101561272a57600060098281548110612614576126146139eb565b60009182526020918290206040805160808101825260049093029091018054835260018101549383019390935260028301549082015260039091015460ff161515606082018190529091506126695750612722565b80604001514210156126a857816000036126965760405163e82a532960e01b815260040160405180910390fd5b6126a16001836139c5565b9250505090565b6000828152600d6020526040902054815181101561271f576009546126cf906001906139c5565b8310801561270b575060096126e58460016139d8565b815481106126f5576126f56139eb565b9060005260206000209060040201600201544210155b15612717575050612722565b509092915050565b50505b6001016125f5565b506009541561274757600954612742906001906139c5565b905090565b60405163e82a532960e01b815260040160405180910390fd5b60026000540361278357604051633ee5aeb560e01b815260040160405180910390fd5b6002600055565b61279261116d565b15610d6c5760405163d93c066560e01b815260040160405180910390fd5b6010546001600160a01b03166127d85760405162461bcd60e51b81526004016111ae90613bc4565b6009548590600090815b6000841180156127f157508181105b15612968578061280081613b60565b915050600061280d612e72565b60095490915081106128325760405163e82a532960e01b815260040160405180910390fd5b6000818152600d6020526040812054600980549192918391908590811061285b5761285b6139eb565b906000526020600020906004020160000154116128795760006128a9565b816009848154811061288d5761288d6139eb565b9060005260206000209060040201600001546128a991906139c5565b9050806000036128c4576128bc83612fc1565b5050506127e2565b60008188116128d357876128d5565b815b905080600d600086815260200190815260200160002060008282546128fa91906139d8565b9091555061290a905081886139d8565b965061291681896139c5565b97506009848154811061292b5761292b6139eb565b906000526020600020906004020160000154600d6000868152602001908152602001600020541061295f5761295f84612fc1565b505050506127e2565b83156129c05760405162461bcd60e51b815260206004820152602160248201527f436f756c64206e6f742066756c66696c6c20656e7469726520707572636861736044820152606560f81b60648201526084016111ae565b888314612a095760405162461bcd60e51b81526020600482015260176024820152762a37b5b2b71031b0b631bab630ba34b7b71032b93937b960491b60448201526064016111ae565b8860026000828254612a1b91906139d8565b925050819055508560066000828254612a3491906139d8565b9091555050601054612a73906001600160a01b037f0000000000000000000000000524ce2aeae1b2add14b0f1ca99be51be8135545811691168b612cf8565b8715612bab57600f546001600160a01b0316612aa15760405162461bcd60e51b81526004016111ae90613df2565b60105460405163db72686f60e01b81526001600160a01b039091169063db72686f90612ad69033908d90600190600401613c6c565b600060405180830381600087803b158015612af057600080fd5b505af1158015612b04573d6000803e3d6000fd5b5050600f54604051635f2c16a160e01b81526001600160a01b039091169250635f2c16a19150612b3a9033908d90600401613e22565b600060405180830381600087803b158015612b5457600080fd5b505af1158015612b68573d6000803e3d6000fd5b505050508860076000828254612b7e91906139d8565b90915550506040518981523390600080516020613e798339815191529060200160405180910390a2612c13565b60105460405163db72686f60e01b81526001600160a01b039091169063db72686f90612be09033908d90600090600401613c6c565b600060405180830381600087803b158015612bfa57600080fd5b505af1158015612c0e573d6000803e3d6000fd5b505050505b612c1d8786613199565b846001600160a01b0316336001600160a01b03167f62e796e00a8e66154d78da76daae129635b4795a6e1b889f2caa6c5cea22ac688b8a8a604051612c6493929190613b79565b60405180910390a3505050505050505050565b33612c8061187d565b6001600160a01b031614610d6c573360405163118cdaa760e01b81526004016111ae9190613796565b612cb16134aa565b6001805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051612cee9190613796565b60405180910390a1565b612d5083846001600160a01b031663a9059cbb8585604051602401612d1e929190613e22565b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050506134cf565b505050565b600180546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b604051636eb1769f60e11b81526000906001600160a01b0385169063dd62ed3e90612dd89030908790600401613b16565b602060405180830381865afa158015612df5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e199190613b30565b9050611a3a8484612e2a85856139d8565b613537565b612e3761278a565b6001805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258612ce13390565b6000805b600954811015612fa457600060098281548110612e9557612e956139eb565b60009182526020918290206040805160808101825260049093029091018054835260018101549383019390935260028301549082015260039091015460ff16151560608201819052909150612eea5750612f9c565b80516000838152600d602052604081205460095492111591612f0e906001906139c5565b84108015612f4a57506009612f248560016139d8565b81548110612f3457612f346139eb565b9060005260206000209060040201600201544210155b905081158015612f6f5750600954612f64906001906139c5565b841480612f6f575080155b15612f7d5750919392505050565b8180612f865750805b15612f9357505050612f9c565b50919392505050565b600101612e76565b50600954612fb25750600090565b600954612742906001906139c5565b600954612fd0906001906139c5565b8110612fd95750565b6000612fe68260016139d8565b600c8190556000838152600d602052604081205460098054939450909285908110613013576130136139eb565b9060005260206000209060040201600001548210613032576000613062565b8160098581548110613046576130466139eb565b90600052602060002090600402016000015461306291906139c5565b9050801561313c57806009848154811061307e5761307e6139eb565b9060005260206000209060040201600001600082825461309e91906139d8565b9250508190555082600080516020613e59833981519152600985815481106130c8576130c86139eb565b906000526020600020906004020160000154600986815481106130ed576130ed6139eb565b90600052602060002090600402016001015460098781548110613112576131126139eb565b90600052602060002090600402016002015460405161313393929190613b79565b60405180910390a25b6000848152600e602052604090819020805460ff1916600117905551839085907f3b044e6dff45e4a421a26b22ad6cb6970b9ca356ffc6727fdd1f1e60d7c378ce9061318b9085815260200190565b60405180910390a350505050565b600a5460000361327a576001600160a01b0381166132455760007f0000000000000000000000002c96e1a9da8c6bb74417741302725959df4d6bdc6001600160a01b03168360405160006040518083038185875af1925050503d806000811461321e576040519150601f19603f3d011682016040523d82523d6000602084013e613223565b606091505b5050905080612d50576040516312171d8360e31b815260040160405180910390fd5b610a596001600160a01b038216337f0000000000000000000000002c96e1a9da8c6bb74417741302725959df4d6bdc856135c9565b8160005b600a548110156133c1576000612710600b83815481106132a0576132a06139eb565b9060005260206000200154866132b69190613b49565b6132c09190613af4565b9050806000036132d057506133b9565b6001600160a01b038416613374576000600a83815481106132f3576132f36139eb565b60009182526020822001546040516001600160a01b039091169184919081818185875af1925050503d8060008114613347576040519150601f19603f3d011682016040523d82523d6000602084013e61334c565b606091505b505090508061336e576040516312171d8360e31b815260040160405180910390fd5b506133ab565b6133ab33600a848154811061338b5761338b6139eb565b6000918252602090912001546001600160a01b03878116929116846135c9565b6133b581846139c5565b9250505b60010161327e565b506000811180156133d35750600a5415155b15612d5057600a8054600091906133ec906001906139c5565b815481106133fc576133fc6139eb565b6000918252602090912001546001600160a01b0390811691508316613495576000816001600160a01b03168360405160006040518083038185875af1925050503d8060008114613468576040519150601f19603f3d011682016040523d82523d6000602084013e61346d565b606091505b505090508061348f576040516312171d8360e31b815260040160405180910390fd5b50611a3a565b611a3a6001600160a01b0384163383856135c9565b6134b261116d565b610d6c57604051638dfc202b60e01b815260040160405180910390fd5b600080602060008451602086016000885af1806134f2576040513d6000823e3d81fd5b50506000513d9150811561350a578060011415613517565b6001600160a01b0384163b155b15611a3a5783604051635274afe760e01b81526004016111ae9190613796565b6000836001600160a01b031663095ea7b3848460405160240161355b929190613e22565b604051602081830303815290604052915060e01b6020820180516001600160e01b03838183161783525050505090506135948482613602565b611a3a576135bf84856001600160a01b031663095ea7b3866000604051602401612d1e929190613e22565b611a3a84826134cf565b6040516001600160a01b038481166024830152838116604483015260648201839052611a3a9186918216906323b872dd90608401612d1e565b6000806000806020600086516020880160008a5af192503d91506000519050828015613647575081156136385780600114613647565b6000866001600160a01b03163b115b9695505050505050565b8015158114611cc357600080fd5b6000806040838503121561367257600080fd5b82359150602083013561368481613651565b809150509250929050565b6000602082840312156136a157600080fd5b5035919050565b60008083601f8401126136ba57600080fd5b5081356001600160401b038111156136d157600080fd5b6020830191508360208260051b85010111156136ec57600080fd5b9250929050565b6000806000806000806060878903121561370c57600080fd5b86356001600160401b0381111561372257600080fd5b61372e89828a016136a8565b90975095505060208701356001600160401b0381111561374d57600080fd5b61375989828a016136a8565b90955093505060408701356001600160401b0381111561377857600080fd5b61378489828a016136a8565b979a9699509497509295939492505050565b6001600160a01b0391909116815260200190565b6000806000806000606086880312156137c257600080fd5b85356001600160401b038111156137d857600080fd5b6137e4888289016136a8565b90965094505060208601356001600160401b0381111561380357600080fd5b61380f888289016136a8565b96999598509660400135949350505050565b80356001600160a01b038116811461383857600080fd5b919050565b60006020828403121561384f57600080fd5b61385882613821565b9392505050565b6000806000806000806000806000806101008b8d03121561387f57600080fd5b6138888b613821565b995061389660208c01613821565b985060408b01356001600160401b038111156138b157600080fd5b6138bd8d828e016136a8565b90995097505060608b01356001600160401b038111156138dc57600080fd5b6138e88d828e016136a8565b9b9e9a9d50989b979a989960808901359860a0810135985060c0810135975060e0013595509350505050565b60008060006060848603121561392957600080fd5b505081359360208301359350604090920135919050565b6000806000806040858703121561395657600080fd5b84356001600160401b0381111561396c57600080fd5b613978878288016136a8565b90955093505060208501356001600160401b0381111561399757600080fd5b6139a3878288016136a8565b95989497509550505050565b634e487b7160e01b600052601160045260246000fd5b818103818111156125eb576125eb6139af565b808201808211156125eb576125eb6139af565b634e487b7160e01b600052603260045260246000fd5b6001815b6001841115613a3c57808504811115613a2057613a206139af565b6001841615613a2e57908102905b60019390931c928002613a05565b935093915050565b600082613a53575060016125eb565b81613a60575060006125eb565b8160018114613a765760028114613a8057613a9c565b60019150506125eb565b60ff841115613a9157613a916139af565b50506001821b6125eb565b5060208310610133831016604e8410600b8410161715613abf575081810a6125eb565b613acc6000198484613a01565b8060001904821115613ae057613ae06139af565b029392505050565b60006138588383613a44565b600082613b1157634e487b7160e01b600052601260045260246000fd5b500490565b6001600160a01b0392831681529116602082015260400190565b600060208284031215613b4257600080fd5b5051919050565b80820281158282048414176125eb576125eb6139af565b600060018201613b7257613b726139af565b5060010190565b9283526020830191909152604082015260600190565b6020808252601b908201527a135a59dc985d1a5bdb88185b1c9958591e4818dbdb5c1b195d1959602a1b604082015260600190565b60208082526015908201527415995cdd1a5b99c81d985d5b1d081b9bdd081cd95d605a1b604082015260600190565b6000808335601e19843603018112613c0a57600080fd5b8301803591506001600160401b03821115613c2457600080fd5b6020019150600581901b36038213156136ec57600080fd5b602080825260169082015275082e4e4c2f2e640d8cadccee8d040dad2e6dac2e8c6d60531b604082015260600190565b6001600160a01b0393909316835260208301919091521515604082015260600190565b81835260208301925060008160005b84811015613ccd576001600160a01b03613cb783613821565b1686526020958601959190910190600101613c9e565b5093949350505050565b81835260006001600160fb1b03831115613cf057600080fd5b8260051b80836020870137939093016020019392505050565b604081526000613d1d604083018688613c8f565b8281036020840152613d30818587613cd7565b979650505050505050565b606081526000613d4f606083018789613c8f565b8281036020840152613d62818688613cd7565b9150508260408301529695505050505050565b604081526000613d1d604083018688613cd7565b80516001600160501b038116811461383857600080fd5b600080600080600060a08688031215613db857600080fd5b613dc186613d89565b60208701516040880151606089015192975090955093509150613de660808701613d89565b90509295509295909350565b60208082526016908201527514dd185ada5b99c81b9bdd0818dbdb999a59dd5c995960521b604082015260600190565b6001600160a01b03929092168252602082015260400190565b600060208284031215613e4d57600080fd5b81516138588161365156fe8801cd9c7e0d9b0ed3a85806cd1f1890396eeb59814f915c53295614f679c6ffb539ca1e5c8d398ddf1c41c30166f33404941683be4683319b57669a93dad4ef76bd38f444648ed345e9f1a2d54dc8711f472ffe25c5156ca6f3a46bf2de190ecc2c7ecadea784eb7f00da16e96860d108ef24d3b6a56a376211537bf2a855721016b036b03a653fe3ebb7a235596b21c42bcfdae2defc658b52f937456a82ac2f208cfc59215097cf327910e25bd607b47d67ae2970ed10690511a6a7358922a2646970667358221220533006442b0e296206d631f43434c90df5845197103050219bbc5b5636e65b6e64736f6c634300081a0033

Verified Source Code Full Match

Compiler: v0.8.26+commit.8a97fa7a EVM: paris Optimization: Yes (1 runs)
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

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

/**
 * @title IERC1363
 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
 *
 * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
 * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
 */
interface IERC1363 is IERC20, IERC165 {
    /*
     * Note: the ERC-165 identifier for this interface is 0xb0202a11.
     * 0xb0202a11 ===
     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
     */

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @param data Additional data with no specified format, sent in call to `spender`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "../utils/introspection/IERC165.sol";
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../token/ERC20/IERC20.sol";
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";

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

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

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

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

    /**
     * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
        return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
        return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

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

    /**
     * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
     * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferFromAndCallRelaxed(
        IERC1363 token,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        if (to.code.length == 0) {
            safeTransferFrom(token, from, to, value);
        } else if (!token.transferFromAndCall(from, to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
     * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
     * once without retrying, and relies on the returned value to be true.
     *
     * Reverts if the returned value is other than `true`.
     */
    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            forceApprove(token, to, value);
        } else if (!token.approveAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            // bubble errors
            if iszero(success) {
                let ptr := mload(0x40)
                returndatacopy(ptr, 0, returndatasize())
                revert(ptr, returndatasize())
            }
            returnSize := returndatasize()
            returnValue := mload(0)
        }

        if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        bool success;
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            returnSize := returndatasize()
            returnValue := mload(0)
        }
        return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
    }
}
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;
    }
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

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

pragma solidity ^0.8.20;

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

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    bool private _paused;

    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    /**
     * @dev The operation failed because the contract is paused.
     */
    error EnforcedPause();

    /**
     * @dev The operation failed because the contract is not paused.
     */
    error ExpectedPause();

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        if (paused()) {
            revert EnforcedPause();
        }
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        if (!paused()) {
            revert ExpectedPause();
        }
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}
ReentrancyGuard.sol 87 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.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 EIP-1153 (transient storage) is available on the chain you're deploying at,
 * consider using {ReentrancyGuardTransient} instead.
 *
 * 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;
    }
}
PresaleVault.sol 722 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

interface Aggregator {
    function latestRoundData()
    external
    view
    returns (
        uint80 roundId,
        int256 answer,
        uint256 startedAt,
        uint256 updatedAt,
        uint80 answeredInRound
    );
}

interface IStakingHandler {
    function stakeByPresale(address _holder, uint256 a_tokenAmount) external;

    function migrateUserStakingData(address[] calldata users, uint256[] calldata amounts, uint256 presaleStartTime) external;
}

interface IVestingVault {
    function registerVesting(address user, uint256 amount, bool staked) external;

    function claimVestedTokens() external returns (uint256);

    function setVestingStart(uint256 _vestingStart) external;

    function getClaimableAmount(address user) external view returns (uint256);

    function convertToStaked(address user, uint256 amount) external returns (bool);

    function getNonStakedAllocation(address user) external view returns (uint256);
}

contract Presale is ReentrancyGuard, Ownable, Pausable {
    using SafeERC20 for IERC20;

    // Constants
    uint256 private constant TOKEN_DECIMALS = 18;
    uint256 private constant USDT_DECIMALS = 6;
    uint256 private constant PRICE_DECIMALS = 18;
    uint256 private constant ETH_PRICE_DECIMALS = 8;
    uint256 private constant PERCENTAGE_BASE = 10000;
    uint256 private constant PRICE_FRESHNESS_THRESHOLD = 3600;
    uint256 private constant MIN_TIME_BETWEEN_STAGES = 1 hours;

    // Structs
    struct Stage {
        uint256 capacity;
        uint256 price;
        uint256 startTime;
        bool initialized;
    }

    // State variables
    uint256 public totalTokensSold;
    uint256 public startTime;
    uint256 public endTime;
    address public immutable saleToken;
    uint256 public immutable baseDecimals;
    uint256 public checkPoint;
    uint256 public usdRaised;
    uint256 public totalBoughtAndStaked;
    uint256 public vestingStart;
    Stage[] public stages;
    address[] public destinationSplitWallets;
    uint256[] public destinationSplitPercentages;
    uint public activeStagePublic;

    mapping(uint256 => uint256) private tokensSoldInStage;
    mapping(uint256 => bool) private stageHasProgressed;

    // Immutable addresses
    address public immutable usdtToken;
    address public immutable destinationWallet;

    // Contract interfaces
    IERC20 private immutable USDTInterface;
    Aggregator private immutable priceAggregator;
    IStakingHandler public stakingHandler;
    IVestingVault public vestingVault;

    // Migration flag
    bool public migrationMode = true;

    // Events
    event StageAdded(uint256 indexed stageId, uint256 capacity, uint256 price, uint256 startTime);
    event StageUpdated(uint256 indexed stageId, uint256 capacity, uint256 price, uint256 startTime);
    event TokensBought(address indexed user, uint256 amount, address indexed purchaseToken, uint256 amountPaid, uint256 usdEquivalent);
    event TokensClaimed(address indexed user, uint256 amount);
    event TokensStaked(address indexed user, uint256 amount);
    event StakingHandlerUpdated(address indexed handler);
    event VestingVaultUpdated(address indexed vault);
    event EmergencyWithdraw(address indexed token, uint256 amount);
    event RefundIssued(address indexed user, uint256 amount, address indexed token);
    event StageProgressed(uint256 indexed fromStage, uint256 indexed toStage, uint256 unsolvedTokensRolledOver);
    event MigrationCompleted();
    event MigrationDataSet(uint256 currentStageId, uint256 totalTokensSold, uint256 usdRaised, uint256 totalBoughtAndStaked);
    event UserBalancesMigrated(address[] users, uint256[] amounts);
    event StageTokensSoldSet(uint256[] stageIds, uint256[] amounts);

    // Custom errors
    error InvalidAmount();
    error InvalidAddress();
    error InvalidStage();
    error InvalidTime();
    error InvalidPrice();
    error InsufficientAllowance();
    error InsufficientBalance();
    error SaleNotActive();
    error ClaimNotStarted();
    error NothingToClaim();
    error TransferFailed();
    error StalePrice();

    // Modifiers
    modifier validAddress(address _address) {
        if (_address == address(0)) revert InvalidAddress();
        _;
    }

    modifier whenSaleActive() {
        if (block.timestamp < startTime || block.timestamp > endTime) revert SaleNotActive();
        _;
    }

    constructor(
        address _oracle,
        address _usdt,
        address _saleToken,
        uint256 _startTime,
        uint256 _endTime,
        address _destinationWallet
    ) Ownable(msg.sender) {
        if (_oracle == address(0) || _usdt == address(0) || _saleToken == address(0)) revert InvalidAddress();

        if (!migrationMode) {
            if (_startTime <= block.timestamp || _endTime <= _startTime) revert InvalidTime();
        }

        priceAggregator = Aggregator(_oracle);
        USDTInterface = IERC20(_usdt);
        usdtToken = _usdt;
        saleToken = _saleToken;
        startTime = _startTime;
        endTime = _endTime;
        destinationWallet = _destinationWallet;
        baseDecimals = 10 ** TOKEN_DECIMALS;
        vestingStart = _endTime;
    }


    function migrateUserBalancesAndStaking(
        address[][] calldata userBatches,
        uint256[][] calldata amountBatches,
        uint256 presaleStartTime
    ) external onlyOwner {
        require(migrationMode, "Migration already completed");
        require(userBatches.length == amountBatches.length, "Batch arrays length mismatch");
        require(address(vestingVault) != address(0), "Vesting vault not set");
        require(address(stakingHandler) != address(0), "Staking handler not set");

        for (uint256 j = 0; j < userBatches.length; j++) {
            address[] calldata users = userBatches[j];
            uint256[] calldata amounts = amountBatches[j];
            require(users.length == amounts.length, "Arrays length mismatch");

            // Migrate balances to vesting vault
            for (uint256 i = 0; i < users.length; i++) {
                if (amounts[i] > 0) {
                    IERC20(saleToken).safeTransfer(address(vestingVault), amounts[i]);
                    vestingVault.registerVesting(users[i], amounts[i], true);
                }
            }
            emit UserBalancesMigrated(users, amounts);

            // Migrate staking data
            stakingHandler.migrateUserStakingData(users, amounts, presaleStartTime);
        }
    }

    // Migration functions
    function completeMigration() external onlyOwner {
        migrationMode = false;
        activeStagePublic = getCurrentStage();
        emit MigrationCompleted();
    }

    function migrateUserBalances(address[] calldata users, uint256[] calldata amounts) external onlyOwner {
        require(migrationMode, "Migration already completed");
        require(users.length == amounts.length, "Arrays length mismatch");
        require(address(vestingVault) != address(0), "Vesting vault not set");

        for (uint256 i = 0; i < users.length; i++) {
            if (amounts[i] > 0) {
                IERC20(saleToken).safeTransfer(address(vestingVault), amounts[i]);
                vestingVault.registerVesting(users[i], amounts[i], true);
            }
        }
        emit UserBalancesMigrated(users, amounts);
    }

    function getLatestPrice() public view returns (uint256) {
        (uint80 roundID, int256 price, , uint256 updatedAt, uint80 answeredInRound) = priceAggregator.latestRoundData();
        if (price <= 0) revert InvalidPrice();
        if (updatedAt == 0) revert StalePrice();
        if (answeredInRound < roundID) revert StalePrice();
        if (block.timestamp - updatedAt > PRICE_FRESHNESS_THRESHOLD) revert StalePrice();
        return uint256(price);
    }

    function getTokensSoldInStage(uint256 stageId) external view returns (uint256) {
        if (stageId >= stages.length) revert InvalidStage();
        if (!stages[stageId].initialized) revert InvalidStage();
        return tokensSoldInStage[stageId];
    }

    function addStage(uint256 _capacity, uint256 _price, uint256 _startTime) external onlyOwner {
        if (_capacity == 0 || _price == 0) revert InvalidAmount();
        if (_startTime <= block.timestamp) revert InvalidTime();
        if (stages.length > 0) {
            Stage memory lastStage = stages[stages.length - 1];
            if (_startTime <= lastStage.startTime + MIN_TIME_BETWEEN_STAGES) revert InvalidTime();
        }

        stages.push(Stage({
            capacity: _capacity,
            price: _price,
            startTime: _startTime,
            initialized: true
        }));
        emit StageAdded(stages.length - 1, _capacity, _price, _startTime);
    }

    function calculateTokensForUSD(uint256 usdAmount) public view returns (uint256) {
        if (usdAmount == 0) return 0;
        uint256 totalTokens = 0;
        uint256 remainingUSD = usdAmount;
        uint256 currentStage = getCurrentStage();

        for (uint256 i = currentStage; i < stages.length && remainingUSD > 0; i++) {
            Stage memory stage = stages[i];
            if (!stage.initialized) break;

            uint256 tokensAlreadySold = tokensSoldInStage[i];
            uint256 tokensAvailableInStage = stage.capacity - tokensAlreadySold;
            if (tokensAvailableInStage == 0) continue;

            uint256 usdValueOfAvailableTokens = (tokensAvailableInStage * stage.price) / baseDecimals;

            if (remainingUSD >= usdValueOfAvailableTokens) {
                totalTokens += tokensAvailableInStage;
                remainingUSD -= usdValueOfAvailableTokens;
            } else {
                uint256 tokensToBuy = (remainingUSD * baseDecimals) / stage.price;
                totalTokens += tokensToBuy;
                remainingUSD = 0;
            }
        }

        if (remainingUSD > 0) revert InvalidAmount();
        return totalTokens;
    }

    function buyWithEth(uint256 tokenAmount, bool stakeTokens) external payable nonReentrant whenNotPaused whenSaleActive {
        uint256 usdAmount = calculateUSDForTokens(tokenAmount);
        uint256 ethPrice = getLatestPrice();
        uint256 ethRequired = (usdAmount * (10 ** ETH_PRICE_DECIMALS)) / ethPrice;
        if (msg.value < ethRequired) revert InsufficientBalance();

        _processPurchase(tokenAmount, stakeTokens, ethRequired, usdAmount, address(0));

        if (msg.value > ethRequired) {
            (bool success,) = msg.sender.call{value: msg.value - ethRequired}("");
            if (!success) revert TransferFailed();
            emit RefundIssued(msg.sender, msg.value - ethRequired, address(0));
        }
    }

    function buyWithUSDT(uint256 tokenAmount, bool stakeTokens) external nonReentrant whenNotPaused whenSaleActive {
        uint256 usdAmount = calculateUSDForTokens(tokenAmount);
        uint256 usdtAmount = usdAmount / (10 ** (PRICE_DECIMALS - USDT_DECIMALS));
        if (USDTInterface.allowance(msg.sender, address(this)) < usdtAmount) revert InsufficientAllowance();

        _processPurchase(tokenAmount, stakeTokens, usdtAmount, usdAmount, address(USDTInterface));
    }

    function _processPurchase(
        uint256 tokenAmount,
        bool stakeTokens,
        uint256 paymentAmount,
        uint256 usdAmount,
        address paymentToken
    ) internal {
        require(address(vestingVault) != address(0), "Vesting vault not set");

        uint256 remainingTokens = tokenAmount;
        uint256 totalTokensPurchased = 0;
        uint256 maxIterations = stages.length; // Prevent infinite loops
        uint256 iterations = 0;

        while (remainingTokens > 0 && iterations < maxIterations) {
            iterations++;

            uint256 activeStage = _getActiveStage();

            if (activeStage >= stages.length) {
                revert InvalidStage();
            }

            uint256 tokensAlreadySold = tokensSoldInStage[activeStage];
            uint256 tokensAvailableInStage = stages[activeStage].capacity > tokensAlreadySold
                ? stages[activeStage].capacity - tokensAlreadySold
                : 0;

            if (tokensAvailableInStage == 0) {
                _forceProgressStage(activeStage);
                continue;
            }

            uint256 tokensFromThisStage = remainingTokens > tokensAvailableInStage
                ? tokensAvailableInStage
                : remainingTokens;

            tokensSoldInStage[activeStage] += tokensFromThisStage;
            totalTokensPurchased += tokensFromThisStage;
            remainingTokens -= tokensFromThisStage;

            if (tokensSoldInStage[activeStage] >= stages[activeStage].capacity) {
                _forceProgressStage(activeStage);
            }
        }

        require(remainingTokens == 0, "Could not fulfill entire purchase");
        require(totalTokensPurchased == tokenAmount, "Token calculation error");

        totalTokensSold += tokenAmount;
        usdRaised += usdAmount;

        IERC20(saleToken).safeTransfer(address(vestingVault), tokenAmount);

        if (stakeTokens) {
            require(address(stakingHandler) != address(0), "Staking not configured");
            vestingVault.registerVesting(msg.sender, tokenAmount, true);
            stakingHandler.stakeByPresale(msg.sender, tokenAmount);
            totalBoughtAndStaked += tokenAmount;
            emit TokensStaked(msg.sender, tokenAmount);
        } else {
            vestingVault.registerVesting(msg.sender, tokenAmount, false);
        }

        _distributePayment(paymentAmount, paymentToken);
        emit TokensBought(msg.sender, tokenAmount, paymentToken, paymentAmount, usdAmount);
    }

    function _getActiveStage() internal view returns (uint256) {
        for (uint256 i = 0; i < stages.length; i++) {
            Stage memory stage = stages[i];
            if (!stage.initialized) continue;

            bool stageFull = tokensSoldInStage[i] >= stage.capacity;
            bool nextStageStarted = (i < stages.length - 1) &&
                (block.timestamp >= stages[i + 1].startTime);

            if (!stageFull && (i == stages.length - 1 || !nextStageStarted)) {
                return i;
            }

            if (stageFull || nextStageStarted) {
                continue;
            }

            return i;
        }

        return stages.length > 0 ? stages.length - 1 : 0;
    }


    function _forceProgressStage(uint256 stageId) internal {
        if (stageId >= stages.length - 1) return;

        uint256 nextStage = stageId + 1;

        activeStagePublic = nextStage;

        uint256 sold = tokensSoldInStage[stageId];
        uint256 unsold = sold < stages[stageId].capacity
            ? stages[stageId].capacity - sold
            : 0;

        if (unsold > 0) {
            stages[nextStage].capacity += unsold;
            emit StageUpdated(nextStage, stages[nextStage].capacity, stages[nextStage].price, stages[nextStage].startTime);
        }

        stageHasProgressed[stageId] = true;

        emit StageProgressed(stageId, nextStage, unsold);
    }

    // Backward compatible claim function - delegates to vesting vault
    function claim() external nonReentrant whenNotPaused {
        uint256 claimedAmount = vestingVault.claimVestedTokens();
        emit TokensClaimed(msg.sender, claimedAmount);
    }

    // View function for backward compatibility
    function calculateVestedAmount(address user) public view returns (uint256) {
        return vestingVault.getClaimableAmount(user);
    }

    /**
     * @notice Stake purchased tokens after buying them
     * @param amount Amount of tokens to stake from purchased tokens
     */
    function stake(uint256 amount) external nonReentrant whenNotPaused {
        if (amount == 0) revert InvalidAmount();
        require(address(stakingHandler) != address(0), "Staking not configured");
        require(address(vestingVault) != address(0), "Vesting vault not set");

        uint256 nonStakedAllocation = vestingVault.getNonStakedAllocation(msg.sender);
        if (nonStakedAllocation < amount) revert InsufficientBalance();

        bool success = vestingVault.convertToStaked(msg.sender, amount);
        require(success, "Failed to convert to staked");

        stakingHandler.stakeByPresale(msg.sender, amount);

        totalBoughtAndStaked += amount;

        emit TokensStaked(msg.sender, amount);
    }

    function emergencyWithdraw(address token) external onlyOwner {
        uint256 balance = IERC20(token).balanceOf(address(this));
        IERC20(token).safeTransfer(msg.sender, balance);
        emit EmergencyWithdraw(token, balance);
    }

    function setStakingHandler(address _handler) external onlyOwner {
        if (_handler == address(0)) revert InvalidAddress();
        stakingHandler = IStakingHandler(_handler);
        emit StakingHandlerUpdated(_handler);
    }

    function setVestingVault(address _vault) external onlyOwner {
        if (_vault == address(0)) revert InvalidAddress();
        vestingVault = IVestingVault(_vault);
        IERC20(saleToken).safeIncreaseAllowance(_vault, type(uint256).max);
        emit VestingVaultUpdated(_vault);
    }

    function finalizePresale() external onlyOwner {
        endTime = block.timestamp;
        vestingStart = block.timestamp;
        if (address(vestingVault) != address(0)) {
            vestingVault.setVestingStart(block.timestamp);
        }
    }

    function pause() external onlyOwner {
        _pause();
    }

    function unpause() external onlyOwner {
        _unpause();
    }

    function getCurrentStage() internal view returns (uint256) {
        for (uint256 i = 0; i < stages.length; i++) {
            Stage memory stage = stages[i];
            if (!stage.initialized) continue;

            if (block.timestamp < stage.startTime) {
                if (i == 0) revert InvalidStage();
                return i - 1;
            }

            uint256 tokensSold = tokensSoldInStage[i];
            if (tokensSold < stage.capacity) {
                if (i < stages.length - 1 && block.timestamp >= stages[i + 1].startTime) {
                    continue;
                }
                return i;
            }
        }

        if (stages.length > 0) {
            return stages.length - 1;
        }
        revert InvalidStage();
    }

    function getCurrentStagePublic() external view returns (uint) {
        return activeStagePublic;
    }

    function checkStageProgression() external view returns (bool shouldProgress, uint256 nextStage, uint256 unsoldTokens) {
        uint256 currentStage = getCurrentStage();
        if (currentStage >= stages.length - 1) {
            return (false, currentStage, 0);
        }

        nextStage = currentStage + 1;

        if (block.timestamp >= stages[nextStage].startTime) {
            uint256 tokensSold = tokensSoldInStage[currentStage];
            unsoldTokens = tokensSold < stages[currentStage].capacity
                ? stages[currentStage].capacity - tokensSold
                : 0;
            return (true, nextStage, unsoldTokens);
        }

        uint256 tokensSoldCapCheck = tokensSoldInStage[currentStage];
        if (tokensSoldCapCheck >= stages[currentStage].capacity) {
            return (true, nextStage, 0);
        }

        return (false, currentStage, 0);
    }

/**
 * @notice Redistribute unsold tokens from previous stage to current stage
 * @dev Only owner can call this function to manually redistribute tokens
 */
    function redistributeFromPreviousStage() external onlyOwner {
        uint256 currentStage = getCurrentStage();

        if (currentStage == 0) {
            revert InvalidStage();
        }

        uint256 previousStage = currentStage - 1;

        uint256 previousStageCapacity = stages[previousStage].capacity;
        uint256 previousStageTokensSold = tokensSoldInStage[previousStage];
        uint256 unsoldTokensPrevStage = previousStageCapacity > previousStageTokensSold
            ? previousStageCapacity - previousStageTokensSold
            : 0;

        if (unsoldTokensPrevStage > 0) {
            stages[currentStage].capacity += unsoldTokensPrevStage;

            emit StageUpdated(currentStage, stages[currentStage].capacity, stages[currentStage].price, stages[currentStage].startTime);
        }
    }

    function _progressStage(uint256 curStage) internal returns (uint256) {
        if (curStage >= stages.length - 1) return curStage;

        uint256 next = curStage + 1;
        bool byTime = block.timestamp >= stages[next].startTime;
        bool byCap = tokensSoldInStage[curStage] >= stages[curStage].capacity;

        if (!(byTime || byCap)) return curStage;

        uint256 sold = tokensSoldInStage[curStage];
        uint256 unsold = sold < stages[curStage].capacity
            ? stages[curStage].capacity - sold
            : 0;

        if (unsold > 0) {
            stages[next].capacity += unsold;
            emit StageUpdated(next, stages[next].capacity, stages[next].price, stages[next].startTime);
        }

        emit StageProgressed(curStage, next, unsold);
        return next;
    }

    function calculateUSDForTokens(uint256 tokenAmount) public view returns (uint256) {
        if (tokenAmount == 0) return 0;
        uint256 totalUSD = 0;
        uint256 remainingTokens = tokenAmount;
        uint256 currentStage = getCurrentStage();

        for (uint256 i = currentStage; i < stages.length && remainingTokens > 0; i++) {
            Stage memory stage = stages[i];
            if (!stage.initialized) break;

            uint256 tokensAlreadySold = tokensSoldInStage[i];
            uint256 tokensAvailableInStage = stage.capacity > tokensAlreadySold
                ? stage.capacity - tokensAlreadySold
                : 0;
            if (tokensAvailableInStage == 0) continue;

            uint256 tokensToBuyFromStage = remainingTokens > tokensAvailableInStage
                ? tokensAvailableInStage
                : remainingTokens;

            uint256 usdForThisStage = (tokensToBuyFromStage * stage.price) / baseDecimals;
            totalUSD += usdForThisStage;
            remainingTokens -= tokensToBuyFromStage;
        }

        if (remainingTokens > 0) revert InvalidAmount();
        return totalUSD;
    }

    function addStages(
        uint256[] calldata _capacities,
        uint256[] calldata _prices,
        uint256[] calldata _startTimes
    ) external onlyOwner {
        if (_capacities.length != _prices.length || _prices.length != _startTimes.length) {
            revert InvalidAmount();
        }

        uint256 length = _capacities.length;
        for (uint256 i = 0; i < length; i++) {
            if (_capacities[i] == 0 || _prices[i] == 0) revert InvalidAmount();

            if (!migrationMode) {
                if (_startTimes[i] <= block.timestamp) revert InvalidTime();
                if (stages.length > 0 || i > 0) {
                    uint256 lastStageTime;
                    if (stages.length > 0) {
                        lastStageTime = stages[stages.length - 1].startTime;
                    } else {
                        lastStageTime = _startTimes[i - 1];
                    }

                    if (_startTimes[i] <= lastStageTime + MIN_TIME_BETWEEN_STAGES) {
                        revert InvalidTime();
                    }
                }
            }

            stages.push(Stage({
                capacity: _capacities[i],
                price: _prices[i],
                startTime: _startTimes[i],
                initialized: true
            }));
            emit StageAdded(stages.length - 1, _capacities[i], _prices[i], _startTimes[i]);
        }
    }

    function _distributePayment(uint256 amount, address token) internal {
        if (destinationSplitWallets.length == 0) {
            if (token == address(0)) {
                (bool success,) = destinationWallet.call{value: amount}("");
                if (!success) revert TransferFailed();
            } else {
                IERC20(token).safeTransferFrom(msg.sender, destinationWallet, amount);
            }
            return;
        }

        uint256 remaining = amount;
        for (uint256 i = 0; i < destinationSplitWallets.length; i++) {
            uint256 share = (amount * destinationSplitPercentages[i]) / PERCENTAGE_BASE;
            if (share == 0) continue;

            if (token == address(0)) {
                (bool success,) = destinationSplitWallets[i].call{value: share}("");
                if (!success) revert TransferFailed();
            } else {
                IERC20(token).safeTransferFrom(msg.sender, destinationSplitWallets[i], share);
            }
            remaining -= share;
        }

        if (remaining > 0 && destinationSplitWallets.length > 0) {
            address lastWallet = destinationSplitWallets[destinationSplitWallets.length - 1];
            if (token == address(0)) {
                (bool success,) = lastWallet.call{value: remaining}("");
                if (!success) revert TransferFailed();
            } else {
                IERC20(token).safeTransferFrom(msg.sender, lastWallet, remaining);
            }
        }
    }

    function multicallConfig(
        address _vestingVault,
        address _stakingHandler,
        uint256[] calldata stageIds,
        uint256[] calldata tokensSoldAmounts,
        uint256 _currentStageId,
        uint256 _totalTokensSold,
        uint256 _usdRaised,
        uint256 _totalBoughtAndStaked
    ) external onlyOwner {
        require(migrationMode, "Migration completed");

        // Set VestingVault
        vestingVault = IVestingVault(_vestingVault);
        IERC20(saleToken).safeIncreaseAllowance(_vestingVault, type(uint256).max);
        emit VestingVaultUpdated(_vestingVault);

        // Set StakingHandler
        stakingHandler = IStakingHandler(_stakingHandler);
        emit StakingHandlerUpdated(_stakingHandler);


        // Set stage tokens sold
        require(stageIds.length == tokensSoldAmounts.length, "Length mismatch");
        for (uint256 i = 0; i < stageIds.length; i++) {
            tokensSoldInStage[stageIds[i]] = tokensSoldAmounts[i];
        }
        emit StageTokensSoldSet(stageIds, tokensSoldAmounts);

        // Set migration data
        totalTokensSold = _totalTokensSold;
        usdRaised = _usdRaised;
        totalBoughtAndStaked = _totalBoughtAndStaked;
        activeStagePublic = _currentStageId;
        emit MigrationDataSet(_currentStageId, _totalTokensSold, _usdRaised, _totalBoughtAndStaked);
    }

    receive() external payable {}
}

Read Contract

activeStagePublic 0x2897e742 → uint256
baseDecimals 0x33f76178 → uint256
calculateTokensForUSD 0xdf46bf2f → uint256
calculateUSDForTokens 0x1dc7bf1a → uint256
calculateVestedAmount 0xffa06b2a → uint256
checkPoint 0xcff805ab → uint256
checkStageProgression 0x086ce9b1 → bool, uint256, uint256
destinationSplitPercentages 0x6da18552 → uint256
destinationSplitWallets 0xc7b7e92f → address
destinationWallet 0x53b7a59b → address
endTime 0x3197cbb6 → uint256
getCurrentStagePublic 0x67ee767e → uint256
getLatestPrice 0x8e15f473 → uint256
getTokensSoldInStage 0xaee59ef5 → uint256
migrationMode 0x7a01e2bd → bool
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
saleToken 0xe985e367 → address
stages 0x845ddcb2 → uint256, uint256, uint256, bool
stakingHandler 0x855902b7 → address
startTime 0x78e97925 → uint256
totalBoughtAndStaked 0x7f6fb253 → uint256
totalTokensSold 0x63b20117 → uint256
usdRaised 0xeadd94ec → uint256
usdtToken 0xa98ad46c → address
vestingStart 0x254800d4 → uint256
vestingVault 0xa5917baf → address

Write Contract 19 functions

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

addStage 0xd13782a7
uint256 _capacity
uint256 _price
uint256 _startTime
addStages 0x4c0f8054
uint256[] _capacities
uint256[] _prices
uint256[] _startTimes
buyWithEth 0x2c65169e
uint256 tokenAmount
bool stakeTokens
buyWithUSDT 0x136021d9
uint256 tokenAmount
bool stakeTokens
claim 0x4e71d92d
No parameters
completeMigration 0x4886f62c
No parameters
emergencyWithdraw 0x6ff1c9bc
address token
finalizePresale 0xa0a6e940
No parameters
migrateUserBalances 0xe6242fe6
address[] users
uint256[] amounts
migrateUserBalancesAndStaking 0x6059bcab
address[][] userBatches
uint256[][] amountBatches
uint256 presaleStartTime
multicallConfig 0x762c8a80
address _vestingVault
address _stakingHandler
uint256[] stageIds
uint256[] tokensSoldAmounts
uint256 _currentStageId
uint256 _totalTokensSold
uint256 _usdRaised
uint256 _totalBoughtAndStaked
pause 0x8456cb59
No parameters
redistributeFromPreviousStage 0xf9fc5b20
No parameters
renounceOwnership 0x715018a6
No parameters
setStakingHandler 0xc2f403a3
address _handler
setVestingVault 0xa91468ba
address _vault
stake 0xa694fc3a
uint256 amount
transferOwnership 0xf2fde38b
address newOwner
unpause 0x3f4ba83a
No parameters

Recent Transactions

No transactions found for this address