@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,433 +0,0 @@
|
|
|
1
|
-
import { Const } from './Const';
|
|
2
|
-
import { Num } from './Num';
|
|
3
|
-
import { LogExpMath } from './LogExpMath';
|
|
4
|
-
import * as Struct from './Struct';
|
|
5
|
-
import { ChainlinkUtils } from './ChainlinkUtils';
|
|
6
|
-
import { ChainLinkData, OracleData } from '../types';
|
|
7
|
-
|
|
8
|
-
export class GeometricBrownianMotion {
|
|
9
|
-
/**
|
|
10
|
-
* @notice Gets asset-pair approximate historical return's mean and variance
|
|
11
|
-
* @param latestRoundIn The round-to-start-from's data including its ID of tokenIn
|
|
12
|
-
* @param latestRoundOut The round-to-start-from's data including its ID of tokenOut
|
|
13
|
-
* @param hpParameters The parameters for historical prices retrieval
|
|
14
|
-
* @return gbmEstimation The asset-pair historical return's mean and variance
|
|
15
|
-
*/
|
|
16
|
-
static getParametersEstimation(
|
|
17
|
-
latestRoundIn: Struct.LatestRound,
|
|
18
|
-
latestRoundOut: Struct.LatestRound,
|
|
19
|
-
hpParameters: Struct.HistoricalPricesParameters,
|
|
20
|
-
historicalOracleStateIn: ChainLinkData,
|
|
21
|
-
historicalOracleStateOut: ChainLinkData,
|
|
22
|
-
): Struct.GBMEstimation {
|
|
23
|
-
// retrieve historical prices of tokenIn
|
|
24
|
-
let [pricesIn, timestampsIn, startIndexIn, noMoreDataPointIn] =
|
|
25
|
-
GeometricBrownianMotion.getHistoricalPrices(
|
|
26
|
-
latestRoundIn,
|
|
27
|
-
hpParameters,
|
|
28
|
-
historicalOracleStateIn,
|
|
29
|
-
);
|
|
30
|
-
if (!noMoreDataPointIn && startIndexIn < hpParameters.lookbackInRound - 1) {
|
|
31
|
-
return {
|
|
32
|
-
mean: 0n,
|
|
33
|
-
variance: 0n,
|
|
34
|
-
success: false,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
let reducedLookbackInSecCandidate =
|
|
39
|
-
hpParameters.timestamp - timestampsIn[startIndexIn];
|
|
40
|
-
if (reducedLookbackInSecCandidate < hpParameters.lookbackInSec) {
|
|
41
|
-
hpParameters.lookbackInSec = reducedLookbackInSecCandidate;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// retrieve historical prices of tokenOut
|
|
45
|
-
let [pricesOut, timestampsOut, startIndexOut, noMoreDataPointOut] =
|
|
46
|
-
GeometricBrownianMotion.getHistoricalPrices(
|
|
47
|
-
latestRoundOut,
|
|
48
|
-
hpParameters,
|
|
49
|
-
historicalOracleStateOut,
|
|
50
|
-
);
|
|
51
|
-
if (
|
|
52
|
-
!noMoreDataPointOut &&
|
|
53
|
-
startIndexOut < hpParameters.lookbackInRound - 1
|
|
54
|
-
) {
|
|
55
|
-
return {
|
|
56
|
-
mean: 0n,
|
|
57
|
-
variance: 0n,
|
|
58
|
-
success: false,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return GeometricBrownianMotion._getParametersEstimation(
|
|
63
|
-
noMoreDataPointIn && noMoreDataPointOut,
|
|
64
|
-
{ startIndex: startIndexIn, timestamps: timestampsIn, prices: pricesIn },
|
|
65
|
-
{
|
|
66
|
-
startIndex: startIndexOut,
|
|
67
|
-
timestamps: timestampsOut,
|
|
68
|
-
prices: pricesOut,
|
|
69
|
-
},
|
|
70
|
-
hpParameters,
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @notice Gets asset-pair historical data return's mean and variance
|
|
76
|
-
* @param noMoreDataPoints True if and only if the retrieved data span over the whole time window of interest
|
|
77
|
-
* @param hpDataIn Historical prices data of tokenIn
|
|
78
|
-
* @param hpDataOut Historical prices data of tokenOut
|
|
79
|
-
* @param hpParameters The parameters for historical prices retrieval
|
|
80
|
-
* @return gbmEstimation The asset-pair historical return's mean and variance
|
|
81
|
-
*/
|
|
82
|
-
static _getParametersEstimation(
|
|
83
|
-
noMoreDataPoints: boolean,
|
|
84
|
-
hpDataIn: Struct.HistoricalPricesData,
|
|
85
|
-
hpDataOut: Struct.HistoricalPricesData,
|
|
86
|
-
hpParameters: Struct.HistoricalPricesParameters,
|
|
87
|
-
): Struct.GBMEstimation {
|
|
88
|
-
// no price return can be calculated with only 1 data point
|
|
89
|
-
if (hpDataIn.startIndex == 0 && hpDataOut.startIndex == 0) {
|
|
90
|
-
return {
|
|
91
|
-
mean: 0n,
|
|
92
|
-
variance: 0n,
|
|
93
|
-
success: true,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (noMoreDataPoints) {
|
|
98
|
-
let ts = hpParameters.timestamp - hpParameters.lookbackInSec;
|
|
99
|
-
hpDataIn.timestamps[hpDataIn.startIndex] = ts;
|
|
100
|
-
hpDataOut.timestamps[hpDataOut.startIndex] = ts;
|
|
101
|
-
} else {
|
|
102
|
-
GeometricBrownianMotion.consolidateStartIndices(hpDataIn, hpDataOut);
|
|
103
|
-
// no price return can be calculated with only 1 data point
|
|
104
|
-
if (hpDataIn.startIndex == 0 && hpDataOut.startIndex == 0) {
|
|
105
|
-
return {
|
|
106
|
-
mean: 0n,
|
|
107
|
-
variance: 0n,
|
|
108
|
-
success: true,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
let [values, timestamps] = GeometricBrownianMotion.getSeries(
|
|
113
|
-
hpDataIn.prices,
|
|
114
|
-
hpDataIn.timestamps,
|
|
115
|
-
hpDataIn.startIndex,
|
|
116
|
-
hpDataOut.prices,
|
|
117
|
-
hpDataOut.timestamps,
|
|
118
|
-
hpDataOut.startIndex,
|
|
119
|
-
);
|
|
120
|
-
let [mean, variance] = GeometricBrownianMotion.getStatistics(
|
|
121
|
-
values,
|
|
122
|
-
timestamps,
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
mean: mean,
|
|
127
|
-
variance: variance,
|
|
128
|
-
success: true,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* @notice Gets asset-pair historical prices with timestamps
|
|
134
|
-
* @param pricesIn The historical prices of tokenIn
|
|
135
|
-
* @param timestampsIn The timestamps corresponding to the tokenIn's historical prices
|
|
136
|
-
* @param startIndexIn The tokenIn historical data's last valid index
|
|
137
|
-
* @param pricesOut The tokenIn historical data's last valid index
|
|
138
|
-
* @param timestampsOut The timestamps corresponding to the tokenOut's historical prices
|
|
139
|
-
* @param startIndexOut The tokenOut historical data's last valid index
|
|
140
|
-
* @return values The asset-pair historical prices array
|
|
141
|
-
* @return timestamps The asset-pair historical timestamps array
|
|
142
|
-
*/
|
|
143
|
-
static getSeries(
|
|
144
|
-
pricesIn: bigint[],
|
|
145
|
-
timestampsIn: bigint[],
|
|
146
|
-
startIndexIn: number,
|
|
147
|
-
pricesOut: bigint[],
|
|
148
|
-
timestampsOut: bigint[],
|
|
149
|
-
startIndexOut: number,
|
|
150
|
-
): [bigint[], bigint[]] {
|
|
151
|
-
let values, timestamps;
|
|
152
|
-
// compute the number of returns
|
|
153
|
-
let count = 1;
|
|
154
|
-
{
|
|
155
|
-
let _startIndexIn = startIndexIn;
|
|
156
|
-
let _startIndexOut = startIndexOut;
|
|
157
|
-
let skip = true;
|
|
158
|
-
while (_startIndexIn > 0 || _startIndexOut > 0) {
|
|
159
|
-
[skip, _startIndexIn, _startIndexOut] =
|
|
160
|
-
GeometricBrownianMotion.getNextSample(
|
|
161
|
-
_startIndexIn,
|
|
162
|
-
_startIndexOut,
|
|
163
|
-
timestampsIn,
|
|
164
|
-
timestampsOut,
|
|
165
|
-
);
|
|
166
|
-
if (!skip) {
|
|
167
|
-
count += 1;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
values = new Array<bigint>(count);
|
|
171
|
-
timestamps = new Array<bigint>(count);
|
|
172
|
-
values[0] = Num.div(pricesOut[startIndexOut], pricesIn[startIndexIn]);
|
|
173
|
-
timestamps[0] =
|
|
174
|
-
Num.max(timestampsOut[startIndexOut], timestampsIn[startIndexIn]) *
|
|
175
|
-
Const.ONE;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// compute actual returns
|
|
179
|
-
{
|
|
180
|
-
count = 1;
|
|
181
|
-
let skip = true;
|
|
182
|
-
while (startIndexIn > 0 || startIndexOut > 0) {
|
|
183
|
-
[skip, startIndexIn, startIndexOut] =
|
|
184
|
-
GeometricBrownianMotion.getNextSample(
|
|
185
|
-
startIndexIn,
|
|
186
|
-
startIndexOut,
|
|
187
|
-
timestampsIn,
|
|
188
|
-
timestampsOut,
|
|
189
|
-
);
|
|
190
|
-
if (!skip) {
|
|
191
|
-
values[count] = Num.div(
|
|
192
|
-
pricesOut[startIndexOut],
|
|
193
|
-
pricesIn[startIndexIn],
|
|
194
|
-
);
|
|
195
|
-
timestamps[count] =
|
|
196
|
-
Num.max(timestampsOut[startIndexOut], timestampsIn[startIndexIn]) *
|
|
197
|
-
Const.ONE;
|
|
198
|
-
count += 1;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return [values, timestamps];
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* @notice Gets asset-pair historical mean/variance from timestamped data
|
|
208
|
-
* @param values The historical values
|
|
209
|
-
* @param timestamps The corresponding time deltas, in seconds
|
|
210
|
-
* @return mean The asset-pair historical return's mean
|
|
211
|
-
* @return variance asset-pair historical return's variance
|
|
212
|
-
*/
|
|
213
|
-
static getStatistics(
|
|
214
|
-
values: bigint[],
|
|
215
|
-
timestamps: bigint[],
|
|
216
|
-
): [bigint, bigint] {
|
|
217
|
-
let n = values.length;
|
|
218
|
-
if (n < 2) {
|
|
219
|
-
return [0n, 0n];
|
|
220
|
-
}
|
|
221
|
-
n -= 1;
|
|
222
|
-
|
|
223
|
-
let tWithPrecision = timestamps[n] - timestamps[0];
|
|
224
|
-
|
|
225
|
-
// mean
|
|
226
|
-
let mean = Num.divInt256(
|
|
227
|
-
LogExpMath.ln(Num.divInt256(values[n], values[0])),
|
|
228
|
-
tWithPrecision,
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
let meanSquare;
|
|
232
|
-
if (mean < 0) {
|
|
233
|
-
meanSquare = Num.mul(-mean, -mean);
|
|
234
|
-
} else {
|
|
235
|
-
meanSquare = Num.mul(mean, mean);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// variance
|
|
239
|
-
let variance = -Num.mul(meanSquare, tWithPrecision);
|
|
240
|
-
for (let i = 1; i <= n; i++) {
|
|
241
|
-
let d = LogExpMath.ln(Num.divInt256(values[i], values[i - 1]));
|
|
242
|
-
if (d < 0) {
|
|
243
|
-
d = -d;
|
|
244
|
-
}
|
|
245
|
-
let dAbs = d;
|
|
246
|
-
variance += Num.div(
|
|
247
|
-
Num.mul(dAbs, dAbs),
|
|
248
|
-
timestamps[i] - timestamps[i - 1],
|
|
249
|
-
);
|
|
250
|
-
}
|
|
251
|
-
variance = Num.divInt256(variance, BigInt(n) * Const.ONE);
|
|
252
|
-
return [mean, Num.positivePart(variance)];
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* @notice Gets historical prices from a Chainlink data feed
|
|
257
|
-
* @dev Few specificities:
|
|
258
|
-
* - it filters out round data with null price or timestamp
|
|
259
|
-
* - it stops filling the prices/timestamps when:
|
|
260
|
-
* a) hpParameters.lookbackInRound rounds have already been found
|
|
261
|
-
* b) time window induced by hpParameters.lookbackInSec is no more satisfied
|
|
262
|
-
* @param latestRound The round-to-start-from's data including its ID
|
|
263
|
-
* @param hpParameters The parameters for historical prices retrieval
|
|
264
|
-
* @return historicalPrices The historical prices of a token
|
|
265
|
-
* @return historicalTimestamps The timestamps of the reported prices
|
|
266
|
-
* @return index The last valid index of the returned arrays
|
|
267
|
-
* @return noMoreDataPoints True if the reported historical prices reaches the lookback time limit
|
|
268
|
-
*/
|
|
269
|
-
static getHistoricalPrices(
|
|
270
|
-
latestRound: Struct.LatestRound,
|
|
271
|
-
hpParameters: Struct.HistoricalPricesParameters,
|
|
272
|
-
historicalOracleState: ChainLinkData,
|
|
273
|
-
): [bigint[], bigint[], number, boolean] {
|
|
274
|
-
let latestTimestamp = latestRound.timestamp;
|
|
275
|
-
|
|
276
|
-
// historical price endtimestamp >= lookback window or it reverts
|
|
277
|
-
let timeLimit = Num.sub(hpParameters.timestamp, hpParameters.lookbackInSec);
|
|
278
|
-
|
|
279
|
-
// result variables
|
|
280
|
-
let prices = new Array<bigint>(hpParameters.lookbackInRound);
|
|
281
|
-
let timestamps = new Array<bigint>(hpParameters.lookbackInRound);
|
|
282
|
-
let idx = 1;
|
|
283
|
-
|
|
284
|
-
{
|
|
285
|
-
prices[0] = latestRound.price; // is supposed to be well valid
|
|
286
|
-
timestamps[0] = latestTimestamp; // is supposed to be well valid
|
|
287
|
-
|
|
288
|
-
if (latestTimestamp < timeLimit) {
|
|
289
|
-
return [prices, timestamps, 0, true];
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
let count = 1;
|
|
293
|
-
|
|
294
|
-
// buffer variables
|
|
295
|
-
let _roundId = latestRound.roundId;
|
|
296
|
-
|
|
297
|
-
while (
|
|
298
|
-
_roundId >= hpParameters.lookbackStepInRound &&
|
|
299
|
-
count < hpParameters.lookbackInRound
|
|
300
|
-
) {
|
|
301
|
-
_roundId -= hpParameters.lookbackStepInRound;
|
|
302
|
-
let [_price, _timestamp] = ChainlinkUtils.getRoundData(
|
|
303
|
-
_roundId,
|
|
304
|
-
historicalOracleState,
|
|
305
|
-
);
|
|
306
|
-
|
|
307
|
-
if (_price > 0 && _timestamp > 0) {
|
|
308
|
-
prices[idx] = _price;
|
|
309
|
-
timestamps[idx] = _timestamp;
|
|
310
|
-
idx += 1;
|
|
311
|
-
|
|
312
|
-
if (_timestamp < timeLimit) {
|
|
313
|
-
return [prices, timestamps, idx - 1, true];
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
count += 1;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
return [prices, timestamps, idx - 1, false];
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* @notice Finds the next data point in chronological order
|
|
326
|
-
* @dev Few considerations:
|
|
327
|
-
* - data point with same timestamp as previous point are tagged with a 'skip=true'
|
|
328
|
-
* - when we reach the last point of a token, we consider it's value constant going forward with the other token
|
|
329
|
-
* As a result the variance of those returns will be underestimated.
|
|
330
|
-
* @param startIndexIn The tokenIn historical data's last valid index
|
|
331
|
-
* @param startIndexOut The tokenOut historical data's last valid index
|
|
332
|
-
* @param timestampsIn The timestamps corresponding to the tokenIn's historical prices
|
|
333
|
-
* @param timestampsOut The timestamps corresponding to the tokenOut's historical prices
|
|
334
|
-
* @return skip The 'skip' tag
|
|
335
|
-
* @return startIndexIn The updated startIndexIn
|
|
336
|
-
* @return startIndexOut The updated startIndexOut
|
|
337
|
-
*/
|
|
338
|
-
static getNextSample(
|
|
339
|
-
startIndexIn: number,
|
|
340
|
-
startIndexOut: number,
|
|
341
|
-
timestampsIn: bigint[],
|
|
342
|
-
timestampsOut: bigint[],
|
|
343
|
-
): [boolean, number, number] {
|
|
344
|
-
let skip = true;
|
|
345
|
-
let nextStartIndexIn = startIndexIn > 0 ? startIndexIn - 1 : startIndexIn;
|
|
346
|
-
let nextStartIndexOut =
|
|
347
|
-
startIndexOut > 0 ? startIndexOut - 1 : startIndexOut;
|
|
348
|
-
if (timestampsIn[nextStartIndexIn] == timestampsOut[nextStartIndexOut]) {
|
|
349
|
-
if (
|
|
350
|
-
timestampsIn[nextStartIndexIn] != timestampsIn[startIndexIn] &&
|
|
351
|
-
timestampsOut[nextStartIndexOut] != timestampsOut[startIndexOut]
|
|
352
|
-
) {
|
|
353
|
-
skip = false;
|
|
354
|
-
}
|
|
355
|
-
if (startIndexIn > 0) {
|
|
356
|
-
startIndexIn--;
|
|
357
|
-
}
|
|
358
|
-
if (startIndexOut > 0) {
|
|
359
|
-
startIndexOut--;
|
|
360
|
-
}
|
|
361
|
-
} else {
|
|
362
|
-
if (startIndexOut == 0) {
|
|
363
|
-
if (timestampsIn[nextStartIndexIn] != timestampsIn[startIndexIn]) {
|
|
364
|
-
skip = false;
|
|
365
|
-
}
|
|
366
|
-
if (startIndexIn > 0) {
|
|
367
|
-
startIndexIn--;
|
|
368
|
-
}
|
|
369
|
-
} else if (startIndexIn == 0) {
|
|
370
|
-
if (timestampsOut[nextStartIndexOut] != timestampsOut[startIndexOut]) {
|
|
371
|
-
skip = false;
|
|
372
|
-
}
|
|
373
|
-
if (startIndexOut > 0) {
|
|
374
|
-
startIndexOut--;
|
|
375
|
-
}
|
|
376
|
-
} else {
|
|
377
|
-
if (timestampsIn[nextStartIndexIn] < timestampsOut[nextStartIndexOut]) {
|
|
378
|
-
if (timestampsIn[nextStartIndexIn] != timestampsIn[startIndexIn]) {
|
|
379
|
-
skip = false;
|
|
380
|
-
}
|
|
381
|
-
if (startIndexIn > 0) {
|
|
382
|
-
startIndexIn--;
|
|
383
|
-
}
|
|
384
|
-
} else {
|
|
385
|
-
if (
|
|
386
|
-
timestampsOut[nextStartIndexOut] != timestampsOut[startIndexOut]
|
|
387
|
-
) {
|
|
388
|
-
skip = false;
|
|
389
|
-
}
|
|
390
|
-
if (startIndexOut > 0) {
|
|
391
|
-
startIndexOut--;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
return [skip, startIndexIn, startIndexOut];
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* @notice Consolidate the last valid indexes of tokenIn and tokenOut
|
|
401
|
-
* @param hpDataIn Historical prices data of tokenIn
|
|
402
|
-
* @param hpDataOut Historical prices data of tokenOut
|
|
403
|
-
*/
|
|
404
|
-
static consolidateStartIndices(
|
|
405
|
-
hpDataIn: Struct.HistoricalPricesData,
|
|
406
|
-
hpDataOut: Struct.HistoricalPricesData,
|
|
407
|
-
) {
|
|
408
|
-
// trim prices/timestamps by adjusting startIndexes
|
|
409
|
-
if (
|
|
410
|
-
hpDataIn.timestamps[hpDataIn.startIndex] >
|
|
411
|
-
hpDataOut.timestamps[hpDataOut.startIndex]
|
|
412
|
-
) {
|
|
413
|
-
while (
|
|
414
|
-
hpDataOut.startIndex > 0 &&
|
|
415
|
-
hpDataOut.timestamps[hpDataOut.startIndex - 1] <=
|
|
416
|
-
hpDataIn.timestamps[hpDataIn.startIndex]
|
|
417
|
-
) {
|
|
418
|
-
--hpDataOut.startIndex;
|
|
419
|
-
}
|
|
420
|
-
} else if (
|
|
421
|
-
hpDataIn.timestamps[hpDataIn.startIndex] <
|
|
422
|
-
hpDataOut.timestamps[hpDataOut.startIndex]
|
|
423
|
-
) {
|
|
424
|
-
while (
|
|
425
|
-
hpDataIn.startIndex > 0 &&
|
|
426
|
-
hpDataIn.timestamps[hpDataIn.startIndex - 1] <=
|
|
427
|
-
hpDataOut.timestamps[hpDataOut.startIndex]
|
|
428
|
-
) {
|
|
429
|
-
--hpDataIn.startIndex;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
}
|