From 094fcb157f46aaab0e93e22d73dca9b78f0d0a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Brand=C3=A3o?= Date: Mon, 4 Dec 2023 20:33:18 +0000 Subject: [PATCH] Adjusting RouterSimulator interface RouterSimulator now supports several input/output assets. --- core/src/abis/RouterSimulator.json | 26 ++-- core/src/config/config.default.ts | 4 +- core/src/path/tx-simulator.ts | 57 +++++---- core/tests/protocols/aave.spec.ts | 30 +++-- core/tests/protocols/balancer.spec.ts | 34 +++-- core/tests/protocols/beefy.spec.ts | 34 +++-- core/tests/protocols/gamma.spec.ts | 121 +++++++++++++----- core/tests/protocols/paraswap.spec.ts | 8 +- .../protocols/uniswapV2Liquidity.spec.ts | 71 +++++++--- core/tests/protocols/utils.ts | 26 ++-- router/contracts/RouterSimulator.sol | 34 +++-- 11 files changed, 311 insertions(+), 134 deletions(-) diff --git a/core/src/abis/RouterSimulator.json b/core/src/abis/RouterSimulator.json index 3a58fb9..30b1a1a 100644 --- a/core/src/abis/RouterSimulator.json +++ b/core/src/abis/RouterSimulator.json @@ -11,19 +11,19 @@ "type": "address" }, { - "internalType": "address", - "name": "inputToken", - "type": "address" + "internalType": "address[]", + "name": "inputTokens", + "type": "address[]" }, { - "internalType": "uint256", - "name": "inputAmount", - "type": "uint256" + "internalType": "uint256[]", + "name": "inputAmounts", + "type": "uint256[]" }, { - "internalType": "address", - "name": "outputToken", - "type": "address" + "internalType": "address[]", + "name": "outputTokens", + "type": "address[]" }, { "components": [ @@ -78,17 +78,17 @@ "name": "simulateJamTx", "outputs": [ { - "internalType": "uint256", + "internalType": "uint256[]", "name": "", - "type": "uint256" + "type": "uint256[]" } ], "stateMutability": "nonpayable", "type": "function" } ], - "bytecode": "0x608060405234801561001057600080fd5b50610e86806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063c9dd0ada14610030575b600080fd5b61004a6004803603810190610045919061057a565b610060565b6040516100579190610654565b60405180910390f35b6000808573ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b815260040161009c919061067e565b602060405180830381865afa1580156100b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100dd91906106ae565b90508773ffffffffffffffffffffffffffffffffffffffff166323b872dd33308a6040518463ffffffff1660e01b815260040161011c939291906106db565b6020604051808303816000875af115801561013b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061015f919061074a565b5060008973ffffffffffffffffffffffffffffffffffffffff166392bc950560e01b87878760405160240161019693929190610caf565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516102009190610d59565b600060405180830381855af49150503d806000811461023b576040519150601f19603f3d011682016040523d82523d6000602084013e610240565b606091505b5050905080610284576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161027b90610dcd565b60405180910390fd5b60008773ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016102bf919061067e565b602060405180830381865afa1580156102dc573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061030091906106ae565b9050828161030e9190610e1c565b9350505050979650505050505050565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061035d82610332565b9050919050565b61036d81610352565b811461037857600080fd5b50565b60008135905061038a81610364565b92915050565b6000819050919050565b6103a381610390565b81146103ae57600080fd5b50565b6000813590506103c08161039a565b92915050565b600080fd5b600080fd5b600080fd5b60008083601f8401126103eb576103ea6103c6565b5b8235905067ffffffffffffffff811115610408576104076103cb565b5b602083019150836020820283011115610424576104236103d0565b5b9250929050565b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6104748261042b565b810181811067ffffffffffffffff821117156104935761049261043c565b5b80604052505050565b60006104a661031e565b90506104b2828261046b565b919050565b600067ffffffffffffffff8211156104d2576104d161043c565b5b602082029050602081019050919050565b60006104f66104f1846104b7565b61049c565b90508083825260208201905060208402830185811115610519576105186103d0565b5b835b81811015610542578061052e88826103b1565b84526020840193505060208101905061051b565b5050509392505050565b600082601f830112610561576105606103c6565b5b81356105718482602086016104e3565b91505092915050565b600080600080600080600060c0888a03121561059957610598610328565b5b60006105a78a828b0161037b565b97505060206105b88a828b0161037b565b96505060406105c98a828b016103b1565b95505060606105da8a828b0161037b565b945050608088013567ffffffffffffffff8111156105fb576105fa61032d565b5b6106078a828b016103d5565b935093505060a088013567ffffffffffffffff81111561062a5761062961032d565b5b6106368a828b0161054c565b91505092959891949750929550565b61064e81610390565b82525050565b60006020820190506106696000830184610645565b92915050565b61067881610352565b82525050565b6000602082019050610693600083018461066f565b92915050565b6000815190506106a88161039a565b92915050565b6000602082840312156106c4576106c3610328565b5b60006106d284828501610699565b91505092915050565b60006060820190506106f0600083018661066f565b6106fd602083018561066f565b61070a6040830184610645565b949350505050565b60008115159050919050565b61072781610712565b811461073257600080fd5b50565b6000815190506107448161071e565b92915050565b6000602082840312156107605761075f610328565b5b600061076e84828501610735565b91505092915050565b600082825260208201905092915050565b6000819050919050565b60006107a1602084018461037b565b905092915050565b6107b281610352565b82525050565b600080fd5b600080fd5b600080fd5b600080833560016020038436030381126107e4576107e36107c2565b5b83810192508235915060208301925067ffffffffffffffff82111561080c5761080b6107b8565b5b600182023603831315610822576108216107bd565b5b509250929050565b600082825260208201905092915050565b82818337600083830152505050565b6000610856838561082a565b935061086383858461083b565b61086c8361042b565b840190509392505050565b60008083356001602003843603038112610894576108936107c2565b5b83810192508235915060208301925067ffffffffffffffff8211156108bc576108bb6107b8565b5b6080820236038313156108d2576108d16107bd565b5b509250929050565b600082825260208201905092915050565b6000819050919050565b6005811061090257600080fd5b50565b600081359050610914816108f5565b92915050565b60006109296020840184610905565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b6005811061097157610970610931565b5b50565b600081905061098282610960565b919050565b600061099282610974565b9050919050565b6109a281610987565b82525050565b60006109b760208401846103b1565b905092915050565b6109c881610390565b82525050565b608082016109df600083018361091a565b6109ec6000850182610999565b506109fa60208301836109a8565b610a0760208501826109bf565b50610a1560408301836109a8565b610a2260408501826109bf565b50610a3060608301836109a8565b610a3d60608501826109bf565b50505050565b6000610a4f83836109ce565b60808301905092915050565b600082905092915050565b6000608082019050919050565b6000610a7f83856108da565b9350610a8a826108eb565b8060005b85811015610ac357610aa08284610a5b565b610aaa8882610a43565b9750610ab583610a66565b925050600181019050610a8e565b5085925050509392505050565b600060608301610ae36000840184610792565b610af060008601826107a9565b50610afe60208401846107c7565b8583036020870152610b1183828461084a565b92505050610b226040840184610877565b8583036040870152610b35838284610a73565b925050508091505092915050565b6000610b4f8383610ad0565b905092915050565b600082356001606003833603038112610b7357610b726107c2565b5b82810191505092915050565b6000602082019050919050565b6000610b988385610777565b935083602084028501610baa84610788565b8060005b87811015610bee578484038952610bc58284610b57565b610bcf8582610b43565b9450610bda83610b7f565b925060208a01995050600181019050610bae565b50829750879450505050509392505050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6000610c3883836109bf565b60208301905092915050565b6000602082019050919050565b6000610c5c82610c00565b610c668185610c0b565b9350610c7183610c1c565b8060005b83811015610ca2578151610c898882610c2c565b9750610c9483610c44565b925050600181019050610c75565b5085935050505092915050565b60006040820190508181036000830152610cca818587610b8c565b90508181036020830152610cde8184610c51565b9050949350505050565b600081519050919050565b600081905092915050565b60005b83811015610d1c578082015181840152602081019050610d01565b60008484015250505050565b6000610d3382610ce8565b610d3d8185610cf3565b9350610d4d818560208601610cfe565b80840191505092915050565b6000610d658284610d28565b915081905092915050565b600082825260208201905092915050565b7f44656c656761746563616c6c206661696c656400000000000000000000000000600082015250565b6000610db7601383610d70565b9150610dc282610d81565b602082019050919050565b60006020820190508181036000830152610de681610daa565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610e2782610390565b9150610e3283610390565b9250828203905081811115610e4a57610e49610ded565b5b9291505056fea2646970667358221220853031ee8e7a3740244e907a90596bb2cb4591af185116003427df2167885f4864736f6c63430008140033", - "deployedBytecode": "0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063c9dd0ada14610030575b600080fd5b61004a6004803603810190610045919061057a565b610060565b6040516100579190610654565b60405180910390f35b6000808573ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b815260040161009c919061067e565b602060405180830381865afa1580156100b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100dd91906106ae565b90508773ffffffffffffffffffffffffffffffffffffffff166323b872dd33308a6040518463ffffffff1660e01b815260040161011c939291906106db565b6020604051808303816000875af115801561013b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061015f919061074a565b5060008973ffffffffffffffffffffffffffffffffffffffff166392bc950560e01b87878760405160240161019693929190610caf565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516102009190610d59565b600060405180830381855af49150503d806000811461023b576040519150601f19603f3d011682016040523d82523d6000602084013e610240565b606091505b5050905080610284576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161027b90610dcd565b60405180910390fd5b60008773ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016102bf919061067e565b602060405180830381865afa1580156102dc573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061030091906106ae565b9050828161030e9190610e1c565b9350505050979650505050505050565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061035d82610332565b9050919050565b61036d81610352565b811461037857600080fd5b50565b60008135905061038a81610364565b92915050565b6000819050919050565b6103a381610390565b81146103ae57600080fd5b50565b6000813590506103c08161039a565b92915050565b600080fd5b600080fd5b600080fd5b60008083601f8401126103eb576103ea6103c6565b5b8235905067ffffffffffffffff811115610408576104076103cb565b5b602083019150836020820283011115610424576104236103d0565b5b9250929050565b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6104748261042b565b810181811067ffffffffffffffff821117156104935761049261043c565b5b80604052505050565b60006104a661031e565b90506104b2828261046b565b919050565b600067ffffffffffffffff8211156104d2576104d161043c565b5b602082029050602081019050919050565b60006104f66104f1846104b7565b61049c565b90508083825260208201905060208402830185811115610519576105186103d0565b5b835b81811015610542578061052e88826103b1565b84526020840193505060208101905061051b565b5050509392505050565b600082601f830112610561576105606103c6565b5b81356105718482602086016104e3565b91505092915050565b600080600080600080600060c0888a03121561059957610598610328565b5b60006105a78a828b0161037b565b97505060206105b88a828b0161037b565b96505060406105c98a828b016103b1565b95505060606105da8a828b0161037b565b945050608088013567ffffffffffffffff8111156105fb576105fa61032d565b5b6106078a828b016103d5565b935093505060a088013567ffffffffffffffff81111561062a5761062961032d565b5b6106368a828b0161054c565b91505092959891949750929550565b61064e81610390565b82525050565b60006020820190506106696000830184610645565b92915050565b61067881610352565b82525050565b6000602082019050610693600083018461066f565b92915050565b6000815190506106a88161039a565b92915050565b6000602082840312156106c4576106c3610328565b5b60006106d284828501610699565b91505092915050565b60006060820190506106f0600083018661066f565b6106fd602083018561066f565b61070a6040830184610645565b949350505050565b60008115159050919050565b61072781610712565b811461073257600080fd5b50565b6000815190506107448161071e565b92915050565b6000602082840312156107605761075f610328565b5b600061076e84828501610735565b91505092915050565b600082825260208201905092915050565b6000819050919050565b60006107a1602084018461037b565b905092915050565b6107b281610352565b82525050565b600080fd5b600080fd5b600080fd5b600080833560016020038436030381126107e4576107e36107c2565b5b83810192508235915060208301925067ffffffffffffffff82111561080c5761080b6107b8565b5b600182023603831315610822576108216107bd565b5b509250929050565b600082825260208201905092915050565b82818337600083830152505050565b6000610856838561082a565b935061086383858461083b565b61086c8361042b565b840190509392505050565b60008083356001602003843603038112610894576108936107c2565b5b83810192508235915060208301925067ffffffffffffffff8211156108bc576108bb6107b8565b5b6080820236038313156108d2576108d16107bd565b5b509250929050565b600082825260208201905092915050565b6000819050919050565b6005811061090257600080fd5b50565b600081359050610914816108f5565b92915050565b60006109296020840184610905565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b6005811061097157610970610931565b5b50565b600081905061098282610960565b919050565b600061099282610974565b9050919050565b6109a281610987565b82525050565b60006109b760208401846103b1565b905092915050565b6109c881610390565b82525050565b608082016109df600083018361091a565b6109ec6000850182610999565b506109fa60208301836109a8565b610a0760208501826109bf565b50610a1560408301836109a8565b610a2260408501826109bf565b50610a3060608301836109a8565b610a3d60608501826109bf565b50505050565b6000610a4f83836109ce565b60808301905092915050565b600082905092915050565b6000608082019050919050565b6000610a7f83856108da565b9350610a8a826108eb565b8060005b85811015610ac357610aa08284610a5b565b610aaa8882610a43565b9750610ab583610a66565b925050600181019050610a8e565b5085925050509392505050565b600060608301610ae36000840184610792565b610af060008601826107a9565b50610afe60208401846107c7565b8583036020870152610b1183828461084a565b92505050610b226040840184610877565b8583036040870152610b35838284610a73565b925050508091505092915050565b6000610b4f8383610ad0565b905092915050565b600082356001606003833603038112610b7357610b726107c2565b5b82810191505092915050565b6000602082019050919050565b6000610b988385610777565b935083602084028501610baa84610788565b8060005b87811015610bee578484038952610bc58284610b57565b610bcf8582610b43565b9450610bda83610b7f565b925060208a01995050600181019050610bae565b50829750879450505050509392505050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6000610c3883836109bf565b60208301905092915050565b6000602082019050919050565b6000610c5c82610c00565b610c668185610c0b565b9350610c7183610c1c565b8060005b83811015610ca2578151610c898882610c2c565b9750610c9483610c44565b925050600181019050610c75565b5085935050505092915050565b60006040820190508181036000830152610cca818587610b8c565b90508181036020830152610cde8184610c51565b9050949350505050565b600081519050919050565b600081905092915050565b60005b83811015610d1c578082015181840152602081019050610d01565b60008484015250505050565b6000610d3382610ce8565b610d3d8185610cf3565b9350610d4d818560208601610cfe565b80840191505092915050565b6000610d658284610d28565b915081905092915050565b600082825260208201905092915050565b7f44656c656761746563616c6c206661696c656400000000000000000000000000600082015250565b6000610db7601383610d70565b9150610dc282610d81565b602082019050919050565b60006020820190508181036000830152610de681610daa565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610e2782610390565b9150610e3283610390565b9250828203905081811115610e4a57610e49610ded565b5b9291505056fea2646970667358221220853031ee8e7a3740244e907a90596bb2cb4591af185116003427df2167885f4864736f6c63430008140033", + "bytecode": "0x608060405234801561001057600080fd5b50611226806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063afdda9f714610030575b600080fd5b61004a6004803603810190610045919061080e565b610060565b60405161005791906109f8565b60405180910390f35b606060008686905067ffffffffffffffff8111156100815761008061069a565b5b6040519080825280602002602001820160405280156100af5781602001602082028036833780820191505090505b50905060005b87879050811015610193578787828181106100d3576100d2610a1a565b5b90506020020160208101906100e89190610a49565b73ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016101209190610a85565b602060405180830381865afa15801561013d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101619190610ab5565b82828151811061017457610173610a1a565b5b602002602001018181525050808061018b90610b11565b9150506100b5565b5060005b8b8b9050811015610276578b8b828181106101b5576101b4610a1a565b5b90506020020160208101906101ca9190610a49565b73ffffffffffffffffffffffffffffffffffffffff166323b872dd33308d8d868181106101fa576101f9610a1a565b5b905060200201356040518463ffffffff1660e01b815260040161021f93929190610b68565b6020604051808303816000875af115801561023e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102629190610bd7565b50808061026e90610b11565b915050610197565b5060008c73ffffffffffffffffffffffffffffffffffffffff166392bc950560e01b8787876040516024016102ad9392919061107e565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516103179190611128565b600060405180830381855af49150503d8060008114610352576040519150601f19603f3d011682016040523d82523d6000602084013e610357565b606091505b505090508061039b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103929061119c565b60405180910390fd5b60008888905067ffffffffffffffff8111156103ba576103b961069a565b5b6040519080825280602002602001820160405280156103e85781602001602082028036833780820191505090505b50905060005b898990508110156104f15789898281811061040c5761040b610a1a565b5b90506020020160208101906104219190610a49565b73ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016104599190610a85565b602060405180830381865afa158015610476573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061049a9190610ab5565b8482815181106104ad576104ac610a1a565b5b60200260200101516104bf91906111bc565b8282815181106104d2576104d1610a1a565b5b60200260200101818152505080806104e990610b11565b9150506103ee565b508093505050509a9950505050505050505050565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006105458261051a565b9050919050565b6105558161053a565b811461056057600080fd5b50565b6000813590506105728161054c565b92915050565b600080fd5b600080fd5b600080fd5b60008083601f84011261059d5761059c610578565b5b8235905067ffffffffffffffff8111156105ba576105b961057d565b5b6020830191508360208202830111156105d6576105d5610582565b5b9250929050565b60008083601f8401126105f3576105f2610578565b5b8235905067ffffffffffffffff8111156106105761060f61057d565b5b60208301915083602082028301111561062c5761062b610582565b5b9250929050565b60008083601f84011261064957610648610578565b5b8235905067ffffffffffffffff8111156106665761066561057d565b5b60208301915083602082028301111561068257610681610582565b5b9250929050565b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6106d282610689565b810181811067ffffffffffffffff821117156106f1576106f061069a565b5b80604052505050565b6000610704610506565b905061071082826106c9565b919050565b600067ffffffffffffffff8211156107305761072f61069a565b5b602082029050602081019050919050565b6000819050919050565b61075481610741565b811461075f57600080fd5b50565b6000813590506107718161074b565b92915050565b600061078a61078584610715565b6106fa565b905080838252602082019050602084028301858111156107ad576107ac610582565b5b835b818110156107d657806107c28882610762565b8452602084019350506020810190506107af565b5050509392505050565b600082601f8301126107f5576107f4610578565b5b8135610805848260208601610777565b91505092915050565b60008060008060008060008060008060c08b8d03121561083157610830610510565b5b600061083f8d828e01610563565b9a505060208b013567ffffffffffffffff8111156108605761085f610515565b5b61086c8d828e01610587565b995099505060408b013567ffffffffffffffff81111561088f5761088e610515565b5b61089b8d828e016105dd565b975097505060608b013567ffffffffffffffff8111156108be576108bd610515565b5b6108ca8d828e01610587565b955095505060808b013567ffffffffffffffff8111156108ed576108ec610515565b5b6108f98d828e01610633565b935093505060a08b013567ffffffffffffffff81111561091c5761091b610515565b5b6109288d828e016107e0565b9150509295989b9194979a5092959850565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b61096f81610741565b82525050565b60006109818383610966565b60208301905092915050565b6000602082019050919050565b60006109a58261093a565b6109af8185610945565b93506109ba83610956565b8060005b838110156109eb5781516109d28882610975565b97506109dd8361098d565b9250506001810190506109be565b5085935050505092915050565b60006020820190508181036000830152610a12818461099a565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600060208284031215610a5f57610a5e610510565b5b6000610a6d84828501610563565b91505092915050565b610a7f8161053a565b82525050565b6000602082019050610a9a6000830184610a76565b92915050565b600081519050610aaf8161074b565b92915050565b600060208284031215610acb57610aca610510565b5b6000610ad984828501610aa0565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610b1c82610741565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610b4e57610b4d610ae2565b5b600182019050919050565b610b6281610741565b82525050565b6000606082019050610b7d6000830186610a76565b610b8a6020830185610a76565b610b976040830184610b59565b949350505050565b60008115159050919050565b610bb481610b9f565b8114610bbf57600080fd5b50565b600081519050610bd181610bab565b92915050565b600060208284031215610bed57610bec610510565b5b6000610bfb84828501610bc2565b91505092915050565b600082825260208201905092915050565b6000819050919050565b6000610c2e6020840184610563565b905092915050565b610c3f8161053a565b82525050565b600080fd5b600080fd5b600080fd5b60008083356001602003843603038112610c7157610c70610c4f565b5b83810192508235915060208301925067ffffffffffffffff821115610c9957610c98610c45565b5b600182023603831315610caf57610cae610c4a565b5b509250929050565b600082825260208201905092915050565b82818337600083830152505050565b6000610ce38385610cb7565b9350610cf0838584610cc8565b610cf983610689565b840190509392505050565b60008083356001602003843603038112610d2157610d20610c4f565b5b83810192508235915060208301925067ffffffffffffffff821115610d4957610d48610c45565b5b608082023603831315610d5f57610d5e610c4a565b5b509250929050565b600082825260208201905092915050565b6000819050919050565b60078110610d8f57600080fd5b50565b600081359050610da181610d82565b92915050565b6000610db66020840184610d92565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b60078110610dfe57610dfd610dbe565b5b50565b6000819050610e0f82610ded565b919050565b6000610e1f82610e01565b9050919050565b610e2f81610e14565b82525050565b6000610e446020840184610762565b905092915050565b60808201610e5d6000830183610da7565b610e6a6000850182610e26565b50610e786020830183610e35565b610e856020850182610966565b50610e936040830183610e35565b610ea06040850182610966565b50610eae6060830183610e35565b610ebb6060850182610966565b50505050565b6000610ecd8383610e4c565b60808301905092915050565b600082905092915050565b6000608082019050919050565b6000610efd8385610d67565b9350610f0882610d78565b8060005b85811015610f4157610f1e8284610ed9565b610f288882610ec1565b9750610f3383610ee4565b925050600181019050610f0c565b5085925050509392505050565b600060608301610f616000840184610c1f565b610f6e6000860182610c36565b50610f7c6020840184610c54565b8583036020870152610f8f838284610cd7565b92505050610fa06040840184610d04565b8583036040870152610fb3838284610ef1565b925050508091505092915050565b6000610fcd8383610f4e565b905092915050565b600082356001606003833603038112610ff157610ff0610c4f565b5b82810191505092915050565b6000602082019050919050565b60006110168385610c04565b93508360208402850161102884610c15565b8060005b8781101561106c5784840389526110438284610fd5565b61104d8582610fc1565b945061105883610ffd565b925060208a0199505060018101905061102c565b50829750879450505050509392505050565b6000604082019050818103600083015261109981858761100a565b905081810360208301526110ad818461099a565b9050949350505050565b600081519050919050565b600081905092915050565b60005b838110156110eb5780820151818401526020810190506110d0565b60008484015250505050565b6000611102826110b7565b61110c81856110c2565b935061111c8185602086016110cd565b80840191505092915050565b600061113482846110f7565b915081905092915050565b600082825260208201905092915050565b7f44656c656761746563616c6c206661696c656400000000000000000000000000600082015250565b600061118660138361113f565b915061119182611150565b602082019050919050565b600060208201905081810360008301526111b581611179565b9050919050565b60006111c782610741565b91506111d283610741565b92508282039050818111156111ea576111e9610ae2565b5b9291505056fea2646970667358221220b577f33777d022a72e70ac76099924ef9b0fe530ceb7c92dc3c164dd05291b0e64736f6c63430008140033", + "deployedBytecode": "0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063afdda9f714610030575b600080fd5b61004a6004803603810190610045919061080e565b610060565b60405161005791906109f8565b60405180910390f35b606060008686905067ffffffffffffffff8111156100815761008061069a565b5b6040519080825280602002602001820160405280156100af5781602001602082028036833780820191505090505b50905060005b87879050811015610193578787828181106100d3576100d2610a1a565b5b90506020020160208101906100e89190610a49565b73ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016101209190610a85565b602060405180830381865afa15801561013d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101619190610ab5565b82828151811061017457610173610a1a565b5b602002602001018181525050808061018b90610b11565b9150506100b5565b5060005b8b8b9050811015610276578b8b828181106101b5576101b4610a1a565b5b90506020020160208101906101ca9190610a49565b73ffffffffffffffffffffffffffffffffffffffff166323b872dd33308d8d868181106101fa576101f9610a1a565b5b905060200201356040518463ffffffff1660e01b815260040161021f93929190610b68565b6020604051808303816000875af115801561023e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102629190610bd7565b50808061026e90610b11565b915050610197565b5060008c73ffffffffffffffffffffffffffffffffffffffff166392bc950560e01b8787876040516024016102ad9392919061107e565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516103179190611128565b600060405180830381855af49150503d8060008114610352576040519150601f19603f3d011682016040523d82523d6000602084013e610357565b606091505b505090508061039b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103929061119c565b60405180910390fd5b60008888905067ffffffffffffffff8111156103ba576103b961069a565b5b6040519080825280602002602001820160405280156103e85781602001602082028036833780820191505090505b50905060005b898990508110156104f15789898281811061040c5761040b610a1a565b5b90506020020160208101906104219190610a49565b73ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016104599190610a85565b602060405180830381865afa158015610476573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061049a9190610ab5565b8482815181106104ad576104ac610a1a565b5b60200260200101516104bf91906111bc565b8282815181106104d2576104d1610a1a565b5b60200260200101818152505080806104e990610b11565b9150506103ee565b508093505050509a9950505050505050505050565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006105458261051a565b9050919050565b6105558161053a565b811461056057600080fd5b50565b6000813590506105728161054c565b92915050565b600080fd5b600080fd5b600080fd5b60008083601f84011261059d5761059c610578565b5b8235905067ffffffffffffffff8111156105ba576105b961057d565b5b6020830191508360208202830111156105d6576105d5610582565b5b9250929050565b60008083601f8401126105f3576105f2610578565b5b8235905067ffffffffffffffff8111156106105761060f61057d565b5b60208301915083602082028301111561062c5761062b610582565b5b9250929050565b60008083601f84011261064957610648610578565b5b8235905067ffffffffffffffff8111156106665761066561057d565b5b60208301915083602082028301111561068257610681610582565b5b9250929050565b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6106d282610689565b810181811067ffffffffffffffff821117156106f1576106f061069a565b5b80604052505050565b6000610704610506565b905061071082826106c9565b919050565b600067ffffffffffffffff8211156107305761072f61069a565b5b602082029050602081019050919050565b6000819050919050565b61075481610741565b811461075f57600080fd5b50565b6000813590506107718161074b565b92915050565b600061078a61078584610715565b6106fa565b905080838252602082019050602084028301858111156107ad576107ac610582565b5b835b818110156107d657806107c28882610762565b8452602084019350506020810190506107af565b5050509392505050565b600082601f8301126107f5576107f4610578565b5b8135610805848260208601610777565b91505092915050565b60008060008060008060008060008060c08b8d03121561083157610830610510565b5b600061083f8d828e01610563565b9a505060208b013567ffffffffffffffff8111156108605761085f610515565b5b61086c8d828e01610587565b995099505060408b013567ffffffffffffffff81111561088f5761088e610515565b5b61089b8d828e016105dd565b975097505060608b013567ffffffffffffffff8111156108be576108bd610515565b5b6108ca8d828e01610587565b955095505060808b013567ffffffffffffffff8111156108ed576108ec610515565b5b6108f98d828e01610633565b935093505060a08b013567ffffffffffffffff81111561091c5761091b610515565b5b6109288d828e016107e0565b9150509295989b9194979a5092959850565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b61096f81610741565b82525050565b60006109818383610966565b60208301905092915050565b6000602082019050919050565b60006109a58261093a565b6109af8185610945565b93506109ba83610956565b8060005b838110156109eb5781516109d28882610975565b97506109dd8361098d565b9250506001810190506109be565b5085935050505092915050565b60006020820190508181036000830152610a12818461099a565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600060208284031215610a5f57610a5e610510565b5b6000610a6d84828501610563565b91505092915050565b610a7f8161053a565b82525050565b6000602082019050610a9a6000830184610a76565b92915050565b600081519050610aaf8161074b565b92915050565b600060208284031215610acb57610aca610510565b5b6000610ad984828501610aa0565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610b1c82610741565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610b4e57610b4d610ae2565b5b600182019050919050565b610b6281610741565b82525050565b6000606082019050610b7d6000830186610a76565b610b8a6020830185610a76565b610b976040830184610b59565b949350505050565b60008115159050919050565b610bb481610b9f565b8114610bbf57600080fd5b50565b600081519050610bd181610bab565b92915050565b600060208284031215610bed57610bec610510565b5b6000610bfb84828501610bc2565b91505092915050565b600082825260208201905092915050565b6000819050919050565b6000610c2e6020840184610563565b905092915050565b610c3f8161053a565b82525050565b600080fd5b600080fd5b600080fd5b60008083356001602003843603038112610c7157610c70610c4f565b5b83810192508235915060208301925067ffffffffffffffff821115610c9957610c98610c45565b5b600182023603831315610caf57610cae610c4a565b5b509250929050565b600082825260208201905092915050565b82818337600083830152505050565b6000610ce38385610cb7565b9350610cf0838584610cc8565b610cf983610689565b840190509392505050565b60008083356001602003843603038112610d2157610d20610c4f565b5b83810192508235915060208301925067ffffffffffffffff821115610d4957610d48610c45565b5b608082023603831315610d5f57610d5e610c4a565b5b509250929050565b600082825260208201905092915050565b6000819050919050565b60078110610d8f57600080fd5b50565b600081359050610da181610d82565b92915050565b6000610db66020840184610d92565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b60078110610dfe57610dfd610dbe565b5b50565b6000819050610e0f82610ded565b919050565b6000610e1f82610e01565b9050919050565b610e2f81610e14565b82525050565b6000610e446020840184610762565b905092915050565b60808201610e5d6000830183610da7565b610e6a6000850182610e26565b50610e786020830183610e35565b610e856020850182610966565b50610e936040830183610e35565b610ea06040850182610966565b50610eae6060830183610e35565b610ebb6060850182610966565b50505050565b6000610ecd8383610e4c565b60808301905092915050565b600082905092915050565b6000608082019050919050565b6000610efd8385610d67565b9350610f0882610d78565b8060005b85811015610f4157610f1e8284610ed9565b610f288882610ec1565b9750610f3383610ee4565b925050600181019050610f0c565b5085925050509392505050565b600060608301610f616000840184610c1f565b610f6e6000860182610c36565b50610f7c6020840184610c54565b8583036020870152610f8f838284610cd7565b92505050610fa06040840184610d04565b8583036040870152610fb3838284610ef1565b925050508091505092915050565b6000610fcd8383610f4e565b905092915050565b600082356001606003833603038112610ff157610ff0610c4f565b5b82810191505092915050565b6000602082019050919050565b60006110168385610c04565b93508360208402850161102884610c15565b8060005b8781101561106c5784840389526110438284610fd5565b61104d8582610fc1565b945061105883610ffd565b925060208a0199505060018101905061102c565b50829750879450505050509392505050565b6000604082019050818103600083015261109981858761100a565b905081810360208301526110ad818461099a565b9050949350505050565b600081519050919050565b600081905092915050565b60005b838110156110eb5780820151818401526020810190506110d0565b60008484015250505050565b6000611102826110b7565b61110c81856110c2565b935061111c8185602086016110cd565b80840191505092915050565b600061113482846110f7565b915081905092915050565b600082825260208201905092915050565b7f44656c656761746563616c6c206661696c656400000000000000000000000000600082015250565b600061118660138361113f565b915061119182611150565b602082019050919050565b600060208201905081810360008301526111b581611179565b9050919050565b60006111c782610741565b91506111d283610741565b92508282039050818111156111ea576111e9610ae2565b5b9291505056fea2646970667358221220b577f33777d022a72e70ac76099924ef9b0fe530ceb7c92dc3c164dd05291b0e64736f6c63430008140033", "linkReferences": {}, "deployedLinkReferences": {} } diff --git a/core/src/config/config.default.ts b/core/src/config/config.default.ts index 57c4e88..7d6c990 100644 --- a/core/src/config/config.default.ts +++ b/core/src/config/config.default.ts @@ -1,8 +1,8 @@ export default { networks: { 137: { - routerAddress: "0x5F5Ef893d65b91c5A060119fcBe8F0EB964dB5a8", - routerSimulatorAddress: "0xf12093D00E70D0AF5a3d16950d515cbC8232d46F", + routerAddress: "0x36CF9f3FC82C3b04f8273402abFF73fC208a809f", + routerSimulatorAddress: "0xc7ab8F80B8FCBFD2d493C0d131B6EaB6691dfBb9", gammaRatiosCalculator: "0x0F306e004258dc4c9Ecc0373b6E3dC59A3f0dB58", }, }, diff --git a/core/src/path/tx-simulator.ts b/core/src/path/tx-simulator.ts index a3a14aa..6c8ba8a 100644 --- a/core/src/path/tx-simulator.ts +++ b/core/src/path/tx-simulator.ts @@ -49,9 +49,9 @@ export async function simulateAssetSwapTransaction({ const populatedTx = await routerSimulator.simulateJamTx.populateTransaction( config.networks[chainId].routerAddress, - sellAsset.address, - amountIn, - buyAsset.address, + [sellAsset.address], + [amountIn], + [buyAsset.address], routerTransactionData.steps, routerTransactionData.stores ); @@ -71,12 +71,16 @@ export async function simulateAssetSwapTransaction({ }; try { - const ret = await (provider as any).send("eth_call", [ + const rawCallResult = await (provider as any).send("eth_call", [ callData, "latest", stateOverrides, ]); - return BigInt(ret); + const decodedCallResult = routerSimulator.interface.decodeFunctionResult( + "simulateJamTx", + rawCallResult + ); + return BigInt(decodedCallResult[0]); } catch (e) { console.error("Failed to simulate transaction"); console.dir( @@ -102,17 +106,17 @@ export async function simulateRouterOperation({ chainId, routerOperation, provider, - sellAsset, - amountIn, - buyAsset, + sellAssets, + amountsIn, + buyAssets, }: { chainId: number; routerOperation: RouterOperation; provider: Provider; - sellAsset: Asset; - amountIn: string; - buyAsset: Asset; -}): Promise { + sellAssets: Asset[]; + amountsIn: BigNumberish[]; + buyAssets: Asset[]; +}): Promise { const config = await loadConfig(); // const txSimulator = getTxSimulatorContract(provider) as Contract; @@ -138,20 +142,24 @@ export async function simulateRouterOperation({ const populatedTx = await routerSimulator.simulateJamTx.populateTransaction( config.networks[chainId].routerAddress, - sellAsset.address, - amountIn, - buyAsset.address, + sellAssets.map((a) => a.address), + amountsIn, + buyAssets.map((a) => a.address), routerTransactionData.steps, routerTransactionData.stores ); const from = "0x6D763ee17cEA70cB1026Fa0F272dd620546A9B9F"; - const stateOverrides = generateTokenApprovalStateDiff( - sellAsset, - from, - config.networks[chainId].routerSimulatorAddress - ); + const stateOverrides = {}; + for (const sellAsset of sellAssets) { + const approvalStateDiff = generateTokenApprovalStateDiff( + sellAsset, + from, + config.networks[chainId].routerSimulatorAddress + ); + Object.assign(stateOverrides, approvalStateDiff); + } const callData = { from: from, @@ -168,12 +176,17 @@ export async function simulateRouterOperation({ ); try { - const ret = await (provider as any).send("eth_call", [ + const rawCallResult = await (provider as any).send("eth_call", [ callData, "latest", stateOverrides, ]); - return BigInt(ret); + const decodedCallResult = routerSimulator.interface.decodeFunctionResult( + "simulateJamTx", + rawCallResult + ); + + return decodedCallResult.map((b) => BigInt(b)); } catch (e) { console.error("Failed to simulate transaction"); throw e; diff --git a/core/tests/protocols/aave.spec.ts b/core/tests/protocols/aave.spec.ts index c386a59..9c4ac68 100644 --- a/core/tests/protocols/aave.spec.ts +++ b/core/tests/protocols/aave.spec.ts @@ -1,20 +1,32 @@ import { test } from "vitest"; -import { simulateSingleAssetToSingleAsset } from "./utils"; +import { simulateRouterOperationHelper } from "./utils"; test("generateTransaction: USDC to aPolUSDC (aaveV3Deposit)", async () => { - await simulateSingleAssetToSingleAsset({ + await simulateRouterOperationHelper({ chainId: 137, - inputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - outputAssetId: "371b83f1-3301-4c69-b3ad-8d199c6d1774", - amountIn: "1000000000", + inputAllocation: [ + { + assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + amountStr: "1000000000", + }, + ], + outputAllocation: [ + { assetId: "371b83f1-3301-4c69-b3ad-8d199c6d1774", fraction: 1.0 }, + ], }); }); test("generateTransaction: aPolUSDC (aaveV3Deposit) to USDC", async () => { - await simulateSingleAssetToSingleAsset({ + await simulateRouterOperationHelper({ chainId: 137, - inputAssetId: "371b83f1-3301-4c69-b3ad-8d199c6d1774", - outputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - amountIn: "1000000000", + inputAllocation: [ + { + assetId: "371b83f1-3301-4c69-b3ad-8d199c6d1774", + amountStr: "1000000000", + }, + ], + outputAllocation: [ + { assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", fraction: 1.0 }, + ], }); }); diff --git a/core/tests/protocols/balancer.spec.ts b/core/tests/protocols/balancer.spec.ts index 27f6b80..4a329c6 100644 --- a/core/tests/protocols/balancer.spec.ts +++ b/core/tests/protocols/balancer.spec.ts @@ -1,20 +1,36 @@ import { test } from "vitest"; -import { simulateSingleAssetToSingleAsset } from "./utils"; +import { simulateRouterOperationHelper } from "./utils"; test("generateTransaction: USDC to jBRL/BRZ (balancerDeposit)", async () => { - await simulateSingleAssetToSingleAsset({ + await simulateRouterOperationHelper({ chainId: 137, - inputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - outputAssetId: "03f36f17-bbc2-4d8d-b0b2-9ce0f534d708", - amountIn: "1000000000", + + inputAllocation: [ + { + assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + amountStr: "1000000000", + }, + ], + outputAllocation: [ + { assetId: "03f36f17-bbc2-4d8d-b0b2-9ce0f534d708", fraction: 1 }, + ], }); }); test("generateTransaction: maticX/WMATIC (balancerDeposit) to USDC", async () => { - await simulateSingleAssetToSingleAsset({ + await simulateRouterOperationHelper({ chainId: 137, - inputAssetId: "9b09afe5-c740-4cd7-a247-4fe4950a7f33", - outputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - amountIn: "10000000000000000000000", + inputAllocation: [ + { + assetId: "9b09afe5-c740-4cd7-a247-4fe4950a7f33", + amountStr: "10000000000000000000000", + }, + ], + outputAllocation: [ + { + assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + fraction: 1, + }, + ], }); }); diff --git a/core/tests/protocols/beefy.spec.ts b/core/tests/protocols/beefy.spec.ts index 93a577d..dc23a91 100644 --- a/core/tests/protocols/beefy.spec.ts +++ b/core/tests/protocols/beefy.spec.ts @@ -1,20 +1,36 @@ import { test } from "vitest"; -import { simulateSingleAssetToSingleAsset } from "./utils"; +import { simulateRouterOperationHelper } from "./utils"; test("generateTransaction: USDC to QUICK (beefyDeposit)", async () => { - await simulateSingleAssetToSingleAsset({ + await simulateRouterOperationHelper({ chainId: 137, - inputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - outputAssetId: "37819023-9c6a-4848-8cf5-24a95350f001", - amountIn: "1000000000", + inputAllocation: [ + { + assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + amountStr: "1000000000", + }, + ], + + outputAllocation: [ + { + assetId: "37819023-9c6a-4848-8cf5-24a95350f001", + fraction: 1.0, + }, + ], }); }); test("generateTransaction: beefy.finance (beefyDeposit) to USDC", async () => { - await simulateSingleAssetToSingleAsset({ + await simulateRouterOperationHelper({ chainId: 137, - inputAssetId: "fecfd33d-e6a7-476b-89cb-910a0058fa48", - outputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - amountIn: "1000000", + inputAllocation: [ + { assetId: "fecfd33d-e6a7-476b-89cb-910a0058fa48", amountStr: "1000000" }, + ], + outputAllocation: [ + { + assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + fraction: 1.0, + }, + ], }); }); diff --git a/core/tests/protocols/gamma.spec.ts b/core/tests/protocols/gamma.spec.ts index 17cc05f..be51d19 100644 --- a/core/tests/protocols/gamma.spec.ts +++ b/core/tests/protocols/gamma.spec.ts @@ -1,65 +1,128 @@ import { test } from "vitest"; -import { simulateSingleAssetToSingleAsset } from "./utils"; +import { simulateRouterOperationHelper } from "./utils"; test("generateTransaction: USDC to USDC/WETH (gammaDeposit)", async () => { - await simulateSingleAssetToSingleAsset({ + await simulateRouterOperationHelper({ chainId: 137, - inputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - outputAssetId: "8da84d12-9e9d-4c04-831d-7b93f1cd822f", - amountIn: "1000000000", + inputAllocation: [ + { + assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + amountStr: "1000000000", + }, + ], + outputAllocation: [ + { + assetId: "8da84d12-9e9d-4c04-831d-7b93f1cd822f", + fraction: 1.0, + }, + ], }); }); test("generateTransaction: USDC to WMATIC/WETH (gammaDeposit)", async () => { - await simulateSingleAssetToSingleAsset({ + await simulateRouterOperationHelper({ chainId: 137, - inputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - outputAssetId: "3c42b7d3-555b-41a4-96b6-ce4fadd62f83", - amountIn: "1000000000", + inputAllocation: [ + { + assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + amountStr: "1000000000", + }, + ], + outputAllocation: [ + { + assetId: "3c42b7d3-555b-41a4-96b6-ce4fadd62f83", + fraction: 1.0, + }, + ], }); }); test("generateTransaction: USDC to WMATIC/MaticX (gammaDeposit)", async () => { - await simulateSingleAssetToSingleAsset({ + await simulateRouterOperationHelper({ chainId: 137, - inputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - outputAssetId: "5a5cd640-b972-43b6-9bb2-24e6711ab1db", - amountIn: "1000000000", + inputAllocation: [ + { + assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + amountStr: "1000000000", + }, + ], + outputAllocation: [ + { + assetId: "5a5cd640-b972-43b6-9bb2-24e6711ab1db", + fraction: 1.0, + }, + ], }); }); test("generateTransaction: WMATIC/MaticX (gammaDeposit) to USDC", async () => { - await simulateSingleAssetToSingleAsset({ + await simulateRouterOperationHelper({ chainId: 137, - inputAssetId: "5a5cd640-b972-43b6-9bb2-24e6711ab1db", - outputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - amountIn: "1000000000000000000000", + inputAllocation: [ + { + assetId: "5a5cd640-b972-43b6-9bb2-24e6711ab1db", + amountStr: "1000000000000000000000", + }, + ], + outputAllocation: [ + { + assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + fraction: 1.0, + }, + ], }); }); test("generateTransaction: WMATIC/WETH (gammaDeposit) to USDC", async () => { - await simulateSingleAssetToSingleAsset({ + await simulateRouterOperationHelper({ chainId: 137, - inputAssetId: "3c42b7d3-555b-41a4-96b6-ce4fadd62f83", - outputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - amountIn: "1000000000000000000", + inputAllocation: [ + { + assetId: "3c42b7d3-555b-41a4-96b6-ce4fadd62f83", + amountStr: "1000000000000000000", + }, + ], + outputAllocation: [ + { + assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + fraction: 1.0, + }, + ], }); }); test("generateTransaction: USDC/WETH (gammaDeposit) to USDC", async () => { - await simulateSingleAssetToSingleAsset({ + await simulateRouterOperationHelper({ chainId: 137, - inputAssetId: "8da84d12-9e9d-4c04-831d-7b93f1cd822f", - outputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - amountIn: "1000000000000000000", + inputAllocation: [ + { + assetId: "8da84d12-9e9d-4c04-831d-7b93f1cd822f", + amountStr: "1000000000000000000", + }, + ], + outputAllocation: [ + { + assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + fraction: 1.0, + }, + ], }); }); test("generateTransaction: USDC/WETH (gammaDeposit) to WMATIC/MaticX (gammaDeposit)", async () => { - await simulateSingleAssetToSingleAsset({ + await simulateRouterOperationHelper({ chainId: 137, - inputAssetId: "8da84d12-9e9d-4c04-831d-7b93f1cd822f", - outputAssetId: "5a5cd640-b972-43b6-9bb2-24e6711ab1db", - amountIn: "1000000000000000000", + inputAllocation: [ + { + assetId: "8da84d12-9e9d-4c04-831d-7b93f1cd822f", + amountStr: "1000000000000000000", + }, + ], + outputAllocation: [ + { + assetId: "5a5cd640-b972-43b6-9bb2-24e6711ab1db", + fraction: 1.0, + }, + ], }); }); diff --git a/core/tests/protocols/paraswap.spec.ts b/core/tests/protocols/paraswap.spec.ts index e6c4a8c..f1b8e1b 100644 --- a/core/tests/protocols/paraswap.spec.ts +++ b/core/tests/protocols/paraswap.spec.ts @@ -41,8 +41,8 @@ test.skip("Paraswap (using multiSwap): PAX Gold to MAI", async () => { buyAsset: assetStore.getAssetById("c5129108-4b4d-4aa2-b75b-9d4348bd1678"), }); - console.log({ swappedValue }); - expect(swappedValue).toBeGreaterThan(0); + console.log(swappedValue[0]); + expect(swappedValue[0]).toBeGreaterThan(0); }); test.skip("Paraswap (using megaSwap): PAX Gold to MAI", async () => { @@ -81,6 +81,6 @@ test.skip("Paraswap (using megaSwap): PAX Gold to MAI", async () => { buyAsset: assetStore.getAssetById("c5129108-4b4d-4aa2-b75b-9d4348bd1678"), }); - console.log({ swappedValue }); - expect(swappedValue).toBeGreaterThan(0); + console.log(swappedValue[0]); + expect(swappedValue[0]).toBeGreaterThan(0); }); diff --git a/core/tests/protocols/uniswapV2Liquidity.spec.ts b/core/tests/protocols/uniswapV2Liquidity.spec.ts index 99c4ed9..792bdfc 100644 --- a/core/tests/protocols/uniswapV2Liquidity.spec.ts +++ b/core/tests/protocols/uniswapV2Liquidity.spec.ts @@ -1,38 +1,75 @@ import { test } from "vitest"; -import { simulateSingleAssetToSingleAsset } from "./utils"; +import { simulateRouterOperationHelper } from "./utils"; test("generateTransaction: USDC to CRV/WETH (sushiswap - uniswapV2Liquidity)", async () => { - await simulateSingleAssetToSingleAsset({ + await simulateRouterOperationHelper({ chainId: 137, - inputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - outputAssetId: "c708a5eb-eefd-4c89-bea3-8ec2e036a1a7", - amountIn: "1000000000", + inputAllocation: [ + { + assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + amountStr: "1000000000", + }, + ], + outputAllocation: [ + { + assetId: "c708a5eb-eefd-4c89-bea3-8ec2e036a1a7", + fraction: 1.0, + }, + ], }); }); test.skip("generateTransaction: CRV/WETH (sushiswap - uniswapV2Liquidity) to USDC", async () => { - await simulateSingleAssetToSingleAsset({ + await simulateRouterOperationHelper({ chainId: 137, - inputAssetId: "c708a5eb-eefd-4c89-bea3-8ec2e036a1a7", - outputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - amountIn: "10000000000000000000", + inputAllocation: [ + { + assetId: "c708a5eb-eefd-4c89-bea3-8ec2e036a1a7", + amountStr: "10000000000000000000", + }, + ], + outputAllocation: [ + { + assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + fraction: 1.0, + }, + ], }); }); test("generateTransaction: USDC to WBTC/WETH (quickswap - uniswapV2Liquidity)", async () => { - await simulateSingleAssetToSingleAsset({ + await simulateRouterOperationHelper({ chainId: 137, - inputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - outputAssetId: "108309b5-19ae-49d9-a98b-bd032291db38", - amountIn: "1000000000", + inputAllocation: [ + { + assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + amountStr: "1000000000", + }, + ], + outputAllocation: [ + { + assetId: "108309b5-19ae-49d9-a98b-bd032291db38", + fraction: 1.0, + }, + ], }); }); test.skip("generateTransaction: WBTC/WETH (quickswap - uniswapV2Liquidity) to USDC", async () => { - await simulateSingleAssetToSingleAsset({ + await simulateRouterOperationHelper({ chainId: 137, - inputAssetId: "108309b5-19ae-49d9-a98b-bd032291db38", - outputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - amountIn: "1000000000", + inputAllocation: [ + { + assetId: "108309b5-19ae-49d9-a98b-bd032291db38", + amountStr: "1000000000", + }, + ], + + outputAllocation: [ + { + assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + fraction: 1.0, + }, + ], }); }); diff --git a/core/tests/protocols/utils.ts b/core/tests/protocols/utils.ts index c4c5e92..38ebaea 100644 --- a/core/tests/protocols/utils.ts +++ b/core/tests/protocols/utils.ts @@ -1,25 +1,27 @@ import { AssetStore, generateTransaction, loadConfig } from "core"; import { simulateRouterOperation } from "core/src/path/tx-simulator"; +import { + AbsoluteAllocation, + FractionAllocation, +} from "core/src/transaction/types"; import { getProvider } from "core/src/utils/get-provider"; -export async function simulateSingleAssetToSingleAsset({ +export async function simulateRouterOperationHelper({ chainId, - inputAssetId, - outputAssetId, - amountIn, + inputAllocation, + outputAllocation, }: { chainId: number; - inputAssetId: string; - outputAssetId: string; - amountIn: string; + inputAllocation: AbsoluteAllocation; + outputAllocation: FractionAllocation; }) { const assetStore = new AssetStore(); const config = await loadConfig(); const provider = await getProvider({ chainId: 137 }); const routerOperation = await generateTransaction({ - inputAllocation: [{ assetId: inputAssetId, amountStr: amountIn }], - outputAllocation: [{ assetId: outputAssetId, fraction: 1.0 }], + inputAllocation, + outputAllocation, assetStore, chainId, walletAddress: config.networks[chainId].routerSimulatorAddress, @@ -31,9 +33,9 @@ export async function simulateSingleAssetToSingleAsset({ chainId, routerOperation, provider, - sellAsset: assetStore.getAssetById(inputAssetId), - amountIn, - buyAsset: assetStore.getAssetById(outputAssetId), + sellAssets: inputAllocation.map((i) => assetStore.getAssetById(i.assetId)), + amountsIn: inputAllocation.map((i) => i.amountStr), + buyAssets: outputAllocation.map((a) => assetStore.getAssetById(a.assetId)), }); console.dir( diff --git a/router/contracts/RouterSimulator.sol b/router/contracts/RouterSimulator.sol index 6c5f849..7b031b4 100644 --- a/router/contracts/RouterSimulator.sol +++ b/router/contracts/RouterSimulator.sol @@ -8,15 +8,26 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; contract RouterSimulator { function simulateJamTx( address routerAddress, - address inputToken, - uint256 inputAmount, - address outputToken, + address[] calldata inputTokens, + uint256[] calldata inputAmounts, + address[] calldata outputTokens, Router.Step[] calldata steps, uint256[] memory stores - ) external returns (uint256) { - uint previousBalance = IERC20(outputToken).balanceOf(address(this)); + ) external returns (uint256[] memory) { + uint256[] memory previousBalances = new uint[](outputTokens.length); + for (uint i = 0; i < outputTokens.length; i++) { + previousBalances[i] = IERC20(outputTokens[i]).balanceOf( + address(this) + ); + } - IERC20(inputToken).transferFrom(msg.sender, address(this), inputAmount); + for (uint i = 0; i < inputTokens.length; i++) { + IERC20(inputTokens[i]).transferFrom( + msg.sender, + address(this), + inputAmounts[i] + ); + } (bool success, ) = routerAddress.delegatecall( abi.encodeWithSelector(Router.runSteps.selector, steps, stores) @@ -24,7 +35,14 @@ contract RouterSimulator { require(success, "Delegatecall failed"); - uint newBalance = IERC20(outputToken).balanceOf(address(this)); - return newBalance - previousBalance; + // uint newBalance = IERC20(outputToken).balanceOf(address(this)); + uint[] memory diffBalances = new uint[](outputTokens.length); + for (uint i = 0; i < outputTokens.length; i++) { + diffBalances[i] = + IERC20(outputTokens[i]).balanceOf(address(this)) - + previousBalances[i]; + } + + return diffBalances; } }