Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xd4e9B0d466789d7F6201442eecCBA6a75A552db0
Balance 0 ETH
Nonce 1
Code Size 11612 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

11612 bytes
0x6080604052600436101561001a575b3615610018575f80fd5b005b5f3560e01c632bdb823c0361000e5760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261025a5760043573ffffffffffffffffffffffffffffffffffffffff81169081810361025a576024359060443567ffffffffffffffff811161025a57806004019160807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc833603011261025a57826100c691610829565b6100d260248201610684565b6064820135801515810361025a5715610649578235600b81101561025a576100fe6044869401856106a5565b939091600181036103565750508260645f927fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f60405197889586947fe4da6f2e0000000000000000000000000000000000000000000000000000000086526040600487015281604487015286860137868582860101528a602485015201168101030181732f577a41bec1be1152aeea12e73b7391d15f655d5afa801561034b575f925f916102c3575b50911561026557610221915b8561025e5784905b604051926101cc606085610778565b602984527f416464726573733a206c6f772d6c6576656c2063616c6c20776974682076616c60208501527f7565206661696c6564000000000000000000000000000000000000000000000060408501526129b2565b503590600b82101561025a5760207f1d8c50a59805451ff93bb2e438559a86b75386bcac2a591d3181d79e7e8346fd91604051908152a3005b5f80fd5b5f906101bd565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602060248201527f50656e646c65537761703a204b79626572207363616c696e67206661696c65646044820152fd5b9250503d805f843e6102d58184610778565b82019160408184031261025a576102eb8161087f565b9060208101519067ffffffffffffffff821161025a570183601f8201121561025a578051610318816107b9565b946103266040519687610778565b8186526020828401011161025a57610344916020808701910161088c565b915f6101a9565b6040513d5f823e3d90fd5b92939192600281036106165750508060041161025a577fffffffff00000000000000000000000000000000000000000000000000000000823516907f3b635ce40000000000000000000000000000000000000000000000000000000082036105e9578201917ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc81840301610140811261025a5760e01361025a57604051926103fd846106f6565b61040960048301610663565b845260208401906024830135825261042360448401610663565b906040860191825261043760648501610663565b60608701908152608087016084860135815260a088019160a4870135835261046160c48801610663565b9360c08a0194855260e48801359067ffffffffffffffff821161025a57600461048c928a0101610d25565b9461012461049d6101048a01610663565b9801359663ffffffff881680980361025a578d8451906104bc916110ce565b81516104c79161110e565b84528d8551906104d6916110ce565b81516104e19161110e565b85528d81526040519a8b9a60208c01525173ffffffffffffffffffffffffffffffffffffffff1660248b01525160448a01525173ffffffffffffffffffffffffffffffffffffffff1660648901525173ffffffffffffffffffffffffffffffffffffffff1660848801525160a48701525160c48601525173ffffffffffffffffffffffffffffffffffffffff1660e485015261010484016101409052610164840161058b916111c1565b9173ffffffffffffffffffffffffffffffffffffffff16610124840152610144830152037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0810182526105de9082610778565b90610221915b6101b5565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52600160045260245ffd5b90939290600681036106315750926105e49161022194611d7f565b9093506004036105e957846105e491610221946114cd565b6105e461065c60446102219401856106a5565b36916107f3565b359073ffffffffffffffffffffffffffffffffffffffff8216820361025a57565b3573ffffffffffffffffffffffffffffffffffffffff8116810361025a5790565b9035907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18136030182121561025a570180359067ffffffffffffffff821161025a5760200191813603831361025a57565b60e0810190811067ffffffffffffffff82111761071257604052565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b60a0810190811067ffffffffffffffff82111761071257604052565b610140810190811067ffffffffffffffff82111761071257604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761071257604052565b67ffffffffffffffff811161071257601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b9291926107ff826107b9565b9161080d6040519384610778565b82948184528183011161025a578281602093845f960137010152565b73ffffffffffffffffffffffffffffffffffffffff16801561087b578135600b81101561025a5760040361086c5761086a9150610864610acf565b906108ad565b565b610864602061086a9301610684565b5050565b5190811515820361025a57565b5f5b83811061089d5750505f910152565b818101518382015260200161088e565b73ffffffffffffffffffffffffffffffffffffffff81169073ffffffffffffffffffffffffffffffffffffffff604051937fdd62ed3e0000000000000000000000000000000000000000000000000000000085523060048601521692836024820152602081604481865afa801561034b575f90610a7d575b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff91501061095257505050565b604051915f80602085017f095ea7b30000000000000000000000000000000000000000000000000000000081528660248701527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6044870152604486526109ba606487610778565b85519082855af1906109ca612983565b82610a43575b5081610a38575b50156109e257505050565b610a3361086a93604051907f095ea7b300000000000000000000000000000000000000000000000000000000602083015260248201525f604482015260448152610a2d606482610778565b82612c02565b612c02565b90503b15155f6109d7565b80519192508115918215610a5b575b5050905f6109d0565b819250906020918101031261025a576020610a76910161087f565b5f80610a52565b506020813d602011610ac7575b81610a9760209383610778565b8101031261025a577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9051610925565b3d9150610a8a565b60014614610be657600a4614610bce5760384614610bb65761a4b14614610b9e576121054614610b86576113884614610b865760846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602360248201527f50656e646c65537761703a204f4b5820436861696e206e6f7420737570706f7260448201527f74656400000000000000000000000000000000000000000000000000000000006064820152fd5b7357df6092665eb6058de53939612413ff4b09114e90565b7370cbb871e8f30fc8ce23609e9e0ea87b6b222f5890565b732c34a2fb1d0b4f55de51e1d0bdefaddce6b7cdd690565b7368d6b739d2020067d1e2f713b999da97e4d5481290565b7340aa958dd87fc8305b97f2ba922cddca374bcd7f90565b91908260a091031261025a57604051610c168161073f565b608080829480358452610c2b60208201610663565b602085015260408101356040850152606081013560608501520135910152565b67ffffffffffffffff81116107125760051b60200190565b9080601f8301121561025a578135610c7a81610c4b565b92610c886040519485610778565b81845260208085019260051b82010192831161025a57602001905b828210610cb05750505090565b8135815260209182019101610ca3565b9080601f8301121561025a578135610cd781610c4b565b92610ce56040519485610778565b81845260208085019260051b82010192831161025a57602001905b828210610d0d5750505090565b60208091610d1a84610663565b815201910190610d00565b9080601f8301121561025a57816020610d40933591016107f3565b90565b81601f8201121561025a57803590610d5a82610c4b565b92610d686040519485610778565b82845260208085019360051b8301019181831161025a5760208101935b838510610d9457505050505090565b843567ffffffffffffffff811161025a57820183603f8201121561025a576020810135610dc081610c4b565b91610dce6040519384610778565b8183526020808085019360051b830101019086821161025a5760408101925b828410610e07575050509082525060209485019401610d85565b833567ffffffffffffffff811161025a5760209083010160a07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0828b03011261025a5760405190610e578261073f565b602081013567ffffffffffffffff811161025a578a6020610e7a92840101610cc0565b8252604081013567ffffffffffffffff811161025a578a6020610e9f92840101610cc0565b6020830152606081013567ffffffffffffffff811161025a578a6020610ec792840101610c63565b6040830152608081013567ffffffffffffffff811161025a576020908201018a601f8201121561025a578035610efc81610c4b565b91610f0a6040519384610778565b81835260208084019260051b820101918d831161025a5760208201905b838210610f4e5750505050606083015260a001356080820152815260209384019301610ded565b813567ffffffffffffffff811161025a578f91610f72602093848094880101610d25565b815201910190610f27565b9080601f8301121561025a57813591610f9583610c4b565b92610fa36040519485610778565b80845260208085019160051b8301019183831161025a5760208101915b838310610fcf57505050505090565b823567ffffffffffffffff811161025a578201906101407fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0838803011261025a576040519061101d8261075b565b6020830135825261103060408401610663565b602083015261104160608401610663565b604083015261105260808401610663565b606083015260a0830135608083015260c083013560a083015260e083013560c083015261010083013560e0830152610120830135801515810361025a576101008301526101408301359167ffffffffffffffff831161025a576110bd88602080969581960101610d25565b610120820152815201920191610fc0565b818102929181159184041417156110e157565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b8115611118570490565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b90602080835192838152019201905f5b8181106111625750505090565b8251845260209384019390920191600101611155565b90602080835192838152019201905f5b8181106111955750505090565b825173ffffffffffffffffffffffffffffffffffffffff16845260209384019390920191600101611188565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f6020936111fd8151809281875287808801910161088c565b0116010190565b9080602083519182815201906020808260051b8501019401915f905b82821061122f57505050505090565b9091929395947fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0878203018252845190815180825260208201906020808260051b8501019401925f5b82811061129c57505050505060208060019296019201920190929195939495611220565b90919293947fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe083829d9c9b9d0301855285519061130c6112fa6112e8845160a0855260a0850190611178565b60208501518482036020860152611178565b60408401518382036040850152611145565b91606081015192828103606084015283519081815260208101906020808460051b8301019601925f915b8183106113645750505050608091820151919092015250999a98999460209081019401929190600101611278565b90919293966020806113a0837fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe086600196030189528b516111c1565b9901950193019190611336565b9080602083519182815201916020808360051b8301019401925f915b8383106113d857505050505090565b90919293946020806114be837fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe086600196030187526101406101208b518051845273ffffffffffffffffffffffffffffffffffffffff86820151168685015273ffffffffffffffffffffffffffffffffffffffff604082015116604085015273ffffffffffffffffffffffffffffffffffffffff60608201511660608501526080810151608085015260a081015160a085015260c081015160c085015260e081015160e085015261010081015115156101008501520151918161012082015201906111c1565b970193019301919392906113c9565b906060928160041161025a577fffffffff000000000000000000000000000000000000000000000000000000008335169160048401947f0d5f0e3b0000000000000000000000000000000000000000000000000000000084145f146115fb575083019260807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc828603011261025a5760648101359167ffffffffffffffff831161025a576115a2611589610d409660046115cf96860101610c63565b9261159d83604460248401359301356110ce565b61110e565b906040519687956020870152356024860152604485015260648401526080608484015260a4830190611145565b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101835282610778565b9193917f03b87e5f00000000000000000000000000000000000000000000000000000000840361180957508101926101407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc838603011261025a5761166260248301610663565b61166f8560448501610bfe565b9460e484013567ffffffffffffffff811161025a5781600461169392870101610c63565b9061010485013567ffffffffffffffff811161025a578160046116b892880101610d43565b916101248601359167ffffffffffffffff831161025a57610d409873ffffffffffffffffffffffffffffffffffffffff6117d8966117046117939460046117a7986115cf9d0101610f7d565b98611716604085019682885191612aa1565b95606085016117316117298483516110ce565b83519061110e565b9052526040519c8d9b60208d01523560248c01521660448a01526064890190608080918051845273ffffffffffffffffffffffffffffffffffffffff602082015116602085015260408101516040850152606081015160608501520151910152565b610140610104880152610164870190611145565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc86830301610124870152611204565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc848303016101448501526113ad565b7f08298b5a0000000000000000000000000000000000000000000000000000000084036118f6575081019060a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc828403011261025a5761186c60648201610663565b60848201359067ffffffffffffffff821161025a57610d40956118c36118af6115cf96600473ffffffffffffffffffffffffffffffffffffffff96880101610c63565b9461159d83604460248401359301356110ce565b9060405198899760208901523560248801526044870152606486015216608484015260a060a484015260c4830190611145565b9193917f9871efa400000000000000000000000000000000000000000000000000000000840361197d575083019260807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc828603011261025a5760648101359167ffffffffffffffff831161025a576115a2611589610d409660046115cf96860101610c63565b93907fb80c2f09000000000000000000000000000000000000000000000000000000008403611b56578101906101207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc828403011261025a576119e38260248301610bfe565b9460c482013567ffffffffffffffff811161025a57836004611a0792850101610c63565b9260e483013567ffffffffffffffff811161025a57816004611a2b92860101610d43565b916101048401359367ffffffffffffffff851161025a57610d40986115cf97611a62611af4956004611b2599611ae1960101610f7d565b97611a74604084019183835191612aa1565b948301611a856117298483516110ce565b9052526040519a8b9960208b01523560248a01526044890190608080918051845273ffffffffffffffffffffffffffffffffffffffff602082015116602085015260408101516040850152606081015160608501520151910152565b61012060e4880152610144870190611145565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc86830301610104870152611204565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc848303016101248501526113ad565b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f50656e646c65537761703a204f4b582073656c6563746f72206e6f742073757060448201527f706f7274656400000000000000000000000000000000000000000000000000006064820152fd5b9160608383031261025a57823567ffffffffffffffff811161025a5783016101008184031261025a5760405190610100820182811067ffffffffffffffff82111761071257604052611c2b81610663565b8252611c3960208201610663565b602083015260408101356040830152606081013560608301526080810135608083015260a081013560a0830152611c7260c08201610663565b60c083015260e08101359067ffffffffffffffff821161025a57611c9891859101610d25565b60e082015292602081013592604082013567ffffffffffffffff811161025a57610d409201610d25565b611d6c60e0610d4095936060845273ffffffffffffffffffffffffffffffffffffffff815116606085015273ffffffffffffffffffffffffffffffffffffffff6020820151166080850152604081015160a0850152606081015160c085015260808101518285015260a081015161010085015273ffffffffffffffffffffffffffffffffffffffff60c08201511661012085015201516101006101408401526101608301906111c1565b92602082015260408184039101526111c1565b916060928260041161025a577fffffffff000000000000000000000000000000000000000000000000000000008135169260048201947fe3ead59e0000000000000000000000000000000000000000000000000000000085145f1461204d5750810190808203946101607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc87011261025a577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc611e3d60e092610663565b96011261025a57604051611e50816106f6565b611e5c60248301610663565b8152611e6a60448301610663565b6020820190815260408201606484013581526060830160848501358152608084019160a4860135835260a085019360c48701358552611eab60e48801610663565b9560c0810196875261012488013567ffffffffffffffff811161025a57896004611ed7928b0101610d25565b9861014489013567ffffffffffffffff811161025a57890160040190611efc91610d25565b9980855190611f0a916110ce565b8451611f159161110e565b855280865190611f24916110ce565b8451611f2f9161110e565b865283526040519b8c9b60208d015273ffffffffffffffffffffffffffffffffffffffff1660248c01525173ffffffffffffffffffffffffffffffffffffffff1660448b01525173ffffffffffffffffffffffffffffffffffffffff1660648a01525160848901525160a48801525160c48701525160e48601525173ffffffffffffffffffffffffffffffffffffffff166101048501526101040135610124840152610144830161016090526101848301611fe9916111c1565b8281037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc0161016484015261201d916111c1565b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081018252610d409082610778565b7fe8bb3b6c00000000000000000000000000000000000000000000000000000000859495939293145f146120dd5750610d4093946115cf92612090920190611bda565b9195606087016120a18282516110ce565b906120b260408a019283519061110e565b9052608088016120c66117298483516110ce565b905252604051958694602086015260248501611cc2565b7f876a02f60000000000000000000000000000000000000000000000000000000084036121195750610d4093946115cf92612090920190611bda565b909391907fd85ca1730000000000000000000000000000000000000000000000000000000084036122b957508301907ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc84830301610100811261025a5760a01361025a576040519461218a8661073f565b358552602085019160248501358352604086019460448101358652606087016064820135815260808801916084810135835260c481013567ffffffffffffffff811161025a578460046121df92840101610d25565b9260e48201359267ffffffffffffffff841161025a57610d40996115cf988c986122426122166122889a600460a49a8a0101610d25565b9a61222d6122258486516110ce565b82519061110e565b845261223a8386516110ce565b90519061110e565b83528d526040519c8d9b60208d01525160248c01525160448b01525160648a01525160848901525182880152013560c486015261010060e48601526101248501906111c1565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc848303016101048501526111c1565b7f1a01c5320000000000000000000000000000000000000000000000000000000084959394145f146124b9575081017ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc82820301610160811261025a576101201361025a5760405194610120860186811067ffffffffffffffff82111761071257604052358552602085016024830135815261235760448401610663565b6040870190815261236a60648501610663565b60608801908152608088016084860135815260a089019160a4870135835260c08a019360c4880135855260e08b019560e489013587526123ad6101048a01610663565b976101008d019889526101448a013567ffffffffffffffff811161025a578a01600401906123da91610d25565b99808651906123e8916110ce565b85516123f39161110e565b865280875190612402916110ce565b855161240d9161110e565b875284526040519b8c9b60208d01525160248c01525160448b01525173ffffffffffffffffffffffffffffffffffffffff1660648a01525173ffffffffffffffffffffffffffffffffffffffff1660848901525160a48801525160c48701525160e4860152516101048501525173ffffffffffffffffffffffffffffffffffffffff16610124840152610124013561014483015261016482016101609052610184820161201d916111c1565b7fe37ed25600000000000000000000000000000000000000000000000000000000850361270857508101937ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc828603016101a0811261025a576101601361025a576040519461016086019086821067ffffffffffffffff83111761071257838761010492819583956040523582526020820160248401358152604083016044850135815261256960648601610663565b906060850191825261257d60848701610663565b926080860193845261259160a48801610663565b9460a087019586526101406125db61014461012060c08b019a60c48d01358c5260e081019c8d60e4820135905261010082019e8f9101359052019c8d610124820135905201610663565b9b019a8b526101848c013567ffffffffffffffff811161025a578c016004019061260491610d25565b9b80885190612612916110ce565b875161261d9161110e565b88528089519061262c916110ce565b87516126379161110e565b89528652604051809e819e60208301525190602401525160448d01525160648c01525173ffffffffffffffffffffffffffffffffffffffff1660848b01525173ffffffffffffffffffffffffffffffffffffffff1660a48a01525173ffffffffffffffffffffffffffffffffffffffff1660c48901525160e48801525161010487015251610124860152516101448501525173ffffffffffffffffffffffffffffffffffffffff1661016484015261016401356101848301526101a482016101a090526101c4820161201d916111c1565b907f987e7d8e0000000000000000000000000000000000000000000000000000000085146127b45760846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f50617261737761705363616c6548656c7065723a20556e737570706f7274656460448201527f20737761702073656c6563746f720000000000000000000000000000000000006064820152fd5b8201907ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc83830301610160811261025a576101401361025a57612802604051966127fd8861075b565b610663565b865261281060248401610663565b9060208701918252604087019060448501358252870160648501358152608088016084860135815260a089019160a4870135835261285060c48801610663565b9360c08b0194855261286460e48901610663565b9560e08c019687526101008c01976101048a013589526101208d01996101248101358b526101448101359067ffffffffffffffff821161025a5701600401906128ac91610d25565b99808451906128ba916110ce565b83516128c59161110e565b845282526040519b8c9b60208d01525173ffffffffffffffffffffffffffffffffffffffff1660248c01525173ffffffffffffffffffffffffffffffffffffffff1660448b01525160648a01525160848901525160a48801525160c48701525173ffffffffffffffffffffffffffffffffffffffff1660e48601525173ffffffffffffffffffffffffffffffffffffffff16610104850152516101248401525161014483015261016482016101609052610184820161201d916111c1565b3d156129ad573d90612994826107b9565b916129a26040519384610778565b82523d5f602084013e565b606090565b909291928347106129dc575f81610d40956020839451920190855af16129d6612983565b91612b32565b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152fd5b8051821015612a745760209160051b010190565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b909291928151917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0612aeb612ad585610c4b565b94612ae36040519687610778565b808652610c4b565b01366020850137825f5b8251811015612b2a5780612b198861159d87612b1360019689612a60565b516110ce565b612b238288612a60565b5201612af5565b509450505050565b91929015612bad5750815115612b46575090565b3b15612b4f5790565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152fd5b825190915015612bc05750805190602001fd5b612bfe906040519182917f08c379a00000000000000000000000000000000000000000000000000000000083526020600484015260248301906111c1565b0390fd5b9073ffffffffffffffffffffffffffffffffffffffff612c6a92165f8060405193612c2e604086610778565b602085527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564602086015260208151910182855af16129d6612983565b8051908115918215612d04575b505015612c8057565b60846040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152fd5b819250906020918101031261025a576020612d1f910161087f565b5f80612c7756fea2646970667358221220a9c2d339f386cb08dc4793e1f819e14a346b6080c99f81b5783166452411691a64736f6c634300081c0033

