Forkchoice Ethereum Mainnet

Address Contract Partially Verified

Address 0x45312ea0eFf7E09C83CBE249fa1d7598c4C8cd4e
Balance 0 ETH
Nonce 1
Code Size 15254 bytes
Last Active
Indexed Transactions 9 (24,591,38824,591,453)
Value (indexed) ↓ 2.3122 ETH
Gas Used (indexed) 3,204,870
External Etherscan · Sourcify

Contract Bytecode

15254 bytes
0x5f3560e01c60026007820660011b613b2801601e395f51565b6354fd4d5081186100965734613b245760208060805260056040527f312e322e3000000000000000000000000000000000000000000000000000000060605260408160800181518152602082015160208201528051806020830101601f825f03163682375050601f19601f8251602001011690509050810190506080f35b635c9c18e28118613b2257610563361115613b24576104c4358060a01c613b24576101a0526104e4358060a01c613b24576101c052610504358060a01c613b24576101e052610524358060a01c613b245761020052610544358060a01c613b245761022052336102405261115656613b22565b63371dc447811861012f576104c3361115613b245760a0366101a0373361024052611156565b63637653cb8118613b225761054436103417613b24576104a4358060a01c613b24576101a0526104c4358060a01c613b24576101c0526104e4358060a01c613b24576101e052610504358060a01c613b245761020052610524358060a01c613b2457610220525b6004358060a01c613b24576040526024358060a01c613b24576060526044358060a01c613b24576080526064358060a01c613b245760a0526084358060a01c613b245760c05260a4358060a01c613b245760e05260c4358060a01c613b24576101005260e4358060a01c613b245761012052610104358060a01c613b245761014052610124358060a01c613b245761016052610144358060a01c613b245761018052604051610240525f6102605261048435610280525f6005905b806102a0526102a0518060011b818160011c18613b2457905060018101818110613b24579050600a8111613b245760051b604001516102c0526102a05160048111613b245760051b6101a001516102e0526102a05160018101818110613b245790508060011b818160011c18613b24579050600a8111613b245760051b604001516102605260a06102a05160048111613b2457026101640180356103005260208101356103205260408101356103405260608101356103605260808101356103805250600161034051186103f8576103605160018118610332576001610338565b600a8118155b9050610393576102c05163556d6e9f6103a052610300516103c052610320516103e052610280516104005260206103a060646103bc845afa61037c573d5f5f3e3d5ffd5b60203d10613b24576103a09050516102805261105d565b6102c051635e0d443f6103c0526103005180607f1c613b24576103e0526103205180607f1c613b245761040052610280516104205260206103c060646103dc845afa6103e1573d5f5f3e3d5ffd5b60203d10613b24576103c09050516102805261105d565b600261034051186104dc57610360516001811861041657600161041c565b600a8118155b9050610477576102c0516385f11d1e6103a052610300516103c052610320516103e052610280516104005260206103a060646103bc845afa610460573d5f5f3e3d5ffd5b60203d10613b24576103a09050516102805261105d565b6102c0516307211ef76103c0526103005180607f1c613b24576103e0526103205180607f1c613b245761040052610280516104205260206103c060646103dc845afa6104c5573d5f5f3e3d5ffd5b60203d10613b24576103c09050516102805261105d565b600361034051186105c85761036051600181186104fa576001610500565b600a8118155b9050610563576102c05163e9737ee26103a0526102e0516103c052610300516103e0526103205161040052610280516104205260206103a060846103bc845afa61054c573d5f5f3e3d5ffd5b60203d10613b24576103a09050516102805261105d565b6102e0516307211ef76103c0526103005180607f1c613b24576103e0526103205180607f1c613b245761040052610280516104205260206103c060646103dc845afa6105b1573d5f5f3e3d5ffd5b60203d10613b24576103c09050516102805261105d565b61034051600481186105db5760016105e1565b60058118155b9050610b395761034051600681186105fa576001610600565b60078118155b9050610a7857600861034051186108fe576020613b365f395f51610240511861062a5760016106ce565b6020613b365f395f5161026051186106435760016106ce565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee61024051186106815773ae7ab96520de3a18e5e111b5eaab095312d7fe84610260511815610683565b5f5b6106cb5773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee61024051186106c557735e8422345238f34275888049021821e8e08caa1f6102605118156106ce565b5f6106ce565b60015b61105d57737f39c581f595b53c5cb19bd0b3f8da6c935e2ca06102405118610735576102c05163bb2952fc6103a052610280516103c05260206103a060246103bc845afa61071e573d5f5f3e3d5ffd5b60203d10613b24576103a09050516102805261105d565b737f39c581f595b53c5cb19bd0b3f8da6c935e2ca06102605118610798576102c05163b0e389006103a052610280516103c05260206103a060246103bc845afa610781573d5f5f3e3d5ffd5b60203d10613b24576103a09050516102805261105d565b73a2e3356610840701bdf5611a53974510ae27e2e161026051186108225761028051670de0b6b3a7640000810281670de0b6b3a7640000820418613b245790506102c051633ba0b9a96103a05260206103a060046103bc845afa6107fe573d5f5f3e3d5ffd5b60203d10613b24576103a09050518015613b2457808204905090506102805261105d565b60636103a0527f5377617020747970652038206973206f6e6c7920666f7220455448203c2d3e206103c0527f574554482c20455448202d3e207374455448206f7220455448202d3e206672786103e0527f4554482c207374455448203c2d3e207773744554482c20455448202d3e207742610400527f4554480000000000000000000000000000000000000000000000000000000000610420526103a0506103a051806103c001601f825f031636823750506308c379a061036052602061038052601f19601f6103a051011660440161037cfd61105d5661105d565b60096103405118610a0f5761030051610956576102c05163c6e6f5926103a052610280516103c05260206103a060246103bc845afa61093f573d5f5f3e3d5ffd5b60203d10613b24576103a09050516102805261105d565b600161030051186109a6576102c0516307a2d13a6103a052610280516103c05260206103a060246103bc845afa61098f573d5f5f3e3d5ffd5b60203d10613b24576103a09050516102805261105d565b600b6103a0527f57726f6e6720696e6465780000000000000000000000000000000000000000006103c0526103a0506103a051806103c001601f825f031636823750506308c379a061036052602061038052601f19601f6103a051011660440161037cfd61105d565b600d6103a0527f42616420737761702074797065000000000000000000000000000000000000006103c0526103a0506103a051806103c001601f825f031636823750506308c379a061036052602061038052601f19601f6103a051011660440161037cfd61105d565b6103605160018118610a8b576001610a91565b600a8118155b9050610ae4576102c051634fb08c5e6103c052610280516103e052610320516104005260206103c060446103dc845afa610acd573d5f5f3e3d5ffd5b60203d10613b24576103c09050516102805261105d565b6102c05163cc2b27d76103e05261028051610400526103205180607f1c613b24576104205260206103e060446103fc845afa610b22573d5f5f3e3d5ffd5b60203d10613b24576103e09050516102805261105d565b60016103605118610bdc57610140366103c037610280516103005160098111613b245760051b6103c001526020613b565f395f516379ccdf49610500526102c0516105205261026051610540526101406105606101406103c060045afa50610380516106a05260016106c05260016106e05260206105006101e461051c845afa610bc5573d5f5f3e3d5ffd5b60203d10613b24576105009050516102805261105d565b600a6103605118610cad57610100366103e03760086103c05261028051610300516103c051811015613b245760051b6103e001526102c051633db06dd86104e0526040806105005280610500015f6103c0518083528060051b5f8260088111613b24578015610c6557905b8060051b6103e001518160051b602088010152600101818118610c47575b505082016020019150509050810190506001610520525060206104e06101646104fc845afa610c96573d5f5f3e3d5ffd5b60203d10613b24576104e09050516102805261105d565b60026103805118610d82576040366103c037610280516103005160018111613b245760051b6103c0015260026103605118610d2f576102c051638d8ea727610400526103c051610420526103e051610440526020610400604461041c845afa610d18573d5f5f3e3d5ffd5b60203d10613b24576104009050516102805261105d565b6102c05163ed8e84f3610400526103c051610420526103e051610440526001610460526020610400606461041c845afa610d6b573d5f5f3e3d5ffd5b60203d10613b24576104009050516102805261105d565b60036103805118610e67576060366103c037610280516103005160028111613b245760051b6103c0015260026103605118610e0c576102c051635b6f1b5a610420526103c051610440526103e0516104605261040051610480526020610420606461043c845afa610df5573d5f5f3e3d5ffd5b60203d10613b24576104209050516102805261105d565b6102c051633883e119610420526103c051610440526103e05161046052610400516104805260016104a0526020610420608461043c845afa610e50573d5f5f3e3d5ffd5b60203d10613b24576104209050516102805261105d565b60046103805118610f5c576080366103c037610280516103005160038111613b245760051b6103c0015260026103605118610ef9576102c051631a805185610440526103c051610460526103e05161048052610400516104a052610420516104c0526020610440608461045c845afa610ee2573d5f5f3e3d5ffd5b60203d10613b24576104409050516102805261105d565b6102c05163cf701ff7610440526103c051610460526103e05161048052610400516104a052610420516104c05260016104e052602061044060a461045c845afa610f45573d5f5f3e3d5ffd5b60203d10613b24576104409050516102805261105d565b6005610380511861105d5760a0366103c037610280516103005160048111613b245760051b6103c0015260026103605118610ff6576102c0516309379690610460526103c051610480526103e0516104a052610400516104c052610420516104e0526104405161050052602061046060a461047c845afa610fdf573d5f5f3e3d5ffd5b60203d10613b24576104609050516102805261105d565b6102c051637ede89c5610460526103c051610480526103e0516104a052610400516104c052610420516104e0526104405161050052600161052052602061046060c461047c845afa61104a573d5f5f3e3d5ffd5b60203d10613b2457610460905051610280525b60046102a0511861106f5760016110a1565b6102a0518060011b818160011c18613b2457905060038101818110613b24579050600a8111613b245760051b60400151155b156110ab576110be565b6102605161024052600101818118610251575b50506102805160018103818111613b245790506102a05260206102a0f3613b22565b63c872a3c5811861277957610583361115613b24576104c4358060a01c613b24576101a0526104e4358060a01c613b24576101c052610504358060a01c613b24576101e052610524358060a01c613b245761020052610544358060a01c613b245761022052610564358060a01c613b2457610240525b6004358060a01c613b24576040526024358060a01c613b24576060526044358060a01c613b24576080526064358060a01c613b245760a0526084358060a01c613b245760c05260a4358060a01c613b245760e05260c4358060a01c613b24576101005260e4358060a01c613b245761012052610104358060a01c613b245761014052610124358060a01c613b245761016052610144358060a01c613b2457610180525f54600214613b245760025f55604051610260525f61028052610484356102a05273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6102605118611246576102a0513418613b24576112c0565b34613b2457610260516323b872dd6102c052336102e05230610300526102a0516103205260206102c060646102dc5f855af1611284573d5f5f3e3d5ffd5b3d61129b57803b15613b24576001610340526112b4565b60203d10613b24576102c0518060011c613b2457610340525b61034090505115613b24575b5f6005905b806102c0526102c0518060011b818160011c18613b2457905060018101818110613b24579050600a8111613b245760051b604001516102e0526102c05160048111613b245760051b6101a00151610300526102c05160018101818110613b245790508060011b818160011c18613b24579050600a8111613b245760051b604001516102805260a06102c05160048111613b2457026101640180356103205260208101356103405260408101356103605260608101356103805260808101356103a05250476103c05273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee61028051146113e957610280516370a082316103e052306104005260206103e060246103fc845afa6113d6573d5f5f3e3d5ffd5b60203d10613b24576103e09050516103c0525b6001610260516020525f5260405f20806102e0516020525f5260405f209050546114b0576102605163095ea7b36103e0526102e051610400527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6104205260206103e060446103fc5f855af1611461573d5f5f3e3d5ffd5b3d61147157600161044052611482565b6103e0518060011c613b2457610440525b61044090505115613b245760016001610260516020525f5260405f20806102e0516020525f5260405f209050555b5f6103e05273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee61026051186114dc576102a0516103e0525b600161036051186116575761038051600181186114fa576001611500565b600a8118155b90506115f45773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee610260511861152b576001611547565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6102805118155b61159b576102e051635b41b90861040052610320516104205261034051610440526102a051610460525f61048052803b15613b24575f610400608461041c5f855af1611595573d5f5f3e3d5ffd5b50612436565b6102e05163394747c561040052610320516104205261034051610440526102a051610460525f6104805260016104a052803b15613b24575f61040060a461041c6103e051855af16115ee573d5f5f3e3d5ffd5b50612436565b6102e051633df02124610420526103205180607f1c613b2457610440526103405180607f1c613b2457610460526102a051610480525f6104a052803b15613b24575f610420608461043c6103e051855af1611651573d5f5f3e3d5ffd5b50612436565b6002610360511861173757610380516001811861167557600161167b565b600a8118155b90506116d4576102e0516365b2489b61040052610320516104205261034051610440526102a051610460525f61048052803b15613b24575f610400608461041c6103e051855af16116ce573d5f5f3e3d5ffd5b50612436565b6102e05163a6417ed6610420526103205180607f1c613b2457610440526103405180607f1c613b2457610460526102a051610480525f6104a052803b15613b24575f610420608461043c6103e051855af1611731573d5f5f3e3d5ffd5b50612436565b6003610360511861187157610380516001811861175557600161175b565b600a8118155b90506118095773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee61026051186117865760016117a2565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6102805118155b610400526102e051632bf78c61610420526103005161044052610320516104605261034051610480526102a0516104a0525f6104c052610400516104e052803b15613b24575f61042060c461043c6103e051855af1611803573d5f5f3e3d5ffd5b50612436565b6102e051637981c43e6104205261030051610440526103205180607f1c613b2457610460526103405180607f1c613b2457610480526102a0516104a0525f6104c052803b15613b24575f61042060a461043c5f855af161186b573d5f5f3e3d5ffd5b50612436565b60046103605118611c2e57600a61038051186119485761010036610420376008610400526102a0516103205161040051811015613b245760051b61042001526102e05163b72df5de610520526040806105405280610540015f610400518083528060051b5f8260088111613b2457801561190557905b8060051b61042001518160051b6020880101526001018181186118e7575b505082016020019150509050810190505f6105605250602061052061016461053c5f855af1611936573d5f5f3e3d5ffd5b60203d10613b24576105205050612436565b601e6103805118611a2a57606036610400376102a0516103205160028111613b245760051b61040001526103e051156119da576102e051632b6e993a610460526104005161048052610420516104a052610440516104c0525f6104e052600161050052602061046060a461047c6103e051855af16119c8573d5f5f3e3d5ffd5b60203d10613b24576104605050612436565b6102e051634515cef3610460526104005161048052610420516104a052610440516104c0525f6104e052803b15613b24575f610460608461047c5f855af1611a24573d5f5f3e3d5ffd5b50612436565b60026103a05118611a9f57604036610400376102a0516103205160018111613b245760051b61040001526102e051630b4c7e4d61044052610400516104605261042051610480525f6104a052803b15613b24575f610440606461045c6103e051855af1611a99573d5f5f3e3d5ffd5b50612436565b60036103a05118611b1c57606036610400376102a0516103205160028111613b245760051b61040001526102e051634515cef3610460526104005161048052610420516104a052610440516104c0525f6104e052803b15613b24575f610460608461047c6103e051855af1611b16573d5f5f3e3d5ffd5b50612436565b60046103a05118611ba157608036610400376102a0516103205160038111613b245760051b61040001526102e05163029b2f3461048052610400516104a052610420516104c052610440516104e05261046051610500525f61052052803b15613b24575f61048060a461049c6103e051855af1611b9b573d5f5f3e3d5ffd5b50612436565b60056103a051186124365760a036610400376102a0516103205160048111613b245760051b61040001526102e05163847384996104a052610400516104c052610420516104e0526104405161050052610460516105205261048051610540525f61056052803b15613b24575f6104a060c46104bc6103e051855af1611c28573d5f5f3e3d5ffd5b50612436565b60056103605118611cb157606036610400376102a0516103205160028111613b245760051b61040001526102e051632b6e993a610460526104005161048052610420516104a052610440516104c0525f6104e052600161050052803b15613b24575f61046060a461047c6103e051855af1611cab573d5f5f3e3d5ffd5b50612436565b60066103605118611df8576103805160018118611ccf576001611cd5565b600a8118155b9050611da857601e6103805118611d065773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee610280511815611d08565b5f5b611d54576102e05163f1dc3cc9610400526102a0516104205261034051610440525f61046052803b15613b24575f610400606461041c5f855af1611d4e573d5f5f3e3d5ffd5b50612436565b6102e051638f15b6b5610400526102a0516104205261034051610440525f610460526001610480526020610400608461041c5f855af1611d96573d5f5f3e3d5ffd5b60203d10613b24576104005050612436565b6102e051631a4d01d2610420526102a051610440526103405180607f1c613b2457610460525f61048052803b15613b24575f610420606461043c5f855af1611df2573d5f5f3e3d5ffd5b50612436565b60076103605118611e5f576102e05163517a55a3610400526102a051610420526103405180607f1c613b2457610440525f610460526001610480526020610400608461041c5f855af1611e4d573d5f5f3e3d5ffd5b60203d10613b24576104005050612436565b600861036051186122b95773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6102605118611e9c576020613b365f395f51610280511815611e9e565b5f5b612283576020613b365f395f516102605118611ed45773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee610280511815611ed6565b5f5b6122485773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6102605118611f185773ae7ab96520de3a18e5e111b5eaab095312d7fe84610280511815611f1a565b5f5b61220d5773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6102605118611f5c57735e8422345238f34275888049021821e8e08caa1f610280511815611f5e565b5f5b6121d75773ae7ab96520de3a18e5e111b5eaab095312d7fe846102605118611fa057737f39c581f595b53c5cb19bd0b3f8da6c935e2ca0610280511815611fa2565b5f5b61219657737f39c581f595b53c5cb19bd0b3f8da6c935e2ca06102605118611fe45773ae7ab96520de3a18e5e111b5eaab095312d7fe84610280511815611fe6565b5f5b6121555773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee61026051186120285773a2e3356610840701bdf5611a53974510ae27e2e161028051181561202a565b5f5b612106576063610400527f5377617020747970652038206973206f6e6c7920666f7220455448203c2d3e20610420527f574554482c20455448202d3e207374455448206f7220455448202d3e20667278610440527f4554482c207374455448203c2d3e207773744554482c20455448202d3e207742610460527f45544800000000000000000000000000000000000000000000000000000000006104805261040050610400518061042001601f825f031636823750506308c379a06103c05260206103e052601f19601f6104005101166044016103dcfd612436565b6102e05163f340fa016104005273ecb456ea5365865ebab8a2661b0c503410e9b34761042052803b15613b24575f610400602461041c6102a051855af161214f573d5f5f3e3d5ffd5b50612436565b6102e05163de0e9a3e610400526102a051610420526020610400602461041c5f855af1612184573d5f5f3e3d5ffd5b60203d10613b24576104005050612436565b6102e05163ea598cb0610400526102a051610420526020610400602461041c5f855af16121c5573d5f5f3e3d5ffd5b60203d10613b24576104005050612436565b6102e051635bcb2fc661040052803b15613b24575f610400600461041c6102a051855af1612207573d5f5f3e3d5ffd5b50612436565b6102e05163a1903eab610400525f61042052803b15613b24575f610400602461041c6102a051855af1612242573d5f5f3e3d5ffd5b50612436565b6102e051632e1a7d4d610400526102a05161042052803b15613b24575f610400602461041c5f855af161227d573d5f5f3e3d5ffd5b50612436565b6102e05163d0e30db061040052803b15613b24575f610400600461041c6102a051855af16122b3573d5f5f3e3d5ffd5b50612436565b600961036051186123d15761032051612312576102e051636e553f65610400526102a0516104205230610440526020610400604461041c5f855af1612300573d5f5f3e3d5ffd5b60203d10613b24576104005050612436565b60016103205118612368576102e05163ba087652610400526102a05161042052306104405230610460526020610400606461041c5f855af1612356573d5f5f3e3d5ffd5b60203d10613b24576104005050612436565b600b610400527f57726f6e6720696e6465780000000000000000000000000000000000000000006104205261040050610400518061042001601f825f031636823750506308c379a06103c05260206103e052601f19601f6104005101166044016103dcfd612436565b600d610400527f42616420737761702074797065000000000000000000000000000000000000006104205261040050610400518061042001601f825f031636823750506308c379a06103c05260206103e052601f19601f6104005101166044016103dcfd5b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee610280511861245e57476102a05261249c565b610280516370a082316104005230610420526020610400602461041c845afa612489573d5f5f3e3d5ffd5b60203d10613b24576104009050516102a0525b6102a0516103c051808203828111613b24579050905061251b576010610400527f5265636569766564206e6f7468696e67000000000000000000000000000000006104205261040050610400518061042001601f825f031636823750506308c379a06103c05260206103e052601f19601f6104005101166044016103dcfd5b60046102c0511861252d57600161255f565b6102c0518060011b818160011c18613b2457905060038101818110613b24579050600a8111613b245760051b60400151155b156125695761257c565b61028051610260526001018181186112c5575b50506102a05160018103818111613b245790506102a0526104a4356102a05110156126065760086102c0527f536c6970706167650000000000000000000000000000000000000000000000006102e0526102c0506102c051806102e001601f825f031636823750506308c379a06102805260206102a052601f19601f6102c051011660440161029cfd5b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee610280511861265957610240516102a0515a5f6102c0526102c0505f5f6102c0516102e0858786f19050905090506126cc573d5f5f3e3d5ffd6126cc565b6102805163a9059cbb6102c052610240516102e0526102a0516103005260206102c060446102dc5f855af1612690573d5f5f3e3d5ffd5b3d6126a757803b15613b24576001610320526126c0565b60203d10613b24576102c0518060011c613b2457610320525b61032090505115613b24575b61024051337f56d0661e240dfb199ef196e16e6f42473990366314f0226ac978f7be3cd9ee836101606102c0610160604060045afa5060a06101646104203760a06102046104c03760a06102a46105603760a06103446106003760a06103e46106a0376101a051610740526101c051610760526101e05161078052610200516107a052610220516107c052610484356107e0526102a051610800526105606102c0a360206102a060035f55f35b6390e7e2058118613b225761068436103417613b2457610544358060a01c613b245761024052610564358060a01c613b245761026052610584358060a01c613b2457610280526105a4358060a01c613b24576102a0526105c4358060a01c613b24576102c0526105e4358060a01c613b24576102e052610604358060a01c613b245761030052610624358060a01c613b245761032052610644358060a01c613b245761034052610664358060a01c613b2457610360525b6004358060a01c613b24576040526024358060a01c613b24576060526044358060a01c613b24576080526064358060a01c613b245760a0526084358060a01c613b245760c05260a4358060a01c613b245760e05260c4358060a01c613b24576101005260e4358060a01c613b245761012052610104358060a01c613b245761014052610124358060a01c613b245761016052610144358060a01c613b2457610180526104a4358060a01c613b24576101a0526104c4358060a01c613b24576101c0526104e4358060a01c613b24576101e052610504358060a01c613b245761020052610524358060a01c613b24576102205261048435610380525f6005905b806103a0526103a0518060040360048111613b245790506103c0526103c0518060011b818160011c18613b2457905060018101818110613b24579050600a8111613b245760051b604001516103e0526103e05161298b57613a47565b6103c0518060011b818160011c18613b24579050600a8111613b245760051b60400151610400526103c05160018101818110613b245790508060011b818160011c18613b24579050600a8111613b245760051b60400151610420526103c05160048111613b245760051b6101a00151610440526103c05160048111613b245760051b6102400151610460526103c05160048111613b245760051b6102e001516104805260a06103c05160048111613b2457026101640180356104a05260208101356104c05260408101356104e05260608101356105005260808101356105205250610520516105405260016104e05118612cdc5760016105005118612b8e5761046051612b0c576020613b565f395f5163158819d46105605261044051610580526104a05180607f1c613b24576105a0526104c05180607f1c613b24576105c052610380516105e0526105405161060052602061056060a461057c845afa612af5573d5f5f3e3d5ffd5b60203d10613b245761056090505161038052613a47565b6020613b565f395f5163571f00b56105605261044051610580526104a05180607f1c613b24576105a0526104c05180607f1c613b24576105c052610380516105e05261054051610600526104605161062052602061056060c461057c845afa612b77573d5f5f3e3d5ffd5b60203d10613b245761056090505161038052613a47565b600a6105005118612bfe57610440516367df02ca610560526104a05180607f1c613b2457610580526104c05180607f1c613b24576105a052610380516105c0526020610560606461057c845afa612be7573d5f5f3e3d5ffd5b60203d10613b245761056090505161038052613a47565b6105005160028118612c11576001612c17565b60038118155b9050612c7257610440516337ed3a7a610560526104a051610580526104c0516105a052610380516105c0526020610560606461057c845afa612c5b573d5f5f3e3d5ffd5b60203d10613b245761056090505161038052613a47565b6020613b765f395f5163ca4bc71461058052610440516105a0526104a0516105c0526104c0516105e05261038051610600526105405161062052602061058060a461059c845afa612cc5573d5f5f3e3d5ffd5b60203d10613b245761058090505161038052613a47565b6104e05160028118612cef576001612cf5565b60038118155b9050613784576104e05160048118612d0e576001612d14565b60058118155b90506136c3576104e05160068118612d2d576001612d33565b60078118155b90506131a15760086104e05118613027576020613b365f395f516104005118612d5d576001612e01565b6020613b365f395f516104205118612d76576001612e01565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6104005118612db45773ae7ab96520de3a18e5e111b5eaab095312d7fe84610420511815612db6565b5f5b612dfe5773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6104005118612df857735e8422345238f34275888049021821e8e08caa1f610420511815612e01565b5f612e01565b60015b613a4757737f39c581f595b53c5cb19bd0b3f8da6c935e2ca06104005118612e68576103e05163b0e389006105605261038051610580526020610560602461057c845afa612e51573d5f5f3e3d5ffd5b60203d10613b245761056090505161038052613a47565b737f39c581f595b53c5cb19bd0b3f8da6c935e2ca06104205118612ecb576103e05163bb2952fc6105605261038051610580526020610560602461057c845afa612eb4573d5f5f3e3d5ffd5b60203d10613b245761056090505161038052613a47565b73a2e3356610840701bdf5611a53974510ae27e2e16104205118612f4b57610380516103e051633ba0b9a9610560526020610560600461057c845afa612f13573d5f5f3e3d5ffd5b60203d10613b2457610560905051808202811583838304141715613b245790509050670de0b6b3a76400008104905061038052613a47565b6063610560527f5377617020747970652038206973206f6e6c7920666f7220455448203c2d3e20610580527f574554482c20455448202d3e207374455448206f7220455448202d3e206672786105a0527f4554482c207374455448203c2d3e207773744554482c20455448202d3e2077426105c0527f45544800000000000000000000000000000000000000000000000000000000006105e05261056050610560518061058001601f825f031636823750506308c379a061052052602061054052601f19601f61056051011660440161053cfd613a4756613a47565b60096104e05118613138576104a05161307f576103e0516307a2d13a6105605261038051610580526020610560602461057c845afa613068573d5f5f3e3d5ffd5b60203d10613b245761056090505161038052613a47565b60016104a051186130cf576103e05163c6e6f5926105605261038051610580526020610560602461057c845afa6130b8573d5f5f3e3d5ffd5b60203d10613b245761056090505161038052613a47565b600b610560527f57726f6e6720696e6465780000000000000000000000000000000000000000006105805261056050610560518061058001601f825f031636823750506308c379a061052052602061054052601f19601f61056051011660440161053cfd613a47565b600d610560527f42616420737761702074797065000000000000000000000000000000000000006105805261056050610560518061058001601f825f031636823750506308c379a061052052602061054052601f19601f61056051011660440161053cfd613a47565b60016105005118613243576101403661058037610380516104c05160098111613b245760051b61058001526020613b565f395f516379ccdf496106c0526103e0516106e052610400516107005261014061072061014061058060045afa5061054051610860525f6108805260016108a05260206106c06101e46106dc845afa61322c573d5f5f3e3d5ffd5b60203d10613b24576106c090505161038052613a47565b600a610500511861331357610100366105a037600861058052610380516104c05161058051811015613b245760051b6105a001526103e051633db06dd86106a0526040806106c052806106c0015f610580518083528060051b5f8260088111613b245780156132cc57905b8060051b6105a001518160051b6020880101526001018181186132ae575b505082016020019150509050810190505f6106e0525060206106a06101646106bc845afa6132fc573d5f5f3e3d5ffd5b60203d10613b24576106a090505161038052613a47565b600261054051186133e75760403661058037610380516104c05160018111613b245760051b610580015260026105005118613395576103e051638d8ea7276105c052610580516105e0526105a0516106005260206105c060446105dc845afa61337e573d5f5f3e3d5ffd5b60203d10613b24576105c090505161038052613a47565b6103e05163ed8e84f36105c052610580516105e0526105a051610600525f6106205260206105c060646105dc845afa6133d0573d5f5f3e3d5ffd5b60203d10613b24576105c090505161038052613a47565b600361054051186134cb5760603661058037610380516104c05160028111613b245760051b610580015260026105005118613471576103e051635b6f1b5a6105e05261058051610600526105a051610620526105c0516106405260206105e060646105fc845afa61345a573d5f5f3e3d5ffd5b60203d10613b24576105e090505161038052613a47565b6103e051633883e1196105e05261058051610600526105a051610620526105c051610640525f6106605260206105e060846105fc845afa6134b4573d5f5f3e3d5ffd5b60203d10613b24576105e090505161038052613a47565b600461054051186135bf5760803661058037610380516104c05160038111613b245760051b61058001526002610500511861355d576103e051631a8051856106005261058051610620526105a051610640526105c051610660526105e051610680526020610600608461061c845afa613546573d5f5f3e3d5ffd5b60203d10613b245761060090505161038052613a47565b6103e05163cf701ff76106005261058051610620526105a051610640526105c051610660526105e051610680525f6106a052602061060060a461061c845afa6135a8573d5f5f3e3d5ffd5b60203d10613b245761060090505161038052613a47565b60056105405118613a475760a03661058037610380516104c05160048111613b245760051b610580015260026105005118613659576103e05163093796906106205261058051610640526105a051610660526105c051610680526105e0516106a052610600516106c052602061062060a461063c845afa613642573d5f5f3e3d5ffd5b60203d10613b245761062090505161038052613a47565b6103e051637ede89c56106205261058051610640526105a051610660526105c051610680526105e0516106a052610600516106c0525f6106e052602061062060c461063c845afa6136ac573d5f5f3e3d5ffd5b60203d10613b245761062090505161038052613a47565b61050051600181186136d65760016136dc565b600a8118155b905061372f576103e051634fb08c5e61058052610380516105a0526104a0516105c0526020610580604461059c845afa613718573d5f5f3e3d5ffd5b60203d10613b245761058090505161038052613a47565b6103e05163cc2b27d76105a052610380516105c0526104a05180607f1c613b24576105e05260206105a060446105bc845afa61376d573d5f5f3e3d5ffd5b60203d10613b24576105a090505161038052613a47565b6001610500511861389b5761046051613811576020613b565f395f51638fd3218f61058052610440516105a0526104a05180607f1c613b24576105c0526104c05180607f1c613b24576105e05261038051610600526105405161062052602061058060a461059c845afa6137fa573d5f5f3e3d5ffd5b60203d10613b245761058090505161038052613a47565b6020613b565f395f51634933a86461058052610440516105a0526104a05180607f1c613b24576105c0526104c05180607f1c613b24576105e0526103805161060052610540516106205261046051610640526104805161066052602061058060e461059c845afa613884573d5f5f3e3d5ffd5b60203d10613b245761058090505161038052613a47565b600a61050051186139d1576104a05180607f1c613b2457610580526104c05180607f1c613b24576105a05260016105805112156138d8575f6138e1565b60016105a05112155b61393a5761044051630e71d1b96105c052610580516105e0526105a05161060052610380516106205260206105c060646105dc845afa613923573d5f5f3e3d5ffd5b60203d10613b24576105c090505161038052613a47565b6020613b565f395f5163158819d46105c052610460516105e052610580516001810380600f0b8118613b24579050610600526105a0516001810380600f0b8118613b245790506106205261038051610640526105405160018103818111613b245790506106605260206105c060a46105dc845afa6139ba573d5f5f3e3d5ffd5b60203d10613b24576105c090505161038052613a47565b6020613b765f395f51638ca1565361058052610440516105a0526104a0516105c0526104c0516105e0526103805161060052610540516106205261046051610640526104805161066052602061058060e461059c845afa613a34573d5f5f3e3d5ffd5b60203d10613b2457610580905051610380525b60010181811861292f5750506020610380f3613b22565b6381889a2c8118613b22576104a436103417613b245760a0366101a03761019656613b22565b63c07b53538118613aa75761054436103417613b24576101403661024037612830565b6381fc0ca58118613b22576105e436103417613b2457610544358060a01c613b245761024052610564358060a01c613b245761026052610584358060a01c613b2457610280526105a4358060a01c613b24576102a0526105c4358060a01c613b24576102c05260a0366102e03761283056613b2256613b22565b5b005b5f80fd3b213b21010910e03a5e00183a84000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000ca8d0747b5573d69653c3ac22242e6341c36e4b4000000000000000000000000a72c85c258a81761433b4e8da60505fe3dd551cc

