Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x33A219Ec2F9afa19D77E9abE2303253fB5072D91
Balance 0 ETH
Nonce 1
Code Size 13760 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

13760 bytes
0x608060405260043610610395575f3560e01c8063676c0d77116101de578063a053ce1f11610108578063de2c9f001161009d578063ed622dd31161006d578063ed622dd314610a63578063f3f91fa014610a82578063f475582714610aad578063fe575a8714610acc575f5ffd5b8063de2c9f00146109f6578063de8801e514610a15578063e413416014610a2a578063e985e36714610a3f575f5ffd5b8063d1232730116100d8578063d12327301461096e578063d1690fec14610999578063d547741f146109b8578063dcb69101146109d7575f5ffd5b8063a053ce1f14610913578063a217fddf14610927578063a74fc7d81461093a578063c0297a551461094f575f5ffd5b8063817b1cd21161017e5780639155e0831161014e5780639155e083146108a857806391d14854146108c75780639a72be82146108e6578063a04f7d78146108fa575f5ffd5b8063817b1cd21461084c5780638456cb59146108615780638715884d146108755780638e15f47314610894575f5ffd5b80636dbc3145116101b95780636dbc3145146107e457806375b238fc146107f85780637b0a47ee14610818578063808213981461082d575f5ffd5b8063676c0d771461079357806367becdeb146107b2578063686c0f05146107d1575f5ffd5b806336b19cd7116102bf578063597cfe1f1161025f578063608e4dd01161022f578063608e4dd01461072057806361b8b5dc1461073f578063625cf0481461076a57806363b201171461077e575f5ffd5b8063597cfe1f146106915780635c975abb146106bc5780635df4f353146106d35780635eec087014610701575f5ffd5b80633ea521ef1161029a5780633ea521ef1461062a5780633f4ba83a146106495780633fe509ad1461065d578063407fcc311461067c575f5ffd5b806336b19cd7146105c9578063372500ab146105e85780633af32abf146105fc575f5ffd5b8063229f3e29116103355780632f2ff15d116103055780632f2ff15d146105575780632f48ab7d146105765780633222012f1461059557806336568abe146105aa575f5ffd5b8063229f3e29146104c8578063245a7bfc146104dd578063248a9ca3146105145780632b7c440b14610542575f5ffd5b806313bb83381161037057806313bb833814610463578063155dd5ee146104765780631957311e146104955780631e212f1c146104a9575f5ffd5b806301ffc9a7146103d55780630ba36dcd146104095780630d392cd914610442575f5ffd5b366103d15760405134815233907fbfe611b001dfcd411432f7bf0d79b82b4b2ee81511edac123a3403c357fb972a9060200160405180910390a2005b5f5ffd5b3480156103e0575f5ffd5b506103f46103ef366004613122565b610afa565b60405190151581526020015b60405180910390f35b348015610414575f5ffd5b50610434610423366004613164565b600f6020525f908152604090205481565b604051908152602001610400565b34801561044d575f5ffd5b5061046161045c36600461318c565b610b30565b005b6104616104713660046131bd565b610bd6565b348015610481575f5ffd5b506104616104903660046131e5565b610fbf565b3480156104a0575f5ffd5b506104616110b7565b3480156104b4575f5ffd5b506104616104c33660046131e5565b6110de565b3480156104d3575f5ffd5b5061043460055481565b3480156104e8575f5ffd5b506014546104fc906001600160a01b031681565b6040516001600160a01b039091168152602001610400565b34801561051f575f5ffd5b5061043461052e3660046131e5565b5f9081526020819052604090206001015490565b34801561054d575f5ffd5b50610434600a5481565b348015610562575f5ffd5b506104616105713660046131fc565b611132565b348015610581575f5ffd5b506003546104fc906001600160a01b031681565b3480156105a0575f5ffd5b5061043460175481565b3480156105b5575f5ffd5b506104616105c43660046131fc565b61115c565b3480156105d4575f5ffd5b506016546104fc906001600160a01b031681565b3480156105f3575f5ffd5b50610461611194565b348015610607575f5ffd5b506103f4610616366004613164565b60126020525f908152604090205460ff1681565b348015610635575f5ffd5b506104616106443660046131e5565b611356565b348015610654575f5ffd5b5061046161146c565b348015610668575f5ffd5b506104616106773660046131e5565b61148e565b348015610687575f5ffd5b5061043460065481565b34801561069c575f5ffd5b506104346106ab366004613164565b60106020525f908152604090205481565b3480156106c7575f5ffd5b5060025460ff166103f4565b3480156106de575f5ffd5b506103f46106ed366004613164565b60136020525f908152604090205460ff1681565b34801561070c575f5ffd5b5061046161071b366004613164565b6115d7565b34801561072b575f5ffd5b5061046161073a3660046131e5565b611667565b34801561074a575f5ffd5b50610434610759366004613164565b600c6020525f908152604090205481565b348015610775575f5ffd5b506104616118f9565b348015610789575f5ffd5b5061043460085481565b34801561079e575f5ffd5b506104616107ad3660046131e5565b6119ab565b3480156107bd575f5ffd5b506104616107cc3660046131e5565b611a3a565b6104616107df36600461321d565b611ad5565b3480156107ef575f5ffd5b5061046161200e565b348015610803575f5ffd5b506104345f51602061356b5f395f51905f5281565b348015610823575f5ffd5b5061043460075481565b348015610838575f5ffd5b506104616108473660046131e5565b612032565b348015610857575f5ffd5b5061043460095481565b34801561086c575f5ffd5b5061046161207e565b348015610880575f5ffd5b5061043461088f3660046131e5565b61209d565b34801561089f575f5ffd5b506104346120c8565b3480156108b3575f5ffd5b506104616108c236600461318c565b6121b2565b3480156108d2575f5ffd5b506103f46108e13660046131fc565b6122af565b3480156108f1575f5ffd5b506104616122d7565b348015610905575f5ffd5b506018546103f49060ff1681565b34801561091e575f5ffd5b50610434600581565b348015610932575f5ffd5b506104345f81565b348015610945575f5ffd5b5061043460155481565b34801561095a575f5ffd5b5061046161096936600461318c565b612427565b348015610979575f5ffd5b50610434610988366004613164565b600d6020525f908152604090205481565b3480156109a4575f5ffd5b506104616109b336600461325d565b6124bb565b3480156109c3575f5ffd5b506104616109d23660046131fc565b61287a565b3480156109e2575f5ffd5b506104616109f13660046131e5565b61289e565b348015610a01575f5ffd5b50610461610a103660046131e5565b6129ad565b348015610a20575f5ffd5b5061043460045481565b348015610a35575f5ffd5b50610434600b5481565b348015610a4a575f5ffd5b506002546104fc9061010090046001600160a01b031681565b348015610a6e575f5ffd5b50610461610a7d36600461327f565b6129f9565b348015610a8d575f5ffd5b50610434610a9c366004613164565b600e6020525f908152604090205481565b348015610ab8575f5ffd5b50610461610ac73660046131e5565b612af6565b348015610ad7575f5ffd5b506103f4610ae6366004613164565b60116020525f908152604090205460ff1681565b5f6001600160e01b03198216637965db0b60e01b1480610b2a57506301ffc9a760e01b6001600160e01b03198316145b92915050565b5f51602061356b5f395f51905f52610b4781612b91565b6001600160a01b038316610b765760405162461bcd60e51b8152600401610b6d9061329f565b60405180910390fd5b6001600160a01b0383165f81815260126020908152604091829020805460ff191686151590811790915591519182527fa54714518c5d275fdcd3d2a461e4858e4e8cb04fb93cd0bca9d6d34115f2644091015b60405180910390a2505050565b600454421015610bf85760405162461bcd60e51b8152600401610b6d906132c8565b600554421115610c1a5760405162461bcd60e51b8152600401610b6d906132ff565b610c22612b9b565b60185460ff1615610c455760405162461bcd60e51b8152600401610b6d9061332b565b610c4d612be1565b5f3411610c9c5760405162461bcd60e51b815260206004820152601b60248201527f4d7573742073656e642045544820746f2062757920746f6b656e7300000000006044820152606401610b6d565b5f610ca63461209d565b90505f8111610cc75760405162461bcd60e51b8152600401610b6d90613362565b6002546040516370a0823160e01b8152306004820152829161010090046001600160a01b0316906370a0823190602401602060405180830381865afa158015610d12573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d369190613390565b1015610d545760405162461bcd60e51b8152600401610b6d906133a7565b600b5415610d7e57600b54811115610d7e5760405162461bcd60e51b8152600401610b6d906133de565b600a5415610dd757600a54335f90815260106020908152604080832054600c909252909120548391610daf91613441565b610db99190613441565b1115610dd75760405162461bcd60e51b8152600401610b6d90613454565b5f670de0b6b3a7640000610de96120c8565b610df39034613483565b610dfd919061349a565b335f908152600f6020526040812080549293508392909190610e20908490613441565b90915550508315610e3a57610e353383612c3a565b610e5e565b335f9081526010602052604081208054849290610e58908490613441565b90915550505b8160085f828254610e6f9190613441565b909155505060408051838152602081018390525f9133917f9c46ba47a94a38b7e008b5a7a4ae121852c03bd4d17b04e99e99e6a7c734ad2b910160405180910390a35f6001600160a01b03841615801590610ed357506001600160a01b0384163314155b15610f6a576064610ee5600534613483565b610eef919061349a565b6040519091506001600160a01b0385169082156108fc029083905f818181858888f19350505050158015610f25573d5f5f3e3d5ffd5b50836001600160a01b03167f6292f4f27d8047af4537a4bd86906de0e2c880c20086f7f58b81eacfeb63912682604051610f6191815260200190565b60405180910390a25b5f610f7582346134b9565b6016546040519192506001600160a01b03169082156108fc029083905f818181858888f19350505050158015610fad573d5f5f3e3d5ffd5b5050505050610fbb60018055565b5050565b5f51602061356b5f395f51905f52610fd681612b91565b610fde612be1565b5f8211610ffd5760405162461bcd60e51b8152600401610b6d906134cc565b8147101561104d5760405162461bcd60e51b815260206004820152601d60248201527f496e73756666696369656e7420636f6e74726163742062616c616e63650000006044820152606401610b6d565b604051339083156108fc029084905f818181858888f19350505050158015611077573d5f5f3e3d5ffd5b5060405182815233907feaff4b37086828766ad3268786972c0cd24259d4c87a80f9d3963a3c3d999b0d906020015b60405180910390a2610fbb60018055565b5f51602061356b5f395f51905f526110ce81612b91565b506018805460ff19166001179055565b5f51602061356b5f395f51905f526110f581612b91565b600b8290556040518281527f3f1095ffa4a37634d2d2262681a8dec0933583b4cb6d0a7dcadc7363ac961b13906020015b60405180910390a15050565b5f8281526020819052604090206001015461114c81612b91565b6111568383612dbf565b50505050565b6001600160a01b03811633146111855760405163334bd91960e11b815260040160405180910390fd5b61118f8282612e4e565b505050565b61119c612b9b565b60185460ff16156111bf5760405162461bcd60e51b8152600401610b6d9061332b565b6111c7612be1565b60055442116112365760405162461bcd60e51b815260206004820152603560248201527f436c61696d696e672072657761726473206973206f6e6c7920617661696c61626044820152746c652061667465722070726573616c6520656e647360581b6064820152608401610b6d565b335f908152600c60205260409020546112845760405162461bcd60e51b815260206004820152601060248201526f4e6f207374616b656420746f6b656e7360801b6044820152606401610b6d565b335f818152600c6020526040812054909161129e91612eb7565b90505f81116112e65760405162461bcd60e51b81526020600482015260146024820152734e6f207265776172647320617661696c61626c6560601b6044820152606401610b6d565b335f818152600e60205260409020429055600254611314916101009091046001600160a01b03169083612f0d565b60405181815233907ffc30cddea38e2bf4d6ea7d3f9ed3b6ad7f176419f4963bd81318067a4aee73fe906020015b60405180910390a25061135460018055565b565b5f51602061356b5f395f51905f5261136d81612b91565b611375612be1565b5f82116113945760405162461bcd60e51b8152600401610b6d906134cc565b6003546040516370a0823160e01b815230600482015283916001600160a01b0316906370a0823190602401602060405180830381865afa1580156113da573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113fe9190613390565b101561144c5760405162461bcd60e51b815260206004820152601960248201527f496e73756666696369656e7420555344542062616c616e6365000000000000006044820152606401610b6d565b611463336003546001600160a01b03169084612f0d565b610fbb60018055565b5f51602061356b5f395f51905f5261148381612b91565b61148b612f6c565b50565b5f51602061356b5f395f51905f526114a581612b91565b6114ad612be1565b5f82116114cc5760405162461bcd60e51b8152600401610b6d906134cc565b6002546040516370a0823160e01b8152306004820152839161010090046001600160a01b0316906370a0823190602401602060405180830381865afa158015611517573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061153b9190613390565b10156115895760405162461bcd60e51b815260206004820152601d60248201527f4e6f7420656e6f75676820746f6b656e7320696e20636f6e74726163740000006044820152606401610b6d565b6115a53360025461010090046001600160a01b03169084612f0d565b60405182815233907fa2bd9fcfcdba69f52bcd9a520846ad4bd685b187483f53efc42d035b2ddebff0906020016110a6565b5f51602061356b5f395f51905f526115ee81612b91565b6001600160a01b0382166116445760405162461bcd60e51b815260206004820152601c60248201527f496e76616c69642061646d696e2077616c6c65742061646472657373000000006044820152606401610b6d565b50601680546001600160a01b0319166001600160a01b0392909216919091179055565b61166f612b9b565b60185460ff16156116925760405162461bcd60e51b8152600401610b6d9061332b565b61169a612be1565b6017546005546116aa9190613441565b4210156117045760405162461bcd60e51b815260206004820152602260248201527f556e7374616b696e6720616c6c6f776564206f6e6c792061667465722064656c604482015261617960f01b6064820152608401610b6d565b5f81116117535760405162461bcd60e51b815260206004820152601a60248201527f43616e6e6f7420756e7374616b65207a65726f20746f6b656e730000000000006044820152606401610b6d565b335f908152600c60205260409020548111156117b15760405162461bcd60e51b815260206004820152601a60248201527f496e73756666696369656e74207374616b656420746f6b656e730000000000006044820152606401610b6d565b335f818152600c602052604081205490916117cb91612eb7565b905080156118295760405162461bcd60e51b815260206004820152602560248201527f506c6561736520636c61696d2072657761726473206265666f726520756e7374604482015264616b696e6760d81b6064820152608401610b6d565b335f908152600c6020526040812080548492906118479084906134b9565b925050819055508160095f82825461185f91906134b9565b9091555050335f908152600c60205260409020541561188e57335f908152600e6020526040902042905561189e565b335f908152600e60205260408120555b6002546118ba9061010090046001600160a01b03163384612f0d565b60405182815233907f9845e367b683334e5c0b12d7b81721ac518e649376fa65e3d68324e8f34f26799060200160405180910390a25061148b60018055565b611901612b9b565b60185460ff16156119245760405162461bcd60e51b8152600401610b6d9061332b565b61192c612be1565b335f90815260106020526040902054806119885760405162461bcd60e51b815260206004820152601a60248201527f4e6f2070656e64696e6720746f6b656e7320746f207374616b650000000000006044820152606401610b6d565b335f818152601060205260408120556119a19082612c3a565b5061135460018055565b5f51602061356b5f395f51905f526119c281612b91565b5f8211611a055760405162461bcd60e51b815260206004820152601160248201527005072696365206d757374206265203e203607c1b6044820152606401610b6d565b60068290556040518281527f6b361c807733cc94a3b7bda39c1c94dcc0511e91aa47b0f7f918068e9397689090602001611126565b5f51602061356b5f395f51905f52611a5181612b91565b5f8211611aa05760405162461bcd60e51b815260206004820152601860248201527f5374616b696e672072617465206d757374206265203e203000000000000000006044820152606401610b6d565b60078290556040518281527f92749c46491117f2352ccdba7275f6a209aa226631d3fdae50e5a4570d35d1f590602001611126565b600454421015611af75760405162461bcd60e51b8152600401610b6d906132c8565b600554421115611b195760405162461bcd60e51b8152600401610b6d906132ff565b611b21612b9b565b60185460ff1615611b445760405162461bcd60e51b8152600401610b6d9061332b565b611b4c612be1565b335f9081526013602052604090205460ff16611bbf5760405162461bcd60e51b815260206004820152602c60248201527f53656e646572206e6f742077686974656c697374656420666f7220576572742060448201526b7472616e73616374696f6e7360a01b6064820152608401610b6d565b6001600160a01b038316611c155760405162461bcd60e51b815260206004820152601b60248201527f496e76616c69642062656e6566696369617279206164647265737300000000006044820152606401610b6d565b6001600160a01b0383165f9081526011602052604090205460ff1615611c735760405162461bcd60e51b8152602060048201526013602482015272155cd95c881a5cc8189b1858dadb1a5cdd1959606a1b6044820152606401610b6d565b5f3411611cc25760405162461bcd60e51b815260206004820152601b60248201527f4d7573742073656e642045544820746f2062757920746f6b656e7300000000006044820152606401610b6d565b5f611ccc3461209d565b90505f8111611ced5760405162461bcd60e51b8152600401610b6d90613362565b6002546040516370a0823160e01b8152306004820152829161010090046001600160a01b0316906370a0823190602401602060405180830381865afa158015611d38573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d5c9190613390565b1015611d7a5760405162461bcd60e51b8152600401610b6d906133a7565b600b5415611da457600b54811115611da45760405162461bcd60e51b8152600401610b6d906133de565b600a5415611e0657600a546001600160a01b0385165f90815260106020908152604080832054600c909252909120548391611dde91613441565b611de89190613441565b1115611e065760405162461bcd60e51b8152600401610b6d90613454565b5f670de0b6b3a7640000611e186120c8565b611e229034613483565b611e2c919061349a565b6001600160a01b0386165f908152600f6020526040812080549293508392909190611e58908490613441565b90915550508315611e7257611e6d8583612c3a565b611e9f565b6001600160a01b0385165f9081526010602052604081208054849290611e99908490613441565b90915550505b8160085f828254611eb09190613441565b909155505060408051838152602081018390525f916001600160a01b038816917f9c46ba47a94a38b7e008b5a7a4ae121852c03bd4d17b04e99e99e6a7c734ad2b910160405180910390a35f6001600160a01b03841615801590611f265750856001600160a01b0316846001600160a01b031614155b15611fbd576064611f38600534613483565b611f42919061349a565b6040519091506001600160a01b0385169082156108fc029083905f818181858888f19350505050158015611f78573d5f5f3e3d5ffd5b50836001600160a01b03167f6292f4f27d8047af4537a4bd86906de0e2c880c20086f7f58b81eacfeb63912682604051611fb491815260200190565b60405180910390a25b5f611fc882346134b9565b6016546040519192506001600160a01b03169082156108fc029083905f818181858888f19350505050158015612000573d5f5f3e3d5ffd5b505050505061118f60018055565b5f51602061356b5f395f51905f5261202581612b91565b506018805460ff19169055565b5f51602061356b5f395f51905f5261204981612b91565b60178290556040518281527f05effc82ed5865161d9fa57915f64ef50f27cda940f4b330d0caef1df4edab3e90602001611126565b5f51602061356b5f395f51905f5261209581612b91565b61148b612fbe565b5f5f6120a76120c8565b6006549091506120b78285613483565b6120c1919061349a565b9392505050565b5f5f60145f9054906101000a90046001600160a01b03166001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa15801561211a573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061213e919061351c565b5050509150505f811361219d575f601554116121955760405162461bcd60e51b815260206004820152601660248201527511985b1b189858dac81c1c9a58d9481b9bdd081cd95d60521b6044820152606401610b6d565b505060155490565b6121ac816402540be400613483565b91505090565b5f51602061356b5f395f51905f526121c981612b91565b6001600160a01b0383166121ef5760405162461bcd60e51b8152600401610b6d9061329f565b336001600160a01b038416036122585760405162461bcd60e51b815260206004820152602860248201527f41646d696e2063616e6e6f74206d6f64696679206f776e20626c61636b6c6973604482015267742073746174757360c01b6064820152608401610b6d565b6001600160a01b0383165f81815260116020908152604091829020805460ff191686151590811790915591519182527fcf3473b85df1594d47b6958f29a32bea0abff9dd68296f7bf33443646793cfd89101610bc9565b5f918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6122df612b9b565b60185460ff16156123025760405162461bcd60e51b8152600401610b6d9061332b565b61230a612be1565b60055442116123785760405162461bcd60e51b815260206004820152603460248201527f436c61696d696e6720746f6b656e73206973206f6e6c7920617661696c61626c604482015273652061667465722070726573616c6520656e647360601b6064820152608401610b6d565b335f90815260106020526040902054806123c95760405162461bcd60e51b81526020600482015260126024820152714e6f20746f6b656e7320746f20636c61696d60701b6044820152606401610b6d565b335f818152601060205260408120556002546123f5916101009091046001600160a01b03169083612f0d565b60405181815233907f9fbdd9c2d1fb653a7784a36c641afef66ceb12371f5bfe794a3d3a893f755b2890602001611342565b5f51602061356b5f395f51905f5261243e81612b91565b6001600160a01b0383166124645760405162461bcd60e51b8152600401610b6d9061329f565b6001600160a01b0383165f81815260136020908152604091829020805460ff191686151590811790915591519182527f324e7b8eaf7f6a42e2a1464c0a2448bd56e740b8654f00c1830cda53f37825af9101610bc9565b6004544210156124dd5760405162461bcd60e51b8152600401610b6d906132c8565b6005544211156124ff5760405162461bcd60e51b8152600401610b6d906132ff565b612507612b9b565b60185460ff161561252a5760405162461bcd60e51b8152600401610b6d9061332b565b612532612be1565b5f83116125815760405162461bcd60e51b815260206004820152601c60248201527f4d7573742073656e64205553445420746f2062757920746f6b656e73000000006044820152606401610b6d565b6006545f9061259885670de0b6b3a7640000613483565b6125a2919061349a565b90505f81116125c35760405162461bcd60e51b8152600401610b6d90613362565b6002546040516370a0823160e01b8152306004820152829161010090046001600160a01b0316906370a0823190602401602060405180830381865afa15801561260e573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906126329190613390565b10156126505760405162461bcd60e51b8152600401610b6d906133a7565b600b541561267a57600b5481111561267a5760405162461bcd60e51b8152600401610b6d906133de565b600a54156126d357600a54335f90815260106020908152604080832054600c9092529091205483916126ab91613441565b6126b59190613441565b11156126d35760405162461bcd60e51b8152600401610b6d90613454565b335f908152600f6020526040812080548692906126f1908490613441565b909155505060035461270e906001600160a01b0316333087612ffb565b5f6001600160a01b0383161580159061273057506001600160a01b0383163314155b156127aa576064612742600587613483565b61274c919061349a565b600354909150612766906001600160a01b03168483612f0d565b826001600160a01b03167f6292f4f27d8047af4537a4bd86906de0e2c880c20086f7f58b81eacfeb639126826040516127a191815260200190565b60405180910390a25b5f6127b582876134b9565b6016546003549192506127d5916001600160a01b03908116911683612f0d565b84156127ea576127e53384612c3a565b61280e565b335f9081526010602052604081208054859290612808908490613441565b90915550505b8260085f82825461281f9190613441565b909155505060035460408051858152602081018990526001600160a01b039092169133917f9c46ba47a94a38b7e008b5a7a4ae121852c03bd4d17b04e99e99e6a7c734ad2b910160405180910390a350505061118f60018055565b5f8281526020819052604090206001015461289481612b91565b6111568383612e4e565b5f51602061356b5f395f51905f526128b581612b91565b42821161290e5760405162461bcd60e51b815260206004820152602160248201527f50726573616c6520656e64206d75737420626520696e207468652066757475726044820152606560f81b6064820152608401610b6d565b600454821161296f5760405162461bcd60e51b815260206004820152602760248201527f50726573616c6520656e64206d7573742062652061667465722070726573616c60448201526619481cdd185c9d60ca1b6064820152608401610b6d565b600582905560045460408051918252602082018490527f180ac9ee78a8b8bea21e5ff90b3ce6e4d79aed3bf6bff5c576f0bfa8530764bd9101611126565b5f51602061356b5f395f51905f526129c481612b91565b600a8290556040518281527f263d87eb38d19f13627cd1a989280ad1d087944e1c67972654f060fb991f48be90602001611126565b5f51602061356b5f395f51905f52612a1081612b91565b428311612a5f5760405162461bcd60e51b815260206004820152601b60248201527f5374617274206d75737420626520696e207468652066757475726500000000006044820152606401610b6d565b828211612aae5760405162461bcd60e51b815260206004820152601760248201527f456e64206d7573742062652061667465722073746172740000000000000000006044820152606401610b6d565b6004839055600582905560408051848152602081018490527f180ac9ee78a8b8bea21e5ff90b3ce6e4d79aed3bf6bff5c576f0bfa8530764bd910160405180910390a1505050565b5f51602061356b5f395f51905f52612b0d81612b91565b5f8211612b5c5760405162461bcd60e51b815260206004820152601a60248201527f46616c6c6261636b207072696365206d757374206265203e20300000000000006044820152606401610b6d565b60158290556040518281527fef016671b6ed7d62b1a817ff4483fb60a62a693ae9fa4a13a778963dd57d609090602001611126565b61148b8133613034565b60025460ff16156113545760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610b6d565b600260015403612c335760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610b6d565b6002600155565b6001600160a01b038216612c875760405162461bcd60e51b8152602060048201526014602482015273496e76616c69642075736572206164647265737360601b6044820152606401610b6d565b5f8111612ce75760405162461bcd60e51b815260206004820152602860248201527f5374616b696e6720616d6f756e74206d7573742062652067726561746572207460448201526768616e207a65726f60c01b6064820152608401610b6d565b6001600160a01b0382165f908152600c602052604081208054839290612d0e908490613441565b90915550506001600160a01b0382165f908152600d60205260408120549003612d4c576001600160a01b0382165f908152600d602052604090204290555b6001600160a01b0382165f908152600e6020526040812042905560098054839290612d78908490613441565b90915550506040518181526001600160a01b038316907fb539ca1e5c8d398ddf1c41c30166f33404941683be4683319b57669a93dad4ef9060200160405180910390a25050565b5f612dca83836122af565b612e47575f838152602081815260408083206001600160a01b03861684529091529020805460ff19166001179055612dff3390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a4506001610b2a565b505f610b2a565b5f612e5983836122af565b15612e47575f838152602081815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a4506001610b2a565b6001600160a01b0382165f908152600e60205260408120548190612edb90426134b9565b905063bbf81e008160075485612ef19190613483565b612efb9190613483565b612f05919061349a565b949350505050565b6040516001600160a01b0383811660248301526044820183905261118f91859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b03838183161783525050505061306d565b612f746130d9565b6002805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b612fc6612b9b565b6002805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258612fa13390565b6040516001600160a01b0384811660248301528381166044830152606482018390526111569186918216906323b872dd90608401612f3a565b61303e82826122af565b610fbb5760405163e2517d3f60e01b81526001600160a01b038216600482015260248101839052604401610b6d565b5f5f60205f8451602086015f885af18061308c576040513d5f823e3d81fd5b50505f513d915081156130a35780600114156130b0565b6001600160a01b0384163b155b1561115657604051635274afe760e01b81526001600160a01b0385166004820152602401610b6d565b60025460ff166113545760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610b6d565b5f60208284031215613132575f5ffd5b81356001600160e01b0319811681146120c1575f5ffd5b80356001600160a01b038116811461315f575f5ffd5b919050565b5f60208284031215613174575f5ffd5b6120c182613149565b8035801515811461315f575f5ffd5b5f5f6040838503121561319d575f5ffd5b6131a683613149565b91506131b46020840161317d565b90509250929050565b5f5f604083850312156131ce575f5ffd5b6131d78361317d565b91506131b460208401613149565b5f602082840312156131f5575f5ffd5b5035919050565b5f5f6040838503121561320d575f5ffd5b823591506131b460208401613149565b5f5f5f6060848603121561322f575f5ffd5b61323884613149565b92506132466020850161317d565b915061325460408501613149565b90509250925092565b5f5f5f6060848603121561326f575f5ffd5b833592506132466020850161317d565b5f5f60408385031215613290575f5ffd5b50508035926020909101359150565b6020808252600f908201526e496e76616c6964206164647265737360881b604082015260600190565b6020808252601c908201527f50726573616c6520686173206e6f742073746172746564207965742e00000000604082015260600190565b602080825260129082015271283932b9b0b632903430b99032b73232b21760711b604082015260600190565b6020808252601a908201527f55736572206f7065726174696f6e732061726520706175736564000000000000604082015260600190565b602080825260149082015273125b9d985b1a59081d1bdad95b88185b5bdd5b9d60621b604082015260600190565b5f602082840312156133a0575f5ffd5b5051919050565b6020808252601b908201527f4e6f7420656e6f75676820746f6b656e7320617661696c61626c650000000000604082015260600190565b6020808252602f908201527f45786365656473206d6178696d756d20707572636861736520616d6f756e742060408201526e3832b9103a3930b739b0b1ba34b7b760891b606082015260800190565b634e487b7160e01b5f52601160045260245ffd5b80820180821115610b2a57610b2a61342d565b602080825260159082015274141d5c98da185cd94818d85c08195e18d959591959605a1b604082015260600190565b8082028115828204841417610b2a57610b2a61342d565b5f826134b457634e487b7160e01b5f52601260045260245ffd5b500490565b81810381811115610b2a57610b2a61342d565b6020808252601d908201527f5769746864726177616c20616d6f756e74206d757374206265203e2030000000604082015260600190565b805169ffffffffffffffffffff8116811461315f575f5ffd5b5f5f5f5f5f60a08688031215613530575f5ffd5b61353986613503565b6020870151604088015160608901519297509095509350915061355e60808701613503565b9050929550929590935056fea49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775a2646970667358221220b50e111328acd247371b50f75c0af0a70626392b6d511cbc70c0e581762fb76664736f6c634300081c0033

