Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x7E48Df39fb7C205Fee9238BAba39069CEE7e3A25
Balance 0 ETH
Nonce 1
Code Size 12108 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

12108 bytes
0x6080604052600436106101c5575f3560e01c8063808b472a116100f2578063bb10c82911610092578063e9fe787211610062578063e9fe787214610575578063f1bb974514610594578063f2fde38b146105b3578063f896f7c4146105d2575f80fd5b8063bb10c829146104e1578063bb7dd06614610518578063c1c03a9914610537578063e532d44814610556575f80fd5b806397af95ca116100cd57806397af95ca146104735780639cf261ec14610486578063a17a97ee146104a3578063ba5d2ed2146104c2575f80fd5b8063808b472a146104195780638da5cb5b146104385780639456fbcc14610454575f80fd5b806331f591221161016857806363bf97701161013857806363bf97701461034e5780636b597cb714610362578063715018a6146103e6578063801a4479146103fa575f80fd5b806331f59122146102b057806332a2c5d0146102df5780633e9a12fa146103105780634025feb21461032f575f80fd5b80631d834409116101a35780631d8344091461024b578063265ef4f81461026e5780632ca7207b14610281578063313ce56714610295575f80fd5b80630ddb8388146101c9578063162a61c2146101fe578063169147b21461021f575b5f80fd5b3480156101d4575f80fd5b506101e86101e336600461255d565b6105f1565b6040516101f591906125a8565b60405180910390f35b348015610209575f80fd5b5061021d610218366004612626565b610726565b005b34801561022a575f80fd5b5061023e61023936600461279c565b610741565b6040516101f5919061283c565b348015610256575f80fd5b5061026060085481565b6040519081526020016101f5565b61021d61027c36600461284e565b610974565b34801561028c575f80fd5b50600554610260565b3480156102a0575f80fd5b50604051601281526020016101f5565b3480156102bb575f80fd5b506102cf6102ca366004612905565b610fbd565b60405190151581526020016101f5565b3480156102ea575f80fd5b506003546001600160a01b03165b6040516001600160a01b0390911681526020016101f5565b34801561031b575f80fd5b5061021d61032a36600461255d565b611090565b34801561033a575f80fd5b5061021d61034936600461295e565b61109d565b348015610359575f80fd5b5061026061115a565b34801561036d575f80fd5b506103b461037c36600461255d565b600b6020525f9081526040902080546001820154600283015460038401546004909401546001600160a01b0390931693919290919085565b604080516001600160a01b0390961686526020860194909452928401919091526060830152608082015260a0016101f5565b3480156103f1575f80fd5b5061021d6112bc565b348015610405575f80fd5b5061021d610414366004612626565b6112cf565b348015610424575f80fd5b5061021d61043336600461299c565b6112f5565b348015610443575f80fd5b505f546001600160a01b03166102f8565b34801561045f575f80fd5b5061021d61046e3660046129b7565b611370565b61021d6104813660046129ee565b611492565b348015610491575f80fd5b506004546001600160a01b03166102f8565b3480156104ae575f80fd5b5061021d6104bd36600461255d565b611b1e565b3480156104cd575f80fd5b5061021d6104dc36600461255d565b611b2b565b3480156104ec575f80fd5b506102606104fb366004612a75565b8051602081830181018051600d8252928201919093012091525481565b348015610523575f80fd5b5061021d61053236600461255d565b611bad565b348015610542575f80fd5b5061021d61055136600461299c565b611bba565b348015610561575f80fd5b5061021d61057036600461295e565b611c6e565b348015610580575f80fd5b5061021d61058f36600461299c565b611dbb565b34801561059f575f80fd5b506102606105ae36600461255d565b611ea7565b3480156105be575f80fd5b5061021d6105cd36600461299c565b611eb2565b3480156105dd575f80fd5b5061021d6105ec36600461299c565b611eef565b5f818152600b6020526040812060040154606091906001600160401b0381111561061d5761061d612655565b60405190808252806020026020018201604052801561066657816020015b604080516060810182525f80825260208083018290529282015282525f1990920191018161063b5790505b5090505f5b5f848152600b602052604090206004015481101561071f575f848152600b60209081526040808320848452600501909152908190208151606081019092528054829060ff1660048111156106c1576106c1612574565b60048111156106d2576106d2612574565b8152905463ffffffff6101008204811660208401526501000000000090910416604090910152825183908390811061070c5761070c612aae565b602090810291909101015260010161066b565b5092915050565b61072e611f1f565b600a805460ff1916911515919091179055565b60605f60605f5b8651811015610840578187828151811061076457610764612aae565b60200260200101515f0151600481111561078057610780612574565b88838151811061079257610792612aae565b6020026020010151602001518984815181106107b0576107b0612aae565b6020026020010151604001516040516020016107cf9493929190612ac2565b60405160208183030381529060405291508681815181106107f2576107f2612aae565b60200260200101516040015187828151811061081057610810612aae565b6020026020010151602001516108269190612b0b565b6108369063ffffffff1684612b2a565b9250600101610748565b5087878287463060405160200161085c96959493929190612b3d565b60405160208183030381529060405290505f61087661115a565b90506007548110156108a35760405162461bcd60e51b815260040161089a90612b8a565b60405180910390fd5b6006548111156108c55760405162461bcd60e51b815260040161089a90612bd4565b806108d26012600a612d01565b6005546108df9086612d0f565b6108e99190612d0f565b6108f39190612d26565b92506064610902846061612d0f565b61090c9190612d26565b9250878311801561091b575084155b156109685760405162461bcd60e51b815260206004820152601c60248201527f746f74616c416d6f756e74206f7574206f6620746f6c6572616e636500000000604482015260640161089a565b50979650505050505050565b61097c611f4b565b600a54600160a81b900460ff16156109d65760405162461bcd60e51b815260206004820152601860248201527f4572726f723a20707269766174652073616c65206f6e6c790000000000000000604482015260640161089a565b5f6109df61115a565b90505f6109eb60055490565b9050600754821015610a0f5760405162461bcd60e51b815260040161089a90612b8a565b600654821115610a315760405162461bcd60e51b815260040161089a90612bd4565b5f610a3e6012600a612d01565b610a488434612d0f565b610a529190612d26565b600880545f908152600b602052604080822080546001600160a01b03191633179055825482528082204260019190910155915481529081206002018590559091505b84518160ff161015610e7f575f6040518060600160405280878460ff1681518110610ac157610ac1612aae565b60200260200101515f01516004811115610add57610add612574565b8152602001878460ff1681518110610af757610af7612aae565b60200260200101516020015163ffffffff168152602001878460ff1681518110610b2357610b23612aae565b60209081029190910181015160409081015163ffffffff169092526008545f908152600b8252828120600480820154835260059091019092529190912082518154939450849391929091839160ff19909116906001908490811115610b8a57610b8a612574565b0217905550602082810151825460409485015163ffffffff908116650100000000000268ffffffff00000000001991909316610100021668ffffffffffffffff001990911617179091556008545f908152600b909152908120600401805491610bf283612d45565b9190505550866001600160a01b03167f20efce14e0489f67c8214805467649f1295289560aea62b8d982984dd333e642878460ff1681518110610c3757610c37612aae565b60200260200101515f0151888560ff1681518110610c5757610c57612aae565b602002602001015160200151898660ff1681518110610c7857610c78612aae565b6020026020010151604001516008546001600b5f60085481526020019081526020015f2060040154610caa9190612d5d565b604051610cbb959493929190612d70565b60405180910390a25f5b868360ff1681518110610cda57610cda612aae565b60200260200101516020015163ffffffff168160ff161015610e6a575f85888560ff1681518110610d0d57610d0d612aae565b60200260200101516040015163ffffffff16610d299190612d0f565b905080851015610d7b5760405162461bcd60e51b815260206004820152601c60248201527f4572726f723a206e6f7420656e6f7567682066756e64732073656e7400000000604482015260640161089a565b6008545f908152600b602052604081206003018054839290610d9e908490612b2a565b909155505060025488516001600160a01b039091169063e0aa65c2908b908b9060ff8916908110610dd157610dd1612aae565b60200260200101515f01518b8860ff1681518110610df157610df1612aae565b6020026020010151604001516040518463ffffffff1660e01b8152600401610e1b93929190612dac565b5f604051808303815f87803b158015610e32575f80fd5b505af1158015610e44573d5f803e3d5ffd5b505050508085610e549190612d5d565b9450508080610e6290612ddd565b915050610cc5565b50508080610e7790612ddd565b915050610a94565b5060088054905f610e8f83612d45565b919050555082610e9d601290565b610ea890600a612d01565b610eb29083612d0f565b610ebc9190612d26565b9050610ed06004546001600160a01b031690565b6001600160a01b03166108fc610ee68347612d5d565b6040518115909202915f818181858888f19350505050158015610f0b573d5f803e3d5ffd5b506040515f90339083908381818185875af1925050503d805f8114610f4b576040519150601f19603f3d011682016040523d82523d5f602084013e610f50565b606091505b5050905080610fac5760405162461bcd60e51b815260206004820152602260248201527f4661696c656420746f2077697468647261772072656d61696e696e672066756e604482015261647360f01b606482015260840161089a565b50505050610fb960018055565b5050565b600c5460408051808201909152601a81527f19457468657265756d205369676e6564204d6573736167653a0a000000000000602082015283515f926001600160a01b031691839161100d90611f75565b8660405160200161102093929190612e12565b60408051601f19818403018152908290528051602090910120915081907fbf891138cde1207ad10a38ceb508ea10e0c4189d74933465b76d0a3ada0aeefe905f90a25f61106d8286612004565b9050806001600160a01b0316836001600160a01b03161493505050505b92915050565b611098611f1f565b600655565b6110a5611f1f565b816001600160a01b0316836001600160a01b03167f43734303d11078efad5d02b38924b4e91a189fb2cbbcd429fc52d9f8cedbcdc7836040516110ea91815260200190565b60405180910390a3604051632142170760e11b81523060048201526001600160a01b038381166024830152604482018390528416906342842e0e906064015f604051808303815f87803b15801561113f575f80fd5b505af1158015611151573d5f803e3d5ffd5b50505050505050565b600a545f90819060ff16156111725750600954611271565b5f600a60019054906101000a90046001600160a01b031690505f80826001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa1580156111c9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111ed9190612e51565b50935050925050610e1081426112039190612d5d565b111561123f5760405162461bcd60e51b815260206004820152600b60248201526a5374616c6520707269636560a81b604482015260640161089a565b819350600861124c601290565b6112569190612e9f565b61126190600a612d01565b61126b9085612d0f565b93505050505b5f81116112b75760405162461bcd60e51b81526020600482015260146024820152731155120c9554d1081c985d19481a5b9d985b1a5960621b604482015260640161089a565b919050565b6112c4611f1f565b6112cd5f61202c565b565b6112d7611f1f565b600a8054911515600160a81b0260ff60a81b19909216919091179055565b6112fd611f1f565b6001600160a01b03811661134e5760405162461bcd60e51b81526020600482015260186024820152771e995c9bc81859191c995cdcc81b9bdd08185b1b1bddd95960421b604482015260640161089a565b600480546001600160a01b0319166001600160a01b0392909216919091179055565b611378611f1f565b6040516370a0823160e01b815230600482015282905f906001600160a01b038316906370a0823190602401602060405180830381865afa1580156113be573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113e29190612eb8565b90505f811161142b5760405162461bcd60e51b81526020600482015260156024820152746e6f20746f6b656e7320746f20776974686472617760581b604482015260640161089a565b826001600160a01b0316846001600160a01b03167f33c35f9541201e342d5e7467016e65a0a06182eb12a5f17103f71cec95b6cb298360405161147091815260200190565b60405180910390a361148c6001600160a01b038316848361207b565b50505050565b61149a611f4b565b6114a785858585856120cd565b6114f35760405162461bcd60e51b815260206004820152601760248201527f5369676e617475726520636865636b206661696c65642e000000000000000000604482015260640161089a565b4282116115335760405162461bcd60e51b815260206004820152600e60248201526d27b33332b91032bc3834b932b21760911b604482015260640161089a565b600d816040516115439190612ecf565b9081526020016040518091039020545f146115905780600d826040516115699190612ecf565b908152604051908190036020018120546360f5fdb560e01b825261089a9291600401612eda565b833410156115d95760405162461bcd60e51b81526020600482015260166024820152753737ba1032b737bab3b410333ab732399039b2b7321760511b604482015260640161089a565b5f6115e261115a565b90506007548110156116065760405162461bcd60e51b815260040161089a90612b8a565b6006548111156116285760405162461bcd60e51b815260040161089a90612bd4565b600880545f908152600b602052604080822080546001600160a01b031916331790558254825280822042600191909101819055925482529081902060020183905551600d90611678908590612ecf565b908152604051908190036020019020555f61169260055490565b90505f5b85518110156119e9575f60405180606001604052808884815181106116bd576116bd612aae565b60200260200101515f015160048111156116d9576116d9612574565b81526020018884815181106116f0576116f0612aae565b60200260200101516020015163ffffffff16815260200188848151811061171957611719612aae565b60209081029190910181015160409081015163ffffffff169092526008545f908152600b8252828120600480820154835260059091019092529190912082518154939450849391929091839160ff1990911690600190849081111561178057611780612574565b0217905550602082810151825460409485015163ffffffff908116650100000000000268ffffffff00000000001991909316610100021668ffffffffffffffff001990911617179091556008545f908152600b9091529081206004018054916117e883612d45565b9190505550886001600160a01b03167f20efce14e0489f67c8214805467649f1295289560aea62b8d982984dd333e64288848151811061182a5761182a612aae565b60200260200101515f015189858151811061184757611847612aae565b6020026020010151602001518a868151811061186557611865612aae565b6020026020010151604001516008546001600b5f60085481526020019081526020015f20600401546118979190612d5d565b6040516118a8959493929190612d70565b60405180910390a25f5b8783815181106118c4576118c4612aae565b60200260200101516020015163ffffffff168110156119df57838884815181106118f0576118f0612aae565b60200260200101516040015163ffffffff1661190c9190612d0f565b6008545f908152600b60205260408120600301805490919061192f908490612b2a565b909155505060025488516001600160a01b039091169063e0aa65c2908c908b908790811061195f5761195f612aae565b60200260200101515f01518b878151811061197c5761197c612aae565b6020026020010151604001516040518463ffffffff1660e01b81526004016119a693929190612dac565b5f604051808303815f87803b1580156119bd575f80fd5b505af11580156119cf573d5f803e3d5ffd5b5050600190920191506118b29050565b5050600101611696565b505f826119f86012600a612d01565b6008545f908152600b6020526040902060030154611a169190612d0f565b611a209190612d26565b6008545f908152600b60209081526040918290206003015482519081529081018a90529081018290529091507f7297f33a8e990a270c83b2aa90206bbf193b1114e7e5992ea9232ae12d25f7259060600160405180910390a160088054905f611a8883612d45565b90915550506004546040516001600160a01b039091169088156108fc029089905f818181858888f19350505050158015611ac4573d5f803e3d5ffd5b505f611ad08834612d5d565b1115611b0b57336108fc611ae48934612d5d565b6040518115909202915f818181858888f19350505050158015611b09573d5f803e3d5ffd5b505b505050611b1760018055565b5050505050565b611b26611f1f565b600755565b611b33611f1f565b5f8111611ba85760405162461bcd60e51b815260206004820152603760248201527f65786368616e6765207261746520555344202f204f696c58436f696e204f584360448201527f206d7573742062652067726561746572207468616e2030000000000000000000606482015260840161089a565b600555565b611bb5611f1f565b600955565b611bc2611f1f565b6001600160a01b038116611c135760405162461bcd60e51b81526020600482015260186024820152771e995c9bc81859191c995cdcc81b9bdd08185b1b1bddd95960421b604482015260640161089a565b600c546040516001600160a01b038084169216907ff8860221d94e42d8f02e7a3b210935252e75a1a9c9f9097dc3b19b3976209ef4905f90a3600c80546001600160a01b0319166001600160a01b0392909216919091179055565b611c76611f1f565b604051627eeac760e11b81523060048201526024810182905283905f906001600160a01b0383169062fdd58e90604401602060405180830381865afa158015611cc1573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ce59190612eb8565b9050836001600160a01b0316856001600160a01b03167fd19a6af682b2b021929d6816639021ffe41d313e2c6878d5dc4924b523be56b28584604051611d35929190918252602082015260400190565b60405180910390a3604051637921219560e11b81523060048201526001600160a01b038581166024830152604482018590526064820183905260a060848301525f60a483015283169063f242432a9060c4015f604051808303815f87803b158015611d9e575f80fd5b505af1158015611db0573d5f803e3d5ffd5b505050505050505050565b611dc3611f1f565b60405147808252906001600160a01b038316907f4763bc463030eb8587a5d2e88d878ee60d7bad204c1b812fed2b3f505473cd7a9060200160405180910390a25f826001600160a01b0316826040515f6040518083038185875af1925050503d805f8114611e4c576040519150601f19603f3d011682016040523d82523d5f602084013e611e51565b606091505b5050905080611ea25760405162461bcd60e51b815260206004820152601860248201527f4661696c656420746f2077697468647261772045746865720000000000000000604482015260640161089a565b505050565b5f61108a8242612b2a565b611eba611f1f565b6001600160a01b038116611ee357604051631e4fbdf760e01b81525f600482015260240161089a565b611eec8161202c565b50565b611ef7611f1f565b600a80546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b5f546001600160a01b031633146112cd5760405163118cdaa760e01b815233600482015260240161089a565b600260015403611f6e57604051633ee5aeb560e01b815260040160405180910390fd5b6002600155565b60605f611f818361212a565b60010190505f816001600160401b03811115611f9f57611f9f612655565b6040519080825280601f01601f191660200182016040528015611fc9576020820181803683370190505b5090508181016020015b5f19016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a8504945084611fd357509392505050565b5f805f806120128686612201565b925092509250612022828261224a565b5090949350505050565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052611ea2908490612302565b5f806120dc878787875f610741565b90507f21f454c12ec230b180b16438a5316946a24908f661bb163465fd27ace1a467178160405161210d919061283c565b60405180910390a161211f8184610fbd565b979650505050505050565b5f8072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b83106121685772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310612194576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc1000083106121b257662386f26fc10000830492506010015b6305f5e10083106121ca576305f5e100830492506008015b61271083106121de57612710830492506004015b606483106121f0576064830492506002015b600a831061108a5760010192915050565b5f805f8351604103612238576020840151604085015160608601515f1a61222a88828585612363565b955095509550505050612243565b505081515f91506002905b9250925092565b5f82600381111561225d5761225d612574565b03612266575050565b600182600381111561227a5761227a612574565b036122985760405163f645eedf60e01b815260040160405180910390fd5b60028260038111156122ac576122ac612574565b036122cd5760405163fce698f760e01b81526004810182905260240161089a565b60038260038111156122e1576122e1612574565b03610fb9576040516335e2f38360e21b81526004810182905260240161089a565b5f6123166001600160a01b0384168361242b565b905080515f1415801561233a5750808060200190518101906123389190612efb565b155b15611ea257604051635274afe760e01b81526001600160a01b038416600482015260240161089a565b5f80807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a084111561239c57505f91506003905082612421565b604080515f808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa1580156123ed573d5f803e3d5ffd5b5050604051601f1901519150506001600160a01b03811661241857505f925060019150829050612421565b92505f91508190505b9450945094915050565b606061243883835f61243f565b9392505050565b6060814710156124645760405163cd78605960e01b815230600482015260240161089a565b5f80856001600160a01b0316848660405161247f9190612ecf565b5f6040518083038185875af1925050503d805f81146124b9576040519150601f19603f3d011682016040523d82523d5f602084013e6124be565b606091505b50915091506124ce8683836124d8565b9695505050505050565b6060826124ed576124e882612534565b612438565b815115801561250457506001600160a01b0384163b155b1561252d57604051639996b31560e01b81526001600160a01b038516600482015260240161089a565b5080612438565b8051156125445780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b5f6020828403121561256d575f80fd5b5035919050565b634e487b7160e01b5f52602160045260245ffd5b600581106125a457634e487b7160e01b5f52602160045260245ffd5b9052565b602080825282518282018190525f918401906040840190835b8181101561260e5783516125d6848251612588565b63ffffffff602082015116602085015263ffffffff6040820151166040850152506060830192506020840193506001810190506125c1565b509095945050505050565b8015158114611eec575f80fd5b5f60208284031215612636575f80fd5b813561243881612619565b6001600160a01b0381168114611eec575f80fd5b634e487b7160e01b5f52604160045260245ffd5b604051606081016001600160401b038111828210171561268b5761268b612655565b60405290565b604051601f8201601f191681016001600160401b03811182821017156126b9576126b9612655565b604052919050565b803563ffffffff811681146112b7575f80fd5b5f82601f8301126126e3575f80fd5b81356001600160401b038111156126fc576126fc612655565b61270b60208260051b01612691565b8082825260208201915060206060840286010192508583111561272c575f80fd5b602085015b838110156127925760608188031215612748575f80fd5b612750612669565b81356005811061275e575f80fd5b815261276c602083016126c1565b602082015261277d604083016126c1565b60408201528352602090920191606001612731565b5095945050505050565b5f805f805f60a086880312156127b0575f80fd5b85356127bb81612641565b94506020860135935060408601356001600160401b038111156127dc575f80fd5b6127e8888289016126d4565b93505060608601359150608086013561280081612619565b809150509295509295909350565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b602081525f612438602083018461280e565b5f806040838503121561285f575f80fd5b823561286a81612641565b915060208301356001600160401b03811115612884575f80fd5b612890858286016126d4565b9150509250929050565b5f82601f8301126128a9575f80fd5b81356001600160401b038111156128c2576128c2612655565b6128d5601f8201601f1916602001612691565b8181528460208386010111156128e9575f80fd5b816020850160208301375f918101602001919091529392505050565b5f8060408385031215612916575f80fd5b82356001600160401b0381111561292b575f80fd5b6129378582860161289a565b92505060208301356001600160401b03811115612952575f80fd5b6128908582860161289a565b5f805f60608486031215612970575f80fd5b833561297b81612641565b9250602084013561298b81612641565b929592945050506040919091013590565b5f602082840312156129ac575f80fd5b813561243881612641565b5f80604083850312156129c8575f80fd5b82356129d381612641565b915060208301356129e381612641565b809150509250929050565b5f805f805f60a08688031215612a02575f80fd5b8535612a0d81612641565b94506020860135935060408601356001600160401b03811115612a2e575f80fd5b612a3a888289016126d4565b9350506060860135915060808601356001600160401b03811115612a5c575f80fd5b612a688882890161289a565b9150509295509295909350565b5f60208284031215612a85575f80fd5b81356001600160401b03811115612a9a575f80fd5b612aa68482850161289a565b949350505050565b634e487b7160e01b5f52603260045260245ffd5b608081525f612ad4608083018761280e565b60208301959095525063ffffffff92831660408201529116606090910152919050565b634e487b7160e01b5f52601160045260245ffd5b63ffffffff818116838216029081169081811461071f5761071f612af7565b8082018082111561108a5761108a612af7565b60018060a01b038716815285602082015260c060408201525f612b6360c083018761280e565b60608301959095525060808101929092526001600160a01b031660a0909101529392505050565b6020808252602a908201527f4572726f723a2065786368616e67652072617465204554482f5553442062656c6040820152696f77206d696e696d756d60b01b606082015260800190565b6020808252602a908201527f4572726f723a2065786368616e67652072617465204554482f5553442061626f6040820152697665206d6178696d756d60b01b606082015260800190565b6001815b6001841115612c5957808504811115612c3d57612c3d612af7565b6001841615612c4b57908102905b60019390931c928002612c22565b935093915050565b5f82612c6f5750600161108a565b81612c7b57505f61108a565b8160018114612c915760028114612c9b57612cb7565b600191505061108a565b60ff841115612cac57612cac612af7565b50506001821b61108a565b5060208310610133831016604e8410600b8410161715612cda575081810a61108a565b612ce65f198484612c1e565b805f1904821115612cf957612cf9612af7565b029392505050565b5f61243860ff841683612c61565b808202811582820484141761108a5761108a612af7565b5f82612d4057634e487b7160e01b5f52601260045260245ffd5b500490565b5f60018201612d5657612d56612af7565b5060010190565b8181038181111561108a5761108a612af7565b60a08101612d7e8288612588565b63ffffffff8616602083015263ffffffff851660408301528360608301528260808301529695505050505050565b6001600160a01b038416815260608101612dc96020830185612588565b63ffffffff83166040830152949350505050565b5f60ff821660ff8103612df257612df2612af7565b60010192915050565b5f81518060208401855e5f93019283525090919050565b5f612e2f612e29612e238488612dfb565b86612dfb565b84612dfb565b95945050505050565b805169ffffffffffffffffffff811681146112b7575f80fd5b5f805f805f60a08688031215612e65575f80fd5b612e6e86612e38565b60208701516040880151606089015192975090955093509150612e9360808701612e38565b90509295509295909350565b60ff828116828216039081111561108a5761108a612af7565b5f60208284031215612ec8575f80fd5b5051919050565b5f6124388284612dfb565b604081525f612eec604083018561280e565b90508260208301529392505050565b5f60208284031215612f0b575f80fd5b81516124388161261956fea26469706673582212203ea7fcfb4519b5bf3b8dba5dfba9e8807a7e8ca98d1dd561122baf372107f04864736f6c634300081a0033