Verified Source Code Partial Match

Compiler: v0.3.10+commit.91361694
CurveRouterv1.2.vy 670 lines
# @version 0.3.10

"""
@title CurveRouter v1.2
@author Curve.Fi
@license Copyright (c) Curve.Fi, 2020-2024 - all rights reserved
@notice Performs up to 5 swaps in a single transaction, can do estimations with get_dy and get_dx
"""

version: public(constant(String[8])) = "1.2.0"


from vyper.interfaces import ERC20

interface StablePool:
    def get_dy(i: int128, j: int128, amount: uint256) -> uint256: view
    def exchange(i: int128, j: int128, dx: uint256, min_dy: uint256): payable
    def get_dy_underlying(i: int128, j: int128, amount: uint256) -> uint256: view
    def exchange_underlying(i: int128, j: int128, dx: uint256, min_dy: uint256): payable
    def calc_withdraw_one_coin(token_amount: uint256, i: int128) -> uint256: view
    def remove_liquidity_one_coin(token_amount: uint256, i: int128, min_amount: uint256): nonpayable

interface CryptoPool:
    def get_dy(i: uint256, j: uint256, amount: uint256) -> uint256: view
    def exchange(i: uint256, j: uint256, dx: uint256, min_dy: uint256): payable
    def get_dy_underlying(i: uint256, j: uint256, amount: uint256) -> uint256: view
    def exchange_underlying(i: uint256, j: uint256, dx: uint256, min_dy: uint256): payable
    def calc_withdraw_one_coin(token_amount: uint256, i: uint256) -> uint256: view
    def remove_liquidity_one_coin(token_amount: uint256, i: uint256, min_amount: uint256): nonpayable

