@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
|
@@ -12,6 +12,7 @@ import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
|
12
12
|
import {
|
|
13
13
|
PoolState,
|
|
14
14
|
DecodedStateMultiCallResultWithRelativeBitmaps,
|
|
15
|
+
DecodeStateMultiCallFunc,
|
|
15
16
|
} from './types';
|
|
16
17
|
import UniswapV3PoolABI from '../../abi/uniswap-v3/UniswapV3Pool.abi.json';
|
|
17
18
|
import { bigIntify, catchParseLogError, isSampled } from '../../utils';
|
|
@@ -45,7 +46,7 @@ export class UniswapV3EventPool extends StatefulEventSubscriber<PoolState> {
|
|
|
45
46
|
|
|
46
47
|
private _poolAddress?: Address;
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
protected _stateRequestCallData?: MultiCallParams<
|
|
49
50
|
bigint | DecodedStateMultiCallResultWithRelativeBitmaps
|
|
50
51
|
>[];
|
|
51
52
|
|
|
@@ -54,15 +55,18 @@ export class UniswapV3EventPool extends StatefulEventSubscriber<PoolState> {
|
|
|
54
55
|
public initFailed = false;
|
|
55
56
|
public initRetryAttemptCount = 0;
|
|
56
57
|
|
|
57
|
-
public
|
|
58
|
+
public feeCodeAsString;
|
|
58
59
|
|
|
59
60
|
constructor(
|
|
60
61
|
readonly dexHelper: IDexHelper,
|
|
61
62
|
parentName: string,
|
|
62
63
|
readonly stateMultiContract: Contract,
|
|
64
|
+
readonly decodeStateMultiCallResultWithRelativeBitmaps:
|
|
65
|
+
| DecodeStateMultiCallFunc
|
|
66
|
+
| undefined,
|
|
63
67
|
readonly erc20Interface: Interface,
|
|
64
68
|
protected readonly factoryAddress: Address,
|
|
65
|
-
public
|
|
69
|
+
public feeCode: bigint,
|
|
66
70
|
token0: Address,
|
|
67
71
|
token1: Address,
|
|
68
72
|
logger: Logger,
|
|
@@ -195,7 +199,7 @@ export class UniswapV3EventPool extends StatefulEventSubscriber<PoolState> {
|
|
|
195
199
|
return null; // ignore unrecognized event
|
|
196
200
|
}
|
|
197
201
|
|
|
198
|
-
|
|
202
|
+
protected _getStateRequestCallData() {
|
|
199
203
|
if (!this._stateRequestCallData) {
|
|
200
204
|
const callData: MultiCallParams<
|
|
201
205
|
bigint | DecodedStateMultiCallResultWithRelativeBitmaps
|
|
@@ -226,9 +230,13 @@ export class UniswapV3EventPool extends StatefulEventSubscriber<PoolState> {
|
|
|
226
230
|
this.getBitmapRangeToRequest(),
|
|
227
231
|
)
|
|
228
232
|
.encodeABI(),
|
|
229
|
-
decodeFunction:
|
|
233
|
+
decodeFunction:
|
|
234
|
+
this.decodeStateMultiCallResultWithRelativeBitmaps !== undefined
|
|
235
|
+
? this.decodeStateMultiCallResultWithRelativeBitmaps
|
|
236
|
+
: decodeStateMultiCallResultWithRelativeBitmaps,
|
|
230
237
|
},
|
|
231
238
|
];
|
|
239
|
+
|
|
232
240
|
this._stateRequestCallData = callData;
|
|
233
241
|
}
|
|
234
242
|
return this._stateRequestCallData;
|
|
@@ -2,20 +2,20 @@ import { defaultAbiCoder, Interface } from '@ethersproject/abi';
|
|
|
2
2
|
import _ from 'lodash';
|
|
3
3
|
import { pack } from '@ethersproject/solidity';
|
|
4
4
|
import {
|
|
5
|
-
|
|
5
|
+
AdapterExchangeParam,
|
|
6
6
|
Address,
|
|
7
7
|
ExchangePrices,
|
|
8
|
-
|
|
9
|
-
SimpleExchangeParam,
|
|
10
|
-
PoolLiquidity,
|
|
8
|
+
ExchangeTxInfo,
|
|
11
9
|
Logger,
|
|
12
10
|
NumberAsString,
|
|
11
|
+
PoolLiquidity,
|
|
13
12
|
PoolPrices,
|
|
14
|
-
TxInfo,
|
|
15
13
|
PreprocessTransactionOptions,
|
|
16
|
-
|
|
14
|
+
SimpleExchangeParam,
|
|
15
|
+
Token,
|
|
16
|
+
TxInfo,
|
|
17
17
|
} from '../../types';
|
|
18
|
-
import {
|
|
18
|
+
import { CACHE_PREFIX, Network, SwapSide } from '../../constants';
|
|
19
19
|
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
20
20
|
import {
|
|
21
21
|
getBigIntPow,
|
|
@@ -39,10 +39,10 @@ import {
|
|
|
39
39
|
getLocalDeadlineAsFriendlyPlaceholder,
|
|
40
40
|
SimpleExchange,
|
|
41
41
|
} from '../simple-exchange';
|
|
42
|
-
import {
|
|
42
|
+
import { Adapters, PoolsToPreload, UniswapV3Config } from './config';
|
|
43
43
|
import { UniswapV3EventPool } from './uniswap-v3-pool';
|
|
44
44
|
import UniswapV3RouterABI from '../../abi/uniswap-v3/UniswapV3Router.abi.json';
|
|
45
|
-
import
|
|
45
|
+
import UniswapV3QuoterV2ABI from '../../abi/uniswap-v3/UniswapV3QuoterV2.abi.json';
|
|
46
46
|
import UniswapV3MultiABI from '../../abi/uniswap-v3/UniswapMulti.abi.json';
|
|
47
47
|
import DirectSwapABI from '../../abi/DirectSwap.json';
|
|
48
48
|
import UniswapV3StateMulticallABI from '../../abi/uniswap-v3/UniswapV3StateMulticall.abi.json';
|
|
@@ -64,6 +64,7 @@ import {
|
|
|
64
64
|
DEFAULT_ID_ERC20_AS_STRING,
|
|
65
65
|
} from '../../lib/tokens/types';
|
|
66
66
|
import { OptimalSwapExchange } from '@paraswap/core';
|
|
67
|
+
import { OnPoolCreatedCallback, UniswapV3Factory } from './uniswap-v3-factory';
|
|
67
68
|
|
|
68
69
|
type PoolPairsInfo = {
|
|
69
70
|
token0: Address;
|
|
@@ -71,14 +72,15 @@ type PoolPairsInfo = {
|
|
|
71
72
|
fee: string;
|
|
72
73
|
};
|
|
73
74
|
|
|
74
|
-
const UNISWAPV3_CLEAN_NOT_EXISTING_POOL_TTL_MS =
|
|
75
|
-
const UNISWAPV3_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS =
|
|
75
|
+
const UNISWAPV3_CLEAN_NOT_EXISTING_POOL_TTL_MS = 3 * 24 * 60 * 60 * 1000; // 3 days
|
|
76
|
+
const UNISWAPV3_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS = 24 * 60 * 60 * 1000; // Once in a day
|
|
76
77
|
const UNISWAPV3_QUOTE_GASLIMIT = 200_000;
|
|
77
78
|
|
|
78
79
|
export class UniswapV3
|
|
79
80
|
extends SimpleExchange
|
|
80
81
|
implements IDex<UniswapV3Data, UniswapV3Param>
|
|
81
82
|
{
|
|
83
|
+
private readonly factory: UniswapV3Factory;
|
|
82
84
|
readonly isFeeOnTransferSupported: boolean = false;
|
|
83
85
|
readonly eventPools: Record<string, UniswapV3EventPool | null> = {};
|
|
84
86
|
|
|
@@ -91,7 +93,14 @@ export class UniswapV3
|
|
|
91
93
|
|
|
92
94
|
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
93
95
|
getDexKeysWithNetwork(
|
|
94
|
-
_.pick(UniswapV3Config, [
|
|
96
|
+
_.pick(UniswapV3Config, [
|
|
97
|
+
'UniswapV3',
|
|
98
|
+
'SushiSwapV3',
|
|
99
|
+
'QuickSwapV3.1',
|
|
100
|
+
'RamsesV2',
|
|
101
|
+
'ChronosV3',
|
|
102
|
+
'Retro',
|
|
103
|
+
]),
|
|
95
104
|
);
|
|
96
105
|
|
|
97
106
|
logger: Logger;
|
|
@@ -107,7 +116,7 @@ export class UniswapV3
|
|
|
107
116
|
protected dexHelper: IDexHelper,
|
|
108
117
|
protected adapters = Adapters[network] || {},
|
|
109
118
|
readonly routerIface = new Interface(UniswapV3RouterABI),
|
|
110
|
-
readonly quoterIface = new Interface(
|
|
119
|
+
readonly quoterIface = new Interface(UniswapV3QuoterV2ABI),
|
|
111
120
|
protected config = UniswapV3Config[dexKey][network],
|
|
112
121
|
protected poolsToPreload = PoolsToPreload[dexKey]?.[network] || [],
|
|
113
122
|
) {
|
|
@@ -118,7 +127,9 @@ export class UniswapV3
|
|
|
118
127
|
this.config.uniswapMulticall,
|
|
119
128
|
);
|
|
120
129
|
this.stateMultiContract = new this.dexHelper.web3Provider.eth.Contract(
|
|
121
|
-
|
|
130
|
+
this.config.stateMultiCallAbi !== undefined
|
|
131
|
+
? this.config.stateMultiCallAbi
|
|
132
|
+
: (UniswapV3StateMulticallABI as AbiItem[]),
|
|
122
133
|
this.config.stateMulticall,
|
|
123
134
|
);
|
|
124
135
|
|
|
@@ -130,6 +141,14 @@ export class UniswapV3
|
|
|
130
141
|
|
|
131
142
|
this.notExistingPoolSetKey =
|
|
132
143
|
`${CACHE_PREFIX}_${network}_${dexKey}_not_existings_pool_set`.toLowerCase();
|
|
144
|
+
|
|
145
|
+
this.factory = new UniswapV3Factory(
|
|
146
|
+
dexHelper,
|
|
147
|
+
dexKey,
|
|
148
|
+
this.config.factory,
|
|
149
|
+
this.logger,
|
|
150
|
+
this.onPoolCreatedDeleteFromNonExistingSet,
|
|
151
|
+
);
|
|
133
152
|
}
|
|
134
153
|
|
|
135
154
|
get supportedFees() {
|
|
@@ -146,6 +165,9 @@ export class UniswapV3
|
|
|
146
165
|
}
|
|
147
166
|
|
|
148
167
|
async initializePricing(blockNumber: number) {
|
|
168
|
+
// Init listening to new pools creation
|
|
169
|
+
await this.factory.initialize(blockNumber);
|
|
170
|
+
|
|
149
171
|
// This is only for testing, because cold pool fetching is goes out of
|
|
150
172
|
// FETCH_POOL_INDENTIFIER_TIMEOUT range
|
|
151
173
|
await Promise.all(
|
|
@@ -176,6 +198,38 @@ export class UniswapV3
|
|
|
176
198
|
}
|
|
177
199
|
}
|
|
178
200
|
|
|
201
|
+
/*
|
|
202
|
+
* When a non existing pool is queried, it's blacklisted for an arbitrary long period in order to prevent issuing too many rpc calls
|
|
203
|
+
* Once the pool is created, it gets immediately flagged
|
|
204
|
+
*/
|
|
205
|
+
onPoolCreatedDeleteFromNonExistingSet: OnPoolCreatedCallback = async ({
|
|
206
|
+
token0,
|
|
207
|
+
token1,
|
|
208
|
+
fee,
|
|
209
|
+
}) => {
|
|
210
|
+
const logPrefix = '[UniswapV3.onPoolCreatedDeleteFromNonExistingSet]';
|
|
211
|
+
const [_token0, _token1] = this._sortTokens(token0, token1);
|
|
212
|
+
const poolKey = `${_token0}_${_token1}_${fee}`;
|
|
213
|
+
|
|
214
|
+
// consider doing it only from master pool for less calls to distant cache
|
|
215
|
+
|
|
216
|
+
// delete entry locally to let local instance discover the pool
|
|
217
|
+
delete this.eventPools[this.getPoolIdentifier(_token0, _token1, fee)];
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
this.logger.info(
|
|
221
|
+
`${logPrefix} delete pool from not existing set: ${poolKey}`,
|
|
222
|
+
);
|
|
223
|
+
// delete pool record from set
|
|
224
|
+
await this.dexHelper.cache.zrem(this.notExistingPoolSetKey, [poolKey]);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
this.logger.error(
|
|
227
|
+
`${logPrefix} failed to delete pool from set: ${poolKey}`,
|
|
228
|
+
error,
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
179
233
|
async getPool(
|
|
180
234
|
srcAddress: Address,
|
|
181
235
|
destAddress: Address,
|
|
@@ -233,12 +287,17 @@ export class UniswapV3
|
|
|
233
287
|
}
|
|
234
288
|
|
|
235
289
|
this.logger.trace(`starting to listen to new pool: ${key}`);
|
|
290
|
+
const poolImplementation =
|
|
291
|
+
this.config.eventPoolImplementation !== undefined
|
|
292
|
+
? this.config.eventPoolImplementation
|
|
293
|
+
: UniswapV3EventPool;
|
|
236
294
|
pool =
|
|
237
295
|
pool ||
|
|
238
|
-
new
|
|
296
|
+
new poolImplementation(
|
|
239
297
|
this.dexHelper,
|
|
240
298
|
this.dexKey,
|
|
241
299
|
this.stateMultiContract,
|
|
300
|
+
this.config.decodeStateMultiCallResultWithRelativeBitmaps,
|
|
242
301
|
this.erc20Interface,
|
|
243
302
|
this.config.factory,
|
|
244
303
|
fee,
|
|
@@ -365,6 +424,7 @@ export class UniswapV3
|
|
|
365
424
|
amounts: bigint[],
|
|
366
425
|
side: SwapSide,
|
|
367
426
|
pools: UniswapV3EventPool[],
|
|
427
|
+
states: PoolState[],
|
|
368
428
|
): Promise<ExchangePrices<UniswapV3Data> | null> {
|
|
369
429
|
if (pools.length === 0) {
|
|
370
430
|
return null;
|
|
@@ -462,7 +522,7 @@ export class UniswapV3
|
|
|
462
522
|
};
|
|
463
523
|
|
|
464
524
|
let i = 0;
|
|
465
|
-
const result = pools.map(pool => {
|
|
525
|
+
const result = pools.map((pool, index) => {
|
|
466
526
|
const _rates = _amounts.map(() => decode(i++));
|
|
467
527
|
const unit: bigint = _rates[0];
|
|
468
528
|
|
|
@@ -482,6 +542,7 @@ export class UniswapV3
|
|
|
482
542
|
tokenIn: from.address,
|
|
483
543
|
tokenOut: to.address,
|
|
484
544
|
fee: pool.feeCodeAsString,
|
|
545
|
+
currentFee: states[index].fee.toString(),
|
|
485
546
|
},
|
|
486
547
|
],
|
|
487
548
|
exchange: pool.poolAddress,
|
|
@@ -593,16 +654,17 @@ export class UniswapV3
|
|
|
593
654
|
},
|
|
594
655
|
);
|
|
595
656
|
|
|
657
|
+
const states = poolsToUse.poolWithState.map(
|
|
658
|
+
p => p.getState(blockNumber)!,
|
|
659
|
+
);
|
|
660
|
+
|
|
596
661
|
const rpcResultsPromise = this.getPricingFromRpc(
|
|
597
662
|
_srcToken,
|
|
598
663
|
_destToken,
|
|
599
664
|
amounts,
|
|
600
665
|
side,
|
|
601
666
|
this.network === Network.ZKEVM ? [] : poolsToUse.poolWithoutState,
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
const states = poolsToUse.poolWithState.map(
|
|
605
|
-
p => p.getState(blockNumber)!,
|
|
667
|
+
this.network === Network.ZKEVM ? [] : states,
|
|
606
668
|
);
|
|
607
669
|
|
|
608
670
|
const unitAmount = getBigIntPow(
|
|
@@ -676,6 +738,7 @@ export class UniswapV3
|
|
|
676
738
|
tokenIn: _srcAddress,
|
|
677
739
|
tokenOut: _destAddress,
|
|
678
740
|
fee: pool.feeCode.toString(),
|
|
741
|
+
currentFee: state.fee.toString(),
|
|
679
742
|
},
|
|
680
743
|
],
|
|
681
744
|
},
|
|
@@ -1055,6 +1118,10 @@ export class UniswapV3
|
|
|
1055
1118
|
deployer: this.config.deployer?.toLowerCase(),
|
|
1056
1119
|
initHash: this.config.initHash,
|
|
1057
1120
|
subgraphURL: this.config.subgraphURL,
|
|
1121
|
+
stateMultiCallAbi: this.config.stateMultiCallAbi,
|
|
1122
|
+
eventPoolImplementation: this.config.eventPoolImplementation,
|
|
1123
|
+
decodeStateMultiCallResultWithRelativeBitmaps:
|
|
1124
|
+
this.config.decodeStateMultiCallResultWithRelativeBitmaps,
|
|
1058
1125
|
};
|
|
1059
1126
|
return newConfig;
|
|
1060
1127
|
}
|
package/src/dex/weth/config.ts
CHANGED
|
@@ -64,6 +64,16 @@ export const WooFiV2Config: DexConfigMap<DexParams> = {
|
|
|
64
64
|
decimals: 6,
|
|
65
65
|
},
|
|
66
66
|
},
|
|
67
|
+
[Network.BASE]: {
|
|
68
|
+
wooPPV2Address: '0xb130a49065178465931d4f887056328CeA5D723f',
|
|
69
|
+
wooOracleV2Address: '0x2Fe5E5D341cFFa606a5d9DA1B6B646a381B0f7ec',
|
|
70
|
+
integrationHelperAddress: '0xC4E9B633685461E7B7A807D12a246C81f96F31B8',
|
|
71
|
+
// USDbC
|
|
72
|
+
quoteToken: {
|
|
73
|
+
address: '0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA',
|
|
74
|
+
decimals: 6,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
67
77
|
},
|
|
68
78
|
};
|
|
69
79
|
|
|
@@ -84,4 +94,7 @@ export const Adapters: Record<number, AdapterMappings> = {
|
|
|
84
94
|
[Network.AVALANCHE]: {
|
|
85
95
|
[SwapSide.SELL]: [{ name: 'AvalancheAdapter01', index: 12 }],
|
|
86
96
|
},
|
|
97
|
+
[Network.BASE]: {
|
|
98
|
+
[SwapSide.SELL]: [{ name: 'BaseAdapter01', index: 5 }],
|
|
99
|
+
},
|
|
87
100
|
};
|
|
@@ -213,4 +213,68 @@ describe('WooFiV2 E2E', () => {
|
|
|
213
213
|
tokenQuoteAmount,
|
|
214
214
|
);
|
|
215
215
|
});
|
|
216
|
+
|
|
217
|
+
describe('Base', () => {
|
|
218
|
+
const network = Network.BASE;
|
|
219
|
+
|
|
220
|
+
const baseATokenSymbol = 'USDbC';
|
|
221
|
+
const baseBTokenSymbol = 'ETH';
|
|
222
|
+
|
|
223
|
+
const tokenBaseAAmount = '100000000';
|
|
224
|
+
const tokenBaseBAmount = '1000000000000000000';
|
|
225
|
+
|
|
226
|
+
const tokens = Tokens[network];
|
|
227
|
+
const holders = Holders[network];
|
|
228
|
+
|
|
229
|
+
const provider = new StaticJsonRpcProvider(
|
|
230
|
+
generateConfig(network).privateHttpProvider,
|
|
231
|
+
network,
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
const sideToContractMethods = new Map([
|
|
235
|
+
[
|
|
236
|
+
SwapSide.SELL,
|
|
237
|
+
[
|
|
238
|
+
ContractMethod.simpleSwap,
|
|
239
|
+
ContractMethod.multiSwap,
|
|
240
|
+
ContractMethod.megaSwap,
|
|
241
|
+
],
|
|
242
|
+
],
|
|
243
|
+
]);
|
|
244
|
+
|
|
245
|
+
sideToContractMethods.forEach((contractMethods, side) =>
|
|
246
|
+
describe(`${side}`, () => {
|
|
247
|
+
contractMethods.forEach((contractMethod: ContractMethod) => {
|
|
248
|
+
describe(`${contractMethod}`, () => {
|
|
249
|
+
it(`${baseATokenSymbol} -> ${baseBTokenSymbol}`, async () => {
|
|
250
|
+
await testE2E(
|
|
251
|
+
tokens[baseATokenSymbol],
|
|
252
|
+
tokens[baseBTokenSymbol],
|
|
253
|
+
holders[baseATokenSymbol],
|
|
254
|
+
tokenBaseAAmount,
|
|
255
|
+
side,
|
|
256
|
+
dexKey,
|
|
257
|
+
contractMethod,
|
|
258
|
+
network,
|
|
259
|
+
provider,
|
|
260
|
+
);
|
|
261
|
+
});
|
|
262
|
+
it(`${baseBTokenSymbol} -> ${baseATokenSymbol}`, async () => {
|
|
263
|
+
await testE2E(
|
|
264
|
+
tokens[baseBTokenSymbol],
|
|
265
|
+
tokens[baseATokenSymbol],
|
|
266
|
+
holders[baseBTokenSymbol],
|
|
267
|
+
tokenBaseBAmount,
|
|
268
|
+
side,
|
|
269
|
+
dexKey,
|
|
270
|
+
contractMethod,
|
|
271
|
+
network,
|
|
272
|
+
provider,
|
|
273
|
+
);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
}),
|
|
278
|
+
);
|
|
279
|
+
});
|
|
216
280
|
});
|
|
@@ -41,6 +41,7 @@ class DummyCache implements ICache {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
async rawget(key: string): Promise<string | null> {
|
|
44
|
+
return this.storage[key] ? this.storage[key] : null;
|
|
44
45
|
return null;
|
|
45
46
|
}
|
|
46
47
|
|
|
@@ -49,10 +50,12 @@ class DummyCache implements ICache {
|
|
|
49
50
|
value: string,
|
|
50
51
|
ttl: number,
|
|
51
52
|
): Promise<string | null> {
|
|
52
|
-
|
|
53
|
+
this.storage[key] = value;
|
|
54
|
+
return 'OK';
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
async rawdel(key: string): Promise<void> {
|
|
58
|
+
delete this.storage[key];
|
|
56
59
|
return;
|
|
57
60
|
}
|
|
58
61
|
|
|
@@ -112,6 +115,10 @@ class DummyCache implements ICache {
|
|
|
112
115
|
return 0;
|
|
113
116
|
}
|
|
114
117
|
|
|
118
|
+
async zrem(key: string, membersKeys: string[]): Promise<number> {
|
|
119
|
+
return 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
115
122
|
async zadd(key: string, bulkItemsToAdd: (number | string)[], option?: 'NX') {
|
|
116
123
|
return 0;
|
|
117
124
|
}
|
package/src/dex-helper/icache.ts
CHANGED
|
@@ -46,6 +46,8 @@ export interface ICache {
|
|
|
46
46
|
|
|
47
47
|
zremrangebyscore(key: string, min: number, max: number): Promise<number>;
|
|
48
48
|
|
|
49
|
+
zrem(key: string, membersKeys: string[]): Promise<number>;
|
|
50
|
+
|
|
49
51
|
zscore(setKey: string, key: string): Promise<string | null>;
|
|
50
52
|
|
|
51
53
|
sismember(setKey: string, key: string): Promise<boolean>;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
2
|
+
import { PartialEventSubscriber } from '../composed-event-subscriber';
|
|
3
|
+
import {
|
|
4
|
+
Address,
|
|
5
|
+
BlockHeader,
|
|
6
|
+
Log,
|
|
7
|
+
Logger,
|
|
8
|
+
MultiCallInput,
|
|
9
|
+
MultiCallOutput,
|
|
10
|
+
} from '../types';
|
|
11
|
+
import { Lens } from '../lens';
|
|
12
|
+
import { Interface } from '@ethersproject/abi';
|
|
13
|
+
import ProxyABI from '../abi/api3-proxy.json';
|
|
14
|
+
import Api3ServerV1ABI from '../abi/api3-server-v1.json';
|
|
15
|
+
|
|
16
|
+
export type Api3FeedSubscriberState = {
|
|
17
|
+
value: bigint;
|
|
18
|
+
timestamp: bigint;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export class Api3FeedSubscriber<State> extends PartialEventSubscriber<
|
|
22
|
+
State,
|
|
23
|
+
Api3FeedSubscriberState
|
|
24
|
+
> {
|
|
25
|
+
static readonly proxyInterface = new Interface(ProxyABI);
|
|
26
|
+
static readonly api3ServerV1Iface = new Interface(Api3ServerV1ABI);
|
|
27
|
+
static readonly ANSWER_UPDATED_SIGNED_DATA =
|
|
28
|
+
Api3FeedSubscriber.api3ServerV1Iface.getEventTopic(
|
|
29
|
+
'UpdatedBeaconWithSignedData',
|
|
30
|
+
);
|
|
31
|
+
static readonly ANSWER_UPDATED_BEACON_SET_DATA =
|
|
32
|
+
Api3FeedSubscriber.api3ServerV1Iface.getEventTopic(
|
|
33
|
+
'UpdatedBeaconSetWithBeacons',
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
constructor(
|
|
37
|
+
private proxy: Address,
|
|
38
|
+
api3Server: Address,
|
|
39
|
+
private dataFeedId: string,
|
|
40
|
+
lens: Lens<DeepReadonly<State>, DeepReadonly<Api3FeedSubscriberState>>,
|
|
41
|
+
logger: Logger,
|
|
42
|
+
) {
|
|
43
|
+
super([api3Server], lens, logger);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static getApi3ServerV1MultiCallInput(proxy: Address): MultiCallInput {
|
|
47
|
+
return {
|
|
48
|
+
target: proxy,
|
|
49
|
+
callData:
|
|
50
|
+
Api3FeedSubscriber.proxyInterface.encodeFunctionData('api3ServerV1'),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static getDapiNameHashMultiCallInput(proxy: Address): MultiCallInput {
|
|
55
|
+
return {
|
|
56
|
+
target: proxy,
|
|
57
|
+
callData:
|
|
58
|
+
Api3FeedSubscriber.proxyInterface.encodeFunctionData('dapiNameHash'),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static getDataFeedId(proxy: Address): MultiCallInput {
|
|
63
|
+
return {
|
|
64
|
+
target: proxy,
|
|
65
|
+
callData:
|
|
66
|
+
Api3FeedSubscriber.proxyInterface.encodeFunctionData('dataFeedId'),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static getFeedIdFromDapiNameHash(
|
|
71
|
+
api3Server: Address,
|
|
72
|
+
dapiNameHash: string,
|
|
73
|
+
): MultiCallInput {
|
|
74
|
+
return {
|
|
75
|
+
target: api3Server,
|
|
76
|
+
callData: Api3FeedSubscriber.api3ServerV1Iface.encodeFunctionData(
|
|
77
|
+
'dapiNameHashToDataFeedId',
|
|
78
|
+
[dapiNameHash],
|
|
79
|
+
),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static decodeFeedIdFromDapiNameHash(multicallOutput: MultiCallOutput) {
|
|
84
|
+
return Api3FeedSubscriber.api3ServerV1Iface.decodeFunctionResult(
|
|
85
|
+
'dapiNameHashToDataFeedId',
|
|
86
|
+
multicallOutput,
|
|
87
|
+
)[0];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static decodeDapiNameHash(multicallOutput: MultiCallOutput) {
|
|
91
|
+
return Api3FeedSubscriber.proxyInterface.decodeFunctionResult(
|
|
92
|
+
'dapiNameHash',
|
|
93
|
+
multicallOutput,
|
|
94
|
+
)[0];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static decodeDataFeedId(multicallOutput: MultiCallOutput) {
|
|
98
|
+
return Api3FeedSubscriber.proxyInterface.decodeFunctionResult(
|
|
99
|
+
'dataFeedId',
|
|
100
|
+
multicallOutput,
|
|
101
|
+
)[0];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static decodeApi3ServerV1Result(multicallOutput: MultiCallOutput): Address {
|
|
105
|
+
return Api3FeedSubscriber.proxyInterface.decodeFunctionResult(
|
|
106
|
+
'api3ServerV1',
|
|
107
|
+
multicallOutput,
|
|
108
|
+
)[0];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public processLog(
|
|
112
|
+
state: DeepReadonly<Api3FeedSubscriberState>,
|
|
113
|
+
log: Readonly<Log>,
|
|
114
|
+
blockHeader: Readonly<BlockHeader>,
|
|
115
|
+
): DeepReadonly<Api3FeedSubscriberState> | null {
|
|
116
|
+
if (log.topics[0] === Api3FeedSubscriber.ANSWER_UPDATED_SIGNED_DATA) {
|
|
117
|
+
const decoded = Api3FeedSubscriber.api3ServerV1Iface.decodeEventLog(
|
|
118
|
+
'UpdatedBeaconWithSignedData',
|
|
119
|
+
log.data,
|
|
120
|
+
log.topics,
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
if (decoded.beaconId !== this.dataFeedId) return null;
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
value: BigInt(decoded.value.toString()),
|
|
127
|
+
timestamp: BigInt(decoded.timestamp.toString()),
|
|
128
|
+
};
|
|
129
|
+
} else if (
|
|
130
|
+
log.topics[0] === Api3FeedSubscriber.ANSWER_UPDATED_BEACON_SET_DATA
|
|
131
|
+
) {
|
|
132
|
+
const decoded = Api3FeedSubscriber.api3ServerV1Iface.decodeEventLog(
|
|
133
|
+
'UpdatedBeaconSetWithBeacons',
|
|
134
|
+
log.data,
|
|
135
|
+
log.topics,
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
if (decoded.beaconSetId !== this.dataFeedId) return null;
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
value: BigInt(decoded.value.toString()),
|
|
142
|
+
timestamp: BigInt(decoded.timestamp.toString()),
|
|
143
|
+
};
|
|
144
|
+
} else {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public getGenerateStateMultiCallInputs(): MultiCallInput[] {
|
|
150
|
+
return [
|
|
151
|
+
{
|
|
152
|
+
target: this.proxy,
|
|
153
|
+
callData: Api3FeedSubscriber.proxyInterface.encodeFunctionData('read'),
|
|
154
|
+
},
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
public generateState(
|
|
159
|
+
multicallOutputs: MultiCallOutput[],
|
|
160
|
+
blockNumber?: number | 'latest',
|
|
161
|
+
): DeepReadonly<Api3FeedSubscriberState> {
|
|
162
|
+
const decoded = Api3FeedSubscriber.proxyInterface.decodeFunctionResult(
|
|
163
|
+
'read',
|
|
164
|
+
multicallOutputs[0],
|
|
165
|
+
);
|
|
166
|
+
return {
|
|
167
|
+
value: BigInt(decoded.value.toString()),
|
|
168
|
+
timestamp: BigInt(decoded.timestamp.toString()),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
public getLatestData(state: DeepReadonly<State>): bigint {
|
|
173
|
+
return this.lens.get()(state).value;
|
|
174
|
+
}
|
|
175
|
+
}
|
package/src/lib/decoders.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Result } from '@ethersproject/abi';
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
|
+
import { BigNumber as EthersBigNumber } from 'ethers';
|
|
3
4
|
import { BytesLike, defaultAbiCoder } from 'ethers/lib/utils';
|
|
4
5
|
import _, { parseInt } from 'lodash';
|
|
5
6
|
import { BN_0 } from '../bignumber-constants';
|
|
@@ -50,6 +51,18 @@ export const uint256ToBigInt = (
|
|
|
50
51
|
return generalDecoder(result, ['uint256'], 0n, value => value[0].toBigInt());
|
|
51
52
|
};
|
|
52
53
|
|
|
54
|
+
export const uint128ToBigNumber = (
|
|
55
|
+
result: MultiResult<BytesLike> | BytesLike,
|
|
56
|
+
): EthersBigNumber => {
|
|
57
|
+
return generalDecoder(result, ['uint128'], 0n, value => value[0]);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const int24ToNumber = (
|
|
61
|
+
result: MultiResult<BytesLike> | BytesLike,
|
|
62
|
+
): number => {
|
|
63
|
+
return generalDecoder(result, ['int24'], 0n, value => value[0]);
|
|
64
|
+
};
|
|
65
|
+
|
|
53
66
|
export const uint256ArrayDecode = (
|
|
54
67
|
result: MultiResult<BytesLike> | BytesLike,
|
|
55
68
|
): bigint => {
|
|
@@ -18,6 +18,7 @@ type StateCache<State> = {
|
|
|
18
18
|
export type InitializeStateOptions<State> = {
|
|
19
19
|
state?: DeepReadonly<State>;
|
|
20
20
|
initCallback?: (state: DeepReadonly<State>) => void;
|
|
21
|
+
forceRegenerate?: boolean;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
export abstract class StatefulEventSubscriber<State>
|
|
@@ -89,6 +90,13 @@ export abstract class StatefulEventSubscriber<State>
|
|
|
89
90
|
let masterBn: undefined | number = undefined;
|
|
90
91
|
if (options && options.state) {
|
|
91
92
|
this.setState(options.state, blockNumber);
|
|
93
|
+
} else if (options && options.forceRegenerate) {
|
|
94
|
+
// ZkEVM forces to always regenerate state when it is old
|
|
95
|
+
this.logger.debug(
|
|
96
|
+
`${this.parentName}: ${this.name}: forced to regenerate state`,
|
|
97
|
+
);
|
|
98
|
+
const state = await this.generateState(blockNumber);
|
|
99
|
+
this.setState(state, blockNumber);
|
|
92
100
|
} else {
|
|
93
101
|
if (this.dexHelper.config.isSlave && this.masterPoolNeeded) {
|
|
94
102
|
let stateAsString = await this.dexHelper.cache.hget(
|
package/src/types.ts
CHANGED
|
@@ -276,6 +276,7 @@ export type Config = {
|
|
|
276
276
|
hashFlowDisabledMMs: string[];
|
|
277
277
|
uniswapV3EventLoggingSampleRate?: number;
|
|
278
278
|
swaapV2AuthToken?: string;
|
|
279
|
+
forceRpcFallbackDexs: string[];
|
|
279
280
|
};
|
|
280
281
|
|
|
281
282
|
export type BigIntAsString = string;
|
|
@@ -290,6 +291,7 @@ export type PreprocessTransactionOptions = {
|
|
|
290
291
|
hmac?: string;
|
|
291
292
|
mockRfqAndLO?: boolean;
|
|
292
293
|
isDirectMethod?: boolean;
|
|
294
|
+
partner?: string;
|
|
293
295
|
};
|
|
294
296
|
|
|
295
297
|
export type TransferFeeParams = {
|