Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x41E4334286d882fe024941baCbc28c242d897372
Balance 0 ETH
Nonce 1
Code Size 12023 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

12023 bytes
0x6080604052600436106101e65760003560e01c80636359b87211610102578063b6cf3fef11610095578063f1650a4611610064578063f1650a46146106aa578063f5abc562146106ca578063f8c8765e146106ea578063fac48eea1461070a57600080fd5b8063b6cf3fef1461060e578063c1af971a1461063c578063c8393ba91461066a578063d547741f1461068a57600080fd5b806386f26f77116100d157806386f26f771461055e57806391d148541461057e5780639cd89e99146105c4578063a217fddf146105f957600080fd5b80636359b872146104a95780636dbaf9ee146104c95780637cef12ae146104dc5780638456cb591461054957600080fd5b806336568abe1161017a5780634d50f9a4116101495780634d50f9a41461043b57806350f73e7c1461045b5780635c975abb146104715780635f57f9681461048957600080fd5b806336568abe146103845780633ddd2511146103a45780633f4ba83a1461040657806347204df11461041b57600080fd5b8063248a9ca3116101b6578063248a9ca3146102da57806329db05e11461030a5780632cb2f198146103425780632f2ff15d1461036257600080fd5b8062918407146101f257806301ffc9a7146102255780630c955fb414610255578063124b82a51461028257600080fd5b366101ed57005b600080fd5b3480156101fe57600080fd5b5061021261020d366004612aca565b610738565b6040519081526020015b60405180910390f35b34801561023157600080fd5b50610245610240366004612b03565b610785565b604051901515815260200161021c565b34801561026157600080fd5b50610212610270366004612b45565b60fe6020526000908152604090205481565b34801561028e57600080fd5b506102bf61029d366004612b62565b6101026020526000908152604090208054600182015460029092015490919083565b6040805193845260208401929092529082015260600161021c565b3480156102e657600080fd5b506102126102f5366004612b62565b600090815260c9602052604090206001015490565b34801561031657600080fd5b5060fc5461032a906001600160a01b031681565b6040516001600160a01b03909116815260200161021c565b34801561034e57600080fd5b5060fd5461032a906001600160a01b031681565b34801561036e57600080fd5b5061038261037d366004612b7b565b61081c565b005b34801561039057600080fd5b5061038261039f366004612b7b565b610846565b3480156103b057600080fd5b506102126103bf366004612ba0565b6040516bffffffffffffffffffffffff19606084901b1660208201526034810182905260009060540160405160208183030381529060405280519060200120905092915050565b34801561041257600080fd5b506103826108d7565b34801561042757600080fd5b506102bf610436366004612bcc565b61090c565b34801561044757600080fd5b50610382610456366004612b62565b610975565b34801561046757600080fd5b5061021260ff5481565b34801561047d57600080fd5b5060335460ff16610245565b34801561049557600080fd5b506102126104a4366004612b45565b6109db565b3480156104b557600080fd5b506102126104c4366004612ba0565b610b60565b6103826104d7366004612b45565b610c5a565b3480156104e857600080fd5b506105296104f7366004612aca565b6101036020908152600092835260408084209091529082529020546001600160801b0380821691600160801b90041682565b604080516001600160801b0393841681529290911660208301520161021c565b34801561055557600080fd5b50610382610fa9565b34801561056a57600080fd5b50610382610579366004612ba0565b610fdb565b34801561058a57600080fd5b50610245610599366004612b7b565b600091825260c9602090815260408084206001600160a01b0393909316845291905290205460ff1690565b3480156105d057600080fd5b506105e46105df366004612c0d565b61105e565b6040805192835260208301919091520161021c565b34801561060557600080fd5b50610212600081565b34801561061a57600080fd5b50610212610629366004612b45565b6101046020526000908152604090205481565b34801561064857600080fd5b50610212610657366004612b45565b6101006020526000908152604090205481565b34801561067657600080fd5b50610382610685366004612ba0565b6115d7565b34801561069657600080fd5b506103826106a5366004612b7b565b6118b8565b3480156106b657600080fd5b5060005461032a906001600160a01b031681565b3480156106d657600080fd5b5060fb5461032a906001600160a01b031681565b3480156106f657600080fd5b50610382610705366004612c48565b6118dd565b34801561071657600080fd5b50610212610725366004612b45565b6101016020526000908152604090205481565b6001600160a01b038281166000908152610103602090815260408083209385168352929052908120546001600160801b03808216600160801b909204811691909103165b90505b92915050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061077f57507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff0000000000000000000000000000000000000000000000000000000083161461077f565b600082815260c9602052604090206001015461083781611adf565b6108418383611ae9565b505050565b6001600160a01b03811633146108c95760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b6108d38282611b8b565b5050565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177561090181611adf565b610909611c0e565b50565b6001600160a01b03808416600090815261010360209081526040808320938616835292905290812081908190819061094a9088906103bf9088611c60565b6000908152610102602052604090208054600182015460029092015490999198509650945050505050565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177561099f81611adf565b60ff8290556040518281527f2e56f6093fb947ef7b002dcdf68fcb314c466a1917eac6fa5b00879a7f5de63f9060200160405180910390a15050565b600080546040517fe16c7d980000000000000000000000000000000000000000000000000000000081527f7a8fe1bac8d7638862c53b62ffada56d0a56c381287c35f66503b5b86fa88b85600482015282916001600160a01b03169063e16c7d9890602401602060405180830381865afa158015610a5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a819190612ca4565b6040517f52c4889f0000000000000000000000000000000000000000000000000000000081526001600160a01b0385811660048301529192506000918316906352c4889f90602401602060405180830381865afa158015610ae6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b0a9190612cc1565b6001600160a01b038516600090815261010460205260409020549091508111610b34576000610b58565b6001600160a01b03841660009081526101046020526040902054610b589082612cf0565b949350505050565b60fc5460405163b3596f0760e01b81526001600160a01b038481166004830152600092169063b3596f0790602401602060405180830381865afa158015610bab573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bcf9190612cc1565b60fc60009054906101000a90046001600160a01b03166001600160a01b031663a539550b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610c22573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c469190612cc1565b610c509084612d03565b61077c9190612d1a565b610c62611ce4565b8073efefefefefefefefefefefefefefefefefefefef6001600160a01b03821614158015610d7a5750600054604051634df48c7360e11b81526001600160a01b03838116600483015290911690639be918e690602401602060405180830381865afa158015610cd5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cf99190612d3c565b1580610d7a57506000805460405163f8806a1360e01b81526001600160a01b0384811660048301529091169063f8806a1390602401602060405180830381865afa158015610d4b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d6f9190612ca4565b6001600160a01b0316145b15610d9857604051633bade18360e11b815260040160405180910390fd5b600260655403610dea5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016108c0565b60026065556001600160a01b0382166000908152610103602090815260408083203384529091528120610e1c90611d39565b6001600160a01b038416600090815261010160205260409020549091508110610e71576040517f321116dc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b604080516bffffffffffffffffffffffff19606086901b1660208083019190915260348083018590528351808403909101815260548301808552815191830191909120600081815261010280855286822060b4870190975286548452600187018054607488015260028801805460949098019788528484529190955295819055928390559190935560ff549151909291610f0a91612d5e565b431015610f43576040517f7d8488e000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610f5285338360200151611ddf565b805160208083015160408051938452918301526001600160a01b0387169133917fca13475b00c46ee0ce4a479bd18ed747ff89395e96e93779ba7f18cbe1735fb4910160405180910390a350506001606555505050565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775610fd381611adf565b610909611e18565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177561100581611adf565b6001600160a01b038316600081815260fe6020908152604091829020859055815192835282018490527fde4ed37901dc230db7df5ec2ec48bb07c4286fa1c66128cd200c6b6e9cd2bc83910160405180910390a1505050565b6000806002606554036110b35760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016108c0565b60026065558573efefefefefefefefefefefefefefefefefefefef6001600160a01b038216141580156111d05750600054604051634df48c7360e11b81526001600160a01b03838116600483015290911690639be918e690602401602060405180830381865afa15801561112b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061114f9190612d3c565b15806111d057506000805460405163f8806a1360e01b81526001600160a01b0384811660048301529091169063f8806a1390602401602060405180830381865afa1580156111a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111c59190612ca4565b6001600160a01b0316145b156111ee57604051633bade18360e11b815260040160405180910390fd5b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177561121881611adf565b60fc54604080517fa539550b00000000000000000000000000000000000000000000000000000000815290516000926001600160a01b03169163a539550b9160048083019260209291908290030181865afa15801561127b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061129f9190612cc1565b60fc5460405163b3596f0760e01b81526001600160a01b038c811660048301529293506000929091169063b3596f0790602401602060405180830381865afa1580156112ef573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113139190612cc1565b905086821015611352576040517f2f25f4ee000000000000000000000000000000000000000000000000000000008152600481018390526024016108c0565b8781101561138f576040517f4f216ee7000000000000000000000000000000000000000000000000000000008152600481018290526024016108c0565b60fd546040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b038c8116600483015260009216906370a0823190602401602060405180830381865afa1580156113f3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114179190612cc1565b905080600003611453576040517f5e85ae7300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6114608b8285858e611e55565b909750955086156114e95760fb546040517f9dc29fac000000000000000000000000000000000000000000000000000000008152306004820152602481018990526001600160a01b0390911690639dc29fac90604401600060405180830381600087803b1580156114d057600080fd5b505af11580156114e4573d6000803e3d6000fd5b505050505b60fd546040517f1e9a69500000000000000000000000000000000000000000000000000000000081526001600160a01b038d811660048301526024820189905290911690631e9a695090604401600060405180830381600087803b15801561155057600080fd5b505af1158015611564573d6000803e3d6000fd5b5050604080516001600160a01b038f168152602081018b905290810189905260608101869052608081018590527f72e38cd9e650a56d27bba7e1a9a8d6f77dc5cc382bb38a7e56f4f1e845be910d925060a001905060405180910390a15050505050600160658190555094509492505050565b6115df611ce4565b6002606554036116315760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016108c0565b60026065558173efefefefefefefefefefefefefefefefefefefef6001600160a01b0382161415801561174e5750600054604051634df48c7360e11b81526001600160a01b03838116600483015290911690639be918e690602401602060405180830381865afa1580156116a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116cd9190612d3c565b158061174e57506000805460405163f8806a1360e01b81526001600160a01b0384811660048301529091169063f8806a1390602401602060405180830381865afa15801561171f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117439190612ca4565b6001600160a01b0316145b1561176c57604051633bade18360e11b815260040160405180910390fd5b81158061179057506001600160a01b038316600090815260fe602052604090205482105b156117c7576040517fe70dea0f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60fb546117df906001600160a01b0316333085612042565b60006117eb8484610b60565b90506117f6846109db565b81111561182f576040517f9fd55ef600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b0384166000908152610104602052604081208054839290611858908490612d5e565b9091555061186990508484836120d0565b604080516001600160a01b03861681526020810185905233917ff79eabc24df3643a1dfc26dde4d79b5bde29ce49ca096544d28132e66ce6c6ff910160405180910390a2505060016065555050565b600082815260c960205260409020600101546118d381611adf565b6108418383611b8b565b600054600160a81b900460ff161580801561190557506000546001600160a01b90910460ff16105b806119265750303b1580156119265750600054600160a01b900460ff166001145b6119985760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a656400000000000000000000000000000000000060648201526084016108c0565b600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff16600160a01b17905580156119e0576000805460ff60a81b1916600160a81b1790555b6119e86121b2565b6119f061221f565b6119f8612298565b600080546001600160a01b038088167fffffffffffffffffffffffff000000000000000000000000000000000000000092831617835560fb805488831690841617905560fc805487831690841617905560fd80549186169190921617905561e10060ff55611a669033611ae9565b611a907fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177533611ae9565b8015611ad8576000805460ff60a81b19169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5050505050565b610909813361230c565b600082815260c9602090815260408083206001600160a01b038516845290915290205460ff166108d357600082815260c9602090815260408083206001600160a01b03851684529091529020805460ff19166001179055611b473390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b600082815260c9602090815260408083206001600160a01b038516845290915290205460ff16156108d357600082815260c9602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b611c1661238c565b6033805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6000611c8483546001600160801b03808216600160801b9092048116919091031690565b8210611cbc576040517f580821e700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5081546001600160801b03908116820116600090815260018301602052604090205492915050565b60335460ff1615611d375760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a207061757365640000000000000000000000000000000060448201526064016108c0565b565b80546000906001600160801b0380821691600160801b9004168103611d8a576040517f75e52f4f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160801b038181166000908152600185810160205260408220805492905585547fffffffffffffffffffffffffffffffff00000000000000000000000000000000169301909116919091179092555090565b73efefefefefefefefefefefefefefefefefefefef6001600160a01b03841603611e0d5761084182826123de565b6108418383836124a7565b611e20611ce4565b6033805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258611c433390565b6001600160a01b038516600090815261010060205260408120548190831115611e95576001600160a01b0387166000908152610100602052604090205492505b6001600160a01b038716600090815261010160205260409020548311611ee7576040517f0ac1d61d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b03871660009081526101016020526040902054831115612038576001600160a01b0387166000908152610101602090815260408083205481516bffffffffffffffffffffffff1960608d901b1681850152603480820192909252825180820390920182526054810180845282519285019290922080865261010290945282852060b482019093528254825260018301546074820152600283015460949091015291929091611f9d90898961260f565b905080891015611faf57505050612038565b60018201546001600160a01b038b166000908152610104602052604081208054909190611fdd908490612cf0565b9091555050600182018190558154611ff59086612d5e565b9450612001818a612cf0565b985061200d8185612d5e565b6001600160a01b038b16600090815261010160205260409020805460010190559350611ee792505050565b9550959350505050565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f23b872dd000000000000000000000000000000000000000000000000000000001790526120ca908590612651565b50505050565b6001600160a01b038316600081815261010060209081526040808320805482516bffffffffffffffffffffffff1960608b901b1681860152603480820192909252835180820390920182526054810180855282519286019290922060b48201855289835260748201898152436094909301928352818852610102875285882093518455516001840155905160029092019190915594845254610103835281842033855290925290912061218291612736565b6001600160a01b0384166000908152610100602052604081208054916121a783612d71565b919050555050505050565b600054600160a81b900460ff16611d375760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b60648201526084016108c0565b600054600160a81b900460ff1661228c5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b60648201526084016108c0565b6033805460ff19169055565b600054600160a81b900460ff166123055760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b60648201526084016108c0565b6001606555565b600082815260c9602090815260408083206001600160a01b038516845290915290205460ff166108d35761234a816001600160a01b031660146127c0565b6123558360206127c0565b604051602001612366929190612dae565b60408051601f198184030181529082905262461bcd60e51b82526108c091600401612e2f565b60335460ff16611d375760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f742070617573656400000000000000000000000060448201526064016108c0565b6000826001600160a01b03168260405160006040518083038185875af1925050503d806000811461242b576040519150601f19603f3d011682016040523d82523d6000602084013e612430565b606091505b50509050806108415760405162461bcd60e51b815260206004820152602260248201527f5472616e7366657248656c7065723a2053656e64696e6720455448206661696c60448201527f656400000000000000000000000000000000000000000000000000000000000060648201526084016108c0565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb0000000000000000000000000000000000000000000000000000000017905291516000928392908716916125319190612e62565b6000604051808303816000865af19150503d806000811461256e576040519150601f19603f3d011682016040523d82523d6000602084013e612573565b606091505b509150915081801561259d57508051158061259d57508080602001905181019061259d9190612d3c565b611ad85760405162461bcd60e51b815260206004820152602d60248201527f5472616e7366657248656c7065723a3a736166655472616e736665723a20747260448201527f616e73666572206661696c65640000000000000000000000000000000000000060648201526084016108c0565b600080828486600001516126239190612d03565b61262d9190612d1a565b9050808560200151106126405780612646565b84602001515b9150505b9392505050565b60006126a6826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166129a19092919063ffffffff16565b80519091501561084157808060200190518101906126c49190612d3c565b6108415760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f7420737563636565640000000000000000000000000000000000000000000060648201526084016108c0565b81546001600160801b03600160801b82048116918116600183019091160361278a576040517f8acb5f2700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160801b03808216600090815260018086016020526040909120939093558354919092018216600160801b029116179055565b606060006127cf836002612d03565b6127da906002612d5e565b67ffffffffffffffff8111156127f2576127f2612e7e565b6040519080825280601f01601f19166020018201604052801561281c576020820181803683370190505b5090507f30000000000000000000000000000000000000000000000000000000000000008160008151811061285357612853612e94565b60200101906001600160f81b031916908160001a9053507f78000000000000000000000000000000000000000000000000000000000000008160018151811061289e5761289e612e94565b60200101906001600160f81b031916908160001a90535060006128c2846002612d03565b6128cd906001612d5e565b90505b6001811115612952577f303132333435363738396162636465660000000000000000000000000000000085600f166010811061290e5761290e612e94565b1a60f81b82828151811061292457612924612e94565b60200101906001600160f81b031916908160001a90535060049490941c9361294b81612eaa565b90506128d0565b50831561077c5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016108c0565b6060610b588484600085856001600160a01b0385163b612a035760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016108c0565b600080866001600160a01b03168587604051612a1f9190612e62565b60006040518083038185875af1925050503d8060008114612a5c576040519150601f19603f3d011682016040523d82523d6000602084013e612a61565b606091505b5091509150612a71828286612a7c565b979650505050505050565b60608315612a8b57508161264a565b825115612a9b5782518084602001fd5b8160405162461bcd60e51b81526004016108c09190612e2f565b6001600160a01b038116811461090957600080fd5b60008060408385031215612add57600080fd5b8235612ae881612ab5565b91506020830135612af881612ab5565b809150509250929050565b600060208284031215612b1557600080fd5b81357fffffffff000000000000000000000000000000000000000000000000000000008116811461077c57600080fd5b600060208284031215612b5757600080fd5b813561077c81612ab5565b600060208284031215612b7457600080fd5b5035919050565b60008060408385031215612b8e57600080fd5b823591506020830135612af881612ab5565b60008060408385031215612bb357600080fd5b8235612bbe81612ab5565b946020939093013593505050565b600080600060608486031215612be157600080fd5b8335612bec81612ab5565b92506020840135612bfc81612ab5565b929592945050506040919091013590565b60008060008060808587031215612c2357600080fd5b8435612c2e81612ab5565b966020860135965060408601359560600135945092505050565b60008060008060808587031215612c5e57600080fd5b8435612c6981612ab5565b93506020850135612c7981612ab5565b92506040850135612c8981612ab5565b91506060850135612c9981612ab5565b939692955090935050565b600060208284031215612cb657600080fd5b815161077c81612ab5565b600060208284031215612cd357600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561077f5761077f612cda565b808202811582820484141761077f5761077f612cda565b600082612d3757634e487b7160e01b600052601260045260246000fd5b500490565b600060208284031215612d4e57600080fd5b8151801515811461077c57600080fd5b8082018082111561077f5761077f612cda565b600060018201612d8357612d83612cda565b5060010190565b60005b83811015612da5578181015183820152602001612d8d565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351612de6816017850160208801612d8a565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351612e23816028840160208801612d8a565b01602801949350505050565b6020815260008251806020840152612e4e816040850160208701612d8a565b601f01601f19169190910160400192915050565b60008251612e74818460208701612d8a565b9190910192915050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600081612eb957612eb9612cda565b50600019019056fea2646970667358221220d86a7e32aebf6b651b9deca2f431304766966099b7ba3b29e11757e8bb28654064736f6c63430008110033