interface StableNgPool:
    def get_dx(i: int128, j: int128, amount: uint256) -> uint256: view
    def get_dx_underlying(i: int128, j: int128, amount: uint256) -> uint256: view
    def calc_token_amount(_amounts: DynArray[uint256, 8], _is_deposit: bool) -> uint256: view
    def add_liquidity(_amounts: DynArray[uint256, 8], _min_mint_amount: uint256) -> uint256: nonpayable

interface CryptoNgPool:
    def get_dx(i: uint256, j: uint256, out_amount: uint256) -> uint256: view

interface TriCryptoNgETH:
    def add_liquidity(amounts: uint256[3], min_mint_amount: uint256, use_eth: bool) -> uint256: payable
    def remove_liquidity_one_coin(token_amount: uint256, i: uint256, min_amount: uint256, use_eth: bool) -> uint256: nonpayable

interface CryptoPoolETH:
    def exchange(i: uint256, j: uint256, dx: uint256, min_dy: uint256, use_eth: bool): payable

interface LendingBasePoolMetaZap:
    def exchange_underlying(pool: address, i: int128, j: int128, dx: uint256, min_dy: uint256): nonpayable

interface CryptoMetaZap:
    def get_dy(pool: address, i: uint256, j: uint256, dx: uint256) -> uint256: view
    def exchange(pool: address, i: uint256, j: uint256, dx: uint256, min_dy: uint256, use_eth: bool): payable

