Address Contract Verified
Address
0x176EEF21ab19d49Be14ed88C7064e1185e8a87CE
Balance
0 ETH
Nonce
1
Code Size
16673 bytes
Creator
0xcE104CAD...2de2 at tx 0x1466cdfd...47f833
Indexed Transactions
0
Contract Bytecode
16673 bytes
0x6080604052600436101561001257600080fd5b6000803560e01c8063025df29b1461275c5780630664c0ba146125f357806306fdde03146125ad5780630d238f9e14612561578063146b3b52146122dc57806317a691aa1461227e57806318b3d2101461207f5780631b4097d814611f58578063239c590714611f0b5780632efe95be14611ce65780633d0beb6514611c945780633f4ba83a14611bba5780634f1ef286146116df5780634fc221bf1461169b5780635011ed4f1461165657806352d1902d146115985780635c975abb146115385780636247f6f2146114f057806364bac416146114ac57806366beb4cb1461145f5780636ac39100146112fb578063715018a61461126657806379ba5097146111c15780638456cb59146110e457806386af1c731461107c578063872d7d57146110405780638ab1d68114610f7c5780638c55297814610f345780638cacd6e714610e0c5780638da5cb5b14610d9b5780638ebd726514610cad578063a0a8e46014610c6a578063a8f37db414610a12578063ad3cb1cc14610997578063b4d034d61461095b578063b685115214610636578063b9b17e7f146105e9578063d2d6f4d514610596578063df643512146104e4578063e30c397814610473578063e51d092114610426578063e69fadb4146103de578063e6f4b5331461038e578063e8fed1d61461032b5763f2fde38b1461020c57600080fd5b346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285773ffffffffffffffffffffffffffffffffffffffff610258612d20565b610260613a70565b16807fffffffffffffffffffffffff00000000000000000000000000000000000000007f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c005416177f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c005573ffffffffffffffffffffffffffffffffffffffff7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930054167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e227008380a380f35b80fd5b50346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261032857604060209173ffffffffffffffffffffffffffffffffffffffff61037d612d20565b168152600383522054604051908152f35b50346103285760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610328576020906103d56103cc612d9f565b602435906131af565b604051910b8152f35b50346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285760406020916004358152600483522054604051908152f35b50346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285760ff60406020926004358152600984522054166040519015158152f35b503461032857807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261032857602073ffffffffffffffffffffffffffffffffffffffff7f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c005416604051908152f35b50346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610328576004359067ffffffffffffffff82116103285761010073ffffffffffffffffffffffffffffffffffffffff63ffffffff61055a6105543660048801612db2565b90613004565b979392949096989195826040519a168a5260208a0152166040880152166060860152608085015260a0840152151560c0830152151560e0820152f35b50346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261032857604060209163ffffffff6105d8612d9f565b168152600a83522054604051908152f35b50346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285760ff60406020926004358152600784522054166040519015158152f35b50346103285760a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285760043567ffffffffffffffff811161095757610686903690600401612db2565b6044359160243591610696612d8c565b60843567ffffffffffffffff8111610953576106b6903690600401612db2565b916106bf6132bd565b86421161092b57604084036109035785156108db5773ffffffffffffffffffffffffffffffffffffffff6106f4368688612ef7565b6020815191012016948589526003602052604089205494858a528960205260ff60408b2054166108b3576107356107ef9594939263ffffffff923691612ef7565b60208151910120916040519960208b01937f8b74ba92973a25c30b64f5650dec09faddb2d1a199e095b249538c2addebe61d855260408c01528960608c015260808b015216978860a082015260a0815261079060c082612e4d565b51902061079b613312565b906107e76107a7613f43565b6107bb60405193849260208401968761334d565b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101835282612e4d565b519020613370565b6107f88461377c565b8061083157506108088282613c96565b505b7f697a463b143a01bd93749c518e1e69d9b29fbba6408f1789236a2e4b24dab84c8480a480f35b80855260066020526040852054830361087c578452836020526040842060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0082541617905561080a565b8452600660205260408420547f140c6815000000000000000000000000000000000000000000000000000000008552600452602484fd5b60048a7ff411c327000000000000000000000000000000000000000000000000000000008152fd5b6004887ff4fc87a4000000000000000000000000000000000000000000000000000000008152fd5b6004887f4b0218a8000000000000000000000000000000000000000000000000000000008152fd5b6004887f7bbfb6fe000000000000000000000000000000000000000000000000000000008152fd5b8680fd5b5080fd5b503461032857807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610328576020600c54604051908152f35b503461032857807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285750610a0e6040516109d8604082612e4d565b600581527f352e302e30000000000000000000000000000000000000000000000000000000602082015260405191829182612e03565b0390f35b50346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285760043567ffffffffffffffff811161095757610a62903690600401612db2565b90610a6b6132bd565b610a736137f4565b60ff600d5460b81c1615610c4257610a8b8282613c44565b939273ffffffffffffffffffffffffffffffffffffffff821692918315610c1a5785610ab8918484613d9a565b91828852600960205260ff604089205416610bf25782885260096020526040882060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0082541617905586604c11610bee57610b59610ba29573ffffffffffffffffffffffffffffffffffffffff94604c7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb463ffffffff9b01920190613518565b604051937fa9059cbb0000000000000000000000000000000000000000000000000000000060208601526024850152604484015260448352610b9c606484612e4d565b16613fc3565b167f9853e4c075911a10a89a0f7a46bac6f8a246c4e9152480d16d86aa6a2391a4f18280a260017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005580f35b8780fd5b6004887f24c1c1ce000000000000000000000000000000000000000000000000000000008152fd5b6004887f867915ab000000000000000000000000000000000000000000000000000000008152fd5b6004837faac0dd91000000000000000000000000000000000000000000000000000000008152fd5b503461032857807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261032857602061ffff600d5460a01c16604051908152f35b50346103285760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285760243567ffffffffffffffff811161095757610cfd903690600401612d48565b9160043591819060015b15610d79575b60018294610d1c858885612f99565b3580821015610d51576040519060208201928352604082015260408152610d44606082612e4d565b5190205b93019293610d07565b906040519060208201928352604082015260408152610d71606082612e4d565b519020610d48565b848310610d0d57602060ff604084878152600784522054166040519015158152f35b503461032857807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261032857602073ffffffffffffffffffffffffffffffffffffffff7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c1993005416604051908152f35b50346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285760043580151580910361095757610e51613a70565b600d548160ff8260b81c16151514610ecf577fffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffff77ff00000000000000000000000000000000000000000000008360b81b16911617600d557f8713af94867086ff18e93beb030e44bc5542cd733709d67cd78d06db7d61b8cf8280a280f35b608482604051907f01ab13a300000000000000000000000000000000000000000000000000000000825260406004830152600860448301527f6c6f776572696e6700000000000000000000000000000000000000000000000060648301526024820152fd5b50346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285760406020916004358152600683522054604051908152f35b50346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285773ffffffffffffffffffffffffffffffffffffffff610fc9612d20565b610fd1613a70565b16808252600260205260ff60408320541615610957578082526002602052604082207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0081541690557ff71517f8293c0bb07835106f436e0b7eeb15391d97d5762894e04b55830ef8808280a280f35b503461032857807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610328576020600b54604051908152f35b50346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285760ff604060209273ffffffffffffffffffffffffffffffffffffffff6110d0612d20565b168152600284522054166040519015158152f35b503461032857807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285761111b613a70565b6111236132bd565b61112b6132bd565b60017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033005416177fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a180f35b503461032857807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610328573373ffffffffffffffffffffffffffffffffffffffff7f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c0054160361123a5761123733613b34565b80f35b807f118cdaa7000000000000000000000000000000000000000000000000000000006024925233600452fd5b503461032857807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285761129d613a70565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600860248201527f44697361626c65640000000000000000000000000000000000000000000000006044820152fd5b50346103285760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261032857611333612d20565b6024359061133f6132bd565b6113476137f4565b73ffffffffffffffffffffffffffffffffffffffff811690818452600260205260ff604085205416156114375760ff600d5460b01c161561140f5782156113e75760206113b97f418da8f85cfa851601f87634c6950491b6b8785a6445c8584f5658048d512cae92604435903361386d565b604051908152a360017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005580f35b6004847ff4fc87a4000000000000000000000000000000000000000000000000000000008152fd5b6004847f07ebf7e8000000000000000000000000000000000000000000000000000000008152fd5b6004847fc1ab6dc1000000000000000000000000000000000000000000000000000000008152fd5b50346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285760ff60406020926004358152600184522054166040519015158152f35b503461032857807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261032857602060ff600d5460b81c166040519015158152f35b50346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285761123761152b612d20565b611533613a70565b613203565b503461032857807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261032857602060ff7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f0330054166040519015158152f35b503461032857807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285773ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000176eef21ab19d49be14ed88c7064e1185e8a87ce16300361162e5760206040517f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8152f35b807fe07c8dba0000000000000000000000000000000000000000000000000000000060049252fd5b503461032857807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610328575060206928b90559000650313b13604051908152f35b503461032857807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261032857602060ff600d5460b01c166040519015158152f35b5060407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261032857611712612d20565b9060243567ffffffffffffffff8111610957573660238201121561095757611744903690602481600401359101612ef7565b9173ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000176eef21ab19d49be14ed88c7064e1185e8a87ce16803014908115611b78575b50611b5057611794613a70565b818060405160208101907f06fdde03000000000000000000000000000000000000000000000000000000008252600481526117d0602482612e4d565b5190845afa6117dd612f69565b9015908115611abc575b50611a9457600d547fffffffffffffffffffff0000ffffffffffffffffffffffffffffffffffffffff75ffff0000000000000000000000000000000000000000600161ffff8460a01c160160a01b169116179283600d5573ffffffffffffffffffffffffffffffffffffffff8216918261ffff6040519660a01c167f66a8fdd2f09f2371790241916505cbd848239fe9eb5d49e6a452a6f2c0f3cfdb8680a37f52d1902d000000000000000000000000000000000000000000000000000000008552602085600481865afa80958596611a5c575b506118ec57602484847f4c9c8ce3000000000000000000000000000000000000000000000000000000008252600452fd5b9091847f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8103611a315750813b15611a0657807fffffffffffffffffffffffff00000000000000000000000000000000000000007f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5416177f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8480a281518390156119d357808360206119cf95519101845af46119c9612f69565b9161404e565b5080f35b505050346119de5780f35b807fb398979f0000000000000000000000000000000000000000000000000000000060049252fd5b7f4c9c8ce3000000000000000000000000000000000000000000000000000000008452600452602483fd5b7faa1d49a4000000000000000000000000000000000000000000000000000000008552600452602484fd5b9095506020813d602011611a8c575b81611a7860209383612e4d565b81010312611a88575194386118bb565b8480fd5b3d9150611a6b565b6004827f68155f9a000000000000000000000000000000000000000000000000000000008152fd5b80915051810190602081818401930312611b4c5760208101519067ffffffffffffffff8211611a88570181603f82011215611b4c576020810151611aff81612ebd565b91611b0d6040519384612e4d565b818352602083019360408284010111611b485790836040611b2e9301612de0565b519020611b39612f2e565b602081519101201415386117e7565b8580fd5b8380fd5b6004827fe07c8dba000000000000000000000000000000000000000000000000000000008152fd5b905073ffffffffffffffffffffffffffffffffffffffff7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5416141538611787565b503461032857807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261032857611bf1613a70565b611bf9613ade565b611c01613ade565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f0330054167fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a180f35b503461032857807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261032857602073ffffffffffffffffffffffffffffffffffffffff600d5416604051908152f35b50346103285760c07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261032857611d1e612d79565b60643560843563ffffffff8116809103611b4c5760a43567ffffffffffffffff8111611a8857611d52903690600401612db2565b9093611d5c6132bd565b834211611ee35763ffffffff1693848652600a6020526040862054611ebb57611dfe9291611df9916928b90559000650313b1395878952600a6020528660408a205560405160208101917f0829dff985150e9fd0cb2bab3c6a1eabb3a57ccecaf60fce030596f096109dc083526004356040830152602435606083015289608083015260a08201528560c082015260c0815261079060e082612e4d565b61377c565b828073ffffffffffffffffffffffffffffffffffffffff600d54166040518260208201917fa0712d6800000000000000000000000000000000000000000000000000000000835286602482015260248152611e5a604482612e4d565b51925af1611e66612f69565b5015611e93577f3ad58a8dc1110baa37ad88a68db14181b4ef0c69192dfa7699a9588960eca7fd8380a380f35b6004837f07637bd8000000000000000000000000000000000000000000000000000000008152fd5b6004867f81a36023000000000000000000000000000000000000000000000000000000008152fd5b6004867f7bbfb6fe000000000000000000000000000000000000000000000000000000008152fd5b50346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285760ff60406020926004358152600884522054166040519015158152f35b50346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285760043580151580910361095757611f9d613a70565b600d548160ff8260b01c1615151461201a577fffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffffff76ff000000000000000000000000000000000000000000008360b01b16911617600d557f749ca68fae31d0cfb5bab03f4b6efbdc3d1309e0ab82818178082487298b7a768280a280f35b608482604051907f01ab13a300000000000000000000000000000000000000000000000000000000825260406004830152600760448301527f6c696674696e670000000000000000000000000000000000000000000000000060648301526024820152fd5b50346103285760e07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610328576120b7612d20565b602435906044356084359160ff8316809303611a88576120d56132bd565b6120dd6137f4565b73ffffffffffffffffffffffffffffffffffffffff811692838652600260205260ff604087205416156122565760ff600d5460b01c161561222e57841561220657833b15611b4857604051907fd505accf0000000000000000000000000000000000000000000000000000000082523360048301523060248301528360448301526064356064830152608482015260a43560a482015260c43560c4820152858160e48183885af180156121fb576121be575b506113b97f418da8f85cfa851601f87634c6950491b6b8785a6445c8584f5658048d512cae926020923361386d565b7f418da8f85cfa851601f87634c6950491b6b8785a6445c8584f5658048d512cae92866121f1602094986113b994612e4d565b969250925061218f565b6040513d88823e3d90fd5b6004867ff4fc87a4000000000000000000000000000000000000000000000000000000008152fd5b6004867f07ebf7e8000000000000000000000000000000000000000000000000000000008152fd5b6004867fc1ab6dc1000000000000000000000000000000000000000000000000000000008152fd5b50346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285773ffffffffffffffffffffffffffffffffffffffff6040602092600435815260058452205416604051908152f35b50346103285760a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285760043560243567ffffffffffffffff811161255d5761232f903690600401612db2565b604435929161233c612d8c565b9060843567ffffffffffffffff81116109535761235d903690600401612db2565b9290916123686132bd565b86421161092b57604085036109035785885260046020526040882054948589528860205260ff60408a20541615612535576123b061240b9594939263ffffffff923691612ef7565b60208151910120916040519860208a01937f34e10d70f436fd8d1fab81c52f261d3bbb41e4bf5f36cc5b8289fe76dd066bbd85528960408c015260608b015260808a015216968760a082015260a0815261079060c082612e4d565b6004600c54111561250d5761241f8361377c565b80845283602052604084207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008154169055808452600160205260ff6040852054166124ae575b8352600560205273ffffffffffffffffffffffffffffffffffffffff6040842054167fa8a7bc47477d28ccc711706cbda958b39da6fdb915d2746405866d89698f6de68480a480f35b8084526001602052604084207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0081541690557fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff600c5401600c55612465565b6004847f3a6a875c000000000000000000000000000000000000000000000000000000008152fd5b6004897f157b0512000000000000000000000000000000000000000000000000000000008152fd5b8280fd5b50346103285760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103285760ff604060209260043581528084522054166040519015158152f35b503461032857807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261032857610a0e6125e7612f2e565b60405191829182612e03565b50346103285760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261032857602435600435612631612d79565b9160643567ffffffffffffffff8111611a8857612652903690600401612db2565b9161265b6132bd565b804211611ee357838652600760205260ff60408720541661273457906126cf929163ffffffff6040519660208801927fac3dbe0e63cde4ac18abd192a611b081a84211becb65de0eacc2632a7d6f376384528760408a0152606089015216958660808201526080815261079060a082612e4d565b6126d88261377c565b80835260076020526040832060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008254161790557f43c04551f5c228dcd139615dac0f9d231bcca473808592eea9a62a8504eaf9638380a380f35b6004867f2c8a3b6e000000000000000000000000000000000000000000000000000000008152fd5b50346103285760c07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261032857612794612d20565b906024359073ffffffffffffffffffffffffffffffffffffffff82168083036109575760443567ffffffffffffffff811161255d576127d7903690600401612d48565b92909160643567ffffffffffffffff811161255d576127fa903690600401612d48565b96909160843567ffffffffffffffff8111611a885761281d903690600401612d48565b91909260a43567ffffffffffffffff811161095357612840903690600401612d48565b9890977ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00549a60ff8c60401c16159b8c67ffffffffffffffff821680159182612d18575b506001149081612d0e575b159081612d05575b50612cdd578c60017fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000008316177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0055612c88575b5073ffffffffffffffffffffffffffffffffffffffff8416948515612c6057612911613eea565b612919613eea565b15612c345761292790613b34565b61292f613eea565b612937613eea565b61293f613eea565b612947613eea565b60017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0055612973613eea565b6001600b5560048210612c0c57818c14801590612c02575b8015612bf8575b612bd057919987929060015b15612af9575b88936129b1818585612f99565b3573ffffffffffffffffffffffffffffffffffffffff8116808203612af5578f73ffffffffffffffffffffffffffffffffffffffff8b612a01868f6129fa8f9188978491612f99565b3593612f99565b356040519060208201928352604082015260408152612a21606082612e4d565b5190201603612acd57808c52600360205260408c2054612aa2575090612a9b612a5a6001938f8f612a53918691612f99565b3590613c96565b6000526001602052604060002060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008254161790556001600c5401600c55565b019361299e565b7f78f22dd1000000000000000000000000000000000000000000000000000000008c5260045260248bfd5b60048c7f4cd87fb5000000000000000000000000000000000000000000000000000000008152fd5b8b80fd5b8284106129a4578890612b358d877fffffffffffffffffffffffff0000000000000000000000000000000000000000600d541617600d55613203565b612b3c5780f35b7fffffffffffffffffffffffffffffffffffffffffffffff00ffffffffffffffff7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054167ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00557fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2602060405160018152a180f35b6004887f097ec09e000000000000000000000000000000000000000000000000000000008152fd5b50818a1415612992565b508185141561298b565b6004887f3a6a875c000000000000000000000000000000000000000000000000000000008152fd5b6024897f1e4fbdf700000000000000000000000000000000000000000000000000000000815280600452fd5b60048a7f867915ab000000000000000000000000000000000000000000000000000000008152fd5b7fffffffffffffffffffffffffffffffffffffffffffffff0000000000000000001668010000000000000001177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0055386128ea565b60048a7ff92ee8a9000000000000000000000000000000000000000000000000000000008152fd5b90501538612897565b303b15915061288f565b91508e612884565b6004359073ffffffffffffffffffffffffffffffffffffffff82168203612d4357565b600080fd5b9181601f84011215612d435782359167ffffffffffffffff8311612d43576020808501948460051b010111612d4357565b6044359063ffffffff82168203612d4357565b6064359063ffffffff82168203612d4357565b6004359063ffffffff82168203612d4357565b9181601f84011215612d435782359167ffffffffffffffff8311612d435760208381860195010111612d4357565b60005b838110612df35750506000910152565b8181015183820152602001612de3565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f60409360208452612e468151809281602088015260208888019101612de0565b0116010190565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff821117612e8e57604052565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b67ffffffffffffffff8111612e8e57601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b929192612f0382612ebd565b91612f116040519384612e4d565b829481845281830111612d43578281602093846000960137010152565b60405190612f3d604083612e4d565b600c82527f456e6572677942726964676500000000000000000000000000000000000000006020830152565b3d15612f94573d90612f7a82612ebd565b91612f886040519384612e4d565b82523d6000602084013e565b606090565b9190811015612fa95760051b0190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b67ffffffffffffffff8111612e8e5760051b60200190565b8051821015612fa95760209160051b010190565b9160ce821061319a576130178284613c44565b9295919490936130298486888a613d9a565b917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb481019081116131595760419004600b54907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe061309f61308984612fd8565b936130976040519586612e4d565b808552612fd8565b0136602084013783600052600960205260ff60406000205416918194604c6130cf60036002600c5460011b010490565b97019060005b8481106130e85750505050508383101591565b6130f3818484613e27565b80600052600160205260ff6040600020541680613188575b156131265790600161311e819387612ff0565b525b016130d5565b50968015613159577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6001910197613120565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b506131938186612ff0565b511561310b565b60009250829150819081908190819081908190565b63ffffffff16600052600860205260ff604060002054166000146131d35750600190565b4211156131fe577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff90565b600090565b73ffffffffffffffffffffffffffffffffffffffff1680156132935780600052600260205260ff60406000205416612d4357806000526002602052604060002060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008254161790557f8903e080b5c69a152a91cd02601be1ae6016a2e837de3a938084856cfacbbbfa600080a2565b7f867915ab0000000000000000000000000000000000000000000000000000000060005260046000fd5b60ff7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f0330054166132e857565b7fd93c06650000000000000000000000000000000000000000000000000000000060005260046000fd5b60405190613321604083612e4d565b600282527f19010000000000000000000000000000000000000000000000000000000000006020830152565b6020906133636040959382815194859201612de0565b0191825260208201520190565b909291600092600b54907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe06133a761308984612fd8565b0136602084013760416133c260036002600c5460011b010490565b93049480933360005260036020526001604060002054970160015b156134e6575b600097808952600160205260ff60408a205416156000146134b0578089528860205260ff60408a20541661342a575b505b6001613421878b8a613e27565b960195976133dd565b915091600190613475836000526001602052604060002060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008254161790556001600c5401600c55565b019161348960036002600c5460011b010490565b918284146134a45761349d60019187612ff0565b5238613412565b50505050945050505050565b6134ba8187612ff0565b51156134c7575b50613414565b92600101928284146134a4576134df60019187612ff0565b52386134c1565b808611156133e3577f409c8aac0000000000000000000000000000000000000000000000000000000060005260046000fd5b909291600b547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe061356161354b83612fd8565b926135596040519485612e4d565b808452612fd8565b01366020830137604161357c60036002600c5460011b010490565b92049360008060208801358160ff60408b0135821a601b8110613772575b1691601d831080613748575b1561373d57602092608091604051918b8352858301528c356040830152606082015282805260015afa15613731578073ffffffffffffffffffffffffffffffffffffffff60409251168152600360205220549593955b95600194855b156136ff575b600097808952600160205260ff60408a205416156000146136c9578089528860205260ff60408a20541661364f575b505b6001613646878b8a613e27565b96019597613602565b91509160019061369a836000526001602052604060002060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008254161790556001600c5401600c55565b01916136ae60036002600c5460011b010490565b918284146134a4576136c260019187612ff0565b5238613637565b6136d38187612ff0565b51156136e0575b50613639565b92600101928284146134a4576136f860019187612ff0565b52386136da565b80861115613608577f409c8aac0000000000000000000000000000000000000000000000000000000060005260046000fd5b604051903d90823e3d90fd5b5050509593956135fc565b507f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08111156135a6565b601b01811661359a565b80600052600860205260ff604060002054166137ca576000526008602052604060002060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00825416179055565b7f7edd16f00000000000000000000000000000000000000000000000000000000060005260046000fd5b60027f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0054146138435760027f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0055565b7f3ee5aeb50000000000000000000000000000000000000000000000000000000060005260046000fd5b9073ffffffffffffffffffffffffffffffffffffffff1690604051927f70a08231000000000000000000000000000000000000000000000000000000008452306004850152602084602481865afa938415613a2e57600094613a3a575b50916139396020926024959473ffffffffffffffffffffffffffffffffffffffff604051927f23b872dd00000000000000000000000000000000000000000000000000000000878501521687830152306044830152606482015260648152613933608482612e4d565b82613fc3565b604051938480927f70a082310000000000000000000000000000000000000000000000000000000082523060048301525afa918215613a2e576000926139fa575b50808211156139d0576fffffffffffffffffffffffffffffffff82116139a65781039081116131595790565b7fc36d28300000000000000000000000000000000000000000000000000000000060005260046000fd5b7fb19ed5190000000000000000000000000000000000000000000000000000000060005260046000fd5b90916020823d602011613a26575b81613a1560209383612e4d565b81010312610328575051903861397a565b3d9150613a08565b6040513d6000823e3d90fd5b90936020823d602011613a68575b81613a5560209383612e4d565b81010312610328575051926139396138ca565b3d9150613a48565b73ffffffffffffffffffffffffffffffffffffffff7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930054163303613ab057565b7f118cdaa7000000000000000000000000000000000000000000000000000000006000523360045260246000fd5b60ff7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300541615613b0a57565b7f8dfc202b0000000000000000000000000000000000000000000000000000000060005260046000fd5b7fffffffffffffffffffffffff00000000000000000000000000000000000000007f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c0054167f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c005573ffffffffffffffffffffffffffffffffffffffff807f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930054921691827fffffffffffffffffffffffff00000000000000000000000000000000000000008216177f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b919060ce11613c6c57813560601c916014810135916048603483013560601c92013560e01c90565b7f09bde3390000000000000000000000000000000000000000000000000000000060005260046000fd5b9190600b549060018201600b558193816000526004602052604060002054613d6c5782600052600560205273ffffffffffffffffffffffffffffffffffffffff6040600020911690817fffffffffffffffffffffffff0000000000000000000000000000000000000000825416179055826000526006602052816040600020556000526003602052816040600020556000526004602052806040600020556000526000602052604060002060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00825416179055565b507f02f3935c0000000000000000000000000000000000000000000000000000000060005260045260246000fd5b9273ffffffffffffffffffffffffffffffffffffffff63ffffffff9293604051948260208701977fc7c94d35b0adfdf765df555abbf561bb450dd32a9c432d42743f393b3606e8c4895216604087015260608601521660808401521660a082015260a08152613e0a60c082612e4d565b519020613e15613312565b90613e216107a7613f43565b51902090565b90604160009302019060ff6020830135936040840135901a601b8110613ee0575b1690601d821080613eb6575b15613ead5760209360009360809360405193845286840152356040830152606082015282805260015afa15613a2e5773ffffffffffffffffffffffffffffffffffffffff60005116600052600360205260406000205490565b50505050600090565b507f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0841115613e54565b601b018116613e48565b60ff7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460401c1615613f1957565b7fd7e6bcf80000000000000000000000000000000000000000000000000000000060005260046000fd5b613f4b612f2e565b6020815191012060405160208101917f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f835260408201527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260a08152613e2160c082612e4d565b906000602091828151910182855af115613a2e576000513d614045575073ffffffffffffffffffffffffffffffffffffffff81163b155b6140015750565b73ffffffffffffffffffffffffffffffffffffffff907f5274afe7000000000000000000000000000000000000000000000000000000006000521660045260246000fd5b60011415613ffa565b9061408d575080511561406357805190602001fd5b7fd6bda2750000000000000000000000000000000000000000000000000000000060005260046000fd5b815115806140e2575b61409e575090565b73ffffffffffffffffffffffffffffffffffffffff907f9996b315000000000000000000000000000000000000000000000000000000006000521660045260246000fd5b50803b1561409656fea2646970667358221220dc66f03dbb44b5e24a9491e20f8054787007c1628c39eb00550453c588a0e50e64736f6c634300081e0033
Verified Source Code Full Match
Compiler: v0.8.30+commit.73712a01
EVM: paris
Optimization: Yes (1000000 runs)
Ownable2StepUpgradeable.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {OwnableUpgradeable} from "./OwnableUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This extension of the {Ownable} contract includes a two-step mechanism to transfer
* ownership, where the new owner must call {acceptOwnership} in order to replace the
* old one. This can help prevent common mistakes, such as transfers of ownership to
* incorrect accounts, or to contracts that are unable to interact with the
* permission system.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {
/// @custom:storage-location erc7201:openzeppelin.storage.Ownable2Step
struct Ownable2StepStorage {
address _pendingOwner;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable2Step")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant Ownable2StepStorageLocation = 0x237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c00;
function _getOwnable2StepStorage() private pure returns (Ownable2StepStorage storage $) {
assembly {
$.slot := Ownable2StepStorageLocation
}
}
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
function __Ownable2Step_init() internal onlyInitializing {
}
function __Ownable2Step_init_unchained() internal onlyInitializing {
}
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
Ownable2StepStorage storage $ = _getOwnable2StepStorage();
return $._pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*
* Setting `newOwner` to the zero address is allowed; this can be used to cancel an initiated ownership transfer.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
Ownable2StepStorage storage $ = _getOwnable2StepStorage();
$._pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
Ownable2StepStorage storage $ = _getOwnable2StepStorage();
delete $._pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}
OwnableUpgradeable.sol 119 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
/// @custom:storage-location erc7201:openzeppelin.storage.Ownable
struct OwnableStorage {
address _owner;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;
function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
assembly {
$.slot := OwnableStorageLocation
}
}
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
function __Ownable_init(address initialOwner) internal onlyInitializing {
__Ownable_init_unchained(initialOwner);
}
function __Ownable_init_unchained(address initialOwner) internal onlyInitializing {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
OwnableStorage storage $ = _getOwnableStorage();
return $._owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
OwnableStorage storage $ = _getOwnableStorage();
address oldOwner = $._owner;
$._owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Initializable.sol 238 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reinitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._initialized = version;
$._initializing = true;
_;
$._initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Pointer to storage slot. Allows integrators to override it with a custom storage location.
*
* NOTE: Consider following the ERC-7201 formula to derive storage locations.
*/
function _initializableStorageSlot() internal pure virtual returns (bytes32) {
return INITIALIZABLE_STORAGE;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
bytes32 slot = _initializableStorageSlot();
assembly {
$.slot := slot
}
}
}
UUPSUpgradeable.sol 152 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.22;
import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*/
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address private immutable __self = address(this);
/**
* @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
* and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
* while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
* If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
* be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
* during an upgrade.
*/
string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";
/**
* @dev The call is from an unauthorized context.
*/
error UUPSUnauthorizedCallContext();
/**
* @dev The storage `slot` is unsupported as a UUID.
*/
error UUPSUnsupportedProxiableUUID(bytes32 slot);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC-1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC-1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
_checkProxy();
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
_checkNotDelegated();
_;
}
function __UUPSUpgradeable_init() internal onlyInitializing {
}
function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
}
/**
* @dev Implementation of the ERC-1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate the implementation's compatibility when performing an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual notDelegated returns (bytes32) {
return ERC1967Utils.IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data);
}
/**
* @dev Reverts if the execution is not performed via delegatecall or the execution
* context is not of a proxy with an ERC-1967 compliant implementation pointing to self.
*/
function _checkProxy() internal view virtual {
if (
address(this) == __self || // Must be called through delegatecall
ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
) {
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Reverts if the execution is performed via delegatecall.
* See {notDelegated}.
*/
function _checkNotDelegated() internal view virtual {
if (address(this) != __self) {
// Must not be called through delegatecall
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
/**
* @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
*
* As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
* is expected to be the implementation slot in ERC-1967.
*
* Emits an {IERC1967-Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
revert UUPSUnsupportedProxiableUUID(slot);
}
ERC1967Utils.upgradeToAndCall(newImplementation, data);
} catch {
// The implementation is not UUPS
revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
}
}
}
ContextUpgradeable.sol 34 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
PausableUpgradeable.sol 133 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Pausable.sol)
pragma solidity ^0.8.20;
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
/// @custom:storage-location erc7201:openzeppelin.storage.Pausable
struct PausableStorage {
bool _paused;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Pausable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant PausableStorageLocation = 0xcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300;
function _getPausableStorage() private pure returns (PausableStorage storage $) {
assembly {
$.slot := PausableStorageLocation
}
}
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
/**
* @dev The operation failed because the contract is paused.
*/
error EnforcedPause();
/**
* @dev The operation failed because the contract is not paused.
*/
error ExpectedPause();
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
function __Pausable_init() internal onlyInitializing {
}
function __Pausable_init_unchained() internal onlyInitializing {
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
PausableStorage storage $ = _getPausableStorage();
return $._paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
if (paused()) {
revert EnforcedPause();
}
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
if (!paused()) {
revert ExpectedPause();
}
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
PausableStorage storage $ = _getPausableStorage();
$._paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
PausableStorage storage $ = _getPausableStorage();
$._paused = false;
emit Unpaused(_msgSender());
}
}
ReentrancyGuardUpgradeable.sol 108 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuardUpgradeable is Initializable {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
/// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard
struct ReentrancyGuardStorage {
uint256 _status;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant ReentrancyGuardStorageLocation = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) {
assembly {
$.slot := ReentrancyGuardStorageLocation
}
}
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
function __ReentrancyGuard_init() internal onlyInitializing {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal onlyInitializing {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
$._status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
// On the first call to nonReentrant, _status will be NOT_ENTERED
if ($._status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
$._status = ENTERED;
}
function _nonReentrantAfter() private {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
$._status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
return $._status == ENTERED;
}
}
draft-IERC1822.sol 20 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.20;
/**
* @dev ERC-1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822Proxiable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}
IERC1363.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";
IERC1967.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1967.sol)
pragma solidity ^0.8.20;
/**
* @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
*/
interface IERC1967 {
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Emitted when the beacon is changed.
*/
event BeaconUpgraded(address indexed beacon);
}
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";
IBeacon.sol 16 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.20;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {UpgradeableBeacon} will check that this address is a contract.
*/
function implementation() external view returns (address);
}
ERC1967Utils.sol 177 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (proxy/ERC1967/ERC1967Utils.sol)
pragma solidity ^0.8.22;
import {IBeacon} from "../beacon/IBeacon.sol";
import {IERC1967} from "../../interfaces/IERC1967.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";
/**
* @dev This library provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] slots.
*/
library ERC1967Utils {
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev The `implementation` of the proxy is invalid.
*/
error ERC1967InvalidImplementation(address implementation);
/**
* @dev The `admin` of the proxy is invalid.
*/
error ERC1967InvalidAdmin(address admin);
/**
* @dev The `beacon` of the proxy is invalid.
*/
error ERC1967InvalidBeacon(address beacon);
/**
* @dev An upgrade function sees `msg.value > 0` that may be lost.
*/
error ERC1967NonPayable();
/**
* @dev Returns the current implementation address.
*/
function getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the ERC-1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
if (newImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(newImplementation);
}
StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Performs implementation upgrade with additional setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-Upgraded} event.
*/
function upgradeToAndCall(address newImplementation, bytes memory data) internal {
_setImplementation(newImplementation);
emit IERC1967.Upgraded(newImplementation);
if (data.length > 0) {
Address.functionDelegateCall(newImplementation, data);
} else {
_checkNonPayable();
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*
* TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
* the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
*/
function getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the ERC-1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
if (newAdmin == address(0)) {
revert ERC1967InvalidAdmin(address(0));
}
StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {IERC1967-AdminChanged} event.
*/
function changeAdmin(address newAdmin) internal {
emit IERC1967.AdminChanged(getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the ERC-1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
if (newBeacon.code.length == 0) {
revert ERC1967InvalidBeacon(newBeacon);
}
StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;
address beaconImplementation = IBeacon(newBeacon).implementation();
if (beaconImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(beaconImplementation);
}
}
/**
* @dev Change the beacon and trigger a setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-BeaconUpgraded} event.
*
* CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
* it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
* efficiency.
*/
function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
_setBeacon(newBeacon);
emit IERC1967.BeaconUpgraded(newBeacon);
if (data.length > 0) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
} else {
_checkNonPayable();
}
}
/**
* @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
* if an upgrade doesn't perform an initialization call.
*/
function _checkNonPayable() private {
if (msg.value > 0) {
revert ERC1967NonPayable();
}
}
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[ERC-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC-20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
SafeERC20.sol 212 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}
Address.sol 150 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, bytes memory returndata) = recipient.call{value: amount}("");
if (!success) {
_revert(returndata);
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {Errors.FailedCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
* of an unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {Errors.FailedCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly ("memory-safe") {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert Errors.FailedCall();
}
}
}
Errors.sol 34 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
StorageSlot.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC-1967 implementation slot:
* ```solidity
* contract ERC1967 {
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct Int256Slot {
int256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Int256Slot` with member `value` located at `slot`.
*/
function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
/**
* @dev Returns a `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
}
EnergyBridge.sol 601 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
/**
* @dev Bridging contract between EWX and Ethereum.
* Enables Author nodes to periodically publish T2 transactional state.
* Allows Authors to be added and removed from participation in consensus.
* Lets Authors trigger periodic inflation of EWT.
* "lifts" whitelisted tokens from Ethereum addresses to EWX accounts.
* "lowers" tokens from EWX accounts to Ethereum addresses.
* Accepts ERC-2612 for single-step lifting of permit-based tokens.
* Proxy upgradeable implementation utilising EIP-1822.
*/
import './interfaces/IEnergyBridge.sol';
import '@openzeppelin/contracts/interfaces/IERC20.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import '@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol';
import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol';
import '@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol';
contract EnergyBridge is IEnergyBridge, Initializable, Ownable2StepUpgradeable, PausableUpgradeable, ReentrancyGuardUpgradeable, UUPSUpgradeable {
using SafeERC20 for IERC20;
string private constant EIP712_PREFIX = '\x19\x01';
bytes32 private constant VERSION_HASH = keccak256('1');
bytes32 private constant DOMAIN_TYPEHASH = keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)');
bytes32 private constant ADD_AUTHOR_TYPEHASH = keccak256('AddAuthor(bytes t1PubKey,bytes32 t2PubKey,uint256 expiry,uint32 t2TxId)');
bytes32 private constant LOWER_DATA_TYPEHASH = keccak256('LowerData(address token,uint256 amount,address recipient,uint32 lowerId)');
bytes32 private constant PUBLISH_ROOT_TYPEHASH = keccak256('PublishRoot(bytes32 rootHash,uint256 expiry,uint32 t2TxId)');
bytes32 private constant REMOVE_AUTHOR_TYPEHASH = keccak256('RemoveAuthor(bytes32 t2PubKey,bytes t1PubKey,uint256 expiry,uint32 t2TxId)');
bytes32 private constant TRIGGER_GROWTH_TYPEHASH = keccak256('TriggerGrowth(uint256 rewards,uint256 avgStaked,uint32 period,uint256 expiry,uint32 t2TxId)');
uint256 public constant GROWTH_PER_PERIOD = (2_500_000 * 1e18) / uint256(13); // 2.5m EWT annual growth target / 13 periods per year
uint256 private constant LOWER_DATA_LENGTH = 20 + 32 + 20 + 4; // token address + amount + recipient address + lower ID
uint256 private constant MINIMUM_AUTHOR_SET = 4;
uint256 private constant SIGNATURE_LENGTH = 65;
uint256 private constant T2_TOKEN_LIMIT = type(uint128).max;
uint256 private constant MINIMUM_LOWER_PROOF_LENGTH = LOWER_DATA_LENGTH + SIGNATURE_LENGTH * 2;
int8 private constant TX_SUCCEEDED = 1;
int8 private constant TX_PENDING = 0;
int8 private constant TX_FAILED = -1;
mapping(uint256 => bool) public isAuthor;
mapping(uint256 => bool) public authorIsActive;
mapping(address => bool) public tokenIsWhitelisted;
mapping(address => uint256) public t1AddressToId;
mapping(bytes32 => uint256) public t2PubKeyToId;
mapping(uint256 => address) public idToT1Address;
mapping(uint256 => bytes32) public idToT2PubKey;
mapping(bytes32 => bool) public isPublishedRootHash;
mapping(uint256 => bool) public isUsedT2TxId;
mapping(bytes32 => bool) public hasLowered;
mapping(uint32 => uint256) public growthAmount;
uint256 public nextAuthorId;
uint256 public numActiveAuthors;
address public EWT;
uint16 public contractVersion;
bool public liftingEnabled;
bool public loweringEnabled;
error AddressIsZero(); // 0x867915ab
error AddressMismatch(); // 0x4cd87fb5
error AlreadyAdded(); // 0xf411c327
error AlreadyInState(string, bool); // 0x01ab13a3
error AmountIsZero(); // 0x43ad20fc
error BadConfirmations(); // 0x409c8aac
error CannotChangeT2Key(bytes32); // 0x140c6815
error InvalidImplementation(); // 0x68155f9a
error InvalidProof(); // 0x09bde339
error InvalidT1Key(); // 0x4b0218a8
error InvalidT2Key(); // 0xf4fc87a4
error InvalidToken(); // 0xc1ab6dc1
error LiftFailed(); // 0xb19ed519
error LiftingDisabled(); // 0x07ebf7e8
error LiftLimitHit(); // 0xc36d2830
error LoweringDisabled(); // 0xaac0dd91
error LowerIsUsed(); // 0x24c1c1ce
error MintFailed(); // 0x07637bd8
error MissingKeys(); // 0x097ec09e
error NotAnAuthor(); // 0x157b0512
error NotEnoughAuthors(); // 0x3a6a875c
error PeriodIsUsed(); // 0x81a36023
error RootHashIsUsed(); // 0x2c8a3b6e
error T1AddressInUse(address); // 0x78f22dd1
error T2KeyInUse(bytes32); // 0x02f3935c
error TxIdIsUsed(); // 0x7edd16f0
error WindowExpired(); // 0x7bbfb6fe
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
modifier onlyWhitelisted(address token) {
if (!tokenIsWhitelisted[token]) revert InvalidToken();
_;
}
modifier withinCallWindow(uint256 expiry) {
if (block.timestamp > expiry) revert WindowExpired();
_;
}
function initialize(
address ewt,
address owner,
address[] calldata t1Addresses,
bytes32[] calldata t1PubKeysLHS,
bytes32[] calldata t1PubKeysRHS,
bytes32[] calldata t2PubKeys
) public initializer {
if (ewt == address(0)) revert AddressIsZero();
__Ownable_init(owner);
__Ownable2Step_init();
__Pausable_init();
__ReentrancyGuard_init();
__UUPSUpgradeable_init();
nextAuthorId = 1;
_initialiseAuthors(t1Addresses, t1PubKeysLHS, t1PubKeysRHS, t2PubKeys);
EWT = ewt;
_whitelistToken(ewt);
}
function name() public pure returns (string memory) {
return 'EnergyBridge';
}
function pause() external onlyOwner whenNotPaused {
_pause();
}
function unpause() external onlyOwner whenPaused {
_unpause();
}
/**
* @dev Allows the owner to enable/disable lifting.
*/
function toggleLifting(bool state) external onlyOwner {
if (liftingEnabled == state) revert AlreadyInState('lifting', state);
liftingEnabled = state;
emit LogLiftingEnabled(state);
}
/**
* @dev Allows the owner to enable/disable lowering.
*/
function toggleLowering(bool state) external onlyOwner {
if (loweringEnabled == state) revert AlreadyInState('lowering', state);
loweringEnabled = state;
emit LogLoweringEnabled(state);
}
/**
* @dev Lets the owner whitelist a token for lifting.
*/
function whitelistToken(address token) public onlyOwner {
_whitelistToken(token);
}
/**
* @dev Allows the owner to remove a token from the whitelist.
*/
function removeFromWhitelist(address token) external onlyOwner {
if (!tokenIsWhitelisted[token]) revert();
tokenIsWhitelisted[token] = false;
emit LogRemovedFromWhitelist(token);
}
/**
* @dev Enables authors to add a new author, permanently linking their T1 and T2 keys.
* Author activation will occur upon the first confirmation received from them.
* Can also be used to reactivate an author.
*/
function addAuthor(
bytes calldata t1PubKey,
bytes32 t2PubKey,
uint256 expiry,
uint32 t2TxId,
bytes calldata confirmations
) external whenNotPaused withinCallWindow(expiry) {
if (t1PubKey.length != 64) revert InvalidT1Key();
if (t2PubKey == bytes32(0)) revert InvalidT2Key();
address t1Address = _toAddress(t1PubKey);
uint256 id = t1AddressToId[t1Address];
if (isAuthor[id]) revert AlreadyAdded();
bytes32 proofHash = _toAddAuthorProofHash(t1PubKey, t2PubKey, expiry, t2TxId);
_verifyConfirmations(false, proofHash, confirmations);
_storeT2TxId(t2TxId);
if (id == 0) {
_addNewAuthor(t1Address, t2PubKey);
} else {
if (t2PubKey != idToT2PubKey[id]) revert CannotChangeT2Key(idToT2PubKey[id]);
isAuthor[id] = true;
}
emit LogAuthorAdded(t1Address, t2PubKey, t2TxId);
}
/**
* @dev Enables authors to remove an author, immediately revoking their authority in the contract.
*/
function removeAuthor(
bytes32 t2PubKey,
bytes calldata t1PubKey,
uint256 expiry,
uint32 t2TxId,
bytes calldata confirmations
) external whenNotPaused withinCallWindow(expiry) {
if (t1PubKey.length != 64) revert InvalidT1Key();
uint256 id = t2PubKeyToId[t2PubKey];
if (!isAuthor[id]) revert NotAnAuthor();
bytes32 proofHash = _toRemoveAuthorProofHash(t2PubKey, t1PubKey, expiry, t2TxId);
_verifyConfirmations(false, proofHash, confirmations);
if (numActiveAuthors <= MINIMUM_AUTHOR_SET) revert NotEnoughAuthors();
_storeT2TxId(t2TxId);
isAuthor[id] = false;
if (authorIsActive[id]) {
authorIsActive[id] = false;
unchecked {
--numActiveAuthors;
}
}
emit LogAuthorRemoved(idToT1Address[id], t2PubKey, t2TxId);
}
/**
* @dev Enables authors to publish a Merkle root summarising the latest set of T2 extrinsic calls.
*/
function publishRoot(bytes32 rootHash, uint256 expiry, uint32 t2TxId, bytes calldata confirmations) external whenNotPaused withinCallWindow(expiry) {
if (isPublishedRootHash[rootHash]) revert RootHashIsUsed();
bytes32 proofHash = _toPublishRootProofHash(rootHash, expiry, t2TxId);
_verifyConfirmations(false, proofHash, confirmations);
_storeT2TxId(t2TxId);
isPublishedRootHash[rootHash] = true;
emit LogRootPublished(rootHash, t2TxId);
}
/**
* @dev Enables authors to trigger inflation of the core token supply, according to the current growth rate.
*/
// TODO: Remove legacy params after T2 proof creation is updated; streamline this function.
function triggerGrowth(
uint256 rewards,
uint256 avgStaked,
uint32 period,
uint256 expiry,
uint32 t2TxId,
bytes calldata confirmations
) external whenNotPaused withinCallWindow(expiry) {
if (growthAmount[period] != 0) revert PeriodIsUsed();
growthAmount[period] = GROWTH_PER_PERIOD;
bytes32 proofHash = _toTriggerGrowthProofHash(rewards, avgStaked, period, expiry, t2TxId);
_verifyConfirmations(false, proofHash, confirmations);
_storeT2TxId(t2TxId);
(bool success, ) = EWT.call(abi.encodeWithSignature('mint(uint256)', GROWTH_PER_PERIOD));
if (!success) revert MintFailed();
emit LogGrowth(GROWTH_PER_PERIOD, period);
}
/**
* @dev Lets the caller lift an amount of ERC20 tokens to the specified T2 recipient, provided they have first been approved.
*/
function lift(address token, bytes32 t2PubKey, uint256 amount) external whenNotPaused nonReentrant onlyWhitelisted(token) {
if (!liftingEnabled) revert LiftingDisabled();
if (t2PubKey == bytes32(0)) revert InvalidT2Key();
emit LogLifted(token, bytes32(t2PubKey), _lift(msg.sender, token, amount));
}
/**
* @dev Lift variant accepting an ERC-2612 permit in place of prior token approval.
*/
function permitLift(
address token,
bytes32 t2PubKey,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external whenNotPaused nonReentrant onlyWhitelisted(token) {
if (!liftingEnabled) revert LiftingDisabled();
if (t2PubKey == bytes32(0)) revert InvalidT2Key();
IERC20Permit(token).permit(msg.sender, address(this), amount, deadline, v, r, s);
emit LogLifted(token, t2PubKey, _lift(msg.sender, token, amount));
}
/** @dev Checks a lower proof. Returns the details, proof validity, and claim status.
* For unclaimed lowers, if the required confirmations exceeds those provided the proof will need to be regenerated.
*/
function checkLower(
bytes calldata lowerProof
)
external
view
returns (
address token,
uint256 amount,
address recipient,
uint32 lowerId,
uint256 confirmationsRequired,
uint256 confirmationsProvided,
bool proofIsValid,
bool lowerIsClaimed
)
{
if (lowerProof.length < MINIMUM_LOWER_PROOF_LENGTH) return (address(0), 0, address(0), 0, 0, 0, false, false);
(token, amount, recipient, lowerId) = _extractLowerData(lowerProof);
bytes32 proofHash = _toLowerDataProofHash(token, amount, recipient, lowerId);
uint256 numConfirmations = (lowerProof.length - LOWER_DATA_LENGTH) / SIGNATURE_LENGTH;
bool[] memory confirmed = new bool[](nextAuthorId);
uint256 confirmationsOffset;
lowerIsClaimed = hasLowered[proofHash];
confirmationsProvided = numConfirmations;
confirmationsRequired = _requiredConfirmations();
assembly {
confirmationsOffset := add(lowerProof.offset, LOWER_DATA_LENGTH)
}
for (uint256 i; i < numConfirmations; ++i) {
uint256 id = _recoverAuthorId(proofHash, confirmationsOffset, i);
if (authorIsActive[id] && !confirmed[id]) confirmed[id] = true;
else confirmationsProvided--;
}
proofIsValid = confirmationsProvided >= confirmationsRequired;
}
/**
* @dev Claims the funds due to the recipient specified in the proof.
*/
function claimLower(bytes calldata lowerProof) external whenNotPaused nonReentrant {
if (!loweringEnabled) revert LoweringDisabled();
(address token, uint256 amount, address recipient, uint32 lowerId) = _extractLowerData(lowerProof);
if (recipient == address(0)) revert AddressIsZero();
_processLower(token, amount, recipient, lowerId, lowerProof);
IERC20(token).safeTransfer(recipient, amount);
emit LogLowerClaimed(lowerId);
}
/**
* @dev Confirms the existence of a T2 extrinsic call within a published root.
*/
function confirmTransaction(bytes32 leafHash, bytes32[] calldata merklePath) external view returns (bool) {
bytes32 node;
uint256 i;
do {
node = merklePath[i];
leafHash = leafHash < node ? keccak256(abi.encode(leafHash, node)) : keccak256(abi.encode(node, leafHash));
unchecked {
++i;
}
} while (i < merklePath.length);
return isPublishedRootHash[leafHash];
}
/**
* @dev Checks the status of an author transaction.
*/
function corroborate(uint32 t2TxId, uint256 expiry) external view returns (int8) {
if (isUsedT2TxId[t2TxId]) return TX_SUCCEEDED;
else if (block.timestamp > expiry) return TX_FAILED;
else return TX_PENDING;
}
/**
* @dev Disabled function
*/
function renounceOwnership() public view override onlyOwner {
revert('Disabled');
}
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {
(bool ok, bytes memory result) = newImplementation.staticcall(abi.encodeWithSignature('name()'));
if (!ok || keccak256(bytes(abi.decode(result, (string)))) != keccak256(bytes(name()))) revert InvalidImplementation();
unchecked {
++contractVersion;
}
emit LogVersion(contractVersion, newImplementation);
}
function _activateAuthor(uint256 id) private {
authorIsActive[id] = true;
unchecked {
++numActiveAuthors;
}
}
function _addNewAuthor(address t1Address, bytes32 t2PubKey) private returns (uint256 id) {
unchecked {
id = nextAuthorId++;
}
if (t2PubKeyToId[t2PubKey] != 0) revert T2KeyInUse(t2PubKey);
idToT1Address[id] = t1Address;
idToT2PubKey[id] = t2PubKey;
t1AddressToId[t1Address] = id;
t2PubKeyToId[t2PubKey] = id;
isAuthor[id] = true;
}
function _domainSeparator() private view returns (bytes32) {
return keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name())), VERSION_HASH, block.chainid, address(this)));
}
function _extractLowerData(bytes calldata lowerProof) private pure returns (address token, uint256 amount, address recipient, uint32 lowerId) {
if (lowerProof.length < MINIMUM_LOWER_PROOF_LENGTH) revert InvalidProof();
assembly {
token := shr(96, calldataload(lowerProof.offset))
amount := calldataload(add(lowerProof.offset, 20))
recipient := shr(96, calldataload(add(lowerProof.offset, 52)))
lowerId := shr(224, calldataload(add(lowerProof.offset, 72)))
}
}
function _initialiseAuthors(
address[] calldata t1Addresses,
bytes32[] calldata t1PubKeysLHS,
bytes32[] calldata t1PubKeysRHS,
bytes32[] calldata t2PubKeys
) private {
uint256 numAuth = t1Addresses.length;
if (numAuth < MINIMUM_AUTHOR_SET) revert NotEnoughAuthors();
if (t1PubKeysLHS.length != numAuth || t1PubKeysRHS.length != numAuth || t2PubKeys.length != numAuth) revert MissingKeys();
bytes memory t1PubKey;
address t1Address;
uint256 i;
do {
t1Address = t1Addresses[i];
t1PubKey = abi.encode(t1PubKeysLHS[i], t1PubKeysRHS[i]);
if (_toAddress(t1PubKey) != t1Address) revert AddressMismatch();
if (t1AddressToId[t1Address] != 0) revert T1AddressInUse(t1Address);
_activateAuthor(_addNewAuthor(t1Address, t2PubKeys[i]));
unchecked {
++i;
}
} while (i < numAuth);
}
function _lift(address lifter, address token, uint256 amount) private returns (uint256) {
uint256 existingBalance = IERC20(token).balanceOf(address(this));
IERC20(token).safeTransferFrom(lifter, address(this), amount);
uint256 newBalance = IERC20(token).balanceOf(address(this));
if (newBalance <= existingBalance) revert LiftFailed();
if (newBalance > T2_TOKEN_LIMIT) revert LiftLimitHit();
return newBalance - existingBalance;
}
function _processLower(address token, uint256 amount, address recipient, uint32 lowerId, bytes calldata lowerProof) private {
bytes32 proofHash = _toLowerDataProofHash(token, amount, recipient, lowerId);
if (hasLowered[proofHash]) revert LowerIsUsed();
hasLowered[proofHash] = true;
_verifyConfirmations(true, proofHash, lowerProof[LOWER_DATA_LENGTH:]);
}
function _recoverAuthorId(bytes32 msgHash, uint256 confirmationsOffset, uint256 confirmationsIndex) private view returns (uint256 id) {
bytes32 r;
bytes32 s;
uint8 v;
assembly {
let sig := add(confirmationsOffset, mul(confirmationsIndex, SIGNATURE_LENGTH))
r := calldataload(sig)
s := calldataload(add(sig, 32))
v := byte(0, calldataload(add(sig, 64)))
}
if (v < 27) {
unchecked {
v += 27;
}
}
id = v < 29 && uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0 ? t1AddressToId[ecrecover(msgHash, v, r, s)] : 0;
}
function _requiredConfirmations() private view returns (uint256 required) {
unchecked {
required = (numActiveAuthors * 2 + 2) / 3;
}
}
function _storeT2TxId(uint256 t2TxId) private {
if (isUsedT2TxId[t2TxId]) revert TxIdIsUsed();
isUsedT2TxId[t2TxId] = true;
}
function _toAddress(bytes memory t1PubKey) private pure returns (address) {
return address(uint160(uint256(keccak256(t1PubKey))));
}
function _toAddAuthorProofHash(bytes calldata t1PubKey, bytes32 t2PubKey, uint256 expiry, uint32 t2TxId) private view returns (bytes32) {
bytes32 t1PubKeyHash = keccak256(t1PubKey);
bytes32 structHash = keccak256(abi.encode(ADD_AUTHOR_TYPEHASH, t1PubKeyHash, t2PubKey, expiry, t2TxId));
return keccak256(abi.encodePacked(EIP712_PREFIX, _domainSeparator(), structHash));
}
function _toLowerDataProofHash(address token, uint256 amount, address recipient, uint32 lowerId) private view returns (bytes32) {
bytes32 structHash = keccak256(abi.encode(LOWER_DATA_TYPEHASH, token, amount, recipient, lowerId));
return keccak256(abi.encodePacked(EIP712_PREFIX, _domainSeparator(), structHash));
}
function _toPublishRootProofHash(bytes32 rootHash, uint256 expiry, uint32 t2TxId) private view returns (bytes32) {
bytes32 structHash = keccak256(abi.encode(PUBLISH_ROOT_TYPEHASH, rootHash, expiry, t2TxId));
return keccak256(abi.encodePacked(EIP712_PREFIX, _domainSeparator(), structHash));
}
function _toRemoveAuthorProofHash(bytes32 t2PubKey, bytes calldata t1PubKey, uint256 expiry, uint32 t2TxId) private view returns (bytes32) {
bytes32 t1PubKeyHash = keccak256(t1PubKey);
bytes32 structHash = keccak256(abi.encode(REMOVE_AUTHOR_TYPEHASH, t2PubKey, t1PubKeyHash, expiry, t2TxId));
return keccak256(abi.encodePacked(EIP712_PREFIX, _domainSeparator(), structHash));
}
function _toTriggerGrowthProofHash(uint256 rewards, uint256 avgStaked, uint32 period, uint256 expiry, uint32 t2TxId) private view returns (bytes32) {
bytes32 structHash = keccak256(abi.encode(TRIGGER_GROWTH_TYPEHASH, rewards, avgStaked, period, expiry, t2TxId));
return keccak256(abi.encodePacked(EIP712_PREFIX, _domainSeparator(), structHash));
}
function _verifyConfirmations(bool isLower, bytes32 msgHash, bytes calldata confirmations) private {
uint256[] memory confirmed = new uint256[](nextAuthorId);
uint256 requiredConfirmations = _requiredConfirmations();
uint256 numConfirmations = confirmations.length / SIGNATURE_LENGTH;
uint256 confirmationsOffset;
uint256 confirmationsIndex;
uint256 validConfirmations;
uint256 authorId;
assembly {
confirmationsOffset := confirmations.offset
}
// Setup the first iteration of the do-while loop:
if (isLower) {
// For lowers all confirmations are explicit so the first authorId is extracted from the first confirmation
authorId = _recoverAuthorId(msgHash, confirmationsOffset, confirmationsIndex);
confirmationsIndex = 1;
} else {
// For non-lowers there is a high chance the sender is an author and, if so, their confirmation is implicit
authorId = t1AddressToId[msg.sender];
unchecked {
++numConfirmations;
}
}
do {
if (!authorIsActive[authorId]) {
if (isAuthor[authorId]) {
_activateAuthor(authorId);
unchecked {
++validConfirmations;
}
requiredConfirmations = _requiredConfirmations();
if (validConfirmations == requiredConfirmations) return; // success
confirmed[authorId] = 1;
}
} else if (confirmed[authorId] == 0) {
unchecked {
++validConfirmations;
}
if (validConfirmations == requiredConfirmations) return; // success
confirmed[authorId] = 1;
}
// Setup the next iteration of the loop
authorId = _recoverAuthorId(msgHash, confirmationsOffset, confirmationsIndex);
unchecked {
++confirmationsIndex;
}
} while (confirmationsIndex <= numConfirmations);
revert BadConfirmations();
}
function _whitelistToken(address token) private {
if (token == address(0)) revert AddressIsZero();
if (tokenIsWhitelisted[token]) revert();
tokenIsWhitelisted[token] = true;
emit LogWhitelisted(token);
}
}
IEnergyBridge.sol 52 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
interface IEnergyBridge {
event LogLiftingEnabled(bool indexed state);
event LogLoweringEnabled(bool indexed state);
event LogAuthorAdded(address indexed t1Address, bytes32 indexed t2PubKey, uint32 indexed t2TxId);
event LogAuthorRemoved(address indexed t1Address, bytes32 indexed t2PubKey, uint32 indexed t2TxId);
event LogGrowth(uint256 indexed amount, uint32 indexed period);
event LogLifted(address indexed token, bytes32 indexed t2PubKey, uint256 amount);
event LogLowerClaimed(uint32 indexed lowerId);
event LogRootPublished(bytes32 indexed rootHash, uint32 indexed t2TxId);
event LogWhitelisted(address indexed token);
event LogRemovedFromWhitelist(address indexed token);
event LogVersion(uint16 indexed newVersion, address indexed implementation);
// Owner only
function toggleLifting(bool state) external;
function toggleLowering(bool state) external;
function whitelistToken(address token) external;
function removeFromWhitelist(address token) external;
// Authors only
function addAuthor(bytes calldata t1PubKey, bytes32 t2PubKey, uint256 expiry, uint32 t2TxId, bytes calldata confirmations) external;
function removeAuthor(bytes32 t2PubKey, bytes calldata t1PubKey, uint256 expiry, uint32 t2TxId, bytes calldata confirmations) external;
function publishRoot(bytes32 rootHash, uint256 expiry, uint32 t2TxId, bytes calldata confirmations) external;
function triggerGrowth(uint256 rewards, uint256 avgStaked, uint32 period, uint256 expiry, uint32 t2TxId, bytes calldata confirmations) external;
// Public
function lift(address token, bytes32 t2PubKey, uint256 amount) external;
function permitLift(address token, bytes32 t2PubKey, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external;
function claimLower(bytes calldata lowerProof) external;
// View
function checkLower(
bytes calldata lowerProof
)
external
view
returns (
address token,
uint256 amount,
address recipient,
uint32 lowerId,
uint256 confirmationsRequired,
uint256 confirmationsProvided,
bool proofIsValid,
bool lowerIsClaimed
);
function confirmTransaction(bytes32 leafHash, bytes32[] calldata merklePath) external view returns (bool);
function corroborate(uint32 t2TxId, uint256 expiry) external view returns (int8);
}
Read Contract
EWT 0x3d0beb65 → address
GROWTH_PER_PERIOD 0x5011ed4f → uint256
UPGRADE_INTERFACE_VERSION 0xad3cb1cc → string
authorIsActive 0x66beb4cb → bool
checkLower 0xdf643512 → address, uint256, address, uint32, uint256, uint256, bool, bool
confirmTransaction 0x8ebd7265 → bool
contractVersion 0xa0a8e460 → uint16
corroborate 0xe6f4b533 → int8
growthAmount 0xd2d6f4d5 → uint256
hasLowered 0xe51d0921 → bool
idToT1Address 0x17a691aa → address
idToT2PubKey 0x8c552978 → bytes32
isAuthor 0x0d238f9e → bool
isPublishedRootHash 0xb9b17e7f → bool
isUsedT2TxId 0x239c5907 → bool
liftingEnabled 0x4fc221bf → bool
loweringEnabled 0x64bac416 → bool
name 0x06fdde03 → string
nextAuthorId 0x872d7d57 → uint256
numActiveAuthors 0xb4d034d6 → uint256
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
pendingOwner 0xe30c3978 → address
proxiableUUID 0x52d1902d → bytes32
renounceOwnership 0x715018a6
t1AddressToId 0xe8fed1d6 → uint256
t2PubKeyToId 0xe69fadb4 → uint256
tokenIsWhitelisted 0x86af1c73 → bool
Write Contract 17 functions
These functions modify contract state and require a wallet transaction to execute.
acceptOwnership 0x79ba5097
No parameters
addAuthor 0xb6851152
bytes t1PubKey
bytes32 t2PubKey
uint256 expiry
uint32 t2TxId
bytes confirmations
claimLower 0xa8f37db4
bytes lowerProof
initialize 0x025df29b
address ewt
address owner
address[] t1Addresses
bytes32[] t1PubKeysLHS
bytes32[] t1PubKeysRHS
bytes32[] t2PubKeys
lift 0x6ac39100
address token
bytes32 t2PubKey
uint256 amount
pause 0x8456cb59
No parameters
permitLift 0x18b3d210
address token
bytes32 t2PubKey
uint256 amount
uint256 deadline
uint8 v
bytes32 r
bytes32 s
publishRoot 0x0664c0ba
bytes32 rootHash
uint256 expiry
uint32 t2TxId
bytes confirmations
removeAuthor 0x146b3b52
bytes32 t2PubKey
bytes t1PubKey
uint256 expiry
uint32 t2TxId
bytes confirmations
removeFromWhitelist 0x8ab1d681
address token
toggleLifting 0x1b4097d8
bool state
toggleLowering 0x8cacd6e7
bool state
transferOwnership 0xf2fde38b
address newOwner
triggerGrowth 0x2efe95be
uint256 rewards
uint256 avgStaked
uint32 period
uint256 expiry
uint32 t2TxId
bytes confirmations
unpause 0x3f4ba83a
No parameters
upgradeToAndCall 0x4f1ef286
address newImplementation
bytes data
whitelistToken 0x6247f6f2
address token
Recent Transactions
No transactions found for this address