Verified Source Code Full Match

Compiler: v0.8.28+commit.7893614a EVM: shanghai Optimization: Yes (1000000 runs)
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);
}
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);
}
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);
}
SafeERC20.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

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

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

    /**
     * @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. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    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));
    }
}
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);
        }
    }
}
TokenHelper.sol 71 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "../../interfaces/IWETH.sol";

abstract contract TokenHelper {
    using SafeERC20 for IERC20;

    address internal constant NATIVE = address(0);
    uint256 internal constant LOWER_BOUND_APPROVAL = type(uint96).max / 2; // some tokens use 96 bits for approval

    function _transferIn(address token, address from, uint256 amount) internal {
        if (token == NATIVE) require(msg.value == amount, "eth mismatch");
        else if (amount != 0) IERC20(token).safeTransferFrom(from, address(this), amount);
    }

    function _transferFrom(IERC20 token, address from, address to, uint256 amount) internal {
        if (amount != 0) token.safeTransferFrom(from, to, amount);
    }

    function _transferOut(address token, address to, uint256 amount) internal {
        if (amount == 0) return;
        if (token == NATIVE) {
            (bool success, ) = to.call{value: amount}("");
            require(success, "eth send failed");
        } else {
            IERC20(token).safeTransfer(to, amount);
        }
    }

    function _transferOut(address[] memory tokens, address to, uint256[] memory amounts) internal {
        uint256 numTokens = tokens.length;
        require(numTokens == amounts.length, "length mismatch");
        for (uint256 i = 0; i < numTokens; ) {
            _transferOut(tokens[i], to, amounts[i]);
            unchecked {
                i++;
            }
        }
    }

    function _selfBalance(address token) internal view returns (uint256) {
        return (token == NATIVE) ? address(this).balance : IERC20(token).balanceOf(address(this));
    }

    function _selfBalance(IERC20 token) internal view returns (uint256) {
        return token.balanceOf(address(this));
    }

    /// @notice Approves the stipulated contract to spend the given allowance in the given token
    /// @dev PLS PAY ATTENTION to tokens that requires the approval to be set to 0 before changing it
    function _safeApprove(address token, address to, uint256 value) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), "Safe Approve");
    }

    function _safeApproveInf(address token, address to) internal {
        if (token == NATIVE) return;
        if (IERC20(token).allowance(address(this), to) < LOWER_BOUND_APPROVAL) {
            _safeApprove(token, to, 0);
            _safeApprove(token, to, type(uint256).max);
        }
    }

    function _wrap_unwrap_ETH(address tokenIn, address tokenOut, uint256 netTokenIn) internal {
        if (tokenIn == NATIVE) IWETH(tokenOut).deposit{value: netTokenIn}();
        else IWETH(tokenIn).withdraw(netTokenIn);
    }
}
IWETH.sol 34 lines
// SPDX-License-Identifier: GPL-3.0-or-later
/*
 * MIT License
 * ===========
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 */
pragma solidity ^0.8.0;

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