Verified Source Code Full Match

Compiler: v0.8.17+commit.8df45f5f EVM: london Optimization: Yes (1000 runs)
AccessControlUpgradeable.sol 260 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "./IAccessControlUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../utils/StringsUpgradeable.sol";
import "../utils/introspection/ERC165Upgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {
    function __AccessControl_init() internal onlyInitializing {
    }

    function __AccessControl_init_unchained() internal onlyInitializing {
    }
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        StringsUpgradeable.toHexString(uint160(account), 20),
                        " is missing role ",
                        StringsUpgradeable.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * May emit a {RoleGranted} event.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}
IAccessControlUpgradeable.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControlUpgradeable {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}
Initializable.sol 138 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.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]
 * ```
 * 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. Equivalent to `reinitializer(1)`.
     */
    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.
     *
     * `initializer` is equivalent to `reinitializer(1)`, so 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.
     *
     * 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.
     */
    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.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized < type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }
}
PausableUpgradeable.sol 117 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    function __Pausable_init() internal onlyInitializing {
        __Pausable_init_unchained();
    }

    function __Pausable_init_unchained() internal onlyInitializing {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}
ReentrancyGuardUpgradeable.sol 75 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuardUpgradeable is Initializable {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}
IERC20Upgradeable.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20Upgradeable {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external returns (bool);
}
AddressUpgradeable.sol 195 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.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
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "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");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason 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 {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly
                /// @solidity memory-safe-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
ContextUpgradeable.sol 37 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}
ERC165Upgradeable.sol 42 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable {
    function __ERC165_init() internal onlyInitializing {
    }

    function __ERC165_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165Upgradeable).interfaceId;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}
IERC165Upgradeable.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165Upgradeable {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
StringsUpgradeable.sol 75 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library StringsUpgradeable {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }
}
draft-IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external returns (bool);
}
SafeERC20.sol 116 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}
Address.sol 222 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "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");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason 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 {
            // 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);
            }
        }
    }
}
AddressLib.sol 12 lines
// SPDX-License-Identifier: MIT

pragma solidity 0.8.17;

library AddressLib {
    address public constant PLATFORM_TOKEN_ADDRESS =
        0xeFEfeFEfeFeFEFEFEfefeFeFefEfEfEfeFEFEFEf;

    function isPlatformToken(address addr) internal pure returns (bool) {
        return addr == PLATFORM_TOKEN_ADDRESS;
    }
}
TransferHelper.sol 67 lines
// SPDX-License-Identifier: MIT

pragma solidity 0.8.17;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "./AddressLib.sol";

library TransferHelper {

    using AddressLib for address;

    function safeTransferToken(
        address token,
        address to,
        uint value
    ) internal {
        if (token.isPlatformToken()) {
            safeTransferETH(to, value);
        } else {
            safeTransfer(IERC20(token), to, value);
        }
    }

    function safeTransferETH(
        address to,
        uint value
    ) internal {
        (bool success, ) = address(to).call{value: value}("");
        require(success, "TransferHelper: Sending ETH failed");
    }

    function balanceOf(address token, address addr) internal view returns (uint) {
        if (token.isPlatformToken()) {
            return addr.balance;
        } else {
            return IERC20(token).balanceOf(addr);
        }
    }

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        // bytes4(keccak256(bytes('transfer(address,uint256)'))) -> 0xa9059cbb
        (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(0xa9059cbb, to, value));
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            'TransferHelper::safeTransfer: transfer failed'
        );
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        // bytes4(keccak256(bytes('transferFrom(address,address,uint256)'))) -> 0x23b872dd
        (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(0x23b872dd, from, to, value));
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            'TransferHelper::safeTransferFrom: transfer failed'
        );
    }
}
IelETH.sol 10 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";

interface IelETH is IERC20Upgradeable {
    function mint(address, uint256) external;

    function burn(address, uint256) external;
}
ILRTConfig.sol 45 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

interface ILRTConfig {
    function getContract(bytes32 _contractKey) external view returns (address);

    function isSupportedAsset(address _asset) external view returns (bool);

    function getSupportedAssets() external view returns (address[] memory);

    function getStrategy(address _asset) external view returns (address);

    function getAssetSwitch(
        address _asset,
        bytes32 _switchKey
    ) external view returns (bool);

    function getGlobalDepositLimitByAsset(
        address _asset
    ) external view returns (uint256);

    function getUserDepositLimitByAsset(
        address _user,
        address _asset
    ) external view returns (uint256);

    event ContractSet(
        bytes32 indexed _contractKey,
        address indexed _contractAddress
    );
    event SupportedAssetAdded(address indexed _asset);
    event SupportedAssetRemoved(address indexed _asset);
    event AssetStrategySet(address indexed _asset, address indexed _strategy);
    event AssetSwitchSet(
        address indexed _asset,
        bytes32 indexed _switchKey,
        bool _value
    );
    event GlobalDepositLimitByAssetSet(address indexed _asset, uint256 _limit);
    event UserDepositLimitByAssetSet(
        address indexed _user,
        address indexed _asset,
        uint256 _limit
    );
}
ILRTDepositPool.sol 47 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

interface ILRTDepositPool {
    function getELETHAmountToMint(
        address _asset,
        uint256 _amount
    ) external view returns (uint256);

    function depositAsset(
        address _asset,
        uint256 _amount,
        uint256 _minELETHAmountToReceive,
        string calldata _referralId
    ) external payable returns (uint256);

    function getTotalAssetDeposits(
        address _asset
    ) external view returns (uint256);

    function getAssetDistributionData(
        address _asset
    )
        external
        view
        returns (
            uint256 assetLyingInDepositPool,
            uint256 assetLyingInProxy,
            uint256 assetStakedInEigenLayer,
            uint256 assetUnstakingFromEigenLayer,
            uint256 assetLyingUnstakingVault
        );

    event AssetDeposited(
        address indexed _user,
        address indexed _asset,
        uint256 _amount,
        uint256 _elETHAmount,
        string _referralId
    );
    event AssetTransferedToProxy(
        address indexed _asset,
        uint256 _amount,
        address indexed _proxy
    );
    event SwellAirdropClaimed(address indexed _to, uint256 _amount);
}
ILRTOracle.sol 16 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

interface ILRTOracle {
    function getAssetPrice(address _asset) external view returns (uint256);

    function elETHPrice() external view returns (uint256);

    event ElETHSet(address indexed elETH);
    event DepositPoolSet(address indexed depositPool);
    event LRTConfigSet(address indexed lrtConfig);
    event AssetPriceOracleUpdate(
        address indexed asset,
        address indexed priceOracle
    );
}
ILRTUnstakingVault.sol 24 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

interface ILRTUnstakingVault {
    error CallerNotLRTProxy();
    error CallerNotLRTWithdrawalManager();

    event SharesUnstakingAdded(address asset, uint256 amount);
    event SharesUnstakingReduced(address asset, uint256 amount);
    event Redeemed(address asset, uint256 amount);
    event EthReceived(address sender, uint256 amount);

    function sharesUnstaking(address asset) external view returns (uint256);

    function getAssetsUnstaking(address asset) external view returns (uint256);

    function balanceOf(address asset) external view returns (uint256);

    function addSharesUnstaking(address asset, uint256 amount) external;

    function reduceSharesUnstaking(address asset, uint256 amount) external;

    function redeem(address asset, uint256 amount) external;
}
ILRTWithdrawalManager.sol 89 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

interface ILRTWithdrawalManager {
    //errors
    error InvalidAmountToWithdraw();
    error ExceedAmountToWithdraw();
    error WithdrawalLocked();
    error WithdrawalDelayNotPassed();
    error NoPendingWithdrawals();
    error AmountMustBeGreaterThanZero();
    error NotSupportedAsset();

    error ElETHPriceMustBeGreaterMinimum(uint256 elETHPrice);
    error AssetPriceMustBeGreaterMinimum(uint256 assetPrice);

    struct WithdrawalRequest {
        uint256 elETHUnstaked;
        uint256 expectedAssetAmount;
        uint256 withdrawalStartBlock;
    }

    //events
    event AssetWithdrawalQueued(
        address indexed withdrawer,
        address asset,
        uint256 elETHUnstaked
    );
    event AssetWithdrawalFinalized(
        address indexed withdrawer,
        address indexed asset,
        uint256 amountBurned,
        uint256 amountReceived
    );
    event EtherReceived(
        address indexed depositor,
        uint256 ethAmount,
        uint256 sharesAmount
    );

    event AssetUnlocked(
        address asset,
        uint256 elETHAmount,
        uint256 assetAmount,
        uint256 rsEThPrice,
        uint256 assetPrice
    );

    event MinAmountToWithdrawUpdated(
        address asset,
        uint256 minAmountToWithdraw
    );
    event WithdrawalDelayBlocksUpdated(uint256 withdrawalDelayBlocks);

    // methods

    function getExpectedAssetAmount(
        address asset,
        uint256 amount
    ) external view returns (uint256);

    function getAvailableAssetAmount(
        address asset
    ) external view returns (uint256 assetAmount);

    function getUserWithdrawalRequest(
        address asset,
        address user,
        uint256 index
    )
        external
        view
        returns (
            uint256 elETHAmount,
            uint256 expectedAssetAmount,
            uint256 withdrawalStartBlock
        );

    function initiateWithdrawal(address asset, uint256 withdrawAmount) external;

    function completeWithdrawal(address asset) external payable;

    function unlockQueue(
        address asset,
        uint256 index,
        uint256 minimumAssetPrice,
        uint256 minimumElEthPrice
    ) external returns (uint256 elETHBurned, uint256 assetAmountUnlocked);
}
LRTWithdrawalManager.sol 461 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import "@shared/lib-contracts-v0.8/contracts/Dependencies/TransferHelper.sol";

import "./Interfaces/IelETH.sol";
import "./Interfaces/ILRTOracle.sol";
import "./Interfaces/ILRTWithdrawalManager.sol";
import "./Interfaces/ILRTDepositPool.sol";
import "./Interfaces/ILRTUnstakingVault.sol";
import "./Utils/DoubleEndedQueue.sol";
import "./Utils/LRTConstants.sol";
import "./Utils/LRTChecker.sol";

contract LRTWithdrawalManager is
    ILRTWithdrawalManager,
    LRTChecker,
    PausableUpgradeable,
    ReentrancyGuardUpgradeable,
    AccessControlUpgradeable
{
    using DoubleEndedQueue for DoubleEndedQueue.Uint256Deque;
    using SafeERC20 for IERC20;

    address public elETH;
    ILRTOracle public lrtOracle;
    address public lrtUnstakingVault;

    mapping(address => uint256) public minAmountToWithdraw;
    uint256 public withdrawalDelayBlocks;

    // Next available nonce for withdrawal requests per asset, indicating total requests made.
    mapping(address => uint256) public nextUnusedNonce;

    // Next nonce for which a withdrawal request remains locked.
    mapping(address => uint256) public nextLockedNonce;

    // Mapping from a unique request identifier to its corresponding withdrawal request
    mapping(bytes32 => WithdrawalRequest) public withdrawalRequests;

    // Maps each asset to user addresses, pointing to an ordert list of their withdrawal request nonces.
    // Utilizes a double-ended queue for efficient management and removal of initial requests.
    mapping(address => mapping(address => DoubleEndedQueue.Uint256Deque))
        public userAssociatedNonces;

    // Asset amount commited to be withdrawn by users.
    mapping(address => uint256) public assetsCommitted;

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    /// @notice Initializes the contract
    /// @param _lrtConfig LRT config address
    function initialize(
        address _lrtConfig,
        address _elETH,
        address _lrtOracle,
        address _lrtUnstakingVault
    ) external initializer {
        __AccessControl_init();
        __Pausable_init_unchained();
        __ReentrancyGuard_init_unchained();

        lrtConfig = ILRTConfig(_lrtConfig);
        elETH = _elETH;
        lrtOracle = ILRTOracle(_lrtOracle);
        lrtUnstakingVault = _lrtUnstakingVault;

        withdrawalDelayBlocks = 8 days / 12 seconds;

        _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _grantRole(LRTConstants.ADMIN_ROLE, msg.sender);
    }

    modifier onlySupported(address asset) {
        if (
            !AddressLib.isPlatformToken(asset) &&
            (!lrtConfig.isSupportedAsset(asset) ||
                lrtConfig.getStrategy(asset) == address(0))
        ) {
            revert NotSupportedAsset();
        }
        _;
    }

    /*//////////////////////////////////////////////////////////////
                                VIEW FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    /// @notice Get request id
    /// @param asset Asset address
    /// @param requestIndex The requests index to generate id for
    function getRequestId(
        address asset,
        uint256 requestIndex
    ) public pure returns (bytes32) {
        return keccak256(abi.encodePacked(asset, requestIndex));
    }

    /// @notice Get asset amount to receive when trading in elETH
    /// @param asset Asset address of LST to receive
    /// @param amount elETH amount to convert
    /// @return underlyingToReceive Amount of underlying to receive
    function getExpectedAssetAmount(
        address asset,
        uint256 amount
    ) public view override returns (uint256 underlyingToReceive) {
        // calculate underlying asset amount to receive based on elETH amount and asset exchange rate
        underlyingToReceive =
            (amount * lrtOracle.elETHPrice()) /
            lrtOracle.getAssetPrice(asset);
    }

    /// @notice Calculates the amount of asset available for withdrawal.
    /// @param asset The asset address.
    /// @return availableAssetAmount The asset amount avaialble for withdrawal.
    function getAvailableAssetAmount(
        address asset
    ) public view override returns (uint256 availableAssetAmount) {
        ILRTDepositPool lrtDepositPool = ILRTDepositPool(
            lrtConfig.getContract(LRTConstants.LRT_DEPOSIT_POOL)
        );
        uint256 totalAssets = lrtDepositPool.getTotalAssetDeposits(asset);
        availableAssetAmount = totalAssets > assetsCommitted[asset]
            ? totalAssets - assetsCommitted[asset]
            : 0;
    }

    /// @notice View user withdrawal request
    /// @param asset Asset address
    /// @param user User address
    /// @param userIndex Index in list of users withdrawal request
    function getUserWithdrawalRequest(
        address asset,
        address user,
        uint256 userIndex
    )
        public
        view
        override
        returns (
            uint256 elETHAmount,
            uint256 expectedAssetAmount,
            uint256 withdrawalStartBlock
        )
    {
        bytes32 requestId = getRequestId(
            asset,
            userAssociatedNonces[asset][user].at(userIndex)
        );
        elETHAmount = withdrawalRequests[requestId].elETHUnstaked;
        expectedAssetAmount = withdrawalRequests[requestId].expectedAssetAmount;
        withdrawalStartBlock = withdrawalRequests[requestId]
            .withdrawalStartBlock;
    }

    function getUserWithdrawlLength(
        address asset,
        address user
    ) external view returns (uint256) {
        return userAssociatedNonces[asset][user].length();
    }

    /*//////////////////////////////////////////////////////////////
                        User Withdrawal functions
    //////////////////////////////////////////////////////////////*/

    /// @notice Initiates a withdrawal request for converting elETH to a specified LST.
    /// @param asset The LST address the user wants to receive.
    /// @param elETHUnstaked The amount of elETH the user wishes to unstake.
    /// @dev This function is only callable by the user and is used to initiate a withdrawal request for a specific
    /// asset. Will be finalised by calling `completeWithdrawal` after the manager unlocked the request and the delay
    /// has past. There is an edge case were the user withdraws last underlying asset and that asset gets slashed.
    function initiateWithdrawal(
        address asset,
        uint256 elETHUnstaked
    ) external override whenNotPaused nonReentrant onlySupported(asset) {
        if (elETHUnstaked == 0 || elETHUnstaked < minAmountToWithdraw[asset]) {
            revert InvalidAmountToWithdraw();
        }

        IERC20(elETH).safeTransferFrom(
            msg.sender,
            address(this),
            elETHUnstaked
        );

        uint256 expectedAssetAmount = getExpectedAssetAmount(
            asset,
            elETHUnstaked
        );

        // Ensure the withdrawal does not exceed the available shares.
        if (expectedAssetAmount > getAvailableAssetAmount(asset)) {
            revert ExceedAmountToWithdraw();
        }

        // preventing over-withdrawal.
        assetsCommitted[asset] += expectedAssetAmount;

        _addUserWithdrawalRequest(asset, elETHUnstaked, expectedAssetAmount);

        emit AssetWithdrawalQueued(msg.sender, asset, elETHUnstaked);
    }

    /// @notice Completes a user's withdrawal process by transferring the LST amount corresponding to the elETH
    /// unstaked.
    /// @param asset The asset address the user wishes to withdraw.
    function completeWithdrawal(
        address asset
    ) external payable whenNotPaused onlySupported(asset) nonReentrant {
        // Retrieve and remove the oldest withdrawal request for the user.
        uint256 usersFirstWithdrawalRequestNonce = userAssociatedNonces[asset][
            msg.sender
        ].popFront();
        // Ensure the request is already unlocked.
        if (usersFirstWithdrawalRequestNonce >= nextLockedNonce[asset]) {
            revert WithdrawalLocked();
        }

        bytes32 requestId = getRequestId(
            asset,
            usersFirstWithdrawalRequestNonce
        );
        WithdrawalRequest memory request = withdrawalRequests[requestId];

        delete withdrawalRequests[requestId];

        // Check that the withdrawal delay has passed since the request's initiation.
        if (
            block.number < request.withdrawalStartBlock + withdrawalDelayBlocks
        ) {
            revert WithdrawalDelayNotPassed();
        }

        TransferHelper.safeTransferToken(
            asset,
            msg.sender,
            request.expectedAssetAmount
        );

        emit AssetWithdrawalFinalized(
            msg.sender,
            asset,
            request.elETHUnstaked,
            request.expectedAssetAmount
        );
    }

    /*//////////////////////////////////////////////////////////////
                        MANAGER UNSTAKING FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    /// @notice Unlocks assets in the queue up to a specified limit.
    /// @param asset The address of the asset to unlock.
    /// @param firstExcludedIndex First withdrawal requests index that will not be considered for unlocking.
    /// @param minimumAssetPrice The minimum acceptable price for the asset.
    /// @param minimumElEthPrice The minimum acceptable price for elETH.
    function unlockQueue(
        address asset,
        uint256 firstExcludedIndex,
        uint256 minimumAssetPrice,
        uint256 minimumElEthPrice
    )
        external
        nonReentrant
        onlySupported(asset)
        onlyRole(LRTConstants.ADMIN_ROLE)
        returns (uint256 elETHBurned, uint256 assetAmountUnlocked)
    {
        uint256 elETHPrice = lrtOracle.elETHPrice();
        uint256 assetPrice = lrtOracle.getAssetPrice(asset);

        // Ensure the current prices meet or exceed the minimum required prices.
        if (elETHPrice < minimumElEthPrice)
            revert ElETHPriceMustBeGreaterMinimum(elETHPrice);
        if (assetPrice < minimumAssetPrice)
            revert AssetPriceMustBeGreaterMinimum(assetPrice);

        uint256 totalAvailableAssets = ILRTUnstakingVault(lrtUnstakingVault)
            .balanceOf(asset);

        if (totalAvailableAssets == 0) {
            revert AmountMustBeGreaterThanZero();
        }

        // Updates and unlocks withdrawal requests up to a specified upper limit or until allocated assets are fully
        // utilized.
        (elETHBurned, assetAmountUnlocked) = _unlockWithdrawalRequests(
            asset,
            totalAvailableAssets,
            elETHPrice,
            assetPrice,
            firstExcludedIndex
        );

        if (elETHBurned != 0) {
            IelETH(elETH).burn(address(this), elETHBurned);
        }
        // Take the amount to distribute from vault
        ILRTUnstakingVault(lrtUnstakingVault).redeem(
            asset,
            assetAmountUnlocked
        );

        emit AssetUnlocked(
            asset,
            elETHBurned,
            assetAmountUnlocked,
            elETHPrice,
            assetPrice
        );
    }

    /*//////////////////////////////////////////////////////////////
                        MANAGER FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    /// @notice update min amount to withdraw
    /// @dev only callable by LRT admin
    /// @param asset Asset address
    /// @param minAmountToWithdraw_ Minimum amount to withdraw
    function setMinAmountToWithdraw(
        address asset,
        uint256 minAmountToWithdraw_
    ) external onlyRole(LRTConstants.ADMIN_ROLE) {
        minAmountToWithdraw[asset] = minAmountToWithdraw_;
        emit MinAmountToWithdrawUpdated(asset, minAmountToWithdraw_);
    }

    /// @notice update withdrawal delay
    /// @dev only callable by LRT admin
    /// @param withdrawalDelayBlocks_ The amount of blocks to wait till to complete a withdraw
    function setWithdrawalDelayBlocks(
        uint256 withdrawalDelayBlocks_
    ) external onlyRole(LRTConstants.ADMIN_ROLE) {
        withdrawalDelayBlocks = withdrawalDelayBlocks_;
        emit WithdrawalDelayBlocksUpdated(withdrawalDelayBlocks);
    }

    /// @dev Triggers stopped state. Contract must not be paused.
    function pause() external onlyRole(LRTConstants.ADMIN_ROLE) {
        _pause();
    }

    /// @dev Returns to normal state. Contract must be paused
    function unpause() external onlyRole(LRTConstants.ADMIN_ROLE) {
        _unpause();
    }

    /*//////////////////////////////////////////////////////////////
                            INTERNAL FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    /// @notice Registers a new request for withdrawing an asset in exchange for elETH.
    /// @param asset The address of the asset being withdrawn.
    /// @param elETHUnstaked The amount of elETH being exchanged.
    /// @param expectedAssetAmount The expected amount of the asset to be received upon withdrawal completion.
    function _addUserWithdrawalRequest(
        address asset,
        uint256 elETHUnstaked,
        uint256 expectedAssetAmount
    ) internal {
        // Generate a unique identifier for the new withdrawal request.
        bytes32 requestId = getRequestId(asset, nextUnusedNonce[asset]);

        // Create and store the new withdrawal request.
        withdrawalRequests[requestId] = WithdrawalRequest({
            elETHUnstaked: elETHUnstaked,
            expectedAssetAmount: expectedAssetAmount,
            withdrawalStartBlock: block.number
        });

        // Map the user to the newly created request index and increment the nonce for future requests.
        userAssociatedNonces[asset][msg.sender].pushBack(
            nextUnusedNonce[asset]
        );
        nextUnusedNonce[asset]++;
    }

    /// @dev Unlocks user withdrawal requests based on current asset availability and prices.
    /// Iterates through pending requests and unlocks them until the provided asset amount is fully allocated.
    /// @param asset The asset's address for which withdrawals are being processed.
    /// @param elETHPrice Current elETH to ETH exchange rate.
    /// @param assetPrice Current asset to ETH exchange rate.
    /// @param firstExcludedIndex First withdrawal requests index that will not be considered for unlocking.
    /// @return elETHAmountToBurn The total amount of elETH unlocked for withdrawals.
    /// @return assetAmountToUnlock The total asset amount allocated to unlocked withdrawals.
    function _unlockWithdrawalRequests(
        address asset,
        uint256 availableAssetAmount,
        uint256 elETHPrice,
        uint256 assetPrice,
        uint256 firstExcludedIndex
    )
        internal
        returns (uint256 elETHAmountToBurn, uint256 assetAmountToUnlock)
    {
        // Check that upper limit is in the range of existing withdrawal requests. If it is greater set it to the first
        // nonce with no withdrawal request.
        if (firstExcludedIndex > nextUnusedNonce[asset]) {
            firstExcludedIndex = nextUnusedNonce[asset];
        }

        // Revert when trying to unlock a request that has already been unlocked
        if (nextLockedNonce[asset] >= firstExcludedIndex)
            revert NoPendingWithdrawals();

        while (nextLockedNonce[asset] < firstExcludedIndex) {
            bytes32 requestId = getRequestId(asset, nextLockedNonce[asset]);
            WithdrawalRequest storage request = withdrawalRequests[requestId];

            // Calculate the amount user will recieve
            uint256 payoutAmount = _calculatePayoutAmount(
                request,
                elETHPrice,
                assetPrice
            );

            if (availableAssetAmount < payoutAmount) break; // Exit if not enough assets to cover this request

            assetsCommitted[asset] -= request.expectedAssetAmount;
            // Set the amount the user will recieve
            request.expectedAssetAmount = payoutAmount;
            elETHAmountToBurn += request.elETHUnstaked;
            availableAssetAmount -= payoutAmount;
            assetAmountToUnlock += payoutAmount;
            unchecked {
                nextLockedNonce[asset]++;
            }
        }
    }

    /// @notice Determines the final amount to be disbursed to the user, based on the lesser of the initially
    /// expected asset amount and the currently calculated return.
    /// @param request The specific withdrawal request being processed.
    /// @param elETHPrice The latest exchange rate of elETH to ETH.
    /// @param assetPrice The latest exchange rate of the asset to ETH.
    /// @return The final amount the user is going to receive.
    function _calculatePayoutAmount(
        WithdrawalRequest memory request,
        uint256 elETHPrice,
        uint256 assetPrice
    ) private pure returns (uint256) {
        uint256 currentReturn = (request.elETHUnstaked * elETHPrice) /
            assetPrice;
        return
            (request.expectedAssetAmount < currentReturn)
                ? request.expectedAssetAmount
                : currentReturn;
    }

    receive() external payable {}
}
DoubleEndedQueue.sol 181 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

/**
 * @dev A sequence of items with the ability to efficiently push and pop items (i.e. insert and remove) on both ends of
 * the sequence (called front and back). Among other access patterns, it can be used to implement efficient LIFO and
 * FIFO queues. Storage use is optimized, and all operations are O(1) constant time. This includes {clear}, given that
 * the existing queue contents are left in storage.
 *
 * The struct is called `Uint256Deque`. Other types can be cast to and from `uint128`. This data structure can only be
 * used in storage, and not in memory.
 * ```solidity
 * DoubleEndedQueue.Uint256Deque queue;
 * ```
 */
library DoubleEndedQueue {
    /**
     * @dev An operation (e.g. {front}) couldn't be completed due to the queue being empty.
     */
    error QueueEmpty();

    /**
     * @dev A push operation couldn't be completed due to the queue being full.
     */
    error QueueFull();

    /**
     * @dev An operation (e.g. {at}) couldn't be completed due to an index being out of bounds.
     */
    error QueueOutOfBounds();

    /**
     * @dev Indices are 128 bits so begin and end are packed in a single storage slot for efficient access.
     *
     * Struct members have an underscore prefix indicating that they are "private" and should not be read or written to
     * directly. Use the functions provided below instead. Modifying the struct manually may violate assumptions and
     * lead to unexpected behavior.
     *
     * The first item is at data[begin] and the last item is at data[end - 1]. This range can wrap around.
     */
    struct Uint256Deque {
        uint128 _begin;
        uint128 _end;
        mapping(uint128 => uint256) _data;
    }

    /**
     * @dev Inserts an item at the end of the queue.
     *
     * Reverts with {QueueFull} if the queue is full.
     */
    function pushBack(Uint256Deque storage deque, uint256 value) internal {
        unchecked {
            uint128 backIndex = deque._end;
            if (backIndex + 1 == deque._begin) revert QueueFull();
            deque._data[backIndex] = value;
            deque._end = backIndex + 1;
        }
    }

    /**
     * @dev Removes the item at the end of the queue and returns it.
     *
     * Reverts with {QueueEmpty} if the queue is empty.
     */
    function popBack(
        Uint256Deque storage deque
    ) internal returns (uint256 value) {
        unchecked {
            uint128 backIndex = deque._end;
            if (backIndex == deque._begin) revert QueueEmpty();
            --backIndex;
            value = deque._data[backIndex];
            delete deque._data[backIndex];
            deque._end = backIndex;
        }
    }

    /**
     * @dev Inserts an item at the beginning of the queue.
     *
     * Reverts with {QueueFull} if the queue is full.
     */
    function pushFront(Uint256Deque storage deque, uint256 value) internal {
        unchecked {
            uint128 frontIndex = deque._begin - 1;
            if (frontIndex == deque._end) revert QueueFull();
            deque._data[frontIndex] = value;
            deque._begin = frontIndex;
        }
    }

    /**
     * @dev Removes the item at the beginning of the queue and returns it.
     *
     * Reverts with `QueueEmpty` if the queue is empty.
     */
    function popFront(
        Uint256Deque storage deque
    ) internal returns (uint256 value) {
        unchecked {
            uint128 frontIndex = deque._begin;
            if (frontIndex == deque._end) revert QueueEmpty();
            value = deque._data[frontIndex];
            delete deque._data[frontIndex];
            deque._begin = frontIndex + 1;
        }
    }

    /**
     * @dev Returns the item at the beginning of the queue.
     *
     * Reverts with `QueueEmpty` if the queue is empty.
     */
    function front(
        Uint256Deque storage deque
    ) internal view returns (uint256 value) {
        if (empty(deque)) revert QueueEmpty();
        return deque._data[deque._begin];
    }

    /**
     * @dev Returns the item at the end of the queue.
     *
     * Reverts with `QueueEmpty` if the queue is empty.
     */
    function back(
        Uint256Deque storage deque
    ) internal view returns (uint256 value) {
        if (empty(deque)) revert QueueEmpty();
        unchecked {
            return deque._data[deque._end - 1];
        }
    }

    /**
     * @dev Return the item at a position in the queue given by `index`, with the first item at 0 and last item at
     * `length(deque) - 1`.
     *
     * Reverts with `QueueOutOfBounds` if the index is out of bounds.
     */
    function at(
        Uint256Deque storage deque,
        uint256 index
    ) internal view returns (uint256 value) {
        if (index >= length(deque)) revert QueueOutOfBounds();
        // By construction, length is a uint128, so the check above ensures that index can be safely downcast to uint128
        unchecked {
            return deque._data[deque._begin + uint128(index)];
        }
    }

    /**
     * @dev Resets the queue back to being empty.
     *
     * NOTE: The current items are left behind in storage. This does not affect the functioning of the queue, but misses
     * out on potential gas refunds.
     */
    function clear(Uint256Deque storage deque) internal {
        deque._begin = 0;
        deque._end = 0;
    }

    /**
     * @dev Returns the number of items in the queue.
     */
    function length(
        Uint256Deque storage deque
    ) internal view returns (uint256) {
        unchecked {
            return uint256(deque._end - deque._begin);
        }
    }

    /**
     * @dev Returns true if the queue is empty.
     */
    function empty(Uint256Deque storage deque) internal view returns (bool) {
        return deque._end == deque._begin;
    }
}
LRTChecker.sol 13 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import "../Interfaces/ILRTConfig.sol";

abstract contract LRTChecker {
    ILRTConfig public lrtConfig;

    modifier onlySupportedAsset(address _asset) {
        require(lrtConfig.isSupportedAsset(_asset), "asset not supported!");

        _;
    }
}
LRTConstants.sol 29 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

library LRTConstants {
    // Roles
    bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
    bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");

    // contracts
    bytes32 public constant LRT_DEPOSIT_POOL = keccak256("LRT_DEPOSIT_POOL");
    bytes32 public constant LRT_PROXY = keccak256("LRT_PROXY");
    bytes32 public constant LRT_WITHDRAW_MANAGER =
        keccak256("LRT_WITHDRAW_MANAGER");
    bytes32 public constant LRT_UNSTAKING_VAULT =
        keccak256("LRT_UNSTAKING_VAULT");
    bytes32 public constant EIGEN_POD_MANAGER = keccak256("EIGEN_POD_MANAGER");
    bytes32 public constant EIGEN_STRATEGY_MANAGER =
        keccak256("EIGEN_STRATEGY_MANAGER");
    bytes32 public constant EIGEN_DELEGATION_MANAGER =
        keccak256("EIGEN_DELEGATION_MANAGER");
    bytes32 public constant BEACON_CHAIN_ETH_STRATEGY =
        keccak256("BEACON_CHAIN_ETH_STRATEGY");
    bytes32 public constant SWELL_MERKLE_DROP = keccak256("SWELL_MERKLE_DROP");

    // swtiches
    bytes32 public constant SWITCH_DEPOSIT_ASSET_TO_STRATEGY =
        keccak256("SWITCH_DEPOSIT_ASSET_TO_STRATEGY");
}

Read Contract

DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
assetsCommitted 0xb6cf3fef → uint256
elETH 0xf5abc562 → address
getAvailableAssetAmount 0x5f57f968 → uint256
getExpectedAssetAmount 0x6359b872 → uint256
getRequestId 0x3ddd2511 → bytes32
getRoleAdmin 0x248a9ca3 → bytes32
getUserWithdrawalRequest 0x47204df1 → uint256, uint256, uint256
getUserWithdrawlLength 0x00918407 → uint256
hasRole 0x91d14854 → bool
lrtConfig 0xf1650a46 → address
lrtOracle 0x29db05e1 → address
lrtUnstakingVault 0x2cb2f198 → address
minAmountToWithdraw 0x0c955fb4 → uint256
nextLockedNonce 0xfac48eea → uint256
nextUnusedNonce 0xc1af971a → uint256
paused 0x5c975abb → bool
supportsInterface 0x01ffc9a7 → bool
userAssociatedNonces 0x7cef12ae → uint128, uint128
withdrawalDelayBlocks 0x50f73e7c → uint256
withdrawalRequests 0x124b82a5 → uint256, uint256, uint256

Write Contract 11 functions

These functions modify contract state and require a wallet transaction to execute.

completeWithdrawal 0x6dbaf9ee
address asset
grantRole 0x2f2ff15d
bytes32 role
address account
initialize 0xf8c8765e
address _lrtConfig
address _elETH
address _lrtOracle
address _lrtUnstakingVault
initiateWithdrawal 0xc8393ba9
address asset
uint256 elETHUnstaked
pause 0x8456cb59
No parameters
renounceRole 0x36568abe
bytes32 role
address account
revokeRole 0xd547741f
bytes32 role
address account
setMinAmountToWithdraw 0x86f26f77
address asset
uint256 minAmountToWithdraw_
setWithdrawalDelayBlocks 0x4d50f9a4
uint256 withdrawalDelayBlocks_
unlockQueue 0x9cd89e99
address asset
uint256 firstExcludedIndex
uint256 minimumAssetPrice
uint256 minimumElEthPrice
returns: uint256, uint256
unpause 0x3f4ba83a
No parameters

Recent Transactions

No transactions found for this address