@paraswap/dex-lib 3.0.6 → 3.2.5-return-amount-pos.4
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/.idea/aws.xml +17 -0
- package/.idea/codeStyles/Project.xml +55 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/paraswap-dex-lib-private.iml +9 -0
- package/.idea/prettier.xml +7 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +327 -10
- package/build/abi/AugustusV6.abi.json +1454 -0
- package/build/abi/angle/stagToken.json +963 -0
- package/build/abi/augustus-v6/ABI.json +1084 -587
- package/build/abi/balancer-v2/gyro-e.abi.json +1595 -0
- package/build/abi/etherfi/eETHPool.json +9 -0
- package/build/abi/etherfi/weETH.json +20 -0
- package/build/abi/maker-psm/pot.json +322 -0
- package/build/abi/rswETH.json +1142 -0
- package/build/abi/sdai/SavingsDai.abi.json +877 -0
- package/build/abi/velodrome-slipstream/VelodromeSlipstreamFactory.abi.json +579 -0
- package/build/abi/velodrome-slipstream/VelodromeSlipstreamPool.abi.json +1275 -0
- package/build/abi/velodrome-slipstream/VelodromeSlipstreamStateMulticall.abi.json +766 -0
- package/build/config.js +51 -46
- package/build/config.js.map +1 -1
- package/build/dex/aave-v1/aave-v1.js +1 -0
- package/build/dex/aave-v1/aave-v1.js.map +1 -1
- package/build/dex/aave-v2/aave-v2.js +1 -0
- package/build/dex/aave-v2/aave-v2.js.map +1 -1
- package/build/dex/aave-v3/aave-v3.js +1 -0
- package/build/dex/aave-v3/aave-v3.js.map +1 -1
- package/build/dex/algebra/algebra-factory.js +1 -1
- package/build/dex/algebra/algebra-factory.js.map +1 -1
- package/build/dex/algebra/algebra-pool-v1_1.d.ts +7 -2
- package/build/dex/algebra/algebra-pool-v1_1.js +9 -2
- package/build/dex/algebra/algebra-pool-v1_1.js.map +1 -1
- package/build/dex/algebra/algebra-pool-v1_9.d.ts +4 -0
- package/build/dex/algebra/algebra-pool-v1_9.js +6 -0
- package/build/dex/algebra/algebra-pool-v1_9.js.map +1 -1
- package/build/dex/algebra/algebra-pool-v1_9_bidirectional_fee.d.ts +16 -0
- package/build/dex/algebra/algebra-pool-v1_9_bidirectional_fee.js +26 -0
- package/build/dex/algebra/algebra-pool-v1_9_bidirectional_fee.js.map +1 -0
- package/build/dex/algebra/algebra.d.ts +2 -1
- package/build/dex/algebra/algebra.js +13 -7
- package/build/dex/algebra/algebra.js.map +1 -1
- package/build/dex/algebra/config.js +4 -0
- package/build/dex/algebra/config.js.map +1 -1
- package/build/dex/algebra/types.d.ts +1 -1
- package/build/dex/angle-staked-stable/angle-staked-stable-pool.d.ts +56 -0
- package/build/dex/angle-staked-stable/angle-staked-stable-pool.js +197 -0
- package/build/dex/angle-staked-stable/angle-staked-stable-pool.js.map +1 -0
- package/build/dex/angle-staked-stable/angle-staked-stable.d.ts +49 -0
- package/build/dex/angle-staked-stable/angle-staked-stable.js +239 -0
- package/build/dex/angle-staked-stable/angle-staked-stable.js.map +1 -0
- package/build/dex/angle-staked-stable/config.d.ts +4 -0
- package/build/dex/angle-staked-stable/config.js +139 -0
- package/build/dex/angle-staked-stable/config.js.map +1 -0
- package/build/dex/angle-staked-stable/types.d.ts +15 -0
- package/build/dex/angle-staked-stable/types.js +3 -0
- package/build/dex/angle-staked-stable/types.js.map +1 -0
- package/build/dex/bProtocol/bProtocol.js +5 -0
- package/build/dex/bProtocol/bProtocol.js.map +1 -1
- package/build/dex/balancer-v1/balancer-v1.js +4 -0
- package/build/dex/balancer-v1/balancer-v1.js.map +1 -1
- package/build/dex/balancer-v2/balancer-v2.d.ts +9 -4
- package/build/dex/balancer-v2/balancer-v2.js +111 -84
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.d.ts +32 -0
- package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.js +149 -0
- package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.js.map +1 -0
- package/build/dex/balancer-v2/pools/gyro/GyroEPool.d.ts +37 -0
- package/build/dex/balancer-v2/pools/gyro/GyroEPool.js +222 -0
- package/build/dex/balancer-v2/pools/gyro/GyroEPool.js.map +1 -0
- package/build/dex/balancer-v2/pools/gyro/gyro-helpers.d.ts +2 -0
- package/build/dex/balancer-v2/pools/gyro/gyro-helpers.js +19 -0
- package/build/dex/balancer-v2/pools/gyro/gyro-helpers.js.map +1 -0
- package/build/dex/balancer-v2/queryOnChain.d.ts +1 -0
- package/build/dex/balancer-v2/queryOnChain.js +40 -0
- package/build/dex/balancer-v2/queryOnChain.js.map +1 -0
- package/build/dex/balancer-v2/types.d.ts +41 -2
- package/build/dex/balancer-v2/types.js +2 -0
- package/build/dex/balancer-v2/types.js.map +1 -1
- package/build/dex/balancer-v2/utils.d.ts +8 -0
- package/build/dex/balancer-v2/utils.js +17 -1
- package/build/dex/balancer-v2/utils.js.map +1 -1
- package/build/dex/bancor/bancor.js +4 -0
- package/build/dex/bancor/bancor.js.map +1 -1
- package/build/dex/camelot/camelot.js +1 -0
- package/build/dex/camelot/camelot.js.map +1 -1
- package/build/dex/compound/compound.js +1 -0
- package/build/dex/compound/compound.js.map +1 -1
- package/build/dex/curve-v1/curve-v1.js +1 -0
- package/build/dex/curve-v1/curve-v1.js.map +1 -1
- package/build/dex/curve-v1-factory/config.js +128 -11
- package/build/dex/curve-v1-factory/config.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +1 -0
- package/build/dex/curve-v1-factory/curve-v1-factory.js +30 -17
- package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-pool-manager.js +1 -0
- package/build/dex/curve-v1-factory/curve-v1-pool-manager.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.js +1 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.js +4 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js +1 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_xp.js +1 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/_xp.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_xp_mem.js +1 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/_xp_mem.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.js +1 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.js +1 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/constants.js +10 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/constants.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D.js +40 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D_mem.js +1 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D_mem.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.js +1 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_dy.js +24 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/get_dy.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.js +1 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_y.js +53 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/get_y.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_y_D.js +1 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/get_y_D.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/utils.d.ts +1 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/utils.js +5 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/utils.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/types.d.ts +2 -2
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.d.ts +3 -2
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js +38 -6
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js.map +1 -1
- package/build/dex/curve-v1-factory/types.d.ts +11 -2
- package/build/dex/curve-v1-factory/types.js +3 -0
- package/build/dex/curve-v1-factory/types.js.map +1 -1
- package/build/dex/curve-v2/curve-v2.js +1 -0
- package/build/dex/curve-v2/curve-v2.js.map +1 -1
- package/build/dex/dexalot/config.js +7 -0
- package/build/dex/dexalot/config.js.map +1 -1
- package/build/dex/dexalot/dexalot.js +2 -0
- package/build/dex/dexalot/dexalot.js.map +1 -1
- package/build/dex/dodo-v1/dodo-v1.js +4 -0
- package/build/dex/dodo-v1/dodo-v1.js.map +1 -1
- package/build/dex/dodo-v2.js +4 -0
- package/build/dex/dodo-v2.js.map +1 -1
- package/build/dex/etherfi.d.ts +27 -0
- package/build/dex/etherfi.js +146 -0
- package/build/dex/etherfi.js.map +1 -0
- package/build/dex/generic-rfq/generic-rfq.js +4 -3
- package/build/dex/generic-rfq/generic-rfq.js.map +1 -1
- package/build/dex/generic-rfq/rate-fetcher.d.ts +1 -1
- package/build/dex/generic-rfq/rate-fetcher.js +2 -1
- package/build/dex/generic-rfq/rate-fetcher.js.map +1 -1
- package/build/dex/generic-rfq/types.d.ts +1 -0
- package/build/dex/generic-rfq/types.js.map +1 -1
- package/build/dex/gmx/gmx.js +4 -0
- package/build/dex/gmx/gmx.js.map +1 -1
- package/build/dex/hashflow/constants.d.ts +27 -0
- package/build/dex/hashflow/constants.js +29 -1
- package/build/dex/hashflow/constants.js.map +1 -1
- package/build/dex/hashflow/hashflow.d.ts +3 -2
- package/build/dex/hashflow/hashflow.js +72 -13
- package/build/dex/hashflow/hashflow.js.map +1 -1
- package/build/dex/hashflow/types.d.ts +11 -0
- package/build/dex/hashflow/types.js +9 -0
- package/build/dex/hashflow/types.js.map +1 -1
- package/build/dex/idex.d.ts +2 -2
- package/build/dex/index.d.ts +2 -2
- package/build/dex/index.js +10 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/jarvis-v6/jarvis-v6.js +1 -0
- package/build/dex/jarvis-v6/jarvis-v6.js.map +1 -1
- package/build/dex/jarvis.js +8 -0
- package/build/dex/jarvis.js.map +1 -1
- package/build/dex/kyberdmm/kyberdmm.js +4 -0
- package/build/dex/kyberdmm/kyberdmm.js.map +1 -1
- package/build/dex/lido/lido.d.ts +4 -1
- package/build/dex/lido/lido.js +18 -1
- package/build/dex/lido/lido.js.map +1 -1
- package/build/dex/maker-psm/maker-psm.js +1 -0
- package/build/dex/maker-psm/maker-psm.js.map +1 -1
- package/build/dex/maverick-v1/maverick-v1.js +4 -0
- package/build/dex/maverick-v1/maverick-v1.js.map +1 -1
- package/build/dex/nerve/nerve.js +4 -0
- package/build/dex/nerve/nerve.js.map +1 -1
- package/build/dex/onebit/onebit.js +5 -0
- package/build/dex/onebit/onebit.js.map +1 -1
- package/build/dex/pancakeswap-v3/config.js +30 -0
- package/build/dex/pancakeswap-v3/config.js.map +1 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js +1 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js.map +1 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.d.ts +5 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js +7 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js.map +1 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js +16 -8
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
- package/build/dex/paraswap-limit-orders/paraswap-limit-orders.js +1 -0
- package/build/dex/paraswap-limit-orders/paraswap-limit-orders.js.map +1 -1
- package/build/dex/platypus/platypus.js +17 -3
- package/build/dex/platypus/platypus.js.map +1 -1
- package/build/dex/polygon-migrator/polygon-migrator.js +1 -0
- package/build/dex/polygon-migrator/polygon-migrator.js.map +1 -1
- package/build/dex/quick-perps/quick-perps.js +7 -1
- package/build/dex/quick-perps/quick-perps.js.map +1 -1
- package/build/dex/simple-exchange.d.ts +0 -1
- package/build/dex/simple-exchange.js +0 -2
- package/build/dex/simple-exchange.js.map +1 -1
- package/build/dex/smoothy/smoothy.js +1 -0
- package/build/dex/smoothy/smoothy.js.map +1 -1
- package/build/dex/smoothy.d.ts +1 -1
- package/build/dex/smoothy.js +2 -3
- package/build/dex/smoothy.js.map +1 -1
- package/build/dex/solidly/config.js +12 -0
- package/build/dex/solidly/config.js.map +1 -1
- package/build/dex/solidly/forks-override/pharaohV1.d.ts +8 -0
- package/build/dex/solidly/forks-override/pharaohV1.js +15 -0
- package/build/dex/solidly/forks-override/pharaohV1.js.map +1 -0
- package/build/dex/solidly/solidly.js +2 -0
- package/build/dex/solidly/solidly.js.map +1 -1
- package/build/dex/solidly-v3/config.js +13 -1
- package/build/dex/solidly-v3/config.js.map +1 -1
- package/build/dex/solidly-v3/solidly-v3-factory.js +1 -1
- package/build/dex/solidly-v3/solidly-v3-factory.js.map +1 -1
- package/build/dex/solidly-v3/solidly-v3-pool.d.ts +5 -0
- package/build/dex/solidly-v3/solidly-v3-pool.js +7 -0
- package/build/dex/solidly-v3/solidly-v3-pool.js.map +1 -1
- package/build/dex/solidly-v3/solidly-v3.d.ts +1 -2
- package/build/dex/solidly-v3/solidly-v3.js +5 -11
- package/build/dex/solidly-v3/solidly-v3.js.map +1 -1
- package/build/dex/solidly-v3/types.d.ts +0 -1
- package/build/dex/solidly-v3/types.js.map +1 -1
- package/build/dex/spark/config.d.ts +11 -0
- package/build/dex/spark/config.js +21 -0
- package/build/dex/spark/config.js.map +1 -0
- package/build/dex/spark/constants.d.ts +2 -0
- package/build/dex/spark/constants.js +6 -0
- package/build/dex/spark/constants.js.map +1 -0
- package/build/dex/spark/scripts/validate-state.d.ts +1 -0
- package/build/dex/spark/scripts/validate-state.js +102 -0
- package/build/dex/spark/scripts/validate-state.js.map +1 -0
- package/build/dex/spark/spark-sdai-pool.d.ts +16 -0
- package/build/dex/spark/spark-sdai-pool.js +85 -0
- package/build/dex/spark/spark-sdai-pool.js.map +1 -0
- package/build/dex/spark/spark.d.ts +52 -0
- package/build/dex/spark/spark.js +195 -0
- package/build/dex/spark/spark.js.map +1 -0
- package/build/dex/spark/types.d.ts +21 -0
- package/build/dex/spark/types.js +11 -0
- package/build/dex/spark/types.js.map +1 -0
- package/build/dex/spark/utils.d.ts +4 -0
- package/build/dex/spark/utils.js +39 -0
- package/build/dex/spark/utils.js.map +1 -0
- package/build/dex/stable-pool/stable-pool.js +4 -0
- package/build/dex/stable-pool/stable-pool.js.map +1 -1
- package/build/dex/swaap-v1/swaap-v1.js +4 -0
- package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
- package/build/dex/swaap-v2/swaap-v2.js +1 -0
- package/build/dex/swaap-v2/swaap-v2.js.map +1 -1
- package/build/dex/swell/config.d.ts +1 -0
- package/build/dex/swell/config.js +1 -0
- package/build/dex/swell/config.js.map +1 -1
- package/build/dex/swell/rsweth-pool.d.ts +16 -0
- package/build/dex/swell/rsweth-pool.js +38 -0
- package/build/dex/swell/rsweth-pool.js.map +1 -0
- package/build/dex/swell/swell.d.ts +7 -2
- package/build/dex/swell/swell.js +58 -27
- package/build/dex/swell/swell.js.map +1 -1
- package/build/dex/swell/sweth-pool.js +1 -1
- package/build/dex/swell/sweth-pool.js.map +1 -1
- package/build/dex/swell/type.d.ts +3 -0
- package/build/dex/swell/utils.d.ts +3 -2
- package/build/dex/swell/utils.js +19 -3
- package/build/dex/swell/utils.js.map +1 -1
- package/build/dex/synthetix/synthetix.js +6 -0
- package/build/dex/synthetix/synthetix.js.map +1 -1
- package/build/dex/trader-joe-v2.1/trader-joe-v2.1.js +4 -0
- package/build/dex/trader-joe-v2.1/trader-joe-v2.1.js.map +1 -1
- package/build/dex/uniswap-v2/config.js +56 -0
- package/build/dex/uniswap-v2/config.js.map +1 -1
- package/build/dex/uniswap-v2/types.d.ts +1 -1
- package/build/dex/uniswap-v2/uniswap-v2.js +2 -1
- package/build/dex/uniswap-v2/uniswap-v2.js.map +1 -1
- package/build/dex/uniswap-v3/config.js +102 -1
- package/build/dex/uniswap-v3/config.js.map +1 -1
- package/build/dex/uniswap-v3/forks/velodrome-slipstream/utils.d.ts +4 -0
- package/build/dex/uniswap-v3/forks/velodrome-slipstream/utils.js +56 -0
- package/build/dex/uniswap-v3/forks/velodrome-slipstream/utils.js.map +1 -0
- package/build/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-factory.d.ts +7 -0
- package/build/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-factory.js +23 -0
- package/build/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-factory.js.map +1 -0
- package/build/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-pool.d.ts +13 -0
- package/build/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-pool.js +137 -0
- package/build/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-pool.js.map +1 -0
- package/build/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream.d.ts +46 -0
- package/build/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream.js +117 -0
- package/build/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream.js.map +1 -0
- package/build/dex/uniswap-v3/types.d.ts +8 -2
- package/build/dex/uniswap-v3/types.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3-factory.js +1 -1
- package/build/dex/uniswap-v3/uniswap-v3-factory.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +9 -2
- package/build/dex/uniswap-v3/uniswap-v3-pool.js +15 -2
- package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3.d.ts +27 -12
- package/build/dex/uniswap-v3/uniswap-v3.js +108 -76
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/build/dex/uniswap-v3.js +4 -0
- package/build/dex/uniswap-v3.js.map +1 -1
- package/build/dex/weth/weth.js +1 -0
- package/build/dex/weth/weth.js.map +1 -1
- package/build/dex/wombat/wombat.js +4 -0
- package/build/dex/wombat/wombat.js.map +1 -1
- package/build/dex/woo-fi-v2/config.js +16 -16
- package/build/dex/woo-fi-v2/woo-fi-v2.js +4 -0
- package/build/dex/woo-fi-v2/woo-fi-v2.js.map +1 -1
- package/build/dex/wsteth/wsteth.js +8 -1
- package/build/dex/wsteth/wsteth.js.map +1 -1
- package/build/dex/zerox/index.js +1 -0
- package/build/dex/zerox/index.js.map +1 -1
- package/build/executor/Executor01BytecodeBuilder.d.ts +6 -8
- package/build/executor/Executor01BytecodeBuilder.js +47 -8
- package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor02BytecodeBuilder.d.ts +18 -12
- package/build/executor/Executor02BytecodeBuilder.js +55 -10
- package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor03BytecodeBuilder.d.ts +11 -8
- package/build/executor/Executor03BytecodeBuilder.js +27 -5
- package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
- package/build/executor/ExecutorBytecodeBuilder.d.ts +29 -6
- package/build/executor/ExecutorBytecodeBuilder.js +23 -4
- package/build/executor/ExecutorBytecodeBuilder.js.map +1 -1
- package/build/executor/ExecutorDetector.d.ts +2 -0
- package/build/executor/ExecutorDetector.js +12 -0
- package/build/executor/ExecutorDetector.js.map +1 -1
- package/build/executor/IExecutorBytecodeBuilder.d.ts +10 -0
- package/build/executor/IExecutorBytecodeBuilder.js +3 -0
- package/build/executor/IExecutorBytecodeBuilder.js.map +1 -0
- package/build/executor/WETHBytecodeBuilder.d.ts +14 -0
- package/build/executor/WETHBytecodeBuilder.js +47 -0
- package/build/executor/WETHBytecodeBuilder.js.map +1 -0
- package/build/executor/constants.d.ts +3 -1
- package/build/executor/constants.js +8 -3
- package/build/executor/constants.js.map +1 -1
- package/build/executor/types.d.ts +1 -0
- package/build/executor/types.js +1 -0
- package/build/executor/types.js.map +1 -1
- package/build/executor/utils.d.ts +2 -0
- package/build/executor/utils.js +30 -0
- package/build/executor/utils.js.map +1 -0
- package/build/generic-swap-transaction-builder.js +11 -5
- package/build/generic-swap-transaction-builder.js.map +1 -1
- package/build/implementations/local-paraswap-sdk.js +1 -1
- package/build/implementations/local-paraswap-sdk.js.map +1 -1
- package/build/stateful-event-subscriber.d.ts +1 -0
- package/build/stateful-event-subscriber.js +8 -1
- package/build/stateful-event-subscriber.js.map +1 -1
- package/build/types.d.ts +3 -0
- package/package.json +4 -3
- package/src/abi/angle/stagToken.json +963 -0
- package/src/abi/augustus-v6/ABI.json +1084 -587
- package/src/abi/balancer-v2/gyro-e.abi.json +1595 -0
- package/src/abi/etherfi/eETHPool.json +9 -0
- package/src/abi/etherfi/weETH.json +20 -0
- package/src/abi/maker-psm/pot.json +322 -0
- package/src/abi/rswETH.json +1142 -0
- package/src/abi/sdai/SavingsDai.abi.json +877 -0
- package/src/abi/velodrome-slipstream/VelodromeSlipstreamFactory.abi.json +579 -0
- package/src/abi/velodrome-slipstream/VelodromeSlipstreamPool.abi.json +1275 -0
- package/src/abi/velodrome-slipstream/VelodromeSlipstreamQuoterV2.abi.json +267 -0
- package/src/abi/velodrome-slipstream/VelodromeSlipstreamStateMulticall.abi.json +766 -0
- package/src/config.ts +51 -46
- package/src/dex/aave-v1/aave-v1.ts +1 -0
- package/src/dex/aave-v2/aave-v2.ts +1 -0
- package/src/dex/aave-v3/aave-v3.ts +1 -0
- package/src/dex/algebra/algebra-e2e.test.ts +22 -0
- package/src/dex/algebra/algebra-factory.ts +8 -1
- package/src/dex/algebra/algebra-pool-v1_1.ts +10 -2
- package/src/dex/algebra/algebra-pool-v1_9.ts +7 -0
- package/src/dex/algebra/algebra-pool-v1_9_bidirectional_fee.ts +55 -0
- package/src/dex/algebra/algebra.ts +28 -14
- package/src/dex/algebra/config.ts +4 -0
- package/src/dex/algebra/types.ts +1 -1
- package/src/dex/angle-staked-stable/angle-staked-stable-e2e.test.ts +146 -0
- package/src/dex/angle-staked-stable/angle-staked-stable-events.test.ts +95 -0
- package/src/dex/angle-staked-stable/angle-staked-stable-integration.test.ts +476 -0
- package/src/dex/angle-staked-stable/angle-staked-stable-pool.ts +325 -0
- package/src/dex/angle-staked-stable/angle-staked-stable.ts +351 -0
- package/src/dex/angle-staked-stable/config.ts +139 -0
- package/src/dex/angle-staked-stable/types.ts +16 -0
- package/src/dex/bProtocol/bProtocol.ts +8 -0
- package/src/dex/balancer-v1/balancer-v1.ts +9 -0
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +94 -0
- package/src/dex/balancer-v2/balancer-v2-gyro3.test.ts +268 -0
- package/src/dex/balancer-v2/balancer-v2-gyroE.test.ts +401 -0
- package/src/dex/balancer-v2/balancer-v2-integration.test.ts +253 -112
- package/src/dex/balancer-v2/balancer-v2.ts +203 -143
- package/src/dex/balancer-v2/pools/gyro/Gyro3Pool.ts +255 -0
- package/src/dex/balancer-v2/pools/gyro/GyroEPool.ts +403 -0
- package/src/dex/balancer-v2/pools/gyro/gyro-helpers.ts +15 -0
- package/src/dex/balancer-v2/queryOnChain.ts +48 -0
- package/src/dex/balancer-v2/types.ts +45 -1
- package/src/dex/balancer-v2/utils.ts +16 -0
- package/src/dex/bancor/bancor.ts +8 -0
- package/src/dex/camelot/camelot.ts +1 -0
- package/src/dex/compound/compound.ts +1 -0
- package/src/dex/curve-v1/curve-v1.ts +1 -0
- package/src/dex/curve-v1-factory/config.ts +128 -11
- package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +122 -1
- package/src/dex/curve-v1-factory/curve-v1-factory-integration.test.ts +392 -0
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +62 -39
- package/src/dex/curve-v1-factory/curve-v1-pool-manager.ts +1 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.ts +2 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.ts +6 -2
- package/src/dex/curve-v1-factory/price-handlers/functions/_rates.ts +2 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/_xp.ts +2 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/_xp_mem.ts +2 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.ts +2 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.ts +2 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/constants.ts +11 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_D.ts +59 -1
- package/src/dex/curve-v1-factory/price-handlers/functions/get_D_mem.ts +2 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.ts +2 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_dy.ts +51 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.ts +2 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_y.ts +68 -1
- package/src/dex/curve-v1-factory/price-handlers/functions/get_y_D.ts +2 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/utils.ts +4 -0
- package/src/dex/curve-v1-factory/price-handlers/types.ts +8 -1
- package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +71 -18
- package/src/dex/curve-v1-factory/state-polling-pools/pool-polling-base.ts +1 -0
- package/src/dex/curve-v1-factory/types.ts +12 -1
- package/src/dex/curve-v2/curve-v2.ts +1 -0
- package/src/dex/dexalot/config.ts +7 -0
- package/src/dex/dexalot/dexalot-e2e.test.ts +23 -1
- package/src/dex/dexalot/dexalot-integration.test.ts +121 -0
- package/src/dex/dexalot/dexalot.ts +2 -0
- package/src/dex/dodo-v1/dodo-v1.ts +9 -0
- package/src/dex/dodo-v2.ts +9 -0
- package/src/dex/etherfi.ts +239 -0
- package/src/dex/generic-rfq/generic-rfq.ts +4 -2
- package/src/dex/generic-rfq/rate-fetcher.ts +2 -0
- package/src/dex/generic-rfq/types.ts +1 -0
- package/src/dex/gmx/gmx.ts +8 -0
- package/src/dex/hashflow/constants.ts +32 -0
- package/src/dex/hashflow/hashflow.ts +126 -20
- package/src/dex/hashflow/types.ts +20 -2
- package/src/dex/idex.ts +2 -1
- package/src/dex/index.ts +12 -2
- package/src/dex/jarvis-v6/jarvis-v6.ts +1 -0
- package/src/dex/jarvis.ts +14 -0
- package/src/dex/kyberdmm/kyberdmm.ts +9 -0
- package/src/dex/lido/lido-e2e.test.ts +10 -0
- package/src/dex/lido/lido.ts +25 -2
- package/src/dex/maker-psm/maker-psm.ts +1 -0
- package/src/dex/maverick-v1/maverick-v1.ts +9 -0
- package/src/dex/nerve/nerve.ts +8 -0
- package/src/dex/onebit/onebit.ts +8 -0
- package/src/dex/pancakeswap-v3/config.ts +32 -0
- package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +21 -0
- package/src/dex/pancakeswap-v3/pancakeswap-v3-factory.ts +8 -1
- package/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts +8 -0
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +27 -13
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders.ts +1 -0
- package/src/dex/platypus/platypus.ts +20 -3
- package/src/dex/polygon-migrator/polygon-migrator.ts +1 -0
- package/src/dex/quick-perps/quick-perps.ts +11 -1
- package/src/dex/simple-exchange.ts +0 -4
- package/src/dex/smoothy/smoothy.ts +1 -0
- package/src/dex/solidly/config.ts +14 -0
- package/src/dex/solidly/forks-override/pharaohV1.ts +10 -0
- package/src/dex/solidly/solidly-e2e.test.ts +21 -0
- package/src/dex/solidly/solidly-integration.test.ts +143 -0
- package/src/dex/solidly/solidly.ts +2 -0
- package/src/dex/solidly-v3/config.ts +15 -1
- package/src/dex/solidly-v3/solidly-v3-e2e.test.ts +33 -0
- package/src/dex/solidly-v3/solidly-v3-factory.ts +8 -1
- package/src/dex/solidly-v3/solidly-v3-pool.ts +8 -0
- package/src/dex/solidly-v3/solidly-v3.ts +8 -16
- package/src/dex/solidly-v3/types.ts +0 -1
- package/src/dex/spark/config.ts +25 -0
- package/src/dex/spark/constants.ts +2 -0
- package/src/dex/spark/scripts/validate-state.ts +144 -0
- package/src/dex/spark/spark-e2e.test.ts +96 -0
- package/src/dex/spark/spark-events.test.ts +102 -0
- package/src/dex/spark/spark-integration.test.ts +151 -0
- package/src/dex/spark/spark-sdai-pool.ts +114 -0
- package/src/dex/spark/spark.ts +284 -0
- package/src/dex/spark/types.ts +23 -0
- package/src/dex/spark/utils.ts +47 -0
- package/src/dex/stable-pool/stable-pool.ts +8 -0
- package/src/dex/swaap-v1/swaap-v1.ts +9 -0
- package/src/dex/swaap-v2/swaap-v2.ts +1 -0
- package/src/dex/swell/config.ts +2 -0
- package/src/dex/swell/rsweth-pool.ts +58 -0
- package/src/dex/swell/swell-e2e.test.ts +33 -31
- package/src/dex/swell/swell.ts +88 -35
- package/src/dex/swell/sweth-pool.ts +2 -2
- package/src/dex/swell/type.ts +4 -0
- package/src/dex/swell/utils.ts +26 -2
- package/src/dex/synthetix/synthetix-state.ts +2 -2
- package/src/dex/synthetix/synthetix.ts +11 -0
- package/src/dex/trader-joe-v2.1/trader-joe-v2.1.ts +9 -0
- package/src/dex/uniswap-v2/config.ts +58 -0
- package/src/dex/uniswap-v2/types.ts +2 -2
- package/src/dex/uniswap-v2/uniswap-v2-e2e-base.test.ts +48 -0
- package/src/dex/uniswap-v2/uniswap-v2.ts +2 -1
- package/src/dex/uniswap-v3/config.ts +112 -3
- package/src/dex/uniswap-v3/forks/velodrome-slipstream/utils.ts +65 -0
- package/src/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-factory.ts +16 -0
- package/src/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-pool.ts +197 -0
- package/src/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream.ts +237 -0
- package/src/dex/uniswap-v3/types.ts +6 -2
- package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +184 -3
- package/src/dex/uniswap-v3/uniswap-v3-factory.ts +8 -1
- package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +741 -6
- package/src/dex/uniswap-v3/uniswap-v3-pool.ts +17 -9
- package/src/dex/uniswap-v3/uniswap-v3.ts +204 -121
- package/src/dex/uniswap-v3.ts +9 -0
- package/src/dex/weth/weth-e2e-v6.test.ts +117 -0
- package/src/dex/weth/weth.ts +1 -0
- package/src/dex/wombat/wombat.ts +9 -0
- package/src/dex/woo-fi-v2/config.ts +16 -16
- package/src/dex/woo-fi-v2/woo-fi-v2.ts +5 -0
- package/src/dex/wsteth/wsteth.ts +13 -4
- package/src/dex/zerox/index.ts +1 -0
- package/src/executor/Executor01BytecodeBuilder.ts +69 -29
- package/src/executor/Executor02BytecodeBuilder.ts +99 -44
- package/src/executor/Executor03BytecodeBuilder.ts +52 -33
- package/src/executor/ExecutorBytecodeBuilder.ts +57 -18
- package/src/executor/ExecutorDetector.ts +14 -0
- package/src/executor/WETHBytecodeBuilder.ts +57 -0
- package/src/executor/constants.ts +8 -2
- package/src/executor/executor01-bytecode-builder-e2e.test.ts +39 -0
- package/src/executor/executor02-bytecode-builder-e2e.test.ts +35 -0
- package/src/executor/types.ts +1 -0
- package/src/executor/utils.ts +44 -0
- package/src/generic-swap-transaction-builder.ts +14 -4
- package/src/implementations/local-paraswap-sdk.ts +1 -1
- package/src/stateful-event-subscriber.ts +13 -1
- package/src/types.ts +3 -0
- package/tests/constants-e2e.ts +233 -12
- package/tests/utils-e2e.ts +82 -2
- package/tests/debug-price-route.json +0 -87
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { BigNumber } from '@ethersproject/bignumber';
|
|
3
|
+
|
|
4
|
+
import { BasePool } from '../balancer-v2-pool';
|
|
5
|
+
import { SwapSide } from '../../../../constants';
|
|
6
|
+
import {
|
|
7
|
+
decodeThrowError,
|
|
8
|
+
getTokenScalingFactor,
|
|
9
|
+
safeParseFixed,
|
|
10
|
+
} from '../../utils';
|
|
11
|
+
import { callData, SubgraphPoolBase, PoolState, TokenState } from '../../types';
|
|
12
|
+
import { MathSol } from '../../balancer-v2-math';
|
|
13
|
+
import { Gyro3Maths } from '@balancer-labs/sor';
|
|
14
|
+
import { _addFee, _reduceFee } from './gyro-helpers';
|
|
15
|
+
|
|
16
|
+
// Swap Limit factor
|
|
17
|
+
const SWAP_LIMIT_FACTOR = BigInt('999999000000000000');
|
|
18
|
+
|
|
19
|
+
// All values should be normalised to 18 decimals. e.g. 1USDC = 1e18 not 1e6
|
|
20
|
+
export type Gyro3PoolPairData = {
|
|
21
|
+
balances: BigNumber[];
|
|
22
|
+
indexIn: number;
|
|
23
|
+
indexOut: number;
|
|
24
|
+
swapFee: bigint;
|
|
25
|
+
balanceTertiary: BigNumber; // Balance of the unchanged asset
|
|
26
|
+
decimalsTertiary: number; // Decimals of the unchanged asset
|
|
27
|
+
scalingFactors: bigint[];
|
|
28
|
+
root3Alpha: BigNumber;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export class Gyro3Pool extends BasePool {
|
|
32
|
+
vaultAddress: string;
|
|
33
|
+
vaultInterface: Interface;
|
|
34
|
+
poolInterface = new Interface([
|
|
35
|
+
'function getSwapFeePercentage() view returns (uint256)',
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
constructor(vaultAddress: string, vaultInterface: Interface) {
|
|
39
|
+
super();
|
|
40
|
+
this.vaultAddress = vaultAddress;
|
|
41
|
+
this.vaultInterface = vaultInterface;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
parsePoolPairData(
|
|
45
|
+
pool: SubgraphPoolBase,
|
|
46
|
+
poolState: PoolState,
|
|
47
|
+
tokenIn: string,
|
|
48
|
+
tokenOut: string,
|
|
49
|
+
): Gyro3PoolPairData {
|
|
50
|
+
// All values should be normalised to 18 decimals. e.g. 1USDC = 1e18 not 1e6
|
|
51
|
+
let indexIn = 0,
|
|
52
|
+
indexOut = 0,
|
|
53
|
+
indexTertiary = 0;
|
|
54
|
+
const scalingFactors: bigint[] = [];
|
|
55
|
+
const balances = pool.tokens.map((t, i) => {
|
|
56
|
+
if (t.address.toLowerCase() === tokenIn.toLowerCase()) {
|
|
57
|
+
indexIn = i;
|
|
58
|
+
} else if (t.address.toLowerCase() === tokenOut.toLowerCase()) {
|
|
59
|
+
indexOut = i;
|
|
60
|
+
} else {
|
|
61
|
+
indexTertiary = i;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const scalingFactor = getTokenScalingFactor(t.decimals);
|
|
65
|
+
scalingFactors.push(scalingFactor);
|
|
66
|
+
|
|
67
|
+
return BigNumber.from(
|
|
68
|
+
this._upscale(
|
|
69
|
+
BigInt(poolState.tokens[t.address.toLowerCase()].balance),
|
|
70
|
+
scalingFactor,
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const balanceTertiary = balances[indexTertiary];
|
|
76
|
+
const decimalsTertiary = pool.tokens[indexTertiary].decimals;
|
|
77
|
+
|
|
78
|
+
const poolPairData: Gyro3PoolPairData = {
|
|
79
|
+
balances,
|
|
80
|
+
indexIn,
|
|
81
|
+
indexOut,
|
|
82
|
+
scalingFactors,
|
|
83
|
+
swapFee: poolState.swapFee,
|
|
84
|
+
balanceTertiary,
|
|
85
|
+
decimalsTertiary,
|
|
86
|
+
root3Alpha: safeParseFixed(pool.root3Alpha, 18),
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return poolPairData;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getSwapMaxAmount(poolPairData: Gyro3PoolPairData, side: SwapSide): bigint {
|
|
93
|
+
if (side === SwapSide.SELL) {
|
|
94
|
+
// Approximation - similar to traditional stable pools
|
|
95
|
+
return this._downscaleDown(
|
|
96
|
+
MathSol.mulDownFixed(
|
|
97
|
+
poolPairData.balances[poolPairData.indexOut].toBigInt(),
|
|
98
|
+
SWAP_LIMIT_FACTOR,
|
|
99
|
+
),
|
|
100
|
+
poolPairData.scalingFactors[poolPairData.indexIn],
|
|
101
|
+
);
|
|
102
|
+
} else {
|
|
103
|
+
return this._downscaleDown(
|
|
104
|
+
MathSol.mulDownFixed(
|
|
105
|
+
poolPairData.balances[poolPairData.indexIn].toBigInt(),
|
|
106
|
+
SWAP_LIMIT_FACTOR,
|
|
107
|
+
),
|
|
108
|
+
poolPairData.scalingFactors[poolPairData.indexOut],
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/*
|
|
114
|
+
Helper function to construct onchain multicall data for Pool.
|
|
115
|
+
*/
|
|
116
|
+
getOnChainCalls(pool: SubgraphPoolBase): callData[] {
|
|
117
|
+
const poolCallData: callData[] = [
|
|
118
|
+
{
|
|
119
|
+
target: this.vaultAddress,
|
|
120
|
+
callData: this.vaultInterface.encodeFunctionData('getPoolTokens', [
|
|
121
|
+
pool.id,
|
|
122
|
+
]),
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
target: pool.address,
|
|
126
|
+
callData: this.poolInterface.encodeFunctionData('getSwapFeePercentage'),
|
|
127
|
+
},
|
|
128
|
+
];
|
|
129
|
+
return poolCallData;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/*
|
|
133
|
+
Helper function to decode multicall data for Pool.
|
|
134
|
+
data must contain returnData
|
|
135
|
+
startIndex is where to start in returnData. Allows this decode function to be called along with other pool types.
|
|
136
|
+
*/
|
|
137
|
+
decodeOnChainCalls(
|
|
138
|
+
pool: SubgraphPoolBase,
|
|
139
|
+
data: { success: boolean; returnData: any }[],
|
|
140
|
+
startIndex: number,
|
|
141
|
+
): [{ [address: string]: PoolState }, number] {
|
|
142
|
+
const pools = {} as { [address: string]: PoolState };
|
|
143
|
+
|
|
144
|
+
const poolTokens = decodeThrowError(
|
|
145
|
+
this.vaultInterface,
|
|
146
|
+
'getPoolTokens',
|
|
147
|
+
data[startIndex++],
|
|
148
|
+
pool.address,
|
|
149
|
+
);
|
|
150
|
+
const swapFee = decodeThrowError(
|
|
151
|
+
this.poolInterface,
|
|
152
|
+
'getSwapFeePercentage',
|
|
153
|
+
data[startIndex++],
|
|
154
|
+
pool.address,
|
|
155
|
+
)[0];
|
|
156
|
+
|
|
157
|
+
const poolState: PoolState = {
|
|
158
|
+
swapFee: BigInt(swapFee.toString()),
|
|
159
|
+
orderedTokens: poolTokens.tokens,
|
|
160
|
+
tokens: poolTokens.tokens.reduce(
|
|
161
|
+
(ptAcc: { [address: string]: TokenState }, pt: string, j: number) => {
|
|
162
|
+
const tokenState: TokenState = {
|
|
163
|
+
balance: BigInt(poolTokens.balances[j].toString()),
|
|
164
|
+
};
|
|
165
|
+
ptAcc[pt.toLowerCase()] = tokenState;
|
|
166
|
+
return ptAcc;
|
|
167
|
+
},
|
|
168
|
+
{},
|
|
169
|
+
),
|
|
170
|
+
};
|
|
171
|
+
pools[pool.address] = poolState;
|
|
172
|
+
return [pools, startIndex];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
onSell(amounts: bigint[], poolPairData: Gyro3PoolPairData): bigint[] {
|
|
176
|
+
try {
|
|
177
|
+
const invariant = Gyro3Maths._calculateInvariant(
|
|
178
|
+
poolPairData.balances,
|
|
179
|
+
poolPairData.root3Alpha,
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
const virtualOffsetInOut = MathSol.mulDownFixed(
|
|
183
|
+
invariant.toBigInt(),
|
|
184
|
+
poolPairData.root3Alpha.toBigInt(),
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
const tokenAmountsInWithFee = amounts.map(a => {
|
|
188
|
+
const withFee = _reduceFee(a, poolPairData.swapFee);
|
|
189
|
+
return this._upscale(
|
|
190
|
+
withFee,
|
|
191
|
+
poolPairData.scalingFactors[poolPairData.indexIn],
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
return tokenAmountsInWithFee.map(amount => {
|
|
196
|
+
try {
|
|
197
|
+
const amountOut = Gyro3Maths._calcOutGivenIn(
|
|
198
|
+
poolPairData.balances[poolPairData.indexIn],
|
|
199
|
+
poolPairData.balances[poolPairData.indexOut],
|
|
200
|
+
BigNumber.from(amount),
|
|
201
|
+
BigNumber.from(virtualOffsetInOut),
|
|
202
|
+
).toBigInt();
|
|
203
|
+
|
|
204
|
+
return this._downscaleDown(
|
|
205
|
+
amountOut,
|
|
206
|
+
poolPairData.scalingFactors[poolPairData.indexOut],
|
|
207
|
+
);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
return BigInt(0);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
} catch (error) {
|
|
213
|
+
return [];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
onBuy(amounts: bigint[], poolPairData: Gyro3PoolPairData): bigint[] {
|
|
218
|
+
try {
|
|
219
|
+
const invariant = Gyro3Maths._calculateInvariant(
|
|
220
|
+
poolPairData.balances,
|
|
221
|
+
poolPairData.root3Alpha,
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const virtualOffsetInOut = MathSol.mulDownFixed(
|
|
225
|
+
invariant.toBigInt(),
|
|
226
|
+
poolPairData.root3Alpha.toBigInt(),
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
const tokenAmountsUpscaled = amounts.map(a =>
|
|
230
|
+
this._upscale(a, poolPairData.scalingFactors[poolPairData.indexOut]),
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
return tokenAmountsUpscaled.map(amount => {
|
|
234
|
+
try {
|
|
235
|
+
const amountIn = Gyro3Maths._calcInGivenOut(
|
|
236
|
+
poolPairData.balances[poolPairData.indexIn],
|
|
237
|
+
poolPairData.balances[poolPairData.indexOut],
|
|
238
|
+
BigNumber.from(amount),
|
|
239
|
+
BigNumber.from(virtualOffsetInOut),
|
|
240
|
+
).toBigInt();
|
|
241
|
+
|
|
242
|
+
const downScaledAmount = this._downscaleUp(
|
|
243
|
+
amountIn,
|
|
244
|
+
poolPairData.scalingFactors[poolPairData.indexIn],
|
|
245
|
+
);
|
|
246
|
+
return _addFee(downScaledAmount, poolPairData.swapFee);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
return BigInt(0);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
} catch (error) {
|
|
252
|
+
return [];
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { BigNumber } from '@ethersproject/bignumber';
|
|
3
|
+
|
|
4
|
+
import { BasePool } from '../balancer-v2-pool';
|
|
5
|
+
import { NULL_ADDRESS, SwapSide } from '../../../../constants';
|
|
6
|
+
import {
|
|
7
|
+
decodeThrowError,
|
|
8
|
+
getTokenScalingFactor,
|
|
9
|
+
safeParseFixed,
|
|
10
|
+
} from '../../utils';
|
|
11
|
+
import { callData, SubgraphPoolBase, PoolState, TokenState } from '../../types';
|
|
12
|
+
import { MathSol } from '../../balancer-v2-math';
|
|
13
|
+
import {
|
|
14
|
+
GyroEMaths,
|
|
15
|
+
DerivedGyroEParams,
|
|
16
|
+
GyroEParams,
|
|
17
|
+
balancesFromTokenInOut,
|
|
18
|
+
Vector2,
|
|
19
|
+
} from '@balancer-labs/sor';
|
|
20
|
+
import GyroEAbi from '../../../../abi/balancer-v2/gyro-e.abi.json';
|
|
21
|
+
import * as util from 'util';
|
|
22
|
+
|
|
23
|
+
// Swap Limit factor
|
|
24
|
+
const SWAP_LIMIT_FACTOR = BigInt('999999000000000000');
|
|
25
|
+
|
|
26
|
+
// All values should be normalised to 18 decimals. e.g. 1USDC = 1e18 not 1e6
|
|
27
|
+
export type GyroEPoolPairData = {
|
|
28
|
+
balances: BigNumber[];
|
|
29
|
+
tokenRates: bigint[];
|
|
30
|
+
gyroParams: GyroEParams;
|
|
31
|
+
gyroDerivedParams: DerivedGyroEParams;
|
|
32
|
+
rateProviders: string[];
|
|
33
|
+
indexIn: number;
|
|
34
|
+
indexOut: number;
|
|
35
|
+
swapFee: bigint;
|
|
36
|
+
scalingFactors: bigint[];
|
|
37
|
+
tokenInIsToken0: boolean;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export class GyroEPool extends BasePool {
|
|
41
|
+
vaultAddress: string;
|
|
42
|
+
vaultInterface: Interface;
|
|
43
|
+
poolInterface = new Interface(GyroEAbi);
|
|
44
|
+
|
|
45
|
+
constructor(vaultAddress: string, vaultInterface: Interface) {
|
|
46
|
+
super();
|
|
47
|
+
this.vaultAddress = vaultAddress;
|
|
48
|
+
this.vaultInterface = vaultInterface;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
parsePoolPairData(
|
|
52
|
+
pool: SubgraphPoolBase,
|
|
53
|
+
poolState: PoolState,
|
|
54
|
+
tokenIn: string,
|
|
55
|
+
tokenOut: string,
|
|
56
|
+
): GyroEPoolPairData {
|
|
57
|
+
// All values should be normalised to 18 decimals. e.g. 1USDC = 1e18 not 1e6
|
|
58
|
+
let indexIn = 0,
|
|
59
|
+
indexOut = 0;
|
|
60
|
+
const scalingFactors: bigint[] = [];
|
|
61
|
+
const balances = pool.tokens.map((t, i) => {
|
|
62
|
+
if (t.address.toLowerCase() === tokenIn.toLowerCase()) indexIn = i;
|
|
63
|
+
else if (t.address.toLowerCase() === tokenOut.toLowerCase()) indexOut = i;
|
|
64
|
+
const scalingFactor = getTokenScalingFactor(t.decimals);
|
|
65
|
+
scalingFactors.push(scalingFactor);
|
|
66
|
+
return BigNumber.from(
|
|
67
|
+
this._upscale(
|
|
68
|
+
BigInt(poolState.tokens[t.address.toLowerCase()].balance),
|
|
69
|
+
scalingFactor,
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const tokenInIsToken0 = indexIn === 0;
|
|
75
|
+
|
|
76
|
+
const tokenRates = poolState.tokenRates
|
|
77
|
+
? [poolState.tokenRates![0], poolState.tokenRates![1]]
|
|
78
|
+
: [];
|
|
79
|
+
|
|
80
|
+
const rateProviders = poolState.rateProviders ?? [];
|
|
81
|
+
|
|
82
|
+
const poolPairData: GyroEPoolPairData = {
|
|
83
|
+
gyroParams: poolState.gyroParams!,
|
|
84
|
+
gyroDerivedParams: poolState.gyroDerivedParams!,
|
|
85
|
+
tokenRates,
|
|
86
|
+
rateProviders,
|
|
87
|
+
balances,
|
|
88
|
+
indexIn,
|
|
89
|
+
indexOut,
|
|
90
|
+
scalingFactors,
|
|
91
|
+
swapFee: poolState.swapFee,
|
|
92
|
+
tokenInIsToken0,
|
|
93
|
+
};
|
|
94
|
+
return poolPairData;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
getSwapMaxAmount(poolPairData: GyroEPoolPairData, side: SwapSide): bigint {
|
|
98
|
+
if (side === SwapSide.SELL) {
|
|
99
|
+
// Approximation - similar to traditional stable pools
|
|
100
|
+
return this._downscaleDown(
|
|
101
|
+
MathSol.mulDownFixed(
|
|
102
|
+
poolPairData.balances[poolPairData.indexOut].toBigInt(),
|
|
103
|
+
SWAP_LIMIT_FACTOR,
|
|
104
|
+
),
|
|
105
|
+
poolPairData.scalingFactors[poolPairData.indexIn],
|
|
106
|
+
);
|
|
107
|
+
} else {
|
|
108
|
+
return this._downscaleDown(
|
|
109
|
+
MathSol.mulDownFixed(
|
|
110
|
+
poolPairData.balances[poolPairData.indexIn].toBigInt(),
|
|
111
|
+
SWAP_LIMIT_FACTOR,
|
|
112
|
+
),
|
|
113
|
+
poolPairData.scalingFactors[poolPairData.indexOut],
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/*
|
|
119
|
+
Helper function to construct onchain multicall data for Pool.
|
|
120
|
+
*/
|
|
121
|
+
getOnChainCalls(pool: SubgraphPoolBase): callData[] {
|
|
122
|
+
const poolCallData: callData[] = [
|
|
123
|
+
{
|
|
124
|
+
target: this.vaultAddress,
|
|
125
|
+
callData: this.vaultInterface.encodeFunctionData('getPoolTokens', [
|
|
126
|
+
pool.id,
|
|
127
|
+
]),
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
target: pool.address,
|
|
131
|
+
callData: this.poolInterface.encodeFunctionData('getSwapFeePercentage'),
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
target: pool.address,
|
|
135
|
+
callData: this.poolInterface.encodeFunctionData('getECLPParams'),
|
|
136
|
+
},
|
|
137
|
+
];
|
|
138
|
+
|
|
139
|
+
// Only version 2 of GyroE uses token rates
|
|
140
|
+
const v2Calls =
|
|
141
|
+
pool.poolTypeVersion === 2
|
|
142
|
+
? [
|
|
143
|
+
{
|
|
144
|
+
target: pool.address,
|
|
145
|
+
callData: this.poolInterface.encodeFunctionData('getTokenRates'),
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
target: pool.address,
|
|
149
|
+
callData: this.poolInterface.encodeFunctionData('rateProvider0'),
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
target: pool.address,
|
|
153
|
+
callData: this.poolInterface.encodeFunctionData('rateProvider1'),
|
|
154
|
+
},
|
|
155
|
+
]
|
|
156
|
+
: [];
|
|
157
|
+
|
|
158
|
+
return [...poolCallData, ...v2Calls];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/*
|
|
162
|
+
Helper function to decode multicall data for Pool.
|
|
163
|
+
data must contain returnData
|
|
164
|
+
startIndex is where to start in returnData. Allows this decode function to be called along with other pool types.
|
|
165
|
+
*/
|
|
166
|
+
decodeOnChainCalls(
|
|
167
|
+
pool: SubgraphPoolBase,
|
|
168
|
+
data: { success: boolean; returnData: any }[],
|
|
169
|
+
startIndex: number,
|
|
170
|
+
): [{ [address: string]: PoolState }, number] {
|
|
171
|
+
const pools = {} as { [address: string]: PoolState };
|
|
172
|
+
|
|
173
|
+
const poolTokens = decodeThrowError(
|
|
174
|
+
this.vaultInterface,
|
|
175
|
+
'getPoolTokens',
|
|
176
|
+
data[startIndex++],
|
|
177
|
+
pool.address,
|
|
178
|
+
);
|
|
179
|
+
const swapFee = decodeThrowError(
|
|
180
|
+
this.poolInterface,
|
|
181
|
+
'getSwapFeePercentage',
|
|
182
|
+
data[startIndex++],
|
|
183
|
+
pool.address,
|
|
184
|
+
)[0];
|
|
185
|
+
|
|
186
|
+
const eclParams = decodeThrowError(
|
|
187
|
+
this.poolInterface,
|
|
188
|
+
'getECLPParams',
|
|
189
|
+
data[startIndex++],
|
|
190
|
+
pool.address,
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
let tokenRates;
|
|
194
|
+
let rateProviders: string[] = [];
|
|
195
|
+
if (pool.poolTypeVersion === 2) {
|
|
196
|
+
tokenRates = decodeThrowError(
|
|
197
|
+
this.poolInterface,
|
|
198
|
+
'getTokenRates',
|
|
199
|
+
data[startIndex++],
|
|
200
|
+
pool.address,
|
|
201
|
+
);
|
|
202
|
+
tokenRates = tokenRates.map(t => BigInt(t.toString()));
|
|
203
|
+
|
|
204
|
+
const rateProvider0 = decodeThrowError(
|
|
205
|
+
this.poolInterface,
|
|
206
|
+
'rateProvider0',
|
|
207
|
+
data[startIndex++],
|
|
208
|
+
pool.address,
|
|
209
|
+
)[0];
|
|
210
|
+
|
|
211
|
+
const rateProvider1 = decodeThrowError(
|
|
212
|
+
this.poolInterface,
|
|
213
|
+
'rateProvider1',
|
|
214
|
+
data[startIndex++],
|
|
215
|
+
pool.address,
|
|
216
|
+
)[0];
|
|
217
|
+
rateProviders = [rateProvider0, rateProvider1];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const poolState: PoolState = {
|
|
221
|
+
gyroParams: eclParams.params,
|
|
222
|
+
gyroDerivedParams: eclParams.d,
|
|
223
|
+
swapFee: BigInt(swapFee.toString()),
|
|
224
|
+
tokenRates,
|
|
225
|
+
rateProviders,
|
|
226
|
+
orderedTokens: poolTokens.tokens,
|
|
227
|
+
tokens: poolTokens.tokens.reduce(
|
|
228
|
+
(ptAcc: { [address: string]: TokenState }, pt: string, j: number) => {
|
|
229
|
+
const tokenState: TokenState = {
|
|
230
|
+
balance: BigInt(poolTokens.balances[j].toString()),
|
|
231
|
+
};
|
|
232
|
+
ptAcc[pt.toLowerCase()] = tokenState;
|
|
233
|
+
return ptAcc;
|
|
234
|
+
},
|
|
235
|
+
{},
|
|
236
|
+
),
|
|
237
|
+
};
|
|
238
|
+
pools[pool.address] = poolState;
|
|
239
|
+
return [pools, startIndex];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
onSell(amounts: bigint[], poolPairData: GyroEPoolPairData): bigint[] {
|
|
243
|
+
try {
|
|
244
|
+
const scalingFactorTokenIn = this._scalingFactor(
|
|
245
|
+
poolPairData.tokenInIsToken0,
|
|
246
|
+
poolPairData,
|
|
247
|
+
);
|
|
248
|
+
const scalingFactorTokenOut = this._scalingFactor(
|
|
249
|
+
!poolPairData.tokenInIsToken0,
|
|
250
|
+
poolPairData,
|
|
251
|
+
);
|
|
252
|
+
const normalizedBalances = this._normalizeBalances(
|
|
253
|
+
poolPairData.balances,
|
|
254
|
+
poolPairData.tokenRates,
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
const orderedNormalizedBalances = balancesFromTokenInOut(
|
|
258
|
+
normalizedBalances[poolPairData.indexIn],
|
|
259
|
+
normalizedBalances[poolPairData.indexOut],
|
|
260
|
+
poolPairData.tokenInIsToken0,
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
const [currentInvariant, invErr] = GyroEMaths.calculateInvariantWithError(
|
|
264
|
+
orderedNormalizedBalances,
|
|
265
|
+
poolPairData.gyroParams,
|
|
266
|
+
poolPairData.gyroDerivedParams,
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
const invariant: Vector2 = {
|
|
270
|
+
x: currentInvariant.add(invErr.mul(2)),
|
|
271
|
+
y: currentInvariant,
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const tokenAmountsInScaled = amounts.map(a =>
|
|
275
|
+
this._upscale(a, scalingFactorTokenIn),
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
const tokenAmountsInWithFee = tokenAmountsInScaled.map(a =>
|
|
279
|
+
this._subtractSwapFeeAmount(a, poolPairData.swapFee),
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
const amountsOut: bigint[] = tokenAmountsInWithFee.map(amount => {
|
|
283
|
+
try {
|
|
284
|
+
const amountOut = GyroEMaths.calcOutGivenIn(
|
|
285
|
+
orderedNormalizedBalances,
|
|
286
|
+
BigNumber.from(amount),
|
|
287
|
+
poolPairData.tokenInIsToken0,
|
|
288
|
+
poolPairData.gyroParams,
|
|
289
|
+
poolPairData.gyroDerivedParams,
|
|
290
|
+
invariant,
|
|
291
|
+
).toBigInt();
|
|
292
|
+
|
|
293
|
+
return this._downscaleDown(amountOut, scalingFactorTokenOut);
|
|
294
|
+
} catch (error) {
|
|
295
|
+
return BigInt(0);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
return amountsOut;
|
|
300
|
+
} catch (error) {
|
|
301
|
+
return [];
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
onBuy(amounts: bigint[], poolPairData: GyroEPoolPairData): bigint[] {
|
|
306
|
+
try {
|
|
307
|
+
const scalingFactorTokenIn = this._scalingFactor(
|
|
308
|
+
poolPairData.tokenInIsToken0,
|
|
309
|
+
poolPairData,
|
|
310
|
+
);
|
|
311
|
+
const scalingFactorTokenOut = this._scalingFactor(
|
|
312
|
+
!poolPairData.tokenInIsToken0,
|
|
313
|
+
poolPairData,
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
const normalizedBalances = this._normalizeBalances(
|
|
317
|
+
poolPairData.balances,
|
|
318
|
+
poolPairData.tokenRates,
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
const orderedNormalizedBalances = balancesFromTokenInOut(
|
|
322
|
+
normalizedBalances[poolPairData.indexIn],
|
|
323
|
+
normalizedBalances[poolPairData.indexOut],
|
|
324
|
+
poolPairData.tokenInIsToken0,
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
const [currentInvariant, invErr] = GyroEMaths.calculateInvariantWithError(
|
|
328
|
+
orderedNormalizedBalances,
|
|
329
|
+
poolPairData.gyroParams,
|
|
330
|
+
poolPairData.gyroDerivedParams,
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
const invariant: Vector2 = {
|
|
334
|
+
x: currentInvariant.add(invErr.mul(2)),
|
|
335
|
+
y: currentInvariant,
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
const tokenAmountsOutScaled = amounts.map(a =>
|
|
339
|
+
this._upscale(a, scalingFactorTokenOut),
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
const amountsIn: bigint[] = tokenAmountsOutScaled.map(amount => {
|
|
343
|
+
try {
|
|
344
|
+
const amountIn = GyroEMaths.calcInGivenOut(
|
|
345
|
+
orderedNormalizedBalances,
|
|
346
|
+
BigNumber.from(amount),
|
|
347
|
+
poolPairData.tokenInIsToken0,
|
|
348
|
+
poolPairData.gyroParams,
|
|
349
|
+
poolPairData.gyroDerivedParams,
|
|
350
|
+
invariant,
|
|
351
|
+
).toBigInt();
|
|
352
|
+
return amountIn;
|
|
353
|
+
} catch (error) {
|
|
354
|
+
return BigInt(0);
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
const downScaled = amountsIn.map(amount =>
|
|
359
|
+
this._downscaleUp(amount, scalingFactorTokenIn),
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
return downScaled.map(a => this._addFeeAmount(a, poolPairData.swapFee));
|
|
363
|
+
} catch (error) {
|
|
364
|
+
return [];
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
private _scalingFactor(
|
|
369
|
+
token0: boolean,
|
|
370
|
+
poolPairData: GyroEPoolPairData,
|
|
371
|
+
): bigint {
|
|
372
|
+
const tokenIndex = token0 ? 0 : 1;
|
|
373
|
+
const scalingFactor = poolPairData.scalingFactors[tokenIndex];
|
|
374
|
+
if (
|
|
375
|
+
poolPairData.rateProviders.length === 0 ||
|
|
376
|
+
poolPairData.rateProviders[tokenIndex].toLowerCase() === NULL_ADDRESS
|
|
377
|
+
) {
|
|
378
|
+
return scalingFactor;
|
|
379
|
+
} else {
|
|
380
|
+
return MathSol.mulDownFixed(
|
|
381
|
+
scalingFactor,
|
|
382
|
+
poolPairData.tokenRates[tokenIndex],
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
private _normalizeBalances(
|
|
388
|
+
balances: BigNumber[],
|
|
389
|
+
tokenRates: bigint[],
|
|
390
|
+
): BigNumber[] {
|
|
391
|
+
// If pool is V1, e.g. has no tokenRates return balances
|
|
392
|
+
if (tokenRates.length === 0) return balances;
|
|
393
|
+
/*
|
|
394
|
+
Apply tokenRates
|
|
395
|
+
SOR upscales here first using scalingFactors but this is already being done in parse pair data so no need to repeat.
|
|
396
|
+
*/
|
|
397
|
+
return balances.map((bal, i) => {
|
|
398
|
+
return BigNumber.from(
|
|
399
|
+
MathSol.mulDownFixed(bal.toBigInt(), tokenRates[i]),
|
|
400
|
+
);
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function _reduceFee(amountIn: bigint, swapFee: bigint): bigint {
|
|
2
|
+
const product = amountIn * swapFee;
|
|
3
|
+
const feeAmount = (product - 1n) / 1000000000000000000n + 1n;
|
|
4
|
+
return amountIn - feeAmount;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function _addFee(amountIn: bigint, swapFee: bigint): bigint {
|
|
8
|
+
const fee = 1000000000000000000n - swapFee;
|
|
9
|
+
return divUp(amountIn, fee);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function divUp(a: bigint, b: bigint): bigint {
|
|
13
|
+
const aInflated = a * 1000000000000000000n;
|
|
14
|
+
return (aInflated - 1n) / b + 1n;
|
|
15
|
+
}
|