@paraswap/dex-lib 3.4.0 → 3.4.1
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/.vscode/launch.json +53 -0
- package/.vscode/settings.json +2 -0
- package/.vscode/tasks.json +15 -0
- package/README.md +3 -3
- package/abis.txt +92 -0
- package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +52 -0
- package/build/abi/{integral/relayer.json → wombat/pool.json} +587 -446
- package/build/config.js +0 -35
- package/build/config.js.map +1 -1
- package/build/constants.d.ts +0 -1
- package/build/constants.js +0 -1
- package/build/constants.js.map +1 -1
- package/build/dex/augustus-rfq.js +0 -1
- package/build/dex/augustus-rfq.js.map +1 -1
- package/build/dex/curve-v1/config.js +1 -57
- package/build/dex/curve-v1/config.js.map +1 -1
- package/build/dex/curve-v1-factory/config.js +1 -1
- package/build/dex/curve-v1-factory/config.js.map +1 -1
- package/build/dex/etherfi.js +1 -1
- package/build/dex/gmx/gmx.js.map +1 -1
- package/build/dex/index.js +0 -14
- package/build/dex/index.js.map +1 -1
- package/build/dex/nerve/config.js +0 -399
- package/build/dex/nerve/config.js.map +1 -1
- package/build/dex/paraswap-limit-orders/config.js +0 -7
- package/build/dex/paraswap-limit-orders/config.js.map +1 -1
- package/build/dex/quick-perps/quick-perps.js.map +1 -1
- package/build/dex/quickswap/config.js +0 -8
- package/build/dex/quickswap/config.js.map +1 -1
- package/build/dex/solidly/config.js +1 -27
- package/build/dex/solidly/config.js.map +1 -1
- package/build/dex/solidly/solidly.js +0 -2
- package/build/dex/solidly/solidly.js.map +1 -1
- package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +1 -0
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js +53 -0
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +1 -0
- package/build/dex/stable-pool/stable-pool.js +1 -8
- package/build/dex/stable-pool/stable-pool.js.map +1 -1
- package/build/dex/stable-pool.js +1 -8
- package/build/dex/stable-pool.js.map +1 -1
- package/build/dex/uniswap-v2/config.js +0 -152
- package/build/dex/uniswap-v2/config.js.map +1 -1
- package/build/dex/uniswap-v2/constants.js +0 -1
- package/build/dex/uniswap-v2/constants.js.map +1 -1
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +17 -0
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +64 -0
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +1 -0
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +17 -0
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +79 -0
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +1 -0
- package/build/dex/weth/config.js +0 -3
- package/build/dex/weth/config.js.map +1 -1
- package/build/dex/wsteth/wsteth.js.map +1 -1
- package/build/types.d.ts +0 -1
- package/package.json +1 -1
- package/src/config.ts +0 -39
- package/src/constants.ts +0 -1
- package/src/dex/augustus-rfq.ts +0 -1
- package/src/dex/curve-v1/config.ts +1 -57
- package/src/dex/curve-v1/curve-v1-e2e.test.ts +0 -51
- package/src/dex/curve-v1-factory/config.ts +1 -1
- package/src/dex/etherfi.ts +1 -1
- package/src/dex/gmx/gmx.ts +1 -4
- package/src/dex/index.ts +0 -14
- package/src/dex/nerve/config.ts +0 -400
- package/src/dex/nerve/nerve-e2e.test.ts +0 -507
- package/src/dex/nerve/nerve-events.test.ts +0 -268
- package/src/dex/paraswap-limit-orders/config.ts +0 -7
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders-e2e.test.ts +2 -2
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders-integration.test.ts +1 -1
- package/src/dex/quick-perps/quick-perps.ts +1 -4
- package/src/dex/quickswap/config.ts +0 -9
- package/src/dex/quickswap/quickswap-e2e.test.ts +0 -97
- package/src/dex/solidly/config.ts +1 -30
- package/src/dex/solidly/solidly-e2e.test.ts +0 -280
- package/src/dex/solidly/solidly-integration.test.ts +0 -135
- package/src/dex/solidly/solidly.ts +0 -2
- package/src/dex/stable-pool/stable-pool.ts +1 -8
- package/src/dex/uniswap-v2/config.ts +0 -185
- package/src/dex/uniswap-v2/constants.ts +0 -1
- package/src/dex/uniswap-v2/uniswap-v2-e2e-avalanche.test.ts +0 -272
- package/src/dex/uniswap-v2/uniswap-v2-e2e-base.test.ts +0 -6
- package/src/dex/uniswap-v2/uniswap-v2-e2e-bsc.test.ts +0 -325
- package/src/dex/uniswap-v2/uniswap-v2-e2e-mainnet.test.ts +0 -175
- package/src/dex/uniswap-v2/uniswap-v2-e2e-polygon.test.ts +0 -413
- package/src/dex/weth/config.ts +0 -3
- package/src/dex/wsteth/wsteth.ts +1 -4
- package/src/types.ts +0 -1
- package/tests/constants-e2e.ts +0 -21
- package/tests/generate-new-limit-order.ts +1 -1
- package/.idea/aws.xml +0 -17
- package/.idea/codeStyles/Project.xml +0 -19
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/paraswap-dex-lib.iml +0 -9
- package/.idea/prettier.xml +0 -7
- package/.idea/vcs.xml +0 -6
- package/build/abi/AugustusV6.abi.json +0 -395
- package/build/abi/algebra/AlgebraPool.abi.json +0 -727
- package/build/abi/curve-v1/StableSwapFRXETH.json +0 -889
- package/build/abi/curve-v1/StableSwapWBETH.json +0 -1223
- package/build/abi/sushiswap-v3/QuoterV2.json +0 -267
- package/build/abi/sushiswap-v3/RouterProcessor3.json +0 -289
- package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
- package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +0 -285
- package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
- package/build/abi/wBETH.json +0 -1527
- package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
- package/build/abi/woo-fi/WooPP.abi.json +0 -548
- package/build/abi/woo-fi/Wooracle.abi.json +0 -260
- package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
- package/build/dex/aave-v3/tokens/avalanche.json +0 -74
- package/build/dex/aave-v3/tokens/fantom.json +0 -62
- package/build/dex/aave-v3/tokens/optimism.json +0 -50
- package/build/dex/aave-v3/tokens/polygon.json +0 -116
- package/build/dex/algebra/algebra-pool.d.ts +0 -114
- package/build/dex/algebra/algebra-pool.js +0 -448
- package/build/dex/algebra/algebra-pool.js.map +0 -1
- package/build/dex/balancer-v2/Gyro3Pool.d.ts +0 -43
- package/build/dex/balancer-v2/Gyro3Pool.js +0 -160
- package/build/dex/balancer-v2/Gyro3Pool.js.map +0 -1
- package/build/dex/balancer-v2/LinearMath.d.ts +0 -88
- package/build/dex/balancer-v2/LinearMath.js +0 -285
- package/build/dex/balancer-v2/LinearMath.js.map +0 -1
- package/build/dex/balancer-v2/LinearPool.d.ts +0 -81
- package/build/dex/balancer-v2/LinearPool.js +0 -444
- package/build/dex/balancer-v2/LinearPool.js.map +0 -1
- package/build/dex/balancer-v2/PhantomStablePool.d.ts +0 -90
- package/build/dex/balancer-v2/PhantomStablePool.js +0 -418
- package/build/dex/balancer-v2/PhantomStablePool.js.map +0 -1
- package/build/dex/balancer-v2/StableMath.d.ts +0 -9
- package/build/dex/balancer-v2/StableMath.js +0 -272
- package/build/dex/balancer-v2/StableMath.js.map +0 -1
- package/build/dex/balancer-v2/balancer-v2-pool.d.ts +0 -140
- package/build/dex/balancer-v2/balancer-v2-pool.js +0 -647
- package/build/dex/balancer-v2/balancer-v2-pool.js.map +0 -1
- package/build/dex/curve-v1/pools/frxETHpool.d.ts +0 -7
- package/build/dex/curve-v1/pools/frxETHpool.js +0 -27
- package/build/dex/curve-v1/pools/frxETHpool.js.map +0 -1
- package/build/dex/curve-v1/pools/wbETHpool.d.ts +0 -29
- package/build/dex/curve-v1/pools/wbETHpool.js +0 -408
- package/build/dex/curve-v1/pools/wbETHpool.js.map +0 -1
- package/build/dex/integral/config.d.ts +0 -4
- package/build/dex/integral/config.js +0 -18
- package/build/dex/integral/config.js.map +0 -1
- package/build/dex/integral/integral-pool.d.ts +0 -39
- package/build/dex/integral/integral-pool.js +0 -67
- package/build/dex/integral/integral-pool.js.map +0 -1
- package/build/dex/integral/integral.d.ts +0 -48
- package/build/dex/integral/integral.js +0 -402
- package/build/dex/integral/integral.js.map +0 -1
- package/build/dex/integral/types.d.ts +0 -25
- package/build/dex/integral/types.js +0 -9
- package/build/dex/integral/types.js.map +0 -1
- package/build/dex/lighter-v1/abi/erc20.json +0 -222
- package/build/dex/lighter-v1/abi/factory.json +0 -291
- package/build/dex/lighter-v1/abi/order_book.json +0 -594
- package/build/dex/lighter-v1/abi/order_book_helper.json +0 -176
- package/build/dex/lighter-v1/abi/router.json +0 -488
- package/build/dex/lighter-v1/config.d.ts +0 -4
- package/build/dex/lighter-v1/config.js +0 -17
- package/build/dex/lighter-v1/config.js.map +0 -1
- package/build/dex/lighter-v1/constants.d.ts +0 -2
- package/build/dex/lighter-v1/constants.js +0 -13
- package/build/dex/lighter-v1/constants.js.map +0 -1
- package/build/dex/lighter-v1/lighter-v1-pool.d.ts +0 -57
- package/build/dex/lighter-v1/lighter-v1-pool.js +0 -310
- package/build/dex/lighter-v1/lighter-v1-pool.js.map +0 -1
- package/build/dex/lighter-v1/lighter-v1.d.ts +0 -45
- package/build/dex/lighter-v1/lighter-v1.js +0 -331
- package/build/dex/lighter-v1/lighter-v1.js.map +0 -1
- package/build/dex/lighter-v1/types.d.ts +0 -40
- package/build/dex/lighter-v1/types.js +0 -3
- package/build/dex/lighter-v1/types.js.map +0 -1
- package/build/dex/pancakeswap-v3/types.d.ts +0 -14
- package/build/dex/pancakeswap-v3/types.js +0 -3
- package/build/dex/pancakeswap-v3/types.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/quickswap-v3.d.ts +0 -21
- package/build/dex/quickswap-v3.js +0 -40
- package/build/dex/quickswap-v3.js.map +0 -1
- package/build/dex/ramses-v2/config.d.ts +0 -4
- package/build/dex/ramses-v2/config.js +0 -28
- package/build/dex/ramses-v2/config.js.map +0 -1
- package/build/dex/ramses-v2/constants.d.ts +0 -28
- package/build/dex/ramses-v2/constants.js +0 -35
- package/build/dex/ramses-v2/constants.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/BitMath.d.ts +0 -4
- package/build/dex/ramses-v2/contract-math/BitMath.js +0 -93
- package/build/dex/ramses-v2/contract-math/BitMath.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +0 -3
- package/build/dex/ramses-v2/contract-math/FixedPoint128.js +0 -8
- package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +0 -4
- package/build/dex/ramses-v2/contract-math/FixedPoint96.js +0 -9
- package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/FullMath.d.ts +0 -4
- package/build/dex/ramses-v2/contract-math/FullMath.js +0 -19
- package/build/dex/ramses-v2/contract-math/FullMath.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +0 -3
- package/build/dex/ramses-v2/contract-math/LiquidityMath.js +0 -22
- package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/Oracle.d.ts +0 -10
- package/build/dex/ramses-v2/contract-math/Oracle.js +0 -133
- package/build/dex/ramses-v2/contract-math/Oracle.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +0 -10
- package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +0 -91
- package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +0 -8
- package/build/dex/ramses-v2/contract-math/SwapMath.js +0 -70
- package/build/dex/ramses-v2/contract-math/SwapMath.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/Tick.d.ts +0 -7
- package/build/dex/ramses-v2/contract-math/Tick.js +0 -45
- package/build/dex/ramses-v2/contract-math/Tick.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +0 -8
- package/build/dex/ramses-v2/contract-math/TickBitMap.js +0 -87
- package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/TickMath.d.ts +0 -8
- package/build/dex/ramses-v2/contract-math/TickMath.js +0 -162
- package/build/dex/ramses-v2/contract-math/TickMath.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +0 -3
- package/build/dex/ramses-v2/contract-math/UnsafeMath.js +0 -10
- package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +0 -18
- package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +0 -392
- package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/utils.d.ts +0 -3
- package/build/dex/ramses-v2/contract-math/utils.js +0 -16
- package/build/dex/ramses-v2/contract-math/utils.js.map +0 -1
- package/build/dex/ramses-v2/ramses-v2-pool.d.ts +0 -42
- package/build/dex/ramses-v2/ramses-v2-pool.js +0 -307
- package/build/dex/ramses-v2/ramses-v2-pool.js.map +0 -1
- package/build/dex/ramses-v2/ramses-v2.d.ts +0 -61
- package/build/dex/ramses-v2/ramses-v2.js +0 -690
- package/build/dex/ramses-v2/ramses-v2.js.map +0 -1
- package/build/dex/ramses-v2/types.d.ts +0 -154
- package/build/dex/ramses-v2/types.js +0 -9
- package/build/dex/ramses-v2/types.js.map +0 -1
- package/build/dex/ramses-v2/utils.d.ts +0 -6
- package/build/dex/ramses-v2/utils.js +0 -71
- package/build/dex/ramses-v2/utils.js.map +0 -1
- package/build/dex/solidly/forks-override/fvm.d.ts +0 -20
- package/build/dex/solidly/forks-override/fvm.js +0 -42
- package/build/dex/solidly/forks-override/fvm.js.map +0 -1
- package/build/dex/sushiswap-v3/config.d.ts +0 -4
- package/build/dex/sushiswap-v3/config.js +0 -132
- package/build/dex/sushiswap-v3/config.js.map +0 -1
- package/build/dex/sushiswap-v3/constants.d.ts +0 -4
- package/build/dex/sushiswap-v3/constants.js +0 -32
- package/build/dex/sushiswap-v3/constants.js.map +0 -1
- package/build/dex/sushiswap-v3/sushiswap-v3-original.d.ts +0 -56
- package/build/dex/sushiswap-v3/sushiswap-v3-original.js +0 -598
- package/build/dex/sushiswap-v3/sushiswap-v3-original.js.map +0 -1
- package/build/dex/sushiswap-v3/sushiswap-v3-pool.d.ts +0 -1
- package/build/dex/sushiswap-v3/sushiswap-v3-pool.js +0 -6
- package/build/dex/sushiswap-v3/sushiswap-v3-pool.js.map +0 -1
- package/build/dex/sushiswap-v3/sushiswap-v3.d.ts +0 -21
- package/build/dex/sushiswap-v3/sushiswap-v3.js +0 -58
- package/build/dex/sushiswap-v3/sushiswap-v3.js.map +0 -1
- package/build/dex/sushiswap-v3/token.d.ts +0 -6
- package/build/dex/sushiswap-v3/token.js +0 -23
- package/build/dex/sushiswap-v3/token.js.map +0 -1
- package/build/dex/sushiswap-v3/types.d.ts +0 -15
- package/build/dex/sushiswap-v3/types.js +0 -18
- package/build/dex/sushiswap-v3/types.js.map +0 -1
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +0 -12
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +0 -23
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +0 -1
- package/build/dex/woo-fi/config.d.ts +0 -4
- package/build/dex/woo-fi/config.js +0 -141
- package/build/dex/woo-fi/config.js.map +0 -1
- package/build/dex/woo-fi/constants.d.ts +0 -5
- package/build/dex/woo-fi/constants.js +0 -20
- package/build/dex/woo-fi/constants.js.map +0 -1
- package/build/dex/woo-fi/types.d.ts +0 -48
- package/build/dex/woo-fi/types.js +0 -3
- package/build/dex/woo-fi/types.js.map +0 -1
- package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
- package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
- package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
- package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
- package/build/dex/woo-fi/woo-fi-math.js +0 -300
- package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
- package/build/dex/woo-fi/woo-fi.d.ts +0 -65
- package/build/dex/woo-fi/woo-fi.js +0 -480
- package/build/dex/woo-fi/woo-fi.js.map +0 -1
- package/build/executor/IExecutorBytecodeBuilder.d.ts +0 -6
- package/build/executor/IExecutorBytecodeBuilder.js +0 -3
- package/build/executor/IExecutorBytecodeBuilder.js.map +0 -1
- package/src/abi/AaveV1_lending_pool.json +0 -27
- package/src/abi/platypus/asset.json +0 -490
- package/src/abi/platypus/avax-pool.json +0 -820
- package/src/abi/platypus/oracle.json +0 -119
- package/src/abi/platypus/pool.json +0 -677
- package/src/abi/smardex/all/smardex-router.json +0 -648
- package/src/abi/smardex/layer-1/smardex-factory.json +0 -242
- package/src/abi/smardex/layer-1/smardex-pool.json +0 -506
- package/src/abi/smardex/layer-2/smardex-factory.json +0 -185
- package/src/abi/smardex/layer-2/smardex-pool.json +0 -578
- package/src/abi/swaap-v1/asset.json +0 -490
- package/src/abi/swaap-v1/oracle.json +0 -119
- package/src/abi/swaap-v1/pool.json +0 -1346
- package/src/dex/aave-v1/aave-v1-e2e.test.ts +0 -105
- package/src/dex/aave-v1/aave-v1-integration.test.ts +0 -100
- package/src/dex/aave-v1/aave-v1.ts +0 -261
- package/src/dex/aave-v1/config.ts +0 -22
- package/src/dex/aave-v1/tokens-mainnet.json +0 -134
- package/src/dex/aave-v1/tokens.ts +0 -58
- package/src/dex/aave-v1/types.ts +0 -24
- package/src/dex/platypus/asset.ts +0 -139
- package/src/dex/platypus/config.ts +0 -72
- package/src/dex/platypus/platypus-e2e.test.ts +0 -168
- package/src/dex/platypus/platypus-events.test.ts +0 -167
- package/src/dex/platypus/platypus-integration.test.ts +0 -256
- package/src/dex/platypus/platypus.ts +0 -639
- package/src/dex/platypus/pool-avax.ts +0 -92
- package/src/dex/platypus/pool-base.ts +0 -155
- package/src/dex/platypus/pool-pure.ts +0 -71
- package/src/dex/platypus/pool-subscriber.ts +0 -239
- package/src/dex/platypus/pool.ts +0 -99
- package/src/dex/platypus/types.ts +0 -104
- package/src/dex/quickswap/spiritswap-v3.ts +0 -19
- package/src/dex/smardex/config.ts +0 -67
- package/src/dex/smardex/constants.ts +0 -35
- package/src/dex/smardex/sdk/constants.ts +0 -10
- package/src/dex/smardex/sdk/core.ts +0 -832
- package/src/dex/smardex/sdk/errors.ts +0 -18
- package/src/dex/smardex/sdk/types.ts +0 -68
- package/src/dex/smardex/sdk/utils.ts +0 -156
- package/src/dex/smardex/smardex-e2e.test.ts +0 -275
- package/src/dex/smardex/smardex-event-pool.ts +0 -164
- package/src/dex/smardex/smardex-events.test.ts +0 -297
- package/src/dex/smardex/smardex-integration.test.ts +0 -258
- package/src/dex/smardex/smardex.ts +0 -770
- package/src/dex/smardex/types.ts +0 -69
- package/src/dex/solidly/forks-override/cone.ts +0 -67
- package/src/dex/solidly/forks-override/solisnek.ts +0 -10
- package/src/dex/swaap-v1/config.ts +0 -62
- package/src/dex/swaap-v1/constants.ts +0 -22
- package/src/dex/swaap-v1/libraries/ChainlinkUtils.ts +0 -152
- package/src/dex/swaap-v1/libraries/Const.ts +0 -29
- package/src/dex/swaap-v1/libraries/GeometricBrownianMotion.ts +0 -433
- package/src/dex/swaap-v1/libraries/LogExpMath.ts +0 -511
- package/src/dex/swaap-v1/libraries/MathMMM.ts +0 -717
- package/src/dex/swaap-v1/libraries/Num.ts +0 -184
- package/src/dex/swaap-v1/libraries/PoolQuotations.ts +0 -322
- package/src/dex/swaap-v1/libraries/Struct.ts +0 -66
- package/src/dex/swaap-v1/swaap-v1-e2e.test.ts +0 -75
- package/src/dex/swaap-v1/swaap-v1-events.test.ts +0 -138
- package/src/dex/swaap-v1/swaap-v1-integration.test.ts +0 -232
- package/src/dex/swaap-v1/swaap-v1-pool.ts +0 -919
- package/src/dex/swaap-v1/swaap-v1.ts +0 -668
- package/src/dex/swaap-v1/types.ts +0 -124
- package/src/dex/uniswap-v2/uniswap-v2-e2e-ropsten.test.ts +0 -481
|
@@ -1,639 +0,0 @@
|
|
|
1
|
-
import { Interface } from '@ethersproject/abi';
|
|
2
|
-
import {
|
|
3
|
-
Token,
|
|
4
|
-
Address,
|
|
5
|
-
ExchangePrices,
|
|
6
|
-
PoolPrices,
|
|
7
|
-
AdapterExchangeParam,
|
|
8
|
-
SimpleExchangeParam,
|
|
9
|
-
PoolLiquidity,
|
|
10
|
-
Logger,
|
|
11
|
-
MultiCallInput,
|
|
12
|
-
NumberAsString,
|
|
13
|
-
DexExchangeParam,
|
|
14
|
-
} from '../../types';
|
|
15
|
-
import { SwapSide, Network } from '../../constants';
|
|
16
|
-
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
17
|
-
import { getDexKeysWithNetwork, getBigIntPow, isETHAddress } from '../../utils';
|
|
18
|
-
import { IDex } from '../../dex/idex';
|
|
19
|
-
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
20
|
-
import {
|
|
21
|
-
DexParams,
|
|
22
|
-
PlatypusOracleType,
|
|
23
|
-
PlatypusData,
|
|
24
|
-
PlatypusConfigInfo,
|
|
25
|
-
} from './types';
|
|
26
|
-
import {
|
|
27
|
-
getLocalDeadlineAsFriendlyPlaceholder,
|
|
28
|
-
SimpleExchange,
|
|
29
|
-
} from '../simple-exchange';
|
|
30
|
-
import { PlatypusConfig, Adapters } from './config';
|
|
31
|
-
import { ChainLinkSubscriber } from '../../lib/chainlink';
|
|
32
|
-
import { PlatypusPoolBase } from './pool-base';
|
|
33
|
-
import { PlatypusPool } from './pool';
|
|
34
|
-
import { PlatypusPurePool } from './pool-pure';
|
|
35
|
-
import { PlatypusAvaxPool } from './pool-avax';
|
|
36
|
-
import ERC20ABI from '../../abi/erc20.json';
|
|
37
|
-
import PoolABI from '../../abi/platypus/pool.json';
|
|
38
|
-
import AvaxPoolABI from '../../abi/platypus/avax-pool.json';
|
|
39
|
-
import AssetABI from '../../abi/platypus/asset.json';
|
|
40
|
-
import OracleABI from '../../abi/platypus/oracle.json';
|
|
41
|
-
import { extractReturnAmountPosition } from '../../executor/utils';
|
|
42
|
-
|
|
43
|
-
export class Platypus extends SimpleExchange implements IDex<PlatypusData> {
|
|
44
|
-
static readonly erc20Interface = new Interface(ERC20ABI);
|
|
45
|
-
static readonly poolInterface = new Interface(PoolABI);
|
|
46
|
-
static readonly avaxPoolInterface = new Interface(AvaxPoolABI);
|
|
47
|
-
static readonly assetInterface = new Interface(AssetABI);
|
|
48
|
-
static readonly oracleInterface = new Interface(OracleABI);
|
|
49
|
-
|
|
50
|
-
protected config: DexParams;
|
|
51
|
-
protected cfgInfo?: PlatypusConfigInfo;
|
|
52
|
-
protected poolLiquidityUSD?: { [poolAddress: string]: number };
|
|
53
|
-
|
|
54
|
-
protected eventPools?: {
|
|
55
|
-
[poolAddress: string]: PlatypusPool | PlatypusPurePool | PlatypusAvaxPool;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
readonly hasConstantPriceLargeAmounts = false;
|
|
59
|
-
readonly isFeeOnTransferSupported = false;
|
|
60
|
-
|
|
61
|
-
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
62
|
-
getDexKeysWithNetwork(PlatypusConfig);
|
|
63
|
-
|
|
64
|
-
logger: Logger;
|
|
65
|
-
|
|
66
|
-
constructor(
|
|
67
|
-
protected network: Network,
|
|
68
|
-
dexKey: string,
|
|
69
|
-
protected dexHelper: IDexHelper,
|
|
70
|
-
protected adapters = Adapters[network], // TODO: add any additional optional params to support other fork DEXes
|
|
71
|
-
) {
|
|
72
|
-
super(dexHelper, dexKey);
|
|
73
|
-
this.config = PlatypusConfig[dexKey][network];
|
|
74
|
-
this.logger = dexHelper.getLogger(`${dexKey}-${network}`);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async generateConfigInfo(blockNumber: number): Promise<PlatypusConfigInfo> {
|
|
78
|
-
const cfgInfo: PlatypusConfigInfo = {
|
|
79
|
-
poolAddresses: [],
|
|
80
|
-
pools: {},
|
|
81
|
-
};
|
|
82
|
-
// Need to filter pools in case we are testing against an old block where the pool didn't exist!
|
|
83
|
-
for (const p of this.config.pools) {
|
|
84
|
-
// When there's no code, getCode should return '0x' but could return '0x0' instead
|
|
85
|
-
if (
|
|
86
|
-
(await this.dexHelper.web3Provider.eth.getCode(p.address, blockNumber))
|
|
87
|
-
.length > 3
|
|
88
|
-
) {
|
|
89
|
-
const poolAddress = p.address.toLowerCase();
|
|
90
|
-
cfgInfo.poolAddresses.push(poolAddress);
|
|
91
|
-
if (p.oracleType === PlatypusOracleType.None) {
|
|
92
|
-
cfgInfo.pools[poolAddress] = {
|
|
93
|
-
oracleType: PlatypusOracleType.None,
|
|
94
|
-
tokenAddresses: [],
|
|
95
|
-
tokens: {},
|
|
96
|
-
};
|
|
97
|
-
} else if (p.oracleType === PlatypusOracleType.ChainLink) {
|
|
98
|
-
cfgInfo.pools[poolAddress] = {
|
|
99
|
-
oracleType: PlatypusOracleType.ChainLink,
|
|
100
|
-
priceOracleAddress: '',
|
|
101
|
-
tokenAddresses: [],
|
|
102
|
-
tokens: {},
|
|
103
|
-
};
|
|
104
|
-
} else if (p.oracleType === PlatypusOracleType.StakedAvax) {
|
|
105
|
-
cfgInfo.pools[poolAddress] = {
|
|
106
|
-
oracleType: PlatypusOracleType.StakedAvax,
|
|
107
|
-
priceOracleAddress: '',
|
|
108
|
-
tokenAddresses: [],
|
|
109
|
-
tokens: {},
|
|
110
|
-
};
|
|
111
|
-
} else {
|
|
112
|
-
throw new Error(`Invalid pool oracle type in ${this.dexKey}`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
let inputs: MultiCallInput[] = [];
|
|
117
|
-
for (const poolAddress of cfgInfo.poolAddresses) {
|
|
118
|
-
const pool = cfgInfo.pools[poolAddress];
|
|
119
|
-
if (pool.oracleType !== PlatypusOracleType.None) {
|
|
120
|
-
inputs.push({
|
|
121
|
-
target: poolAddress,
|
|
122
|
-
callData: Platypus.poolInterface.encodeFunctionData('getPriceOracle'),
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
inputs.push({
|
|
126
|
-
target: poolAddress,
|
|
127
|
-
callData:
|
|
128
|
-
Platypus.poolInterface.encodeFunctionData('getTokenAddresses'),
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
let returnData = (
|
|
132
|
-
await this.dexHelper.multiContract.methods
|
|
133
|
-
.aggregate(inputs)
|
|
134
|
-
.call({}, blockNumber)
|
|
135
|
-
).returnData;
|
|
136
|
-
let i = 0;
|
|
137
|
-
for (const poolAddress of cfgInfo.poolAddresses) {
|
|
138
|
-
const pool = cfgInfo.pools[poolAddress];
|
|
139
|
-
if (pool.oracleType !== PlatypusOracleType.None) {
|
|
140
|
-
pool.priceOracleAddress = Platypus.poolInterface
|
|
141
|
-
.decodeFunctionResult('getPriceOracle', returnData[i++])[0]
|
|
142
|
-
.toLowerCase();
|
|
143
|
-
}
|
|
144
|
-
pool.tokenAddresses = Platypus.poolInterface
|
|
145
|
-
.decodeFunctionResult('getTokenAddresses', returnData[i++])[0]
|
|
146
|
-
.map((a: Address) => a.toLowerCase());
|
|
147
|
-
}
|
|
148
|
-
inputs = [];
|
|
149
|
-
for (const poolAddress of cfgInfo.poolAddresses) {
|
|
150
|
-
const pool = cfgInfo.pools[poolAddress];
|
|
151
|
-
for (const tokenAddress of pool.tokenAddresses) {
|
|
152
|
-
inputs.push({
|
|
153
|
-
target: tokenAddress,
|
|
154
|
-
callData: Platypus.erc20Interface.encodeFunctionData('symbol'),
|
|
155
|
-
});
|
|
156
|
-
inputs.push({
|
|
157
|
-
target: tokenAddress,
|
|
158
|
-
callData: Platypus.erc20Interface.encodeFunctionData('decimals'),
|
|
159
|
-
});
|
|
160
|
-
inputs.push({
|
|
161
|
-
target: poolAddress,
|
|
162
|
-
callData: Platypus.poolInterface.encodeFunctionData('assetOf', [
|
|
163
|
-
tokenAddress,
|
|
164
|
-
]),
|
|
165
|
-
});
|
|
166
|
-
if (pool.oracleType === PlatypusOracleType.ChainLink) {
|
|
167
|
-
inputs.push({
|
|
168
|
-
target: pool.priceOracleAddress,
|
|
169
|
-
callData: Platypus.oracleInterface.encodeFunctionData(
|
|
170
|
-
'getSourceOfAsset',
|
|
171
|
-
[tokenAddress],
|
|
172
|
-
),
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
returnData = (
|
|
178
|
-
await this.dexHelper.multiContract.methods
|
|
179
|
-
.aggregate(inputs)
|
|
180
|
-
.call({}, blockNumber)
|
|
181
|
-
).returnData;
|
|
182
|
-
i = 0;
|
|
183
|
-
for (const poolAddress of cfgInfo.poolAddresses) {
|
|
184
|
-
const pool = cfgInfo.pools[poolAddress];
|
|
185
|
-
for (const tokenAddress of pool.tokenAddresses) {
|
|
186
|
-
const tokenSymbol = Platypus.erc20Interface.decodeFunctionResult(
|
|
187
|
-
'symbol',
|
|
188
|
-
returnData[i++],
|
|
189
|
-
)[0];
|
|
190
|
-
const tokenDecimals = Platypus.erc20Interface.decodeFunctionResult(
|
|
191
|
-
'decimals',
|
|
192
|
-
returnData[i++],
|
|
193
|
-
)[0];
|
|
194
|
-
const assetAddress = Platypus.poolInterface
|
|
195
|
-
.decodeFunctionResult('assetOf', returnData[i++])[0]
|
|
196
|
-
.toLowerCase();
|
|
197
|
-
if (pool.oracleType === PlatypusOracleType.ChainLink) {
|
|
198
|
-
const proxyAddress = Platypus.oracleInterface
|
|
199
|
-
.decodeFunctionResult('getSourceOfAsset', returnData[i++])[0]
|
|
200
|
-
.toLowerCase();
|
|
201
|
-
pool.tokens[tokenAddress] = {
|
|
202
|
-
tokenSymbol,
|
|
203
|
-
tokenDecimals,
|
|
204
|
-
assetAddress,
|
|
205
|
-
chainlink: {
|
|
206
|
-
proxyAddress,
|
|
207
|
-
aggregatorAddress: '',
|
|
208
|
-
},
|
|
209
|
-
};
|
|
210
|
-
} else {
|
|
211
|
-
pool.tokens[tokenAddress] = {
|
|
212
|
-
tokenSymbol,
|
|
213
|
-
tokenDecimals,
|
|
214
|
-
assetAddress,
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
inputs = [];
|
|
220
|
-
for (const poolAddress of cfgInfo.poolAddresses) {
|
|
221
|
-
const pool = cfgInfo.pools[poolAddress];
|
|
222
|
-
if (pool.oracleType === PlatypusOracleType.ChainLink) {
|
|
223
|
-
for (const tokenAddress of pool.tokenAddresses) {
|
|
224
|
-
inputs.push(
|
|
225
|
-
ChainLinkSubscriber.getReadAggregatorMultiCallInput(
|
|
226
|
-
pool.tokens[tokenAddress].chainlink.proxyAddress,
|
|
227
|
-
),
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
returnData = (
|
|
233
|
-
await this.dexHelper.multiContract.methods
|
|
234
|
-
.aggregate(inputs)
|
|
235
|
-
.call({}, blockNumber)
|
|
236
|
-
).returnData;
|
|
237
|
-
i = 0;
|
|
238
|
-
for (const poolAddress of cfgInfo.poolAddresses) {
|
|
239
|
-
const pool = cfgInfo.pools[poolAddress];
|
|
240
|
-
if (pool.oracleType === PlatypusOracleType.ChainLink) {
|
|
241
|
-
for (const tokenAddress of pool.tokenAddresses) {
|
|
242
|
-
pool.tokens[tokenAddress].chainlink.aggregatorAddress =
|
|
243
|
-
ChainLinkSubscriber.readAggregator(returnData[i++]).toLowerCase();
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return cfgInfo;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
async init(blockNumber: number) {
|
|
251
|
-
if (this.cfgInfo) return;
|
|
252
|
-
this.cfgInfo = await this.generateConfigInfo(blockNumber);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Initialize pricing is called once in the start of
|
|
256
|
-
// pricing service. It is intended to setup the integration
|
|
257
|
-
// for pricing requests. It is optional for a DEX to
|
|
258
|
-
// implement this function
|
|
259
|
-
async initializePricing(blockNumber: number) {
|
|
260
|
-
await this.init(blockNumber);
|
|
261
|
-
if (!this.cfgInfo)
|
|
262
|
-
throw new Error(
|
|
263
|
-
`initializePricing: ${this.dexKey} cfgInfo still null after init`,
|
|
264
|
-
);
|
|
265
|
-
const eventPools: {
|
|
266
|
-
[poolAddress: string]: PlatypusPool | PlatypusPurePool | PlatypusAvaxPool;
|
|
267
|
-
} = {};
|
|
268
|
-
for (const poolAddress of this.cfgInfo.poolAddresses) {
|
|
269
|
-
const cfgPool = this.cfgInfo.pools[poolAddress];
|
|
270
|
-
const poolName = this.config.pools.find(
|
|
271
|
-
p => p.address.toLowerCase() === poolAddress,
|
|
272
|
-
)!.name;
|
|
273
|
-
let pool: PlatypusPool | PlatypusPurePool | PlatypusAvaxPool;
|
|
274
|
-
if (cfgPool.oracleType === PlatypusOracleType.None) {
|
|
275
|
-
pool = new PlatypusPurePool(
|
|
276
|
-
this.dexKey,
|
|
277
|
-
this.network,
|
|
278
|
-
poolName,
|
|
279
|
-
poolAddress,
|
|
280
|
-
cfgPool,
|
|
281
|
-
this.dexHelper,
|
|
282
|
-
);
|
|
283
|
-
} else if (cfgPool.oracleType === PlatypusOracleType.ChainLink) {
|
|
284
|
-
pool = new PlatypusPool(
|
|
285
|
-
this.dexKey,
|
|
286
|
-
this.network,
|
|
287
|
-
poolName,
|
|
288
|
-
poolAddress,
|
|
289
|
-
cfgPool,
|
|
290
|
-
this.dexHelper,
|
|
291
|
-
);
|
|
292
|
-
} else if (cfgPool.oracleType === PlatypusOracleType.StakedAvax) {
|
|
293
|
-
pool = new PlatypusAvaxPool(
|
|
294
|
-
this.dexKey,
|
|
295
|
-
this.network,
|
|
296
|
-
poolName,
|
|
297
|
-
poolAddress,
|
|
298
|
-
cfgPool,
|
|
299
|
-
this.dexHelper,
|
|
300
|
-
);
|
|
301
|
-
} else {
|
|
302
|
-
throw new Error(`${this.dexKey} cfgInfo invalid pool type`);
|
|
303
|
-
}
|
|
304
|
-
await pool.initialize(blockNumber);
|
|
305
|
-
eventPools[poolAddress] = pool;
|
|
306
|
-
}
|
|
307
|
-
this.eventPools = eventPools;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// Returns the list of contract adapters (name and index)
|
|
311
|
-
// for a buy/sell. Return null if there are no adapters.
|
|
312
|
-
getAdapters(side: SwapSide): { name: string; index: number }[] | null {
|
|
313
|
-
return this.adapters[side];
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
protected findPools(
|
|
317
|
-
srcTokenAddress: Address,
|
|
318
|
-
destTokenAddress: Address,
|
|
319
|
-
): Address[] {
|
|
320
|
-
if (!this.cfgInfo) return [];
|
|
321
|
-
return Object.entries(this.cfgInfo.pools)
|
|
322
|
-
.filter(
|
|
323
|
-
([poolAddress, poolConfig]) =>
|
|
324
|
-
poolConfig.tokenAddresses.includes(srcTokenAddress) &&
|
|
325
|
-
poolConfig.tokenAddresses.includes(destTokenAddress),
|
|
326
|
-
)
|
|
327
|
-
.map(([poolAddress, poolConfig]) => poolAddress);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
protected getPoolIdentifier(poolAddress: Address): string {
|
|
331
|
-
return `${this.dexKey}_${poolAddress}`;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
// Returns list of pool identifiers that can be used
|
|
335
|
-
// for a given swap. poolIdentifers must be unique
|
|
336
|
-
// across DEXes. It is recommended to use
|
|
337
|
-
// ${dexKey}_${poolAddress} as a poolIdentifier
|
|
338
|
-
async getPoolIdentifiers(
|
|
339
|
-
srcToken: Token,
|
|
340
|
-
destToken: Token,
|
|
341
|
-
side: SwapSide,
|
|
342
|
-
blockNumber: number,
|
|
343
|
-
): Promise<string[]> {
|
|
344
|
-
if (side === SwapSide.BUY) return [];
|
|
345
|
-
return this.findPools(
|
|
346
|
-
this.dexHelper.config.wrapETH(srcToken).address.toLowerCase(),
|
|
347
|
-
this.dexHelper.config.wrapETH(destToken).address.toLowerCase(),
|
|
348
|
-
).map(p => this.getPoolIdentifier(p));
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
// Returns pool prices for amounts.
|
|
352
|
-
// If limitPools is defined only pools in limitPools
|
|
353
|
-
// should be used. If limitPools is undefined then
|
|
354
|
-
// any pools can be used.
|
|
355
|
-
async getPricesVolume(
|
|
356
|
-
srcToken: Token,
|
|
357
|
-
destToken: Token,
|
|
358
|
-
amounts: bigint[],
|
|
359
|
-
side: SwapSide,
|
|
360
|
-
blockNumber: number,
|
|
361
|
-
limitPools?: string[],
|
|
362
|
-
): Promise<null | ExchangePrices<PlatypusData>> {
|
|
363
|
-
if (side === SwapSide.BUY) return null;
|
|
364
|
-
if (!this.eventPools) {
|
|
365
|
-
this.logger.error(
|
|
366
|
-
`Missing event pools for ${this.dexKey} in getPricesVolume`,
|
|
367
|
-
);
|
|
368
|
-
return null;
|
|
369
|
-
}
|
|
370
|
-
const srcTokenAddress = this.dexHelper.config
|
|
371
|
-
.wrapETH(srcToken)
|
|
372
|
-
.address.toLowerCase();
|
|
373
|
-
const destTokenAddress = this.dexHelper.config
|
|
374
|
-
.wrapETH(destToken)
|
|
375
|
-
.address.toLowerCase();
|
|
376
|
-
if (srcTokenAddress === destTokenAddress) return null;
|
|
377
|
-
return (
|
|
378
|
-
await Promise.all(
|
|
379
|
-
this.findPools(srcTokenAddress, destTokenAddress)
|
|
380
|
-
.filter(
|
|
381
|
-
poolAddress =>
|
|
382
|
-
!limitPools ||
|
|
383
|
-
limitPools.includes(this.getPoolIdentifier(poolAddress)),
|
|
384
|
-
)
|
|
385
|
-
.map(poolAddress =>
|
|
386
|
-
(async <P>(
|
|
387
|
-
pool: P extends PlatypusPoolBase<infer S> ? P : never,
|
|
388
|
-
) => {
|
|
389
|
-
let state = pool.getState(blockNumber);
|
|
390
|
-
if (!state) {
|
|
391
|
-
state = await pool.generateState(blockNumber);
|
|
392
|
-
pool.setState(state, blockNumber);
|
|
393
|
-
}
|
|
394
|
-
if (state.params.paused) return null;
|
|
395
|
-
const [unit, ...prices] = pool.computePrices(
|
|
396
|
-
{
|
|
397
|
-
address: srcTokenAddress,
|
|
398
|
-
decimals: srcToken.decimals,
|
|
399
|
-
},
|
|
400
|
-
{
|
|
401
|
-
address: destTokenAddress,
|
|
402
|
-
decimals: destToken.decimals,
|
|
403
|
-
},
|
|
404
|
-
[getBigIntPow(srcToken.decimals), ...amounts],
|
|
405
|
-
state,
|
|
406
|
-
);
|
|
407
|
-
const ret: PoolPrices<PlatypusData> = {
|
|
408
|
-
prices,
|
|
409
|
-
unit,
|
|
410
|
-
data: {
|
|
411
|
-
pool: poolAddress,
|
|
412
|
-
},
|
|
413
|
-
poolAddresses: [poolAddress],
|
|
414
|
-
exchange: this.dexKey,
|
|
415
|
-
gasCost: 260 * 1000,
|
|
416
|
-
poolIdentifier: this.getPoolIdentifier(poolAddress),
|
|
417
|
-
};
|
|
418
|
-
return ret;
|
|
419
|
-
})(this.eventPools![poolAddress]),
|
|
420
|
-
),
|
|
421
|
-
)
|
|
422
|
-
).filter((p): p is PoolPrices<PlatypusData> => !!p);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
426
|
-
getCalldataGasCost(poolPrices: PoolPrices<PlatypusData>): number | number[] {
|
|
427
|
-
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
// Encode params required by the exchange adapter
|
|
431
|
-
// Used for multiSwap, buy & megaSwap
|
|
432
|
-
// Hint: abiCoder.encodeParameter() couls be useful
|
|
433
|
-
getAdapterParam(
|
|
434
|
-
srcToken: string,
|
|
435
|
-
destToken: string,
|
|
436
|
-
srcAmount: string,
|
|
437
|
-
destAmount: string,
|
|
438
|
-
data: PlatypusData,
|
|
439
|
-
side: SwapSide,
|
|
440
|
-
): AdapterExchangeParam {
|
|
441
|
-
return {
|
|
442
|
-
targetExchange: data.pool,
|
|
443
|
-
payload: '0x',
|
|
444
|
-
networkFee: '0',
|
|
445
|
-
};
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// Encode call data used by simpleSwap like routers
|
|
449
|
-
// Used for simpleSwap & simpleBuy
|
|
450
|
-
// Hint: this.buildSimpleParamWithoutWETHConversion
|
|
451
|
-
// could be useful
|
|
452
|
-
async getSimpleParam(
|
|
453
|
-
srcToken: string,
|
|
454
|
-
destToken: string,
|
|
455
|
-
srcAmount: string,
|
|
456
|
-
destAmount: string,
|
|
457
|
-
data: PlatypusData,
|
|
458
|
-
side: SwapSide,
|
|
459
|
-
): Promise<SimpleExchangeParam> {
|
|
460
|
-
return this.buildSimpleParamWithoutWETHConversion(
|
|
461
|
-
srcToken,
|
|
462
|
-
srcAmount,
|
|
463
|
-
destToken,
|
|
464
|
-
destAmount,
|
|
465
|
-
isETHAddress(srcToken)
|
|
466
|
-
? Platypus.avaxPoolInterface.encodeFunctionData('swapFromETH', [
|
|
467
|
-
destToken,
|
|
468
|
-
1,
|
|
469
|
-
this.augustusAddress,
|
|
470
|
-
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
471
|
-
])
|
|
472
|
-
: isETHAddress(destToken)
|
|
473
|
-
? Platypus.avaxPoolInterface.encodeFunctionData('swapToETH', [
|
|
474
|
-
srcToken,
|
|
475
|
-
srcAmount,
|
|
476
|
-
1,
|
|
477
|
-
this.augustusAddress,
|
|
478
|
-
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
479
|
-
])
|
|
480
|
-
: Platypus.poolInterface.encodeFunctionData('swap', [
|
|
481
|
-
srcToken,
|
|
482
|
-
destToken,
|
|
483
|
-
srcAmount,
|
|
484
|
-
1,
|
|
485
|
-
this.augustusAddress,
|
|
486
|
-
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
487
|
-
]),
|
|
488
|
-
data.pool,
|
|
489
|
-
);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
getDexParam(
|
|
493
|
-
srcToken: Address,
|
|
494
|
-
destToken: Address,
|
|
495
|
-
srcAmount: NumberAsString,
|
|
496
|
-
destAmount: NumberAsString,
|
|
497
|
-
recipient: Address,
|
|
498
|
-
data: PlatypusData,
|
|
499
|
-
side: SwapSide,
|
|
500
|
-
): DexExchangeParam {
|
|
501
|
-
const iface = isETHAddress(srcToken)
|
|
502
|
-
? Platypus.avaxPoolInterface
|
|
503
|
-
: isETHAddress(destToken)
|
|
504
|
-
? Platypus.avaxPoolInterface
|
|
505
|
-
: Platypus.poolInterface;
|
|
506
|
-
|
|
507
|
-
const swapFunction = isETHAddress(srcToken)
|
|
508
|
-
? 'swapFromETH'
|
|
509
|
-
: isETHAddress(destToken)
|
|
510
|
-
? 'swapToETH'
|
|
511
|
-
: 'swap';
|
|
512
|
-
|
|
513
|
-
const swapData = isETHAddress(srcToken)
|
|
514
|
-
? iface.encodeFunctionData(swapFunction, [
|
|
515
|
-
destToken,
|
|
516
|
-
1,
|
|
517
|
-
recipient,
|
|
518
|
-
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
519
|
-
])
|
|
520
|
-
: isETHAddress(destToken)
|
|
521
|
-
? iface.encodeFunctionData(swapFunction, [
|
|
522
|
-
srcToken,
|
|
523
|
-
srcAmount,
|
|
524
|
-
1,
|
|
525
|
-
recipient,
|
|
526
|
-
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
527
|
-
])
|
|
528
|
-
: iface.encodeFunctionData(swapFunction, [
|
|
529
|
-
srcToken,
|
|
530
|
-
destToken,
|
|
531
|
-
srcAmount,
|
|
532
|
-
1,
|
|
533
|
-
recipient,
|
|
534
|
-
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
535
|
-
]);
|
|
536
|
-
|
|
537
|
-
return {
|
|
538
|
-
needWrapNative: this.needWrapNative,
|
|
539
|
-
dexFuncHasRecipient: true,
|
|
540
|
-
exchangeData: swapData,
|
|
541
|
-
targetExchange: data.pool,
|
|
542
|
-
returnAmountPos:
|
|
543
|
-
side === SwapSide.SELL
|
|
544
|
-
? extractReturnAmountPosition(iface, swapFunction, 'actualToAmount')
|
|
545
|
-
: undefined,
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
// This is called once before getTopPoolsForToken is
|
|
550
|
-
// called for multiple tokens. This can be helpful to
|
|
551
|
-
// update common state required for calculating
|
|
552
|
-
// getTopPoolsForToken. It is optional for a DEX
|
|
553
|
-
// to implement this
|
|
554
|
-
async updatePoolState(): Promise<void> {
|
|
555
|
-
const blockNumber = await this.dexHelper.web3Provider.eth.getBlockNumber();
|
|
556
|
-
await this.init(blockNumber);
|
|
557
|
-
if (!this.cfgInfo)
|
|
558
|
-
throw new Error(
|
|
559
|
-
'updatePoolState: Platypus cfgInfo still null after init',
|
|
560
|
-
);
|
|
561
|
-
|
|
562
|
-
// All tokens are USD stablecoins so to estimate liquidity can just add
|
|
563
|
-
// the cash balances of all the tokens
|
|
564
|
-
const poolLiquidityUSD: { [poolAddress: string]: number } = {};
|
|
565
|
-
let inputs: MultiCallInput[] = [];
|
|
566
|
-
for (const poolAddress of this.cfgInfo.poolAddresses) {
|
|
567
|
-
for (const tokenAddress of this.cfgInfo.pools[poolAddress]
|
|
568
|
-
.tokenAddresses) {
|
|
569
|
-
inputs.push({
|
|
570
|
-
target:
|
|
571
|
-
this.cfgInfo.pools[poolAddress].tokens[tokenAddress].assetAddress,
|
|
572
|
-
callData: Platypus.assetInterface.encodeFunctionData('cash'),
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
const returnData = (
|
|
577
|
-
await this.dexHelper.multiContract.methods
|
|
578
|
-
.aggregate(inputs)
|
|
579
|
-
.call({}, blockNumber)
|
|
580
|
-
).returnData;
|
|
581
|
-
const usdPromises = [];
|
|
582
|
-
let i = 0;
|
|
583
|
-
for (const poolAddress of this.cfgInfo.poolAddresses) {
|
|
584
|
-
for (const tokenAddress of this.cfgInfo.pools[poolAddress]
|
|
585
|
-
.tokenAddresses) {
|
|
586
|
-
usdPromises.push(
|
|
587
|
-
this.dexHelper.getTokenUSDPrice(
|
|
588
|
-
{
|
|
589
|
-
address: tokenAddress,
|
|
590
|
-
decimals:
|
|
591
|
-
this.cfgInfo.pools[poolAddress].tokens[tokenAddress]
|
|
592
|
-
.tokenDecimals,
|
|
593
|
-
},
|
|
594
|
-
BigInt(
|
|
595
|
-
Platypus.assetInterface
|
|
596
|
-
.decodeFunctionResult('cash', returnData[i++])[0]
|
|
597
|
-
.toString(),
|
|
598
|
-
),
|
|
599
|
-
),
|
|
600
|
-
);
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
const usdValues = await Promise.all(usdPromises);
|
|
604
|
-
i = 0;
|
|
605
|
-
for (const poolAddress of this.cfgInfo.poolAddresses) {
|
|
606
|
-
poolLiquidityUSD[poolAddress] = 0;
|
|
607
|
-
for (const tokenAddress of this.cfgInfo.pools[poolAddress]
|
|
608
|
-
.tokenAddresses) {
|
|
609
|
-
poolLiquidityUSD[poolAddress] += usdValues[i++];
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
this.poolLiquidityUSD = poolLiquidityUSD;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
// Returns list of top pools based on liquidity. Max
|
|
616
|
-
// limit number pools should be returned.
|
|
617
|
-
async getTopPoolsForToken(
|
|
618
|
-
tokenAddress: Address,
|
|
619
|
-
limit: number,
|
|
620
|
-
): Promise<PoolLiquidity[]> {
|
|
621
|
-
if (!this.cfgInfo || !this.poolLiquidityUSD) await this.updatePoolState();
|
|
622
|
-
tokenAddress = tokenAddress.toLowerCase();
|
|
623
|
-
const pools = this.cfgInfo!.poolAddresses.filter(
|
|
624
|
-
poolAddress => !!this.cfgInfo!.pools[poolAddress].tokens[tokenAddress],
|
|
625
|
-
);
|
|
626
|
-
pools.sort((a, b) => this.poolLiquidityUSD![b] - this.poolLiquidityUSD![a]);
|
|
627
|
-
return pools.slice(0, limit).map(poolAddress => ({
|
|
628
|
-
exchange: this.dexKey,
|
|
629
|
-
address: poolAddress,
|
|
630
|
-
connectorTokens: this.cfgInfo!.pools[poolAddress].tokenAddresses.filter(
|
|
631
|
-
t => t !== tokenAddress,
|
|
632
|
-
).map(t => ({
|
|
633
|
-
decimals: this.cfgInfo!.pools[poolAddress].tokens[t].tokenDecimals,
|
|
634
|
-
address: t,
|
|
635
|
-
})),
|
|
636
|
-
liquidityUSD: this.poolLiquidityUSD![poolAddress],
|
|
637
|
-
}));
|
|
638
|
-
}
|
|
639
|
-
}
|