Verified Source Code Full Match

Compiler: v0.8.26+commit.8a97fa7a EVM: cancun Optimization: Yes (200 runs)
SalesContractNft.sol 507 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "./OilXEnumDeclaration.sol";
import "./WithdrawContracts.sol";
import "./NftMinter.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; //OIA-10

abstract contract ChainlinkOracle {
  function latestAnswer() public view virtual returns (int256);

  function latestRoundData()
    public
    view
    virtual
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );
}

/* 
* @title OilXCoin NFT Sales Contract
* @notice This contract allows users to purchase OilXCoin NFTs by paying Ether. 
*         Each NFT represents a specified amount of OilXCoin tokens.
*/
contract SalesContractNft is WithdrawContractsOwnable, ReentrancyGuard {
  NftMinter nftMinter;

  address internal _oilXCoinContractAddress;
  address internal _salesWalletAddress;

  uint256 internal _exchangeRatePerOxcInUsd;
  uint256 internal _maxRateETH2USD;
  uint256 internal _minRateETH2USD;
  uint256 public totalOrders;

  uint256 private _exchangeRateETHUSDfixed;
  bool private _useexchangeRateETHUSDfixed; // Chainlink not exists on testnet
  address internal _addressChainlinkOracle;

  bool privateSaleOnly = true;

  event Purchase(
    address indexed to,
    OilXNftTokenType nftType,
    uint32 quantity,
    uint32 amountOXC,
    uint256 orderId,
    uint256 orderPos
  );

  /**
   * for ABI decode event in webshop
   */
  event MintOilXNFT(
    address indexed to,
    uint256 indexed tokenId,
    OilXNftTokenType tokenType,
    uint256 indexed amountOXC
  );

  /**
   * for ABI decode event in webshop
   */
  event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

  // store order information
  struct Basket {
    OilXNftTokenType purchaseNFTtype;
    uint32 quantity;
    uint32 amountOXC;
  }

  struct Order {
    address buyer;
    uint256 timestamp;
    uint256 exchangeRate;
    uint256 totalAmount;
    uint256 numPositions;
    mapping(uint256 => Basket) positions;
  }

  mapping(uint256 => Order) public orderbook;

  /*
  * @notice Constructor for the SalesContractNft contract
  * @param _addressNftMinter The address of the NftMinter contract
  * @dev NftMinter contract stores mint date for each NFT for vesting
  */
  constructor(address _addressNftMinter, address _salesWallet, address _owner)
    WithdrawContractsOwnable(_owner)
  {
    require(_addressNftMinter != address(0), "nft minter address not set");
    require(_salesWallet != address(0), "sales wallet address not set");
    require(_owner != address(0), "owner address not set");

    _salesWalletAddress = _salesWallet; //receives ETH from sales
    nftMinter = NftMinter(_addressNftMinter);

    // Chainlink Oracle address for ETH/USD rate
    _addressChainlinkOracle = 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419;
    _useexchangeRateETHUSDfixed = false;
    _exchangeRateETHUSDfixed = 1750 * 10 ** decimals(); // price approx at 22.04.2025
    _maxRateETH2USD = 3000 * 10 ** decimals(); // 1 ETH = 3000 US$
    _minRateETH2USD = 1500 * 10 ** decimals();
    _exchangeRatePerOxcInUsd = 1 * 10 ** decimals(); // 1 OXC = 1 US$
  }

  function decimals() public pure returns (uint8) {
    return 18;
  }

  function getRateETH2USD() public view returns (uint256) {
    // ETH 2 USD rate - on testnet chainlink not exists
    uint256 rate;
    if (_useexchangeRateETHUSDfixed) {
      rate = uint256(_exchangeRateETHUSDfixed);
    } else {
      ChainlinkOracle oracle = ChainlinkOracle(_addressChainlinkOracle);
      (, int256 answer,, uint256 updatedAt,) = oracle.latestRoundData();
      require(block.timestamp - updatedAt <= 3600, "Stale price"); //OIA-02
      rate = uint256(answer);
      rate = rate * 10 ** (decimals() - 8); // convert from 10**8 to 10**18
    }
    require(rate > 0, "ETH2USD rate invalid");
    return rate;
  }

  function getRatePerOxcInUsd() public view returns (uint256) {
    return (_exchangeRatePerOxcInUsd);
  }

  function setExchangeRateOilXCoin(uint256 _newrate) public onlyOwner {
    require(_newrate > 0, "exchange rate USD / OilXCoin OXC must be greater than 0"); //OIA-03
    _exchangeRatePerOxcInUsd = _newrate;
  }

  // @dev tolerance for ETH2USD rate
  function setExchangeRateETHmin(uint256 minValue) public onlyOwner {
    _minRateETH2USD = minValue;
  }

  // @dev fallback for manual exchange rate
  function setexchangeRateETHUSDfixed(uint256 value) public onlyOwner {
    _exchangeRateETHUSDfixed = value;
  }

  // @dev fallback for manual exchange rate
  function setuseexchangeRateETHUSDfixed(bool value) public onlyOwner {
    _useexchangeRateETHUSDfixed = value;
  }

  // @dev tolerance for ETH2USD rate
  function setExchangeRateETHmax(uint256 maxValue) public onlyOwner {
    _maxRateETH2USD = maxValue;
  }

  function setChainLinkOracle(address address_) public onlyOwner {
    // depends on chain, can be deactivated by setting to address(0)
    _addressChainlinkOracle = address_;
  }

  /*
  * @notice read order history from orderbook
  * @param orderId The ID of the order
  * @return buyer The address of the buyer
  * @return timestamp The timestamp of the order
  * @return exchangeRate The exchange rate of the order
  * @return totalAmount The total amount of the order
    returns (
      address buyer,
      uint256 timestamp,
      uint256 exchangeRate,
      uint256 totalAmount,
      uint256 numPositions
    )
  {
    buyer = orderbook[orderId].buyer;
    timestamp = orderbook[orderId].timestamp;
    exchangeRate = orderbook[orderId].exchangeRate;
    totalAmount = orderbook[orderId].totalAmount;
    numPositions = orderbook[orderId].numPositions;
  }

  /*
  * @notice read order basket from orderbook
  * @param orderId The ID of the order
  * @return basket The basket of the order
  */
  function getOrderBasket(uint256 orderId) public view returns (Basket[] memory) {
    Basket[] memory basket = new Basket[](orderbook[orderId].numPositions);

    for (uint256 i = 0; i < orderbook[orderId].numPositions; i++) {
      basket[i] = orderbook[orderId].positions[i];
    }
    return basket;
  }

  /*
  * @notice get the contract address
  * @return _oilXCoinContractAddress The address of the OilXCoin NFT contract
  */
  function getContractAddress() public view returns (address) {
    return _oilXCoinContractAddress;
  }

  /*
  * @notice set the sales wallet address
  * @param salesWallet The address of the sales wallet
  */
  function setSalesWalletAddress(address salesWallet) public onlyOwner {
    require(salesWallet != address(0), "zero address not allowed");
    _salesWalletAddress = salesWallet;
  }

  function getSalesWalletAddress() public view returns (address) {
    return _salesWalletAddress;
  }

  /// @dev purchase NFTs with ETH directly
  function purchase(address to, Basket[] memory basket) public payable nonReentrant {
    require(!privateSaleOnly, "Error: private sale only");
    uint256 rateETHUSD = getRateETH2USD();
    uint256 rateOxcUsd = getRatePerOxcInUsd();

    // ETH / USD out of range?
    require(rateETHUSD >= _minRateETH2USD, "Error: exchange rate ETH/USD below minimum");
    require(rateETHUSD <= _maxRateETH2USD, "Error: exchange rate ETH/USD above maximum");

    // calculate total amount in USD, basis Salesrate for OXC
    uint256 remainingFunds = (msg.value * rateETHUSD) / 10 ** decimals();

    // Order Head
    orderbook[totalOrders].buyer = msg.sender;
    orderbook[totalOrders].timestamp = block.timestamp;
    orderbook[totalOrders].exchangeRate = rateETHUSD;

    for (uint8 i = 0; i < basket.length; i++) {
      /* save basket information */
      Basket memory pos = Basket(basket[i].purchaseNFTtype, basket[i].quantity, basket[i].amountOXC);
      orderbook[totalOrders].positions[orderbook[totalOrders].numPositions] = pos;
      orderbook[totalOrders].numPositions++;

      emit Purchase(
        to,
        basket[i].purchaseNFTtype,
        basket[i].quantity,
        basket[i].amountOXC,
        totalOrders,
        orderbook[totalOrders].numPositions - 1
      );

      /* mint NFTs for each basket position */
      for (uint8 amount = 0; amount < basket[i].quantity; amount++) {
        /* amountOXC sent without 18 decimals, but rateOXCUSD has 18 decimals */
        uint256 buyOilXCoinAmount = basket[i].amountOXC * rateOxcUsd;
        require(remainingFunds >= buyOilXCoinAmount, "Error: not enough funds sent"); // funds in
          // US$!
        orderbook[totalOrders].totalAmount += buyOilXCoinAmount; // Order Total Amount in US$
        // use NFT minter contract to store mint date for vesting
        nftMinter.safeMintTs(to, basket[i].purchaseNFTtype, basket[i].amountOXC);
        remainingFunds -= buyOilXCoinAmount;
      }
    }

    totalOrders++;
    // rate has 18 decimals, add decimals again!
    remainingFunds = (remainingFunds * 10 ** decimals()) / rateETHUSD;
    // withdraw to sales wallet
    payable(getSalesWalletAddress()).transfer(address(this).balance - remainingFunds);
    // withdraw remaining funds
    (bool success,) = msg.sender.call{value: remainingFunds}("");
    require(success, "Failed to withdraw remaining funds");
  }

  /*
  * @notice Defines if sales are allowed directly or require a signed message
  * @param value The value to set private sale only
  */
  function setPrivateSaleOnly(bool value) public onlyOwner {
    privateSaleOnly = value;
  }
}

