@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,919 +0,0 @@
|
|
|
1
|
-
import { DeepReadonly } from 'ts-essentials';
|
|
2
|
-
import { BlockHeader } from '../../types';
|
|
3
|
-
import { Address } from '../../types';
|
|
4
|
-
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
5
|
-
import {
|
|
6
|
-
SwaapV1PoolState,
|
|
7
|
-
SubgraphPoolBase,
|
|
8
|
-
SwaapV1PoolParameters,
|
|
9
|
-
SwaapV1PoolLiquidities,
|
|
10
|
-
SwaapV1PoolOracles,
|
|
11
|
-
OracleInitialData,
|
|
12
|
-
ChainLinkData,
|
|
13
|
-
} from './types';
|
|
14
|
-
import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
15
|
-
import { Log, MultiCallInput, MultiCallOutput } from '../../types';
|
|
16
|
-
import PoolABI from '../../abi/swaap-v1/pool.json';
|
|
17
|
-
import ProxyABI from '../../abi/chainlink.json';
|
|
18
|
-
import Erc20ABI from '../../abi/erc20.json';
|
|
19
|
-
import { Interface } from '@ethersproject/abi';
|
|
20
|
-
import { isHexString } from '@ethersproject/bytes';
|
|
21
|
-
|
|
22
|
-
export class SwaapV1Pool extends StatefulEventSubscriber<SwaapV1PoolState> {
|
|
23
|
-
static readonly poolInterface = new Interface(PoolABI);
|
|
24
|
-
static readonly proxyInterface = new Interface(ProxyABI);
|
|
25
|
-
static readonly erc20Interface = new Interface(Erc20ABI);
|
|
26
|
-
// LOG_CALL Event topics 0
|
|
27
|
-
static readonly SWAP_FEE_TOPIC =
|
|
28
|
-
'0x34e1990700000000000000000000000000000000000000000000000000000000';
|
|
29
|
-
static readonly LB_IN_ROUND_TOPIC =
|
|
30
|
-
'0x3cc3396000000000000000000000000000000000000000000000000000000000';
|
|
31
|
-
static readonly LB_STEP_IN_ROUND_TOPIC =
|
|
32
|
-
'0x045dbae000000000000000000000000000000000000000000000000000000000';
|
|
33
|
-
static readonly Z_TOPIC =
|
|
34
|
-
'0x3c515d9900000000000000000000000000000000000000000000000000000000';
|
|
35
|
-
static readonly HORIZON_TOPIC =
|
|
36
|
-
'0x314d204f00000000000000000000000000000000000000000000000000000000';
|
|
37
|
-
static readonly LB_IN_SEC_TOPIC =
|
|
38
|
-
'0x538e285c00000000000000000000000000000000000000000000000000000000';
|
|
39
|
-
static readonly MAX_UNPEG_TOPIC =
|
|
40
|
-
'0xacb21b3100000000000000000000000000000000000000000000000000000000';
|
|
41
|
-
|
|
42
|
-
static readonly ANSWER_UPDATED_TOPIC =
|
|
43
|
-
SwaapV1Pool.proxyInterface.getEventTopic('AnswerUpdated');
|
|
44
|
-
public id: Address;
|
|
45
|
-
public oracleTokenMap: { [oracleAddress: Address]: Address };
|
|
46
|
-
public tokens: Address[];
|
|
47
|
-
|
|
48
|
-
constructor(
|
|
49
|
-
dexKey: string,
|
|
50
|
-
network: number,
|
|
51
|
-
protected pool: SubgraphPoolBase,
|
|
52
|
-
protected dexHelper: IDexHelper,
|
|
53
|
-
) {
|
|
54
|
-
super(
|
|
55
|
-
dexKey,
|
|
56
|
-
pool.id,
|
|
57
|
-
dexHelper,
|
|
58
|
-
dexHelper.getLogger(`${dexKey}-${network}-${pool.id}`),
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
this.id = pool.id;
|
|
62
|
-
this.tokens = pool.tokens.map(t => t.address);
|
|
63
|
-
|
|
64
|
-
this.addressesSubscribed = [pool.id];
|
|
65
|
-
this.oracleTokenMap = pool.tokens.reduce((acc, t) => {
|
|
66
|
-
this.addressesSubscribed.push(
|
|
67
|
-
t.oracleInitialState.aggregator.toLowerCase(),
|
|
68
|
-
);
|
|
69
|
-
return {
|
|
70
|
-
...acc,
|
|
71
|
-
[t.oracleInitialState.aggregator.toLowerCase()]: t.address,
|
|
72
|
-
};
|
|
73
|
-
}, {});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Function which transforms the given state for the given log event.
|
|
77
|
-
// If the provided log does not affect the state, return null.
|
|
78
|
-
public async processLog(
|
|
79
|
-
state: DeepReadonly<SwaapV1PoolState>,
|
|
80
|
-
log: Readonly<Log>,
|
|
81
|
-
blockHeader: Readonly<BlockHeader>,
|
|
82
|
-
): Promise<DeepReadonly<SwaapV1PoolState> | null> {
|
|
83
|
-
try {
|
|
84
|
-
const tokenAddress = this.oracleTokenMap[log.address.toLowerCase()];
|
|
85
|
-
|
|
86
|
-
if (tokenAddress) {
|
|
87
|
-
// log comes from a subscribed oracle
|
|
88
|
-
|
|
89
|
-
if (log.topics[0] != SwaapV1Pool.ANSWER_UPDATED_TOPIC) return null;
|
|
90
|
-
const decoded = SwaapV1Pool.proxyInterface.decodeEventLog(
|
|
91
|
-
'AnswerUpdated',
|
|
92
|
-
log.data,
|
|
93
|
-
log.topics,
|
|
94
|
-
);
|
|
95
|
-
const latestRoundId = Number(decoded.roundId.toString());
|
|
96
|
-
const latestRoundData = {
|
|
97
|
-
answer: BigInt(decoded.current.toString()),
|
|
98
|
-
timestamp: BigInt(decoded.updatedAt.toString()),
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
let previousRoundId = state.oracles[tokenAddress].latestRoundId;
|
|
102
|
-
|
|
103
|
-
if (previousRoundId == latestRoundId) {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
let updatedHistoricalState = {
|
|
108
|
-
...state.oracles[tokenAddress].historicalOracleState,
|
|
109
|
-
};
|
|
110
|
-
const roundLookbackWindow =
|
|
111
|
-
(state.parameters.priceStatisticsLookbackInRound - 1) *
|
|
112
|
-
state.parameters.priceStatisticsLookbackStepInRound;
|
|
113
|
-
|
|
114
|
-
// Case where roundIds are skipped
|
|
115
|
-
while (latestRoundId > previousRoundId + 1) {
|
|
116
|
-
delete updatedHistoricalState[previousRoundId - roundLookbackWindow];
|
|
117
|
-
updatedHistoricalState[++previousRoundId] = {
|
|
118
|
-
answer: 0n,
|
|
119
|
-
timestamp: 0n,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
delete updatedHistoricalState[previousRoundId - roundLookbackWindow];
|
|
124
|
-
updatedHistoricalState[latestRoundId] = latestRoundData;
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
...state,
|
|
128
|
-
oracles: {
|
|
129
|
-
...state.oracles,
|
|
130
|
-
[tokenAddress]: {
|
|
131
|
-
...state.oracles[tokenAddress],
|
|
132
|
-
latestRoundId: latestRoundId,
|
|
133
|
-
historicalOracleState: updatedHistoricalState,
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
} else if (this.pool.id === log.address.toLowerCase()) {
|
|
138
|
-
// log comes from the Pool
|
|
139
|
-
|
|
140
|
-
// Check if the event is anonymous or not
|
|
141
|
-
let isAnonymousEvent: boolean = true;
|
|
142
|
-
const nameOrSignatureOrTopic: string = log.topics[0];
|
|
143
|
-
if (isHexString(nameOrSignatureOrTopic)) {
|
|
144
|
-
const topichash = nameOrSignatureOrTopic.toLowerCase();
|
|
145
|
-
for (const name of Object.keys(SwaapV1Pool.poolInterface.events)) {
|
|
146
|
-
if (topichash === SwaapV1Pool.poolInterface.getEventTopic(name)) {
|
|
147
|
-
isAnonymousEvent = false;
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (isAnonymousEvent) {
|
|
154
|
-
// anonymous events
|
|
155
|
-
const topic0 = log.topics[0];
|
|
156
|
-
switch (topic0) {
|
|
157
|
-
// setSwapFee
|
|
158
|
-
case SwaapV1Pool.SWAP_FEE_TOPIC: {
|
|
159
|
-
const value = BigInt(SwaapV1Pool.getValueFromAnonymousEvent(log));
|
|
160
|
-
return {
|
|
161
|
-
...state,
|
|
162
|
-
parameters: {
|
|
163
|
-
...state.parameters,
|
|
164
|
-
swapFee: value,
|
|
165
|
-
},
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
// setPriceStatisticsLookbackInRound
|
|
169
|
-
case SwaapV1Pool.LB_IN_ROUND_TOPIC: {
|
|
170
|
-
const value = Number(SwaapV1Pool.getValueFromAnonymousEvent(log));
|
|
171
|
-
|
|
172
|
-
const oldRoundLookbackWindow =
|
|
173
|
-
(state.parameters.priceStatisticsLookbackInRound - 1) *
|
|
174
|
-
state.parameters.priceStatisticsLookbackStepInRound;
|
|
175
|
-
const newRoundLookbackWindow =
|
|
176
|
-
(value - 1) *
|
|
177
|
-
state.parameters.priceStatisticsLookbackStepInRound;
|
|
178
|
-
const tokens = Object.keys(state.oracles);
|
|
179
|
-
|
|
180
|
-
if (value > state.parameters.priceStatisticsLookbackInRound) {
|
|
181
|
-
const multiCallInputs: MultiCallInput[] = tokens
|
|
182
|
-
.map((token: Address) => {
|
|
183
|
-
return [
|
|
184
|
-
{
|
|
185
|
-
target: state.oracles[token].oraclesBindState.proxy,
|
|
186
|
-
callData:
|
|
187
|
-
SwaapV1Pool.proxyInterface.encodeFunctionData(
|
|
188
|
-
'latestRound',
|
|
189
|
-
),
|
|
190
|
-
},
|
|
191
|
-
];
|
|
192
|
-
})
|
|
193
|
-
.flat();
|
|
194
|
-
|
|
195
|
-
const multicallOutputs: MultiCallOutput[] = (
|
|
196
|
-
await this.dexHelper.multiContract.methods
|
|
197
|
-
.aggregate(multiCallInputs)
|
|
198
|
-
.call({}, blockHeader.number)
|
|
199
|
-
).returnData;
|
|
200
|
-
|
|
201
|
-
let i = 0;
|
|
202
|
-
const latestRoundIdsBN: { [key: Address]: bigint } =
|
|
203
|
-
tokens.reduce((acc, token) => {
|
|
204
|
-
return {
|
|
205
|
-
...acc,
|
|
206
|
-
[token]: BigInt(
|
|
207
|
-
SwaapV1Pool.proxyInterface
|
|
208
|
-
.decodeFunctionResult(
|
|
209
|
-
'latestRound',
|
|
210
|
-
multicallOutputs[i++],
|
|
211
|
-
)[0]
|
|
212
|
-
.toString(),
|
|
213
|
-
),
|
|
214
|
-
};
|
|
215
|
-
}, {});
|
|
216
|
-
|
|
217
|
-
const missingHistoricalData: { [key: Address]: ChainLinkData } =
|
|
218
|
-
await this.getHistoricalRoundsData(
|
|
219
|
-
tokens,
|
|
220
|
-
newRoundLookbackWindow,
|
|
221
|
-
latestRoundIdsBN,
|
|
222
|
-
state.oracles,
|
|
223
|
-
blockHeader.number,
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
const updatedOraclesData: SwaapV1PoolOracles = tokens.reduce(
|
|
227
|
-
(acc, token) => {
|
|
228
|
-
return {
|
|
229
|
-
...acc,
|
|
230
|
-
[token]: {
|
|
231
|
-
oraclesBindState: {
|
|
232
|
-
...state.oracles[token].oraclesBindState,
|
|
233
|
-
},
|
|
234
|
-
latestRoundId: state.oracles[token].latestRoundId,
|
|
235
|
-
historicalOracleState: missingHistoricalData[token],
|
|
236
|
-
},
|
|
237
|
-
};
|
|
238
|
-
},
|
|
239
|
-
{},
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
return {
|
|
243
|
-
...state,
|
|
244
|
-
parameters: {
|
|
245
|
-
...state.parameters,
|
|
246
|
-
priceStatisticsLookbackInRound: value,
|
|
247
|
-
},
|
|
248
|
-
oracles: { ...updatedOraclesData },
|
|
249
|
-
};
|
|
250
|
-
} else if (
|
|
251
|
-
value < state.parameters.priceStatisticsLookbackInRound
|
|
252
|
-
) {
|
|
253
|
-
const updatedOraclesData = tokens.reduce((acc, token) => {
|
|
254
|
-
let historicalData = {
|
|
255
|
-
...state.oracles[token].historicalOracleState,
|
|
256
|
-
};
|
|
257
|
-
let roundId =
|
|
258
|
-
state.oracles[token].latestRoundId - oldRoundLookbackWindow;
|
|
259
|
-
const endRoundId =
|
|
260
|
-
state.oracles[token].latestRoundId - newRoundLookbackWindow;
|
|
261
|
-
|
|
262
|
-
while (roundId < endRoundId) {
|
|
263
|
-
delete historicalData[roundId++];
|
|
264
|
-
}
|
|
265
|
-
return {
|
|
266
|
-
...acc,
|
|
267
|
-
[token]: {
|
|
268
|
-
oraclesBindState: {
|
|
269
|
-
...state.oracles[token].oraclesBindState,
|
|
270
|
-
},
|
|
271
|
-
latestRoundId: state.oracles[token].latestRoundId,
|
|
272
|
-
historicalOracleState: historicalData,
|
|
273
|
-
},
|
|
274
|
-
};
|
|
275
|
-
}, {});
|
|
276
|
-
|
|
277
|
-
return {
|
|
278
|
-
...state,
|
|
279
|
-
parameters: {
|
|
280
|
-
...state.parameters,
|
|
281
|
-
priceStatisticsLookbackInRound: value,
|
|
282
|
-
},
|
|
283
|
-
oracles: updatedOraclesData,
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return null;
|
|
288
|
-
}
|
|
289
|
-
// setPriceStatisticsLookbackStepInRound
|
|
290
|
-
case SwaapV1Pool.LB_STEP_IN_ROUND_TOPIC: {
|
|
291
|
-
const value = Number(SwaapV1Pool.getValueFromAnonymousEvent(log));
|
|
292
|
-
const oldRoundLookbackWindow =
|
|
293
|
-
(state.parameters.priceStatisticsLookbackInRound - 1) *
|
|
294
|
-
state.parameters.priceStatisticsLookbackStepInRound;
|
|
295
|
-
const newRoundLookbackWindow =
|
|
296
|
-
(state.parameters.priceStatisticsLookbackInRound - 1) * value;
|
|
297
|
-
const tokens = Object.keys(state.oracles);
|
|
298
|
-
|
|
299
|
-
if (value > state.parameters.priceStatisticsLookbackStepInRound) {
|
|
300
|
-
const multiCallInputs: MultiCallInput[] = tokens
|
|
301
|
-
.map((token: Address) => {
|
|
302
|
-
return [
|
|
303
|
-
{
|
|
304
|
-
target: state.oracles[token].oraclesBindState.proxy,
|
|
305
|
-
callData:
|
|
306
|
-
SwaapV1Pool.proxyInterface.encodeFunctionData(
|
|
307
|
-
'latestRound',
|
|
308
|
-
),
|
|
309
|
-
},
|
|
310
|
-
];
|
|
311
|
-
})
|
|
312
|
-
.flat();
|
|
313
|
-
|
|
314
|
-
const multicallOutputs: MultiCallOutput[] = (
|
|
315
|
-
await this.dexHelper.multiContract.methods
|
|
316
|
-
.aggregate(multiCallInputs)
|
|
317
|
-
.call({}, blockHeader.number)
|
|
318
|
-
).returnData;
|
|
319
|
-
|
|
320
|
-
let i = 0;
|
|
321
|
-
const latestRoundIdsBN: { [key: Address]: bigint } =
|
|
322
|
-
tokens.reduce((acc, token) => {
|
|
323
|
-
return {
|
|
324
|
-
...acc,
|
|
325
|
-
[token]: BigInt(
|
|
326
|
-
SwaapV1Pool.proxyInterface
|
|
327
|
-
.decodeFunctionResult(
|
|
328
|
-
'latestRound',
|
|
329
|
-
multicallOutputs[i++],
|
|
330
|
-
)[0]
|
|
331
|
-
.toString(),
|
|
332
|
-
),
|
|
333
|
-
};
|
|
334
|
-
}, {});
|
|
335
|
-
|
|
336
|
-
const missingHistoricalData: { [key: Address]: ChainLinkData } =
|
|
337
|
-
await this.getHistoricalRoundsData(
|
|
338
|
-
tokens,
|
|
339
|
-
newRoundLookbackWindow,
|
|
340
|
-
latestRoundIdsBN,
|
|
341
|
-
state.oracles,
|
|
342
|
-
blockHeader.number,
|
|
343
|
-
);
|
|
344
|
-
|
|
345
|
-
const updatedOraclesData: SwaapV1PoolOracles = tokens.reduce(
|
|
346
|
-
(acc, token) => {
|
|
347
|
-
return {
|
|
348
|
-
...acc,
|
|
349
|
-
[token]: {
|
|
350
|
-
oraclesBindState: {
|
|
351
|
-
...state.oracles[token].oraclesBindState,
|
|
352
|
-
},
|
|
353
|
-
latestRoundId: state.oracles[token].latestRoundId,
|
|
354
|
-
historicalOracleState: missingHistoricalData[token],
|
|
355
|
-
},
|
|
356
|
-
};
|
|
357
|
-
},
|
|
358
|
-
{},
|
|
359
|
-
);
|
|
360
|
-
|
|
361
|
-
return {
|
|
362
|
-
...state,
|
|
363
|
-
parameters: {
|
|
364
|
-
...state.parameters,
|
|
365
|
-
priceStatisticsLookbackStepInRound: value,
|
|
366
|
-
},
|
|
367
|
-
oracles: { ...updatedOraclesData },
|
|
368
|
-
};
|
|
369
|
-
} else if (
|
|
370
|
-
value < state.parameters.priceStatisticsLookbackStepInRound
|
|
371
|
-
) {
|
|
372
|
-
const updatedOraclesData = tokens.reduce((acc, token) => {
|
|
373
|
-
let historicalData = {
|
|
374
|
-
...state.oracles[token].historicalOracleState,
|
|
375
|
-
};
|
|
376
|
-
let roundId =
|
|
377
|
-
state.oracles[token].latestRoundId - oldRoundLookbackWindow;
|
|
378
|
-
const endRoundId =
|
|
379
|
-
state.oracles[token].latestRoundId - newRoundLookbackWindow;
|
|
380
|
-
|
|
381
|
-
while (roundId < endRoundId) {
|
|
382
|
-
delete historicalData[roundId++];
|
|
383
|
-
}
|
|
384
|
-
return {
|
|
385
|
-
...acc,
|
|
386
|
-
[token]: {
|
|
387
|
-
oraclesBindState: {
|
|
388
|
-
...state.oracles[token].oraclesBindState,
|
|
389
|
-
},
|
|
390
|
-
latestRoundId: state.oracles[token].latestRoundId,
|
|
391
|
-
historicalOracleState: historicalData,
|
|
392
|
-
},
|
|
393
|
-
};
|
|
394
|
-
}, {});
|
|
395
|
-
|
|
396
|
-
return {
|
|
397
|
-
...state,
|
|
398
|
-
parameters: {
|
|
399
|
-
...state.parameters,
|
|
400
|
-
priceStatisticsLookbackStepInRound: value,
|
|
401
|
-
},
|
|
402
|
-
oracles: updatedOraclesData,
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
return {
|
|
407
|
-
...state,
|
|
408
|
-
parameters: {
|
|
409
|
-
...state.parameters,
|
|
410
|
-
priceStatisticsLookbackStepInRound: value,
|
|
411
|
-
},
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
// setDynamicCoverageFeesZ
|
|
415
|
-
case SwaapV1Pool.Z_TOPIC: {
|
|
416
|
-
const value = BigInt(SwaapV1Pool.getValueFromAnonymousEvent(log));
|
|
417
|
-
return {
|
|
418
|
-
...state,
|
|
419
|
-
parameters: {
|
|
420
|
-
...state.parameters,
|
|
421
|
-
dynamicCoverageFeesZ: value,
|
|
422
|
-
},
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
// setDynamicCoverageFeesHorizon
|
|
426
|
-
case SwaapV1Pool.HORIZON_TOPIC: {
|
|
427
|
-
const value = BigInt(SwaapV1Pool.getValueFromAnonymousEvent(log));
|
|
428
|
-
return {
|
|
429
|
-
...state,
|
|
430
|
-
parameters: {
|
|
431
|
-
...state.parameters,
|
|
432
|
-
dynamicCoverageFeesHorizon: value,
|
|
433
|
-
},
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
|
-
// setPriceStatisticsLookbackInSec
|
|
437
|
-
case SwaapV1Pool.LB_IN_SEC_TOPIC: {
|
|
438
|
-
const value = BigInt(SwaapV1Pool.getValueFromAnonymousEvent(log));
|
|
439
|
-
return {
|
|
440
|
-
...state,
|
|
441
|
-
parameters: {
|
|
442
|
-
...state.parameters,
|
|
443
|
-
priceStatisticsLookbackInSec: value,
|
|
444
|
-
},
|
|
445
|
-
};
|
|
446
|
-
}
|
|
447
|
-
// setMaxPriceUnpegRatio
|
|
448
|
-
case SwaapV1Pool.MAX_UNPEG_TOPIC: {
|
|
449
|
-
const value = BigInt(SwaapV1Pool.getValueFromAnonymousEvent(log));
|
|
450
|
-
return {
|
|
451
|
-
...state,
|
|
452
|
-
parameters: {
|
|
453
|
-
...state.parameters,
|
|
454
|
-
maxPriceUnpegRatio: value,
|
|
455
|
-
},
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
} else {
|
|
460
|
-
// named events
|
|
461
|
-
const parsed = SwaapV1Pool.poolInterface.parseLog(log);
|
|
462
|
-
switch (parsed.name) {
|
|
463
|
-
case 'LOG_JOIN': {
|
|
464
|
-
const tokenIn = parsed.args.tokenIn.toString().toLowerCase();
|
|
465
|
-
const tokenAmountIn = BigInt(
|
|
466
|
-
parsed.args.tokenAmountIn.toString(),
|
|
467
|
-
);
|
|
468
|
-
return {
|
|
469
|
-
...state,
|
|
470
|
-
liquidities: {
|
|
471
|
-
...state.liquidities,
|
|
472
|
-
[tokenIn]: {
|
|
473
|
-
...state.liquidities[tokenIn],
|
|
474
|
-
balance: state.liquidities[tokenIn].balance + tokenAmountIn,
|
|
475
|
-
},
|
|
476
|
-
},
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
|
-
case 'LOG_EXIT': {
|
|
480
|
-
const tokenOut = parsed.args.tokenOut.toString().toLowerCase();
|
|
481
|
-
const tokenAmountOut = BigInt(
|
|
482
|
-
parsed.args.tokenAmountOut.toString(),
|
|
483
|
-
);
|
|
484
|
-
return {
|
|
485
|
-
...state,
|
|
486
|
-
liquidities: {
|
|
487
|
-
...state.liquidities,
|
|
488
|
-
[tokenOut]: {
|
|
489
|
-
...state.liquidities[tokenOut],
|
|
490
|
-
balance:
|
|
491
|
-
state.liquidities[tokenOut].balance - tokenAmountOut,
|
|
492
|
-
},
|
|
493
|
-
},
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
case 'LOG_SWAP': {
|
|
497
|
-
const tokenIn = parsed.args.tokenIn.toString().toLowerCase();
|
|
498
|
-
const tokenAmountIn = BigInt(
|
|
499
|
-
parsed.args.tokenAmountIn.toString(),
|
|
500
|
-
);
|
|
501
|
-
const tokenOut = parsed.args.tokenOut.toString().toLowerCase();
|
|
502
|
-
const tokenAmountOut = BigInt(
|
|
503
|
-
parsed.args.tokenAmountOut.toString(),
|
|
504
|
-
);
|
|
505
|
-
return {
|
|
506
|
-
...state,
|
|
507
|
-
liquidities: {
|
|
508
|
-
...state.liquidities,
|
|
509
|
-
[tokenIn]: {
|
|
510
|
-
...state.liquidities[tokenIn],
|
|
511
|
-
balance: state.liquidities[tokenIn].balance + tokenAmountIn,
|
|
512
|
-
},
|
|
513
|
-
[tokenOut]: {
|
|
514
|
-
...state.liquidities[tokenOut],
|
|
515
|
-
balance:
|
|
516
|
-
state.liquidities[tokenOut].balance - tokenAmountOut,
|
|
517
|
-
},
|
|
518
|
-
},
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
default: {
|
|
522
|
-
return null;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
return null;
|
|
529
|
-
} catch (e) {
|
|
530
|
-
this.logger.error('Failed to decode result', e);
|
|
531
|
-
return null;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
public async getTokensAndParameters(
|
|
536
|
-
blockNumber: number,
|
|
537
|
-
): Promise<[Address[], SwaapV1PoolParameters]> {
|
|
538
|
-
const multiCallInputs: MultiCallInput[] = [
|
|
539
|
-
{
|
|
540
|
-
target: this.pool.id,
|
|
541
|
-
callData: SwaapV1Pool.poolInterface.encodeFunctionData('getTokens'),
|
|
542
|
-
},
|
|
543
|
-
{
|
|
544
|
-
target: this.pool.id,
|
|
545
|
-
callData: SwaapV1Pool.poolInterface.encodeFunctionData(
|
|
546
|
-
'getCoverageParameters',
|
|
547
|
-
),
|
|
548
|
-
},
|
|
549
|
-
{
|
|
550
|
-
target: this.pool.id,
|
|
551
|
-
callData: SwaapV1Pool.poolInterface.encodeFunctionData('getSwapFee'),
|
|
552
|
-
},
|
|
553
|
-
];
|
|
554
|
-
|
|
555
|
-
const returnData: MultiCallOutput[] = (
|
|
556
|
-
await this.dexHelper.multiContract.methods
|
|
557
|
-
.aggregate(multiCallInputs)
|
|
558
|
-
.call({}, blockNumber)
|
|
559
|
-
).returnData;
|
|
560
|
-
|
|
561
|
-
let tokens: Address[] = SwaapV1Pool.poolInterface.decodeFunctionResult(
|
|
562
|
-
'getTokens',
|
|
563
|
-
returnData[0],
|
|
564
|
-
)[0];
|
|
565
|
-
tokens = tokens.map(t => t.toLowerCase());
|
|
566
|
-
|
|
567
|
-
const coverageParameters = SwaapV1Pool.poolInterface.decodeFunctionResult(
|
|
568
|
-
'getCoverageParameters',
|
|
569
|
-
returnData[1],
|
|
570
|
-
);
|
|
571
|
-
|
|
572
|
-
const parameters: SwaapV1PoolParameters = {
|
|
573
|
-
swapFee: BigInt(
|
|
574
|
-
SwaapV1Pool.poolInterface
|
|
575
|
-
.decodeFunctionResult('getSwapFee', returnData[2])[0]
|
|
576
|
-
.toString(),
|
|
577
|
-
),
|
|
578
|
-
priceStatisticsLookbackInRound: Number(coverageParameters[0].toString()),
|
|
579
|
-
priceStatisticsLookbackStepInRound: Number(
|
|
580
|
-
coverageParameters[1].toString(),
|
|
581
|
-
),
|
|
582
|
-
dynamicCoverageFeesZ: BigInt(coverageParameters[2].toString()),
|
|
583
|
-
dynamicCoverageFeesHorizon: BigInt(coverageParameters[3].toString()),
|
|
584
|
-
priceStatisticsLookbackInSec: BigInt(coverageParameters[4].toString()),
|
|
585
|
-
maxPriceUnpegRatio: BigInt(coverageParameters[5].toString()),
|
|
586
|
-
};
|
|
587
|
-
|
|
588
|
-
return [tokens, parameters];
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
public async getProxiesAndLiquidities(
|
|
592
|
-
tokens: Address[],
|
|
593
|
-
blockNumber: number,
|
|
594
|
-
): Promise<[{ [key: Address]: Address }, SwaapV1PoolLiquidities]> {
|
|
595
|
-
let multiCallInputs: MultiCallInput[] = tokens
|
|
596
|
-
.map(token => {
|
|
597
|
-
return [
|
|
598
|
-
{
|
|
599
|
-
target: this.pool.id,
|
|
600
|
-
callData: SwaapV1Pool.poolInterface.encodeFunctionData(
|
|
601
|
-
'getBalance',
|
|
602
|
-
[token],
|
|
603
|
-
),
|
|
604
|
-
},
|
|
605
|
-
{
|
|
606
|
-
target: this.pool.id,
|
|
607
|
-
callData: SwaapV1Pool.poolInterface.encodeFunctionData(
|
|
608
|
-
'getDenormalizedWeight',
|
|
609
|
-
[token],
|
|
610
|
-
),
|
|
611
|
-
},
|
|
612
|
-
{
|
|
613
|
-
target: token,
|
|
614
|
-
callData: SwaapV1Pool.erc20Interface.encodeFunctionData('decimals'),
|
|
615
|
-
},
|
|
616
|
-
];
|
|
617
|
-
})
|
|
618
|
-
.flat();
|
|
619
|
-
|
|
620
|
-
multiCallInputs = tokens.reduce((acc, token) => {
|
|
621
|
-
return [
|
|
622
|
-
...acc,
|
|
623
|
-
{
|
|
624
|
-
target: this.pool.id,
|
|
625
|
-
callData: SwaapV1Pool.poolInterface.encodeFunctionData(
|
|
626
|
-
'getTokenPriceOracle',
|
|
627
|
-
[token],
|
|
628
|
-
),
|
|
629
|
-
},
|
|
630
|
-
].flat();
|
|
631
|
-
}, multiCallInputs);
|
|
632
|
-
|
|
633
|
-
let multicallOutputs: MultiCallOutput[] = (
|
|
634
|
-
await this.dexHelper.multiContract.methods
|
|
635
|
-
.aggregate(multiCallInputs)
|
|
636
|
-
.call({}, blockNumber)
|
|
637
|
-
).returnData;
|
|
638
|
-
|
|
639
|
-
let idx = 0;
|
|
640
|
-
// get liquidities
|
|
641
|
-
const liquidities = tokens.reduce((acc, token) => {
|
|
642
|
-
const balance = BigInt(
|
|
643
|
-
SwaapV1Pool.poolInterface
|
|
644
|
-
.decodeFunctionResult('getBalance', multicallOutputs[idx++])[0]
|
|
645
|
-
.toString(),
|
|
646
|
-
);
|
|
647
|
-
const initialWeight = BigInt(
|
|
648
|
-
SwaapV1Pool.poolInterface
|
|
649
|
-
.decodeFunctionResult(
|
|
650
|
-
'getDenormalizedWeight',
|
|
651
|
-
multicallOutputs[idx++],
|
|
652
|
-
)[0]
|
|
653
|
-
.toString(),
|
|
654
|
-
);
|
|
655
|
-
const decimals = parseInt(
|
|
656
|
-
SwaapV1Pool.erc20Interface
|
|
657
|
-
.decodeFunctionResult('decimals', multicallOutputs[idx++])[0]
|
|
658
|
-
.toString(),
|
|
659
|
-
);
|
|
660
|
-
return {
|
|
661
|
-
...acc,
|
|
662
|
-
[token]: {
|
|
663
|
-
balance: balance,
|
|
664
|
-
initialWeight: initialWeight,
|
|
665
|
-
decimals: decimals,
|
|
666
|
-
},
|
|
667
|
-
};
|
|
668
|
-
}, {});
|
|
669
|
-
|
|
670
|
-
const oracles = tokens.reduce((acc, token) => {
|
|
671
|
-
const oracle: Address = SwaapV1Pool.poolInterface
|
|
672
|
-
.decodeFunctionResult('getTokenPriceOracle', multicallOutputs[idx++])[0]
|
|
673
|
-
.toString()
|
|
674
|
-
.toLowerCase();
|
|
675
|
-
|
|
676
|
-
return {
|
|
677
|
-
...acc,
|
|
678
|
-
[token]: oracle,
|
|
679
|
-
};
|
|
680
|
-
}, {});
|
|
681
|
-
|
|
682
|
-
return [oracles, liquidities];
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
public async getOraclesData(
|
|
686
|
-
tokens: Address[],
|
|
687
|
-
proxies: { [key: Address]: Address }, // key: token, value: proxy
|
|
688
|
-
parameters: SwaapV1PoolParameters,
|
|
689
|
-
blockNumber: number,
|
|
690
|
-
): Promise<SwaapV1PoolOracles> {
|
|
691
|
-
// aggregators
|
|
692
|
-
let multiCallInputs: MultiCallInput[] = tokens.map((token: Address) => {
|
|
693
|
-
return {
|
|
694
|
-
target: proxies[token],
|
|
695
|
-
callData: SwaapV1Pool.proxyInterface.encodeFunctionData('aggregator'),
|
|
696
|
-
};
|
|
697
|
-
});
|
|
698
|
-
|
|
699
|
-
// oracle's addresses
|
|
700
|
-
let multicallOutputs: MultiCallOutput[] = (
|
|
701
|
-
await this.dexHelper.multiContract.methods
|
|
702
|
-
.aggregate(multiCallInputs)
|
|
703
|
-
.call({}, blockNumber)
|
|
704
|
-
).returnData;
|
|
705
|
-
|
|
706
|
-
let i: number = 0;
|
|
707
|
-
const oracles: { [key: Address]: Address } = tokens.reduce((acc, token) => {
|
|
708
|
-
return {
|
|
709
|
-
...acc,
|
|
710
|
-
[token]: SwaapV1Pool.poolInterface
|
|
711
|
-
.decodeFunctionResult('getTokenPriceOracle', multicallOutputs[i++])[0]
|
|
712
|
-
.toString()
|
|
713
|
-
.toLowerCase(),
|
|
714
|
-
};
|
|
715
|
-
}, {});
|
|
716
|
-
|
|
717
|
-
multiCallInputs = tokens
|
|
718
|
-
.map((token: Address) => {
|
|
719
|
-
return [
|
|
720
|
-
{
|
|
721
|
-
target: this.pool.id,
|
|
722
|
-
callData: SwaapV1Pool.poolInterface.encodeFunctionData(
|
|
723
|
-
'getTokenOracleInitialPrice',
|
|
724
|
-
[token],
|
|
725
|
-
),
|
|
726
|
-
},
|
|
727
|
-
{
|
|
728
|
-
target: proxies[token],
|
|
729
|
-
callData: SwaapV1Pool.proxyInterface.encodeFunctionData('decimals'),
|
|
730
|
-
},
|
|
731
|
-
{
|
|
732
|
-
target: proxies[token],
|
|
733
|
-
callData:
|
|
734
|
-
SwaapV1Pool.proxyInterface.encodeFunctionData('description'),
|
|
735
|
-
},
|
|
736
|
-
{
|
|
737
|
-
target: proxies[token],
|
|
738
|
-
callData:
|
|
739
|
-
SwaapV1Pool.proxyInterface.encodeFunctionData('latestRoundData'),
|
|
740
|
-
},
|
|
741
|
-
];
|
|
742
|
-
})
|
|
743
|
-
.flat();
|
|
744
|
-
|
|
745
|
-
multicallOutputs = (
|
|
746
|
-
await this.dexHelper.multiContract.methods
|
|
747
|
-
.aggregate(multiCallInputs)
|
|
748
|
-
.call({}, blockNumber)
|
|
749
|
-
).returnData;
|
|
750
|
-
|
|
751
|
-
let latestRoundIdsBN: { [key: Address]: bigint } = {};
|
|
752
|
-
|
|
753
|
-
i = 0;
|
|
754
|
-
let oraclesData: SwaapV1PoolOracles = tokens.reduce((acc, token) => {
|
|
755
|
-
const oraclesBindState: OracleInitialData = {
|
|
756
|
-
proxy: proxies[token],
|
|
757
|
-
aggregator: oracles[token],
|
|
758
|
-
price: BigInt(
|
|
759
|
-
SwaapV1Pool.poolInterface
|
|
760
|
-
.decodeFunctionResult(
|
|
761
|
-
'getTokenOracleInitialPrice',
|
|
762
|
-
multicallOutputs[i++],
|
|
763
|
-
)[0]
|
|
764
|
-
.toString(),
|
|
765
|
-
),
|
|
766
|
-
decimals: Number(
|
|
767
|
-
SwaapV1Pool.proxyInterface
|
|
768
|
-
.decodeFunctionResult('decimals', multicallOutputs[i++])[0]
|
|
769
|
-
.toString(),
|
|
770
|
-
),
|
|
771
|
-
description: SwaapV1Pool.proxyInterface
|
|
772
|
-
.decodeFunctionResult('description', multicallOutputs[i++])[0]
|
|
773
|
-
.toString(),
|
|
774
|
-
};
|
|
775
|
-
|
|
776
|
-
const latestRoundData = SwaapV1Pool.proxyInterface.decodeFunctionResult(
|
|
777
|
-
'latestRoundData',
|
|
778
|
-
multicallOutputs[i++],
|
|
779
|
-
);
|
|
780
|
-
const latestRoundId = BigInt(latestRoundData.roundId.toString());
|
|
781
|
-
latestRoundIdsBN[token] = latestRoundId;
|
|
782
|
-
return {
|
|
783
|
-
...acc,
|
|
784
|
-
[token]: {
|
|
785
|
-
oraclesBindState: oraclesBindState,
|
|
786
|
-
latestRoundId: Number(latestRoundId % 2n ** 64n),
|
|
787
|
-
historicalOracleState: {
|
|
788
|
-
[Number(latestRoundId % 2n ** 64n)]: {
|
|
789
|
-
answer: BigInt(latestRoundData.answer.toString()),
|
|
790
|
-
timestamp: BigInt(latestRoundData.updatedAt.toString()),
|
|
791
|
-
},
|
|
792
|
-
},
|
|
793
|
-
},
|
|
794
|
-
};
|
|
795
|
-
}, {});
|
|
796
|
-
|
|
797
|
-
const roundLookbackWindow =
|
|
798
|
-
(parameters.priceStatisticsLookbackInRound - 1) *
|
|
799
|
-
parameters.priceStatisticsLookbackStepInRound;
|
|
800
|
-
|
|
801
|
-
const historicalRoundsData = await this.getHistoricalRoundsData(
|
|
802
|
-
tokens,
|
|
803
|
-
roundLookbackWindow,
|
|
804
|
-
latestRoundIdsBN,
|
|
805
|
-
oraclesData,
|
|
806
|
-
blockNumber,
|
|
807
|
-
);
|
|
808
|
-
|
|
809
|
-
tokens.forEach(token => {
|
|
810
|
-
oraclesData[token].historicalOracleState = historicalRoundsData[token];
|
|
811
|
-
});
|
|
812
|
-
|
|
813
|
-
return oraclesData;
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
public async getHistoricalRoundsData(
|
|
817
|
-
tokens: Address[],
|
|
818
|
-
roundLookbackWindow: number,
|
|
819
|
-
latestRoundIdsBN: { [key: Address]: bigint },
|
|
820
|
-
oraclesData: SwaapV1PoolOracles,
|
|
821
|
-
blockNumber: number,
|
|
822
|
-
): Promise<{ [key: Address]: ChainLinkData }> {
|
|
823
|
-
// historical round data
|
|
824
|
-
let historicalStates: { [key: Address]: ChainLinkData } = tokens.reduce(
|
|
825
|
-
(acc, token) => {
|
|
826
|
-
return {
|
|
827
|
-
...acc,
|
|
828
|
-
[token]: { ...oraclesData[token].historicalOracleState },
|
|
829
|
-
};
|
|
830
|
-
},
|
|
831
|
-
{},
|
|
832
|
-
);
|
|
833
|
-
let multiCallInputs = tokens
|
|
834
|
-
.map((token: Address) => {
|
|
835
|
-
const startRoundId: bigint = latestRoundIdsBN[token];
|
|
836
|
-
return Array.from({ length: roundLookbackWindow }, (x, idx) => idx)
|
|
837
|
-
.map(idx => {
|
|
838
|
-
return {
|
|
839
|
-
target: oraclesData[token].oraclesBindState.proxy,
|
|
840
|
-
callData: SwaapV1Pool.proxyInterface.encodeFunctionData(
|
|
841
|
-
'getRoundData',
|
|
842
|
-
[startRoundId - BigInt(idx + 1)],
|
|
843
|
-
),
|
|
844
|
-
};
|
|
845
|
-
})
|
|
846
|
-
.flat();
|
|
847
|
-
})
|
|
848
|
-
.flat();
|
|
849
|
-
|
|
850
|
-
try {
|
|
851
|
-
let multicallOutputs = (
|
|
852
|
-
await this.dexHelper.multiContract.methods
|
|
853
|
-
.aggregate(multiCallInputs)
|
|
854
|
-
.call({}, blockNumber)
|
|
855
|
-
).returnData;
|
|
856
|
-
|
|
857
|
-
let i = 0;
|
|
858
|
-
tokens.map(token => {
|
|
859
|
-
Array.from({ length: roundLookbackWindow }, (x, idx) => idx).map(
|
|
860
|
-
idx => {
|
|
861
|
-
const decoded = SwaapV1Pool.proxyInterface.decodeFunctionResult(
|
|
862
|
-
'getRoundData',
|
|
863
|
-
multicallOutputs[i++],
|
|
864
|
-
);
|
|
865
|
-
const roundId = Number(
|
|
866
|
-
BigInt(decoded.roundId.toString()) % 2n ** 64n,
|
|
867
|
-
);
|
|
868
|
-
|
|
869
|
-
historicalStates[token][roundId] = {
|
|
870
|
-
answer: BigInt(decoded.answer.toString()),
|
|
871
|
-
timestamp: BigInt(decoded.updatedAt.toString()),
|
|
872
|
-
};
|
|
873
|
-
},
|
|
874
|
-
);
|
|
875
|
-
});
|
|
876
|
-
} catch (e) {
|
|
877
|
-
this.logger.error('Failed to get historical round data', e);
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
return historicalStates;
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
//Function used to generate a state if one is not currently present, which
|
|
884
|
-
//must be the state at exactly the given block number, unless one is not
|
|
885
|
-
//provided, in which case one should be generated for latest block. This
|
|
886
|
-
//function should not use any previous states to derive a new state, it should
|
|
887
|
-
//generate one from scratch.
|
|
888
|
-
public async generateState(
|
|
889
|
-
blockNumber?: number | 'latest',
|
|
890
|
-
): Promise<DeepReadonly<SwaapV1PoolState>> {
|
|
891
|
-
if (blockNumber === 'latest' || blockNumber === undefined) {
|
|
892
|
-
blockNumber = await this.dexHelper.provider.getBlockNumber();
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
const [tokens, parameters] = await this.getTokensAndParameters(blockNumber);
|
|
896
|
-
const [proxies, liquidities] = await this.getProxiesAndLiquidities(
|
|
897
|
-
tokens,
|
|
898
|
-
blockNumber,
|
|
899
|
-
);
|
|
900
|
-
const oracles = await this.getOraclesData(
|
|
901
|
-
tokens,
|
|
902
|
-
proxies,
|
|
903
|
-
parameters,
|
|
904
|
-
blockNumber,
|
|
905
|
-
);
|
|
906
|
-
|
|
907
|
-
return {
|
|
908
|
-
parameters: parameters,
|
|
909
|
-
liquidities: liquidities,
|
|
910
|
-
oracles: oracles,
|
|
911
|
-
};
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
static getValueFromAnonymousEvent(log: Readonly<Log>): string {
|
|
915
|
-
const data = log.data.toString();
|
|
916
|
-
const startIdx = 2 + 64 + 64 + 8;
|
|
917
|
-
return '0x' + data.slice(startIdx, startIdx + 64).toString();
|
|
918
|
-
}
|
|
919
|
-
}
|