Verified Source Code Full Match

Compiler: v0.8.28+commit.7893614a EVM: cancun Optimization: Yes (200 runs)
AccessControl.sol 209 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)

pragma solidity ^0.8.20;

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

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

    mapping(bytes32 role => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

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

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

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

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

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

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

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

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

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

        _revokeRole(role, callerConfirmation);
    }

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

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

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

pragma solidity ^0.8.20;

/**
 * @dev External interface of AccessControl declared to support ERC-165 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. This account bears the admin role (for the granted role).
     * Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.
     */
    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;
}
IERC1363.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

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

pragma solidity ^0.8.20;

import {IERC20} from "../token/ERC20/IERC20.sol";
Pausable.sol 105 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

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

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

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

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

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

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

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

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

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}
ReentrancyGuard.sol 77 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @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;

    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
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // 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;
    }
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

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

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

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
ERC165.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.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 ERC-165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

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

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; 
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/security/Pausable.sol";

/**
 * @title Aggregator Interface
 * @notice Interface for the price feed aggregator.
 */
interface Aggregator {
    function latestRoundData()
        external
        view
        returns (
            uint80 roundId,
            int256 answer,
            uint256 startedAt,
            uint256 updatedAt,
            uint80 answeredInRound
        );
}

/**
 * @title SecurePresaleV12
 * @notice This contract manages a token presale with optional staking and reward claiming.
 * Purchased tokens that are not staked are locked until the presale ends.
 * Staked tokens accrue rewards (calculated on a per‑second basis) that must be claimed explicitly.
 * The contract implements pausing for user operations, input validations, front‑running protection,
 * and per‑transaction and per‑user maximum purchase limits.
 * Administrative functions are provided to update parameters and withdraw funds.
 */