interface StablePool2Coins:
    def add_liquidity(amounts: uint256[2], min_mint_amount: uint256): payable
    def calc_token_amount(amounts: uint256[2], is_deposit: bool) -> uint256: view

interface CryptoPool2Coins:
    def calc_token_amount(amounts: uint256[2]) -> uint256: view

interface StablePool3Coins:
    def add_liquidity(amounts: uint256[3], min_mint_amount: uint256): payable
    def calc_token_amount(amounts: uint256[3], is_deposit: bool) -> uint256: view

interface CryptoPool3Coins:
    def calc_token_amount(amounts: uint256[3]) -> uint256: view

interface StablePool4Coins:
    def add_liquidity(amounts: uint256[4], min_mint_amount: uint256): payable
    def calc_token_amount(amounts: uint256[4], is_deposit: bool) -> uint256: view

interface CryptoPool4Coins:
    def calc_token_amount(amounts: uint256[4]) -> uint256: view

interface StablePool5Coins:
    def add_liquidity(amounts: uint256[5], min_mint_amount: uint256): payable
    def calc_token_amount(amounts: uint256[5], is_deposit: bool) -> uint256: view

interface CryptoPool5Coins:
    def calc_token_amount(amounts: uint256[5]) -> uint256: view

interface LendingStablePool3Coins:
    def add_liquidity(amounts: uint256[3], min_mint_amount: uint256, use_underlying: bool): payable
    def remove_liquidity_one_coin(token_amount: uint256, i: int128, min_amount: uint256, use_underlying: bool) -> uint256: nonpayable

