Address Contract Verified
Address
0x91bbD489ab2191dECa3B41551a205e39fa29B459
Balance
0 ETH
Nonce
1
Code Size
16225 bytes
Creator
0xdda5A944...4c88 at tx 0x1de85a9b...8aef3d
Indexed Transactions
0
Contract Bytecode
16225 bytes
0x60a0806040526004361015610012575f80fd5b5f6080525f3560e01c90816301ffc9a714612c735750806303d9d4ec14612c6057806314336e1c14612858578063170bd03d1461281c5780631b73183d146127c45780631f24b0371461278057806323886383146126ee578063248a9ca31461269f57806328c223391461261e5780632f2ff15d1461251f57806336568abe1461243b5780633659cfe6146121b9578063373f2ff414611d6657806338368eb814611d285780634250644914611cad5780634f1ef28614611920578063526282ad146118e557806352d1902d146117ca5780635af608d3146116075780636ed130db146115c357806373db51be1461159657806377e5441514611405578063808ed15d14611354578063809f71d01461131257806390896eea14610cbf57806391d1485414610c465780639693231d14610bf9578063a217fddf14610bbd578063ab9068fa14610b7a578063b1a0928914610b3c578063be9a655514610afe578063c2b40ae414610aa8578063c891091314610a3b578063ce0a2022146109bb578063d3095d4a1461089f578063d547741f1461083a578063d54ad2a1146107fc578063d89135cd146107be578063dae404a014610502578063dc42286b14610484578063e8169c51146103f8578063eaddb9c6146103a4578063edfc3fe814610350578063f005625f1461030c578063f5f881d5146102c9578063f6a03ebf146102855763f72c0d8b14610225575f80fd5b3461027f576080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f5760206040517f189ab7a9244df0848122154315af71fe140f3db0fe014031783b0946b8c9d2e38152f35b60805180fd5b3461027f5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f576102bc6135c9565b60043561012e5560805180f35b3461027f576080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f576020604051683627e8f712373c00008152f35b3461027f5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f576020610348600435613524565b604051908152f35b3461027f5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57602061039a61038c612d2f565b610394612d85565b906134c0565b6040519015158152f35b3461027f576080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57602073ffffffffffffffffffffffffffffffffffffffff61012d5416604051908152f35b3461027f5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f5760ff610431612d75565b166080515261013260205260406080512060ff81541661048060018301549260036002820154910154906040519485948590949392606092608083019615158352602083015260408201520152565b0390f35b3461027f5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f576104bb6135c9565b6104c6600435612f39565b81549060031b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff602435831b921b1916179055608051608051f35b3461027f5760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f5767ffffffffffffffff60043581811161027f57610552903690600401612df4565b919060243582811161027f5761056c903690600401612df4565b91909260443590811161027f57610587903690600401612df4565b9390926105926135c9565b6080515b8681106105a35760805180f35b8073ffffffffffffffffffffffffffffffffffffffff6105ce6105c96001948b89613464565b613474565b166080515261013160205260ff604060805120541615610688575b6106826105ff6105fa838a8a613464565b6134b3565b73ffffffffffffffffffffffffffffffffffffffff6106226105c9858d8b613464565b166080515261013360205260406080512060ff61064861064386898b613464565b6134a5565b165f5260205260405f209060ff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0083541691151516179055565b01610596565b60ff610698610643838688613464565b166080515261013260205260406080512073ffffffffffffffffffffffffffffffffffffffff6106cc6105c9848c8a613464565b166080515261013360205260406080512060ff6106ed61064385888a613464565b165f5260205260405f2090808203610763575b505073ffffffffffffffffffffffffffffffffffffffff6107256105c9838b89613464565b1660805152610131602052604060805120827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008254161790556105e9565b61079c60ff825416839060ff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0083541691151516179055565b8084015482850155600280820154908301556003908101549101558880610700565b3461027f576080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57602061013654604051908152f35b3461027f576080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57602061013554604051908152f35b3461027f5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57610899600435610877612d52565b90806080515260c960205261089460016040608051200154613959565b613a8c565b60805180f35b3461027f5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f5767ffffffffffffffff60043581811161027f576108ef903690600401612df4565b9160243590811161027f57610908903690600401612df4565b6109139291926135c9565b80840361095d576080515b84811061092b5760805180f35b806109396001928487613464565b35610945828887613464565b3560805152610134602052604060805120550161091e565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f496e76616c6964206c656e0000000000000000000000000000000000000000006044820152fd5b3461027f5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f576109f2612d75565b73ffffffffffffffffffffffffffffffffffffffff610a0f612d52565b166080515261013160205260ff60016040608051200191165f52602052602060405f2054604051908152f35b3461027f5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f5773ffffffffffffffffffffffffffffffffffffffff610a87612d2f565b1660805152610131602052602060ff60406080512054166040519015158152f35b3461027f5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f5760043561012f5481101561027f57610af0602091612f39565b90546040519160031b1c8152f35b3461027f576080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57602061012e54604051908152f35b3461027f576080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57602061013754604051908152f35b3461027f576080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57602060ff61013054166040519015158152f35b3461027f576080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f5760206040516080518152f35b3461027f5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f5760043560805152610134602052602060406080512054604051908152f35b3461027f5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57610c7d612d52565b6004356080515260c960205273ffffffffffffffffffffffffffffffffffffffff60406080512091165f52602052602060ff60405f2054166040519015158152f35b3461027f5760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f5760043567ffffffffffffffff811161027f57610d0e903690600401612df4565b9060243567ffffffffffffffff811161027f57610d2f903690600401612df4565b60449391933567ffffffffffffffff811161027f57610d52903690600401612df4565b91909260643567ffffffffffffffff811161027f57610d75903690600401612df4565b929093828214801590611308575b80156112fe575b6112d4576080515b828110610d9f5760805180f35b610dad61064382868b613464565b90610db981858c613464565b35610dc582858b613464565b35878310156112a3576005907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18a36030184831b8b0135121561027f5783821b8a01358a019167ffffffffffffffff83351161027f578235901b3603602083011361027f57600260fb541461124557600260fb5560ff610130541661121b57610e4d85612f39565b9054604080513360208201908152818301889052918152919391829190610e75606082612e8d565b519020036111f15792608051905b803582106111a957505060031b1c0361117f5782610ea1913361302c565b9182156111555733608051526101318060205260016040608051200160ff83165f5260205260405f20610ed5858254613012565b9055610ee08461317d565b91610135610eef838254613012565b9055610136610eff848254613012565b9055336080515260205260026040608051200160ff84165f5260205260405f20610f2a828254613012565b905561012d80546040517fa9059cbb000000000000000000000000000000000000000000000000000000006020820190815233602483015260448083019590955293815273ffffffffffffffffffffffffffffffffffffffff93610feb92851690610f96606484612e8d565b60405192610fa384612e39565b602084527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564602085015260805191608051915190608051855af1610fe5613e38565b91613e67565b8051908115918215611132575b5050156110ae575416803b1561027f57604051917f42966c6800000000000000000000000000000000000000000000000000000000835260048301528160248160805193608051905af180156110a15761108b575b506001926040519081527fa0749e1bd91b704a590d54652ab241875bafecdd428ab0a9b01aeb035682ad2d602060ff33941692a38160fb5501610d92565b61109490612e25565b60805161027f578b61104d565b6040513d608051823e3d90fd5b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152fd5b819250906020918101031261027f5760200151801515810361027f578f80610ff8565b60046040517f47e789c2000000000000000000000000000000000000000000000000000000008152fd5b60046040517f09bde339000000000000000000000000000000000000000000000000000000008152fd5b90936111ba85833560208501613464565b3590818110156111dc576080515260205260016040608051205b940190610e83565b906080515260205260016040608051206111d4565b60046040517f35100de8000000000000000000000000000000000000000000000000000000008152fd5b60046040517f06e81f2b000000000000000000000000000000000000000000000000000000008152fd5b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152fd5b7f4e487b71000000000000000000000000000000000000000000000000000000006080515260326004526024608051fd5b60046040517fa86b6512000000000000000000000000000000000000000000000000000000008152fd5b5083821415610d8a565b5080821415610d83565b3461027f576080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f576020604051670de0b6b3a76400008152f35b3461027f5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f5761138b612d2f565b73ffffffffffffffffffffffffffffffffffffffff6113a8612d85565b91166080515261013360205260ff60406080512091165f5260205260405f2060ff81541661048060018301549260036002820154910154906040519485948590949392606092608083019615158352602083015260408201520152565b3461027f5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f5767ffffffffffffffff60043581811161027f57611455903690600401612df4565b60249260243590811161027f57611470903690600401612f08565b909161147a6135c9565b6080515b60ff80821684811015610899576020916127108361149d84898b613495565b01351161156c57816060916114c36106436114bb6003968b8d613495565b93898d613464565b16608051526101328452604060805120936115116114e0836134b3565b869060ff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0083541691151516179055565b810135600185015560408101356002850155013591015560ff80911690811461153c5760010161147e565b857f4e487b7100000000000000000000000000000000000000000000000000000000608051526011600452608051fd5b60046040517ffe680b26000000000000000000000000000000000000000000000000000000008152fd5b3461027f5760406115b76115b26115ac36612d95565b9161302c565b61317d565b82519182526020820152f35b3461027f5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f576115fa6135c9565b6004356101375560805180f35b3461027f576060807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f5767ffffffffffffffff60043581811161027f57611658903690600401612df4565b9260243583811161027f57611671903690600401612df4565b91909360443590811161027f5761168c903690600401612f08565b9390956116976135c9565b6080515b8581106116a85760805180f35b879073ffffffffffffffffffffffffffffffffffffffff806116ce6105c9848789613464565b166080515260209061013182526127108261171b858c604060805120986001998a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00825416179055613495565b01351161156c5786866001958c60ff8f6106438f8f6003996117518f8e6105c99161174b8280986117679b613495565b9c613464565b16608051526101338b5260406080512095613464565b165f52855260405f20946117ae61177d846134b3565b879060ff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0083541691151516179055565b820135908501556040810135600285015501359101550161169b565b3461027f576080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f5773ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000091bbd489ab2191deca3b41551a205e39fa29b4591630036118615760206040517f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8152f35b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c00000000000000006064820152fd5b3461027f576080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57602061034842613524565b60407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57611952612d2f565b6024359067ffffffffffffffff821161027f573660238301121561027f57816004013561197e81612ece565b9261198c6040519485612e8d565b81845260209182850191366024838301011161027f576024829101833782608051918601015273ffffffffffffffffffffffffffffffffffffffff807f00000000000000000000000091bbd489ab2191deca3b41551a205e39fa29b45916906119f78230141561334e565b611a267f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc9282845416146133d9565b611a2e6137ea565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1615611a6657505050506108999150613c21565b84939416906040517f52d1902d0000000000000000000000000000000000000000000000000000000081528581600481865afa5f9181611c7a575b50611b2a57608486604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201527f6f6e206973206e6f7420555550530000000000000000000000000000000000006064820152fd5b03611bf657611b3883613c21565b7fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b5f80a2835115801590611bee575b611b75575b50505050610899565b5f8091611be4957f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c60405196611baa88612e55565b602788528701527f206661696c65640000000000000000000000000000000000000000000000000060408701525190845af4610fe5613e38565b5080808080611b6c565b506001611b67565b608484604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f7860448201527f6961626c655555494400000000000000000000000000000000000000000000006064820152fd5b9091508681813d8311611ca6575b611c928183612e8d565b81010312611ca257519088611aa1565b5f80fd5b503d611c88565b3461027f5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57600435801515809103611ca257611cf16135c9565b6101309060ff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008354169116179055608051608051f35b3461027f576080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57602061013854604051908152f35b3461027f5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57611d9d612d2f565b67ffffffffffffffff9060243582811161027f57611dbf903690600401612df4565b608092919251549260ff94858560081c1615938480956121ad575b8015612197575b15612113576001967fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0096868989831617608051556120e2575b50611e47816080515460081c16611e3081613b2b565b611e3981613b2b565b611e4281613b2b565b613b2b565b60fb889055335f9081527f81fe90a866a48a634a12852c1be675b683a22307409932a7443b8029347be756602090815260409091205490979082161561209a575b7f189ab7a9244df0848122154315af71fe140f3db0fe014031783b0946b8c9d2e391825f5260c9895260405f20335f52895260405f2054161561204f575b505073ffffffffffffffffffffffffffffffffffffffff61012d91167fffffffffffffffffffffffff0000000000000000000000000000000000000000825416179055821161201e5768010000000000000000821161201e5761012f908154838355808410611fdc575b509060805152846080515b838110611faa5750505050611f505760805180f35b7f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff608051541660805155604051908152a18080610899565b858335930192817f232da9e50dad2971456a78fb5cd6ff6b75019984d6e918139ce990999420f9790155018590611f3b565b86847f232da9e50dad2971456a78fb5cd6ff6b75019984d6e918139ce990999420f97992830192015b828110612013575050611f30565b5f8155018790612005565b7f4e487b71000000000000000000000000000000000000000000000000000000006080515260416004526024608051fd5b815f5260c9885260405f20335f5288528860405f2091825416179055339033907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d5f80a48780611ec6565b5f805260c9885260405f20335f52885260405f20898282541617905533335f7f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d8180a4611e88565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00006101019116176080515588611e1a565b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a65640000000000000000000000000000000000006064820152fd5b50303b158015611de15750600187871614611de1565b50600187871610611dda565b3461027f576020807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f576121f1612d2f565b73ffffffffffffffffffffffffffffffffffffffff91827f00000000000000000000000091bbd489ab2191deca3b41551a205e39fa29b45916926122378430141561334e565b6122667f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc9482865416146133d9565b61226e6137ea565b604051938285019185831067ffffffffffffffff84111761240e5782604052608051865260ff7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd914354165f146122cb57505050506108999150613c21565b84939416906040517f52d1902d0000000000000000000000000000000000000000000000000000000081528581600481865afa5f91816123df575b5061238f57608486604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201527f6f6e206973206e6f7420555550530000000000000000000000000000000000006064820152fd5b03611bf65761239d83613c21565b7fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b5f80a28351158015906123d857611b755750505050610899565b505f611b67565b9091508681813d8311612407575b6123f78183612e8d565b81010312611ca257519088612306565b503d6123ed565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b3461027f5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57612472612d52565b3373ffffffffffffffffffffffffffffffffffffffff82160361249b5761089990600435613a8c565b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c6600000000000000000000000000000000006064820152fd5b3461027f5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57600435612559612d52565b816080515260c960205261257560016040608051200154613959565b815f5260c960205273ffffffffffffffffffffffffffffffffffffffff60405f20911690815f5260205260ff60405f205416156125b25760805180f35b815f5260c960205260405f20815f5260205260405f2060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0082541617905533917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d5f80a48080610899565b3461027f5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57612655612d2f565b73ffffffffffffffffffffffffffffffffffffffff612672612d85565b91166080515261013160205260ff60026040608051200191165f52602052602060405f2054604051908152f35b3461027f5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f576004356080515260c9602052602060016040608051200154604051908152f35b3461027f5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f57612725612d75565b6024358015158103611ca25760ff6108999261273f6135c9565b16608051526101326020526040608051209060ff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0083541691151516179055565b3461027f5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f576127b76135c9565b6004356101385560805180f35b3461027f5760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f576127fb612d2f565b60443560ff81168103611ca2576020916103489160643591602435906131cd565b3461027f5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261027f5760406115b760043561317d565b34611ca25760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112611ca25761288f612d75565b6044359060243560643567ffffffffffffffff8111611ca2576128b6903690600401612df4565b600260fb939293541461124557600260fb5560ff610130541661121b576128dc84612f39565b9054906040519460209780898801886129198933846020909392919373ffffffffffffffffffffffffffffffffffffffff60408201951681520152565b039861294b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09a8b8101835282612e8d565b519020036111f15793905f915b808310612c245750505060031b1c0361117f5782612976913361302c565b92831561115557335f526101319182825260ff600160405f2001941693845f52825260405f206129a7868254613012565b90556129b28561317d565b936101356129c1838254613012565b90556101366129d1868254613012565b9055335f528352600260405f2001855f52835260405f206129f3828254613012565b9055612ac773ffffffffffffffffffffffffffffffffffffffff9261012d925f808686541692612a846040519586612a788c8201947fa9059cbb00000000000000000000000000000000000000000000000000000000865233602484016020909392919373ffffffffffffffffffffffffffffffffffffffff60408201951681520152565b03908101875286612e8d565b60405194612a9186612e39565b8986527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648a870152519082855af1610fe5613e38565b8051848115918215612c04575b5050905015612b8057541691823b15611ca2575f926024849260405195869384927f42966c6800000000000000000000000000000000000000000000000000000000845260048401525af1918215612b75577fa0749e1bd91b704a590d54652ab241875bafecdd428ab0a9b01aeb035682ad2d92612b62575b506040519384523393a3600160fb5560805180f35b612b6b90612e25565b5f60805284612b4d565b6040513d5f823e3d90fd5b608483604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152fd5b8380929350010312611ca2578301518015158103611ca257808489612ad4565b909194612c32868385613464565b359081811015612c50575f528952600160405f205b95019190612958565b905f528952600160405f20612c47565b34611ca25760206103486115ac36612d95565b34611ca25760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112611ca257600435907fffffffff000000000000000000000000000000000000000000000000000000008216809203611ca257817f7965db0b0000000000000000000000000000000000000000000000000000000060209314908115612d05575b5015158152f35b7f01ffc9a70000000000000000000000000000000000000000000000000000000091501483612cfe565b6004359073ffffffffffffffffffffffffffffffffffffffff82168203611ca257565b6024359073ffffffffffffffffffffffffffffffffffffffff82168203611ca257565b6004359060ff82168203611ca257565b6024359060ff82168203611ca257565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc6060910112611ca25760043573ffffffffffffffffffffffffffffffffffffffff81168103611ca257906024359060443560ff81168103611ca25790565b9181601f84011215611ca25782359167ffffffffffffffff8311611ca2576020808501948460051b010111611ca257565b67ffffffffffffffff811161240e57604052565b6040810190811067ffffffffffffffff82111761240e57604052565b6060810190811067ffffffffffffffff82111761240e57604052565b6080810190811067ffffffffffffffff82111761240e57604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761240e57604052565b67ffffffffffffffff811161240e57601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b9181601f84011215611ca25782359167ffffffffffffffff8311611ca2576020808501948460071b010111611ca257565b61012f8054821015612f6e575f527f232da9e50dad2971456a78fb5cd6ff6b75019984d6e918139ce990999420f97901905f90565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b81810292918115918404141715612fae57565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b8115612fe5570490565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b91908201809211612fae57565b91908203918211612fae57565b909161012e54918242106131755773ffffffffffffffffffffffffffffffffffffffff1690815f5261013160209080825260409360ff855f205416155f1461315c5760ff84165f526101328352845f20965b60ff885416613150576130a861271061309b60018b015484612f9b565b049760028a015490613012565b6201518090818101808211612fae5742116130e3575b5050506130e096505f52815260ff6001845f200192165f52525f20549061301f565b90565b816130fb6130f48b86979c9661301f565b924261301f565b04828102928184041490151715612fae5760036130e09a0154938483105f146131455750926131306131359261313b95612f9b565b612fdb565b90613012565b945b5f80806130be565b93505050509461313d565b50505050505050505f90565b6101338352845f2060ff85165f528352845f209661307e565b505050505f90565b9061318742613524565b670de0b6b3a7640000908161319c8286612f9b565b049361013754683627e8f712373c0000908101809111612fae576131c9926131c39161301f565b90612f9b565b0490565b929161012e54938484106133455773ffffffffffffffffffffffffffffffffffffffff16805f5261013160209181835260409460ff865f205416155f1461332d5760ff85165f526101328452855f205b60ff8154166133205761324761271061323a600184015485612f9b565b0499600283015490613012565b906201518092838301808411612fae578a1161329b575b50505050936131c39361329593670de0b6b3a764000098936131c998975f52815260ff6001845f200192165f52525f20549061301f565b91613524565b836132ba6132b38d849d9c9899959a969b979d61301f565b998b61301f565b048a81029a818c041490151715612fae57670de0b6b3a76400009a6131c99a6131c39960036132959a0154938483105f146133155750926131306131359261330195612f9b565b945b93979881959a5083975082965061325e565b935050505094613303565b5050505050505050505f90565b6101338452855f2060ff86165f528452855f2061321d565b50505050505f90565b1561335557565b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201527f64656c656761746563616c6c00000000000000000000000000000000000000006064820152fd5b156133e057565b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201527f6163746976652070726f787900000000000000000000000000000000000000006064820152fd5b9190811015612f6e5760051b0190565b3573ffffffffffffffffffffffffffffffffffffffff81168103611ca25790565b9190811015612f6e5760071b0190565b3560ff81168103611ca25790565b358015158103611ca25790565b73ffffffffffffffffffffffffffffffffffffffff16805f5261013160205260ff60405f2054165f1461350d575f5261013360205260ff60405f2091165f5260205260ff60405f20541690565b5060ff165f5261013260205260ff60405f20541690565b610138549081811161353e575050670de0b6b3a764000090565b620151809161354c9161301f565b048061355f5750670de0b6b3a764000090565b605b8111156135af575061013754683627e8f712373c0000908101809111156130e0577f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f526101346020526130e060405f20546101375490613012565b335f9081527f81fe90a866a48a634a12852c1be675b683a22307409932a7443b8029347be75660209081526040918290205460ff1615613607575050565b61361033613d1e565b82515f9161361d82612e71565b60428252838201926060368537825115612f6e5760308453825160019060011015612f6e57607860218501536041905b80821161377b57505061371f576136a79385936136eb936136dc60489461371b995198857f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008b978801528251928391603789019101613bb6565b8401917f206973206d697373696e6720726f6c6520000000000000000000000000000000603784015251809386840190613bb6565b01036028810185520183612e8d565b519182917f08c379a000000000000000000000000000000000000000000000000000000000835260048301613bd7565b0390fd5b6064848651907f08c379a000000000000000000000000000000000000000000000000000000000825280600483015260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152fd5b9091600f81166010811015612f6e577f3031323334353637383961626364656600000000000000000000000000000000901a6137b78487613d0d565b5360041c918015612fae577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff019061364d565b335f9081527f5bd066a11de3c39d5a00651506dcc7d8e5d6a879bde036d3aa74ff1af7e954956020908152604091829020547f189ab7a9244df0848122154315af71fe140f3db0fe014031783b0946b8c9d2e39060ff161561384b57505050565b61385433613d1e565b83519061386082612e71565b60428252838201926060368537825115612f6e5760308453825160019060011015612f6e57607860218501536041905b8082116138ea57505061371f576136a79385936136eb936136dc60489461371b995198857f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008b978801528251928391603789019101613bb6565b9091600f81166010811015612f6e577f3031323334353637383961626364656600000000000000000000000000000000901a6139268487613d0d565b5360041c918015612fae577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190613890565b805f52602060c98152604091825f20335f52825260ff835f2054161561397e57505050565b61398733613d1e565b83519061399382612e71565b60428252838201926060368537825115612f6e5760308453825160019060011015612f6e57607860218501536041905b808211613a1d57505061371f576136a79385936136eb936136dc60489461371b995198857f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008b978801528251928391603789019101613bb6565b9091600f81166010811015612f6e577f3031323334353637383961626364656600000000000000000000000000000000901a613a598487613d0d565b5360041c918015612fae577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01906139c3565b90815f5260c960205273ffffffffffffffffffffffffffffffffffffffff60405f20911690815f5260205260ff60405f205416613ac7575050565b815f5260c960205260405f20815f5260205260405f207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00815416905533917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b5f80a4565b15613b3257565b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152fd5b5f5b838110613bc75750505f910152565b8181015183820152602001613bb8565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f60409360208452613c1a8151809281602088015260208888019101613bb6565b0116010190565b803b15613c895773ffffffffffffffffffffffffffffffffffffffff7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc91167fffffffffffffffffffffffff0000000000000000000000000000000000000000825416179055565b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201527f6f74206120636f6e7472616374000000000000000000000000000000000000006064820152fd5b908151811015612f6e570160200190565b60405190613d2b82612e55565b602a8252602082016040368237825115612f6e5760309053815160019060011015612f6e57607860218401536029905b808211613dc9575050613d6b5790565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602060248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152fd5b9091600f81166010811015612f6e577f3031323334353637383961626364656600000000000000000000000000000000901a613e058486613d0d565b5360041c918015612fae577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190613d5b565b3d15613e62573d90613e4982612ece565b91613e576040519384612e8d565b82523d5f602084013e565b606090565b91929015613ee25750815115613e7b575090565b3b15613e845790565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152fd5b825190915015613ef55750805190602001fd5b61371b906040519182917f08c379a000000000000000000000000000000000000000000000000000000000835260048301613bd756fea2646970667358221220608d288fdb4ea59c6bfe9bd7253252d391b7bef77d04d8fae8f64c0d52a6f3ab64736f6c63430008160033
Verified Source Code Full Match
Compiler: v0.8.22+commit.4fc1097e
EVM: shanghai
Optimization: Yes (99999 runs)
AccessControlUpgradeable.sol 261 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControlUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../utils/StringsUpgradeable.sol";
import "../utils/introspection/ERC165Upgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {
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);
_;
}
function __AccessControl_init() internal onlyInitializing {
}
function __AccessControl_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlUpgradeable).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 ",
StringsUpgradeable.toHexString(account),
" is missing role ",
StringsUpgradeable.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());
}
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
IAccessControlUpgradeable.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 IAccessControlUpgradeable {
/**
* @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;
}
IERC1967Upgradeable.sol 26 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC1967.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
*
* _Available since v4.8.3._
*/
interface IERC1967Upgradeable {
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Emitted when the beacon is changed.
*/
event BeaconUpgraded(address indexed beacon);
}
draft-IERC1822Upgradeable.sol 20 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822ProxiableUpgradeable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}
ERC1967UpgradeUpgradeable.sol 170 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/ERC1967/ERC1967Upgrade.sol)
pragma solidity ^0.8.2;
import "../beacon/IBeaconUpgradeable.sol";
import "../../interfaces/IERC1967Upgradeable.sol";
import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../../utils/AddressUpgradeable.sol";
import "../../utils/StorageSlotUpgradeable.sol";
import {Initializable} from "../utils/Initializable.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*
* _Available since v4.1._
*/
abstract contract ERC1967UpgradeUpgradeable is Initializable, IERC1967Upgradeable {
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
function __ERC1967Upgrade_init() internal onlyInitializing {
}
function __ERC1967Upgrade_init_unchained() internal onlyInitializing {
}
/**
* @dev Returns the current implementation address.
*/
function _getImplementation() internal view returns (address) {
return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract");
StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Perform implementation upgrade
*
* Emits an {Upgraded} event.
*/
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
/**
* @dev Perform implementation upgrade with additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {
_upgradeTo(newImplementation);
if (data.length > 0 || forceCall) {
AddressUpgradeable.functionDelegateCall(newImplementation, data);
}
}
/**
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal {
// Upgrades from old implementations will perform a rollback test. This test requires the new
// implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
// this special case will break upgrade paths from old UUPS implementation to new ones.
if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) {
_setImplementation(newImplementation);
} else {
try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) {
require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
} catch {
revert("ERC1967Upgrade: new implementation is not UUPS");
}
_upgradeToAndCall(newImplementation, data, forceCall);
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*/
function _getAdmin() internal view returns (address) {
return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
require(newAdmin != address(0), "ERC1967: new admin is the zero address");
StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {AdminChanged} event.
*/
function _changeAdmin(address newAdmin) internal {
emit AdminChanged(_getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
*/
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function _getBeacon() internal view returns (address) {
return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract");
require(
AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()),
"ERC1967: beacon implementation is not a contract"
);
StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon;
}
/**
* @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
* not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
*
* Emits a {BeaconUpgraded} event.
*/
function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) {
AddressUpgradeable.functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data);
}
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}
IBeaconUpgradeable.sol 16 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.0;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeaconUpgradeable {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {BeaconProxy} will check that this address is a contract.
*/
function implementation() external view returns (address);
}
Initializable.sol 166 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}
UUPSUpgradeable.sol 112 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.0;
import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../ERC1967/ERC1967UpgradeUpgradeable.sol";
import {Initializable} from "./Initializable.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*
* _Available since v4.1._
*/
abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
address private immutable __self = address(this);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
require(address(this) != __self, "Function must be called through delegatecall");
require(_getImplementation() == __self, "Function must be called through active proxy");
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");
_;
}
function __UUPSUpgradeable_init() internal onlyInitializing {
}
function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
}
/**
* @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate the implementation's compatibility when performing an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual override notDelegated returns (bytes32) {
return _IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeTo(address newImplementation) public virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data, true);
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeTo} and {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal override onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}
ReentrancyGuardUpgradeable.sol 89 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @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 ReentrancyGuardUpgradeable is Initializable {
// 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;
function __ReentrancyGuard_init() internal onlyInitializing {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal onlyInitializing {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
AddressUpgradeable.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @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
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [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://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/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);
}
}
}
ContextUpgradeable.sol 41 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @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 ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}
StorageSlotUpgradeable.sol 138 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._
* _Available since v4.9 for `string`, `bytes`._
*/
library StorageSlotUpgradeable {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}
StringsUpgradeable.sol 85 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/MathUpgradeable.sol";
import "./math/SignedMathUpgradeable.sol";
/**
* @dev String operations.
*/
library StringsUpgradeable {
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 = MathUpgradeable.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 `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMathUpgradeable.abs(value))));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, MathUpgradeable.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);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}
ERC165Upgradeable.sol 42 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165Upgradeable.sol";
import {Initializable} from "../../proxy/utils/Initializable.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 ERC165Upgradeable is Initializable, IERC165Upgradeable {
function __ERC165_init() internal onlyInitializing {
}
function __ERC165_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165Upgradeable).interfaceId;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}
IERC165Upgradeable.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 IERC165Upgradeable {
/**
* @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);
}
MathUpgradeable.sol 339 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library MathUpgradeable {
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) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 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 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}
SignedMathUpgradeable.sol 43 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMathUpgradeable {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}
IERC20.sol 78 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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);
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/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.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
SafeERC20.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/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;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.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));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
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");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
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");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation 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).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [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://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/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);
}
}
}
MerkleProof.sol 227 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.2) (utils/cryptography/MerkleProof.sol)
pragma solidity ^0.8.0;
/**
* @dev These functions deal with verification of Merkle Tree proofs.
*
* The tree and the proofs can be generated using our
* https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
* You will find a quickstart guide in the readme.
*
* WARNING: You should avoid using leaf values that are 64 bytes long prior to
* hashing, or use a hash function other than keccak256 for hashing leaves.
* This is because the concatenation of a sorted pair of internal nodes in
* the merkle tree could be reinterpreted as a leaf value.
* OpenZeppelin's JavaScript library generates merkle trees that are safe
* against this attack out of the box.
*/
library MerkleProof {
/**
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
* defined by `root`. For this, a `proof` must be provided, containing
* sibling hashes on the branch from the leaf to the root of the tree. Each
* pair of leaves and each pair of pre-images are assumed to be sorted.
*/
function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
return processProof(proof, leaf) == root;
}
/**
* @dev Calldata version of {verify}
*
* _Available since v4.7._
*/
function verifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
return processProofCalldata(proof, leaf) == root;
}
/**
* @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
* from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
* hash matches the root of the tree. When processing the proof, the pairs
* of leafs & pre-images are assumed to be sorted.
*
* _Available since v4.4._
*/
function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
/**
* @dev Calldata version of {processProof}
*
* _Available since v4.7._
*/
function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
/**
* @dev Returns true if the `leaves` can be simultaneously proven to be a part of a merkle tree defined by
* `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
*
* CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
*
* _Available since v4.7._
*/
function multiProofVerify(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProof(proof, proofFlags, leaves) == root;
}
/**
* @dev Calldata version of {multiProofVerify}
*
* CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
*
* _Available since v4.7._
*/
function multiProofVerifyCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProofCalldata(proof, proofFlags, leaves) == root;
}
/**
* @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
* proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
* leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
* respectively.
*
* CAUTION: Not all merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
*
* _Available since v4.7._
*/
function processMultiProof(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
// This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
// `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
// the merkle tree.
uint256 leavesLen = leaves.length;
uint256 proofLen = proof.length;
uint256 totalHashes = proofFlags.length;
// Check proof validity.
require(leavesLen + proofLen - 1 == totalHashes, "MerkleProof: invalid multiproof");
// The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
// `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
bytes32[] memory hashes = new bytes32[](totalHashes);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
// At each step, we compute the next hash using two values:
// - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
// get the next hash.
// - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
// `proof` array.
for (uint256 i = 0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i]
? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
: proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes > 0) {
require(proofPos == proofLen, "MerkleProof: invalid multiproof");
unchecked {
return hashes[totalHashes - 1];
}
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
/**
* @dev Calldata version of {processMultiProof}.
*
* CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
*
* _Available since v4.7._
*/
function processMultiProofCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
// This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
// `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
// the merkle tree.
uint256 leavesLen = leaves.length;
uint256 proofLen = proof.length;
uint256 totalHashes = proofFlags.length;
// Check proof validity.
require(leavesLen + proofLen - 1 == totalHashes, "MerkleProof: invalid multiproof");
// The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
// `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
bytes32[] memory hashes = new bytes32[](totalHashes);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
// At each step, we compute the next hash using two values:
// - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
// get the next hash.
// - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
// `proof` array.
for (uint256 i = 0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i]
? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
: proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes > 0) {
require(proofPos == proofLen, "MerkleProof: invalid multiproof");
unchecked {
return hashes[totalHashes - 1];
}
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {
return a < b ? _efficientHash(a, b) : _efficientHash(b, a);
}
function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, a)
mstore(0x20, b)
value := keccak256(0x00, 0x40)
}
}
}
MerklePass.sol 30 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import { MerkleProof } from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
library MerklePass {
error InvalidLeaf();
function isValid(
bytes32[] calldata proof,
bytes32 leaf,
bytes32 root,
uint256 amount
) internal view returns (bool) {
verifyLeaf(msg.sender, amount, leaf);
return MerkleProof.verifyCalldata(proof, root, leaf);
}
// check that amount passed is the same as amount was generated
function verifyLeaf(
address user,
uint256 amount,
bytes32 leaf
) private pure {
bytes32 _hash = keccak256(abi.encode(user, amount));
if (_hash != leaf) {
revert InvalidLeaf();
}
}
}
Vesting_V2.sol 459 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Burnable} from "./interfaces/IERC20Burnable.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {MerklePass} from "./MerklePass.sol";
/**
* @title Vesting contract for Entangle Token $NGL
*/
contract Vesting_V2 is
Initializable,
UUPSUpgradeable,
AccessControlUpgradeable,
ReentrancyGuardUpgradeable
{
using SafeERC20 for IERC20;
// =========================================
// ERRORS AND EVENTS
// =========================================
error ClaimingBlocked();
error InvalidProof();
error InvalidStart();
error ClaimingClosed();
error ZeroClaim();
error InvalidParams();
error InvalidConfigData();
event Claimed(uint8 indexed bucketId, address indexed user, uint256 amount);
// =========================================
// STORAGE
// =========================================
bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");
uint256 public constant CURVE_MAX = 999e18;
uint256 public constant MUL_DENOM = 1e18;
IERC20 public ngl;
uint256 public start;
bytes32[] public roots;
bool public circuitBreakerEnabled;
struct Config {
bool claimingBlocked;
uint256 tgePercent;
uint256 cliff;
uint256 vestingDuration;
}
struct UserData {
bool configSet;
mapping(uint8 => uint256) claimed;
mapping(uint8 => uint256) multipliedClaimedAmount;
}
mapping(address user => UserData) public userData;
mapping(uint8 id => Config) public buckets;
mapping(address user => mapping(uint8 bucket => Config)) public personalConfigs;
/* Updated */
mapping(uint256 day => uint256 multiplier) public mulTable;
/// @dev Stats moved down for old vesting compatibility
uint256 public totalClaimed;
uint256 public totalBurned;
/// @dev multiplier delta that is used for diferrent proxy-contracts
uint256 public mulDelta;
uint256 public curveStart;
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
function initialize(
address _ngl,
bytes32[] calldata _roots
) public initializer {
__AccessControl_init();
__UUPSUpgradeable_init();
__ReentrancyGuard_init();
_grantRole(DEFAULT_ADMIN_ROLE, _msgSender());
_grantRole(UPGRADER_ROLE, _msgSender());
ngl = IERC20(_ngl);
roots = _roots;
}
/**
* @notice claim tokens during the vesting from different buckets
* @param bucketIds bucket ids
* @param amountListed whole amount of user in diff buckets
* @param leafs user leafs
* @param proofs merkle proofs
*/
function claimBatch(
uint8[] calldata bucketIds,
uint256[] calldata amountListed,
bytes32[] calldata leafs,
bytes32[][] calldata proofs
) external {
uint256 len = amountListed.length;
if (len != bucketIds.length || len != leafs.length || len != proofs.length) {
revert InvalidParams();
}
for (uint256 i = 0; i < len; i++) {
claim(bucketIds[i], amountListed[i], leafs[i], proofs[i]);
}
}
/**
* @notice claim tokens during the vesting
* @dev start shifted with cliff
* @param bucketId bucket id
* @param amountListed whole amount of user
* @param leaf user leaf
* @param proof merkle proof
*/
function claim(
uint8 bucketId,
uint256 amountListed,
bytes32 leaf,
bytes32[] calldata proof
)
public
nonReentrant
{
if (circuitBreakerEnabled) {
revert ClaimingBlocked();
}
bool treeStatus = MerklePass.isValid(proof, leaf, roots[bucketId], amountListed);
if (!treeStatus) {
revert InvalidProof();
}
uint256 availableAmount = getAvailableAmount(_msgSender(), amountListed, bucketId);
if (availableAmount == 0) {
revert ZeroClaim();
}
userData[_msgSender()].claimed[bucketId] += availableAmount;
(uint256 toTransfer, uint256 toBurn) = getFinalAmounts(availableAmount);
totalClaimed += toTransfer;
totalBurned += toBurn;
userData[_msgSender()].multipliedClaimedAmount[bucketId] += toTransfer;
ngl.safeTransfer(_msgSender(), toTransfer);
IERC20Burnable(address(ngl)).burn(toBurn);
emit Claimed(bucketId, _msgSender(), availableAmount);
}
// =========================================
// GETTERS
// =========================================
function getMaxAvailableAmount(
address user,
uint256 amountListed,
uint8 bucketId,
uint256 timestamp
) external view returns(uint256 toGive) {
if (timestamp < start) {
return 0;
}
Config storage cfg;
if (!userData[user].configSet) {
cfg = buckets[bucketId];
} else {
cfg = personalConfigs[user][bucketId];
}
if (cfg.claimingBlocked) {
return 0;
}
uint256 result = (amountListed * cfg.tgePercent) / 10000;
uint256 vestStart = start + cfg.cliff;
if (timestamp > vestStart + 1 days) {
uint256 availableForVesting = amountListed - result;
uint256 vestingPeriodToClaim = ((timestamp - vestStart) / 1 days) * 1 days;
if (vestingPeriodToClaim < cfg.vestingDuration) {
result += (availableForVesting * vestingPeriodToClaim) / cfg.vestingDuration;
} else {
result = amountListed;
}
}
result -= userData[user].claimed[bucketId];
return result * getCurveMultiplier(timestamp) / MUL_DENOM;
}
/**
* @notice Function for getting available amount
* @dev should be used on FE also
* @param user user wallet address
* @param amountListed amount listed for vesting
* @param bucketId bucketId
*/
function getAvailableAmount(address user, uint256 amountListed, uint8 bucketId) public view returns (uint256 result) {
if (block.timestamp < start) {
return 0;
}
Config storage cfg;
if (!userData[user].configSet) {
cfg = buckets[bucketId];
} else {
cfg = personalConfigs[user][bucketId];
}
if (cfg.claimingBlocked) {
return 0;
}
result = (amountListed * cfg.tgePercent) / 10000;
uint256 vestStart = start + cfg.cliff;
if (block.timestamp > vestStart + 1 days) {
uint256 availableForVesting = amountListed - result;
uint256 vestingPeriodToClaim = ((block.timestamp - vestStart) / 1 days) * 1 days;
if (vestingPeriodToClaim < cfg.vestingDuration) {
result += (availableForVesting * vestingPeriodToClaim) / cfg.vestingDuration;
} else {
result = amountListed;
}
}
result -= userData[user].claimed[bucketId];
}
function multipliedClaimed(address user, uint8 bucketId) external view returns(uint256) {
return userData[user].multipliedClaimedAmount[bucketId];
}
/**
* @notice Function for getting amount claimed from bucket
* @param bucketId bucket id
* @param user user wallet address
*/
function getUserClaimFromBucket(
uint8 bucketId,
address user
) external view returns (uint256 claimed) {
claimed = userData[user].claimed[bucketId];
}
/**
* @notice Function for checking if claim is blocked
* @param user user wallet address
* @param bucketId bucket id
*/
function isBlocked(address user, uint8 bucketId) external view returns (bool) {
if (userData[user].configSet) {
return personalConfigs[user][bucketId].claimingBlocked;
} else {
return buckets[bucketId].claimingBlocked;
}
}
function getFinalAvailable(
address user,
uint256 amountListed,
uint8 bucketId
) public view returns(uint256, uint256) {
uint256 orig = getAvailableAmount(user, amountListed, bucketId);
(uint256 toGive, uint256 toBurn) = getFinalAmounts(orig);
return (toGive, toBurn);
}
function getFinalAmounts(
uint256 original
) public view returns (uint256, uint256) {
uint256 mul = getCurveMultiplier(block.timestamp);
uint256 toGive = original * mul / MUL_DENOM;
uint256 toBurn = original * (CURVE_MAX + mulDelta - mul) / MUL_DENOM;
return (toGive, toBurn);
}
function getCurveMultiplierNow() public view returns(uint256) {
return getCurveMultiplier(block.timestamp);
}
function getCurveMultiplier(uint256 time) public view returns (uint256) {
uint256 mul;
if (time <= curveStart) {
mul = MUL_DENOM;
} else {
uint256 daysGone = (time - curveStart) / 1 days;
if (daysGone == 0) mul = MUL_DENOM;
else if (daysGone > 91) mul = CURVE_MAX + mulDelta;
else mul = mulTable[daysGone] + mulDelta;
}
return mul;
}
// =========================================
// ADMIN
// =========================================
/**
* @notice Sets start time
* @dev start can be moved beforehand based on tge
* @param _newStart start time of vesting period
*/
function setStart(
uint256 _newStart
) external onlyRole(DEFAULT_ADMIN_ROLE) {
start = _newStart;
}
function setCurveStart(uint256 newCurveStart) external onlyRole(DEFAULT_ADMIN_ROLE) {
curveStart = newCurveStart;
}
/**
* @notice Stops claiming for users
* @param users array of users
* @param bucketIds array of bucket ids
* @param statuses array of statuses
*/
function setClaimingBlockedUsers(
address[] calldata users,
uint8[] calldata bucketIds,
bool[] calldata statuses
) external onlyRole(DEFAULT_ADMIN_ROLE) {
uint256 len = users.length;
for (uint256 i = 0; i < len; i++) {
if (!userData[users[i]].configSet) {
personalConfigs[users[i]][bucketIds[i]] = buckets[bucketIds[i]];
userData[users[i]].configSet = true;
}
personalConfigs[users[i]][bucketIds[i]].claimingBlocked = statuses[i];
}
}
/**
* @notice Stops claiming for all those with bucket config
* @param bucketId bucket id
* @param status status
*/
function setClaimingBlockedBucket(
uint8 bucketId,
bool status
) external onlyRole(DEFAULT_ADMIN_ROLE) {
buckets[bucketId].claimingBlocked = status;
}
/**
* @notice Set buckets
* @param bucketIds array of bucket ids
* @param configs array of configs for bucket
*/
function addBucketConfigs(
uint8[] calldata bucketIds,
Config[] calldata configs
) external onlyRole(DEFAULT_ADMIN_ROLE) {
uint256 len = configs.length;
for (uint8 i = 0; i < len; i++) {
if (configs[i].tgePercent > 10000) {
revert InvalidConfigData();
}
buckets[bucketIds[i]] = configs[i];
}
}
/**
* @notice set personal configs
* @param users array of users
* @param bucketIds array of bucket ids
* @param configs personal configs
*/
function addPersonalConfigs(
address[] calldata users,
uint8[] calldata bucketIds,
Config[] calldata configs
) external onlyRole(DEFAULT_ADMIN_ROLE) {
uint256 len = configs.length;
for (uint256 i = 0; i < len; i++) {
userData[users[i]].configSet = true;
if (configs[i].tgePercent > 10000) {
revert InvalidConfigData();
}
personalConfigs[users[i]][bucketIds[i]] = configs[i];
}
}
/**
* @notice changes root
* @param index index of root
* @param _root new root
*/
function changeRoot(
uint256 index,
bytes32 _root
) external onlyRole(DEFAULT_ADMIN_ROLE) {
roots[index] = _root;
}
function setCircuitBreaker(
bool status
) external onlyRole(DEFAULT_ADMIN_ROLE) {
circuitBreakerEnabled = status;
}
function setMulTable(
uint256[] calldata _days,
uint256[] calldata multipliers
) external onlyRole(DEFAULT_ADMIN_ROLE) {
uint256 len = _days.length;
if (len != multipliers.length) {
revert("Invalid len");
}
for (uint256 i = 0; i < len; i++) {
mulTable[_days[i]] = multipliers[i];
}
}
function setMulDelta(
uint256 _delta
) external onlyRole(DEFAULT_ADMIN_ROLE) {
mulDelta = _delta;
}
// =========================================
// UPGRADES
// =========================================
function _authorizeUpgrade(
address newImplementation
) internal override onlyRole(UPGRADER_ROLE) {}
}
IERC20Burnable.sol 8 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IERC20Burnable {
function burn(uint256 value) external;
}
Read Contract
CURVE_MAX 0xf5f881d5 → uint256
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
MUL_DENOM 0x809f71d0 → uint256
UPGRADER_ROLE 0xf72c0d8b → bytes32
buckets 0xe8169c51 → bool, uint256, uint256, uint256
circuitBreakerEnabled 0xab9068fa → bool
curveStart 0x38368eb8 → uint256
getAvailableAmount 0x03d9d4ec → uint256
getCurveMultiplier 0xf005625f → uint256
getCurveMultiplierNow 0x526282ad → uint256
getFinalAmounts 0x170bd03d → uint256, uint256
getFinalAvailable 0x73db51be → uint256, uint256
getMaxAvailableAmount 0x1b73183d → uint256
getRoleAdmin 0x248a9ca3 → bytes32
getUserClaimFromBucket 0xce0a2022 → uint256
hasRole 0x91d14854 → bool
isBlocked 0xedfc3fe8 → bool
mulDelta 0xb1a09289 → uint256
mulTable 0x9693231d → uint256
multipliedClaimed 0x28c22339 → uint256
ngl 0xeaddb9c6 → address
personalConfigs 0x808ed15d → bool, uint256, uint256, uint256
proxiableUUID 0x52d1902d → bytes32
roots 0xc2b40ae4 → bytes32
start 0xbe9a6555 → uint256
supportsInterface 0x01ffc9a7 → bool
totalBurned 0xd89135cd → uint256
totalClaimed 0xd54ad2a1 → uint256
userData 0xc8910913 → bool
Write Contract 18 functions
These functions modify contract state and require a wallet transaction to execute.
addBucketConfigs 0x34beb0f8
uint8[] bucketIds
tuple[] configs
addPersonalConfigs 0xa5a509b4
address[] users
uint8[] bucketIds
tuple[] configs
changeRoot 0xdc42286b
uint256 index
bytes32 _root
claim 0x14336e1c
uint8 bucketId
uint256 amountListed
bytes32 leaf
bytes32[] proof
claimBatch 0x90896eea
uint8[] bucketIds
uint256[] amountListed
bytes32[] leafs
bytes32[][] proofs
grantRole 0x2f2ff15d
bytes32 role
address account
initialize 0x373f2ff4
address _ngl
bytes32[] _roots
renounceRole 0x36568abe
bytes32 role
address account
revokeRole 0xd547741f
bytes32 role
address account
setCircuitBreaker 0x42506449
bool status
setClaimingBlockedBucket 0x23886383
uint8 bucketId
bool status
setClaimingBlockedUsers 0xdae404a0
address[] users
uint8[] bucketIds
bool[] statuses
setCurveStart 0x1f24b037
uint256 newCurveStart
setMulDelta 0x6ed130db
uint256 _delta
setMulTable 0xd3095d4a
uint256[] _days
uint256[] multipliers
setStart 0xf6a03ebf
uint256 _newStart
upgradeTo 0x3659cfe6
address newImplementation
upgradeToAndCall 0x4f1ef286
address newImplementation
bytes data
Recent Transactions
No transactions found for this address