/*
* @title SalesContractNftPurchaseWithOffer
* @notice This contract allows to purchase through signed offers from the webshop
* @dev private sale only with signed offers*/
contract SalesContractNftPurchaseWithOffer is SalesContractNft {
  using ECDSA for bytes32;

  bytes constant prefix = "\x19Ethereum Signed Message:\n";

  address SalesSigner;
  mapping(bytes => uint256) public signatureUsed; //list of used signatures

  event LogHash(bytes32 indexed msg);
  event LogMessage(bytes msg);
  event OfferTotalAmount(uint256 totalOilX, uint256 sendETH, uint256 estETH);
  event NewSalesSigner(address indexed oldSigner, address indexed newSigner);

  event PurchaseOffer(
    address indexed _to,
    OilXNftTokenType nftType,
    uint32 quantity,
    uint32 amountOilXCoin,
    uint256 orderID,
    uint256 orderPos,
    uint256 totalAmount,
    string signer
  );

  /**
   * @notice Error indicating that a signature has already been used
   * @param signature The signature that was used
   * @param timestamp The timestamp when the signature was used
   */
  error SignatureAlreadyUsed(bytes signature, uint256 timestamp);

  /**
   * @notice Constructor for the SalesContractNftPurchaseWithOffer contract
   * @param _addressOilXNft The address of the OilXNft contract
   * @param _salesWallet The address of the sales wallet
   * @param _owner The address of the owner of the contract
   */
  constructor(address _addressOilXNft, address _salesWallet, address _owner)
    SalesContractNft(_addressOilXNft, _salesWallet, _owner)
  {}

  /**
   * @notice Sets the sales signer address, only one signer is possible
   * @param newSigner The new sales signer address
   */
  function setSalesSigner(address newSigner) public onlyOwner {
    require(newSigner != address(0), "zero address not allowed");
    emit NewSalesSigner(SalesSigner, newSigner);
    SalesSigner = newSigner;
  }

  /**
   * @notice Creates a message for the sales signer
   * @param to The address of the buyer
   * @param totalAmount The total amount of the sale
   * @param basket The basket of the sale
   * @param validUntilBlockTimeStamp The valid until block time stamp
   * @param confirmLowPrice Whether to confirm a lower price than the estimated price
   * @return The message for the sales signer to sign
   */
  function createSignerMessage(
    address to,
    uint256 totalAmount,
    Basket[] memory basket,
    uint256 validUntilBlockTimeStamp,
    bool confirmLowPrice
  ) public view returns (bytes memory) {
    uint256 estTotal;

    //* OIA-04 hashing strings removed *//
    bytes memory message;
    for (uint256 i = 0; i < basket.length; i++) {
      message = abi.encode(
        message, uint256(basket[i].purchaseNFTtype), basket[i].quantity, basket[i].amountOXC
      );

      estTotal += basket[i].quantity * basket[i].amountOXC;
    }

    message =
      abi.encode(to, totalAmount, message, validUntilBlockTimeStamp, block.chainid, address(this));

    /* validate and confirm - totalAmount below estimated price */
    /**
     * calculcation:
     *  estTotal = TotalOXC amount without decimals
     *  estTotal = estTotal * getRatePerOxcInUsd() --> price for OXC in USD$ with 18 decimals
     *  estTotal = estTotal * 10 ** decimals() / getRateETH2USD() --> price in ETH with 18 decimals
     *  estTotal = estTotal * 97 / 100; // 3% tolerance
     */
    uint256 exchangeRate = getRateETH2USD();
    require(exchangeRate >= _minRateETH2USD, "Error: exchange rate ETH/USD below minimum");
    require(exchangeRate <= _maxRateETH2USD, "Error: exchange rate ETH/USD above maximum");
    estTotal = estTotal * getRatePerOxcInUsd() * 10 ** decimals() / exchangeRate; //OIA-16
    estTotal = estTotal * 97 / 100; // 3% tolerance

    if (estTotal > totalAmount && !confirmLowPrice) revert("totalAmount out of tolerance");
    return message;
  }

  function verifySignature(bytes memory message, bytes memory signature) public returns (bool) {
    address signer = SalesSigner; // public key/wallet address
    bytes32 hash = keccak256(abi.encodePacked(prefix, Strings.toString(message.length), message));
    emit LogHash(hash);
    address recoveredSigner = hash.recover(signature);
    return signer == recoveredSigner;
  }

  function offerValid(
    address to,
    uint256 totalAmount,
    Basket[] memory basket,
    uint256 validUntilBlockTimeStamp,
    bytes memory signature
  ) internal returns (bool) {
    bytes memory unsignedMsg =
      createSignerMessage(to, totalAmount, basket, validUntilBlockTimeStamp, false); //OIA-06
    emit LogMessage(unsignedMsg);

    return verifySignature(unsignedMsg, signature);
  }

  /**
   * @notice Purchase NFTs with a signed offer
   * @param to The address of the buyer
   * @param totalAmount The total amount of the sale
   * @param basket The basket of the sale
   * @param validUntilBlockTimeStamp The valid until block time stamp
   * @param signature The signature of the sales signer for createSignerMessage
   */
  function purchaseWithOffer(
    address to,
    uint256 totalAmount,
    Basket[] memory basket,
    uint256 validUntilBlockTimeStamp,
    bytes memory signature
  ) public payable nonReentrant {
    /* offer still valid? */
    require(
      offerValid(to, totalAmount, basket, validUntilBlockTimeStamp, signature),
      "Signature check failed."
    );
    require(validUntilBlockTimeStamp > block.timestamp, "Offer expired.");
    if (signatureUsed[signature] != 0) {
      //OIA-05
      /* signatures cannot be reused to prevent duplicate execution */
      revert SignatureAlreadyUsed(signature, signatureUsed[signature]);
    }
    require(msg.value >= totalAmount, "not enough funds send."); // sell for fix price!

    // ETH / USD out of range?
    uint256 exchangeRate = getRateETH2USD();
    require(exchangeRate >= _minRateETH2USD, "Error: exchange rate ETH/USD below minimum");
    require(exchangeRate <= _maxRateETH2USD, "Error: exchange rate ETH/USD above maximum");

    // Order Head
    orderbook[totalOrders].buyer = msg.sender;
    orderbook[totalOrders].timestamp = block.timestamp;
    orderbook[totalOrders].exchangeRate = exchangeRate;
    signatureUsed[signature] = block.timestamp; //OIA-05

    uint256 _rateOxcUsd = getRatePerOxcInUsd();
    for (uint256 i = 0; i < basket.length; i++) {
      /* save basket information */
      Basket memory pos = Basket(basket[i].purchaseNFTtype, basket[i].quantity, basket[i].amountOXC);
      orderbook[totalOrders].positions[orderbook[totalOrders].numPositions] = pos;
      orderbook[totalOrders].numPositions++;

      emit Purchase(
        to,
        basket[i].purchaseNFTtype,
        basket[i].quantity,
        basket[i].amountOXC,
        totalOrders,
        orderbook[totalOrders].numPositions - 1
      );

      for (uint256 amount = 0; amount < basket[i].quantity; amount++) {
        // update orderbook
        orderbook[totalOrders].totalAmount += (basket[i].amountOXC * _rateOxcUsd); // Order
          // Total OilXCoin OXC Amount in US$

        /* mint NFTs for each basket position */
        nftMinter.safeMintTs(to, basket[i].purchaseNFTtype, basket[i].amountOXC);
      }
    }

    /**
     * calculation with off-chain exchange rate
     *  orderbook[totalOrders].totalAmount = TotalOilXCoin OXC Amount in US$ with 18 decimals
     *  estimatedETH = orderbook[totalOrders].totalAmount * 10 ** decimals() / exchangeRate; //
     * Exchange
     *     // rate has 18 decimals
     */
    uint256 estimatedETH = orderbook[totalOrders].totalAmount * 10 ** decimals() / exchangeRate; // Exchange
      // rate has 18 decimals
    emit OfferTotalAmount(orderbook[totalOrders].totalAmount, totalAmount, estimatedETH);

    totalOrders++; //OIA-10
    payable(getSalesWalletAddress()).transfer(totalAmount); // withdrawal to sales wallet

    if (msg.value - totalAmount > 0) payable(msg.sender).transfer(msg.value - totalAmount); // send
      // the rest back
  }

  function getValidToBlockTime(uint256 offset) public view returns (uint256) {
    return block.timestamp + offset;
  }

  function getStringLength(string memory string_) private pure returns (uint256) {
    return bytes(string_).length;
  }
}
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));
    }
}
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);
        }
    }
}
OilXEnumDeclaration.sol 10 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