interface WETH:
    def deposit(): payable
    def withdraw(_amount: uint256): nonpayable

interface stETH:
    def submit(_refferer: address): payable

interface frxETHMinter:
    def submit(): payable

interface wstETH:
    def getWstETHByStETH(_stETHAmount: uint256) -> uint256: view
    def getStETHByWstETH(_wstETHAmount: uint256) -> uint256: view
    def wrap(_stETHAmount: uint256) -> uint256: nonpayable
    def unwrap(_wstETHAmount: uint256) -> uint256: nonpayable

interface ERC4626:
    def convertToShares(assets: uint256) -> uint256: view
    def convertToAssets(shares: uint256) -> uint256: view
    def deposit(assets: uint256, receiver: address) -> uint256: nonpayable
    def redeem(shares: uint256, receiver: address, owner: address) -> uint256: nonpayable

interface wBETH:
    def deposit(referral: address): payable
    def exchangeRate() -> uint256: view

# Calc zaps
interface StableCalc:
    def calc_token_amount(pool: address, token: address, amounts: uint256[10], n_coins: uint256, deposit: bool, use_underlying: bool) -> uint256: view
    def get_dx(pool: address, i: int128, j: int128, dy: uint256, n_coins: uint256) -> uint256: view
    def get_dx_underlying(pool: address, i: int128, j: int128, dy: uint256, n_coins: uint256) -> uint256: view
    def get_dx_meta(pool: address, i: int128, j: int128, dy: uint256, n_coins: uint256, base_pool: address) -> uint256: view
    def get_dx_meta_underlying(pool: address, i: int128, j: int128, dy: uint256, n_coins: uint256, base_pool: address, base_token: address) -> uint256: view

interface CryptoCalc:
    def get_dx(pool: address, i: uint256, j: uint256, dy: uint256, n_coins: uint256) -> uint256: view
    def get_dx_meta_underlying(pool: address, i: uint256, j: uint256, dy: uint256, n_coins: uint256, base_pool: address, base_token: address) -> uint256: view


event Exchange:
    sender: indexed(address)
    receiver: indexed(address)
    route: address[11]
    swap_params: uint256[5][5]
    pools: address[5]
    in_amount: uint256
    out_amount: uint256


ETH_ADDRESS: constant(address) = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
STETH_ADDRESS: constant(address) = 0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84
WSTETH_ADDRESS: constant(address) = 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0
FRXETH_ADDRESS: constant(address) = 0x5E8422345238F34275888049021821E8E08CAa1f
WBETH_ADDRESS: constant(address) = 0xa2E3356610840701BDf5611a53974510Ae27E2e1
WETH_ADDRESS: immutable(address)

# Calc zaps
STABLE_CALC: immutable(StableCalc)
CRYPTO_CALC: immutable(CryptoCalc)

is_approved: HashMap[address, HashMap[address, bool]]


@external
@payable
def __default__():
    pass


@external
def __init__( _weth: address, _stable_calc: address, _crypto_calc: address):
    self.is_approved[WSTETH_ADDRESS][WSTETH_ADDRESS] = True

    WETH_ADDRESS = _weth
    STABLE_CALC = StableCalc(_stable_calc)
    CRYPTO_CALC = CryptoCalc(_crypto_calc)