interface IWETH is IERC20 {
    event Deposit(address indexed dst, uint256 wad);
    event Withdrawal(address indexed src, uint256 wad);

    function deposit() external payable;

    function withdraw(uint256 wad) external;
}
IPSwapAggregator.sol 37 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;

struct SwapData {
    SwapType swapType;
    address extRouter;
    bytes extCalldata;
    bool needScale;
}

struct SwapDataExtra {
    address tokenIn;
    address tokenOut;
    uint256 minOut;
    SwapData swapData;
}

enum SwapType {
    NONE,
    KYBERSWAP,
    ODOS,
    // ETH_WETH not used in Aggregator
    ETH_WETH,
    OKX,
    ONE_INCH,
    PARASWAP,
    RESERVE_2,
    RESERVE_3,
    RESERVE_4,
    RESERVE_5
}

interface IPSwapAggregator {
    event SwapSingle(SwapType indexed swapType, address indexed tokenIn, uint256 amountIn);

    function swap(address tokenIn, uint256 amountIn, SwapData calldata swapData) external payable;
}
OKXScaleHelper.sol 215 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;

import "../../core/libraries/TokenHelper.sol";
import "./IPSwapAggregator.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

abstract contract OKXScaleHelper {
    function _okx_getTokenApprove() internal view returns (address) {
        if (block.chainid == 1) {
            return 0x40aA958dd87FC8305b97f2BA922CDdCa374bcD7f;
        }
        if (block.chainid == 10) {
            return 0x68D6B739D2020067D1e2F713b999dA97E4d54812;
        }
        if (block.chainid == 56) {
            return 0x2c34A2Fb1d0b4f55de51E1d0bDEfaDDce6b7cDD6;
        }
        if (block.chainid == 42161) {
            return 0x70cBb871E8f30Fc8Ce23609E9E0Ea87B6b222F58;
        }
        if (block.chainid == 8453) {
            return 0x57df6092665eb6058DE53939612413ff4B09114E;
        }
        if (block.chainid == 5000) {
            return 0x57df6092665eb6058DE53939612413ff4B09114E;
        }

        revert("PendleSwap: OKX Chain not supported");
    }

    function _okxScaling(
        bytes calldata rawCallData,
        uint256 actualAmount
    ) internal pure returns (bytes memory scaledCallData) {
        bytes4 selector = bytes4(rawCallData[:4]);
        bytes calldata dataToDecode = rawCallData[4:];

        if (selector == IOKXDexRouter.uniswapV3SwapTo.selector) {
            (uint256 receiver, uint256 amount, uint256 minReturn, uint256[] memory pools) = abi.decode(
                dataToDecode,
                (uint256, uint256, uint256, uint256[])
            );

            minReturn = (minReturn * actualAmount) / amount;
            amount = actualAmount;

            return abi.encodeWithSelector(selector, receiver, amount, minReturn, pools);
        } else if (selector == IOKXDexRouter.smartSwapTo.selector) {
            (
                uint256 orderId,
                address receiver,
                IOKXDexRouter.BaseRequest memory baseRequest,
                uint256[] memory batchesAmount,
                IOKXDexRouter.RouterPath[][] memory batches,
                IOKXDexRouter.PMMSwapRequest[] memory extraData
            ) = abi.decode(
                    dataToDecode,
                    (
                        uint256,
                        address,
                        IOKXDexRouter.BaseRequest,
                        uint256[],
                        IOKXDexRouter.RouterPath[][],
                        IOKXDexRouter.PMMSwapRequest[]
                    )
                );

            batchesAmount = _scaleArray(batchesAmount, actualAmount, baseRequest.fromTokenAmount);
            baseRequest.minReturnAmount = (baseRequest.minReturnAmount * actualAmount) / baseRequest.fromTokenAmount;
            baseRequest.fromTokenAmount = actualAmount;

            return abi.encodeWithSelector(selector, orderId, receiver, baseRequest, batchesAmount, batches, extraData);
        } else if (selector == IOKXDexRouter.unxswapTo.selector) {
            (uint256 srcToken, uint256 amount, uint256 minReturn, address receiver, bytes32[] memory pools) = abi
                .decode(dataToDecode, (uint256, uint256, uint256, address, bytes32[]));

            minReturn = (minReturn * actualAmount) / amount;
            amount = actualAmount;

            return abi.encodeWithSelector(selector, srcToken, amount, minReturn, receiver, pools);
        } else if (selector == IOKXDexRouter.unxswapByOrderId.selector) {
            (uint256 srcToken, uint256 amount, uint256 minReturn, bytes32[] memory pools) = abi.decode(
                dataToDecode,
                (uint256, uint256, uint256, bytes32[])
            );

            minReturn = (minReturn * actualAmount) / amount;
            amount = actualAmount;

            return abi.encodeWithSelector(selector, srcToken, amount, minReturn, pools);
        } else if (selector == IOKXDexRouter.smartSwapByOrderId.selector) {
            (
                uint256 orderId,
                IOKXDexRouter.BaseRequest memory baseRequest,
                uint256[] memory batchesAmount,
                IOKXDexRouter.RouterPath[][] memory batches,
                IOKXDexRouter.PMMSwapRequest[] memory extraData
            ) = abi.decode(
                    dataToDecode,
                    (
                        uint256,
                        IOKXDexRouter.BaseRequest,
                        uint256[],
                        IOKXDexRouter.RouterPath[][],
                        IOKXDexRouter.PMMSwapRequest[]
                    )
                );

            batchesAmount = _scaleArray(batchesAmount, actualAmount, baseRequest.fromTokenAmount);
            baseRequest.minReturnAmount = (baseRequest.minReturnAmount * actualAmount) / baseRequest.fromTokenAmount;
            baseRequest.fromTokenAmount = actualAmount;

            return abi.encodeWithSelector(selector, orderId, baseRequest, batchesAmount, batches, extraData);
        } else {
            revert("PendleSwap: OKX selector not supported");
        }
    }

    function _scaleArray(
        uint256[] memory arr,
        uint256 newAmount,
        uint256 oldAmount
    ) internal pure returns (uint256[] memory scaledArr) {
        scaledArr = new uint256[](arr.length);
        for (uint256 i = 0; i < arr.length; i++) {
            scaledArr[i] = (arr[i] * newAmount) / oldAmount;
        }
    }
}

