Address Contract Verified
Address
0xeBA7323f4054d385873C45E53a3F7f7F802c8AE0
Balance
0 ETH
Nonce
1
Code Size
13870 bytes
Creator
0xbF55F275...4BFa at tx 0xe97604db...1b0436
Indexed Transactions
0
Contract Bytecode
13870 bytes
0x6080806040526004361015610054575b50361561001b57600080fd5b7f00000000000000000000000000000000000000000000000000000000000000011561004357005b631d28d91d60e11b60005260046000fd5b60003560e01c90816301ffc9a714611d9f57508063022d63fb14611d815780630603793914611c5e57806307e2cea514611c235780630aa6220b14611b8f5780630b09c72914611adc5780630b493e0f146119ef57806318a860c5146119c35780631a4709ff146119725780631a54259c146119055780631a90b159146118ca5780631c4922da146117b1578063248a9ca3146117845780632f2ff15d1461173e57806331c059131461169d57806333289a4614611632578063364f1f16146114b857806336568abe146113c957806341529364146112ab578063521c228e1461126e57806359f9d7d9146111975780635c074f4414611179578063634e93da146110a0578063649a5ec714610f2d5780636ace1ac814610e6a57806370a34c3d14610e0357806370bb45b314610da8578063784eca0914610d735780637c41cd5214610d575780638305930314610d1c57806384ef8ffc14610ca25780638d6be15014610ccb5780638da5cb5b14610ca25780639010d07c14610c7d57806391d1485414610c30578063930d3f1714610b5b5780639667846214610a665780639ec5a89414610a4b578063a1eda53c146109e8578063a217fddf146109cc578063a3b0b5a314610991578063ab541a8514610938578063beca03d514610915578063c0cd94f0146108d7578063ca15c873146108ab578063cc8463c814610880578063cefc1429146107cf578063cf6eefb714610795578063d0e30db014610744578063d547741f146106e8578063d602b9fd14610685578063dd1e8b7714610633578063e94ad65b146105ee578063eb044e7e14610332578063f5b541a6146102f75763ff2a7d30146102c9573861000f565b346102f25760003660031901126102f2576009546040516001600160a01b039091168152602090f35b600080fd5b346102f25760003660031901126102f25760206040517f97667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b9298152f35b346102f25760203660031901126102f2576004356001600160401b0381116102f2576060816004019160031990360301126102f25761036f6123e2565b80356001600160a01b038116908190036102f257156105dd5761039a6103953683611f44565b6120af565b6000818152600b60205260409020546001600160a01b03166105cc576103cd604051926103c684611e83565b3690611f44565b825260006020808401828152838352600b8252604092839020945180519281015160a01b6001600160a01b0319166001600160a01b039390931692909217855591015180516001850194916001600160401b0382116105b657600160401b82116105b6578554828755808310610557575b506020019460005260206000208160021c9160005b838110610511575060031981169003806104b1575b60208686600287019051151560ff801983541691161790557f88316dbe92b13253e312411200baf2f4863a91f4dbfb2d776f22b20cf399bfbb82604051838152a1604051908152f35b9560009660005b8181106104d357505050019390935560209260028580610468565b90919760206105076001926001600160401b038c5116908560031b6001600160401b03809160031b9316831b921b19161790565b99019291016104b8565b6000805b6004811061052a575083820155600101610453565b89519099916001916020916001600160401b0360068e901b81811b199092169216901b1792019901610515565b866000526020600020600380850160021c8201920160021c019060188460031b1680610599575b505b81811061058d575061043e565b60008155600101610580565b6000198201908154906000199060200360031b1c1690558861057e565b634e487b7160e01b600052604160045260246000fd5b630b86c4cf60e31b60005260046000fd5b630863a45360e11b60005260046000fd5b346102f25760003660031901126102f2576040517f00000000000000000000000000000000219ab540356cbb839cbe05303d7705fa6001600160a01b03168152602090f35b346102f25760603660031901126102f25761064c611f2e565b6024356001600160401b03811681036102f2576044359065ffffffffffff821682036102f2576106839261067e612370565b6127b1565b005b346102f25760003660031901126102f25761069e6122bd565b600180546001600160d01b0319811690915560a01c65ffffffffffff166106c157005b7f8886ebfc4259abdbc16601dd8fb5678e54878f47b3c34836cfc51154a9605109600080a1005b346102f25760403660031901126102f257600435610704611e3c565b8115610733578161072e61072961068394600052600060205260016040600020015490565b612454565b613442565b631fe1e13d60e11b60005260046000fd5b60003660031901126102f2576107586122fe565b61076434600a54612229565b600a556040513481527fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c60203392a2005b346102f25760003660031901126102f257600154604080516001600160a01b038316815260a09290921c65ffffffffffff16602083015290f35b346102f25760003660031901126102f2576001546001600160a01b0316330361086b5760015460a081901c65ffffffffffff16906001600160a01b031681158015610861575b61084c576002546108399190610833906001600160a01b03166133cc565b50612c3f565b50600180546001600160d01b0319169055005b506319ca5ebb60e01b60005260045260246000fd5b5042821015610815565b636116401160e11b6000523360045260246000fd5b346102f25760003660031901126102f257602061089b612284565b65ffffffffffff60405191168152f35b346102f25760203660031901126102f25760043560005260036020526020604060002054604051908152f35b346102f25760206108fc6108ea36611e26565b90600052600483526040600020612020565b905460405160039290921b1c6001600160a01b03168152f35b346102f25760003660031901126102f2576020610930612256565b604051908152f35b346102f25760403660031901126102f257610951611e52565b6001600160a01b03166000908152600c60205260409020805460243591908210156102f25760209161098291612020565b90549060031b1c604051908152f35b346102f25760003660031901126102f25760206040517f8f4f2da22e8ac8f11e15f9fc141cddbb5deea8800186560abb6e68c5496619a98152f35b346102f25760003660031901126102f257602060405160008152f35b346102f25760003660031901126102f2576002548060d01c9081151580610a41575b15610a375760a01c65ffffffffffff165b6040805165ffffffffffff928316815292909116602083015290f35b5050600080610a1b565b5042821015610a0a565b346102f25760003660031901126102f2576020610930612236565b346102f25760203660031901126102f2576004356001600160401b0381116102f257366023820112156102f2578060040135906001600160401b0382116102f2573660248360051b830101116102f257610abe6123e2565b600a546801bc16d674ec8000008302908382046801bc16d674ec8000001484151715610b4557818110610b345703600a553681900360a21901919060005b8281101561068357600060248260051b840101359085821215610b31575090610b2b6024600193850101612990565b01610afc565b80fd5b63356680b760e01b60005260046000fd5b634e487b7160e01b600052601160045260246000fd5b346102f25760203660031901126102f257610b74611e52565b6001600160a01b03166000818152600c6020908152604080832090518154808252918452828420909290918391820190855b818110610c17575050610bbb92500382611e9e565b815b8151831015610bec57610be4600191610bde60208660051b8601015161249a565b90612229565b920191610bbd565b839080158015610bf857005b633b9aca008202918204633b9aca00141715610b45576106839161271d565b8454835260019485019486945060209093019201610ba6565b346102f25760403660031901126102f257610c49611e3c565b600435600052600060205260406000209060018060a01b0316600052602052602060ff604060002054166040519015158152f35b346102f25760206108fc610c9036611e26565b90600052600383526040600020612020565b346102f25760003660031901126102f2576002546040516001600160a01b039091168152602090f35b346102f25760203660031901126102f2576001600160401b03610cec611f2e565b1660005260066020526040806000205465ffffffffffff8251916001600160401b0381168352831c166020820152f35b346102f25760003660031901126102f25760206040517f010000000000000000000000eba7323f4054d385873c45e53a3f7f7f802c8ae08152f35b346102f25760203660031901126102f257610683600435612127565b346102f25760203660031901126102f2576004356001600160401b0381116102f2576109306103956020923690600401611f44565b346102f25760003660031901126102f2576009546001600160a01b03167ff404cd4814ff561c9e00078e4984b7c5580a7d479c47554807962de186f34e9a6020610df0612236565b610dfa818561271d565b604051908152a2005b346102f25760203660031901126102f2576004356001600160401b0381116102f257608060031982360301126102f257610e3b6123e2565b600a54906801bc16d674ec8000008210610b3457610683916801bc16d674ec7fffff1901600a55600401612990565b346102f25760203660031901126102f2576004356001600160401b0381116102f257366023820112156102f25780600401356001600160401b0381116102f257602482019160243691606084020101116102f257610ec6612370565b60005b818110610ed257005b610ee5610ee082848661208b565b61209b565b90610efc6020610ef683868861208b565b0161209b565b916040610f0a83868861208b565b013565ffffffffffff811681036102f257600193610f27926127b1565b01610ec9565b346102f25760203660031901126102f25760043565ffffffffffff8116908181036102f257610fbf7ff1038c18cf84a56e432fdbfaf746924b7ea511dfe03a6506a0ceba4888788d9b92610f7f6122bd565b610f8842612d66565b9083610f92612284565b65ffffffffffff81168311156110905750506206978081101561107f5765ffffffffffff905b1690612775565b906002548060d01c80611022575b5050600280546001600160a01b031660a083901b65ffffffffffff60a01b161760d084901b6001600160d01b0319161790556040805165ffffffffffff9283168152929091166020830152819081015b0390a1005b42111561105457600180546001600160d01b031660309290921b6001600160d01b0319169190911790555b8380610fcd565b507f2b1fa2edafe6f7b9e97c1a9e0c3660e645beb2dcaa2d45bdbf9beaf5472e1ec5600080a161104d565b5065ffffffffffff62069780610fb8565b61109a9250612793565b90612775565b346102f25760203660031901126102f2576110b9611e52565b6110c16122bd565b6001600160a01b03168015610733577f3377dc44241e779dd06afab5b788a35ca5f3b778836e2990bdb26a2a4b2e5ed660206111076110ff42612d66565b61109a612284565b600180546001600160d01b03198116861760a084811b65ffffffffffff60a01b1691909117909255901c65ffffffffffff1661114f575b65ffffffffffff60405191168152a2005b7f8886ebfc4259abdbc16601dd8fb5678e54878f47b3c34836cfc51154a9605109600080a161113e565b346102f25760003660031901126102f2576020600a54604051908152f35b346102f25760203660031901126102f2576004356111b36122fe565b6000818152600b6020526040902080546001600160a01b038116929091831561125d576002019283549260ff841661124c57429060a01c1061123b577f942e1b58e86195262137610a19da111b7d2263eb4b95d67a856e77abc0ad683493600160209460ff1916179055600052600c825261123281604060002061204e565b604051908152a1005b6328a7237960e01b60005260046000fd5b63a5e98d0760e01b60005260046000fd5b63635e873760e01b60005260046000fd5b346102f25760003660031901126102f25760206040517f000000000000000000000000000000000000000000000000000000000000000115158152f35b346102f2576112b936611e26565b6112d182600052600060205260016040600020015490565b3360009081526000805160206135b9833981519152602052604090205460ff161590816113a5575b508061137e575b61134557816040917f7235b6b0d4799d931377083ba89650956975f8e6d0ed6e35aa2f885819acb92793600052600560205260008381205582519182526020820152a1005b63e2517d3f60e01b600052336004527f82e82596d56fdc368915d9eb235b890264902e8f25b874228ea2cecbcb1e096360245260446000fd5b503360009081526000805160206135d9833981519152602052604090205460ff1615611300565b60009081526020818152604080832033845290915290205460ff16159050836112f9565b346102f25760403660031901126102f2576004356113e5611e3c565b8115806114a1575b61141c575b336001600160a01b0382160361140b5761068391613442565b63334bd91960e11b60005260046000fd5b60015465ffffffffffff60a082901c16906001600160a01b031615801590611491575b801561147f575b61146257506001805465ffffffffffff60a01b191690556113f2565b65ffffffffffff906319ca5ebb60e01b6000521660045260246000fd5b504265ffffffffffff82161015611446565b5065ffffffffffff81161561143f565b506002546001600160a01b038281169116146113ed565b346102f25760203660031901126102f257600435600052600b60205260406000206040516114e581611e68565b81546001600160a01b038116825260a01c602080830191909152604051600184018054808352600091825283822093830195935b8160038401106115e657836115789760ff96946002969461155c9454918181106115cc575b8181106115af575b818110611592575b10611584575b500382611e9e565b6040850152015416604051928392604084526040840190611ebf565b90151560208301520390f35b60c01c815260200189611554565b9260206001916001600160401b038560801c16815201930161154e565b9260206001916001600160401b038560401c168152019301611546565b9260206001916001600160401b038516815201930161153e565b956001608060049289546001600160401b03811682526001600160401b038160401c1660208301526001600160401b0381841c16604083015260c01c6060820152019701920191611519565b346102f25760203660031901126102f25760043561164e6122fe565b600a54808211610b3457818103908111610b4557600a5561166f813361271d565b6040519081527f4482101800a5c2e900f4156e57e05e19ffd7b366cde579553d723fd3abb2180e60203392a2005b346102f2576116ab36611e26565b3360009081526000805160206135b9833981519152602052604090205460ff161580611717575b61134557816040917f83db1b4cf8e9d1e1126394ad20f1c00681fb7abc040d3bd96f6a16aba7833bf493600052600560205280836000205582519182526020820152a1005b503360009081526000805160206135d9833981519152602052604090205460ff16156116d2565b346102f25760403660031901126102f25760043561175a611e3c565b8115610733578161177f61072961068394600052600060205260016040600020015490565b612cb9565b346102f25760203660031901126102f2576020610930600435600052600060205260016040600020015490565b346102f25760403660031901126102f2576004356117cd611e3c565b6117e582600052600060205260016040600020015490565b3360009081526000805160206135b9833981519152602052604090205460ff161590816118a6575b508061187f575b6113455760008281526004602052604090207f5cfe8536526fca3924189ba4c613d84a99cc0eed64783199456f632531e7d038929061185d906001600160a01b03841690612b9f565b50604080519182526001600160a01b039092166020820152908190810161101d565b503360009081526000805160206135d9833981519152602052604090205460ff1615611814565b60009081526020818152604080832033845290915290205460ff161590508361180d565b346102f25760003660031901126102f25760206040517f82e82596d56fdc368915d9eb235b890264902e8f25b874228ea2cecbcb1e09638152f35b346102f25760203660031901126102f2576004356001600160a01b038116908190036102f2576119336122fe565b80156105dd57600980546001600160a01b031916821790557fbf0fc913061e14d8af291e5131432ddc189ad930d87ee8c9210f93299f67f60c600080a2005b346102f25760203660031901126102f25760043580600052600b6020526040600020600160ff60028301541615150361125d57546001600160a01b0316906119b99061249a565b80158015610bf857005b346102f25760203660031901126102f25760043560005260046020526020604060002054604051908152f35b346102f25760403660031901126102f257600435611a0b611e3c565b611a2382600052600060205260016040600020015490565b60008181526020818152604080832033845290915290205460ff161580611ab5575b611a9d57506000828152600460205260409020611a6c906001600160a01b03831690612b9f565b1561140b578161185d827f5c35cbad3ba47dea6af29472ee06ceac110509c66b7b5f2d90dcecc5a5c07ba194612cb9565b63e2517d3f60e01b6000523360045260245260446000fd5b503360009081526000805160206135d9833981519152602052604090205460ff1615611a45565b346102f25760403660031901126102f257600435611af8611e3c565b3360009081526000805160206135b9833981519152602052604090205460ff161580611b68575b6113455760008281526004602052604090207f96c4d7106fd894adf600ee4ed01746c7833c4567c3112e77b605766441303799929061185d906001600160a01b03841690612b36565b503360009081526000805160206135d9833981519152602052604090205460ff1615611b1f565b346102f25760003660031901126102f257611ba86122bd565b6002548060d01c80611bc6575b600280546001600160a01b03169055005b421115611bf857600180546001600160d01b031660309290921b6001600160d01b0319169190911790555b8080611bb5565b507f2b1fa2edafe6f7b9e97c1a9e0c3660e645beb2dcaa2d45bdbf9beaf5472e1ec5600080a1611bf1565b346102f25760003660031901126102f25760206040517f68e79a7bf1e0bc45d0a330c573bc367f9cf464fd326078812f301165fbda4ef18152f35b346102f257611c6c36611e26565b611c8482600052600060205260016040600020015490565b60008181526020818152604080832033845290915290205460ff161580611d5a575b611a9d5750816000526005602052806040600020540361140b578160005260056020526000604081205581156107335781604091611d137fffbc116f80d6852a611cf856963aced606540f400360ca3482da99375505e50294600052600060205260016040600020015490565b9180600052600060205281600185600020015581845193827fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff600080a482526020820152a1005b503360009081526000805160206135d9833981519152602052604090205460ff1615611ca6565b346102f25760003660031901126102f2576020604051620697808152f35b346102f25760203660031901126102f2576004359063ffffffff60e01b82168092036102f257602091635a05180f60e01b8114908115611de1575b5015158152f35b6318a4c3c360e11b811491508115611dfb575b5083611dda565b637965db0b60e01b811491508115611e15575b5083611df4565b6301ffc9a760e01b14905083611e0e565b60409060031901126102f2576004359060243590565b602435906001600160a01b03821682036102f257565b600435906001600160a01b03821682036102f257565b606081019081106001600160401b038211176105b657604052565b604081019081106001600160401b038211176105b657604052565b90601f801991011681019081106001600160401b038211176105b657604052565b602060806040606085019360018060a01b0381511686526bffffffffffffffffffffffff8482015116848701520151936060604082015284518094520192019060005b818110611f0f5750505090565b82516001600160401b0316845260209384019390920191600101611f02565b600435906001600160401b03821682036102f257565b91906060838203126102f257604051611f5c81611e68565b92839080356001600160a01b03811681036102f257825260208101356bffffffffffffffffffffffff811681036102f25760208301526040810135906001600160401b0382116102f2570182601f820112156102f2578035926001600160401b0384116105b6578360051b9160405194611fd96020850187611e9e565b85526020808601938201019182116102f257602001915b8183106120005750505060400152565b82356001600160401b03811681036102f257815260209283019201611ff0565b80548210156120385760005260206000200190600090565b634e487b7160e01b600052603260045260246000fd5b805490600160401b8210156105b6578161207091600161208794018155612020565b819391549060031b91821b91600019901b19161790565b9055565b9190811015612038576060020190565b356001600160401b03811681036102f25790565b6040516120da816120cc6020820194602086526040830190611ebf565b03601f198101835282611e9e565b51902090565b60008155600181018054906000815581612100575b505060026000910155565b60005260036020600020910160021c8101905b818110156120f55760008155600101612113565b80600052600b60205260ff6002604060002001541661124c5780600052600b60205260406000205460a01c421180156121f1575b80156121b9575b61217757634ca8886760e01b60005260046000fd5b6020817f55295d4ce992922fa2e5ffbf3a3dcdb367de0a15e125ace083456017fd22060f92600052600b82526121b060406000206120e0565b604051908152a1565b503360009081527fee57cd81e84075558e8fcc182a1f4393f91fc97f963a136e66b7f949a62f319f602052604090205460ff16612162565b503360009081527fcd535922ec6598051cb9009e5385a1e92110f0406d6b811e10c8a3249b96d6dd602052604090205460ff1661215b565b91908201809211610b4557565b612244600a54610bde612256565b80471061225057470390565b50600090565b6122686001600160401b034316613325565b633b9aca00810290808204633b9aca001490151715610b455790565b6002548060d01c80151590816122b3575b50156122a95760a01c65ffffffffffff1690565b5060015460d01c90565b9050421138612295565b3360009081526000805160206135d9833981519152602052604090205460ff16156122e457565b63e2517d3f60e01b60005233600452600060245260446000fd5b3360009081527fcd535922ec6598051cb9009e5385a1e92110f0406d6b811e10c8a3249b96d6dd602052604090205460ff161561233757565b63e2517d3f60e01b600052336004527f8f4f2da22e8ac8f11e15f9fc141cddbb5deea8800186560abb6e68c5496619a960245260446000fd5b3360009081527fa629f6981c2f6895a67dc766e8e03ff72d04a413d0d8773a3ca56e9e474032c1602052604090205460ff16156123a957565b63e2517d3f60e01b600052336004527f68e79a7bf1e0bc45d0a330c573bc367f9cf464fd326078812f301165fbda4ef160245260446000fd5b3360009081527fee57cd81e84075558e8fcc182a1f4393f91fc97f963a136e66b7f949a62f319f602052604090205460ff161561241b57565b63e2517d3f60e01b600052336004527f97667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b92960245260446000fd5b60008181526020818152604080832033845290915290205460ff1615611a9d5750565b919091805483101561203857600052601860206000208360021c019260031b1690565b90600090828252600b6020526040822060ff600282015416156127175782600182019283549586925b83801561260a5760001901936001600160401b036124e18689612477565b90549060031b1c169081600052600660205260406000206040519061250582611e83565b5465ffffffffffff6001600160401b0382169182845260401c169081602084015280156126005743101561253d575b505050506124c3565b61255092939a9794506001970199612d25565b819860001901918281106125ad575b50508554801561259757600019016125778188612477565b6001600160401b0382549160031b1b191690558655969238808080612534565b634e487b7160e01b600052603160045260246000fd5b909198506125f66125d86001600160401b036125c98c8b612477565b90549060031b1c169289612477565b81939154906001600160401b03809160031b9316831b921b19161790565b905596388061255f565b50505050506124c3565b5092509290955060018060a01b03905416925415612677575b61262c57505090565b633b9aca008302838104633b9aca001484151715610b45577fca14619b15a8983bd8a0a511c166f11324d409b9cc85a7c9414d5b3efac33d199160409182519182526020820152a290565b82600052600c6020526040600020805480915b82801561270e576000190192856126a18584612020565b90549060031b1c146126b3575061268a565b6126cb9260001901938481106126e8575b5050612b76565b505b81600052600b6020526126e360406000206120e0565b612623565b6127066120706126f88786612020565b90549060031b1c9285612020565b9055386126c4565b505050506126cd565b50915090565b6000918291829182916001600160a01b03165af13d15612770573d6001600160401b0381116105b6576040519061275e601f8201601f191660200183611e9e565b8152600060203d92013e5b156102f257565b612769565b9065ffffffffffff8091169116019065ffffffffffff8211610b4557565b9065ffffffffffff8091169116039065ffffffffffff8211610b4557565b906001600160401b0381169283156129315765ffffffffffff8116928315612923576001600160401b0316908160005260066020526040600020805491866001600160401b0365ffffffffffff8560401c169416146128ab57506128949261289996926001600160401b0365ffffffffffff935416908161289b575b50506040519261283c84611e83565b8352602083019086825260005260066020526001600160401b03806040600020945116166001600160401b0319845416178355511665ffffffffffff60401b82549160401b169065ffffffffffff60401b1916179055565b612e83565b565b6128a491613160565b388061282d565b9550909293809250831461291c5780546dffffffffffff00000000000000001916604086901b65ffffffffffff60401b16179055811115612901576128fa6128999365ffffffffffff92612793565b1690613160565b61291565ffffffffffff9161289994612793565b1690612e83565b5050505050565b925050506128999150612d97565b50506128999150612d97565b903590601e19813603018212156102f257018035906001600160401b0382116102f2576020019181360383136102f257565b908060209392818452848401376000828201840152601f01601f1916010190565b6020810161299e818361293d565b60009291359060208110612b24575b507f010000000000000000000000eba7323f4054d385873c45e53a3f7f7f802c8ae003612b1557612a16907f00000000000000000000000000000000219ab540356cbb839cbe05303d7705fa6001600160a01b031690612a0d858061293d565b9390918661293d565b9390612a25604088018861293d565b9091853b15612b115792612a91612a6d95936801bc16d674ec80000093612a7f8b99976040519b8c9a8b998a986304512a2360e31b8a52608060048b015260848a019161296f565b8781036003190160248901529161296f565b8481036003190160448601529161296f565b60608a0135606483015203925af18015612b0657917fd62a007bd3566ce3a36d14fa227c12fc1e16b43a0a006d61e59792447fc892119391612ada93612af6575b50508061293d565b612af160405192839260208452602084019161296f565b0390a1565b81612b0091611e9e565b38612ad2565b6040513d84823e3d90fd5b8780fd5b639be7315960e01b8252600482fd5b6000199060200360031b1b16386129ad565b6001810190826000528160205260406000205415600014612b6e57612b5b838261204e565b5491600052602052604060002055600190565b505050600090565b80548015612597576000190190612b8d8282612020565b8154906000199060031b1b1916905555565b906001820191816000528260205260406000205490811515600014612c3657600019820191808311610b455781546000198101908111610b45578381612bed9503612bff575b505050612b76565b60005260205260006040812055600190565b612c1f612c0f6120709386612020565b90549060031b1c92839286612020565b905560005284602052604060002055388080612be5565b50505050600090565b600254906001600160a01b038216610733576001600160a01b0381166001600160a01b0319929092168217600255612c789060006134b2565b9081612c82575090565b600080526003602052612cb5907f3617319a054d772f909f7c479a2cebe5066e836a939412e32403c99029b92eff612b36565b5090565b8015612cf7575b612cca82826134b2565b9182612cd557505090565b600091825260036020526040909120612cb5916001600160a01b031690612b36565b6002546001600160a01b038116610733576001600160a01b0319166001600160a01b03831617600255612cc0565b6001600160401b031660005260066020526000604081205565ffffffffffff60208201511680612d53575050565b6001600160401b03612899925116613160565b65ffffffffffff8111612d7e5765ffffffffffff1690565b6306dfcc6560e41b600052603060045260245260446000fd5b6001600160401b0381166000526006602052604060002060405190612dbb82611e83565b5465ffffffffffff6001600160401b0382169182845260401c16806020840152159081612df5575b50612df15761289991612d25565b5050565b90501538612de3565b15612e0557565b634e487b7160e01b600052600160045260246000fd5b906001600160401b03809116911601906001600160401b038211610b4557565b9067ffffffffffffffff60401b82549160401b169067ffffffffffffffff60401b1916179055565b906001600160401b03809116911603906001600160401b038211610b4557565b916001600160401b0382161561315b576001600160401b03831692612ea9841515612dfe565b60406000858152600860205220926001600160401b03612ecd818654169283612e1b565b166001600160401b0319855416178455613155576001600160401b036007541615613118576001600160401b0360075460401c1680851161309157506001600160401b036007541680851061301f5750916001600160401b0360075460401c169083915b6001600160401b03811692868410612f6f5750806001600160401b036040612f6a939560009081526008602052205460801c1690612e63565b612f31565b916001600160401b0394965084935090612fe591612fe061289997612f9e612f978583612e63565b9187612e63565b978894166000526008602052612fb8816040600020612e3b565b825467ffffffffffffffff60801b191660809190911b67ffffffffffffffff60801b16178255565b612e3b565b166000908152600860205260409020805467ffffffffffffffff60801b191660809290921b67ffffffffffffffff60801b16919091179055565b61303261307e9395949261303992612e63565b8092612e3b565b6007546001600160401b03166000908152600860205260409020805467ffffffffffffffff60801b191660809290921b67ffffffffffffffff60801b16919091179055565b6001600160401b03196007541617600755565b6130ef9294506130a66130ce91839593612e63565b825467ffffffffffffffff60801b1916608082901b67ffffffffffffffff60801b1617909255565b6001600160401b0360075460401c1660005260086020526040600020612e3b565b67ffffffffffffffff60401b6007549160401b169067ffffffffffffffff60401b191617600755565b9150916001600160401b0319600754161760075567ffffffffffffffff60401b6007549160401b169067ffffffffffffffff60401b191617600755565b50915050565b915050565b6001600160401b0382168015613320576001600160401b036131a36000946040838616968781526008602052209361319e8486541691821015612dfe565b612e63565b166001600160401b031982541617815554916001600160401b038316156131c957505050565b6001600160401b03808460401c169360801c16906000526008602052600060408120558215808091613318575b6132f957613297578015613246576132236128999361321d6001600160401b039385612e63565b93612e1b565b8161322e8483612e63565b93166000526008602052612fe5836040600020612e3b565b506001600160401b039161325991612e1b565b166001600160401b031960075416176007556001600160401b0360075416600052600860205260406000206001600160401b0360801b198154169055565b906132a29250612e63565b67ffffffffffffffff60401b6007549160401b169067ffffffffffffffff60401b1916176007556001600160401b0360075460401c166000526008602052604060002067ffffffffffffffff60401b198154169055565b5050600780546fffffffffffffffffffffffffffffffff191690555050565b5081156131f6565b505050565b6001600160401b03600754169081156133c5576001600160401b03168082116133c5576000915b6001600160401b036133976040600083851681526008602052206040519061337382611e68565b54958387169182815260408560208301998181841c168b5260801c16910152612229565b93511680156133bf576133a991612e1b565b816001600160401b038216111561334c57505090565b50505090565b5050600090565b6002546001600160a01b03828116926133f092909116831461342d575b6000613536565b90816133fa575090565b600080526003602052612cb5907f3617319a054d772f909f7c479a2cebe5066e836a939412e32403c99029b92eff612b9f565b600280546001600160a01b03191690556133e9565b80158061349b575b613486575b6134598282613536565b918261346457505090565b600091825260036020526040909120612cb5916001600160a01b031690612b9f565b600280546001600160a01b031916905561344f565b506002546001600160a01b0383811691161461344a565b6000818152602081815260408083206001600160a01b038616845290915290205460ff166133c5576000818152602081815260408083206001600160a01b0395909516808452949091528120805460ff19166001179055339291907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9080a4600190565b6000818152602081815260408083206001600160a01b038616845290915290205460ff16156133c5576000818152602081815260408083206001600160a01b0395909516808452949091528120805460ff19169055339291907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9080a460019056fe13e477d93e5959681e63340ebd0555122995fc07a09660846b8f713bdff28963ad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5a26469706673582212209629435afdef837021c84c038363ec03538c7e7466fdfa6804e9e8c55058165764736f6c634300081a0033
Verified Source Code Full Match
Compiler: v0.8.26+commit.8a97fa7a
EVM: paris
Optimization: Yes (200 runs)
UnorderedSet.sol 95 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
/// @title UnorderedSet
/// @notice This library implements efficient removals from unordered sets
library UnorderedSet {
/// @notice Efficiently removes an element from the unordered set, while iterating from the end to the start. Return values for the next index to visit and new length.
/// @param array The array to remove the element from
/// @param index The index of the element to remove
/// @param length The length of the array
/// @return Tuple of next index and new length. In case an element was removed from the middle of the array, iterating over all elements necessitates revisiting the same index
function removeIndexUnchecked(uint64[] storage array, uint256 index, uint256 length)
internal
returns (uint256, uint256)
{
// Move the last element to the index being removed if we're not removing the last element
uint256 last;
unchecked {
last = length - 1;
}
if (index < last) {
array[index] = array[last];
unchecked {
index++;
}
}
// Remove the last element and decrement the length
array.pop();
unchecked {
length--;
}
return (index, length);
}
/// @notice Efficiently removes an element from the unordered set, while iterating from the end to the start. Return values for the next index to visit and new length.
/// @param array The array to remove the element from
/// @param index The index of the element to remove
/// @param length The length of the array
/// @return Tuple of next index and new length. In case an element was removed from the middle of the array, iterating over all elements necessitates revisiting the same index
function removeIndexUnchecked(bytes32[] storage array, uint256 index, uint256 length)
internal
returns (uint256, uint256)
{
// Move the last element to the index being removed if we're not removing the last element
uint256 last;
unchecked {
last = length - 1;
}
if (index < last) {
array[index] = array[last];
unchecked {
index++;
}
}
// Remove the last element and decrement the length
array.pop();
unchecked {
length--;
}
return (index, length);
}
/// @notice Efficiently removes an element from the unordered set. Returns the index removed and the new length
/// @param array The array to remove the element from
/// @param value The value to remove
/// @return Tuple of index removed and new length. If the length did notchange, no element was removed
function removeValue(bytes32[] storage array, bytes32 value) internal returns (uint256, uint256) {
return removeValue(array, value, array.length);
}
/// @notice Efficiently removes an element from the unordered set. Returns the index removed and the new length. This is an optimised version if the length is already known
/// @param array The array to remove the element from
/// @param value The value to remove
/// @param length The length of the array
/// @return Tuple of index removed and new length. If the length did not change, no element was removed
function removeValue(bytes32[] storage array, bytes32 value, uint256 length) internal returns (uint256, uint256) {
uint256 i = length;
while (i > 0) {
unchecked {
i--;
}
if (array[i] == value) {
(, length) = removeIndexUnchecked(array, i, length);
break;
}
}
return (i, length);
}
}
BeaconHelpers.sol 11 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
bytes1 constant ETH1_ADDRESS_WITHDRAWAL_PREFIX = 0x01;
/// @notice Returns the withdrawal credential for a given execution address
/// @param executionAddress The execution address, ie. 20 byte address
/// @return The withdrawal credential
function eth1WithdrawalCredential(address executionAddress) pure returns (bytes32) {
return bytes32(abi.encodePacked(ETH1_ADDRESS_WITHDRAWAL_PREFIX, bytes11(0x00), executionAddress));
}
CumulativeSum.sol 147 lines
// // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
/// @title CumulativeSum
/// @notice This library implements a cumulative sum of uint64 amounts over sparse block numbers
/// @dev The implementation uses a double linked list internally. Appending at the end and removing from the front are assumed likely operations.
library CumulativeSum {
// uint64 has capacity for 7 billion years of blocks at 12s per block
struct Storage {
uint64 head;
uint64 tail;
mapping(uint64 => Node) nodes;
}
// uint64 has capacity for 281k ETH per block
// uint64 has capacity for 1633 years of block gaps
struct Node {
uint64 sum;
uint64 nextOffset;
uint64 prevOffset;
}
/// @notice Add an amount to the cumulative sum at a given block number
/// @param self The storage reference
/// @param blockNumber The block number to update
/// @param amount The amount to add. Note the smaller bit width
function add(Storage storage self, uint64 blockNumber, uint64 amount) internal {
if (amount == 0) return;
assert(blockNumber > 0);
// Optimistically update the sum, as the default values are 0 in EVM
Node storage cur = self.nodes[blockNumber];
uint64 prevSum = cur.sum;
cur.sum = prevSum + amount;
// This was an update
if (prevSum > 0) return;
// Base case. head == 0 implies tail == 0
if (self.head == 0) {
self.head = blockNumber;
self.tail = blockNumber;
return;
}
// append
if (blockNumber > self.tail) {
uint64 delta = blockNumber - self.tail;
cur.prevOffset = delta;
self.nodes[self.tail].nextOffset = delta;
self.tail = blockNumber;
return;
}
// prepend
if (blockNumber < self.head) {
uint64 delta = self.head - blockNumber;
cur.nextOffset = delta;
self.nodes[self.head].prevOffset = delta;
self.head = blockNumber;
return;
}
// find insertion point, starting from the tail
uint64 lo = self.tail;
uint64 hi = blockNumber;
while (true) {
// Assumptions covered by branches above;
// lo != blockNumber (that would imply the node already exists)
// lo > 0 (that would imply we can reach the head)
if (lo < blockNumber) break;
hi = lo;
lo = lo - self.nodes[lo].prevOffset;
}
uint64 deltaBefore = blockNumber - lo;
uint64 deltaAfter = hi - blockNumber;
self.nodes[lo].nextOffset = deltaBefore;
cur.prevOffset = deltaBefore;
cur.nextOffset = deltaAfter;
self.nodes[hi].prevOffset = deltaAfter;
}
/// @notice Subtract an amount from the cumulative sum at a given block number
/// @param self The storage reference
/// @param blockNumber The block number to update
/// @param amount The amount to subtract. Note the smaller bit width
function sub(Storage storage self, uint64 blockNumber, uint64 amount) internal {
if (amount == 0) return;
Node storage cur = self.nodes[blockNumber];
assert(cur.sum >= amount);
cur.sum -= amount;
if (cur.sum == 0) {
(uint64 nextOffset, uint64 prevOffset) = (cur.nextOffset, cur.prevOffset);
delete self.nodes[blockNumber];
// Pointer fixup
if (nextOffset == 0 && prevOffset == 0) {
self.head = 0;
self.tail = 0;
return;
}
if (nextOffset == 0) {
self.tail = blockNumber - prevOffset;
self.nodes[self.tail].nextOffset = 0;
return;
}
if (prevOffset == 0) {
self.head = blockNumber + nextOffset;
self.nodes[self.head].prevOffset = 0;
return;
}
uint64 prev = blockNumber - prevOffset;
uint64 next = blockNumber + nextOffset;
uint64 delta = next - prev;
self.nodes[prev].nextOffset = delta;
self.nodes[next].prevOffset = delta;
}
}
/// @notice Get the cumulative sum at a given block number
/// @param self The storage reference
/// @param blockNumber The block number to query
/// @return The cumulative sum up to the block number
function sum(Storage storage self, uint64 blockNumber) internal view returns (uint256) {
if (self.head == 0) return 0;
if (self.head > blockNumber) return 0;
uint256 _sum = 0;
uint64 next = self.head;
while (true) {
Node memory cur = self.nodes[next];
_sum += cur.sum;
if (cur.nextOffset == 0) break;
next += cur.nextOffset;
if (next > blockNumber) break;
}
return _sum;
}
}
IDepositContract.sol 41 lines
// ┏━━━┓━┏┓━┏┓━━┏━━━┓━━┏━━━┓━━━━┏━━━┓━━━━━━━━━━━━━━━━━━━┏┓━━━━━┏━━━┓━━━━━━━━━┏┓━━━━━━━━━━━━━━┏┓━
// ┃┏━━┛┏┛┗┓┃┃━━┃┏━┓┃━━┃┏━┓┃━━━━┗┓┏┓┃━━━━━━━━━━━━━━━━━━┏┛┗┓━━━━┃┏━┓┃━━━━━━━━┏┛┗┓━━━━━━━━━━━━┏┛┗┓
// ┃┗━━┓┗┓┏┛┃┗━┓┗┛┏┛┃━━┃┃━┃┃━━━━━┃┃┃┃┏━━┓┏━━┓┏━━┓┏━━┓┏┓┗┓┏┛━━━━┃┃━┗┛┏━━┓┏━┓━┗┓┏┛┏━┓┏━━┓━┏━━┓┗┓┏┛
// ┃┏━━┛━┃┃━┃┏┓┃┏━┛┏┛━━┃┃━┃┃━━━━━┃┃┃┃┃┏┓┃┃┏┓┃┃┏┓┃┃━━┫┣┫━┃┃━━━━━┃┃━┏┓┃┏┓┃┃┏┓┓━┃┃━┃┏┛┗━┓┃━┃┏━┛━┃┃━
// ┃┗━━┓━┃┗┓┃┃┃┃┃┃┗━┓┏┓┃┗━┛┃━━━━┏┛┗┛┃┃┃━┫┃┗┛┃┃┗┛┃┣━━┃┃┃━┃┗┓━━━━┃┗━┛┃┃┗┛┃┃┃┃┃━┃┗┓┃┃━┃┗┛┗┓┃┗━┓━┃┗┓
// ┗━━━┛━┗━┛┗┛┗┛┗━━━┛┗┛┗━━━┛━━━━┗━━━┛┗━━┛┃┏━┛┗━━┛┗━━┛┗┛━┗━┛━━━━┗━━━┛┗━━┛┗┛┗┛━┗━┛┗┛━┗━━━┛┗━━┛━┗━┛
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┃┃━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┗┛━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SPDX-License-Identifier: CC0-1.0
pragma solidity *;
// This interface is designed to be compatible with the Vyper version.
/// @notice This is the Ethereum 2.0 deposit contract interface.
/// For more information see the Phase 0 specification under https://github.com/ethereum/eth2.0-specs
interface IDepositContract {
/// @notice A processed deposit event.
event DepositEvent(bytes pubkey, bytes withdrawal_credentials, bytes amount, bytes signature, bytes index);
/// @notice Submit a Phase 0 DepositData object.
/// @param pubkey A BLS12-381 public key.
/// @param withdrawal_credentials Commitment to a public key for withdrawals.
/// @param signature A BLS12-381 signature.
/// @param deposit_data_root The SHA-256 hash of the SSZ-encoded DepositData object.
/// Used as a protection against malformed input.
function deposit(
bytes calldata pubkey,
bytes calldata withdrawal_credentials,
bytes calldata signature,
bytes32 deposit_data_root
) external payable;
/// @notice Query the current deposit root hash.
/// @return The deposit root hash.
function get_deposit_root() external view returns (bytes32);
/// @notice Query the current deposit count.
/// @return The deposit count encoded as a little endian 64-bit number.
function get_deposit_count() external view returns (bytes memory);
}
WithdrawalOracle.sol 96 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import {CumulativeSum} from "./CumulativeSum.sol";
struct ExecutionWithdrawal {
// Using smaller types for compactness
uint64 blockNumber;
uint48 amountGwei;
}
// This contract maintains two data structures:
// - validatorWithdrawals: simple KV mapping from validatorIndex to ExecutionWithdrawal that can be
// overwritten in place
// - _cumulativeWithdrawals: an aggregated sum per block of reserved withdrawal amounts.
// Values here must be carefully updated, deducting any difference in case of
// an update rather than a new insert
abstract contract WithdrawalOracle {
using CumulativeSum for CumulativeSum.Storage;
mapping(uint64 validatorIndex => ExecutionWithdrawal) public validatorWithdrawals;
CumulativeSum.Storage private _cumulativeWithdrawals;
uint64 internal constant UNSET_BLOCK_NUMBER = 0;
/// @notice Get the cumulative sum of withdrawals up to a block number
/// @param blockNumber The block number to query
/// @return The cumulative sum of withdrawals up to the block number in Gwei
function _sum(uint64 blockNumber) internal view returns (uint256) {
return _cumulativeWithdrawals.sum(blockNumber);
}
/// @notice Update the withdrawal amount for a validator
/// @dev This functions supports insertions, updates and deletions of withdrawals. Deletions happen by setting the blockNumber and/or amountGwei to 0.
/// @param validatorIndex The index of the validator
/// @param blockNumber The block number when the withdrawal will be executed.
/// @param amountGwei The amount of Gwei that will be withdrawn.
function _upsert(uint64 validatorIndex, uint64 blockNumber, uint48 amountGwei) internal {
// "early return"; Directly delete the withdrawal
if (blockNumber == UNSET_BLOCK_NUMBER) return _delete(validatorIndex);
if (amountGwei == 0) return _delete(validatorIndex);
// We can now assume that any stored withdrawal has a blockNumber > 0 and amountGwei > 0
ExecutionWithdrawal storage w = validatorWithdrawals[validatorIndex];
// Cache the previous amount as we modify it below
uint48 prevAmount = w.amountGwei;
// Update only amount, since the withdrawal already exists with the same blockNumber
if (w.blockNumber == blockNumber) {
if (prevAmount == amountGwei) return; // you just did an expensive no-op
// We can now assume the amounts are different
// Update the withdrawal with the new amount
w.amountGwei = amountGwei;
// Adjust cumulative sum
if (prevAmount > amountGwei) {
_cumulativeWithdrawals.sub(blockNumber, prevAmount - amountGwei);
} else {
_cumulativeWithdrawals.add(blockNumber, amountGwei - prevAmount);
}
return;
}
// If the withdrawal is new, the blockNumber read from storage will be UNSET_BLOCK_NUMBER
// however since we are wanting to set a blockNumber that was not stored (the above check)
// clean up previous withdrawal amount before applying a new one
if (w.blockNumber != UNSET_BLOCK_NUMBER) {
_cumulativeWithdrawals.sub(w.blockNumber, prevAmount);
}
validatorWithdrawals[validatorIndex] = ExecutionWithdrawal({blockNumber: blockNumber, amountGwei: amountGwei});
_cumulativeWithdrawals.add(blockNumber, amountGwei);
}
/// @notice Delete a withdrawal that has already been read into memory
/// @param validatorIndex The index of the validator
/// @param w The withdrawal to delete that was already read into memory
function _delete(uint64 validatorIndex, ExecutionWithdrawal memory w) internal {
delete validatorWithdrawals[validatorIndex];
// Only update cumulativeSum if the withdrawal was had an amount, otherwise save some gas traversing the structure
if (w.amountGwei > 0) _cumulativeWithdrawals.sub(w.blockNumber, w.amountGwei);
}
/// @notice Delete a withdrawal
/// @param validatorIndex The index of the validator
function _delete(uint64 validatorIndex) internal {
ExecutionWithdrawal memory w = validatorWithdrawals[validatorIndex];
// Optimisation; no need to try and delete a non-existent withdrawal
if (w.amountGwei == 0 && w.blockNumber == UNSET_BLOCK_NUMBER) return;
return _delete(validatorIndex, w);
}
}
AccessControlExtension.sol 179 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {AccessControlEnumerable} from "@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";
import {AccessControlDefaultAdminRules} from
"@openzeppelin/contracts/access/extensions/AccessControlDefaultAdminRules.sol";
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
contract AccessControlExtension is AccessControlDefaultAdminRules, AccessControlEnumerable {
bytes32 public constant ROLE_PROPOSER_ROLE = keccak256("ROLE_PROPOSER_ROLE");
using EnumerableSet for EnumerableSet.AddressSet;
event AccessControlProposedRole(bytes32 role, address account);
event AccessControlAcceptedRole(bytes32 role, address account);
event AccessControlRejectedRole(bytes32 role, address account);
event AccessControlProposedRoleAdmin(bytes32 role, bytes32 adminRole);
event AccessControlAcceptedRoleAdmin(bytes32 role, bytes32 adminRole);
event AccessControlRejectedRoleAdmin(bytes32 role, bytes32 adminRole);
mapping(bytes32 role => EnumerableSet.AddressSet) private _roleProposals;
mapping(bytes32 role => bytes32 adminRole) private _roleAdminsProposal;
constructor(uint48 initialDelay, address initialDefaultAdmin)
AccessControlDefaultAdminRules(initialDelay, initialDefaultAdmin)
{}
/// @dev Overriding the default admin transfer to prevent setting the default admin to address(0)
function _beginDefaultAdminTransfer(address newDefaultAdmin) internal override {
if (newDefaultAdmin == address(0)) {
revert AccessControlEnforcedDefaultAdminRules();
}
super._beginDefaultAdminTransfer(newDefaultAdmin);
}
// Union overrides
function _grantRole(bytes32 role, address account)
internal
override(AccessControlDefaultAdminRules, AccessControlEnumerable)
returns (bool)
{
return super._grantRole(role, account);
}
function _revokeRole(bytes32 role, address account)
internal
override(AccessControlDefaultAdminRules, AccessControlEnumerable)
returns (bool)
{
return super._revokeRole(role, account);
}
function _setRoleAdmin(bytes32 role, bytes32 adminRole)
internal
override(AccessControlDefaultAdminRules, AccessControl)
{
super._setRoleAdmin(role, adminRole);
}
function grantRole(bytes32 role, address account)
public
override(AccessControlDefaultAdminRules, AccessControl, IAccessControl)
{
return super.grantRole(role, account);
}
function revokeRole(bytes32 role, address account)
public
override(AccessControlDefaultAdminRules, AccessControl, IAccessControl)
{
return super.revokeRole(role, account);
}
function renounceRole(bytes32 role, address account)
public
override(AccessControlDefaultAdminRules, AccessControl, IAccessControl)
{
return super.renounceRole(role, account);
}
function supportsInterface(bytes4 interfaceId)
public
view
override(AccessControlDefaultAdminRules, AccessControlEnumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
modifier onlyRoleOrAdmin(bytes32 role) {
if (!hasRole(role, _msgSender()) && !hasRole(DEFAULT_ADMIN_ROLE, _msgSender())) {
revert AccessControlUnauthorizedAccount(_msgSender(), role);
}
_;
}
modifier anyOfRoles2OrAdmin(bytes32 role1, bytes32 role2) {
if (!hasRole(role1, _msgSender()) && !hasRole(role2, _msgSender()) && !hasRole(DEFAULT_ADMIN_ROLE, _msgSender())) {
revert AccessControlUnauthorizedAccount(_msgSender(), role1);
}
_;
}
/// @notice Read the role proposal at a given index. To get the length see `getRoleProposalsCount`.
/// @param role The role to get the proposals for
/// @param index The index of the proposal to get
/// @return The address of the proposed account
function getRoleProposal(bytes32 role, uint256 index) public view returns (address) {
return _roleProposals[role].at(index);
}
/// @notice Get the number of role proposals
/// @param role The role to get the proposals count for
/// @return The number of proposals for the role
function getRoleProposalsCount(bytes32 role) public view returns (uint256) {
return _roleProposals[role].length();
}
/// @notice Propose `role` for `account`
/// @param role The role to propose
/// @param account The account to propose the role for
function proposeRole(bytes32 role, address account) public onlyRoleOrAdmin(ROLE_PROPOSER_ROLE) {
_roleProposals[role].add(account);
emit AccessControlProposedRole(role, account);
}
/// @notice Accept the role proposal
/// @param role The role to accept
/// @param account The account to accept the role for
function acceptRole(bytes32 role, address account) public onlyRoleOrAdmin(getRoleAdmin(role)) {
bool wasProposed = _roleProposals[role].remove(account);
require(wasProposed, AccessControlBadConfirmation());
_grantRole(role, account);
emit AccessControlAcceptedRole(role, account);
}
/// @notice Reject the role proposal
/// @param role The role to reject
/// @param account The account to reject the role for
function rejectRole(bytes32 role, address account) public anyOfRoles2OrAdmin(ROLE_PROPOSER_ROLE, getRoleAdmin(role)) {
_roleProposals[role].remove(account);
emit AccessControlRejectedRole(role, account);
}
/// @notice Propose a new role admin for a role. This means assigning a new role that can manage memebers of subject role.
/// @param role The role to be administered by `adminRole`
/// @param adminRole The role that will be able to manage the members of `role`
function proposeRoleAdmin(bytes32 role, bytes32 adminRole) public onlyRoleOrAdmin(ROLE_PROPOSER_ROLE) {
_roleAdminsProposal[role] = adminRole;
emit AccessControlProposedRoleAdmin(role, adminRole);
}
/// @notice Accept the role admin proposal
/// @param role The role to accept the admin for
/// @param adminRole The role that will be able to manage the members of `role`. This is required such that the proposed adminRole does not change during the acceptance.
function acceptRoleAdmin(bytes32 role, bytes32 adminRole) public onlyRoleOrAdmin(getRoleAdmin(role)) {
bytes32 _proposedAdminRole = _roleAdminsProposal[role];
require(_proposedAdminRole == adminRole, AccessControlBadConfirmation());
delete _roleAdminsProposal[role];
_setRoleAdmin(role, adminRole);
emit AccessControlAcceptedRoleAdmin(role, adminRole);
}
/// @notice Reject the role admin proposal
/// @param role The role to reject the admin for
/// @param adminRole The role that will be able to manage the members of `role`. This is required such that the proposed adminRole does not change during the rejection.
function rejectRoleAdmin(bytes32 role, bytes32 adminRole)
public
anyOfRoles2OrAdmin(ROLE_PROPOSER_ROLE, getRoleAdmin(role))
{
_roleAdminsProposal[role] = bytes32(0);
emit AccessControlRejectedRoleAdmin(role, adminRole);
}
}
NSTokenizedStakingVault.sol 371 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import {AccessControlExtension} from "./AccessControlExtension.sol";
import {IDepositContract} from "./IDepositContract.sol";
import "./BeaconHelpers.sol" as BeaconHelpers;
import {WithdrawalOracle, ExecutionWithdrawal} from "./WithdrawalOracle.sol";
import {UnorderedSet} from "./UnorderedSet.sol";
contract NSTokenizedStakingVault is AccessControlExtension, WithdrawalOracle {
struct ExitProposal {
// Ultimate beneficiary of the final withdrawals
address beneficiary;
// Deadline for the proposal in seconds since epoch
uint96 deadline;
// Indices of the validators to exit
uint64[] validatorIndices;
}
struct DepositData {
bytes pubkey;
bytes withdrawalCredentials;
bytes signature;
bytes32 depositDataRoot;
}
bytes32 public constant DEPOSITOR_ROLE = keccak256("DEPOSITOR_ROLE");
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
bytes32 public constant ORACLE_ROLE = keccak256("ORACLE_ROLE");
error NoMev();
error AccessDenied();
error InvalidWithdrawalCredentials();
error InsufficientFunds();
error InvalidAddressZero();
error ProposalExists();
error ProposalExpired();
error ProposalAlreadyAccepted();
error ProposalNotFound();
/// @notice Emitted when a depositor sends funds to the vault. This should prompt the operator to queue validators for activation.
event Deposit(address indexed depositor, uint256 amount);
/// @notice Emitted when a depositor withdraws pending deposits from the vault.
event DepositWithdrawn(address indexed depositor, uint256 amount);
/// @notice Emitted when the rewards recipient is updated.
event RewardsRecipientChanged(address indexed recipient);
/// @notice Emitted when someone collects rewards from the vault.
event RewardsCollected(address indexed recipient, uint256 amount);
/// @notice Emitted when a validator is queued for activation after forwarding Eth to the deposit contract.
event ValidatorQueued(bytes pubkey);
/// @notice Emitted when a proposal is created by the operator to exit validators.
event Proposal(bytes32 proposalId);
/// @notice Emitted when a proposal is accepted, and validators should exit, by the depositor. This should prompt the operator to broadcast a voluntary exit.
event ProposalAccepted(bytes32 proposalId);
/// @notice Emitted when a proposal is rejected, either by the depositor, operator or if the deadline has passed.
event ProposalRejected(bytes32 proposalId);
/// @notice Emitted when a withdrawal is claimed for a beneficiary. Multiple events for the same proposalId may be emitted, as they can be claimed over multiple transactions
event ClaimedWithdrawal(address indexed beneficiary, bytes32 proposalId, uint256 amount);
/// @notice Whether the vault accepts MEV rewards. Can be read by the operator for node configuration.
bool public immutable isMevEnabled;
/// @notice The withdrawal credentials for the deposit contract. Can be read by the operator when generating deposit data.
bytes32 public immutable withdrawalCredential;
/// @notice The deposit contract for the beacon chain.
IDepositContract public immutable depositContract;
/// @notice The address to send rewards to. Defaults to the vault itself. Can be updated by the depositor with `setRewardsRecipient`.
address payable public rewardsRecipient;
/// @notice The total amount of eth pending in the vault.
uint256 public pendingDeposits;
struct ExitProposalStatus {
ExitProposal proposal;
bool accepted;
}
mapping(bytes32 id => ExitProposalStatus) public exitProposals;
mapping(address beneficiary => bytes32[]) public claims;
/// @param _depositContract The deposit contract for the beacon chain.
/// @param _isMevEnabled Whether the vault accepts MEV rewards.
constructor(IDepositContract _depositContract, bool _isMevEnabled, uint48 initialDelay)
AccessControlExtension(initialDelay, msg.sender)
{
depositContract = _depositContract;
isMevEnabled = _isMevEnabled;
rewardsRecipient = payable(address(this));
withdrawalCredential = BeaconHelpers.eth1WithdrawalCredential(address(this));
}
function _transfer(address payable recipient, uint256 amount) internal {
(bool success,) = recipient.call{value: amount}("");
require(success);
}
/// @notice Returns the total rewards available for harvesting.
/// @dev This is the total balance of the contract minus the pending deposits and pending withdrawals at the current block.
function rewards() public view returns (uint256) {
uint256 reserved = pendingDeposits + pendingWithdrawals();
// In case of underflow, return 0
if (address(this).balance < reserved) return 0;
unchecked {
return address(this).balance - reserved;
}
}
/// @notice Returns the total withdrawals available from the current block
function pendingWithdrawals() public view returns (uint256) {
return WithdrawalOracle._sum(uint64(block.number)) * 1 gwei;
}
/// @notice Deposit funds into the staking vault for validator creation.
function deposit() external payable onlyRole(DEPOSITOR_ROLE) {
pendingDeposits += msg.value;
emit Deposit(_msgSender(), msg.value);
}
/// @notice Withdraw funds from the staking vault before they are used for validator creation.
function withdrawDeposit(uint256 wad) external onlyRole(DEPOSITOR_ROLE) {
require(wad <= pendingDeposits, InsufficientFunds());
pendingDeposits -= wad;
_transfer(payable(_msgSender()), wad);
emit DepositWithdrawn(_msgSender(), wad);
}
/// @notice Set the rewards recipient for the vault.
function setRewardsRecipient(address payable recipient) external onlyRole(DEPOSITOR_ROLE) {
require(recipient != address(0), InvalidAddressZero());
rewardsRecipient = recipient;
emit RewardsRecipientChanged(recipient);
}
/// @dev Harvest any accumulated rewards.
function collectRewards() external {
address payable _rewardsRecipient = rewardsRecipient;
uint256 _rewards = rewards();
_transfer(_rewardsRecipient, _rewards);
emit RewardsCollected(_rewardsRecipient, _rewards);
}
/// @notice Default function for receiving Ether (ie. MEV rewards)
receive() external payable {
require(isMevEnabled, NoMev());
}
/// @notice Helper function for deriving the deterministic id of an exit proposal.
function exitProposalId(ExitProposal memory proposal) public pure returns (bytes32) {
return keccak256(abi.encode(proposal));
}
/// @notice Propose an exit for a list of validators. Note that the proposal must have the list of validators deterministically sorted, whether numerically or (preferably) by first available withdrawal. Making two proposals with the same validator indices will lead to undefined behaviour when claiming withdrawals.
function proposeExit(ExitProposal calldata proposal) external onlyRole(OPERATOR_ROLE) returns (bytes32) {
require(proposal.beneficiary != address(0), InvalidAddressZero());
bytes32 id = exitProposalId(proposal);
require(exitProposals[id].proposal.beneficiary == address(0), ProposalExists());
exitProposals[id] = ExitProposalStatus(proposal, false);
emit Proposal(id);
return id;
}
/// @notice Accepts an exit proposal, assigning future withdrawals for the specific validators to the beneficiary.
function acceptExit(bytes32 proposalId) external onlyRole(DEPOSITOR_ROLE) {
ExitProposalStatus storage ps = exitProposals[proposalId];
require(ps.proposal.beneficiary != address(0), ProposalNotFound());
require(ps.accepted == false, ProposalAlreadyAccepted());
require(ps.proposal.deadline >= block.timestamp, ProposalExpired());
ps.accepted = true;
claims[ps.proposal.beneficiary].push(proposalId);
emit ProposalAccepted(proposalId);
}
/// @notice Rejects an exit proposal, either by the depositor or if the deadline has passed. Only proposals that haven't been accepted can be rejected.
/// @param proposalId The id of the proposal to reject.
function rejectExit(bytes32 proposalId) external {
require(exitProposals[proposalId].accepted == false, ProposalAlreadyAccepted());
// Check deadline, Operator or Depositor
if (
exitProposals[proposalId].proposal.deadline < block.timestamp || hasRole(DEPOSITOR_ROLE, _msgSender())
|| hasRole(OPERATOR_ROLE, _msgSender())
) {
delete exitProposals[proposalId];
emit ProposalRejected(proposalId);
return;
}
// fallback
revert AccessDenied();
}
/// @notice Transfers pending claims for specific beneficiary.
/// @param beneficiary The beneficiary of the claims.
function claimWithdrawals(address beneficiary) external {
uint256 gweiSum = 0;
// Notice this array is copied into memory, such that any mutation to storage do not impact iteration
bytes32[] memory beneficiaryClaims = claims[beneficiary];
for (uint256 i = 0; i < beneficiaryClaims.length; i++) {
gweiSum += _claimProposal(beneficiaryClaims[i]);
}
// Do not perform a no-op transfer
if (gweiSum > 0) _transfer(payable(beneficiary), gweiSum * 1 gwei);
}
// @notice Transfers pending claims for specific proposal to the beneficiary.
function claimWithdrawals(bytes32 proposalId) external {
ExitProposalStatus storage ps = exitProposals[proposalId];
require(ps.accepted == true, ProposalNotFound());
address beneficiary = ps.proposal.beneficiary;
uint256 gweiSum = _claimProposal(proposalId);
// Do not perform a no-op transfer
if (gweiSum > 0) _transfer(payable(beneficiary), gweiSum * 1 gwei);
}
/// @notice Internal function for claiming a single proposal including cleanup logic. Returns the total amount of Gwei claimed.
function _claimProposal(bytes32 proposalId) internal returns (uint256) {
uint256 gweiSum = 0;
ExitProposalStatus storage ps = exitProposals[proposalId];
// Return early if the proposal is not accepted
if (ps.accepted == false) return gweiSum;
ExitProposal storage proposal = ps.proposal;
// Flag to determine if any validators were claimed. Used when deciding to emit an event with the claimed sum
bool claimedAnyValidator = false;
// Loop over each validator index in a proposal from the end.
// Doing it from the end allows for some minor gas optimisations when removing elements.
uint256 length = proposal.validatorIndices.length;
// Start at the end of the list
uint256 i = length;
// Bespoke loop, since Solidity for loops will underflow when iterating from the end
while (true) {
if (i == 0) break;
// Underflow is impossible given the above condition
unchecked {
i--;
}
uint64 idx = proposal.validatorIndices[i];
ExecutionWithdrawal memory withdrawal = validatorWithdrawals[idx];
// Not yet received an oracle update for this validator, so skip.
if (withdrawal.blockNumber == WithdrawalOracle.UNSET_BLOCK_NUMBER) continue;
// Validator is ready to be withdrawn.
if (withdrawal.blockNumber <= block.number) {
claimedAnyValidator = true;
// Overflow is impossible given the relative bit widths of the variables
unchecked {
gweiSum += withdrawal.amountGwei;
}
WithdrawalOracle._delete(idx, withdrawal);
// Removing a validator, which may move elements around so we need to use the returned length and index
(i, length) = UnorderedSet.removeIndexUnchecked(proposal.validatorIndices, i, length);
}
}
// Cache the beneficiary address as it may be deleted below, but is also needed for the event
address beneficiary = proposal.beneficiary;
// All validators from the given proposal have been claimed, so we can cleanup any references
bool allValidatorsClaimed = proposal.validatorIndices.length == 0;
if (allValidatorsClaimed) {
// Delete the proposal from the beneficiary's list of claims
UnorderedSet.removeValue(claims[beneficiary], proposalId);
// Delete the proposal itself
delete exitProposals[proposalId];
}
if (claimedAnyValidator) emit ClaimedWithdrawal(beneficiary, proposalId, gweiSum * 1 gwei);
return gweiSum;
}
/// @notice Queue a validator for activation by forwarding 32 eth and the deposit data to the deposit contract.
/// @dev Internal function with preconditions checked in calling functions
function _queueValidator(DepositData calldata _deposit) internal {
bool isValidCredential = bytes32(_deposit.withdrawalCredentials) == withdrawalCredential;
require(isValidCredential, InvalidWithdrawalCredentials());
depositContract.deposit{value: 32 ether}(
_deposit.pubkey, _deposit.withdrawalCredentials, _deposit.signature, _deposit.depositDataRoot
);
emit ValidatorQueued(_deposit.pubkey);
}
/// @notice Queue a batch of validators for activation. See the singular function for more details.
/// @param deposits The list of deposits to queue.
/// @dev This function is only callable by the operator role.
function queueValidator(DepositData[] calldata deposits) external onlyRole(OPERATOR_ROLE) {
require(pendingDeposits >= deposits.length * 32 ether, InsufficientFunds());
// Underflow is checked by the require above
unchecked {
pendingDeposits -= deposits.length * 32 ether;
}
for (uint256 i = 0; i < deposits.length; i++) {
_queueValidator(deposits[i]);
}
}
/// @notice Queue a validator for activation by forwarding 32 eth and the deposit data to the deposit contract. Notice the withdrawal credentials must match the vault's credentials.
/// @param _deposit The deposit data for the validator.
/// @dev This function is only callable by the operator role.
function queueValidator(DepositData calldata _deposit) external onlyRole(OPERATOR_ROLE) {
require(pendingDeposits >= 32 ether, InsufficientFunds());
// Underflow is checked by the require above
unchecked {
pendingDeposits -= 32 ether;
}
_queueValidator(_deposit);
}
struct Withdrawal {
uint64 validatorIndex;
uint64 blockNumber;
uint48 amountGwei;
}
/// @notice Update a batch of withdrawals for validators available at specific blocks. Note that the transaction costs are minimized by sorting the withdrawals from first to last. See the singular function for more details.
/// @param withdrawals The list of withdrawals to update.
/// @dev This function is only callable by the oracle role.
function updateWithdrawal(Withdrawal[] calldata withdrawals) external onlyRole(ORACLE_ROLE) {
for (uint256 i = 0; i < withdrawals.length; i++) {
WithdrawalOracle._upsert(withdrawals[i].validatorIndex, withdrawals[i].blockNumber, withdrawals[i].amountGwei);
}
}
/// @notice Update a withdrawal for a validator available at a specific block. Errorneous updates can be changed by posting another update with the correct block/amount. An update with amount and block 0 will remove the withdrawal.
/// @param validatorIndex The index of the validator
/// @param blockNumber The block number when the withdrawal will be executed.
/// @param amountGwei The amount of Gwei that will be withdrawn.
/// @dev This function is only callable by the oracle role.
function updateWithdrawal(uint64 validatorIndex, uint64 blockNumber, uint48 amountGwei)
external
onlyRole(ORACLE_ROLE)
{
WithdrawalOracle._upsert(validatorIndex, blockNumber, amountGwei);
}
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Math.sol 415 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @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 towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
return a / b;
}
// (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 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
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.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 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.
uint256 twos = denominator & (0 - denominator);
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 (unsignedRoundsUp(rounding) && 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
* towards zero.
*
* 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 + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* 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 + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* 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 + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* 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 + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}
IERC5313.sol 16 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5313.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface for the Light Contract Ownership Standard.
*
* A standardized minimal interface required to identify an account that controls a contract
*/
interface IERC5313 {
/**
* @dev Gets the address of the owner.
*/
function owner() external view returns (address);
}
SafeCast.sol 1153 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
}
AccessControl.sol 209 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
mapping(bytes32 role => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with an {AccessControlUnauthorizedAccount} error including the required role.
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual returns (bool) {
return _roles[role].hasRole[account];
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
* is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
* is missing `role`.
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert AccessControlUnauthorizedAccount(account, role);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
if (callerConfirmation != _msgSender()) {
revert AccessControlBadConfirmation();
}
_revokeRole(role, callerConfirmation);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
if (!hasRole(role, account)) {
_roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
return false;
}
}
/**
* @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
if (hasRole(role, account)) {
_roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}
IAccessControl.sol 98 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/IAccessControl.sol)
pragma solidity ^0.8.20;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev The `account` is missing a role.
*/
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
/**
* @dev The caller of a function is not the expected one.
*
* NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
*/
error AccessControlBadConfirmation();
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, 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 `callerConfirmation`.
*/
function renounceRole(bytes32 role, address callerConfirmation) external;
}
ERC165.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement 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);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
EnumerableSet.sol 378 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.20;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position is the index of the value in the `values` array plus 1.
// Position 0 is used to mean a value is not in the set.
mapping(bytes32 value => uint256) _positions;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._positions[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We cache the value's position to prevent multiple reads from the same storage slot
uint256 position = set._positions[value];
if (position != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 valueIndex = position - 1;
uint256 lastIndex = set._values.length - 1;
if (valueIndex != lastIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the lastValue to the index where the value to delete is
set._values[valueIndex] = lastValue;
// Update the tracked position of the lastValue (that was just moved)
set._positions[lastValue] = position;
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the tracked position for the deleted slot
delete set._positions[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._positions[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}
AccessControlEnumerable.sol 70 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/extensions/AccessControlEnumerable.sol)
pragma solidity ^0.8.20;
import {IAccessControlEnumerable} from "./IAccessControlEnumerable.sol";
import {AccessControl} from "../AccessControl.sol";
import {EnumerableSet} from "../../utils/structs/EnumerableSet.sol";
/**
* @dev Extension of {AccessControl} that allows enumerating the members of each role.
*/
abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
using EnumerableSet for EnumerableSet.AddressSet;
mapping(bytes32 role => EnumerableSet.AddressSet) private _roleMembers;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) public view virtual returns (address) {
return _roleMembers[role].at(index);
}
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) public view virtual returns (uint256) {
return _roleMembers[role].length();
}
/**
* @dev Overload {AccessControl-_grantRole} to track enumerable memberships
*/
function _grantRole(bytes32 role, address account) internal virtual override returns (bool) {
bool granted = super._grantRole(role, account);
if (granted) {
_roleMembers[role].add(account);
}
return granted;
}
/**
* @dev Overload {AccessControl-_revokeRole} to track enumerable memberships
*/
function _revokeRole(bytes32 role, address account) internal virtual override returns (bool) {
bool revoked = super._revokeRole(role, account);
if (revoked) {
_roleMembers[role].remove(account);
}
return revoked;
}
}
IAccessControlEnumerable.sol 31 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/extensions/IAccessControlEnumerable.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "../IAccessControl.sol";
/**
* @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
*/
interface IAccessControlEnumerable is IAccessControl {
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) external view returns (address);
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) external view returns (uint256);
}
AccessControlDefaultAdminRules.sol 396 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/extensions/AccessControlDefaultAdminRules.sol)
pragma solidity ^0.8.20;
import {IAccessControlDefaultAdminRules} from "./IAccessControlDefaultAdminRules.sol";
import {AccessControl, IAccessControl} from "../AccessControl.sol";
import {SafeCast} from "../../utils/math/SafeCast.sol";
import {Math} from "../../utils/math/Math.sol";
import {IERC5313} from "../../interfaces/IERC5313.sol";
/**
* @dev Extension of {AccessControl} that allows specifying special rules to manage
* the `DEFAULT_ADMIN_ROLE` holder, which is a sensitive role with special permissions
* over other roles that may potentially have privileged rights in the system.
*
* If a specific role doesn't have an admin role assigned, the holder of the
* `DEFAULT_ADMIN_ROLE` will have the ability to grant it and revoke it.
*
* This contract implements the following risk mitigations on top of {AccessControl}:
*
* * Only one account holds the `DEFAULT_ADMIN_ROLE` since deployment until it's potentially renounced.
* * Enforces a 2-step process to transfer the `DEFAULT_ADMIN_ROLE` to another account.
* * Enforces a configurable delay between the two steps, with the ability to cancel before the transfer is accepted.
* * The delay can be changed by scheduling, see {changeDefaultAdminDelay}.
* * It is not possible to use another role to manage the `DEFAULT_ADMIN_ROLE`.
*
* Example usage:
*
* ```solidity
* contract MyToken is AccessControlDefaultAdminRules {
* constructor() AccessControlDefaultAdminRules(
* 3 days,
* msg.sender // Explicit initial `DEFAULT_ADMIN_ROLE` holder
* ) {}
* }
* ```
*/
abstract contract AccessControlDefaultAdminRules is IAccessControlDefaultAdminRules, IERC5313, AccessControl {
// pending admin pair read/written together frequently
address private _pendingDefaultAdmin;
uint48 private _pendingDefaultAdminSchedule; // 0 == unset
uint48 private _currentDelay;
address private _currentDefaultAdmin;
// pending delay pair read/written together frequently
uint48 private _pendingDelay;
uint48 private _pendingDelaySchedule; // 0 == unset
/**
* @dev Sets the initial values for {defaultAdminDelay} and {defaultAdmin} address.
*/
constructor(uint48 initialDelay, address initialDefaultAdmin) {
if (initialDefaultAdmin == address(0)) {
revert AccessControlInvalidDefaultAdmin(address(0));
}
_currentDelay = initialDelay;
_grantRole(DEFAULT_ADMIN_ROLE, initialDefaultAdmin);
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlDefaultAdminRules).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC5313-owner}.
*/
function owner() public view virtual returns (address) {
return defaultAdmin();
}
///
/// Override AccessControl role management
///
/**
* @dev See {AccessControl-grantRole}. Reverts for `DEFAULT_ADMIN_ROLE`.
*/
function grantRole(bytes32 role, address account) public virtual override(AccessControl, IAccessControl) {
if (role == DEFAULT_ADMIN_ROLE) {
revert AccessControlEnforcedDefaultAdminRules();
}
super.grantRole(role, account);
}
/**
* @dev See {AccessControl-revokeRole}. Reverts for `DEFAULT_ADMIN_ROLE`.
*/
function revokeRole(bytes32 role, address account) public virtual override(AccessControl, IAccessControl) {
if (role == DEFAULT_ADMIN_ROLE) {
revert AccessControlEnforcedDefaultAdminRules();
}
super.revokeRole(role, account);
}
/**
* @dev See {AccessControl-renounceRole}.
*
* For the `DEFAULT_ADMIN_ROLE`, it only allows renouncing in two steps by first calling
* {beginDefaultAdminTransfer} to the `address(0)`, so it's required that the {pendingDefaultAdmin} schedule
* has also passed when calling this function.
*
* After its execution, it will not be possible to call `onlyRole(DEFAULT_ADMIN_ROLE)` functions.
*
* NOTE: Renouncing `DEFAULT_ADMIN_ROLE` will leave the contract without a {defaultAdmin},
* thereby disabling any functionality that is only available for it, and the possibility of reassigning a
* non-administrated role.
*/
function renounceRole(bytes32 role, address account) public virtual override(AccessControl, IAccessControl) {
if (role == DEFAULT_ADMIN_ROLE && account == defaultAdmin()) {
(address newDefaultAdmin, uint48 schedule) = pendingDefaultAdmin();
if (newDefaultAdmin != address(0) || !_isScheduleSet(schedule) || !_hasSchedulePassed(schedule)) {
revert AccessControlEnforcedDefaultAdminDelay(schedule);
}
delete _pendingDefaultAdminSchedule;
}
super.renounceRole(role, account);
}
/**
* @dev See {AccessControl-_grantRole}.
*
* For `DEFAULT_ADMIN_ROLE`, it only allows granting if there isn't already a {defaultAdmin} or if the
* role has been previously renounced.
*
* NOTE: Exposing this function through another mechanism may make the `DEFAULT_ADMIN_ROLE`
* assignable again. Make sure to guarantee this is the expected behavior in your implementation.
*/
function _grantRole(bytes32 role, address account) internal virtual override returns (bool) {
if (role == DEFAULT_ADMIN_ROLE) {
if (defaultAdmin() != address(0)) {
revert AccessControlEnforcedDefaultAdminRules();
}
_currentDefaultAdmin = account;
}
return super._grantRole(role, account);
}
/**
* @dev See {AccessControl-_revokeRole}.
*/
function _revokeRole(bytes32 role, address account) internal virtual override returns (bool) {
if (role == DEFAULT_ADMIN_ROLE && account == defaultAdmin()) {
delete _currentDefaultAdmin;
}
return super._revokeRole(role, account);
}
/**
* @dev See {AccessControl-_setRoleAdmin}. Reverts for `DEFAULT_ADMIN_ROLE`.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual override {
if (role == DEFAULT_ADMIN_ROLE) {
revert AccessControlEnforcedDefaultAdminRules();
}
super._setRoleAdmin(role, adminRole);
}
///
/// AccessControlDefaultAdminRules accessors
///
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function defaultAdmin() public view virtual returns (address) {
return _currentDefaultAdmin;
}
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function pendingDefaultAdmin() public view virtual returns (address newAdmin, uint48 schedule) {
return (_pendingDefaultAdmin, _pendingDefaultAdminSchedule);
}
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function defaultAdminDelay() public view virtual returns (uint48) {
uint48 schedule = _pendingDelaySchedule;
return (_isScheduleSet(schedule) && _hasSchedulePassed(schedule)) ? _pendingDelay : _currentDelay;
}
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function pendingDefaultAdminDelay() public view virtual returns (uint48 newDelay, uint48 schedule) {
schedule = _pendingDelaySchedule;
return (_isScheduleSet(schedule) && !_hasSchedulePassed(schedule)) ? (_pendingDelay, schedule) : (0, 0);
}
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function defaultAdminDelayIncreaseWait() public view virtual returns (uint48) {
return 5 days;
}
///
/// AccessControlDefaultAdminRules public and internal setters for defaultAdmin/pendingDefaultAdmin
///
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function beginDefaultAdminTransfer(address newAdmin) public virtual onlyRole(DEFAULT_ADMIN_ROLE) {
_beginDefaultAdminTransfer(newAdmin);
}
/**
* @dev See {beginDefaultAdminTransfer}.
*
* Internal function without access restriction.
*/
function _beginDefaultAdminTransfer(address newAdmin) internal virtual {
uint48 newSchedule = SafeCast.toUint48(block.timestamp) + defaultAdminDelay();
_setPendingDefaultAdmin(newAdmin, newSchedule);
emit DefaultAdminTransferScheduled(newAdmin, newSchedule);
}
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function cancelDefaultAdminTransfer() public virtual onlyRole(DEFAULT_ADMIN_ROLE) {
_cancelDefaultAdminTransfer();
}
/**
* @dev See {cancelDefaultAdminTransfer}.
*
* Internal function without access restriction.
*/
function _cancelDefaultAdminTransfer() internal virtual {
_setPendingDefaultAdmin(address(0), 0);
}
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function acceptDefaultAdminTransfer() public virtual {
(address newDefaultAdmin, ) = pendingDefaultAdmin();
if (_msgSender() != newDefaultAdmin) {
// Enforce newDefaultAdmin explicit acceptance.
revert AccessControlInvalidDefaultAdmin(_msgSender());
}
_acceptDefaultAdminTransfer();
}
/**
* @dev See {acceptDefaultAdminTransfer}.
*
* Internal function without access restriction.
*/
function _acceptDefaultAdminTransfer() internal virtual {
(address newAdmin, uint48 schedule) = pendingDefaultAdmin();
if (!_isScheduleSet(schedule) || !_hasSchedulePassed(schedule)) {
revert AccessControlEnforcedDefaultAdminDelay(schedule);
}
_revokeRole(DEFAULT_ADMIN_ROLE, defaultAdmin());
_grantRole(DEFAULT_ADMIN_ROLE, newAdmin);
delete _pendingDefaultAdmin;
delete _pendingDefaultAdminSchedule;
}
///
/// AccessControlDefaultAdminRules public and internal setters for defaultAdminDelay/pendingDefaultAdminDelay
///
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function changeDefaultAdminDelay(uint48 newDelay) public virtual onlyRole(DEFAULT_ADMIN_ROLE) {
_changeDefaultAdminDelay(newDelay);
}
/**
* @dev See {changeDefaultAdminDelay}.
*
* Internal function without access restriction.
*/
function _changeDefaultAdminDelay(uint48 newDelay) internal virtual {
uint48 newSchedule = SafeCast.toUint48(block.timestamp) + _delayChangeWait(newDelay);
_setPendingDelay(newDelay, newSchedule);
emit DefaultAdminDelayChangeScheduled(newDelay, newSchedule);
}
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function rollbackDefaultAdminDelay() public virtual onlyRole(DEFAULT_ADMIN_ROLE) {
_rollbackDefaultAdminDelay();
}
/**
* @dev See {rollbackDefaultAdminDelay}.
*
* Internal function without access restriction.
*/
function _rollbackDefaultAdminDelay() internal virtual {
_setPendingDelay(0, 0);
}
/**
* @dev Returns the amount of seconds to wait after the `newDelay` will
* become the new {defaultAdminDelay}.
*
* The value returned guarantees that if the delay is reduced, it will go into effect
* after a wait that honors the previously set delay.
*
* See {defaultAdminDelayIncreaseWait}.
*/
function _delayChangeWait(uint48 newDelay) internal view virtual returns (uint48) {
uint48 currentDelay = defaultAdminDelay();
// When increasing the delay, we schedule the delay change to occur after a period of "new delay" has passed, up
// to a maximum given by defaultAdminDelayIncreaseWait, by default 5 days. For example, if increasing from 1 day
// to 3 days, the new delay will come into effect after 3 days. If increasing from 1 day to 10 days, the new
// delay will come into effect after 5 days. The 5 day wait period is intended to be able to fix an error like
// using milliseconds instead of seconds.
//
// When decreasing the delay, we wait the difference between "current delay" and "new delay". This guarantees
// that an admin transfer cannot be made faster than "current delay" at the time the delay change is scheduled.
// For example, if decreasing from 10 days to 3 days, the new delay will come into effect after 7 days.
return
newDelay > currentDelay
? uint48(Math.min(newDelay, defaultAdminDelayIncreaseWait())) // no need to safecast, both inputs are uint48
: currentDelay - newDelay;
}
///
/// Private setters
///
/**
* @dev Setter of the tuple for pending admin and its schedule.
*
* May emit a DefaultAdminTransferCanceled event.
*/
function _setPendingDefaultAdmin(address newAdmin, uint48 newSchedule) private {
(, uint48 oldSchedule) = pendingDefaultAdmin();
_pendingDefaultAdmin = newAdmin;
_pendingDefaultAdminSchedule = newSchedule;
// An `oldSchedule` from `pendingDefaultAdmin()` is only set if it hasn't been accepted.
if (_isScheduleSet(oldSchedule)) {
// Emit for implicit cancellations when another default admin was scheduled.
emit DefaultAdminTransferCanceled();
}
}
/**
* @dev Setter of the tuple for pending delay and its schedule.
*
* May emit a DefaultAdminDelayChangeCanceled event.
*/
function _setPendingDelay(uint48 newDelay, uint48 newSchedule) private {
uint48 oldSchedule = _pendingDelaySchedule;
if (_isScheduleSet(oldSchedule)) {
if (_hasSchedulePassed(oldSchedule)) {
// Materialize a virtual delay
_currentDelay = _pendingDelay;
} else {
// Emit for implicit cancellations when another delay was scheduled.
emit DefaultAdminDelayChangeCanceled();
}
}
_pendingDelay = newDelay;
_pendingDelaySchedule = newSchedule;
}
///
/// Private helpers
///
/**
* @dev Defines if an `schedule` is considered set. For consistency purposes.
*/
function _isScheduleSet(uint48 schedule) private pure returns (bool) {
return schedule != 0;
}
/**
* @dev Defines if an `schedule` is considered passed. For consistency purposes.
*/
function _hasSchedulePassed(uint48 schedule) private view returns (bool) {
return schedule < block.timestamp;
}
}
IAccessControlDefaultAdminRules.sol 192 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/extensions/IAccessControlDefaultAdminRules.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "../IAccessControl.sol";
/**
* @dev External interface of AccessControlDefaultAdminRules declared to support ERC165 detection.
*/
interface IAccessControlDefaultAdminRules is IAccessControl {
/**
* @dev The new default admin is not a valid default admin.
*/
error AccessControlInvalidDefaultAdmin(address defaultAdmin);
/**
* @dev At least one of the following rules was violated:
*
* - The `DEFAULT_ADMIN_ROLE` must only be managed by itself.
* - The `DEFAULT_ADMIN_ROLE` must only be held by one account at the time.
* - Any `DEFAULT_ADMIN_ROLE` transfer must be in two delayed steps.
*/
error AccessControlEnforcedDefaultAdminRules();
/**
* @dev The delay for transferring the default admin delay is enforced and
* the operation must wait until `schedule`.
*
* NOTE: `schedule` can be 0 indicating there's no transfer scheduled.
*/
error AccessControlEnforcedDefaultAdminDelay(uint48 schedule);
/**
* @dev Emitted when a {defaultAdmin} transfer is started, setting `newAdmin` as the next
* address to become the {defaultAdmin} by calling {acceptDefaultAdminTransfer} only after `acceptSchedule`
* passes.
*/
event DefaultAdminTransferScheduled(address indexed newAdmin, uint48 acceptSchedule);
/**
* @dev Emitted when a {pendingDefaultAdmin} is reset if it was never accepted, regardless of its schedule.
*/
event DefaultAdminTransferCanceled();
/**
* @dev Emitted when a {defaultAdminDelay} change is started, setting `newDelay` as the next
* delay to be applied between default admin transfer after `effectSchedule` has passed.
*/
event DefaultAdminDelayChangeScheduled(uint48 newDelay, uint48 effectSchedule);
/**
* @dev Emitted when a {pendingDefaultAdminDelay} is reset if its schedule didn't pass.
*/
event DefaultAdminDelayChangeCanceled();
/**
* @dev Returns the address of the current `DEFAULT_ADMIN_ROLE` holder.
*/
function defaultAdmin() external view returns (address);
/**
* @dev Returns a tuple of a `newAdmin` and an accept schedule.
*
* After the `schedule` passes, the `newAdmin` will be able to accept the {defaultAdmin} role
* by calling {acceptDefaultAdminTransfer}, completing the role transfer.
*
* A zero value only in `acceptSchedule` indicates no pending admin transfer.
*
* NOTE: A zero address `newAdmin` means that {defaultAdmin} is being renounced.
*/
function pendingDefaultAdmin() external view returns (address newAdmin, uint48 acceptSchedule);
/**
* @dev Returns the delay required to schedule the acceptance of a {defaultAdmin} transfer started.
*
* This delay will be added to the current timestamp when calling {beginDefaultAdminTransfer} to set
* the acceptance schedule.
*
* NOTE: If a delay change has been scheduled, it will take effect as soon as the schedule passes, making this
* function returns the new delay. See {changeDefaultAdminDelay}.
*/
function defaultAdminDelay() external view returns (uint48);
/**
* @dev Returns a tuple of `newDelay` and an effect schedule.
*
* After the `schedule` passes, the `newDelay` will get into effect immediately for every
* new {defaultAdmin} transfer started with {beginDefaultAdminTransfer}.
*
* A zero value only in `effectSchedule` indicates no pending delay change.
*
* NOTE: A zero value only for `newDelay` means that the next {defaultAdminDelay}
* will be zero after the effect schedule.
*/
function pendingDefaultAdminDelay() external view returns (uint48 newDelay, uint48 effectSchedule);
/**
* @dev Starts a {defaultAdmin} transfer by setting a {pendingDefaultAdmin} scheduled for acceptance
* after the current timestamp plus a {defaultAdminDelay}.
*
* Requirements:
*
* - Only can be called by the current {defaultAdmin}.
*
* Emits a DefaultAdminRoleChangeStarted event.
*/
function beginDefaultAdminTransfer(address newAdmin) external;
/**
* @dev Cancels a {defaultAdmin} transfer previously started with {beginDefaultAdminTransfer}.
*
* A {pendingDefaultAdmin} not yet accepted can also be cancelled with this function.
*
* Requirements:
*
* - Only can be called by the current {defaultAdmin}.
*
* May emit a DefaultAdminTransferCanceled event.
*/
function cancelDefaultAdminTransfer() external;
/**
* @dev Completes a {defaultAdmin} transfer previously started with {beginDefaultAdminTransfer}.
*
* After calling the function:
*
* - `DEFAULT_ADMIN_ROLE` should be granted to the caller.
* - `DEFAULT_ADMIN_ROLE` should be revoked from the previous holder.
* - {pendingDefaultAdmin} should be reset to zero values.
*
* Requirements:
*
* - Only can be called by the {pendingDefaultAdmin}'s `newAdmin`.
* - The {pendingDefaultAdmin}'s `acceptSchedule` should've passed.
*/
function acceptDefaultAdminTransfer() external;
/**
* @dev Initiates a {defaultAdminDelay} update by setting a {pendingDefaultAdminDelay} scheduled for getting
* into effect after the current timestamp plus a {defaultAdminDelay}.
*
* This function guarantees that any call to {beginDefaultAdminTransfer} done between the timestamp this
* method is called and the {pendingDefaultAdminDelay} effect schedule will use the current {defaultAdminDelay}
* set before calling.
*
* The {pendingDefaultAdminDelay}'s effect schedule is defined in a way that waiting until the schedule and then
* calling {beginDefaultAdminTransfer} with the new delay will take at least the same as another {defaultAdmin}
* complete transfer (including acceptance).
*
* The schedule is designed for two scenarios:
*
* - When the delay is changed for a larger one the schedule is `block.timestamp + newDelay` capped by
* {defaultAdminDelayIncreaseWait}.
* - When the delay is changed for a shorter one, the schedule is `block.timestamp + (current delay - new delay)`.
*
* A {pendingDefaultAdminDelay} that never got into effect will be canceled in favor of a new scheduled change.
*
* Requirements:
*
* - Only can be called by the current {defaultAdmin}.
*
* Emits a DefaultAdminDelayChangeScheduled event and may emit a DefaultAdminDelayChangeCanceled event.
*/
function changeDefaultAdminDelay(uint48 newDelay) external;
/**
* @dev Cancels a scheduled {defaultAdminDelay} change.
*
* Requirements:
*
* - Only can be called by the current {defaultAdmin}.
*
* May emit a DefaultAdminDelayChangeCanceled event.
*/
function rollbackDefaultAdminDelay() external;
/**
* @dev Maximum time in seconds for an increase to {defaultAdminDelay} (that is scheduled using {changeDefaultAdminDelay})
* to take effect. Default to 5 days.
*
* When the {defaultAdminDelay} is scheduled to be increased, it goes into effect after the new delay has passed with
* the purpose of giving enough time for reverting any accidental change (i.e. using milliseconds instead of seconds)
* that may lock the contract. However, to avoid excessive schedules, the wait is capped by this function and it can
* be overrode for a custom {defaultAdminDelay} increase scheduling.
*
* IMPORTANT: Make sure to add a reasonable amount of time while overriding this value, otherwise,
* there's a risk of setting a high new delay that goes into effect almost immediately without the
* possibility of human intervention in the case of an input error (eg. set milliseconds instead of seconds).
*/
function defaultAdminDelayIncreaseWait() external view returns (uint48);
}
Read Contract
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
DEPOSITOR_ROLE 0xa3b0b5a3 → bytes32
OPERATOR_ROLE 0xf5b541a6 → bytes32
ORACLE_ROLE 0x07e2cea5 → bytes32
ROLE_PROPOSER_ROLE 0x1a90b159 → bytes32
claims 0xab541a85 → bytes32
defaultAdmin 0x84ef8ffc → address
defaultAdminDelay 0xcc8463c8 → uint48
defaultAdminDelayIncreaseWait 0x022d63fb → uint48
depositContract 0xe94ad65b → address
exitProposalId 0x72b3281e → bytes32
exitProposals 0x364f1f16 → tuple, bool
getRoleAdmin 0x248a9ca3 → bytes32
getRoleMember 0x9010d07c → address
getRoleMemberCount 0xca15c873 → uint256
getRoleProposal 0xc0cd94f0 → address
getRoleProposalsCount 0x18a860c5 → uint256
hasRole 0x91d14854 → bool
isMevEnabled 0x521c228e → bool
owner 0x8da5cb5b → address
pendingDefaultAdmin 0xcf6eefb7 → address, uint48
pendingDefaultAdminDelay 0xa1eda53c → uint48, uint48
pendingDeposits 0x5c074f44 → uint256
pendingWithdrawals 0xbeca03d5 → uint256
rewards 0x9ec5a894 → uint256
rewardsRecipient 0xff2a7d30 → address
supportsInterface 0x01ffc9a7 → bool
validatorWithdrawals 0x8d6be150 → uint64, uint48
withdrawalCredential 0x83059303 → bytes32
Write Contract 27 functions
These functions modify contract state and require a wallet transaction to execute.
acceptDefaultAdminTransfer 0xcefc1429
No parameters
acceptExit 0x59f9d7d9
bytes32 proposalId
acceptRole 0x0b493e0f
bytes32 role
address account
acceptRoleAdmin 0x06037939
bytes32 role
bytes32 adminRole
beginDefaultAdminTransfer 0x634e93da
address newAdmin
cancelDefaultAdminTransfer 0xd602b9fd
No parameters
changeDefaultAdminDelay 0x649a5ec7
uint48 newDelay
claimWithdrawals 0x1a4709ff
bytes32 proposalId
claimWithdrawals 0x930d3f17
address beneficiary
collectRewards 0x70bb45b3
No parameters
deposit 0xd0e30db0
No parameters
grantRole 0x2f2ff15d
bytes32 role
address account
proposeExit 0xc9b46ca4
tuple proposal
returns: bytes32
proposeRole 0x0b09c729
bytes32 role
address account
proposeRoleAdmin 0x31c05913
bytes32 role
bytes32 adminRole
queueValidator 0xa87fbcb6
tuple _deposit
queueValidator 0xd0123cf9
tuple[] deposits
rejectExit 0x7c41cd52
bytes32 proposalId
rejectRole 0x1c4922da
bytes32 role
address account
rejectRoleAdmin 0x41529364
bytes32 role
bytes32 adminRole
renounceRole 0x36568abe
bytes32 role
address account
revokeRole 0xd547741f
bytes32 role
address account
rollbackDefaultAdminDelay 0x0aa6220b
No parameters
setRewardsRecipient 0x1a54259c
address recipient
updateWithdrawal 0x9df351d2
tuple[] withdrawals
updateWithdrawal 0xdd1e8b77
uint64 validatorIndex
uint64 blockNumber
uint48 amountGwei
withdrawDeposit 0x33289a46
uint256 wad
Recent Transactions
No transactions found for this address