Address Contract Verified
Address
0xA10fAde7038aB58a3EfaDd47B98224B4a5174F6d
Balance
0 ETH
Nonce
1
Code Size
19242 bytes
Creator
0x77A6Be2D...3212 at tx 0x257150dc...6c8346
Indexed Transactions
0
Contract Bytecode
19242 bytes
0x608060405234801561001057600080fd5b50600436106102695760003560e01c806381014fe411610151578063abe50f19116100c3578063cdf24c2f11610087578063cdf24c2f146106a7578063d37e51da146106c5578063d547741f146106e3578063f7c618c1146106ff578063f854a27f1461071d578063fb9604ce1461074e57610269565b8063abe50f1914610629578063b12ed45e14610645578063bd5c566414610663578063c4b8d27d14610681578063c9e721aa1461069d57610269565b8063a217fddf11610115578063a217fddf14610568578063a728517614610586578063a7c8a9e6146105a2578063a87430ba146105be578063a9170d81146105ef578063aa8172301461060d57610269565b806381014fe4146104d85780638456cb59146104f65780638980f11f1461050057806391d148541461051c57806392930b451461054c57610269565b806336568abe116101ea5780635c975abb116101ae5780635c975abb14610424578063643059161461044257806372f702f3146104605780637718d1e21461047e5780637f91d2351461049c5780638021e4a2146104ba57610269565b806336568abe146103ba578063372500ab146103d65780633f4ba83a146103e057806348928d57146103ea5780635992c85c1461040857610269565b8063230f289711610231578063230f289714610314578063248a9ca31461033257806325c065b1146103625780632876d7e4146103805780632f2ff15d1461039e57610269565b806301ffc9a71461026e57806306e0cf651461029e5780630f8cc3fd146102bc57806312d3b8c9146102da57806316992873146102f8575b600080fd5b61028860048036038101906102839190613199565b61076a565b60405161029591906131e1565b60405180910390f35b6102a66107e4565b6040516102b39190613215565b60405180910390f35b6102c46107ea565b6040516102d19190613215565b60405180910390f35b6102e26107f0565b6040516102ef9190613215565b60405180910390f35b610312600480360381019061030d919061325c565b6107f6565b005b61031c61094d565b6040516103299190613215565b60405180910390f35b61034c600480360381019061034791906132bf565b610953565b60405161035991906132fb565b60405180910390f35b61036a610973565b6040516103779190613215565b60405180910390f35b610388610979565b6040516103959190613215565b60405180910390f35b6103b860048036038101906103b39190613374565b61097f565b005b6103d460048036038101906103cf9190613374565b6109a0565b005b6103de610a23565b005b6103e8610a4f565b005b6103f2610a84565b6040516103ff9190613215565b60405180910390f35b610422600480360381019061041d91906133b4565b610a8a565b005b61042c610b53565b60405161043991906131e1565b60405180910390f35b61044a610b6a565b60405161045791906132fb565b60405180910390f35b610468610b8e565b6040516104759190613453565b60405180910390f35b610486610bb2565b6040516104939190613215565b60405180910390f35b6104a4610bb8565b6040516104b19190613215565b60405180910390f35b6104c2610bbe565b6040516104cf9190613491565b60405180910390f35b6104e0610bd8565b6040516104ed9190613215565b60405180910390f35b6104fe610bde565b005b61051a600480360381019061051591906134ea565b610c13565b005b61053660048036038101906105319190613374565b610eb0565b60405161054391906131e1565b60405180910390f35b61056660048036038101906105619190613556565b610f1b565b005b610570610f43565b60405161057d91906132fb565b60405180910390f35b6105a0600480360381019061059b919061325c565b610f4a565b005b6105bc60048036038101906105b7919061325c565b61108e565b005b6105d860048036038101906105d391906135a9565b6111d2565b6040516105e69291906135d6565b60405180910390f35b6105f76111f6565b6040516106049190613215565b60405180910390f35b610627600480360381019061062291906133b4565b61120b565b005b610643600480360381019061063e91906135ff565b611285565b005b61064d6112ab565b60405161065a91906132fb565b60405180910390f35b61066b6112cf565b6040516106789190613491565b60405180910390f35b61069b6004803603810190610696919061325c565b6112f3565b005b6106a561148d565b005b6106af61152f565b6040516106bc9190613215565b60405180910390f35b6106cd611535565b6040516106da9190613491565b60405180910390f35b6106fd60048036038101906106f89190613374565b61154f565b005b610707611570565b6040516107149190613453565b60405180910390f35b610737600480360381019061073291906135a9565b611594565b6040516107459291906135d6565b60405180910390f35b6107686004803603810190610763919061366b565b61177a565b005b60007f7965db0b000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614806107dd57506107dc82611886565b5b9050919050565b60055481565b60085481565b60045481565b6107fe6118f0565b7fbde745d383bd90948c6bf528cf5a56a9fe775bfee56a5d53b36fd785802b88ec6108288161193f565b6000821161086b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108629061371b565b60405180910390fd5b6108bf610876611953565b30847f0000000000000000000000006758647a4cd6b4225b922b456be5c0535901203273ffffffffffffffffffffffffffffffffffffffff1661195b909392919063ffffffff16565b81600660008282546108d1919061376a565b925050819055507fed3478da81eace932babc39c0291e9731a6cc6249b5199cc742ec19a720bcc57600654600a60089054906101000a900467ffffffffffffffff16600a60009054906101000a900467ffffffffffffffff166040516109399392919061379e565b60405180910390a15061094a6119e4565b50565b60065481565b600060026000838152602001908152602001600020600101549050919050565b60035481565b60075481565b61098882610953565b6109918161193f565b61099b83836119ee565b505050565b6109a8611953565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614610a15576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a0c90613847565b60405180910390fd5b610a1f8282611acf565b5050565b610a2b6118f0565b610a33611bb1565b610a3b611bfb565b610a456000611dae565b610a4d6119e4565b565b7fbde745d383bd90948c6bf528cf5a56a9fe775bfee56a5d53b36fd785802b88ec610a798161193f565b610a81612030565b50565b600d5481565b7f969e743677c83a4458df4afcef9c1049579c1137c04e48694290c3e5fe6ef476610ab48161193f565b81600a84610ac29190613867565b1115610b03576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610afa906138f5565b60405180910390fd5b82600b8190555081600c819055507f091392e521f32b928e7effd1b5ff766e8c6faf01f5aceb57f54dc32cd2f57583600b54600c54604051610b469291906135d6565b60405180910390a1505050565b6000600160009054906101000a900460ff16905090565b7fbde745d383bd90948c6bf528cf5a56a9fe775bfee56a5d53b36fd785802b88ec81565b7f000000000000000000000000dad6a675ff6216c456b467570a7fc4801f49520481565b600c5481565b600e5481565b600a60089054906101000a900467ffffffffffffffff1681565b600b5481565b7fbde745d383bd90948c6bf528cf5a56a9fe775bfee56a5d53b36fd785802b88ec610c088161193f565b610c10612093565b50565b610c1b6118f0565b7fbde745d383bd90948c6bf528cf5a56a9fe775bfee56a5d53b36fd785802b88ec610c458161193f565b7f000000000000000000000000dad6a675ff6216c456b467570a7fc4801f49520473ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603610cd3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cca90613987565b60405180910390fd5b7f0000000000000000000000006758647a4cd6b4225b922b456be5c0535901203273ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603610d61576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d58906139f3565b60405180910390fd5b60008373ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401610d9c9190613a22565b602060405180830381865afa158015610db9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ddd9190613a52565b905082811015610e22576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e1990613acb565b60405180910390fd5b610e54610e2d611953565b848673ffffffffffffffffffffffffffffffffffffffff166120f59092919063ffffffff16565b8373ffffffffffffffffffffffffffffffffffffffff167f55350610fe57096d8c0ffa30beede987326bccfcb0b4415804164d0dd50ce8b184604051610e9a9190613215565b60405180910390a25050610eac6119e4565b5050565b60006002600084815260200190815260200160002060000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b610f236118f0565b610f2b611bb1565b610f3683838361217b565b610f3e6119e4565b505050565b6000801b81565b610f526118f0565b7fbde745d383bd90948c6bf528cf5a56a9fe775bfee56a5d53b36fd785802b88ec610f7c8161193f565b60008211610fbf576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fb690613b5d565b60405180910390fd5b6000600954600854610fd19190613b7d565b905080831115611016576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161100d90613c23565b60405180910390fd5b8260096000828254611028919061376a565b9250508190555061108161103a611953565b847f0000000000000000000000006758647a4cd6b4225b922b456be5c0535901203273ffffffffffffffffffffffffffffffffffffffff166120f59092919063ffffffff16565b505061108b6119e4565b50565b6110966118f0565b7f969e743677c83a4458df4afcef9c1049579c1137c04e48694290c3e5fe6ef4766110c08161193f565b60008211611103576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016110fa90613cb5565b60405180910390fd5b6000600e54600d546111159190613b7d565b90508083111561115a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161115190613d47565b60405180910390fd5b82600e600082825461116c919061376a565b925050819055506111c561117e611953565b847f0000000000000000000000006758647a4cd6b4225b922b456be5c0535901203273ffffffffffffffffffffffffffffffffffffffff166120f59092919063ffffffff16565b50506111cf6119e4565b50565b600f6020528060005260406000206000915090508060000154908060010154905082565b701d6329f1c35ca4bfabb9f561000000000081565b7fbde745d383bd90948c6bf528cf5a56a9fe775bfee56a5d53b36fd785802b88ec6112358161193f565b82600381905550816004819055507f14207e149af257f57a5573a804ff84d3f14a60673e606ec6c2acdd9f70c355226003546004546040516112789291906135d6565b60405180910390a1505050565b61128d6118f0565b611295611bb1565b61129f8282612560565b6112a76119e4565b5050565b7f969e743677c83a4458df4afcef9c1049579c1137c04e48694290c3e5fe6ef47681565b7f000000000000000000000000000000000000000000000000000000006480b79081565b6112fb6118f0565b7fbde745d383bd90948c6bf528cf5a56a9fe775bfee56a5d53b36fd785802b88ec6113258161193f565b60008211611368576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161135f90613dd9565b60405180910390fd5b6006548211156113ad576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113a490613e6b565b60405180910390fd5b81600660008282546113bf9190613b7d565b925050819055506114186113d1611953565b837f0000000000000000000000006758647a4cd6b4225b922b456be5c0535901203273ffffffffffffffffffffffffffffffffffffffff166120f59092919063ffffffff16565b7fed3478da81eace932babc39c0291e9731a6cc6249b5199cc742ec19a720bcc57600654600a60089054906101000a900467ffffffffffffffff16600a60009054906101000a900467ffffffffffffffff166040516114799392919061379e565b60405180910390a15061148a6119e4565b50565b7fbde745d383bd90948c6bf528cf5a56a9fe775bfee56a5d53b36fd785802b88ec6114b78161193f565b7f000000000000000000000000000000000000000000000000000000006480b79067ffffffffffffffff16421015611524576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161151b90613ed7565b60405180910390fd5b61152c611bfb565b50565b60095481565b600a60009054906101000a900467ffffffffffffffff1681565b61155882610953565b6115618161193f565b61156b8383611acf565b505050565b7f0000000000000000000000006758647a4cd6b4225b922b456be5c0535901203281565b60008060006115c342600a60009054906101000a900467ffffffffffffffff1667ffffffffffffffff166128e5565b90506000600a60089054906101000a900467ffffffffffffffff16600a60009054906101000a900467ffffffffffffffff166115ff9190613ef7565b90506000600a60089054906101000a900467ffffffffffffffff16836116259190613ef7565b90506000808367ffffffffffffffff16111561165f5761165c6006548367ffffffffffffffff168567ffffffffffffffff166128fe565b90505b60006007549050600a60009054906101000a900467ffffffffffffffff1667ffffffffffffffff168567ffffffffffffffff16111580156116a257506000600554115b156116d3576116c582701d6329f1c35ca4bfabb9f56100000000006005546128fe565b816116d0919061376a565b90505b611768600f60008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060010154600f60008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000015483600b54600c546129d9565b80975081985050505050505050915091565b7fbde745d383bd90948c6bf528cf5a56a9fe775bfee56a5d53b36fd785802b88ec6117a48161193f565b428267ffffffffffffffff16116117f0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016117e790613fa5565b60405180910390fd5b81600a60006101000a81548167ffffffffffffffff021916908367ffffffffffffffff1602179055507fed3478da81eace932babc39c0291e9731a6cc6249b5199cc742ec19a720bcc57600654600a60089054906101000a900467ffffffffffffffff16600a60009054906101000a900467ffffffffffffffff1660405161187a9392919061379e565b60405180910390a15050565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b600260005403611935576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161192c90614011565b60405180910390fd5b6002600081905550565b6119508161194b611953565b612a33565b50565b600033905090565b6119de846323b872dd60e01b85858560405160240161197c93929190614031565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050612ab8565b50505050565b6001600081905550565b6119f88282610eb0565b611acb5760016002600084815260200190815260200160002060000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550611a70611953565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45b5050565b611ad98282610eb0565b15611bad5760006002600084815260200190815260200160002060000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550611b52611953565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45b5050565b611bb9610b53565b15611bf9576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611bf0906140b4565b60405180910390fd5b565b6000611c2742600a60009054906101000a900467ffffffffffffffff1667ffffffffffffffff166128e5565b90506000600a60089054906101000a900467ffffffffffffffff16600a60009054906101000a900467ffffffffffffffff16611c639190613ef7565b905060008167ffffffffffffffff1603611c7e575050611dac565b6000600a60089054906101000a900467ffffffffffffffff1683611ca29190613ef7565b90506000611cc76006548367ffffffffffffffff168567ffffffffffffffff166128fe565b90506000806005541115611d1357611cf382701d6329f1c35ca4bfabb9f56100000000006005546128fe565b90508060076000828254611d07919061376a565b92505081905550611d64565b8160086000828254611d25919061376a565b925050819055507fa641ca195988b20fb3185bbfd64521b79089ad0913255a52c171bac83783bdda82604051611d5b9190613215565b60405180910390a15b8160066000828254611d769190613b7d565b9250508190555084600a60086101000a81548167ffffffffffffffff021916908367ffffffffffffffff16021790555050505050505b565b600080611e56600f6000611dc0611953565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060010154600f6000611e0a611953565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000154600754600b54600c546129d9565b9150915060045482101580611e685750825b611ea7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611e9e90614120565b60405180910390fd5b600754600f6000611eb6611953565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101819055508215611f68578082611f09919061376a565b60086000828254611f1a919061376a565b925050819055507fa641ca195988b20fb3185bbfd64521b79089ad0913255a52c171bac83783bdda8183611f4e919061376a565b604051611f5b9190613215565b60405180910390a161202b565b80600d6000828254611f7a919061376a565b92505081905550611fd3611f8c611953565b837f0000000000000000000000006758647a4cd6b4225b922b456be5c0535901203273ffffffffffffffffffffffffffffffffffffffff166120f59092919063ffffffff16565b611fdb611953565b73ffffffffffffffffffffffffffffffffffffffff167fdacbdde355ba930696a362ea6738feb9f8bd52dfb3d81947558fd3217e23e32583836040516120229291906135d6565b60405180910390a25b505050565b612038612b7f565b6000600160006101000a81548160ff0219169083151502179055507f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa61207c611953565b6040516120899190613a22565b60405180910390a1565b61209b611bb1565b60018060006101000a81548160ff0219169083151502179055507f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586120de611953565b6040516120eb9190613a22565b60405180910390a1565b6121768363a9059cbb60e01b8484604051602401612114929190614140565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050612ab8565b505050565b6000600f6000612189611953565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000015403612207576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016121fe906141b5565b60405180910390fd5b82600f6000612214611953565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600001541015612293576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161228a90614247565b60405180910390fd5b600083116122d6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016122cd906142b3565b60405180910390fd5b82600f60006122e3611953565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600001541480612383575060035483600f6000612338611953565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600001546123809190613b7d565b10155b6123c2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016123b99061436b565b60405180910390fd5b6123ca611bfb565b600083600f60006123d9611953565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600001546124219190613b7d565b9050828061242f5750600081145b156124425761243d82611dae565b61244c565b61244b81612bc8565b5b80600f6000612459611953565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000018190555083600560008282546124ac9190613b7d565b925050819055506125056124be611953565b857f000000000000000000000000dad6a675ff6216c456b467570a7fc4801f49520473ffffffffffffffffffffffffffffffffffffffff166120f59092919063ffffffff16565b61250d611953565b73ffffffffffffffffffffffffffffffffffffffff167f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5856040516125529190613215565b60405180910390a250505050565b7f000000000000000000000000000000000000000000000000000000006480b79067ffffffffffffffff164210156125cd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016125c490613ed7565b60405180910390fd5b600060065411612612576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612609906143fd565b60405180910390fd5b600a60009054906101000a900467ffffffffffffffff1667ffffffffffffffff164210612674576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161266b90614469565b60405180910390fd5b600082116126b7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016126ae906144d5565b60405180910390fd5b600354600f60006126c6611953565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600001548361270f919061376a565b1015612750576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161274790614567565b60405180910390fd5b6127a461275b611953565b30847f000000000000000000000000dad6a675ff6216c456b467570a7fc4801f49520473ffffffffffffffffffffffffffffffffffffffff1661195b909392919063ffffffff16565b6127ac611bfb565b600082600f60006127bb611953565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000154612803919061376a565b9050811561281a576128156000611dae565b612824565b61282381612bc8565b5b80600f6000612831611953565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600001819055508260056000828254612884919061376a565b92505081905550612893611953565b73ffffffffffffffffffffffffffffffffffffffff167f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d846040516128d89190613215565b60405180910390a2505050565b60008183106128f457816128f6565b825b905092915050565b60008060008019858709858702925082811083820303915050600081036129395783828161292f5761292e614587565b5b04925050506129d2565b80841161294557600080fd5b60008486880990508281118203915080830392506000600186190186169050808604955080840493506001818260000304019050808302841793506000600287600302189050808702600203810290508087026002038102905080870260020381029050808702600203810290508087026002038102905080870260020381029050808502955050505050505b9392505050565b600080600087866129ea9190613b7d565b90506000612a0a8289701d6329f1c35ca4bfabb9f56100000000006128fe565b9050612a178187876128fe565b92508281612a259190613b7d565b935050509550959350505050565b612a3d8282610eb0565b612ab457612a4a81612d06565b612a588360001c6020612d33565b604051602001612a699291906146bf565b6040516020818303038152906040526040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612aab9190614743565b60405180910390fd5b5050565b6000612b1a826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16612f6f9092919063ffffffff16565b9050600081511115612b7a5780806020019051810190612b3a919061477a565b612b79576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612b7090614819565b60405180910390fd5b5b505050565b612b87610b53565b612bc6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612bbd90614885565b60405180910390fd5b565b600080612c70600f6000612bda611953565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060010154600f6000612c24611953565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000154600754600b54600c546129d9565b9150915060008183612c82919061376a565b90506000612ca282701d6329f1c35ca4bfabb9f5610000000000876128fe565b905080600754612cb29190613b7d565b600f6000612cbe611953565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101819055505050505050565b6060612d2c8273ffffffffffffffffffffffffffffffffffffffff16601460ff16612d33565b9050919050565b606060006002836002612d469190613867565b612d50919061376a565b67ffffffffffffffff811115612d6957612d686148a5565b5b6040519080825280601f01601f191660200182016040528015612d9b5781602001600182028036833780820191505090505b5090507f300000000000000000000000000000000000000000000000000000000000000081600081518110612dd357612dd26148d4565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110612e3757612e366148d4565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060006001846002612e779190613867565b612e81919061376a565b90505b6001811115612f21577f3031323334353637383961626364656600000000000000000000000000000000600f861660108110612ec357612ec26148d4565b5b1a60f81b828281518110612eda57612ed96148d4565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600485901c945080612f1a90614903565b9050612e84565b5060008414612f65576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612f5c90614978565b60405180910390fd5b8091505092915050565b6060612f7e8484600085612f87565b90509392505050565b606082471015612fcc576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612fc390614a0a565b60405180910390fd5b6000808673ffffffffffffffffffffffffffffffffffffffff168587604051612ff59190614a71565b60006040518083038185875af1925050503d8060008114613032576040519150601f19603f3d011682016040523d82523d6000602084013e613037565b606091505b509150915061304887838387613054565b92505050949350505050565b606083156130b65760008351036130ae5761306e856130c9565b6130ad576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016130a490614ad4565b60405180910390fd5b5b8290506130c1565b6130c083836130ec565b5b949350505050565b6000808273ffffffffffffffffffffffffffffffffffffffff163b119050919050565b6000825111156130ff5781518083602001fd5b806040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016131339190614743565b60405180910390fd5b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b61317681613141565b811461318157600080fd5b50565b6000813590506131938161316d565b92915050565b6000602082840312156131af576131ae61313c565b5b60006131bd84828501613184565b91505092915050565b60008115159050919050565b6131db816131c6565b82525050565b60006020820190506131f660008301846131d2565b92915050565b6000819050919050565b61320f816131fc565b82525050565b600060208201905061322a6000830184613206565b92915050565b613239816131fc565b811461324457600080fd5b50565b60008135905061325681613230565b92915050565b6000602082840312156132725761327161313c565b5b600061328084828501613247565b91505092915050565b6000819050919050565b61329c81613289565b81146132a757600080fd5b50565b6000813590506132b981613293565b92915050565b6000602082840312156132d5576132d461313c565b5b60006132e3848285016132aa565b91505092915050565b6132f581613289565b82525050565b600060208201905061331060008301846132ec565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061334182613316565b9050919050565b61335181613336565b811461335c57600080fd5b50565b60008135905061336e81613348565b92915050565b6000806040838503121561338b5761338a61313c565b5b6000613399858286016132aa565b92505060206133aa8582860161335f565b9150509250929050565b600080604083850312156133cb576133ca61313c565b5b60006133d985828601613247565b92505060206133ea85828601613247565b9150509250929050565b6000819050919050565b600061341961341461340f84613316565b6133f4565b613316565b9050919050565b600061342b826133fe565b9050919050565b600061343d82613420565b9050919050565b61344d81613432565b82525050565b60006020820190506134686000830184613444565b92915050565b600067ffffffffffffffff82169050919050565b61348b8161346e565b82525050565b60006020820190506134a66000830184613482565b92915050565b60006134b782613336565b9050919050565b6134c7816134ac565b81146134d257600080fd5b50565b6000813590506134e4816134be565b92915050565b600080604083850312156135015761350061313c565b5b600061350f858286016134d5565b925050602061352085828601613247565b9150509250929050565b613533816131c6565b811461353e57600080fd5b50565b6000813590506135508161352a565b92915050565b60008060006060848603121561356f5761356e61313c565b5b600061357d86828701613247565b935050602061358e86828701613541565b925050604061359f86828701613541565b9150509250925092565b6000602082840312156135bf576135be61313c565b5b60006135cd8482850161335f565b91505092915050565b60006040820190506135eb6000830185613206565b6135f86020830184613206565b9392505050565b600080604083850312156136165761361561313c565b5b600061362485828601613247565b925050602061363585828601613541565b9150509250929050565b6136488161346e565b811461365357600080fd5b50565b6000813590506136658161363f565b92915050565b6000602082840312156136815761368061313c565b5b600061368f84828501613656565b91505092915050565b600082825260208201905092915050565b7f556e61626c6520746f206465706f73697420302072657761726420746f6b656e60008201527f7300000000000000000000000000000000000000000000000000000000000000602082015250565b6000613705602183613698565b9150613710826136a9565b604082019050919050565b60006020820190508181036000830152613734816136f8565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000613775826131fc565b9150613780836131fc565b92508282019050808211156137985761379761373b565b5b92915050565b60006060820190506137b36000830186613206565b6137c06020830185613482565b6137cd6040830184613482565b949350505050565b7f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560008201527f20726f6c657320666f722073656c660000000000000000000000000000000000602082015250565b6000613831602f83613698565b915061383c826137d5565b604082019050919050565b6000602082019050818103600083015261386081613824565b9050919050565b6000613872826131fc565b915061387d836131fc565b925082820261388b816131fc565b915082820484148315176138a2576138a161373b565b5b5092915050565b7f54617820726174696f2065786365656473203130252063617000000000000000600082015250565b60006138df601983613698565b91506138ea826138a9565b602082019050919050565b6000602082019050818103600083015261390e816138d2565b9050919050565b7f43616e6e6f7420776974686472617720746865207374616b696e6720746f6b6560008201527f6e00000000000000000000000000000000000000000000000000000000000000602082015250565b6000613971602183613698565b915061397c82613915565b604082019050919050565b600060208201905081810360008301526139a081613964565b9050919050565b7f43616e6e6f74207769746864726177207468652072657761726420746f6b656e600082015250565b60006139dd602083613698565b91506139e8826139a7565b602082019050919050565b60006020820190508181036000830152613a0c816139d0565b9050919050565b613a1c81613336565b82525050565b6000602082019050613a376000830184613a13565b92915050565b600081519050613a4c81613230565b92915050565b600060208284031215613a6857613a6761313c565b5b6000613a7684828501613a3d565b91505092915050565b7f4e6f7420656e6f75676820746f6b656e7320746f207769746864726177000000600082015250565b6000613ab5601d83613698565b9150613ac082613a7f565b602082019050919050565b60006020820190508181036000830152613ae481613aa8565b9050919050565b7f556e61626c6520746f2077697468647261772030206c6f73742072657761726460008201527f7320746f6b656e73000000000000000000000000000000000000000000000000602082015250565b6000613b47602883613698565b9150613b5282613aeb565b604082019050919050565b60006020820190508181036000830152613b7681613b3a565b9050919050565b6000613b88826131fc565b9150613b93836131fc565b9250828203905081811115613bab57613baa61373b565b5b92915050565b7f416d6f756e742069732067726561746572207468616e20617661696c61626c6560008201527f206c6f7374207265776172647300000000000000000000000000000000000000602082015250565b6000613c0d602d83613698565b9150613c1882613bb1565b604082019050919050565b60006020820190508181036000830152613c3c81613c00565b9050919050565b7f556e61626c6520746f20776974686472617720302070726f6772616d2074617860008201527f6573000000000000000000000000000000000000000000000000000000000000602082015250565b6000613c9f602283613698565b9150613caa82613c43565b604082019050919050565b60006020820190508181036000830152613cce81613c92565b9050919050565b7f416d6f756e742069732067726561746572207468616e20617661696c61626c6560008201527f2074617865730000000000000000000000000000000000000000000000000000602082015250565b6000613d31602683613698565b9150613d3c82613cd5565b604082019050919050565b60006020820190508181036000830152613d6081613d24565b9050919050565b7f556e61626c6520746f20776974686472617720302072657761726420746f6b6560008201527f6e73000000000000000000000000000000000000000000000000000000000000602082015250565b6000613dc3602283613698565b9150613dce82613d67565b604082019050919050565b60006020820190508181036000830152613df281613db6565b9050919050565b7f556e61626c6520746f207769746864726177206d6f7265207468616e2074686560008201527f2070726f6772616d207265776172642072656d61696e696e6700000000000000602082015250565b6000613e55603983613698565b9150613e6082613df9565b604082019050919050565b60006020820190508181036000830152613e8481613e48565b9050919050565b7f5374616b696e672070726f6772616d206e6f74206f70656e2079657400000000600082015250565b6000613ec1601c83613698565b9150613ecc82613e8b565b602082019050919050565b60006020820190508181036000830152613ef081613eb4565b9050919050565b6000613f028261346e565b9150613f0d8361346e565b9250828203905067ffffffffffffffff811115613f2d57613f2c61373b565b5b92915050565b7f4e65772070726f6772616d206465706c6574696f6e2064617465206d7573742060008201527f62652067726561746572207468616e2063757272656e742074696d6500000000602082015250565b6000613f8f603c83613698565b9150613f9a82613f33565b604082019050919050565b60006020820190508181036000830152613fbe81613f82565b9050919050565b7f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00600082015250565b6000613ffb601f83613698565b915061400682613fc5565b602082019050919050565b6000602082019050818103600083015261402a81613fee565b9050919050565b60006060820190506140466000830186613a13565b6140536020830185613a13565b6140606040830184613206565b949350505050565b7f5061757361626c653a2070617573656400000000000000000000000000000000600082015250565b600061409e601083613698565b91506140a982614068565b602082019050919050565b600060208201905081810360008301526140cd81614091565b9050919050565b7f4e6f7420656e6f756768207265776172647320746f20636c61696d0000000000600082015250565b600061410a601b83613698565b9150614115826140d4565b602082019050919050565b60006020820190508181036000830152614139816140fd565b9050919050565b60006040820190506141556000830185613a13565b6141626020830184613206565b9392505050565b7f4e6f20616d6f756e7420746f2077697468647261770000000000000000000000600082015250565b600061419f601583613698565b91506141aa82614169565b602082019050919050565b600060208201905081810360008301526141ce81614192565b9050919050565b7f416d6f756e7420746f207769746864726177206973206772656174657220746860008201527f616e207374616b65640000000000000000000000000000000000000000000000602082015250565b6000614231602983613698565b915061423c826141d5565b604082019050919050565b6000602082019050818103600083015261426081614224565b9050919050565b7f556e61626c6520746f207769746864726177203020746f6b656e730000000000600082015250565b600061429d601b83613698565b91506142a882614267565b602082019050919050565b600060208201905081810360008301526142cc81614290565b9050919050565b7f5468652066696e616c207374616b656420616d6f756e7420776f756c6420626560008201527f206c657373207468616e2072657175697265642062792074686520737065636960208201527f666965642070726f6772616d0000000000000000000000000000000000000000604082015250565b6000614355604c83613698565b9150614360826142d3565b606082019050919050565b6000602082019050818103600083015261438481614348565b9050919050565b7f546865726520617265206e6f2072657761726473206465706f7369746564207960008201527f6574000000000000000000000000000000000000000000000000000000000000602082015250565b60006143e7602283613698565b91506143f28261438b565b604082019050919050565b60006020820190508181036000830152614416816143da565b9050919050565b7f5374616b696e672070726f6772616d2068617320636c6f736564000000000000600082015250565b6000614453601a83613698565b915061445e8261441d565b602082019050919050565b6000602082019050818103600083015261448281614446565b9050919050565b7f556e61626c6520746f207374616b65203020746f6b656e730000000000000000600082015250565b60006144bf601883613698565b91506144ca82614489565b602082019050919050565b600060208201905081810360008301526144ee816144b2565b9050919050565b7f5374616b696e67206c657373207468616e20726571756972656420627920746860008201527f65207370656369666965642070726f6772616d00000000000000000000000000602082015250565b6000614551603383613698565b915061455c826144f5565b604082019050919050565b6000602082019050818103600083015261458081614544565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600081905092915050565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000600082015250565b60006145f76017836145b6565b9150614602826145c1565b601782019050919050565b600081519050919050565b60005b8381101561463657808201518184015260208101905061461b565b60008484015250505050565b600061464d8261460d565b61465781856145b6565b9350614667818560208601614618565b80840191505092915050565b7f206973206d697373696e6720726f6c6520000000000000000000000000000000600082015250565b60006146a96011836145b6565b91506146b482614673565b601182019050919050565b60006146ca826145ea565b91506146d68285614642565b91506146e18261469c565b91506146ed8284614642565b91508190509392505050565b6000601f19601f8301169050919050565b60006147158261460d565b61471f8185613698565b935061472f818560208601614618565b614738816146f9565b840191505092915050565b6000602082019050818103600083015261475d818461470a565b905092915050565b6000815190506147748161352a565b92915050565b6000602082840312156147905761478f61313c565b5b600061479e84828501614765565b91505092915050565b7f5361666545524332303a204552433230206f7065726174696f6e20646964206e60008201527f6f74207375636365656400000000000000000000000000000000000000000000602082015250565b6000614803602a83613698565b915061480e826147a7565b604082019050919050565b60006020820190508181036000830152614832816147f6565b9050919050565b7f5061757361626c653a206e6f7420706175736564000000000000000000000000600082015250565b600061486f601483613698565b915061487a82614839565b602082019050919050565b6000602082019050818103600083015261489e81614862565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600061490e826131fc565b9150600082036149215761492061373b565b5b600182039050919050565b7f537472696e67733a20686578206c656e67746820696e73756666696369656e74600082015250565b6000614962602083613698565b915061496d8261492c565b602082019050919050565b6000602082019050818103600083015261499181614955565b9050919050565b7f416464726573733a20696e73756666696369656e742062616c616e636520666f60008201527f722063616c6c0000000000000000000000000000000000000000000000000000602082015250565b60006149f4602683613698565b91506149ff82614998565b604082019050919050565b60006020820190508181036000830152614a23816149e7565b9050919050565b600081519050919050565b600081905092915050565b6000614a4b82614a2a565b614a558185614a35565b9350614a65818560208601614618565b80840191505092915050565b6000614a7d8284614a40565b915081905092915050565b7f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000600082015250565b6000614abe601d83613698565b9150614ac982614a88565b602082019050919050565b60006020820190508181036000830152614aed81614ab1565b905091905056fea2646970667358221220bc9c2003d2e09db21d5df4bc722aa9ebcdd59632b8474e96b57bf93a82ad0f8a64736f6c63430008120033
Verified Source Code Full Match
Compiler: v0.8.18+commit.87f61d96
EVM: paris
Optimization: No
LatticeFixedRewardStaking.sol 543 lines
// SPDX-License-Identifier: MIT /** * @title Lattice Fixed Reward Staking Contract * @author Stardust Collective <[email protected]> * * Transformed idea from SushiSwap's https://github.com/sushiswap/StakingContract */ pragma solidity ^0.8.18; import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol'; import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import {ReentrancyGuard} from '@openzeppelin/contracts/security/ReentrancyGuard.sol'; import {Pausable} from '@openzeppelin/contracts/security/Pausable.sol'; import {AccessControl} from '@openzeppelin/contracts/access/AccessControl.sol'; import {Math} from '@openzeppelin/contracts/utils/math/Math.sol'; contract LatticeFixedRewardStaking is ReentrancyGuard, Pausable, AccessControl { using SafeERC20 for IERC20; bytes32 public constant CONFIGURATION_ROLE = keccak256('CONFIGURATION_ROLE'); bytes32 public constant STEWARD_ROLE = keccak256('STEWARD_ROLE'); uint256 public constant MAGNITUDE_CONSTANT = 1e40; IERC20 public immutable stakingToken; uint256 public minStakingAmount; IERC20 public immutable rewardToken; uint256 public minRewardAmount; uint64 public immutable programStartsAt; uint256 public programStakedLiquidity; uint256 public programRewardRemaining; uint256 public programRewardPerLiquidity; uint256 public programRewardLost; uint256 public programRewardLostWithdrawn; uint64 public programRewardsDepletionAt; uint64 public programLastAccruedRewardsAt; uint256 public taxRatioNumerator; uint256 public taxRatioDenominator; uint256 public taxAccumulated; uint256 public taxAccumulatedWithdrawn; struct StakingUser { uint256 amountStaked; uint256 lastProgramRewardPerLiquidity; } mapping(address => StakingUser) public users; event Staked(address indexed user, uint256 amount); event Withdrawn(address indexed user, uint256 amount); event RewardsClaimed( address indexed user, uint256 rewardsTaxed, uint256 taxes ); event StakingConditionChanged( uint256 remainingRewards, uint64 programLastAccruedRewardsAt, uint64 programRewardsDepletionAt ); event StakingRestrictionChanged( uint256 minStakingAmount, uint256 minRewardAmount ); event TaxConditionChanged( uint256 taxRatioNumerator, uint256 taxRatioDenominator ); event RewardsLost(uint256 amount); event RecoveredERC20(address indexed token, uint256 amount); constructor( address _stakingToken, uint256 _minStakingAmount, address _rewardToken, uint256 _minRewardAmount, uint64 _programStartsAt, uint64 _programRewardsDepletionAt, uint256 _taxRatioNumerator, uint256 _taxRatioDenominator, address[] memory managers ) { require( _programStartsAt < _programRewardsDepletionAt, 'Invalid program timeline' ); require(_stakingToken != address(0), 'Invalid staking token'); require(_rewardToken != address(0), 'Invalid reward token'); require( _taxRatioNumerator * 10 <= _taxRatioDenominator, 'Tax ratio exceeds 10% cap' ); // Program Condition stakingToken = IERC20(_stakingToken); minStakingAmount = _minStakingAmount; rewardToken = IERC20(_rewardToken); minRewardAmount = _minRewardAmount; // Program Timeline programStartsAt = _programStartsAt; programRewardsDepletionAt = _programRewardsDepletionAt; programLastAccruedRewardsAt = _programStartsAt; // Program Taxes taxRatioNumerator = _taxRatioNumerator; taxRatioDenominator = _taxRatioDenominator; _setRoleAdmin(CONFIGURATION_ROLE, CONFIGURATION_ROLE); _setRoleAdmin(STEWARD_ROLE, CONFIGURATION_ROLE); _grantRole(CONFIGURATION_ROLE, _msgSender()); _grantRole(STEWARD_ROLE, _msgSender()); for (uint16 i = 0; i < managers.length; i++) { _grantRole(STEWARD_ROLE, managers[i]); } } /** * General Functions */ function stake( uint256 _amount, bool _claimExistingRewards ) external nonReentrant whenNotPaused { _stake(_amount, _claimExistingRewards); } function withdraw( uint256 _amount, bool _claimExistingRewards, bool _waiveExistingRewards ) external nonReentrant whenNotPaused { _withdraw(_amount, _claimExistingRewards, _waiveExistingRewards); } function claimRewards() external nonReentrant whenNotPaused { // We generate a new rewards period to include immediately previous rewards for the user _accrueRewardsPeriod(); _claimRewards(false); } /** * Calculate a new rewards period for the current time, and calculate rewards based * on the next program reward per liquidity. */ function availableRewards( address user ) external view returns (uint256 _userRewardsTaxed, uint256 _userTaxes) { uint64 _programNextAccruedRewardsAt = uint64( Math.min(block.timestamp, programRewardsDepletionAt) ); uint64 _rewardRemainingDuration = programRewardsDepletionAt - programLastAccruedRewardsAt; uint64 _rewardPeriodDuration = _programNextAccruedRewardsAt - programLastAccruedRewardsAt; uint256 _rewardAmountForPeriod = 0; if (_rewardRemainingDuration > 0) { _rewardAmountForPeriod = Math.mulDiv( programRewardRemaining, _rewardPeriodDuration, _rewardRemainingDuration ); } uint256 _nextProgramRewardPerLiquidity = programRewardPerLiquidity; // Use actual RPL if the program has ended or staked liquidity == 0 if ( _programNextAccruedRewardsAt <= programRewardsDepletionAt && programStakedLiquidity > 0 ) { _nextProgramRewardPerLiquidity += Math.mulDiv( _rewardAmountForPeriod, MAGNITUDE_CONSTANT, programStakedLiquidity ); } (_userRewardsTaxed, _userTaxes) = _calculateRewardsAndTaxes( users[user].lastProgramRewardPerLiquidity, users[user].amountStaked, _nextProgramRewardPerLiquidity, taxRatioNumerator, taxRatioDenominator ); } /** * General Internal Functions */ function _stake(uint256 _amount, bool _claimExistingRewards) internal { require( block.timestamp >= programStartsAt, 'Staking program not open yet' ); require( programRewardRemaining > 0, 'There are no rewards deposited yet' ); require( block.timestamp < programRewardsDepletionAt, 'Staking program has closed' ); require(_amount > 0, 'Unable to stake 0 tokens'); require( _amount + users[_msgSender()].amountStaked >= minStakingAmount, 'Staking less than required by the specified program' ); stakingToken.safeTransferFrom(_msgSender(), address(this), _amount); // Generate a new rewards period => new program reward per liquidity _accrueRewardsPeriod(); uint256 _userNextAmountStaked = users[_msgSender()].amountStaked + _amount; if (_claimExistingRewards) { _claimRewards(false); } else { _saveRewards(_userNextAmountStaked); } users[_msgSender()].amountStaked = _userNextAmountStaked; programStakedLiquidity += _amount; emit Staked(_msgSender(), _amount); } function _withdraw( uint256 _amount, bool _claimExistingRewards, bool _waiveExistingRewards ) internal { require(users[_msgSender()].amountStaked != 0, 'No amount to withdraw'); require( users[_msgSender()].amountStaked >= _amount, 'Amount to withdraw is greater than staked' ); require(_amount > 0, 'Unable to withdraw 0 tokens'); require( users[_msgSender()].amountStaked == _amount || users[_msgSender()].amountStaked - _amount >= minStakingAmount, 'The final staked amount would be less than required by the specified program' ); // Generate a new rewards period => new program reward per liquidity _accrueRewardsPeriod(); uint256 _userNextAmountStaked = users[_msgSender()].amountStaked - _amount; if (_claimExistingRewards || _userNextAmountStaked == 0) { _claimRewards(_waiveExistingRewards); } else { _saveRewards(_userNextAmountStaked); } users[_msgSender()].amountStaked = _userNextAmountStaked; programStakedLiquidity -= _amount; stakingToken.safeTransfer(_msgSender(), _amount); emit Withdrawn(_msgSender(), _amount); } function _claimRewards(bool _waiveExistingRewards) internal { ( uint256 _userRewardsTaxed, uint256 _userTaxes ) = _calculateRewardsAndTaxes( users[_msgSender()].lastProgramRewardPerLiquidity, users[_msgSender()].amountStaked, programRewardPerLiquidity, taxRatioNumerator, taxRatioDenominator ); require( _userRewardsTaxed >= minRewardAmount || _waiveExistingRewards, 'Not enough rewards to claim' ); users[_msgSender()] .lastProgramRewardPerLiquidity = programRewardPerLiquidity; if (_waiveExistingRewards) { programRewardLost += _userRewardsTaxed + _userTaxes; emit RewardsLost(_userRewardsTaxed + _userTaxes); } else { taxAccumulated += _userTaxes; rewardToken.safeTransfer(_msgSender(), _userRewardsTaxed); emit RewardsClaimed(_msgSender(), _userRewardsTaxed, _userTaxes); } } /** * We derive a new [user].lastProgramRewardPerLiquidity based on the new amount * staked and considering previous rewards. The in the next call to _calculateRewardsAndTaxes() * user will receive both previous-non-claimed rewards and new rewards. */ function _saveRewards(uint256 _nextAmountStaked) internal { ( uint256 _userRewardsTaxed, uint256 _userTaxes ) = _calculateRewardsAndTaxes( users[_msgSender()].lastProgramRewardPerLiquidity, users[_msgSender()].amountStaked, programRewardPerLiquidity, taxRatioNumerator, taxRatioDenominator ); uint256 _userRewards = _userRewardsTaxed + _userTaxes; uint256 _userProgramRewardPerLiquidityDelta = Math.mulDiv( _userRewards, MAGNITUDE_CONSTANT, _nextAmountStaked ); users[_msgSender()].lastProgramRewardPerLiquidity = programRewardPerLiquidity - _userProgramRewardPerLiquidityDelta; } /** * Generate a new rewards period, discard unused/reserved reward amount for the generated period * add reward per liquidity for the generated period in order to claim/calculate rewards. */ function _accrueRewardsPeriod() internal { uint64 _programNextAccruedRewardsAt = uint64( Math.min(block.timestamp, programRewardsDepletionAt) ); uint64 _rewardRemainingDuration = programRewardsDepletionAt - programLastAccruedRewardsAt; // Don't accrue if the remaining duration is 0 (program has ended) if (_rewardRemainingDuration == 0) { return; } uint64 _rewardPeriodDuration = _programNextAccruedRewardsAt - programLastAccruedRewardsAt; uint256 _rewardAmountForPeriod = Math.mulDiv( programRewardRemaining, _rewardPeriodDuration, _rewardRemainingDuration ); uint256 _programRewardPerLiquidityChange = 0; if (programStakedLiquidity > 0) { _programRewardPerLiquidityChange = Math.mulDiv( _rewardAmountForPeriod, MAGNITUDE_CONSTANT, programStakedLiquidity ); programRewardPerLiquidity += _programRewardPerLiquidityChange; } else { programRewardLost += _rewardAmountForPeriod; emit RewardsLost(_rewardAmountForPeriod); } programRewardRemaining -= _rewardAmountForPeriod; programLastAccruedRewardsAt = _programNextAccruedRewardsAt; } function _calculateRewardsAndTaxes( uint256 _userLastProgramRewardPerLiquidity, uint256 _userAmountStaked, uint256 _programRewardPerLiquidity, uint256 _taxRatioNumerator, uint256 _taxRatioDenominator ) internal pure returns (uint256 _userRewardsTaxed, uint256 _userTaxes) { uint256 _userProgramRewardPerLiquidityDelta = _programRewardPerLiquidity - _userLastProgramRewardPerLiquidity; uint256 _userRewards = Math.mulDiv( _userProgramRewardPerLiquidityDelta, _userAmountStaked, MAGNITUDE_CONSTANT ); _userTaxes = Math.mulDiv( _userRewards, _taxRatioNumerator, _taxRatioDenominator ); _userRewardsTaxed = _userRewards - _userTaxes; } /** * Admin Functions */ function accrueRewardsPeriod() external onlyRole(STEWARD_ROLE) { require( block.timestamp >= programStartsAt, 'Staking program not open yet' ); _accrueRewardsPeriod(); } function depositProgramRewards( uint256 _amount ) external nonReentrant onlyRole(STEWARD_ROLE) { require(_amount > 0, 'Unable to deposit 0 reward tokens'); rewardToken.safeTransferFrom(_msgSender(), address(this), _amount); programRewardRemaining += _amount; emit StakingConditionChanged( programRewardRemaining, programLastAccruedRewardsAt, programRewardsDepletionAt ); } function withdrawProgramRewards( uint256 _amount ) external nonReentrant onlyRole(STEWARD_ROLE) { require(_amount > 0, 'Unable to withdraw 0 reward tokens'); require( _amount <= programRewardRemaining, 'Unable to withdraw more than the program reward remaining' ); programRewardRemaining -= _amount; rewardToken.safeTransfer(_msgSender(), _amount); emit StakingConditionChanged( programRewardRemaining, programLastAccruedRewardsAt, programRewardsDepletionAt ); } function withdrawProgramLostRewards( uint256 _amount ) external nonReentrant onlyRole(STEWARD_ROLE) { require(_amount > 0, 'Unable to withdraw 0 lost rewards tokens'); uint256 _lostRewardsAvailable = programRewardLost - programRewardLostWithdrawn; require( _amount <= _lostRewardsAvailable, 'Amount is greater than available lost rewards' ); programRewardLostWithdrawn += _amount; rewardToken.safeTransfer(_msgSender(), _amount); } function withdrawProgramTaxes( uint256 _amount ) external nonReentrant onlyRole(CONFIGURATION_ROLE) { require(_amount > 0, 'Unable to withdraw 0 program taxes'); uint256 _taxesAvailable = taxAccumulated - taxAccumulatedWithdrawn; require( _amount <= _taxesAvailable, 'Amount is greater than available taxes' ); taxAccumulatedWithdrawn += _amount; rewardToken.safeTransfer(_msgSender(), _amount); } function updateProgramDepletionDate( uint64 _programRewardsDepletionAt ) external onlyRole(STEWARD_ROLE) { require( _programRewardsDepletionAt > block.timestamp, 'New program depletion date must be greater than current time' ); programRewardsDepletionAt = _programRewardsDepletionAt; emit StakingConditionChanged( programRewardRemaining, programLastAccruedRewardsAt, programRewardsDepletionAt ); } function updateProgramRestriction( uint256 _minStakingAmount, uint256 _minRewardAmount ) external onlyRole(STEWARD_ROLE) { minStakingAmount = _minStakingAmount; minRewardAmount = _minRewardAmount; emit StakingRestrictionChanged(minStakingAmount, minRewardAmount); } function updateProgramTax( uint256 _taxRatioNumerator, uint256 _taxRatioDenominator ) external onlyRole(CONFIGURATION_ROLE) { require( _taxRatioNumerator * 10 <= _taxRatioDenominator, 'Tax ratio exceeds 10% cap' ); taxRatioNumerator = _taxRatioNumerator; taxRatioDenominator = _taxRatioDenominator; emit TaxConditionChanged(taxRatioNumerator, taxRatioDenominator); } function recoverERC20( IERC20 token, uint256 amount ) external nonReentrant onlyRole(STEWARD_ROLE) { require( address(token) != address(stakingToken), 'Cannot withdraw the staking token' ); require( address(token) != address(rewardToken), 'Cannot withdraw the reward token' ); uint256 tokenBalance = token.balanceOf(address(this)); require(tokenBalance >= amount, 'Not enough tokens to withdraw'); token.safeTransfer(_msgSender(), amount); emit RecoveredERC20(address(token), amount); } function pause() external onlyRole(STEWARD_ROLE) { _pause(); } function unpause() external onlyRole(STEWARD_ROLE) { _unpause(); } }
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @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://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @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, it is bubbled up by this
* function (like regular Solidity function calls).
*
* 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.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @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`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @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;
}
}
Strings.sol 70 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}
Math.sol 345 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}
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());
}
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` 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 amount
) external returns (bool);
}
AccessControl.sol 247 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../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:
*
* ```
* 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}:
*
* ```
* 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.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
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 override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `_msgSender()` is missing `role`.
* Overriding this function changes the behavior of the {onlyRole} modifier.
*
* Format of the revert message is described in {_checkRole}.
*
* _Available since v4.6._
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(account),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @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 override 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 override 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 override 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 `account`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* May emit a {RoleGranted} event.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @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 Grants `role` to `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
IAccessControl.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @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.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}
ReentrancyGuard.sol 69 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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;
}
}
ERC165.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
SafeERC20.sol 116 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
draft-IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
ERC20.sol 389 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
IERC20Metadata.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
Read Contract
CONFIGURATION_ROLE 0xb12ed45e → bytes32
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
MAGNITUDE_CONSTANT 0xa9170d81 → uint256
STEWARD_ROLE 0x64305916 → bytes32
availableRewards 0xf854a27f → uint256, uint256
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
minRewardAmount 0x12d3b8c9 → uint256
minStakingAmount 0x25c065b1 → uint256
paused 0x5c975abb → bool
programLastAccruedRewardsAt 0x8021e4a2 → uint64
programRewardLost 0x0f8cc3fd → uint256
programRewardLostWithdrawn 0xcdf24c2f → uint256
programRewardPerLiquidity 0x2876d7e4 → uint256
programRewardRemaining 0x230f2897 → uint256
programRewardsDepletionAt 0xd37e51da → uint64
programStakedLiquidity 0x06e0cf65 → uint256
programStartsAt 0xbd5c5664 → uint64
rewardToken 0xf7c618c1 → address
stakingToken 0x72f702f3 → address
supportsInterface 0x01ffc9a7 → bool
taxAccumulated 0x48928d57 → uint256
taxAccumulatedWithdrawn 0x7f91d235 → uint256
taxRatioDenominator 0x7718d1e2 → uint256
taxRatioNumerator 0x81014fe4 → uint256
users 0xa87430ba → uint256, uint256
Write Contract 17 functions
These functions modify contract state and require a wallet transaction to execute.
accrueRewardsPeriod 0xc9e721aa
No parameters
claimRewards 0x372500ab
No parameters
depositProgramRewards 0x16992873
uint256 _amount
grantRole 0x2f2ff15d
bytes32 role
address account
pause 0x8456cb59
No parameters
recoverERC20 0x8980f11f
address token
uint256 amount
renounceRole 0x36568abe
bytes32 role
address account
revokeRole 0xd547741f
bytes32 role
address account
stake 0xabe50f19
uint256 _amount
bool _claimExistingRewards
unpause 0x3f4ba83a
No parameters
updateProgramDepletionDate 0xfb9604ce
uint64 _programRewardsDepletionAt
updateProgramRestriction 0xaa817230
uint256 _minStakingAmount
uint256 _minRewardAmount
updateProgramTax 0x5992c85c
uint256 _taxRatioNumerator
uint256 _taxRatioDenominator
withdraw 0x92930b45
uint256 _amount
bool _claimExistingRewards
bool _waiveExistingRewards
withdrawProgramLostRewards 0xa7285176
uint256 _amount
withdrawProgramRewards 0xc4b8d27d
uint256 _amount
withdrawProgramTaxes 0xa7c8a9e6
uint256 _amount
Recent Transactions
No transactions found for this address