interface IOKXDexRouter {
    struct BaseRequest {
        uint256 fromToken;
        address toToken;
        uint256 fromTokenAmount;
        uint256 minReturnAmount;
        uint256 deadLine;
    }

    struct RouterPath {
        address[] mixAdapters;
        address[] assetTo;
        uint256[] rawData;
        bytes[] extraData;
        uint256 fromToken;
    }

    struct PMMSwapRequest {
        uint256 pathIndex;
        address payer;
        address fromToken;
        address toToken;
        uint256 fromTokenAmountMax;
        uint256 toTokenAmountMax;
        uint256 salt;
        uint256 deadLine;
        bool isPushOrder;
        bytes extension;
    }

    // // address marketMaker;
    // // uint256 subIndex;
    // // bytes signature;
    // // uint256 source;  1byte type + 1byte bool(reverse) + 0...0 + 20 bytes address

    // function smartSwapByInvest(
    //     BaseRequest calldata baseRequest,
    //     uint256[] calldata batchesAmount,
    //     RouterPath[][] calldata batches,
    //     PMMSwapRequest[] calldata extraData,
    //     address to
    // ) external payable;

    function uniswapV3SwapTo(
        uint256 receiver,
        uint256 amount,
        uint256 minReturn,
        uint256[] calldata pools
    ) external payable returns (uint256 returnAmount);