enum OilXNftTokenType {
  DIAMOND,
  PLATINUM,
  GOLD,
  SILVER,
  BLACK
}
WithdrawContracts.sol 150 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/interfaces/IERC20.sol";
import "@openzeppelin/contracts/interfaces/IERC721.sol";
import "@openzeppelin/contracts/interfaces/IERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
/*
* @title Contract to Recover Tokens or ETH sent by mistake to the contract
* @author OilXCoin.io Dev Team
* @notice Release Tests
*/

contract WithdrawContractsOwnable is Ownable {
  using SafeERC20 for IERC20;

  constructor(address _initialOwner) Ownable(_initialOwner) {}

  event WithdrawERC20(address indexed tokenAddress, address indexed to, uint256 amount);
  event WithdrawERC721(address indexed tokenAddress, address indexed to, uint256 tokenId);
  event WithdrawERC1155(
    address indexed tokenAddress, address indexed to, uint256 tokenId, uint256 amount
  );
  event WithdrawNativeToken(address indexed to, uint256 amount);

  /**
   * @dev Withdraw all ERC20 tokens from the contract
   * @param _tokenAddress Address of the ERC20 contract
   * @param _to Address to send the tokens to
   */
  function withdrawERC20(address _tokenAddress, address _to) public virtual onlyOwner {
    IERC20 token = IERC20(_tokenAddress);
    uint256 balance = token.balanceOf(address(this));
    require(balance > 0, "no tokens to withdraw");
    emit WithdrawERC20(_tokenAddress, _to, balance);
    token.safeTransfer(_to, balance); //WCO-01
  }

  /**
   * @dev Withdraw all ERC721 tokens from the contract
   * @param _tokenAddress Address of the ERC721 contract
   * @param _to Address to send the tokens to
   */
  function withdrawERC721(address _tokenAddress, address _to, uint256 _tokenId) public onlyOwner {
    emit WithdrawERC721(_tokenAddress, _to, _tokenId);
    IERC721(_tokenAddress).safeTransferFrom(address(this), _to, _tokenId);
  }

  /**
   * @dev Withdraw all ERC1155 tokens from the contract
   * @param _tokenAddress Address of the ERC1155 contract
   * @param _to Address to send the tokens to
   */
  function withdrawERC1155(address _tokenAddress, address _to, uint256 _tokenId) public onlyOwner {
    IERC1155 token = IERC1155(_tokenAddress);
    uint256 balance = token.balanceOf(address(this), _tokenId);
    emit WithdrawERC1155(_tokenAddress, _to, _tokenId, balance);
    token.safeTransferFrom(address(this), _to, _tokenId, balance, "");
  }

  /**
   * @dev Withdraw all ETH from the contract
   */
  function withdrawNativeToken(address payable _to) public onlyOwner {
    uint256 balance = address(this).balance;
    emit WithdrawNativeToken(_to, balance);
    (bool success,) = _to.call{value: balance}(""); //WCO-01 OXO-12
    require(success, "Failed to withdraw Ether"); //OXO-12
  }
}

