Address Contract Verified
Address
0xFF8432EA93Ce82eF9a8a7FBD2Ed160Ad9EDA732E
Balance
0 ETH
Nonce
1
Code Size
14024 bytes
Creator
0x38896b4a...797D at tx 0xde3194a6...7dffe8
Indexed Transactions
0
Contract Bytecode
14024 bytes
0x60806040526004361015610022575b3615610018575f80fd5b6100206123d3565b005b5f3560e01c806301ffc9a714610211578063046f7da21461020c57806317fcb39b146102075780632575e80b1461020257806337bfc1ef146101fd5780633fa4f245146101f857806343183834146101f3578063452a9320146101ee57806346904840146101e95780634bb278f3146101e45780634e71d92d146101df5780634e8bc852146101da57806359e97475146101d55780635c1c6dcd146101d05780635c975abb146101cb57806369eb50ef146101c6578063715018a6146101c1578063779b3c00146101bc57806379ba5097146101b75780638456cb59146101b25780638da5cb5b146101ad578063979d7e86146101a8578063b3f05b97146101a3578063cd7033c41461019e578063ddca3f4314610199578063e30c397814610194578063e79bf13b1461018f578063ecdbb2b31461018a578063f2fde38b14610185578063faaebd21146101805763fb63daa10361000e57611be8565b611bac565b611b00565b6118ae565b611817565b61179f565b611765565b61173f565b61171a565b6116d7565b6116b2565b6115e1565b61150f565b6114f2565b6114b0565b61135c565b611326565b611198565b610ecb565b610924565b610767565b6104f9565b6104d3565b6104ad565b610490565b6103f1565b6103d4565b6103b7565b610374565b61028f565b34610281576020366003190112610281576004356001600160e01b0319811680910361028157807fec75542d0000000000000000000000000000000000000000000000000000000060209214908115610270575b506040519015158152f35b6301ffc9a760e01b9150145f610265565b5f80fd5b5f91031261028157565b34610281575f366003190112610281576102a7613359565b6001600160a01b0360035416156103635760ff60055460a01c166103525742600a5560015460ff8160a01c161561030e5760ff60a01b19166001557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a1005b606460405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152fd5b600460405163b3a5458960e01b8152fd5b600460405163097e401760e11b8152fd5b34610281575f3660031901126102815760206040516001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2168152f35b34610281575f366003190112610281576020600754604051908152f35b34610281575f366003190112610281576020600954604051908152f35b34610281575f8060031936011261048d576040519063edf94acd60e01b825280826004816001600160a01b037f00000000000000000000000010d9c320aa9ba32bffedc08ba7b0446e8e0d9ad8165afa8015610488576020928261045c9392610465575b50506127ad565b50604051908152f35b61048192503d8091833e6104798183611dd4565b81019061232b565b5f80610455565b611e54565b80fd5b34610281575f366003190112610281576020600654604051908152f35b34610281575f3660031901126102815760206001600160a01b0360045416604051908152f35b34610281575f3660031901126102815760206001600160a01b0360055416604051908152f35b34610281575f8060031936011261048d57610512613403565b61051a613359565b6001600160a01b038060035416156103635760ff60055460a01c1661035257819061054361247b565b6105646105586003546001600160a01b031690565b6001600160a01b031690565b803b156107635782906004604051809581937fbfd31dc40000000000000000000000000000000000000000000000000000000083525af1908115610488576004928492610750575b506105c5600160a01b60ff60a01b196005541617600555565b604051928380926371a9730560e01b82527f00000000000000000000000010d9c320aa9ba32bffedc08ba7b0446e8e0d9ad8165afa80156104885761061191839161072e575b50612e7f565b8051825b8181106106d4575050816106346105586003546001600160a01b031690565b803b156106d05781906004604051809481937f683acef00000000000000000000000000000000000000000000000000000000083525af18015610488576106b7575b507f11ca3c8bf5b555e9fe7f80a815f6c9a090ccc14a0d37f7016e89b8e4e4b8fd96604051806106a73394826117c5565b0390a26106b46001600255565b80f35b806106c46106ca92611d67565b80610285565b5f610676565b5080fd5b6001906020806106e483876121a0565b5101516106f3575b5001610615565b6107289061071261070484886121a0565b51516001600160a01b031690565b9061071d84886121a0565b510151903390613456565b5f6106ec565b61074a91503d8085833e6107428183611dd4565b810190611f20565b5f61060b565b806106c461075d92611d67565b5f6105ac565b5050fd5b34610281575f8060031936011261048d57610780613403565b61078861247b565b335f9081526008602052604090205480156108f3576040516370a0823160e01b81523060048201527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc291906020816024816001600160a01b0387165afa908115610488576107ff91839186916108c5575b50613347565b9182156108905761086e83610849817f9cdcf2f7714cca3508c7f0110b04a90a80a3a8dd0e35de99689db74d28c5383e9561084461083f83600954612319565b600955565b612319565b9283610866336001600160a01b03165f52600860205260405f2090565b553390613456565b60095460408051948552602085019290925290830152339180606081016106a7565b6040517fd7f3a468000000000000000000000000000000000000000000000000000000008152336004820152602490fd5b0390fd5b6108e6915060203d81116108ec575b6108de8183611dd4565b8101906121b4565b5f6107f9565b503d6108d4565b6040517f2129c592000000000000000000000000000000000000000000000000000000008152336004820152602490fd5b346102815760208060031936011261028157600480359167ffffffffffffffff9182841161028157366023850112156102815783810135928311610281576024840193602436918560051b0101116102815761097e613403565b6001600160a01b0392838254163303610e5557836003541615610e455760ff60055460a01c16610e35576109b06133b0565b6109b861247b565b6040928351946370a0823160e01b865230848701528186602481847f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2165afa958615610488575f96610e16575b50610a1b6105586003546001600160a01b031690565b803b156102815785517f3280648e000000000000000000000000000000000000000000000000000000008152905f908290818381610a5c8a8f8d84016121c3565b03925af1801561048857610e03575b5090610a826105586003546001600160a01b031690565b8216905f5b848110610ba2575050505047610b6b575b610aad6105586003546001600160a01b031690565b94853b15610281575f845180977fa0e38c81000000000000000000000000000000000000000000000000000000008252818381610aed88888b84016121c3565b03925af192831561048857610b3b610558610b4692610b4e997f83175f8c84aa4e36267d4380f6880279b38aab5493b1c7a5db6bf5ffc3d2724597610b58575b50546001600160a01b031690565b9451928392836121c3565b0390a2612fd7565b6100206001600255565b806106c4610b6592611d67565b5f610b2d565b5f808080477f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc25af150610b9c612085565b50610a98565b610bad81868b612236565b8781016001600160e01b0319610bd5610bcf610bc98486612045565b90612258565b90612283565b166323b872dd60e01b811480610dce575b610da6577fb460af94000000000000000000000000000000000000000000000000000000008114908115610d7c575b50610d17575b84610c286105588461203b565b14610ce35730610c3a6105588461203b565b14610cbb5781610c695f9392868c610c5c610c55889761203b565b9386612045565b9490915180958193612078565b03930135905af1610c78612085565b9015610c875750600101610a87565b6108c1879189519384937f248ef89c00000000000000000000000000000000000000000000000000000000855284016122ee565b8789517f6829be6f000000000000000000000000000000000000000000000000000000008152fd5b88517f6eb86bd800000000000000000000000000000000000000000000000000000000815280890184815281906020010390fd5b610d36610d2e610d278385612045565b8091612266565b8101906122c4565b91505086610d4d815f54166001600160a01b031690565b911603610c1b578789517f2219f13e000000000000000000000000000000000000000000000000000000008152fd5b7fba087652000000000000000000000000000000000000000000000000000000009150145f610c15565b888a517f37933357000000000000000000000000000000000000000000000000000000008152fd5b50610de7610ddf610d278486612045565b8101906122af565b87610dfb815f54166001600160a01b031690565b911614610be6565b806106c4610e1092611d67565b5f610a6b565b610e2e919650823d84116108ec576108de8183611dd4565b945f610a05565b5060405163b3a5458960e01b8152fd5b5060405163097e401760e11b8152fd5b506040517ff5185ed1000000000000000000000000000000000000000000000000000000008152fd5b9060206003198301126102815760043567ffffffffffffffff9283821161028157806023830112156102815781600401359384116102815760248460061b83010111610281576024019190565b3461028157610ed936610e7e565b90610ee2613403565b610eea613359565b6001600160a01b03918260035416156103635760ff60055460a01c1661035257610f1261247b565b610f276105586003546001600160a01b031690565b92833b156102815782604091825180967f162146fb0000000000000000000000000000000000000000000000000000000082525f978891818381610f708b60049d8e8401611df6565b03925af1801561048857611185575b50610f93610f8e368685611eb7565b612a18565b8251906371a9730560e01b825286828781847f00000000000000000000000010d9c320aa9ba32bffedc08ba7b0446e8e0d9ad8165afa918215610488578792611169575b50908694939291610fe6611fec565b5085915b85831061107a575050506110096105586003546001600160a01b031690565b91823b156110765761104995859151968795869485937f2f40e5b80000000000000000000000000000000000000000000000000000000085528401611df6565b03925af1801561048857611063575b506106b46001600255565b806106c461107092611d67565b5f611058565b8480fd5b9091929394955061109461108f848887612018565b61202d565b926110af826110aa86516001600160a01b031690565b61318d565b501561112e576110ef60016110cb86516001600160a01b031690565b926110e06020880194855190309033906134a9565b0194516001600160a01b031690565b905186519081529083169033907f5548c837ab068cf56a2c2479df0882a4922fd203edb7517321831d95078c5f6290602090a390879594939291610fea565b85886108c161114487516001600160a01b031690565b92516362d0df2960e11b81526001600160a01b03909316918301918252829160200190565b61117e9192503d8089833e6107428183611dd4565b905f610fd7565b806106c461119292611d67565b5f610f7f565b34610281576003196020368201126102815760043567ffffffffffffffff811161028157606081600401928236030112610281576111d4613403565b6111dc613359565b6111e58261203b565b6111fd6105586105586003546001600160a01b031690565b6001600160a01b03809216146112fc576112168361203b565b1630146112d2575f8091602461122b8561203b565b6112386044840187612045565b929061124960405180958193612078565b03930135905af1611258612085565b901561129c57507f581f7fcb4603641e147a9f037fab064116f10ab9f195b7de511aac72fb3a45326040518061128f33948261218f565b0390a26100206001600255565b6108c1906040519182917f0e4f9cb400000000000000000000000000000000000000000000000000000000835260048301612102565b60046040517f3dac4c4e000000000000000000000000000000000000000000000000000000008152fd5b60046040517fb06c99f1000000000000000000000000000000000000000000000000000000008152fd5b34610281575f36600319011261028157602060ff60015460a01c166040519015158152f35b6001600160a01b0381160361028157565b3461028157604080600319360112610281576004803561137b8161134b565b602435906113888261134b565b611390613359565b60ff60055460a01c166114a1576113a561247b565b6001600160a01b03928382169384156114795733851461146a57831694851561144457338614611437575050906113f5611411926001600160a01b03166001600160a01b03196004541617600455565b6001600160a01b03166001600160a01b03196005541617600555565b7fef48f1577712f3f29564778f489f620f33b22e71b98872465e95c0794b76952f5f80a3005b51635515a0d760e11b8152fd5b517f12370b1c000000000000000000000000000000000000000000000000000000008152fd5b508451631eeea85b60e21b8152fd5b5084517fc93c2579000000000000000000000000000000000000000000000000000000008152fd5b82845163b3a5458960e01b8152fd5b34610281575f366003190112610281576114c8613359565b60046040517fe55b23a5000000000000000000000000000000000000000000000000000000008152fd5b34610281575f366003190112610281576020600a54604051908152f35b34610281575f8060031936011261048d576001546001600160a01b033381831603611577576001600160a01b0319809216600155825491339083161783553391167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b608460405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f74207468652060448201527f6e6577206f776e657200000000000000000000000000000000000000000000006064820152fd5b34610281575f8060031936011261048d576115fa613403565b6001600160a01b038082541633141590816116a3575b506116795760ff60055460a01c166103525761162a61247b565b6116326133b0565b600160a01b60ff60a01b1960015416176001557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a16106b46001600255565b60046040517f831dddf0000000000000000000000000000000000000000000000000000000008152fd5b9050600454163314155f611610565b34610281575f3660031901126102815760206001600160a01b035f5416604051908152f35b34610281575f3660031901126102815760206040516001600160a01b037f00000000000000000000000010d9c320aa9ba32bffedc08ba7b0446e8e0d9ad8168152f35b34610281575f36600319011261028157602060ff60055460a01c166040519015158152f35b34610281575f3660031901126102815760206001600160a01b0360035416604051908152f35b34610281575f3660031901126102815760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b34610281575f3660031901126102815760206001600160a01b0360015416604051908152f35b60208082019080835283518092528060408094019401925f905b8382106117ee57505050505090565b845180516001600160a01b031687528301518684015294850194938201936001909101906117df565b34610281575f8060031936011261048d57604051906371a9730560e01b825280826004816001600160a01b037f00000000000000000000000010d9c320aa9ba32bffedc08ba7b0446e8e0d9ad8165afa80156104885761188f92826118839392611893575b5050612e7f565b604051918291826117c5565b0390f35b6118a792503d8091833e6107428183611dd4565b5f8061187c565b34610281576118bc36610e7e565b906118c5613403565b6118cd613359565b6001600160a01b03918260035416156103635760ff60055460a01c16610352576118f561247b565b6040918251936371a9730560e01b85525f948581600481857f00000000000000000000000010d9c320aa9ba32bffedc08ba7b0446e8e0d9ad8165afa801561048857611954918791611ae6575b5061194e368686611eb7565b90612a9b565b611962610f8e368585611eb7565b6119776105586003546001600160a01b031690565b803b15611ae25785855180927fb99892750000000000000000000000000000000000000000000000000000000082528183816119b78a8a60048401611df6565b03925af1801561048857611acf575b50908492916119d3611fec565b50835b838110611a385750506119f46105586003546001600160a01b031690565b90813b15611a34578361104995518096819582947f34d184ae00000000000000000000000000000000000000000000000000000000845260048401611df6565b8380fd5b839450611a4d61108f82859660019596612018565b60208101908151908115611ac557611a79611a869233611a7484516001600160a01b031690565b613456565b516001600160a01b031690565b905187519081529084169033907f9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb90602090a301905b859392916119d6565b5050500190611abc565b806106c4611adc92611d67565b5f6119c6565b8580fd5b611afa91503d8089833e6107428183611dd4565b5f611942565b3461028157602036600319011261028157600435611b1d8161134b565b611b25613359565b6001600160a01b038080600454169216918214611b9b5780600554168214611b8a57611b4f613359565b816001600160a01b031960015416176001555f54167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e227005f80a3005b6004604051635515a0d760e11b8152fd5b6004604051631eeea85b60e21b8152fd5b34610281576020366003190112610281576001600160a01b03600435611bd18161134b565b165f526008602052602060405f2054604051908152f35b3461028157602036600319011261028157600435611c058161134b565b611c0d613403565b611c15613359565b60ff60055460a01c1661035257611c2a61247b565b611c3381613094565b611c486105586003546001600160a01b031690565b906001600160a01b0391828116611cc8575b7fdb0670e174c4203280e70166db52920a0ddc53923128a7e0e964c5350de54f1f611cbb83611ca18682166001600160a01b03166001600160a01b03196003541617600355565b6040516001600160a01b0390911681529081906020820190565b0390a16100206001600255565b90813b15610281575f80926004604051809581937f7f068c0f0000000000000000000000000000000000000000000000000000000083525af18015610488577fdb0670e174c4203280e70166db52920a0ddc53923128a7e0e964c5350de54f1f93611cbb93611ca192611d40575b5093505090611c5a565b806106c4611d4d92611d67565b5f611d36565b634e487b7160e01b5f52604160045260245ffd5b67ffffffffffffffff8111611d7b57604052565b611d53565b6040810190811067ffffffffffffffff821117611d7b57604052565b6080810190811067ffffffffffffffff821117611d7b57604052565b6060810190811067ffffffffffffffff821117611d7b57604052565b90601f8019910116810190811067ffffffffffffffff821117611d7b57604052565b60208082528082018490526040918201939092915f5b828110611e1b57505050505090565b90919293959482806001926001600160a01b038835611e398161134b565b168152878a01358a8201529798970196950193929101611e0c565b6040513d5f823e3d90fd5b60405190611e6c82611d80565b565b67ffffffffffffffff8111611d7b5760051b60200190565b919082604091031261028157604051611e9e81611d80565b60208082948035611eae8161134b565b84520135910152565b929192611ec382611e6e565b604092611ed284519283611dd4565b819581835260208093019160061b84019381851161028157915b848310611efb57505050505050565b838691611f088486611e86565b815201920191611eec565b5190811515820361028157565b9060209182818303126102815780519067ffffffffffffffff8211610281570181601f8201121561028157805192611f5784611e6e565b93604093611f6785519687611dd4565b818652828087019260071b85010193818511610281578301915b848310611f915750505050505090565b60808383031261028157836080918751611faa81611d9c565b8551611fb58161134b565b81528286015183820152611fca898701611f13565b8982015260608087015190611fde8261134b565b820152815201920191611f81565b60405190611ff982611d80565b5f6020838281520152565b634e487b7160e01b5f52603260045260245ffd5b91908110156120285760061b0190565b612004565b612038903690611e86565b90565b356120388161134b565b903590601e1981360301821215610281570180359067ffffffffffffffff82116102815760200191813603831361028157565b908092918237015f815290565b3d156120bf573d9067ffffffffffffffff8211611d7b57604051916120b4601f8201601f191660200184611dd4565b82523d5f602084013e565b606090565b91908251928382525f5b8481106120ee575050825f602080949584010152601f8019910116010190565b6020818301810151848301820152016120ce565b9060206120389281815201906120c4565b6001600160a01b0381356121268161134b565b168252602081013560208301526040810135601e19823603018112156102815701906020823592019167ffffffffffffffff8111610281578036038313610281578060809360606040850152816060850152848401375f828201840152601f01601f1916010190565b906020612038928181520190612113565b80518210156120285760209160051b010190565b90816020910312610281575190565b916020908082850183865252604084019160408260051b86010194845f80925b8584106121f557505050505050505090565b9091929394959697603f198282030188528835605e1985360301811215611a34578661222660019387839401612113565b9a019801969594019291906121e3565b91908110156120285760051b81013590605e1981360301821215610281570190565b906004116102815790600490565b909291928360041161028157831161028157600401916003190190565b6001600160e01b031990358181169392600481106122a057505050565b60040360031b82901b16169150565b9081602091031261028157356120388161134b565b9081606091031261028157803591604060208301356122e28161134b565b9201356120388161134b565b6040906120389392815281602082015201906120c4565b634e487b7160e01b5f52601160045260245ffd5b9190820391821161232657565b612305565b9060209182818303126102815780519067ffffffffffffffff8211610281570181601f820112156102815780519261236284611e6e565b9360409361237285519687611dd4565b818652828087019260061b85010193818511610281578301915b84831061239c5750505050505090565b85838303126102815783869182516123b381611d80565b85516123be8161134b565b8152828601518382015281520192019161238c565b6001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216330361240557565b60046040517f5683d0ea000000000000000000000000000000000000000000000000000000008152fd5b8181029291811591840414171561232657565b604d811161232657600a0a90565b811561245a570490565b634e487b7160e01b5f52601260045260245ffd5b9190820180921161232657565b7f000000000000000000000000000000000000000000000000000000000000000080158015612788575b8015612779575b612776576124b8612797565b908115612698576001600160a01b039160405163edf94acd60e01b81525f81600481877f00000000000000000000000010d9c320aa9ba32bffedc08ba7b0446e8e0d9ad8165afa5f918161275b575b5061273c5750612515612085565b8051156127125761254d7f5d801530a4e94131b234f165923bd70de2c3e71c9891f090501832eb5ddf3d7c9160405191829182612102565b0390a15b6007549081156126ca576125de9261256e6125739260065461242f565b61242f565b7f00000000000000000000000000000000000000000000000000000000000000127f00000000000000000000000000000000000000000000000000000000000000128082101561269c576125ce6125d993926125d392612319565b612442565b9061242f565b612450565b908115612698577fc80de135628ee55c4963b1bf37e23eb2d7325f1d92417e120e02bcea56b9bed99061261042600a55565b61263c6126256005546001600160a01b031690565b6001600160a01b03165f52600860205260405f2090565b61264784825461246e565b905561265861083f8460095461246e565b600554600a546006546007546009546040805198895260208901949094529287019190915260608601526080850152166001600160a01b03169160a090a2565b5050565b908181116126ac575b5050612450565b6125ce6126c393926126bd92612319565b90612450565b5f806126a5565b5050600a54600654600954604080519384526020840192909252908201527fb3da20cbb4a87f41036953a90dfa636fa7b5ad4d642283f4d8cf45be61a79d88925060609150a1565b60046040517f039cd3a0000000000000000000000000000000000000000000000000000000008152fd5b61275161274b612756926127ad565b60075590565b600655565b612551565b61276f91923d8091833e6104798183611dd4565b905f612507565b50565b5060055460a01c60ff166124ac565b5060ff60015460a01c166124a5565b5f600a548042116127a6575090565b9050420390565b5f915f91826001600160a01b039060409283516371a9730560e01b8152600483828281887f00000000000000000000000010d9c320aa9ba32bffedc08ba7b0446e8e0d9ad8165afa9182156104885784926129fc575b5061281d61281683979697959495612e7f565b9483612c50565b91909280519585987f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216925b878a106128b457505050505050505050506128837f0000000000000000000000000000000000000000000000000000000000000012612442565b670de0b6b3a764000081036128955750565b6128a3906128b1929461242f565b670de0b6b3a7640000900490565b91565b9091929394959697989b8c6128d58b6128cd83886121a0565b510151151590565b156129e85761293e818c6128f8610558610558610558610704612904988d6121a0565b6020809581948a6121a0565b510151915180809581947f07a2d13a0000000000000000000000000000000000000000000000000000000083528a83019190602083019252565b03915afa908115610488578f928b926129cb575b50505b86612966610558610704858a6121a0565b146129b2575b9161299c8261299561298e6001966129876129a2978f6121a0565b519061242f565b918b6121a0565b5190612450565b9061246e565b9c01989796959493929190612849565b91819d50886129c183826121a0565b519e50509161296c565b6129e19250803d106108ec576108de8183611dd4565b5f80612952565b60206129f482866121a0565b510151612955565b612a119192503d8086833e6107428183611dd4565b905f612803565b8051600191825b828110612a2c5750505050565b5f19810181811161232657612a4c906001600160a01b03918291856121a0565b51511690612a5a83856121a0565b5151161115612a6a578301612a1f565b602490604051907f0141de6e0000000000000000000000000000000000000000000000000000000082526004820152fd5b90805190612aa883612e7f565b90612ab1611fec565b505f5b838110612ac2575050505050565b612acc81836121a0565b51612ae2866110aa83516001600160a01b031690565b9015612b805760209081612af682886121a0565b5101519282810151809410612b115750505050600101612ab4565b91612b316108c192612b2b8995516001600160a01b031690565b946121a0565b5101516040519384937f9609a70c000000000000000000000000000000000000000000000000000000008552600485016040919493926001600160a01b03606083019616825260208201520152565b6108c1612b9483516001600160a01b031690565b6040516362d0df2960e11b81526001600160a01b0390911660048201529081906024820190565b90612bc582611e6e565b612bd26040519182611dd4565b8281528092612be3601f1991611e6e565b0190602036910137565b60405190612bfa82611d9c565b5f6060838281528260208201528260408201520152565b9081602091031261028157516120388161134b565b90816020910312610281575160ff811681036102815790565b60ff16604d811161232657600a0a90565b90918151835190612c6081612bbb565b94612c6a82612bbb565b94612c73612bed565b505f5b838110612c84575050505050565b612c8e81836121a0565b51604090612c9e82820151151590565b15612e2157610558610558610558612cbd93516001600160a01b031690565b815180917f38d52e0f00000000000000000000000000000000000000000000000000000000825281600460209485935afa908115610488576001600160a01b03925f92612df4575b5050165b5f915b878310612dc5575b91612d3791600485948d612d406001600160a01b03988b602098899889926121a0565b510151926121a0565b5251809681937f313ce567000000000000000000000000000000000000000000000000000000008352165afa801561048857600193612d87925f92612d98575b5050612c3f565b612d91828a6121a0565b5201612c76565b612db79250803d10612dbe575b612daf8183611dd4565b810190612c26565b5f80612d80565b503d612da5565b91612dd661055861070483896121a0565b6001600160a01b03831614612dee5760010191612d0c565b91612d14565b612e139250803d10612e1a575b612e0b8183611dd4565b810190612c11565b5f80612d05565b503d612e01565b516001600160a01b0316612d09565b90612e3a82611e6e565b612e476040519182611dd4565b8281528092612e58601f1991611e6e565b01905f5b828110612e6857505050565b602090612e73611fec565b82828501015201612e5c565b90815191612e8c83612e30565b92612e95612bed565b505f91826001600160a01b0391827f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216915b848110612ed657505050505050565b612ee081836121a0565b5190612ef382516001600160a01b031690565b6040516370a0823160e01b81523060048201526020919082816024818b86165afa91821561048857600195612f64868f610558948f97612f72978e9991612fba575b50612f50612f41611e5f565b6001600160a01b039093168352565b89820152612f5e83836121a0565b526121a0565b50516001600160a01b031690565b14612f7f575b5001612ec7565b612fb2612f9d8b83612f9486600954936121a0565b51015190613347565b91612fa8848d6121a0565b5101918251612319565b90525f612f78565b612fd191508a3d8c116108ec576108de8183611dd4565b5f612f35565b604051906370a0823160e01b82523060048301526020826024816001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2165afa918215610488575f92613074575b506009548210918261306a575b505061304057565b60046040517f58a65885000000000000000000000000000000000000000000000000000000008152fd5b1090505f80613038565b61308d91925060203d81116108ec576108de8183611dd4565b905f61302b565b6001600160a01b0390818116908115610363576130b76130b3826131fb565b1590565b6131515750906020600492604051938480927ffbfa77cf0000000000000000000000000000000000000000000000000000000082525afa918215610488575f92613131575b503091160361310757565b60046040517faf826849000000000000000000000000000000000000000000000000000000008152fd5b61314a91925060203d8111612e1a57612e0b8183611dd4565b905f6130fc565b6040517f8537fbfb0000000000000000000000000000000000000000000000000000000081526001600160a01b03919091166004820152602490fd5b90915f925f9281515f925b8184106131a6575b50505050565b6001600160a01b0391826131ba86846121a0565b515116938381168095106131ec575050836131d4916121a0565b515116146131e4578080806131a0565b600193509150565b60019095019493509150613198565b604051906020808301815f6301ffc9a760e01b958684528660248201526024815261322581611db8565b51617530938685fa933d5f5190866132c8575b50856132be575b508461325c575b50505081613252575090565b61203891506132d3565b839450905f9183946040518581019283526001600160e01b031960248201526024815261328881611db8565b5192fa5f5190913d836132b3575b5050816132a9575b5015905f8080613246565b905015155f61329e565b101591505f80613296565b151594505f61323f565b84111595505f613238565b5f602091604051838101906301ffc9a760e01b82527f755e75630000000000000000000000000000000000000000000000000000000060248201526024815261331b81611db8565b5191617530fa5f513d8261333b575b5081613334575090565b9050151590565b6020111591505f61332a565b9080821015613354575090565b905090565b6001600160a01b035f5416330361336c57565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b60ff60015460a01c166133bf57565b606460405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152fd5b60028054146134125760028055565b606460405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152fd5b611e6c926001600160a01b03604051937fa9059cbb0000000000000000000000000000000000000000000000000000000060208601521660248401526044830152604482526134a482611d9c565b6134fb565b9290604051926323b872dd60e01b60208501526001600160a01b03809216602485015216604483015260648201526064815260a081019181831067ffffffffffffffff841117611d7b57611e6c926040525b604051613558916001600160a01b031661351482611d80565b5f806020958685527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656487860152868151910182855af1613552612085565b916135fa565b80518281159182156135db575b50509050156135715750565b6084906040519062461bcd60e51b82526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152fd5b838092935001031261028157816135f29101611f13565b80825f613565565b9192901561365b575081511561360e575090565b3b156136175790565b606460405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152fd5b82519091501561366e5750805190602001fd5b6108c19060405191829162461bcd60e51b83526020600484015260248301906120c456fea264697066735822122081da0912feca3cf272c37f112aabdc6f855497b51c02c39e4cad917166ce388f64736f6c63430008150033
Verified Source Code Full Match
Compiler: v0.8.21+commit.d9974bed
EVM: shanghai
Optimization: Yes (1000 runs)
Types.sol 95 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;
import "@openzeppelin/IERC20.sol";
import "./interfaces/IAssetRegistry.sol";
// Types.sol
//
// This file defines the types used in V2.
/// @notice Combination of contract address and sighash to be used in allowlist.
/// @dev It's packed as follows:
/// [target 160 bits] [selector 32 bits] [<empty> 64 bits]
type TargetSighash is bytes32;
/// @notice Struct encapulating an asset and an associated value.
/// @param asset Asset address.
/// @param value The associated value for this asset (e.g., amount or price).
struct AssetValue {
IERC20 asset;
uint256 value;
}
/// @notice Execution details for a vault operation.
/// @param target Target contract address.
/// @param value Native token amount.
/// @param data Calldata.
struct Operation {
address target;
uint256 value;
bytes data;
}
/// @notice Contract address and sighash struct to be used in the public interface.
struct TargetSighashData {
address target;
bytes4 selector;
}
/// @notice Parameters for vault deployment.
/// @param owner Initial owner address.
/// @param assetRegistry Asset registry address.
/// @param hooks Hooks address.
/// @param guardian Guardian address.
/// @param feeRecipient Fee recipient address.
/// @param fee Fees accrued per second, denoted in 18 decimal fixed point format.
struct Parameters {
address owner;
address assetRegistry;
address hooks;
address guardian;
address feeRecipient;
uint256 fee;
}
/// @notice Vault parameters for vault deployment.
/// @param owner Initial owner address.
/// @param guardian Guardian address.
/// @param feeRecipient Fee recipient address.
/// @param fee Fees accrued per second, denoted in 18 decimal fixed point format.
struct VaultParameters {
address owner;
address guardian;
address feeRecipient;
uint256 fee;
}
/// @notice Asset registry parameters for asset registry deployment.
/// @param factory Asset registry factory address.
/// @param owner Initial owner address.
/// @param assets Initial list of registered assets.
/// @param numeraireToken Numeraire token address.
/// @param feeToken Fee token address.
/// @param sequencer Sequencer Uptime Feed address for L2.
struct AssetRegistryParameters {
address factory;
address owner;
IAssetRegistry.AssetInformation[] assets;
IERC20 numeraireToken;
IERC20 feeToken;
AggregatorV2V3Interface sequencer;
}
/// @notice Hooks parameters for hooks deployment.
/// @param factory Hooks factory address.
/// @param owner Initial owner address.
/// @param minDailyValue The fraction of value that the vault has to retain per day
/// in the course of submissions.
/// @param targetSighashAllowlist Array of target contract and sighash combinations to allow.
struct HooksParameters {
address factory;
address owner;
uint256 minDailyValue;
TargetSighashData[] targetSighashAllowlist;
}
Constants.sol 9 lines
// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.21; // Constants.sol // // This file defines the constants used across several contracts in V2. /// @dev Fixed point multiplier. uint256 constant ONE = 1e18;
AeraVaultV2.sol 963 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;
import "@openzeppelin/ERC165.sol";
import "@openzeppelin/ERC165Checker.sol";
import "@openzeppelin/IERC4626.sol";
import "@openzeppelin/Math.sol";
import "@openzeppelin/Ownable2Step.sol";
import "@openzeppelin/Pausable.sol";
import "@openzeppelin/ReentrancyGuard.sol";
import "@openzeppelin/SafeERC20.sol";
import "./interfaces/IAeraV2Factory.sol";
import "./interfaces/IHooks.sol";
import "./interfaces/IVault.sol";
import {ONE} from "./Constants.sol";
/// @title AeraVaultV2.
/// @notice Aera Vault V2 Vault contract.
contract AeraVaultV2 is
IVault,
ERC165,
Ownable2Step,
Pausable,
ReentrancyGuard
{
using SafeERC20 for IERC20;
/// @notice Largest possible fee earned proportion per one second.
/// @dev 0.0000001% per second, i.e. 3.1536% per year.
/// 0.0000001% * (365 * 24 * 60 * 60) = 3.1536%
/// or 3.16224% per year in leap years.
uint256 private constant _MAX_FEE = 10 ** 9;
/// @notice Number of decimals for fee token.
uint256 private immutable _feeTokenDecimals;
/// @notice Number of decimals for numeraire token.
uint256 private immutable _numeraireTokenDecimals;
/// @notice Fee token used by asset registry.
IERC20 private immutable _feeToken;
/// @notice Fee per second in 18 decimal fixed point format.
uint256 public immutable fee;
/// @notice Asset registry address.
IAssetRegistry public immutable assetRegistry;
/// @notice The address of wrapped native token.
address public immutable wrappedNativeToken;
/// STORAGE ///
/// @notice Hooks module address.
IHooks public hooks;
/// @notice Guardian address.
address public guardian;
/// @notice Fee recipient address.
address public feeRecipient;
/// @notice True if vault has been finalized.
bool public finalized;
/// @notice Last measured value of assets in vault.
uint256 public lastValue;
/// @notice Last spot price of fee token.
uint256 public lastFeeTokenPrice;
/// @notice Fee earned amount for each prior fee recipient.
mapping(address => uint256) public fees;
/// @notice Total fee earned and unclaimed amount by all fee recipients.
uint256 public feeTotal;
/// @notice Last timestamp when fee index was reserved.
uint256 public lastFeeCheckpoint;
/// MODIFIERS ///
/// @dev Throws if called by any account other than the owner or guardian.
modifier onlyOwnerOrGuardian() {
if (msg.sender != owner() && msg.sender != guardian) {
revert Aera__CallerIsNotOwnerAndGuardian();
}
_;
}
/// @dev Throws if called by any account other than the guardian.
modifier onlyGuardian() {
if (msg.sender != guardian) {
revert Aera__CallerIsNotGuardian();
}
_;
}
/// @dev Throws if called after the vault is finalized.
modifier whenNotFinalized() {
if (finalized) {
revert Aera__VaultIsFinalized();
}
_;
}
/// @dev Throws if hooks is not set
modifier whenHooksSet() {
if (address(hooks) == address(0)) {
revert Aera__HooksIsZeroAddress();
}
_;
}
/// @dev Calculate current guardian fees.
modifier reserveFees() {
_reserveFees();
_;
}
/// @dev Check insolvency of fee token was not made worse.
modifier checkReservedFees() {
uint256 prevFeeTokenBalance =
IERC20(_feeToken).balanceOf(address(this));
_;
_checkReservedFees(prevFeeTokenBalance);
}
/// FUNCTIONS ///
constructor() Ownable() ReentrancyGuard() {
(
address owner_,
address assetRegistry_,
address hooks_,
address guardian_,
address feeRecipient_,
uint256 fee_
) = IAeraV2Factory(msg.sender).parameters();
// Requirements: check provided addresses.
_checkAssetRegistryAddress(assetRegistry_);
_checkHooksAddress(hooks_);
_checkGuardianAddress(guardian_, owner_);
_checkFeeRecipientAddress(feeRecipient_, owner_);
// Requirements: check that initial owner is not zero address.
if (owner_ == address(0)) {
revert Aera__InitialOwnerIsZeroAddress();
}
// Requirements: check if fee is within bounds.
if (fee_ > _MAX_FEE) {
revert Aera__FeeIsAboveMax(fee_, _MAX_FEE);
}
// Effects: initialize vault state.
wrappedNativeToken = IAeraV2Factory(msg.sender).wrappedNativeToken();
assetRegistry = IAssetRegistry(assetRegistry_);
hooks = IHooks(hooks_);
guardian = guardian_;
feeRecipient = feeRecipient_;
fee = fee_;
lastFeeCheckpoint = block.timestamp;
// Effects: cache numeraire and fee token decimals.
_feeToken = IAssetRegistry(assetRegistry_).feeToken();
_feeTokenDecimals = IERC20Metadata(address(_feeToken)).decimals();
_numeraireTokenDecimals =
IERC20Metadata(address(assetRegistry.numeraireToken())).decimals();
// Effects: set new owner.
_transferOwnership(owner_);
// Effects: pause vault.
_pause();
// Log setting of asset registry.
emit SetAssetRegistry(assetRegistry_);
// Log new hooks address.
emit SetHooks(hooks_);
// Log the current guardian and fee recipient.
emit SetGuardianAndFeeRecipient(guardian_, feeRecipient_);
}
/// @inheritdoc IVault
function deposit(AssetValue[] calldata amounts)
external
override
nonReentrant
onlyOwner
whenHooksSet
whenNotFinalized
reserveFees
{
// Hooks: before transferring assets.
hooks.beforeDeposit(amounts);
// Requirements: check that provided amounts are sorted by asset and unique.
_checkAmountsSorted(amounts);
IAssetRegistry.AssetInformation[] memory assets =
assetRegistry.assets();
uint256 numAmounts = amounts.length;
AssetValue memory assetValue;
bool isRegistered;
for (uint256 i = 0; i < numAmounts;) {
assetValue = amounts[i];
(isRegistered,) = _isAssetRegistered(assetValue.asset, assets);
// Requirements: check that deposited assets are registered.
if (!isRegistered) {
revert Aera__AssetIsNotRegistered(assetValue.asset);
}
// Interactions: transfer asset from owner to vault.
assetValue.asset.safeTransferFrom(
msg.sender, address(this), assetValue.value
);
unchecked {
i++; // gas savings
}
// Log deposit for this asset.
emit Deposit(msg.sender, assetValue.asset, assetValue.value);
}
// Hooks: after transferring assets.
hooks.afterDeposit(amounts);
}
/// @inheritdoc IVault
function withdraw(AssetValue[] calldata amounts)
external
override
nonReentrant
onlyOwner
whenHooksSet
whenNotFinalized
reserveFees
{
IAssetRegistry.AssetInformation[] memory assets =
assetRegistry.assets();
// Requirements: check the withdraw request.
_checkWithdrawRequest(assets, amounts);
// Requirements: check that provided amounts are sorted by asset and unique.
_checkAmountsSorted(amounts);
// Hooks: before transferring assets.
hooks.beforeWithdraw(amounts);
uint256 numAmounts = amounts.length;
AssetValue memory assetValue;
for (uint256 i = 0; i < numAmounts;) {
assetValue = amounts[i];
if (assetValue.value == 0) {
unchecked {
i++; // gas savings
}
continue;
}
// Interactions: withdraw assets.
assetValue.asset.safeTransfer(msg.sender, assetValue.value);
// Log withdrawal for this asset.
emit Withdraw(msg.sender, assetValue.asset, assetValue.value);
unchecked {
i++; // gas savings
}
}
// Hooks: after transferring assets.
hooks.afterWithdraw(amounts);
}
/// @inheritdoc IVault
function setGuardianAndFeeRecipient(
address newGuardian,
address newFeeRecipient
) external override onlyOwner whenNotFinalized reserveFees {
// Requirements: check guardian and fee recipient addresses.
_checkGuardianAddress(newGuardian, msg.sender);
_checkFeeRecipientAddress(newFeeRecipient, msg.sender);
// Effects: update guardian and fee recipient addresses.
guardian = newGuardian;
// slither-disable-next-line missing-zero-check
feeRecipient = newFeeRecipient;
// Log new guardian and fee recipient addresses.
emit SetGuardianAndFeeRecipient(newGuardian, newFeeRecipient);
}
/// @inheritdoc IVault
function setHooks(address newHooks)
external
override
nonReentrant
onlyOwner
whenNotFinalized
reserveFees
{
// Requirements: validate hooks address.
_checkHooksAddress(newHooks);
// Effects: decommission old hooks contract.
if (address(hooks) != address(0)) {
hooks.decommission();
}
// Effects: set new hooks address.
hooks = IHooks(newHooks);
// Log new hooks address.
emit SetHooks(newHooks);
}
/// @inheritdoc IVault
/// @dev reserveFees modifier is not used to avoid reverts.
function execute(Operation calldata operation)
external
override
nonReentrant
onlyOwner
{
// Requirements: check that the target contract is not hooks.
if (operation.target == address(hooks)) {
revert Aera__ExecuteTargetIsHooksAddress();
}
// Requirements: check that the target contract is not vault itself.
if (operation.target == address(this)) {
revert Aera__ExecuteTargetIsVaultAddress();
}
// Interactions: execute operation.
(bool success, bytes memory result) =
operation.target.call{value: operation.value}(operation.data);
// Invariants: check that the operation was successful.
if (!success) {
revert Aera__ExecutionFailed(result);
}
// Log that the operation was executed.
emit Executed(msg.sender, operation);
}
/// @inheritdoc IVault
function finalize()
external
override
nonReentrant
onlyOwner
whenHooksSet
whenNotFinalized
reserveFees
{
// Hooks: before finalizing.
hooks.beforeFinalize();
// Effects: mark the vault as finalized.
finalized = true;
IAssetRegistry.AssetInformation[] memory assets =
assetRegistry.assets();
AssetValue[] memory assetAmounts = _getHoldings(assets);
uint256 numAssetAmounts = assetAmounts.length;
for (uint256 i = 0; i < numAssetAmounts;) {
// Effects: transfer registered assets to owner.
// Excludes reserved fee tokens and native token (e.g., ETH).
if (assetAmounts[i].value > 0) {
assetAmounts[i].asset.safeTransfer(
msg.sender, assetAmounts[i].value
);
}
unchecked {
i++; // gas savings
}
}
// Hooks: after finalizing.
hooks.afterFinalize();
// Log finalization.
emit Finalized(msg.sender, assetAmounts);
}
/// @inheritdoc IVault
function pause()
external
override
nonReentrant
onlyOwnerOrGuardian
whenNotFinalized
reserveFees
{
// Requirements and Effects: checks contract is unpaused and pauses it.
_pause();
}
/// @inheritdoc IVault
function resume()
external
override
onlyOwner
whenHooksSet
whenNotFinalized
{
// Effects: start a new fee checkpoint.
lastFeeCheckpoint = block.timestamp;
// Requirements and Effects: checks contract is paused and unpauses it.
_unpause();
}
/// @inheritdoc IVault
function submit(Operation[] calldata operations)
external
override
nonReentrant
onlyGuardian
whenHooksSet
whenNotFinalized
whenNotPaused
reserveFees
checkReservedFees
{
// Hooks: before executing operations.
hooks.beforeSubmit(operations);
uint256 numOperations = operations.length;
Operation calldata operation;
bytes4 selector;
bool success;
bytes memory result;
address hooksAddress = address(hooks);
for (uint256 i = 0; i < numOperations;) {
operation = operations[i];
selector = bytes4(operation.data[0:4]);
// Requirements: validate that it doesn't transfer asset from owner.
if (
selector == IERC20.transferFrom.selector
&& abi.decode(operation.data[4:], (address)) == owner()
) {
revert Aera__SubmitTransfersAssetFromOwner();
}
// Requirements: check that operation is not trying to redeem ERC4626 shares from owner.
// This could occur if the owner had a pre-existing allowance introduced during deposit.
if (
selector == IERC4626.withdraw.selector
|| selector == IERC4626.redeem.selector
) {
(,, address assetOwner) =
abi.decode(operation.data[4:], (uint256, address, address));
if (assetOwner == owner()) {
revert Aera__SubmitRedeemERC4626AssetFromOwner();
}
}
// Requirements: check that the target contract is not hooks.
if (operation.target == hooksAddress) {
revert Aera__SubmitTargetIsHooksAddress(i);
}
// Requirements: check that the target contract is not vault itself.
if (operation.target == address(this)) {
revert Aera__SubmitTargetIsVaultAddress();
}
// Interactions: execute operation.
(success, result) =
operation.target.call{value: operation.value}(operation.data);
// Invariants: confirm that operation succeeded.
if (!success) {
revert Aera__SubmissionFailed(i, result);
}
unchecked {
i++; // gas savings
}
}
if (address(this).balance > 0) {
wrappedNativeToken.call{value: address(this).balance}("");
}
// Hooks: after executing operations.
hooks.afterSubmit(operations);
// Log submission.
emit Submitted(guardian, operations);
}
/// @inheritdoc IVault
function claim() external override nonReentrant reserveFees {
uint256 reservedFee = fees[msg.sender];
// Requirements: check that there are fees to claim.
if (reservedFee == 0) {
revert Aera__NoClaimableFeesForCaller(msg.sender);
}
uint256 availableFee =
Math.min(_feeToken.balanceOf(address(this)), reservedFee);
// Requirements: check that fees are available to claim.
if (availableFee == 0) {
revert Aera__NoAvailableFeesForCaller(msg.sender);
}
// Effects: update fee total.
feeTotal -= availableFee;
reservedFee -= availableFee;
// Effects: update leftover fee.
fees[msg.sender] = reservedFee;
// Interactions: transfer fee to caller.
_feeToken.safeTransfer(msg.sender, availableFee);
// Log the claim.
emit Claimed(msg.sender, availableFee, reservedFee, feeTotal);
}
/// @inheritdoc IVault
function holdings() external view override returns (AssetValue[] memory) {
IAssetRegistry.AssetInformation[] memory assets =
assetRegistry.assets();
return _getHoldings(assets);
}
/// @inheritdoc IVault
function value() external view override returns (uint256 vaultValue) {
IAssetRegistry.AssetPriceReading[] memory erc20SpotPrices =
assetRegistry.spotPrices();
(vaultValue,) = _value(erc20SpotPrices);
}
/// @inheritdoc IERC165
function supportsInterface(bytes4 interfaceId)
public
view
override
returns (bool)
{
return interfaceId == type(IVault).interfaceId
|| super.supportsInterface(interfaceId);
}
/// @inheritdoc Ownable
function renounceOwnership() public view override onlyOwner {
revert Aera__CannotRenounceOwnership();
}
/// @inheritdoc Ownable2Step
function transferOwnership(address newOwner) public override onlyOwner {
// Requirements: check that new owner is disaffiliated from existing roles.
if (newOwner == guardian) {
revert Aera__GuardianIsOwner();
}
if (newOwner == feeRecipient) {
revert Aera__FeeRecipientIsOwner();
}
// Effects: initiate ownership transfer.
super.transferOwnership(newOwner);
}
/// @notice Only accept native token from the wrapped native token contract
/// when burning wrapped native tokens.
receive() external payable {
// Requirements: verify that the sender is wrapped native token.
if (msg.sender != wrappedNativeToken) {
revert Aera__NotWrappedNativeTokenContract();
}
}
/// INTERNAL FUNCTIONS ///
/// @notice Calculate guardian fee index.
/// @return feeIndex Guardian fee index.
function _getFeeIndex() internal view returns (uint256 feeIndex) {
if (block.timestamp > lastFeeCheckpoint) {
unchecked {
feeIndex = block.timestamp - lastFeeCheckpoint;
}
}
return feeIndex;
}
/// @notice Calculate current guardian fees.
function _reserveFees() internal {
// Requirements: check if fees are being accrued.
if (fee == 0 || paused() || finalized) {
return;
}
uint256 feeIndex = _getFeeIndex();
// Requirements: check if fees have been accruing.
if (feeIndex == 0) {
return;
}
// Calculate vault value using oracle or backup value if oracle is reverting.
try assetRegistry.spotPrices() returns (
IAssetRegistry.AssetPriceReading[] memory erc20SpotPrices
) {
(lastValue, lastFeeTokenPrice) = _value(erc20SpotPrices);
} catch (bytes memory reason) {
// Check if there is a clear reason for the revert.
if (reason.length == 0) {
revert Aera__SpotPricesReverted();
}
emit SpotPricesReverted(reason);
}
// Requirements: check that fee token has a positive price.
if (lastFeeTokenPrice == 0) {
emit NoFeesReserved(lastFeeCheckpoint, lastValue, feeTotal);
return;
}
// Calculate new fee for current fee recipient.
// It calculates the fee in fee token decimals.
uint256 newFee = lastValue * feeIndex * fee;
if (_numeraireTokenDecimals < _feeTokenDecimals) {
newFee =
newFee * (10 ** (_feeTokenDecimals - _numeraireTokenDecimals));
} else if (_numeraireTokenDecimals > _feeTokenDecimals) {
newFee =
newFee / (10 ** (_numeraireTokenDecimals - _feeTokenDecimals));
}
newFee /= lastFeeTokenPrice;
if (newFee == 0) {
return;
}
// Move fee checkpoint only if fee is nonzero
lastFeeCheckpoint = block.timestamp;
// Effects: accrue fee to fee recipient and remember new fee total.
fees[feeRecipient] += newFee;
feeTotal += newFee;
// Log fee reservation.
emit FeesReserved(
feeRecipient,
newFee,
lastFeeCheckpoint,
lastValue,
lastFeeTokenPrice,
feeTotal
);
}
/// @notice Get current total value of assets in vault and price of fee token.
/// @dev It calculates the value in Numeraire token decimals.
/// @param erc20SpotPrices Spot prices of ERC20 assets.
/// @return vaultValue Current total value.
/// @return feeTokenPrice Fee token price.
function _value(IAssetRegistry.AssetPriceReading[] memory erc20SpotPrices)
internal
view
returns (uint256 vaultValue, uint256 feeTokenPrice)
{
IAssetRegistry.AssetInformation[] memory assets =
assetRegistry.assets();
AssetValue[] memory assetAmounts = _getHoldings(assets);
(uint256[] memory spotPrices, uint256[] memory assetUnits) =
_getSpotPricesAndUnits(assets, erc20SpotPrices);
uint256 numAssets = assets.length;
uint256 balance;
for (uint256 i = 0; i < numAssets;) {
if (assets[i].isERC4626) {
balance = IERC4626(address(assets[i].asset)).convertToAssets(
assetAmounts[i].value
);
} else {
balance = assetAmounts[i].value;
}
if (assets[i].asset == _feeToken) {
feeTokenPrice = spotPrices[i];
}
vaultValue += (balance * spotPrices[i]) / assetUnits[i];
unchecked {
i++; // gas savings
}
}
uint256 numeraireUnit = 10 ** _numeraireTokenDecimals;
if (numeraireUnit != ONE) {
vaultValue = vaultValue * numeraireUnit / ONE;
}
}
/// @notice Check that assets in provided amounts are sorted and unique.
/// @param amounts Struct details for assets and amounts to withdraw.
function _checkAmountsSorted(AssetValue[] memory amounts) internal pure {
uint256 numAssets = amounts.length;
for (uint256 i = 1; i < numAssets;) {
if (amounts[i - 1].asset >= amounts[i].asset) {
revert Aera__AmountsOrderIsIncorrect(i);
}
unchecked {
i++; // gas savings
}
}
}
/// @notice Check request to withdraw.
/// @param assets Struct details for asset information from asset registry.
/// @param amounts Struct details for assets and amounts to withdraw.
function _checkWithdrawRequest(
IAssetRegistry.AssetInformation[] memory assets,
AssetValue[] memory amounts
) internal view {
uint256 numAmounts = amounts.length;
AssetValue[] memory assetAmounts = _getHoldings(assets);
bool isRegistered;
AssetValue memory assetValue;
uint256 assetIndex;
for (uint256 i = 0; i < numAmounts;) {
assetValue = amounts[i];
(isRegistered, assetIndex) =
_isAssetRegistered(assetValue.asset, assets);
if (!isRegistered) {
revert Aera__AssetIsNotRegistered(assetValue.asset);
}
if (assetAmounts[assetIndex].value < assetValue.value) {
revert Aera__AmountExceedsAvailable(
assetValue.asset,
assetValue.value,
assetAmounts[assetIndex].value
);
}
unchecked {
i++; // gas savings
}
}
}
/// @notice Get spot prices and units of requested assets.
/// @dev Spot prices are scaled to 18 decimals.
/// @param assets Registered assets in asset registry and their information.
/// @param erc20SpotPrices Struct details for spot prices of ERC20 assets.
/// @return spotPrices Spot prices of assets.
/// @return assetUnits Units of assets.
function _getSpotPricesAndUnits(
IAssetRegistry.AssetInformation[] memory assets,
IAssetRegistry.AssetPriceReading[] memory erc20SpotPrices
)
internal
view
returns (uint256[] memory spotPrices, uint256[] memory assetUnits)
{
uint256 numAssets = assets.length;
uint256 numERC20SpotPrices = erc20SpotPrices.length;
spotPrices = new uint256[](numAssets);
assetUnits = new uint256[](numAssets);
IAssetRegistry.AssetInformation memory asset;
for (uint256 i = 0; i < numAssets;) {
asset = assets[i];
IERC20 assetToFind = (
asset.isERC4626
? IERC20(IERC4626(address(asset.asset)).asset())
: asset.asset
);
uint256 j = 0;
for (; j < numERC20SpotPrices;) {
if (assetToFind == erc20SpotPrices[j].asset) {
break;
}
unchecked {
j++; // gas savings
}
}
spotPrices[i] = erc20SpotPrices[j].spotPrice;
assetUnits[i] =
10 ** IERC20Metadata(address(assetToFind)).decimals();
unchecked {
i++; // gas savings
}
}
}
/// @notice Get total amount of assets in vault.
/// @param assets Struct details for registered assets in asset registry.
/// @return assetAmounts Amount of assets.
function _getHoldings(IAssetRegistry.AssetInformation[] memory assets)
internal
view
returns (AssetValue[] memory assetAmounts)
{
uint256 numAssets = assets.length;
assetAmounts = new AssetValue[](numAssets);
IAssetRegistry.AssetInformation memory assetInfo;
for (uint256 i = 0; i < numAssets;) {
assetInfo = assets[i];
assetAmounts[i] = AssetValue({
asset: assetInfo.asset,
value: assetInfo.asset.balanceOf(address(this))
});
if (assetInfo.asset == _feeToken) {
assetAmounts[i].value -=
Math.min(feeTotal, assetAmounts[i].value);
}
unchecked {
i++; //gas savings
}
}
}
/// @notice Check if balance of fee becomes insolvent or becomes more insolvent.
/// @param prevFeeTokenBalance Balance of fee token before action.
function _checkReservedFees(uint256 prevFeeTokenBalance) internal view {
uint256 feeTokenBalance = IERC20(_feeToken).balanceOf(address(this));
if (
feeTokenBalance < feeTotal && feeTokenBalance < prevFeeTokenBalance
) {
revert Aera__CannotUseReservedFees();
}
}
/// @notice Check if the address can be a guardian.
/// @param newGuardian Address to check.
/// @param owner_ Owner address.
function _checkGuardianAddress(
address newGuardian,
address owner_
) internal pure {
if (newGuardian == address(0)) {
revert Aera__GuardianIsZeroAddress();
}
if (newGuardian == owner_) {
revert Aera__GuardianIsOwner();
}
}
/// @notice Check if the address can be a fee recipient.
/// @param newFeeRecipient Address to check.
/// @param owner_ Owner address.
function _checkFeeRecipientAddress(
address newFeeRecipient,
address owner_
) internal pure {
if (newFeeRecipient == address(0)) {
revert Aera__FeeRecipientIsZeroAddress();
}
if (newFeeRecipient == owner_) {
revert Aera__FeeRecipientIsOwner();
}
}
/// @notice Check if the address can be an asset registry.
/// @param newAssetRegistry Address to check.
function _checkAssetRegistryAddress(address newAssetRegistry)
internal
view
{
if (newAssetRegistry == address(0)) {
revert Aera__AssetRegistryIsZeroAddress();
}
if (
!ERC165Checker.supportsInterface(
newAssetRegistry, type(IAssetRegistry).interfaceId
)
) {
revert Aera__AssetRegistryIsNotValid(newAssetRegistry);
}
if (IAssetRegistry(newAssetRegistry).vault() != address(this)) {
revert Aera__AssetRegistryHasInvalidVault();
}
}
/// @notice Check if the address can be a hooks contract.
/// @param newHooks Address to check.
function _checkHooksAddress(address newHooks) internal view {
if (newHooks == address(0)) {
revert Aera__HooksIsZeroAddress();
}
if (
!ERC165Checker.supportsInterface(newHooks, type(IHooks).interfaceId)
) {
revert Aera__HooksIsNotValid(newHooks);
}
if (IHooks(newHooks).vault() != address(this)) {
revert Aera__HooksHasInvalidVault();
}
}
/// @notice Check whether asset is registered to asset registry or not.
/// @param asset Asset to check.
/// @param registeredAssets Array of registered assets.
/// @return isRegistered True if asset is registered.
/// @return index Index of asset in asset registry.
function _isAssetRegistered(
IERC20 asset,
IAssetRegistry.AssetInformation[] memory registeredAssets
) internal pure returns (bool isRegistered, uint256 index) {
uint256 numAssets = registeredAssets.length;
for (uint256 i = 0; i < numAssets;) {
if (registeredAssets[i].asset < asset) {
unchecked {
i++; // gas savings
}
continue;
}
if (registeredAssets[i].asset == asset) {
return (true, i);
}
break;
}
}
}
IHooks.sol 53 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;
import {AssetValue, Operation} from "../Types.sol";
/// @title IHooks
/// @notice Interface for the hooks module.
interface IHooks {
/// @notice Get address of vault.
/// @return vault Vault address.
function vault() external view returns (address vault);
/// @notice Hook that runs before deposit.
/// @param amounts Struct details for assets and amounts to deposit.
/// @dev MUST revert if not called by vault.
function beforeDeposit(AssetValue[] memory amounts) external;
/// @notice Hook that runs after deposit.
/// @param amounts Struct details for assets and amounts to deposit.
/// @dev MUST revert if not called by vault.
function afterDeposit(AssetValue[] memory amounts) external;
/// @notice Hook that runs before withdraw.
/// @param amounts Struct details for assets and amounts to withdraw.
/// @dev MUST revert if not called by vault.
function beforeWithdraw(AssetValue[] memory amounts) external;
/// @notice Hook that runs after withdraw.
/// @param amounts Struct details for assets and amounts to withdraw.
/// @dev MUST revert if not called by vault.
function afterWithdraw(AssetValue[] memory amounts) external;
/// @notice Hook that runs before submit.
/// @param operations Array of struct details for target and calldata to submit.
/// @dev MUST revert if not called by vault.
function beforeSubmit(Operation[] memory operations) external;
/// @notice Hook that runs after submit.
/// @param operations Array of struct details for target and calldata to submit.
/// @dev MUST revert if not called by vault.
function afterSubmit(Operation[] memory operations) external;
/// @notice Hook that runs before finalize.
/// @dev MUST revert if not called by vault.
function beforeFinalize() external;
/// @notice Hook that runs after finalize.
/// @dev MUST revert if not called by vault.
function afterFinalize() external;
/// @notice Take hooks out of use.
function decommission() external;
}
IVault.sol 135 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;
import "@openzeppelin/IERC20.sol";
import "./IAssetRegistry.sol";
import "./IVaultEvents.sol";
import "./IHooks.sol";
/// @title IVault
/// @notice Interface for the vault.
/// @dev Any implementation MUST also implement Ownable2Step.
interface IVault is IVaultEvents {
/// ERRORS ///
error Aera__AssetRegistryIsZeroAddress();
error Aera__AssetRegistryIsNotValid(address assetRegistry);
error Aera__AssetRegistryHasInvalidVault();
error Aera__HooksIsZeroAddress();
error Aera__HooksIsNotValid(address hooks);
error Aera__HooksHasInvalidVault();
error Aera__GuardianIsZeroAddress();
error Aera__GuardianIsOwner();
error Aera__InitialOwnerIsZeroAddress();
error Aera__FeeRecipientIsZeroAddress();
error Aera__ExecuteTargetIsHooksAddress();
error Aera__ExecuteTargetIsVaultAddress();
error Aera__SubmitTransfersAssetFromOwner();
error Aera__SubmitRedeemERC4626AssetFromOwner();
error Aera__SubmitTargetIsVaultAddress();
error Aera__SubmitTargetIsHooksAddress(uint256 index);
error Aera__FeeRecipientIsOwner();
error Aera__FeeIsAboveMax(uint256 actual, uint256 max);
error Aera__CallerIsNotOwnerAndGuardian();
error Aera__CallerIsNotGuardian();
error Aera__AssetIsNotRegistered(IERC20 asset);
error Aera__AmountExceedsAvailable(
IERC20 asset, uint256 amount, uint256 available
);
error Aera__ExecutionFailed(bytes result);
error Aera__VaultIsFinalized();
error Aera__SubmissionFailed(uint256 index, bytes result);
error Aera__CannotUseReservedFees();
error Aera__SpotPricesReverted();
error Aera__AmountsOrderIsIncorrect(uint256 index);
error Aera__NoAvailableFeesForCaller(address caller);
error Aera__NoClaimableFeesForCaller(address caller);
error Aera__NotWrappedNativeTokenContract();
error Aera__CannotRenounceOwnership();
/// FUNCTIONS ///
/// @notice Deposit assets.
/// @param amounts Assets and amounts to deposit.
/// @dev MUST revert if not called by owner.
function deposit(AssetValue[] memory amounts) external;
/// @notice Withdraw assets.
/// @param amounts Assets and amounts to withdraw.
/// @dev MUST revert if not called by owner.
function withdraw(AssetValue[] memory amounts) external;
/// @notice Set current guardian and fee recipient.
/// @param guardian New guardian address.
/// @param feeRecipient New fee recipient address.
/// @dev MUST revert if not called by owner.
function setGuardianAndFeeRecipient(
address guardian,
address feeRecipient
) external;
/// @notice Sets the current hooks module.
/// @param hooks New hooks module address.
/// @dev MUST revert if not called by owner.
function setHooks(address hooks) external;
/// @notice Execute a transaction via the vault.
/// @dev Execution still should work when vault is finalized.
/// @param operation Struct details for target and calldata to execute.
/// @dev MUST revert if not called by owner.
function execute(Operation memory operation) external;
/// @notice Terminate the vault and return all funds to owner.
/// @dev MUST revert if not called by owner.
function finalize() external;
/// @notice Stops the guardian from submission and halts fee accrual.
/// @dev MUST revert if not called by owner or guardian.
function pause() external;
/// @notice Resume fee accrual and guardian submissions.
/// @dev MUST revert if not called by owner.
function resume() external;
/// @notice Submit a series of transactions for execution via the vault.
/// @param operations Sequence of operations to execute.
/// @dev MUST revert if not called by guardian.
function submit(Operation[] memory operations) external;
/// @notice Claim fees on behalf of a current or previous fee recipient.
function claim() external;
/// @notice Get the current guardian.
/// @return guardian Address of guardian.
function guardian() external view returns (address guardian);
/// @notice Get the current fee recipient.
/// @return feeRecipient Address of fee recipient.
function feeRecipient() external view returns (address feeRecipient);
/// @notice Get the current asset registry.
/// @return assetRegistry Address of asset registry.
function assetRegistry()
external
view
returns (IAssetRegistry assetRegistry);
/// @notice Get the current hooks module address.
/// @return hooks Address of hooks module.
function hooks() external view returns (IHooks hooks);
/// @notice Get fee per second.
/// @return fee Fee per second in 18 decimal fixed point format.
function fee() external view returns (uint256 fee);
/// @notice Get current balances of all assets.
/// @return assetAmounts Amounts of registered assets.
function holdings()
external
view
returns (AssetValue[] memory assetAmounts);
/// @notice Get current total value of assets in vault.
/// @return value Current total value.
function value() external view returns (uint256 value);
}
IVaultEvents.sol 95 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;
import "@openzeppelin/IERC20.sol";
import {AssetValue, Operation} from "../Types.sol";
/// @title Interface for vault events.
interface IVaultEvents {
/// @notice Emitted when deposit is called.
/// @param owner Owner address.
/// @param asset Deposited asset.
/// @param amount Deposited asset amount.
event Deposit(address indexed owner, IERC20 indexed asset, uint256 amount);
/// @notice Emitted when withdraw is called.
/// @param owner Owner address.
/// @param asset Withdrawn asset.
/// @param amount Withdrawn asset amount.
event Withdraw(
address indexed owner, IERC20 indexed asset, uint256 amount
);
/// @notice Emitted when guardian is set.
/// @param guardian Address of new guardian.
/// @param feeRecipient Address of new fee recipient.
event SetGuardianAndFeeRecipient(
address indexed guardian, address indexed feeRecipient
);
/// @notice Emitted when asset registry is set.
/// @param assetRegistry Address of new asset registry.
event SetAssetRegistry(address assetRegistry);
/// @notice Emitted when hooks is set.
/// @param hooks Address of new hooks.
event SetHooks(address hooks);
/// @notice Emitted when execute is called.
/// @param owner Owner address.
/// @param operation Struct details for target and calldata.
event Executed(address indexed owner, Operation operation);
/// @notice Emitted when vault is finalized.
/// @param owner Owner address.
/// @param withdrawnAmounts Struct details for withdrawn assets and amounts (sent to owner).
event Finalized(address indexed owner, AssetValue[] withdrawnAmounts);
/// @notice Emitted when submit is called.
/// @param guardian Guardian address.
/// @param operations Array of struct details for targets and calldatas.
event Submitted(address indexed guardian, Operation[] operations);
/// @notice Emitted when guardian fees are claimed.
/// @param feeRecipient Fee recipient address.
/// @param claimedFee Claimed amount of fee token.
/// @param unclaimedFee Unclaimed amount of fee token (unclaimed because Vault does not have enough balance of feeToken).
/// @param feeTotal New total reserved fee value.
event Claimed(
address indexed feeRecipient,
uint256 claimedFee,
uint256 unclaimedFee,
uint256 feeTotal
);
/// @notice Emitted when new fees are reserved for recipient.
/// @param feeRecipient Fee recipient address.
/// @param newFee Fee amount reserved.
/// @param lastFeeCheckpoint Updated fee checkpoint.
/// @param lastValue Last registered vault value.
/// @param lastFeeTokenPrice Last registered fee token price.
/// @param feeTotal New total reserved fee value.
event FeesReserved(
address indexed feeRecipient,
uint256 newFee,
uint256 lastFeeCheckpoint,
uint256 lastValue,
uint256 lastFeeTokenPrice,
uint256 feeTotal
);
/// @notice Emitted when no fees are reserved.
/// @param lastFeeCheckpoint Updated fee checkpoint.
/// @param lastValue Last registered vault value.
/// @param feeTotal New total reserved fee value.
event NoFeesReserved(
uint256 lastFeeCheckpoint,
uint256 lastValue,
uint256 feeTotal
);
/// @notice Emitted when the call to get spot prices from the asset registry reverts.
/// @param reason Revert reason.
event SpotPricesReverted(bytes reason);
}
IAeraV2Factory.sol 67 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;
import {
AssetRegistryParameters,
HooksParameters,
VaultParameters
} from "../Types.sol";
/// @title IAeraV2Factory
/// @notice Interface for the V2 vault factory.
interface IAeraV2Factory {
/// @notice Create V2 vault.
/// @param saltInput The salt input value to generate salt.
/// @param description Vault description.
/// @param vaultParameters Struct details for vault deployment.
/// @param assetRegistryParameters Struct details for asset registry deployment.
/// @param hooksParameters Struct details for hooks deployment.
/// @return deployedVault The address of deployed vault.
/// @return deployedAssetRegistry The address of deployed asset registry.
/// @return deployedHooks The address of deployed hooks.
function create(
bytes32 saltInput,
string calldata description,
VaultParameters calldata vaultParameters,
AssetRegistryParameters memory assetRegistryParameters,
HooksParameters memory hooksParameters
)
external
returns (
address deployedVault,
address deployedAssetRegistry,
address deployedHooks
);
/// @notice Calculate deployment address of V2 vault.
/// @param saltInput The salt input value to generate salt.
/// @param description Vault description.
/// @param vaultParameters Struct details for vault deployment.
function computeVaultAddress(
bytes32 saltInput,
string calldata description,
VaultParameters calldata vaultParameters
) external view returns (address);
/// @notice Returns the address of wrapped native token.
function wrappedNativeToken() external view returns (address);
/// @notice Returns vault parameters for vault deployment.
/// @return owner Initial owner address.
/// @return assetRegistry Asset registry address.
/// @return hooks Hooks address.
/// @return guardian Guardian address.
/// @return feeRecipient Fee recipient address.
/// @return fee Fees accrued per second, denoted in 18 decimal fixed point format.
function parameters()
external
view
returns (
address owner,
address assetRegistry,
address hooks,
address guardian,
address feeRecipient,
uint256 fee
);
}
IAssetRegistry.sol 62 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;
import "@chainlink/interfaces/AggregatorV2V3Interface.sol";
import "@openzeppelin/IERC20.sol";
/// @title IAssetRegistry
/// @notice Asset registry interface.
/// @dev Any implementation MUST also implement Ownable2Step and ERC165.
interface IAssetRegistry {
/// @param asset Asset address.
/// @param heartbeat Frequency of oracle price updates.
/// @param isERC4626 True if yield-bearing asset, false if just an ERC20 asset.
/// @param oracle If applicable, oracle address for asset.
struct AssetInformation {
IERC20 asset;
uint256 heartbeat;
bool isERC4626;
AggregatorV2V3Interface oracle;
}
/// @param asset Asset address.
/// @param spotPrice Spot price of an asset in Numeraire token terms.
struct AssetPriceReading {
IERC20 asset;
uint256 spotPrice;
}
/// @notice Get address of vault.
/// @return vault Address of vault.
function vault() external view returns (address vault);
/// @notice Get a list of all registered assets.
/// @return assets List of assets.
/// @dev MUST return assets in an order sorted by address.
function assets()
external
view
returns (AssetInformation[] memory assets);
/// @notice Get address of fee token.
/// @return feeToken Address of fee token.
/// @dev Represented as an address for efficiency reasons.
/// @dev MUST be present in assets array.
function feeToken() external view returns (IERC20 feeToken);
/// @notice Get the index of the Numeraire token in the assets array.
/// @return numeraireToken Numeraire token address.
/// @dev Represented as an index for efficiency reasons.
/// @dev MUST be a number between 0 (inclusive) and the length of assets array (exclusive).
function numeraireToken() external view returns (IERC20 numeraireToken);
/// @notice Calculate spot prices of non-ERC4626 assets.
/// @return spotPrices Spot prices of non-ERC4626 assets in 18 decimals.
/// @dev MUST return assets in the same order as in assets but with ERC4626 assets filtered out.
/// @dev MUST also include Numeraire token (spot price = 1).
/// @dev MAY revert if oracle prices for any asset are unreliable at the time.
function spotPrices()
external
view
returns (AssetPriceReading[] memory spotPrices);
}
Math.sol 339 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}
ERC165.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
IERC20.sol 78 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
IERC165.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 IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "./Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
IERC4626.sol 232 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC4626.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./IERC20Metadata.sol";
/**
* @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in
* https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
*
* _Available since v4.7._
*/
interface IERC4626 is IERC20, IERC20Metadata {
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
event Withdraw(
address indexed sender,
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares
);
/**
* @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
*
* - MUST be an ERC-20 token contract.
* - MUST NOT revert.
*/
function asset() external view returns (address assetTokenAddress);
/**
* @dev Returns the total amount of the underlying asset that is “managed” by Vault.
*
* - SHOULD include any compounding that occurs from yield.
* - MUST be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT revert.
*/
function totalAssets() external view returns (uint256 totalManagedAssets);
/**
* @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToShares(uint256 assets) external view returns (uint256 shares);
/**
* @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToAssets(uint256 shares) external view returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
* through a deposit call.
*
* - MUST return a limited value if receiver is subject to some deposit limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
* - MUST NOT revert.
*/
function maxDeposit(address receiver) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
* call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
* in the same transaction.
* - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
* deposit would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewDeposit(uint256 assets) external view returns (uint256 shares);
/**
* @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* deposit execution, and are accounted for during deposit.
* - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function deposit(uint256 assets, address receiver) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
* - MUST return a limited value if receiver is subject to some mint limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
* - MUST NOT revert.
*/
function maxMint(address receiver) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
* in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
* same transaction.
* - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
* would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by minting.
*/
function previewMint(uint256 shares) external view returns (uint256 assets);
/**
* @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
* execution, and are accounted for during mint.
* - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function mint(uint256 shares, address receiver) external returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
* Vault, through a withdraw call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxWithdraw(address owner) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
* call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
* called
* in the same transaction.
* - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
* the withdrawal would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewWithdraw(uint256 assets) external view returns (uint256 shares);
/**
* @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* withdraw execution, and are accounted for during withdraw.
* - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
* through a redeem call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxRedeem(address owner) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
* in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
* same transaction.
* - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
* redemption would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by redeeming.
*/
function previewRedeem(uint256 shares) external view returns (uint256 assets);
/**
* @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* redeem execution, and are accounted for during redeem.
* - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}
Pausable.sol 105 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "./Context.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 Pausable is Context {
/**
* @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.
*/
constructor() {
_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());
}
}
SafeERC20.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./IERC20Permit.sol";
import "./Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to
* 0 before setting it to a non-zero value.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}
IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
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);
}
Ownable2Step.sol 57 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.0;
import "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
require(pendingOwner() == sender, "Ownable2Step: caller is not the new owner");
_transferOwnership(sender);
}
}
ERC165Checker.sol 126 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/introspection/ERC165Checker.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Library used to query support of an interface declared via {IERC165}.
*
* Note that these functions return the actual result of the query: they do not
* `revert` if an interface is not supported. It is up to the caller to decide
* what to do in these cases.
*/
library ERC165Checker {
// As per the EIP-165 spec, no interface should ever match 0xffffffff
bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;
/**
* @dev Returns true if `account` supports the {IERC165} interface.
*/
function supportsERC165(address account) internal view returns (bool) {
// Any contract that implements ERC165 must explicitly indicate support of
// InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
return
supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) &&
!supportsERC165InterfaceUnchecked(account, _INTERFACE_ID_INVALID);
}
/**
* @dev Returns true if `account` supports the interface defined by
* `interfaceId`. Support for {IERC165} itself is queried automatically.
*
* See {IERC165-supportsInterface}.
*/
function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {
// query support of both ERC165 as per the spec and support of _interfaceId
return supportsERC165(account) && supportsERC165InterfaceUnchecked(account, interfaceId);
}
/**
* @dev Returns a boolean array where each value corresponds to the
* interfaces passed in and whether they're supported or not. This allows
* you to batch check interfaces for a contract where your expectation
* is that some interfaces may not be supported.
*
* See {IERC165-supportsInterface}.
*
* _Available since v3.4._
*/
function getSupportedInterfaces(
address account,
bytes4[] memory interfaceIds
) internal view returns (bool[] memory) {
// an array of booleans corresponding to interfaceIds and whether they're supported or not
bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);
// query support of ERC165 itself
if (supportsERC165(account)) {
// query support of each interface in interfaceIds
for (uint256 i = 0; i < interfaceIds.length; i++) {
interfaceIdsSupported[i] = supportsERC165InterfaceUnchecked(account, interfaceIds[i]);
}
}
return interfaceIdsSupported;
}
/**
* @dev Returns true if `account` supports all the interfaces defined in
* `interfaceIds`. Support for {IERC165} itself is queried automatically.
*
* Batch-querying can lead to gas savings by skipping repeated checks for
* {IERC165} support.
*
* See {IERC165-supportsInterface}.
*/
function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {
// query support of ERC165 itself
if (!supportsERC165(account)) {
return false;
}
// query support of each interface in interfaceIds
for (uint256 i = 0; i < interfaceIds.length; i++) {
if (!supportsERC165InterfaceUnchecked(account, interfaceIds[i])) {
return false;
}
}
// all interfaces supported
return true;
}
/**
* @notice Query if a contract implements an interface, does not check ERC165 support
* @param account The address of the contract to query for support of an interface
* @param interfaceId The interface identifier, as specified in ERC-165
* @return true if the contract at account indicates support of the interface with
* identifier interfaceId, false otherwise
* @dev Assumes that account contains a contract that supports ERC165, otherwise
* the behavior of this method is undefined. This precondition can be checked
* with {supportsERC165}.
*
* Some precompiled contracts will falsely indicate support for a given interface, so caution
* should be exercised when using this function.
*
* Interface identification is specified in ERC-165.
*/
function supportsERC165InterfaceUnchecked(address account, bytes4 interfaceId) internal view returns (bool) {
// prepare call
bytes memory encodedParams = abi.encodeWithSelector(IERC165.supportsInterface.selector, interfaceId);
// perform static call
bool success;
uint256 returnSize;
uint256 returnValue;
assembly {
success := staticcall(30000, account, add(encodedParams, 0x20), mload(encodedParams), 0x00, 0x20)
returnSize := returndatasize()
returnValue := mload(0x00)
}
return success && returnSize >= 0x20 && returnValue > 0;
}
}
IERC20Metadata.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
ReentrancyGuard.sol 77 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @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 ReentrancyGuard {
// 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;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
AggregatorInterface.sol 18 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface AggregatorInterface {
function latestAnswer() external view returns (int256);
function latestTimestamp() external view returns (uint256);
function latestRound() external view returns (uint256);
function getAnswer(uint256 roundId) external view returns (int256);
function getTimestamp(uint256 roundId) external view returns (uint256);
event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 updatedAt);
event NewRound(uint256 indexed roundId, address indexed startedBy, uint256 startedAt);
}
AggregatorV3Interface.sol 35 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
// getRoundData and latestRoundData should both raise "No data present"
// if they do not have data to report, instead of returning unset values
// which could be misinterpreted as actual reported values.
function getRoundData(uint80 _roundId)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}
AggregatorV2V3Interface.sol 7 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./AggregatorInterface.sol";
import "./AggregatorV3Interface.sol";
interface AggregatorV2V3Interface is AggregatorInterface, AggregatorV3Interface {}
Read Contract
assetRegistry 0x979d7e86 → address
fee 0xddca3f43 → uint256
feeRecipient 0x46904840 → address
feeTotal 0x37bfc1ef → uint256
fees 0xfaaebd21 → uint256
finalized 0xb3f05b97 → bool
guardian 0x452a9320 → address
holdings 0xe79bf13b → tuple[]
hooks 0xcd7033c4 → address
lastFeeCheckpoint 0x779b3c00 → uint256
lastFeeTokenPrice 0x2575e80b → uint256
lastValue 0x43183834 → uint256
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
pendingOwner 0xe30c3978 → address
renounceOwnership 0x715018a6
supportsInterface 0x01ffc9a7 → bool
value 0x3fa4f245 → uint256
wrappedNativeToken 0x17fcb39b → address
Write Contract 12 functions
These functions modify contract state and require a wallet transaction to execute.
acceptOwnership 0x79ba5097
No parameters
claim 0x4e71d92d
No parameters
deposit 0xe00f4b6e
tuple[] amounts
execute 0x1ff5a783
tuple operation
finalize 0x4bb278f3
No parameters
pause 0x8456cb59
No parameters
resume 0x046f7da2
No parameters
setGuardianAndFeeRecipient 0x69eb50ef
address newGuardian
address newFeeRecipient
setHooks 0xfb63daa1
address newHooks
submit 0x04f71751
tuple[] operations
transferOwnership 0xf2fde38b
address newOwner
withdraw 0x49dd205e
tuple[] amounts
Token Balances (2)
View Transfers →Recent Transactions
No transactions found for this address