@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,97 @@
|
|
|
1
|
+
import { Address } from '../../types';
|
|
2
|
+
import { Api3FeedSubscriberState } from '../../lib/api3-feed';
|
|
3
|
+
|
|
4
|
+
export type PoolState = {
|
|
5
|
+
primaryPrices: { [poolAddress: string]: Api3FeedSubscriberState };
|
|
6
|
+
secondaryPrices: FastPriceFeedState;
|
|
7
|
+
vault: VaultState;
|
|
8
|
+
usdq: USDQState;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type FastPriceFeedState = {
|
|
12
|
+
lastUpdatedAt: number;
|
|
13
|
+
prices: { [tokenAddress: string]: bigint };
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type VaultState = {
|
|
17
|
+
usdqAmounts: { [tokenAddress: string]: bigint };
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type USDQState = {
|
|
21
|
+
totalSupply: bigint;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type QuickPerpsData = {
|
|
25
|
+
// TODO: QuickPerpsData is the dex data that is
|
|
26
|
+
// returned by the API that can be used for
|
|
27
|
+
// tx building. The data structure should be minimal.
|
|
28
|
+
// Complete me!
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type DexParams = {
|
|
32
|
+
vault: Address;
|
|
33
|
+
reader: Address;
|
|
34
|
+
priceFeed: Address;
|
|
35
|
+
fastPriceFeed: Address;
|
|
36
|
+
fastPriceEvents: Address;
|
|
37
|
+
// Last three param can be fetched on chain by calling
|
|
38
|
+
// vaultAddress.priceFeed() => priceFeed
|
|
39
|
+
// priceFeed.secondaryPriceFeed() => fastPriceFeed
|
|
40
|
+
// fastPriceFeed.fastPriceEvents() => fastPriceEvents
|
|
41
|
+
// It is added as constants to avoid unnecessary
|
|
42
|
+
// sequential onchain calls
|
|
43
|
+
usdq: Address;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type FastPriceFeedConfig = {
|
|
47
|
+
priceDuration: number;
|
|
48
|
+
maxDeviationBasisPoints: bigint;
|
|
49
|
+
favorFastPrice: Record<string, boolean>;
|
|
50
|
+
spreadBasisPointsIfInactive: bigint;
|
|
51
|
+
spreadBasisPointsIfChainError: bigint;
|
|
52
|
+
maxPriceUpdateDelay: number;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type VaultPriceFeedConfig = {
|
|
56
|
+
isSecondaryPriceEnabled: boolean;
|
|
57
|
+
strictStableTokens: { [address: string]: boolean };
|
|
58
|
+
spreadBasisPoints: { [address: string]: bigint };
|
|
59
|
+
adjustmentBasisPoints: { [address: string]: bigint };
|
|
60
|
+
isAdjustmentAdditive: { [address: string]: boolean };
|
|
61
|
+
priceDecimals: { [address: string]: number };
|
|
62
|
+
maxStrictPriceDeviation: bigint;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type VaultConfig = {
|
|
66
|
+
tokenDecimals: { [address: string]: number };
|
|
67
|
+
stableTokens: { [address: string]: boolean };
|
|
68
|
+
tokenWeights: { [address: string]: bigint };
|
|
69
|
+
stableSwapFeeBasisPoints: bigint;
|
|
70
|
+
swapFeeBasisPoints: bigint;
|
|
71
|
+
stableTaxBasisPoints: bigint;
|
|
72
|
+
taxBasisPoints: bigint;
|
|
73
|
+
hasDynamicFees: bigint;
|
|
74
|
+
includeAmmPrice: boolean;
|
|
75
|
+
useSwapPricing: boolean;
|
|
76
|
+
totalTokenWeights: bigint;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type PoolConfig = {
|
|
80
|
+
vaultAddress: Address;
|
|
81
|
+
readerAddress: Address;
|
|
82
|
+
priceFeed: Address;
|
|
83
|
+
fastPriceFeed: Address;
|
|
84
|
+
fastPriceEvents: Address;
|
|
85
|
+
usdqAddress: Address;
|
|
86
|
+
tokenAddresses: Address[];
|
|
87
|
+
vaultConfig: VaultConfig;
|
|
88
|
+
vaultPriceFeedConfig: VaultPriceFeedConfig;
|
|
89
|
+
fastPriceFeedConfig: FastPriceFeedConfig;
|
|
90
|
+
api3ServerV1: {
|
|
91
|
+
[address: string]: {
|
|
92
|
+
proxy: Address;
|
|
93
|
+
api3ServerV1: Address;
|
|
94
|
+
dataFeedId: string;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import { Interface } from '@ethersproject/abi';
|
|
3
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
4
|
+
import { PartialEventSubscriber } from '../../composed-event-subscriber';
|
|
5
|
+
import {
|
|
6
|
+
Address,
|
|
7
|
+
MultiCallInput,
|
|
8
|
+
MultiCallOutput,
|
|
9
|
+
Logger,
|
|
10
|
+
Log,
|
|
11
|
+
BlockHeader,
|
|
12
|
+
} from '../../types';
|
|
13
|
+
import { USDQState } from './types';
|
|
14
|
+
import ERC20ABI from '../../abi/erc20.json';
|
|
15
|
+
import { Lens } from '../../lens';
|
|
16
|
+
import { NULL_ADDRESS } from '../../constants';
|
|
17
|
+
|
|
18
|
+
export class USDQ<State> extends PartialEventSubscriber<State, USDQState> {
|
|
19
|
+
static readonly interface = new Interface(ERC20ABI);
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
private usdqAddress: Address,
|
|
23
|
+
lens: Lens<DeepReadonly<State>, DeepReadonly<USDQState>>,
|
|
24
|
+
logger: Logger,
|
|
25
|
+
) {
|
|
26
|
+
super([usdqAddress], lens, logger);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
getTotalSupply(state: DeepReadonly<State>) {
|
|
30
|
+
return this.lens.get()(state).totalSupply;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public processLog(
|
|
34
|
+
state: DeepReadonly<USDQState>,
|
|
35
|
+
log: Readonly<Log>,
|
|
36
|
+
blockHeader: Readonly<BlockHeader>,
|
|
37
|
+
): DeepReadonly<USDQState> | null {
|
|
38
|
+
try {
|
|
39
|
+
const parsed = USDQ.interface.parseLog(log);
|
|
40
|
+
const _state: USDQState = _.cloneDeep(state);
|
|
41
|
+
switch (parsed.name) {
|
|
42
|
+
case 'Transfer': {
|
|
43
|
+
const fromAddress = parsed.args.src;
|
|
44
|
+
const toAddress = parsed.args.dst;
|
|
45
|
+
if (fromAddress === NULL_ADDRESS) {
|
|
46
|
+
_state.totalSupply += BigInt(parsed.args.wad.toString());
|
|
47
|
+
} else if (toAddress === NULL_ADDRESS) {
|
|
48
|
+
_state.totalSupply -= BigInt(parsed.args.wad.toString());
|
|
49
|
+
}
|
|
50
|
+
return _state;
|
|
51
|
+
}
|
|
52
|
+
default:
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
} catch (e) {
|
|
56
|
+
this.logger.error('Failed to parse log', e);
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public getGenerateStateMultiCallInputs(): MultiCallInput[] {
|
|
62
|
+
return [
|
|
63
|
+
{
|
|
64
|
+
target: this.usdqAddress,
|
|
65
|
+
callData: USDQ.interface.encodeFunctionData('totalSupply'),
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public generateState(
|
|
71
|
+
multicallOutputs: MultiCallOutput[],
|
|
72
|
+
blockNumber?: number | 'latest',
|
|
73
|
+
): DeepReadonly<USDQState> {
|
|
74
|
+
return {
|
|
75
|
+
totalSupply: BigInt(
|
|
76
|
+
USDQ.interface.decodeFunctionResult(
|
|
77
|
+
'totalSupply',
|
|
78
|
+
multicallOutputs[0],
|
|
79
|
+
)[0],
|
|
80
|
+
),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { Address, MultiCallInput, MultiCallOutput } from '../../types';
|
|
3
|
+
import { VaultPriceFeedConfig } from './types';
|
|
4
|
+
import { FastPriceFeed } from './fast-price-feed';
|
|
5
|
+
import VaultPriceFeedAbi from '../../abi/quick-perps/vault-price-feed.json';
|
|
6
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
7
|
+
import { Api3FeedSubscriber } from '../../lib/api3-feed';
|
|
8
|
+
|
|
9
|
+
export class VaultPriceFeed<State> {
|
|
10
|
+
BASIS_POINTS_DIVISOR = 10000n;
|
|
11
|
+
PRICE_PRECISION = 10n ** 30n;
|
|
12
|
+
ONE_USD = this.PRICE_PRECISION;
|
|
13
|
+
|
|
14
|
+
static interface = new Interface(VaultPriceFeedAbi);
|
|
15
|
+
|
|
16
|
+
protected isSecondaryPriceEnabled: boolean;
|
|
17
|
+
protected strictStableTokens: { [address: string]: boolean };
|
|
18
|
+
protected spreadBasisPoints: { [address: string]: bigint };
|
|
19
|
+
protected adjustmentBasisPoints: { [address: string]: bigint };
|
|
20
|
+
protected isAdjustmentAdditive: { [address: string]: boolean };
|
|
21
|
+
protected priceDecimals: { [address: string]: number };
|
|
22
|
+
protected maxStrictPriceDeviation: bigint;
|
|
23
|
+
|
|
24
|
+
constructor(
|
|
25
|
+
config: VaultPriceFeedConfig,
|
|
26
|
+
protected primaryPrices: { [token: string]: Api3FeedSubscriber<State> },
|
|
27
|
+
protected secondaryPrice: FastPriceFeed<State>,
|
|
28
|
+
) {
|
|
29
|
+
this.isSecondaryPriceEnabled = config.isSecondaryPriceEnabled;
|
|
30
|
+
this.strictStableTokens = config.strictStableTokens;
|
|
31
|
+
this.spreadBasisPoints = config.spreadBasisPoints;
|
|
32
|
+
this.adjustmentBasisPoints = config.adjustmentBasisPoints;
|
|
33
|
+
this.isAdjustmentAdditive = config.isAdjustmentAdditive;
|
|
34
|
+
this.priceDecimals = config.priceDecimals;
|
|
35
|
+
this.maxStrictPriceDeviation = config.maxStrictPriceDeviation;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getPrice(
|
|
39
|
+
state: DeepReadonly<State>,
|
|
40
|
+
_token: Address,
|
|
41
|
+
_maximize: boolean,
|
|
42
|
+
_includeAmmPrice: boolean,
|
|
43
|
+
_useSwapPricing: boolean,
|
|
44
|
+
): bigint {
|
|
45
|
+
let price = this.getPriceV1(state, _token, _maximize, _includeAmmPrice);
|
|
46
|
+
|
|
47
|
+
const adjustmentBps = this.adjustmentBasisPoints[_token];
|
|
48
|
+
if (adjustmentBps > 0n) {
|
|
49
|
+
const isAdditive = this.isAdjustmentAdditive[_token];
|
|
50
|
+
if (isAdditive) {
|
|
51
|
+
price =
|
|
52
|
+
(price * (this.BASIS_POINTS_DIVISOR + adjustmentBps)) /
|
|
53
|
+
this.BASIS_POINTS_DIVISOR;
|
|
54
|
+
} else {
|
|
55
|
+
price =
|
|
56
|
+
(price * (this.BASIS_POINTS_DIVISOR - adjustmentBps)) /
|
|
57
|
+
this.BASIS_POINTS_DIVISOR;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return price;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getPriceV1(
|
|
65
|
+
state: DeepReadonly<State>,
|
|
66
|
+
_token: Address,
|
|
67
|
+
_maximize: boolean,
|
|
68
|
+
_includeAmmPrice: boolean,
|
|
69
|
+
): bigint {
|
|
70
|
+
let price = this.getPrimaryPrice(state, _token, _maximize);
|
|
71
|
+
|
|
72
|
+
if (this.isSecondaryPriceEnabled) {
|
|
73
|
+
price = this.getSecondaryPrice(state, _token, price, _maximize);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (this.strictStableTokens[_token]) {
|
|
77
|
+
const delta =
|
|
78
|
+
price > this.ONE_USD ? price - this.ONE_USD : this.ONE_USD - price;
|
|
79
|
+
if (delta <= this.maxStrictPriceDeviation) {
|
|
80
|
+
return this.ONE_USD;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// if _maximize and price is e.g. 1.02, return 1.02
|
|
84
|
+
if (_maximize && price > this.ONE_USD) {
|
|
85
|
+
return price;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// if !_maximize and price is e.g. 0.98, return 0.98
|
|
89
|
+
if (!_maximize && price < this.ONE_USD) {
|
|
90
|
+
return price;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return this.ONE_USD;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const _spreadBasisPoints = this.spreadBasisPoints[_token];
|
|
97
|
+
|
|
98
|
+
if (_maximize) {
|
|
99
|
+
return (
|
|
100
|
+
(price * (this.BASIS_POINTS_DIVISOR + _spreadBasisPoints)) /
|
|
101
|
+
this.BASIS_POINTS_DIVISOR
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
(price * (this.BASIS_POINTS_DIVISOR - _spreadBasisPoints)) /
|
|
107
|
+
this.BASIS_POINTS_DIVISOR
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
getAmmPrice(state: DeepReadonly<State>, token: Address): bigint {
|
|
112
|
+
throw new Error(
|
|
113
|
+
'getAmmPrice implementation is not complete, developers should disable the dex or complete the implementation',
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
getPrimaryPrice(
|
|
118
|
+
state: DeepReadonly<State>,
|
|
119
|
+
_token: Address,
|
|
120
|
+
_maximize: boolean,
|
|
121
|
+
): bigint {
|
|
122
|
+
// const priceFeedAddress = this.priceFeeds[_token];
|
|
123
|
+
// require(priceFeedAddress != address(0), "VaultPriceFeed: invalid price feed");
|
|
124
|
+
|
|
125
|
+
// if (chainlinkFlags != address(0)) {
|
|
126
|
+
// bool isRaised = IChainlinkFlags(chainlinkFlags).getFlag(FLAG_ARBITRUM_SEQ_OFFLINE);
|
|
127
|
+
// if (isRaised) {
|
|
128
|
+
// // If flag is raised we shouldn't perform any critical operations
|
|
129
|
+
// revert("Chainlink feeds are not being updated");
|
|
130
|
+
// }
|
|
131
|
+
// }
|
|
132
|
+
|
|
133
|
+
// IPriceFeed priceFeed = IPriceFeed(priceFeedAddress);
|
|
134
|
+
let price = 0n;
|
|
135
|
+
// const roundId = priceFeed.latestRound;
|
|
136
|
+
|
|
137
|
+
// for (let i = 0; i < this.priceSampleSpace; i++) {
|
|
138
|
+
// if (roundId <= i) {
|
|
139
|
+
// break;
|
|
140
|
+
// }
|
|
141
|
+
|
|
142
|
+
// if (i == 0) {
|
|
143
|
+
// const _p = priceFeed.latestAnswer();
|
|
144
|
+
// require(_p > 0, "VaultPriceFeed: invalid price");
|
|
145
|
+
// p = uint256(_p);
|
|
146
|
+
// } else {
|
|
147
|
+
// (, int256 _p, , ,) = priceFeed.getRoundData(roundId - i);
|
|
148
|
+
// require(_p > 0, "VaultPriceFeed: invalid price");
|
|
149
|
+
// p = uint256(_p);
|
|
150
|
+
// }
|
|
151
|
+
|
|
152
|
+
// if (price == 0n) {
|
|
153
|
+
// price = p;
|
|
154
|
+
// continue;
|
|
155
|
+
// }
|
|
156
|
+
|
|
157
|
+
// if (_maximize && p > price) {
|
|
158
|
+
// price = p;
|
|
159
|
+
// continue;
|
|
160
|
+
// }
|
|
161
|
+
|
|
162
|
+
// if (!_maximize && p < price) {
|
|
163
|
+
// price = p;
|
|
164
|
+
// }
|
|
165
|
+
// }
|
|
166
|
+
price = this.primaryPrices[_token].getLatestData(state);
|
|
167
|
+
|
|
168
|
+
// require(price > 0n, "VaultPriceFeed: could not fetch price");
|
|
169
|
+
if (price <= 0n) throw new Error('VaultPriceFeed: could not fetch price');
|
|
170
|
+
// normalize price precision
|
|
171
|
+
const _priceDecimals = this.priceDecimals[_token];
|
|
172
|
+
return (price * this.PRICE_PRECISION) / BigInt(10 ** _priceDecimals);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
getSecondaryPrice(
|
|
176
|
+
state: DeepReadonly<State>,
|
|
177
|
+
_token: Address,
|
|
178
|
+
_referencePrice: bigint,
|
|
179
|
+
_maximize: boolean,
|
|
180
|
+
): bigint {
|
|
181
|
+
return this.secondaryPrice.getPrice(
|
|
182
|
+
state,
|
|
183
|
+
_token,
|
|
184
|
+
_referencePrice,
|
|
185
|
+
_maximize,
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
static getConfigMulticallInputs(
|
|
190
|
+
vaultPriceFeedAddress: Address,
|
|
191
|
+
tokenAddresses: Address[],
|
|
192
|
+
): MultiCallInput[] {
|
|
193
|
+
return [
|
|
194
|
+
{
|
|
195
|
+
target: vaultPriceFeedAddress,
|
|
196
|
+
callData: VaultPriceFeed.interface.encodeFunctionData(
|
|
197
|
+
'isSecondaryPriceEnabled',
|
|
198
|
+
),
|
|
199
|
+
},
|
|
200
|
+
...tokenAddresses.map(t => ({
|
|
201
|
+
target: vaultPriceFeedAddress,
|
|
202
|
+
callData: VaultPriceFeed.interface.encodeFunctionData(
|
|
203
|
+
'strictStableTokens',
|
|
204
|
+
[t],
|
|
205
|
+
),
|
|
206
|
+
})),
|
|
207
|
+
...tokenAddresses.map(t => ({
|
|
208
|
+
target: vaultPriceFeedAddress,
|
|
209
|
+
callData: VaultPriceFeed.interface.encodeFunctionData(
|
|
210
|
+
'spreadBasisPoints',
|
|
211
|
+
[t],
|
|
212
|
+
),
|
|
213
|
+
})),
|
|
214
|
+
...tokenAddresses.map(t => ({
|
|
215
|
+
target: vaultPriceFeedAddress,
|
|
216
|
+
callData: VaultPriceFeed.interface.encodeFunctionData(
|
|
217
|
+
'isAdjustmentAdditive',
|
|
218
|
+
[t],
|
|
219
|
+
),
|
|
220
|
+
})),
|
|
221
|
+
...tokenAddresses.map(t => ({
|
|
222
|
+
target: vaultPriceFeedAddress,
|
|
223
|
+
callData: VaultPriceFeed.interface.encodeFunctionData(
|
|
224
|
+
'adjustmentBasisPoints',
|
|
225
|
+
[t],
|
|
226
|
+
),
|
|
227
|
+
})),
|
|
228
|
+
...tokenAddresses.map(t => ({
|
|
229
|
+
target: vaultPriceFeedAddress,
|
|
230
|
+
callData: VaultPriceFeed.interface.encodeFunctionData('priceDecimals', [
|
|
231
|
+
t,
|
|
232
|
+
]),
|
|
233
|
+
})),
|
|
234
|
+
{
|
|
235
|
+
target: vaultPriceFeedAddress,
|
|
236
|
+
callData: VaultPriceFeed.interface.encodeFunctionData(
|
|
237
|
+
'maxStrictPriceDeviation',
|
|
238
|
+
),
|
|
239
|
+
},
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
static getConfig(
|
|
244
|
+
multicallOutputs: MultiCallOutput[],
|
|
245
|
+
tokenAddress: Address[],
|
|
246
|
+
): VaultPriceFeedConfig {
|
|
247
|
+
let i = 0;
|
|
248
|
+
return {
|
|
249
|
+
isSecondaryPriceEnabled: VaultPriceFeed.interface.decodeFunctionResult(
|
|
250
|
+
'isSecondaryPriceEnabled',
|
|
251
|
+
multicallOutputs[i++],
|
|
252
|
+
)[0],
|
|
253
|
+
strictStableTokens: tokenAddress.reduce(
|
|
254
|
+
(acc: { [address: string]: boolean }, t: Address) => {
|
|
255
|
+
acc[t] = VaultPriceFeed.interface.decodeFunctionResult(
|
|
256
|
+
'strictStableTokens',
|
|
257
|
+
multicallOutputs[i++],
|
|
258
|
+
)[0];
|
|
259
|
+
return acc;
|
|
260
|
+
},
|
|
261
|
+
{},
|
|
262
|
+
),
|
|
263
|
+
spreadBasisPoints: tokenAddress.reduce(
|
|
264
|
+
(acc: { [address: string]: bigint }, t: Address) => {
|
|
265
|
+
acc[t] = BigInt(
|
|
266
|
+
VaultPriceFeed.interface
|
|
267
|
+
.decodeFunctionResult(
|
|
268
|
+
'spreadBasisPoints',
|
|
269
|
+
multicallOutputs[i++],
|
|
270
|
+
)[0]
|
|
271
|
+
.toString(),
|
|
272
|
+
);
|
|
273
|
+
return acc;
|
|
274
|
+
},
|
|
275
|
+
{},
|
|
276
|
+
),
|
|
277
|
+
isAdjustmentAdditive: tokenAddress.reduce(
|
|
278
|
+
(acc: { [address: string]: boolean }, t: Address) => {
|
|
279
|
+
acc[t] = VaultPriceFeed.interface.decodeFunctionResult(
|
|
280
|
+
'isAdjustmentAdditive',
|
|
281
|
+
multicallOutputs[i++],
|
|
282
|
+
)[0];
|
|
283
|
+
return acc;
|
|
284
|
+
},
|
|
285
|
+
{},
|
|
286
|
+
),
|
|
287
|
+
adjustmentBasisPoints: tokenAddress.reduce(
|
|
288
|
+
(acc: { [address: string]: bigint }, t: Address) => {
|
|
289
|
+
acc[t] = BigInt(
|
|
290
|
+
VaultPriceFeed.interface
|
|
291
|
+
.decodeFunctionResult(
|
|
292
|
+
'adjustmentBasisPoints',
|
|
293
|
+
multicallOutputs[i++],
|
|
294
|
+
)[0]
|
|
295
|
+
.toString(),
|
|
296
|
+
);
|
|
297
|
+
return acc;
|
|
298
|
+
},
|
|
299
|
+
{},
|
|
300
|
+
),
|
|
301
|
+
priceDecimals: tokenAddress.reduce(
|
|
302
|
+
(acc: { [address: string]: number }, t: Address) => {
|
|
303
|
+
acc[t] = parseInt(
|
|
304
|
+
VaultPriceFeed.interface
|
|
305
|
+
.decodeFunctionResult('priceDecimals', multicallOutputs[i++])[0]
|
|
306
|
+
.toString(),
|
|
307
|
+
);
|
|
308
|
+
return acc;
|
|
309
|
+
},
|
|
310
|
+
{},
|
|
311
|
+
),
|
|
312
|
+
maxStrictPriceDeviation: BigInt(
|
|
313
|
+
VaultPriceFeed.interface
|
|
314
|
+
.decodeFunctionResult(
|
|
315
|
+
'maxStrictPriceDeviation',
|
|
316
|
+
multicallOutputs[i++],
|
|
317
|
+
)[0]
|
|
318
|
+
.toString(),
|
|
319
|
+
),
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Vault } from './vault';
|
|
2
|
+
import { Address } from '../../types';
|
|
3
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
4
|
+
|
|
5
|
+
export class VaultUtils<State> {
|
|
6
|
+
constructor(protected vault: Vault<State>) {}
|
|
7
|
+
|
|
8
|
+
getFeeBasisPoints(
|
|
9
|
+
state: DeepReadonly<State>,
|
|
10
|
+
_token: Address,
|
|
11
|
+
_usdqDelta: bigint,
|
|
12
|
+
_feeBasisPoints: bigint,
|
|
13
|
+
_taxBasisPoints: bigint,
|
|
14
|
+
_increment: boolean,
|
|
15
|
+
) {
|
|
16
|
+
if (!this.vault.hasDynamicFees) {
|
|
17
|
+
return _feeBasisPoints;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const initialAmount = this.vault.getUSDQAmount(state, _token);
|
|
21
|
+
let nextAmount = initialAmount + _usdqDelta;
|
|
22
|
+
if (!_increment) {
|
|
23
|
+
nextAmount = _usdqDelta > initialAmount ? 0n : initialAmount - _usdqDelta;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const targetAmount = this.vault.getTargetUsdqAmount(state, _token);
|
|
27
|
+
if (targetAmount == 0n) {
|
|
28
|
+
return _feeBasisPoints;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const initialDiff =
|
|
32
|
+
initialAmount > targetAmount
|
|
33
|
+
? initialAmount - targetAmount
|
|
34
|
+
: targetAmount - initialAmount;
|
|
35
|
+
const nextDiff =
|
|
36
|
+
nextAmount > targetAmount
|
|
37
|
+
? nextAmount - targetAmount
|
|
38
|
+
: targetAmount - nextAmount;
|
|
39
|
+
|
|
40
|
+
// action improves relative asset balance
|
|
41
|
+
if (nextDiff < initialDiff) {
|
|
42
|
+
const rebateBps = (_taxBasisPoints * initialDiff) / targetAmount;
|
|
43
|
+
return rebateBps > _feeBasisPoints ? 0n : _feeBasisPoints - rebateBps;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let averageDiff = (initialDiff + nextDiff) / 2n;
|
|
47
|
+
if (averageDiff > targetAmount) {
|
|
48
|
+
averageDiff = targetAmount;
|
|
49
|
+
}
|
|
50
|
+
const taxBps = (_taxBasisPoints * averageDiff) / targetAmount;
|
|
51
|
+
return _feeBasisPoints + taxBps;
|
|
52
|
+
}
|
|
53
|
+
}
|