/*
* @title Contract to Recover Tokens or ETH sent by mistake to the contract
* @author OilXCoin.io Dev Team
* @notice Release Tests
*/
contract WithdrawContractsAccessControl is AccessControl {
  using SafeERC20 for IERC20;

  bytes32 public constant WITHDRAWCONTRACT_ROLE = keccak256("WITHDRAWCONTRACT_ROLE");

  constructor(address _initialOwner) {
    _grantRole(WITHDRAWCONTRACT_ROLE, _initialOwner);
  }

  event WithdrawERC20(address indexed tokenAddress, address indexed to, uint256 amount);
  event WithdrawERC721(address indexed tokenAddress, address indexed to, uint256 tokenId);
  event WithdrawERC1155(
    address indexed tokenAddress, address indexed to, uint256 tokenId, uint256 amount
  );
  event WithdrawNativeToken(address indexed to, uint256 amount);

  /**
   * @dev Withdraw all ERC20 tokens from the contract
   * @param _tokenAddress Address of the ERC20 contract
   * @param _to Address to send the tokens to
   */
  function withdrawERC20(address _tokenAddress, address _to)
    public
    virtual
    onlyRole(WITHDRAWCONTRACT_ROLE)
  {
    IERC20 token = IERC20(_tokenAddress);
    uint256 balance = token.balanceOf(address(this));
    require(balance > 0, "no tokens to withdraw");
    emit WithdrawERC20(_tokenAddress, _to, balance);
    token.safeTransfer(_to, balance); //WCO-01
  }

  /**
   * @dev Withdraw all ERC721 tokens from the contract
   * @param _tokenAddress Address of the ERC721 contract
   * @param _to Address to send the tokens to
   */
  function withdrawERC721(address _tokenAddress, address _to, uint256 _tokenId)
    public
    onlyRole(WITHDRAWCONTRACT_ROLE)
  {
    emit WithdrawERC721(_tokenAddress, _to, _tokenId);
    IERC721(_tokenAddress).safeTransferFrom(address(this), _to, _tokenId);
  }

  /**
   * @dev Withdraw all ERC1155 tokens from the contract
   * @param _tokenAddress Address of the ERC1155 contract
   * @param _to Address to send the tokens to
   */
  function withdrawERC1155(address _tokenAddress, address _to, uint256 _tokenId)
    public
    onlyRole(WITHDRAWCONTRACT_ROLE)
  {
    IERC1155 token = IERC1155(_tokenAddress);
    uint256 balance = token.balanceOf(address(this), _tokenId);
    emit WithdrawERC1155(_tokenAddress, _to, _tokenId, balance);
    token.safeTransferFrom(address(this), _to, _tokenId, balance, "");
  }

  /**
   * @dev Withdraw all native Token from the contract
   */
  function withdrawNativeToken(address payable _to) public onlyRole(WITHDRAWCONTRACT_ROLE) {
    uint256 balance = address(this).balance;
    emit WithdrawNativeToken(_to, balance);
    // _to.transfer(balance);
    (bool success,) = _to.call{value: balance}(""); //WCO-01 OXO-12
    require(success, "Failed to withdraw Ether"); //OXO-12
  }
}
NftMinter.sol 143 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "./IOilXCoinNFT.sol";
import "./WithdrawContracts.sol";