    function smartSwapTo(
        uint256 orderId,
        address receiver,
        BaseRequest calldata baseRequest,
        uint256[] calldata batchesAmount,
        RouterPath[][] calldata batches,
        PMMSwapRequest[] calldata extraData
    ) external payable;

    function unxswapTo(
        uint256 srcToken,
        uint256 amount,
        uint256 minReturn,
        address receiver,
        // solhint-disable-next-line no-unused-vars
        bytes32[] calldata pools
    ) external payable returns (uint256 returnAmount);

    function unxswapByOrderId(
        uint256 srcToken,
        uint256 amount,
        uint256 minReturn,
        // solhint-disable-next-line no-unused-vars
        bytes32[] calldata pools
    ) external payable returns (uint256 returnAmount);

    function smartSwapByOrderId(
        uint256 orderId,
        BaseRequest calldata baseRequest,
        uint256[] calldata batchesAmount,
        RouterPath[][] calldata batches,
        PMMSwapRequest[] calldata extraData
    ) external payable returns (uint256 returnAmount);
}
ParaswapScaleHelper.sol 252 lines
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.17;

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

interface IAugustusV6 {
    // ============ Generic Swap ============
    struct GenericData {
        IERC20 srcToken;
        IERC20 destToken;
        uint256 fromAmount;
        uint256 toAmount;
        uint256 quotedAmount;
        bytes32 metadata;
        address payable beneficiary;
    }