contract SecurePresaleV12 is AccessControl, ReentrancyGuard, Pausable {
    using SafeERC20 for IERC20;

    // ---------------------------
    // State Variables
    // ---------------------------
    IERC20 public saleToken;
    IERC20 public usdt;

    uint256 public presaleStart;
    uint256 public presaleEnd;
    uint256 public tokenPriceUSD;

    uint256 public rewardRate = 10;
    uint256 public totalTokensSold;
    uint256 public totalStaked;

    uint256 public maxPurchaseCap;
    uint256 public maxPurchaseAmountPerTx;

    mapping(address => uint256) public stakingBalances;
    mapping(address => uint256) public stakingStartTime;
    mapping(address => uint256) public lastClaimedTime;
    mapping(address => uint256) public userDeposits;
    mapping(address => uint256) public pendingPurchase;

    mapping(address => bool) public isBlacklisted;
    mapping(address => bool) public isWhitelisted;
    mapping(address => bool) public wertWhitelisted;

    Aggregator public aggregator;
    uint256 public fallbackPriceETH = 4000 * 1e18;

    address public adminWallet;
    uint256 public constant referralRate = 5;

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

    // Instead of a constant, we use a state variable for the unstaking delay.
    uint256 public unstakeDelay = 7 days;

    // ---------------------------
    // Pausing for User Operations
    // ---------------------------
    bool public userOperationsPaused;

    modifier whenUserNotPaused() {
        require(!userOperationsPaused, "User operations are paused");
        _;
    }

    // ---------------------------
    // Events
    // ---------------------------
    event TokensBought(address indexed user, uint256 amount, address indexed paymentMethod, uint256 usdValue);
    event ETHReceived(address indexed sender, uint256 amount);
    event FundsWithdrawn(address indexed recipient, uint256 amount);
    event TokenWithdrawn(address indexed recipient, uint256 amount);
    event PurchasedTokensClaimed(address indexed user, uint256 amount);
    event Blacklisted(address indexed user, bool status);
    event Whitelisted(address indexed user, bool status);
    event WertWhitelisted(address indexed user, bool status);
    event TokensStaked(address indexed user, uint256 amount);
    event TokensUnstaked(address indexed user, uint256 amount);
    event RewardsClaimed(address indexed user, uint256 rewardAmount);
    event TokenPriceUpdated(uint256 newPrice);
    event PresaleTimesUpdated(uint256 newStart, uint256 newEnd);
    event StakingRateUpdated(uint256 newRate);
    event FallbackPriceUpdated(uint256 newPrice);
    event MaxPurchaseCapUpdated(uint256 newCap);
    event MaxPurchaseAmountPerTxUpdated(uint256 newMax);
    event ReferralPaid(address indexed referral, uint256 amount);
    event UnstakeDelayUpdated(uint256 newDelay);

    modifier onlyDuringPresale() {
        require(block.timestamp >= presaleStart, "Presale has not started yet.");
        require(block.timestamp <= presaleEnd, "Presale has ended.");
        _;
    }

    // ---------------------------
    // Constructor
    // ---------------------------
    constructor(
        address _token,
        address _usdt,
        address _aggregator,
        uint256 _tokenPriceUSD,
        uint256 _presaleStart,
        uint256 _presaleEnd
    ) {
        require(_token != address(0), "Invalid token address");
        require(_usdt != address(0), "Invalid USDT address");
        require(_aggregator != address(0), "Invalid aggregator address");
        require(_presaleStart > block.timestamp, "Presale start must be in the future");
        require(_presaleEnd > _presaleStart, "Presale end must be after start");
        require(_tokenPriceUSD > 0, "Token price must be greater than zero");

        saleToken = IERC20(_token);
        usdt = IERC20(_usdt);
        aggregator = Aggregator(_aggregator);
        tokenPriceUSD = _tokenPriceUSD;
        presaleStart = _presaleStart;
        presaleEnd = _presaleEnd;

        adminWallet = msg.sender;

        _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _grantRole(ADMIN_ROLE, msg.sender);
    }

    // ---------------------------
    // Administrative Pausing Functions
    // ---------------------------
    function pauseUserOperations() external onlyRole(ADMIN_ROLE) {
        userOperationsPaused = true;
    }

    function unpauseUserOperations() external onlyRole(ADMIN_ROLE) {
        userOperationsPaused = false;
    }

    // ---------------------------
    // Purchase Functions with Referral and Purchase Cap
    // ---------------------------
    function buyWithETH(
        bool stake,
        address referral
    )
        external
        payable
        onlyDuringPresale
        whenNotPaused
        whenUserNotPaused
        nonReentrant
    {
        require(msg.value > 0, "Must send ETH to buy tokens");

        uint256 tokensToReceive = calculateTokensForETH(msg.value);
        require(tokensToReceive > 0, "Invalid token amount");
        require(saleToken.balanceOf(address(this)) >= tokensToReceive, "Not enough tokens available");

        if (maxPurchaseAmountPerTx > 0) {
            require(tokensToReceive <= maxPurchaseAmountPerTx, "Exceeds maximum purchase amount per transaction");
        }

        if (maxPurchaseCap > 0) {
            require(
                stakingBalances[msg.sender] + pendingPurchase[msg.sender] + tokensToReceive <= maxPurchaseCap,
                "Purchase cap exceeded"
            );
        }

        uint256 usdValue = (msg.value * getLatestPrice()) / 1e18;
        userDeposits[msg.sender] += usdValue;

        if (stake) {
            _stakeTokens(msg.sender, tokensToReceive);
        } else {
            pendingPurchase[msg.sender] += tokensToReceive;
        }

        totalTokensSold += tokensToReceive;
        emit TokensBought(msg.sender, tokensToReceive, address(0), usdValue);

        uint256 referralAmount = 0;
        if (referral != address(0) && referral != msg.sender) {
            referralAmount = (msg.value * referralRate) / 100;
            payable(referral).transfer(referralAmount);
            emit ReferralPaid(referral, referralAmount);
        }
        uint256 adminAmount = msg.value - referralAmount;
        payable(adminWallet).transfer(adminAmount);
    }

    function buyWithUSDT(
        uint256 _usdtAmount,
        bool stake,
        address referral
    )
        external
        onlyDuringPresale
        whenNotPaused
        whenUserNotPaused
        nonReentrant
    {
        require(_usdtAmount > 0, "Must send USDT to buy tokens");

        uint256 tokensToReceive = (_usdtAmount * 1e18) / tokenPriceUSD;
        require(tokensToReceive > 0, "Invalid token amount");
        require(saleToken.balanceOf(address(this)) >= tokensToReceive, "Not enough tokens available");

        if (maxPurchaseAmountPerTx > 0) {
            require(tokensToReceive <= maxPurchaseAmountPerTx, "Exceeds maximum purchase amount per transaction");
        }

        if (maxPurchaseCap > 0) {
            require(
                stakingBalances[msg.sender] + pendingPurchase[msg.sender] + tokensToReceive <= maxPurchaseCap,
                "Purchase cap exceeded"
            );
        }

        userDeposits[msg.sender] += _usdtAmount;
        usdt.safeTransferFrom(msg.sender, address(this), _usdtAmount);

        uint256 referralAmount = 0;
        if (referral != address(0) && referral != msg.sender) {
            referralAmount = (_usdtAmount * referralRate) / 100;
            usdt.safeTransfer(referral, referralAmount);
            emit ReferralPaid(referral, referralAmount);
        }
        uint256 adminAmount = _usdtAmount - referralAmount;
        usdt.safeTransfer(adminWallet, adminAmount);

        if (stake) {
            _stakeTokens(msg.sender, tokensToReceive);
        } else {
            pendingPurchase[msg.sender] += tokensToReceive;
        }

        totalTokensSold += tokensToReceive;
        emit TokensBought(msg.sender, tokensToReceive, address(usdt), _usdtAmount);
    }

    function buyWithETHWert(
        address _user,
        bool stake,
        address referral
    )
        external
        payable
        onlyDuringPresale
        whenNotPaused
        whenUserNotPaused
        nonReentrant
    {
        require(wertWhitelisted[msg.sender], "Sender not whitelisted for Wert transactions");
        require(_user != address(0), "Invalid beneficiary address");
        require(!isBlacklisted[_user], "User is blacklisted");
        require(msg.value > 0, "Must send ETH to buy tokens");

        uint256 tokensToReceive = calculateTokensForETH(msg.value);
        require(tokensToReceive > 0, "Invalid token amount");
        require(saleToken.balanceOf(address(this)) >= tokensToReceive, "Not enough tokens available");

        if (maxPurchaseAmountPerTx > 0) {
            require(tokensToReceive <= maxPurchaseAmountPerTx, "Exceeds maximum purchase amount per transaction");
        }

        if (maxPurchaseCap > 0) {
            require(
                stakingBalances[_user] + pendingPurchase[_user] + tokensToReceive <= maxPurchaseCap,
                "Purchase cap exceeded"
            );
        }

        uint256 usdValue = (msg.value * getLatestPrice()) / 1e18;
        userDeposits[_user] += usdValue;

        if (stake) {
            _stakeTokens(_user, tokensToReceive);
        } else {
            pendingPurchase[_user] += tokensToReceive;
        }

        totalTokensSold += tokensToReceive;
        emit TokensBought(_user, tokensToReceive, address(0), usdValue);

        uint256 referralAmount = 0;
        if (referral != address(0) && referral != _user) {
            referralAmount = (msg.value * referralRate) / 100;
            payable(referral).transfer(referralAmount);
            emit ReferralPaid(referral, referralAmount);
        }
        uint256 adminAmount = msg.value - referralAmount;
        payable(adminWallet).transfer(adminAmount);
    }

    function claimPurchasedTokens()
        external
        whenNotPaused
        whenUserNotPaused
        nonReentrant
    {
        require(block.timestamp > presaleEnd, "Claiming tokens is only available after presale ends");
        uint256 amount = pendingPurchase[msg.sender];
        require(amount > 0, "No tokens to claim");

        pendingPurchase[msg.sender] = 0;
        saleToken.safeTransfer(msg.sender, amount);
        emit PurchasedTokensClaimed(msg.sender, amount);
    }

    function stakePendingTokens() external whenNotPaused whenUserNotPaused nonReentrant {
        uint256 pendingAmount = pendingPurchase[msg.sender];
        require(pendingAmount > 0, "No pending tokens to stake");

        pendingPurchase[msg.sender] = 0;
        _stakeTokens(msg.sender, pendingAmount);
    }

    // ---------------------------
    // Staking & Reward Functions
    // ---------------------------
    function _stakeTokens(address _user, uint256 _amount) internal {
        require(_user != address(0), "Invalid user address");
        require(_amount > 0, "Staking amount must be greater than zero");

        stakingBalances[_user] += _amount;

        if (stakingStartTime[_user] == 0) {
            stakingStartTime[_user] = block.timestamp;
        }
        lastClaimedTime[_user] = block.timestamp;

        totalStaked += _amount;
        emit TokensStaked(_user, _amount);
    }

    function claimRewards()
        external
        whenNotPaused
        whenUserNotPaused
        nonReentrant
    {
        require(block.timestamp > presaleEnd, "Claiming rewards is only available after presale ends");
        require(stakingBalances[msg.sender] > 0, "No staked tokens");

        uint256 pendingReward = _calculateReward(msg.sender, stakingBalances[msg.sender]);
        require(pendingReward > 0, "No rewards available");

        lastClaimedTime[msg.sender] = block.timestamp;
        saleToken.safeTransfer(msg.sender, pendingReward);
        emit RewardsClaimed(msg.sender, pendingReward);
    }

    function unstakeTokens(uint256 _amount)
        external
        whenNotPaused
        whenUserNotPaused
        nonReentrant
    {
        // Use the adjustable unstakeDelay variable here:
        require(block.timestamp >= presaleEnd + unstakeDelay, "Unstaking allowed only after delay");
        require(_amount > 0, "Cannot unstake zero tokens");
        require(stakingBalances[msg.sender] >= _amount, "Insufficient staked tokens");

        uint256 pendingReward = _calculateReward(msg.sender, stakingBalances[msg.sender]);
        require(pendingReward == 0, "Please claim rewards before unstaking");

        stakingBalances[msg.sender] -= _amount;
        totalStaked -= _amount;

        if (stakingBalances[msg.sender] > 0) {
            lastClaimedTime[msg.sender] = block.timestamp;
        } else {
            lastClaimedTime[msg.sender] = 0;
        }

        saleToken.safeTransfer(msg.sender, _amount);
        emit TokensUnstaked(msg.sender, _amount);
    }

    function _calculateReward(address _user, uint256 _stakedAmount) internal view returns (uint256 reward) {
        uint256 timeDifference = block.timestamp - lastClaimedTime[_user];
        reward = (_stakedAmount * rewardRate * timeDifference) / (365 days * 100);
    }

    // ---------------------------
    // Price Calculation Functions
    // ---------------------------
    function calculateTokensForETH(uint256 _ethAmount) public view returns (uint256 tokens) {
        uint256 ethPrice = getLatestPrice();
        tokens = (_ethAmount * ethPrice) / tokenPriceUSD;
    }

    function getLatestPrice() public view returns (uint256 price) {
        (, int256 answer, , , ) = aggregator.latestRoundData();
        if (answer <= 0) {
            require(fallbackPriceETH > 0, "Fallback price not set");
            return fallbackPriceETH;
        }
        return uint256(answer) * 1e10;
    }

    // ---------------------------
    // Administrative Functions
    // ---------------------------
    function withdrawFunds(uint256 _amount)
        external
        onlyRole(ADMIN_ROLE)
        nonReentrant
    {
        require(_amount > 0, "Withdrawal amount must be > 0");
        require(address(this).balance >= _amount, "Insufficient contract balance");
        payable(_msgSender()).transfer(_amount);
        emit FundsWithdrawn(_msgSender(), _amount);
    }

    function withdrawUSDT(uint256 _amount)
        external
        onlyRole(ADMIN_ROLE)
        nonReentrant
    {
        require(_amount > 0, "Withdrawal amount must be > 0");
        require(usdt.balanceOf(address(this)) >= _amount, "Insufficient USDT balance");
        usdt.safeTransfer(_msgSender(), _amount);
    }

    function withdrawSaleTokens(uint256 _amount)
        external
        onlyRole(ADMIN_ROLE)
        nonReentrant
    {
        require(_amount > 0, "Withdrawal amount must be > 0");
        require(saleToken.balanceOf(address(this)) >= _amount, "Not enough tokens in contract");
        saleToken.safeTransfer(_msgSender(), _amount);
        emit TokenWithdrawn(_msgSender(), _amount);
    }

    function updateStakingRate(uint256 _newRate)
        external
        onlyRole(ADMIN_ROLE)
    {
        require(_newRate > 0, "Staking rate must be > 0");
        rewardRate = _newRate;
        emit StakingRateUpdated(_newRate);
    }

    function updateTokenPrice(uint256 _newPrice)
        external
        onlyRole(ADMIN_ROLE)
    {
        require(_newPrice > 0, "Price must be > 0");
        tokenPriceUSD = _newPrice;
        emit TokenPriceUpdated(_newPrice);
    }

    function updatePresaleTimes(uint256 _newStart, uint256 _newEnd)
        external
        onlyRole(ADMIN_ROLE)
    {
        require(_newStart > block.timestamp, "Start must be in the future");
        require(_newEnd > _newStart, "End must be after start");
        presaleStart = _newStart;
        presaleEnd = _newEnd;
        emit PresaleTimesUpdated(_newStart, _newEnd);
    }
    
    function updatePresaleEnd(uint256 _newEnd) external onlyRole(ADMIN_ROLE) {
        require(_newEnd > block.timestamp, "Presale end must be in the future");
        require(_newEnd > presaleStart, "Presale end must be after presale start");
        presaleEnd = _newEnd;
        emit PresaleTimesUpdated(presaleStart, _newEnd);
    }

    // New admin function to update the unstaking delay.
    function updateUnstakeDelay(uint256 newDelay) external onlyRole(ADMIN_ROLE) {
        unstakeDelay = newDelay;
        emit UnstakeDelayUpdated(newDelay);
    }

    function updateBlacklist(address _user, bool _status)
        external
        onlyRole(ADMIN_ROLE)
    {
        require(_user != address(0), "Invalid address");
        require(_user != msg.sender, "Admin cannot modify own blacklist status");
        isBlacklisted[_user] = _status;
        emit Blacklisted(_user, _status);
    }

    function updateWhitelist(address _user, bool _status)
        external
        onlyRole(ADMIN_ROLE)
    {
        require(_user != address(0), "Invalid address");
        isWhitelisted[_user] = _status;
        emit Whitelisted(_user, _status);
    }

    function updateWertWhitelist(address _user, bool _status)
        external
        onlyRole(ADMIN_ROLE)
    {
        require(_user != address(0), "Invalid address");
        wertWhitelisted[_user] = _status;
        emit WertWhitelisted(_user, _status);
    }

    function updateFallbackPrice(uint256 newPrice) external onlyRole(ADMIN_ROLE) {
        require(newPrice > 0, "Fallback price must be > 0");
        fallbackPriceETH = newPrice;
        emit FallbackPriceUpdated(newPrice);
    }

    function updateMaxPurchaseCap(uint256 newCap) external onlyRole(ADMIN_ROLE) {
        maxPurchaseCap = newCap;
        emit MaxPurchaseCapUpdated(newCap);
    }

    function updateMaxPurchaseAmountPerTx(uint256 newMax) external onlyRole(ADMIN_ROLE) {
        maxPurchaseAmountPerTx = newMax;
        emit MaxPurchaseAmountPerTxUpdated(newMax);
    }

    function updateAdminWallet(address _newAdminWallet) external onlyRole(ADMIN_ROLE) {
        require(_newAdminWallet != address(0), "Invalid admin wallet address");
        adminWallet = _newAdminWallet;
    }

    // ---------------------------
    // Emergency Pause (Global)
    // ---------------------------
    function pause() external onlyRole(ADMIN_ROLE) {
        _pause();
    }

    function unpause() external onlyRole(ADMIN_ROLE) {
        _unpause();
    }

    // ---------------------------
    // Fallback Function
    // ---------------------------
    receive() external payable {
        emit ETHReceived(msg.sender, msg.value);
    }
}