interface INftOXC is IOilXCoinNFT {
  function ownerOf(uint256 tokenId) external view returns (address owner);
  function totalSupply() external view returns (uint256);
  function balanceOf(address owner) external view returns (uint256);
  function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
  function safeMint(address to) external;
}

/**
 * @title NftMinter
 * @notice Contract for minting NFTs with timestamp tracking
 * @dev grant NFT minter role to this contract and remove minter role form old salescontract and
 * batchminter, grant this MINTER_ROLE to new salescontract
 */
contract NftMinter is WithdrawContractsAccessControl {
  bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");

  INftOXC oilXNftContract;
  bool public allowBatchMint;

  mapping(uint256 => uint256) public NftMintTs;

  event MintOilXNFT(
    address indexed to,
    uint256 indexed tokenId,
    OilXNftTokenType tokenType,
    uint256 indexed amountOilX
  );

  event MintOilXCoinNftTs(
    address indexed to, uint256 indexed tokenId, uint256 indexed amountOilXCoin, uint256 timestamp
  );

  /**
   * for ABI decode event from NFT
   */
  event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

  struct Basket {
    OilXNftTokenType purchaseNFTtype;
    uint32 quantity;
    uint32 amountOilX;
  }

  /**
   * @notice Emitted when batch minting is enabled or disabled
   * @param enabled The new state of batch minting
   */
  event BatchMintEnabled(bool enabled);

  /**
   * @notice Emitted when NFT contract address is updated
   * @param oldAddress Previous NFT contract address
   * @param newAddress New NFT contract address
   */
  event NFTContractAddressUpdated(address indexed oldAddress, address indexed newAddress);

  /**
   * @notice Emitted when NFT is minted with timestamp
   * @param to Address receiving the NFT
   * @param tokenId ID of minted NFT
   * @param timestamp Block timestamp when NFT was minted
   */
  event NFTMintedWithTimestamp(address indexed to, uint256 indexed tokenId, uint256 timestamp);

  constructor(address _addressOilXNft, address _admin, address _minter)
    WithdrawContractsAccessControl(_admin)
  {
    _grantRole(DEFAULT_ADMIN_ROLE, _admin);
    _grantRole(MINTER_ROLE, _minter);
    oilXNftContract = INftOXC(_addressOilXNft);
    allowBatchMint = true;
  }

  function getNFTAddress() public view returns (address) {
    return address(oilXNftContract);
  }

  function setOnOff(bool _allowBatchMint) public onlyRole(DEFAULT_ADMIN_ROLE) {
    allowBatchMint = _allowBatchMint;
  }

  /**
   * @notice Mints multiple NFTs in a single transaction
   * @param to The address that will own the minted NFTs
   * @param basket An array of Basket structs containing the NFT type and quantity
   * @dev Requires batchmint to be enabled and valid address
   */
  function batchmint(address to, Basket[] memory basket) public onlyRole(MINTER_ROLE) {
    require(allowBatchMint, "Error: batchmint is off");
    require(to != address(0), "Error: address is zero");

    for (uint8 i = 0; i < basket.length; i++) {
      /* mint NFTs for each basket position */
      for (uint8 amount = 0; amount < basket[i].quantity; amount++) {
        safeMintTs(to, basket[i].purchaseNFTtype, basket[i].amountOilX);
      }
    }
  }

  /**
   * @notice Mints a new NFT with timestamp tracking
   * @param to The address that will own the minted NFT
   * @param tokenType The type of NFT to mint (PLATINUM, GOLD, SILVER, BLACK)
   * @param oilXTokenClaimable The amount of OILX tokens that can be claimed with this NFT
   * @dev Mints NFT via nftContract.safeMint() and records timestamp
   * @dev Emits MintOilXCoinNftTs event with token details and timestamp
   */
  function safeMintTs(address to, OilXNftTokenType tokenType, uint256 oilXTokenClaimable)
    public
    onlyRole(MINTER_ROLE)
  {
    uint256 tokenId = oilXNftContract.totalSupply();
    oilXNftContract.safeMint(to, tokenType, oilXTokenClaimable);
    uint256 newSupply = oilXNftContract.totalSupply();
    require(newSupply == tokenId + 1, "nothing minted");
    require(to == oilXNftContract.ownerOf(tokenId), "token belongs to other address");
    // uint256 balance = nftEnumerable.balanceOf(to);
    // require(balance > 0, "Nothing minted");
    // uint256 tokenId = nftEnumerable.tokenOfOwnerByIndex(to, balance - 1);
    // require(totalSupply == tokenId, "Token ID mismatch");

    NftMintTs[tokenId] = block.timestamp;
    emit MintOilXCoinNftTs(to, tokenId, oilXTokenClaimable, block.timestamp);
  }

  /**
   * @notice Retrieves the timestamp when an NFT was minted
   * @param tokenId The ID of the NFT to check
   * @return The timestamp when the NFT was minted
   * @dev Requires the NFT to exist and be minted
   */
  function getNftMintTs(uint256 tokenId) public view returns (uint256) {
    require(oilXNftContract.ownerOf(tokenId) != address(0), "token not minted");
    return NftMintTs[tokenId];
  }
}
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;
    }
}
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);
        }
    }
}
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";
IERC721.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC721.sol)