@external
@payable
@nonreentrant('lock')
def exchange(
    _route: address[11],
    _swap_params: uint256[5][5],
    _amount: uint256,
    _min_dy: uint256,
    _pools: address[5]=empty(address[5]),
    _receiver: address=msg.sender
) -> uint256:
    """
    @notice Performs up to 5 swaps in a single transaction.
    @dev Routing and swap params must be determined off-chain. This
         functionality is designed for gas efficiency over ease-of-use.
    @param _route Array of [initial token, pool or zap, token, pool or zap, token, ...]
                  The array is iterated until a pool address of 0x00, then the last
                  given token is transferred to `_receiver`
    @param _swap_params Multidimensional array of [i, j, swap_type, pool_type, n_coins] where
                        i is the index of input token
                        j is the index of output token
                        For ERC4626:
                            i == 0 - asset -> share
                            i == 1 - share -> asset

                        The swap_type should be:
                        1. for `exchange`,
                        2. for `exchange_underlying`,
                        3. for underlying exchange via zap: factory stable metapools with lending base pool `exchange_underlying`
                           and factory crypto-meta pools underlying exchange (`exchange` method in zap)
                        4. for coin -> LP token "exchange" (actually `add_liquidity`),
                        5. for lending pool underlying coin -> LP token "exchange" (actually `add_liquidity`),
                        6. for LP token -> coin "exchange" (actually `remove_liquidity_one_coin`)
                        7. for LP token -> lending or fake pool underlying coin "exchange" (actually `remove_liquidity_one_coin`)
                        8. for ETH <-> WETH, ETH -> stETH or ETH -> frxETH, stETH <-> wstETH, ETH -> wBETH
                        9. for ERC4626 asset <-> share

                        pool_type: 1 - stable, 2 - twocrypto, 3 - tricrypto, 4 - llamma
                                   10 - stable-ng, 20 - twocrypto-ng, 30 - tricrypto-ng

                        n_coins is the number of coins in pool

    @param _amount The amount of input token (`_route[0]`) to be sent.
    @param _min_dy The minimum amount received after the final swap.
    @param _pools Array of pools for swaps via zap contracts. This parameter is only needed for swap_type = 3.
    @param _receiver Address to transfer the final output token to.
    @return Received amount of the final output token.
    """
    input_token: address = _route[0]
    output_token: address = empty(address)
    amount: uint256 = _amount

    # validate / transfer initial token
    if input_token == ETH_ADDRESS:
        assert msg.value == amount
    else:
        assert msg.value == 0
        assert ERC20(input_token).transferFrom(msg.sender, self, amount, default_return_value=True)

    for i in range(5):
        # 5 rounds of iteration to perform up to 5 swaps
        swap: address = _route[i * 2 + 1]
        pool: address = _pools[i]  # Only for Polygon meta-factories underlying swap (swap_type == 6)
        output_token = _route[(i + 1) * 2]
        params: uint256[5] = _swap_params[i]  # i, j, swap_type, pool_type, n_coins

        # store the initial balance of the output_token
        output_token_initial_balance: uint256 = self.balance
        if output_token != ETH_ADDRESS:
            output_token_initial_balance = ERC20(output_token).balanceOf(self)

        if not self.is_approved[input_token][swap]:
            assert ERC20(input_token).approve(swap, max_value(uint256), default_return_value=True, skip_contract_check=True)
            self.is_approved[input_token][swap] = True

        eth_amount: uint256 = 0
        if input_token == ETH_ADDRESS:
            eth_amount = amount
        # perform the swap according to the swap type
        if params[2] == 1:
            if params[3] in [1, 10]:  # stable and stable_ng
                StablePool(swap).exchange(convert(params[0], int128), convert(params[1], int128), amount, 0, value=eth_amount)
            else:  # crypto or llamma
                if input_token == ETH_ADDRESS or output_token == ETH_ADDRESS:
                    CryptoPoolETH(swap).exchange(params[0], params[1], amount, 0, True, value=eth_amount)
                else:
                    CryptoPool(swap).exchange(params[0], params[1], amount, 0)
        elif params[2] == 2:
            if params[3] in [1, 10]:  # stable and stable_ng
                StablePool(swap).exchange_underlying(convert(params[0], int128), convert(params[1], int128), amount, 0, value=eth_amount)
            else:  # crypto
                CryptoPool(swap).exchange_underlying(params[0], params[1], amount, 0, value=eth_amount)
        elif params[2] == 3:  # SWAP IS ZAP HERE !!!
            if params[3] in [1, 10]:  # stable and stable_ng
                LendingBasePoolMetaZap(swap).exchange_underlying(pool, convert(params[0], int128), convert(params[1], int128), amount, 0)
            else:  # crypto
                use_eth: bool = input_token == ETH_ADDRESS or output_token == ETH_ADDRESS
                CryptoMetaZap(swap).exchange(pool, params[0], params[1], amount, 0, use_eth, value=eth_amount)
        elif params[2] == 4:
            if params[3] == 10:  # stable_ng
                amounts: DynArray[uint256, 8] = [0, 0, 0, 0, 0, 0, 0, 0]
                amounts[params[0]] = amount
                StableNgPool(swap).add_liquidity(amounts, 0)
            elif params[3] == 30:  # tricrypto-ng
                amounts: uint256[3] = [0, 0, 0]
                amounts[params[0]] = amount
                if eth_amount > 0:
                    TriCryptoNgETH(swap).add_liquidity(amounts, 0, True, value=eth_amount)
                else:
                    StablePool3Coins(swap).add_liquidity(amounts, 0)
            elif params[4] == 2:
                amounts: uint256[2] = [0, 0]
                amounts[params[0]] = amount
                StablePool2Coins(swap).add_liquidity(amounts, 0, value=eth_amount)
            elif params[4] == 3:
                amounts: uint256[3] = [0, 0, 0]
                amounts[params[0]] = amount
                StablePool3Coins(swap).add_liquidity(amounts, 0, value=eth_amount)
            elif params[4] == 4:
                amounts: uint256[4] = [0, 0, 0, 0]
                amounts[params[0]] = amount
                StablePool4Coins(swap).add_liquidity(amounts, 0, value=eth_amount)
            elif params[4] == 5:
                amounts: uint256[5] = [0, 0, 0, 0, 0]
                amounts[params[0]] = amount
                StablePool5Coins(swap).add_liquidity(amounts, 0, value=eth_amount)
        elif params[2] == 5:
            amounts: uint256[3] = [0, 0, 0]
            amounts[params[0]] = amount
            LendingStablePool3Coins(swap).add_liquidity(amounts, 0, True, value=eth_amount) # example: aave on Polygon
        elif params[2] == 6:
            if params[3] in [1, 10]:  # stable and stable_ng
                StablePool(swap).remove_liquidity_one_coin(amount, convert(params[1], int128), 0)
            elif params[3] == 30 and output_token == ETH_ADDRESS:  # tricrypto-ng & ETH
                TriCryptoNgETH(swap).remove_liquidity_one_coin(amount, params[1], 0, True)
            else:  # crypto
                CryptoPool(swap).remove_liquidity_one_coin(amount, params[1], 0)  # example: atricrypto3 on Polygon
        elif params[2] == 7:
            LendingStablePool3Coins(swap).remove_liquidity_one_coin(amount, convert(params[1], int128), 0, True) # example: aave on Polygon
        elif params[2] == 8:
            if input_token == ETH_ADDRESS and output_token == WETH_ADDRESS:
                WETH(swap).deposit(value=amount)
            elif input_token == WETH_ADDRESS and output_token == ETH_ADDRESS:
                WETH(swap).withdraw(amount)
            elif input_token == ETH_ADDRESS and output_token == STETH_ADDRESS:
                stETH(swap).submit(0x0000000000000000000000000000000000000000, value=amount)
            elif input_token == ETH_ADDRESS and output_token == FRXETH_ADDRESS:
                frxETHMinter(swap).submit(value=amount)
            elif input_token == STETH_ADDRESS and output_token == WSTETH_ADDRESS:
                wstETH(swap).wrap(amount)
            elif input_token == WSTETH_ADDRESS and output_token == STETH_ADDRESS:
                wstETH(swap).unwrap(amount)
            elif input_token == ETH_ADDRESS and output_token == WBETH_ADDRESS:
                wBETH(swap).deposit(0xeCb456EA5365865EbAb8a2661B0c503410e9B347, value=amount)
            else:
                raise "Swap type 8 is only for ETH <-> WETH, ETH -> stETH or ETH -> frxETH, stETH <-> wstETH, ETH -> wBETH"
        elif params[2] == 9:
            if params[0] == 0:
                ERC4626(swap).deposit(amount, self)
            elif params[0] == 1:
                ERC4626(swap).redeem(amount, self, self)
            else:
                raise "Wrong index"
        else:
            raise "Bad swap type"

        # update the amount received
        if output_token == ETH_ADDRESS:
            amount = self.balance
        else:
            amount = ERC20(output_token).balanceOf(self)

        # sanity check, if the routing data is incorrect we will have a 0 balance change and that is bad
        assert amount - output_token_initial_balance != 0, "Received nothing"

        # check if this was the last swap
        if i == 4 or _route[i * 2 + 3] == empty(address):
            break
        # if there is another swap, the output token becomes the input for the next round
        input_token = output_token

    amount -= 1  # Change non-zero -> non-zero costs less gas than zero -> non-zero
    assert amount >= _min_dy, "Slippage"

    # transfer the final token to the receiver
    if output_token == ETH_ADDRESS:
        raw_call(_receiver, b"", value=amount)
    else:
        assert ERC20(output_token).transfer(_receiver, amount, default_return_value=True)

    log Exchange(msg.sender, _receiver, _route, _swap_params, _pools, _amount, amount)

    return amount