Read Contract

ADMIN_ROLE 0x75b238fc → bytes32
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
adminWallet 0x36b19cd7 → address
aggregator 0x245a7bfc → address
calculateTokensForETH 0x8715884d → uint256
fallbackPriceETH 0xa74fc7d8 → uint256
getLatestPrice 0x8e15f473 → uint256
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
isBlacklisted 0xfe575a87 → bool
isWhitelisted 0x3af32abf → bool
lastClaimedTime 0xf3f91fa0 → uint256
maxPurchaseAmountPerTx 0xe4134160 → uint256
maxPurchaseCap 0x2b7c440b → uint256
paused 0x5c975abb → bool
pendingPurchase 0x597cfe1f → uint256
presaleEnd 0x229f3e29 → uint256
presaleStart 0xde8801e5 → uint256
referralRate 0xa053ce1f → uint256
rewardRate 0x7b0a47ee → uint256
saleToken 0xe985e367 → address
stakingBalances 0x61b8b5dc → uint256
stakingStartTime 0xd1232730 → uint256
supportsInterface 0x01ffc9a7 → bool
tokenPriceUSD 0x407fcc31 → uint256
totalStaked 0x817b1cd2 → uint256
totalTokensSold 0x63b20117 → uint256
unstakeDelay 0x3222012f → uint256
usdt 0x2f48ab7d → address
userDeposits 0x0ba36dcd → uint256
userOperationsPaused 0xa04f7d78 → bool
wertWhitelisted 0x5df4f353 → bool

