@paraswap/dex-lib 2.45.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release-package.yml +32 -0
- package/.vscode/launch.json +72 -0
- package/.vscode/settings.json +2 -0
- package/.vscode/tasks.json +15 -0
- package/build/abi/AugustusV6.abi.json +1454 -0
- package/build/abi/augustus-v6/ABI.json +1075 -0
- package/build/config.d.ts +1 -0
- package/build/config.js +53 -1
- package/build/config.js.map +1 -1
- package/build/constants.d.ts +6 -0
- package/build/constants.js +9 -2
- package/build/constants.js.map +1 -1
- package/build/dex/aave-v1/aave-v1.d.ts +2 -1
- package/build/dex/aave-v1/aave-v1.js +22 -0
- package/build/dex/aave-v1/aave-v1.js.map +1 -1
- package/build/dex/aave-v2/aave-v2.d.ts +2 -1
- package/build/dex/aave-v2/aave-v2.js +80 -0
- package/build/dex/aave-v2/aave-v2.js.map +1 -1
- package/build/dex/aave-v3/aave-v3.d.ts +3 -1
- package/build/dex/aave-v3/aave-v3.js +39 -0
- package/build/dex/aave-v3/aave-v3.js.map +1 -1
- package/build/dex/algebra/algebra.d.ts +2 -1
- package/build/dex/algebra/algebra.js +52 -1
- package/build/dex/algebra/algebra.js.map +1 -1
- package/build/dex/algebra/scripts/validate-state-v1-1.d.ts +1 -0
- package/build/dex/algebra/scripts/validate-state-v1-1.js +206 -0
- package/build/dex/algebra/scripts/validate-state-v1-1.js.map +1 -0
- package/build/dex/augustus-approvals-helper.d.ts +22 -0
- package/build/dex/augustus-approvals-helper.js +110 -0
- package/build/dex/augustus-approvals-helper.js.map +1 -0
- package/build/dex/augustus-approvals.d.ts +24 -0
- package/build/dex/augustus-approvals.js +106 -0
- package/build/dex/augustus-approvals.js.map +1 -0
- package/build/dex/bProtocol/bProtocol.d.ts +15 -0
- package/build/dex/bProtocol/bProtocol.js +51 -0
- package/build/dex/bProtocol/bProtocol.js.map +1 -0
- package/build/dex/bProtocol/types.d.ts +11 -0
- package/build/dex/bProtocol/types.js +8 -0
- package/build/dex/bProtocol/types.js.map +1 -0
- package/build/dex/bProtocol.d.ts +2 -1
- package/build/dex/bProtocol.js +15 -0
- package/build/dex/bProtocol.js.map +1 -1
- package/build/dex/balancer-v1/balancer-v1.d.ts +5 -3
- package/build/dex/balancer-v1/balancer-v1.js +72 -3
- package/build/dex/balancer-v1/balancer-v1.js.map +1 -1
- package/build/dex/balancer-v2/balancer-v2.d.ts +16 -4
- package/build/dex/balancer-v2/balancer-v2.js +154 -7
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/balancer-v2/constants.d.ts +4 -0
- package/build/dex/balancer-v2/constants.js +6 -1
- package/build/dex/balancer-v2/constants.js.map +1 -1
- package/build/dex/balancer-v2/types.d.ts +11 -0
- package/build/dex/bancor/bancor.d.ts +15 -0
- package/build/dex/bancor/bancor.js +69 -0
- package/build/dex/bancor/bancor.js.map +1 -0
- package/build/dex/bancor/config.d.ts +6 -0
- package/build/dex/bancor/config.js +11 -0
- package/build/dex/bancor/config.js.map +1 -0
- package/build/dex/bancor/types.d.ts +16 -0
- package/build/dex/bancor/types.js +8 -0
- package/build/dex/bancor/types.js.map +1 -0
- package/build/dex/bancor.d.ts +2 -1
- package/build/dex/bancor.js +19 -0
- package/build/dex/bancor.js.map +1 -1
- package/build/dex/camelot/camelot.d.ts +3 -1
- package/build/dex/camelot/camelot.js +31 -0
- package/build/dex/camelot/camelot.js.map +1 -1
- package/build/dex/camelot/scripts/validate-state.d.ts +1 -0
- package/build/dex/camelot/scripts/validate-state.js +84 -0
- package/build/dex/camelot/scripts/validate-state.js.map +1 -0
- package/build/dex/compound/compound.d.ts +15 -0
- package/build/dex/compound/compound.js +54 -0
- package/build/dex/compound/compound.js.map +1 -0
- package/build/dex/compound/types.d.ts +8 -0
- package/build/dex/compound/types.js +9 -0
- package/build/dex/compound/types.js.map +1 -0
- package/build/dex/compound.d.ts +2 -1
- package/build/dex/compound.js +12 -0
- package/build/dex/compound.js.map +1 -1
- package/build/dex/curve-v1/constants.d.ts +1 -0
- package/build/dex/curve-v1/constants.js +2 -1
- package/build/dex/curve-v1/constants.js.map +1 -1
- package/build/dex/curve-v1/curve-v1.d.ts +10 -3
- package/build/dex/curve-v1/curve-v1.js +57 -7
- package/build/dex/curve-v1/curve-v1.js.map +1 -1
- package/build/dex/curve-v1/packer.d.ts +2 -0
- package/build/dex/curve-v1/packer.js +18 -0
- package/build/dex/curve-v1/packer.js.map +1 -0
- package/build/dex/curve-v1/types.d.ts +16 -0
- package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +2 -1
- package/build/dex/curve-v1-factory/curve-v1-factory.js +19 -7
- package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/polling-manager.js +3 -1
- package/build/dex/curve-v1-factory/state-polling-pools/polling-manager.js.map +1 -1
- package/build/dex/curve-v2/constants.d.ts +1 -0
- package/build/dex/curve-v2/constants.js +5 -0
- package/build/dex/curve-v2/constants.js.map +1 -0
- package/build/dex/curve-v2/curve-v2.d.ts +61 -0
- package/build/dex/curve-v2/curve-v2.js +245 -0
- package/build/dex/curve-v2/curve-v2.js.map +1 -0
- package/build/dex/curve-v2/types.d.ts +24 -0
- package/build/dex/curve-v2/types.js +10 -0
- package/build/dex/curve-v2/types.js.map +1 -0
- package/build/dex/dexalot/dexalot.d.ts +2 -1
- package/build/dex/dexalot/dexalot.js +25 -0
- package/build/dex/dexalot/dexalot.js.map +1 -1
- package/build/dex/dodo-v1/config.d.ts +7 -0
- package/build/dex/dodo-v1/config.js +16 -0
- package/build/dex/dodo-v1/config.js.map +1 -0
- package/build/dex/dodo-v1/dodo-v1.d.ts +16 -0
- package/build/dex/dodo-v1/dodo-v1.js +71 -0
- package/build/dex/dodo-v1/dodo-v1.js.map +1 -0
- package/build/dex/dodo-v1/types.d.ts +22 -0
- package/build/dex/dodo-v1/types.js +8 -0
- package/build/dex/dodo-v1/types.js.map +1 -0
- package/build/dex/dodo-v1.d.ts +2 -1
- package/build/dex/dodo-v1.js +20 -0
- package/build/dex/dodo-v1.js.map +1 -1
- package/build/dex/dodo-v2.d.ts +2 -1
- package/build/dex/dodo-v2.js +54 -0
- package/build/dex/dodo-v2.js.map +1 -1
- package/build/dex/generic-rfq/e2e-test-config.js +50 -6
- package/build/dex/generic-rfq/e2e-test-config.js.map +1 -1
- package/build/dex/generic-rfq/fetch-mm-api.js +2 -2
- package/build/dex/generic-rfq/fetch-mm-api.js.map +1 -1
- package/build/dex/generic-rfq/generic-rfq.d.ts +10 -3
- package/build/dex/generic-rfq/generic-rfq.js +68 -10
- package/build/dex/generic-rfq/generic-rfq.js.map +1 -1
- package/build/dex/generic-rfq/rate-fetcher.js +2 -2
- package/build/dex/generic-rfq/rate-fetcher.js.map +1 -1
- package/build/dex/generic-rfq/test-v6/constants.d.ts +1 -0
- package/build/dex/generic-rfq/test-v6/constants.js +5 -0
- package/build/dex/generic-rfq/test-v6/constants.js.map +1 -0
- package/build/dex/generic-rfq/test-v6/get-config.d.ts +1 -0
- package/build/dex/generic-rfq/test-v6/get-config.js +63 -0
- package/build/dex/generic-rfq/test-v6/get-config.js.map +1 -0
- package/build/dex/generic-rfq/test-v6/types.d.ts +14 -0
- package/build/dex/generic-rfq/test-v6/types.js +3 -0
- package/build/dex/generic-rfq/test-v6/types.js.map +1 -0
- package/build/dex/generic-rfq/tokens.json +570 -0
- package/build/dex/generic-rfq/types.d.ts +14 -2
- package/build/dex/generic-rfq/types.js.map +1 -1
- package/build/dex/generic-rfq/utils.d.ts +1 -1
- package/build/dex/generic-rfq/utils.js +4 -7
- package/build/dex/generic-rfq/utils.js.map +1 -1
- package/build/dex/generic-rfq/validators.d.ts +1 -0
- package/build/dex/generic-rfq/validators.js +9 -12
- package/build/dex/generic-rfq/validators.js.map +1 -1
- package/build/dex/gmx/gmx.d.ts +2 -1
- package/build/dex/gmx/gmx.js +15 -0
- package/build/dex/gmx/gmx.js.map +1 -1
- package/build/dex/hashflow/hashflow.d.ts +2 -1
- package/build/dex/hashflow/hashflow.js +31 -1
- package/build/dex/hashflow/hashflow.js.map +1 -1
- package/build/dex/idex.d.ts +7 -1
- package/build/dex/index.d.ts +2 -0
- package/build/dex/index.js +23 -10
- package/build/dex/index.js.map +1 -1
- package/build/dex/jarvis-v6/jarvis-v6.d.ts +2 -1
- package/build/dex/jarvis-v6/jarvis-v6.js +24 -0
- package/build/dex/jarvis-v6/jarvis-v6.js.map +1 -1
- package/build/dex/jarvis.d.ts +2 -1
- package/build/dex/jarvis.js +50 -0
- package/build/dex/jarvis.js.map +1 -1
- package/build/dex/kyberdmm/kyberdmm.d.ts +2 -1
- package/build/dex/kyberdmm/kyberdmm.js +20 -0
- package/build/dex/kyberdmm/kyberdmm.js.map +1 -1
- package/build/dex/lido/config.d.ts +1 -0
- package/build/dex/lido/config.js +8 -0
- package/build/dex/lido/config.js.map +1 -0
- package/build/dex/lido/lido.d.ts +16 -0
- package/build/dex/lido/lido.js +46 -0
- package/build/dex/lido/lido.js.map +1 -0
- package/build/dex/lido/types.d.ts +4 -0
- package/build/dex/lido/types.js +8 -0
- package/build/dex/lido/types.js.map +1 -0
- package/build/dex/lido.d.ts +2 -1
- package/build/dex/lido.js +9 -0
- package/build/dex/lido.js.map +1 -1
- package/build/dex/maker-psm/maker-psm.d.ts +2 -1
- package/build/dex/maker-psm/maker-psm.js +27 -0
- package/build/dex/maker-psm/maker-psm.js.map +1 -1
- package/build/dex/maverick-v1/maverick-v1.d.ts +3 -1
- package/build/dex/maverick-v1/maverick-v1.js +35 -0
- package/build/dex/maverick-v1/maverick-v1.js.map +1 -1
- package/build/dex/nerve/nerve.d.ts +2 -1
- package/build/dex/nerve/nerve.js +19 -0
- package/build/dex/nerve/nerve.js.map +1 -1
- package/build/dex/onebit/onebit.d.ts +16 -0
- package/build/dex/onebit/onebit.js +56 -0
- package/build/dex/onebit/onebit.js.map +1 -0
- package/build/dex/onebit/types.d.ts +14 -0
- package/build/dex/onebit/types.js +8 -0
- package/build/dex/onebit/types.js.map +1 -0
- package/build/dex/onebit.d.ts +2 -1
- package/build/dex/onebit.js +17 -0
- package/build/dex/onebit.js.map +1 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +2 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js +30 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
- package/build/dex/paraswap-limit-orders/paraswap-limit-orders.d.ts +2 -1
- package/build/dex/paraswap-limit-orders/paraswap-limit-orders.js +15 -0
- package/build/dex/paraswap-limit-orders/paraswap-limit-orders.js.map +1 -1
- package/build/dex/paraswap-limit-orders/types.d.ts +1 -0
- package/build/dex/platypus/platypus.d.ts +2 -1
- package/build/dex/platypus/platypus.js +31 -0
- package/build/dex/platypus/platypus.js.map +1 -1
- package/build/dex/polygon-migrator/polygon-migrator.d.ts +2 -1
- package/build/dex/polygon-migrator/polygon-migrator.js +11 -0
- package/build/dex/polygon-migrator/polygon-migrator.js.map +1 -1
- package/build/dex/quick-perps/quick-perps.d.ts +2 -1
- package/build/dex/quick-perps/quick-perps.js +15 -0
- package/build/dex/quick-perps/quick-perps.js.map +1 -1
- package/build/dex/simple-exchange.d.ts +2 -5
- package/build/dex/simple-exchange.js +4 -32
- package/build/dex/simple-exchange.js.map +1 -1
- package/build/dex/smoothy/smoothy.d.ts +16 -0
- package/build/dex/smoothy/smoothy.js +58 -0
- package/build/dex/smoothy/smoothy.js.map +1 -0
- package/build/dex/smoothy/types.d.ts +15 -0
- package/build/dex/smoothy/types.js +8 -0
- package/build/dex/smoothy/types.js.map +1 -0
- package/build/dex/smoothy.d.ts +2 -1
- package/build/dex/smoothy.js +13 -0
- package/build/dex/smoothy.js.map +1 -1
- package/build/dex/solidly/solidly.d.ts +2 -1
- package/build/dex/solidly/solidly.js +30 -0
- package/build/dex/solidly/solidly.js.map +1 -1
- package/build/dex/solidly-v3/contract-math/Tick.js.map +1 -1
- package/build/dex/solidly-v3/contract-math/uniswap-v3-math.js +4 -4
- package/build/dex/solidly-v3/contract-math/uniswap-v3-math.js.map +1 -1
- package/build/dex/solidly-v3/solidly-v3.d.ts +2 -3
- package/build/dex/solidly-v3/solidly-v3.js +25 -37
- package/build/dex/solidly-v3/solidly-v3.js.map +1 -1
- package/build/dex/stable-pool/stable-pool.d.ts +16 -0
- package/build/dex/stable-pool/stable-pool.js +78 -0
- package/build/dex/stable-pool/stable-pool.js.map +1 -0
- package/build/dex/stable-pool/types.d.ts +17 -0
- package/build/dex/stable-pool/types.js +8 -0
- package/build/dex/stable-pool/types.js.map +1 -0
- package/build/dex/stable-pool.d.ts +2 -1
- package/build/dex/stable-pool.js +19 -0
- package/build/dex/stable-pool.js.map +1 -1
- package/build/dex/swaap-v1/swaap-v1.d.ts +2 -1
- package/build/dex/swaap-v1/swaap-v1.js +10 -0
- package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
- package/build/dex/swaap-v2/rate-fetcher.d.ts +1 -1
- package/build/dex/swaap-v2/rate-fetcher.js +4 -4
- package/build/dex/swaap-v2/rate-fetcher.js.map +1 -1
- package/build/dex/swaap-v2/swaap-v2.d.ts +3 -1
- package/build/dex/swaap-v2/swaap-v2.js +17 -1
- package/build/dex/swaap-v2/swaap-v2.js.map +1 -1
- package/build/dex/swaap-v2/validators.d.ts +1 -0
- package/build/dex/swaap-v2/validators.js +9 -12
- package/build/dex/swaap-v2/validators.js.map +1 -1
- package/build/dex/swell/swell.d.ts +2 -1
- package/build/dex/swell/swell.js +12 -2
- package/build/dex/swell/swell.js.map +1 -1
- package/build/dex/synthetix/synthetix.d.ts +2 -1
- package/build/dex/synthetix/synthetix.js +24 -0
- package/build/dex/synthetix/synthetix.js.map +1 -1
- package/build/dex/trader-joe-v2.1/config.d.ts +4 -0
- package/build/dex/trader-joe-v2.1/config.js +11 -0
- package/build/dex/trader-joe-v2.1/config.js.map +1 -0
- package/build/dex/trader-joe-v2.1/trader-joe-v2.1.d.ts +19 -0
- package/build/dex/trader-joe-v2.1/trader-joe-v2.1.js +98 -0
- package/build/dex/trader-joe-v2.1/trader-joe-v2.1.js.map +1 -0
- package/build/dex/trader-joe-v2.1/types.d.ts +31 -0
- package/build/dex/trader-joe-v2.1/types.js +9 -0
- package/build/dex/trader-joe-v2.1/types.js.map +1 -0
- package/build/dex/trader-joe-v2.1.d.ts +2 -1
- package/build/dex/trader-joe-v2.1.js +28 -0
- package/build/dex/trader-joe-v2.1.js.map +1 -1
- package/build/dex/uniswap-v2/config.js +36 -0
- package/build/dex/uniswap-v2/config.js.map +1 -1
- package/build/dex/uniswap-v2/constants.js +7 -6
- package/build/dex/uniswap-v2/constants.js.map +1 -1
- package/build/dex/uniswap-v2/dfyn.d.ts +4 -2
- package/build/dex/uniswap-v2/dfyn.js +13 -0
- package/build/dex/uniswap-v2/dfyn.js.map +1 -1
- package/build/dex/uniswap-v2/types.d.ts +19 -0
- package/build/dex/uniswap-v2/types.js +6 -1
- package/build/dex/uniswap-v2/types.js.map +1 -1
- package/build/dex/uniswap-v2/uniswap-v2-optimizer.d.ts +2 -0
- package/build/dex/uniswap-v2/uniswap-v2-optimizer.js +75 -0
- package/build/dex/uniswap-v2/uniswap-v2-optimizer.js.map +1 -0
- package/build/dex/uniswap-v2/uniswap-v2.d.ts +15 -4
- package/build/dex/uniswap-v2/uniswap-v2.js +124 -1
- package/build/dex/uniswap-v2/uniswap-v2.js.map +1 -1
- package/build/dex/uniswap-v3/constants.d.ts +4 -0
- package/build/dex/uniswap-v3/constants.js +6 -1
- package/build/dex/uniswap-v3/constants.js.map +1 -1
- package/build/dex/uniswap-v3/types.d.ts +15 -0
- package/build/dex/uniswap-v3/types.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3.d.ts +13 -4
- package/build/dex/uniswap-v3/uniswap-v3.js +130 -27
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/build/dex/uniswap-v3.d.ts +2 -1
- package/build/dex/uniswap-v3.js +28 -0
- package/build/dex/uniswap-v3.js.map +1 -1
- package/build/dex/weth/weth.d.ts +3 -1
- package/build/dex/weth/weth.js +17 -2
- package/build/dex/weth/weth.js.map +1 -1
- package/build/dex/wombat/wombat.d.ts +3 -2
- package/build/dex/wombat/wombat.js +20 -0
- package/build/dex/wombat/wombat.js.map +1 -1
- package/build/dex/woo-fi-v2/woo-fi-v2.d.ts +2 -1
- package/build/dex/woo-fi-v2/woo-fi-v2.js +27 -0
- package/build/dex/woo-fi-v2/woo-fi-v2.js.map +1 -1
- package/build/dex/wsteth/wsteth.d.ts +2 -1
- package/build/dex/wsteth/wsteth.js +9 -0
- package/build/dex/wsteth/wsteth.js.map +1 -1
- package/build/dex/zerox/config.d.ts +2 -0
- package/build/dex/zerox/config.js +33 -0
- package/build/dex/zerox/config.js.map +1 -0
- package/build/dex/zerox/index.d.ts +3 -25
- package/build/dex/zerox/index.js +49 -42
- package/build/dex/zerox/index.js.map +1 -1
- package/build/dex/zerox/types.d.ts +29 -0
- package/build/dex/zerox/types.js +8 -1
- package/build/dex/zerox/types.js.map +1 -1
- package/build/dex-helper/dummy-dex-helper.d.ts +2 -0
- package/build/dex-helper/dummy-dex-helper.js +20 -1
- package/build/dex-helper/dummy-dex-helper.js.map +1 -1
- package/build/dex-helper/icache.d.ts +2 -0
- package/build/dex-helper/idex-helper.d.ts +2 -0
- package/build/executor/Executor01BytecodeBuilder.d.ts +53 -0
- package/build/executor/Executor01BytecodeBuilder.js +253 -0
- package/build/executor/Executor01BytecodeBuilder.js.map +1 -0
- package/build/executor/Executor02BytecodeBuilder.d.ts +77 -0
- package/build/executor/Executor02BytecodeBuilder.js +717 -0
- package/build/executor/Executor02BytecodeBuilder.js.map +1 -0
- package/build/executor/Executor03BytecodeBuilder.d.ts +41 -0
- package/build/executor/Executor03BytecodeBuilder.js +226 -0
- package/build/executor/Executor03BytecodeBuilder.js.map +1 -0
- package/build/executor/ExecutorBytecodeBuilder.d.ts +42 -0
- package/build/executor/ExecutorBytecodeBuilder.js +150 -0
- package/build/executor/ExecutorBytecodeBuilder.js.map +1 -0
- package/build/executor/ExecutorDetector.d.ts +16 -0
- package/build/executor/ExecutorDetector.js +93 -0
- package/build/executor/ExecutorDetector.js.map +1 -0
- package/build/executor/IExecutorBytecodeBuilder.d.ts +6 -0
- package/build/executor/IExecutorBytecodeBuilder.js +3 -0
- package/build/executor/IExecutorBytecodeBuilder.js.map +1 -0
- package/build/executor/constants.d.ts +18 -0
- package/build/executor/constants.js +49 -0
- package/build/executor/constants.js.map +1 -0
- package/build/executor/tests/utils-e2e-v6.d.ts +8 -0
- package/build/executor/tests/utils-e2e-v6.js +175 -0
- package/build/executor/tests/utils-e2e-v6.js.map +1 -0
- package/build/executor/types.d.ts +37 -0
- package/build/executor/types.js +46 -0
- package/build/executor/types.js.map +1 -0
- package/build/generic-swap-transaction-builder.d.ts +56 -0
- package/build/generic-swap-transaction-builder.js +306 -0
- package/build/generic-swap-transaction-builder.js.map +1 -0
- package/build/implementations/local-paraswap-sdk.d.ts +15 -9
- package/build/implementations/local-paraswap-sdk.js +43 -27
- package/build/implementations/local-paraswap-sdk.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.js +3 -1
- package/build/index.js.map +1 -1
- package/build/lib/curve/encoder.d.ts +5 -0
- package/build/lib/curve/encoder.js +13 -0
- package/build/lib/curve/encoder.js.map +1 -0
- package/build/transaction-builder.d.ts +13 -1
- package/build/transaction-builder.js +17 -0
- package/build/transaction-builder.js.map +1 -1
- package/build/types.d.ts +34 -1
- package/jest.config.js +1 -1
- package/package.json +2 -2
- package/src/abi/augustus-v6/ABI.json +1075 -0
- package/src/config.ts +59 -3
- package/src/constants.ts +10 -1
- package/src/dex/aave-v1/aave-v1-e2e.test.ts +4 -8
- package/src/dex/aave-v1/aave-v1.ts +44 -0
- package/src/dex/aave-v2/aave-v2-e2e.test.ts +8 -5
- package/src/dex/aave-v2/aave-v2.ts +104 -0
- package/src/dex/aave-v3/aave-v3-e2e.test.ts +7 -5
- package/src/dex/aave-v3/aave-v3.ts +63 -0
- package/src/dex/algebra/algebra-e2e.test.ts +42 -72
- package/src/dex/algebra/algebra.ts +70 -3
- package/src/dex/augustus-approvals.ts +175 -0
- package/src/dex/bProtocol/bProtocol-e2e.test.ts +93 -0
- package/src/dex/{bProtocol.ts → bProtocol/bProtocol.ts} +40 -14
- package/src/dex/bProtocol/types.ts +13 -0
- package/src/dex/balancer-v1/balancer-v1-e2e.test.ts +7 -5
- package/src/dex/balancer-v1/balancer-v1.ts +116 -14
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +303 -267
- package/src/dex/balancer-v2/balancer-v2.ts +295 -15
- package/src/dex/balancer-v2/constants.ts +5 -0
- package/src/dex/balancer-v2/types.ts +13 -0
- package/src/dex/bancor/bancor-e2e.test.ts +91 -0
- package/src/dex/{bancor.ts → bancor/bancor.ts} +46 -33
- package/src/dex/bancor/config.ts +9 -0
- package/src/dex/bancor/types.ts +19 -0
- package/src/dex/camelot/camelot-e2e.test.ts +72 -4
- package/src/dex/camelot/camelot.ts +50 -0
- package/src/dex/compound/compound-e2e.test.ts +91 -0
- package/src/dex/{compound.ts → compound/compound.ts} +39 -17
- package/src/dex/compound/types.ts +10 -0
- package/src/dex/curve-v1/constants.ts +1 -0
- package/src/dex/curve-v1/curve-v1-e2e.test.ts +124 -64
- package/src/dex/curve-v1/curve-v1.ts +108 -9
- package/src/dex/curve-v1/packer.ts +17 -0
- package/src/dex/curve-v1/types.ts +18 -0
- package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +9 -8
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +37 -7
- package/src/dex/curve-v1-factory/state-polling-pools/polling-manager.ts +3 -3
- package/src/dex/curve-v2/constants.ts +1 -0
- package/src/dex/curve-v2/curve-v2-e2e.test.ts +104 -0
- package/src/dex/{curve-v2.ts → curve-v2/curve-v2.ts} +143 -23
- package/src/dex/curve-v2/types.ts +27 -0
- package/src/dex/dexalot/dexalot-e2e.test.ts +8 -6
- package/src/dex/dexalot/dexalot.ts +46 -0
- package/src/dex/dodo-v1/config.ts +15 -0
- package/src/dex/dodo-v1/dodo-v1-e2e.test.ts +101 -0
- package/src/dex/{dodo-v1.ts → dodo-v1/dodo-v1.ts} +52 -48
- package/src/dex/dodo-v1/types.ts +25 -0
- package/src/dex/dodo-v2.ts +80 -1
- package/src/dex/generic-rfq/e2e-test-config.ts +50 -6
- package/src/dex/generic-rfq/fetch-mm-api.ts +2 -4
- package/src/dex/generic-rfq/generic-rfq-e2e.test.ts +3 -3
- package/src/dex/generic-rfq/generic-rfq.ts +128 -11
- package/src/dex/generic-rfq/rate-fetcher.ts +2 -3
- package/src/dex/generic-rfq/types.ts +19 -2
- package/src/dex/generic-rfq/utils.ts +3 -9
- package/src/dex/generic-rfq/validators.ts +12 -15
- package/src/dex/gmx/gmx-e2e.test.ts +11 -8
- package/src/dex/gmx/gmx.ts +27 -0
- package/src/dex/hashflow/hashflow-e2e.test.ts +7 -5
- package/src/dex/hashflow/hashflow.ts +48 -1
- package/src/dex/idex.ts +34 -0
- package/src/dex/index.ts +27 -10
- package/src/dex/jarvis-v6/jarvis-v6-e2e.test.ts +5 -4
- package/src/dex/jarvis-v6/jarvis-v6.ts +37 -0
- package/src/dex/jarvis.ts +68 -1
- package/src/dex/kyberdmm/kyberdmm-e2e.test.ts +8 -5
- package/src/dex/kyberdmm/kyberdmm.ts +36 -0
- package/src/dex/lido/config.ts +5 -0
- package/src/dex/lido/lido-e2e.test.ts +71 -0
- package/src/dex/{lido.ts → lido/lido.ts} +34 -16
- package/src/dex/lido/types.ts +5 -0
- package/src/dex/maker-psm/maker-psm-e2e.test.ts +37 -7
- package/src/dex/maker-psm/maker-psm.ts +52 -0
- package/src/dex/maverick-v1/maverick-v1-e2e.test.ts +108 -0
- package/src/dex/maverick-v1/maverick-v1.ts +51 -0
- package/src/dex/nerve/nerve-e2e.test.ts +114 -57
- package/src/dex/nerve/nerve.ts +36 -0
- package/src/dex/{onebit.ts → onebit/onebit.ts} +43 -21
- package/src/dex/onebit/types.ts +17 -0
- package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +19 -5
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +46 -0
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders.ts +34 -0
- package/src/dex/paraswap-limit-orders/types.ts +1 -0
- package/src/dex/platypus/platypus-e2e.test.ts +5 -4
- package/src/dex/platypus/platypus.ts +43 -0
- package/src/dex/polygon-migrator/polygon-migrator-e2e.test.ts +7 -5
- package/src/dex/polygon-migrator/polygon-migrator.ts +26 -0
- package/src/dex/quick-perps/quick-perps-e2e.test.ts +4 -3
- package/src/dex/quick-perps/quick-perps.ts +28 -0
- package/src/dex/quickswap/quickswap-e2e.test.ts +7 -5
- package/src/dex/simple-exchange.ts +16 -60
- package/src/dex/smoothy/smoothy-e2e.test.ts +81 -0
- package/src/dex/{smoothy.ts → smoothy/smoothy.ts} +34 -24
- package/src/dex/smoothy/types.ts +18 -0
- package/src/dex/solidly/solidly-e2e.test.ts +122 -0
- package/src/dex/solidly/solidly.ts +49 -0
- package/src/dex/solidly-v3/contract-math/Tick.ts +1 -4
- package/src/dex/solidly-v3/contract-math/uniswap-v3-math.ts +6 -14
- package/src/dex/solidly-v3/solidly-v3-e2e.test.ts +7 -5
- package/src/dex/solidly-v3/solidly-v3-events.test.ts +9 -7
- package/src/dex/solidly-v3/solidly-v3.ts +40 -52
- package/src/dex/{stable-pool.ts → stable-pool/stable-pool.ts} +45 -32
- package/src/dex/stable-pool/stablepool-e2e.test.ts +73 -0
- package/src/dex/stable-pool/types.ts +20 -0
- package/src/dex/swaap-v1/swaap-v1-e2e.test.ts +7 -5
- package/src/dex/swaap-v1/swaap-v1.ts +32 -0
- package/src/dex/swaap-v2/rate-fetcher.ts +6 -4
- package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +7 -5
- package/src/dex/swaap-v2/swaap-v2.ts +39 -2
- package/src/dex/swaap-v2/validators.ts +12 -15
- package/src/dex/swell/swell-e2e.test.ts +4 -3
- package/src/dex/swell/swell.ts +27 -2
- package/src/dex/synthetix/synthetix-e2e.test.ts +5 -4
- package/src/dex/synthetix/synthetix.ts +38 -0
- package/src/dex/trader-joe-v2.1/config.ts +9 -0
- package/src/dex/trader-joe-v2.1/trader-joe-v2.1-e2e.test.ts +101 -0
- package/src/dex/{trader-joe-v2.1.ts → trader-joe-v2.1/trader-joe-v2.1.ts} +63 -48
- package/src/dex/trader-joe-v2.1/types.ts +38 -0
- package/src/dex/uniswap-v2/config.ts +42 -0
- package/src/dex/uniswap-v2/constants.ts +8 -6
- package/src/dex/uniswap-v2/dfyn.ts +44 -3
- package/src/dex/uniswap-v2/types.ts +22 -0
- package/src/dex/uniswap-v2/uniswap-v2-e2e-avalanche.test.ts +16 -13
- package/src/dex/uniswap-v2/uniswap-v2-e2e-bsc.test.ts +33 -17
- package/src/dex/uniswap-v2/uniswap-v2-e2e-mainnet.test.ts +424 -5
- package/src/dex/uniswap-v2/uniswap-v2-e2e-polygon.test.ts +145 -46
- package/src/dex/uniswap-v2/uniswap-v2-optimizer.ts +114 -0
- package/src/dex/uniswap-v2/uniswap-v2.ts +206 -2
- package/src/dex/uniswap-v3/constants.ts +5 -0
- package/src/dex/uniswap-v3/types.ts +17 -0
- package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +460 -402
- package/src/dex/uniswap-v3/uniswap-v3.ts +217 -43
- package/src/dex/uniswap-v3.ts +52 -1
- package/src/dex/weth/weth-e2e.test.ts +69 -38
- package/src/dex/weth/weth.ts +29 -5
- package/src/dex/wombat/wombat-e2e.test.ts +5 -4
- package/src/dex/wombat/wombat.ts +32 -1
- package/src/dex/woo-fi-v2/woo-fi-v2-e2e.test.ts +5 -4
- package/src/dex/woo-fi-v2/woo-fi-v2.ts +42 -0
- package/src/dex/wsteth/wsteth-e2e.test.ts +4 -3
- package/src/dex/wsteth/wsteth.ts +24 -0
- package/src/dex/zerox/config.ts +31 -0
- package/src/dex/zerox/index.ts +63 -67
- package/src/dex/zerox/types.ts +34 -0
- package/src/dex/zerox/zerox-e2e.test.ts +110 -0
- package/src/dex-helper/dummy-dex-helper.ts +28 -1
- package/src/dex-helper/icache.ts +4 -0
- package/src/dex-helper/idex-helper.ts +2 -0
- package/src/executor/Executor01BytecodeBuilder.ts +433 -0
- package/src/executor/Executor02BytecodeBuilder.ts +1329 -0
- package/src/executor/Executor03BytecodeBuilder.ts +419 -0
- package/src/executor/ExecutorBytecodeBuilder.ts +350 -0
- package/src/executor/ExecutorDetector.ts +117 -0
- package/src/executor/__snapshots__/executor01-bytecode-builder-snapshot.test.ts.snap +35 -0
- package/src/executor/__snapshots__/executor02-bytecode-builder-snapshot.test.ts.snap +23 -0
- package/src/executor/constants.ts +59 -0
- package/src/executor/executor01-bytecode-builder-e2e.test.ts +1439 -0
- package/src/executor/executor01-bytecode-builder-snapshot.test.ts +271 -0
- package/src/executor/executor02-bytecode-builder-e2e.test.ts +1489 -0
- package/src/executor/executor02-bytecode-builder-snapshot.test.ts +188 -0
- package/src/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +16 -0
- package/src/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +16 -0
- package/src/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +16 -0
- package/src/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +16 -0
- package/src/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-dai-usdc-eth.json +16 -0
- package/src/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-eth-usdc-dai.json +16 -0
- package/src/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +16 -0
- package/src/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdt-usdc-dai.json +16 -0
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-eth-usdc.json +9 -0
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-eth.json +9 -0
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-wbtc.json +9 -0
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-eth-steth.json +9 -0
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-steth-eth.json +9 -0
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-usdc-usdt.json +9 -0
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-eth-usdc.json +9 -0
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-eth.json +9 -0
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-usdt.json +9 -0
- package/src/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +12 -0
- package/src/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +7 -0
- package/src/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +7 -0
- package/src/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-dai-usdc-eth.json +7 -0
- package/src/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-eth-usdc-dai.json +7 -0
- package/src/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +12 -0
- package/src/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-eth-usdc.json +7 -0
- package/src/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-usdc-eth.json +7 -0
- package/src/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +78 -0
- package/src/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +81 -0
- package/src/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +78 -0
- package/src/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +78 -0
- package/src/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-dai-usdc-eth.json +81 -0
- package/src/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-eth-usdc-dai.json +81 -0
- package/src/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +81 -0
- package/src/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdt-usdc-dai.json +81 -0
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-eth-usdc.json +64 -0
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-eth.json +85 -0
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-wbtc.json +64 -0
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-eth-steth.json +52 -0
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-steth-eth.json +52 -0
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-usdc-usdt.json +52 -0
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-eth-usdc.json +55 -0
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-eth.json +55 -0
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-usdt.json +55 -0
- package/src/executor/fixtures/executor02/exchange-params/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +23 -0
- package/src/executor/fixtures/executor02/exchange-params/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +37 -0
- package/src/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +23 -0
- package/src/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +23 -0
- package/src/executor/fixtures/executor02/exchange-params/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +51 -0
- package/src/executor/fixtures/executor02/exchange-params/price-route-multiswap-univ3-usdt-dai-eth.json +58 -0
- package/src/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +23 -0
- package/src/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +23 -0
- package/src/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +9 -0
- package/src/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +16 -0
- package/src/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +23 -0
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +12 -0
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +7 -0
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +12 -0
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +12 -0
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +7 -0
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-univ3-usdt-dai-eth.json +7 -0
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +7 -0
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +7 -0
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +7 -0
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +7 -0
- package/src/executor/fixtures/executor02/routes/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +130 -0
- package/src/executor/fixtures/executor02/routes/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +136 -0
- package/src/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +100 -0
- package/src/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +100 -0
- package/src/executor/fixtures/executor02/routes/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +166 -0
- package/src/executor/fixtures/executor02/routes/price-route-multiswap-univ3-usdt-dai-eth.json +190 -0
- package/src/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +114 -0
- package/src/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +114 -0
- package/src/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +55 -0
- package/src/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +73 -0
- package/src/executor/fixtures/executor02/routes/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +82 -0
- package/src/executor/types.ts +41 -0
- package/src/generic-swap-transaction-builder.ts +679 -0
- package/src/implementations/local-paraswap-sdk.ts +70 -29
- package/src/index.ts +1 -0
- package/src/lib/curve/encoder.ts +19 -0
- package/src/transaction-builder.ts +45 -1
- package/src/types.ts +35 -1
- package/tests/augustus-approvals.test.ts +628 -0
- package/tests/constants-e2e.ts +167 -35
- package/tests/debug-price-route.json +68 -0
- package/tests/debug-price-route.test.ts +55 -0
- package/tests/tenderly-simulation.ts +54 -5
- package/tests/utils-e2e.ts +347 -53
- package/tests/v6/executors.test.ts +110 -0
- package/tests/v6/price-routes/arbitrum/sell-0.1-ETH-USDC.json +104 -0
- package/tests/v6/price-routes/arbitrum/sell-1_000-ETH-DAI.json +294 -0
- package/tests/v6/price-routes/arbitrum/sell-1_000-WETH-wstETH.json +121 -0
- package/tests/v6/price-routes/arbitrum/sell-1_000_000-ARB-DAI.json +270 -0
- package/tests/v6/price-routes/arbitrum/sell-1_000_000-ARB-ETH.json +326 -0
- package/tests/v6/price-routes/arbitrum/sell-1_000_000-DAI-ARB.json +434 -0
- package/tests/v6/price-routes/arbitrum/sell-250_000-LINK-USDC.json +182 -0
- package/tests/v6/price-routes/arbitrum/sell-3_000-BAL-UNI.json +154 -0
- package/tests/v6/price-routes/avalanche/sell-100_000-WAVAX-USDC.json +315 -0
- package/tests/v6/price-routes/avalanche/sell-40-BTC-AVAX.json +207 -0
- package/tests/v6/price-routes/fantom/test.json +161 -0
- package/tests/v6/price-routes/mainnet/buy-3200-ETH-DAI.json +228 -0
- package/tests/v6/price-routes/mainnet/buy-usdc.json +233 -0
- package/tests/v6/price-routes/mainnet/executor-01.json +93 -0
- package/tests/v6/price-routes/mainnet/executor01-test copy.json +88 -0
- package/tests/v6/price-routes/mainnet/executor01-test.json +88 -0
- package/tests/v6/price-routes/mainnet/sell-1-USDC-USDT.json +78 -0
- package/tests/v6/price-routes/mainnet/sell-1-WBTC-BAL.json +158 -0
- package/tests/v6/price-routes/mainnet/sell-100-tBTC-WBTC.json +100 -0
- package/tests/v6/price-routes/mainnet/sell-1000-eth-dai.json +340 -0
- package/tests/v6/price-routes/mainnet/sell-1000-wbtc-eth-uniswapv3-balancerv2.json +162 -0
- package/tests/v6/price-routes/mainnet/sell-100_000-USDC-USDT-2-univ2-pools.json +86 -0
- package/tests/v6/price-routes/mainnet/sell-10_000-ETH-USDC-balancer.json +383 -0
- package/tests/v6/price-routes/mainnet/sell-10_000-ETH-stETH.json +168 -0
- package/tests/v6/price-routes/mainnet/sell-10_000-USDC-USDT-BalancerV2.json +68 -0
- package/tests/v6/price-routes/mainnet/sell-10_000-eth-usdc-uniswapv3-balancerv2.json +348 -0
- package/tests/v6/price-routes/mainnet/sell-1_000-stETH-ETH.json +100 -0
- package/tests/v6/price-routes/mainnet/sell-50-eth-usdc.json +153 -0
- package/tests/v6/price-routes/polygon/sell-100-WBTC-MATIC-1.json +571 -0
- package/tests/v6/price-routes/polygon/sell-100-WBTC-MATIC.json +559 -0
- package/tests/v6/price-routes/polygon/sell-1_000_000-DAI-MATIC-2.json +447 -0
- package/tests/v6/price-routes/polygon/sell-1_000_000-DAI-MATIC-3.json +472 -0
- package/tests/v6/price-routes/polygon/sell-1_000_000-DAI-MATIC.json +628 -0
- package/tests/v6/price-routes/polygon/test.json +109 -0
- package/tests/v6/utils-e2e-v6.ts +177 -0
- package/build/abi/algebra/AlgebraPool.abi.json +0 -727
- package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
- package/build/abi/wombat/pool.json +0 -1289
- package/build/dex/algebra/algebra-pool.d.ts +0 -46
- package/build/dex/algebra/algebra-pool.js +0 -336
- package/build/dex/algebra/algebra-pool.js.map +0 -1
- package/build/dex/quickswap/camelot-v3.d.ts +0 -6
- package/build/dex/quickswap/camelot-v3.js +0 -19
- package/build/dex/quickswap/camelot-v3.js.map +0 -1
- package/build/dex/quickswap/zyberswap-v3.d.ts +0 -6
- package/build/dex/quickswap/zyberswap-v3.js +0 -19
- package/build/dex/quickswap/zyberswap-v3.js.map +0 -1
- package/build/dex/uniswap-v2/rebase-tokens.json +0 -7
|
@@ -0,0 +1,1329 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import {
|
|
3
|
+
OptimalRoute,
|
|
4
|
+
OptimalRate,
|
|
5
|
+
OptimalSwap,
|
|
6
|
+
OptimalSwapExchange,
|
|
7
|
+
} from '@paraswap/core';
|
|
8
|
+
import { DexExchangeBuildParam, DexExchangeParam } from '../types';
|
|
9
|
+
import { Executors, Flag, SpecialDex } from './types';
|
|
10
|
+
import { isETHAddress } from '../utils';
|
|
11
|
+
import { DepositWithdrawReturn } from '../dex/weth/types';
|
|
12
|
+
import { ExecutorBytecodeBuilder } from './ExecutorBytecodeBuilder';
|
|
13
|
+
import {
|
|
14
|
+
BYTES_64_LENGTH,
|
|
15
|
+
NOT_EXISTING_EXCHANGE_PARAM_INDEX,
|
|
16
|
+
ETH_SRC_TOKEN_POS_FOR_MULTISWAP_METADATA,
|
|
17
|
+
SWAP_EXCHANGE_100_PERCENTAGE,
|
|
18
|
+
ZEROS_20_BYTES,
|
|
19
|
+
ZEROS_28_BYTES,
|
|
20
|
+
ZEROS_4_BYTES,
|
|
21
|
+
} from './constants';
|
|
22
|
+
import { assert } from 'ts-essentials';
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
utils: { hexlify, hexDataLength, hexConcat, hexZeroPad, solidityPack },
|
|
26
|
+
} = ethers;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Class to build bytecode for Executor02 - simpleSwap with N DEXs (VERTICAL_BRANCH), multiSwaps (VERTICAL_BRANCH_HORIZONTAL_SEQUENCE) and megaswaps (NESTED_VERTICAL_BRANCH_HORIZONTAL_SEQUENCE)
|
|
30
|
+
*/
|
|
31
|
+
export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder {
|
|
32
|
+
type = Executors.TWO;
|
|
33
|
+
/**
|
|
34
|
+
* Executor02 Flags:
|
|
35
|
+
* switch (flag % 4):
|
|
36
|
+
* case 0: don't instert fromAmount
|
|
37
|
+
* case 1: sendEth equal to fromAmount
|
|
38
|
+
* case 2: sendEth equal to fromAmount + insert fromAmount
|
|
39
|
+
* case 3: insert fromAmount
|
|
40
|
+
|
|
41
|
+
* switch (flag % 3):
|
|
42
|
+
* case 0: don't check balance after swap
|
|
43
|
+
* case 1: check eth balance after swap
|
|
44
|
+
* case 2: check destToken balance after swap
|
|
45
|
+
*/
|
|
46
|
+
protected buildSimpleSwapFlags(
|
|
47
|
+
priceRoute: OptimalRate,
|
|
48
|
+
exchangeParams: DexExchangeBuildParam[],
|
|
49
|
+
routeIndex: number,
|
|
50
|
+
swapIndex: number,
|
|
51
|
+
swapExchangeIndex: number,
|
|
52
|
+
exchangeParamIndex: number,
|
|
53
|
+
maybeWethCallData?: DepositWithdrawReturn,
|
|
54
|
+
): { dexFlag: Flag; approveFlag: Flag } {
|
|
55
|
+
const { srcToken, destToken } =
|
|
56
|
+
priceRoute.bestRoute[routeIndex].swaps[swapIndex];
|
|
57
|
+
const isEthSrc = isETHAddress(srcToken);
|
|
58
|
+
const isEthDest = isETHAddress(destToken);
|
|
59
|
+
|
|
60
|
+
const exchangeParam = exchangeParams[exchangeParamIndex];
|
|
61
|
+
const {
|
|
62
|
+
dexFuncHasRecipient,
|
|
63
|
+
needWrapNative,
|
|
64
|
+
specialDexFlag,
|
|
65
|
+
specialDexSupportsInsertFromAmount,
|
|
66
|
+
swappedAmountNotPresentInExchangeData,
|
|
67
|
+
} = exchangeParam;
|
|
68
|
+
|
|
69
|
+
const needWrap = needWrapNative && isEthSrc && maybeWethCallData?.deposit;
|
|
70
|
+
const needUnwrap =
|
|
71
|
+
needWrapNative && isEthDest && maybeWethCallData?.withdraw;
|
|
72
|
+
const isSpecialDex =
|
|
73
|
+
specialDexFlag !== undefined && specialDexFlag !== SpecialDex.DEFAULT;
|
|
74
|
+
|
|
75
|
+
const forcePreventInsertFromAmount =
|
|
76
|
+
swappedAmountNotPresentInExchangeData ||
|
|
77
|
+
(isSpecialDex && !specialDexSupportsInsertFromAmount);
|
|
78
|
+
|
|
79
|
+
let dexFlag = forcePreventInsertFromAmount
|
|
80
|
+
? Flag.DONT_INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP
|
|
81
|
+
: Flag.INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP; // 0 or 3
|
|
82
|
+
let approveFlag =
|
|
83
|
+
Flag.DONT_INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP; // 0
|
|
84
|
+
|
|
85
|
+
if (isEthSrc && !needWrap) {
|
|
86
|
+
dexFlag =
|
|
87
|
+
Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP; // 5
|
|
88
|
+
} else if (isEthDest && !needUnwrap) {
|
|
89
|
+
dexFlag = forcePreventInsertFromAmount
|
|
90
|
+
? Flag.DONT_INSERT_FROM_AMOUNT_CHECK_ETH_BALANCE_AFTER_SWAP
|
|
91
|
+
: Flag.INSERT_FROM_AMOUNT_CHECK_ETH_BALANCE_AFTER_SWAP; // 4 or 7
|
|
92
|
+
} else if (!dexFuncHasRecipient || (isEthDest && needUnwrap)) {
|
|
93
|
+
dexFlag = forcePreventInsertFromAmount
|
|
94
|
+
? Flag.DONT_INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP
|
|
95
|
+
: Flag.INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP; // 8 or 11
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
dexFlag,
|
|
100
|
+
approveFlag,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Executor02 Flags:
|
|
106
|
+
* switch (flag % 4):
|
|
107
|
+
* case 0: don't instert fromAmount
|
|
108
|
+
* case 1: sendEth equal to fromAmount
|
|
109
|
+
* case 2: sendEth equal to fromAmount + insert fromAmount
|
|
110
|
+
* case 3: insert fromAmount
|
|
111
|
+
|
|
112
|
+
* switch (flag % 3):
|
|
113
|
+
* case 0: don't check balance after swap
|
|
114
|
+
* case 1: check eth balance after swap
|
|
115
|
+
* case 2: check destToken balance after swap
|
|
116
|
+
*/
|
|
117
|
+
protected buildMultiMegaSwapFlags(
|
|
118
|
+
priceRoute: OptimalRate,
|
|
119
|
+
exchangeParams: DexExchangeBuildParam[],
|
|
120
|
+
routeIndex: number,
|
|
121
|
+
swapIndex: number,
|
|
122
|
+
swapExchangeIndex: number,
|
|
123
|
+
exchangeParamIndex: number,
|
|
124
|
+
maybeWethCallData?: DepositWithdrawReturn,
|
|
125
|
+
): { dexFlag: Flag; approveFlag: Flag } {
|
|
126
|
+
const route = priceRoute.bestRoute[routeIndex];
|
|
127
|
+
const swap = route.swaps[swapIndex];
|
|
128
|
+
|
|
129
|
+
const exchangeParam = exchangeParams[exchangeParamIndex];
|
|
130
|
+
|
|
131
|
+
const { srcToken, destToken } = swap;
|
|
132
|
+
const applyVerticalBranching = this.doesSwapNeedToApplyVerticalBranching(
|
|
133
|
+
priceRoute,
|
|
134
|
+
routeIndex,
|
|
135
|
+
swap,
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
const isHorizontalSequence = route.swaps.length > 1; // check if route is a multi-swap (horizontal sequence)
|
|
139
|
+
const isFirstSwap = swapIndex === 0;
|
|
140
|
+
const isLastSwap = !isFirstSwap && swapIndex === route.swaps.length - 1;
|
|
141
|
+
|
|
142
|
+
const {
|
|
143
|
+
dexFuncHasRecipient,
|
|
144
|
+
needWrapNative,
|
|
145
|
+
specialDexFlag,
|
|
146
|
+
specialDexSupportsInsertFromAmount,
|
|
147
|
+
swappedAmountNotPresentInExchangeData,
|
|
148
|
+
wethAddress,
|
|
149
|
+
sendEthButSupportsInsertFromAmount,
|
|
150
|
+
} = exchangeParam;
|
|
151
|
+
|
|
152
|
+
const isEthSrc = isETHAddress(srcToken);
|
|
153
|
+
const isEthDest = isETHAddress(destToken);
|
|
154
|
+
const isWethDest =
|
|
155
|
+
(wethAddress && destToken.toLowerCase() === wethAddress.toLowerCase()) ||
|
|
156
|
+
this.dexHelper.config.isWETH(destToken);
|
|
157
|
+
|
|
158
|
+
const isSpecialDex =
|
|
159
|
+
specialDexFlag !== undefined && specialDexFlag !== SpecialDex.DEFAULT;
|
|
160
|
+
|
|
161
|
+
const forcePreventInsertFromAmount =
|
|
162
|
+
swappedAmountNotPresentInExchangeData ||
|
|
163
|
+
(isSpecialDex && !specialDexSupportsInsertFromAmount);
|
|
164
|
+
|
|
165
|
+
const forceBalanceOfCheck =
|
|
166
|
+
(isSpecialDex &&
|
|
167
|
+
isHorizontalSequence &&
|
|
168
|
+
!applyVerticalBranching &&
|
|
169
|
+
!isLastSwap) ||
|
|
170
|
+
!dexFuncHasRecipient;
|
|
171
|
+
|
|
172
|
+
const needUnwrap =
|
|
173
|
+
needWrapNative && isEthDest && maybeWethCallData?.withdraw;
|
|
174
|
+
|
|
175
|
+
const needSendEth = isEthSrc && !needWrapNative;
|
|
176
|
+
const needCheckEthBalance = isEthDest && !needWrapNative;
|
|
177
|
+
|
|
178
|
+
const needCheckSrcTokenBalanceOf =
|
|
179
|
+
(needUnwrap && !applyVerticalBranching && !isLastSwap) ||
|
|
180
|
+
(isHorizontalSequence && !applyVerticalBranching && !isLastSwap);
|
|
181
|
+
|
|
182
|
+
let dexFlag: Flag;
|
|
183
|
+
let approveFlag =
|
|
184
|
+
Flag.DONT_INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP; // 0
|
|
185
|
+
|
|
186
|
+
if (needSendEth) {
|
|
187
|
+
const preventInsertForSendEth =
|
|
188
|
+
forcePreventInsertFromAmount || !sendEthButSupportsInsertFromAmount;
|
|
189
|
+
dexFlag = forceBalanceOfCheck
|
|
190
|
+
? preventInsertForSendEth
|
|
191
|
+
? Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP // 5
|
|
192
|
+
: Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_PLUS_INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP // 14
|
|
193
|
+
: dexFuncHasRecipient
|
|
194
|
+
? preventInsertForSendEth
|
|
195
|
+
? Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP // 9
|
|
196
|
+
: Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_PLUS_INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP // 18
|
|
197
|
+
: preventInsertForSendEth
|
|
198
|
+
? Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP // 5
|
|
199
|
+
: Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_PLUS_INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP; // 18
|
|
200
|
+
} else if (needCheckEthBalance) {
|
|
201
|
+
dexFlag =
|
|
202
|
+
needCheckSrcTokenBalanceOf || forceBalanceOfCheck
|
|
203
|
+
? forcePreventInsertFromAmount && dexFuncHasRecipient
|
|
204
|
+
? Flag.DONT_INSERT_FROM_AMOUNT_CHECK_ETH_BALANCE_AFTER_SWAP // 4
|
|
205
|
+
: Flag.INSERT_FROM_AMOUNT_CHECK_ETH_BALANCE_AFTER_SWAP // 7
|
|
206
|
+
: forcePreventInsertFromAmount && dexFuncHasRecipient
|
|
207
|
+
? Flag.DONT_INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP // 0
|
|
208
|
+
: Flag.INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP; // 3
|
|
209
|
+
} else {
|
|
210
|
+
dexFlag =
|
|
211
|
+
needCheckSrcTokenBalanceOf || forceBalanceOfCheck
|
|
212
|
+
? forcePreventInsertFromAmount
|
|
213
|
+
? Flag.DONT_INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP // 8
|
|
214
|
+
: Flag.INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP // 11
|
|
215
|
+
: forcePreventInsertFromAmount
|
|
216
|
+
? Flag.DONT_INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP // 0
|
|
217
|
+
: Flag.INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP; // 3
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return {
|
|
221
|
+
dexFlag,
|
|
222
|
+
approveFlag,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
protected buildDexCallData(
|
|
227
|
+
priceRoute: OptimalRate,
|
|
228
|
+
routeIndex: number,
|
|
229
|
+
swapIndex: number,
|
|
230
|
+
swapExchangeIndex: number,
|
|
231
|
+
exchangeParams: DexExchangeBuildParam[],
|
|
232
|
+
exchangeParamIndex: number,
|
|
233
|
+
isLastSwap: boolean,
|
|
234
|
+
flag: Flag,
|
|
235
|
+
swapExchange: OptimalSwapExchange<any>,
|
|
236
|
+
): string {
|
|
237
|
+
const swap = priceRoute.bestRoute[routeIndex].swaps[swapIndex];
|
|
238
|
+
const exchangeParam = exchangeParams[exchangeParamIndex];
|
|
239
|
+
let { exchangeData, specialDexFlag, targetExchange, needWrapNative } =
|
|
240
|
+
exchangeParam;
|
|
241
|
+
|
|
242
|
+
const applyVerticalBranching = this.doesSwapNeedToApplyVerticalBranching(
|
|
243
|
+
priceRoute,
|
|
244
|
+
routeIndex,
|
|
245
|
+
swap,
|
|
246
|
+
);
|
|
247
|
+
const dontCheckBalanceAfterSwap = flag % 3 === 0;
|
|
248
|
+
const checkDestTokenBalanceAfterSwap = flag % 3 === 2;
|
|
249
|
+
const insertFromAmount = flag % 4 === 3 || flag % 4 === 2;
|
|
250
|
+
|
|
251
|
+
const srcTokenAddress =
|
|
252
|
+
isETHAddress(swap.srcToken) && needWrapNative
|
|
253
|
+
? this.getWETHAddress(exchangeParam)
|
|
254
|
+
: swap.srcToken.toLowerCase();
|
|
255
|
+
|
|
256
|
+
const destTokenAddress =
|
|
257
|
+
isETHAddress(swap.destToken) && needWrapNative
|
|
258
|
+
? this.getWETHAddress(exchangeParam)
|
|
259
|
+
: swap.destToken.toLowerCase();
|
|
260
|
+
|
|
261
|
+
exchangeData = this.addTokenAddressToCallData(
|
|
262
|
+
exchangeData,
|
|
263
|
+
srcTokenAddress,
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
if (
|
|
267
|
+
applyVerticalBranching ||
|
|
268
|
+
(checkDestTokenBalanceAfterSwap && !dontCheckBalanceAfterSwap)
|
|
269
|
+
) {
|
|
270
|
+
exchangeData = this.addTokenAddressToCallData(
|
|
271
|
+
exchangeData,
|
|
272
|
+
destTokenAddress,
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
let destTokenPos = 0;
|
|
277
|
+
if (checkDestTokenBalanceAfterSwap && !dontCheckBalanceAfterSwap) {
|
|
278
|
+
const destTokenAddrIndex = exchangeData
|
|
279
|
+
.replace('0x', '')
|
|
280
|
+
.indexOf(destTokenAddress.replace('0x', ''));
|
|
281
|
+
destTokenPos = (destTokenAddrIndex - 24) / 2;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
let fromAmountPos = 0;
|
|
285
|
+
if (insertFromAmount) {
|
|
286
|
+
const fromAmount = ethers.utils.defaultAbiCoder.encode(
|
|
287
|
+
['uint256'],
|
|
288
|
+
[swapExchange.srcAmount],
|
|
289
|
+
);
|
|
290
|
+
const fromAmountIndex = exchangeData
|
|
291
|
+
.replace('0x', '')
|
|
292
|
+
.indexOf(fromAmount.replace('0x', ''));
|
|
293
|
+
|
|
294
|
+
assert(
|
|
295
|
+
fromAmountIndex !== -1,
|
|
296
|
+
'Encoding error: could not resolve position of fromAmount in exchangeData',
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
fromAmountPos = fromAmountIndex / 2;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return this.buildCallData(
|
|
303
|
+
targetExchange,
|
|
304
|
+
exchangeData,
|
|
305
|
+
fromAmountPos,
|
|
306
|
+
destTokenPos,
|
|
307
|
+
specialDexFlag || SpecialDex.DEFAULT,
|
|
308
|
+
flag,
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
private addMultiSwapMetadata(
|
|
313
|
+
priceRoute: OptimalRate,
|
|
314
|
+
exchangeParams: DexExchangeBuildParam[],
|
|
315
|
+
callData: string,
|
|
316
|
+
percentage: number,
|
|
317
|
+
swap: OptimalSwap,
|
|
318
|
+
exchangeParamIndex: number,
|
|
319
|
+
wrapWasAddedInSwapExchange: boolean,
|
|
320
|
+
addedUnwrapForDexWithNoNeedWrapNative = false,
|
|
321
|
+
) {
|
|
322
|
+
let srcTokenAddress = swap.srcToken;
|
|
323
|
+
|
|
324
|
+
let doesAnyDexOnSwapNeedsWrapNative: boolean;
|
|
325
|
+
if (exchangeParamIndex > -1) {
|
|
326
|
+
doesAnyDexOnSwapNeedsWrapNative =
|
|
327
|
+
isETHAddress(srcTokenAddress) &&
|
|
328
|
+
(exchangeParams[exchangeParamIndex].needWrapNative ||
|
|
329
|
+
(!exchangeParams[exchangeParamIndex].needWrapNative &&
|
|
330
|
+
addedUnwrapForDexWithNoNeedWrapNative));
|
|
331
|
+
} else {
|
|
332
|
+
doesAnyDexOnSwapNeedsWrapNative =
|
|
333
|
+
isETHAddress(srcTokenAddress) &&
|
|
334
|
+
this.anyDexOnSwapNeedsWrapNative(priceRoute, swap, exchangeParams);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (
|
|
338
|
+
doesAnyDexOnSwapNeedsWrapNative &&
|
|
339
|
+
isETHAddress(srcTokenAddress) &&
|
|
340
|
+
!wrapWasAddedInSwapExchange
|
|
341
|
+
) {
|
|
342
|
+
srcTokenAddress =
|
|
343
|
+
exchangeParamIndex > -1
|
|
344
|
+
? this.getWETHAddress(exchangeParams[exchangeParamIndex])
|
|
345
|
+
: this.dexHelper.config.data.wrappedNativeTokenAddress;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
let srcTokenAddressLowered = srcTokenAddress.toLowerCase();
|
|
349
|
+
let srcTokenPos: string;
|
|
350
|
+
|
|
351
|
+
if (percentage === SWAP_EXCHANGE_100_PERCENTAGE) {
|
|
352
|
+
srcTokenPos = hexZeroPad(hexlify(0), 8);
|
|
353
|
+
} else if (isETHAddress(srcTokenAddressLowered)) {
|
|
354
|
+
srcTokenPos = ETH_SRC_TOKEN_POS_FOR_MULTISWAP_METADATA;
|
|
355
|
+
} else {
|
|
356
|
+
const srcTokenAddrIndex = callData
|
|
357
|
+
.replace('0x', '')
|
|
358
|
+
.indexOf(srcTokenAddressLowered.replace('0x', ''));
|
|
359
|
+
|
|
360
|
+
srcTokenPos = hexZeroPad(hexlify(srcTokenAddrIndex / 2), 8);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return solidityPack(
|
|
364
|
+
['bytes16', 'bytes8', 'bytes8', 'bytes'],
|
|
365
|
+
[
|
|
366
|
+
hexZeroPad(hexlify(hexDataLength(callData)), 16), // calldata size
|
|
367
|
+
srcTokenPos, // srcTokenPos
|
|
368
|
+
hexZeroPad(hexlify(Math.round(percentage * 100)), 8), // percentage
|
|
369
|
+
callData, // swap calldata
|
|
370
|
+
],
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
private packVerticalBranchingData(swapCallData: string): string {
|
|
375
|
+
return solidityPack(
|
|
376
|
+
['bytes28', 'bytes4', 'bytes32', 'bytes32', 'bytes'],
|
|
377
|
+
[
|
|
378
|
+
ZEROS_28_BYTES, // empty bytes28
|
|
379
|
+
ZEROS_4_BYTES, // fallback selector
|
|
380
|
+
hexZeroPad(hexlify(32), 32), // calldata offset
|
|
381
|
+
hexZeroPad(hexlify(hexDataLength(swapCallData)), 32), // calldata length
|
|
382
|
+
swapCallData, // calldata
|
|
383
|
+
],
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
private packVerticalBranchingCallData(
|
|
388
|
+
verticalBranchingData: string,
|
|
389
|
+
fromAmountPos: number,
|
|
390
|
+
destTokenPos: number,
|
|
391
|
+
flag: Flag,
|
|
392
|
+
): string {
|
|
393
|
+
return solidityPack(
|
|
394
|
+
[
|
|
395
|
+
'bytes20',
|
|
396
|
+
'bytes4',
|
|
397
|
+
'bytes2',
|
|
398
|
+
'bytes2',
|
|
399
|
+
'bytes1',
|
|
400
|
+
'bytes1',
|
|
401
|
+
'bytes2',
|
|
402
|
+
'bytes',
|
|
403
|
+
],
|
|
404
|
+
[
|
|
405
|
+
ZEROS_20_BYTES, // bytes20(0)
|
|
406
|
+
hexZeroPad(hexlify(hexDataLength(verticalBranchingData)), 4), // dex calldata length
|
|
407
|
+
hexZeroPad(hexlify(fromAmountPos), 2), // fromAmountPos
|
|
408
|
+
hexZeroPad(hexlify(destTokenPos), 2), // destTokenPos
|
|
409
|
+
hexZeroPad(hexlify(0), 1), // returnAmountPos
|
|
410
|
+
hexZeroPad(hexlify(SpecialDex.EXECUTE_VERTICAL_BRANCHING), 1), // special
|
|
411
|
+
hexZeroPad(hexlify(flag), 2), // flag
|
|
412
|
+
verticalBranchingData, // dexes calldata
|
|
413
|
+
],
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
private buildVerticalBranchingCallData(
|
|
418
|
+
priceRoute: OptimalRate,
|
|
419
|
+
routeIndex: number,
|
|
420
|
+
exchangeParams: DexExchangeBuildParam[],
|
|
421
|
+
swap: OptimalSwap,
|
|
422
|
+
swapCallData: string,
|
|
423
|
+
flag: Flag,
|
|
424
|
+
) {
|
|
425
|
+
const data = this.packVerticalBranchingData(swapCallData);
|
|
426
|
+
|
|
427
|
+
const destTokenAddrLowered = swap.destToken.toLowerCase();
|
|
428
|
+
const isEthDest = isETHAddress(destTokenAddrLowered);
|
|
429
|
+
|
|
430
|
+
let anyDexOnSwapNeedsWrapNative = false;
|
|
431
|
+
let anyDexOnSwapDoesntNeedWrapNative = false;
|
|
432
|
+
let destTokenPos: number;
|
|
433
|
+
|
|
434
|
+
if (isEthDest) {
|
|
435
|
+
anyDexOnSwapNeedsWrapNative = this.anyDexOnSwapNeedsWrapNative(
|
|
436
|
+
priceRoute,
|
|
437
|
+
swap,
|
|
438
|
+
exchangeParams,
|
|
439
|
+
);
|
|
440
|
+
anyDexOnSwapDoesntNeedWrapNative = this.anyDexOnSwapDoesntNeedWrapNative(
|
|
441
|
+
priceRoute,
|
|
442
|
+
swap,
|
|
443
|
+
exchangeParams,
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
if (
|
|
448
|
+
isEthDest &&
|
|
449
|
+
anyDexOnSwapDoesntNeedWrapNative &&
|
|
450
|
+
!anyDexOnSwapNeedsWrapNative
|
|
451
|
+
) {
|
|
452
|
+
destTokenPos = 0;
|
|
453
|
+
} else {
|
|
454
|
+
const destTokenAddrIndex = data
|
|
455
|
+
.replace('0x', '')
|
|
456
|
+
.indexOf(
|
|
457
|
+
(isEthDest
|
|
458
|
+
? this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase()
|
|
459
|
+
: destTokenAddrLowered.toLowerCase()
|
|
460
|
+
).replace('0x', ''),
|
|
461
|
+
);
|
|
462
|
+
|
|
463
|
+
destTokenPos = destTokenAddrIndex / 2 - 40;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const fromAmountPos = hexDataLength(data) - 64 - 28; // 64 (position), 28 (selector padding);
|
|
467
|
+
|
|
468
|
+
return this.packVerticalBranchingCallData(
|
|
469
|
+
data,
|
|
470
|
+
fromAmountPos,
|
|
471
|
+
destTokenPos < 0 ? 0 : destTokenPos,
|
|
472
|
+
flag,
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
private buildSingleSwapExchangeCallData(
|
|
477
|
+
priceRoute: OptimalRate,
|
|
478
|
+
routeIndex: number,
|
|
479
|
+
swapIndex: number,
|
|
480
|
+
swapExchangeIndex: number,
|
|
481
|
+
exchangeParams: DexExchangeBuildParam[],
|
|
482
|
+
flags: { approves: Flag[]; dexes: Flag[]; wrap: Flag },
|
|
483
|
+
addedWrapToSwapExchangeMap: { [key: string]: boolean },
|
|
484
|
+
allowToAddWrap = true,
|
|
485
|
+
prevBranchWasWrapped = false,
|
|
486
|
+
maybeWethCallData?: DepositWithdrawReturn,
|
|
487
|
+
addMultiSwapMetadata?: boolean,
|
|
488
|
+
applyVerticalBranching?: boolean,
|
|
489
|
+
): string {
|
|
490
|
+
const isSimpleSwap =
|
|
491
|
+
priceRoute.bestRoute.length === 1 &&
|
|
492
|
+
priceRoute.bestRoute[0].swaps.length === 1;
|
|
493
|
+
let swapExchangeCallData = '';
|
|
494
|
+
const swap = priceRoute.bestRoute[routeIndex].swaps[swapIndex];
|
|
495
|
+
const swapExchange = swap.swapExchanges[swapExchangeIndex];
|
|
496
|
+
|
|
497
|
+
let exchangeParamIndex = 0;
|
|
498
|
+
let tempExchangeParamIndex = 0;
|
|
499
|
+
|
|
500
|
+
priceRoute.bestRoute.map(route =>
|
|
501
|
+
route.swaps.map(curSwap => {
|
|
502
|
+
curSwap.swapExchanges.map(async se => {
|
|
503
|
+
if (Object.is(se, swapExchange)) {
|
|
504
|
+
exchangeParamIndex = tempExchangeParamIndex;
|
|
505
|
+
}
|
|
506
|
+
tempExchangeParamIndex++;
|
|
507
|
+
});
|
|
508
|
+
}),
|
|
509
|
+
);
|
|
510
|
+
|
|
511
|
+
const curExchangeParam = exchangeParams[exchangeParamIndex];
|
|
512
|
+
|
|
513
|
+
const dexCallData = this.buildDexCallData(
|
|
514
|
+
priceRoute,
|
|
515
|
+
routeIndex,
|
|
516
|
+
swapIndex,
|
|
517
|
+
swapExchangeIndex,
|
|
518
|
+
exchangeParams,
|
|
519
|
+
exchangeParamIndex,
|
|
520
|
+
false,
|
|
521
|
+
flags.dexes[exchangeParamIndex],
|
|
522
|
+
swapExchange,
|
|
523
|
+
);
|
|
524
|
+
|
|
525
|
+
swapExchangeCallData = hexConcat([dexCallData]);
|
|
526
|
+
|
|
527
|
+
const isLastSwap =
|
|
528
|
+
swapIndex === priceRoute.bestRoute[routeIndex].swaps.length - 1;
|
|
529
|
+
const isLast = exchangeParamIndex === exchangeParams.length - 1;
|
|
530
|
+
|
|
531
|
+
if (curExchangeParam.transferSrcTokenBeforeSwap) {
|
|
532
|
+
const transferCallData = this.buildTransferCallData(
|
|
533
|
+
this.erc20Interface.encodeFunctionData('transfer', [
|
|
534
|
+
curExchangeParam.transferSrcTokenBeforeSwap,
|
|
535
|
+
swapExchange.srcAmount,
|
|
536
|
+
]),
|
|
537
|
+
isETHAddress(swap.srcToken)
|
|
538
|
+
? this.getWETHAddress(curExchangeParam)
|
|
539
|
+
: swap.srcToken.toLowerCase(),
|
|
540
|
+
);
|
|
541
|
+
|
|
542
|
+
swapExchangeCallData = hexConcat([
|
|
543
|
+
transferCallData,
|
|
544
|
+
swapExchangeCallData,
|
|
545
|
+
]);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
if (
|
|
549
|
+
!isETHAddress(swap!.srcToken) &&
|
|
550
|
+
!curExchangeParam.transferSrcTokenBeforeSwap &&
|
|
551
|
+
curExchangeParam.approveData
|
|
552
|
+
) {
|
|
553
|
+
const approveCallData = this.buildApproveCallData(
|
|
554
|
+
curExchangeParam.approveData.target,
|
|
555
|
+
curExchangeParam.approveData.token,
|
|
556
|
+
flags.approves[exchangeParamIndex],
|
|
557
|
+
);
|
|
558
|
+
|
|
559
|
+
swapExchangeCallData = hexConcat([approveCallData, swapExchangeCallData]);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
if (curExchangeParam.needWrapNative) {
|
|
563
|
+
if (isETHAddress(swap!.srcToken)) {
|
|
564
|
+
let approveWethCalldata = '0x';
|
|
565
|
+
if (
|
|
566
|
+
curExchangeParam.approveData &&
|
|
567
|
+
!curExchangeParam.transferSrcTokenBeforeSwap
|
|
568
|
+
) {
|
|
569
|
+
approveWethCalldata = this.buildApproveCallData(
|
|
570
|
+
curExchangeParam.approveData.target,
|
|
571
|
+
curExchangeParam.approveData.token,
|
|
572
|
+
flags.approves[exchangeParamIndex],
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
const isNotFirstSwap = swapIndex !== 0;
|
|
577
|
+
let skipWrap = false;
|
|
578
|
+
if (isNotFirstSwap) {
|
|
579
|
+
const prevSwap =
|
|
580
|
+
priceRoute.bestRoute[routeIndex].swaps[swapIndex - 1];
|
|
581
|
+
const anyDexOnSwapDoesntNeedWrapNative =
|
|
582
|
+
this.anyDexOnSwapDoesntNeedWrapNative(
|
|
583
|
+
priceRoute,
|
|
584
|
+
prevSwap,
|
|
585
|
+
exchangeParams,
|
|
586
|
+
);
|
|
587
|
+
skipWrap = !anyDexOnSwapDoesntNeedWrapNative;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
let depositCallData = '0x';
|
|
591
|
+
if (
|
|
592
|
+
maybeWethCallData &&
|
|
593
|
+
maybeWethCallData.deposit &&
|
|
594
|
+
!this.doesRouteNeedsRootWrapEth(priceRoute, exchangeParams) &&
|
|
595
|
+
allowToAddWrap &&
|
|
596
|
+
!addedWrapToSwapExchangeMap[
|
|
597
|
+
`${routeIndex}_${swapIndex}_${swapExchangeIndex}`
|
|
598
|
+
] &&
|
|
599
|
+
!skipWrap
|
|
600
|
+
) {
|
|
601
|
+
depositCallData = this.buildWrapEthCallData(
|
|
602
|
+
this.getWETHAddress(curExchangeParam),
|
|
603
|
+
maybeWethCallData.deposit.calldata,
|
|
604
|
+
Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP, // 9
|
|
605
|
+
);
|
|
606
|
+
addedWrapToSwapExchangeMap[
|
|
607
|
+
`${routeIndex}_${swapIndex}_${swapExchangeIndex}`
|
|
608
|
+
] = true;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
swapExchangeCallData = hexConcat([
|
|
612
|
+
approveWethCalldata,
|
|
613
|
+
depositCallData,
|
|
614
|
+
swapExchangeCallData,
|
|
615
|
+
]);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
if (
|
|
619
|
+
maybeWethCallData &&
|
|
620
|
+
maybeWethCallData.withdraw &&
|
|
621
|
+
((!applyVerticalBranching && isETHAddress(swap.destToken)) ||
|
|
622
|
+
(applyVerticalBranching &&
|
|
623
|
+
isETHAddress(swap.destToken) &&
|
|
624
|
+
this.anyDexOnSwapDoesntNeedWrapNative(
|
|
625
|
+
priceRoute,
|
|
626
|
+
swap,
|
|
627
|
+
exchangeParams,
|
|
628
|
+
)))
|
|
629
|
+
) {
|
|
630
|
+
let withdrawCallData = '0x';
|
|
631
|
+
|
|
632
|
+
const customWethAddress = curExchangeParam.wethAddress;
|
|
633
|
+
const isLastSimpleWithUnwrap =
|
|
634
|
+
isSimpleSwap &&
|
|
635
|
+
// check if current exchange is the last with needWrapNative
|
|
636
|
+
exchangeParams.reduceRight(
|
|
637
|
+
(acc, exchangeParam, index) =>
|
|
638
|
+
exchangeParam.needWrapNative === true && acc === -1 ? index : acc,
|
|
639
|
+
-1,
|
|
640
|
+
) === exchangeParamIndex;
|
|
641
|
+
|
|
642
|
+
if (
|
|
643
|
+
customWethAddress ||
|
|
644
|
+
isLastSimpleWithUnwrap // unwrap after last dex call with unwrap for simple swap case
|
|
645
|
+
) {
|
|
646
|
+
withdrawCallData = this.buildUnwrapEthCallData(
|
|
647
|
+
this.getWETHAddress(curExchangeParam),
|
|
648
|
+
maybeWethCallData.withdraw.calldata,
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
swapExchangeCallData = hexConcat([
|
|
653
|
+
swapExchangeCallData,
|
|
654
|
+
withdrawCallData,
|
|
655
|
+
]);
|
|
656
|
+
|
|
657
|
+
if (isLastSimpleWithUnwrap || customWethAddress) {
|
|
658
|
+
const finalSpecialFlagCalldata = this.buildFinalSpecialFlagCalldata();
|
|
659
|
+
swapExchangeCallData = hexConcat([
|
|
660
|
+
swapExchangeCallData,
|
|
661
|
+
finalSpecialFlagCalldata,
|
|
662
|
+
]);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
let addedUnwrapForDexWithNoNeedWrapNative = false;
|
|
668
|
+
if (
|
|
669
|
+
isETHAddress(swap.srcToken) &&
|
|
670
|
+
maybeWethCallData &&
|
|
671
|
+
maybeWethCallData.withdraw &&
|
|
672
|
+
!curExchangeParam.needWrapNative
|
|
673
|
+
) {
|
|
674
|
+
const prevSwap = priceRoute.bestRoute[routeIndex].swaps[swapIndex - 1];
|
|
675
|
+
let eachDexOnPrevSwapReturnsWeth: boolean = false;
|
|
676
|
+
|
|
677
|
+
if (prevSwap && !prevBranchWasWrapped) {
|
|
678
|
+
eachDexOnPrevSwapReturnsWeth = this.eachDexOnSwapNeedsWrapNative(
|
|
679
|
+
priceRoute,
|
|
680
|
+
prevSwap,
|
|
681
|
+
exchangeParams,
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
if (prevBranchWasWrapped || eachDexOnPrevSwapReturnsWeth) {
|
|
686
|
+
const withdrawCallData = this.buildUnwrapEthCallData(
|
|
687
|
+
this.getWETHAddress(curExchangeParam),
|
|
688
|
+
maybeWethCallData.withdraw.calldata,
|
|
689
|
+
);
|
|
690
|
+
|
|
691
|
+
swapExchangeCallData = hexConcat([
|
|
692
|
+
withdrawCallData,
|
|
693
|
+
swapExchangeCallData,
|
|
694
|
+
]);
|
|
695
|
+
addedUnwrapForDexWithNoNeedWrapNative = true;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
if (
|
|
700
|
+
isLastSwap &&
|
|
701
|
+
!exchangeParams[exchangeParamIndex].dexFuncHasRecipient &&
|
|
702
|
+
!isETHAddress(swap.destToken) &&
|
|
703
|
+
priceRoute.destToken === swap.destToken
|
|
704
|
+
) {
|
|
705
|
+
const transferCallData = this.buildTransferCallData(
|
|
706
|
+
this.erc20Interface.encodeFunctionData('transfer', [
|
|
707
|
+
this.dexHelper.config.data.augustusV6Address,
|
|
708
|
+
swapExchange.destAmount,
|
|
709
|
+
]),
|
|
710
|
+
swap.destToken,
|
|
711
|
+
);
|
|
712
|
+
|
|
713
|
+
swapExchangeCallData = hexConcat([
|
|
714
|
+
swapExchangeCallData,
|
|
715
|
+
transferCallData,
|
|
716
|
+
]);
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
if (
|
|
720
|
+
!exchangeParams[exchangeParamIndex].dexFuncHasRecipient &&
|
|
721
|
+
isETHAddress(swap.destToken) &&
|
|
722
|
+
isLast
|
|
723
|
+
) {
|
|
724
|
+
const finalSpecialFlagCalldata = this.buildFinalSpecialFlagCalldata();
|
|
725
|
+
swapExchangeCallData = hexConcat([
|
|
726
|
+
swapExchangeCallData,
|
|
727
|
+
finalSpecialFlagCalldata,
|
|
728
|
+
]);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
if (addMultiSwapMetadata) {
|
|
732
|
+
return this.addMultiSwapMetadata(
|
|
733
|
+
priceRoute,
|
|
734
|
+
exchangeParams,
|
|
735
|
+
swapExchangeCallData,
|
|
736
|
+
swapExchange.percent,
|
|
737
|
+
swap,
|
|
738
|
+
exchangeParamIndex,
|
|
739
|
+
addedWrapToSwapExchangeMap[
|
|
740
|
+
`${routeIndex}_${swapIndex}_${swapExchangeIndex}`
|
|
741
|
+
],
|
|
742
|
+
addedUnwrapForDexWithNoNeedWrapNative,
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
return swapExchangeCallData;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
private appendWrapEthCallData(
|
|
750
|
+
calldata: string,
|
|
751
|
+
maybeWethCallData?: DepositWithdrawReturn,
|
|
752
|
+
checkWethBalanceAfter = false,
|
|
753
|
+
) {
|
|
754
|
+
if (maybeWethCallData?.deposit) {
|
|
755
|
+
const callData = checkWethBalanceAfter
|
|
756
|
+
? this.addTokenAddressToCallData(
|
|
757
|
+
maybeWethCallData.deposit.calldata,
|
|
758
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase(),
|
|
759
|
+
)
|
|
760
|
+
: maybeWethCallData.deposit.calldata;
|
|
761
|
+
|
|
762
|
+
const depositCallData = this.buildWrapEthCallData(
|
|
763
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase(),
|
|
764
|
+
callData,
|
|
765
|
+
checkWethBalanceAfter
|
|
766
|
+
? Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP // 5
|
|
767
|
+
: Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP, // 9
|
|
768
|
+
checkWethBalanceAfter ? 4 : 0,
|
|
769
|
+
);
|
|
770
|
+
|
|
771
|
+
return hexConcat([calldata, depositCallData]);
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
return calldata;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
private eachDexOnSwapNeedsWrapNative(
|
|
778
|
+
priceRoute: OptimalRate,
|
|
779
|
+
swap: OptimalSwap,
|
|
780
|
+
exchangeParams: DexExchangeBuildParam[],
|
|
781
|
+
): boolean {
|
|
782
|
+
return swap.swapExchanges.every(curSe => {
|
|
783
|
+
let index = 0;
|
|
784
|
+
let swapExchangeIndex = 0;
|
|
785
|
+
priceRoute.bestRoute.map(route => {
|
|
786
|
+
route.swaps.map(curSwap =>
|
|
787
|
+
curSwap.swapExchanges.map(async se => {
|
|
788
|
+
if (Object.is(se, curSe)) {
|
|
789
|
+
index = swapExchangeIndex;
|
|
790
|
+
}
|
|
791
|
+
swapExchangeIndex++;
|
|
792
|
+
}),
|
|
793
|
+
);
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
const curExchangeParam = exchangeParams[index];
|
|
797
|
+
|
|
798
|
+
return curExchangeParam.needWrapNative && !curExchangeParam.wethAddress;
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
private anyDexOnSwapNeedsWrapNative(
|
|
803
|
+
priceRoute: OptimalRate,
|
|
804
|
+
swap: OptimalSwap,
|
|
805
|
+
exchangeParams: DexExchangeBuildParam[],
|
|
806
|
+
): boolean {
|
|
807
|
+
const res = swap.swapExchanges.map(curSe => {
|
|
808
|
+
let index = 0;
|
|
809
|
+
let swapExchangeIndex = 0;
|
|
810
|
+
priceRoute.bestRoute.map(route => {
|
|
811
|
+
route.swaps.map(curSwap => {
|
|
812
|
+
return curSwap.swapExchanges.map(async se => {
|
|
813
|
+
if (Object.is(se, curSe)) {
|
|
814
|
+
index = swapExchangeIndex;
|
|
815
|
+
}
|
|
816
|
+
swapExchangeIndex++;
|
|
817
|
+
});
|
|
818
|
+
});
|
|
819
|
+
});
|
|
820
|
+
|
|
821
|
+
const curExchangeParam = exchangeParams[index];
|
|
822
|
+
|
|
823
|
+
return curExchangeParam.needWrapNative && !curExchangeParam.wethAddress;
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
return res.includes(true);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
private getSwapExchangesWhichNeedWrapNative(
|
|
830
|
+
priceRoute: OptimalRate,
|
|
831
|
+
swap: OptimalSwap,
|
|
832
|
+
exchangeParams: DexExchangeBuildParam[],
|
|
833
|
+
) {
|
|
834
|
+
return swap.swapExchanges.filter(curSe => {
|
|
835
|
+
let index = 0;
|
|
836
|
+
let swapExchangeIndex = 0;
|
|
837
|
+
priceRoute.bestRoute.map(route => {
|
|
838
|
+
route.swaps.map(curSwap => {
|
|
839
|
+
return curSwap.swapExchanges.map(async se => {
|
|
840
|
+
if (Object.is(se, curSe)) {
|
|
841
|
+
index = swapExchangeIndex;
|
|
842
|
+
}
|
|
843
|
+
swapExchangeIndex++;
|
|
844
|
+
});
|
|
845
|
+
});
|
|
846
|
+
});
|
|
847
|
+
|
|
848
|
+
const curExchangeParam = exchangeParams[index];
|
|
849
|
+
|
|
850
|
+
return curExchangeParam.needWrapNative && !curExchangeParam.wethAddress;
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
private getSwapExchangesWhichDontNeedWrapNative(
|
|
855
|
+
priceRoute: OptimalRate,
|
|
856
|
+
swap: OptimalSwap,
|
|
857
|
+
exchangeParams: DexExchangeBuildParam[],
|
|
858
|
+
) {
|
|
859
|
+
return swap.swapExchanges.filter(curSe => {
|
|
860
|
+
let index = 0;
|
|
861
|
+
let swapExchangeIndex = 0;
|
|
862
|
+
priceRoute.bestRoute.map(route => {
|
|
863
|
+
route.swaps.map(curSwap => {
|
|
864
|
+
return curSwap.swapExchanges.map(async se => {
|
|
865
|
+
if (Object.is(se, curSe)) {
|
|
866
|
+
index = swapExchangeIndex;
|
|
867
|
+
}
|
|
868
|
+
swapExchangeIndex++;
|
|
869
|
+
});
|
|
870
|
+
});
|
|
871
|
+
});
|
|
872
|
+
|
|
873
|
+
const curExchangeParam = exchangeParams[index];
|
|
874
|
+
|
|
875
|
+
return !curExchangeParam.needWrapNative || curExchangeParam.wethAddress;
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
private anyDexOnSwapDoesntNeedWrapNative(
|
|
880
|
+
priceRoute: OptimalRate,
|
|
881
|
+
swap: OptimalSwap,
|
|
882
|
+
exchangeParams: DexExchangeBuildParam[],
|
|
883
|
+
): boolean {
|
|
884
|
+
return swap.swapExchanges
|
|
885
|
+
.map(curSe => {
|
|
886
|
+
let index = 0;
|
|
887
|
+
let swapExchangeIndex = 0;
|
|
888
|
+
priceRoute.bestRoute.map(route => {
|
|
889
|
+
route.swaps.map(curSwap =>
|
|
890
|
+
curSwap.swapExchanges.map(async se => {
|
|
891
|
+
if (Object.is(se, curSe)) {
|
|
892
|
+
index = swapExchangeIndex;
|
|
893
|
+
}
|
|
894
|
+
swapExchangeIndex++;
|
|
895
|
+
}),
|
|
896
|
+
);
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
const curExchangeParam = exchangeParams[index];
|
|
900
|
+
|
|
901
|
+
return !curExchangeParam.needWrapNative;
|
|
902
|
+
})
|
|
903
|
+
.includes(true);
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
private doesSwapNeedToApplyVerticalBranching(
|
|
907
|
+
priceRoute: OptimalRate,
|
|
908
|
+
routeIndex: number,
|
|
909
|
+
swap: OptimalSwap,
|
|
910
|
+
): boolean {
|
|
911
|
+
const isMegaSwap = priceRoute.bestRoute.length > 1;
|
|
912
|
+
const isMultiSwap =
|
|
913
|
+
!isMegaSwap && priceRoute.bestRoute[routeIndex].swaps.length > 1;
|
|
914
|
+
|
|
915
|
+
return (isMultiSwap || isMegaSwap) && swap.swapExchanges.length > 1;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
private buildVerticalBranchingFlag(
|
|
919
|
+
priceRoute: OptimalRate,
|
|
920
|
+
swap: OptimalSwap,
|
|
921
|
+
exchangeParams: DexExchangeBuildParam[],
|
|
922
|
+
routeIndex: number,
|
|
923
|
+
swapIndex: number,
|
|
924
|
+
): Flag {
|
|
925
|
+
let flag = Flag.INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP; // 11
|
|
926
|
+
|
|
927
|
+
const isLastSwap =
|
|
928
|
+
swapIndex === priceRoute.bestRoute[routeIndex].swaps.length - 1;
|
|
929
|
+
|
|
930
|
+
if (isLastSwap) {
|
|
931
|
+
const isEthDest = isETHAddress(priceRoute.destToken);
|
|
932
|
+
const lastSwap =
|
|
933
|
+
priceRoute.bestRoute[routeIndex].swaps[
|
|
934
|
+
priceRoute.bestRoute[routeIndex].swaps.length - 1
|
|
935
|
+
];
|
|
936
|
+
const lastSwapExchanges = lastSwap.swapExchanges;
|
|
937
|
+
const anyDexLastSwapNeedUnwrap = lastSwapExchanges
|
|
938
|
+
.map(curSe => {
|
|
939
|
+
let index = 0;
|
|
940
|
+
let swapExchangeIndex = 0;
|
|
941
|
+
priceRoute.bestRoute[routeIndex].swaps.map(curSwap =>
|
|
942
|
+
curSwap.swapExchanges.map(async se => {
|
|
943
|
+
if (Object.is(se, curSe)) {
|
|
944
|
+
index = swapExchangeIndex;
|
|
945
|
+
}
|
|
946
|
+
swapExchangeIndex++;
|
|
947
|
+
}),
|
|
948
|
+
);
|
|
949
|
+
|
|
950
|
+
const curExchangeParam = exchangeParams[index];
|
|
951
|
+
|
|
952
|
+
return (
|
|
953
|
+
curExchangeParam.needWrapNative && !curExchangeParam.wethAddress
|
|
954
|
+
);
|
|
955
|
+
})
|
|
956
|
+
.includes(true);
|
|
957
|
+
|
|
958
|
+
const noNeedUnwrap = isEthDest && !anyDexLastSwapNeedUnwrap;
|
|
959
|
+
|
|
960
|
+
if (noNeedUnwrap || !isEthDest) {
|
|
961
|
+
flag = Flag.INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP; // 3
|
|
962
|
+
}
|
|
963
|
+
} else {
|
|
964
|
+
const isEthDest = isETHAddress(swap!.destToken);
|
|
965
|
+
|
|
966
|
+
if (isEthDest) {
|
|
967
|
+
if (
|
|
968
|
+
this.anyDexOnSwapDoesntNeedWrapNative(
|
|
969
|
+
priceRoute,
|
|
970
|
+
swap,
|
|
971
|
+
exchangeParams,
|
|
972
|
+
)
|
|
973
|
+
) {
|
|
974
|
+
flag = Flag.INSERT_FROM_AMOUNT_CHECK_ETH_BALANCE_AFTER_SWAP; // 7
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
return flag;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
protected buildSingleSwapCallData(
|
|
983
|
+
priceRoute: OptimalRate,
|
|
984
|
+
exchangeParams: DexExchangeBuildParam[],
|
|
985
|
+
routeIndex: number,
|
|
986
|
+
swapIndex: number,
|
|
987
|
+
flags: { approves: Flag[]; dexes: Flag[]; wrap: Flag },
|
|
988
|
+
sender: string,
|
|
989
|
+
appendedWrapToSwapMap: { [key: number]: boolean },
|
|
990
|
+
addedWrapToSwapExchangeMap: { [key: string]: boolean },
|
|
991
|
+
maybeWethCallData?: DepositWithdrawReturn,
|
|
992
|
+
swap?: OptimalSwap,
|
|
993
|
+
): string {
|
|
994
|
+
const isLastSwap =
|
|
995
|
+
swapIndex === priceRoute.bestRoute[routeIndex].swaps.length - 1;
|
|
996
|
+
const isMegaSwap = priceRoute.bestRoute.length > 1;
|
|
997
|
+
const isMultiSwap =
|
|
998
|
+
!isMegaSwap && priceRoute.bestRoute[routeIndex].swaps.length > 1;
|
|
999
|
+
|
|
1000
|
+
const { swapExchanges } = swap!;
|
|
1001
|
+
|
|
1002
|
+
const applyVerticalBranching = this.doesSwapNeedToApplyVerticalBranching(
|
|
1003
|
+
priceRoute,
|
|
1004
|
+
routeIndex,
|
|
1005
|
+
swap!,
|
|
1006
|
+
);
|
|
1007
|
+
|
|
1008
|
+
const anyDexOnSwapDoesntNeedWrapNative =
|
|
1009
|
+
this.anyDexOnSwapDoesntNeedWrapNative(priceRoute, swap!, exchangeParams);
|
|
1010
|
+
|
|
1011
|
+
const needToAppendWrapCallData =
|
|
1012
|
+
isETHAddress(swap!.destToken) &&
|
|
1013
|
+
anyDexOnSwapDoesntNeedWrapNative &&
|
|
1014
|
+
!isLastSwap &&
|
|
1015
|
+
maybeWethCallData?.deposit;
|
|
1016
|
+
|
|
1017
|
+
let swapCallData = swapExchanges.reduce(
|
|
1018
|
+
(acc, swapExchange, swapExchangeIndex) => {
|
|
1019
|
+
return hexConcat([
|
|
1020
|
+
acc,
|
|
1021
|
+
this.buildSingleSwapExchangeCallData(
|
|
1022
|
+
priceRoute,
|
|
1023
|
+
routeIndex,
|
|
1024
|
+
swapIndex,
|
|
1025
|
+
swapExchangeIndex,
|
|
1026
|
+
exchangeParams,
|
|
1027
|
+
flags,
|
|
1028
|
+
addedWrapToSwapExchangeMap,
|
|
1029
|
+
!appendedWrapToSwapMap[swapIndex - 1],
|
|
1030
|
+
appendedWrapToSwapMap[swapIndex - 1],
|
|
1031
|
+
maybeWethCallData,
|
|
1032
|
+
swap!.swapExchanges.length > 1,
|
|
1033
|
+
applyVerticalBranching,
|
|
1034
|
+
),
|
|
1035
|
+
]);
|
|
1036
|
+
},
|
|
1037
|
+
'0x',
|
|
1038
|
+
);
|
|
1039
|
+
|
|
1040
|
+
if (needToAppendWrapCallData) {
|
|
1041
|
+
appendedWrapToSwapMap[swapIndex] = true;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
if (!isMultiSwap && !isMegaSwap) {
|
|
1045
|
+
return needToAppendWrapCallData
|
|
1046
|
+
? this.appendWrapEthCallData(swapCallData, maybeWethCallData)
|
|
1047
|
+
: swapCallData;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
if (applyVerticalBranching) {
|
|
1051
|
+
const vertBranchingCallData = this.buildVerticalBranchingCallData(
|
|
1052
|
+
priceRoute,
|
|
1053
|
+
routeIndex,
|
|
1054
|
+
exchangeParams,
|
|
1055
|
+
swap!,
|
|
1056
|
+
swapCallData,
|
|
1057
|
+
this.buildVerticalBranchingFlag(
|
|
1058
|
+
priceRoute,
|
|
1059
|
+
swap!,
|
|
1060
|
+
exchangeParams,
|
|
1061
|
+
routeIndex,
|
|
1062
|
+
swapIndex,
|
|
1063
|
+
),
|
|
1064
|
+
);
|
|
1065
|
+
|
|
1066
|
+
return needToAppendWrapCallData
|
|
1067
|
+
? this.appendWrapEthCallData(
|
|
1068
|
+
vertBranchingCallData,
|
|
1069
|
+
maybeWethCallData,
|
|
1070
|
+
true,
|
|
1071
|
+
)
|
|
1072
|
+
: vertBranchingCallData;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
return needToAppendWrapCallData
|
|
1076
|
+
? this.appendWrapEthCallData(swapCallData, maybeWethCallData)
|
|
1077
|
+
: swapCallData;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
protected buildSingleRouteCallData(
|
|
1081
|
+
priceRoute: OptimalRate,
|
|
1082
|
+
exchangeParams: DexExchangeBuildParam[],
|
|
1083
|
+
route: OptimalRoute,
|
|
1084
|
+
routeIndex: number,
|
|
1085
|
+
flags: { approves: Flag[]; dexes: Flag[]; wrap: Flag },
|
|
1086
|
+
sender: string,
|
|
1087
|
+
maybeWethCallData?: DepositWithdrawReturn,
|
|
1088
|
+
): string {
|
|
1089
|
+
const isMegaSwap = priceRoute.bestRoute.length > 1;
|
|
1090
|
+
|
|
1091
|
+
const { swaps } = route;
|
|
1092
|
+
|
|
1093
|
+
const appendedWrapToSwapExchangeMap = {};
|
|
1094
|
+
const addedWrapToSwapMap = {};
|
|
1095
|
+
const callData = swaps.reduce<string>(
|
|
1096
|
+
(swapAcc, swap, swapIndex) =>
|
|
1097
|
+
hexConcat([
|
|
1098
|
+
swapAcc,
|
|
1099
|
+
this.buildSingleSwapCallData(
|
|
1100
|
+
priceRoute,
|
|
1101
|
+
exchangeParams,
|
|
1102
|
+
routeIndex,
|
|
1103
|
+
swapIndex,
|
|
1104
|
+
flags,
|
|
1105
|
+
sender,
|
|
1106
|
+
appendedWrapToSwapExchangeMap,
|
|
1107
|
+
addedWrapToSwapMap,
|
|
1108
|
+
maybeWethCallData,
|
|
1109
|
+
swap,
|
|
1110
|
+
),
|
|
1111
|
+
]),
|
|
1112
|
+
'0x',
|
|
1113
|
+
);
|
|
1114
|
+
|
|
1115
|
+
const routeDoesntNeedToAddMultiSwapMetadata =
|
|
1116
|
+
route.swaps.length === 1 &&
|
|
1117
|
+
route.swaps[0].swapExchanges.length !== 1 &&
|
|
1118
|
+
!this.doesSwapNeedToApplyVerticalBranching(
|
|
1119
|
+
priceRoute,
|
|
1120
|
+
routeIndex,
|
|
1121
|
+
route.swaps[0],
|
|
1122
|
+
);
|
|
1123
|
+
|
|
1124
|
+
if (isMegaSwap && !routeDoesntNeedToAddMultiSwapMetadata) {
|
|
1125
|
+
return this.addMultiSwapMetadata(
|
|
1126
|
+
priceRoute,
|
|
1127
|
+
exchangeParams,
|
|
1128
|
+
callData,
|
|
1129
|
+
route.percent,
|
|
1130
|
+
route.swaps[0],
|
|
1131
|
+
NOT_EXISTING_EXCHANGE_PARAM_INDEX,
|
|
1132
|
+
Object.values(addedWrapToSwapMap).includes(true),
|
|
1133
|
+
);
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
return callData;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
private doesRouteNeedsRootWrapEth(
|
|
1140
|
+
priceRoute: OptimalRate,
|
|
1141
|
+
exchangeParams: DexExchangeBuildParam[],
|
|
1142
|
+
): boolean {
|
|
1143
|
+
if (!isETHAddress(priceRoute.srcToken)) {
|
|
1144
|
+
return false;
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
const res = priceRoute.bestRoute.every((route, routeIndex) => {
|
|
1148
|
+
const firstSwap = route.swaps[0];
|
|
1149
|
+
const eachDexOnSwapNeedsWrapNative = this.eachDexOnSwapNeedsWrapNative(
|
|
1150
|
+
priceRoute,
|
|
1151
|
+
firstSwap,
|
|
1152
|
+
exchangeParams,
|
|
1153
|
+
);
|
|
1154
|
+
|
|
1155
|
+
return eachDexOnSwapNeedsWrapNative;
|
|
1156
|
+
});
|
|
1157
|
+
|
|
1158
|
+
return res;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
private doesRouteNeedsRootUnwrapEth(
|
|
1162
|
+
priceRoute: OptimalRate,
|
|
1163
|
+
exchangeParams: DexExchangeParam[],
|
|
1164
|
+
): boolean {
|
|
1165
|
+
if (!isETHAddress(priceRoute.destToken)) {
|
|
1166
|
+
return false;
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
const res = priceRoute.bestRoute.every((route, routeIndex) => {
|
|
1170
|
+
const lastSwap = route.swaps[route.swaps.length - 1];
|
|
1171
|
+
const eachDexOnSwapNeedsWrapNative = this.anyDexOnSwapNeedsWrapNative(
|
|
1172
|
+
priceRoute,
|
|
1173
|
+
lastSwap,
|
|
1174
|
+
exchangeParams,
|
|
1175
|
+
);
|
|
1176
|
+
|
|
1177
|
+
return eachDexOnSwapNeedsWrapNative;
|
|
1178
|
+
});
|
|
1179
|
+
|
|
1180
|
+
return res;
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
public getAddress(): string {
|
|
1184
|
+
return this.dexHelper.config.data.executorsAddresses![Executors.TWO];
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
public buildByteCode(
|
|
1188
|
+
priceRoute: OptimalRate,
|
|
1189
|
+
exchangeParams: DexExchangeBuildParam[],
|
|
1190
|
+
sender: string,
|
|
1191
|
+
maybeWethCallData?: DepositWithdrawReturn,
|
|
1192
|
+
): string {
|
|
1193
|
+
const isMegaSwap = priceRoute.bestRoute.length > 1;
|
|
1194
|
+
const isMultiSwap = !isMegaSwap && priceRoute.bestRoute[0].swaps.length > 1;
|
|
1195
|
+
|
|
1196
|
+
const needWrapEth =
|
|
1197
|
+
maybeWethCallData?.deposit && isETHAddress(priceRoute.srcToken);
|
|
1198
|
+
const needUnwrapEth =
|
|
1199
|
+
maybeWethCallData?.withdraw && isETHAddress(priceRoute.destToken);
|
|
1200
|
+
const needSendNativeEth = isETHAddress(priceRoute.destToken);
|
|
1201
|
+
const routeNeedsRootWrapEth = this.doesRouteNeedsRootWrapEth(
|
|
1202
|
+
priceRoute,
|
|
1203
|
+
exchangeParams,
|
|
1204
|
+
);
|
|
1205
|
+
const routeNeedsRootUnwrapEth = this.doesRouteNeedsRootUnwrapEth(
|
|
1206
|
+
priceRoute,
|
|
1207
|
+
exchangeParams,
|
|
1208
|
+
);
|
|
1209
|
+
|
|
1210
|
+
const flags = this.buildFlags(
|
|
1211
|
+
priceRoute,
|
|
1212
|
+
exchangeParams,
|
|
1213
|
+
maybeWethCallData,
|
|
1214
|
+
);
|
|
1215
|
+
|
|
1216
|
+
let swapsCalldata = priceRoute.bestRoute.reduce<string>(
|
|
1217
|
+
(routeAcc, route, routeIndex) =>
|
|
1218
|
+
hexConcat([
|
|
1219
|
+
routeAcc,
|
|
1220
|
+
this.buildSingleRouteCallData(
|
|
1221
|
+
priceRoute,
|
|
1222
|
+
exchangeParams,
|
|
1223
|
+
route,
|
|
1224
|
+
routeIndex,
|
|
1225
|
+
flags,
|
|
1226
|
+
sender,
|
|
1227
|
+
maybeWethCallData,
|
|
1228
|
+
),
|
|
1229
|
+
]),
|
|
1230
|
+
'0x',
|
|
1231
|
+
);
|
|
1232
|
+
|
|
1233
|
+
if (isMegaSwap && (needWrapEth || needUnwrapEth)) {
|
|
1234
|
+
const lastPriceRoute =
|
|
1235
|
+
priceRoute.bestRoute[priceRoute.bestRoute.length - 1];
|
|
1236
|
+
swapsCalldata = this.buildVerticalBranchingCallData(
|
|
1237
|
+
priceRoute,
|
|
1238
|
+
priceRoute.bestRoute.length - 1,
|
|
1239
|
+
exchangeParams,
|
|
1240
|
+
lastPriceRoute.swaps[lastPriceRoute.swaps.length - 1],
|
|
1241
|
+
swapsCalldata,
|
|
1242
|
+
needWrapEth
|
|
1243
|
+
? Flag.DONT_INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP // 0
|
|
1244
|
+
: Flag.DONT_INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP, // 8
|
|
1245
|
+
);
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
// ETH wrap
|
|
1249
|
+
if (needWrapEth && routeNeedsRootWrapEth) {
|
|
1250
|
+
let depositCallData = this.buildWrapEthCallData(
|
|
1251
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress,
|
|
1252
|
+
maybeWethCallData.deposit!.calldata,
|
|
1253
|
+
Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP, // 9
|
|
1254
|
+
);
|
|
1255
|
+
|
|
1256
|
+
if (!(isMegaSwap || isMultiSwap)) {
|
|
1257
|
+
const swap = priceRoute.bestRoute[0].swaps[0];
|
|
1258
|
+
const percent = exchangeParams.every(ep => ep.needWrapNative)
|
|
1259
|
+
? 100
|
|
1260
|
+
: swap.swapExchanges
|
|
1261
|
+
.filter((se, index) => {
|
|
1262
|
+
return exchangeParams[index].needWrapNative;
|
|
1263
|
+
})
|
|
1264
|
+
.reduce<number>((acc, se) => {
|
|
1265
|
+
acc += se.percent;
|
|
1266
|
+
return acc;
|
|
1267
|
+
}, 0);
|
|
1268
|
+
|
|
1269
|
+
depositCallData = solidityPack(
|
|
1270
|
+
['bytes16', 'bytes16', 'bytes'],
|
|
1271
|
+
[
|
|
1272
|
+
hexZeroPad(hexlify(hexDataLength(depositCallData)), 16),
|
|
1273
|
+
hexZeroPad(hexlify(100 * percent), 16),
|
|
1274
|
+
depositCallData,
|
|
1275
|
+
],
|
|
1276
|
+
);
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
swapsCalldata = hexConcat([depositCallData, swapsCalldata]);
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
// ETH unwrap, only for multiswaps and mega swaps
|
|
1283
|
+
if (
|
|
1284
|
+
needUnwrapEth &&
|
|
1285
|
+
routeNeedsRootUnwrapEth &&
|
|
1286
|
+
(isMultiSwap || isMegaSwap)
|
|
1287
|
+
) {
|
|
1288
|
+
const withdrawCallData = this.buildUnwrapEthCallData(
|
|
1289
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress,
|
|
1290
|
+
maybeWethCallData.withdraw!.calldata,
|
|
1291
|
+
);
|
|
1292
|
+
swapsCalldata = hexConcat([swapsCalldata, withdrawCallData]);
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
// Special flag (send native) calldata, only for multiswaps and mega swaps
|
|
1296
|
+
if (
|
|
1297
|
+
needSendNativeEth &&
|
|
1298
|
+
routeNeedsRootUnwrapEth &&
|
|
1299
|
+
(isMultiSwap || isMegaSwap)
|
|
1300
|
+
) {
|
|
1301
|
+
const finalSpecialFlagCalldata = this.buildFinalSpecialFlagCalldata();
|
|
1302
|
+
swapsCalldata = hexConcat([swapsCalldata, finalSpecialFlagCalldata]);
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
if (((needWrapEth || needUnwrapEth) && isMegaSwap) || isMultiSwap) {
|
|
1306
|
+
swapsCalldata = this.addMultiSwapMetadata(
|
|
1307
|
+
priceRoute,
|
|
1308
|
+
exchangeParams,
|
|
1309
|
+
swapsCalldata,
|
|
1310
|
+
SWAP_EXCHANGE_100_PERCENTAGE,
|
|
1311
|
+
priceRoute.bestRoute[0].swaps[0],
|
|
1312
|
+
NOT_EXISTING_EXCHANGE_PARAM_INDEX,
|
|
1313
|
+
false,
|
|
1314
|
+
);
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
return solidityPack(
|
|
1318
|
+
['bytes32', 'bytes', 'bytes'],
|
|
1319
|
+
[
|
|
1320
|
+
hexZeroPad(hexlify(32), 32), // calldata offset
|
|
1321
|
+
hexZeroPad(
|
|
1322
|
+
hexlify(hexDataLength(swapsCalldata) + BYTES_64_LENGTH), // calldata length (64 bytes = bytes12(0) + msg.sender)
|
|
1323
|
+
32,
|
|
1324
|
+
),
|
|
1325
|
+
swapsCalldata, // calldata
|
|
1326
|
+
],
|
|
1327
|
+
);
|
|
1328
|
+
}
|
|
1329
|
+
}
|