@paraswap/dex-lib 2.28.9-take-surplus.0 → 2.28.9-take-surplus.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/build/abi/RamsesV2StateMulticall.abi.json +891 -0
- package/build/abi/aerodrome/aerodrome-pool-factory.json +586 -0
- package/build/abi/algebra/AlgebraFactory-v1_1.abi.json +250 -0
- package/build/abi/api3-proxy.json +53 -0
- package/build/abi/api3-server-v1.json +463 -0
- package/build/abi/nomiswap-v2/nomiswap-v2-pool.json +773 -0
- package/build/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json +300 -0
- package/build/abi/quick-perps/fast-price-events.json +70 -0
- package/build/abi/quick-perps/fast-price-feed.json +741 -0
- package/build/abi/quick-perps/reader.json +313 -0
- package/build/abi/quick-perps/vault-price-feed.json +323 -0
- package/build/abi/quick-perps/vault.json +1953 -0
- package/build/abi/quickPerps/fast-price-events.json +70 -0
- package/build/abi/quickPerps/fast-price-feed.json +748 -0
- package/build/abi/quickPerps/reader.json +313 -0
- package/build/abi/quickPerps/vault-price-feed.json +477 -0
- package/build/abi/quickPerps/vault.json +1953 -0
- package/build/abi/ramses-v2/RamsesV2Pool.abi.json +1599 -0
- package/build/abi/uniswap-v3/UniswapV3Factory.abi.json +148 -0
- package/build/abi/uniswap-v3/UniswapV3QuoterV2.abi.json +155 -0
- package/build/composed-event-subscriber.js +8 -2
- package/build/composed-event-subscriber.js.map +1 -1
- package/build/config.d.ts +0 -1
- package/build/config.js +75 -14
- package/build/config.js.map +1 -1
- package/build/constants.d.ts +2 -1
- package/build/constants.js +1 -0
- package/build/constants.js.map +1 -1
- package/build/dex/algebra/algebra-factory.d.ts +25 -0
- package/build/dex/algebra/algebra-factory.js +43 -0
- package/build/dex/algebra/algebra-factory.js.map +1 -0
- package/build/dex/algebra/algebra-pool-v1_1.d.ts +16 -2
- package/build/dex/algebra/algebra-pool-v1_1.js +166 -4
- package/build/dex/algebra/algebra-pool-v1_1.js.map +1 -1
- package/build/dex/algebra/algebra.d.ts +4 -1
- package/build/dex/algebra/algebra.js +42 -21
- package/build/dex/algebra/algebra.js.map +1 -1
- package/build/dex/algebra/config.js +1 -0
- package/build/dex/algebra/config.js.map +1 -1
- package/build/dex/algebra/lib/TickTable.js +51 -40
- package/build/dex/algebra/lib/TickTable.js.map +1 -1
- package/build/dex/algebra/types.d.ts +5 -2
- package/build/dex/algebra/utils.d.ts +3 -1
- package/build/dex/algebra/utils.js +59 -1
- package/build/dex/algebra/utils.js.map +1 -1
- package/build/dex/balancer-v2/balancer-v2.js +79 -6
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/balancer-v2/config.js +10 -2
- package/build/dex/balancer-v2/config.js.map +1 -1
- package/build/dex/balancer-v2/optimizer.js +38 -51
- package/build/dex/balancer-v2/optimizer.js.map +1 -1
- package/build/dex/balancer-v2/types.d.ts +0 -4
- package/build/dex/balancer-v2/types.js.map +1 -1
- package/build/dex/curve-v1/config.js +40 -38
- package/build/dex/curve-v1/config.js.map +1 -1
- package/build/dex/curve-v1-factory/config.js +17 -9
- package/build/dex/curve-v1-factory/config.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +1 -1
- package/build/dex/curve-v1-factory/curve-v1-factory.js +205 -182
- package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-pool-manager.d.ts +2 -1
- package/build/dex/curve-v1-factory/curve-v1-pool-manager.js +8 -2
- 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 +1 -0
- 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 +2 -1
- 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 +61 -14
- 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 +1 -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 +1 -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 +1 -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/state-polling-pools/custom-pool-polling.js +11 -4
- package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.d.ts +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js +2 -2
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js.map +1 -1
- package/build/dex/curve-v1-factory/types.d.ts +4 -1
- package/build/dex/curve-v1-factory/types.js +1 -0
- package/build/dex/curve-v1-factory/types.js.map +1 -1
- package/build/dex/generic-rfq/generic-rfq.d.ts +2 -1
- package/build/dex/generic-rfq/generic-rfq.js +9 -5
- 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/hashflow/hashflow.d.ts +1 -0
- package/build/dex/hashflow/hashflow.js +1 -0
- package/build/dex/hashflow/hashflow.js.map +1 -1
- package/build/dex/idex.d.ts +1 -0
- package/build/dex/index.d.ts +1 -0
- package/build/dex/index.js +21 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/maverick-v1/config.js +9 -0
- package/build/dex/maverick-v1/config.js.map +1 -1
- package/build/dex/maverick-v1/maverick-v1.js +11 -2
- package/build/dex/maverick-v1/maverick-v1.js.map +1 -1
- package/build/dex/maverick-v1/scripts/event-sequence.d.ts +1 -0
- package/build/dex/maverick-v1/scripts/event-sequence.js +110 -0
- package/build/dex/maverick-v1/scripts/event-sequence.js.map +1 -0
- package/build/dex/pancakeswap-v3/config.js +17 -0
- package/build/dex/pancakeswap-v3/config.js.map +1 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.d.ts +26 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js +44 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js.map +1 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +3 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js +26 -2
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
- package/build/dex/quick-perps/config.d.ts +11 -0
- package/build/dex/quick-perps/config.js +27 -0
- package/build/dex/quick-perps/config.js.map +1 -0
- package/build/dex/quick-perps/fast-price-feed.d.ts +26 -0
- package/build/dex/quick-perps/fast-price-feed.js +176 -0
- package/build/dex/quick-perps/fast-price-feed.js.map +1 -0
- package/build/dex/quick-perps/pool.d.ts +21 -0
- package/build/dex/quick-perps/pool.js +225 -0
- package/build/dex/quick-perps/pool.js.map +1 -0
- package/build/dex/quick-perps/quick-perps.d.ts +52 -0
- package/build/dex/quick-perps/quick-perps.js +211 -0
- package/build/dex/quick-perps/quick-perps.js.map +1 -0
- package/build/dex/quick-perps/types.d.ts +98 -0
- package/build/dex/quick-perps/types.js +3 -0
- package/build/dex/quick-perps/types.js.map +1 -0
- package/build/dex/quick-perps/usdq.d.ts +15 -0
- package/build/dex/quick-perps/usdq.js +61 -0
- package/build/dex/quick-perps/usdq.js.map +1 -0
- package/build/dex/quick-perps/vault-price-feed.d.ts +43 -0
- package/build/dex/quick-perps/vault-price-feed.js +194 -0
- package/build/dex/quick-perps/vault-price-feed.js.map +1 -0
- package/build/dex/quick-perps/vault-utils.d.ts +8 -0
- package/build/dex/quick-perps/vault-utils.js +41 -0
- package/build/dex/quick-perps/vault-utils.js.map +1 -0
- package/build/dex/quick-perps/vault.d.ts +46 -0
- package/build/dex/quick-perps/vault.js +166 -0
- package/build/dex/quick-perps/vault.js.map +1 -0
- package/build/dex/solidly/config.js +52 -2
- package/build/dex/solidly/config.js.map +1 -1
- package/build/dex/solidly/forks-override/aerodrome.d.ts +14 -0
- package/build/dex/solidly/forks-override/aerodrome.js +48 -0
- package/build/dex/solidly/forks-override/aerodrome.js.map +1 -0
- package/build/dex/solidly/forks-override/equalizer.d.ts +20 -0
- package/build/dex/solidly/forks-override/equalizer.js +46 -0
- package/build/dex/solidly/forks-override/equalizer.js.map +1 -0
- package/build/dex/solidly/forks-override/ramses.d.ts +44 -0
- package/build/dex/solidly/forks-override/ramses.js +144 -0
- package/build/dex/solidly/forks-override/ramses.js.map +1 -0
- package/build/dex/solidly/forks-override/velodromeV2.d.ts +20 -0
- package/build/dex/solidly/forks-override/velodromeV2.js +50 -0
- package/build/dex/solidly/forks-override/velodromeV2.js.map +1 -0
- package/build/dex/solidly/solidly.js +4 -0
- package/build/dex/solidly/solidly.js.map +1 -1
- package/build/dex/uniswap-v2/nomiswap-v2.d.ts +24 -0
- package/build/dex/uniswap-v2/nomiswap-v2.js +44 -0
- package/build/dex/uniswap-v2/nomiswap-v2.js.map +1 -0
- package/build/dex/uniswap-v3/config.js +166 -0
- package/build/dex/uniswap-v3/config.js.map +1 -1
- package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.d.ts +19 -0
- package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.js +99 -0
- package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.js.map +1 -0
- package/build/dex/uniswap-v3/forks/ramses-v2/utils.d.ts +4 -0
- package/build/dex/uniswap-v3/forks/ramses-v2/utils.js +63 -0
- package/build/dex/uniswap-v3/forks/ramses-v2/utils.js.map +1 -0
- package/build/dex/uniswap-v3/types.d.ts +10 -1
- package/build/dex/uniswap-v3/types.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3-factory.d.ts +26 -0
- package/build/dex/uniswap-v3/uniswap-v3-factory.js +44 -0
- package/build/dex/uniswap-v3/uniswap-v3-factory.js.map +1 -0
- package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +8 -6
- package/build/dex/uniswap-v3/uniswap-v3-pool.js +5 -2
- package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3.d.ts +7 -4
- package/build/dex/uniswap-v3/uniswap-v3.js +51 -10
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/build/dex/weth/config.js +3 -0
- package/build/dex/weth/config.js.map +1 -1
- package/build/dex/woo-fi-v2/config.js +13 -0
- package/build/dex/woo-fi-v2/config.js.map +1 -1
- package/build/dex-helper/dummy-dex-helper.js +7 -1
- package/build/dex-helper/dummy-dex-helper.js.map +1 -1
- package/build/dex-helper/icache.d.ts +1 -0
- package/build/lib/api3-feed.d.ts +30 -0
- package/build/lib/api3-feed.js +100 -0
- package/build/lib/api3-feed.js.map +1 -0
- package/build/lib/decoders.d.ts +3 -0
- package/build/lib/decoders.js +9 -1
- package/build/lib/decoders.js.map +1 -1
- package/build/stateful-event-subscriber.d.ts +1 -0
- package/build/stateful-event-subscriber.js +6 -0
- package/build/stateful-event-subscriber.js.map +1 -1
- package/build/types.d.ts +2 -0
- package/build/workers.d.ts +0 -0
- package/build/workers.js +2 -0
- package/build/workers.js.map +1 -0
- package/package.json +1 -1
- package/src/abi/RamsesV2Pool.abi.json +1554 -0
- package/src/abi/RamsesV2Quoter.abi.json +274 -0
- package/src/abi/RamsesV2StateMulticall.abi.json +891 -0
- package/src/abi/aerodrome/aerodrome-pool-factory.json +586 -0
- package/src/abi/algebra/AlgebraFactory-v1_1.abi.json +250 -0
- package/src/abi/api3-proxy.json +53 -0
- package/src/abi/api3-server-v1.json +463 -0
- package/src/abi/nomiswap-v2/nomiswap-v2-pool.json +773 -0
- package/src/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json +300 -0
- package/src/abi/quick-perps/fast-price-events.json +70 -0
- package/src/abi/quick-perps/fast-price-feed.json +741 -0
- package/src/abi/quick-perps/reader.json +313 -0
- package/src/abi/quick-perps/vault-price-feed.json +323 -0
- package/src/abi/quick-perps/vault.json +1953 -0
- package/src/abi/ramses-v2/RamsesV2Pool.abi.json +1599 -0
- package/src/composed-event-subscriber.ts +16 -11
- package/src/config.ts +80 -14
- package/src/constants.ts +1 -0
- package/src/dex/algebra/algebra-factory.ts +70 -0
- package/src/dex/algebra/algebra-integration.test.ts +316 -16
- package/src/dex/algebra/algebra-pool-v1_1.ts +259 -8
- package/src/dex/algebra/algebra.ts +73 -22
- package/src/dex/algebra/config.ts +1 -0
- package/src/dex/algebra/lib/TickTable.ts +75 -74
- package/src/dex/algebra/types.ts +6 -2
- package/src/dex/algebra/utils.ts +83 -2
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +133 -4
- package/src/dex/balancer-v2/balancer-v2.ts +87 -6
- package/src/dex/balancer-v2/config.ts +11 -2
- package/src/dex/balancer-v2/optimizer.ts +49 -62
- package/src/dex/balancer-v2/types.ts +0 -4
- package/src/dex/curve-v1/config.ts +40 -38
- package/src/dex/curve-v1-factory/config.ts +17 -9
- package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +19 -0
- package/src/dex/curve-v1-factory/curve-v1-factory-integration.test.ts +165 -45
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +477 -415
- package/src/dex/curve-v1-factory/curve-v1-pool-manager.ts +15 -2
- package/src/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.ts +1 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.ts +1 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/_rates.ts +2 -1
- package/src/dex/curve-v1-factory/price-handlers/functions/_xp.ts +1 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/_xp_mem.ts +1 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.ts +71 -13
- package/src/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.ts +1 -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 +2 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_D_mem.ts +1 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.ts +1 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_dy.ts +1 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.ts +1 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_y.ts +1 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_y_D.ts +1 -0
- package/src/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.ts +13 -5
- package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +2 -1
- package/src/dex/curve-v1-factory/types.ts +3 -1
- package/src/dex/generic-rfq/example-api.test.ts +1 -1
- package/src/dex/generic-rfq/generic-rfq.ts +12 -4
- package/src/dex/generic-rfq/rate-fetcher.ts +4 -2
- package/src/dex/generic-rfq/types.ts +1 -0
- package/src/dex/hashflow/hashflow-e2e.test.ts +36 -3
- package/src/dex/hashflow/hashflow.ts +2 -1
- package/src/dex/idex.ts +1 -0
- package/src/dex/index.ts +21 -0
- package/src/dex/maverick-v1/config.ts +10 -0
- package/src/dex/maverick-v1/maverick-v1-e2e.test.ts +115 -1
- package/src/dex/maverick-v1/maverick-v1.ts +12 -2
- package/src/dex/pancakeswap-v3/config.ts +19 -0
- package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +114 -0
- package/src/dex/pancakeswap-v3/pancakeswap-v3-factory.ts +73 -0
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +50 -2
- package/src/dex/quick-perps/config.ts +31 -0
- package/src/dex/quick-perps/fast-price-feed.ts +279 -0
- package/src/dex/quick-perps/pool.ts +407 -0
- package/src/dex/quick-perps/quick-perps-e2e.test.ts +65 -0
- package/src/dex/quick-perps/quick-perps-events.test.ts +100 -0
- package/src/dex/quick-perps/quick-perps-integration.test.ts +153 -0
- package/src/dex/quick-perps/quick-perps.ts +302 -0
- package/src/dex/quick-perps/types.ts +97 -0
- package/src/dex/quick-perps/usdq.ts +83 -0
- package/src/dex/quick-perps/vault-price-feed.ts +322 -0
- package/src/dex/quick-perps/vault-utils.ts +53 -0
- package/src/dex/quick-perps/vault.ts +290 -0
- package/src/dex/solidly/config.ts +58 -2
- package/src/dex/solidly/forks-override/aerodrome.ts +53 -0
- package/src/dex/solidly/forks-override/equalizer.ts +58 -0
- package/src/dex/solidly/forks-override/ramses.ts +253 -0
- package/src/dex/solidly/forks-override/velodromeV2.ts +63 -0
- package/src/dex/solidly/solidly-e2e.test.ts +313 -1
- package/src/dex/solidly/solidly-integration.test.ts +540 -41
- package/src/dex/solidly/solidly.ts +5 -0
- package/src/dex/uniswap-v2/nomiswap-v2.ts +63 -0
- package/src/dex/uniswap-v2/uniswap-v2-e2e-bsc.test.ts +120 -1
- package/src/dex/uniswap-v3/config.ts +174 -0
- package/src/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.ts +156 -0
- package/src/dex/uniswap-v3/forks/ramses-v2/utils.ts +72 -0
- package/src/dex/uniswap-v3/types.ts +14 -1
- package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +1071 -346
- package/src/dex/uniswap-v3/uniswap-v3-factory.ts +73 -0
- package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +787 -14
- package/src/dex/uniswap-v3/uniswap-v3-pool.ts +13 -5
- package/src/dex/uniswap-v3/uniswap-v3.ts +87 -20
- package/src/dex/weth/config.ts +3 -0
- package/src/dex/woo-fi-v2/config.ts +13 -0
- package/src/dex/woo-fi-v2/woo-fi-v2-e2e.test.ts +64 -0
- package/src/dex-helper/dummy-dex-helper.ts +8 -1
- package/src/dex-helper/icache.ts +2 -0
- package/src/lib/api3-feed.ts +175 -0
- package/src/lib/decoders.ts +13 -0
- package/src/stateful-event-subscriber.ts +8 -0
- package/src/types.ts +2 -0
- package/tests/constants-e2e.ts +102 -6
- package/tests/tenderly-simulation.ts +48 -4
- package/tests/utils-e2e.ts +21 -11
|
@@ -127,7 +127,7 @@ export class CurveV1Factory
|
|
|
127
127
|
private coinsTypeTemplate: AbiItem = DefaultCoinsABI,
|
|
128
128
|
) {
|
|
129
129
|
super(dexHelper, dexKey);
|
|
130
|
-
this.logger = dexHelper.getLogger(dexKey);
|
|
130
|
+
this.logger = dexHelper.getLogger(`${this.dexKey}-${this.network}`);
|
|
131
131
|
this.ifaces = {
|
|
132
132
|
exchangeRouter: new Interface(CurveABI),
|
|
133
133
|
factory: new Interface(FactoryCurveV1ABI as JsonFragment[]),
|
|
@@ -181,10 +181,13 @@ export class CurveV1Factory
|
|
|
181
181
|
// This is only to start timer, each pool is initialized with updated state
|
|
182
182
|
this.poolManager.initializePollingPools();
|
|
183
183
|
await this.fetchFactoryPools(blockNumber);
|
|
184
|
+
await this.poolManager.fetchLiquiditiesFromApi();
|
|
185
|
+
await this.poolManager.updatePollingPoolsInBatch();
|
|
184
186
|
this.logger.info(`${this.dexKey}: successfully initialized`);
|
|
185
187
|
}
|
|
186
188
|
|
|
187
189
|
async initializeCustomPollingPools(
|
|
190
|
+
factoryAddresses: string[],
|
|
188
191
|
blockNumber?: number,
|
|
189
192
|
// We don't want to initialize state for PoolTracker. It doesn't make any sense
|
|
190
193
|
initializeInitialState: boolean = true,
|
|
@@ -193,131 +196,144 @@ export class CurveV1Factory
|
|
|
193
196
|
return;
|
|
194
197
|
}
|
|
195
198
|
|
|
196
|
-
const { factoryAddress } = this.config;
|
|
197
|
-
if (!factoryAddress) {
|
|
198
|
-
this.logger.warn(
|
|
199
|
-
`${this.dexKey}: No factory address specified for ${this.network}`,
|
|
200
|
-
);
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
199
|
await Promise.all(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
200
|
+
factoryAddresses.map(async factoryAddress => {
|
|
201
|
+
try {
|
|
202
|
+
await Promise.all(
|
|
203
|
+
Object.values(this.config.customPools).map(async customPool => {
|
|
204
|
+
const poolIdentifier = this.getPoolIdentifier(
|
|
205
|
+
customPool.address,
|
|
206
|
+
false,
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
const poolContextConstants =
|
|
210
|
+
ImplementationConstants[customPool.name];
|
|
211
|
+
const {
|
|
212
|
+
N_COINS: nCoins,
|
|
213
|
+
USE_LENDING: useLending,
|
|
214
|
+
isLending,
|
|
215
|
+
} = poolContextConstants;
|
|
216
|
+
|
|
217
|
+
const coinsAndImplementations =
|
|
218
|
+
await this.dexHelper.multiWrapper.aggregate(
|
|
219
|
+
_.range(0, nCoins)
|
|
220
|
+
.map(i => ({
|
|
221
|
+
target: customPool.address,
|
|
222
|
+
callData: this.abiCoder.encodeFunctionCall(
|
|
223
|
+
this._getCoinsABI(customPool.coinsInputType),
|
|
224
|
+
[i.toString()],
|
|
225
|
+
),
|
|
226
|
+
decodeFunction: addressDecode,
|
|
227
|
+
}))
|
|
228
|
+
.concat([
|
|
229
|
+
{
|
|
230
|
+
target: factoryAddress,
|
|
231
|
+
callData: this.ifaces.factory.encodeFunctionData(
|
|
232
|
+
'get_implementation_address',
|
|
233
|
+
[customPool.address],
|
|
234
|
+
),
|
|
235
|
+
decodeFunction: addressDecode,
|
|
236
|
+
},
|
|
237
|
+
]),
|
|
238
|
+
);
|
|
239
|
+
const COINS = coinsAndImplementations.slice(0, -1);
|
|
240
|
+
const implementationAddress =
|
|
241
|
+
coinsAndImplementations.slice(-1)[0];
|
|
242
|
+
|
|
243
|
+
const coins_decimals = (
|
|
244
|
+
await this.dexHelper.multiWrapper.tryAggregate(
|
|
245
|
+
true,
|
|
246
|
+
COINS.map(c => ({
|
|
247
|
+
target: c,
|
|
248
|
+
callData: this.ifaces.erc20.encodeFunctionData(
|
|
249
|
+
'decimals',
|
|
250
|
+
[],
|
|
251
|
+
),
|
|
252
|
+
decodeFunction: uint8ToNumber,
|
|
253
|
+
})),
|
|
254
|
+
)
|
|
255
|
+
).map(r => r.returnData);
|
|
256
|
+
|
|
257
|
+
const poolConstants: PoolConstants = {
|
|
258
|
+
COINS,
|
|
259
|
+
coins_decimals,
|
|
260
|
+
rate_multipliers: this._calcRateMultipliers(coins_decimals),
|
|
261
|
+
lpTokenAddress: customPool.lpTokenAddress,
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
let newPool: PoolPollingBase;
|
|
265
|
+
if (
|
|
266
|
+
Object.values<ImplementationNames>(
|
|
267
|
+
CustomImplementationNames,
|
|
268
|
+
).includes(customPool.name)
|
|
269
|
+
) {
|
|
270
|
+
// We don't want custom pools to be used for pricing, unless explicitly specified
|
|
271
|
+
newPool = new CustomBasePoolForFactory(
|
|
272
|
+
this.logger,
|
|
273
|
+
this.dexKey,
|
|
274
|
+
this.dexHelper.config.data.network,
|
|
275
|
+
this.cacheStateKey,
|
|
276
|
+
customPool.name,
|
|
277
|
+
implementationAddress,
|
|
278
|
+
customPool.address,
|
|
279
|
+
this.config.stateUpdatePeriodMs,
|
|
280
|
+
poolIdentifier,
|
|
281
|
+
poolConstants,
|
|
282
|
+
poolContextConstants,
|
|
283
|
+
customPool.liquidityApiSlug,
|
|
284
|
+
customPool.lpTokenAddress,
|
|
285
|
+
isLending,
|
|
286
|
+
customPool.balancesInputType,
|
|
287
|
+
useLending,
|
|
288
|
+
customPool.useForPricing,
|
|
289
|
+
);
|
|
290
|
+
} else {
|
|
291
|
+
// Use for pricing pools from factory
|
|
292
|
+
newPool = new CustomBasePoolForFactory(
|
|
293
|
+
this.logger,
|
|
294
|
+
this.dexKey,
|
|
295
|
+
this.dexHelper.config.data.network,
|
|
296
|
+
this.cacheStateKey,
|
|
297
|
+
customPool.name,
|
|
298
|
+
implementationAddress,
|
|
299
|
+
customPool.address,
|
|
300
|
+
this.config.stateUpdatePeriodMs,
|
|
301
|
+
poolIdentifier,
|
|
302
|
+
poolConstants,
|
|
303
|
+
poolContextConstants,
|
|
304
|
+
customPool.liquidityApiSlug,
|
|
305
|
+
customPool.lpTokenAddress,
|
|
306
|
+
isLending,
|
|
307
|
+
customPool.balancesInputType,
|
|
308
|
+
useLending,
|
|
309
|
+
true,
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
this.poolManager.initializeNewPoolForState(
|
|
314
|
+
poolIdentifier,
|
|
315
|
+
newPool,
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
if (initializeInitialState) {
|
|
319
|
+
await this.poolManager.initializeIndividualPollingPoolState(
|
|
320
|
+
poolIdentifier,
|
|
321
|
+
CustomBasePoolForFactory.IS_SRC_FEE_ON_TRANSFER_SUPPORTED,
|
|
322
|
+
blockNumber,
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
}),
|
|
239
326
|
);
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
await this.dexHelper.multiWrapper.tryAggregate(
|
|
245
|
-
true,
|
|
246
|
-
COINS.map(c => ({
|
|
247
|
-
target: c,
|
|
248
|
-
callData: this.ifaces.erc20.encodeFunctionData('decimals', []),
|
|
249
|
-
decodeFunction: uint8ToNumber,
|
|
250
|
-
})),
|
|
251
|
-
)
|
|
252
|
-
).map(r => r.returnData);
|
|
253
|
-
|
|
254
|
-
const poolConstants: PoolConstants = {
|
|
255
|
-
COINS,
|
|
256
|
-
coins_decimals,
|
|
257
|
-
rate_multipliers: this._calcRateMultipliers(coins_decimals),
|
|
258
|
-
lpTokenAddress: customPool.lpTokenAddress,
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
let newPool: PoolPollingBase;
|
|
262
|
-
if (
|
|
263
|
-
Object.values<ImplementationNames>(
|
|
264
|
-
CustomImplementationNames,
|
|
265
|
-
).includes(customPool.name)
|
|
266
|
-
) {
|
|
267
|
-
// We don't want custom pools to be used for pricing, unless explicitly specified
|
|
268
|
-
newPool = new CustomBasePoolForFactory(
|
|
269
|
-
this.logger,
|
|
270
|
-
this.dexKey,
|
|
271
|
-
this.dexHelper.config.data.network,
|
|
272
|
-
this.cacheStateKey,
|
|
273
|
-
customPool.name,
|
|
274
|
-
implementationAddress,
|
|
275
|
-
customPool.address,
|
|
276
|
-
this.config.stateUpdatePeriodMs,
|
|
277
|
-
poolIdentifier,
|
|
278
|
-
poolConstants,
|
|
279
|
-
poolContextConstants,
|
|
280
|
-
customPool.liquidityApiSlug,
|
|
281
|
-
customPool.lpTokenAddress,
|
|
282
|
-
isLending,
|
|
283
|
-
customPool.balancesInputType,
|
|
284
|
-
useLending,
|
|
285
|
-
customPool.useForPricing,
|
|
286
|
-
);
|
|
287
|
-
} else {
|
|
288
|
-
// Use for pricing pools from factory
|
|
289
|
-
newPool = new CustomBasePoolForFactory(
|
|
290
|
-
this.logger,
|
|
291
|
-
this.dexKey,
|
|
292
|
-
this.dexHelper.config.data.network,
|
|
293
|
-
this.cacheStateKey,
|
|
294
|
-
customPool.name,
|
|
295
|
-
implementationAddress,
|
|
296
|
-
customPool.address,
|
|
297
|
-
this.config.stateUpdatePeriodMs,
|
|
298
|
-
poolIdentifier,
|
|
299
|
-
poolConstants,
|
|
300
|
-
poolContextConstants,
|
|
301
|
-
customPool.liquidityApiSlug,
|
|
302
|
-
customPool.lpTokenAddress,
|
|
303
|
-
isLending,
|
|
304
|
-
customPool.balancesInputType,
|
|
305
|
-
useLending,
|
|
306
|
-
true,
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
this.poolManager.initializeNewPoolForState(poolIdentifier, newPool);
|
|
311
|
-
|
|
312
|
-
if (initializeInitialState) {
|
|
313
|
-
await this.poolManager.initializeIndividualPollingPoolState(
|
|
314
|
-
poolIdentifier,
|
|
315
|
-
CustomBasePoolForFactory.IS_SRC_FEE_ON_TRANSFER_SUPPORTED,
|
|
316
|
-
blockNumber,
|
|
327
|
+
} catch (e) {
|
|
328
|
+
this.logger.error(
|
|
329
|
+
`Error initializing custom polling pools for factory ${factoryAddress}: `,
|
|
330
|
+
e,
|
|
317
331
|
);
|
|
332
|
+
throw e;
|
|
318
333
|
}
|
|
319
334
|
}),
|
|
320
335
|
);
|
|
336
|
+
|
|
321
337
|
this.areCustomPoolsFetched = true;
|
|
322
338
|
}
|
|
323
339
|
|
|
@@ -326,283 +342,317 @@ export class CurveV1Factory
|
|
|
326
342
|
// Variable initializeInitialState is only for poolTracker. We don't want to keep state updated with scheduler
|
|
327
343
|
// We just want to initialize factory pools and send request to CurveAPI
|
|
328
344
|
// Other values are not used
|
|
329
|
-
initializeInitialState: boolean =
|
|
345
|
+
initializeInitialState: boolean = false,
|
|
330
346
|
) {
|
|
331
347
|
if (this.areFactoryPoolsFetched) {
|
|
332
348
|
return;
|
|
333
349
|
}
|
|
334
350
|
|
|
351
|
+
if (
|
|
352
|
+
!this.config.factoryAddresses ||
|
|
353
|
+
this.config.factoryAddresses.length == 0
|
|
354
|
+
) {
|
|
355
|
+
this.logger.warn(`No factory address specified in configs`);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
|
|
335
359
|
// There is no scenario when we need to call initialize custom pools without factory pools
|
|
336
360
|
// So I put it here to not forget call, because custom pools must be initialised before factory pools
|
|
337
361
|
// This function may be called multiple times, but will execute only once
|
|
338
362
|
await this.initializeCustomPollingPools(
|
|
363
|
+
this.config.factoryAddresses,
|
|
339
364
|
blockNumber,
|
|
340
365
|
initializeInitialState,
|
|
341
366
|
);
|
|
342
367
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
);
|
|
367
|
-
|
|
368
|
-
const poolCount = poolCountResult[0].returnData;
|
|
369
|
-
const basePoolCount = poolCountResult[1].returnData;
|
|
370
|
-
|
|
371
|
-
const calldataGetPoolAddresses = _.range(0, poolCount).map(i => ({
|
|
372
|
-
target: factoryAddress,
|
|
373
|
-
callData: this.ifaces.factory.encodeFunctionData('pool_list', [i]),
|
|
374
|
-
decodeFunction: addressDecode,
|
|
375
|
-
}));
|
|
376
|
-
|
|
377
|
-
const calldataGetBasePoolAddresses = _.range(0, basePoolCount).map(i => ({
|
|
378
|
-
target: factoryAddress,
|
|
379
|
-
callData: this.ifaces.factory.encodeFunctionData('base_pool_list', [i]),
|
|
380
|
-
decodeFunction: addressDecode,
|
|
381
|
-
}));
|
|
382
|
-
|
|
383
|
-
const allPoolAddresses = (
|
|
384
|
-
await this.dexHelper.multiWrapper.tryAggregate(
|
|
385
|
-
true,
|
|
386
|
-
calldataGetPoolAddresses.concat(calldataGetBasePoolAddresses),
|
|
387
|
-
)
|
|
388
|
-
).map(e => e.returnData);
|
|
389
|
-
|
|
390
|
-
const poolAddresses = allPoolAddresses.slice(0, poolCount);
|
|
391
|
-
const basePoolAddresses = allPoolAddresses.slice(poolCount);
|
|
392
|
-
|
|
393
|
-
const customPoolAddresses = Object.values(this.config.customPools).map(
|
|
394
|
-
customPool => customPool.address,
|
|
395
|
-
);
|
|
396
|
-
basePoolAddresses.forEach(basePool => {
|
|
397
|
-
if (
|
|
398
|
-
!customPoolAddresses.includes(basePool) &&
|
|
399
|
-
!this.config.disabledPools.has(basePool)
|
|
400
|
-
) {
|
|
401
|
-
this._reportForUnspecifiedCustomPool(basePool);
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
let callDataFromFactoryPools: MultiCallParams<
|
|
406
|
-
string[] | number[] | string
|
|
407
|
-
>[] = poolAddresses
|
|
408
|
-
.map(p => [
|
|
409
|
-
{
|
|
410
|
-
target: factoryAddress,
|
|
411
|
-
callData: this.ifaces.factory.encodeFunctionData(
|
|
412
|
-
'get_implementation_address',
|
|
413
|
-
[p],
|
|
414
|
-
),
|
|
415
|
-
decodeFunction: addressDecode,
|
|
416
|
-
},
|
|
417
|
-
{
|
|
418
|
-
target: factoryAddress,
|
|
419
|
-
callData: this.ifaces.factory.encodeFunctionData('get_coins', [p]),
|
|
420
|
-
decodeFunction: (
|
|
421
|
-
result: MultiResult<BytesLike> | BytesLike,
|
|
422
|
-
): string[] =>
|
|
423
|
-
generalDecoder<string[]>(
|
|
424
|
-
result,
|
|
425
|
-
['address[4]'],
|
|
426
|
-
new Array(4).fill(NULL_ADDRESS),
|
|
427
|
-
parsed => parsed[0].map((p: string) => p.toLowerCase()),
|
|
428
|
-
),
|
|
429
|
-
},
|
|
430
|
-
{
|
|
431
|
-
target: factoryAddress,
|
|
432
|
-
callData: this.ifaces.factory.encodeFunctionData('get_decimals', [p]),
|
|
433
|
-
decodeFunction: (
|
|
434
|
-
result: MultiResult<BytesLike> | BytesLike,
|
|
435
|
-
): number[] =>
|
|
436
|
-
generalDecoder<number[]>(
|
|
437
|
-
result,
|
|
438
|
-
['uint256[4]'],
|
|
439
|
-
[0, 0, 0, 0],
|
|
440
|
-
parsed => parsed[0].map((p: BigNumber) => Number(p.toString())),
|
|
441
|
-
),
|
|
442
|
-
},
|
|
443
|
-
])
|
|
444
|
-
.flat();
|
|
445
|
-
|
|
446
|
-
// This is divider between pools related results and implementations
|
|
447
|
-
const factoryResultsDivider = callDataFromFactoryPools.length;
|
|
448
|
-
|
|
449
|
-
// Implementations must be requested from factory, but it accepts as arg basePool address
|
|
450
|
-
// for metaPools
|
|
451
|
-
callDataFromFactoryPools = callDataFromFactoryPools.concat(
|
|
452
|
-
...basePoolAddresses.map(basePoolAddress => ({
|
|
453
|
-
target: factoryAddress,
|
|
454
|
-
callData: this.ifaces.factory.encodeFunctionData(
|
|
455
|
-
'metapool_implementations',
|
|
456
|
-
[basePoolAddress],
|
|
457
|
-
),
|
|
458
|
-
decodeFunction: (
|
|
459
|
-
result: MultiResult<BytesLike> | BytesLike,
|
|
460
|
-
): string[] =>
|
|
461
|
-
generalDecoder<string[]>(
|
|
462
|
-
result,
|
|
463
|
-
['address[10]'],
|
|
464
|
-
new Array(10).fill(NULL_ADDRESS),
|
|
465
|
-
parsed => parsed[0].map((p: string) => p.toLowerCase()),
|
|
466
|
-
),
|
|
467
|
-
})),
|
|
468
|
-
// To receive plain pool implementation address, you have to call plain_implementations
|
|
469
|
-
// with two variables: N_COINS and implementations_index
|
|
470
|
-
// N_COINS is between 2-4. Currently more than 4 coins is not supported
|
|
471
|
-
// as for implementation index, there are only 0-9 indexes
|
|
472
|
-
..._.flattenDeep(
|
|
473
|
-
_.range(2, FACTORY_MAX_PLAIN_COINS + 1).map(coinNumber =>
|
|
474
|
-
_.range(FACTORY_MAX_PLAIN_IMPLEMENTATIONS_FOR_COIN).map(implInd => ({
|
|
368
|
+
await Promise.all(
|
|
369
|
+
this.config.factoryAddresses.map(async factoryAddress => {
|
|
370
|
+
try {
|
|
371
|
+
const poolCountResult =
|
|
372
|
+
await this.dexHelper.multiWrapper!.tryAggregate(true, [
|
|
373
|
+
{
|
|
374
|
+
target: factoryAddress,
|
|
375
|
+
callData: this.ifaces.factory.encodeFunctionData('pool_count'),
|
|
376
|
+
decodeFunction: uint256DecodeToNumber,
|
|
377
|
+
},
|
|
378
|
+
// This is used later to request all available implementations. In particular meta implementations
|
|
379
|
+
{
|
|
380
|
+
target: factoryAddress,
|
|
381
|
+
callData:
|
|
382
|
+
this.ifaces.factory.encodeFunctionData('base_pool_count'),
|
|
383
|
+
decodeFunction: uint256DecodeToNumber,
|
|
384
|
+
},
|
|
385
|
+
]);
|
|
386
|
+
|
|
387
|
+
const poolCount = poolCountResult[0].returnData;
|
|
388
|
+
const basePoolCount = poolCountResult[1].returnData;
|
|
389
|
+
|
|
390
|
+
const calldataGetPoolAddresses = _.range(0, poolCount).map(i => ({
|
|
475
391
|
target: factoryAddress,
|
|
476
|
-
callData: this.ifaces.factory.encodeFunctionData(
|
|
477
|
-
'plain_implementations',
|
|
478
|
-
[coinNumber, implInd],
|
|
479
|
-
),
|
|
392
|
+
callData: this.ifaces.factory.encodeFunctionData('pool_list', [i]),
|
|
480
393
|
decodeFunction: addressDecode,
|
|
481
|
-
}))
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
394
|
+
}));
|
|
395
|
+
|
|
396
|
+
const calldataGetBasePoolAddresses = _.range(0, basePoolCount).map(
|
|
397
|
+
i => ({
|
|
398
|
+
target: factoryAddress,
|
|
399
|
+
callData: this.ifaces.factory.encodeFunctionData(
|
|
400
|
+
'base_pool_list',
|
|
401
|
+
[i],
|
|
402
|
+
),
|
|
403
|
+
decodeFunction: addressDecode,
|
|
404
|
+
}),
|
|
405
|
+
);
|
|
485
406
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
407
|
+
const allPoolAddresses = (
|
|
408
|
+
await this.dexHelper.multiWrapper.tryAggregate(
|
|
409
|
+
true,
|
|
410
|
+
calldataGetPoolAddresses.concat(calldataGetBasePoolAddresses),
|
|
411
|
+
)
|
|
412
|
+
).map(e => e.returnData);
|
|
413
|
+
|
|
414
|
+
const poolAddresses = allPoolAddresses.slice(0, poolCount);
|
|
415
|
+
const basePoolAddresses = allPoolAddresses.slice(poolCount);
|
|
416
|
+
|
|
417
|
+
const customPoolAddresses = Object.values(
|
|
418
|
+
this.config.customPools,
|
|
419
|
+
).map(customPool => customPool.address);
|
|
420
|
+
basePoolAddresses.forEach(basePool => {
|
|
421
|
+
if (
|
|
422
|
+
!customPoolAddresses.includes(basePool) &&
|
|
423
|
+
!this.config.disabledPools.has(basePool)
|
|
424
|
+
) {
|
|
425
|
+
this._reportForUnspecifiedCustomPool(basePool);
|
|
426
|
+
}
|
|
427
|
+
});
|
|
491
428
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
429
|
+
let callDataFromFactoryPools: MultiCallParams<
|
|
430
|
+
string[] | number[] | string
|
|
431
|
+
>[] = poolAddresses
|
|
432
|
+
.map(p => [
|
|
433
|
+
{
|
|
434
|
+
target: factoryAddress,
|
|
435
|
+
callData: this.ifaces.factory.encodeFunctionData(
|
|
436
|
+
'get_implementation_address',
|
|
437
|
+
[p],
|
|
438
|
+
),
|
|
439
|
+
decodeFunction: addressDecode,
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
target: factoryAddress,
|
|
443
|
+
callData: this.ifaces.factory.encodeFunctionData('get_coins', [
|
|
444
|
+
p,
|
|
445
|
+
]),
|
|
446
|
+
decodeFunction: (
|
|
447
|
+
result: MultiResult<BytesLike> | BytesLike,
|
|
448
|
+
): string[] =>
|
|
449
|
+
generalDecoder<string[]>(
|
|
450
|
+
result,
|
|
451
|
+
['address[4]'],
|
|
452
|
+
new Array(4).fill(NULL_ADDRESS),
|
|
453
|
+
parsed => parsed[0].map((p: string) => p.toLowerCase()),
|
|
454
|
+
),
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
target: factoryAddress,
|
|
458
|
+
callData: this.ifaces.factory.encodeFunctionData(
|
|
459
|
+
'get_decimals',
|
|
460
|
+
[p],
|
|
461
|
+
),
|
|
462
|
+
decodeFunction: (
|
|
463
|
+
result: MultiResult<BytesLike> | BytesLike,
|
|
464
|
+
): number[] =>
|
|
465
|
+
generalDecoder<number[]>(
|
|
466
|
+
result,
|
|
467
|
+
['uint256[4]'],
|
|
468
|
+
[0, 0, 0, 0],
|
|
469
|
+
parsed =>
|
|
470
|
+
parsed[0].map((p: BigNumber) => Number(p.toString())),
|
|
471
|
+
),
|
|
472
|
+
},
|
|
473
|
+
])
|
|
474
|
+
.flat();
|
|
475
|
+
|
|
476
|
+
// This is divider between pools related results and implementations
|
|
477
|
+
const factoryResultsDivider = callDataFromFactoryPools.length;
|
|
478
|
+
|
|
479
|
+
// Implementations must be requested from factory, but it accepts as arg basePool address
|
|
480
|
+
// for metaPools
|
|
481
|
+
callDataFromFactoryPools = callDataFromFactoryPools.concat(
|
|
482
|
+
...basePoolAddresses.map(basePoolAddress => ({
|
|
483
|
+
target: factoryAddress,
|
|
484
|
+
callData: this.ifaces.factory.encodeFunctionData(
|
|
485
|
+
'metapool_implementations',
|
|
486
|
+
[basePoolAddress],
|
|
487
|
+
),
|
|
488
|
+
decodeFunction: (
|
|
489
|
+
result: MultiResult<BytesLike> | BytesLike,
|
|
490
|
+
): string[] =>
|
|
491
|
+
generalDecoder<string[]>(
|
|
492
|
+
result,
|
|
493
|
+
['address[10]'],
|
|
494
|
+
new Array(10).fill(NULL_ADDRESS),
|
|
495
|
+
parsed => parsed[0].map((p: string) => p.toLowerCase()),
|
|
496
|
+
),
|
|
497
|
+
})),
|
|
498
|
+
// To receive plain pool implementation address, you have to call plain_implementations
|
|
499
|
+
// with two variables: N_COINS and implementations_index
|
|
500
|
+
// N_COINS is between 2-4. Currently more than 4 coins is not supported
|
|
501
|
+
// as for implementation index, there are only 0-9 indexes
|
|
502
|
+
..._.flattenDeep(
|
|
503
|
+
_.range(2, FACTORY_MAX_PLAIN_COINS + 1).map(coinNumber =>
|
|
504
|
+
_.range(FACTORY_MAX_PLAIN_IMPLEMENTATIONS_FOR_COIN).map(
|
|
505
|
+
implInd => ({
|
|
506
|
+
target: factoryAddress,
|
|
507
|
+
callData: this.ifaces.factory.encodeFunctionData(
|
|
508
|
+
'plain_implementations',
|
|
509
|
+
[coinNumber, implInd],
|
|
510
|
+
),
|
|
511
|
+
decodeFunction: addressDecode,
|
|
512
|
+
}),
|
|
513
|
+
),
|
|
514
|
+
),
|
|
515
|
+
),
|
|
516
|
+
);
|
|
496
517
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
!this.config.disabledImplementations.has(implementation),
|
|
503
|
-
);
|
|
518
|
+
const allResultsFromFactory = (
|
|
519
|
+
await this.dexHelper.multiWrapper.tryAggregate<
|
|
520
|
+
string[] | number[] | string
|
|
521
|
+
>(true, callDataFromFactoryPools)
|
|
522
|
+
).map(r => r.returnData);
|
|
504
523
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
this._reportForUnspecifiedImplementation(implementation);
|
|
510
|
-
}
|
|
511
|
-
});
|
|
524
|
+
const resultsFromFactory = allResultsFromFactory.slice(
|
|
525
|
+
0,
|
|
526
|
+
factoryResultsDivider,
|
|
527
|
+
);
|
|
512
528
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
529
|
+
const allAvailableImplementations = _.flattenDeep(
|
|
530
|
+
allResultsFromFactory.slice(factoryResultsDivider) as string[],
|
|
531
|
+
).filter(
|
|
532
|
+
implementation =>
|
|
533
|
+
implementation !== NULL_ADDRESS &&
|
|
534
|
+
!this.config.disabledImplementations.has(implementation),
|
|
535
|
+
);
|
|
519
536
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
537
|
+
allAvailableImplementations.forEach(implementation => {
|
|
538
|
+
const currentImplementation =
|
|
539
|
+
this.config.factoryPoolImplementations[implementation];
|
|
540
|
+
if (currentImplementation === undefined) {
|
|
541
|
+
this._reportForUnspecifiedImplementation(implementation);
|
|
542
|
+
}
|
|
543
|
+
});
|
|
525
544
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
545
|
+
const stateInitializePromises: Promise<void>[] = [];
|
|
546
|
+
_.chunk(resultsFromFactory, 3).forEach((result, i) => {
|
|
547
|
+
if (this.config.disabledPools.has(poolAddresses[i])) {
|
|
548
|
+
this.logger.trace(`Filtering disabled pool ${poolAddresses[i]}`);
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
let [implementationAddress, coins, coins_decimals] = result as [
|
|
553
|
+
string,
|
|
554
|
+
string[],
|
|
555
|
+
number[],
|
|
556
|
+
];
|
|
557
|
+
|
|
558
|
+
implementationAddress = implementationAddress.toLowerCase();
|
|
559
|
+
coins = coins
|
|
560
|
+
.map(c => c.toLowerCase())
|
|
561
|
+
.filter(c => c !== NULL_ADDRESS);
|
|
562
|
+
coins_decimals = coins_decimals.filter(cd => cd !== 0);
|
|
563
|
+
|
|
564
|
+
const factoryImplementationFromConfig =
|
|
565
|
+
this.config.factoryPoolImplementations[implementationAddress];
|
|
566
|
+
|
|
567
|
+
if (
|
|
568
|
+
factoryImplementationFromConfig === undefined &&
|
|
569
|
+
!this.config.disabledImplementations.has(implementationAddress)
|
|
570
|
+
) {
|
|
571
|
+
this._reportForUnspecifiedImplementation(
|
|
572
|
+
implementationAddress,
|
|
573
|
+
poolAddresses[i],
|
|
574
|
+
);
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
const factoryImplementationConstants =
|
|
579
|
+
ImplementationConstants[factoryImplementationFromConfig.name];
|
|
580
|
+
|
|
581
|
+
let isMeta: boolean = false;
|
|
582
|
+
let basePoolStateFetcher: PoolPollingBase | undefined;
|
|
583
|
+
if (factoryImplementationFromConfig.basePoolAddress !== undefined) {
|
|
584
|
+
isMeta = true;
|
|
585
|
+
const basePoolIdentifier = this.getPoolIdentifier(
|
|
586
|
+
factoryImplementationFromConfig.basePoolAddress,
|
|
587
|
+
false,
|
|
588
|
+
);
|
|
589
|
+
const basePool = this.poolManager.getPool(
|
|
590
|
+
basePoolIdentifier,
|
|
591
|
+
false,
|
|
592
|
+
);
|
|
593
|
+
if (basePool === null) {
|
|
594
|
+
this.logger.error(
|
|
595
|
+
`${this.dexKey}_${this.dexHelper.config.data.network}: custom base pool ${basePoolIdentifier} was not initialized properly. ` +
|
|
596
|
+
`You must call initializeCustomPollingPools before fetching factory`,
|
|
597
|
+
);
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
basePoolStateFetcher = basePool;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
const poolConstants: PoolConstants = {
|
|
604
|
+
COINS: coins,
|
|
605
|
+
coins_decimals,
|
|
606
|
+
rate_multipliers: this._calcRateMultipliers(coins_decimals),
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
const poolIdentifier = this.getPoolIdentifier(
|
|
610
|
+
poolAddresses[i],
|
|
611
|
+
isMeta,
|
|
612
|
+
);
|
|
529
613
|
|
|
530
|
-
|
|
531
|
-
|
|
614
|
+
const newPool = new FactoryStateHandler(
|
|
615
|
+
this.logger,
|
|
616
|
+
this.dexKey,
|
|
617
|
+
this.dexHelper.config.data.network,
|
|
618
|
+
this.cacheStateKey,
|
|
619
|
+
factoryImplementationFromConfig.name,
|
|
620
|
+
implementationAddress.toLowerCase(),
|
|
621
|
+
poolAddresses[i],
|
|
622
|
+
this.config.stateUpdatePeriodMs,
|
|
623
|
+
factoryAddress,
|
|
624
|
+
poolIdentifier,
|
|
625
|
+
poolConstants,
|
|
626
|
+
factoryImplementationConstants,
|
|
627
|
+
factoryImplementationConstants.isFeeOnTransferSupported,
|
|
628
|
+
factoryImplementationFromConfig.liquidityApiSlug ?? '/factory',
|
|
629
|
+
basePoolStateFetcher,
|
|
630
|
+
factoryImplementationFromConfig.customGasCost,
|
|
631
|
+
factoryImplementationFromConfig.isStoreRateSupported,
|
|
632
|
+
);
|
|
532
633
|
|
|
533
|
-
|
|
534
|
-
factoryImplementationFromConfig === undefined &&
|
|
535
|
-
!this.config.disabledImplementations.has(implementationAddress)
|
|
536
|
-
) {
|
|
537
|
-
this._reportForUnspecifiedImplementation(
|
|
538
|
-
implementationAddress,
|
|
539
|
-
poolAddresses[i],
|
|
540
|
-
);
|
|
541
|
-
return;
|
|
542
|
-
}
|
|
634
|
+
this.poolManager.initializeNewPool(poolIdentifier, newPool);
|
|
543
635
|
|
|
544
|
-
|
|
545
|
-
|
|
636
|
+
if (initializeInitialState) {
|
|
637
|
+
stateInitializePromises.push(
|
|
638
|
+
this.poolManager.initializeIndividualPollingPoolState(
|
|
639
|
+
poolIdentifier,
|
|
640
|
+
factoryImplementationConstants.isFeeOnTransferSupported,
|
|
641
|
+
),
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
});
|
|
546
645
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
if (factoryImplementationFromConfig.basePoolAddress !== undefined) {
|
|
550
|
-
isMeta = true;
|
|
551
|
-
const basePoolIdentifier = this.getPoolIdentifier(
|
|
552
|
-
factoryImplementationFromConfig.basePoolAddress,
|
|
553
|
-
false,
|
|
554
|
-
);
|
|
555
|
-
const basePool = this.poolManager.getPool(basePoolIdentifier, false);
|
|
556
|
-
if (basePool === null) {
|
|
646
|
+
await Promise.all(stateInitializePromises);
|
|
647
|
+
} catch (e) {
|
|
557
648
|
this.logger.error(
|
|
558
|
-
|
|
559
|
-
|
|
649
|
+
`Error fetching factory pools for ${factoryAddress}: `,
|
|
650
|
+
e,
|
|
560
651
|
);
|
|
561
|
-
|
|
652
|
+
throw e;
|
|
562
653
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
const poolConstants: PoolConstants = {
|
|
567
|
-
COINS: coins,
|
|
568
|
-
coins_decimals,
|
|
569
|
-
rate_multipliers: this._calcRateMultipliers(coins_decimals),
|
|
570
|
-
};
|
|
571
|
-
|
|
572
|
-
const poolIdentifier = this.getPoolIdentifier(poolAddresses[i], isMeta);
|
|
573
|
-
|
|
574
|
-
const newPool = new FactoryStateHandler(
|
|
575
|
-
this.logger,
|
|
576
|
-
this.dexKey,
|
|
577
|
-
this.dexHelper.config.data.network,
|
|
578
|
-
this.cacheStateKey,
|
|
579
|
-
factoryImplementationFromConfig.name,
|
|
580
|
-
implementationAddress.toLowerCase(),
|
|
581
|
-
poolAddresses[i],
|
|
582
|
-
this.config.stateUpdatePeriodMs,
|
|
583
|
-
factoryAddress,
|
|
584
|
-
poolIdentifier,
|
|
585
|
-
poolConstants,
|
|
586
|
-
factoryImplementationConstants,
|
|
587
|
-
factoryImplementationConstants.isFeeOnTransferSupported,
|
|
588
|
-
basePoolStateFetcher,
|
|
589
|
-
factoryImplementationFromConfig.customGasCost,
|
|
590
|
-
factoryImplementationFromConfig.isStoreRateSupported,
|
|
591
|
-
);
|
|
592
|
-
|
|
593
|
-
this.poolManager.initializeNewPool(poolIdentifier, newPool);
|
|
594
|
-
|
|
595
|
-
if (initializeInitialState) {
|
|
596
|
-
stateInitializePromises.push(
|
|
597
|
-
this.poolManager.initializeIndividualPollingPoolState(
|
|
598
|
-
poolIdentifier,
|
|
599
|
-
factoryImplementationConstants.isFeeOnTransferSupported,
|
|
600
|
-
),
|
|
601
|
-
);
|
|
602
|
-
}
|
|
603
|
-
});
|
|
604
|
-
|
|
605
|
-
await Promise.all(stateInitializePromises);
|
|
654
|
+
}),
|
|
655
|
+
);
|
|
606
656
|
|
|
607
657
|
this.areFactoryPoolsFetched = true;
|
|
608
658
|
}
|
|
@@ -722,57 +772,69 @@ export class CurveV1Factory
|
|
|
722
772
|
)
|
|
723
773
|
: amountsWithUnit;
|
|
724
774
|
|
|
725
|
-
const results =
|
|
726
|
-
(
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
775
|
+
const results = await Promise.all(
|
|
776
|
+
pools.map(
|
|
777
|
+
async (pool): Promise<PoolPrices<CurveV1FactoryData> | null> => {
|
|
778
|
+
let state = pool.getState();
|
|
779
|
+
if (!state) {
|
|
780
|
+
await this.poolManager.updateManuallyPollingPools(
|
|
781
|
+
pool.baseStatePoolPolling
|
|
782
|
+
? [pool.baseStatePoolPolling, pool]
|
|
783
|
+
: [pool],
|
|
784
|
+
);
|
|
785
|
+
state = pool.getState();
|
|
786
|
+
if (!state) {
|
|
787
|
+
return null;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
if (state.balances.every(b => b === 0n)) {
|
|
792
|
+
this.logger.trace(
|
|
793
|
+
`${this.dexKey} on ${this.dexHelper.config.data.network}: State balances equal to 0 in pool ${pool.address}`,
|
|
794
|
+
);
|
|
795
|
+
return null;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
const poolData = pool.getPoolData(
|
|
799
|
+
srcTokenAddress,
|
|
800
|
+
destTokenAddress,
|
|
736
801
|
);
|
|
737
|
-
return null;
|
|
738
|
-
}
|
|
739
802
|
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
803
|
+
if (poolData === null) {
|
|
804
|
+
this.logger.error(
|
|
805
|
+
`${pool.fullName}: one or both tokens can not be exchanged in pool ${pool.address}: ${srcTokenAddress} -> ${destTokenAddress}`,
|
|
806
|
+
);
|
|
807
|
+
return null;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
let outputs: bigint[] = this.poolManager
|
|
811
|
+
.getPriceHandler(pool.implementationAddress)
|
|
812
|
+
.getOutputs(
|
|
813
|
+
state,
|
|
814
|
+
amountsWithUnitAndFee,
|
|
815
|
+
poolData.i,
|
|
816
|
+
poolData.j,
|
|
817
|
+
poolData.underlyingSwap,
|
|
818
|
+
);
|
|
819
|
+
|
|
820
|
+
outputs = applyTransferFee(
|
|
821
|
+
outputs,
|
|
822
|
+
side,
|
|
823
|
+
transferFees.destDexFee,
|
|
824
|
+
this.DEST_TOKEN_DEX_TRANSFERS,
|
|
757
825
|
);
|
|
758
826
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
exchange: this.dexKey,
|
|
771
|
-
poolIdentifier: pool.poolIdentifier,
|
|
772
|
-
gasCost: POOL_EXCHANGE_GAS_COST,
|
|
773
|
-
poolAddresses: [pool.address],
|
|
774
|
-
};
|
|
775
|
-
},
|
|
827
|
+
return {
|
|
828
|
+
prices: [0n, ...outputs.slice(1)],
|
|
829
|
+
unit: outputs[0],
|
|
830
|
+
data: poolData,
|
|
831
|
+
exchange: this.dexKey,
|
|
832
|
+
poolIdentifier: pool.poolIdentifier,
|
|
833
|
+
gasCost: POOL_EXCHANGE_GAS_COST,
|
|
834
|
+
poolAddresses: [pool.address],
|
|
835
|
+
};
|
|
836
|
+
},
|
|
837
|
+
),
|
|
776
838
|
);
|
|
777
839
|
|
|
778
840
|
return results.filter(
|