@paraswap/dex-lib 4.1.9 → 4.1.10-ekubo
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/build/abi/AaveV1_lending_pool.json +27 -0
- package/build/abi/Aave_GSM.json +751 -0
- package/build/abi/Balancer.json +257 -0
- package/build/abi/BalancerV2.json +1179 -0
- package/build/abi/RamsesV2Pool.abi.json +1554 -0
- package/build/abi/RamsesV2Quoter.abi.json +274 -0
- package/build/abi/USDM.json +807 -0
- package/build/abi/UniswapV2Router.json +397 -0
- package/build/abi/angle-transmuter/ChainlinkAccessControlledOffchainAggregator.json +1246 -0
- package/build/abi/angle-transmuter/ChainlinkEACAggregatorProxy.json +509 -0
- package/build/abi/curve-v1/CurveBUSDv2.abi.json +1356 -0
- package/build/abi/curve-v1/CurveTokenV1.json +305 -0
- package/build/abi/curve-v1/CurveTokenV2.json +318 -0
- package/build/abi/curve-v1/CurveV1StableNg.json +1452 -0
- package/build/abi/curve-v1/CurveV2Swap.json +700 -0
- package/build/abi/curve-v1/FactoryCryptoRegistry.json +316 -0
- package/build/abi/curve-v1/FactoryRegistry.json +508 -0
- package/build/abi/curve-v1/StableSwapAave.json +1152 -0
- package/build/abi/curve-v1/StableSwapBUSD.json +814 -0
- package/build/abi/curve-v1/StableSwapCompound.json +814 -0
- package/build/abi/curve-v1/StableSwapIDLE.json +1253 -0
- package/build/abi/curve-v1/StableSwapPax.json +865 -0
- package/build/abi/curve-v1/StableSwapSnow.json +900 -0
- package/build/abi/curve-v1/StableSwapUSDN.json +1004 -0
- package/build/abi/curve-v1/StableSwapUSDT.json +814 -0
- package/build/abi/curve-v1/StableSwapY.json +814 -0
- package/build/abi/ekubo/core.json +1266 -0
- package/build/abi/ekubo/data-fetcher.json +161 -0
- package/build/abi/ekubo/router.json +803 -0
- package/build/abi/inception/inception-ineth-pool.json +1062 -0
- package/build/abi/inception/inception-ineth.json +609 -0
- package/build/abi/inception/inception-ratio-feed.json +329 -0
- package/build/abi/inception/inception-vault.json +991 -0
- package/build/abi/kyberdmm/kyber-storage.abi.json +824 -0
- package/build/abi/kyberdmm.abi.json +1148 -0
- package/build/abi/maverick-v2/MaverickV2Quoter.json +278 -0
- package/build/abi/nerve/nerve-metapool.json +790 -0
- package/build/abi/platypus/asset.json +490 -0
- package/build/abi/platypus/avax-pool.json +820 -0
- package/build/abi/platypus/oracle.json +119 -0
- package/build/abi/platypus/pool.json +677 -0
- package/build/abi/smardex/all/smardex-router.json +648 -0
- package/build/abi/smardex/layer-1/smardex-factory.json +242 -0
- package/build/abi/smardex/layer-1/smardex-pool.json +506 -0
- package/build/abi/smardex/layer-2/smardex-factory.json +185 -0
- package/build/abi/smardex/layer-2/smardex-pool.json +578 -0
- package/build/abi/swaap-v1/pool.json +1346 -0
- package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +193 -0
- package/build/abi/velodrome-slipstream/VelodromeSlipstreamQuoterV2.abi.json +267 -0
- package/build/dex/aave-v1/aave-v1.d.ts +34 -0
- package/build/dex/aave-v1/aave-v1.js +180 -0
- package/build/dex/aave-v1/aave-v1.js.map +1 -0
- package/build/dex/aave-v1/config.d.ts +11 -0
- package/build/dex/aave-v1/config.js +20 -0
- package/build/dex/aave-v1/config.js.map +1 -0
- package/build/dex/aave-v1/tokens-mainnet.json +134 -0
- package/build/dex/aave-v1/tokens.d.ts +3 -0
- package/build/dex/aave-v1/tokens.js +50 -0
- package/build/dex/aave-v1/tokens.js.map +1 -0
- package/build/dex/aave-v1/types.d.ts +12 -0
- package/build/dex/aave-v1/types.js +3 -0
- package/build/dex/aave-v1/types.js.map +1 -0
- package/build/dex/aave-v3-stata/config.js +8 -8
- package/build/dex/aave-v3-stata/config.js.map +1 -1
- package/build/dex/aave-v3-stata-v2/aave-v3-stata-v2.js +2 -2
- package/build/dex/aave-v3-stata-v2/aave-v3-stata-v2.js.map +1 -1
- package/build/dex/aave-v3-stata-v2/config.js +31 -24
- package/build/dex/aave-v3-stata-v2/config.js.map +1 -1
- package/build/dex/aave-v3-stata-v2/types.d.ts +3 -2
- package/build/dex/aave-v3-stata-v2/types.js.map +1 -1
- package/build/dex/aave-v3-stata-v2/utils.d.ts +2 -2
- package/build/dex/aave-v3-stata-v2/utils.js +7 -6
- package/build/dex/aave-v3-stata-v2/utils.js.map +1 -1
- package/build/dex/balancer-v1/balancer-pools.json +33333 -0
- package/build/dex/bebop/websocket-fetcher.d.ts +35 -0
- package/build/dex/bebop/websocket-fetcher.js +87 -0
- package/build/dex/bebop/websocket-fetcher.js.map +1 -0
- package/build/dex/ekubo/config.d.ts +3 -0
- package/build/dex/ekubo/config.js +16 -0
- package/build/dex/ekubo/config.js.map +1 -0
- package/build/dex/ekubo/ekubo.d.ts +49 -0
- package/build/dex/ekubo/ekubo.js +419 -0
- package/build/dex/ekubo/ekubo.js.map +1 -0
- package/build/dex/ekubo/pools/base-pool.d.ts +47 -0
- package/build/dex/ekubo/pools/base-pool.js +184 -0
- package/build/dex/ekubo/pools/base-pool.js.map +1 -0
- package/build/dex/ekubo/pools/math/constants.d.ts +3 -0
- package/build/dex/ekubo/pools/math/constants.js +7 -0
- package/build/dex/ekubo/pools/math/constants.js.map +1 -0
- package/build/dex/ekubo/pools/math/delta.d.ts +2 -0
- package/build/dex/ekubo/pools/math/delta.js +51 -0
- package/build/dex/ekubo/pools/math/delta.js.map +1 -0
- package/build/dex/ekubo/pools/math/price.d.ts +7 -0
- package/build/dex/ekubo/pools/math/price.js +116 -0
- package/build/dex/ekubo/pools/math/price.js.map +1 -0
- package/build/dex/ekubo/pools/math/swap.d.ts +18 -0
- package/build/dex/ekubo/pools/math/swap.js +128 -0
- package/build/dex/ekubo/pools/math/swap.js.map +1 -0
- package/build/dex/ekubo/pools/math/tick.d.ts +7 -0
- package/build/dex/ekubo/pools/math/tick.js +112 -0
- package/build/dex/ekubo/pools/math/tick.js.map +1 -0
- package/build/dex/ekubo/pools/oracle-pool.d.ts +10 -0
- package/build/dex/ekubo/pools/oracle-pool.js +19 -0
- package/build/dex/ekubo/pools/oracle-pool.js.map +1 -0
- package/build/dex/ekubo/types.d.ts +88 -0
- package/build/dex/ekubo/types.js +238 -0
- package/build/dex/ekubo/types.js.map +1 -0
- package/build/dex/ekubo/utils.d.ts +6 -0
- package/build/dex/ekubo/utils.js +30 -0
- package/build/dex/ekubo/utils.js.map +1 -0
- package/build/dex/idle-dao/idle-dao-pool.d.ts +56 -0
- package/build/dex/idle-dao/idle-dao-pool.js +176 -0
- package/build/dex/idle-dao/idle-dao-pool.js.map +1 -0
- package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +16 -0
- package/build/dex/idle-dao/idle-dao-pooling-pool.js +57 -0
- package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +1 -0
- package/build/dex/idle-dao/scripts.d.ts +9 -0
- package/build/dex/idle-dao/scripts.js +552 -0
- package/build/dex/idle-dao/scripts.js.map +1 -0
- package/build/dex/inception/config.d.ts +4 -0
- package/build/dex/inception/config.js +109 -0
- package/build/dex/inception/config.js.map +1 -0
- package/build/dex/inception/inception-event-pool.d.ts +16 -0
- package/build/dex/inception/inception-event-pool.js +51 -0
- package/build/dex/inception/inception-event-pool.js.map +1 -0
- package/build/dex/inception/inception-native.d.ts +43 -0
- package/build/dex/inception/inception-native.js +131 -0
- package/build/dex/inception/inception-native.js.map +1 -0
- package/build/dex/inception/inception-pool.d.ts +18 -0
- package/build/dex/inception/inception-pool.js +32 -0
- package/build/dex/inception/inception-pool.js.map +1 -0
- package/build/dex/inception/inception-price-feed.d.ts +19 -0
- package/build/dex/inception/inception-price-feed.js +51 -0
- package/build/dex/inception/inception-price-feed.js.map +1 -0
- package/build/dex/inception/inception.d.ts +43 -0
- package/build/dex/inception/inception.js +204 -0
- package/build/dex/inception/inception.js.map +1 -0
- package/build/dex/inception/tokens.d.ts +9 -0
- package/build/dex/inception/tokens.js +28 -0
- package/build/dex/inception/tokens.js.map +1 -0
- package/build/dex/inception/types.d.ts +22 -0
- package/build/dex/inception/types.js +3 -0
- package/build/dex/inception/types.js.map +1 -0
- package/build/dex/inception/utils.d.ts +6 -0
- package/build/dex/inception/utils.js +37 -0
- package/build/dex/inception/utils.js.map +1 -0
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/platypus/asset.d.ts +14 -0
- package/build/dex/platypus/asset.js +97 -0
- package/build/dex/platypus/asset.js.map +1 -0
- package/build/dex/platypus/config.d.ts +11 -0
- package/build/dex/platypus/config.js +69 -0
- package/build/dex/platypus/config.js.map +1 -0
- package/build/dex/platypus/platypus.d.ts +63 -0
- package/build/dex/platypus/platypus.js +473 -0
- package/build/dex/platypus/platypus.js.map +1 -0
- package/build/dex/platypus/pool-avax.d.ts +8 -0
- package/build/dex/platypus/pool-avax.js +54 -0
- package/build/dex/platypus/pool-avax.js.map +1 -0
- package/build/dex/platypus/pool-base.d.ts +19 -0
- package/build/dex/platypus/pool-base.js +86 -0
- package/build/dex/platypus/pool-base.js.map +1 -0
- package/build/dex/platypus/pool-pure.d.ts +8 -0
- package/build/dex/platypus/pool-pure.js +37 -0
- package/build/dex/platypus/pool-pure.js.map +1 -0
- package/build/dex/platypus/pool-subscriber.d.ts +14 -0
- package/build/dex/platypus/pool-subscriber.js +167 -0
- package/build/dex/platypus/pool-subscriber.js.map +1 -0
- package/build/dex/platypus/pool.d.ts +8 -0
- package/build/dex/platypus/pool.js +58 -0
- package/build/dex/platypus/pool.js.map +1 -0
- package/build/dex/platypus/types.d.ts +92 -0
- package/build/dex/platypus/types.js +10 -0
- package/build/dex/platypus/types.js.map +1 -0
- package/build/dex/quickswap/spiritswap-v3.d.ts +6 -0
- package/build/dex/quickswap/spiritswap-v3.js +19 -0
- package/build/dex/quickswap/spiritswap-v3.js.map +1 -0
- package/build/dex/smardex/config.d.ts +4 -0
- package/build/dex/smardex/config.js +64 -0
- package/build/dex/smardex/config.js.map +1 -0
- package/build/dex/smardex/constants.d.ts +18 -0
- package/build/dex/smardex/constants.js +33 -0
- package/build/dex/smardex/constants.js.map +1 -0
- package/build/dex/smardex/sdk/constants.d.ts +6 -0
- package/build/dex/smardex/sdk/constants.js +13 -0
- package/build/dex/smardex/sdk/constants.js.map +1 -0
- package/build/dex/smardex/sdk/core.d.ts +113 -0
- package/build/dex/smardex/sdk/core.js +499 -0
- package/build/dex/smardex/sdk/core.js.map +1 -0
- package/build/dex/smardex/sdk/errors.d.ts +15 -0
- package/build/dex/smardex/sdk/errors.js +22 -0
- package/build/dex/smardex/sdk/errors.js.map +1 -0
- package/build/dex/smardex/sdk/types.d.ts +62 -0
- package/build/dex/smardex/sdk/types.js +3 -0
- package/build/dex/smardex/sdk/types.js.map +1 -0
- package/build/dex/smardex/sdk/utils.d.ts +44 -0
- package/build/dex/smardex/sdk/utils.js +133 -0
- package/build/dex/smardex/sdk/utils.js.map +1 -0
- package/build/dex/smardex/smardex-event-pool.d.ts +28 -0
- package/build/dex/smardex/smardex-event-pool.js +119 -0
- package/build/dex/smardex/smardex-event-pool.js.map +1 -0
- package/build/dex/smardex/smardex.d.ts +65 -0
- package/build/dex/smardex/smardex.js +519 -0
- package/build/dex/smardex/smardex.js.map +1 -0
- package/build/dex/smardex/types.d.ts +55 -0
- package/build/dex/smardex/types.js +3 -0
- package/build/dex/smardex/types.js.map +1 -0
- package/build/dex/solidly/forks-override/cone.d.ts +22 -0
- package/build/dex/solidly/forks-override/cone.js +53 -0
- package/build/dex/solidly/forks-override/cone.js.map +1 -0
- package/build/dex/solidly/forks-override/solisnek.d.ts +8 -0
- package/build/dex/solidly/forks-override/solisnek.js +15 -0
- package/build/dex/solidly/forks-override/solisnek.js.map +1 -0
- package/build/dex/swaap-v1/config.d.ts +17 -0
- package/build/dex/swaap-v1/config.js +56 -0
- package/build/dex/swaap-v1/config.js.map +1 -0
- package/build/dex/swaap-v1/constants.d.ts +6 -0
- package/build/dex/swaap-v1/constants.js +17 -0
- package/build/dex/swaap-v1/constants.js.map +1 -0
- package/build/dex/swaap-v1/libraries/ChainlinkUtils.d.ts +25 -0
- package/build/dex/swaap-v1/libraries/ChainlinkUtils.js +62 -0
- package/build/dex/swaap-v1/libraries/ChainlinkUtils.js.map +1 -0
- package/build/dex/swaap-v1/libraries/Const.d.ts +18 -0
- package/build/dex/swaap-v1/libraries/Const.js +26 -0
- package/build/dex/swaap-v1/libraries/Const.js.map +1 -0
- package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.d.ts +77 -0
- package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js +316 -0
- package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js.map +1 -0
- package/build/dex/swaap-v1/libraries/LogExpMath.d.ts +75 -0
- package/build/dex/swaap-v1/libraries/LogExpMath.js +418 -0
- package/build/dex/swaap-v1/libraries/LogExpMath.js.map +1 -0
- package/build/dex/swaap-v1/libraries/MathMMM.d.ts +185 -0
- package/build/dex/swaap-v1/libraries/MathMMM.js +453 -0
- package/build/dex/swaap-v1/libraries/MathMMM.js.map +1 -0
- package/build/dex/swaap-v1/libraries/Num.d.ts +31 -0
- package/build/dex/swaap-v1/libraries/Num.js +167 -0
- package/build/dex/swaap-v1/libraries/Num.js.map +1 -0
- package/build/dex/swaap-v1/libraries/PoolQuotations.d.ts +23 -0
- package/build/dex/swaap-v1/libraries/PoolQuotations.js +131 -0
- package/build/dex/swaap-v1/libraries/PoolQuotations.js.map +1 -0
- package/build/dex/swaap-v1/libraries/Struct.d.ts +56 -0
- package/build/dex/swaap-v1/libraries/Struct.js +3 -0
- package/build/dex/swaap-v1/libraries/Struct.js.map +1 -0
- package/build/dex/swaap-v1/swaap-v1-pool.d.ts +45 -0
- package/build/dex/swaap-v1/swaap-v1-pool.js +656 -0
- package/build/dex/swaap-v1/swaap-v1-pool.js.map +1 -0
- package/build/dex/swaap-v1/swaap-v1.d.ts +62 -0
- package/build/dex/swaap-v1/swaap-v1.js +379 -0
- package/build/dex/swaap-v1/swaap-v1.js.map +1 -0
- package/build/dex/swaap-v1/types.d.ts +106 -0
- package/build/dex/swaap-v1/types.js +9 -0
- package/build/dex/swaap-v1/types.js.map +1 -0
- package/build/dex/zerox/index.d.ts +1 -1
- package/build/dex/zerox/index.js.map +1 -1
- package/build/dex-helper/dummy-dex-helper.js +3 -0
- package/build/dex-helper/dummy-dex-helper.js.map +1 -1
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +16 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +16 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +16 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +16 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-dai-usdc-eth.json +16 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-eth-usdc-dai.json +16 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +16 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdt-usdc-dai.json +16 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-eth-usdc.json +9 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-eth.json +9 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-wbtc.json +9 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-eth-steth.json +9 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-steth-eth.json +9 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-usdc-usdt.json +9 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-eth-usdc.json +9 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-eth.json +9 -0
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-usdt.json +9 -0
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +12 -0
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +7 -0
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +7 -0
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-dai-usdc-eth.json +7 -0
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-eth-usdc-dai.json +7 -0
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +12 -0
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-eth-usdc.json +7 -0
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-usdc-eth.json +7 -0
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +78 -0
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +81 -0
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +78 -0
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +78 -0
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-dai-usdc-eth.json +81 -0
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-eth-usdc-dai.json +81 -0
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +81 -0
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdt-usdc-dai.json +81 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-eth-usdc.json +64 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-eth.json +85 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-wbtc.json +64 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-eth-steth.json +52 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-steth-eth.json +52 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-usdc-usdt.json +52 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-eth-usdc.json +55 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-eth.json +55 -0
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-usdt.json +55 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +23 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +37 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +23 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +23 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +51 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiswap-univ3-usdt-dai-eth.json +58 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +23 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +23 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +9 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +16 -0
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +23 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +12 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +7 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +12 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +12 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +7 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-univ3-usdt-dai-eth.json +7 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +7 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +7 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +7 -0
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +7 -0
- package/build/executor/fixtures/executor02/routes/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +130 -0
- package/build/executor/fixtures/executor02/routes/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +136 -0
- package/build/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +100 -0
- package/build/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +100 -0
- package/build/executor/fixtures/executor02/routes/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +166 -0
- package/build/executor/fixtures/executor02/routes/price-route-multiswap-univ3-usdt-dai-eth.json +190 -0
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +114 -0
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +114 -0
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +55 -0
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +73 -0
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +82 -0
- package/package.json +2 -2
- package/src/abi/ekubo/core.json +1266 -0
- package/src/abi/ekubo/data-fetcher.json +161 -0
- package/src/abi/ekubo/router.json +803 -0
- package/src/dex/aave-v3-stata/config.ts +8 -8
- package/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-e2e.test.ts +5 -5
- package/src/dex/aave-v3-stata-v2/aave-v3-stata-v2.ts +2 -2
- package/src/dex/aave-v3-stata-v2/config.ts +31 -24
- package/src/dex/aave-v3-stata-v2/types.ts +3 -2
- package/src/dex/aave-v3-stata-v2/utils.ts +18 -10
- package/src/dex/ekubo/config.ts +15 -0
- package/src/dex/ekubo/ekubo-e2e.test.ts +124 -0
- package/src/dex/ekubo/ekubo-events.test.ts +209 -0
- package/src/dex/ekubo/ekubo-integration.test.ts +243 -0
- package/src/dex/ekubo/ekubo.ts +657 -0
- package/src/dex/ekubo/pools/base-pool.ts +267 -0
- package/src/dex/ekubo/pools/math/constants.ts +5 -0
- package/src/dex/ekubo/pools/math/delta.test.ts +131 -0
- package/src/dex/ekubo/pools/math/delta.ts +68 -0
- package/src/dex/ekubo/pools/math/price.test.ts +54 -0
- package/src/dex/ekubo/pools/math/price.ts +129 -0
- package/src/dex/ekubo/pools/math/swap.test.ts +215 -0
- package/src/dex/ekubo/pools/math/swap.ts +161 -0
- package/src/dex/ekubo/pools/math/tick.test.ts +72 -0
- package/src/dex/ekubo/pools/math/tick.ts +120 -0
- package/src/dex/ekubo/pools/oracle-pool.ts +46 -0
- package/src/dex/ekubo/types.test.ts +552 -0
- package/src/dex/ekubo/types.ts +408 -0
- package/src/dex/ekubo/utils.ts +34 -0
- package/src/dex/index.ts +2 -0
- package/src/dex-helper/dummy-dex-helper.ts +10 -0
- package/tests/constants-e2e.ts +15 -0
- package/tests/utils-e2e.ts +0 -1
- package/.idea/codeStyles/Project.xml +0 -59
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/paraswap-dex-lib.iml +0 -12
- package/.idea/prettier.xml +0 -7
- package/.idea/vcs.xml +0 -6
- package/scripts/get-uniswap-v3-dexes.ts +0 -64
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { Interface, Result } from '@ethersproject/abi';
|
|
2
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
3
|
+
import { Log, Logger } from '../../../types';
|
|
4
|
+
import { catchParseLogError } from '../../../utils';
|
|
5
|
+
import { StatefulEventSubscriber } from '../../../stateful-event-subscriber';
|
|
6
|
+
import { IDexHelper } from '../../../dex-helper/idex-helper';
|
|
7
|
+
import { PoolKey, PoolState } from '../types';
|
|
8
|
+
import { Contract } from 'ethers';
|
|
9
|
+
import _ from 'lodash';
|
|
10
|
+
import { computeStep, isPriceIncreasing } from './math/swap';
|
|
11
|
+
import {
|
|
12
|
+
approximateNumberOfTickSpacingsCrossed,
|
|
13
|
+
FULL_RANGE_TICK_SPACING,
|
|
14
|
+
MAX_SQRT_RATIO,
|
|
15
|
+
MIN_SQRT_RATIO,
|
|
16
|
+
toSqrtRatio,
|
|
17
|
+
} from './math/tick';
|
|
18
|
+
import { floatSqrtRatioToFixed } from './math/price';
|
|
19
|
+
|
|
20
|
+
export interface Quote {
|
|
21
|
+
consumedAmount: bigint;
|
|
22
|
+
calculatedAmount: bigint;
|
|
23
|
+
gasConsumed: number;
|
|
24
|
+
skipAhead: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const BASE_GAS_COST = 75_000;
|
|
28
|
+
const GAS_COST_OF_ONE_INITIALIZED_TICK_CROSSED = 20_000;
|
|
29
|
+
const GAS_COST_OF_ONE_TICK_SPACING_CROSSED = 4_000;
|
|
30
|
+
|
|
31
|
+
export class BasePool extends StatefulEventSubscriber<PoolState.Object> {
|
|
32
|
+
public readonly addressesSubscribed: string[];
|
|
33
|
+
|
|
34
|
+
constructor(
|
|
35
|
+
public readonly parentName: string,
|
|
36
|
+
protected network: number,
|
|
37
|
+
protected dexHelper: IDexHelper,
|
|
38
|
+
logger: Logger,
|
|
39
|
+
private readonly coreIface: Interface,
|
|
40
|
+
private readonly dataFetcher: Contract,
|
|
41
|
+
public readonly key: PoolKey,
|
|
42
|
+
core: Contract,
|
|
43
|
+
) {
|
|
44
|
+
super(parentName, key.string_id, dexHelper, logger);
|
|
45
|
+
|
|
46
|
+
this.addressesSubscribed = [core.address];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The function is called every time any of the subscribed
|
|
51
|
+
* addresses release log. The function accepts the current
|
|
52
|
+
* state, updates the state according to the log, and returns
|
|
53
|
+
* the updated state.
|
|
54
|
+
* @param state - Current state of event subscriber
|
|
55
|
+
* @param log - Log released by one of the subscribed addresses
|
|
56
|
+
* @returns Updates state of the event subscriber after the log
|
|
57
|
+
*/
|
|
58
|
+
protected processLog(
|
|
59
|
+
state: DeepReadonly<PoolState.Object>,
|
|
60
|
+
log: Readonly<Log>,
|
|
61
|
+
): DeepReadonly<PoolState.Object> | null {
|
|
62
|
+
if (log.topics.length === 0) {
|
|
63
|
+
return this.handleSwappedEvent(log.data, state);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const event = this.coreIface.parseLog(log);
|
|
68
|
+
|
|
69
|
+
if (event.name === 'PositionUpdated') {
|
|
70
|
+
return this.handlePositionUpdatedEvent(event.args, state);
|
|
71
|
+
}
|
|
72
|
+
} catch (e) {
|
|
73
|
+
catchParseLogError(e, this.logger);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The function generates state using on-chain calls. This
|
|
81
|
+
* function is called to regenerate state if the event based
|
|
82
|
+
* system fails to fetch events and the local state is no
|
|
83
|
+
* more correct.
|
|
84
|
+
* @param blockNumber - Blocknumber for which the state should
|
|
85
|
+
* should be generated
|
|
86
|
+
* @returns state of the event subscriber at blocknumber
|
|
87
|
+
*/
|
|
88
|
+
async generateState(
|
|
89
|
+
blockNumber: number,
|
|
90
|
+
): Promise<DeepReadonly<PoolState.Object>> {
|
|
91
|
+
const data = await this.dataFetcher.getQuoteData([this.key.toAbi()], 10, {
|
|
92
|
+
blockTag: blockNumber,
|
|
93
|
+
});
|
|
94
|
+
return PoolState.fromQuoter(
|
|
95
|
+
data[0],
|
|
96
|
+
this.key.config.tickSpacing === FULL_RANGE_TICK_SPACING,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
handleSwappedEvent(
|
|
101
|
+
data: string,
|
|
102
|
+
oldState: DeepReadonly<PoolState.Object>,
|
|
103
|
+
): DeepReadonly<PoolState.Object> | null {
|
|
104
|
+
let n = BigInt(data);
|
|
105
|
+
|
|
106
|
+
const poolId = (n >> 512n) & ((1n << 256n) - 1n);
|
|
107
|
+
|
|
108
|
+
if (this.key.num_id !== poolId) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// tick: int32 (4 bytes)
|
|
113
|
+
const tickRaw = n & ((1n << 32n) - 1n);
|
|
114
|
+
const tickAfter = Number(toSigned(tickRaw, 32));
|
|
115
|
+
n >>= 32n;
|
|
116
|
+
|
|
117
|
+
// sqrtRatio: uint96 (12 bytes)
|
|
118
|
+
const sqrtRatioAfterCompact = n & ((1n << 96n) - 1n);
|
|
119
|
+
n >>= 96n;
|
|
120
|
+
|
|
121
|
+
const sqrtRatioAfter = floatSqrtRatioToFixed(sqrtRatioAfterCompact);
|
|
122
|
+
|
|
123
|
+
// liquidity: uint128 (16 bytes)
|
|
124
|
+
const liquidityAfter = n & ((1n << 128n) - 1n);
|
|
125
|
+
|
|
126
|
+
return PoolState.fromSwappedEvent(
|
|
127
|
+
oldState,
|
|
128
|
+
sqrtRatioAfter,
|
|
129
|
+
liquidityAfter,
|
|
130
|
+
tickAfter,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
handlePositionUpdatedEvent(
|
|
135
|
+
args: Result,
|
|
136
|
+
oldState: DeepReadonly<PoolState.Object>,
|
|
137
|
+
): DeepReadonly<PoolState.Object> | null {
|
|
138
|
+
if (this.key.num_id !== BigInt(args.poolId)) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const params = args.params;
|
|
143
|
+
|
|
144
|
+
return PoolState.fromPositionUpdatedEvent(
|
|
145
|
+
oldState,
|
|
146
|
+
[params.bounds.lower, params.bounds.upper],
|
|
147
|
+
params.liquidityDelta.toBigInt(),
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
public quote(amount: bigint, token: bigint, blockNumber: number): Quote {
|
|
152
|
+
const isToken1 = token === this.key.token1;
|
|
153
|
+
|
|
154
|
+
if (!isToken1 && this.key.token0 !== token) {
|
|
155
|
+
throw new Error('Invalid token');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (amount === 0n) {
|
|
159
|
+
return {
|
|
160
|
+
consumedAmount: 0n,
|
|
161
|
+
calculatedAmount: 0n,
|
|
162
|
+
gasConsumed: 0,
|
|
163
|
+
skipAhead: 0,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const isIncreasing = isPriceIncreasing(amount, isToken1);
|
|
168
|
+
|
|
169
|
+
let state = this.getState(blockNumber);
|
|
170
|
+
if (state === null) {
|
|
171
|
+
throw new Error(
|
|
172
|
+
`Quote for block number ${blockNumber} requested but state is not recent enough`,
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let { sqrtRatio, liquidity, activeTickIndex, sortedTicks } = state;
|
|
177
|
+
|
|
178
|
+
const sqrtRatioLimit = isIncreasing ? MAX_SQRT_RATIO : MIN_SQRT_RATIO;
|
|
179
|
+
|
|
180
|
+
let calculatedAmount = 0n;
|
|
181
|
+
let initializedTicksCrossed = 0;
|
|
182
|
+
let amountRemaining = amount;
|
|
183
|
+
|
|
184
|
+
const startingSqrtRatio = sqrtRatio;
|
|
185
|
+
|
|
186
|
+
while (amountRemaining !== 0n && sqrtRatio !== sqrtRatioLimit) {
|
|
187
|
+
const nextInitializedTick =
|
|
188
|
+
(isIncreasing
|
|
189
|
+
? sortedTicks[activeTickIndex === null ? 0 : activeTickIndex + 1]
|
|
190
|
+
: activeTickIndex === null
|
|
191
|
+
? null
|
|
192
|
+
: sortedTicks[activeTickIndex]) ?? null;
|
|
193
|
+
|
|
194
|
+
const nextInitializedTickSqrtRatio = nextInitializedTick
|
|
195
|
+
? toSqrtRatio(nextInitializedTick.number)
|
|
196
|
+
: null;
|
|
197
|
+
|
|
198
|
+
const stepSqrtRatioLimit =
|
|
199
|
+
nextInitializedTickSqrtRatio === null
|
|
200
|
+
? sqrtRatioLimit
|
|
201
|
+
: nextInitializedTickSqrtRatio < sqrtRatioLimit === isIncreasing
|
|
202
|
+
? nextInitializedTickSqrtRatio
|
|
203
|
+
: sqrtRatioLimit;
|
|
204
|
+
|
|
205
|
+
const step = computeStep({
|
|
206
|
+
fee: this.key.config.fee,
|
|
207
|
+
sqrtRatio,
|
|
208
|
+
liquidity,
|
|
209
|
+
isToken1,
|
|
210
|
+
sqrtRatioLimit: stepSqrtRatioLimit,
|
|
211
|
+
amount: amountRemaining,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
amountRemaining -= step.consumedAmount;
|
|
215
|
+
calculatedAmount += step.calculatedAmount;
|
|
216
|
+
sqrtRatio = step.sqrtRatioNext;
|
|
217
|
+
|
|
218
|
+
// cross the tick if the price moved all the way to the next initialized tick price
|
|
219
|
+
if (nextInitializedTick && sqrtRatio === nextInitializedTickSqrtRatio) {
|
|
220
|
+
activeTickIndex = isIncreasing
|
|
221
|
+
? activeTickIndex === null
|
|
222
|
+
? 0
|
|
223
|
+
: activeTickIndex + 1
|
|
224
|
+
: activeTickIndex
|
|
225
|
+
? activeTickIndex - 1
|
|
226
|
+
: null;
|
|
227
|
+
initializedTicksCrossed++;
|
|
228
|
+
liquidity += isIncreasing
|
|
229
|
+
? nextInitializedTick.liquidityDelta
|
|
230
|
+
: -nextInitializedTick.liquidityDelta;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const tickSpacingsCrossed = approximateNumberOfTickSpacingsCrossed(
|
|
235
|
+
startingSqrtRatio,
|
|
236
|
+
sqrtRatio,
|
|
237
|
+
this.key.config.tickSpacing,
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
consumedAmount: amount - amountRemaining,
|
|
242
|
+
calculatedAmount,
|
|
243
|
+
gasConsumed:
|
|
244
|
+
BASE_GAS_COST +
|
|
245
|
+
initializedTicksCrossed * GAS_COST_OF_ONE_INITIALIZED_TICK_CROSSED +
|
|
246
|
+
tickSpacingsCrossed * GAS_COST_OF_ONE_TICK_SPACING_CROSSED,
|
|
247
|
+
skipAhead:
|
|
248
|
+
initializedTicksCrossed === 0
|
|
249
|
+
? 0
|
|
250
|
+
: Math.floor(tickSpacingsCrossed / initializedTicksCrossed),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
public computeTvl(): [bigint, bigint] | null {
|
|
255
|
+
const state = this.getStaleState();
|
|
256
|
+
if (state === null) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return PoolState.computeTvl(state);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function toSigned(value: bigint, bits: number): bigint {
|
|
265
|
+
const half = 1n << BigInt(bits - 1);
|
|
266
|
+
return value >= half ? value - (1n << BigInt(bits)) : value;
|
|
267
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { amount0Delta, amount1Delta } from './delta';
|
|
2
|
+
import { MAX_SQRT_RATIO, MIN_SQRT_RATIO } from './tick';
|
|
3
|
+
|
|
4
|
+
describe(amount0Delta, () => {
|
|
5
|
+
it('price_down', () => {
|
|
6
|
+
expect(
|
|
7
|
+
amount0Delta(
|
|
8
|
+
339942424496442021441932674757011200255n,
|
|
9
|
+
0x100000000000000000000000000000000n,
|
|
10
|
+
1000000n,
|
|
11
|
+
false,
|
|
12
|
+
),
|
|
13
|
+
).toMatchInlineSnapshot(`1000n`);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('price_down_reverse', () => {
|
|
17
|
+
expect(
|
|
18
|
+
amount0Delta(
|
|
19
|
+
0x100000000000000000000000000000000n,
|
|
20
|
+
339942424496442021441932674757011200255n,
|
|
21
|
+
1000000n,
|
|
22
|
+
false,
|
|
23
|
+
),
|
|
24
|
+
).toMatchInlineSnapshot(`1000n`);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('price example down', () => {
|
|
28
|
+
expect(
|
|
29
|
+
amount0Delta(
|
|
30
|
+
0x100000000000000000000000000000000n,
|
|
31
|
+
34028236692093846346337460743176821145n + (1n << 128n),
|
|
32
|
+
1000000000000000000n,
|
|
33
|
+
false,
|
|
34
|
+
),
|
|
35
|
+
).toMatchInlineSnapshot(`90909090909090909n`);
|
|
36
|
+
});
|
|
37
|
+
it('price example up', () => {
|
|
38
|
+
expect(
|
|
39
|
+
amount0Delta(
|
|
40
|
+
0x100000000000000000000000000000000n,
|
|
41
|
+
34028236692093846346337460743176821145n + (1n << 128n),
|
|
42
|
+
1000000000000000000n,
|
|
43
|
+
true,
|
|
44
|
+
),
|
|
45
|
+
).toMatchInlineSnapshot(`90909090909090910n`);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe(amount1Delta, () => {
|
|
50
|
+
it('price_down', () => {
|
|
51
|
+
expect(
|
|
52
|
+
amount1Delta(
|
|
53
|
+
339942424496442021441932674757011200255n,
|
|
54
|
+
0x100000000000000000000000000000000n,
|
|
55
|
+
1000000n,
|
|
56
|
+
false,
|
|
57
|
+
),
|
|
58
|
+
).toMatchInlineSnapshot(`999n`);
|
|
59
|
+
});
|
|
60
|
+
it('price_down_reverse', () => {
|
|
61
|
+
expect(
|
|
62
|
+
amount1Delta(
|
|
63
|
+
0x100000000000000000000000000000000n,
|
|
64
|
+
339942424496442021441932674757011200255n,
|
|
65
|
+
1000000n,
|
|
66
|
+
false,
|
|
67
|
+
),
|
|
68
|
+
).toMatchInlineSnapshot(`999n`);
|
|
69
|
+
});
|
|
70
|
+
it('price_up', () => {
|
|
71
|
+
expect(
|
|
72
|
+
amount1Delta(
|
|
73
|
+
340622989910849312776150758189957120n + (1n << 128n),
|
|
74
|
+
0x100000000000000000000000000000000n,
|
|
75
|
+
1000000n,
|
|
76
|
+
false,
|
|
77
|
+
),
|
|
78
|
+
).toMatchInlineSnapshot(`1001n`);
|
|
79
|
+
});
|
|
80
|
+
it('price_up_reverse', () => {
|
|
81
|
+
expect(
|
|
82
|
+
amount1Delta(
|
|
83
|
+
0x100000000000000000000000000000000n,
|
|
84
|
+
339942424496442021441932674757011200255n,
|
|
85
|
+
1000000n,
|
|
86
|
+
true,
|
|
87
|
+
),
|
|
88
|
+
).toMatchInlineSnapshot(`1000n`);
|
|
89
|
+
});
|
|
90
|
+
it('price_example_down', () => {
|
|
91
|
+
expect(
|
|
92
|
+
amount1Delta(
|
|
93
|
+
0x100000000000000000000000000000000n,
|
|
94
|
+
309347606291762239512158734028880192232n,
|
|
95
|
+
1000000000000000000n,
|
|
96
|
+
false,
|
|
97
|
+
),
|
|
98
|
+
).toMatchInlineSnapshot(`90909090909090909n`);
|
|
99
|
+
});
|
|
100
|
+
it('price_example_up', () => {
|
|
101
|
+
expect(
|
|
102
|
+
amount1Delta(
|
|
103
|
+
0x100000000000000000000000000000000n,
|
|
104
|
+
309347606291762239512158734028880192232n,
|
|
105
|
+
1000000000000000000n,
|
|
106
|
+
true,
|
|
107
|
+
),
|
|
108
|
+
).toMatchInlineSnapshot(`90909090909090910n`);
|
|
109
|
+
});
|
|
110
|
+
it('no overflow half price range', () => {
|
|
111
|
+
expect(
|
|
112
|
+
amount1Delta(
|
|
113
|
+
0x100000000000000000000000000000000n,
|
|
114
|
+
MAX_SQRT_RATIO,
|
|
115
|
+
0xffffffffffffffffn,
|
|
116
|
+
false,
|
|
117
|
+
),
|
|
118
|
+
).toMatchInlineSnapshot(`340274119756928397675478831271437331477n`);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should panic', () => {
|
|
122
|
+
expect(() =>
|
|
123
|
+
amount1Delta(
|
|
124
|
+
MIN_SQRT_RATIO,
|
|
125
|
+
MAX_SQRT_RATIO,
|
|
126
|
+
0xffffffffffffffffffffffffffffffffn,
|
|
127
|
+
false,
|
|
128
|
+
),
|
|
129
|
+
).toThrow('AMOUNT1_DELTA_OVERFLOW_U256');
|
|
130
|
+
});
|
|
131
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { MAX_U128, MAX_U256 } from './constants';
|
|
2
|
+
|
|
3
|
+
export function amount0Delta(
|
|
4
|
+
sqrtRatioA: bigint,
|
|
5
|
+
sqrtRatioB: bigint,
|
|
6
|
+
liquidity: bigint,
|
|
7
|
+
roundUp: boolean,
|
|
8
|
+
): bigint {
|
|
9
|
+
if (liquidity === 0n || sqrtRatioA === sqrtRatioB) return 0n;
|
|
10
|
+
|
|
11
|
+
const [lower, upper] =
|
|
12
|
+
sqrtRatioA < sqrtRatioB
|
|
13
|
+
? [sqrtRatioA, sqrtRatioB]
|
|
14
|
+
: [sqrtRatioB, sqrtRatioA];
|
|
15
|
+
|
|
16
|
+
const numerator = (liquidity << 128n) * (upper - lower);
|
|
17
|
+
|
|
18
|
+
let result0 = numerator / upper;
|
|
19
|
+
if (roundUp && numerator % upper !== 0n) {
|
|
20
|
+
result0++;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (result0 > MAX_U256) {
|
|
24
|
+
throw new Error('AMOUNT0_DELTA_OVERFLOW_U256');
|
|
25
|
+
}
|
|
26
|
+
let result = result0 / lower;
|
|
27
|
+
if (roundUp && result % lower !== 0n) {
|
|
28
|
+
result++;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (result > MAX_U128) {
|
|
32
|
+
throw new Error('AMOUNT0_DELTA_OVERFLOW_U128');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const TWO_POW_128 = 0x100000000000000000000000000000000n;
|
|
39
|
+
|
|
40
|
+
export function amount1Delta(
|
|
41
|
+
sqrtRatioA: bigint,
|
|
42
|
+
sqrtRatioB: bigint,
|
|
43
|
+
liquidity: bigint,
|
|
44
|
+
roundUp: boolean,
|
|
45
|
+
): bigint {
|
|
46
|
+
if (liquidity === 0n || sqrtRatioA === sqrtRatioB) return 0n;
|
|
47
|
+
|
|
48
|
+
const [lower, upper] =
|
|
49
|
+
sqrtRatioA < sqrtRatioB
|
|
50
|
+
? [sqrtRatioA, sqrtRatioB]
|
|
51
|
+
: [sqrtRatioB, sqrtRatioA];
|
|
52
|
+
|
|
53
|
+
const result = liquidity * (upper - lower);
|
|
54
|
+
|
|
55
|
+
if (result > MAX_U256) {
|
|
56
|
+
throw new Error('AMOUNT1_DELTA_OVERFLOW_U256');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (roundUp && result % TWO_POW_128 !== 0n) {
|
|
60
|
+
const delta = result / TWO_POW_128 + 1n;
|
|
61
|
+
if (delta > MAX_U128) {
|
|
62
|
+
throw new Error('AMOUNT1_DELTA_OVERFLOW_U128');
|
|
63
|
+
}
|
|
64
|
+
return delta;
|
|
65
|
+
} else {
|
|
66
|
+
return result >> 128n;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { nextSqrtRatioFromAmount0, nextSqrtRatioFromAmount1 } from './price';
|
|
2
|
+
|
|
3
|
+
describe(nextSqrtRatioFromAmount0, () => {
|
|
4
|
+
it('add_price_goes_down', () => {
|
|
5
|
+
expect(
|
|
6
|
+
nextSqrtRatioFromAmount0(1n << 128n, 1000000n, 1000n),
|
|
7
|
+
).toMatchInlineSnapshot(`339942424496442021441932674757011200256n`);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('exact_out_overflow', () => {
|
|
11
|
+
expect(
|
|
12
|
+
nextSqrtRatioFromAmount0(1n << 128n, 1n, -100000000000000n),
|
|
13
|
+
).toMatchInlineSnapshot(`null`);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('exact_in_cant_underflow', () => {
|
|
17
|
+
expect(
|
|
18
|
+
nextSqrtRatioFromAmount0(1n << 128n, 1n, 100000000000000n),
|
|
19
|
+
).toMatchInlineSnapshot(`3402823669209350606397054n`);
|
|
20
|
+
});
|
|
21
|
+
it('sub_price_goes_up', () => {
|
|
22
|
+
expect(
|
|
23
|
+
nextSqrtRatioFromAmount0(1n << 128n, 100000000000n, -1000n),
|
|
24
|
+
).toMatchInlineSnapshot(`340282370323762166700996274441730955874n`);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe(nextSqrtRatioFromAmount1, () => {
|
|
29
|
+
it('add_price_goes_up', () => {
|
|
30
|
+
expect(
|
|
31
|
+
nextSqrtRatioFromAmount1(1n << 128n, 1000000n, 1000n),
|
|
32
|
+
).toMatchInlineSnapshot(`340622649287859401926837982039199979667n`);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('exact_out_overflow', () => {
|
|
36
|
+
expect(
|
|
37
|
+
nextSqrtRatioFromAmount1(1n << 128n, 1n, -100000000000000n),
|
|
38
|
+
).toMatchInlineSnapshot(`null`);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('exact_in_cant_underflow', () => {
|
|
42
|
+
expect(
|
|
43
|
+
nextSqrtRatioFromAmount1(1n << 128n, 1n, 100000000000000n),
|
|
44
|
+
).toMatchInlineSnapshot(
|
|
45
|
+
`34028236692094186628704381681640284520207431768211456n`,
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('sub_price_goes_down', () => {
|
|
50
|
+
expect(
|
|
51
|
+
nextSqrtRatioFromAmount1(1n << 128n, 100000000000n, -1000n),
|
|
52
|
+
).toMatchInlineSnapshot(`340282363518114794253989972798022137138n`);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { BigNumber } from 'ethers';
|
|
2
|
+
import { MAX_U256 } from './constants';
|
|
3
|
+
import { MAX_SQRT_RATIO, MIN_SQRT_RATIO } from './tick';
|
|
4
|
+
|
|
5
|
+
const BIT_MASK = 0xc00000000000000000000000n;
|
|
6
|
+
const NOT_BIT_MASK = 0x3fffffffffffffffffffffffn;
|
|
7
|
+
|
|
8
|
+
export function floatSqrtRatioToFixed(sqrtRatioFloat: bigint): bigint {
|
|
9
|
+
return (
|
|
10
|
+
(sqrtRatioFloat & NOT_BIT_MASK) <<
|
|
11
|
+
(2n + ((sqrtRatioFloat & BIT_MASK) >> 89n))
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const TWO_POW_192 = 2n ** 192n;
|
|
16
|
+
const TWO_POW_160 = 2n ** 160n;
|
|
17
|
+
const TWO_POW_128 = 2n ** 128n;
|
|
18
|
+
const TWO_POW_96 = 2n ** 96n;
|
|
19
|
+
const TWO_POW_95 = 2n ** 95n;
|
|
20
|
+
const TWO_POW_94 = 2n ** 94n;
|
|
21
|
+
|
|
22
|
+
export function fixedSqrtRatioToFloat(sqrtRatioFixed: bigint): bigint {
|
|
23
|
+
if (sqrtRatioFixed >= TWO_POW_192) {
|
|
24
|
+
throw new Error('Out of bounds');
|
|
25
|
+
} else if (sqrtRatioFixed >= TWO_POW_160) {
|
|
26
|
+
return (sqrtRatioFixed >> 98n) + BIT_MASK;
|
|
27
|
+
} else if (sqrtRatioFixed >= TWO_POW_128) {
|
|
28
|
+
return (sqrtRatioFixed >> 66n) + TWO_POW_95;
|
|
29
|
+
} else if (sqrtRatioFixed >= TWO_POW_96) {
|
|
30
|
+
return (sqrtRatioFixed >> 34n) + TWO_POW_94;
|
|
31
|
+
} else {
|
|
32
|
+
return sqrtRatioFixed >> 2n;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const MAX_SQRT_RATIO_FLOAT = BigNumber.from(
|
|
37
|
+
fixedSqrtRatioToFloat(MAX_SQRT_RATIO),
|
|
38
|
+
);
|
|
39
|
+
export const MIN_SQRT_RATIO_FLOAT = BigNumber.from(
|
|
40
|
+
fixedSqrtRatioToFloat(MIN_SQRT_RATIO),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export function nextSqrtRatioFromAmount0(
|
|
44
|
+
sqrtRatio: bigint,
|
|
45
|
+
liquidity: bigint,
|
|
46
|
+
amount0: bigint,
|
|
47
|
+
): bigint | null {
|
|
48
|
+
if (amount0 === 0n) return sqrtRatio;
|
|
49
|
+
|
|
50
|
+
if (liquidity === 0n) throw new Error('NO_LIQUIDITY');
|
|
51
|
+
|
|
52
|
+
const numerator1 = liquidity << 128n;
|
|
53
|
+
|
|
54
|
+
// because quotient is rounded down, this price movement is also rounded towards sqrt_ratio
|
|
55
|
+
if (amount0 < 0n) {
|
|
56
|
+
const product = amount0 * -1n * sqrtRatio;
|
|
57
|
+
|
|
58
|
+
if (product >= MAX_U256) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const denominator = numerator1 - product;
|
|
63
|
+
|
|
64
|
+
if (denominator < 0n) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const num = numerator1 * sqrtRatio;
|
|
69
|
+
|
|
70
|
+
const result = num / denominator + (num % denominator === 0n ? 0n : 1n);
|
|
71
|
+
|
|
72
|
+
if (result > MAX_U256) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return result;
|
|
77
|
+
} else {
|
|
78
|
+
const denomP1 = numerator1 / sqrtRatio;
|
|
79
|
+
|
|
80
|
+
const denom = denomP1 + amount0;
|
|
81
|
+
const quotient = numerator1 / denom;
|
|
82
|
+
const remainder = numerator1 % denom;
|
|
83
|
+
|
|
84
|
+
if (remainder === 0n) return quotient;
|
|
85
|
+
const sum = quotient + 1n;
|
|
86
|
+
if (sum > MAX_U256) return null;
|
|
87
|
+
return sum;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function nextSqrtRatioFromAmount1(
|
|
92
|
+
sqrtRatio: bigint,
|
|
93
|
+
liquidity: bigint,
|
|
94
|
+
amount1: bigint,
|
|
95
|
+
): bigint | null {
|
|
96
|
+
if (amount1 === 0n) return sqrtRatio;
|
|
97
|
+
|
|
98
|
+
if (liquidity === 0n) throw new Error('NO_LIQUIDITY');
|
|
99
|
+
|
|
100
|
+
const amountShifted = amount1 << 128n;
|
|
101
|
+
const quotient = amountShifted / liquidity;
|
|
102
|
+
const remainder = amountShifted % liquidity;
|
|
103
|
+
|
|
104
|
+
// because quotient is rounded down, this price movement is also rounded towards sqrt_ratio
|
|
105
|
+
if (amount1 < 0n) {
|
|
106
|
+
// adding amount1, taking out amount0
|
|
107
|
+
const res = sqrtRatio + quotient;
|
|
108
|
+
if (res < 0n) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
if (remainder === 0n) {
|
|
112
|
+
return res;
|
|
113
|
+
} else {
|
|
114
|
+
if (res != 0n) {
|
|
115
|
+
return res - 1n;
|
|
116
|
+
} else {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
// adding amount1, taking out amount0, price goes up
|
|
122
|
+
const res = sqrtRatio + quotient;
|
|
123
|
+
if (res > MAX_U256) {
|
|
124
|
+
return null;
|
|
125
|
+
} else {
|
|
126
|
+
return res;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|