    function swapExactAmountIn(
        address executor,
        GenericData calldata swapData,
        uint256 partnerAndFee,
        bytes calldata permit,
        bytes calldata executorData
    ) external payable;

    // ============ UniswapV2 Swap ============
    struct UniswapV2Data {
        IERC20 srcToken;
        IERC20 destToken;
        uint256 fromAmount;
        uint256 toAmount;
        uint256 quotedAmount;
        bytes32 metadata;
        address payable beneficiary;
        bytes pools;
    }

    function swapExactAmountInOnUniswapV2(
        UniswapV2Data calldata uniData,
        uint256 partnerAndFee,
        bytes calldata permit
    ) external payable returns (uint256 receivedAmount, uint256 paraswapShare, uint256 partnerShare);

    // ============ UniswapV3 Swap ============
    struct UniswapV3Data {
        IERC20 srcToken;
        IERC20 destToken;
        uint256 fromAmount;
        uint256 toAmount;
        uint256 quotedAmount;
        bytes32 metadata;
        address payable beneficiary;
        bytes pools;
    }

    function swapExactAmountInOnUniswapV3(
        UniswapV3Data calldata uniData,
        uint256 partnerAndFee,
        bytes calldata permit
    ) external payable returns (uint256 receivedAmount, uint256 paraswapShare, uint256 partnerShare);

    // ============ BalancerV2 Swap ============
    struct BalancerV2Data {
        uint256 fromAmount;
        uint256 toAmount;
        uint256 quotedAmount;
        bytes32 metadata;
        uint256 beneficiaryAndApproveFlag;
    }

    function swapExactAmountInOnBalancerV2(
        BalancerV2Data calldata balancerData,
        uint256 partnerAndFee,
        bytes calldata permit,
        bytes calldata data
    ) external payable returns (uint256 receivedAmount, uint256 paraswapShare, uint256 partnerShare);