@view
@external
def get_dy(
    _route: address[11],
    _swap_params: uint256[5][5],
    _amount: uint256,
    _pools: address[5]=empty(address[5])
) -> uint256:
    """
    @notice Get amount of the final output token received in an exchange
    @dev Routing and swap params must be determined off-chain. This
         functionality is designed for gas efficiency over ease-of-use.
    @param _route Array of [initial token, pool or zap, token, pool or zap, token, ...]
                  The array is iterated until a pool address of 0x00, then the last
                  given token is transferred to `_receiver`
    @param _swap_params Multidimensional array of [i, j, swap_type, pool_type, n_coins] where
                        i is the index of input token
                        j is the index of output token
                        For ERC4626:
                            i == 0 - asset -> share
                            i == 1 - share -> asset

                        The swap_type should be:
                        1. for `exchange`,
                        2. for `exchange_underlying`,
                        3. for underlying exchange via zap: factory stable metapools with lending base pool `exchange_underlying`
                           and factory crypto-meta pools underlying exchange (`exchange` method in zap)
                        4. for coin -> LP token "exchange" (actually `add_liquidity`),
                        5. for lending pool underlying coin -> LP token "exchange" (actually `add_liquidity`),
                        6. for LP token -> coin "exchange" (actually `remove_liquidity_one_coin`)
                        7. for LP token -> lending or fake pool underlying coin "exchange" (actually `remove_liquidity_one_coin`)
                        8. for ETH <-> WETH, ETH -> stETH or ETH -> frxETH, stETH <-> wstETH, ETH -> wBETH
                        9. for ERC4626 asset <-> share

                        pool_type: 1 - stable, 2 - twocrypto, 3 - tricrypto, 4 - llamma
                                   10 - stable-ng, 20 - twocrypto-ng, 30 - tricrypto-ng

                        n_coins is the number of coins in pool

    @param _amount The amount of input token (`_route[0]`) to be sent.
    @param _pools Array of pools for swaps via zap contracts. This parameter is needed only for swap_type = 3.
    @return Expected amount of the final output token.
    """
    input_token: address = _route[0]
    output_token: address = empty(address)
    amount: uint256 = _amount

    for i in range(5):
        # 5 rounds of iteration to perform up to 5 swaps
        swap: address = _route[i * 2 + 1]
        pool: address = _pools[i]  # Only for Polygon meta-factories underlying swap (swap_type == 4)
        output_token = _route[(i + 1) * 2]
        params: uint256[5] = _swap_params[i]  # i, j, swap_type, pool_type, n_coins

        # Calc output amount according to the swap type
        if params[2] == 1:
            if params[3] in [1, 10]:  # stable and stable_ng
                amount = StablePool(swap).get_dy(convert(params[0], int128), convert(params[1], int128), amount)
            else:  # crypto or llamma
                amount = CryptoPool(swap).get_dy(params[0], params[1], amount)
        elif params[2] == 2:
            if params[3] in [1, 10]:  # stable and stable_ng
                amount = StablePool(swap).get_dy_underlying(convert(params[0], int128), convert(params[1], int128), amount)
            else:  # crypto
                amount = CryptoPool(swap).get_dy_underlying(params[0], params[1], amount)
        elif params[2] == 3:  # SWAP IS ZAP HERE !!!
            if params[3] in [1, 10]:  # stable and stable_ng
                amount = StablePool(pool).get_dy_underlying(convert(params[0], int128), convert(params[1], int128), amount)
            else:  # crypto
                amount = CryptoMetaZap(swap).get_dy(pool, params[0], params[1], amount)
        elif params[2] in [4, 5]:
            if params[3] == 1:  # stable
                amounts: uint256[10] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
                amounts[params[0]] = amount
                amount = STABLE_CALC.calc_token_amount(swap, output_token, amounts, params[4], True, True)
            elif params[3] == 10:  # stable_ng
                amounts: DynArray[uint256, 8] = [0, 0, 0, 0, 0, 0, 0, 0]
                amounts[params[0]] = amount
                amount = StableNgPool(swap).calc_token_amount(amounts, True)
            else:
                # Tricrypto pools have stablepool interface for calc_token_amount
                if params[4] == 2:
                    amounts: uint256[2] = [0, 0]
                    amounts[params[0]] = amount
                    if params[3] == 2:  # twocrypto
                        amount = CryptoPool2Coins(swap).calc_token_amount(amounts)
                    else:  # tricrypto, twocrypto-ng
                        amount = StablePool2Coins(swap).calc_token_amount(amounts, True)
                elif params[4] == 3:
                    amounts: uint256[3] = [0, 0, 0]
                    amounts[params[0]] = amount
                    if params[3] == 2:  # twocrypto
                        amount = CryptoPool3Coins(swap).calc_token_amount(amounts)
                    else:  # tricrypto, tricrypto-ng
                        amount = StablePool3Coins(swap).calc_token_amount(amounts, True)
                elif params[4] == 4:
                    amounts: uint256[4] = [0, 0, 0, 0]
                    amounts[params[0]] = amount
                    if params[3] == 2:  # twocrypto
                        amount = CryptoPool4Coins(swap).calc_token_amount(amounts)
                    else:  # tricrypto
                        amount = StablePool4Coins(swap).calc_token_amount(amounts, True)
                elif params[4] == 5:
                    amounts: uint256[5] = [0, 0, 0, 0, 0]
                    amounts[params[0]] = amount
                    if params[3] == 2:  # twocrypto
                        amount = CryptoPool5Coins(swap).calc_token_amount(amounts)
                    else:  # tricrypto
                        amount = StablePool5Coins(swap).calc_token_amount(amounts, True)
        elif params[2] in [6, 7]:
            if params[3] in [1, 10]:  # stable and stable_ng
                amount = StablePool(swap).calc_withdraw_one_coin(amount, convert(params[1], int128))
            else:  # crypto
                amount = CryptoPool(swap).calc_withdraw_one_coin(amount, params[1])
        elif params[2] == 8:
            if input_token == WETH_ADDRESS or output_token == WETH_ADDRESS or \
                    (input_token == ETH_ADDRESS and output_token == STETH_ADDRESS) or \
                    (input_token == ETH_ADDRESS and output_token == FRXETH_ADDRESS):
                # ETH <--> WETH rate is 1:1
                # ETH ---> stETH rate is 1:1
                # ETH ---> frxETH rate is 1:1
                pass
            elif input_token == WSTETH_ADDRESS:
                amount = wstETH(swap).getStETHByWstETH(amount)
            elif output_token == WSTETH_ADDRESS:
                amount = wstETH(swap).getWstETHByStETH(amount)
            elif output_token == WBETH_ADDRESS:
                amount = amount * 10**18 / wBETH(swap).exchangeRate()
            else:
                raise "Swap type 8 is only for ETH <-> WETH, ETH -> stETH or ETH -> frxETH, stETH <-> wstETH, ETH -> wBETH"
        elif params[2] == 9:
            if params[0] == 0:
                amount = ERC4626(swap).convertToShares(amount)
            elif params[0] == 1:
                amount = ERC4626(swap).convertToAssets(amount)
            else:
                raise "Wrong index"
        else:
            raise "Bad swap type"

        # check if this was the last swap
        if i == 4 or _route[i * 2 + 3] == empty(address):
            break
        # if there is another swap, the output token becomes the input for the next round
        input_token = output_token

    return amount - 1