Write Contract 29 functions

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

buyWithETH 0x13bb8338
bool stake
address referral
buyWithETHWert 0x686c0f05
address _user
bool stake
address referral
buyWithUSDT 0xd1690fec
uint256 _usdtAmount
bool stake
address referral
claimPurchasedTokens 0x9a72be82
No parameters
claimRewards 0x372500ab
No parameters
grantRole 0x2f2ff15d
bytes32 role
address account
pause 0x8456cb59
No parameters
pauseUserOperations 0x1957311e
No parameters
renounceRole 0x36568abe
bytes32 role
address callerConfirmation
revokeRole 0xd547741f
bytes32 role
address account
stakePendingTokens 0x625cf048
No parameters
unpause 0x3f4ba83a
No parameters
unpauseUserOperations 0x6dbc3145
No parameters
unstakeTokens 0x608e4dd0
uint256 _amount
updateAdminWallet 0x5eec0870
address _newAdminWallet
updateBlacklist 0x9155e083
address _user
bool _status
updateFallbackPrice 0xf4755827
uint256 newPrice
updateMaxPurchaseAmountPerTx 0x1e212f1c
uint256 newMax
updateMaxPurchaseCap 0xde2c9f00
uint256 newCap
updatePresaleEnd 0xdcb69101
uint256 _newEnd
updatePresaleTimes 0xed622dd3
uint256 _newStart
uint256 _newEnd
updateStakingRate 0x67becdeb
uint256 _newRate
updateTokenPrice 0x676c0d77
uint256 _newPrice
updateUnstakeDelay 0x80821398
uint256 newDelay
updateWertWhitelist 0xc0297a55
address _user
bool _status
updateWhitelist 0x0d392cd9
address _user
bool _status
withdrawFunds 0x155dd5ee
uint256 _amount
withdrawSaleTokens 0x3fe509ad
uint256 _amount
withdrawUSDT 0x3ea521ef
uint256 _amount

Recent Transactions

No transactions found for this address