    // ============ CurveV1 Swap ============
    struct CurveV1Data {
        uint256 curveData;
        uint256 curveAssets;
        IERC20 srcToken;
        IERC20 destToken;
        uint256 fromAmount;
        uint256 toAmount;
        uint256 quotedAmount;
        bytes32 metadata;
        address payable beneficiary;
    }

    function swapExactAmountInOnCurveV1(
        CurveV1Data calldata curveV1Data,
        uint256 partnerAndFee,
        bytes calldata permit
    ) external payable returns (uint256 receivedAmount, uint256 paraswapShare, uint256 partnerShare);

    // ============ CurveV2 Swap ============
    struct CurveV2Data {
        uint256 curveData;
        uint256 i;
        uint256 j;
        address poolAddress;
        IERC20 srcToken;
        IERC20 destToken;
        uint256 fromAmount;
        uint256 toAmount;
        uint256 quotedAmount;
        bytes32 metadata;
        address payable beneficiary;
    }

    function swapExactAmountInOnCurveV2(
        CurveV2Data calldata curveV2Data,
        uint256 partnerAndFee,
        bytes calldata permit
    ) external payable returns (uint256 receivedAmount, uint256 paraswapShare, uint256 partnerShare);

    // ============ MakerPSM Swap ============
    struct MakerPSMData {
        IERC20 srcToken;
        IERC20 destToken;
        uint256 fromAmount;
        uint256 toAmount;
        uint256 toll;
        uint256 to18ConversionFactor;
        address exchange;
        address gemJoinAddress;
        bytes32 metadata;
        uint256 beneficiaryDirectionApproveFlag;
    }

    function swapExactAmountInOutOnMakerPSM(
        MakerPSMData calldata makerPSMData,
        bytes calldata permit
    ) external returns (uint256 spentAmount, uint256 receivedAmount);
}

contract ParaswapScaleHelper {
    function _paraswapScaling(
        bytes calldata rawCallData,
        uint256 amountIn
    ) internal pure returns (bytes memory scaledCallData) {
        bytes4 selector = bytes4(rawCallData[:4]);
        bytes calldata dataToDecode = rawCallData[4:];

        // Handle Generic Swap
        if (selector == IAugustusV6.swapExactAmountIn.selector) {
            (
                address executor,
                IAugustusV6.GenericData memory swapData,
                uint256 partnerAndFee,
                bytes memory permit,
                bytes memory executorData
            ) = abi.decode(dataToDecode, (address, IAugustusV6.GenericData, uint256, bytes, bytes));

            // Direct scaling calculation
            swapData.toAmount = (swapData.toAmount * amountIn) / swapData.fromAmount;
            swapData.quotedAmount = (swapData.quotedAmount * amountIn) / swapData.fromAmount;
            swapData.fromAmount = amountIn;

            return abi.encodeWithSelector(selector, executor, swapData, partnerAndFee, permit, executorData);
        }
        // Handle UniswapV2
        else if (selector == IAugustusV6.swapExactAmountInOnUniswapV2.selector) {
            (IAugustusV6.UniswapV2Data memory uniData, uint256 partnerAndFee, bytes memory permit) = abi.decode(
                dataToDecode,
                (IAugustusV6.UniswapV2Data, uint256, bytes)
            );

            // Direct scaling calculation
            uniData.toAmount = (uniData.toAmount * amountIn) / uniData.fromAmount;
            uniData.quotedAmount = (uniData.quotedAmount * amountIn) / uniData.fromAmount;
            uniData.fromAmount = amountIn;

            return abi.encodeWithSelector(selector, uniData, partnerAndFee, permit);
        }
        // Handle UniswapV3
        else if (selector == IAugustusV6.swapExactAmountInOnUniswapV3.selector) {
            (IAugustusV6.UniswapV3Data memory uniV3Data, uint256 partnerAndFee, bytes memory permit) = abi.decode(
                dataToDecode,
                (IAugustusV6.UniswapV3Data, uint256, bytes)
            );

            // Direct scaling calculation
            uniV3Data.toAmount = (uniV3Data.toAmount * amountIn) / uniV3Data.fromAmount;
            uniV3Data.quotedAmount = (uniV3Data.quotedAmount * amountIn) / uniV3Data.fromAmount;
            uniV3Data.fromAmount = amountIn;

            return abi.encodeWithSelector(selector, uniV3Data, partnerAndFee, permit);
        }
        // Handle BalancerV2
        else if (selector == IAugustusV6.swapExactAmountInOnBalancerV2.selector) {
            (
                IAugustusV6.BalancerV2Data memory balancerData,
                uint256 partnerAndFee,
                bytes memory permit,
                bytes memory data
            ) = abi.decode(dataToDecode, (IAugustusV6.BalancerV2Data, uint256, bytes, bytes));

            // Direct scaling calculation
            balancerData.toAmount = (balancerData.toAmount * amountIn) / balancerData.fromAmount;
            balancerData.quotedAmount = (balancerData.quotedAmount * amountIn) / balancerData.fromAmount;
            balancerData.fromAmount = amountIn;

            return abi.encodeWithSelector(selector, balancerData, partnerAndFee, permit, data);
        }
        // Handle CurveV1
        else if (selector == IAugustusV6.swapExactAmountInOnCurveV1.selector) {
            (IAugustusV6.CurveV1Data memory curveV1Data, uint256 partnerAndFee, bytes memory permit) = abi.decode(
                dataToDecode,
                (IAugustusV6.CurveV1Data, uint256, bytes)
            );

            // Direct scaling calculation
            curveV1Data.toAmount = (curveV1Data.toAmount * amountIn) / curveV1Data.fromAmount;
            curveV1Data.quotedAmount = (curveV1Data.quotedAmount * amountIn) / curveV1Data.fromAmount;
            curveV1Data.fromAmount = amountIn;

            return abi.encodeWithSelector(selector, curveV1Data, partnerAndFee, permit);
        }
        // Handle CurveV2
        else if (selector == IAugustusV6.swapExactAmountInOnCurveV2.selector) {
            (IAugustusV6.CurveV2Data memory curveV2Data, uint256 partnerAndFee, bytes memory permit) = abi.decode(
                dataToDecode,
                (IAugustusV6.CurveV2Data, uint256, bytes)
            );

            // Direct scaling calculation
            curveV2Data.toAmount = (curveV2Data.toAmount * amountIn) / curveV2Data.fromAmount;
            curveV2Data.quotedAmount = (curveV2Data.quotedAmount * amountIn) / curveV2Data.fromAmount;
            curveV2Data.fromAmount = amountIn;

            return abi.encodeWithSelector(selector, curveV2Data, partnerAndFee, permit);
        }
        // Handle MakerPSM
        else if (selector == IAugustusV6.swapExactAmountInOutOnMakerPSM.selector) {
            (IAugustusV6.MakerPSMData memory makerPSMData, bytes memory permit) = abi.decode(
                dataToDecode,
                (IAugustusV6.MakerPSMData, bytes)
            );

            // Direct scaling calculation
            makerPSMData.toAmount = (makerPSMData.toAmount * amountIn) / makerPSMData.fromAmount;
            makerPSMData.fromAmount = amountIn;

            return abi.encodeWithSelector(selector, makerPSMData, permit);
        }

        revert("ParaswapScaleHelper: Unsupported swap selector");
    }
}
PendleSwap.sol 115 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;

