Address Contract Verified
Address
0xcA10Fb0f2Ce19CDE44B42DF2F42607977Dfa4549
Balance
0 ETH
Nonce
1
Code Size
20585 bytes
Creator
0x1FcCC097...1Fb7 at tx 0x47acad46...342efa
Indexed Transactions
0 (1 on-chain, 1.5% indexed)
Contract Bytecode
20585 bytes
0x60806040526004361015610011575f80fd5b5f3560e01c8063078dfbe71461350157806313b6e971146132ef57806313d65dcb14612fb357806316ac7e3014612f0e5780631c9bdb4914612e885780632104902814612e185780632477bfbe14612dd75780632982d51914612d865780633659cfe614612b07578063366c771d1461299457806338b8765c1461295a5780633e39b6501461287c57806349be407d146127f35780634e71e0c8146126ed5780634f1ef2861461236c57806352d1902d14612253578063592557061461218c578063632c096d14612084578063646fb67c14611fa0578063698766ee146115485780636aea2826146114cf57806382ae9ef71461133457806382dabb21146112c657806389c071ea146112585780638d66c284146111135780638da5cb5b146110c35780638f45ff7814610f0457806392a8b2d314610ea1578063945f183814610e2957806399a2af7514610dee5780639efc757514610db35780639f752aef14610d2a578063a0e1163414610cd9578063a71f6f5f14610c4c578063b292bf9514610bff578063bfa5b32414610bbc578063c291230d14610af6578063c4d66de8146107f9578063cc88370e14610635578063d45f5e21146105dc578063d5cd7d201461052e578063e30c3978146104dd578063e5c6493514610362578063f144cf17146102d7578063f4359ce51461029c578063f7f03fea1461025e5763fa78668f1461021e575f80fd5b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a5760206040516303bfc4008152f35b5f80fd5b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a576020609a5460801c604051908152f35b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57602060405162093a808152f35b3461025a5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a576020610310613682565b6fffffffffffffffffffffffffffffffff908161032b61381f565b165f5260a1835273ffffffffffffffffffffffffffffffffffffffff600160405f200191165f52825260405f205416604051908152f35b3461025a576103703661397e565b73ffffffffffffffffffffffffffffffffffffffff939193928360a45416331480156104d1575b6103a090613a79565b8181036104a757925f5b848110610461575060405193806040860160408752526060850193915f905b82821061043d575050505082820360208401528082527f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811161025a577ff928912629bf241f6bddb48fd8de3f071422321e8118042858e8e4a901d2566993602092849260051b80928583013701030190a1005b909192946001908261044e886136c8565b16815260209081019601939201906103c9565b8061047a6104756001938888999699613a48565b613a58565b8661048683878b613a48565b359161049183614b17565b165f5260a660205260405f2055019390936103aa565b60046040517fa24a13a6000000000000000000000000000000000000000000000000000000008152fd5b505f5484163314610397565b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57602073ffffffffffffffffffffffffffffffffffffffff60015416604051908152f35b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a5760405180609b5491828152602080910192609b5f527fbba9db4cdbea0a37c207bbb83e20f828cd4441c49891101dc94fd20dc8efc349915f905b8282106105c5576105c1856105ad81890382613766565b6040519182916020835260208301906137d6565b0390f35b835486529485019460019384019390910190610596565b3461025a5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a5761062d73ffffffffffffffffffffffffffffffffffffffff5f541633146139e3565b600435603255005b3461025a5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57609d80546004356024803590838210156107cf5761068283836141a2565b92600193600181018091116107a25761069a90613af2565b95815b848111156106c35787876105c160405192839283526040602084015260408301906137d6565b8681101561077657815f5273ffffffffffffffffffffffffffffffffffffffff817fd26e832454299e9fabb89e0e5fffdc046d4e14431bc1bf607ffb2e8a1ddecf7b01541661071b61071585846141a2565b8a613ade565b527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811461074a57850161069d565b837f4e487b71000000000000000000000000000000000000000000000000000000005f5260116004525ffd5b837f4e487b71000000000000000000000000000000000000000000000000000000005f5260326004525ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b60046040517f7f52b2bf000000000000000000000000000000000000000000000000000000008152fd5b3461025a5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57610830613682565b600190815460ff8160a81c161590818092610ae7575b8015610ace575b15610a4a5781740100000000000000000000000000000000000000007fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff8316178555610a08575b5082549160ff8360a81c16156109845773ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffff00000000000000000000000000000000000000005f5416175f556fffffffffffffffffffffffffffffffff61090262093a80824216046148d8565b167fffffffffffffffffffffffffffffffff00000000000000000000000000000000609a541617609a5561093257005b7f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498917fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff602092168155604051908152a1005b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152fd5b7fffffffffffffffffffff0000ffffffffffffffffffffffffffffffffffffffff16750101000000000000000000000000000000000000000017835583610894565b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a65640000000000000000000000000000000000006064820152fd5b50303b15801561084d57508360ff8260a01c161461084d565b508360ff8260a01c1610610846565b60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57610b286137bf565b6fffffffffffffffffffffffffffffffff90610b4a62093a80834216046148d8565b91821691825f5260a160205260ff60405f20541615610b8b57610b789250609a5460801c9060a75492614308565b47610b7f57005b610b8947336141de565b005b602483604051907f760c443c0000000000000000000000000000000000000000000000000000000082526004820152fd5b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a5760206040516a084595161401484a0000008152f35b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a5760206fffffffffffffffffffffffffffffffff609a5416604051908152f35b3461025a5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a577f8cbc4fe2c8f6dfa7ac4f8affa74f9664acfb5c6fd044f51706e458cb5a8b8fa46020600435610cc373ffffffffffffffffffffffffffffffffffffffff5f541633146139e3565b610ccc81614b17565b8060a755604051908152a1005b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57602073ffffffffffffffffffffffffffffffffffffffff60a55416604051908152f35b3461025a5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57610d61613682565b73ffffffffffffffffffffffffffffffffffffffff90610d85825f541633146139e3565b167fffffffffffffffffffffffff000000000000000000000000000000000000000060a454161760a4555f80f35b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a576020603254604051908152f35b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57602060a754604051908152f35b3461025a5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a5773ffffffffffffffffffffffffffffffffffffffff610e75613682565b165f90815260a660205260409020548015610e96576020905b604051908152f35b50602060a754610e8e565b3461025a5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a5773ffffffffffffffffffffffffffffffffffffffff610eed613682565b165f5260a6602052602060405f2054604051908152f35b3461025a57610f123661385d565b909173ffffffffffffffffffffffffffffffffffffffff8091165f52602060a2815260405f209367ffffffffffffffff8086541694610f50816137a7565b94610f5e6040519687613766565b8186527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0610f8b836137a7565b015f5b81811061109e5750505f916001809901925b81811061103d5750505050505060405193849360408501908552604083860152835180915260609280606087019501935f905b838210610fe05787870388f35b91859750828761102b8799849895979951805167ffffffffffffffff16825260209081015180516fffffffffffffffffffffffffffffffff9081168385015291015116604090910152565b01970192018796959391949294610fd3565b988983611052610475849b9c9a9d868b613a48565b165f52848b5260405f20611079836040519261106d8461371a565b89815416845201613e00565b8c820152611087828c613ade565b52611092818b613ade565b50019895979698610fa0565b9580999798966110af969496614145565b82828c010152019895979698949294610f8e565b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57602073ffffffffffffffffffffffffffffffffffffffff5f5416604051908152f35b3461025a5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a5761114a61383e565b60243567ffffffffffffffff811161025a5761116a9036906004016136e9565b6fffffffffffffffffffffffffffffffff80931662093a808106611227575f9291925260209060a160205260405f20908154936111a681613af2565b936001938401915f5b8181106111e45788886105c189604051938360ff8695161515855260081c1660208401526060604084015260608301906138cc565b8073ffffffffffffffffffffffffffffffffffffffff6112096104758994868a613a48565b165f528484528960405f205416611220828a613ade565b52016111af565b602490604051907ff7e2d9d20000000000000000000000000000000000000000000000000000000082526004820152fd5b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57602060405173ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000007b1014c88f14c9e910092526db57a20052e989f168152f35b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57602060405173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004f30a9d41b80ecc5b94306ab4364951ae3170210168152f35b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57609b80545f5b81811061144b576fffffffffffffffffffffffffffffffff61139062093a80824216046148d8565b5b8180609a5416911690811180611434575b15610b8957807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6c580915f5260a160205260405f2060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008254161790550181811115611391577f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b50805f5260a160205260ff60405f205416156113a2565b82548110156114a257600190835f5261149c73ffffffffffffffffffffffffffffffffffffffff827fbba9db4cdbea0a37c207bbb83e20f828cd4441c49891101dc94fd20dc8efc349015416613e6f565b01611368565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b3461025a5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57611506613682565b61150e6136a5565b9073ffffffffffffffffffffffffffffffffffffffff8091165f5260a360205260405f2091165f52602052602060405f2054604051908152f35b3461025a576115563661397e565b92908383036104a75773ffffffffffffffffffffffffffffffffffffffff5f5416331493841580611ec4575b611e9457604051946115938661371a565b5f808752602087015215611da4576fffffffffffffffffffffffffffffffff6303bfc400814216018181116107a25762093a80826115d29216046148d8565b1660208601526a084595161401484a00000085525b5f5b84811061165057335f5260a260205267ffffffffffffffff60405f205416670de0b6b3a76400009081811161161a57005b604491604051917f903482f500000000000000000000000000000000000000000000000000000000835260048301526024820152fd5b61168873ffffffffffffffffffffffffffffffffffffffff611676610475848989613a48565b165f52609c60205260405f2054151590565b611d89575b61169b610475828787613a48565b906116af6116aa828587613a48565b61418d565b6040516116bb8161371a565b5f81525f602082015290335f5260a260205260405f209073ffffffffffffffffffffffffffffffffffffffff85165f5260a060205260405f20916001810160205261170b600160405f2001613e00565b6fffffffffffffffffffffffffffffffff815116611b6a575b5067ffffffffffffffff8216611834575b50507fa512c82e73ec974de3c794a3ea6bbdfbad18531c1394ace9972f3f0166b67863604073ffffffffffffffffffffffffffffffffffffffff6001968783519501546fffffffffffffffffffffffffffffffff8116865260801c60208601521692a273ffffffffffffffffffffffffffffffffffffffff6117bb610475848a8a613a48565b6118066117cc6116aa86898b613a48565b9367ffffffffffffffff604051951685526020850190602090816fffffffffffffffffffffffffffffffff91828151168552015116910152565b16907fc71e393f1527f71ce01b78ea87c9bd4fca84f1482359ce7ac9b73f358c61b1e160603392a3016115e9565b90925061186273ffffffffffffffffffffffffffffffffffffffff86165f52609c60205260405f2054151590565b15611b2357604051926118748461371a565b5f84525f6020850152670de0b6b3a76400006303bfc4006118b38d6fffffffffffffffffffffffffffffffff67ffffffffffffffff86169151166142f5565b04046fffffffffffffffffffffffffffffffff811161025a576118f68c6fffffffffffffffffffffffffffffffff6020818095169283828b0152015116906148fe565b168452611aaa846fffffffffffffffffffffffffffffffff602061191c60018801613e00565b6119ae83806119608186604051966119338861371a565b5f88525f828901528261194e8c828085511691511690613e4b565b16885201511682878a01511690613e4b565b1683850181905292517fffffffffffffffffffffffffffffffff0000000000000000000000000000000060809490941b841691166fffffffffffffffffffffffffffffffff161760018a0155565b828285015116836119be86614a60565b165f5260028901835260405f209082856119dc845493828516613e4b565b16911617905560016040516119f08161371a565b67ffffffffffffffff8816815283810195865273ffffffffffffffffffffffffffffffffffffffff8d165f52818901845267ffffffffffffffff60405f209151167fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000008254161781550193519083825116908554161784550151166fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b81549067ffffffffffffffff80821681841601116107a25767ffffffffffffffff90811681831601167fffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000919091161790557fa512c82e73ec974de3c794a3ea6bbdfbad18531c1394ace9972f3f0166b678636040611735565b60248573ffffffffffffffffffffffffffffffffffffffff604051917f913accad000000000000000000000000000000000000000000000000000000008352166004820152fd5b611b9573ffffffffffffffffffffffffffffffffffffffff88165f52609c60205260405f2054151590565b80611d46575b611c4d575b5073ffffffffffffffffffffffffffffffffffffffff86165f526001810160205267ffffffffffffffff60405f20541681549067ffffffffffffffff8181841603116107a25767ffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000918184160316911617815573ffffffffffffffffffffffffffffffffffffffff86165f52600181016020525f60016040822082815501558b611724565b60018401906fffffffffffffffffffffffffffffffff611d0c81611c7085613e00565b611d0460405191611c808361371a565b5f835283806020808601935f855282611ca18c8280855116915116906148b6565b1687520151169381611cbb60208b019682885116906148b6565b1692839052517fffffffffffffffffffffffffffffffff0000000000000000000000000000000060809390931b831691166fffffffffffffffffffffffffffffffff1617909755565b511692614a60565b165f526002850160205260405f20916fffffffffffffffffffffffffffffffff611d3a8454938285166148b6565b1691161790558b611ba0565b506fffffffffffffffffffffffffffffffff60208201511615158015611b9b57506fffffffffffffffffffffffffffffffff611d8182614a60565b164210611b9b565b611d9f611d9a610475838888613a48565b613e6f565b61168d565b6040517fcb6b4f3c00000000000000000000000000000000000000000000000000000000815233600482015260408160248173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004f30a9d41b80ecc5b94306ab4364951ae3170210165afa908115611e89575f905f92611e41575b506fffffffffffffffffffffffffffffffff80921660208801521685526115e7565b9150506040813d604011611e81575b81611e5d60409383613766565b8101031261025a57611e7a6020611e7383614170565b9201614170565b9087611e1f565b3d9150611e50565b6040513d5f823e3d90fd5b60246040517fe7640c03000000000000000000000000000000000000000000000000000000008152336004820152fd5b506040517f70a0823100000000000000000000000000000000000000000000000000000000815233600482015260208160248173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004f30a9d41b80ecc5b94306ab4364951ae3170210165afa8015611e89575f90611f57575b6fffffffffffffffffffffffffffffffff91501615611582565b506020813d602011611f98575b81611f7160209383613766565b8101031261025a57611f936fffffffffffffffffffffffffffffffff91614170565b611f3d565b3d9150611f64565b3461025a5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57611fd7613682565b611fdf6136a5565b90611fe8614145565b5073ffffffffffffffffffffffffffffffffffffffff8091165f5260a2602052600160405f200191165f52602052606060405f2061204260016040519261202e8461371a565b67ffffffffffffffff815416845201613e00565b602082810191825260408051935167ffffffffffffffff168452915180516fffffffffffffffffffffffffffffffff908116858401529101511690820152f35bf35b3461025a5760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a576120bb613682565b6120c36136a5565b604435916120cf614145565b5073ffffffffffffffffffffffffffffffffffffffff8091165f5260a360205260405f2091165f5260205260405f2090612107614145565b5081548110156114a2576060915f5260205f209060011b016120826040519161212f8361371a565b61215260016fffffffffffffffffffffffffffffffff9283815416865201613e00565b90602084019182526040519351168352516020830190602090816fffffffffffffffffffffffffffffffff91828151168552015116910152565b3461025a5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a577ffe870af61f024df0d7f960ad100676f3ffaa7ea6a44bc6c7adf2756cb8cf4b3860206121e661383e565b61220873ffffffffffffffffffffffffffffffffffffffff5f541633146139e3565b6fffffffffffffffffffffffffffffffff609a54817fffffffffffffffffffffffffffffffff000000000000000000000000000000008460801b16911617609a5560405191168152a1005b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a5773ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000ca10fb0f2ce19cde44b42df2f42607977dfa45491630036122e85760206040517f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8152f35b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c00000000000000006064820152fd5b60407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a5761239e613682565b6024359067ffffffffffffffff821161025a573660238301121561025a5781600401356123ca81613944565b926123d86040519485613766565b81845260209182850191366024838301011161025a57815f92602486930185378601015273ffffffffffffffffffffffffffffffffffffffff807f000000000000000000000000ca10fb0f2ce19cde44b42df2f42607977dfa4549169061244182301415613cea565b6124707f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc928284541614613d75565b61247e815f541633146139e3565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff16156124b65750505050610b899150614974565b84939416906040517f52d1902d0000000000000000000000000000000000000000000000000000000081528581600481865afa5f91816126be575b5061257a57608486604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201527f6f6e206973206e6f7420555550530000000000000000000000000000000000006064820152fd5b0361263a5761258883614974565b7fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b5f80a2835115801590612632575b6125bd57005b5f8091610b89957f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c604051966125f28861374a565b602788528701527f206661696c65640000000000000000000000000000000000000000000000000060408701525190845af461262c6141af565b91614f63565b5060016125b7565b608484604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f7860448201527f6961626c655555494400000000000000000000000000000000000000000000006064820152fd5b9091508681813d83116126e6575b6126d68183613766565b8101031261025a575190886124f1565b503d6126cc565b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a5760015473ffffffffffffffffffffffffffffffffffffffff9081811680330361279557805f549384167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a37fffffffffffffffffffffffff0000000000000000000000000000000000000000928316175f5516600155005b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602060248201527f4f776e61626c653a2063616c6c657220213d2070656e64696e67206f776e65726044820152fd5b3461025a5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a5761282a613682565b73ffffffffffffffffffffffffffffffffffffffff9061284e825f541633146139e3565b167fffffffffffffffffffffffff000000000000000000000000000000000000000060a554161760a5555f80f35b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a576033546128b681613af2565b906128c081613af2565b905f5b8181106128f4576128e6846105c185604051938493604085526040850190613911565b9083820360208501526137d6565b806001917f82a75bdeeae8604d839476ae9efd8b0e15aa447e21bfd7f41283bb54e22c9a820154805f52603560205273ffffffffffffffffffffffffffffffffffffffff60405f2054166129488387613ade565b526129538287613ade565b52016128c3565b3461025a5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57610b89611d9a613682565b3461025a576129a23661385d565b604051919273ffffffffffffffffffffffffffffffffffffffff906129c68461371a565b5f84525f602080950152165f5260a060205260405f20918254926fffffffffffffffffffffffffffffffff94600191612a0160018201613e00565b93612a0b86613af2565b9560025f9301925b818110612a7a5789896105c18a612a698b604051958567ffffffffffffffff889716875260401c1660208601526040850190602090816fffffffffffffffffffffffffffffffff91828151168552015116910152565b60a0608084015260a08301906138cc565b62093a808a612a92612a8d84868a613a48565b613e2e565b1606612ac757808a612aa9612a8d8994868a613a48565b165f528484528a60405f205416612ac0828b613ade565b5201612a13565b612ad8612a8d8b9260249488613a48565b6040517ff7e2d9d200000000000000000000000000000000000000000000000000000000815291166004820152fd5b3461025a576020807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57612b3f613682565b73ffffffffffffffffffffffffffffffffffffffff91827f000000000000000000000000ca10fb0f2ce19cde44b42df2f42607977dfa45491692612b8584301415613cea565b612bb47f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc948286541614613d75565b612bc2815f541633146139e3565b604051938285019185831067ffffffffffffffff841117612d5957826040525f865260ff7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd914354165f14612c1d5750505050610b899150614974565b84939416906040517f52d1902d0000000000000000000000000000000000000000000000000000000081528581600481865afa5f9181612d2a575b50612ce157608486604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201527f6f6e206973206e6f7420555550530000000000000000000000000000000000006064820152fd5b0361263a57612cef83614974565b7fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b5f80a2835115801590612d23576125bd57005b505f6125b7565b9091508681813d8311612d52575b612d428183613766565b8101031261025a57519088612c58565b503d612d38565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b3461025a575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57602073ffffffffffffffffffffffffffffffffffffffff60a45416604051908152f35b3461025a5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a576020610e8e612e136137bf565b613b81565b60407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57610b89612e4d613682565b6024359073ffffffffffffffffffffffffffffffffffffffff90612e75825f541633146139e3565b825f5260356020521660405f2055614e12565b60607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57612eba6137bf565b612ec261381f565b906044356fffffffffffffffffffffffffffffffff8116810361025a57610b7892612f0573ffffffffffffffffffffffffffffffffffffffff5f541633146139e3565b60a75492614308565b3461025a576020807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a5767ffffffffffffffff612f4f6137bf565b165f52609f815260405f20906040518083838295549384815201905f52835f20925f5b85828210612f9d57505050612f8992500383613766565b6105c16040519282849384528301906137d6565b8554845260019586019588955093019201612f72565b3461025a5760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a5760043567ffffffffffffffff80821161025a573660238301121561025a57816004013591602490613012846137a7565b906130206040519283613766565b848252602094838684019160051b8301019136831161025a578401905b8282106132d75750505081359083821161025a573660238301121561025a57816004013561306a816137a7565b926130786040519485613766565b818452848785019260051b8201019136831161025a5785889201905b8382106132c0575050505073ffffffffffffffffffffffffffffffffffffffff8060a45416331480156132b4575b6130cb90613a79565b81518351036104a757909362093a80426fffffffffffffffffffffffffffffffff160491905f5b8651811015610b8957816131068289613ade565b5116836131138388613ade565b51169061312b825f52609c60205260405f2054151590565b61328457815f52609e8a5260405f205461325457805f52609f8a526131538260405f20614e83565b156132285761316182614dbf565b15613228579060019291815f526131fe60a0808d5260405f20837fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000008254161790556131ab896148d8565b90845f528d5260405f20907fffffffffffffffff00000000000000000000000000000000ffffffffffffffff77ffffffffffffffffffffffffffffffff000000000000000083549260401b169116179055565b7f336f0b3cc523e98d21e261389542b62abaffc094a21a82f1eec2779d7c8323cb5f80a3016130f2565b877f4e487b71000000000000000000000000000000000000000000000000000000005f5260016004525ffd5b8782604051907f4753d2830000000000000000000000000000000000000000000000000000000082526004820152fd5b8782604051907f9e7f1f410000000000000000000000000000000000000000000000000000000082526004820152fd5b505f54811633146130c2565b8280916132cc846136c8565b815201910190613094565b8135868116810361025a57815290860190860161303d565b3461025a576020807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a5767ffffffffffffffff60043581811161025a576133409036906004016136e9565b919073ffffffffffffffffffffffffffffffffffffffff908160a55416331480156134f5575b15613497575f5b84811061337657005b613384610475828785613a48565b9083821661339d815f52609c60205260405f2054151590565b1561346657805f5260a0928389526133bb8760405f20541691613e6f565b815f528389528660405f2054165f52609f89526133db8260405f20614c86565b15613439576133e982614b5a565b15613439576133f782614d4e565b1561343957600193825f5289525f846040822082815501557ff2e3b584c4d1ed5ead9a4b7de2a8225fd42d13f09e417cd294d03f1dd07fc9145f80a30161336d565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52600160045260245ffd5b602490604051907f913accad0000000000000000000000000000000000000000000000000000000082526004820152fd5b606485604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152601760248201527f72656d6f766520706f6f6c206e6f7420616c6c6f7765640000000000000000006044820152fd5b50815f54163314613366565b3461025a5760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a57613538613682565b602435801515810361025a5760443590811515820361025a5773ffffffffffffffffffffffffffffffffffffffff928391613577835f541633146139e3565b15613651571690811590811591613649575b50156135eb57805f549283167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a37fffffffffffffffffffffffff0000000000000000000000000000000000000000809216175f55600154166001555f80f35b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f4f776e61626c653a207a65726f206164647265737300000000000000000000006044820152fd5b905083613589565b915050167fffffffffffffffffffffffff000000000000000000000000000000000000000060015416176001555f80f35b6004359073ffffffffffffffffffffffffffffffffffffffff8216820361025a57565b6024359073ffffffffffffffffffffffffffffffffffffffff8216820361025a57565b359073ffffffffffffffffffffffffffffffffffffffff8216820361025a57565b9181601f8401121561025a5782359167ffffffffffffffff831161025a576020808501948460051b01011161025a57565b6040810190811067ffffffffffffffff821117612d5957604052565b67ffffffffffffffff8111612d5957604052565b6060810190811067ffffffffffffffff821117612d5957604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff821117612d5957604052565b67ffffffffffffffff8111612d595760051b60200190565b6004359067ffffffffffffffff8216820361025a57565b9081518082526020808093019301915f5b8281106137f5575050505090565b835173ffffffffffffffffffffffffffffffffffffffff16855293810193928101926001016137e7565b602435906fffffffffffffffffffffffffffffffff8216820361025a57565b600435906fffffffffffffffffffffffffffffffff8216820361025a57565b9060407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc83011261025a5760043573ffffffffffffffffffffffffffffffffffffffff8116810361025a57916024359067ffffffffffffffff821161025a576138c8916004016136e9565b9091565b9081518082526020808093019301915f5b8281106138eb575050505090565b83516fffffffffffffffffffffffffffffffff16855293810193928101926001016138dd565b9081518082526020808093019301915f5b828110613930575050505090565b835185529381019392810192600101613922565b67ffffffffffffffff8111612d5957601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b60407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc82011261025a5767ffffffffffffffff9160043583811161025a57826139c9916004016136e9565b9390939260243591821161025a576138c8916004016136e9565b156139ea57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b91908110156114a25760051b0190565b3573ffffffffffffffffffffffffffffffffffffffff8116810361025a5790565b15613a8057565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f61646420706f6f6c206e6f7420616c6c6f7765640000000000000000000000006044820152fd5b80518210156114a25760209160051b010190565b90613afc826137a7565b613b096040519182613766565b8281527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0613b3782946137a7565b0190602036910137565b91613b70906fffffffffffffffffffffffffffffffff613b7e95931684526060602085015260608401906137d6565b916040818403910152613911565b90565b67ffffffffffffffff16468114613ce557805f52602090609f825260405f20548015613cde57613be1613c1e82613bc1613bbb8795613af2565b91613af2565b90613c126040519485925f888501526060604085015260808401906137d6565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09384848303016060850152613911565b03908101835282613766565b73ffffffffffffffffffffffffffffffffffffffff80613c3d85614ed5565b169360325494613c7c604051968795869485947f84fe172100000000000000000000000000000000000000000000000000000000865260048601614879565b03917f00000000000000000000000007b1014c88f14c9e910092526db57a20052e989f165afa918215611e89575f92613cb457505090565b90809250813d8311613cd7575b613ccb8183613766565b8101031261025a575190565b503d613cc1565b5050505f90565b505f90565b15613cf157565b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201527f64656c656761746563616c6c00000000000000000000000000000000000000006064820152fd5b15613d7c57565b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201527f6163746976652070726f787900000000000000000000000000000000000000006064820152fd5b90604051613e0d8161371a565b91546fffffffffffffffffffffffffffffffff8116835260801c6020830152565b356fffffffffffffffffffffffffffffffff8116810361025a5790565b9190916fffffffffffffffffffffffffffffffff808094169116019182116107a257565b73ffffffffffffffffffffffffffffffffffffffff16613e9a815f52609c60205260405f2054151590565b1561346657805f5260a060209060a082526fffffffffffffffffffffffffffffffff9160409280845f2054851c169162093a809382613edc86824216046148d8565b16908185101561413b57939594875f5260a083526001948591613f036001895f2001613e00565b965b614002575b5050505f87815260a083528590208451928501517fffffffffffffffffffffffffffffffff0000000000000000000000000000000090851660801b16939092166fffffffffffffffffffffffffffffffff169290921760018201557fa512c82e73ec974de3c794a3ea6bbdfbad18531c1394ace9972f3f0166b6786394613fd492507fffffffffffffffff00000000000000000000000000000000ffffffffffffffff77ffffffffffffffffffffffffffffffff000000000000000083549260401b169116179055565b613fff82518092602090816fffffffffffffffffffffffffffffffff91828151168552015116910152565ba2565b9091929697858116908882101561413357508101968588116107a2578388978b5f528487528a5f2060020190888b1691825f528852888b8d8280825f20541691519461404d8661371a565b5f86528c828481838a01935f85528501511690614069916148b6565b169052511691614078916148fe565b614081916148b6565b168152809a61408f91614925565b90805f5260a1908189528c5f2080546008858d83831c16906140b091613e4b565b901b70ffffffffffffffffffffffffffffffff0016907fffffffffffffffffffffffffffffff00000000000000000000000000000000ff161790555f528752818b5f20018c5f528752878b5f20911681547fffffffffffffffffffffffffffffffff00000000000000000000000000000000161790559291909398979698613f05565b989750613f0a565b5050505050505050565b604051906141528261371a565b5f82526040516020836141648361371a565b5f83525f828401520152565b51906fffffffffffffffffffffffffffffffff8216820361025a57565b3567ffffffffffffffff8116810361025a5790565b919082039182116107a257565b3d156141d9573d906141c082613944565b916141ce6040519384613766565b82523d5f602084013e565b606090565b814710614297575f80809373ffffffffffffffffffffffffffffffffffffffff8294165af161420b6141af565b501561421357565b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d617920686176652072657665727465640000000000006064820152fd5b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e63650000006044820152fd5b818102929181159184041417156107a257565b92906fffffffffffffffffffffffffffffffff81165f5260a16020526fffffffffffffffffffffffffffffffff60405f205460081c168015806148155767ffffffffffffffff86165f52609f60205260405f2091825490811561413b576040519360208584815201905f528460205f20915f5b8581106147fb575061438f92500385613766565b61439882613af2565b955f5b8381106146c957505050505067ffffffffffffffff851646036144965773ffffffffffffffffffffffffffffffffffffffff6143e067ffffffffffffffff8716614ed5565b1692833b1561025a57614426935f92836040518097819582947f72cbf8700000000000000000000000000000000000000000000000000000000084528960048501613b41565b03925af1918215611e89576fffffffffffffffffffffffffffffffff60209267ffffffffffffffff927fc78a580f215ba474e75ecbd7636c375e8d2cd25edb0f2467f99b2d0752e104ba95614487575b505b816040519616865216941692a3565b61449090613736565b5f614476565b6144d9906144ad6040519485928560208501613b41565b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101845283613766565b67ffffffffffffffff84165f52603460205260405f205415613439578173ffffffffffffffffffffffffffffffffffffffff8061451f67ffffffffffffffff8816614ed5565b1690603254907f00000000000000000000000007b1014c88f14c9e910092526db57a20052e989f1690602067ffffffffffffffff8961458e8460405198899485947f84fe1721000000000000000000000000000000000000000000000000000000008652168960048601614879565b0381855afa938415611e89575f94614695575b5083471061465d57813b1561025a575f93886145f867ffffffffffffffff93604051998a97889687957fb2267a7b000000000000000000000000000000000000000000000000000000008752169060048601614879565b03925af1918215611e89576fffffffffffffffffffffffffffffffff60209267ffffffffffffffff927fc78a580f215ba474e75ecbd7636c375e8d2cd25edb0f2467f99b2d0752e104ba9561464e575b50614478565b61465790613736565b5f614648565b6044844790604051917fe098b7ca00000000000000000000000000000000000000000000000000000000835260048301526024820152fd5b9093506020813d6020116146c1575b816146b160209383613766565b8101031261025a5751925f6145a1565b3d91506146a4565b6fffffffffffffffffffffffffffffffff87165f5260a1602052600160405f20019073ffffffffffffffffffffffffffffffffffffffff918261470c838a613ade565b51165f526020526fffffffffffffffffffffffffffffffff60405f205416916147358289613ade565b51165f90815260a6602052604090205480156147f4575b670de0b6b3a764000092838102908082048514901517156107a257876147c757859004808210156147bf5750915b62093a806fffffffffffffffffffffffffffffffff8c168181029181159183041417156107a2576001936147ad916142f5565b046147b8828b613ade565b520161439b565b90509161477a565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b508261474c565b91506001602081928554815201930191019186919261437b565b505050505050565b91908251928382525f5b8481106148655750507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f845f6020809697860101520116010190565b602081830181015184830182015201614827565b94939260609273ffffffffffffffffffffffffffffffffffffffff6148b193168752602087015260806040870152608086019061481d565b930152565b6fffffffffffffffffffffffffffffffff91821690821603919082116107a257565b9062093a806fffffffffffffffffffffffffffffffff809316029182169182036107a257565b9190916fffffffffffffffffffffffffffffffff808094169116029182169182036107a257565b602081016fffffffffffffffffffffffffffffffff9283928361494b83828651166148fe565b915116938491161161496c57613b7e936149669251166148fe565b906148b6565b505050505f90565b803b156149dc5773ffffffffffffffffffffffffffffffffffffffff7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc91167fffffffffffffffffffffffff0000000000000000000000000000000000000000825416179055565b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201527f6f74206120636f6e7472616374000000000000000000000000000000000000006064820152fd5b60208101906fffffffffffffffffffffffffffffffff90818351168015614a9357505191518116911681156147c7570490565b82604492511690604051917ffbd384a500000000000000000000000000000000000000000000000000000000835260048301526024820152fd5b609b548110156114a257609b5f527fbba9db4cdbea0a37c207bbb83e20f828cd4441c49891101dc94fd20dc8efc34901905f90565b80548210156114a2575f5260205f2001905f90565b670de0b6b3a76400008111614b295750565b602490604051907f701170a20000000000000000000000000000000000000000000000000000000082526004820152fd5b5f818152609c60205260409020548015614c80577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff908181018181116107a257609b54908382019182116107a257808203614c17575b505050609b548015614bea57810190614bc882614acd565b909182549160031b1b19169055609b555f52609c6020525f6040812055600190565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603160045260245ffd5b614c6a614c26614c3593614acd565b90549060031b1c928392614acd565b81939154907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9060031b92831b921b19161790565b90555f52609c60205260405f20555f8080614bb0565b50505f90565b906001820191815f528260205260405f2054908115155f1461496c577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff918281018181116107a2578254908482019182116107a257808203614d19575b50505080548015614bea57820191614cfb8383614b02565b909182549160031b1b19169055555f526020525f6040812055600190565b614d39614d29614c359386614b02565b90549060031b1c92839286614b02565b90555f528460205260405f20555f8080614ce3565b805f52609e60205260405f2054155f14613ce557609d5468010000000000000000811015612d59576001810180609d558110156114a25781907fd26e832454299e9fabb89e0e5fffdc046d4e14431bc1bf607ffb2e8a1ddecf7b0155609d54905f52609e60205260405f2055600190565b805f52609c60205260405f2054155f14613ce557609b5468010000000000000000811015612d5957614dfb614c35826001859401609b55614acd565b9055609b54905f52609c60205260405f2055600190565b805f52603460205260405f2054155f14613ce55760335468010000000000000000811015612d595760018101806033558110156114a25781907f82a75bdeeae8604d839476ae9efd8b0e15aa447e21bfd7f41283bb54e22c9a820155603354905f52603460205260405f2055600190565b6001810190825f528160205260405f2054155f14613cde57805468010000000000000000811015612d5957614ec2614c35826001879401855584614b02565b905554915f5260205260405f2055600190565b5f52603560205260405f20548015801590614f51575b15614ef35790565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f456e756d657261626c654d61703a206e6f6e6578697374656e74206b657900006044820152fd5b50603460205260405f20541515614eeb565b91929015614fde5750815115614f77575090565b3b15614f805790565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152fd5b825190915015614ff15750805190602001fd5b61502f906040519182917f08c379a000000000000000000000000000000000000000000000000000000000835260206004840152602483019061481d565b0390fdfea264697066735822122054b19d5851c85bfad0729d6bb1b10572a5596ff1845c5df90930c165e7a645f364736f6c63430008180033
Verified Source Code Full Match
Compiler: v0.8.24+commit.e11b9ed9
EVM: shanghai
Optimization: Yes (1000000 runs)
Initializable.sol 166 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}
AddressUpgradeable.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
draft-IERC1822.sol 20 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface 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);
}
IERC1967.sol 26 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC1967.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
*
* _Available since v4.8.3._
*/
interface 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);
}
IBeacon.sol 16 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.0;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {BeaconProxy} will check that this address is a contract.
*/
function implementation() external view returns (address);
}
ERC1967Upgrade.sol 157 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/ERC1967/ERC1967Upgrade.sol)
pragma solidity ^0.8.2;
import "../beacon/IBeacon.sol";
import "../../interfaces/IERC1967.sol";
import "../../interfaces/draft-IERC1822.sol";
import "../../utils/Address.sol";
import "../../utils/StorageSlot.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*
* _Available since v4.1._
*/
abstract contract ERC1967Upgrade is IERC1967 {
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @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 EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Perform implementation upgrade
*
* Emits an {Upgraded} event.
*/
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
/**
* @dev Perform implementation upgrade with additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {
_upgradeTo(newImplementation);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(newImplementation, data);
}
}
/**
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal {
// Upgrades from old implementations will perform a rollback test. This test requires the new
// implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
// this special case will break upgrade paths from old UUPS implementation to new ones.
if (StorageSlot.getBooleanSlot(_ROLLBACK_SLOT).value) {
_setImplementation(newImplementation);
} else {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
} catch {
revert("ERC1967Upgrade: new implementation is not UUPS");
}
_upgradeToAndCall(newImplementation, data, forceCall);
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*/
function _getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
require(newAdmin != address(0), "ERC1967: new admin is the zero address");
StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {AdminChanged} event.
*/
function _changeAdmin(address newAdmin) internal {
emit AdminChanged(_getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
*/
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function _getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(_BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract");
require(
Address.isContract(IBeacon(newBeacon).implementation()),
"ERC1967: beacon implementation is not a contract"
);
StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon;
}
/**
* @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
* not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
*
* Emits a {BeaconUpgraded} event.
*/
function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
}
}
}
UUPSUpgradeable.sol 99 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.0;
import "../../interfaces/draft-IERC1822.sol";
import "../ERC1967/ERC1967Upgrade.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*
* _Available since v4.1._
*/
abstract contract UUPSUpgradeable is IERC1822Proxiable, ERC1967Upgrade {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
address private immutable __self = address(this);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
require(address(this) != __self, "Function must be called through delegatecall");
require(_getImplementation() == __self, "Function must be called through active proxy");
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");
_;
}
/**
* @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate the implementation's compatibility when performing an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual override notDelegated returns (bytes32) {
return _IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeTo(address newImplementation) public virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data, true);
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeTo} and {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal override onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
StorageSlot.sol 138 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._
* _Available since v4.9 for `string`, `bytes`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}
EnumerableMap.sol 598 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableMap.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableMap.js.
pragma solidity ^0.8.0;
import "./EnumerableSet.sol";
/**
* @dev Library for managing an enumerable variant of Solidity's
* https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]
* type.
*
* Maps have the following properties:
*
* - Entries are added, removed, and checked for existence in constant time
* (O(1)).
* - Entries are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableMap for EnumerableMap.UintToAddressMap;
*
* // Declare a set state variable
* EnumerableMap.UintToAddressMap private myMap;
* }
* ```
*
* The following map types are supported:
*
* - `uint256 -> address` (`UintToAddressMap`) since v3.0.0
* - `address -> uint256` (`AddressToUintMap`) since v4.6.0
* - `bytes32 -> bytes32` (`Bytes32ToBytes32Map`) since v4.6.0
* - `uint256 -> uint256` (`UintToUintMap`) since v4.7.0
* - `bytes32 -> uint256` (`Bytes32ToUintMap`) since v4.7.0
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableMap, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableMap.
* ====
*/
library EnumerableMap {
using EnumerableSet for EnumerableSet.Bytes32Set;
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Map type with
// bytes32 keys and values.
// The Map implementation uses private functions, and user-facing
// implementations (such as Uint256ToAddressMap) are just wrappers around
// the underlying Map.
// This means that we can only create new EnumerableMaps for types that fit
// in bytes32.
struct Bytes32ToBytes32Map {
// Storage of keys
EnumerableSet.Bytes32Set _keys;
mapping(bytes32 => bytes32) _values;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(Bytes32ToBytes32Map storage map, bytes32 key, bytes32 value) internal returns (bool) {
map._values[key] = value;
return map._keys.add(key);
}
/**
* @dev Removes a key-value pair from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(Bytes32ToBytes32Map storage map, bytes32 key) internal returns (bool) {
delete map._values[key];
return map._keys.remove(key);
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool) {
return map._keys.contains(key);
}
/**
* @dev Returns the number of key-value pairs in the map. O(1).
*/
function length(Bytes32ToBytes32Map storage map) internal view returns (uint256) {
return map._keys.length();
}
/**
* @dev Returns the key-value pair stored at position `index` in the map. O(1).
*
* Note that there are no guarantees on the ordering of entries inside the
* array, and it may change when more entries are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32ToBytes32Map storage map, uint256 index) internal view returns (bytes32, bytes32) {
bytes32 key = map._keys.at(index);
return (key, map._values[key]);
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool, bytes32) {
bytes32 value = map._values[key];
if (value == bytes32(0)) {
return (contains(map, key), bytes32(0));
} else {
return (true, value);
}
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bytes32) {
bytes32 value = map._values[key];
require(value != 0 || contains(map, key), "EnumerableMap: nonexistent key");
return value;
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(
Bytes32ToBytes32Map storage map,
bytes32 key,
string memory errorMessage
) internal view returns (bytes32) {
bytes32 value = map._values[key];
require(value != 0 || contains(map, key), errorMessage);
return value;
}
/**
* @dev Return the an array containing all the keys
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function keys(Bytes32ToBytes32Map storage map) internal view returns (bytes32[] memory) {
return map._keys.values();
}
// UintToUintMap
struct UintToUintMap {
Bytes32ToBytes32Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(UintToUintMap storage map, uint256 key, uint256 value) internal returns (bool) {
return set(map._inner, bytes32(key), bytes32(value));
}
/**
* @dev Removes a value from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(UintToUintMap storage map, uint256 key) internal returns (bool) {
return remove(map._inner, bytes32(key));
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(UintToUintMap storage map, uint256 key) internal view returns (bool) {
return contains(map._inner, bytes32(key));
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(UintToUintMap storage map) internal view returns (uint256) {
return length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the map. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintToUintMap storage map, uint256 index) internal view returns (uint256, uint256) {
(bytes32 key, bytes32 value) = at(map._inner, index);
return (uint256(key), uint256(value));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(UintToUintMap storage map, uint256 key) internal view returns (bool, uint256) {
(bool success, bytes32 value) = tryGet(map._inner, bytes32(key));
return (success, uint256(value));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(UintToUintMap storage map, uint256 key) internal view returns (uint256) {
return uint256(get(map._inner, bytes32(key)));
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(UintToUintMap storage map, uint256 key, string memory errorMessage) internal view returns (uint256) {
return uint256(get(map._inner, bytes32(key), errorMessage));
}
/**
* @dev Return the an array containing all the keys
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function keys(UintToUintMap storage map) internal view returns (uint256[] memory) {
bytes32[] memory store = keys(map._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintToAddressMap
struct UintToAddressMap {
Bytes32ToBytes32Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) {
return set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) {
return remove(map._inner, bytes32(key));
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) {
return contains(map._inner, bytes32(key));
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(UintToAddressMap storage map) internal view returns (uint256) {
return length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the map. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) {
(bytes32 key, bytes32 value) = at(map._inner, index);
return (uint256(key), address(uint160(uint256(value))));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {
(bool success, bytes32 value) = tryGet(map._inner, bytes32(key));
return (success, address(uint160(uint256(value))));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {
return address(uint160(uint256(get(map._inner, bytes32(key)))));
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(
UintToAddressMap storage map,
uint256 key,
string memory errorMessage
) internal view returns (address) {
return address(uint160(uint256(get(map._inner, bytes32(key), errorMessage))));
}
/**
* @dev Return the an array containing all the keys
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function keys(UintToAddressMap storage map) internal view returns (uint256[] memory) {
bytes32[] memory store = keys(map._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressToUintMap
struct AddressToUintMap {
Bytes32ToBytes32Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(AddressToUintMap storage map, address key, uint256 value) internal returns (bool) {
return set(map._inner, bytes32(uint256(uint160(key))), bytes32(value));
}
/**
* @dev Removes a value from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(AddressToUintMap storage map, address key) internal returns (bool) {
return remove(map._inner, bytes32(uint256(uint160(key))));
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(AddressToUintMap storage map, address key) internal view returns (bool) {
return contains(map._inner, bytes32(uint256(uint160(key))));
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(AddressToUintMap storage map) internal view returns (uint256) {
return length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the map. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressToUintMap storage map, uint256 index) internal view returns (address, uint256) {
(bytes32 key, bytes32 value) = at(map._inner, index);
return (address(uint160(uint256(key))), uint256(value));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(AddressToUintMap storage map, address key) internal view returns (bool, uint256) {
(bool success, bytes32 value) = tryGet(map._inner, bytes32(uint256(uint160(key))));
return (success, uint256(value));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(AddressToUintMap storage map, address key) internal view returns (uint256) {
return uint256(get(map._inner, bytes32(uint256(uint160(key)))));
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(
AddressToUintMap storage map,
address key,
string memory errorMessage
) internal view returns (uint256) {
return uint256(get(map._inner, bytes32(uint256(uint160(key))), errorMessage));
}
/**
* @dev Return the an array containing all the keys
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function keys(AddressToUintMap storage map) internal view returns (address[] memory) {
bytes32[] memory store = keys(map._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// Bytes32ToUintMap
struct Bytes32ToUintMap {
Bytes32ToBytes32Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(Bytes32ToUintMap storage map, bytes32 key, uint256 value) internal returns (bool) {
return set(map._inner, key, bytes32(value));
}
/**
* @dev Removes a value from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(Bytes32ToUintMap storage map, bytes32 key) internal returns (bool) {
return remove(map._inner, key);
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(Bytes32ToUintMap storage map, bytes32 key) internal view returns (bool) {
return contains(map._inner, key);
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(Bytes32ToUintMap storage map) internal view returns (uint256) {
return length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the map. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32ToUintMap storage map, uint256 index) internal view returns (bytes32, uint256) {
(bytes32 key, bytes32 value) = at(map._inner, index);
return (key, uint256(value));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(Bytes32ToUintMap storage map, bytes32 key) internal view returns (bool, uint256) {
(bool success, bytes32 value) = tryGet(map._inner, key);
return (success, uint256(value));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(Bytes32ToUintMap storage map, bytes32 key) internal view returns (uint256) {
return uint256(get(map._inner, key));
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(
Bytes32ToUintMap storage map,
bytes32 key,
string memory errorMessage
) internal view returns (uint256) {
return uint256(get(map._inner, key, errorMessage));
}
/**
* @dev Return the an array containing all the keys
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function keys(Bytes32ToUintMap storage map) internal view returns (bytes32[] memory) {
bytes32[] memory store = keys(map._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}
EnumerableSet.sol 378 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastValue;
// Update the index for the moved value
set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}
BoringOwnableUpgradeableV2.sol 58 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
contract BoringOwnableUpgradeableData {
address public owner;
address public pendingOwner;
}
abstract contract BoringOwnableUpgradeableV2 is BoringOwnableUpgradeableData, Initializable {
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
function __BoringOwnableV2_init(address _owner) internal onlyInitializing {
owner = _owner;
}
/// @notice Transfers ownership to `newOwner`. Either directly or claimable by the new pending owner.
/// Can only be invoked by the current `owner`.
/// @param newOwner Address of the new owner.
/// @param direct True if `newOwner` should be set immediately. False if `newOwner` needs to use `claimOwnership`.
/// @param renounce Allows the `newOwner` to be `address(0)` if `direct` and `renounce` is True. Has no effect otherwise.
function transferOwnership(address newOwner, bool direct, bool renounce) public onlyOwner {
if (direct) {
// Checks
require(newOwner != address(0) || renounce, "Ownable: zero address");
// Effects
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
pendingOwner = address(0);
} else {
// Effects
pendingOwner = newOwner;
}
}
/// @notice Needs to be called by `pendingOwner` to claim ownership.
function claimOwnership() public {
address _pendingOwner = pendingOwner;
// Checks
require(msg.sender == _pendingOwner, "Ownable: caller != pending owner");
// Effects
emit OwnershipTransferred(owner, _pendingOwner);
owner = _pendingOwner;
pendingOwner = address(0);
}
/// @notice Only allows the `owner` to execute the function.
modifier onlyOwner() {
require(msg.sender == owner, "Ownable: caller is not the owner");
_;
}
uint256[48] private __gap;
}
Errors.sol 183 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
library Errors {
// BulkSeller
error BulkInsufficientSyForTrade(uint256 currentAmount, uint256 requiredAmount);
error BulkInsufficientTokenForTrade(uint256 currentAmount, uint256 requiredAmount);
error BulkInSufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);
error BulkInSufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);
error BulkInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);
error BulkNotMaintainer();
error BulkNotAdmin();
error BulkSellerAlreadyExisted(address token, address SY, address bulk);
error BulkSellerInvalidToken(address token, address SY);
error BulkBadRateTokenToSy(uint256 actualRate, uint256 currentRate, uint256 eps);
error BulkBadRateSyToToken(uint256 actualRate, uint256 currentRate, uint256 eps);
// APPROX
error ApproxFail();
error ApproxParamsInvalid(uint256 guessMin, uint256 guessMax, uint256 eps);
error ApproxBinarySearchInputInvalid(
uint256 approxGuessMin,
uint256 approxGuessMax,
uint256 minGuessMin,
uint256 maxGuessMax
);
// MARKET + MARKET MATH CORE
error MarketExpired();
error MarketZeroAmountsInput();
error MarketZeroAmountsOutput();
error MarketZeroLnImpliedRate();
error MarketInsufficientPtForTrade(int256 currentAmount, int256 requiredAmount);
error MarketInsufficientPtReceived(uint256 actualBalance, uint256 requiredBalance);
error MarketInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);
error MarketZeroTotalPtOrTotalAsset(int256 totalPt, int256 totalAsset);
error MarketExchangeRateBelowOne(int256 exchangeRate);
error MarketProportionMustNotEqualOne();
error MarketRateScalarBelowZero(int256 rateScalar);
error MarketScalarRootBelowZero(int256 scalarRoot);
error MarketProportionTooHigh(int256 proportion, int256 maxProportion);
error OracleUninitialized();
error OracleTargetTooOld(uint32 target, uint32 oldest);
error OracleZeroCardinality();
error MarketFactoryExpiredPt();
error MarketFactoryInvalidPt();
error MarketFactoryMarketExists();
error MarketFactoryLnFeeRateRootTooHigh(uint80 lnFeeRateRoot, uint256 maxLnFeeRateRoot);
error MarketFactoryOverriddenFeeTooHigh(uint80 overriddenFee, uint256 marketLnFeeRateRoot);
error MarketFactoryReserveFeePercentTooHigh(uint8 reserveFeePercent, uint8 maxReserveFeePercent);
error MarketFactoryZeroTreasury();
error MarketFactoryInitialAnchorTooLow(int256 initialAnchor, int256 minInitialAnchor);
error MFNotPendleMarket(address addr);
// ROUTER
error RouterInsufficientLpOut(uint256 actualLpOut, uint256 requiredLpOut);
error RouterInsufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);
error RouterInsufficientPtOut(uint256 actualPtOut, uint256 requiredPtOut);
error RouterInsufficientYtOut(uint256 actualYtOut, uint256 requiredYtOut);
error RouterInsufficientPYOut(uint256 actualPYOut, uint256 requiredPYOut);
error RouterInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);
error RouterInsufficientSyRepay(uint256 actualSyRepay, uint256 requiredSyRepay);
error RouterInsufficientPtRepay(uint256 actualPtRepay, uint256 requiredPtRepay);
error RouterNotAllSyUsed(uint256 netSyDesired, uint256 netSyUsed);
error RouterTimeRangeZero();
error RouterCallbackNotPendleMarket(address caller);
error RouterInvalidAction(bytes4 selector);
error RouterInvalidFacet(address facet);
error RouterKyberSwapDataZero();
error SimulationResults(bool success, bytes res);
// YIELD CONTRACT
error YCExpired();
error YCNotExpired();
error YieldContractInsufficientSy(uint256 actualSy, uint256 requiredSy);
error YCNothingToRedeem();
error YCPostExpiryDataNotSet();
error YCNoFloatingSy();
// YieldFactory
error YCFactoryInvalidExpiry();
error YCFactoryYieldContractExisted();
error YCFactoryZeroExpiryDivisor();
error YCFactoryZeroTreasury();
error YCFactoryInterestFeeRateTooHigh(uint256 interestFeeRate, uint256 maxInterestFeeRate);
error YCFactoryRewardFeeRateTooHigh(uint256 newRewardFeeRate, uint256 maxRewardFeeRate);
// SY
error SYInvalidTokenIn(address token);
error SYInvalidTokenOut(address token);
error SYZeroDeposit();
error SYZeroRedeem();
error SYInsufficientSharesOut(uint256 actualSharesOut, uint256 requiredSharesOut);
error SYInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);
// SY-specific
error SYQiTokenMintFailed(uint256 errCode);
error SYQiTokenRedeemFailed(uint256 errCode);
error SYQiTokenRedeemRewardsFailed(uint256 rewardAccruedType0, uint256 rewardAccruedType1);
error SYQiTokenBorrowRateTooHigh(uint256 borrowRate, uint256 borrowRateMax);
error SYCurveInvalidPid();
error SYCurve3crvPoolNotFound();
error SYApeDepositAmountTooSmall(uint256 amountDeposited);
error SYBalancerInvalidPid();
error SYInvalidRewardToken(address token);
error SYStargateRedeemCapExceeded(uint256 amountLpDesired, uint256 amountLpRedeemable);
error SYBalancerReentrancy();
error NotFromTrustedRemote(uint16 srcChainId, bytes path);
error ApxETHNotEnoughBuffer();
// Liquidity Mining
error VCInvalidCap(uint256 cap);
error VCInactivePool(address pool);
error VCPoolAlreadyActive(address pool);
error VCZeroVePendle(address user);
error VCExceededMaxWeight(uint256 totalWeight, uint256 maxWeight);
error VCEpochNotFinalized(uint256 wTime);
error VCPoolAlreadyAddAndRemoved(address pool);
error VEInvalidNewExpiry(uint256 newExpiry);
error VEExceededMaxLockTime();
error VEInsufficientLockTime();
error VENotAllowedReduceExpiry();
error VEZeroAmountLocked();
error VEPositionNotExpired();
error VEZeroPosition();
error VEZeroSlope(uint128 bias, uint128 slope);
error VEReceiveOldSupply(uint256 msgTime);
error GCNotPendleMarket(address caller);
error GCNotVotingController(address caller);
error InvalidWTime(uint256 wTime);
error ExpiryInThePast(uint256 expiry);
error ChainNotSupported(uint256 chainId);
error FDTotalAmountFundedNotMatch(uint256 actualTotalAmount, uint256 expectedTotalAmount);
error FDEpochLengthMismatch();
error FDInvalidPool(address pool);
error FDPoolAlreadyExists(address pool);
error FDInvalidNewFinishedEpoch(uint256 oldFinishedEpoch, uint256 newFinishedEpoch);
error FDInvalidStartEpoch(uint256 startEpoch);
error FDInvalidWTimeFund(uint256 lastFunded, uint256 wTime);
error FDFutureFunding(uint256 lastFunded, uint256 currentWTime);
error BDInvalidEpoch(uint256 epoch, uint256 startTime);
// Cross-Chain
error MsgNotFromSendEndpoint(uint16 srcChainId, bytes path);
error MsgNotFromReceiveEndpoint(address sender);
error InsufficientFeeToSendMsg(uint256 currentFee, uint256 requiredFee);
error ApproxDstExecutionGasNotSet();
error InvalidRetryData();
// GENERIC MSG
error ArrayLengthMismatch();
error ArrayEmpty();
error ArrayOutOfBounds();
error ZeroAddress();
error FailedToSendEther();
error InvalidMerkleProof();
error OnlyLayerZeroEndpoint();
error OnlyYT();
error OnlyYCFactory();
error OnlyWhitelisted();
// Swap Aggregator
error SAInsufficientTokenIn(address tokenIn, uint256 amountExpected, uint256 amountActual);
error UnsupportedSelector(uint256 aggregatorType, bytes4 selector);
}
PMath.sol 225 lines
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.8.0;
/* solhint-disable private-vars-leading-underscore, reason-string */
library PMath {
uint256 internal constant ONE = 1e18; // 18 decimal places
int256 internal constant IONE = 1e18; // 18 decimal places
function subMax0(uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
return (a >= b ? a - b : 0);
}
}
function subNoNeg(int256 a, int256 b) internal pure returns (int256) {
require(a >= b, "negative");
return a - b; // no unchecked since if b is very negative, a - b might overflow
}
function mulDown(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 product = a * b;
unchecked {
return product / ONE;
}
}
function mulDown(int256 a, int256 b) internal pure returns (int256) {
int256 product = a * b;
unchecked {
return product / IONE;
}
}
function divDown(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 aInflated = a * ONE;
unchecked {
return aInflated / b;
}
}
function divDown(int256 a, int256 b) internal pure returns (int256) {
int256 aInflated = a * IONE;
unchecked {
return aInflated / b;
}
}
function rawDivUp(uint256 a, uint256 b) internal pure returns (uint256) {
return (a + b - 1) / b;
}
function rawDivUp(int256 a, int256 b) internal pure returns (int256) {
return (a + b - 1) / b;
}
function tweakUp(uint256 a, uint256 factor) internal pure returns (uint256) {
return mulDown(a, ONE + factor);
}
function tweakDown(uint256 a, uint256 factor) internal pure returns (uint256) {
return mulDown(a, ONE - factor);
}
/// @return res = min(a + b, bound)
/// @dev This function should handle arithmetic operation and bound check without overflow/underflow
function addWithUpperBound(uint256 a, uint256 b, uint256 bound) internal pure returns (uint256 res) {
unchecked {
if (type(uint256).max - b < a) res = bound;
else res = min(bound, a + b);
}
}
/// @return res = max(a - b, bound)
/// @dev This function should handle arithmetic operation and bound check without overflow/underflow
function subWithLowerBound(uint256 a, uint256 b, uint256 bound) internal pure returns (uint256 res) {
unchecked {
if (b > a) res = bound;
else res = max(a - b, bound);
}
}
function clamp(uint256 x, uint256 lower, uint256 upper) internal pure returns (uint256 res) {
res = x;
if (x < lower) res = lower;
else if (x > upper) res = upper;
}
// @author Uniswap
function sqrt(uint256 y) internal pure returns (uint256 z) {
if (y > 3) {
z = y;
uint256 x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
}
} else if (y != 0) {
z = 1;
}
}
function square(uint256 x) internal pure returns (uint256) {
return x * x;
}
function squareDown(uint256 x) internal pure returns (uint256) {
return mulDown(x, x);
}
function abs(int256 x) internal pure returns (uint256) {
return uint256(x > 0 ? x : -x);
}
function neg(int256 x) internal pure returns (int256) {
return x * (-1);
}
function neg(uint256 x) internal pure returns (int256) {
return Int(x) * (-1);
}
function max(uint256 x, uint256 y) internal pure returns (uint256) {
return (x > y ? x : y);
}
function max(int256 x, int256 y) internal pure returns (int256) {
return (x > y ? x : y);
}
function min(uint256 x, uint256 y) internal pure returns (uint256) {
return (x < y ? x : y);
}
function min(int256 x, int256 y) internal pure returns (int256) {
return (x < y ? x : y);
}
/*///////////////////////////////////////////////////////////////
SIGNED CASTS
//////////////////////////////////////////////////////////////*/
function Int(uint256 x) internal pure returns (int256) {
require(x <= uint256(type(int256).max));
return int256(x);
}
function Int128(int256 x) internal pure returns (int128) {
require(type(int128).min <= x && x <= type(int128).max);
return int128(x);
}
function Int128(uint256 x) internal pure returns (int128) {
return Int128(Int(x));
}
/*///////////////////////////////////////////////////////////////
UNSIGNED CASTS
//////////////////////////////////////////////////////////////*/
function Uint(int256 x) internal pure returns (uint256) {
require(x >= 0);
return uint256(x);
}
function Uint32(uint256 x) internal pure returns (uint32) {
require(x <= type(uint32).max);
return uint32(x);
}
function Uint64(uint256 x) internal pure returns (uint64) {
require(x <= type(uint64).max);
return uint64(x);
}
function Uint112(uint256 x) internal pure returns (uint112) {
require(x <= type(uint112).max);
return uint112(x);
}
function Uint96(uint256 x) internal pure returns (uint96) {
require(x <= type(uint96).max);
return uint96(x);
}
function Uint128(uint256 x) internal pure returns (uint128) {
require(x <= type(uint128).max);
return uint128(x);
}
function Uint192(uint256 x) internal pure returns (uint192) {
require(x <= type(uint192).max);
return uint192(x);
}
function Uint80(uint256 x) internal pure returns (uint80) {
require(x <= type(uint80).max);
return uint80(x);
}
function isAApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {
return mulDown(b, ONE - eps) <= a && a <= mulDown(b, ONE + eps);
}
function isAGreaterApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {
return a >= b && a <= mulDown(b, ONE + eps);
}
function isASmallerApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {
return a <= b && a >= mulDown(b, ONE - eps);
}
}
MiniHelpers.sol 16 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
library MiniHelpers {
function isCurrentlyExpired(uint256 expiry) internal view returns (bool) {
return (expiry <= block.timestamp);
}
function isExpired(uint256 expiry, uint256 blockTime) internal pure returns (bool) {
return (expiry <= blockTime);
}
function isTimeInThePast(uint256 timestamp) internal view returns (bool) {
return (timestamp <= block.timestamp); // same definition as isCurrentlyExpired
}
}
IPGaugeController.sol 20 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
interface IPGaugeController {
event MarketClaimReward(address indexed market, uint256 amount);
event ReceiveVotingResults(uint128 indexed wTime, address[] markets, uint256[] pendleAmounts);
event UpdateMarketReward(address indexed market, uint256 pendlePerSec, uint256 incentiveEndsAt);
function fundPendle(uint256 amount) external;
function withdrawPendle(uint256 amount) external;
function pendle() external returns (address);
function redeemMarketReward() external;
function rewardData(address pool) external view returns (uint128 pendlePerSec, uint128, uint128, uint128);
}
IPGaugeControllerMainchain.sol 8 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
import "./IPGaugeController.sol";
interface IPGaugeControllerMainchain is IPGaugeController {
function updateVotingResults(uint128 wTime, address[] calldata markets, uint256[] calldata pendleSpeeds) external;
}
IPMsgSendEndpoint.sol 19 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.0;
interface IPMsgSendEndpoint {
function calcFee(
address dstAddress,
uint256 dstChainId,
bytes memory payload,
uint256 estimatedGasAmount
) external view returns (uint256 fee);
function sendMessage(
address dstAddress,
uint256 dstChainId,
bytes calldata payload,
uint256 estimatedGasAmount
) external payable;
}
IPVeToken.sol 19 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
interface IPVeToken {
// ============= USER INFO =============
function balanceOf(address user) external view returns (uint128);
function positionData(address user) external view returns (uint128 amount, uint128 expiry);
// ============= META DATA =============
function totalSupplyStored() external view returns (uint128);
function totalSupplyCurrent() external returns (uint128);
function totalSupplyAndBalanceCurrent(address user) external returns (uint128, uint128);
}
IPVotingController.sol 43 lines
pragma solidity ^0.8.0;
import "../LiquidityMining/libraries/VeBalanceLib.sol";
import "../LiquidityMining/libraries/VeHistoryLib.sol";
interface IPVotingController {
event AddPool(uint64 indexed chainId, address indexed pool);
event RemovePool(uint64 indexed chainId, address indexed pool);
event Vote(address indexed user, address indexed pool, uint64 weight, VeBalance vote);
event PoolVoteChange(address indexed pool, VeBalance vote);
event SetPendlePerSec(uint256 newPendlePerSec);
event BroadcastResults(uint64 indexed chainId, uint128 indexed wTime, uint128 totalPendlePerSec);
event SetPoolCaps(address[] pools, uint256[] caps);
event SetGlobalCap(uint256 cap);
function applyPoolSlopeChanges(address pool) external;
/// @notice deprecated, only kept for compatibility reasons
function getUserPoolHistoryLength(address user, address pool) external view returns (uint256);
/// @notice deprecated, only kept for compatibility reasons
function getUserPoolHistoryAt(address user, address pool, uint256 index) external view returns (Checkpoint memory);
function getWeekData(
uint128 wTime,
address[] calldata pools
) external view returns (bool isEpochFinalized, uint128 totalVotes, uint128[] memory poolVotes);
function getPoolTotalVoteAt(address pool, uint128 wTime) external view returns (uint128);
function finalizeEpoch() external;
function getBroadcastResultFee(uint64 chainId) external view returns (uint256);
function broadcastResults(uint64 chainId) external payable;
}
PendleMsgSenderAppUpg.sol 67 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
import "../../interfaces/IPMsgSendEndpoint.sol";
import "../../core/libraries/BoringOwnableUpgradeableV2.sol";
import "../../core/libraries/Errors.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
// solhint-disable no-empty-blocks
abstract contract PendleMsgSenderAppUpg is BoringOwnableUpgradeableV2 {
using EnumerableMap for EnumerableMap.UintToAddressMap;
uint256 public approxDstExecutionGas;
IPMsgSendEndpoint public immutable pendleMsgSendEndpoint;
// destinationContracts mapping contains one address for each chainId only
EnumerableMap.UintToAddressMap internal destinationContracts;
uint256[100] private __gap;
modifier refundUnusedEth() {
_;
if (address(this).balance > 0) {
AddressUpgradeable.sendValue(payable(msg.sender), address(this).balance);
}
}
constructor(address _pendleMsgSendEndpoint, uint256 _approxDstExecutionGas) {
pendleMsgSendEndpoint = IPMsgSendEndpoint(_pendleMsgSendEndpoint);
approxDstExecutionGas = _approxDstExecutionGas;
}
function _sendMessage(uint256 chainId, bytes memory message) internal {
assert(destinationContracts.contains(chainId));
address toAddr = destinationContracts.get(chainId);
uint256 estimatedGasAmount = approxDstExecutionGas;
uint256 fee = pendleMsgSendEndpoint.calcFee(toAddr, chainId, message, estimatedGasAmount);
// LM contracts won't hold ETH on its own so this is fine
if (address(this).balance < fee) revert Errors.InsufficientFeeToSendMsg(address(this).balance, fee);
pendleMsgSendEndpoint.sendMessage{value: fee}(toAddr, chainId, message, estimatedGasAmount);
}
function addDestinationContract(address _address, uint256 _chainId) external payable onlyOwner {
destinationContracts.set(_chainId, _address);
}
function setApproxDstExecutionGas(uint256 gas) external onlyOwner {
approxDstExecutionGas = gas;
}
function getAllDestinationContracts() public view returns (uint256[] memory chainIds, address[] memory addrs) {
uint256 length = destinationContracts.length();
chainIds = new uint256[](length);
addrs = new address[](length);
for (uint256 i = 0; i < length; ++i) {
(chainIds[i], addrs[i]) = destinationContracts.at(i);
}
}
function _getSendMessageFee(uint256 chainId, bytes memory message) internal view returns (uint256) {
return
pendleMsgSendEndpoint.calcFee(destinationContracts.get(chainId), chainId, message, approxDstExecutionGas);
}
}
VeBalanceLib.sol 75 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
import "../../core/libraries/math/PMath.sol";
import "../../core/libraries/Errors.sol";
struct VeBalance {
uint128 bias;
uint128 slope;
}
struct LockedPosition {
uint128 amount;
uint128 expiry;
}
library VeBalanceLib {
using PMath for uint256;
uint128 internal constant MAX_LOCK_TIME = 104 weeks;
uint256 internal constant USER_VOTE_MAX_WEIGHT = 10 ** 18;
function add(VeBalance memory a, VeBalance memory b) internal pure returns (VeBalance memory res) {
res.bias = a.bias + b.bias;
res.slope = a.slope + b.slope;
}
function sub(VeBalance memory a, VeBalance memory b) internal pure returns (VeBalance memory res) {
res.bias = a.bias - b.bias;
res.slope = a.slope - b.slope;
}
function sub(VeBalance memory a, uint128 slope, uint128 expiry) internal pure returns (VeBalance memory res) {
res.slope = a.slope - slope;
res.bias = a.bias - slope * expiry;
}
function isExpired(VeBalance memory a) internal view returns (bool) {
return a.slope * uint128(block.timestamp) >= a.bias;
}
function getCurrentValue(VeBalance memory a) internal view returns (uint128) {
if (isExpired(a)) return 0;
return getValueAt(a, uint128(block.timestamp));
}
function getValueAt(VeBalance memory a, uint128 t) internal pure returns (uint128) {
if (a.slope * t > a.bias) {
return 0;
}
return a.bias - a.slope * t;
}
function getExpiry(VeBalance memory a) internal pure returns (uint128) {
if (a.slope == 0) revert Errors.VEZeroSlope(a.bias, a.slope);
return a.bias / a.slope;
}
function convertToVeBalance(LockedPosition memory position) internal pure returns (VeBalance memory res) {
res.slope = position.amount / MAX_LOCK_TIME;
res.bias = res.slope * position.expiry;
}
function convertToVeBalance(
LockedPosition memory position,
uint256 weight
) internal pure returns (VeBalance memory res) {
res.slope = ((position.amount * weight) / MAX_LOCK_TIME / USER_VOTE_MAX_WEIGHT).Uint128();
res.bias = res.slope * position.expiry;
}
function convertToVeBalance(uint128 amount, uint128 expiry) internal pure returns (uint128, uint128) {
VeBalance memory balance = convertToVeBalance(LockedPosition(amount, expiry));
return (balance.bias, balance.slope);
}
}
VeHistoryLib.sol 42 lines
// SPDX-License-Identifier: GPL-3.0-or-later
// Forked from OpenZeppelin (v4.5.0) (utils/Checkpoints.sol)
pragma solidity ^0.8.0;
import "../../core/libraries/math/PMath.sol";
import "./VeBalanceLib.sol";
import "./WeekMath.sol";
struct Checkpoint {
uint128 timestamp;
VeBalance value;
}
library CheckpointHelper {
function assignWith(Checkpoint memory a, Checkpoint memory b) internal pure {
a.timestamp = b.timestamp;
a.value = b.value;
}
}
library Checkpoints {
struct History {
Checkpoint[] _checkpoints;
}
function length(History storage self) internal view returns (uint256) {
return self._checkpoints.length;
}
function get(History storage self, uint256 index) internal view returns (Checkpoint memory) {
return self._checkpoints[index];
}
function push(History storage self, VeBalance memory value) internal {
uint256 pos = self._checkpoints.length;
if (pos > 0 && self._checkpoints[pos - 1].timestamp == WeekMath.getCurrentWeekStart()) {
self._checkpoints[pos - 1].value = value;
} else {
self._checkpoints.push(Checkpoint({timestamp: WeekMath.getCurrentWeekStart(), value: value}));
}
}
}
WeekMath.sol 19 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
library WeekMath {
uint128 internal constant WEEK = 7 days;
function getWeekStartTimestamp(uint128 timestamp) internal pure returns (uint128) {
return (timestamp / WEEK) * WEEK;
}
function getCurrentWeekStart() internal view returns (uint128) {
return getWeekStartTimestamp(uint128(block.timestamp));
}
function isValidWTime(uint256 time) internal pure returns (bool) {
return time % WEEK == 0;
}
}
PendleVotingControllerUpg.sol 322 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
import "./VotingControllerStorageUpg.sol";
import "../CrossChainMsg/PendleMsgSenderAppUpg.sol";
import "../libraries/VeBalanceLib.sol";
import "../../core/libraries/math/PMath.sol";
import "../../interfaces/IPGaugeControllerMainchain.sol";
import "../../interfaces/IPVotingController.sol";
import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
/*
Voting accounting:
- For gauge controller, it will consider each message from voting controller
as a pack of money to incentivize it during the very next WEEK (block.timestamp -> block.timestamp + WEEK)
- If the reward duration for the last pack of money has not ended, it will combine
the leftover reward with the current reward to distribute.
- In the very extreme case where no one broadcast the result of week x, and at week x+1,
the results for both are now broadcasted, then the WEEK of (block.timestamp -> WEEK)
will receive both of the reward pack
- Each pack of money will has it own id as timestamp, a gauge controller does not
receive a pack of money with the same id twice, this allow governance to rebroadcast
in case the last message was corrupted by LayerZero
Pros:
- If governance does not forget broadcasting the reward on the early of the week,
the mechanism works just the same as the epoch-based one
- If governance forget to broadcast the reward, the whole system still works normally,
the reward is still incentivized, but only approximately fair
Cons:
- Does not guarantee the reward will be distributed on epoch start and end
*/
contract PendleVotingControllerUpg is PendleMsgSenderAppUpg, VotingControllerStorageUpg, UUPSUpgradeable {
using VeBalanceLib for VeBalance;
using PMath for uint256;
using PMath for int256;
using EnumerableMap for EnumerableMap.UintToAddressMap;
using EnumerableSet for EnumerableSet.AddressSet;
constructor(
address _vePendle,
address _pendleMsgSendEndpoint,
uint256 initialApproxDestinationGas
)
VotingControllerStorageUpg(_vePendle)
PendleMsgSenderAppUpg(_pendleMsgSendEndpoint, initialApproxDestinationGas) // constructor only set immutable variables
initializer
//solhint-disable-next-line
{
}
function initialize(address _owner) external initializer {
__BoringOwnableV2_init(_owner);
deployedWTime = WeekMath.getCurrentWeekStart();
}
/*///////////////////////////////////////////////////////////////
FUNCTIONS CAN BE CALLED BY ANYONE
//////////////////////////////////////////////////////////////*/
/**
* @notice updates a user's vote weights, also allowing user to divide their voting power
* across different pools
* @param pools pools to change vote weights, if not listed then existing weight won't change
* @param weights voting weight on each pool in `pools`, must be same length as `pools`
* @dev A user's max voting weights is equal to `USER_VOTE_MAX_WEIGHT` (1e18). If their total
* voted weights is less than such, then the excess weight is not counted. For such reason, a
* user's voting power will only be fully utilized if their total voted weight is exactly 1e18.
* @dev Reverts if, after all vote changes, the total voted weight is more than 1e18.
* @dev A removed pool can be included, but the new weight must be 0, otherwise will revert.
* @dev See {`VotingControllerStorageUpg - getUserData()`} for current user data.
*/
function vote(address[] calldata pools, uint64[] calldata weights) external {
address user = msg.sender;
if (pools.length != weights.length) revert Errors.ArrayLengthMismatch();
if (user != owner && vePendle.balanceOf(user) == 0) revert Errors.VCZeroVePendle(user);
LockedPosition memory userPosition = _getUserVePendlePosition(user);
for (uint256 i = 0; i < pools.length; ++i) {
if (_isPoolActive(pools[i])) applyPoolSlopeChanges(pools[i]);
VeBalance memory newVote = _modifyVoteWeight(user, pools[i], userPosition, weights[i]);
emit Vote(user, pools[i], weights[i], newVote);
}
uint256 totalVotedWeight = userData[user].totalVotedWeight;
if (totalVotedWeight > VeBalanceLib.USER_VOTE_MAX_WEIGHT)
revert Errors.VCExceededMaxWeight(totalVotedWeight, VeBalanceLib.USER_VOTE_MAX_WEIGHT);
}
/**
* @notice Process all the slopeChanges that haven't been processed & update these data into
* poolData
* @dev reverts if pool is not active
* @dev if pool is already up-to-date, the function will succeed without any state updates
*/
function applyPoolSlopeChanges(address pool) public {
if (!_isPoolActive(pool)) revert Errors.VCInactivePool(pool);
uint128 wTime = poolData[pool].lastSlopeChangeAppliedAt;
uint128 currentWeekStart = WeekMath.getCurrentWeekStart();
// no state changes are expected
if (wTime >= currentWeekStart) return;
VeBalance memory currentVote = poolData[pool].totalVote;
while (wTime < currentWeekStart) {
wTime += WEEK;
currentVote = currentVote.sub(poolData[pool].slopeChanges[wTime], wTime);
_setFinalPoolVoteForWeek(pool, wTime, currentVote.getValueAt(wTime));
}
_setNewVotePoolData(pool, currentVote, wTime);
}
/**
* @notice finalize the voting results of all pools, up to the current epoch
* @dev See `applyPoolSlopeChanges()` for more details
* @dev This function might be gas-costly if there are a lot of active pools, but this can be
* mitigated by calling `applyPoolSlopeChanges()` for each pool separately, spreading the gas
* cost across multiple txs (although the total gas cost will be higher).
* This is because `applyPoolSlopeChanges()` will not update anything if already up-to-date.
*/
function finalizeEpoch() public {
uint256 length = allActivePools.length();
for (uint256 i = 0; i < length; ++i) {
applyPoolSlopeChanges(allActivePools.at(i));
}
_setAllPastEpochsAsFinalized();
}
/**
* @notice broadcast the voting results of the current week to the chain with chainId. Can be
* called by anyone.
* @dev It's intentional to allow the same results to be broadcasted multiple
* times. The receiver should be able to filter these duplicated messages
* @dev The epoch must have already been finalized by `finalizeEpoch()`, otherwise will revert.
*/
function broadcastResults(uint64 chainId) external payable refundUnusedEth {
uint128 wTime = WeekMath.getCurrentWeekStart();
if (!weekData[wTime].isEpochFinalized) revert Errors.VCEpochNotFinalized(wTime);
_broadcastResults(chainId, wTime, pendlePerSec, globalCap);
}
/*///////////////////////////////////////////////////////////////
GOVERNANCE-ONLY FUNCTIONS
//////////////////////////////////////////////////////////////*/
modifier onlyAddPoolHelperAndOwner() {
require(msg.sender == addPoolHelper || msg.sender == owner, "add pool not allowed");
_;
}
modifier onlyRemovePoolHelperAndOwner() {
require(msg.sender == removePoolHelper || msg.sender == owner, "remove pool not allowed");
_;
}
/**
* @notice add a pool to allow users to vote. Can only be done by [governance/owner helper]
* @custom:gov NOTE TO GOV:
* - Previous week's results should have been broadcasted prior to calling this function.
* - `pool` must not have been added before (even if has been removed).
* - `chainId` must be valid.
*/
function addMultiPools(uint64[] memory chainIds, address[] memory pools) external onlyAddPoolHelperAndOwner {
if (chainIds.length != pools.length) revert Errors.ArrayLengthMismatch();
for (uint256 i = 0; i < chainIds.length; ++i) {
(uint64 chainId, address pool) = (chainIds[i], pools[i]);
if (_isPoolActive(pool)) revert Errors.VCPoolAlreadyActive(pool);
if (allRemovedPools.contains(pool)) revert Errors.VCPoolAlreadyAddAndRemoved(pool);
_addPool(chainId, pool);
emit AddPool(chainId, pool);
}
}
/**
* @notice remove a pool from voting. Can only be done by governance
* @custom:gov NOTE TO GOV:
* - Previous week's results should have been broadcasted prior to calling this function.
* - `pool` must be currently active.
*/
function removeMultiPools(address[] calldata pools) external onlyRemovePoolHelperAndOwner {
for (uint256 i = 0; i < pools.length; ++i) {
address pool = pools[i];
if (!_isPoolActive(pool)) revert Errors.VCInactivePool(pool);
uint64 chainId = poolData[pool].chainId;
applyPoolSlopeChanges(pool);
_removePool(pool);
emit RemovePool(chainId, pool);
}
}
/**
* @notice set the cap for a pool, or remove cap (using global cap) if `cap` is 0
*/
function setPoolCaps(address[] calldata pools, uint256[] calldata caps) external onlyAddPoolHelperAndOwner {
if (pools.length != caps.length) revert Errors.ArrayLengthMismatch();
for (uint256 i = 0; i < pools.length; ++i) {
_setPoolCap(pools[i], caps[i]);
}
emit SetPoolCaps(pools, caps);
}
function setGlobalCap(uint256 cap) external onlyOwner {
_setGlobalCap(cap);
emit SetGlobalCap(cap);
}
/**
* @notice use the gov-privilege to force broadcast a message in case there are issues with LayerZero
* @custom:gov NOTE TO GOV: gov should always call finalizeEpoch beforehand
*/
function forceBroadcastResults(
uint64 chainId,
uint128 wTime,
uint128 forcedPendlePerSec
) external payable onlyOwner refundUnusedEth {
_broadcastResults(chainId, wTime, forcedPendlePerSec, globalCap);
}
/**
* @notice sets new pendlePerSec
* @dev no zero checks because gov may want to stop liquidity mining
* @custom:gov NOTE TO GOV: Should be done mid-week, well before the next broadcast to avoid
* race condition
*/
function setPendlePerSec(uint128 newPendlePerSec) external onlyOwner {
pendlePerSec = newPendlePerSec;
emit SetPendlePerSec(newPendlePerSec);
}
function getBroadcastResultFee(uint64 chainId) external view returns (uint256) {
if (chainId == block.chainid) return 0; // Mainchain broadcast
uint256 length = activeChainPools[chainId].length();
if (length == 0) return 0;
address[] memory pools = new address[](length);
uint256[] memory totalPendleAmounts = new uint256[](length);
return _getSendMessageFee(chainId, abi.encode(uint128(0), pools, totalPendleAmounts));
}
/*///////////////////////////////////////////////////////////////
INTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
function _removePoolAndApplySlope(address pool) internal {
if (!_isPoolActive(pool)) revert Errors.VCInactivePool(pool);
uint64 chainId = poolData[pool].chainId;
applyPoolSlopeChanges(pool);
_removePool(pool);
emit RemovePool(chainId, pool);
}
/// @notice broadcast voting results of the timestamp to chainId
function _broadcastResults(
uint64 chainId,
uint128 wTime,
uint128 totalPendlePerSec,
uint256 currentGlobalCap
) internal {
uint256 totalVotes = weekData[wTime].totalVotes;
if (totalVotes == 0) return;
uint256 length = activeChainPools[chainId].length();
if (length == 0) return;
address[] memory pools = activeChainPools[chainId].values();
uint256[] memory totalPendleAmounts = new uint256[](length);
for (uint256 i = 0; i < length; ++i) {
uint256 poolVotes = weekData[wTime].poolVotes[pools[i]];
uint256 cappedRate = PMath.min(_getPoolCapOpt(pools[i], currentGlobalCap), poolVotes.divDown(totalVotes));
totalPendleAmounts[i] = (uint256(totalPendlePerSec) * WEEK).mulDown(cappedRate);
}
if (chainId == block.chainid) {
address gaugeController = destinationContracts.get(chainId);
IPGaugeControllerMainchain(gaugeController).updateVotingResults(wTime, pools, totalPendleAmounts);
} else {
_sendMessage(chainId, abi.encode(wTime, pools, totalPendleAmounts));
}
emit BroadcastResults(chainId, wTime, totalPendlePerSec);
}
function _getUserVePendlePosition(address user) internal view returns (LockedPosition memory userPosition) {
if (user == owner) {
(userPosition.amount, userPosition.expiry) = (
GOVERNANCE_PENDLE_VOTE,
WeekMath.getWeekStartTimestamp(uint128(block.timestamp) + MAX_LOCK_TIME)
);
} else {
(userPosition.amount, userPosition.expiry) = vePendle.positionData(user);
}
}
function setAddPoolHelper(address _helper) public onlyOwner {
addPoolHelper = _helper;
}
function setRemovePoolHelper(address _helper) public onlyOwner {
removePoolHelper = _helper;
}
//solhint-disable-next-line
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
}
VotingControllerStorageUpg.sol 297 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
import "../../interfaces/IPVeToken.sol";
import "../../interfaces/IPVotingController.sol";
import "../libraries/VeBalanceLib.sol";
import "../libraries/WeekMath.sol";
import "../libraries/VeHistoryLib.sol";
import "../../core/libraries/MiniHelpers.sol";
import "../../core/libraries/Errors.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
abstract contract VotingControllerStorageUpg is IPVotingController {
using VeBalanceLib for VeBalance;
using VeBalanceLib for LockedPosition;
using EnumerableSet for EnumerableSet.AddressSet;
using Checkpoints for Checkpoints.History;
using WeekMath for uint128;
struct PoolData {
uint64 chainId;
uint128 lastSlopeChangeAppliedAt;
VeBalance totalVote;
// wTime => slopeChange value
mapping(uint128 => uint128) slopeChanges;
}
struct UserPoolData {
uint64 weight;
VeBalance vote;
}
struct UserData {
uint64 totalVotedWeight;
mapping(address => UserPoolData) voteForPools;
}
struct WeekData {
bool isEpochFinalized;
uint128 totalVotes;
mapping(address => uint128) poolVotes;
}
uint128 public constant MAX_LOCK_TIME = 104 weeks;
uint128 public constant WEEK = 1 weeks;
uint128 public constant GOVERNANCE_PENDLE_VOTE = 10 * (10 ** 6) * (10 ** 18); // 10 mils of PENDLE
IPVeToken public immutable vePendle;
uint128 public deployedWTime;
uint128 public pendlePerSec;
EnumerableSet.AddressSet internal allActivePools;
EnumerableSet.AddressSet internal allRemovedPools;
// [chainId] => [pool]
mapping(uint64 => EnumerableSet.AddressSet) internal activeChainPools;
// [poolAddress] -> PoolData
mapping(address => PoolData) internal poolData;
// [wTime] => WeekData
mapping(uint128 => WeekData) internal weekData;
// user voting data
mapping(address => UserData) internal userData;
// [user][pool] => checkpoint
mapping(address => mapping(address => Checkpoints.History)) internal __dep_userPoolHistory;
address public addPoolHelper;
address public removePoolHelper;
// [pool] => cap
mapping(address => uint256) public poolCaps;
uint256 public globalCap;
uint256[96] private __gap;
constructor(address _vePendle) {
vePendle = IPVeToken(_vePendle);
}
/*///////////////////////////////////////////////////////////////
VIEW FUNCTIONS
//////////////////////////////////////////////////////////////*/
function getPoolCap(address pool) public view returns (uint256) {
uint256 cap = poolCaps[pool];
return (cap != 0) ? cap : globalCap;
}
function getPoolTotalVoteAt(address pool, uint128 wTime) public view returns (uint128) {
return weekData[wTime].poolVotes[pool];
}
/// @notice deprecated, only kept for compatibility reasons
function getUserPoolHistoryLength(address user, address pool) external view returns (uint256) {
return __dep_userPoolHistory[user][pool].length();
}
/// @notice deprecated, only kept for compatibility reasons
function getUserPoolHistoryAt(address user, address pool, uint256 index) external view returns (Checkpoint memory) {
return __dep_userPoolHistory[user][pool].get(index);
}
function getPoolData(
address pool,
uint128[] calldata wTimes
)
public
view
returns (
uint64 chainId,
uint128 lastSlopeChangeAppliedAt,
VeBalance memory totalVote,
uint128[] memory slopeChanges
)
{
PoolData storage data = poolData[pool];
(chainId, lastSlopeChangeAppliedAt, totalVote) = (data.chainId, data.lastSlopeChangeAppliedAt, data.totalVote);
slopeChanges = new uint128[](wTimes.length);
for (uint256 i = 0; i < wTimes.length; ++i) {
if (!wTimes[i].isValidWTime()) revert Errors.InvalidWTime(wTimes[i]);
slopeChanges[i] = data.slopeChanges[wTimes[i]];
}
}
function getUserData(
address user,
address[] calldata pools
) public view returns (uint64 totalVotedWeight, UserPoolData[] memory voteForPools) {
UserData storage data = userData[user];
totalVotedWeight = data.totalVotedWeight;
voteForPools = new UserPoolData[](pools.length);
for (uint256 i = 0; i < pools.length; ++i) voteForPools[i] = data.voteForPools[pools[i]];
}
function getWeekData(
uint128 wTime,
address[] calldata pools
) public view returns (bool isEpochFinalized, uint128 totalVotes, uint128[] memory poolVotes) {
if (!wTime.isValidWTime()) revert Errors.InvalidWTime(wTime);
WeekData storage data = weekData[wTime];
(isEpochFinalized, totalVotes) = (data.isEpochFinalized, data.totalVotes);
poolVotes = new uint128[](pools.length);
for (uint256 i = 0; i < pools.length; ++i) poolVotes[i] = data.poolVotes[pools[i]];
}
function getAllActivePools() external view returns (address[] memory) {
return allActivePools.values();
}
function getAllRemovedPools(
uint256 start,
uint256 end
) external view returns (uint256 lengthOfRemovedPools, address[] memory arr) {
lengthOfRemovedPools = allRemovedPools.length();
if (end >= lengthOfRemovedPools) revert Errors.ArrayOutOfBounds();
arr = new address[](end - start + 1);
for (uint256 i = start; i <= end; ++i) arr[i - start] = allRemovedPools.at(i);
}
function getActiveChainPools(uint64 chainId) external view returns (address[] memory) {
return activeChainPools[chainId].values();
}
function getUserPoolVote(address user, address pool) external view returns (UserPoolData memory) {
return userData[user].voteForPools[pool];
}
/*///////////////////////////////////////////////////////////////
INTERNAL DATA MANIPULATION FUNCTIONS
//////////////////////////////////////////////////////////////*/
function _addPool(uint64 chainId, address pool) internal {
if (!activeChainPools[chainId].add(pool)) assert(false);
if (!allActivePools.add(pool)) assert(false);
poolData[pool].chainId = chainId;
poolData[pool].lastSlopeChangeAppliedAt = WeekMath.getCurrentWeekStart();
}
function _removePool(address pool) internal {
uint64 chainId = poolData[pool].chainId;
if (!activeChainPools[chainId].remove(pool)) assert(false);
if (!allActivePools.remove(pool)) assert(false);
if (!allRemovedPools.add(pool)) assert(false);
delete poolData[pool];
}
function _setFinalPoolVoteForWeek(address pool, uint128 wTime, uint128 vote) internal {
weekData[wTime].totalVotes += vote;
weekData[wTime].poolVotes[pool] = vote;
}
function _setNewVotePoolData(address pool, VeBalance memory vote, uint128 wTime) internal {
poolData[pool].totalVote = vote;
poolData[pool].lastSlopeChangeAppliedAt = wTime;
emit PoolVoteChange(pool, vote);
}
/**
* @notice modifies `user`'s vote weight on `pool`
* @dev works by simply removing the old vote position, then adds in a fresh vote
*/
function _modifyVoteWeight(
address user,
address pool,
LockedPosition memory userPosition,
uint64 weight
) internal returns (VeBalance memory newVote) {
UserData storage uData = userData[user];
PoolData storage pData = poolData[pool];
VeBalance memory oldVote = uData.voteForPools[pool].vote;
// REMOVE OLD VOTE
if (oldVote.bias != 0) {
if (_isPoolActive(pool) && _isVoteActive(oldVote)) {
pData.totalVote = pData.totalVote.sub(oldVote);
pData.slopeChanges[oldVote.getExpiry()] -= oldVote.slope;
}
uData.totalVotedWeight -= uData.voteForPools[pool].weight;
delete uData.voteForPools[pool];
}
// ADD NEW VOTE
if (weight != 0) {
if (!_isPoolActive(pool)) revert Errors.VCInactivePool(pool);
newVote = userPosition.convertToVeBalance(weight);
pData.totalVote = pData.totalVote.add(newVote);
pData.slopeChanges[newVote.getExpiry()] += newVote.slope;
uData.voteForPools[pool] = UserPoolData(weight, newVote);
uData.totalVotedWeight += weight;
}
emit PoolVoteChange(pool, pData.totalVote);
}
function _setAllPastEpochsAsFinalized() internal {
uint128 wTime = WeekMath.getCurrentWeekStart();
while (wTime > deployedWTime && weekData[wTime].isEpochFinalized == false) {
weekData[wTime].isEpochFinalized = true;
wTime -= WEEK;
}
}
function _isPoolActive(address pool) internal view returns (bool) {
return allActivePools.contains(pool);
}
/// @notice check if a vote still counts by checking if the vote is not (x,0) (in case the
/// weight of the vote is too small) & the expiry is after the current time
function _isVoteActive(VeBalance memory vote) internal view returns (bool) {
return vote.slope != 0 && !MiniHelpers.isCurrentlyExpired(vote.getExpiry());
}
function _setPoolCap(address pool, uint256 cap) internal {
_validateCap(cap);
poolCaps[pool] = cap;
}
function _setGlobalCap(uint256 cap) internal {
_validateCap(cap);
globalCap = cap;
}
function _getPoolCapOpt(address _pool, uint256 _globalCap) internal view returns (uint256) {
uint256 cap = poolCaps[_pool];
return (cap != 0) ? cap : _globalCap;
}
function _validateCap(uint256 cap) internal pure {
if (cap > PMath.ONE) {
revert Errors.VCInvalidCap(cap);
}
}
}
Read Contract
GOVERNANCE_PENDLE_VOTE 0xbfa5b324 → uint128
MAX_LOCK_TIME 0xfa78668f → uint128
WEEK 0xf4359ce5 → uint128
addPoolHelper 0x2982d519 → address
approxDstExecutionGas 0x9efc7575 → uint256
deployedWTime 0xb292bf95 → uint128
getActiveChainPools 0x16ac7e30 → address[]
getAllActivePools 0xd5cd7d20 → address[]
getAllDestinationContracts 0x3e39b650 → uint256[], address[]
getAllRemovedPools 0xcc88370e → uint256, address[]
getBroadcastResultFee 0x2477bfbe → uint256
getPoolCap 0x945f1838 → uint256
getPoolData 0x366c771d → uint64, uint128, tuple, uint128[]
getPoolTotalVoteAt 0xf144cf17 → uint128
getUserData 0x8f45ff78 → uint64, tuple[]
getUserPoolHistoryAt 0x632c096d → tuple
getUserPoolHistoryLength 0x6aea2826 → uint256
getUserPoolVote 0x646fb67c → tuple
getWeekData 0x8d66c284 → bool, uint128, uint128[]
globalCap 0x99a2af75 → uint256
owner 0x8da5cb5b → address
pendingOwner 0xe30c3978 → address
pendleMsgSendEndpoint 0x89c071ea → address
pendlePerSec 0xf7f03fea → uint128
poolCaps 0x92a8b2d3 → uint256
proxiableUUID 0x52d1902d → bytes32
removePoolHelper 0xa0e11634 → address
vePendle 0x82dabb21 → address
Write Contract 19 functions
These functions modify contract state and require a wallet transaction to execute.
addDestinationContract 0x21049028
address _address
uint256 _chainId
addMultiPools 0x13d65dcb
uint64[] chainIds
address[] pools
applyPoolSlopeChanges 0x38b8765c
address pool
broadcastResults 0xc291230d
uint64 chainId
claimOwnership 0x4e71e0c8
No parameters
finalizeEpoch 0x82ae9ef7
No parameters
forceBroadcastResults 0x1c9bdb49
uint64 chainId
uint128 wTime
uint128 forcedPendlePerSec
initialize 0xc4d66de8
address _owner
removeMultiPools 0x13b6e971
address[] pools
setAddPoolHelper 0x9f752aef
address _helper
setApproxDstExecutionGas 0xd45f5e21
uint256 gas
setGlobalCap 0xa71f6f5f
uint256 cap
setPendlePerSec 0x59255706
uint128 newPendlePerSec
setPoolCaps 0xe5c64935
address[] pools
uint256[] caps
setRemovePoolHelper 0x49be407d
address _helper
transferOwnership 0x078dfbe7
address newOwner
bool direct
bool renounce
upgradeTo 0x3659cfe6
address newImplementation
upgradeToAndCall 0x4f1ef286
address newImplementation
bytes data
vote 0x698766ee
address[] pools
uint64[] weights
Recent Transactions
This address has 1 on-chain transactions, but only 1.5% of the chain is indexed. Transactions will appear as indexing progresses. View on Etherscan →