pragma solidity ^0.8.20;

import {IERC721} from "../token/ERC721/IERC721.sol";
IERC1155.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1155.sol)

pragma solidity ^0.8.20;

import {IERC1155} from "../token/ERC1155/IERC1155.sol";
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);
    }
}
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;
        }
    }
}
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;
    }
}
IOilXCoinNFT.sol 75 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "./OilXEnumDeclaration.sol";

/**
 * @dev OilXCoin Interfaces for contract interactions
 */

/*
* @title OilXNft
* @author OilXCoin.io Dev Team
* @notice Interface for OilXNft
*/
interface IOilXCoinNFT {
  event OilXClaimed(uint256 indexed tokenId, uint256 amount);
  event ClaimedFeeIncreased(uint256 indexed tokenId, uint256 feeAmount);
  event RewardsBlackNFT(uint256 indexed tokenId, uint256 amount);
  event MintOilXNFT(
    address indexed to,
    uint256 indexed tokenId,
    OilXNftTokenType tokenType,
    uint256 indexed amountOilX
  );
  event AddressOilXCoinChanged(address indexed oldAddress, address indexed newAddress);
  event AddressFeeClaimerChanged(address indexed oldAddress, address indexed newAddress);
  event AddressNFTTokenClaimerChanged(address indexed oldAddress, address indexed newAddress);
  event RewardProgrammClosed();

