sushi 3.2.4 → 4.0.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/dist/_cjs/calculate/fee.js +2 -2
- package/dist/_cjs/calculate/fee.js.map +1 -1
- package/dist/_cjs/index.js +0 -3
- package/dist/_cjs/index.js.map +1 -1
- package/dist/_cjs/math/functions/get-big-int.js +15 -0
- package/dist/_cjs/math/functions/get-big-int.js.map +1 -0
- package/dist/_cjs/math/functions/index.js +3 -1
- package/dist/_cjs/math/functions/index.js.map +1 -1
- package/dist/_cjs/pool/sushiswap-v3/utils/computePoolAddress.js +14 -18
- package/dist/_cjs/pool/sushiswap-v3/utils/computePoolAddress.js.map +1 -1
- package/dist/_cjs/router/index.js +27 -11
- package/dist/_cjs/router/index.js.map +1 -1
- package/dist/_cjs/router/pool-type.js +14 -0
- package/dist/_cjs/router/pool-type.js.map +1 -0
- package/dist/_cjs/router/route-status.js +10 -0
- package/dist/_cjs/router/route-status.js.map +1 -0
- package/dist/_cjs/router/router-liquidity-source.js +9 -0
- package/dist/_cjs/router/router-liquidity-source.js.map +1 -0
- package/dist/_cjs/validate/index.js +1 -0
- package/dist/_cjs/validate/index.js.map +1 -1
- package/dist/_cjs/{serializer/AddressValidation.js → validate/isAddressFast.js} +1 -1
- package/dist/_cjs/validate/isAddressFast.js.map +1 -0
- package/dist/_esm/calculate/fee.js +1 -1
- package/dist/_esm/calculate/fee.js.map +1 -1
- package/dist/_esm/index.js +0 -3
- package/dist/_esm/index.js.map +1 -1
- package/dist/_esm/math/functions/get-big-int.js +12 -0
- package/dist/_esm/math/functions/get-big-int.js.map +1 -0
- package/dist/_esm/math/functions/index.js +1 -0
- package/dist/_esm/math/functions/index.js.map +1 -1
- package/dist/_esm/pool/sushiswap-v3/utils/computePoolAddress.js +15 -18
- package/dist/_esm/pool/sushiswap-v3/utils/computePoolAddress.js.map +1 -1
- package/dist/_esm/router/get-currency-combinations.js +0 -2
- package/dist/_esm/router/get-currency-combinations.js.map +1 -1
- package/dist/_esm/router/index.js +21 -11
- package/dist/_esm/router/index.js.map +1 -1
- package/dist/_esm/router/pool-type.js +11 -0
- package/dist/_esm/router/pool-type.js.map +1 -0
- package/dist/_esm/router/route-status.js +7 -0
- package/dist/_esm/router/route-status.js.map +1 -0
- package/dist/_esm/router/router-liquidity-source.js +6 -0
- package/dist/_esm/router/router-liquidity-source.js.map +1 -0
- package/dist/_esm/validate/index.js +1 -0
- package/dist/_esm/validate/index.js.map +1 -1
- package/dist/_esm/{serializer/AddressValidation.js → validate/isAddressFast.js} +1 -1
- package/dist/_esm/validate/isAddressFast.js.map +1 -0
- package/dist/_types/index.d.ts +0 -3
- package/dist/_types/index.d.ts.map +1 -1
- package/dist/_types/math/functions/get-big-int.d.ts +2 -0
- package/dist/_types/math/functions/get-big-int.d.ts.map +1 -0
- package/dist/_types/math/functions/index.d.ts +1 -0
- package/dist/_types/math/functions/index.d.ts.map +1 -1
- package/dist/_types/pool/sushiswap-v3/utils/computePoolAddress.d.ts.map +1 -1
- package/dist/_types/router/get-currency-combinations.d.ts +2 -2
- package/dist/_types/router/get-currency-combinations.d.ts.map +1 -1
- package/dist/_types/router/index.d.ts +24 -11
- package/dist/_types/router/index.d.ts.map +1 -1
- package/dist/_types/router/pool-type.d.ts +10 -0
- package/dist/_types/router/pool-type.d.ts.map +1 -0
- package/dist/_types/router/route-status.d.ts +6 -0
- package/dist/_types/router/route-status.d.ts.map +1 -0
- package/dist/_types/router/router-liquidity-source.d.ts +5 -0
- package/dist/_types/router/router-liquidity-source.d.ts.map +1 -0
- package/dist/_types/validate/index.d.ts +1 -0
- package/dist/_types/validate/index.d.ts.map +1 -1
- package/dist/_types/{serializer/AddressValidation.d.ts → validate/isAddressFast.d.ts} +1 -1
- package/dist/_types/validate/isAddressFast.d.ts.map +1 -0
- package/package.json +1 -25
- package/dist/_cjs/pricing/IncrementalPricer.js +0 -375
- package/dist/_cjs/pricing/IncrementalPricer.js.map +0 -1
- package/dist/_cjs/pricing/PoolTokenGraph.js +0 -58
- package/dist/_cjs/pricing/PoolTokenGraph.js.map +0 -1
- package/dist/_cjs/pricing/index.js +0 -18
- package/dist/_cjs/pricing/index.js.map +0 -1
- package/dist/_cjs/router/HEXer.js +0 -112
- package/dist/_cjs/router/HEXer.js.map +0 -1
- package/dist/_cjs/router/PoolBinarySerialization.js +0 -466
- package/dist/_cjs/router/PoolBinarySerialization.js.map +0 -1
- package/dist/_cjs/router/Sankey.AnyChart.js +0 -25
- package/dist/_cjs/router/Sankey.AnyChart.js.map +0 -1
- package/dist/_cjs/router/curve-sdk.js +0 -204
- package/dist/_cjs/router/curve-sdk.js.map +0 -1
- package/dist/_cjs/router/data-fetcher.js +0 -159
- package/dist/_cjs/router/data-fetcher.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/ApeSwap.js +0 -31
- package/dist/_cjs/router/liquidity-providers/ApeSwap.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/Biswap.js +0 -26
- package/dist/_cjs/router/liquidity-providers/Biswap.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/CurvePoolsWhitelist.js +0 -3983
- package/dist/_cjs/router/liquidity-providers/CurvePoolsWhitelist.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/CurveProvider.js +0 -398
- package/dist/_cjs/router/liquidity-providers/CurveProvider.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/CurveProviderWhitelist.js +0 -99
- package/dist/_cjs/router/liquidity-providers/CurveProviderWhitelist.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/Dfyn.js +0 -31
- package/dist/_cjs/router/liquidity-providers/Dfyn.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/DovishV3.js +0 -28
- package/dist/_cjs/router/liquidity-providers/DovishV3.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/Elk.js +0 -47
- package/dist/_cjs/router/liquidity-providers/Elk.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/HoneySwap.js +0 -25
- package/dist/_cjs/router/liquidity-providers/HoneySwap.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/JetSwap.js +0 -29
- package/dist/_cjs/router/liquidity-providers/JetSwap.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/LaserSwap.js +0 -26
- package/dist/_cjs/router/liquidity-providers/LaserSwap.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/LiquidityProvider.js +0 -100
- package/dist/_cjs/router/liquidity-providers/LiquidityProvider.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/NativeWrapProvider.js +0 -46
- package/dist/_cjs/router/liquidity-providers/NativeWrapProvider.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/NetSwap.js +0 -25
- package/dist/_cjs/router/liquidity-providers/NetSwap.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/PancakeSwap.js +0 -28
- package/dist/_cjs/router/liquidity-providers/PancakeSwap.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/QuickSwap.js +0 -25
- package/dist/_cjs/router/liquidity-providers/QuickSwap.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/SpookySwap.js +0 -25
- package/dist/_cjs/router/liquidity-providers/SpookySwap.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/SushiSwapV2.js +0 -20
- package/dist/_cjs/router/liquidity-providers/SushiSwapV2.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/SushiSwapV3.js +0 -106
- package/dist/_cjs/router/liquidity-providers/SushiSwapV3.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/TraderJoe.js +0 -25
- package/dist/_cjs/router/liquidity-providers/TraderJoe.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/UbeSwap.js +0 -25
- package/dist/_cjs/router/liquidity-providers/UbeSwap.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/UniswapV2.js +0 -25
- package/dist/_cjs/router/liquidity-providers/UniswapV2.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/UniswapV2Base.js +0 -112
- package/dist/_cjs/router/liquidity-providers/UniswapV2Base.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/UniswapV3.js +0 -43
- package/dist/_cjs/router/liquidity-providers/UniswapV3.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/UniswapV3Base.js +0 -281
- package/dist/_cjs/router/liquidity-providers/UniswapV3Base.js.map +0 -1
- package/dist/_cjs/router/liquidity-providers/index.js +0 -27
- package/dist/_cjs/router/liquidity-providers/index.js.map +0 -1
- package/dist/_cjs/router/pool-codes/BentoBridge.js +0 -82
- package/dist/_cjs/router/pool-codes/BentoBridge.js.map +0 -1
- package/dist/_cjs/router/pool-codes/BentoPool.js +0 -47
- package/dist/_cjs/router/pool-codes/BentoPool.js.map +0 -1
- package/dist/_cjs/router/pool-codes/Bridge.js +0 -7
- package/dist/_cjs/router/pool-codes/Bridge.js.map +0 -1
- package/dist/_cjs/router/pool-codes/ConstantProductPool.js +0 -42
- package/dist/_cjs/router/pool-codes/ConstantProductPool.js.map +0 -1
- package/dist/_cjs/router/pool-codes/CurvePool.js +0 -43
- package/dist/_cjs/router/pool-codes/CurvePool.js.map +0 -1
- package/dist/_cjs/router/pool-codes/NativeWrapBridge.js +0 -50
- package/dist/_cjs/router/pool-codes/NativeWrapBridge.js.map +0 -1
- package/dist/_cjs/router/pool-codes/PoolCode.js +0 -35
- package/dist/_cjs/router/pool-codes/PoolCode.js.map +0 -1
- package/dist/_cjs/router/pool-codes/TridentCLPool.js +0 -27
- package/dist/_cjs/router/pool-codes/TridentCLPool.js.map +0 -1
- package/dist/_cjs/router/pool-codes/UniV3Pool.js +0 -27
- package/dist/_cjs/router/pool-codes/UniV3Pool.js.map +0 -1
- package/dist/_cjs/router/pool-codes/UniV4Pool.js +0 -40
- package/dist/_cjs/router/pool-codes/UniV4Pool.js.map +0 -1
- package/dist/_cjs/router/pool-codes/index.js +0 -22
- package/dist/_cjs/router/pool-codes/index.js.map +0 -1
- package/dist/_cjs/router/router.js +0 -352
- package/dist/_cjs/router/router.js.map +0 -1
- package/dist/_cjs/router/routingBases.js +0 -55
- package/dist/_cjs/router/routingBases.js.map +0 -1
- package/dist/_cjs/router/tines-to-route-processor-2.js +0 -187
- package/dist/_cjs/router/tines-to-route-processor-2.js.map +0 -1
- package/dist/_cjs/router/tines-to-route-processor-4.js +0 -69
- package/dist/_cjs/router/tines-to-route-processor-4.js.map +0 -1
- package/dist/_cjs/router/tines-to-route-processor-6.js +0 -17
- package/dist/_cjs/router/tines-to-route-processor-6.js.map +0 -1
- package/dist/_cjs/router/tines-to-route-processor.js +0 -192
- package/dist/_cjs/router/tines-to-route-processor.js.map +0 -1
- package/dist/_cjs/serializer/AddressValidation.js.map +0 -1
- package/dist/_cjs/serializer/BinarySerialization.js +0 -256
- package/dist/_cjs/serializer/BinarySerialization.js.map +0 -1
- package/dist/_cjs/serializer/index.js +0 -18
- package/dist/_cjs/serializer/index.js.map +0 -1
- package/dist/_cjs/tines/BridgeBento.js +0 -116
- package/dist/_cjs/tines/BridgeBento.js.map +0 -1
- package/dist/_cjs/tines/BridgeBidirectionalUnlimited.js +0 -26
- package/dist/_cjs/tines/BridgeBidirectionalUnlimited.js.map +0 -1
- package/dist/_cjs/tines/BridgeStargateV04OneWay.js +0 -44
- package/dist/_cjs/tines/BridgeStargateV04OneWay.js.map +0 -1
- package/dist/_cjs/tines/CLPool.js +0 -248
- package/dist/_cjs/tines/CLPool.js.map +0 -1
- package/dist/_cjs/tines/CurveMultitokenPool.js +0 -238
- package/dist/_cjs/tines/CurveMultitokenPool.js.map +0 -1
- package/dist/_cjs/tines/CurveMultitokenPoolSingle.js +0 -195
- package/dist/_cjs/tines/CurveMultitokenPoolSingle.js.map +0 -1
- package/dist/_cjs/tines/CurvePool.js +0 -121
- package/dist/_cjs/tines/CurvePool.js.map +0 -1
- package/dist/_cjs/tines/Graph.js +0 -1187
- package/dist/_cjs/tines/Graph.js.map +0 -1
- package/dist/_cjs/tines/MultiRouter.js +0 -192
- package/dist/_cjs/tines/MultiRouter.js.map +0 -1
- package/dist/_cjs/tines/PrimaryPools.js +0 -147
- package/dist/_cjs/tines/PrimaryPools.js.map +0 -1
- package/dist/_cjs/tines/RPool.js +0 -77
- package/dist/_cjs/tines/RPool.js.map +0 -1
- package/dist/_cjs/tines/StableSwapPool.js +0 -222
- package/dist/_cjs/tines/StableSwapPool.js.map +0 -1
- package/dist/_cjs/tines/StarGateFeesV04.js +0 -113
- package/dist/_cjs/tines/StarGateFeesV04.js.map +0 -1
- package/dist/_cjs/tines/UniV3Pool.js +0 -291
- package/dist/_cjs/tines/UniV3Pool.js.map +0 -1
- package/dist/_cjs/tines/UniV4Pool.js +0 -28
- package/dist/_cjs/tines/UniV4Pool.js.map +0 -1
- package/dist/_cjs/tines/Utils.js +0 -113
- package/dist/_cjs/tines/Utils.js.map +0 -1
- package/dist/_cjs/tines/constants/hybrid.js +0 -5
- package/dist/_cjs/tines/constants/hybrid.js.map +0 -1
- package/dist/_cjs/tines/constants/index.js +0 -18
- package/dist/_cjs/tines/constants/index.js.map +0 -1
- package/dist/_cjs/tines/functions/computeHybridLiquidity.js +0 -25
- package/dist/_cjs/tines/functions/computeHybridLiquidity.js.map +0 -1
- package/dist/_cjs/tines/functions/convertTokenToBento.js +0 -13
- package/dist/_cjs/tines/functions/convertTokenToBento.js.map +0 -1
- package/dist/_cjs/tines/functions/getBentoChainId.js +0 -7
- package/dist/_cjs/tines/functions/getBentoChainId.js.map +0 -1
- package/dist/_cjs/tines/functions/index.js +0 -10
- package/dist/_cjs/tines/functions/index.js.map +0 -1
- package/dist/_cjs/tines/index.js +0 -34
- package/dist/_cjs/tines/index.js.map +0 -1
- package/dist/_esm/pricing/IncrementalPricer.js +0 -430
- package/dist/_esm/pricing/IncrementalPricer.js.map +0 -1
- package/dist/_esm/pricing/PoolTokenGraph.js +0 -56
- package/dist/_esm/pricing/PoolTokenGraph.js.map +0 -1
- package/dist/_esm/pricing/index.js +0 -2
- package/dist/_esm/pricing/index.js.map +0 -1
- package/dist/_esm/router/HEXer.js +0 -110
- package/dist/_esm/router/HEXer.js.map +0 -1
- package/dist/_esm/router/PoolBinarySerialization.js +0 -471
- package/dist/_esm/router/PoolBinarySerialization.js.map +0 -1
- package/dist/_esm/router/Sankey.AnyChart.js +0 -25
- package/dist/_esm/router/Sankey.AnyChart.js.map +0 -1
- package/dist/_esm/router/curve-sdk.js +0 -215
- package/dist/_esm/router/curve-sdk.js.map +0 -1
- package/dist/_esm/router/data-fetcher.js +0 -188
- package/dist/_esm/router/data-fetcher.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/ApeSwap.js +0 -27
- package/dist/_esm/router/liquidity-providers/ApeSwap.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/Biswap.js +0 -22
- package/dist/_esm/router/liquidity-providers/Biswap.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/CurvePoolsWhitelist.js +0 -3980
- package/dist/_esm/router/liquidity-providers/CurvePoolsWhitelist.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/CurveProvider.js +0 -473
- package/dist/_esm/router/liquidity-providers/CurveProvider.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/CurveProviderWhitelist.js +0 -200
- package/dist/_esm/router/liquidity-providers/CurveProviderWhitelist.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/Dfyn.js +0 -27
- package/dist/_esm/router/liquidity-providers/Dfyn.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/DovishV3.js +0 -24
- package/dist/_esm/router/liquidity-providers/DovishV3.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/Elk.js +0 -51
- package/dist/_esm/router/liquidity-providers/Elk.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/HoneySwap.js +0 -21
- package/dist/_esm/router/liquidity-providers/HoneySwap.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/JetSwap.js +0 -25
- package/dist/_esm/router/liquidity-providers/JetSwap.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/LaserSwap.js +0 -22
- package/dist/_esm/router/liquidity-providers/LaserSwap.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/LiquidityProvider.js +0 -106
- package/dist/_esm/router/liquidity-providers/LiquidityProvider.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/NativeWrapProvider.js +0 -42
- package/dist/_esm/router/liquidity-providers/NativeWrapProvider.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/NetSwap.js +0 -21
- package/dist/_esm/router/liquidity-providers/NetSwap.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/PancakeSwap.js +0 -24
- package/dist/_esm/router/liquidity-providers/PancakeSwap.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/QuickSwap.js +0 -21
- package/dist/_esm/router/liquidity-providers/QuickSwap.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/SpookySwap.js +0 -21
- package/dist/_esm/router/liquidity-providers/SpookySwap.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/SushiSwapV2.js +0 -17
- package/dist/_esm/router/liquidity-providers/SushiSwapV2.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/SushiSwapV3.js +0 -102
- package/dist/_esm/router/liquidity-providers/SushiSwapV3.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/TraderJoe.js +0 -21
- package/dist/_esm/router/liquidity-providers/TraderJoe.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/UbeSwap.js +0 -21
- package/dist/_esm/router/liquidity-providers/UbeSwap.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/UniswapV2.js +0 -21
- package/dist/_esm/router/liquidity-providers/UniswapV2.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/UniswapV2Base.js +0 -112
- package/dist/_esm/router/liquidity-providers/UniswapV2Base.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/UniswapV3.js +0 -39
- package/dist/_esm/router/liquidity-providers/UniswapV3.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/UniswapV3Base.js +0 -286
- package/dist/_esm/router/liquidity-providers/UniswapV3Base.js.map +0 -1
- package/dist/_esm/router/liquidity-providers/index.js +0 -9
- package/dist/_esm/router/liquidity-providers/index.js.map +0 -1
- package/dist/_esm/router/pool-codes/BentoBridge.js +0 -86
- package/dist/_esm/router/pool-codes/BentoBridge.js.map +0 -1
- package/dist/_esm/router/pool-codes/BentoPool.js +0 -48
- package/dist/_esm/router/pool-codes/BentoPool.js.map +0 -1
- package/dist/_esm/router/pool-codes/Bridge.js +0 -4
- package/dist/_esm/router/pool-codes/Bridge.js.map +0 -1
- package/dist/_esm/router/pool-codes/ConstantProductPool.js +0 -41
- package/dist/_esm/router/pool-codes/ConstantProductPool.js.map +0 -1
- package/dist/_esm/router/pool-codes/CurvePool.js +0 -41
- package/dist/_esm/router/pool-codes/CurvePool.js.map +0 -1
- package/dist/_esm/router/pool-codes/NativeWrapBridge.js +0 -52
- package/dist/_esm/router/pool-codes/NativeWrapBridge.js.map +0 -1
- package/dist/_esm/router/pool-codes/PoolCode.js +0 -36
- package/dist/_esm/router/pool-codes/PoolCode.js.map +0 -1
- package/dist/_esm/router/pool-codes/TridentCLPool.js +0 -25
- package/dist/_esm/router/pool-codes/TridentCLPool.js.map +0 -1
- package/dist/_esm/router/pool-codes/UniV3Pool.js +0 -25
- package/dist/_esm/router/pool-codes/UniV3Pool.js.map +0 -1
- package/dist/_esm/router/pool-codes/UniV4Pool.js +0 -37
- package/dist/_esm/router/pool-codes/UniV4Pool.js.map +0 -1
- package/dist/_esm/router/pool-codes/index.js +0 -10
- package/dist/_esm/router/pool-codes/index.js.map +0 -1
- package/dist/_esm/router/router.js +0 -351
- package/dist/_esm/router/router.js.map +0 -1
- package/dist/_esm/router/routingBases.js +0 -50
- package/dist/_esm/router/routingBases.js.map +0 -1
- package/dist/_esm/router/tines-to-route-processor-2.js +0 -189
- package/dist/_esm/router/tines-to-route-processor-2.js.map +0 -1
- package/dist/_esm/router/tines-to-route-processor-4.js +0 -75
- package/dist/_esm/router/tines-to-route-processor-4.js.map +0 -1
- package/dist/_esm/router/tines-to-route-processor-6.js +0 -14
- package/dist/_esm/router/tines-to-route-processor-6.js.map +0 -1
- package/dist/_esm/router/tines-to-route-processor.js +0 -200
- package/dist/_esm/router/tines-to-route-processor.js.map +0 -1
- package/dist/_esm/serializer/AddressValidation.js.map +0 -1
- package/dist/_esm/serializer/BinarySerialization.js +0 -270
- package/dist/_esm/serializer/BinarySerialization.js.map +0 -1
- package/dist/_esm/serializer/index.js +0 -2
- package/dist/_esm/serializer/index.js.map +0 -1
- package/dist/_esm/tines/BridgeBento.js +0 -116
- package/dist/_esm/tines/BridgeBento.js.map +0 -1
- package/dist/_esm/tines/BridgeBidirectionalUnlimited.js +0 -22
- package/dist/_esm/tines/BridgeBidirectionalUnlimited.js.map +0 -1
- package/dist/_esm/tines/BridgeStargateV04OneWay.js +0 -43
- package/dist/_esm/tines/BridgeStargateV04OneWay.js.map +0 -1
- package/dist/_esm/tines/CLPool.js +0 -265
- package/dist/_esm/tines/CLPool.js.map +0 -1
- package/dist/_esm/tines/CurveMultitokenPool.js +0 -268
- package/dist/_esm/tines/CurveMultitokenPool.js.map +0 -1
- package/dist/_esm/tines/CurveMultitokenPoolSingle.js +0 -194
- package/dist/_esm/tines/CurveMultitokenPoolSingle.js.map +0 -1
- package/dist/_esm/tines/CurvePool.js +0 -120
- package/dist/_esm/tines/CurvePool.js.map +0 -1
- package/dist/_esm/tines/Graph.js +0 -1324
- package/dist/_esm/tines/Graph.js.map +0 -1
- package/dist/_esm/tines/MultiRouter.js +0 -191
- package/dist/_esm/tines/MultiRouter.js.map +0 -1
- package/dist/_esm/tines/PrimaryPools.js +0 -166
- package/dist/_esm/tines/PrimaryPools.js.map +0 -1
- package/dist/_esm/tines/RPool.js +0 -80
- package/dist/_esm/tines/RPool.js.map +0 -1
- package/dist/_esm/tines/StableSwapPool.js +0 -221
- package/dist/_esm/tines/StableSwapPool.js.map +0 -1
- package/dist/_esm/tines/StarGateFeesV04.js +0 -135
- package/dist/_esm/tines/StarGateFeesV04.js.map +0 -1
- package/dist/_esm/tines/UniV3Pool.js +0 -325
- package/dist/_esm/tines/UniV3Pool.js.map +0 -1
- package/dist/_esm/tines/UniV4Pool.js +0 -40
- package/dist/_esm/tines/UniV4Pool.js.map +0 -1
- package/dist/_esm/tines/Utils.js +0 -108
- package/dist/_esm/tines/Utils.js.map +0 -1
- package/dist/_esm/tines/constants/hybrid.js +0 -2
- package/dist/_esm/tines/constants/hybrid.js.map +0 -1
- package/dist/_esm/tines/constants/index.js +0 -2
- package/dist/_esm/tines/constants/index.js.map +0 -1
- package/dist/_esm/tines/functions/computeHybridLiquidity.js +0 -22
- package/dist/_esm/tines/functions/computeHybridLiquidity.js.map +0 -1
- package/dist/_esm/tines/functions/convertTokenToBento.js +0 -11
- package/dist/_esm/tines/functions/convertTokenToBento.js.map +0 -1
- package/dist/_esm/tines/functions/getBentoChainId.js +0 -4
- package/dist/_esm/tines/functions/getBentoChainId.js.map +0 -1
- package/dist/_esm/tines/functions/index.js +0 -4
- package/dist/_esm/tines/functions/index.js.map +0 -1
- package/dist/_esm/tines/index.js +0 -18
- package/dist/_esm/tines/index.js.map +0 -1
- package/dist/_types/pricing/IncrementalPricer.d.ts +0 -48
- package/dist/_types/pricing/IncrementalPricer.d.ts.map +0 -1
- package/dist/_types/pricing/PoolTokenGraph.d.ts +0 -22
- package/dist/_types/pricing/PoolTokenGraph.d.ts.map +0 -1
- package/dist/_types/pricing/index.d.ts +0 -2
- package/dist/_types/pricing/index.d.ts.map +0 -1
- package/dist/_types/router/HEXer.d.ts +0 -20
- package/dist/_types/router/HEXer.d.ts.map +0 -1
- package/dist/_types/router/PoolBinarySerialization.d.ts +0 -11
- package/dist/_types/router/PoolBinarySerialization.d.ts.map +0 -1
- package/dist/_types/router/Sankey.AnyChart.d.ts +0 -7
- package/dist/_types/router/Sankey.AnyChart.d.ts.map +0 -1
- package/dist/_types/router/curve-sdk.d.ts +0 -214
- package/dist/_types/router/curve-sdk.d.ts.map +0 -1
- package/dist/_types/router/data-fetcher.d.ts +0 -24
- package/dist/_types/router/data-fetcher.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/ApeSwap.d.ts +0 -10
- package/dist/_types/router/liquidity-providers/ApeSwap.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/Biswap.d.ts +0 -11
- package/dist/_types/router/liquidity-providers/Biswap.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/CurvePoolsWhitelist.d.ts +0 -12
- package/dist/_types/router/liquidity-providers/CurvePoolsWhitelist.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/CurveProvider.d.ts +0 -41
- package/dist/_types/router/liquidity-providers/CurveProvider.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/CurveProviderWhitelist.d.ts +0 -40
- package/dist/_types/router/liquidity-providers/CurveProviderWhitelist.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/Dfyn.d.ts +0 -10
- package/dist/_types/router/liquidity-providers/Dfyn.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/DovishV3.d.ts +0 -10
- package/dist/_types/router/liquidity-providers/DovishV3.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/Elk.d.ts +0 -10
- package/dist/_types/router/liquidity-providers/Elk.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/HoneySwap.d.ts +0 -10
- package/dist/_types/router/liquidity-providers/HoneySwap.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/JetSwap.d.ts +0 -10
- package/dist/_types/router/liquidity-providers/JetSwap.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/LaserSwap.d.ts +0 -11
- package/dist/_types/router/liquidity-providers/LaserSwap.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/LiquidityProvider.d.ts +0 -123
- package/dist/_types/router/liquidity-providers/LiquidityProvider.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/NativeWrapProvider.d.ts +0 -15
- package/dist/_types/router/liquidity-providers/NativeWrapProvider.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/NetSwap.d.ts +0 -10
- package/dist/_types/router/liquidity-providers/NetSwap.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/PancakeSwap.d.ts +0 -11
- package/dist/_types/router/liquidity-providers/PancakeSwap.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/QuickSwap.d.ts +0 -10
- package/dist/_types/router/liquidity-providers/QuickSwap.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/SpookySwap.d.ts +0 -10
- package/dist/_types/router/liquidity-providers/SpookySwap.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/SushiSwapV2.d.ts +0 -10
- package/dist/_types/router/liquidity-providers/SushiSwapV2.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/SushiSwapV3.d.ts +0 -10
- package/dist/_types/router/liquidity-providers/SushiSwapV3.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/TraderJoe.d.ts +0 -10
- package/dist/_types/router/liquidity-providers/TraderJoe.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/UbeSwap.d.ts +0 -10
- package/dist/_types/router/liquidity-providers/UbeSwap.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/UniswapV2.d.ts +0 -10
- package/dist/_types/router/liquidity-providers/UniswapV2.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/UniswapV2Base.d.ts +0 -29
- package/dist/_types/router/liquidity-providers/UniswapV2Base.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/UniswapV3.d.ts +0 -10
- package/dist/_types/router/liquidity-providers/UniswapV3.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/UniswapV3Base.d.ts +0 -32
- package/dist/_types/router/liquidity-providers/UniswapV3Base.d.ts.map +0 -1
- package/dist/_types/router/liquidity-providers/index.d.ts +0 -9
- package/dist/_types/router/liquidity-providers/index.d.ts.map +0 -1
- package/dist/_types/router/pool-codes/BentoBridge.d.ts +0 -11
- package/dist/_types/router/pool-codes/BentoBridge.d.ts.map +0 -1
- package/dist/_types/router/pool-codes/BentoPool.d.ts +0 -9
- package/dist/_types/router/pool-codes/BentoPool.d.ts.map +0 -1
- package/dist/_types/router/pool-codes/Bridge.d.ts +0 -5
- package/dist/_types/router/pool-codes/Bridge.d.ts.map +0 -1
- package/dist/_types/router/pool-codes/ConstantProductPool.d.ts +0 -10
- package/dist/_types/router/pool-codes/ConstantProductPool.d.ts.map +0 -1
- package/dist/_types/router/pool-codes/CurvePool.d.ts +0 -13
- package/dist/_types/router/pool-codes/CurvePool.d.ts.map +0 -1
- package/dist/_types/router/pool-codes/NativeWrapBridge.d.ts +0 -10
- package/dist/_types/router/pool-codes/NativeWrapBridge.d.ts.map +0 -1
- package/dist/_types/router/pool-codes/PoolCode.d.ts +0 -24
- package/dist/_types/router/pool-codes/PoolCode.d.ts.map +0 -1
- package/dist/_types/router/pool-codes/TridentCLPool.d.ts +0 -10
- package/dist/_types/router/pool-codes/TridentCLPool.d.ts.map +0 -1
- package/dist/_types/router/pool-codes/UniV3Pool.d.ts +0 -10
- package/dist/_types/router/pool-codes/UniV3Pool.d.ts.map +0 -1
- package/dist/_types/router/pool-codes/UniV4Pool.d.ts +0 -13
- package/dist/_types/router/pool-codes/UniV4Pool.d.ts.map +0 -1
- package/dist/_types/router/pool-codes/index.d.ts +0 -10
- package/dist/_types/router/pool-codes/index.d.ts.map +0 -1
- package/dist/_types/router/router.d.ts +0 -68
- package/dist/_types/router/router.d.ts.map +0 -1
- package/dist/_types/router/routingBases.d.ts +0 -8
- package/dist/_types/router/routingBases.d.ts.map +0 -1
- package/dist/_types/router/tines-to-route-processor-2.d.ts +0 -41
- package/dist/_types/router/tines-to-route-processor-2.d.ts.map +0 -1
- package/dist/_types/router/tines-to-route-processor-4.d.ts +0 -12
- package/dist/_types/router/tines-to-route-processor-4.d.ts.map +0 -1
- package/dist/_types/router/tines-to-route-processor-6.d.ts +0 -5
- package/dist/_types/router/tines-to-route-processor-6.d.ts.map +0 -1
- package/dist/_types/router/tines-to-route-processor.d.ts +0 -21
- package/dist/_types/router/tines-to-route-processor.d.ts.map +0 -1
- package/dist/_types/serializer/AddressValidation.d.ts.map +0 -1
- package/dist/_types/serializer/BinarySerialization.d.ts +0 -43
- package/dist/_types/serializer/BinarySerialization.d.ts.map +0 -1
- package/dist/_types/serializer/index.d.ts +0 -2
- package/dist/_types/serializer/index.d.ts.map +0 -1
- package/dist/_types/tines/BridgeBento.d.ts +0 -21
- package/dist/_types/tines/BridgeBento.d.ts.map +0 -1
- package/dist/_types/tines/BridgeBidirectionalUnlimited.d.ts +0 -16
- package/dist/_types/tines/BridgeBidirectionalUnlimited.d.ts.map +0 -1
- package/dist/_types/tines/BridgeStargateV04OneWay.d.ts +0 -23
- package/dist/_types/tines/BridgeStargateV04OneWay.d.ts.map +0 -1
- package/dist/_types/tines/CLPool.d.ts +0 -27
- package/dist/_types/tines/CLPool.d.ts.map +0 -1
- package/dist/_types/tines/CurveMultitokenPool.d.ts +0 -58
- package/dist/_types/tines/CurveMultitokenPool.d.ts.map +0 -1
- package/dist/_types/tines/CurveMultitokenPoolSingle.d.ts +0 -54
- package/dist/_types/tines/CurveMultitokenPoolSingle.d.ts.map +0 -1
- package/dist/_types/tines/CurvePool.d.ts +0 -28
- package/dist/_types/tines/CurvePool.d.ts.map +0 -1
- package/dist/_types/tines/Graph.d.ts +0 -135
- package/dist/_types/tines/Graph.d.ts.map +0 -1
- package/dist/_types/tines/MultiRouter.d.ts +0 -11
- package/dist/_types/tines/MultiRouter.d.ts.map +0 -1
- package/dist/_types/tines/PrimaryPools.d.ts +0 -44
- package/dist/_types/tines/PrimaryPools.d.ts.map +0 -1
- package/dist/_types/tines/RPool.d.ts +0 -54
- package/dist/_types/tines/RPool.d.ts.map +0 -1
- package/dist/_types/tines/StableSwapPool.d.ts +0 -50
- package/dist/_types/tines/StableSwapPool.d.ts.map +0 -1
- package/dist/_types/tines/StarGateFeesV04.d.ts +0 -16
- package/dist/_types/tines/StarGateFeesV04.d.ts.map +0 -1
- package/dist/_types/tines/UniV3Pool.d.ts +0 -25
- package/dist/_types/tines/UniV3Pool.d.ts.map +0 -1
- package/dist/_types/tines/UniV4Pool.d.ts +0 -13
- package/dist/_types/tines/UniV4Pool.d.ts.map +0 -1
- package/dist/_types/tines/Utils.d.ts +0 -9
- package/dist/_types/tines/Utils.d.ts.map +0 -1
- package/dist/_types/tines/constants/hybrid.d.ts +0 -2
- package/dist/_types/tines/constants/hybrid.d.ts.map +0 -1
- package/dist/_types/tines/constants/index.d.ts +0 -2
- package/dist/_types/tines/constants/index.d.ts.map +0 -1
- package/dist/_types/tines/functions/computeHybridLiquidity.d.ts +0 -2
- package/dist/_types/tines/functions/computeHybridLiquidity.d.ts.map +0 -1
- package/dist/_types/tines/functions/convertTokenToBento.d.ts +0 -4
- package/dist/_types/tines/functions/convertTokenToBento.d.ts.map +0 -1
- package/dist/_types/tines/functions/getBentoChainId.d.ts +0 -2
- package/dist/_types/tines/functions/getBentoChainId.d.ts.map +0 -1
- package/dist/_types/tines/functions/index.d.ts +0 -4
- package/dist/_types/tines/functions/index.d.ts.map +0 -1
- package/dist/_types/tines/index.d.ts +0 -18
- package/dist/_types/tines/index.d.ts.map +0 -1
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StableSwapRPool = exports.RebaseInternal = void 0;
|
|
4
|
-
exports.toAmountBI = toAmountBI;
|
|
5
|
-
exports.toShareBI = toShareBI;
|
|
6
|
-
exports.realReservesToAdjusted = realReservesToAdjusted;
|
|
7
|
-
exports.adjustedReservesToReal = adjustedReservesToReal;
|
|
8
|
-
const index_js_1 = require("../math/index.js");
|
|
9
|
-
const RPool_js_1 = require("./RPool.js");
|
|
10
|
-
const Utils_js_1 = require("./Utils.js");
|
|
11
|
-
function toAmountBI(share, total) {
|
|
12
|
-
if (total.base === 0n || total.elastic === 0n)
|
|
13
|
-
return share;
|
|
14
|
-
return (share * total.elastic) / total.base;
|
|
15
|
-
}
|
|
16
|
-
function toShareBI(elastic, total) {
|
|
17
|
-
if (total.base === 0n || total.elastic === 0n)
|
|
18
|
-
return elastic;
|
|
19
|
-
return (elastic * total.base) / total.elastic;
|
|
20
|
-
}
|
|
21
|
-
class RebaseInternal {
|
|
22
|
-
constructor(rebase) {
|
|
23
|
-
this.rebaseBI = rebase;
|
|
24
|
-
if (rebase !== undefined) {
|
|
25
|
-
if (rebase.base === 0n || rebase.elastic === 0n)
|
|
26
|
-
this.elastic2Base = 1;
|
|
27
|
-
else
|
|
28
|
-
this.elastic2Base =
|
|
29
|
-
parseInt(rebase.elastic.toString()) / parseInt(rebase.base.toString());
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
this.elastic2Base = 1;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
toAmount(share) {
|
|
36
|
-
return share * this.elastic2Base;
|
|
37
|
-
}
|
|
38
|
-
toShare(amount) {
|
|
39
|
-
return amount / this.elastic2Base;
|
|
40
|
-
}
|
|
41
|
-
toAmountBI(share) {
|
|
42
|
-
return toAmountBI(share, this.rebaseBI);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.RebaseInternal = RebaseInternal;
|
|
46
|
-
function realReservesToAdjusted(reserve, total, decimals) {
|
|
47
|
-
const amount = toAmountBI(reserve, total);
|
|
48
|
-
return (amount * (0, Utils_js_1.getBigInt)(1e12)) / (0, Utils_js_1.getBigInt)(10 ** decimals);
|
|
49
|
-
}
|
|
50
|
-
function adjustedReservesToReal(reserve, total, decimals) {
|
|
51
|
-
const amount = (reserve * (0, Utils_js_1.getBigInt)(10 ** decimals)) / (0, Utils_js_1.getBigInt)(1e12);
|
|
52
|
-
return toShareBI(amount, total);
|
|
53
|
-
}
|
|
54
|
-
class StableSwapRPool extends RPool_js_1.RPool {
|
|
55
|
-
constructor(address, token0, token1, fee, reserve0, reserve1, decimals0, decimals1, total0, total1) {
|
|
56
|
-
super(address, token0, token1, fee, reserve0 === undefined
|
|
57
|
-
? undefined
|
|
58
|
-
: realReservesToAdjusted(reserve0, total0, decimals0), reserve1 === undefined
|
|
59
|
-
? undefined
|
|
60
|
-
: realReservesToAdjusted(reserve1, total1, decimals1));
|
|
61
|
-
this.k = 0n;
|
|
62
|
-
this.decimals0 = decimals0;
|
|
63
|
-
this.decimals1 = decimals1;
|
|
64
|
-
if (address) {
|
|
65
|
-
this.decimalsCompensation0 = 10 ** (12 - decimals0);
|
|
66
|
-
this.decimalsCompensation1 = 10 ** (12 - decimals1);
|
|
67
|
-
this.total0 = new RebaseInternal(total0);
|
|
68
|
-
this.total1 = new RebaseInternal(total1);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
this.decimalsCompensation0 = 0;
|
|
72
|
-
this.decimalsCompensation1 = 0;
|
|
73
|
-
this.total0 = undefined;
|
|
74
|
-
this.total1 = undefined;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
getReserve0() {
|
|
78
|
-
return adjustedReservesToReal(this.reserve0, this.total0.rebaseBI, this.decimals0);
|
|
79
|
-
}
|
|
80
|
-
getReserve1() {
|
|
81
|
-
return adjustedReservesToReal(this.reserve1, this.total1.rebaseBI, this.decimals1);
|
|
82
|
-
}
|
|
83
|
-
granularity0() {
|
|
84
|
-
return Math.max(1 / this.decimalsCompensation0, 1);
|
|
85
|
-
}
|
|
86
|
-
granularity1() {
|
|
87
|
-
return Math.max(1 / this.decimalsCompensation1, 1);
|
|
88
|
-
}
|
|
89
|
-
updateReserves(res0, res1) {
|
|
90
|
-
this.k = 0n;
|
|
91
|
-
this.reserve0 = realReservesToAdjusted(res0, this.total0.rebaseBI, this.decimals0);
|
|
92
|
-
this.reserve1 = realReservesToAdjusted(res1, this.total1.rebaseBI, this.decimals1);
|
|
93
|
-
}
|
|
94
|
-
poolType() {
|
|
95
|
-
return RPool_js_1.PoolType.Stable;
|
|
96
|
-
}
|
|
97
|
-
updateReservesAmounts(res0, res1) {
|
|
98
|
-
this.k = 0n;
|
|
99
|
-
this.reserve0 = (res0 * (0, Utils_js_1.getBigInt)(1e12)) / (0, Utils_js_1.getBigInt)(10 ** this.decimals0);
|
|
100
|
-
this.reserve1 = (res1 * (0, Utils_js_1.getBigInt)(1e12)) / (0, Utils_js_1.getBigInt)(10 ** this.decimals1);
|
|
101
|
-
}
|
|
102
|
-
getTotal0() {
|
|
103
|
-
return this.total0.rebaseBI;
|
|
104
|
-
}
|
|
105
|
-
getTotal1() {
|
|
106
|
-
return this.total1.rebaseBI;
|
|
107
|
-
}
|
|
108
|
-
updateTotals(total0, total1) {
|
|
109
|
-
this.total0 = new RebaseInternal(total0);
|
|
110
|
-
this.total1 = new RebaseInternal(total1);
|
|
111
|
-
}
|
|
112
|
-
updateTotal0(total0) {
|
|
113
|
-
this.total0 = new RebaseInternal(total0);
|
|
114
|
-
}
|
|
115
|
-
updateTotal1(total1) {
|
|
116
|
-
this.total1 = new RebaseInternal(total1);
|
|
117
|
-
}
|
|
118
|
-
computeK() {
|
|
119
|
-
if (this.k === 0n) {
|
|
120
|
-
const x = this.reserve0;
|
|
121
|
-
const y = this.reserve1;
|
|
122
|
-
this.k = x * y * (x * x + y * y);
|
|
123
|
-
}
|
|
124
|
-
return this.k;
|
|
125
|
-
}
|
|
126
|
-
computeY(x, yHint) {
|
|
127
|
-
const k = this.computeK();
|
|
128
|
-
const x2 = x << 1n;
|
|
129
|
-
const x3 = x * 3n;
|
|
130
|
-
const xCube = x * x * x;
|
|
131
|
-
let yPrev = yHint;
|
|
132
|
-
let y = yHint;
|
|
133
|
-
for (let i = 0; i < 255; ++i) {
|
|
134
|
-
const ySquare = y * y;
|
|
135
|
-
const yCube = ySquare * y;
|
|
136
|
-
y = (yCube * x2 + k) / (ySquare * x3 + xCube);
|
|
137
|
-
if ((0, index_js_1.abs)(y - yPrev) <= 1)
|
|
138
|
-
break;
|
|
139
|
-
yPrev = y;
|
|
140
|
-
}
|
|
141
|
-
return y;
|
|
142
|
-
}
|
|
143
|
-
calcOutByIn(amountIn, direction, throwIfOutOfLiquidity = true) {
|
|
144
|
-
amountIn = direction
|
|
145
|
-
? this.total0.toAmount(amountIn)
|
|
146
|
-
: this.total1.toAmount(amountIn);
|
|
147
|
-
amountIn *= direction
|
|
148
|
-
? this.decimalsCompensation0
|
|
149
|
-
: this.decimalsCompensation1;
|
|
150
|
-
const x = direction ? this.reserve0 : this.reserve1;
|
|
151
|
-
const y = direction ? this.reserve1 : this.reserve0;
|
|
152
|
-
const xNew = x + (0, Utils_js_1.getBigInt)(Math.floor(amountIn * (1 - this.fee)));
|
|
153
|
-
const yNew = this.computeY(xNew, y);
|
|
154
|
-
const outA = parseInt((y - yNew).toString()) - 1;
|
|
155
|
-
const outB = Math.max(outA, 0);
|
|
156
|
-
const outC = direction
|
|
157
|
-
? this.total1.toShare(outB)
|
|
158
|
-
: this.total0.toShare(outB);
|
|
159
|
-
const out = outC /
|
|
160
|
-
(direction ? this.decimalsCompensation1 : this.decimalsCompensation0);
|
|
161
|
-
const initialReserve = direction ? this.getReserve1() : this.getReserve0();
|
|
162
|
-
if (throwIfOutOfLiquidity &&
|
|
163
|
-
initialReserve - (0, Utils_js_1.getBigInt)(out) < this.minLiquidity)
|
|
164
|
-
throw new Error('StableSwap OutOfLiquidity');
|
|
165
|
-
return { out, gasSpent: this.swapGasCost };
|
|
166
|
-
}
|
|
167
|
-
calcOutByInReal(amountIn, direction) {
|
|
168
|
-
return Math.floor(this.calcOutByIn(amountIn, direction, false).out);
|
|
169
|
-
}
|
|
170
|
-
calcInByOut(amountOut, direction) {
|
|
171
|
-
amountOut = direction
|
|
172
|
-
? this.total1.toAmount(amountOut)
|
|
173
|
-
: this.total0.toAmount(amountOut);
|
|
174
|
-
amountOut *= direction
|
|
175
|
-
? this.decimalsCompensation1
|
|
176
|
-
: this.decimalsCompensation0;
|
|
177
|
-
const x = direction ? this.reserve0 : this.reserve1;
|
|
178
|
-
const y = direction ? this.reserve1 : this.reserve0;
|
|
179
|
-
const yNew = y - (0, Utils_js_1.getBigInt)(Math.ceil(amountOut));
|
|
180
|
-
if (yNew < this.minLiquidity) {
|
|
181
|
-
return { inp: Number.POSITIVE_INFINITY, gasSpent: this.swapGasCost };
|
|
182
|
-
}
|
|
183
|
-
const xNew = this.computeY(yNew, x);
|
|
184
|
-
const inp0 = parseInt((xNew - x).toString()) / (1 - this.fee);
|
|
185
|
-
const inp1 = direction
|
|
186
|
-
? this.total0.toShare(inp0)
|
|
187
|
-
: this.total1.toShare(inp0);
|
|
188
|
-
const inp2 = inp1 /
|
|
189
|
-
(direction ? this.decimalsCompensation0 : this.decimalsCompensation1);
|
|
190
|
-
const inp = Math.max(inp2, 1);
|
|
191
|
-
return { inp, gasSpent: this.swapGasCost };
|
|
192
|
-
}
|
|
193
|
-
calcCurrentPriceWithoutFee(direction) {
|
|
194
|
-
const calcDirection = this.reserve0 > this.reserve1;
|
|
195
|
-
const xBI = calcDirection ? this.reserve0 : this.reserve1;
|
|
196
|
-
const x = parseInt(xBI.toString());
|
|
197
|
-
const k = parseInt(this.computeK().toString());
|
|
198
|
-
const q = k / x / 2;
|
|
199
|
-
const qD = -q / x;
|
|
200
|
-
const Q = x ** 6 / 27 + q * q;
|
|
201
|
-
const QD = (6 * x ** 5) / 27 + 2 * q * qD;
|
|
202
|
-
const sqrtQ = Math.sqrt(Q);
|
|
203
|
-
const sqrtQD = (1 / 2 / sqrtQ) * QD;
|
|
204
|
-
const a = sqrtQ + q;
|
|
205
|
-
const aD = sqrtQD + qD;
|
|
206
|
-
const b = sqrtQ - q;
|
|
207
|
-
const bD = sqrtQD - qD;
|
|
208
|
-
const a3 = a ** (1 / 3);
|
|
209
|
-
const a3D = (((1 / 3) * a3) / a) * aD;
|
|
210
|
-
const b3 = b ** (1 / 3);
|
|
211
|
-
const b3D = (((1 / 3) * b3) / b) * bD;
|
|
212
|
-
const yD = a3D - b3D;
|
|
213
|
-
const yDShares = calcDirection
|
|
214
|
-
? this.total1.toShare(this.total0.toAmount(yD))
|
|
215
|
-
: this.total0.toShare(this.total1.toAmount(yD));
|
|
216
|
-
const price = calcDirection === direction ? -yDShares : -1 / yDShares;
|
|
217
|
-
const scale = this.decimalsCompensation0 / this.decimalsCompensation1;
|
|
218
|
-
return direction ? price * scale : price / scale;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
exports.StableSwapRPool = StableSwapRPool;
|
|
222
|
-
//# sourceMappingURL=StableSwapPool.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StableSwapPool.js","sourceRoot":"","sources":["../../../src/tines/StableSwapPool.ts"],"names":[],"mappings":";;;AAWA,gCAGC;AAED,8BAGC;AAgCD,wDAOC;AAED,wDAOC;AAlED,+CAAsC;AAEtC,yCAAyD;AACzD,yCAAsC;AAOtC,SAAgB,UAAU,CAAC,KAAa,EAAE,KAAa;IACrD,IAAI,KAAK,CAAC,IAAI,KAAK,EAAE,IAAI,KAAK,CAAC,OAAO,KAAK,EAAE;QAAE,OAAO,KAAK,CAAA;IAC3D,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,IAAI,CAAA;AAC7C,CAAC;AAED,SAAgB,SAAS,CAAC,OAAe,EAAE,KAAa;IACtD,IAAI,KAAK,CAAC,IAAI,KAAK,EAAE,IAAI,KAAK,CAAC,OAAO,KAAK,EAAE;QAAE,OAAO,OAAO,CAAA;IAC7D,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,OAAO,CAAA;AAC/C,CAAC;AAED,MAAa,cAAc;IAIzB,YAAY,MAAc;QACxB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAA;QACtB,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,IAAI,MAAM,CAAC,IAAI,KAAK,EAAE,IAAI,MAAM,CAAC,OAAO,KAAK,EAAE;gBAAE,IAAI,CAAC,YAAY,GAAG,CAAC,CAAA;;gB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AC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAA;QACrC,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,CAAA;QACpB,MAAM,QAAQ,GAAG,aAAa;YAC5B,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YAC/C,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;QACjD,MAAM,KAAK,GAAG,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAA;QACrE,MAAM,KAAK,GAAG,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,qBAAqB,CAAA;QACrE,OAAO,SAAS,CAAC,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,KAAK,CAAA;IAClD,CAAC;CACF;AA7OD,0CA6OC"}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getStarGateFeesV04 = getStarGateFeesV04;
|
|
4
|
-
const ZERO = 0n;
|
|
5
|
-
const E14 = 10n ** 14n;
|
|
6
|
-
const E13 = 10n ** 13n;
|
|
7
|
-
const E17 = 10n ** 17n;
|
|
8
|
-
const DENOMINATOR = 10n ** 18n;
|
|
9
|
-
const DELTA_1 = 6000n * E14;
|
|
10
|
-
const DELTA_2 = 500n * E14;
|
|
11
|
-
const LAMBDA_1 = 40n * E14;
|
|
12
|
-
const LAMBDA_2 = 9960n * E14;
|
|
13
|
-
const LP_FEE = 10n * E13;
|
|
14
|
-
const PROTOCOL_FEE = 50n * E13;
|
|
15
|
-
const PROTOCOL_SUBSIDY = 3n * E13;
|
|
16
|
-
const FIFTY_PERCENT = 5n * E17;
|
|
17
|
-
const SIXTY_PERCENT = 6n * E17;
|
|
18
|
-
function getStarGateFeesV04(state, whitelisted, amountSD) {
|
|
19
|
-
const eqReward = getEqReward(state, amountSD);
|
|
20
|
-
const { eqFee, protocolSubsidy } = getEquilibriumFee(state, amountSD);
|
|
21
|
-
const { protocolFee, lpFee } = whitelisted
|
|
22
|
-
? { protocolFee: ZERO, lpFee: ZERO }
|
|
23
|
-
: getProtocolAndLpFee(state, amountSD, protocolSubsidy);
|
|
24
|
-
return {
|
|
25
|
-
eqFee,
|
|
26
|
-
eqReward,
|
|
27
|
-
lpFee,
|
|
28
|
-
protocolFee,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function getEqReward(state, amountSD) {
|
|
32
|
-
if (state.lpAsset <= state.currentAssetSD) {
|
|
33
|
-
return ZERO;
|
|
34
|
-
}
|
|
35
|
-
const poolDeficit = state.lpAsset - state.currentAssetSD;
|
|
36
|
-
if ((state.currentAssetSD * 100n) / state.lpAsset < 75n &&
|
|
37
|
-
amountSD * 100n > poolDeficit * 2n) {
|
|
38
|
-
const eqReward = (state.eqFeePool * amountSD) / poolDeficit;
|
|
39
|
-
if (eqReward > state.eqFeePool) {
|
|
40
|
-
return state.eqFeePool;
|
|
41
|
-
}
|
|
42
|
-
return eqReward;
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
return ZERO;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function getEquilibriumFee(state, amountSD) {
|
|
49
|
-
const beforeBalance = state.currentBalance;
|
|
50
|
-
const idealBalance = state.idealBalance;
|
|
51
|
-
const afterBalance = beforeBalance - amountSD;
|
|
52
|
-
const safeZoneMax = (idealBalance * DELTA_1) / DENOMINATOR;
|
|
53
|
-
const safeZoneMin = (idealBalance * DELTA_2) / DENOMINATOR;
|
|
54
|
-
let eqFee = ZERO;
|
|
55
|
-
let protocolSubsidy = ZERO;
|
|
56
|
-
if (afterBalance >= safeZoneMax) {
|
|
57
|
-
eqFee = (amountSD * PROTOCOL_SUBSIDY) / DENOMINATOR;
|
|
58
|
-
protocolSubsidy = eqFee;
|
|
59
|
-
}
|
|
60
|
-
else if (afterBalance >= safeZoneMin) {
|
|
61
|
-
const proxyBeforeBalance = beforeBalance < safeZoneMax ? beforeBalance : safeZoneMax;
|
|
62
|
-
eqFee = getTrapezoidArea(LAMBDA_1, ZERO, safeZoneMax, safeZoneMin, proxyBeforeBalance, afterBalance);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
if (beforeBalance >= safeZoneMin) {
|
|
66
|
-
const proxyBeforeBalance = beforeBalance < safeZoneMax ? beforeBalance : safeZoneMax;
|
|
67
|
-
eqFee =
|
|
68
|
-
eqFee +
|
|
69
|
-
getTrapezoidArea(LAMBDA_1, ZERO, safeZoneMax, safeZoneMin, proxyBeforeBalance, safeZoneMin);
|
|
70
|
-
eqFee =
|
|
71
|
-
eqFee +
|
|
72
|
-
getTrapezoidArea(LAMBDA_2, LAMBDA_1, safeZoneMin, ZERO, safeZoneMin, afterBalance);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
eqFee =
|
|
76
|
-
eqFee +
|
|
77
|
-
getTrapezoidArea(LAMBDA_2, LAMBDA_1, safeZoneMin, ZERO, beforeBalance, afterBalance);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return { eqFee, protocolSubsidy };
|
|
81
|
-
}
|
|
82
|
-
function getProtocolAndLpFee(state, amountSD, protocolSubsidy) {
|
|
83
|
-
let protocolFee = (amountSD * PROTOCOL_FEE) / DENOMINATOR - protocolSubsidy;
|
|
84
|
-
let lpFee = (amountSD * LP_FEE) / DENOMINATOR;
|
|
85
|
-
if (state.allocPointIsPositive) {
|
|
86
|
-
protocolFee = protocolFee + lpFee;
|
|
87
|
-
lpFee = ZERO;
|
|
88
|
-
}
|
|
89
|
-
if (state.lpAsset === 0n) {
|
|
90
|
-
return { protocolFee, lpFee };
|
|
91
|
-
}
|
|
92
|
-
const isAboveIdeal = state.currentBalance - amountSD >
|
|
93
|
-
(state.idealBalance * SIXTY_PERCENT) / DENOMINATOR;
|
|
94
|
-
const currentAssetNumerated = (state.currentAssetSD * DENOMINATOR) / state.lpAsset;
|
|
95
|
-
if (currentAssetNumerated <= FIFTY_PERCENT && isAboveIdeal) {
|
|
96
|
-
protocolFee = ZERO;
|
|
97
|
-
lpFee = ZERO;
|
|
98
|
-
}
|
|
99
|
-
else if (currentAssetNumerated < SIXTY_PERCENT && isAboveIdeal) {
|
|
100
|
-
const haircut = (currentAssetNumerated - FIFTY_PERCENT) * 10n;
|
|
101
|
-
protocolFee = (protocolFee * haircut) / DENOMINATOR;
|
|
102
|
-
lpFee = (lpFee * haircut) / DENOMINATOR;
|
|
103
|
-
}
|
|
104
|
-
return { protocolFee, lpFee };
|
|
105
|
-
}
|
|
106
|
-
function getTrapezoidArea(lambda, yOffset, xUpperBound, xLowerBound, xStart, xEnd) {
|
|
107
|
-
const xBoundWidth = xUpperBound - xLowerBound;
|
|
108
|
-
const yStart = ((xUpperBound - xStart) * lambda) / xBoundWidth + yOffset;
|
|
109
|
-
const yEnd = ((xUpperBound - xEnd) * lambda) / xBoundWidth + yOffset;
|
|
110
|
-
const deltaX = xStart - xEnd;
|
|
111
|
-
return ((yStart + yEnd) * deltaX) / 2n / DENOMINATOR;
|
|
112
|
-
}
|
|
113
|
-
//# sourceMappingURL=StarGateFeesV04.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StarGateFeesV04.js","sourceRoot":"","sources":["../../../src/tines/StarGateFeesV04.ts"],"names":[],"mappings":";;AA+BA,gDAqBC;AApCD,MAAM,IAAI,GAAG,EAAE,CAAA;AACf,MAAM,GAAG,GAAG,GAAG,IAAI,GAAG,CAAA;AACtB,MAAM,GAAG,GAAG,GAAG,IAAI,GAAG,CAAA;AACtB,MAAM,GAAG,GAAG,GAAG,IAAI,GAAG,CAAA;AACtB,MAAM,W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
|
-
const RPool_js_1 = require("./RPool.js");
|
|
6
|
-
const BASE_GAS_CONSUMPTION = 70_000;
|
|
7
|
-
const STEP_GAS_CONSUMPTION = 40_000;
|
|
8
|
-
const ZERO = 0n;
|
|
9
|
-
const c01 = BigInt('0xfffcb933bd6fad37aa2d162d1a594001');
|
|
10
|
-
const c02 = BigInt('0x100000000000000000000000000000000');
|
|
11
|
-
const c03 = BigInt('0xfff97272373d413259a46990580e213a');
|
|
12
|
-
const c04 = BigInt('0xfff2e50f5f656932ef12357cf3c7fdcc');
|
|
13
|
-
const c05 = BigInt('0xffe5caca7e10e4e61c3624eaa0941cd0');
|
|
14
|
-
const c06 = BigInt('0xffcb9843d60f6159c9db58835c926644');
|
|
15
|
-
const c07 = BigInt('0xff973b41fa98c081472e6896dfb254c0');
|
|
16
|
-
const c08 = BigInt('0xff2ea16466c96a3843ec78b326b52861');
|
|
17
|
-
const c09 = BigInt('0xfe5dee046a99a2a811c461f1969c3053');
|
|
18
|
-
const c10 = BigInt('0xfcbe86c7900a88aedcffc83b479aa3a4');
|
|
19
|
-
const c11 = BigInt('0xf987a7253ac413176f2b074cf7815e54');
|
|
20
|
-
const c12 = BigInt('0xf3392b0822b70005940c7a398e4b70f3');
|
|
21
|
-
const c13 = BigInt('0xe7159475a2c29b7443b29c7fa6e889d9');
|
|
22
|
-
const c14 = BigInt('0xd097f3bdfd2022b8845ad8f792aa5825');
|
|
23
|
-
const c15 = BigInt('0xa9f746462d870fdf8a65dc1f90e061e5');
|
|
24
|
-
const c16 = BigInt('0x70d869a156d2a1b890bb3df62baf32f7');
|
|
25
|
-
const c17 = BigInt('0x31be135f97d08fd981231505542fcfa6');
|
|
26
|
-
const c18 = BigInt('0x9aa508b5b7a84e1c677de54f3e99bc9');
|
|
27
|
-
const c19 = BigInt('0x5d6af8dedb81196699c329225ee604');
|
|
28
|
-
const c20 = BigInt('0x2216e584f5fa1ea926041bedfe98');
|
|
29
|
-
const c21 = BigInt('0x48a170391f7dc42444e8fa2');
|
|
30
|
-
const max256 = 2n ** 256n - 1n;
|
|
31
|
-
function getSqrtRatioAtTick(tick) {
|
|
32
|
-
const absTick = Math.abs(tick);
|
|
33
|
-
let ratio = (absTick & 0x1) !== 0 ? c01 : c02;
|
|
34
|
-
if ((absTick & 0x2) !== 0)
|
|
35
|
-
ratio = (ratio * c03) >> 128n;
|
|
36
|
-
if ((absTick & 0x4) !== 0)
|
|
37
|
-
ratio = (ratio * c04) >> 128n;
|
|
38
|
-
if ((absTick & 0x8) !== 0)
|
|
39
|
-
ratio = (ratio * c05) >> 128n;
|
|
40
|
-
if ((absTick & 0x10) !== 0)
|
|
41
|
-
ratio = (ratio * c06) >> 128n;
|
|
42
|
-
if ((absTick & 0x20) !== 0)
|
|
43
|
-
ratio = (ratio * c07) >> 128n;
|
|
44
|
-
if ((absTick & 0x40) !== 0)
|
|
45
|
-
ratio = (ratio * c08) >> 128n;
|
|
46
|
-
if ((absTick & 0x80) !== 0)
|
|
47
|
-
ratio = (ratio * c09) >> 128n;
|
|
48
|
-
if ((absTick & 0x100) !== 0)
|
|
49
|
-
ratio = (ratio * c10) >> 128n;
|
|
50
|
-
if ((absTick & 0x200) !== 0)
|
|
51
|
-
ratio = (ratio * c11) >> 128n;
|
|
52
|
-
if ((absTick & 0x400) !== 0)
|
|
53
|
-
ratio = (ratio * c12) >> 128n;
|
|
54
|
-
if ((absTick & 0x800) !== 0)
|
|
55
|
-
ratio = (ratio * c13) >> 128n;
|
|
56
|
-
if ((absTick & 0x1000) !== 0)
|
|
57
|
-
ratio = (ratio * c14) >> 128n;
|
|
58
|
-
if ((absTick & 0x2000) !== 0)
|
|
59
|
-
ratio = (ratio * c15) >> 128n;
|
|
60
|
-
if ((absTick & 0x4000) !== 0)
|
|
61
|
-
ratio = (ratio * c16) >> 128n;
|
|
62
|
-
if ((absTick & 0x8000) !== 0)
|
|
63
|
-
ratio = (ratio * c17) >> 128n;
|
|
64
|
-
if ((absTick & 0x10000) !== 0)
|
|
65
|
-
ratio = (ratio * c18) >> 128n;
|
|
66
|
-
if ((absTick & 0x20000) !== 0)
|
|
67
|
-
ratio = (ratio * c19) >> 128n;
|
|
68
|
-
if ((absTick & 0x40000) !== 0)
|
|
69
|
-
ratio = (ratio * c20) >> 128n;
|
|
70
|
-
if ((absTick & 0x80000) !== 0)
|
|
71
|
-
ratio = (ratio * c21) >> 128n;
|
|
72
|
-
if (tick > 0)
|
|
73
|
-
ratio = max256 / ratio;
|
|
74
|
-
return ratio >> 32n;
|
|
75
|
-
}
|
|
76
|
-
const two96 = 2 ** 96;
|
|
77
|
-
class UniV3Pool extends RPool_js_1.RPool {
|
|
78
|
-
constructor(address, token0, token1, fee, reserve0, reserve1, tick, liquidity, sqrtPriceX96, ticks, nearestTick) {
|
|
79
|
-
super(address, token0, token1, fee, reserve0, reserve1, RPool_js_1.TYPICAL_MINIMAL_LIQUIDITY, RPool_js_1.TYPICAL_SWAP_GAS_COST);
|
|
80
|
-
this.ticks = ticks;
|
|
81
|
-
if (address !== undefined) {
|
|
82
|
-
if (this.ticks.length === 0) {
|
|
83
|
-
this.ticks.push({ index: CLPool_js_1.CL_MIN_TICK, DLiquidity: ZERO });
|
|
84
|
-
this.ticks.push({ index: CLPool_js_1.CL_MAX_TICK, DLiquidity: ZERO });
|
|
85
|
-
}
|
|
86
|
-
if (this.ticks[0].index > CLPool_js_1.CL_MIN_TICK)
|
|
87
|
-
this.ticks.unshift({ index: CLPool_js_1.CL_MIN_TICK, DLiquidity: ZERO });
|
|
88
|
-
if (this.ticks[this.ticks.length - 1].index < CLPool_js_1.CL_MAX_TICK)
|
|
89
|
-
this.ticks.push({ index: CLPool_js_1.CL_MAX_TICK, DLiquidity: ZERO });
|
|
90
|
-
this.liquidity = liquidity;
|
|
91
|
-
this.sqrtPriceX96 = sqrtPriceX96;
|
|
92
|
-
this.nearestTick = nearestTick ?? this._findTickForPrice(tick);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
this.liquidity = undefined;
|
|
96
|
-
this.sqrtPriceX96 = undefined;
|
|
97
|
-
this.nearestTick = 0;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
updateState(reserve0, reserve1, tick, liquidity, sqrtPriceX96) {
|
|
101
|
-
this.updateReserves(reserve0, reserve1);
|
|
102
|
-
this.liquidity = liquidity;
|
|
103
|
-
this.sqrtPriceX96 = sqrtPriceX96;
|
|
104
|
-
this.nearestTick = this._findTickForPrice(tick);
|
|
105
|
-
}
|
|
106
|
-
poolType() {
|
|
107
|
-
return RPool_js_1.PoolType.Concentrated;
|
|
108
|
-
}
|
|
109
|
-
_findTickForPrice(tick) {
|
|
110
|
-
let a = 0;
|
|
111
|
-
let b = this.ticks.length;
|
|
112
|
-
while (b - a > 1) {
|
|
113
|
-
const c = Math.floor((a + b) / 2);
|
|
114
|
-
const ind = this.ticks[c].index;
|
|
115
|
-
if (ind === tick)
|
|
116
|
-
return c;
|
|
117
|
-
if (ind < tick)
|
|
118
|
-
a = c;
|
|
119
|
-
else
|
|
120
|
-
b = c;
|
|
121
|
-
}
|
|
122
|
-
return a;
|
|
123
|
-
}
|
|
124
|
-
calcOutByIn(amountIn, direction, throwIfOutOfLiquidity = true) {
|
|
125
|
-
let nextTickToCross = direction ? this.nearestTick : this.nearestTick + 1;
|
|
126
|
-
const currentPriceBI = this.sqrtPriceX96;
|
|
127
|
-
let currentPrice = parseInt(currentPriceBI.toString()) / two96;
|
|
128
|
-
let currentLiquidityBI = this.liquidity;
|
|
129
|
-
let outAmount = 0;
|
|
130
|
-
let input = amountIn * (1 - this.fee);
|
|
131
|
-
let stepCounter = 0;
|
|
132
|
-
let startFlag = true;
|
|
133
|
-
while (input > 0) {
|
|
134
|
-
if (nextTickToCross < 0 || nextTickToCross >= this.ticks.length) {
|
|
135
|
-
if (throwIfOutOfLiquidity)
|
|
136
|
-
throw new Error(`UniV3 OutOfLiquidity ${this.address}`);
|
|
137
|
-
else
|
|
138
|
-
return { out: outAmount, gasSpent: this.swapGasCost };
|
|
139
|
-
}
|
|
140
|
-
let nextTickPrice;
|
|
141
|
-
let priceDiff;
|
|
142
|
-
if (startFlag) {
|
|
143
|
-
const nextTickPriceBI = getSqrtRatioAtTick(this.ticks[nextTickToCross].index);
|
|
144
|
-
nextTickPrice = parseInt(nextTickPriceBI.toString()) / two96;
|
|
145
|
-
priceDiff =
|
|
146
|
-
parseInt((currentPriceBI - nextTickPriceBI).toString()) / two96;
|
|
147
|
-
startFlag = false;
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
nextTickPrice = Math.sqrt(1.0001 ** this.ticks[nextTickToCross].index);
|
|
151
|
-
priceDiff = currentPrice - nextTickPrice;
|
|
152
|
-
}
|
|
153
|
-
let output = 0;
|
|
154
|
-
const currentLiquidity = parseInt(currentLiquidityBI.toString());
|
|
155
|
-
if (direction) {
|
|
156
|
-
const maxDx = (currentLiquidity * priceDiff) / currentPrice / nextTickPrice;
|
|
157
|
-
if (input <= maxDx) {
|
|
158
|
-
output =
|
|
159
|
-
(currentLiquidity * currentPrice * input) /
|
|
160
|
-
(input + currentLiquidity / currentPrice);
|
|
161
|
-
input = 0;
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
output = currentLiquidity * priceDiff;
|
|
165
|
-
currentPrice = nextTickPrice;
|
|
166
|
-
input -= maxDx;
|
|
167
|
-
currentLiquidityBI =
|
|
168
|
-
currentLiquidityBI -
|
|
169
|
-
this.ticks[nextTickToCross].DLiquidity;
|
|
170
|
-
nextTickToCross--;
|
|
171
|
-
if (nextTickToCross === 0)
|
|
172
|
-
currentLiquidityBI = ZERO;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
const maxDy = currentLiquidity * -priceDiff;
|
|
177
|
-
if (input <= maxDy) {
|
|
178
|
-
output =
|
|
179
|
-
input / currentPrice / (currentPrice + input / currentLiquidity);
|
|
180
|
-
input = 0;
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
output =
|
|
184
|
-
(currentLiquidity * -priceDiff) / currentPrice / nextTickPrice;
|
|
185
|
-
currentPrice = nextTickPrice;
|
|
186
|
-
input -= maxDy;
|
|
187
|
-
currentLiquidityBI =
|
|
188
|
-
currentLiquidityBI +
|
|
189
|
-
this.ticks[nextTickToCross].DLiquidity;
|
|
190
|
-
nextTickToCross++;
|
|
191
|
-
if (nextTickToCross === this.ticks.length - 1)
|
|
192
|
-
currentLiquidityBI = ZERO;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
outAmount += output;
|
|
196
|
-
++stepCounter;
|
|
197
|
-
}
|
|
198
|
-
return {
|
|
199
|
-
out: outAmount,
|
|
200
|
-
gasSpent: BASE_GAS_CONSUMPTION + STEP_GAS_CONSUMPTION * stepCounter,
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
calcOutByInReal(amountIn, direction) {
|
|
204
|
-
const amountInRounded = Math.floor(amountIn * (1 - this.fee)) / (1 - this.fee);
|
|
205
|
-
return Math.floor(this.calcOutByIn(amountInRounded, direction, false).out);
|
|
206
|
-
}
|
|
207
|
-
calcInByOut(amountOut, direction) {
|
|
208
|
-
let nextTickToCross = direction ? this.nearestTick : this.nearestTick + 1;
|
|
209
|
-
const currentPriceBI = this.sqrtPriceX96;
|
|
210
|
-
let currentPrice = parseInt(currentPriceBI.toString()) / two96;
|
|
211
|
-
let currentLiquidityBI = this.liquidity;
|
|
212
|
-
let input = 0;
|
|
213
|
-
let outBeforeFee = amountOut;
|
|
214
|
-
let stepCounter = 0;
|
|
215
|
-
let startFlag = true;
|
|
216
|
-
while (outBeforeFee > 0) {
|
|
217
|
-
if (nextTickToCross < 0 || nextTickToCross >= this.ticks.length)
|
|
218
|
-
return { inp: Number.POSITIVE_INFINITY, gasSpent: this.swapGasCost };
|
|
219
|
-
++stepCounter;
|
|
220
|
-
let nextTickPrice;
|
|
221
|
-
let priceDiff;
|
|
222
|
-
if (startFlag) {
|
|
223
|
-
const nextTickPriceBI = getSqrtRatioAtTick(this.ticks[nextTickToCross].index);
|
|
224
|
-
nextTickPrice = parseInt(nextTickPriceBI.toString()) / two96;
|
|
225
|
-
priceDiff =
|
|
226
|
-
parseInt((currentPriceBI - nextTickPriceBI).toString()) / two96;
|
|
227
|
-
startFlag = false;
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
nextTickPrice = Math.sqrt(1.0001 ** this.ticks[nextTickToCross].index);
|
|
231
|
-
priceDiff = currentPrice - nextTickPrice;
|
|
232
|
-
}
|
|
233
|
-
const currentLiquidity = parseInt(currentLiquidityBI.toString());
|
|
234
|
-
if (direction) {
|
|
235
|
-
const maxDy = currentLiquidity * priceDiff;
|
|
236
|
-
if (outBeforeFee <= maxDy) {
|
|
237
|
-
input +=
|
|
238
|
-
outBeforeFee /
|
|
239
|
-
currentPrice /
|
|
240
|
-
(currentPrice - outBeforeFee / currentLiquidity);
|
|
241
|
-
outBeforeFee = 0;
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
input += (currentLiquidity * priceDiff) / currentPrice / nextTickPrice;
|
|
245
|
-
currentPrice = nextTickPrice;
|
|
246
|
-
outBeforeFee -= maxDy;
|
|
247
|
-
currentLiquidityBI =
|
|
248
|
-
currentLiquidityBI -
|
|
249
|
-
this.ticks[nextTickToCross].DLiquidity;
|
|
250
|
-
nextTickToCross--;
|
|
251
|
-
if (nextTickToCross === 0)
|
|
252
|
-
currentLiquidityBI = ZERO;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
const maxDx = (currentLiquidity * -priceDiff) / currentPrice / nextTickPrice;
|
|
257
|
-
if (outBeforeFee <= maxDx) {
|
|
258
|
-
input +=
|
|
259
|
-
(currentLiquidity * currentPrice * outBeforeFee) /
|
|
260
|
-
(currentLiquidity / currentPrice - outBeforeFee);
|
|
261
|
-
outBeforeFee = 0;
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
input += currentLiquidity * -priceDiff;
|
|
265
|
-
currentPrice = nextTickPrice;
|
|
266
|
-
outBeforeFee -= maxDx;
|
|
267
|
-
currentLiquidityBI =
|
|
268
|
-
currentLiquidityBI +
|
|
269
|
-
this.ticks[nextTickToCross].DLiquidity;
|
|
270
|
-
nextTickToCross++;
|
|
271
|
-
if (nextTickToCross === this.ticks.length - 1)
|
|
272
|
-
currentLiquidityBI = ZERO;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
return {
|
|
277
|
-
inp: input / (1 - this.fee),
|
|
278
|
-
gasSpent: BASE_GAS_CONSUMPTION + STEP_GAS_CONSUMPTION * stepCounter,
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
calcCurrentPriceWithoutFee(direction) {
|
|
282
|
-
const currentPrice = parseInt(this.sqrtPriceX96.toString()) / two96;
|
|
283
|
-
const p = currentPrice * currentPrice;
|
|
284
|
-
return direction ? p : 1 / p;
|
|
285
|
-
}
|
|
286
|
-
isPoolAppropriateForPricing() {
|
|
287
|
-
return (super.isPoolAppropriateForPricing() && this.liquidity >= this.minLiquidity);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
exports.UniV3Pool = UniV3Pool;
|
|
291
|
-
//# sourceMappingURL=UniV3Pool.js.map
|