import "../../core/libraries/TokenHelper.sol";
import "./IPSwapAggregator.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "./OKXScaleHelper.sol";
import "./ParaswapScaleHelper.sol";

contract PendleSwap is IPSwapAggregator, TokenHelper, OKXScaleHelper, ParaswapScaleHelper {
    using Address for address;
    using SafeERC20 for IERC20;

    address private constant KYBER_SCALING_HELPER = 0x2f577A41BeC1BE1152AeEA12e73b7391d15f655D;

    function swap(address tokenIn, uint256 amountIn, SwapData calldata data) external payable {
        _approveForExtRouter(tokenIn, data);
        data.extRouter.functionCallWithValue(
            data.needScale ? _getScaledInputData(data.swapType, data.extCalldata, amountIn) : data.extCalldata,
            tokenIn == NATIVE ? amountIn : 0
        );

        emit SwapSingle(data.swapType, tokenIn, amountIn);
    }

    function _approveForExtRouter(address token, SwapData calldata data) internal {
        if (token == NATIVE) return;

        if (data.swapType == SwapType.OKX) {
            _safeApproveInfV2(IERC20(token), _okx_getTokenApprove());
        } else {
            _safeApproveInfV2(IERC20(token), data.extRouter);
        }
    }

    function _safeApproveInfV2(IERC20 token, address spender) internal {
        if (token.allowance(address(this), spender) < type(uint256).max) {
            token.forceApprove(spender, type(uint256).max);
        }
    }

    function _getScaledInputData(
        SwapType swapType,
        bytes calldata rawCallData,
        uint256 amountIn
    ) internal view returns (bytes memory scaledCallData) {
        if (swapType == SwapType.KYBERSWAP) {
            bool isSuccess;
            (isSuccess, scaledCallData) = IKyberScalingHelper(KYBER_SCALING_HELPER).getScaledInputData(
                rawCallData,
                amountIn
            );

            require(isSuccess, "PendleSwap: Kyber scaling failed");
        } else if (swapType == SwapType.ODOS) {
            scaledCallData = _odosScaling(rawCallData, amountIn);
        } else if (swapType == SwapType.PARASWAP) {
            scaledCallData = _paraswapScaling(rawCallData, amountIn);
        } else if (swapType == SwapType.OKX) {
            scaledCallData = _okxScaling(rawCallData, amountIn);
        } else {
            assert(false);
        }
    }

    function _odosScaling(
        bytes calldata rawCallData,
        uint256 amountIn
    ) internal pure returns (bytes memory scaledCallData) {
        bytes4 selector = bytes4(rawCallData[:4]);
        bytes calldata dataToDecode = rawCallData[4:];

        assert(selector == IOdosRouterV2.swap.selector);
        (
            IOdosRouterV2.swapTokenInfo memory tokenInfo,
            bytes memory pathDefinition,
            address executor,
            uint32 referralCode
        ) = abi.decode(dataToDecode, (IOdosRouterV2.swapTokenInfo, bytes, address, uint32));

        tokenInfo.outputQuote = (tokenInfo.outputQuote * amountIn) / tokenInfo.inputAmount;
        tokenInfo.outputMin = (tokenInfo.outputMin * amountIn) / tokenInfo.inputAmount;
        tokenInfo.inputAmount = amountIn;

        return abi.encodeWithSelector(selector, tokenInfo, pathDefinition, executor, referralCode);
    }

    receive() external payable {}
}

interface IKyberScalingHelper {
    function getScaledInputData(
        bytes calldata inputData,
        uint256 newAmount
    ) external view returns (bool isSuccess, bytes memory data);
}

interface IOdosRouterV2 {
    struct swapTokenInfo {
        address inputToken;
        uint256 inputAmount;
        address inputReceiver;
        address outputToken;
        uint256 outputQuote;
        uint256 outputMin;
        address outputReceiver;
    }

    function swap(
        swapTokenInfo memory tokenInfo,
        bytes calldata pathDefinition,
        address executor,
        uint32 referralCode
    ) external payable returns (uint256 amountOut);
}

Write Contract 1 functions

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

swap 0xfd472065
address tokenIn
uint256 amountIn
tuple data

Recent Transactions

No transactions found for this address