Address Contract Verified
Address
0xD0A8C78C0960f65eB5cfe6Fe3CcF9B022a533945
Balance
0 ETH
Nonce
1
Code Size
10985 bytes
Creator
0xCEF158D2...E4e7 at tx 0x8322865b...3f46f5
Indexed Transactions
0
Contract Bytecode
10985 bytes
0x608060405260043610610228575f3560e01c806398e6b46e11610129578063c6c5fbd4116100a8578063e2bbb1581161006d578063e2bbb1581461073d578063ec87621c14610750578063f525cb6814610770578063f851a44014610785578063fdff9b4d146107a9575f80fd5b8063c6c5fbd414610694578063d547741f146106c1578063d86c0444146106e0578063d8b0deb1146106ff578063dfe24ffa1461071e575f80fd5b8063ba3bc96d116100ee578063ba3bc96d146105d7578063bc25973a146105f6578063bd82063814610622578063c346dc1314610656578063c6419cda14610675575f80fd5b806398e6b46e146104a9578063a217fddf146104d5578063ac18de43146104e8578063ac4afa3814610507578063b6b9609d146105b8575f80fd5b806341d9a7b2116101b557806375b238fc1161017a57806375b238fc1461041857806375fb0d78146104385780638456cb591461045757806391d148541461046b578063929456071461048a575f80fd5b806341d9a7b21461036d5780634e0552441461038c5780635c975abb146103ab5780636595f73a146103c257806367ccdf38146103e1575f80fd5b80632e1a7d4d116101fb5780632e1a7d4d146102db5780632f2ff15d146102fc57806336568abe1461031b5780633a1aef061461033a5780633f4ba83a14610359575f80fd5b806301ffc9a71461022c5780630c196a74146102605780632099920e1461028d578063248a9ca3146102ac575b5f80fd5b348015610237575f80fd5b5061024b610246366004612676565b6107f3565b60405190151581526020015b60405180910390f35b34801561026b575f80fd5b5061027f61027a3660046126a4565b610829565b604051908152602001610257565b348015610298575f80fd5b5061027f6102a73660046126d6565b61086f565b3480156102b7575f80fd5b5061027f6102c63660046126a4565b5f908152600160208190526040909120015490565b3480156102e6575f80fd5b506102fa6102f53660046126a4565b61095e565b005b348015610307575f80fd5b506102fa6103163660046126d6565b610c5c565b348015610326575f80fd5b506102fa6103353660046126d6565b610c87565b348015610345575f80fd5b5061027f6103543660046126a4565b610cbf565b348015610364575f80fd5b506102fa610cf8565b348015610378575f80fd5b506102fa610387366004612700565b610d35565b348015610397575f80fd5b5061027f6103a63660046126d6565b611069565b3480156103b6575f80fd5b5060025460ff1661024b565b3480156103cd575f80fd5b5061027f6103dc3660046126a4565b611129565b3480156103ec575f80fd5b506104006103fb3660046126a4565b61115f565b6040516001600160a01b039091168152602001610257565b348015610423575f80fd5b5061027f5f80516020612a9483398151915281565b348015610443575f80fd5b506102fa610452366004612720565b6111a6565b348015610462575f80fd5b506102fa611328565b348015610476575f80fd5b5061024b6104853660046126d6565b611363565b348015610495575f80fd5b506102fa6104a4366004612748565b61138d565b3480156104b4575f80fd5b506104c86104c33660046126a4565b6114df565b6040516102579190612771565b3480156104e0575f80fd5b5061027f5f81565b3480156104f3575f80fd5b506102fa6105023660046127b1565b61156e565b348015610512575f80fd5b506105726105213660046126a4565b600360208190525f918252604090912080546001820154600283015493830154600484015460058501546006909501549395929492939192909160ff82169161010090046001600160a01b03169088565b6040805198895260208901979097529587019490945260608601929092526080850152151560a08401526001600160a01b031660c083015260e082015261010001610257565b3480156105c3575f80fd5b506102fa6105d23660046127ca565b61167b565b3480156105e2575f80fd5b5061024b6105f13660046126a4565b61182c565b348015610601575f80fd5b506106156106103660046126d6565b611868565b6040516102579190612806565b34801561062d575f80fd5b5061064161063c3660046126d6565b611937565b60408051928352602083019190915201610257565b348015610661575f80fd5b5061027f6106703660046126a4565b611a55565b348015610680575f80fd5b5061027f61068f3660046126a4565b611b28565b34801561069f575f80fd5b506106b36106ae3660046126d6565b611bca565b6040516102579291906128a9565b3480156106cc575f80fd5b506102fa6106db3660046126d6565b611da7565b3480156106eb575f80fd5b506102fa6106fa366004612748565b611dcc565b34801561070a575f80fd5b5061027f6107193660046126a4565b611ebc565b348015610729575f80fd5b506102fa610738366004612720565b611ef6565b6102fa61074b366004612700565b61202e565b34801561075b575f80fd5b5061027f5f80516020612a7483398151915281565b34801561077b575f80fd5b5061027f60055481565b348015610790575f80fd5b506002546104009061010090046001600160a01b031681565b3480156107b4575f80fd5b506107de6107c33660046127b1565b60046020525f90815260409020805460019091015460ff1682565b60408051928352901515602083015201610257565b5f6001600160e01b03198216637965db0b60e01b148061082357506301ffc9a760e01b6001600160e01b03198316145b92915050565b5f8160055481106108555760405162461bcd60e51b815260040161084c906128d6565b60405180910390fd5b5f8381526003602052604090206001015491505b50919050565b5f8260055481106108925760405162461bcd60e51b815260040161084c906128d6565b5f8481526003602090815260408083206001600160a01b0387168452600781019092528220909190815b8154811015610952575f8282815481106108d8576108d86128ff565b5f9182526020909120600590910201600281015490915060ff16610949575f8160010154426109079190612927565b90505f64496cebb800828460040154855f0154610924919061293a565b61092e919061293a565b6109389190612951565b90506109448187612970565b955050505b506001016108bc565b50909695505050505050565b6109666122d9565b8060055481106109885760405162461bcd60e51b815260040161084c906128d6565b610990612330565b5f8281526003602090815260408083203384526007810190925282209091908190815b8154811015610a81575f8282815481106109cf576109cf6128ff565b5f9182526020909120600590910201600281015490915060ff16158015610a09575080600301548160010154610a059190612970565b4210155b15610a78575f64496cebb800826001015442610a259190612927565b60048401548454610a36919061293a565b610a40919061293a565b610a4a9190612951565b9050610a568186612970565b8254909550610a659087612970565b60028301805460ff191660011790559550505b506001016109b3565b505f8311610ad15760405162461bcd60e51b815260206004820152601d60248201527f4e6f20756e6c6f636b65642066756e647320746f207769746864726177000000604482015260640161084c565b82846003015f828254610ae49190612927565b909155505f9050610af58385612970565b905080610b0188611a55565b1015610b4f5760405162461bcd60e51b815260206004820152601d60248201527f496e73756666696369656e7420636f6e74726163742062616c616e6365000000604482015260640161084c565b600585015460ff1615610bef576040515f90339083908381818185875af1925050503d805f8114610b9b576040519150601f19603f3d011682016040523d82523d5f602084013e610ba0565b606091505b5050905080610be95760405162461bcd60e51b8152602060048201526015602482015274115512081dda5d1a191c985dd85b0819985a5b1959605a1b604482015260640161084c565b50610c0d565b6005850154610c0d9061010090046001600160a01b03163383612376565b6040805185815260208101859052889133917f02f25270a4d87bea75db541cdfe559334a275b4a233520ed6c0a2429667cca94910160405180910390a3505050505050610c5960015f55565b50565b5f8281526001602081905260409091200154610c77816123d5565b610c8183836123df565b50505050565b6001600160a01b0381163314610cb05760405163334bd91960e11b815260040160405180910390fd5b610cba8282612455565b505050565b5f816005548110610ce25760405162461bcd60e51b815260040161084c906128d6565b50505f9081526003602052604090206002015490565b610d0f5f80516020612a9483398151915233611363565b610d2b5760405162461bcd60e51b815260040161084c90612983565b610d336124c0565b565b610d3d6122d9565b610d545f80516020612a7483398151915233611363565b610d905760405162461bcd60e51b815260206004820152600d60248201526c2737ba10309036b0b730b3b2b960991b604482015260640161084c565b816005548110610db25760405162461bcd60e51b815260040161084c906128d6565b610dba612330565b5f8381526003602090815260408083203384526004909252909120600181015460ff16610e1f5760405162461bcd60e51b81526020600482015260136024820152724d616e6167657220697320696e61637469766560681b604482015260640161084c565b5f8411610e7f5760405162461bcd60e51b815260206004820152602860248201527f5769746864726177616c20616d6f756e74206d75737420626520677265617465604482015267072207468616e20360c41b606482015260840161084c565b8054841115610edb5760405162461bcd60e51b815260206004820152602260248201527f45786365656473206d616e616765722773207769746864726177616c206c696d6044820152611a5d60f21b606482015260840161084c565b83610ee586611a55565b1015610f335760405162461bcd60e51b815260206004820152601960248201527f496e73756666696369656e7420706f6f6c2062616c616e636500000000000000604482015260640161084c565b83815f015f828254610f459190612927565b9250508190555083826006015f828254610f5f9190612970565b9091555050600582015460ff1615611004576040515f90339086908381818185875af1925050503d805f8114610fb0576040519150601f19603f3d011682016040523d82523d5f602084013e610fb5565b606091505b5050905080610ffe5760405162461bcd60e51b8152602060048201526015602482015274115512081dda5d1a191c985dd85b0819985a5b1959605a1b604482015260640161084c565b50611022565b60058201546110229061010090046001600160a01b03163386612376565b604051848152859033907f0ed408dce716323e6d5783c7f8c73db86e30f4b0838eb61d3c65086c49111c769060200160405180910390a350505061106560015f55565b5050565b5f82600554811061108c5760405162461bcd60e51b815260040161084c906128d6565b5f8481526003602090815260408083206001600160a01b03871684526007019091528120815b815481101561111e578181815481106110cd576110cd6128ff565b5f91825260209091206002600590920201015460ff16611116578181815481106110f9576110f96128ff565b905f5260205f2090600502015f0154836111139190612970565b92505b6001016110b2565b509095945050505050565b5f81600554811061114c5760405162461bcd60e51b815260040161084c906128d6565b50505f9081526003602052604090205490565b5f8160055481106111825760405162461bcd60e51b815260040161084c906128d6565b50505f9081526003602052604090206005015461010090046001600160a01b031690565b6111bd5f80516020612a9483398151915233611363565b6111d95760405162461bcd60e51b815260040161084c90612983565b6111e1612330565b6001600160a01b0382166112375760405162461bcd60e51b815260206004820152601760248201527f496e76616c6964206d616e616765722061646472657373000000000000000000604482015260640161084c565b5f81116112865760405162461bcd60e51b815260206004820152601c60248201527f4c696d6974206d7573742062652067726561746572207468616e203000000000604482015260640161084c565b604080518082018252828152600160208083018281526001600160a01b0387165f90815260049092529390209151825591519101805460ff19169115159190911790556112e05f80516020612a74833981519152836123df565b50816001600160a01b03167ffae05d1286e3d4cd0db21fce06a66beb75ec586eb923fc0fcc332e69d7ad2e2f8260405161131c91815260200190565b60405180910390a25050565b61133f5f80516020612a9483398151915233611363565b61135b5760405162461bcd60e51b815260040161084c90612983565b610d33612512565b5f9182526001602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6113a45f80516020612a9483398151915233611363565b6113c05760405162461bcd60e51b815260040161084c90612983565b6113c8612330565b5f831161140b5760405162461bcd60e51b8152602060048201526011602482015270496e76616c696420706f6f6c2073697a6560781b604482015260640161084c565b5f821161142a5760405162461bcd60e51b815260040161084c906129a9565b5f81116114495760405162461bcd60e51b815260040161084c906129ed565b600580545f918261145983612a30565b909155505f8181526003602090815260408083208881556001808201899055600282018890556005820180546001600160a81b03191682179055426004830155825190815292830193909352929350909183917f6329fdef76690453095fc310ee858cc7b9d8192236bcb125a67ce9fdb211823391015b60405180910390a25050505050565b60608160055481106115035760405162461bcd60e51b815260040161084c906128d6565b5f838152600360209081526040918290206008018054835181840281018401909452808452909183018282801561156157602002820191905f5260205f20905b81546001600160a01b03168152600190910190602001808311611543575b5050505050915050919050565b6115855f80516020612a9483398151915233611363565b6115a15760405162461bcd60e51b815260040161084c90612983565b6115a9612330565b6001600160a01b0381165f9081526004602052604090206001015460ff1661160b5760405162461bcd60e51b81526020600482015260156024820152744d616e61676572206973206e6f742061637469766560581b604482015260640161084c565b6001600160a01b0381165f908152600460205260409020600101805460ff191690556116445f80516020612a7483398151915282612455565b506040516001600160a01b038216907fef69f7d97228658c92417be1b16b19058315de71fecb435d07b7d23728b6bd31905f90a250565b6116925f80516020612a9483398151915233611363565b6116ae5760405162461bcd60e51b815260040161084c90612983565b6116b6612330565b5f84116116f95760405162461bcd60e51b8152602060048201526011602482015270496e76616c696420706f6f6c2073697a6560781b604482015260640161084c565b5f83116117185760405162461bcd60e51b815260040161084c906129a9565b5f82116117375760405162461bcd60e51b815260040161084c906129ed565b6001600160a01b0381166117855760405162461bcd60e51b8152602060048201526015602482015274496e76616c696420746f6b656e206164647265737360581b604482015260640161084c565b600580545f918261179583612a30565b909155505f81815260036020908152604080832089815560018101899055600281018890556005810180546001600160a81b0319166101006001600160a01b038a16908102919091179091554260048301558251948552928401929092529293509183917f6329fdef76690453095fc310ee858cc7b9d8192236bcb125a67ce9fdb2118233910160405180910390a2505050505050565b5f81600554811061184f5760405162461bcd60e51b815260040161084c906128d6565b50505f9081526003602052604090206005015460ff1690565b606082600554811061188c5760405162461bcd60e51b815260040161084c906128d6565b5f8481526003602090815260408083206001600160a01b0387168452600701825280832080548251818502810185019093528083529193909284015b8282101561192a575f8481526020908190206040805160a081018252600586029092018054835260018082015484860152600282015460ff161515928401929092526003810154606084015260040154608083015290835290920191016118c8565b5050505091505092915050565b5f8083600554811061195b5760405162461bcd60e51b815260040161084c906128d6565b5f8581526003602090815260408083206001600160a01b03881684526007810190925282209091908190815b8154811015611a46575f8282815481106119a3576119a36128ff565b5f9182526020909120600590910201600281015490915060ff161580156119dd5750806003015481600101546119d99190612970565b4210155b15611a3d575f64496cebb8008260010154426119f99190612927565b60048401548454611a0a919061293a565b611a14919061293a565b611a1e9190612951565b9050611a2a8186612970565b8254909550611a399087612970565b9550505b50600101611987565b50919890975095505050505050565b5f816005548110611a785760405162461bcd60e51b815260040161084c906128d6565b5f838152600360205260409020600581015460ff1615611aa9576006810154611aa19047612927565b925050610869565b600681015460058201546040516370a0823160e01b81523060048201526101009091046001600160a01b0316906370a0823190602401602060405180830381865afa158015611afa573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b1e9190612a48565b611aa19190612927565b5f816005548110611b4b5760405162461bcd60e51b815260040161084c906128d6565b5f8381526003602052604090208054611ba65760405162461bcd60e51b815260206004820181905260248201527f506f6f6c2073697a65206d7573742062652067726561746572207468616e2030604482015260640161084c565b80546003820154611bb890606461293a565b611bc29190612951565b949350505050565b606080836005548110611bef5760405162461bcd60e51b815260040161084c906128d6565b5f8581526003602090815260408083206001600160a01b03881684526007810190925282209091805b8254811015611c6357828181548110611c3357611c336128ff565b5f91825260209091206002600590920201015460ff16611c5b5781611c5781612a30565b9250505b600101611c18565b508067ffffffffffffffff811115611c7d57611c7d612a5f565b604051908082528060200260200182016040528015611ca6578160200160208202803683370190505b5095508067ffffffffffffffff811115611cc257611cc2612a5f565b604051908082528060200260200182016040528015611ceb578160200160208202803683370190505b5094505f805b8354811015611d9a575f848281548110611d0d57611d0d6128ff565b5f9182526020909120600590910201600281015490915060ff16611d91575f81600301548260010154611d409190612970565b9050808a8581518110611d5557611d556128ff565b602002602001018181525050815f0154898581518110611d7757611d776128ff565b602090810291909101015283611d8c81612a30565b945050505b50600101611cf1565b5050505050509250929050565b5f8281526001602081905260409091200154611dc2816123d5565b610c818383612455565b611de35f80516020612a9483398151915233611363565b611dff5760405162461bcd60e51b815260040161084c90612983565b826005548110611e215760405162461bcd60e51b815260040161084c906128d6565b611e29612330565b5f8311611e485760405162461bcd60e51b815260040161084c906129a9565b5f8211611e675760405162461bcd60e51b815260040161084c906129ed565b5f84815260036020908152604091829020600181018690556002810185905582518681529182018590529186917f17b8644f386d1c7c7138ef98b3c8035622bbe94d7be9b26f71d2654a547c294391016114d0565b5f816005548110611edf5760405162461bcd60e51b815260040161084c906128d6565b50505f908152600360208190526040909120015490565b611f0d5f80516020612a9483398151915233611363565b611f295760405162461bcd60e51b815260040161084c90612983565b611f31612330565b5f8111611f805760405162461bcd60e51b815260206004820181905260248201527f4e6577206c696d6974206d7573742062652067726561746572207468616e2030604482015260640161084c565b6001600160a01b0382165f9081526004602052604090206001015460ff16611fe25760405162461bcd60e51b81526020600482015260156024820152744d616e61676572206973206e6f742061637469766560581b604482015260640161084c565b6001600160a01b0382165f8181526004602052604090819020839055517f17b1c1c46320523bb4f6d4fad03805446c98a6f17fefdc8ccbfb809c10e303069061131c9084815260200190565b6120366122d9565b8160055481106120585760405162461bcd60e51b815260040161084c906128d6565b612060612330565b5f82116120bd5760405162461bcd60e51b815260206004820152602560248201527f4465706f73697420616d6f756e74206d75737420626520677265617465722074604482015264068616e20360dc1b606482015260840161084c565b5f8381526003602081905260409091208054918101549091906120e1908590612970565b11156121235760405162461bcd60e51b81526020600482015260116024820152704578636565647320706f6f6c2073697a6560781b604482015260640161084c565b600581015460ff1615612193578234146121755760405162461bcd60e51b815260206004820152601360248201527208aa89040c2dadeeadce840dad2e6dac2e8c6d606b1b604482015260640161084c565b34816003015f8282546121889190612970565b909155506121cb9050565b60058101546121b29061010090046001600160a01b031633308661254f565b82816003015f8282546121c59190612970565b90915550505b335f9081526007820160205260408120549003612209576008810180546001810182555f91825260209091200180546001600160a01b031916331790555b335f8181526007830160209081526040808320815160a081018352888152428185018181528285018781526002808b0154606086019081526001808d01546080880190815288548083018a55988c529a8a90209651600590980290960196875592519486019490945551928401805460ff19169315159390931790925590516003830155935160049182015585019290925590518581528692917f90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a15910160405180910390a3505061106560015f55565b60025f540361232a5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161084c565b60025f55565b60025460ff1615610d335760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015260640161084c565b6040516001600160a01b03838116602483015260448201839052610cba91859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050612588565b610c5981336125f4565b5f6123ea8383611363565b61244e575f8381526001602081815260408084206001600160a01b0387168086529252808420805460ff19169093179092559051339286917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9190a4506001610823565b505f610823565b5f6124608383611363565b1561244e575f8381526001602090815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a4506001610823565b6124c861262d565b6002805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b61251a612330565b6002805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586124f53390565b6040516001600160a01b038481166024830152838116604483015260648201839052610c819186918216906323b872dd906084016123a3565b5f8060205f8451602086015f885af1806125a7576040513d5f823e3d81fd5b50505f513d915081156125be5780600114156125cb565b6001600160a01b0384163b155b15610c8157604051635274afe760e01b81526001600160a01b038516600482015260240161084c565b6125fe8282611363565b6110655760405163e2517d3f60e01b81526001600160a01b03821660048201526024810183905260440161084c565b60025460ff16610d335760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015260640161084c565b5f60208284031215612686575f80fd5b81356001600160e01b03198116811461269d575f80fd5b9392505050565b5f602082840312156126b4575f80fd5b5035919050565b80356001600160a01b03811681146126d1575f80fd5b919050565b5f80604083850312156126e7575f80fd5b823591506126f7602084016126bb565b90509250929050565b5f8060408385031215612711575f80fd5b50508035926020909101359150565b5f8060408385031215612731575f80fd5b61273a836126bb565b946020939093013593505050565b5f805f6060848603121561275a575f80fd5b505081359360208301359350604090920135919050565b602080825282518282018190525f918401906040840190835b8181101561111e5783516001600160a01b031683526020938401939092019160010161278a565b5f602082840312156127c1575f80fd5b61269d826126bb565b5f805f80608085870312156127dd575f80fd5b8435935060208501359250604085013591506127fb606086016126bb565b905092959194509250565b602080825282518282018190525f918401906040840190835b8181101561111e578351805184526020810151602085015260408101511515604085015260608101516060850152608081015160808501525060a08301925060208401935060018101905061281f565b5f8151808452602084019350602083015f5b8281101561289f578151865260209586019590910190600101612881565b5093949350505050565b604081525f6128bb604083018561286f565b82810360208401526128cd818561286f565b95945050505050565b6020808252600f908201526e125b9d985b1a59081c1bdbdb081251608a1b604082015260600190565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b8181038181111561082357610823612913565b808202811582820484141761082357610823612913565b5f8261296b57634e487b7160e01b5f52601260045260245ffd5b500490565b8082018082111561082357610823612913565b6020808252600c908201526b2737ba1030b71030b236b4b760a11b604082015260600190565b60208082526024908201527f496e7465726573742072617465206d75737420626520677265617465722074686040820152630616e20360e41b606082015260800190565b60208082526023908201527f4c6f636b2d696e2074696d65206d75737420626520677265617465722074686160408201526206e20360ec1b606082015260800190565b5f60018201612a4157612a41612913565b5060010190565b5f60208284031215612a58575f80fd5b5051919050565b634e487b7160e01b5f52604160045260245ffdfe241ecf16d79d0f8dbfb92cbc07fe17840425976cf0667f022fe9877caa831b08a49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775a2646970667358221220ccb472400894dec5ed5acc00f3fd47dd89755bdf04a472a56e8d34c8d8dcaed064736f6c634300081a0033
Verified Source Code Full Match
Compiler: v0.8.26+commit.8a97fa7a
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.0;
/**
* @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);
}
staking.sol 592 lines
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // +========================================================+ // | ██╗ ██████╗███████╗ ███████╗██╗ ██╗ | // |██╔╝ ██╔════╝██╔════╝ ██╔════╝██║ ╚██╗| // |██║█████╗ ██║ █████╗ █████╗ ██║ █████╗██║| // |██║╚════╝ ██║ ██╔══╝ ██╔══╝ ██║ ╚════╝██║| // |╚██╗ ╚██████╗███████╗██╗██║ ██║ ██╔╝| // | ╚═╝ ╚═════╝╚══════╝╚═╝╚═╝ ╚═╝ ╚═╝ | // +========================================================+ //Visit https://CE.FI //CE.FI: Decentralized AI-Driven Finance for Real-World Assets //Stake with Confidence for Optimal APR Powered by DeFi, AI, and RWA! //⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡ //───────────────────────────────────────────────────────────────────────────────────────────────────── //─██████─██████─██████─██████████████─██████─────────██████████████─████████████████───██████████████─ //─██░░██─██░░██─██░░██─██░░░░░░░░░░██─██░░██─────────██░░░░░░░░░░██─██░░░░░░░░░░░░██───██░░░░░░░░░░██─ //─██░░██─██░░██─██░░██─██░░██████░░██─██░░██─────────██░░██████████─██░░████████░░██───██████░░██████─ //─██░░██─██░░██─██░░██─██░░██──██░░██─██░░██─────────██░░██─────────██░░██────██░░██───────██░░██───── //─██░░██─██░░██─██░░██─██░░██████░░██─██░░██─────────██░░██████████─██░░████████░░██───────██░░██───── //─██░░██─██░░██─██░░██─██░░░░░░░░░░██─██░░██─────────██░░░░░░░░░░██─██░░░░░░░░░░░░██───────██░░██───── //─██████─██████─██████─██░░██████░░██─██░░██─────────██░░██████████─██░░██████░░████───────██░░██───── //──────────────────────██░░██──██░░██─██░░██─────────██░░██─────────██░░██──██░░██─────────██░░██───── //─██████─██████─██████─██░░██──██░░██─██░░██████████─██░░██████████─██░░██──██░░██████─────██░░██───── //─██░░██─██░░██─██░░██─██░░██──██░░██─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░██──██░░░░░░██─────██░░██───── //─██████─██████─██████─██████──██████─██████████████─██████████████─██████──██████████─────██████───── //───────────────────────────────────────────────────────────────────────────────────────────────────── //⚠️ Encounter a bug or issue? Email [email protected] to report and earn a bounty reward! 🚀 //💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡 import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/security/Pausable.sol"; contract CeFidApp is ReentrancyGuard, AccessControl, Pausable { using SafeERC20 for IERC20; bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE"); bytes32 public constant MANAGER_ROLE = keccak256("MANAGER_ROLE"); address public admin; struct DepositRecord { uint256 amount; uint256 depositTime; bool withdrawn; uint256 lockInTime; // Added: Store lock-in time at deposit uint256 interestRate; // Added: Store interest rate at deposit } struct Pool { uint256 poolSize; uint256 interestRate; uint256 lockInTime; uint256 totalDeposits; uint256 lastUpdated; bool isETHPool; address tokenAddress; uint256 managerWithdrawals; // Added: Track manager withdrawals mapping(address => DepositRecord[]) deposits; address[] depositors; } struct Manager { uint256 limit; bool isActive; } mapping(uint256 => Pool) public pools; mapping(address => Manager) public managers; uint256 public poolCount; event Deposit(address indexed user, uint256 indexed poolId, uint256 amount); event Withdraw( address indexed user, uint256 indexed poolId, uint256 amount, uint256 reward ); event ManagerWithdraw( address indexed manager, uint256 indexed poolId, uint256 amount ); event PoolCreated( uint256 indexed poolId, bool isETHPool, address tokenAddress ); event PoolUpdated( uint256 indexed poolId, uint256 interestRate, uint256 lockInTime ); event ManagerAdded(address indexed manager, uint256 limit); event ManagerLimitUpdated(address indexed manager, uint256 newLimit); event ManagerRemoved(address indexed manager); modifier onlyAdmin() { require(hasRole(ADMIN_ROLE, msg.sender), "Not an admin"); _; } modifier onlyManager() { require(hasRole(MANAGER_ROLE, msg.sender), "Not a manager"); _; } modifier validPool(uint256 poolId) { require(poolId < poolCount, "Invalid pool ID"); _; } constructor() { admin = msg.sender; _grantRole(ADMIN_ROLE, admin); } // 🔹 ADMIN FUNCTIONS function addETHPool( uint256 poolSize, uint256 interestRate, uint256 lockInTime ) public onlyAdmin whenNotPaused { require(poolSize > 0, "Invalid pool size"); require(interestRate > 0, "Interest rate must be greater than 0"); require(lockInTime > 0, "Lock-in time must be greater than 0"); uint256 poolId = poolCount++; Pool storage pool = pools[poolId]; pool.poolSize = poolSize; pool.interestRate = interestRate; pool.lockInTime = lockInTime; pool.isETHPool = true; pool.tokenAddress = address(0); pool.lastUpdated = block.timestamp; emit PoolCreated(poolId, true, address(0)); } function addERC20Pool( uint256 poolSize, uint256 interestRate, uint256 lockInTime, address tokenAddress ) public onlyAdmin whenNotPaused { require(poolSize > 0, "Invalid pool size"); require(interestRate > 0, "Interest rate must be greater than 0"); require(lockInTime > 0, "Lock-in time must be greater than 0"); require(tokenAddress != address(0), "Invalid token address"); uint256 poolId = poolCount++; Pool storage pool = pools[poolId]; pool.poolSize = poolSize; pool.interestRate = interestRate; pool.lockInTime = lockInTime; pool.isETHPool = false; pool.tokenAddress = tokenAddress; pool.lastUpdated = block.timestamp; emit PoolCreated(poolId, false, tokenAddress); } function updatePool( uint256 poolId, uint256 interestRate, uint256 lockInTime ) public onlyAdmin validPool(poolId) whenNotPaused { require(interestRate > 0, "Interest rate must be greater than 0"); require(lockInTime > 0, "Lock-in time must be greater than 0"); Pool storage pool = pools[poolId]; pool.interestRate = interestRate; pool.lockInTime = lockInTime; emit PoolUpdated(poolId, interestRate, lockInTime); } function addManager(address manager, uint256 limit) public onlyAdmin whenNotPaused { require(manager != address(0), "Invalid manager address"); require(limit > 0, "Limit must be greater than 0"); managers[manager] = Manager({limit: limit, isActive: true}); _grantRole(MANAGER_ROLE, manager); emit ManagerAdded(manager, limit); } function updateManagerLimit(address manager, uint256 newLimit) public onlyAdmin whenNotPaused { require(newLimit > 0, "New limit must be greater than 0"); require(managers[manager].isActive, "Manager is not active"); managers[manager].limit = newLimit; emit ManagerLimitUpdated(manager, newLimit); } function removeManager(address manager) public onlyAdmin whenNotPaused { require(managers[manager].isActive, "Manager is not active"); managers[manager].isActive = false; _revokeRole(MANAGER_ROLE, manager); emit ManagerRemoved(manager); } function pause() public onlyAdmin { _pause(); } function unpause() public onlyAdmin { _unpause(); } // 🔹 USER FUNCTIONS function deposit(uint256 poolId, uint256 amount) public payable nonReentrant validPool(poolId) whenNotPaused { require(amount > 0, "Deposit amount must be greater than 0"); Pool storage pool = pools[poolId]; require( pool.totalDeposits + amount <= pool.poolSize, "Exceeds pool size" ); if (pool.isETHPool) { require(msg.value == amount, "ETH amount mismatch"); pool.totalDeposits += msg.value; } else { IERC20(pool.tokenAddress).safeTransferFrom( msg.sender, address(this), amount ); pool.totalDeposits += amount; } if (pool.deposits[msg.sender].length == 0) { pool.depositors.push(msg.sender); } pool.deposits[msg.sender].push( DepositRecord({ amount: amount, depositTime: block.timestamp, withdrawn: false, lockInTime: pool.lockInTime, // Store lock-in time interestRate: pool.interestRate // Store interest rate }) ); pool.lastUpdated = block.timestamp; emit Deposit(msg.sender, poolId, amount); } function withdraw(uint256 poolId) public nonReentrant validPool(poolId) whenNotPaused { Pool storage pool = pools[poolId]; uint256 totalWithdrawable = 0; uint256 totalReward = 0; DepositRecord[] storage userDeposits = pool.deposits[msg.sender]; for (uint256 i = 0; i < userDeposits.length; ) { DepositRecord storage depositRecord = userDeposits[i]; if ( !depositRecord.withdrawn && block.timestamp >= depositRecord.depositTime + depositRecord.lockInTime // Use stored lock-in time ) { uint256 reward = (depositRecord.amount * depositRecord.interestRate * // Use stored interest rate (block.timestamp - depositRecord.depositTime)) / (365 days * 10000); totalReward += reward; totalWithdrawable += depositRecord.amount; depositRecord.withdrawn = true; } unchecked { i++; } } require(totalWithdrawable > 0, "No unlocked funds to withdraw"); pool.totalDeposits -= totalWithdrawable; uint256 totalPayout = totalWithdrawable + totalReward; require( getAvailablePoolBalance(poolId) >= totalPayout, "Insufficient contract balance" ); if (pool.isETHPool) { (bool success, ) = msg.sender.call{value: totalPayout}(""); require(success, "ETH withdrawal failed"); } else { IERC20(pool.tokenAddress).safeTransfer(msg.sender, totalPayout); } emit Withdraw(msg.sender, poolId, totalWithdrawable, totalReward); } // 🔹 MANAGER FUNCTIONS function withdrawByManager(uint256 poolId, uint256 amount) public nonReentrant onlyManager validPool(poolId) whenNotPaused { Pool storage pool = pools[poolId]; Manager storage manager = managers[msg.sender]; require(manager.isActive, "Manager is inactive"); require(amount > 0, "Withdrawal amount must be greater than 0"); require(amount <= manager.limit, "Exceeds manager's withdrawal limit"); require( getAvailablePoolBalance(poolId) >= amount, "Insufficient pool balance" ); // Update manager's limit and pool state manager.limit -= amount; pool.managerWithdrawals += amount; // Track manager withdrawals // Transfer funds if (pool.isETHPool) { (bool success, ) = msg.sender.call{value: amount}(""); require(success, "ETH withdrawal failed"); } else { IERC20(pool.tokenAddress).safeTransfer(msg.sender, amount); } emit ManagerWithdraw(msg.sender, poolId, amount); } // 🔹 PUBLIC READ FUNCTIONS function getDepositors(uint256 poolId) public view validPool(poolId) returns (address[] memory) { return pools[poolId].depositors; } function getUserDeposits(uint256 poolId, address user) public view validPool(poolId) returns (DepositRecord[] memory) { return pools[poolId].deposits[user]; } function getTotalDeposits(uint256 poolId) public view validPool(poolId) returns (uint256) { return pools[poolId].totalDeposits; } function getPoolSize(uint256 poolId) public view validPool(poolId) returns (uint256) { return pools[poolId].poolSize; } function getPoolPercentageFull(uint256 poolId) public view validPool(poolId) returns (uint256) { Pool storage pool = pools[poolId]; require(pool.poolSize > 0, "Pool size must be greater than 0"); return (pool.totalDeposits * 100) / pool.poolSize; } function getUserDeposit(uint256 poolId, address user) public view validPool(poolId) returns (uint256) { uint256 totalDeposit = 0; DepositRecord[] storage userDeposits = pools[poolId].deposits[user]; for (uint256 i = 0; i < userDeposits.length; ) { if (!userDeposits[i].withdrawn) { totalDeposit += userDeposits[i].amount; } unchecked { i++; } } return totalDeposit; } function getUserReward(uint256 poolId, address user) public view validPool(poolId) returns (uint256) { Pool storage pool = pools[poolId]; uint256 totalReward = 0; DepositRecord[] storage userDeposits = pool.deposits[user]; for (uint256 i = 0; i < userDeposits.length; ) { DepositRecord storage depositRecord = userDeposits[i]; // Only calculate reward for non-withdrawn deposits if (!depositRecord.withdrawn) { uint256 timeElapsed = block.timestamp - depositRecord.depositTime; uint256 reward = (depositRecord.amount * depositRecord.interestRate * timeElapsed) / (365 days * 10000); totalReward += reward; } unchecked { i++; } } return totalReward; } function getMaxWithdrawableAmount(uint256 poolId, address user) public view validPool(poolId) returns (uint256, uint256) { Pool storage pool = pools[poolId]; uint256 totalWithdrawable = 0; uint256 totalReward = 0; DepositRecord[] storage userDeposits = pool.deposits[user]; for (uint256 i = 0; i < userDeposits.length; ) { DepositRecord storage depositRecord = userDeposits[i]; if ( !depositRecord.withdrawn && block.timestamp >= depositRecord.depositTime + depositRecord.lockInTime ) { uint256 reward = (depositRecord.amount * depositRecord.interestRate * (block.timestamp - depositRecord.depositTime)) / (365 days * 10000); totalReward += reward; totalWithdrawable += depositRecord.amount; } unchecked { i++; } } return (totalWithdrawable, totalReward); } function getAvailablePoolBalance(uint256 poolId) public view validPool(poolId) returns (uint256) { Pool storage pool = pools[poolId]; if (pool.isETHPool) { return address(this).balance - pool.managerWithdrawals; } else { return IERC20(pool.tokenAddress).balanceOf(address(this)) - pool.managerWithdrawals; } } function getInterestRate(uint256 poolId) public view validPool(poolId) returns (uint256) { return pools[poolId].interestRate; } function getLockInTime(uint256 poolId) public view validPool(poolId) returns (uint256) { return pools[poolId].lockInTime; } function getIsETHPool(uint256 poolId) public view validPool(poolId) returns (bool) { return pools[poolId].isETHPool; } function getTokenAddress(uint256 poolId) public view validPool(poolId) returns (address) { return pools[poolId].tokenAddress; } function getUnlockTimeAndAmountsForActiveDeposits( uint256 poolId, address user ) public view validPool(poolId) returns (uint256[] memory unlockTimestamps, uint256[] memory amounts) { Pool storage pool = pools[poolId]; DepositRecord[] storage userDeposits = pool.deposits[user]; // Count the number of active deposits (not withdrawn) uint256 activeCount = 0; for (uint256 i = 0; i < userDeposits.length; i++) { if (!userDeposits[i].withdrawn) { activeCount++; } } // Initialize arrays to store the unlock timestamps and amounts unlockTimestamps = new uint256[](activeCount); amounts = new uint256[](activeCount); uint256 index = 0; // Iterate through deposits and collect unlock timestamps and amounts for active deposits for (uint256 i = 0; i < userDeposits.length; i++) { DepositRecord storage depositRecord = userDeposits[i]; if (!depositRecord.withdrawn) { uint256 unlockTimestamp = depositRecord.depositTime + depositRecord.lockInTime; unlockTimestamps[index] = unlockTimestamp; amounts[index] = depositRecord.amount; index++; } } return (unlockTimestamps, amounts); } }
Read Contract
ADMIN_ROLE 0x75b238fc → bytes32
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
MANAGER_ROLE 0xec87621c → bytes32
admin 0xf851a440 → address
getAvailablePoolBalance 0xc346dc13 → uint256
getDepositors 0x98e6b46e → address[]
getInterestRate 0x0c196a74 → uint256
getIsETHPool 0xba3bc96d → bool
getLockInTime 0x3a1aef06 → uint256
getMaxWithdrawableAmount 0xbd820638 → uint256, uint256
getPoolPercentageFull 0xc6419cda → uint256
getPoolSize 0x6595f73a → uint256
getRoleAdmin 0x248a9ca3 → bytes32
getTokenAddress 0x67ccdf38 → address
getTotalDeposits 0xd8b0deb1 → uint256
getUnlockTimeAndAmountsForActiveDeposits 0xc6c5fbd4 → uint256[], uint256[]
getUserDeposit 0x4e055244 → uint256
getUserDeposits 0xbc25973a → tuple[]
getUserReward 0x2099920e → uint256
hasRole 0x91d14854 → bool
managers 0xfdff9b4d → uint256, bool
paused 0x5c975abb → bool
poolCount 0xf525cb68 → uint256
pools 0xac4afa38 → uint256, uint256, uint256, uint256, uint256, bool, address, uint256
supportsInterface 0x01ffc9a7 → bool
Write Contract 14 functions
These functions modify contract state and require a wallet transaction to execute.
addERC20Pool 0xb6b9609d
uint256 poolSize
uint256 interestRate
uint256 lockInTime
address tokenAddress
addETHPool 0x92945607
uint256 poolSize
uint256 interestRate
uint256 lockInTime
addManager 0x75fb0d78
address manager
uint256 limit
deposit 0xe2bbb158
uint256 poolId
uint256 amount
grantRole 0x2f2ff15d
bytes32 role
address account
pause 0x8456cb59
No parameters
removeManager 0xac18de43
address manager
renounceRole 0x36568abe
bytes32 role
address callerConfirmation
revokeRole 0xd547741f
bytes32 role
address account
unpause 0x3f4ba83a
No parameters
updateManagerLimit 0xdfe24ffa
address manager
uint256 newLimit
updatePool 0xd86c0444
uint256 poolId
uint256 interestRate
uint256 lockInTime
withdraw 0x2e1a7d4d
uint256 poolId
withdrawByManager 0x41d9a7b2
uint256 poolId
uint256 amount
Recent Transactions
No transactions found for this address