  /**
   * @notice mint a new OilX NFT
   * @param to The address of the new NFT owner
   * @param tokenType The type of the NFT (PLATINUM, GOLD, SILVER, BLACK)
   * @param oilXTokenClaimable The amount of OILX tokens the NFT can claim
   */
  function safeMint(address to, OilXNftTokenType tokenType, uint256 oilXTokenClaimable) external;

  /**
   * @notice returns claimable OILX and resets to 0, for a given tokenId
   * @param tokenId ID of an OilXNFT
   * @return The amount of OILX which can be claimed
   */
  function resetClaimableOilX(uint256 tokenId) external returns (uint256);

  /**
   * @notice OilXCoin token contract can set the address of the token sale claimer contract
   * @param newAddress The address of the new token sale claimer contract
   */
  function setAddressTokenSaleClaimer(address newAddress) external;

  function increaseOilXRewards(uint256 tokenId, uint256 oilXAmount) external;
  function closeRewardProgram() external;

  /**
   * @notice increase amount of claimed ERC-20 fees for NFT. Function will be called by the fee
   * claiming contract
   * @param tokenId The ID of the NFT to increase the claimed fee amount
   * @param feeAmount The amount of ERC-20 fees to increase
   */
  function increaseClaimedOilXFee(uint256 tokenId, uint256 feeAmount) external;

  /**
   * @notice OilXCoin token contract can set the address of the fee claimer contract
   * @param newAddress The address of the new fee claimer contract
   */
  function setAddressFeeClaimer(address newAddress) external;

  /**
   * @notice set OilXCoin ERC-20 token contract address once
   * @param finalAddress The address of the OilXCoin ERC-20 token contract
   */
  function setAddressOilXCoin(address finalAddress) external;

  function updateMetaData(address newAddr) external;
}
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);
}
IERC721.sol 135 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
     *   a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
     *   {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
     *   a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the address zero.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}
IERC1155.sol 127 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (token/ERC1155/IERC1155.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Required interface of an ERC1155 compliant contract, as defined in the
 * https://eips.ethereum.org/EIPS/eip-1155[EIP].
 */
interface IERC1155 is IERC165 {
    /**
     * @dev Emitted when `value` amount of tokens of type `id` are transferred from `from` to `to` by `operator`.
     */
    event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);

    /**
     * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
     * transfers.
     */
    event TransferBatch(
        address indexed operator,
        address indexed from,
        address indexed to,
        uint256[] ids,
        uint256[] values
    );

    /**
     * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
     * `approved`.
     */
    event ApprovalForAll(address indexed account, address indexed operator, bool approved);

    /**
     * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
     *
     * If an {URI} event was emitted for `id`, the standard
     * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
     * returned by {IERC1155MetadataURI-uri}.
     */
    event URI(string value, uint256 indexed id);

    /**
     * @dev Returns the value of tokens of token type `id` owned by `account`.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function balanceOf(address account, uint256 id) external view returns (uint256);

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(
        address[] calldata accounts,
        uint256[] calldata ids
    ) external view returns (uint256[] memory);

    /**
     * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
     *
     * Emits an {ApprovalForAll} event.
     *
     * Requirements:
     *
     * - `operator` cannot be the caller.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
     *
     * See {setApprovalForAll}.
     */
    function isApprovedForAll(address account, address operator) external view returns (bool);

    /**
     * @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`.
     *
     * WARNING: This function can potentially allow a reentrancy attack when transferring tokens
     * to an untrusted contract, when invoking {onERC1155Received} on the receiver.
     * Ensure to follow the checks-effects-interactions pattern and consider employing
     * reentrancy guards when interacting with untrusted contracts.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
     * - `from` must have a balance of tokens of type `id` of at least `value` amount.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes calldata data) external;

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
     *
     * WARNING: This function can potentially allow a reentrancy attack when transferring tokens
     * to an untrusted contract, when invoking {onERC1155BatchReceived} on the receiver.
     * Ensure to follow the checks-effects-interactions pattern and consider employing
     * reentrancy guards when interacting with untrusted contracts.
     *
     * Emits either a {TransferSingle} or a {TransferBatch} event, depending on the length of the array arguments.
     *
     * Requirements:
     *
     * - `ids` and `values` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] calldata ids,
        uint256[] calldata values,
        bytes calldata data
    ) external;
}
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;
    }
}
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;
}
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;
    }
}
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);
}
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();
        }
    }
}
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);
}

Read Contract

createSignerMessage 0x5e2557fd → bytes
decimals 0x313ce567 → uint8
getContractAddress 0x32a2c5d0 → address
getOrderBasket 0x0ddb8388 → tuple[]
getRateETH2USD 0x63bf9770 → uint256
getRatePerOxcInUsd 0x2ca7207b → uint256
getSalesWalletAddress 0x9cf261ec → address
getValidToBlockTime 0xf1bb9745 → uint256
orderbook 0x6b597cb7 → address, uint256, uint256, uint256, uint256
owner 0x8da5cb5b → address
signatureUsed 0xbb10c829 → uint256
totalOrders 0x1d834409 → uint256

Write Contract 18 functions

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

purchase 0xafe781af
address to
tuple[] basket
purchaseWithOffer 0xea12e814
address to
uint256 totalAmount
tuple[] basket
uint256 validUntilBlockTimeStamp
bytes signature
renounceOwnership 0x715018a6
No parameters
setChainLinkOracle 0xf896f7c4
address address_
setExchangeRateETHmax 0x3e9a12fa
uint256 maxValue
setExchangeRateETHmin 0xa17a97ee
uint256 minValue
setExchangeRateOilXCoin 0xba5d2ed2
uint256 _newrate
setPrivateSaleOnly 0x801a4479
bool value
setSalesSigner 0xc1c03a99
address newSigner
setSalesWalletAddress 0x808b472a
address salesWallet
setexchangeRateETHUSDfixed 0xbb7dd066
uint256 value
setuseexchangeRateETHUSDfixed 0x162a61c2
bool value
transferOwnership 0xf2fde38b
address newOwner
verifySignature 0x31f59122
bytes message
bytes signature
returns: bool
withdrawERC1155 0xe532d448
address _tokenAddress
address _to
uint256 _tokenId
withdrawERC20 0x9456fbcc
address _tokenAddress
address _to
withdrawERC721 0x4025feb2
address _tokenAddress
address _to
uint256 _tokenId
withdrawNativeToken 0xe9fe7872
address _to

Recent Transactions

No transactions found for this address