@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
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
dotenv.config();
|
|
3
|
+
|
|
4
|
+
import { testE2E } from '../../../tests/utils-e2e';
|
|
5
|
+
import { Tokens, Holders } from '../../../tests/constants-e2e';
|
|
6
|
+
import { Network, ContractMethod, SwapSide } from '../../constants';
|
|
7
|
+
import { StaticJsonRpcProvider } from '@ethersproject/providers';
|
|
8
|
+
import { generateConfig } from '../../config';
|
|
9
|
+
|
|
10
|
+
describe('QuickPerps E2E', () => {
|
|
11
|
+
const dexKey = 'QuickPerps';
|
|
12
|
+
|
|
13
|
+
describe('QuickPerps zkEVM', () => {
|
|
14
|
+
const network = Network.ZKEVM;
|
|
15
|
+
const tokens = Tokens[network];
|
|
16
|
+
const holders = Holders[network];
|
|
17
|
+
const provider = new StaticJsonRpcProvider(
|
|
18
|
+
generateConfig(network).privateHttpProvider,
|
|
19
|
+
network,
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const tokenASymbol: string = 'ETH';
|
|
23
|
+
const tokenBSymbol: string = 'MATIC';
|
|
24
|
+
|
|
25
|
+
const tokenAAmount: string = '100000000000000000';
|
|
26
|
+
const tokenBAmount: string = '10000000000000000000';
|
|
27
|
+
|
|
28
|
+
const sideToContractMethods = new Map([
|
|
29
|
+
[
|
|
30
|
+
SwapSide.SELL,
|
|
31
|
+
[
|
|
32
|
+
ContractMethod.simpleSwap,
|
|
33
|
+
ContractMethod.multiSwap,
|
|
34
|
+
ContractMethod.megaSwap,
|
|
35
|
+
],
|
|
36
|
+
],
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
sideToContractMethods.forEach((contractMethods, side) =>
|
|
40
|
+
contractMethods.forEach((contractMethod: ContractMethod) => {
|
|
41
|
+
describe(`${contractMethod}`, () => {
|
|
42
|
+
it('ETH -> MATIC', async () => {
|
|
43
|
+
await testE2E(
|
|
44
|
+
tokens[tokenASymbol],
|
|
45
|
+
tokens[tokenBSymbol],
|
|
46
|
+
holders[tokenASymbol],
|
|
47
|
+
side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
|
|
48
|
+
side,
|
|
49
|
+
dexKey,
|
|
50
|
+
contractMethod,
|
|
51
|
+
network,
|
|
52
|
+
provider,
|
|
53
|
+
undefined,
|
|
54
|
+
undefined,
|
|
55
|
+
undefined,
|
|
56
|
+
undefined,
|
|
57
|
+
undefined,
|
|
58
|
+
true,
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}),
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
dotenv.config();
|
|
3
|
+
|
|
4
|
+
import { QuickPerpsEventPool } from './pool';
|
|
5
|
+
import { QuickPerpsConfig } from './config';
|
|
6
|
+
import { Network } from '../../constants';
|
|
7
|
+
import { DummyDexHelper } from '../../dex-helper/index';
|
|
8
|
+
import { testEventSubscriber } from '../../../tests/utils-events';
|
|
9
|
+
import { PoolConfig, PoolState } from './types';
|
|
10
|
+
|
|
11
|
+
jest.setTimeout(50 * 1000);
|
|
12
|
+
const dexKey = 'QuickPerps';
|
|
13
|
+
const network = Network.ZKEVM;
|
|
14
|
+
const params = QuickPerpsConfig[dexKey][network];
|
|
15
|
+
const dexHelper = new DummyDexHelper(network);
|
|
16
|
+
const logger = dexHelper.getLogger(dexKey);
|
|
17
|
+
|
|
18
|
+
async function fetchPoolState(
|
|
19
|
+
quickPerpsPool: QuickPerpsEventPool,
|
|
20
|
+
blockNumber: number,
|
|
21
|
+
): Promise<PoolState> {
|
|
22
|
+
return quickPerpsPool.generateState(blockNumber);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// timestamp can't be compared exactly as the event released
|
|
26
|
+
// doesn't have the timestamp. It is safe to consider the
|
|
27
|
+
// timestamp as the blockTime as the max deviation is bounded
|
|
28
|
+
// on the contract
|
|
29
|
+
const stateWithoutTimestamp = (state: PoolState) => ({
|
|
30
|
+
...state,
|
|
31
|
+
secondaryPrices: {
|
|
32
|
+
prices: state.secondaryPrices.prices,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
function compareState(state: PoolState, expectedState: PoolState) {
|
|
37
|
+
expect(stateWithoutTimestamp(state)).toEqual(
|
|
38
|
+
stateWithoutTimestamp(expectedState),
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('QuickPerps Event', function () {
|
|
43
|
+
const blockNumbers: { [eventName: string]: number[] } = {
|
|
44
|
+
IncreaseUsdqAmount: [
|
|
45
|
+
4960808, 4960808, 4961034, 4961037, 4961046, 4961052, 4961055, 4961062,
|
|
46
|
+
4961153, 4961167, 4961190, 4961194, 4961215, 4961220, 4961353, 4961472,
|
|
47
|
+
4961476, 4961521, 4961628, 4961629, 4961648, 4961664, 4961683, 4961710,
|
|
48
|
+
4961716, 4961848, 4961853, 4961863, 4961866, 4962156, 4962180, 4962200,
|
|
49
|
+
4962296,
|
|
50
|
+
],
|
|
51
|
+
DecreaseUsdqAmount: [
|
|
52
|
+
4960808, 4960808, 4961034, 4961037, 4961046, 4961052, 4961055, 4961062,
|
|
53
|
+
4961153, 4961167, 4961190, 4961194, 4961215, 4961220, 4961353, 4961472,
|
|
54
|
+
4961476, 4961521, 4961628, 4961629, 4961648, 4961664, 4961683, 4961710,
|
|
55
|
+
4961716, 4961848, 4961853, 4961863, 4961866, 4962156, 4962180, 4962200,
|
|
56
|
+
4962296,
|
|
57
|
+
],
|
|
58
|
+
Transfer: [4958541, 4959994, 4959998, 4960452, 4960452],
|
|
59
|
+
PriceUpdate: [
|
|
60
|
+
4960534, 4960569, 4960584, 4960609, 4960637, 4960660, 4960694, 4960700,
|
|
61
|
+
],
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
describe('QuickPerpsEventPool', function () {
|
|
65
|
+
let config: PoolConfig;
|
|
66
|
+
let quickPerpsPool: QuickPerpsEventPool;
|
|
67
|
+
let blockNumber: number;
|
|
68
|
+
beforeAll(async function () {
|
|
69
|
+
blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
70
|
+
|
|
71
|
+
config = await QuickPerpsEventPool.getConfig(
|
|
72
|
+
params,
|
|
73
|
+
blockNumber,
|
|
74
|
+
dexHelper.multiContract,
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
Object.keys(blockNumbers).forEach((event: string) => {
|
|
78
|
+
blockNumbers[event].forEach((blockNumber: number) => {
|
|
79
|
+
it(`Should return the correct state after the ${blockNumber}:${event}`, async function () {
|
|
80
|
+
quickPerpsPool = new QuickPerpsEventPool(
|
|
81
|
+
dexKey,
|
|
82
|
+
network,
|
|
83
|
+
dexHelper,
|
|
84
|
+
config,
|
|
85
|
+
);
|
|
86
|
+
await testEventSubscriber(
|
|
87
|
+
quickPerpsPool,
|
|
88
|
+
quickPerpsPool.addressesSubscribed,
|
|
89
|
+
(_blockNumber: number) =>
|
|
90
|
+
fetchPoolState(quickPerpsPool, _blockNumber),
|
|
91
|
+
blockNumber,
|
|
92
|
+
`${dexKey}_${params.vault}`,
|
|
93
|
+
dexHelper.provider,
|
|
94
|
+
compareState,
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import dotenv from 'dotenv';
|
|
3
|
+
dotenv.config();
|
|
4
|
+
|
|
5
|
+
import { Interface } from '@ethersproject/abi';
|
|
6
|
+
import { DummyDexHelper } from '../../dex-helper/index';
|
|
7
|
+
import { Network, SwapSide } from '../../constants';
|
|
8
|
+
import { QuickPerps } from './quick-perps';
|
|
9
|
+
import { QuickPerpsConfig } from './config';
|
|
10
|
+
import {
|
|
11
|
+
checkPoolPrices,
|
|
12
|
+
checkPoolsLiquidity,
|
|
13
|
+
checkConstantPoolPrices,
|
|
14
|
+
} from '../../../tests/utils';
|
|
15
|
+
import { Tokens } from '../../../tests/constants-e2e';
|
|
16
|
+
import ReaderABI from '../../abi/quick-perps/reader.json';
|
|
17
|
+
|
|
18
|
+
const network = Network.ZKEVM;
|
|
19
|
+
const dexKey = 'QuickPerps';
|
|
20
|
+
const params = QuickPerpsConfig[dexKey][network];
|
|
21
|
+
const readerInterface = new Interface(ReaderABI);
|
|
22
|
+
const readerAddress = '0xf1CFB75854DE535475B88Bb6FBad317eea98c0F9';
|
|
23
|
+
|
|
24
|
+
function testsForCase(
|
|
25
|
+
tokenASymbol: string,
|
|
26
|
+
tokenBSymbol: string,
|
|
27
|
+
amounts: bigint[],
|
|
28
|
+
) {
|
|
29
|
+
const TokenA = Tokens[network][tokenASymbol];
|
|
30
|
+
const TokenB = Tokens[network][tokenBSymbol];
|
|
31
|
+
|
|
32
|
+
it('getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
33
|
+
const dexHelper = new DummyDexHelper(network);
|
|
34
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
35
|
+
const quickPerps = new QuickPerps(network, dexKey, dexHelper);
|
|
36
|
+
|
|
37
|
+
await quickPerps.initializePricing(blocknumber);
|
|
38
|
+
|
|
39
|
+
const pools = await quickPerps.getPoolIdentifiers(
|
|
40
|
+
TokenA,
|
|
41
|
+
TokenB,
|
|
42
|
+
SwapSide.SELL,
|
|
43
|
+
blocknumber,
|
|
44
|
+
);
|
|
45
|
+
console.log(`${tokenASymbol} <> ${tokenBSymbol} Pool Identifiers: `, pools);
|
|
46
|
+
|
|
47
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
48
|
+
|
|
49
|
+
const poolPrices = await quickPerps.getPricesVolume(
|
|
50
|
+
TokenA,
|
|
51
|
+
TokenB,
|
|
52
|
+
amounts,
|
|
53
|
+
SwapSide.SELL,
|
|
54
|
+
blocknumber,
|
|
55
|
+
pools,
|
|
56
|
+
);
|
|
57
|
+
console.log(`${tokenASymbol} <> ${tokenBSymbol} Pool Prices: `, poolPrices);
|
|
58
|
+
|
|
59
|
+
expect(poolPrices).not.toBeNull();
|
|
60
|
+
if (quickPerps.hasConstantPriceLargeAmounts) {
|
|
61
|
+
checkConstantPoolPrices(poolPrices!, amounts, dexKey);
|
|
62
|
+
} else {
|
|
63
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Do on chain pricing based on reader to compare
|
|
67
|
+
const readerCallData = amounts.map(a => ({
|
|
68
|
+
target: readerAddress,
|
|
69
|
+
callData: readerInterface.encodeFunctionData('getAmountOut', [
|
|
70
|
+
params.vault,
|
|
71
|
+
TokenA.address,
|
|
72
|
+
TokenB.address,
|
|
73
|
+
a.toString(),
|
|
74
|
+
]),
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
const readerResult = (
|
|
78
|
+
await dexHelper.multiContract.methods
|
|
79
|
+
.aggregate(readerCallData)
|
|
80
|
+
.call({}, blocknumber)
|
|
81
|
+
).returnData;
|
|
82
|
+
const expectedPrices = readerResult.map((p: any) =>
|
|
83
|
+
BigInt(
|
|
84
|
+
readerInterface.decodeFunctionResult('getAmountOut', p)[0].toString(),
|
|
85
|
+
),
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
expect(poolPrices![0].prices).toEqual(expectedPrices);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('getTopPoolsForToken', async function () {
|
|
92
|
+
const dexHelper = new DummyDexHelper(network);
|
|
93
|
+
const quickPerps = new QuickPerps(network, dexKey, dexHelper);
|
|
94
|
+
|
|
95
|
+
await quickPerps.updatePoolState();
|
|
96
|
+
const poolLiquidity = await quickPerps.getTopPoolsForToken(
|
|
97
|
+
TokenA.address,
|
|
98
|
+
10,
|
|
99
|
+
);
|
|
100
|
+
console.log(
|
|
101
|
+
`${tokenASymbol} Top Pools:`,
|
|
102
|
+
JSON.stringify(poolLiquidity, null, 2),
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
if (!quickPerps.hasConstantPriceLargeAmounts) {
|
|
106
|
+
checkPoolsLiquidity(poolLiquidity, TokenA.address, dexKey);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
describe('QuickPerps', function () {
|
|
112
|
+
describe('WETH -> MATIC', function () {
|
|
113
|
+
const TokenASymbol = 'WETH';
|
|
114
|
+
const TokenBSymbol = 'MATIC';
|
|
115
|
+
|
|
116
|
+
const amounts = [
|
|
117
|
+
0n,
|
|
118
|
+
100000000000000000n,
|
|
119
|
+
200000000000000000n,
|
|
120
|
+
300000000000000000n,
|
|
121
|
+
400000000000000000n,
|
|
122
|
+
500000000000000000n,
|
|
123
|
+
600000000000000000n,
|
|
124
|
+
700000000000000000n,
|
|
125
|
+
800000000000000000n,
|
|
126
|
+
900000000000000000n,
|
|
127
|
+
1000000000000000000n,
|
|
128
|
+
];
|
|
129
|
+
|
|
130
|
+
testsForCase(TokenASymbol, TokenBSymbol, amounts);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('WBTC -> USDC', function () {
|
|
134
|
+
const TokenASymbol = 'WBTC';
|
|
135
|
+
const TokenBSymbol = 'USDC';
|
|
136
|
+
|
|
137
|
+
const amounts = [
|
|
138
|
+
0n,
|
|
139
|
+
100000000n,
|
|
140
|
+
200000000n,
|
|
141
|
+
300000000n,
|
|
142
|
+
400000000n,
|
|
143
|
+
500000000n,
|
|
144
|
+
600000000n,
|
|
145
|
+
700000000n,
|
|
146
|
+
800000000n,
|
|
147
|
+
900000000n,
|
|
148
|
+
1000000000n,
|
|
149
|
+
];
|
|
150
|
+
|
|
151
|
+
testsForCase(TokenASymbol, TokenBSymbol, amounts);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import {
|
|
4
|
+
Token,
|
|
5
|
+
Address,
|
|
6
|
+
ExchangePrices,
|
|
7
|
+
PoolPrices,
|
|
8
|
+
AdapterExchangeParam,
|
|
9
|
+
SimpleExchangeParam,
|
|
10
|
+
PoolLiquidity,
|
|
11
|
+
Logger,
|
|
12
|
+
} from '../../types';
|
|
13
|
+
import { SwapSide, Network } from '../../constants';
|
|
14
|
+
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
15
|
+
import { getDexKeysWithNetwork, getBigIntPow } from '../../utils';
|
|
16
|
+
import { IDex } from '../idex';
|
|
17
|
+
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
18
|
+
import { QuickPerpsData, DexParams } from './types';
|
|
19
|
+
import { QuickPerpsEventPool } from './pool';
|
|
20
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
21
|
+
import { QuickPerpsConfig, Adapters } from './config';
|
|
22
|
+
import { Vault } from './vault';
|
|
23
|
+
import ERC20ABI from '../../abi/erc20.json';
|
|
24
|
+
|
|
25
|
+
const QuickPerpsGasCost = 300 * 1000;
|
|
26
|
+
|
|
27
|
+
export class QuickPerps extends SimpleExchange implements IDex<QuickPerpsData> {
|
|
28
|
+
protected pool: QuickPerpsEventPool | null = null;
|
|
29
|
+
protected supportedTokensMap: { [address: string]: boolean } = {};
|
|
30
|
+
// supportedTokens is only used by the pooltracker
|
|
31
|
+
protected supportedTokens: Token[] = [];
|
|
32
|
+
|
|
33
|
+
readonly hasConstantPriceLargeAmounts = false;
|
|
34
|
+
readonly needWrapNative = true;
|
|
35
|
+
readonly isFeeOnTransferSupported = false;
|
|
36
|
+
|
|
37
|
+
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
38
|
+
getDexKeysWithNetwork(QuickPerpsConfig);
|
|
39
|
+
|
|
40
|
+
public static erc20Interface = new Interface(ERC20ABI);
|
|
41
|
+
|
|
42
|
+
vaultUSDBalance: number = 0;
|
|
43
|
+
|
|
44
|
+
logger: Logger;
|
|
45
|
+
|
|
46
|
+
constructor(
|
|
47
|
+
protected network: Network,
|
|
48
|
+
dexKey: string,
|
|
49
|
+
protected dexHelper: IDexHelper,
|
|
50
|
+
protected adapters = Adapters[network],
|
|
51
|
+
protected params: DexParams = QuickPerpsConfig[dexKey][network],
|
|
52
|
+
) {
|
|
53
|
+
super(dexHelper, dexKey);
|
|
54
|
+
this.logger = dexHelper.getLogger(dexKey);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async initializePricing(blockNumber: number) {
|
|
58
|
+
const config = await QuickPerpsEventPool.getConfig(
|
|
59
|
+
this.params,
|
|
60
|
+
blockNumber,
|
|
61
|
+
this.dexHelper.multiContract,
|
|
62
|
+
);
|
|
63
|
+
config.tokenAddresses.forEach(
|
|
64
|
+
(token: Address) => (this.supportedTokensMap[token] = true),
|
|
65
|
+
);
|
|
66
|
+
this.pool = new QuickPerpsEventPool(
|
|
67
|
+
this.dexKey,
|
|
68
|
+
this.network,
|
|
69
|
+
this.dexHelper,
|
|
70
|
+
config,
|
|
71
|
+
);
|
|
72
|
+
await this.pool.initialize(blockNumber);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Returns the list of contract adapters (name and index)
|
|
76
|
+
// for a buy/sell. Return null if there are no adapters.
|
|
77
|
+
getAdapters(side: SwapSide): { name: string; index: number }[] | null {
|
|
78
|
+
return this.adapters[side];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Returns list of pool identifiers that can be used
|
|
82
|
+
// for a given swap. poolIdentifiers must be unique
|
|
83
|
+
// across DEXes.
|
|
84
|
+
async getPoolIdentifiers(
|
|
85
|
+
srcToken: Token,
|
|
86
|
+
destToken: Token,
|
|
87
|
+
side: SwapSide,
|
|
88
|
+
blockNumber: number,
|
|
89
|
+
): Promise<string[]> {
|
|
90
|
+
if (side === SwapSide.BUY || !this.pool) return [];
|
|
91
|
+
const srcAddress = this.dexHelper.config
|
|
92
|
+
.wrapETH(srcToken)
|
|
93
|
+
.address.toLowerCase();
|
|
94
|
+
const destAddress = this.dexHelper.config
|
|
95
|
+
.wrapETH(destToken)
|
|
96
|
+
.address.toLowerCase();
|
|
97
|
+
if (
|
|
98
|
+
srcAddress !== destAddress &&
|
|
99
|
+
this.supportedTokensMap[srcAddress] &&
|
|
100
|
+
this.supportedTokensMap[destAddress]
|
|
101
|
+
) {
|
|
102
|
+
return [`${this.dexKey}_${srcAddress}`, `${this.dexKey}_${destAddress}`];
|
|
103
|
+
}
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Returns pool prices for amounts.
|
|
108
|
+
// If limitPools is defined only pools in limitPools
|
|
109
|
+
// should be used. If limitPools is undefined then
|
|
110
|
+
// any pools can be used.
|
|
111
|
+
async getPricesVolume(
|
|
112
|
+
srcToken: Token,
|
|
113
|
+
destToken: Token,
|
|
114
|
+
amounts: bigint[],
|
|
115
|
+
side: SwapSide,
|
|
116
|
+
blockNumber: number,
|
|
117
|
+
limitPools?: string[],
|
|
118
|
+
): Promise<null | ExchangePrices<QuickPerpsData>> {
|
|
119
|
+
if (side === SwapSide.BUY || !this.pool) return null;
|
|
120
|
+
try {
|
|
121
|
+
const srcAddress = this.dexHelper.config
|
|
122
|
+
.wrapETH(srcToken)
|
|
123
|
+
.address.toLowerCase();
|
|
124
|
+
const destAddress = this.dexHelper.config
|
|
125
|
+
.wrapETH(destToken)
|
|
126
|
+
.address.toLowerCase();
|
|
127
|
+
if (
|
|
128
|
+
srcAddress === destAddress ||
|
|
129
|
+
!(
|
|
130
|
+
this.supportedTokensMap[srcAddress] &&
|
|
131
|
+
this.supportedTokensMap[destAddress]
|
|
132
|
+
)
|
|
133
|
+
)
|
|
134
|
+
return null;
|
|
135
|
+
const srcPoolIdentifier = `${this.dexKey}_${srcAddress}`;
|
|
136
|
+
const destPoolIdentifier = `${this.dexKey}_${destAddress}`;
|
|
137
|
+
const pools = [srcPoolIdentifier, destPoolIdentifier];
|
|
138
|
+
if (limitPools && pools.some(p => !limitPools.includes(p))) return null;
|
|
139
|
+
|
|
140
|
+
const unitVolume = getBigIntPow(srcToken.decimals);
|
|
141
|
+
const prices = await this.pool.getAmountOut(
|
|
142
|
+
srcAddress,
|
|
143
|
+
destAddress,
|
|
144
|
+
[unitVolume, ...amounts],
|
|
145
|
+
blockNumber,
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
if (!prices) return null;
|
|
149
|
+
|
|
150
|
+
return [
|
|
151
|
+
{
|
|
152
|
+
prices: prices.slice(1),
|
|
153
|
+
unit: prices[0],
|
|
154
|
+
gasCost: QuickPerpsGasCost,
|
|
155
|
+
exchange: this.dexKey,
|
|
156
|
+
data: {},
|
|
157
|
+
poolAddresses: [this.params.vault],
|
|
158
|
+
},
|
|
159
|
+
];
|
|
160
|
+
} catch (e) {
|
|
161
|
+
this.logger.error(
|
|
162
|
+
`Error_getPrices ${srcToken.symbol || srcToken.address}, ${
|
|
163
|
+
destToken.symbol || destToken.address
|
|
164
|
+
}, ${side}: `,
|
|
165
|
+
e,
|
|
166
|
+
);
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
172
|
+
getCalldataGasCost(
|
|
173
|
+
poolPrices: PoolPrices<QuickPerpsData>,
|
|
174
|
+
): number | number[] {
|
|
175
|
+
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
getAdapterParam(
|
|
179
|
+
srcToken: string,
|
|
180
|
+
destToken: string,
|
|
181
|
+
srcAmount: string,
|
|
182
|
+
destAmount: string,
|
|
183
|
+
data: QuickPerpsData,
|
|
184
|
+
side: SwapSide,
|
|
185
|
+
): AdapterExchangeParam {
|
|
186
|
+
return {
|
|
187
|
+
targetExchange: this.params.vault,
|
|
188
|
+
payload: '0x',
|
|
189
|
+
networkFee: '0',
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
getSimpleParam(
|
|
194
|
+
srcToken: string,
|
|
195
|
+
destToken: string,
|
|
196
|
+
srcAmount: string,
|
|
197
|
+
destAmount: string,
|
|
198
|
+
data: QuickPerpsData,
|
|
199
|
+
side: SwapSide,
|
|
200
|
+
): SimpleExchangeParam {
|
|
201
|
+
return {
|
|
202
|
+
callees: [srcToken, this.params.vault],
|
|
203
|
+
calldata: [
|
|
204
|
+
QuickPerps.erc20Interface.encodeFunctionData('transfer', [
|
|
205
|
+
this.params.vault,
|
|
206
|
+
srcAmount,
|
|
207
|
+
]),
|
|
208
|
+
Vault.interface.encodeFunctionData('swap', [
|
|
209
|
+
srcToken,
|
|
210
|
+
destToken,
|
|
211
|
+
this.augustusAddress,
|
|
212
|
+
]),
|
|
213
|
+
],
|
|
214
|
+
values: ['0', '0'],
|
|
215
|
+
networkFee: '0',
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async updatePoolState(): Promise<void> {
|
|
220
|
+
if (!this.supportedTokens.length) {
|
|
221
|
+
const tokenAddresses = await QuickPerpsEventPool.getWhitelistedTokens(
|
|
222
|
+
this.params.vault,
|
|
223
|
+
'latest',
|
|
224
|
+
this.dexHelper.multiContract,
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
const decimalsCallData =
|
|
228
|
+
QuickPerps.erc20Interface.encodeFunctionData('decimals');
|
|
229
|
+
const tokenBalanceMultiCall = tokenAddresses.map(t => ({
|
|
230
|
+
target: t,
|
|
231
|
+
callData: decimalsCallData,
|
|
232
|
+
}));
|
|
233
|
+
const res = (
|
|
234
|
+
await this.dexHelper.multiContract.methods
|
|
235
|
+
.aggregate(tokenBalanceMultiCall)
|
|
236
|
+
.call()
|
|
237
|
+
).returnData;
|
|
238
|
+
|
|
239
|
+
const tokenDecimals = res.map((r: any) =>
|
|
240
|
+
parseInt(
|
|
241
|
+
QuickPerps.erc20Interface
|
|
242
|
+
.decodeFunctionResult('decimals', r)[0]
|
|
243
|
+
.toString(),
|
|
244
|
+
),
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
this.supportedTokens = tokenAddresses.map((t, i) => ({
|
|
248
|
+
address: t,
|
|
249
|
+
decimals: tokenDecimals[i],
|
|
250
|
+
}));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const erc20BalanceCalldata = QuickPerps.erc20Interface.encodeFunctionData(
|
|
254
|
+
'balanceOf',
|
|
255
|
+
[this.params.vault],
|
|
256
|
+
);
|
|
257
|
+
const tokenBalanceMultiCall = this.supportedTokens.map(t => ({
|
|
258
|
+
target: t.address,
|
|
259
|
+
callData: erc20BalanceCalldata,
|
|
260
|
+
}));
|
|
261
|
+
const res = (
|
|
262
|
+
await this.dexHelper.multiContract.methods
|
|
263
|
+
.aggregate(tokenBalanceMultiCall)
|
|
264
|
+
.call()
|
|
265
|
+
).returnData;
|
|
266
|
+
const tokenBalances = res.map((r: any) =>
|
|
267
|
+
BigInt(
|
|
268
|
+
QuickPerps.erc20Interface
|
|
269
|
+
.decodeFunctionResult('balanceOf', r)[0]
|
|
270
|
+
.toString(),
|
|
271
|
+
),
|
|
272
|
+
);
|
|
273
|
+
const tokenBalancesUSD = await Promise.all(
|
|
274
|
+
this.supportedTokens.map((t, i) =>
|
|
275
|
+
this.dexHelper.getTokenUSDPrice(t, tokenBalances[i]),
|
|
276
|
+
),
|
|
277
|
+
);
|
|
278
|
+
this.vaultUSDBalance = tokenBalancesUSD.reduce(
|
|
279
|
+
(sum: number, curr: number) => sum + curr,
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Returns list of top pools based on liquidity. Max
|
|
284
|
+
// limit number pools should be returned.
|
|
285
|
+
async getTopPoolsForToken(
|
|
286
|
+
_tokenAddress: Address,
|
|
287
|
+
limit: number,
|
|
288
|
+
): Promise<PoolLiquidity[]> {
|
|
289
|
+
const tokenAddress = _tokenAddress.toLowerCase();
|
|
290
|
+
if (!this.supportedTokens.some(t => t.address === tokenAddress)) return [];
|
|
291
|
+
return [
|
|
292
|
+
{
|
|
293
|
+
exchange: this.dexKey,
|
|
294
|
+
address: this.params.vault,
|
|
295
|
+
connectorTokens: this.supportedTokens.filter(
|
|
296
|
+
t => t.address !== tokenAddress,
|
|
297
|
+
),
|
|
298
|
+
liquidityUSD: this.vaultUSDBalance,
|
|
299
|
+
},
|
|
300
|
+
];
|
|
301
|
+
}
|
|
302
|
+
}
|