@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,92 +0,0 @@
|
|
|
1
|
-
import { DeepReadonly } from 'ts-essentials';
|
|
2
|
-
import { Address, Token } from '../../types';
|
|
3
|
-
import { lens } from '../../lens';
|
|
4
|
-
import { StakedAvaxSubscriber } from '../../lib/benqi/staked-avax';
|
|
5
|
-
import { PlatypusAssetSubscriber } from './asset';
|
|
6
|
-
import { PlatypusPoolSubscriber } from './pool-subscriber';
|
|
7
|
-
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
8
|
-
import { PlatypusAvaxPoolState, PlatypusAvaxPoolConfigInfo } from './types';
|
|
9
|
-
import { PlatypusPoolBase, calcPrice, WAD, wmul, wdiv } from './pool-base';
|
|
10
|
-
|
|
11
|
-
export class PlatypusAvaxPool extends PlatypusPoolBase<PlatypusAvaxPoolState> {
|
|
12
|
-
constructor(
|
|
13
|
-
dexKey: string,
|
|
14
|
-
network: number,
|
|
15
|
-
name: string,
|
|
16
|
-
poolAddress: Address,
|
|
17
|
-
poolCfg: PlatypusAvaxPoolConfigInfo,
|
|
18
|
-
dexHelper: IDexHelper,
|
|
19
|
-
) {
|
|
20
|
-
super(
|
|
21
|
-
dexKey,
|
|
22
|
-
network,
|
|
23
|
-
name,
|
|
24
|
-
dexHelper,
|
|
25
|
-
[
|
|
26
|
-
new PlatypusPoolSubscriber<PlatypusAvaxPoolState>(
|
|
27
|
-
poolAddress,
|
|
28
|
-
lens<DeepReadonly<PlatypusAvaxPoolState>>().params,
|
|
29
|
-
dexHelper.getLogger(`${dexKey}-${network} Params ${name}`),
|
|
30
|
-
),
|
|
31
|
-
new StakedAvaxSubscriber<PlatypusAvaxPoolState>(
|
|
32
|
-
poolCfg.priceOracleAddress,
|
|
33
|
-
lens<DeepReadonly<PlatypusAvaxPoolState>>().stakedAvax,
|
|
34
|
-
dexHelper.getLogger(`Staked AVAX for ${dexKey}-${network} ${name}`),
|
|
35
|
-
),
|
|
36
|
-
...Object.entries(poolCfg.tokens).map(
|
|
37
|
-
([tokenAddress, c]) =>
|
|
38
|
-
new PlatypusAssetSubscriber<PlatypusAvaxPoolState>(
|
|
39
|
-
c.assetAddress,
|
|
40
|
-
lens<DeepReadonly<PlatypusAvaxPoolState>>().asset[tokenAddress],
|
|
41
|
-
dexHelper.getLogger(
|
|
42
|
-
`${dexKey}-${network} ${c.tokenSymbol} asset ${name}`,
|
|
43
|
-
),
|
|
44
|
-
),
|
|
45
|
-
),
|
|
46
|
-
],
|
|
47
|
-
{
|
|
48
|
-
params: {
|
|
49
|
-
paused: false,
|
|
50
|
-
slippageParamK: 0n,
|
|
51
|
-
slippageParamN: 0n,
|
|
52
|
-
c1: 0n,
|
|
53
|
-
xThreshold: 0n,
|
|
54
|
-
haircutRate: 0n,
|
|
55
|
-
retentionRatio: 0n,
|
|
56
|
-
maxPriceDeviation: 0n,
|
|
57
|
-
},
|
|
58
|
-
asset: {},
|
|
59
|
-
stakedAvax: {
|
|
60
|
-
totalPooledAvax: 0n,
|
|
61
|
-
totalShares: 0n,
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
public computePrices(
|
|
68
|
-
srcToken: Token,
|
|
69
|
-
destToken: Token,
|
|
70
|
-
amounts: bigint[],
|
|
71
|
-
state: PlatypusAvaxPoolState,
|
|
72
|
-
): bigint[] {
|
|
73
|
-
let fromShares: boolean;
|
|
74
|
-
if (this.dexHelper.config.isWETH(destToken.address)) {
|
|
75
|
-
fromShares = true;
|
|
76
|
-
} else if (this.dexHelper.config.isWETH(srcToken.address)) {
|
|
77
|
-
fromShares = false;
|
|
78
|
-
} else {
|
|
79
|
-
throw new Error(`Unexpected tokens being swapped in ${this.name}`);
|
|
80
|
-
}
|
|
81
|
-
const sAvaxRate = StakedAvaxSubscriber.getPooledAvaxByShares(
|
|
82
|
-
WAD,
|
|
83
|
-
state.stakedAvax,
|
|
84
|
-
);
|
|
85
|
-
return amounts.map(fromAmount => {
|
|
86
|
-
const idealToAmount = fromShares
|
|
87
|
-
? wmul(fromAmount, sAvaxRate)
|
|
88
|
-
: wdiv(fromAmount, sAvaxRate);
|
|
89
|
-
return calcPrice(srcToken, destToken, fromAmount, idealToAmount, state);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { DeepReadonly } from 'ts-essentials';
|
|
2
|
-
import {
|
|
3
|
-
PartialEventSubscriber,
|
|
4
|
-
ComposedEventSubscriber,
|
|
5
|
-
} from '../../composed-event-subscriber';
|
|
6
|
-
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
7
|
-
import { PlatypusPoolStateCommon } from './types';
|
|
8
|
-
import { Token } from '../../types';
|
|
9
|
-
import { BI_POWS } from '../../bigint-constants';
|
|
10
|
-
|
|
11
|
-
export const ETH_UNIT = BI_POWS[18];
|
|
12
|
-
export const WAD = BI_POWS[18];
|
|
13
|
-
export const RAY = BI_POWS[27];
|
|
14
|
-
|
|
15
|
-
export function wmul(x: bigint, y: bigint): bigint {
|
|
16
|
-
return (x * y + WAD / 2n) / WAD;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function wdiv(x: bigint, y: bigint): bigint {
|
|
20
|
-
return (x * WAD + y / 2n) / y;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function rmul(x: bigint, y: bigint): bigint {
|
|
24
|
-
return (x * y + RAY / 2n) / RAY;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function rpow(x: bigint, n: bigint): bigint {
|
|
28
|
-
let z = n % 2n !== 0n ? x : RAY;
|
|
29
|
-
|
|
30
|
-
for (n /= 2n; n !== 0n; n /= 2n) {
|
|
31
|
-
x = rmul(x, x);
|
|
32
|
-
|
|
33
|
-
if (n % 2n !== 0n) {
|
|
34
|
-
z = rmul(z, x);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return z;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function slippageFunc(
|
|
42
|
-
k: bigint,
|
|
43
|
-
n: bigint,
|
|
44
|
-
c1: bigint,
|
|
45
|
-
xThreshold: bigint,
|
|
46
|
-
x: bigint,
|
|
47
|
-
): bigint {
|
|
48
|
-
if (x < xThreshold) {
|
|
49
|
-
return c1 - x;
|
|
50
|
-
} else {
|
|
51
|
-
return wdiv(k, (rpow((x * RAY) / WAD, n) * WAD) / RAY);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function calcSlippage(
|
|
56
|
-
k: bigint,
|
|
57
|
-
n: bigint,
|
|
58
|
-
c1: bigint,
|
|
59
|
-
xThreshold: bigint,
|
|
60
|
-
cash: bigint,
|
|
61
|
-
liability: bigint,
|
|
62
|
-
cashChange: bigint,
|
|
63
|
-
addCash: boolean,
|
|
64
|
-
): bigint {
|
|
65
|
-
const covBefore = wdiv(cash, liability);
|
|
66
|
-
let covAfter: bigint;
|
|
67
|
-
if (addCash) {
|
|
68
|
-
covAfter = wdiv(cash + cashChange, liability);
|
|
69
|
-
} else {
|
|
70
|
-
covAfter = wdiv(cash - cashChange, liability);
|
|
71
|
-
}
|
|
72
|
-
if (covBefore === covAfter) {
|
|
73
|
-
return 0n;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const slippageBefore = slippageFunc(k, n, c1, xThreshold, covBefore);
|
|
77
|
-
const slippageAfter = slippageFunc(k, n, c1, xThreshold, covAfter);
|
|
78
|
-
|
|
79
|
-
if (covBefore > covAfter) {
|
|
80
|
-
return wdiv(slippageAfter - slippageBefore, covBefore - covAfter);
|
|
81
|
-
} else {
|
|
82
|
-
return wdiv(slippageBefore - slippageAfter, covAfter - covBefore);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function calcSwappingSlippage(si: bigint, sj: bigint): bigint {
|
|
87
|
-
return WAD + si - sj;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function calcHaircut(amount: bigint, rate: bigint): bigint {
|
|
91
|
-
return wmul(amount, rate);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function calcPrice(
|
|
95
|
-
srcToken: Token,
|
|
96
|
-
destToken: Token,
|
|
97
|
-
fromAmount: bigint,
|
|
98
|
-
idealToAmount: bigint,
|
|
99
|
-
state: PlatypusPoolStateCommon,
|
|
100
|
-
): bigint {
|
|
101
|
-
if (state.asset[destToken.address].cash < idealToAmount) return 0n;
|
|
102
|
-
const slippageFrom = calcSlippage(
|
|
103
|
-
state.params.slippageParamK,
|
|
104
|
-
state.params.slippageParamN,
|
|
105
|
-
state.params.c1,
|
|
106
|
-
state.params.xThreshold,
|
|
107
|
-
state.asset[srcToken.address].cash,
|
|
108
|
-
state.asset[srcToken.address].liability,
|
|
109
|
-
fromAmount,
|
|
110
|
-
true,
|
|
111
|
-
);
|
|
112
|
-
const slippageTo = calcSlippage(
|
|
113
|
-
state.params.slippageParamK,
|
|
114
|
-
state.params.slippageParamN,
|
|
115
|
-
state.params.c1,
|
|
116
|
-
state.params.xThreshold,
|
|
117
|
-
state.asset[destToken.address].cash,
|
|
118
|
-
state.asset[destToken.address].liability,
|
|
119
|
-
idealToAmount,
|
|
120
|
-
false,
|
|
121
|
-
);
|
|
122
|
-
const swappingSlippage = calcSwappingSlippage(slippageFrom, slippageTo);
|
|
123
|
-
const toAmount = wmul(idealToAmount, swappingSlippage);
|
|
124
|
-
const haircut = calcHaircut(toAmount, state.params.haircutRate);
|
|
125
|
-
return toAmount - haircut;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export abstract class PlatypusPoolBase<
|
|
129
|
-
State extends PlatypusPoolStateCommon,
|
|
130
|
-
> extends ComposedEventSubscriber<State> {
|
|
131
|
-
constructor(
|
|
132
|
-
readonly dexKey: string,
|
|
133
|
-
protected readonly network: number,
|
|
134
|
-
name: string,
|
|
135
|
-
dexHelper: IDexHelper,
|
|
136
|
-
parts: PartialEventSubscriber<State, any>[],
|
|
137
|
-
blankState: DeepReadonly<State>,
|
|
138
|
-
) {
|
|
139
|
-
super(
|
|
140
|
-
dexKey,
|
|
141
|
-
name,
|
|
142
|
-
dexHelper.getLogger(`${dexKey}-${network} ${name}`),
|
|
143
|
-
dexHelper,
|
|
144
|
-
parts,
|
|
145
|
-
blankState,
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
public abstract computePrices(
|
|
150
|
-
srcToken: Token,
|
|
151
|
-
destToken: Token,
|
|
152
|
-
amounts: bigint[],
|
|
153
|
-
state: State,
|
|
154
|
-
): bigint[];
|
|
155
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { DeepReadonly } from 'ts-essentials';
|
|
2
|
-
import { Address, Token } from '../../types';
|
|
3
|
-
import { lens } from '../../lens';
|
|
4
|
-
import { PlatypusAssetSubscriber } from './asset';
|
|
5
|
-
import { PlatypusPoolSubscriber } from './pool-subscriber';
|
|
6
|
-
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
7
|
-
import { PlatypusPurePoolState, PlatypusPurePoolConfigInfo } from './types';
|
|
8
|
-
import { getBigIntPow } from '../../utils';
|
|
9
|
-
import { PlatypusPoolBase, calcPrice } from './pool-base';
|
|
10
|
-
|
|
11
|
-
export class PlatypusPurePool extends PlatypusPoolBase<PlatypusPurePoolState> {
|
|
12
|
-
constructor(
|
|
13
|
-
dexKey: string,
|
|
14
|
-
network: number,
|
|
15
|
-
name: string,
|
|
16
|
-
poolAddress: Address,
|
|
17
|
-
poolCfg: PlatypusPurePoolConfigInfo,
|
|
18
|
-
dexHelper: IDexHelper,
|
|
19
|
-
) {
|
|
20
|
-
super(
|
|
21
|
-
dexKey,
|
|
22
|
-
network,
|
|
23
|
-
name,
|
|
24
|
-
dexHelper,
|
|
25
|
-
[
|
|
26
|
-
new PlatypusPoolSubscriber<PlatypusPurePoolState>(
|
|
27
|
-
poolAddress,
|
|
28
|
-
lens<DeepReadonly<PlatypusPurePoolState>>().params,
|
|
29
|
-
dexHelper.getLogger(`${dexKey}-${network} Params ${name}`),
|
|
30
|
-
),
|
|
31
|
-
...Object.entries(poolCfg.tokens).map(
|
|
32
|
-
([tokenAddress, c]) =>
|
|
33
|
-
new PlatypusAssetSubscriber<PlatypusPurePoolState>(
|
|
34
|
-
c.assetAddress,
|
|
35
|
-
lens<DeepReadonly<PlatypusPurePoolState>>().asset[tokenAddress],
|
|
36
|
-
dexHelper.getLogger(
|
|
37
|
-
`${dexKey}-${network} ${c.tokenSymbol} asset ${name}`,
|
|
38
|
-
),
|
|
39
|
-
),
|
|
40
|
-
),
|
|
41
|
-
],
|
|
42
|
-
{
|
|
43
|
-
params: {
|
|
44
|
-
paused: false,
|
|
45
|
-
slippageParamK: 0n,
|
|
46
|
-
slippageParamN: 0n,
|
|
47
|
-
c1: 0n,
|
|
48
|
-
xThreshold: 0n,
|
|
49
|
-
haircutRate: 0n,
|
|
50
|
-
retentionRatio: 0n,
|
|
51
|
-
maxPriceDeviation: 0n,
|
|
52
|
-
},
|
|
53
|
-
asset: {},
|
|
54
|
-
},
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public computePrices(
|
|
59
|
-
srcToken: Token,
|
|
60
|
-
destToken: Token,
|
|
61
|
-
amounts: bigint[],
|
|
62
|
-
state: PlatypusPurePoolState,
|
|
63
|
-
): bigint[] {
|
|
64
|
-
return amounts.map(fromAmount => {
|
|
65
|
-
const idealToAmount =
|
|
66
|
-
(fromAmount * getBigIntPow(destToken.decimals)) /
|
|
67
|
-
getBigIntPow(srcToken.decimals);
|
|
68
|
-
return calcPrice(srcToken, destToken, fromAmount, idealToAmount, state);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import { DeepReadonly } from 'ts-essentials';
|
|
2
|
-
import { PartialEventSubscriber } from '../../composed-event-subscriber';
|
|
3
|
-
import {
|
|
4
|
-
Address,
|
|
5
|
-
BlockHeader,
|
|
6
|
-
Log,
|
|
7
|
-
Logger,
|
|
8
|
-
MultiCallInput,
|
|
9
|
-
MultiCallOutput,
|
|
10
|
-
} from '../../types';
|
|
11
|
-
import { Lens } from '../../lens';
|
|
12
|
-
import { Interface } from '@ethersproject/abi';
|
|
13
|
-
import PoolABI from '../../abi/platypus/pool.json';
|
|
14
|
-
import { PlatypusPoolParams } from './types';
|
|
15
|
-
|
|
16
|
-
export class PlatypusPoolSubscriber<State> extends PartialEventSubscriber<
|
|
17
|
-
State,
|
|
18
|
-
PlatypusPoolParams
|
|
19
|
-
> {
|
|
20
|
-
static readonly poolInterface = new Interface(PoolABI);
|
|
21
|
-
|
|
22
|
-
constructor(
|
|
23
|
-
private pool: Address,
|
|
24
|
-
lens: Lens<DeepReadonly<State>, DeepReadonly<PlatypusPoolParams>>,
|
|
25
|
-
logger: Logger,
|
|
26
|
-
) {
|
|
27
|
-
super([pool], lens, logger);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public processLog(
|
|
31
|
-
state: DeepReadonly<PlatypusPoolParams>,
|
|
32
|
-
log: Readonly<Log>,
|
|
33
|
-
blockHeader: Readonly<BlockHeader>,
|
|
34
|
-
): DeepReadonly<PlatypusPoolParams> | null {
|
|
35
|
-
try {
|
|
36
|
-
const parsed = PlatypusPoolSubscriber.poolInterface.parseLog(log);
|
|
37
|
-
switch (parsed.name) {
|
|
38
|
-
case 'Paused': {
|
|
39
|
-
return {
|
|
40
|
-
...state,
|
|
41
|
-
paused: true,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
case 'Unpaused': {
|
|
45
|
-
return {
|
|
46
|
-
...state,
|
|
47
|
-
paused: false,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
case 'PriceDeviationUpdated': {
|
|
51
|
-
const previousPriceDeviation = BigInt(
|
|
52
|
-
parsed.args.previousPriceDeviation.toString(),
|
|
53
|
-
);
|
|
54
|
-
const newPriceDeviation = BigInt(
|
|
55
|
-
parsed.args.newPriceDeviation.toString(),
|
|
56
|
-
);
|
|
57
|
-
if (state.maxPriceDeviation !== previousPriceDeviation) {
|
|
58
|
-
this.logger.error(
|
|
59
|
-
'state.maxPriceDeviation !== previousPriceDeviation',
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
...state,
|
|
64
|
-
maxPriceDeviation: newPriceDeviation,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
case 'SlippageParamsUpdated': {
|
|
68
|
-
const previousK = BigInt(parsed.args.previousK.toString());
|
|
69
|
-
const newK = BigInt(parsed.args.newK.toString());
|
|
70
|
-
const previousN = BigInt(parsed.args.previousN.toString());
|
|
71
|
-
const newN = BigInt(parsed.args.newN.toString());
|
|
72
|
-
const previousC1 = BigInt(parsed.args.previousC1.toString());
|
|
73
|
-
const newC1 = BigInt(parsed.args.newC1.toString());
|
|
74
|
-
const previousXThreshold = BigInt(
|
|
75
|
-
parsed.args.previousXThreshold.toString(),
|
|
76
|
-
);
|
|
77
|
-
const newXThreshold = BigInt(parsed.args.newXThreshold.toString());
|
|
78
|
-
if (state.slippageParamK !== previousK) {
|
|
79
|
-
this.logger.error('state.slippageParamK !== previousK');
|
|
80
|
-
}
|
|
81
|
-
if (state.slippageParamN !== previousN) {
|
|
82
|
-
this.logger.error('state.slippageParamN !== previousN');
|
|
83
|
-
}
|
|
84
|
-
if (state.c1 !== previousC1) {
|
|
85
|
-
this.logger.error('state.c1 !== previousC1');
|
|
86
|
-
}
|
|
87
|
-
if (state.xThreshold !== previousXThreshold) {
|
|
88
|
-
this.logger.error('state.xThreshold !== previousXThreshold');
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
...state,
|
|
92
|
-
slippageParamK: newK,
|
|
93
|
-
slippageParamN: newN,
|
|
94
|
-
c1: newC1,
|
|
95
|
-
xThreshold: newXThreshold,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
case 'HaircutRateUpdated': {
|
|
99
|
-
const previousHaircut = BigInt(
|
|
100
|
-
parsed.args.previousHaircut.toString(),
|
|
101
|
-
);
|
|
102
|
-
const newHaircut = BigInt(parsed.args.newHaircut.toString());
|
|
103
|
-
if (state.haircutRate !== previousHaircut) {
|
|
104
|
-
this.logger.error('state.haircutRate !== previousHaircut');
|
|
105
|
-
}
|
|
106
|
-
return {
|
|
107
|
-
...state,
|
|
108
|
-
haircutRate: newHaircut,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
case 'RetentionRatioUpdated': {
|
|
112
|
-
const previousRetentionRatio = BigInt(
|
|
113
|
-
parsed.args.previousRetentionRatio.toString(),
|
|
114
|
-
);
|
|
115
|
-
const newRetentionRatio = BigInt(
|
|
116
|
-
parsed.args.newRetentionRatio.toString(),
|
|
117
|
-
);
|
|
118
|
-
if (state.retentionRatio !== previousRetentionRatio) {
|
|
119
|
-
this.logger.error(
|
|
120
|
-
'state.retentionRatio !== previousRetentionRatio',
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
...state,
|
|
125
|
-
retentionRatio: newRetentionRatio,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
default:
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
} catch (e) {
|
|
132
|
-
this.logger.error('Failed to parse log', e);
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public getGenerateStateMultiCallInputs(): MultiCallInput[] {
|
|
138
|
-
return [
|
|
139
|
-
{
|
|
140
|
-
target: this.pool,
|
|
141
|
-
callData:
|
|
142
|
-
PlatypusPoolSubscriber.poolInterface.encodeFunctionData('paused'),
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
target: this.pool,
|
|
146
|
-
callData:
|
|
147
|
-
PlatypusPoolSubscriber.poolInterface.encodeFunctionData(
|
|
148
|
-
'getSlippageParamK',
|
|
149
|
-
),
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
target: this.pool,
|
|
153
|
-
callData:
|
|
154
|
-
PlatypusPoolSubscriber.poolInterface.encodeFunctionData(
|
|
155
|
-
'getSlippageParamN',
|
|
156
|
-
),
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
target: this.pool,
|
|
160
|
-
callData:
|
|
161
|
-
PlatypusPoolSubscriber.poolInterface.encodeFunctionData('getC1'),
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
target: this.pool,
|
|
165
|
-
callData:
|
|
166
|
-
PlatypusPoolSubscriber.poolInterface.encodeFunctionData(
|
|
167
|
-
'getXThreshold',
|
|
168
|
-
),
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
target: this.pool,
|
|
172
|
-
callData:
|
|
173
|
-
PlatypusPoolSubscriber.poolInterface.encodeFunctionData(
|
|
174
|
-
'getHaircutRate',
|
|
175
|
-
),
|
|
176
|
-
},
|
|
177
|
-
{
|
|
178
|
-
target: this.pool,
|
|
179
|
-
callData:
|
|
180
|
-
PlatypusPoolSubscriber.poolInterface.encodeFunctionData(
|
|
181
|
-
'getRetentionRatio',
|
|
182
|
-
),
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
target: this.pool,
|
|
186
|
-
callData: PlatypusPoolSubscriber.poolInterface.encodeFunctionData(
|
|
187
|
-
'getMaxPriceDeviation',
|
|
188
|
-
),
|
|
189
|
-
},
|
|
190
|
-
];
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
public generateState(
|
|
194
|
-
multicallOutputs: MultiCallOutput[],
|
|
195
|
-
blockNumber?: number | 'latest',
|
|
196
|
-
): DeepReadonly<PlatypusPoolParams> {
|
|
197
|
-
return {
|
|
198
|
-
paused: PlatypusPoolSubscriber.poolInterface.decodeFunctionResult(
|
|
199
|
-
'paused',
|
|
200
|
-
multicallOutputs[0],
|
|
201
|
-
)[0],
|
|
202
|
-
slippageParamK: BigInt(
|
|
203
|
-
PlatypusPoolSubscriber.poolInterface
|
|
204
|
-
.decodeFunctionResult('getSlippageParamK', multicallOutputs[1])[0]
|
|
205
|
-
.toString(),
|
|
206
|
-
),
|
|
207
|
-
slippageParamN: BigInt(
|
|
208
|
-
PlatypusPoolSubscriber.poolInterface
|
|
209
|
-
.decodeFunctionResult('getSlippageParamN', multicallOutputs[2])[0]
|
|
210
|
-
.toString(),
|
|
211
|
-
),
|
|
212
|
-
c1: BigInt(
|
|
213
|
-
PlatypusPoolSubscriber.poolInterface
|
|
214
|
-
.decodeFunctionResult('getC1', multicallOutputs[3])[0]
|
|
215
|
-
.toString(),
|
|
216
|
-
),
|
|
217
|
-
xThreshold: BigInt(
|
|
218
|
-
PlatypusPoolSubscriber.poolInterface
|
|
219
|
-
.decodeFunctionResult('getXThreshold', multicallOutputs[4])[0]
|
|
220
|
-
.toString(),
|
|
221
|
-
),
|
|
222
|
-
haircutRate: BigInt(
|
|
223
|
-
PlatypusPoolSubscriber.poolInterface
|
|
224
|
-
.decodeFunctionResult('getHaircutRate', multicallOutputs[5])[0]
|
|
225
|
-
.toString(),
|
|
226
|
-
),
|
|
227
|
-
retentionRatio: BigInt(
|
|
228
|
-
PlatypusPoolSubscriber.poolInterface
|
|
229
|
-
.decodeFunctionResult('getRetentionRatio', multicallOutputs[6])[0]
|
|
230
|
-
.toString(),
|
|
231
|
-
),
|
|
232
|
-
maxPriceDeviation: BigInt(
|
|
233
|
-
PlatypusPoolSubscriber.poolInterface
|
|
234
|
-
.decodeFunctionResult('getMaxPriceDeviation', multicallOutputs[7])[0]
|
|
235
|
-
.toString(),
|
|
236
|
-
),
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
}
|
package/src/dex/platypus/pool.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { DeepReadonly } from 'ts-essentials';
|
|
2
|
-
import { Address, Token } from '../../types';
|
|
3
|
-
import { lens } from '../../lens';
|
|
4
|
-
import { ChainLinkSubscriber } from '../../lib/chainlink';
|
|
5
|
-
import { PlatypusAssetSubscriber } from './asset';
|
|
6
|
-
import { PlatypusPoolSubscriber } from './pool-subscriber';
|
|
7
|
-
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
8
|
-
import { PlatypusPoolState, PlatypusPoolConfigInfo } from './types';
|
|
9
|
-
import { getBigIntPow } from '../../utils';
|
|
10
|
-
import { PlatypusPoolBase, calcPrice, ETH_UNIT } from './pool-base';
|
|
11
|
-
|
|
12
|
-
export class PlatypusPool extends PlatypusPoolBase<PlatypusPoolState> {
|
|
13
|
-
constructor(
|
|
14
|
-
dexKey: string,
|
|
15
|
-
network: number,
|
|
16
|
-
name: string,
|
|
17
|
-
poolAddress: Address,
|
|
18
|
-
poolCfg: PlatypusPoolConfigInfo,
|
|
19
|
-
dexHelper: IDexHelper,
|
|
20
|
-
) {
|
|
21
|
-
super(
|
|
22
|
-
dexKey,
|
|
23
|
-
network,
|
|
24
|
-
name,
|
|
25
|
-
dexHelper,
|
|
26
|
-
[
|
|
27
|
-
new PlatypusPoolSubscriber<PlatypusPoolState>(
|
|
28
|
-
poolAddress,
|
|
29
|
-
lens<DeepReadonly<PlatypusPoolState>>().params,
|
|
30
|
-
dexHelper.getLogger(`${dexKey}-${network} Params ${name}`),
|
|
31
|
-
),
|
|
32
|
-
...Object.entries(poolCfg.tokens)
|
|
33
|
-
.map(([tokenAddress, c]) => [
|
|
34
|
-
new PlatypusAssetSubscriber<PlatypusPoolState>(
|
|
35
|
-
c.assetAddress,
|
|
36
|
-
lens<DeepReadonly<PlatypusPoolState>>().asset[tokenAddress],
|
|
37
|
-
dexHelper.getLogger(
|
|
38
|
-
`${dexKey}-${network} ${c.tokenSymbol} asset ${name}`,
|
|
39
|
-
),
|
|
40
|
-
),
|
|
41
|
-
new ChainLinkSubscriber<PlatypusPoolState>(
|
|
42
|
-
c.chainlink.proxyAddress,
|
|
43
|
-
c.chainlink.aggregatorAddress,
|
|
44
|
-
lens<DeepReadonly<PlatypusPoolState>>().chainlink[tokenAddress],
|
|
45
|
-
dexHelper.getLogger(
|
|
46
|
-
`${c.tokenSymbol} ChainLink for ${dexKey}-${network} ${name}`,
|
|
47
|
-
),
|
|
48
|
-
),
|
|
49
|
-
])
|
|
50
|
-
.flat(),
|
|
51
|
-
],
|
|
52
|
-
{
|
|
53
|
-
params: {
|
|
54
|
-
paused: false,
|
|
55
|
-
slippageParamK: 0n,
|
|
56
|
-
slippageParamN: 0n,
|
|
57
|
-
c1: 0n,
|
|
58
|
-
xThreshold: 0n,
|
|
59
|
-
haircutRate: 0n,
|
|
60
|
-
retentionRatio: 0n,
|
|
61
|
-
maxPriceDeviation: 0n,
|
|
62
|
-
},
|
|
63
|
-
asset: {},
|
|
64
|
-
chainlink: {},
|
|
65
|
-
},
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public computePrices(
|
|
70
|
-
srcToken: Token,
|
|
71
|
-
destToken: Token,
|
|
72
|
-
amounts: bigint[],
|
|
73
|
-
state: PlatypusPoolState,
|
|
74
|
-
): bigint[] {
|
|
75
|
-
const tokenAPrice = state.chainlink[srcToken.address].answer;
|
|
76
|
-
const tokenBPrice = state.chainlink[destToken.address].answer;
|
|
77
|
-
if (tokenBPrice > tokenAPrice) {
|
|
78
|
-
if (
|
|
79
|
-
((tokenBPrice - tokenAPrice) * ETH_UNIT) / tokenBPrice >
|
|
80
|
-
state.params.maxPriceDeviation
|
|
81
|
-
) {
|
|
82
|
-
return Array(amounts.length).fill(0n);
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
if (
|
|
86
|
-
((tokenAPrice - tokenBPrice) * ETH_UNIT) / tokenAPrice >
|
|
87
|
-
state.params.maxPriceDeviation
|
|
88
|
-
) {
|
|
89
|
-
return Array(amounts.length).fill(0n);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return amounts.map(fromAmount => {
|
|
93
|
-
const idealToAmount =
|
|
94
|
-
(fromAmount * getBigIntPow(destToken.decimals)) /
|
|
95
|
-
getBigIntPow(srcToken.decimals);
|
|
96
|
-
return calcPrice(srcToken, destToken, fromAmount, idealToAmount, state);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}
|