@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,668 +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, MAX_INT, MAX_UINT } from '../../constants';
|
|
16
|
-
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
17
|
-
import { getDexKeysWithNetwork, getBigIntPow } from '../../utils';
|
|
18
|
-
import { IDex } from '../../dex/idex';
|
|
19
|
-
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
20
|
-
import { ChainLinkSubscriber } from '../../lib/chainlink';
|
|
21
|
-
import {
|
|
22
|
-
DexParams,
|
|
23
|
-
SwaapV1Data,
|
|
24
|
-
SwaapV1PoolState,
|
|
25
|
-
SubgraphPoolBase,
|
|
26
|
-
SwaapV1ProxySwapArguments,
|
|
27
|
-
SwaapV1PoolSwapArguments,
|
|
28
|
-
SwaapV1Swap,
|
|
29
|
-
} from './types';
|
|
30
|
-
import { SimpleExchange } from '../simple-exchange';
|
|
31
|
-
import {
|
|
32
|
-
SwaapV1Config,
|
|
33
|
-
Adapters,
|
|
34
|
-
SUBGRAPH_FETCH_ALL_POOOLS_RQ,
|
|
35
|
-
SUBGRAPH_TIMEOUT,
|
|
36
|
-
MAX_POOL_CNT,
|
|
37
|
-
POOL_CACHE_TTL,
|
|
38
|
-
MAX_GAS_COST_ESTIMATION,
|
|
39
|
-
RECCURING_POOL_FETCH_INTERVAL_MS,
|
|
40
|
-
} from './config';
|
|
41
|
-
import { SwaapV1Pool } from './swaap-v1-pool';
|
|
42
|
-
import PoolABI from '../../abi/swaap-v1/pool.json';
|
|
43
|
-
import { PoolQuotations } from './libraries/PoolQuotations';
|
|
44
|
-
import { extractReturnAmountPosition } from '../../executor/utils';
|
|
45
|
-
|
|
46
|
-
export class SwaapV1 extends SimpleExchange implements IDex<SwaapV1Data> {
|
|
47
|
-
static readonly poolInterface = new Interface(PoolABI);
|
|
48
|
-
|
|
49
|
-
protected config: DexParams;
|
|
50
|
-
protected subgraphURL: string;
|
|
51
|
-
protected exchangeProxy: string;
|
|
52
|
-
|
|
53
|
-
protected eventPools: { [poolAddress: string]: SwaapV1Pool } = {};
|
|
54
|
-
|
|
55
|
-
readonly hasConstantPriceLargeAmounts = false;
|
|
56
|
-
readonly isFeeOnTransferSupported: boolean = false;
|
|
57
|
-
|
|
58
|
-
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
59
|
-
getDexKeysWithNetwork(SwaapV1Config);
|
|
60
|
-
|
|
61
|
-
logger: Logger;
|
|
62
|
-
|
|
63
|
-
constructor(
|
|
64
|
-
readonly network: Network,
|
|
65
|
-
readonly dexKey: string,
|
|
66
|
-
readonly dexHelper: IDexHelper,
|
|
67
|
-
protected adapters = Adapters[network], // TODO: add any additional optional params to support other fork DEXes
|
|
68
|
-
) {
|
|
69
|
-
super(dexHelper, dexKey);
|
|
70
|
-
this.config = SwaapV1Config[dexKey][network];
|
|
71
|
-
this.logger = dexHelper.getLogger(`${dexKey}-${network}`);
|
|
72
|
-
this.subgraphURL = this.config.subgraphURL;
|
|
73
|
-
this.exchangeProxy = this.config.exchangeProxy;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Initialize pricing is called once in the start of
|
|
77
|
-
// pricing service. It is intended to setup the integration
|
|
78
|
-
// for pricing requests. It is optional for a DEX to
|
|
79
|
-
// implement this function
|
|
80
|
-
async initializePricing(blockNumber: number) {
|
|
81
|
-
await this.getPools(blockNumber, true);
|
|
82
|
-
setInterval(
|
|
83
|
-
() => this.getPools(null, false),
|
|
84
|
-
RECCURING_POOL_FETCH_INTERVAL_MS,
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async getPools(_blockNumber: number | null, init: boolean) {
|
|
89
|
-
const blockNumber = _blockNumber
|
|
90
|
-
? _blockNumber
|
|
91
|
-
: await this.dexHelper.provider.getBlockNumber();
|
|
92
|
-
const allPools = await this.fetchAllSubgraphPools(blockNumber);
|
|
93
|
-
|
|
94
|
-
await SwaapV1.initPools(
|
|
95
|
-
this.dexHelper,
|
|
96
|
-
blockNumber,
|
|
97
|
-
Object.values(allPools),
|
|
98
|
-
);
|
|
99
|
-
if (!allPools)
|
|
100
|
-
if (init) {
|
|
101
|
-
throw new Error(
|
|
102
|
-
'initializePricing: SwaapV1 cfgInfo still null after init',
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
for (const poolConfig of allPools.values()) {
|
|
106
|
-
if (
|
|
107
|
-
init ||
|
|
108
|
-
!Object.values(this.eventPools)
|
|
109
|
-
.map(e => e.id)
|
|
110
|
-
.includes(poolConfig.id)
|
|
111
|
-
) {
|
|
112
|
-
await this.addPool(poolConfig, blockNumber);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async addPool(poolConfig: SubgraphPoolBase, blockNumber: number) {
|
|
118
|
-
const pool = new SwaapV1Pool(
|
|
119
|
-
this.dexKey,
|
|
120
|
-
this.network,
|
|
121
|
-
poolConfig,
|
|
122
|
-
this.dexHelper,
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
await pool.initialize(blockNumber);
|
|
126
|
-
this.eventPools[poolConfig.id] = pool;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
130
|
-
getCalldataGasCost(poolPrices: PoolPrices<SwaapV1Data>): number | number[] {
|
|
131
|
-
// TODO: update if there is any payload in getAdapterParam
|
|
132
|
-
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Returns the list of contract adapters (name and index)
|
|
136
|
-
// for a buy/sell. Return null if there are no adapters.
|
|
137
|
-
getAdapters(side: SwapSide): { name: string; index: number }[] | null {
|
|
138
|
-
return this.adapters[side];
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
protected findPools(
|
|
142
|
-
srcTokenAddress: Address,
|
|
143
|
-
destTokenAddress: Address,
|
|
144
|
-
): Address[] {
|
|
145
|
-
if (!this.eventPools) return [];
|
|
146
|
-
return Object.values(this.eventPools)
|
|
147
|
-
.filter(poolConfig => {
|
|
148
|
-
return (
|
|
149
|
-
poolConfig.tokens.includes(srcTokenAddress) &&
|
|
150
|
-
poolConfig.tokens.includes(destTokenAddress)
|
|
151
|
-
);
|
|
152
|
-
})
|
|
153
|
-
.map(p => p.id);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
protected getPoolIdentifier(poolAddress: Address): string {
|
|
157
|
-
return `${this.dexKey}_${poolAddress}`;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Returns list of pool identifiers that can be used
|
|
161
|
-
// for a given swap. poolIdentifers must be unique
|
|
162
|
-
// across DEXes. It is recommended to use
|
|
163
|
-
// ${dexKey}_${poolAddress} as a poolIdentifier
|
|
164
|
-
async getPoolIdentifiers(
|
|
165
|
-
srcToken: Token,
|
|
166
|
-
destToken: Token,
|
|
167
|
-
side: SwapSide,
|
|
168
|
-
blockNumber: number,
|
|
169
|
-
): Promise<string[]> {
|
|
170
|
-
return this.findPools(
|
|
171
|
-
srcToken.address.toLowerCase(),
|
|
172
|
-
destToken.address.toLowerCase(),
|
|
173
|
-
).map(p => this.getPoolIdentifier(p));
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Encode params required by the exchange adapter
|
|
177
|
-
// Used for multiSwap, buy & megaSwap
|
|
178
|
-
// Hint: abiCoder.encodeParameter() couls be useful
|
|
179
|
-
getAdapterParam(
|
|
180
|
-
srcToken: string,
|
|
181
|
-
destToken: string,
|
|
182
|
-
srcAmount: string,
|
|
183
|
-
destAmount: string,
|
|
184
|
-
data: SwaapV1Data,
|
|
185
|
-
side: SwapSide,
|
|
186
|
-
): AdapterExchangeParam {
|
|
187
|
-
return {
|
|
188
|
-
targetExchange: data.pool,
|
|
189
|
-
payload: '0x',
|
|
190
|
-
networkFee: '0',
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
private getSwaapV1Param(
|
|
195
|
-
srcToken: string,
|
|
196
|
-
destToken: string,
|
|
197
|
-
srcAmount: string,
|
|
198
|
-
destAmount: string,
|
|
199
|
-
data: SwaapV1Data,
|
|
200
|
-
side: SwapSide,
|
|
201
|
-
): [SwaapV1PoolSwapArguments, string] {
|
|
202
|
-
let functionName;
|
|
203
|
-
let limitAmount;
|
|
204
|
-
let amountIn;
|
|
205
|
-
let amountOut;
|
|
206
|
-
if (side == SwapSide.SELL) {
|
|
207
|
-
functionName = 'swapExactAmountInMMM';
|
|
208
|
-
limitAmount = MAX_INT;
|
|
209
|
-
amountIn = BigInt(srcAmount);
|
|
210
|
-
amountOut = BigInt(0);
|
|
211
|
-
} else {
|
|
212
|
-
functionName = 'swapExactAmountOutMMM';
|
|
213
|
-
limitAmount = MAX_INT;
|
|
214
|
-
amountIn = BigInt(MAX_UINT);
|
|
215
|
-
amountOut = BigInt(destAmount);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const params: SwaapV1PoolSwapArguments = [
|
|
219
|
-
srcToken,
|
|
220
|
-
BigInt(amountIn),
|
|
221
|
-
destToken,
|
|
222
|
-
BigInt(amountOut),
|
|
223
|
-
BigInt(MAX_UINT),
|
|
224
|
-
];
|
|
225
|
-
|
|
226
|
-
return [params, functionName];
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Encode call data used by simpleSwap like routers
|
|
230
|
-
// Used for simpleSwap & simpleBuy
|
|
231
|
-
// Hint: this.buildSimpleParamWithoutWETHConversion
|
|
232
|
-
// could be useful
|
|
233
|
-
async getSimpleParam(
|
|
234
|
-
srcToken: string,
|
|
235
|
-
destToken: string,
|
|
236
|
-
srcAmount: string,
|
|
237
|
-
destAmount: string,
|
|
238
|
-
data: SwaapV1Data,
|
|
239
|
-
side: SwapSide,
|
|
240
|
-
): Promise<SimpleExchangeParam> {
|
|
241
|
-
const [params, functionName] = this.getSwaapV1Param(
|
|
242
|
-
srcToken,
|
|
243
|
-
destToken,
|
|
244
|
-
srcAmount,
|
|
245
|
-
destAmount,
|
|
246
|
-
data,
|
|
247
|
-
side,
|
|
248
|
-
);
|
|
249
|
-
const swapData = SwaapV1.poolInterface.encodeFunctionData(
|
|
250
|
-
functionName,
|
|
251
|
-
params,
|
|
252
|
-
);
|
|
253
|
-
return this.buildSimpleParamWithoutWETHConversion(
|
|
254
|
-
srcToken,
|
|
255
|
-
srcAmount,
|
|
256
|
-
destToken,
|
|
257
|
-
destAmount,
|
|
258
|
-
swapData,
|
|
259
|
-
data.pool,
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
getDexParam(
|
|
264
|
-
srcToken: Address,
|
|
265
|
-
destToken: Address,
|
|
266
|
-
srcAmount: NumberAsString,
|
|
267
|
-
destAmount: NumberAsString,
|
|
268
|
-
recipient: Address,
|
|
269
|
-
data: SwaapV1Data,
|
|
270
|
-
side: SwapSide,
|
|
271
|
-
): DexExchangeParam {
|
|
272
|
-
const [params, functionName] = this.getSwaapV1Param(
|
|
273
|
-
srcToken,
|
|
274
|
-
destToken,
|
|
275
|
-
srcAmount,
|
|
276
|
-
destAmount,
|
|
277
|
-
data,
|
|
278
|
-
side,
|
|
279
|
-
);
|
|
280
|
-
const swapData = SwaapV1.poolInterface.encodeFunctionData(
|
|
281
|
-
functionName,
|
|
282
|
-
params,
|
|
283
|
-
);
|
|
284
|
-
|
|
285
|
-
return {
|
|
286
|
-
needWrapNative: this.needWrapNative,
|
|
287
|
-
dexFuncHasRecipient: false,
|
|
288
|
-
exchangeData: swapData,
|
|
289
|
-
targetExchange: data.pool,
|
|
290
|
-
returnAmountPos:
|
|
291
|
-
side === SwapSide.SELL
|
|
292
|
-
? extractReturnAmountPosition(
|
|
293
|
-
SwaapV1.poolInterface,
|
|
294
|
-
functionName,
|
|
295
|
-
'tokenAmountOut',
|
|
296
|
-
)
|
|
297
|
-
: undefined,
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// // Returns list of top pools based on liquidity. Max
|
|
302
|
-
// // limit number pools should be returned.
|
|
303
|
-
async getTopPoolsForToken(
|
|
304
|
-
tokenAddress: Address,
|
|
305
|
-
count: number,
|
|
306
|
-
): Promise<PoolLiquidity[]> {
|
|
307
|
-
return this.getTopPoolsForTokens([tokenAddress], count, null).then(
|
|
308
|
-
pools =>
|
|
309
|
-
pools.map((pool: SubgraphPoolBase) => {
|
|
310
|
-
return {
|
|
311
|
-
exchange: this.dexKey,
|
|
312
|
-
address: pool.id.toLowerCase(),
|
|
313
|
-
connectorTokens: pool.tokens.reduce(
|
|
314
|
-
(
|
|
315
|
-
acc: Token[],
|
|
316
|
-
{ decimals, address }: { decimals: number; address: string },
|
|
317
|
-
) => {
|
|
318
|
-
if (address.toLowerCase() != tokenAddress.toLowerCase()) {
|
|
319
|
-
acc.push({ decimals, address: address.toLowerCase() });
|
|
320
|
-
}
|
|
321
|
-
return acc;
|
|
322
|
-
},
|
|
323
|
-
[],
|
|
324
|
-
),
|
|
325
|
-
liquidityUSD: Number(pool.liquidityUSD),
|
|
326
|
-
};
|
|
327
|
-
}),
|
|
328
|
-
_ => [],
|
|
329
|
-
);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// // Returns list of top pools based on liquidity. Max
|
|
333
|
-
// // limit number pools should be returned.
|
|
334
|
-
async getTopPoolsForTokens(
|
|
335
|
-
tokenAddresses: Address[],
|
|
336
|
-
count: number,
|
|
337
|
-
blockNumber: number | null,
|
|
338
|
-
): Promise<SubgraphPoolBase[]> {
|
|
339
|
-
const variables = {
|
|
340
|
-
tokens: tokenAddresses,
|
|
341
|
-
count,
|
|
342
|
-
};
|
|
343
|
-
const query = `query ($tokens: [Bytes!], $count: Int) {
|
|
344
|
-
pools (first: $count, orderBy: liquidity, orderDirection: desc,
|
|
345
|
-
where: {tokensList_contains: $tokens,
|
|
346
|
-
finalized: true,
|
|
347
|
-
liquidity_gt: 0}) {
|
|
348
|
-
id
|
|
349
|
-
liquidityUSD: liquidity
|
|
350
|
-
tokens {
|
|
351
|
-
address
|
|
352
|
-
decimals
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}`;
|
|
356
|
-
const { data } = await this.dexHelper.httpRequest.post(
|
|
357
|
-
this.subgraphURL,
|
|
358
|
-
{
|
|
359
|
-
query,
|
|
360
|
-
variables,
|
|
361
|
-
},
|
|
362
|
-
SUBGRAPH_TIMEOUT,
|
|
363
|
-
);
|
|
364
|
-
|
|
365
|
-
if (!(data && data.pools))
|
|
366
|
-
throw new Error(
|
|
367
|
-
`Error_${this.dexKey}_Subgraph: couldn't fetch the pools from the subgraph`,
|
|
368
|
-
);
|
|
369
|
-
|
|
370
|
-
return data.pools.map((pool: SubgraphPoolBase) => {
|
|
371
|
-
const castedPool = SwaapV1.castSubgraphPoolBase(pool);
|
|
372
|
-
if (
|
|
373
|
-
blockNumber &&
|
|
374
|
-
!Object.values(this.eventPools)
|
|
375
|
-
.map(e => e.id)
|
|
376
|
-
.includes(castedPool.id)
|
|
377
|
-
) {
|
|
378
|
-
this.addPool(castedPool, blockNumber!);
|
|
379
|
-
}
|
|
380
|
-
return castedPool;
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
static castSubgraphPoolBase(pool: SubgraphPoolBase): SubgraphPoolBase {
|
|
385
|
-
return {
|
|
386
|
-
...pool,
|
|
387
|
-
liquidityUSD: Number(pool.liquidityUSD),
|
|
388
|
-
swapFee: Number(pool.swapFee),
|
|
389
|
-
dynamicCoverageFeesZ: Number(pool.dynamicCoverageFeesZ),
|
|
390
|
-
dynamicCoverageFeesHorizon: Number(pool.dynamicCoverageFeesHorizon),
|
|
391
|
-
priceStatisticsLookbackInSec: Number(pool.priceStatisticsLookbackInSec),
|
|
392
|
-
maxPriceUnpegRatio: Number(pool.maxPriceUnpegRatio),
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
async fetchAllSubgraphPools(
|
|
397
|
-
blockNumber: number,
|
|
398
|
-
): Promise<Map<string, SubgraphPoolBase>> {
|
|
399
|
-
const cacheKey = 'AllSubgraphPools';
|
|
400
|
-
const cachedPools = await this.dexHelper.cache.get(
|
|
401
|
-
this.dexKey,
|
|
402
|
-
this.network,
|
|
403
|
-
cacheKey,
|
|
404
|
-
);
|
|
405
|
-
if (cachedPools) {
|
|
406
|
-
const allPools = JSON.parse(cachedPools);
|
|
407
|
-
this.logger.info(
|
|
408
|
-
`Got ${allPools.length} ${this.dexKey}_${this.network} pools from cache`,
|
|
409
|
-
);
|
|
410
|
-
return allPools;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
this.logger.info(
|
|
414
|
-
`Fetching ${this.dexKey}_${this.network} Pools from subgraph`,
|
|
415
|
-
);
|
|
416
|
-
const variables = {
|
|
417
|
-
count: MAX_POOL_CNT,
|
|
418
|
-
};
|
|
419
|
-
const { data } = await this.dexHelper.httpRequest.post(
|
|
420
|
-
this.subgraphURL,
|
|
421
|
-
{ query: SUBGRAPH_FETCH_ALL_POOOLS_RQ, variables },
|
|
422
|
-
SUBGRAPH_TIMEOUT,
|
|
423
|
-
);
|
|
424
|
-
if (!(data && data.pools))
|
|
425
|
-
throw new Error('Unable to fetch pools from the subgraph');
|
|
426
|
-
|
|
427
|
-
this.dexHelper.cache.setex(
|
|
428
|
-
this.dexKey,
|
|
429
|
-
this.network,
|
|
430
|
-
cacheKey,
|
|
431
|
-
POOL_CACHE_TTL,
|
|
432
|
-
JSON.stringify(data.pools),
|
|
433
|
-
);
|
|
434
|
-
const allPools = await SwaapV1.initPools(
|
|
435
|
-
this.dexHelper,
|
|
436
|
-
blockNumber,
|
|
437
|
-
data.pools,
|
|
438
|
-
);
|
|
439
|
-
|
|
440
|
-
this.logger.info(
|
|
441
|
-
`Got ${allPools.size} ${this.dexKey}_${this.network} pools from subgraph`,
|
|
442
|
-
);
|
|
443
|
-
return allPools;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
static async initPools(
|
|
447
|
-
dexHelper: IDexHelper,
|
|
448
|
-
blockNumber: number,
|
|
449
|
-
allPools: SubgraphPoolBase[],
|
|
450
|
-
): Promise<Map<string, SubgraphPoolBase>> {
|
|
451
|
-
// aggregators
|
|
452
|
-
let inputs: any = allPools
|
|
453
|
-
.map((pool: SubgraphPoolBase) => {
|
|
454
|
-
return pool.tokens.map(t =>
|
|
455
|
-
ChainLinkSubscriber.getReadAggregatorMultiCallInput(
|
|
456
|
-
t.oracleInitialState.proxy,
|
|
457
|
-
),
|
|
458
|
-
);
|
|
459
|
-
})
|
|
460
|
-
.flat();
|
|
461
|
-
let returnData = (
|
|
462
|
-
await dexHelper.multiContract.methods
|
|
463
|
-
.aggregate(inputs)
|
|
464
|
-
.call({}, blockNumber)
|
|
465
|
-
).returnData;
|
|
466
|
-
let idx: number = 0;
|
|
467
|
-
allPools.forEach((pool: SubgraphPoolBase) => {
|
|
468
|
-
pool.tokens.forEach(token => {
|
|
469
|
-
const aggregator: Address = ChainLinkSubscriber.proxyInterface
|
|
470
|
-
.decodeFunctionResult('aggregator', returnData[idx++])[0]
|
|
471
|
-
.toLowerCase();
|
|
472
|
-
token.oracleInitialState.aggregator = aggregator;
|
|
473
|
-
});
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
return allPools.reduce(
|
|
477
|
-
(acc: Map<string, SubgraphPoolBase>, pool: SubgraphPoolBase) => {
|
|
478
|
-
return acc.set(pool.id, {
|
|
479
|
-
...SwaapV1.castSubgraphPoolBase(pool),
|
|
480
|
-
});
|
|
481
|
-
},
|
|
482
|
-
new Map<string, SubgraphPoolBase>(),
|
|
483
|
-
);
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
getPricesPool(
|
|
487
|
-
from: Address,
|
|
488
|
-
to: Address,
|
|
489
|
-
unitVolume: bigint,
|
|
490
|
-
amounts: bigint[],
|
|
491
|
-
side: SwapSide,
|
|
492
|
-
state: SwaapV1PoolState,
|
|
493
|
-
currentTimestamp: bigint,
|
|
494
|
-
): [bigint, bigint[]] {
|
|
495
|
-
if (side === SwapSide.SELL) {
|
|
496
|
-
let unitAmountOut: bigint;
|
|
497
|
-
try {
|
|
498
|
-
unitAmountOut = PoolQuotations.getAmountOutGivenInMMM(
|
|
499
|
-
state.liquidities[from],
|
|
500
|
-
state.oracles[from],
|
|
501
|
-
unitVolume,
|
|
502
|
-
state.liquidities[to],
|
|
503
|
-
state.oracles[to],
|
|
504
|
-
state.parameters,
|
|
505
|
-
currentTimestamp,
|
|
506
|
-
);
|
|
507
|
-
} catch (e) {
|
|
508
|
-
this.logger.warn(
|
|
509
|
-
`Failed to get historical round data: (unit: ${unitVolume})`,
|
|
510
|
-
e,
|
|
511
|
-
);
|
|
512
|
-
unitAmountOut = 0n;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
const amountsOut: bigint[] = amounts.map(amountIn => {
|
|
516
|
-
try {
|
|
517
|
-
return PoolQuotations.getAmountOutGivenInMMM(
|
|
518
|
-
state.liquidities[from],
|
|
519
|
-
state.oracles[from],
|
|
520
|
-
amountIn,
|
|
521
|
-
state.liquidities[to],
|
|
522
|
-
state.oracles[to],
|
|
523
|
-
state.parameters,
|
|
524
|
-
currentTimestamp,
|
|
525
|
-
);
|
|
526
|
-
} catch (e) {
|
|
527
|
-
return 0n;
|
|
528
|
-
}
|
|
529
|
-
});
|
|
530
|
-
|
|
531
|
-
return [unitAmountOut, amountsOut];
|
|
532
|
-
} else {
|
|
533
|
-
let unitAmountIn;
|
|
534
|
-
try {
|
|
535
|
-
unitAmountIn = PoolQuotations.getAmountInGivenOutMMM(
|
|
536
|
-
state.liquidities[from],
|
|
537
|
-
state.oracles[from],
|
|
538
|
-
state.liquidities[to],
|
|
539
|
-
state.oracles[to],
|
|
540
|
-
unitVolume,
|
|
541
|
-
state.parameters,
|
|
542
|
-
currentTimestamp,
|
|
543
|
-
);
|
|
544
|
-
} catch (e) {
|
|
545
|
-
unitAmountIn = BigInt(MAX_UINT);
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
const amountsIn = amounts.map(amountOut => {
|
|
549
|
-
try {
|
|
550
|
-
return PoolQuotations.getAmountInGivenOutMMM(
|
|
551
|
-
state.liquidities[from],
|
|
552
|
-
state.oracles[from],
|
|
553
|
-
state.liquidities[to],
|
|
554
|
-
state.oracles[to],
|
|
555
|
-
amountOut,
|
|
556
|
-
state.parameters,
|
|
557
|
-
currentTimestamp,
|
|
558
|
-
);
|
|
559
|
-
} catch (e) {
|
|
560
|
-
return BigInt(MAX_UINT);
|
|
561
|
-
}
|
|
562
|
-
});
|
|
563
|
-
return [unitAmountIn, amountsIn];
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
// Returns pool prices for amounts.
|
|
568
|
-
// If limitPools is defined only pools in limitPools
|
|
569
|
-
// should be used. If limitPools is undefined then
|
|
570
|
-
// any pools can be used.
|
|
571
|
-
getPricesVolume(
|
|
572
|
-
_from: Token,
|
|
573
|
-
_to: Token,
|
|
574
|
-
amounts: bigint[],
|
|
575
|
-
side: SwapSide,
|
|
576
|
-
blockNumber: number,
|
|
577
|
-
limitPools?: string[],
|
|
578
|
-
): Promise<null | ExchangePrices<SwaapV1Data>> {
|
|
579
|
-
return this.getPricesVolumeLogic(
|
|
580
|
-
_from,
|
|
581
|
-
_to,
|
|
582
|
-
amounts,
|
|
583
|
-
side,
|
|
584
|
-
blockNumber,
|
|
585
|
-
null,
|
|
586
|
-
limitPools,
|
|
587
|
-
);
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
async getPricesVolumeLogic(
|
|
591
|
-
_from: Token,
|
|
592
|
-
_to: Token,
|
|
593
|
-
amounts: bigint[],
|
|
594
|
-
side: SwapSide,
|
|
595
|
-
blockNumber: number,
|
|
596
|
-
_currentTimeStamp: bigint | null,
|
|
597
|
-
limitPools?: string[],
|
|
598
|
-
): Promise<null | ExchangePrices<SwaapV1Data>> {
|
|
599
|
-
const from = this.dexHelper.config.wrapETH(_from);
|
|
600
|
-
const to = this.dexHelper.config.wrapETH(_to);
|
|
601
|
-
|
|
602
|
-
const srcTokenAddress = from.address.toLowerCase();
|
|
603
|
-
const destTokenAddress = to.address.toLowerCase();
|
|
604
|
-
|
|
605
|
-
const topPools: Address[] = this.findPools(
|
|
606
|
-
srcTokenAddress,
|
|
607
|
-
destTokenAddress,
|
|
608
|
-
);
|
|
609
|
-
|
|
610
|
-
const allowedPools = limitPools
|
|
611
|
-
? topPools.filter((p: Address) =>
|
|
612
|
-
limitPools.includes(`${this.dexKey}_${p.toLowerCase()}`),
|
|
613
|
-
)
|
|
614
|
-
: topPools;
|
|
615
|
-
|
|
616
|
-
if (!allowedPools.length) return null;
|
|
617
|
-
|
|
618
|
-
const unitVolume = getBigIntPow(
|
|
619
|
-
(side === SwapSide.SELL ? from : to).decimals,
|
|
620
|
-
);
|
|
621
|
-
|
|
622
|
-
if (srcTokenAddress === destTokenAddress) return null;
|
|
623
|
-
const currentTimestamp =
|
|
624
|
-
_currentTimeStamp || BigInt(Math.floor(Date.now() / 1000)); // the on-chain pricing logic is not too much sensitive to that value
|
|
625
|
-
return await Promise.all(
|
|
626
|
-
allowedPools.map(async poolAddress => {
|
|
627
|
-
let state = this.eventPools[poolAddress].getState(blockNumber);
|
|
628
|
-
if (!state) {
|
|
629
|
-
state = await this.eventPools[poolAddress].generateState(blockNumber);
|
|
630
|
-
}
|
|
631
|
-
let [unit, prices] = this.getPricesPool(
|
|
632
|
-
from.address,
|
|
633
|
-
to.address,
|
|
634
|
-
unitVolume,
|
|
635
|
-
amounts,
|
|
636
|
-
side,
|
|
637
|
-
state,
|
|
638
|
-
currentTimestamp,
|
|
639
|
-
);
|
|
640
|
-
|
|
641
|
-
if (unit === 0n) {
|
|
642
|
-
// If we didn't fulfill unit amount, scale up the latest amount with a positive price till unit
|
|
643
|
-
let i = prices.length - 1;
|
|
644
|
-
let largestAmountPositivePrice = prices.slice(i)[0];
|
|
645
|
-
while (largestAmountPositivePrice == 0n && i > 0) {
|
|
646
|
-
--i;
|
|
647
|
-
largestAmountPositivePrice = prices.slice(i)[0];
|
|
648
|
-
}
|
|
649
|
-
if (largestAmountPositivePrice > 0n) {
|
|
650
|
-
unit =
|
|
651
|
-
(unitVolume * largestAmountPositivePrice) / amounts.slice(i)[0];
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
return {
|
|
655
|
-
prices,
|
|
656
|
-
unit,
|
|
657
|
-
data: {
|
|
658
|
-
pool: poolAddress,
|
|
659
|
-
},
|
|
660
|
-
poolAddresses: [poolAddress],
|
|
661
|
-
exchange: this.dexKey,
|
|
662
|
-
gasCost: MAX_GAS_COST_ESTIMATION,
|
|
663
|
-
poolIdentifier: this.getPoolIdentifier(poolAddress),
|
|
664
|
-
};
|
|
665
|
-
}),
|
|
666
|
-
);
|
|
667
|
-
}
|
|
668
|
-
}
|