Address Contract Verified
Address
0x627a32C64B13EEE9aD418C7Fc8dd1bE28CB1d543
Balance
0.000100000 ETH ($0.20)
Nonce
51
Code Size
13393 bytes
Creator
0xd3F81253...093a at tx 0x80213dad...a978e7
Indexed Transactions
0
Contract Bytecode
13393 bytes
0x6080604052600436106101d15760003560e01c806391d14854116100f7578063c4502e4211610095578063d3792e2a11610064578063d3792e2a146105e6578063d547741f14610606578063f4915f2714610626578063f5b541a61461063b57600080fd5b8063c4502e4214610563578063c824116014610590578063cb804eae146105b0578063cfdbf254146105d057600080fd5b8063a217fddf116100d1578063a217fddf146104da578063ad5c4648146104ef578063b2c22efd14610523578063b4bc25b61461054357600080fd5b806391d148541461047a5780639d2dcde71461049a5780639d2e8724146104ba57600080fd5b806336568abe1161016f5780637ff502f01161013e5780637ff502f0146103ea578063841e5c561461041a5780638985646a1461043a5780638e18cdfc1461045a57600080fd5b806336568abe14610356578063387277f2146103765780634036edc21461039657806375b238fc146103b657600080fd5b80632b26a6bf116101ab5780632b26a6bf146102d25780632f2ff15d146102f45780632f622e6b14610314578063349b59541461033457600080fd5b806301ffc9a7146102125780630758d92414610247578063248a9ca31461029357600080fd5b3661020d5760405134815233907f9820dd13494dd7d9f03807aa0bb724fe8266855b5ac4db99848a199904f8074b9060200160405180910390a2005b600080fd5b34801561021e57600080fd5b5061023261022d3660046123cf565b61065d565b60405190151581526020015b60405180910390f35b34801561025357600080fd5b5061027b7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d81565b6040516001600160a01b03909116815260200161023e565b34801561029f57600080fd5b506102c46102ae3660046123f9565b6000908152600160208190526040909120015490565b60405190815260200161023e565b3480156102de57600080fd5b506102f26102ed3660046123f9565b610694565b005b34801561030057600080fd5b506102f261030f366004612427565b61074f565b34801561032057600080fd5b506102f261032f366004612457565b61077b565b34801561034057600080fd5b506102c46000805160206133dc83398151915281565b34801561036257600080fd5b506102f2610371366004612427565b6108df565b34801561038257600080fd5b506102f2610391366004612474565b610917565b3480156103a257600080fd5b506102f26103b13660046124b5565b610a2d565b3480156103c257600080fd5b506102c47fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177581565b3480156103f657600080fd5b50610232610405366004612457565b60036020526000908152604090205460ff1681565b34801561042657600080fd5b506102c46104353660046123f9565b610b8f565b34801561044657600080fd5b506102f2610455366004612474565b610bce565b34801561046657600080fd5b506102f26104753660046124e3565b610cd8565b34801561048657600080fd5b50610232610495366004612427565b611230565b3480156104a657600080fd5b506102f26104b5366004612529565b61125b565b3480156104c657600080fd5b5061027b6104d53660046123f9565b611534565b3480156104e657600080fd5b506102c4600081565b3480156104fb57600080fd5b5061027b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b34801561052f57600080fd5b506102f261053e3660046123f9565b61155e565b34801561054f57600080fd5b506102f261055e3660046125b3565b611706565b34801561056f57600080fd5b5061058361057e3660046125e8565b611b76565b60405161023e919061264f565b34801561059c57600080fd5b506102f26105ab366004612457565b611c11565b3480156105bc57600080fd5b5061027b6105cb3660046123f9565b611cc6565b3480156105dc57600080fd5b506102c460025481565b3480156105f257600080fd5b506105836106013660046125e8565b611d16565b34801561061257600080fd5b506102f2610621366004612427565b611e7f565b34801561063257600080fd5b506004546102c4565b34801561064757600080fd5b506102c46000805160206133fc83398151915281565b60006001600160e01b03198216637965db0b60e01b148061068e57506301ffc9a760e01b6001600160e01b03198316145b92915050565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c217756106be81611ea5565b600082116107085760405162461bcd60e51b8152602060048201526012602482015271496e76616c69642062617463682073697a6560701b60448201526064015b60405180910390fd5b600280549083905560408051828152602081018590527f6b141d34195f1cbfa2080571bebbe19ad6d201cc0d1d53c70550795d14a4be8391015b60405180910390a1505050565b6000828152600160208190526040909120015461076b81611ea5565b6107758383611eb2565b50505050565b6000805160206133dc83398151915261079381611ea5565b61079b611f2b565b6001600160a01b0382166107e55760405162461bcd60e51b8152602060048201526011602482015270125b9d985b1a59081c9958da5c1a595b9d607a1b60448201526064016106ff565b478061082c5760405162461bcd60e51b81526020600482015260166024820152754e6f2062616c616e636520746f20776974686472617760501b60448201526064016106ff565b6000836001600160a01b03168260405160006040518083038185875af1925050503d8060008114610879576040519150601f19603f3d011682016040523d82523d6000602084013e61087e565b606091505b50509050806108cf5760405162461bcd60e51b815260206004820152601c60248201527f4e617469766520746f6b656e207472616e73666572206661696c65640000000060448201526064016106ff565b50506108db6001600055565b5050565b6001600160a01b03811633146109085760405163334bd91960e11b815260040160405180910390fd5b6109128282611f55565b505050565b6000805160206133fc83398151915261092f81611ea5565b610937611f2b565b6001600160a01b03841660009081526003602052604090205460ff1661096f5760405162461bcd60e51b81526004016106ff90612662565b6001600160a01b0383166109c15760405162461bcd60e51b8152602060048201526019602482015278496e76616c696420726563697069656e74206164647265737360381b60448201526064016106ff565b604051633d64922b60e11b81526001600160a01b03848116600483015260248201849052851690637ac9245690604401600060405180830381600087803b158015610a0b57600080fd5b505af1158015610a1f573d6000803e3d6000fd5b505050506107756001600055565b6000805160206133dc833981519152610a4581611ea5565b610a4d611f2b565b6001600160a01b038316610a735760405162461bcd60e51b81526004016106ff9061268c565b6001600160a01b038216610abd5760405162461bcd60e51b8152602060048201526011602482015270125b9d985b1a59081c9958da5c1a595b9d607a1b60448201526064016106ff565b6040516370a0823160e01b815230600482015283906000906001600160a01b038316906370a0823190602401602060405180830381865afa158015610b06573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b2a91906126bb565b9050610b406001600160a01b0383168583611fc2565b846001600160a01b03167fe89cf45f6d87800815bb4906b7e402f3e1d4659afef69147c92484fe3ff2a7a582604051610b7b91815260200190565b60405180910390a250506109126001600055565b6040516814d55095d05313115560ba1b602082015260298101829052600090604901604051602081830303815290604052805190602001209050919050565b6000805160206133fc833981519152610be681611ea5565b6001600160a01b03841660009081526003602052604090205460ff16610c1e5760405162461bcd60e51b81526004016106ff90612662565b6001600160a01b038316610c705760405162461bcd60e51b8152602060048201526019602482015278496e76616c696420726563697069656e74206164647265737360381b60448201526064016106ff565b60405163da95ebf760e01b81526001600160a01b0384811660048301526024820184905285169063da95ebf790604401600060405180830381600087803b158015610cba57600080fd5b505af1158015610cce573d6000803e3d6000fd5b5050505050505050565b6000805160206133dc833981519152610cf081611ea5565b610cf8611f2b565b6001600160a01b03851615801590610d1857506001600160a01b03841615155b610d345760405162461bcd60e51b81526004016106ff9061268c565b836001600160a01b0316856001600160a01b031603610d8a5760405162461bcd60e51b815260206004820152601260248201527124b73b30b634b2103a37b5b2b7103830b4b960711b60448201526064016106ff565b60008311610dda5760405162461bcd60e51b815260206004820152601d60248201527f416d6f756e74206d7573742062652067726561746572207468616e203000000060448201526064016106ff565b6040516370a0823160e01b815230600482015285906000906001600160a01b038316906370a0823190602401602060405180830381865afa158015610e23573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e4791906126bb565b905084811015610e905760405162461bcd60e51b8152602060048201526014602482015273496e73756666696369656e742062616c616e636560601b60448201526064016106ff565b610ec46001600160a01b0383167f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d87612021565b60607f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316886001600160a01b03161480610f3757507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316876001600160a01b0316145b15610fc95760408051600280825260608201835290916020830190803683370190505090508781600081518110610f7057610f706126ea565b60200260200101906001600160a01b031690816001600160a01b0316815250508681600181518110610fa457610fa46126ea565b60200260200101906001600160a01b031690816001600160a01b0316815250506110a7565b6040805160038082526080820190925290602082016060803683370190505090508781600081518110610ffe57610ffe6126ea565b60200260200101906001600160a01b031690816001600160a01b0316815250507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281600181518110611052576110526126ea565b60200260200101906001600160a01b031690816001600160a01b0316815250508681600281518110611086576110866126ea565b60200260200101906001600160a01b031690816001600160a01b0316815250505b6040516338ed173960e01b81526000906001600160a01b037f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d16906338ed1739906110fe908a908a90879030904290600401612700565b6000604051808303816000875af115801561111d573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611145919081019061273c565b905061119f7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d8260008151811061117e5761117e6126ea565b6020026020010151866001600160a01b03166120ab9092919063ffffffff16565b876001600160a01b0316896001600160a01b03167f25f1d03755df23c30e25db2dbd3891e31ce084bdfbfc46f9fe5e446ee5f9b2d48984600186516111e4919061281f565b815181106111f4576111f46126ea565b6020026020010151604051611213929190918252602082015260400190565b60405180910390a3505050506112296001600055565b5050505050565b60009182526001602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6000805160206133dc83398151915261127381611ea5565b61127b611f2b565b6001600160a01b0384166112a15760405162461bcd60e51b81526004016106ff9061268c565b836000805b848110156114e457600360008787848181106112c4576112c46126ea565b90506020020160208101906112d99190612457565b6001600160a01b0316815260208101919091526040016000205460ff166113125760405162461bcd60e51b81526004016106ff90612662565b6000836001600160a01b03166370a08231888885818110611335576113356126ea565b905060200201602081019061134a9190612457565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa15801561138e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113b291906126bb565b905080156114db5760008787848181106113ce576113ce6126ea565b90506020020160208101906113e39190612457565b6040516001600160a01b038b8116602483015260448201859052919091169060640160408051601f198184030181529181526020820180516001600160e01b03166350edcbc160e11b1790525161143a9190612832565b6000604051808303816000865af19150503d8060008114611477576040519150601f19603f3d011682016040523d82523d6000602084013e61147c565b606091505b50509050806114cd5760405162461bcd60e51b815260206004820152601760248201527f4552433230207769746864726177616c206661696c656400000000000000000060448201526064016106ff565b6114d78285612861565b9350505b506001016112a6565b50856001600160a01b03167f7e2c99819371db0a6fc6f4269fe872496e44f502df19ba3eae594b7a159874608260405161152091815260200190565b60405180910390a250506107756001600055565b6004818154811061154457600080fd5b6000918252602090912001546001600160a01b0316905081565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177561158881611ea5565b816000036115a957604051631a49577b60e11b815260040160405180910390fd5b6002548211156115cc5760405163eb6e620960e01b815260040160405180910390fd5b60045460005b838110156116cf5760006115e96104358385612861565b9050600061161b60008360405180602001611603906123c2565b601f1982820381018352601f90910116604052612168565b6001600160a01b0381166000818152600360205260408120805460ff19166001908117909155600480548083018255928190527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b90920180546001600160a01b03191684179055905492935090917fda37afbf815bb46f18586b298afee8eacc369db901622973daf007019f88e75f916116b49161281f565b60405190815260200160405180910390a250506001016115d2565b5060408051828152602081018590527f1fa29e3a8a15e1b98bb1c9e1a94f930368cefb551e8d5558ca92a203412fbe969101610742565b6000805160206133dc83398151915261171e81611ea5565b611726611f2b565b6001600160a01b03841661174c5760405162461bcd60e51b81526004016106ff9061268c565b6000831161179c5760405162461bcd60e51b815260206004820152601d60248201527f416d6f756e74206d7573742062652067726561746572207468616e203000000060448201526064016106ff565b6040516370a0823160e01b815230600482015284906000906001600160a01b038316906370a0823190602401602060405180830381865afa1580156117e5573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061180991906126bb565b9050848110156118525760405162461bcd60e51b8152602060048201526014602482015273496e73756666696369656e742062616c616e636560601b60448201526064016106ff565b6118866001600160a01b0383167f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d87612021565b60007f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316876001600160a01b0316146118e457604080516002808252606082018352909160208301908036833701905050611902565b60408051600180825281830190925290602080830190803683375050505b90507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316876001600160a01b031603611996577f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281600081518110611971576119716126ea565b60200260200101906001600160a01b031690816001600160a01b031681525050611a1f565b86816000815181106119aa576119aa6126ea565b60200260200101906001600160a01b031690816001600160a01b0316815250507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2816001815181106119fe576119fe6126ea565b60200260200101906001600160a01b031690816001600160a01b0316815250505b6040516318cbafe560e01b81526000906001600160a01b037f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d16906318cbafe590611a76908a908a90879030904290600401612700565b6000604051808303816000875af1158015611a95573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611abd919081019061273c565b9050611af67f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d8260008151811061117e5761117e6126ea565b876001600160a01b03167f8cd2336c72a249c06b8452867c153b6c0830f3be02c95c920fa2a899b5a48419888360018551611b31919061281f565b81518110611b4157611b416126ea565b6020026020010151604051611b60929190918252602082015260400190565b60405180910390a2505050506107756001600055565b606060008267ffffffffffffffff811115611b9357611b936126d4565b604051908082528060200260200182016040528015611bbc578160200160208202803683370190505b50905060005b83811015611c0957611bd76105cb8287612861565b828281518110611be957611be96126ea565b6001600160a01b0390921660209283029190910190910152600101611bc2565b509392505050565b6000805160206133fc833981519152611c2981611ea5565b611c31611f2b565b6001600160a01b03821660009081526003602052604090205460ff16611c695760405162461bcd60e51b81526004016106ff90612662565b816001600160a01b0316635da498266040518163ffffffff1660e01b8152600401600060405180830381600087803b158015611ca457600080fd5b505af1158015611cb8573d6000803e3d6000fd5b505050506108db6001600055565b600080611cd283610b8f565b9050600060405180602001611ce6906123c2565b6020820181038252601f19601f82011660405250805190602001209050611d0e828230612206565b949350505050565b606081831115611d585760405162461bcd60e51b815260206004820152600d60248201526c496e76616c69642072616e676560981b60448201526064016106ff565b6004548210611d9f5760405162461bcd60e51b8152602060048201526013602482015272496e646578206f7574206f6620626f756e647360681b60448201526064016106ff565b6000611dab848461281f565b611db6906001612861565b905060008167ffffffffffffffff811115611dd357611dd36126d4565b604051908082528060200260200182016040528015611dfc578160200160208202803683370190505b50905060005b82811015611e76576004611e168288612861565b81548110611e2657611e266126ea565b9060005260206000200160009054906101000a90046001600160a01b0316828281518110611e5657611e566126ea565b6001600160a01b0390921660209283029190910190910152600101611e02565b50949350505050565b60008281526001602081905260409091200154611e9b81611ea5565b6107758383611f55565b611eaf8133612239565b50565b6000611ebe8383611230565b611f235760008381526001602081815260408084206001600160a01b0387168086529252808420805460ff19169093179092559051339286917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9190a450600161068e565b50600061068e565b600260005403611f4e57604051633ee5aeb560e01b815260040160405180910390fd5b6002600055565b6000611f618383611230565b15611f235760008381526001602090815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a450600161068e565b6040516001600160a01b0383811660248301526044820183905261091291859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050612272565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e90604401602060405180830381865afa158015612071573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061209591906126bb565b905061077584846120a68585612861565b6122e3565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e90604401602060405180830381865afa1580156120fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061211f91906126bb565b90508181101561215b5760405163e570110f60e01b81526001600160a01b038416600482015260248101829052604481018390526064016106ff565b61077584848484036122e3565b6000834710156121945760405163cf47918160e01b8152476004820152602481018590526044016106ff565b81516000036121b657604051631328927760e21b815260040160405180910390fd5b8282516020840186f590503d1519811516156121d8576040513d6000823e3d81fd5b6001600160a01b0381166121ff5760405163b06ebf3d60e01b815260040160405180910390fd5b9392505050565b6000604051836040820152846020820152828152600b8101905060ff8153605590206001600160a01b0316949350505050565b6122438282611230565b6108db5760405163e2517d3f60e01b81526001600160a01b0382166004820152602481018390526044016106ff565b600080602060008451602086016000885af180612295576040513d6000823e3d81fd5b50506000513d915081156122ad5780600114156122ba565b6001600160a01b0384163b155b1561077557604051635274afe760e01b81526001600160a01b03851660048201526024016106ff565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526123348482612373565b610775576040516001600160a01b0384811660248301526000604483015261236991869182169063095ea7b390606401611fef565b6107758482612272565b6000806000806020600086516020880160008a5af192503d915060005190508280156123b8575081156123a957806001146123b8565b6000866001600160a01b03163b115b9695505050505050565b610b678061287583390190565b6000602082840312156123e157600080fd5b81356001600160e01b0319811681146121ff57600080fd5b60006020828403121561240b57600080fd5b5035919050565b6001600160a01b0381168114611eaf57600080fd5b6000806040838503121561243a57600080fd5b82359150602083013561244c81612412565b809150509250929050565b60006020828403121561246957600080fd5b81356121ff81612412565b60008060006060848603121561248957600080fd5b833561249481612412565b925060208401356124a481612412565b929592945050506040919091013590565b600080604083850312156124c857600080fd5b82356124d381612412565b9150602083013561244c81612412565b600080600080608085870312156124f957600080fd5b843561250481612412565b9350602085013561251481612412565b93969395505050506040820135916060013590565b60008060006040848603121561253e57600080fd5b833561254981612412565b9250602084013567ffffffffffffffff81111561256557600080fd5b8401601f8101861361257657600080fd5b803567ffffffffffffffff81111561258d57600080fd5b8660208260051b84010111156125a257600080fd5b939660209190910195509293505050565b6000806000606084860312156125c857600080fd5b83356125d381612412565b95602085013595506040909401359392505050565b600080604083850312156125fb57600080fd5b50508035926020909101359150565b600081518084526020840193506020830160005b828110156126455781516001600160a01b031686526020958601959091019060010161261e565b5093949350505050565b6020815260006121ff602083018461260a565b60208082526010908201526f139bdd0818481cdd588b5dd85b1b195d60821b604082015260600190565b602080825260159082015274496e76616c696420746f6b656e206164647265737360581b604082015260600190565b6000602082840312156126cd57600080fd5b5051919050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b85815284602082015260a06040820152600061271f60a083018661260a565b6001600160a01b0394909416606083015250608001529392505050565b60006020828403121561274e57600080fd5b815167ffffffffffffffff81111561276557600080fd5b8201601f8101841361277657600080fd5b805167ffffffffffffffff811115612790576127906126d4565b8060051b604051601f19603f830116810181811067ffffffffffffffff821117156127bd576127bd6126d4565b6040529182526020818401810192908101878411156127db57600080fd5b6020850194505b838510156127fe578451808252602095860195909350016127e2565b509695505050505050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561068e5761068e612809565b6000825160005b818110156128535760208186018101518583015201612839565b506000920191825250919050565b8082018082111561068e5761068e61280956fe60a060405234801561001057600080fd5b50600160005533608052608051610ad7610090600039600081816101050152818161018b015281816101fb01528181610268015281816102f101528181610441015281816104910152818161050401528181610573015281816105ec01528181610690015281816107d60152818161087301526108ff0152610ad76000f3fe60806040526004361061007f5760003560e01c8063a1db97821161004e578063a1db978214610382578063b9adc770146103a2578063da95ebf7146103bf578063f3f43703146103df57600080fd5b8063230b9da3146102df57806344dd3d0d146103305780635da498261461034d5780637ac924561461036257600080fd5b366102da5761008c61040c565b600061009834476109eb565b905060006100a682476109eb565b90503481146101015760408051348152602081018390527f6a87a79f168cdaeb12ad3b487401fc17648c2046a66c38acfb64dd7564a13073910160405180910390a16040516335fc448960e21b815260040160405180910390fd5b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826108fc90604051600060405180830381858888f193505050503d8060008114610173576040519150601f19603f3d011682016040523d82523d6000602084013e610178565b606091505b50509050806102cb576001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000166000908152600160205260408120546101c5908490610a04565b9050683635c9adc5dea000008111156101f157604051630e6deaf960e41b815260040160405180910390fd5b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001660009081526001602052604090819020829055517ff95b2a3154fc5244abc7fbbacd9b3f2a09a91b79e8e8bf05b8fd5e7819afd5ad9061025e9085815260200190565b60405180910390a17f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03167f3f56495688c20e30376aeab77377f820c8d2d6cf7e83309a8e556611373f2522826040516102c191815260200190565b60405180910390a2505b5050506102d86001600055565b005b600080fd5b3480156102eb57600080fd5b506103137f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561033c57600080fd5b50475b604051908152602001610327565b34801561035957600080fd5b506102d8610436565b34801561036e57600080fd5b506102d861037d366004610a2f565b610685565b34801561038e57600080fd5b506102d861039d366004610a2f565b6107cb565b3480156103ae57600080fd5b5061033f683635c9adc5dea0000081565b3480156103cb57600080fd5b506102d86103da366004610a2f565b6108f4565b3480156103eb57600080fd5b5061033f6103fa366004610a5b565b60016020526000908152604090205481565b60026000540361042f57604051633ee5aeb560e01b815260040160405180910390fd5b6002600055565b336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161461047f57604051631a27eac360e11b815260040160405180910390fd5b61048761040c565b6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016600090815260016020526040812054908190036104e15760405163162908e360e11b815260040160405180910390fd5b8047101561050257604051631e9acf1760e31b815260040160405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166000818152600160209081526040808320839055519182527f3f56495688c20e30376aeab77377f820c8d2d6cf7e83309a8e556611373f2522910160405180910390a260007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168260405160006040518083038185875af1925050503d80600081146105dc576040519150601f19603f3d011682016040523d82523d6000602084013e6105e1565b606091505b5050905080610677577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316600081815260016020908152604091829020479081905591518281529192917f3f56495688c20e30376aeab77377f820c8d2d6cf7e83309a8e556611373f2522910160405180910390a26040516327fcd9d160e01b815260040160405180910390fd5b50506106836001600055565b565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146106ce57604051631a27eac360e11b815260040160405180910390fd5b6106d661040c565b6001600160a01b0382166106fd5760405163e6c4247b60e01b815260040160405180910390fd5b80158061070957504781115b156107275760405163162908e360e11b815260040160405180910390fd5b8047101561074857604051631e9acf1760e31b815260040160405180910390fd5b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114610795576040519150601f19603f3d011682016040523d82523d6000602084013e61079a565b606091505b50509050806107bc576040516327fcd9d160e01b815260040160405180910390fd5b506107c76001600055565b5050565b336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161461081457604051631a27eac360e11b815260040160405180910390fd5b6001600160a01b03821661083b5760405163e6c4247b60e01b815260040160405180910390fd5b8060000361085c5760405163162908e360e11b815260040160405180910390fd5b60405163a9059cbb60e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811660048301526024820183905283169063a9059cbb906044016020604051808303816000875af11580156108cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108ef9190610a7f565b505050565b336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161461093d57604051631a27eac360e11b815260040160405180910390fd5b6001600160a01b0382166109645760405163e6c4247b60e01b815260040160405180910390fd5b80158061097057504781115b1561098e5760405163162908e360e11b815260040160405180910390fd5b816001600160a01b03167fe670e4e82118d22a1f9ee18920455ebc958bae26a90a05d31d3378788b1b0e44826040516109c991815260200190565b60405180910390a25050565b634e487b7160e01b600052601160045260246000fd5b818103818111156109fe576109fe6109d5565b92915050565b808201808211156109fe576109fe6109d5565b6001600160a01b0381168114610a2c57600080fd5b50565b60008060408385031215610a4257600080fd5b8235610a4d81610a17565b946020939093013593505050565b600060208284031215610a6d57600080fd5b8135610a7881610a17565b9392505050565b600060208284031215610a9157600080fd5b81518015158114610a7857600080fdfea26469706673582212203978f934b1547ecfd22cf2a9249671ab1edf9b609de8951856ee8e3e24b4113064736f6c634300081b0033940d6b1946ff1d2b5a9f1909219c3c81a370804b5ba0f91ec0828c99a2e6a68197667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b929a264697066735822122046771ac165172c2cc7efef523d4455beef12e3d51e48ada183c17ded1e87d38964736f6c634300081b0033
Verified Source Code Full Match
Compiler: v0.8.27+commit.40a35a09
EVM: paris
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";
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 199 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
import {Address} from "../../../utils/Address.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);
}
}
Address.sol 150 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @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 Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert Errors.FailedCall();
}
}
/**
* @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
* {Errors.FailedCall} 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 Errors.InsufficientBalance(address(this).balance, value);
}
(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 {Errors.FailedCall}) 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 {Errors.FailedCall} 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 {Errors.FailedCall}.
*/
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
assembly ("memory-safe") {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert Errors.FailedCall();
}
}
}
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;
}
}
Create2.sol 92 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Create2.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Helper to make usage of the `CREATE2` EVM opcode easier and safer.
* `CREATE2` can be used to compute in advance the address where a smart
* contract will be deployed, which allows for interesting new mechanisms known
* as 'counterfactual interactions'.
*
* See the https://eips.ethereum.org/EIPS/eip-1014#motivation[EIP] for more
* information.
*/
library Create2 {
/**
* @dev There's no code to deploy.
*/
error Create2EmptyBytecode();
/**
* @dev Deploys a contract using `CREATE2`. The address where the contract
* will be deployed can be known in advance via {computeAddress}.
*
* The bytecode for a contract can be obtained from Solidity with
* `type(contractName).creationCode`.
*
* Requirements:
*
* - `bytecode` must not be empty.
* - `salt` must have not been used for `bytecode` already.
* - the factory must have a balance of at least `amount`.
* - if `amount` is non-zero, `bytecode` must have a `payable` constructor.
*/
function deploy(uint256 amount, bytes32 salt, bytes memory bytecode) internal returns (address addr) {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
if (bytecode.length == 0) {
revert Create2EmptyBytecode();
}
assembly ("memory-safe") {
addr := create2(amount, add(bytecode, 0x20), mload(bytecode), salt)
// if no address was created, and returndata is not empty, bubble revert
if and(iszero(addr), not(iszero(returndatasize()))) {
let p := mload(0x40)
returndatacopy(p, 0, returndatasize())
revert(p, returndatasize())
}
}
if (addr == address(0)) {
revert Errors.FailedDeployment();
}
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy}. Any change in the
* `bytecodeHash` or `salt` will result in a new destination address.
*/
function computeAddress(bytes32 salt, bytes32 bytecodeHash) internal view returns (address) {
return computeAddress(salt, bytecodeHash, address(this));
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at
* `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}.
*/
function computeAddress(bytes32 salt, bytes32 bytecodeHash, address deployer) internal pure returns (address addr) {
assembly ("memory-safe") {
let ptr := mload(0x40) // Get free memory pointer
// | | ↓ ptr ... ↓ ptr + 0x0B (start) ... ↓ ptr + 0x20 ... ↓ ptr + 0x40 ... |
// |-------------------|---------------------------------------------------------------------------|
// | bytecodeHash | CCCCCCCCCCCCC...CC |
// | salt | BBBBBBBBBBBBB...BB |
// | deployer | 000000...0000AAAAAAAAAAAAAAAAAAA...AA |
// | 0xFF | FF |
// |-------------------|---------------------------------------------------------------------------|
// | memory | 000000...00FFAAAAAAAAAAAAAAAAAAA...AABBBBBBBBBBBBB...BBCCCCCCCCCCCCC...CC |
// | keccak(start, 85) | ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ |
mstore(add(ptr, 0x40), bytecodeHash)
mstore(add(ptr, 0x20), salt)
mstore(ptr, deployer) // Right-aligned with 12 preceding garbage bytes
let start := add(ptr, 0x0b) // The hashed data starts at the final garbage byte which we will set to 0xff
mstore8(start, 0xff)
addr := and(keccak256(start, 85), 0xffffffffffffffffffffffffffffffffffffffff)
}
}
}
Errors.sol 34 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}
ReentrancyGuard.sol 87 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
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);
}
CasineoScalableDepositSystem.sol 478 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/Create2.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
interface IUniswapV2Router02 {
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactTokensForETH(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function WETH() external pure returns (address);
}
contract CasineoScalableDepositSystem is ReentrancyGuard, AccessControl {
using SafeERC20 for IERC20;
// Role definitions
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
bytes32 public constant FINANCE_ROLE = keccak256("FINANCE_ROLE");
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
uint256 public MAX_BATCH_SIZE = 500;
mapping(address => bool) public isSubWallet;
address[] public subWallets;
address public immutable WETH;
IUniswapV2Router02 public immutable dexRouter;
event ERC20WithdrawnToOwner(address indexed token, uint256 amount);
event SubWalletCreated(address indexed subWallet, uint256 index);
event BatchCreationCompleted(uint256 startIndex, uint256 count);
event NativeTokenReceived(address indexed from, uint256 amount);
event ERC20Withdrawn(address indexed token, uint256 amount);
event TokensSwappedToNative(
address indexed fromToken,
uint256 amountIn,
uint256 amountOut
);
event TokensSwapped(
address indexed fromToken,
address indexed toToken,
uint256 amountIn,
uint256 amountOut
);
event MaxBatchSizeUpdated(uint256 oldValue, uint256 newValue);
event MaxTotalWalletsUpdated(uint256 oldValue, uint256 newValue);
error ExcessiveBatchSize();
error MaxWalletsExceeded();
error InvalidCount();
error WalletCreationFailed();
error UnauthorizedRole(bytes32 role);
constructor(address _dexRouter, address _weth) {
require(_dexRouter != address(0), "Invalid DEX router address");
require(_weth != address(0), "Invalid WETH address");
dexRouter = IUniswapV2Router02(_dexRouter);
WETH = _weth;
// Setup initial roles
_setUpInitialRoles();
}
function _setUpInitialRoles() private {
// Grant the contract deployer all roles
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(ADMIN_ROLE, msg.sender);
_grantRole(FINANCE_ROLE, msg.sender);
_grantRole(OPERATOR_ROLE, msg.sender);
// Set role hierarchies
_setRoleAdmin(FINANCE_ROLE, ADMIN_ROLE);
_setRoleAdmin(OPERATOR_ROLE, ADMIN_ROLE);
}
// Get the salt for a specific wallet index - this will be the same across all chains
function getWalletSalt(uint256 index) public pure returns (bytes32) {
return keccak256(abi.encodePacked("SUBWALLET", index));
}
// Get the address a wallet will have before it's created
function getWalletAddress(uint256 index) public view returns (address) {
bytes32 salt = getWalletSalt(index);
bytes32 bytecodeHash = keccak256(type(SubWallet).creationCode);
return Create2.computeAddress(salt, bytecodeHash, address(this));
}
// Get addresses for a range of wallet indices before they're created
function getWalletAddresses(
uint256 startIndex,
uint256 count
) external view returns (address[] memory) {
address[] memory addresses = new address[](count);
for (uint256 i = 0; i < count; i++) {
addresses[i] = getWalletAddress(startIndex + i);
}
return addresses;
}
// Administrative functions
function createSubWallets(uint256 count) external onlyRole(ADMIN_ROLE) {
if (count == 0) revert InvalidCount();
if (count > MAX_BATCH_SIZE) revert ExcessiveBatchSize();
uint256 startIndex = subWallets.length;
for (uint256 i = 0; i < count; i++) {
// Use deterministic salt based on index
bytes32 salt = getWalletSalt(startIndex + i);
// Deploy wallet with CREATE2
address subWallet = Create2.deploy(
0,
salt,
type(SubWallet).creationCode
);
isSubWallet[subWallet] = true;
subWallets.push(subWallet);
emit SubWalletCreated(subWallet, subWallets.length - 1);
}
emit BatchCreationCompleted(startIndex, count);
}
// Financial operations
function withdrawERC20(
address token,
address[] calldata _subWallets
) external onlyRole(FINANCE_ROLE) nonReentrant {
require(token != address(0), "Invalid token address");
IERC20 erc20 = IERC20(token);
uint256 totalAmount = 0;
for (uint256 i = 0; i < _subWallets.length; i++) {
require(isSubWallet[_subWallets[i]], "Not a sub-wallet");
uint256 balance = erc20.balanceOf(_subWallets[i]);
if (balance > 0) {
(bool success, ) = _subWallets[i].call(
abi.encodeWithSignature(
"withdrawERC20(address,uint256)",
token,
balance
)
);
require(success, "ERC20 withdrawal failed");
totalAmount += balance;
}
}
emit ERC20Withdrawn(token, totalAmount);
}
function withdrawERC20ToAddress(
address token,
address recipient
) external onlyRole(FINANCE_ROLE) nonReentrant {
require(token != address(0), "Invalid token address");
require(recipient != address(0), "Invalid recipient");
IERC20 tokenContract = IERC20(token);
uint256 balance = tokenContract.balanceOf(address(this));
tokenContract.safeTransfer(recipient, balance);
emit ERC20WithdrawnToOwner(token, balance);
}
function setMaxBatchSize(uint256 newSize) external onlyRole(ADMIN_ROLE) {
require(newSize > 0, "Invalid batch size");
uint256 oldSize = MAX_BATCH_SIZE;
MAX_BATCH_SIZE = newSize;
emit MaxBatchSizeUpdated(oldSize, newSize);
}
function swapTokensToNative(
address fromToken,
uint256 amountIn,
uint256 amountOutMin
) external onlyRole(FINANCE_ROLE) nonReentrant {
require(fromToken != address(0), "Invalid token address");
require(amountIn > 0, "Amount must be greater than 0");
IERC20 fromTokenContract = IERC20(fromToken);
uint256 balance = fromTokenContract.balanceOf(address(this));
require(balance >= amountIn, "Insufficient balance");
fromTokenContract.safeIncreaseAllowance(address(dexRouter), amountIn);
address[] memory path = fromToken == WETH
? new address[](1)
: new address[](2);
if (fromToken == WETH) {
path[0] = WETH;
} else {
path[0] = fromToken;
path[1] = WETH;
}
uint[] memory amounts = dexRouter.swapExactTokensForETH(
amountIn,
amountOutMin,
path,
address(this),
block.timestamp
);
fromTokenContract.safeDecreaseAllowance(address(dexRouter), amounts[0]);
emit TokensSwappedToNative(
fromToken,
amountIn,
amounts[amounts.length - 1]
);
}
function swapTokens(
address fromToken,
address toToken,
uint256 amountIn,
uint256 amountOutMin
) external onlyRole(FINANCE_ROLE) nonReentrant {
require(
fromToken != address(0) && toToken != address(0),
"Invalid token address"
);
require(fromToken != toToken, "Invalid token pair");
require(amountIn > 0, "Amount must be greater than 0");
IERC20 fromTokenContract = IERC20(fromToken);
uint256 balance = fromTokenContract.balanceOf(address(this));
require(balance >= amountIn, "Insufficient balance");
fromTokenContract.safeIncreaseAllowance(address(dexRouter), amountIn);
address[] memory path;
if (fromToken == WETH || toToken == WETH) {
path = new address[](2);
path[0] = fromToken;
path[1] = toToken;
} else {
path = new address[](3);
path[0] = fromToken;
path[1] = WETH;
path[2] = toToken;
}
uint[] memory amounts = dexRouter.swapExactTokensForTokens(
amountIn,
amountOutMin,
path,
address(this),
block.timestamp
);
fromTokenContract.safeDecreaseAllowance(address(dexRouter), amounts[0]);
emit TokensSwapped(
fromToken,
toToken,
amountIn,
amounts[amounts.length - 1]
);
}
// Operational functions
function withdrawPendingNative(
address subWallet
) external onlyRole(OPERATOR_ROLE) nonReentrant {
require(isSubWallet[subWallet], "Not a sub-wallet");
SubWallet(payable(subWallet)).withdrawPendingNative();
}
function requestWithdrawal(
address subWallet,
address payable recipient,
uint256 amount
) external onlyRole(OPERATOR_ROLE) {
require(isSubWallet[subWallet], "Not a sub-wallet");
require(recipient != address(0), "Invalid recipient address");
SubWallet(payable(subWallet)).requestWithdrawal(recipient, amount);
}
function executeWithdrawal(
address subWallet,
address payable recipient,
uint256 amount
) external onlyRole(OPERATOR_ROLE) nonReentrant {
require(isSubWallet[subWallet], "Not a sub-wallet");
require(recipient != address(0), "Invalid recipient address");
SubWallet(payable(subWallet)).executeWithdrawal(recipient, amount);
}
function withdrawNative(
address payable recipient
) external onlyRole(FINANCE_ROLE) nonReentrant {
require(recipient != address(0), "Invalid recipient");
uint256 balance = address(this).balance;
require(balance > 0, "No balance to withdraw");
(bool success, ) = recipient.call{value: balance}("");
require(success, "Native token transfer failed");
}
// View functions
function getSubWalletCount() external view returns (uint256) {
return subWallets.length;
}
function getSubWalletsInRange(
uint256 startIndex,
uint256 endIndex
) external view returns (address[] memory) {
require(startIndex <= endIndex, "Invalid range");
require(endIndex < subWallets.length, "Index out of bounds");
uint256 size = endIndex - startIndex + 1;
address[] memory wallets = new address[](size);
for (uint256 i = 0; i < size; i++) {
wallets[i] = subWallets[startIndex + i];
}
return wallets;
}
receive() external payable virtual {
emit NativeTokenReceived(msg.sender, msg.value);
}
}
contract SubWallet is ReentrancyGuard {
address public immutable parentContract;
mapping(address => uint256) public pendingWithdrawals;
uint256 public constant MAX_PENDING_WITHDRAWAL = 1000 ether;
event FailedTransfer(uint256 amount);
event WithdrawalRequested(address indexed recipient, uint256 amount);
event PendingWithdrawalUpdated(
address indexed recipient,
uint256 newAmount
);
event BalanceValidationFailed(
uint256 expectedAmount,
uint256 actualBalance
);
error InvalidEtherValue();
error ExcessivePendingWithdrawal();
error UnauthorizedAccess();
error InvalidAmount();
error InvalidAddress();
error WithdrawalFailed();
error InsufficientBalance();
error BalanceValidationError();
constructor() {
parentContract = msg.sender;
}
modifier onlyParent() {
if (msg.sender != parentContract) revert UnauthorizedAccess();
_;
}
function withdrawERC20(address token, uint256 amount) external onlyParent {
if (token == address(0)) revert InvalidAddress();
if (amount == 0) revert InvalidAmount();
IERC20(token).transfer(parentContract, amount);
}
receive() external payable nonReentrant {
// Store initial balance for validation
uint256 initialBalance = address(this).balance - msg.value;
// Verify the actual received amount matches msg.value
uint256 actualReceived = address(this).balance - initialBalance;
if (actualReceived != msg.value) {
emit BalanceValidationFailed(msg.value, actualReceived);
revert BalanceValidationError();
}
// Attempt to forward to parent
(bool success, ) = parentContract.call{
value: actualReceived,
gas: 2300
}("");
if (!success) {
// Calculate new pending amount based on actual balance increase
uint256 newPendingAmount = pendingWithdrawals[parentContract] +
actualReceived;
if (newPendingAmount > MAX_PENDING_WITHDRAWAL)
revert ExcessivePendingWithdrawal();
pendingWithdrawals[parentContract] = newPendingAmount;
emit FailedTransfer(actualReceived);
emit PendingWithdrawalUpdated(parentContract, newPendingAmount);
}
}
function withdrawPendingNative() external onlyParent nonReentrant {
uint256 amount = pendingWithdrawals[parentContract];
if (amount == 0) revert InvalidAmount();
// Verify contract has sufficient balance
if (address(this).balance < amount) revert InsufficientBalance();
// Update storage before transfer
pendingWithdrawals[parentContract] = 0;
emit PendingWithdrawalUpdated(parentContract, 0);
// Attempt transfer
(bool success, ) = parentContract.call{value: amount}("");
if (!success) {
// Only restore the actually available balance if transfer fails
uint256 availableBalance = address(this).balance;
pendingWithdrawals[parentContract] = availableBalance;
emit PendingWithdrawalUpdated(parentContract, availableBalance);
revert WithdrawalFailed();
}
}
function requestWithdrawal(
address payable recipient,
uint256 amount
) external onlyParent {
if (recipient == address(0)) revert InvalidAddress();
if (amount == 0 || amount > address(this).balance)
revert InvalidAmount();
emit WithdrawalRequested(recipient, amount);
}
function executeWithdrawal(
address payable recipient,
uint256 amount
) external onlyParent nonReentrant {
if (recipient == address(0)) revert InvalidAddress();
if (amount == 0 || amount > address(this).balance)
revert InvalidAmount();
// Verify contract has sufficient balance
if (address(this).balance < amount) revert InsufficientBalance();
(bool success, ) = recipient.call{value: amount}("");
if (!success) revert WithdrawalFailed();
}
// View function to get actual contract balance
function getActualBalance() external view returns (uint256) {
return address(this).balance;
}
}
Read Contract
ADMIN_ROLE 0x75b238fc → bytes32
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
FINANCE_ROLE 0x349b5954 → bytes32
MAX_BATCH_SIZE 0xcfdbf254 → uint256
OPERATOR_ROLE 0xf5b541a6 → bytes32
WETH 0xad5c4648 → address
dexRouter 0x0758d924 → address
getRoleAdmin 0x248a9ca3 → bytes32
getSubWalletCount 0xf4915f27 → uint256
getSubWalletsInRange 0xd3792e2a → address[]
getWalletAddress 0xcb804eae → address
getWalletAddresses 0xc4502e42 → address[]
getWalletSalt 0x841e5c56 → bytes32
hasRole 0x91d14854 → bool
isSubWallet 0x7ff502f0 → bool
subWallets 0x9d2e8724 → address
supportsInterface 0x01ffc9a7 → bool
Write Contract 13 functions
These functions modify contract state and require a wallet transaction to execute.
createSubWallets 0xb2c22efd
uint256 count
executeWithdrawal 0x387277f2
address subWallet
address recipient
uint256 amount
grantRole 0x2f2ff15d
bytes32 role
address account
renounceRole 0x36568abe
bytes32 role
address callerConfirmation
requestWithdrawal 0x8985646a
address subWallet
address recipient
uint256 amount
revokeRole 0xd547741f
bytes32 role
address account
setMaxBatchSize 0x2b26a6bf
uint256 newSize
swapTokens 0x8e18cdfc
address fromToken
address toToken
uint256 amountIn
uint256 amountOutMin
swapTokensToNative 0xb4bc25b6
address fromToken
uint256 amountIn
uint256 amountOutMin
withdrawERC20 0x9d2dcde7
address token
address[] _subWallets
withdrawERC20ToAddress 0x4036edc2
address token
address recipient
withdrawNative 0x2f622e6b
address recipient
withdrawPendingNative 0xc8241160
address subWallet
Recent Transactions
No transactions found for this address