@view
@external
def get_dx(
    _route: address[11],
    _swap_params: uint256[5][5],
    _out_amount: uint256,
    _pools: address[5],
    _base_pools: address[5]=empty(address[5]),
    _base_tokens: address[5]=empty(address[5]),
) -> uint256:
    """
    @notice Calculate the input amount required to receive the desired output amount.
            This method is NOT PRECISE for swap_type = 4, 5, 6, 7.
    @dev Routing and swap params must be determined off-chain. This
         functionality is designed for gas efficiency over ease-of-use.
    @param _route Array of [initial token, pool or zap, token, pool or zap, token, ...]
                  The array is iterated until a pool address of 0x00, then the last
                  given token is transferred to `_receiver`
    @param _swap_params Multidimensional array of [i, j, swap_type, pool_type, n_coins] where
                        i is the index of input token
                        j is the index of output token
                        For ERC4626:
                            i == 0 - asset -> share
                            i == 1 - share -> asset

                        The swap_type should be:
                        1. for `exchange`,
                        2. for `exchange_underlying`,
                        3. for underlying exchange via zap: factory stable metapools with lending base pool `exchange_underlying`
                           and factory crypto-meta pools underlying exchange (`exchange` method in zap)
                        4. for coin -> LP token "exchange" (actually `add_liquidity`),
                        5. for lending pool underlying coin -> LP token "exchange" (actually `add_liquidity`),
                        6. for LP token -> coin "exchange" (actually `remove_liquidity_one_coin`)
                        7. for LP token -> lending or fake pool underlying coin "exchange" (actually `remove_liquidity_one_coin`)
                        8. for ETH <-> WETH, ETH -> stETH or ETH -> frxETH, stETH <-> wstETH, ETH -> wBETH
                        9. for ERC4626 asset <-> share

                        pool_type: 1 - stable, 2 - twocrypto, 3 - tricrypto, 4 - llamma
                                   10 - stable-ng, 20 - twocrypto-ng, 30 - tricrypto-ng

                        n_coins is the number of coins in pool
    @param _out_amount The desired amount of output coin to receive.
    @param _pools Array of pools.
    @param _base_pools Array of base pools (for meta pools).
    @param _base_tokens Array of base lp tokens (for meta pools). Should be a zap address for double meta pools.
    @return Required amount of input token to send.
    """
    amount: uint256 = _out_amount

    for _i in range(5):
        # 5 rounds of iteration to perform up to 5 swaps
        i: uint256 = 4 - _i
        swap: address = _route[i * 2 + 1]
        if swap == empty(address):
            continue
        input_token: address = _route[i * 2]
        output_token: address = _route[(i + 1) * 2]
        pool: address = _pools[i]
        base_pool: address = _base_pools[i]
        base_token: address = _base_tokens[i]
        params: uint256[5] = _swap_params[i]  # i, j, swap_type, pool_type, n_coins
        n_coins: uint256 = params[4]

        # Calc a required input amount according to the swap type
        if params[2] == 1:
            if params[3] == 1:  # stable
                if base_pool == empty(address):  # non-meta
                    amount = STABLE_CALC.get_dx(pool, convert(params[0], int128), convert(params[1], int128), amount, n_coins)
                else:
                    amount = STABLE_CALC.get_dx_meta(pool, convert(params[0], int128), convert(params[1], int128), amount, n_coins, base_pool)
            elif params[3] == 10:  # stable-ng
                amount = StableNgPool(pool).get_dx(convert(params[0], int128), convert(params[1], int128), amount)
            elif params[3] in [2, 3]:  # crypto
                amount = CRYPTO_CALC.get_dx(pool, params[0], params[1], amount, n_coins)
            else:  # llamma, twocrypto-ng, tricrypto-ng
                amount = CryptoNgPool(pool).get_dx(params[0], params[1], amount)
        elif params[2] in [2, 3]:
            if params[3] == 1:  # stable
                if base_pool == empty(address):  # non-meta
                    amount = STABLE_CALC.get_dx_underlying(pool, convert(params[0], int128), convert(params[1], int128), amount, n_coins)
                else:
                    amount = STABLE_CALC.get_dx_meta_underlying(pool, convert(params[0], int128), convert(params[1], int128), amount, n_coins, base_pool, base_token)
            elif params[3] == 10:  # stable-ng
                _n: int128 = convert(params[0], int128)
                _k: int128 = convert(params[1], int128)
                if _n > 0 and _k > 0:
                    amount = STABLE_CALC.get_dx(base_pool, _n - 1, _k - 1, amount, n_coins - 1)
                else:
                    amount = StableNgPool(pool).get_dx_underlying(_n, _k, amount)
            else:  # crypto
                amount = CRYPTO_CALC.get_dx_meta_underlying(pool, params[0], params[1], amount, n_coins, base_pool, base_token)
        elif params[2] in [4, 5]:
            # This is not correct. Should be something like calc_add_one_coin. But tests say that it's precise enough.
            if params[3] in [1, 10]:  # stable and stable_ng
                amount = StablePool(swap).calc_withdraw_one_coin(amount, convert(params[0], int128))
            else:  # crypto
                amount = CryptoPool(swap).calc_withdraw_one_coin(amount, params[0])
        elif params[2] in [6, 7]:
            if params[3] == 1:  # stable
                amounts: uint256[10] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
                amounts[params[1]] = amount
                amount = STABLE_CALC.calc_token_amount(swap, input_token, amounts, n_coins, False, True)
            elif params[3] == 10:  # stable_ng
                amounts: DynArray[uint256, 8] = [0, 0, 0, 0, 0, 0, 0, 0]
                amounts[params[1]] = amount
                amount = StableNgPool(swap).calc_token_amount(amounts, False)
            else:
                # Tricrypto pools have stablepool interface for calc_token_amount
                if n_coins == 2:
                    amounts: uint256[2] = [0, 0]
                    amounts[params[1]] = amount
                    if params[3] == 2:  # twocrypto
                        amount = CryptoPool2Coins(swap).calc_token_amount(amounts)  # This is not correct
                    else:  # tricrypto, twocrypto-ng
                        amount = StablePool2Coins(swap).calc_token_amount(amounts, False)
                elif n_coins == 3:
                    amounts: uint256[3] = [0, 0, 0]
                    amounts[params[1]] = amount
                    if params[3] == 2:  # twocrypto
                        amount = CryptoPool3Coins(swap).calc_token_amount(amounts)  # This is not correct
                    else:  # tricrypto, tricrypto-ng
                        amount = StablePool3Coins(swap).calc_token_amount(amounts, False)
                elif n_coins == 4:
                    amounts: uint256[4] = [0, 0, 0, 0]
                    amounts[params[1]] = amount
                    if params[3] == 2:  # twocrypto
                        amount = CryptoPool4Coins(swap).calc_token_amount(amounts)  # This is not correct
                    else:  # tricrypto
                        amount = StablePool4Coins(swap).calc_token_amount(amounts, False)
                elif n_coins == 5:
                    amounts: uint256[5] = [0, 0, 0, 0, 0]
                    amounts[params[1]] = amount
                    if params[3] == 2:  # twocrypto
                        amount = CryptoPool5Coins(swap).calc_token_amount(amounts)  # This is not correct
                    else:  # tricrypto
                        amount = StablePool5Coins(swap).calc_token_amount(amounts, False)
        elif params[2] == 8:
            if input_token == WETH_ADDRESS or output_token == WETH_ADDRESS or \
                    (input_token == ETH_ADDRESS and output_token == STETH_ADDRESS) or \
                    (input_token == ETH_ADDRESS and output_token == FRXETH_ADDRESS):
                # ETH <--> WETH rate is 1:1
                # ETH ---> stETH rate is 1:1
                # ETH ---> frxETH rate is 1:1
                pass
            elif input_token == WSTETH_ADDRESS:
                amount = wstETH(swap).getWstETHByStETH(amount)
            elif output_token == WSTETH_ADDRESS:
                amount = wstETH(swap).getStETHByWstETH(amount)
            elif output_token == WBETH_ADDRESS:
                amount = amount * wBETH(swap).exchangeRate() / 10**18
            else:
                raise "Swap type 8 is only for ETH <-> WETH, ETH -> stETH or ETH -> frxETH, stETH <-> wstETH, ETH -> wBETH"
        elif params[2] == 9:
            if params[0] == 0:
                amount = ERC4626(swap).convertToAssets(amount)
            elif params[0] == 1:
                amount = ERC4626(swap).convertToShares(amount)
            else:
                raise "Wrong index"
        else:
            raise "Bad swap type"

    return amount

Read Contract

get_dx 0xc07b5353 → uint256
get_dx 0x81fc0ca5 → uint256
get_dx 0x90e7e205 → uint256
get_dy 0x81889a2c → uint256
get_dy 0x637653cb → uint256
version 0x54fd4d50 → string

Write Contract 3 functions

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

exchange 0x371dc447
address[11] _route
uint256[5][5] _swap_params
uint256 _amount
uint256 _min_dy
returns: uint256
exchange 0x5c9c18e2
address[11] _route
uint256[5][5] _swap_params
uint256 _amount
uint256 _min_dy
address[5] _pools
returns: uint256
exchange 0xc872a3c5
address[11] _route
uint256[5][5] _swap_params
uint256 _amount
uint256 _min_dy
address[5] _pools
address _receiver
returns: uint256

Top Interactions

Recent Transactions

CSV
|
Hash Method Block Age From/To Value Txn Fee Type
0x3988b9d3...18b179 Fail 0x5c9c18e2 24,591,453 IN 0x7f7428Dd...bD4D 0 ETH 0.000600362342 ETH EIP-1559
0x40cafe28...b7cfe7 0x5c9c18e2 24,591,450 IN 0x00a36bF3...9fF9 0 ETH 0.000020112795 ETH EIP-1559
0x6f5c63c6...a0116d 0x5c9c18e2 24,591,442 IN 0x7f7428Dd...bD4D 0 ETH 0.000318656928 ETH EIP-1559
0xe7e71130...f170fb 0x5c9c18e2 24,591,439 IN 0xcAd8A875...D755 0 ETH 0.000018223458 ETH EIP-1559
0x6e045da8...d742af Fail 0x5c9c18e2 24,591,438 IN 0x7f7428Dd...bD4D 0 ETH 0.000654343300 ETH EIP-1559
0x715ea5d4...b08e68 0x5c9c18e2 24,591,430 IN 0x17F8E6f6...f325 0 ETH 0.000352085754 ETH EIP-1559
0xb5e5bc79...f8ec28 0x5c9c18e2 24,591,400 IN 0xa9965d17...7D6c 0.312220 ETH 0.000017446004 ETH Legacy
0x9bf97f61...53886b 0x5c9c18e2 24,591,394 IN 0xa9965d17...7D6c 1.0000 ETH 0.000018887553 ETH Legacy
0xb16e3822...e61b83 0x5c9c18e2 24,591,388 IN 0xa9965d17...7D6c 1.0000 ETH 0.000020911520 ETH Legacy