@paraswap/dex-lib 4.1.20 → 4.1.21
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/aave-gsm/Pool.json +1459 -0
- package/build/dex/aave-gsm/aave-gsm-pool.d.ts +7 -1
- package/build/dex/aave-gsm/aave-gsm-pool.js +46 -4
- package/build/dex/aave-gsm/aave-gsm-pool.js.map +1 -1
- package/build/dex/aave-gsm/aave-gsm.js +37 -30
- package/build/dex/aave-gsm/aave-gsm.js.map +1 -1
- package/build/dex/aave-gsm/config.js +6 -5
- package/build/dex/aave-gsm/config.js.map +1 -1
- package/build/dex/aave-gsm/types.d.ts +5 -2
- package/build/dex/pancakeswap-v3/config.js +1 -1
- package/build/dex/pancakeswap-v3/config.js.map +1 -1
- package/build/dex/uniswap-v3/config.js +2 -2
- package/build/dex/uniswap-v3/config.js.map +1 -1
- package/build/dex/wombat/wombat.d.ts +0 -1
- package/build/dex/wombat/wombat.js +2 -44
- package/build/dex/wombat/wombat.js.map +1 -1
- package/build/dex/woo-fi-v2/config.js +16 -15
- package/build/dex/woo-fi-v2/config.js.map +1 -1
- package/package.json +1 -1
- package/.env.example +0 -15
- package/.eslintrc.js +0 -65
- package/.github/workflows/ci.yaml +0 -22
- package/.husky/pre-commit +0 -4
- package/.prettierrc +0 -10
- package/dex-template/__DexName__-e2e.test.ts.template +0 -155
- package/dex-template/__DexName__-events.test.ts.template +0 -110
- package/dex-template/__DexName__-integration.test.ts.template +0 -251
- package/dex-template/__DexName__-pool.ts.template +0 -91
- package/dex-template/__DexName__.ts.template +0 -156
- package/dex-template/config.ts.template +0 -9
- package/dex-template/types.ts.template +0 -22
- package/funding.json +0 -5
- package/jest.config.js +0 -10
- package/scripts/dex-integration.ts +0 -164
- package/scripts/fetch-event-blocknumber.ts +0 -51
- package/scripts/generate-bytecode.ts +0 -11
- package/scripts/run-dex-integration-v3.ts +0 -78
- package/scripts/run-dex-integration.ts +0 -95
- package/src/abi/AaveV2_lending_pool.json +0 -53
- package/src/abi/AaveV3_lending_pool.json +0 -1715
- package/src/abi/Balancer.json +0 -257
- package/src/abi/BalancerCustomMulticall.json +0 -26
- package/src/abi/BalancerV1ExchangeProxy.json +0 -377
- package/src/abi/BalancerV1Pool.json +0 -1630
- package/src/abi/BalancerV2.json +0 -1179
- package/src/abi/Bancor.json +0 -392
- package/src/abi/Compound_CETH.json +0 -12
- package/src/abi/Curve.json +0 -54
- package/src/abi/CurveV2.json +0 -700
- package/src/abi/DirectSwap.json +0 -1018
- package/src/abi/ERC1155.abi.json +0 -459
- package/src/abi/ERC1271.abi.json +0 -25
- package/src/abi/ERC20.abi.json +0 -288
- package/src/abi/ERC4626.json +0 -791
- package/src/abi/ERC721.abi.json +0 -165
- package/src/abi/IParaswap.json +0 -3059
- package/src/abi/RamsesV2Pool.abi.json +0 -1554
- package/src/abi/RamsesV2Quoter.abi.json +0 -274
- package/src/abi/RamsesV2StateMulticall.abi.json +0 -891
- package/src/abi/Redstone.json +0 -739
- package/src/abi/SSPM.json +0 -829
- package/src/abi/SimpleSwapHelperRouter.json +0 -38
- package/src/abi/Smoothy.json +0 -1049
- package/src/abi/StablePool.json +0 -1035
- package/src/abi/StaderOracle.json +0 -2170
- package/src/abi/TraderJoeV21Router.json +0 -1489
- package/src/abi/USDM.json +0 -807
- package/src/abi/UniswapV2ExchangeRouter.json +0 -84
- package/src/abi/UniswapV2Router.json +0 -397
- package/src/abi/UniswapV3Router.json +0 -274
- package/src/abi/aave-gsm/Aave_GSM.json +0 -751
- package/src/abi/aave-gsm/IFeeStrategy.json +0 -78
- package/src/abi/aave-v3-weth-gateway.json +0 -290
- package/src/abi/aave-weth-gateway-avalanche.json +0 -242
- package/src/abi/aave-weth-gateway-polygon.json +0 -242
- package/src/abi/aave-weth-gateway.json +0 -38
- package/src/abi/aavev3stata/Factory.json +0 -128
- package/src/abi/aavev3stata/Token.json +0 -735
- package/src/abi/aavev3statav2/Factory.json +0 -131
- package/src/abi/aavev3statav2/Pool.json +0 -1459
- package/src/abi/aavev3statav2/Token.json +0 -997
- package/src/abi/aerodrome/aerodrome-pool-factory.json +0 -586
- package/src/abi/algebra/AlgebraFactory-v1_1.abi.json +0 -250
- package/src/abi/algebra/AlgebraPool-v1_1.abi.json +0 -727
- package/src/abi/algebra/AlgebraPool-v1_9.abi.json +0 -756
- package/src/abi/algebra/AlgebraQuoter.abi.json +0 -138
- package/src/abi/algebra/AlgebraStateMulticall.abi.json +0 -801
- package/src/abi/algebra/SwapRouter.json +0 -281
- package/src/abi/angle/stagToken.json +0 -963
- package/src/abi/angle-transmuter/ChainlinkAccessControlledOffchainAggregator.json +0 -1246
- package/src/abi/angle-transmuter/ChainlinkEACAggregatorProxy.json +0 -509
- package/src/abi/angle-transmuter/MorphoOracle.json +0 -193
- package/src/abi/angle-transmuter/MorphoVault.json +0 -2506
- package/src/abi/angle-transmuter/Pyth.json +0 -1534
- package/src/abi/angle-transmuter/Transmuter.json +0 -1711
- package/src/abi/angle-transmuter/TransmuterSidechain.json +0 -1798
- package/src/abi/api3-proxy.json +0 -53
- package/src/abi/api3-server-v1.json +0 -463
- package/src/abi/augustus-v6/ABI.json +0 -1572
- package/src/abi/augustus.json +0 -375
- package/src/abi/balancer-v2/ComposableStable.json +0 -1391
- package/src/abi/balancer-v2/gyro-e.abi.json +0 -1595
- package/src/abi/balancer-v2/linearPoolAbi.json +0 -1062
- package/src/abi/balancer-v2/meta-stable-pool.json +0 -1437
- package/src/abi/balancer-v2/stable-pool.json +0 -1053
- package/src/abi/balancer-v2/vault.json +0 -918
- package/src/abi/balancer-v2/weighted-pool.json +0 -1142
- package/src/abi/balancer-v3/batch-router.json +0 -989
- package/src/abi/balancer-v3/directionalFeeHook.json +0 -684
- package/src/abi/balancer-v3/router.json +0 -1792
- package/src/abi/balancer-v3/stableSurgeHook.json +0 -976
- package/src/abi/balancer-v3/vault-extension.json +0 -2834
- package/src/abi/bebop/BebopSettlement.abi.json +0 -2137
- package/src/abi/benqi/staked-avax.json +0 -954
- package/src/abi/cables/CablesMainnetRFQ.json +0 -1083
- package/src/abi/camelot/CamelotFactory.json +0 -494
- package/src/abi/camelot/CamelotPair.json +0 -1027
- package/src/abi/chainlink.json +0 -323
- package/src/abi/concentrator/arUSD.json +0 -568
- package/src/abi/concentrator/arUSD5115.json +0 -1746
- package/src/abi/curve-v1/CurveBUSDv2.abi.json +0 -1356
- package/src/abi/curve-v1/CurveTokenV1.json +0 -305
- package/src/abi/curve-v1/CurveTokenV2.json +0 -318
- package/src/abi/curve-v1/CurveV1StableNg.json +0 -1452
- package/src/abi/curve-v1/CurveV2Swap.json +0 -700
- package/src/abi/curve-v1/FactoryCryptoRegistry.json +0 -316
- package/src/abi/curve-v1/FactoryRegistry.json +0 -508
- package/src/abi/curve-v1/StableSwap3Pool.json +0 -838
- package/src/abi/curve-v1/StableSwapAave.json +0 -1152
- package/src/abi/curve-v1/StableSwapBBTC.json +0 -1017
- package/src/abi/curve-v1/StableSwapBUSD.json +0 -814
- package/src/abi/curve-v1/StableSwapCompound.json +0 -814
- package/src/abi/curve-v1/StableSwapDUSD.json +0 -1004
- package/src/abi/curve-v1/StableSwapEURS.json +0 -868
- package/src/abi/curve-v1/StableSwapGUSD.json +0 -1004
- package/src/abi/curve-v1/StableSwapHBTC.json +0 -838
- package/src/abi/curve-v1/StableSwapHUSD.json +0 -1004
- package/src/abi/curve-v1/StableSwapIDLE.json +0 -1253
- package/src/abi/curve-v1/StableSwapLinkUSD.json +0 -1004
- package/src/abi/curve-v1/StableSwapMUSD.json +0 -1004
- package/src/abi/curve-v1/StableSwapOBTC.json +0 -1017
- package/src/abi/curve-v1/StableSwapPBTC.json +0 -1017
- package/src/abi/curve-v1/StableSwapPax.json +0 -865
- package/src/abi/curve-v1/StableSwapRSV.json +0 -1004
- package/src/abi/curve-v1/StableSwapRen.json +0 -851
- package/src/abi/curve-v1/StableSwapSBTC.json +0 -851
- package/src/abi/curve-v1/StableSwapSETH.json +0 -850
- package/src/abi/curve-v1/StableSwapSLINK.json +0 -899
- package/src/abi/curve-v1/StableSwapSTETH.json +0 -895
- package/src/abi/curve-v1/StableSwapSUSD.json +0 -760
- package/src/abi/curve-v1/StableSwapSnow.json +0 -900
- package/src/abi/curve-v1/StableSwapTBTC.json +0 -1017
- package/src/abi/curve-v1/StableSwapUSDK.json +0 -1004
- package/src/abi/curve-v1/StableSwapUSDN.json +0 -1004
- package/src/abi/curve-v1/StableSwapUSDT.json +0 -814
- package/src/abi/curve-v1/StableSwapUST.json +0 -1017
- package/src/abi/curve-v1/StableSwapY.json +0 -814
- package/src/abi/curve-v1-factory/CurveV1Router.abi.json +0 -331
- package/src/abi/curve-v1-factory/FactoryCurveV1.json +0 -508
- package/src/abi/curve-v1-factory/ThreePool.json +0 -468
- package/src/abi/curve-v2/GenericFactoryZap.json +0 -233
- package/src/abi/dexalot/DexalotMainnetRFQ.json +0 -952
- package/src/abi/dodo-v2-proxy.json +0 -565
- package/src/abi/ekubo/core.json +0 -1266
- package/src/abi/ekubo/data-fetcher.json +0 -161
- package/src/abi/ekubo/router.json +0 -803
- package/src/abi/erc20.json +0 -308
- package/src/abi/etherfi/eETHPool.json +0 -9
- package/src/abi/etherfi/weETH.json +0 -20
- package/src/abi/fluid-dex/dexFactory.abi.json +0 -506
- package/src/abi/fluid-dex/fluid-dex.abi.json +0 -1476
- package/src/abi/fluid-dex/liquidityUserModule.abi.json +0 -145
- package/src/abi/fluid-dex/resolver.abi.json +0 -2030
- package/src/abi/fx-protocol/FxMarket.json +0 -1284
- package/src/abi/fx-protocol/FxUSD.json +0 -1227
- package/src/abi/fx-protocol/weETHOralce.json +0 -676
- package/src/abi/gmx/fast-price-events.json +0 -70
- package/src/abi/gmx/fast-price-feed.json +0 -748
- package/src/abi/gmx/reader.json +0 -337
- package/src/abi/gmx/vault-price-feed.json +0 -477
- package/src/abi/gmx/vault.json +0 -2002
- package/src/abi/hashflow/HashflowRouter.abi.json +0 -1539
- package/src/abi/idle-dao/idle-cdo-factory.json +0 -38
- package/src/abi/idle-dao/idle-cdo.json +0 -1245
- package/src/abi/infusion/InfusionFactory.json +0 -147
- package/src/abi/infusion/InfusionPair.json +0 -658
- package/src/abi/infusion/InfusionRouter.json +0 -442
- package/src/abi/jarvis/ChainlinkAccessControlledOffchainAggregator.json +0 -1009
- package/src/abi/jarvis/SynthereumPriceFeed.json +0 -381
- package/src/abi/jarvis/jarvis-v6-pool.json +0 -1041
- package/src/abi/kyberdmm/kyber-dmm-exchange-router.abi.json +0 -1148
- package/src/abi/kyberdmm/kyber-dmm-factory.abi.json +0 -335
- package/src/abi/kyberdmm/kyber-dmm-pool.abi.json +0 -803
- package/src/abi/kyberdmm/kyber-storage.abi.json +0 -824
- package/src/abi/kyberdmm.abi.json +0 -1148
- package/src/abi/lite-psm/dai.json +0 -333
- package/src/abi/lite-psm/psm.json +0 -468
- package/src/abi/lite-psm/usdc.json +0 -814
- package/src/abi/lite-psm/usdsPsm.json +0 -163
- package/src/abi/m-token/WrappedM.abi.json +0 -1708
- package/src/abi/maker-psm/pot.json +0 -322
- package/src/abi/maker-psm/psm.json +0 -243
- package/src/abi/maker-psm/vat.json +0 -363
- package/src/abi/maverick-v1/pool-inspector.json +0 -216
- package/src/abi/maverick-v1/pool.json +0 -1111
- package/src/abi/maverick-v1/router.json +0 -389
- package/src/abi/maverick-v2/MaverickV2Pool.json +0 -1234
- package/src/abi/maverick-v2/MaverickV2PoolLens.json +0 -1232
- package/src/abi/maverick-v2/MaverickV2Quoter.json +0 -278
- package/src/abi/maverick-v2/MaverickV2Router.json +0 -778
- package/src/abi/multi-v2.json +0 -313
- package/src/abi/nerve/axial-pool.json +0 -693
- package/src/abi/nerve/iron-v2-pool.json +0 -785
- package/src/abi/nerve/nerve-metapool.json +0 -790
- package/src/abi/nerve/nerve-pool.json +0 -1035
- package/src/abi/nomiswap-v2/nomiswap-v2-pool.json +0 -773
- package/src/abi/oswap/oswap.abi.json +0 -452
- package/src/abi/pancakeswap-v3/PancakeV3StateMulticall.abi.json +0 -781
- package/src/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json +0 -300
- package/src/abi/pancakeswap-v3/PancakeswapV3Pool.abi.json +0 -1039
- package/src/abi/pancakeswap-v3/PancakeswapV3Quoter.abi.json +0 -285
- package/src/abi/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
- package/src/abi/paraswap-limit-orders/AugustusRFQ.abi.json +0 -1081
- package/src/abi/permit/IERC20Permit.json +0 -45
- package/src/abi/permit/IERC20PermitLegacy.json +0 -50
- package/src/abi/permit2.json +0 -581
- package/src/abi/polygon-migration/PolygonMigration.abi.json +0 -364
- package/src/abi/quick-perps/fast-price-events.json +0 -70
- package/src/abi/quick-perps/fast-price-feed.json +0 -741
- package/src/abi/quick-perps/reader.json +0 -313
- package/src/abi/quick-perps/vault-price-feed.json +0 -323
- package/src/abi/quick-perps/vault.json +0 -1953
- package/src/abi/ramses-v2/RamsesV2Pool.abi.json +0 -1599
- package/src/abi/rswETH.json +0 -1142
- package/src/abi/sdai/PSM3.abi.json +0 -721
- package/src/abi/sdai/SSRAuthOracle.abi.json +0 -522
- package/src/abi/sdai/SavingsDai.abi.json +0 -877
- package/src/abi/sdai/SavingsUSDS.abi.json +0 -720
- package/src/abi/sky-converter/DaiUsdsConverter.json +0 -116
- package/src/abi/sky-converter/MkrSkyConverter.json +0 -118
- package/src/abi/solidly/SolidlyFactory.json +0 -147
- package/src/abi/solidly/SolidlyPair.json +0 -658
- package/src/abi/solidly-v3/SolidlyV3Pool.abi.json +0 -738
- package/src/abi/solidly-v3/SolidlyV3StateMulticall.abi.json +0 -375
- package/src/abi/stETH.json +0 -735
- package/src/abi/stkGHO.json +0 -1131
- package/src/abi/swETH.json +0 -1086
- package/src/abi/swaap-v2/vault.json +0 -918
- package/src/abi/synthetix/CombinedSynthetix.abi.json +0 -422
- package/src/abi/uniswap-v2/biswap-pool.json +0 -501
- package/src/abi/uniswap-v2/excalibur-pool.json +0 -881
- package/src/abi/uniswap-v2/mdex-factory.json +0 -759
- package/src/abi/uniswap-v2/uniswap-v2-factory.json +0 -125
- package/src/abi/uniswap-v2/uniswap-v2-pool.json +0 -461
- package/src/abi/uniswap-v3/UniswapMulti.abi.json +0 -52
- package/src/abi/uniswap-v3/UniswapV3Factory.abi.json +0 -148
- package/src/abi/uniswap-v3/UniswapV3Pool.abi.json +0 -988
- package/src/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
- package/src/abi/uniswap-v3/UniswapV3QuoterV2.abi.json +0 -155
- package/src/abi/uniswap-v3/UniswapV3Router.abi.json +0 -274
- package/src/abi/uniswap-v3/UniswapV3StateMulticall.abi.json +0 -781
- package/src/abi/usual-bond/usd0pp.abi.json +0 -867
- package/src/abi/usual-m-usd0/usualCollateralDao.abi.json +0 -681
- package/src/abi/usual-m-wrapped-m/usualM.abi.json +0 -509
- package/src/abi/usual-pp/abi.json +0 -750
- package/src/abi/velodrome-slipstream/VelodromeSlipstreamFactory.abi.json +0 -579
- package/src/abi/velodrome-slipstream/VelodromeSlipstreamPool.abi.json +0 -1275
- package/src/abi/velodrome-slipstream/VelodromeSlipstreamQuoterV2.abi.json +0 -267
- package/src/abi/velodrome-slipstream/VelodromeSlipstreamStateMulticall.abi.json +0 -766
- package/src/abi/weth.abi.json +0 -153
- package/src/abi/wombat/asset.json +0 -743
- package/src/abi/wombat/bmw.json +0 -1247
- package/src/abi/wombat/pool-v2.json +0 -1289
- package/src/abi/wombat/pool-v3.json +0 -2013
- package/src/abi/woo-fi-v2/IntegrationHelper.abi.json +0 -116
- package/src/abi/woo-fi-v2/WooOracleV2.abi.json +0 -358
- package/src/abi/woo-fi-v2/WooPPV2.abi.json +0 -580
- package/src/abi/wstETH.json +0 -252
- package/src/bigint-constants.ts +0 -21
- package/src/bignumber-constants.ts +0 -20
- package/src/calldata-gas-cost.ts +0 -26
- package/src/composed-event-subscriber.ts +0 -131
- package/src/config.ts +0 -580
- package/src/constants.ts +0 -74
- package/src/dex/aave-gsm/aave-gsm-e2e.test.ts +0 -110
- package/src/dex/aave-gsm/aave-gsm-events.test.ts +0 -82
- package/src/dex/aave-gsm/aave-gsm-gas-estimation.test.ts +0 -32
- package/src/dex/aave-gsm/aave-gsm-integration.test.ts +0 -522
- package/src/dex/aave-gsm/aave-gsm-pool.ts +0 -225
- package/src/dex/aave-gsm/aave-gsm.ts +0 -431
- package/src/dex/aave-gsm/config.ts +0 -16
- package/src/dex/aave-gsm/types.ts +0 -24
- package/src/dex/aave-v2/aave-v2-e2e.test.ts +0 -287
- package/src/dex/aave-v2/aave-v2-gas-estimation.test.ts +0 -28
- package/src/dex/aave-v2/aave-v2-integration.test.ts +0 -100
- package/src/dex/aave-v2/aave-v2.ts +0 -409
- package/src/dex/aave-v2/config.ts +0 -56
- package/src/dex/aave-v2/tokenlist.json +0 -904
- package/src/dex/aave-v2/tokens.ts +0 -76
- package/src/dex/aave-v2/types.ts +0 -43
- package/src/dex/aave-v3/aave-v3-e2e.test.ts +0 -578
- package/src/dex/aave-v3/aave-v3-gas-estimation.test.ts +0 -66
- package/src/dex/aave-v3/aave-v3-integration.test.ts +0 -148
- package/src/dex/aave-v3/aave-v3.ts +0 -331
- package/src/dex/aave-v3/config.ts +0 -157
- package/src/dex/aave-v3/tokens.ts +0 -68
- package/src/dex/aave-v3/types.ts +0 -46
- package/src/dex/aave-v3/utils.ts +0 -153
- package/src/dex/aave-v3-stata/aave-v3-stata-e2e.test.ts +0 -355
- package/src/dex/aave-v3-stata/aave-v3-stata-gas-estimation.test.ts +0 -41
- package/src/dex/aave-v3-stata/aave-v3-stata-integration.test.ts +0 -282
- package/src/dex/aave-v3-stata/aave-v3-stata.ts +0 -530
- package/src/dex/aave-v3-stata/config.ts +0 -61
- package/src/dex/aave-v3-stata/tokens.ts +0 -48
- package/src/dex/aave-v3-stata/types.ts +0 -69
- package/src/dex/aave-v3-stata/utils.ts +0 -84
- package/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-e2e.test.ts +0 -376
- package/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-gas-estimation.test.ts +0 -41
- package/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-integration.test.ts +0 -600
- package/src/dex/aave-v3-stata-v2/aave-v3-stata-v2.ts +0 -477
- package/src/dex/aave-v3-stata-v2/config.ts +0 -47
- package/src/dex/aave-v3-stata-v2/tokens.ts +0 -48
- package/src/dex/aave-v3-stata-v2/types.ts +0 -42
- package/src/dex/aave-v3-stata-v2/utils.ts +0 -96
- package/src/dex/algebra/algebra-e2e.test.ts +0 -313
- package/src/dex/algebra/algebra-events.test.ts +0 -186
- package/src/dex/algebra/algebra-factory.ts +0 -77
- package/src/dex/algebra/algebra-integration.test.ts +0 -558
- package/src/dex/algebra/algebra-pool-v1_1.ts +0 -853
- package/src/dex/algebra/algebra-pool-v1_9.ts +0 -614
- package/src/dex/algebra/algebra-pool-v1_9_bidirectional_fee.ts +0 -55
- package/src/dex/algebra/algebra.ts +0 -1141
- package/src/dex/algebra/config.ts +0 -128
- package/src/dex/algebra/constants.ts +0 -17
- package/src/dex/algebra/lib/AlgebraMath.ts +0 -706
- package/src/dex/algebra/lib/Constants.ts +0 -5
- package/src/dex/algebra/lib/TickManager.ts +0 -91
- package/src/dex/algebra/lib/TickTable.ts +0 -227
- package/src/dex/algebra/lib/yul-helper.ts +0 -29
- package/src/dex/algebra/scripts/validate-state.ts +0 -292
- package/src/dex/algebra/types.ts +0 -146
- package/src/dex/algebra/utils.ts +0 -217
- package/src/dex/angle-staked-stable/angle-staked-stable-e2e.test.ts +0 -146
- package/src/dex/angle-staked-stable/angle-staked-stable-events.test.ts +0 -95
- package/src/dex/angle-staked-stable/angle-staked-stable-gas-estimation.test.ts +0 -29
- package/src/dex/angle-staked-stable/angle-staked-stable-integration.test.ts +0 -476
- package/src/dex/angle-staked-stable/angle-staked-stable-pool.ts +0 -325
- package/src/dex/angle-staked-stable/angle-staked-stable.ts +0 -356
- package/src/dex/angle-staked-stable/config.ts +0 -139
- package/src/dex/angle-staked-stable/types.ts +0 -16
- package/src/dex/angle-transmuter/angle-transmuter-e2e.test.ts +0 -156
- package/src/dex/angle-transmuter/angle-transmuter-events.test.ts +0 -365
- package/src/dex/angle-transmuter/angle-transmuter-gas-estimation.test.ts +0 -41
- package/src/dex/angle-transmuter/angle-transmuter-integration.test.ts +0 -390
- package/src/dex/angle-transmuter/angle-transmuter-pool.ts +0 -895
- package/src/dex/angle-transmuter/angle-transmuter.ts +0 -407
- package/src/dex/angle-transmuter/backedOracle.ts +0 -91
- package/src/dex/angle-transmuter/config.ts +0 -50
- package/src/dex/angle-transmuter/constants.ts +0 -138
- package/src/dex/angle-transmuter/morphoOracle.ts +0 -335
- package/src/dex/angle-transmuter/morphoVault.ts +0 -134
- package/src/dex/angle-transmuter/pyth.ts +0 -105
- package/src/dex/angle-transmuter/redstone.ts +0 -105
- package/src/dex/angle-transmuter/transmuter.ts +0 -619
- package/src/dex/angle-transmuter/types.ts +0 -203
- package/src/dex/angle-transmuter/utils.ts +0 -358
- package/src/dex/augustus-approvals.ts +0 -208
- package/src/dex/augustus-rfq.ts +0 -180
- package/src/dex/balancer-v1/balancer-pools.json +0 -33333
- package/src/dex/balancer-v1/balancer-v1-e2e.test.ts +0 -119
- package/src/dex/balancer-v1/balancer-v1-events.test.ts +0 -83
- package/src/dex/balancer-v1/balancer-v1-gas-estimation.test.ts +0 -29
- package/src/dex/balancer-v1/balancer-v1-integration.test.ts +0 -307
- package/src/dex/balancer-v1/balancer-v1-math.ts +0 -154
- package/src/dex/balancer-v1/balancer-v1-pool.ts +0 -232
- package/src/dex/balancer-v1/balancer-v1.ts +0 -578
- package/src/dex/balancer-v1/config.ts +0 -29
- package/src/dex/balancer-v1/optimizer.ts +0 -76
- package/src/dex/balancer-v1/types.ts +0 -100
- package/src/dex/balancer-v1/utils.ts +0 -57
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +0 -1612
- package/src/dex/balancer-v2/balancer-v2-events.test.ts +0 -132
- package/src/dex/balancer-v2/balancer-v2-gas-estimation.test.ts +0 -98
- package/src/dex/balancer-v2/balancer-v2-gyro3.test.ts +0 -268
- package/src/dex/balancer-v2/balancer-v2-gyroE.test.ts +0 -401
- package/src/dex/balancer-v2/balancer-v2-integration.test.ts +0 -931
- package/src/dex/balancer-v2/balancer-v2-math.ts +0 -592
- package/src/dex/balancer-v2/balancer-v2.ts +0 -1724
- package/src/dex/balancer-v2/config.ts +0 -81
- package/src/dex/balancer-v2/constants.ts +0 -20
- package/src/dex/balancer-v2/optimizer.ts +0 -70
- package/src/dex/balancer-v2/pools/balancer-v2-pool.ts +0 -274
- package/src/dex/balancer-v2/pools/gyro/Gyro3Pool.ts +0 -255
- package/src/dex/balancer-v2/pools/gyro/GyroEPool.ts +0 -402
- package/src/dex/balancer-v2/pools/gyro/gyro-helpers.ts +0 -15
- package/src/dex/balancer-v2/pools/linear/LinearMath.ts +0 -286
- package/src/dex/balancer-v2/pools/linear/LinearPool.ts +0 -639
- package/src/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.ts +0 -494
- package/src/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.ts +0 -581
- package/src/dex/balancer-v2/pools/stable/StableMath.ts +0 -203
- package/src/dex/balancer-v2/pools/stable/StablePool.ts +0 -223
- package/src/dex/balancer-v2/pools/weighted/WeightedMath.ts +0 -84
- package/src/dex/balancer-v2/pools/weighted/WeightedPool.ts +0 -188
- package/src/dex/balancer-v2/queryOnChain.ts +0 -48
- package/src/dex/balancer-v2/types.ts +0 -215
- package/src/dex/balancer-v2/utils.ts +0 -212
- package/src/dex/balancer-v3/balancer-api.test.ts +0 -122
- package/src/dex/balancer-v3/balancer-buffer.test.ts +0 -75
- package/src/dex/balancer-v3/balancer-gyroECLP.test.ts +0 -76
- package/src/dex/balancer-v3/balancer-hooks-events.test.ts +0 -166
- package/src/dex/balancer-v3/balancer-stableSurge.test.ts +0 -112
- package/src/dex/balancer-v3/balancer-test-helpers.ts +0 -251
- package/src/dex/balancer-v3/balancer-test-weighted.test.ts +0 -96
- package/src/dex/balancer-v3/balancer-v3-e2e.test.ts +0 -476
- package/src/dex/balancer-v3/balancer-v3-events.test.ts +0 -457
- package/src/dex/balancer-v3/balancer-v3-gas-estimation.test.ts +0 -30
- package/src/dex/balancer-v3/balancer-v3-integration.test.ts +0 -1008
- package/src/dex/balancer-v3/balancer-v3-pool.ts +0 -796
- package/src/dex/balancer-v3/balancer-v3.ts +0 -665
- package/src/dex/balancer-v3/config.ts +0 -100
- package/src/dex/balancer-v3/getGasCost.ts +0 -40
- package/src/dex/balancer-v3/getOnChainState.ts +0 -486
- package/src/dex/balancer-v3/getPoolsApi.ts +0 -191
- package/src/dex/balancer-v3/getTopPoolsApi.ts +0 -130
- package/src/dex/balancer-v3/gyroECLPPool.ts +0 -17
- package/src/dex/balancer-v3/hooks/balancer-hook-event-subscriber.ts +0 -212
- package/src/dex/balancer-v3/hooks/directionalFeeHook.ts +0 -53
- package/src/dex/balancer-v3/hooks/loadHooksConfig.ts +0 -12
- package/src/dex/balancer-v3/hooks/stableSurgeHook.ts +0 -200
- package/src/dex/balancer-v3/optimizer.ts +0 -66
- package/src/dex/balancer-v3/stablePool.ts +0 -78
- package/src/dex/balancer-v3/types.ts +0 -93
- package/src/dex/balancer-v3/utils.ts +0 -11
- package/src/dex/balancer-v3/weightedPool.ts +0 -2
- package/src/dex/bancor/bancor-e2e.test.ts +0 -91
- package/src/dex/bancor/bancor-gas-estimation.test.ts +0 -30
- package/src/dex/bancor/bancor.ts +0 -128
- package/src/dex/bancor/config.ts +0 -9
- package/src/dex/bancor/types.ts +0 -19
- package/src/dex/bebop/bebop-e2e.test.ts +0 -228
- package/src/dex/bebop/bebop-gas-estimation.test.ts +0 -30
- package/src/dex/bebop/bebop-integration.test.ts +0 -182
- package/src/dex/bebop/bebop.json +0 -72
- package/src/dex/bebop/bebop.proto +0 -15
- package/src/dex/bebop/bebop.ts +0 -930
- package/src/dex/bebop/config.ts +0 -42
- package/src/dex/bebop/constants.ts +0 -20
- package/src/dex/bebop/rate-fetcher.ts +0 -168
- package/src/dex/bebop/types.ts +0 -95
- package/src/dex/bebop/validators.ts +0 -39
- package/src/dex/cables/cables-e2e.test.ts +0 -207
- package/src/dex/cables/cables-integration.test.ts +0 -391
- package/src/dex/cables/cables.ts +0 -857
- package/src/dex/cables/config.ts +0 -13
- package/src/dex/cables/constants.ts +0 -33
- package/src/dex/cables/rate-fetcher.ts +0 -212
- package/src/dex/cables/types.ts +0 -113
- package/src/dex/cables/validators.test.ts +0 -151
- package/src/dex/cables/validators.ts +0 -61
- package/src/dex/camelot/camelot-e2e.test.ts +0 -161
- package/src/dex/camelot/camelot-integration.test.ts +0 -215
- package/src/dex/camelot/camelot-pool-discovery.test.ts +0 -149
- package/src/dex/camelot/camelot.ts +0 -882
- package/src/dex/camelot/config.ts +0 -23
- package/src/dex/camelot/types.ts +0 -15
- package/src/dex/compound/compound-e2e.test.ts +0 -91
- package/src/dex/compound/compound.ts +0 -112
- package/src/dex/compound/types.ts +0 -10
- package/src/dex/concentrator-arusd/concentrator-arusd-e2e.test.ts +0 -92
- package/src/dex/concentrator-arusd/concentrator-arusd-event.ts +0 -100
- package/src/dex/concentrator-arusd/concentrator-arusd-gas-estimation.test.ts +0 -29
- package/src/dex/concentrator-arusd/concentrator-arusd-integration.test.ts +0 -104
- package/src/dex/concentrator-arusd/concentrator-arusd.ts +0 -269
- package/src/dex/concentrator-arusd/concetrator-arusd-events.test.ts +0 -97
- package/src/dex/concentrator-arusd/config.ts +0 -13
- package/src/dex/concentrator-arusd/types.ts +0 -16
- package/src/dex/concentrator-arusd/utils.ts +0 -36
- package/src/dex/curve-v1/config.ts +0 -1181
- package/src/dex/curve-v1/constants.ts +0 -12
- package/src/dex/curve-v1/curve-v1-e2e.test.ts +0 -587
- package/src/dex/curve-v1/curve-v1-events.test.ts +0 -335
- package/src/dex/curve-v1/curve-v1-gas-estimation.test.ts +0 -29
- package/src/dex/curve-v1/curve-v1-integration.test.ts +0 -143
- package/src/dex/curve-v1/curve-v1.ts +0 -1315
- package/src/dex/curve-v1/forks/curve-forks/config.ts +0 -177
- package/src/dex/curve-v1/forks/curve-forks/curve-forks.ts +0 -73
- package/src/dex/curve-v1/forks/swerve/config.ts +0 -47
- package/src/dex/curve-v1/forks/swerve/swerve.ts +0 -68
- package/src/dex/curve-v1/packer.ts +0 -17
- package/src/dex/curve-v1/pools/3pool.ts +0 -313
- package/src/dex/curve-v1/pools/DUSDpool.ts +0 -52
- package/src/dex/curve-v1/pools/EURSpool.ts +0 -37
- package/src/dex/curve-v1/pools/GUSDpool.ts +0 -52
- package/src/dex/curve-v1/pools/HUSDpool.ts +0 -52
- package/src/dex/curve-v1/pools/LinkUSDpool.ts +0 -52
- package/src/dex/curve-v1/pools/MUSDpool.ts +0 -52
- package/src/dex/curve-v1/pools/bBTCpool.ts +0 -52
- package/src/dex/curve-v1/pools/curve-metapool.ts +0 -1113
- package/src/dex/curve-v1/pools/curve-pool.ts +0 -489
- package/src/dex/curve-v1/pools/getstate-multicall.ts +0 -156
- package/src/dex/curve-v1/pools/hBTCpool.ts +0 -37
- package/src/dex/curve-v1/pools/oBTCpool.ts +0 -52
- package/src/dex/curve-v1/pools/pBTCpool.ts +0 -52
- package/src/dex/curve-v1/pools/renpool.ts +0 -38
- package/src/dex/curve-v1/pools/rsvpool.ts +0 -52
- package/src/dex/curve-v1/pools/sBTCpool.ts +0 -38
- package/src/dex/curve-v1/pools/sETHpool.ts +0 -69
- package/src/dex/curve-v1/pools/sLinkpool.ts +0 -37
- package/src/dex/curve-v1/pools/sUSDpool.ts +0 -133
- package/src/dex/curve-v1/pools/stETHpool.ts +0 -52
- package/src/dex/curve-v1/pools/tBTCpool.ts +0 -52
- package/src/dex/curve-v1/pools/usdkpool.ts +0 -52
- package/src/dex/curve-v1/pools/usdnpool.ts +0 -59
- package/src/dex/curve-v1/pools/ustpool.ts +0 -52
- package/src/dex/curve-v1/types.ts +0 -88
- package/src/dex/curve-v1-factory/config.ts +0 -1004
- package/src/dex/curve-v1-factory/constants.ts +0 -41
- package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +0 -441
- package/src/dex/curve-v1-factory/curve-v1-factory-integration.test.ts +0 -827
- package/src/dex/curve-v1-factory/curve-v1-factory-node-cache.ts +0 -10
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +0 -1567
- package/src/dex/curve-v1-factory/curve-v1-pool-manager.ts +0 -449
- package/src/dex/curve-v1-factory/optimizer.ts +0 -57
- package/src/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.ts +0 -292
- package/src/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.ts +0 -103
- package/src/dex/curve-v1-factory/price-handlers/functions/_rates.ts +0 -116
- package/src/dex/curve-v1-factory/price-handlers/functions/_xp.ts +0 -114
- package/src/dex/curve-v1-factory/price-handlers/functions/_xp_mem.ts +0 -103
- package/src/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.ts +0 -230
- package/src/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.ts +0 -90
- package/src/dex/curve-v1-factory/price-handlers/functions/constants.ts +0 -604
- package/src/dex/curve-v1-factory/price-handlers/functions/get_D.ts +0 -386
- package/src/dex/curve-v1-factory/price-handlers/functions/get_D_mem.ts +0 -148
- package/src/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.ts +0 -120
- package/src/dex/curve-v1-factory/price-handlers/functions/get_dx.ts +0 -145
- package/src/dex/curve-v1-factory/price-handlers/functions/get_dy.ts +0 -327
- package/src/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.ts +0 -293
- package/src/dex/curve-v1-factory/price-handlers/functions/get_y.ts +0 -262
- package/src/dex/curve-v1-factory/price-handlers/functions/get_y_D.ts +0 -183
- package/src/dex/curve-v1-factory/price-handlers/functions/utils.ts +0 -76
- package/src/dex/curve-v1-factory/price-handlers/price-handler.ts +0 -130
- package/src/dex/curve-v1-factory/price-handlers/types.ts +0 -142
- package/src/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.ts +0 -301
- package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +0 -227
- package/src/dex/curve-v1-factory/state-polling-pools/polling-manager.ts +0 -266
- package/src/dex/curve-v1-factory/state-polling-pools/pool-polling-base.ts +0 -181
- package/src/dex/curve-v1-factory/types.ts +0 -286
- package/src/dex/curve-v1-stable-ng/config.ts +0 -315
- package/src/dex/curve-v1-stable-ng/curve-v1-stable-ng-e2e.test.ts +0 -219
- package/src/dex/curve-v1-stable-ng/curve-v1-stable-ng-integration.test.ts +0 -567
- package/src/dex/curve-v1-stable-ng/curve-v1-stable-ng.ts +0 -33
- package/src/dex/curve-v2/constants.ts +0 -1
- package/src/dex/curve-v2/curve-v2-e2e.test.ts +0 -104
- package/src/dex/curve-v2/curve-v2-gas-estimation.test.ts +0 -29
- package/src/dex/curve-v2/curve-v2.ts +0 -440
- package/src/dex/curve-v2/types.ts +0 -27
- package/src/dex/dexalot/config.ts +0 -28
- package/src/dex/dexalot/constants.ts +0 -32
- package/src/dex/dexalot/dexalot-e2e.test.ts +0 -260
- package/src/dex/dexalot/dexalot-integration.test.ts +0 -431
- package/src/dex/dexalot/dexalot.ts +0 -1114
- package/src/dex/dexalot/rate-fetcher.ts +0 -197
- package/src/dex/dexalot/types.ts +0 -131
- package/src/dex/dexalot/validators.ts +0 -46
- package/src/dex/dodo-v1/config.ts +0 -15
- package/src/dex/dodo-v1/dodo-v1-e2e.test.ts +0 -101
- package/src/dex/dodo-v1/dodo-v1.ts +0 -132
- package/src/dex/dodo-v1/types.ts +0 -25
- package/src/dex/dodo-v2.ts +0 -266
- package/src/dex/ekubo/config.ts +0 -15
- package/src/dex/ekubo/ekubo-e2e.test.ts +0 -124
- package/src/dex/ekubo/ekubo-events.test.ts +0 -209
- package/src/dex/ekubo/ekubo-integration.test.ts +0 -243
- package/src/dex/ekubo/ekubo.ts +0 -628
- package/src/dex/ekubo/pools/base-pool.ts +0 -267
- package/src/dex/ekubo/pools/math/constants.ts +0 -5
- package/src/dex/ekubo/pools/math/delta.test.ts +0 -131
- package/src/dex/ekubo/pools/math/delta.ts +0 -68
- package/src/dex/ekubo/pools/math/price.test.ts +0 -54
- package/src/dex/ekubo/pools/math/price.ts +0 -129
- package/src/dex/ekubo/pools/math/swap.test.ts +0 -215
- package/src/dex/ekubo/pools/math/swap.ts +0 -161
- package/src/dex/ekubo/pools/math/tick.test.ts +0 -72
- package/src/dex/ekubo/pools/math/tick.ts +0 -120
- package/src/dex/ekubo/pools/oracle-pool.ts +0 -46
- package/src/dex/ekubo/pools/pool-utils.ts +0 -348
- package/src/dex/ekubo/types.test.ts +0 -552
- package/src/dex/ekubo/types.ts +0 -55
- package/src/dex/ekubo/utils.ts +0 -34
- package/src/dex/erc4626/config.ts +0 -41
- package/src/dex/erc4626/constants.ts +0 -6
- package/src/dex/erc4626/erc-4626-pool.ts +0 -132
- package/src/dex/erc4626/erc4626-e2e.test.ts +0 -224
- package/src/dex/erc4626/erc4626-event.test.ts +0 -128
- package/src/dex/erc4626/erc4626-gas-estimation.test.ts +0 -41
- package/src/dex/erc4626/erc4626-integration.test.ts +0 -164
- package/src/dex/erc4626/erc4626.ts +0 -333
- package/src/dex/erc4626/types.ts +0 -26
- package/src/dex/etherfi.ts +0 -244
- package/src/dex/fluid-dex/config.ts +0 -27
- package/src/dex/fluid-dex/constants.ts +0 -2
- package/src/dex/fluid-dex/fluid-dex-e2e.test.ts +0 -311
- package/src/dex/fluid-dex/fluid-dex-events.test.ts +0 -179
- package/src/dex/fluid-dex/fluid-dex-factory.ts +0 -151
- package/src/dex/fluid-dex/fluid-dex-gas-estimation.test.ts +0 -29
- package/src/dex/fluid-dex/fluid-dex-integration.test.ts +0 -355
- package/src/dex/fluid-dex/fluid-dex-liquidity-proxy.ts +0 -210
- package/src/dex/fluid-dex/fluid-dex-pool.ts +0 -138
- package/src/dex/fluid-dex/fluid-dex.ts +0 -1169
- package/src/dex/fluid-dex/types.ts +0 -104
- package/src/dex/fluid-dex/utils.ts +0 -15
- package/src/dex/fx-protocol-rusd/config.ts +0 -14
- package/src/dex/fx-protocol-rusd/fx-protocol-e2e.test.ts +0 -96
- package/src/dex/fx-protocol-rusd/fx-protocol-events.test.ts +0 -101
- package/src/dex/fx-protocol-rusd/fx-protocol-integration.test.ts +0 -104
- package/src/dex/fx-protocol-rusd/fx-protocol-rusd-event.ts +0 -112
- package/src/dex/fx-protocol-rusd/fx-protocol-rusd-gas-estimation.test.ts +0 -29
- package/src/dex/fx-protocol-rusd/fx-protocol-rusd.ts +0 -282
- package/src/dex/fx-protocol-rusd/types.ts +0 -16
- package/src/dex/fx-protocol-rusd/utils.ts +0 -47
- package/src/dex/generic-rfq/e2e-test-config.ts +0 -25
- package/src/dex/generic-rfq/example-api.test.ts +0 -233
- package/src/dex/generic-rfq/fetch-mm-api.ts +0 -284
- package/src/dex/generic-rfq/generic-rfq-e2e.test.ts +0 -118
- package/src/dex/generic-rfq/generic-rfq-integration.test.ts +0 -235
- package/src/dex/generic-rfq/generic-rfq-local-e2e.test.ts +0 -107
- package/src/dex/generic-rfq/generic-rfq.ts +0 -463
- package/src/dex/generic-rfq/rate-fetcher.ts +0 -491
- package/src/dex/generic-rfq/security.ts +0 -55
- package/src/dex/generic-rfq/types.ts +0 -120
- package/src/dex/generic-rfq/utils.ts +0 -74
- package/src/dex/generic-rfq/validators.test.ts +0 -245
- package/src/dex/generic-rfq/validators.ts +0 -189
- package/src/dex/gmx/config.ts +0 -81
- package/src/dex/gmx/fast-price-feed.ts +0 -279
- package/src/dex/gmx/gmx-e2e.test.ts +0 -322
- package/src/dex/gmx/gmx-events.test.ts +0 -114
- package/src/dex/gmx/gmx-integration.test.ts +0 -211
- package/src/dex/gmx/gmx.ts +0 -321
- package/src/dex/gmx/pool.ts +0 -360
- package/src/dex/gmx/types.ts +0 -94
- package/src/dex/gmx/usdg.ts +0 -83
- package/src/dex/gmx/vault-price-feed.ts +0 -384
- package/src/dex/gmx/vault-utils.ts +0 -53
- package/src/dex/gmx/vault.ts +0 -290
- package/src/dex/hashflow/config.ts +0 -56
- package/src/dex/hashflow/constants.ts +0 -54
- package/src/dex/hashflow/hashflow-e2e.test.ts +0 -351
- package/src/dex/hashflow/hashflow-gas-estimation.test.ts +0 -30
- package/src/dex/hashflow/hashflow-integration.test.ts +0 -157
- package/src/dex/hashflow/hashflow.ts +0 -1119
- package/src/dex/hashflow/rate-fetcher.ts +0 -118
- package/src/dex/hashflow/types.ts +0 -83
- package/src/dex/hashflow/validators.ts +0 -38
- package/src/dex/idex.ts +0 -268
- package/src/dex/idle-dao/config.ts +0 -26
- package/src/dex/idle-dao/idle-dao--gas-estimation.test.ts +0 -30
- package/src/dex/idle-dao/idle-dao-e2e.test.ts +0 -112
- package/src/dex/idle-dao/idle-dao-integration.test.ts +0 -155
- package/src/dex/idle-dao/idle-dao.ts +0 -402
- package/src/dex/idle-dao/token_list.ts +0 -287
- package/src/dex/idle-dao/tokens.ts +0 -99
- package/src/dex/idle-dao/types.ts +0 -43
- package/src/dex/idle-dao/utils.ts +0 -216
- package/src/dex/index.ts +0 -402
- package/src/dex/infusion/config.ts +0 -21
- package/src/dex/infusion/infusion-e2e.test.ts +0 -110
- package/src/dex/infusion/infusion-integration.test.ts +0 -232
- package/src/dex/infusion/infusion-stable-pool.ts +0 -91
- package/src/dex/infusion/infusion.ts +0 -652
- package/src/dex/infusion/types.ts +0 -60
- package/src/dex/infusion/utils/isStablePair.ts +0 -18
- package/src/dex/jarvis-v6/chainLinkpriceFeed-event.ts +0 -76
- package/src/dex/jarvis-v6/config.ts +0 -261
- package/src/dex/jarvis-v6/jarvis-v6-e2e.test.ts +0 -113
- package/src/dex/jarvis-v6/jarvis-v6-events.test.ts +0 -67
- package/src/dex/jarvis-v6/jarvis-v6-events.ts +0 -67
- package/src/dex/jarvis-v6/jarvis-v6-integration.test.ts +0 -111
- package/src/dex/jarvis-v6/jarvis-v6.ts +0 -509
- package/src/dex/jarvis-v6/syntheteumPool-event.ts +0 -68
- package/src/dex/jarvis-v6/types.ts +0 -59
- package/src/dex/jarvis-v6/utils.ts +0 -127
- package/src/dex/kyberdmm/config.ts +0 -61
- package/src/dex/kyberdmm/fee-formula.ts +0 -113
- package/src/dex/kyberdmm/kyberdmm-e2e.test.ts +0 -325
- package/src/dex/kyberdmm/kyberdmm-events.test.ts +0 -123
- package/src/dex/kyberdmm/kyberdmm-integration.test.ts +0 -93
- package/src/dex/kyberdmm/kyberdmm.ts +0 -649
- package/src/dex/kyberdmm/math-ext.ts +0 -29
- package/src/dex/kyberdmm/pool.ts +0 -226
- package/src/dex/kyberdmm/types.ts +0 -85
- package/src/dex/lido/config.ts +0 -5
- package/src/dex/lido/lido-e2e.test.ts +0 -81
- package/src/dex/lido/lido-gas-estimation.test.ts +0 -29
- package/src/dex/lido/lido.ts +0 -110
- package/src/dex/lido/types.ts +0 -5
- package/src/dex/limit-order-exchange.ts +0 -40
- package/src/dex/lite-psm/config.ts +0 -33
- package/src/dex/lite-psm/lite-psm-e2e.test.ts +0 -146
- package/src/dex/lite-psm/lite-psm-event-pool.ts +0 -216
- package/src/dex/lite-psm/lite-psm-events.test.ts +0 -61
- package/src/dex/lite-psm/lite-psm-gas-estimation.test.ts +0 -34
- package/src/dex/lite-psm/lite-psm-integration.test.ts +0 -99
- package/src/dex/lite-psm/lite-psm.ts +0 -540
- package/src/dex/lite-psm/types.ts +0 -47
- package/src/dex/maker-psm/config.ts +0 -59
- package/src/dex/maker-psm/maker-psm-e2e.test.ts +0 -83
- package/src/dex/maker-psm/maker-psm-events.test.ts +0 -63
- package/src/dex/maker-psm/maker-psm-gas-estimation.test.ts +0 -34
- package/src/dex/maker-psm/maker-psm-integration.test.ts +0 -99
- package/src/dex/maker-psm/maker-psm.ts +0 -722
- package/src/dex/maker-psm/types.ts +0 -45
- package/src/dex/maverick-v1/config.ts +0 -33
- package/src/dex/maverick-v1/constants.ts +0 -1
- package/src/dex/maverick-v1/maverick-math/maverick-basic-math.ts +0 -187
- package/src/dex/maverick-v1/maverick-math/maverick-bin-map.ts +0 -182
- package/src/dex/maverick-v1/maverick-math/maverick-pool-math.test.ts +0 -680
- package/src/dex/maverick-v1/maverick-math/maverick-pool-math.ts +0 -562
- package/src/dex/maverick-v1/maverick-v1-e2e.test.ts +0 -346
- package/src/dex/maverick-v1/maverick-v1-events.test.ts +0 -112
- package/src/dex/maverick-v1/maverick-v1-gas-estimation.test.ts +0 -29
- package/src/dex/maverick-v1/maverick-v1-integration.test.ts +0 -170
- package/src/dex/maverick-v1/maverick-v1-pool.ts +0 -394
- package/src/dex/maverick-v1/maverick-v1.ts +0 -536
- package/src/dex/maverick-v1/subgraph-queries.ts +0 -60
- package/src/dex/maverick-v1/types.ts +0 -83
- package/src/dex/maverick-v2/config.ts +0 -32
- package/src/dex/maverick-v2/maverick-math/maverick-basic-math.ts +0 -152
- package/src/dex/maverick-v2/maverick-math/maverick-bin-math.ts +0 -288
- package/src/dex/maverick-v2/maverick-math/maverick-delta-math.ts +0 -32
- package/src/dex/maverick-v2/maverick-math/maverick-math.ts +0 -30
- package/src/dex/maverick-v2/maverick-math/maverick-pool-lib.ts +0 -42
- package/src/dex/maverick-v2/maverick-math/maverick-pool-math.ts +0 -714
- package/src/dex/maverick-v2/maverick-math/maverick-swap-math.ts +0 -199
- package/src/dex/maverick-v2/maverick-math/maverick-tick-math.ts +0 -171
- package/src/dex/maverick-v2/maverick-math/maverick-twa-math.ts +0 -54
- package/src/dex/maverick-v2/maverick-v2-e2e.test.ts +0 -171
- package/src/dex/maverick-v2/maverick-v2-events.test.ts +0 -112
- package/src/dex/maverick-v2/maverick-v2-gas-estimation.test.ts +0 -29
- package/src/dex/maverick-v2/maverick-v2-integration.test.ts +0 -287
- package/src/dex/maverick-v2/maverick-v2-pool.ts +0 -369
- package/src/dex/maverick-v2/maverick-v2.ts +0 -409
- package/src/dex/maverick-v2/types.ts +0 -155
- package/src/dex/nerve/config.ts +0 -635
- package/src/dex/nerve/nerve-e2e.test.ts +0 -731
- package/src/dex/nerve/nerve-events.test.ts +0 -911
- package/src/dex/nerve/nerve-integration.test.ts +0 -73
- package/src/dex/nerve/nerve-math.ts +0 -304
- package/src/dex/nerve/nerve-metapool.ts +0 -203
- package/src/dex/nerve/nerve-pool.ts +0 -425
- package/src/dex/nerve/nerve.ts +0 -467
- package/src/dex/nerve/types.ts +0 -65
- package/src/dex/nerve/utils.ts +0 -39
- package/src/dex/oswap/config.ts +0 -32
- package/src/dex/oswap/oswap-e2e.test.ts +0 -91
- package/src/dex/oswap/oswap-events.test.ts +0 -88
- package/src/dex/oswap/oswap-integration.test.ts +0 -291
- package/src/dex/oswap/oswap-pool.ts +0 -190
- package/src/dex/oswap/oswap.ts +0 -414
- package/src/dex/oswap/types.ts +0 -29
- package/src/dex/pancakeswap-v3/config.ts +0 -119
- package/src/dex/pancakeswap-v3/constants.ts +0 -36
- package/src/dex/pancakeswap-v3/contract-math/BitMath.ts +0 -90
- package/src/dex/pancakeswap-v3/contract-math/FixedPoint128.ts +0 -3
- package/src/dex/pancakeswap-v3/contract-math/FixedPoint96.ts +0 -4
- package/src/dex/pancakeswap-v3/contract-math/FullMath.ts +0 -30
- package/src/dex/pancakeswap-v3/contract-math/LiquidityMath.ts +0 -17
- package/src/dex/pancakeswap-v3/contract-math/Oracle.ts +0 -226
- package/src/dex/pancakeswap-v3/contract-math/SqrtPriceMath.ts +0 -226
- package/src/dex/pancakeswap-v3/contract-math/SwapMath.ts +0 -139
- package/src/dex/pancakeswap-v3/contract-math/Tick.ts +0 -82
- package/src/dex/pancakeswap-v3/contract-math/TickBitMap.ts +0 -128
- package/src/dex/pancakeswap-v3/contract-math/TickMath.ts +0 -211
- package/src/dex/pancakeswap-v3/contract-math/UnsafeMath.ts +0 -5
- package/src/dex/pancakeswap-v3/contract-math/pancakeswap-v3-math.ts +0 -687
- package/src/dex/pancakeswap-v3/contract-math/utils.ts +0 -11
- package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +0 -459
- package/src/dex/pancakeswap-v3/pancakeswap-v3-events.test.ts +0 -124
- package/src/dex/pancakeswap-v3/pancakeswap-v3-factory.ts +0 -80
- package/src/dex/pancakeswap-v3/pancakeswap-v3-gas-estimation.test.ts +0 -29
- package/src/dex/pancakeswap-v3/pancakeswap-v3-integration.test.ts +0 -529
- package/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts +0 -555
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +0 -1161
- package/src/dex/pancakeswap-v3/utils.ts +0 -65
- package/src/dex/paraswap-limit-orders/config.ts +0 -60
- package/src/dex/paraswap-limit-orders/constant.ts +0 -32
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders-e2e.test.ts +0 -221
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders-integration.test.ts +0 -328
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders.ts +0 -634
- package/src/dex/paraswap-limit-orders/types.ts +0 -84
- package/src/dex/paraswap-limit-orders/utils.ts +0 -52
- package/src/dex/polygon-migrator/config.ts +0 -25
- package/src/dex/polygon-migrator/constants.ts +0 -1
- package/src/dex/polygon-migrator/polygon-migrator-e2e.test.ts +0 -98
- package/src/dex/polygon-migrator/polygon-migrator-gas-estimation.test.ts +0 -41
- package/src/dex/polygon-migrator/polygon-migrator-integration.test.ts +0 -139
- package/src/dex/polygon-migrator/polygon-migrator.ts +0 -194
- package/src/dex/polygon-migrator/types.ts +0 -14
- package/src/dex/quick-perps/config.ts +0 -31
- package/src/dex/quick-perps/fast-price-feed.ts +0 -279
- package/src/dex/quick-perps/pool.ts +0 -407
- package/src/dex/quick-perps/quick-perps-e2e.test.ts +0 -66
- package/src/dex/quick-perps/quick-perps-events.test.ts +0 -100
- package/src/dex/quick-perps/quick-perps-integration.test.ts +0 -153
- package/src/dex/quick-perps/quick-perps.ts +0 -337
- package/src/dex/quick-perps/types.ts +0 -97
- package/src/dex/quick-perps/usdq.ts +0 -83
- package/src/dex/quick-perps/vault-price-feed.ts +0 -322
- package/src/dex/quick-perps/vault-utils.ts +0 -53
- package/src/dex/quick-perps/vault.ts +0 -290
- package/src/dex/quickswap/config.ts +0 -16
- package/src/dex/quickswap/quickswap-e2e.test.ts +0 -384
- package/src/dex/quickswap/quickswap-v3.ts +0 -74
- package/src/dex/quickswap/thena-fusion.ts +0 -19
- package/src/dex/quickswap/types.ts +0 -5
- package/src/dex/simple-exchange.ts +0 -146
- package/src/dex/sky-converter/config.ts +0 -31
- package/src/dex/sky-converter/sky-converter-e2e.test.ts +0 -113
- package/src/dex/sky-converter/sky-converter-gas-estimation.test.ts +0 -78
- package/src/dex/sky-converter/sky-converter-integration.test.ts +0 -135
- package/src/dex/sky-converter/sky-converter.ts +0 -221
- package/src/dex/sky-converter/types.ts +0 -14
- package/src/dex/smoothy/smoothy-e2e.test.ts +0 -81
- package/src/dex/smoothy/smoothy.ts +0 -110
- package/src/dex/smoothy/types.ts +0 -18
- package/src/dex/solidly/config.ts +0 -218
- package/src/dex/solidly/forks-override/aerodrome.ts +0 -53
- package/src/dex/solidly/forks-override/chronos.ts +0 -231
- package/src/dex/solidly/forks-override/equalizer.ts +0 -58
- package/src/dex/solidly/forks-override/pharaohV1.ts +0 -10
- package/src/dex/solidly/forks-override/ramses.ts +0 -253
- package/src/dex/solidly/forks-override/spiritSwapV2.ts +0 -61
- package/src/dex/solidly/forks-override/thena.ts +0 -58
- package/src/dex/solidly/forks-override/usdfi.ts +0 -10
- package/src/dex/solidly/forks-override/velocimeter.ts +0 -58
- package/src/dex/solidly/forks-override/velodrome.ts +0 -58
- package/src/dex/solidly/forks-override/velodromeV2.ts +0 -63
- package/src/dex/solidly/solidly-e2e.test.ts +0 -1421
- package/src/dex/solidly/solidly-ethereum.ts +0 -61
- package/src/dex/solidly/solidly-gas-estimation.test.ts +0 -29
- package/src/dex/solidly/solidly-integration.test.ts +0 -1753
- package/src/dex/solidly/solidly-stable-pool.ts +0 -91
- package/src/dex/solidly/solidly.ts +0 -708
- package/src/dex/solidly/types.ts +0 -38
- package/src/dex/solidly-v3/config.ts +0 -118
- package/src/dex/solidly-v3/constants.ts +0 -42
- package/src/dex/solidly-v3/contract-math/BitMath.ts +0 -90
- package/src/dex/solidly-v3/contract-math/FixedPoint128.ts +0 -3
- package/src/dex/solidly-v3/contract-math/FixedPoint96.ts +0 -4
- package/src/dex/solidly-v3/contract-math/FullMath.ts +0 -30
- package/src/dex/solidly-v3/contract-math/LiquidityMath.ts +0 -17
- package/src/dex/solidly-v3/contract-math/SqrtPriceMath.ts +0 -226
- package/src/dex/solidly-v3/contract-math/SwapMath.ts +0 -139
- package/src/dex/solidly-v3/contract-math/Tick.ts +0 -63
- package/src/dex/solidly-v3/contract-math/TickBitMap.ts +0 -123
- package/src/dex/solidly-v3/contract-math/TickMath.ts +0 -211
- package/src/dex/solidly-v3/contract-math/UnsafeMath.ts +0 -5
- package/src/dex/solidly-v3/contract-math/uniswap-v3-math.ts +0 -562
- package/src/dex/solidly-v3/contract-math/utils.ts +0 -50
- package/src/dex/solidly-v3/solidly-v3-e2e.test.ts +0 -270
- package/src/dex/solidly-v3/solidly-v3-events.test.ts +0 -146
- package/src/dex/solidly-v3/solidly-v3-factory.ts +0 -80
- package/src/dex/solidly-v3/solidly-v3-gas-estimation.test.ts +0 -29
- package/src/dex/solidly-v3/solidly-v3-integration.test.ts +0 -358
- package/src/dex/solidly-v3/solidly-v3-pool.ts +0 -502
- package/src/dex/solidly-v3/solidly-v3.ts +0 -976
- package/src/dex/solidly-v3/types.ts +0 -157
- package/src/dex/solidly-v3/utils.ts +0 -71
- package/src/dex/spark/config.ts +0 -69
- package/src/dex/spark/constants.ts +0 -2
- package/src/dex/spark/scripts/validate-state.ts +0 -145
- package/src/dex/spark/spark-e2e.test.ts +0 -225
- package/src/dex/spark/spark-events.test.ts +0 -214
- package/src/dex/spark/spark-gas-estimation.test.ts +0 -29
- package/src/dex/spark/spark-integration.test.ts +0 -690
- package/src/dex/spark/spark-psm.ts +0 -361
- package/src/dex/spark/spark-sdai-pool.ts +0 -116
- package/src/dex/spark/spark.ts +0 -323
- package/src/dex/spark/types.ts +0 -54
- package/src/dex/spark/utils.ts +0 -151
- package/src/dex/stable-pool/stable-pool.ts +0 -129
- package/src/dex/stable-pool/stablepool-e2e.test.ts +0 -73
- package/src/dex/stable-pool/types.ts +0 -20
- package/src/dex/stader/config.ts +0 -13
- package/src/dex/stader/stader-e2e.test.ts +0 -74
- package/src/dex/stader/stader-events.test.ts +0 -64
- package/src/dex/stader/stader-gas-estimation.test.ts +0 -29
- package/src/dex/stader/stader-integration.test.ts +0 -240
- package/src/dex/stader/stader-pool.ts +0 -77
- package/src/dex/stader/stader.ts +0 -240
- package/src/dex/stader/types.ts +0 -16
- package/src/dex/stader/utils.ts +0 -34
- package/src/dex/stkgho/config.ts +0 -14
- package/src/dex/stkgho/stkgho-e2e.test.ts +0 -77
- package/src/dex/stkgho/stkgho-events.test.ts +0 -79
- package/src/dex/stkgho/stkgho-gas-estimation.test.ts +0 -29
- package/src/dex/stkgho/stkgho-integration.test.ts +0 -226
- package/src/dex/stkgho/stkgho-pool.ts +0 -111
- package/src/dex/stkgho/stkgho.ts +0 -223
- package/src/dex/stkgho/types.ts +0 -14
- package/src/dex/swaap-v2/config.ts +0 -42
- package/src/dex/swaap-v2/constants.ts +0 -52
- package/src/dex/swaap-v2/rate-fetcher.ts +0 -267
- package/src/dex/swaap-v2/stable-coins.ts +0 -25
- package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +0 -584
- package/src/dex/swaap-v2/swaap-v2-estimation.test.ts +0 -29
- package/src/dex/swaap-v2/swaap-v2-integration.test.ts +0 -219
- package/src/dex/swaap-v2/swaap-v2.ts +0 -1067
- package/src/dex/swaap-v2/types.ts +0 -105
- package/src/dex/swaap-v2/utils.ts +0 -46
- package/src/dex/swaap-v2/validators.ts +0 -131
- package/src/dex/swell/config.ts +0 -29
- package/src/dex/swell/rsweth-pool.ts +0 -58
- package/src/dex/swell/swell-e2e.test.ts +0 -56
- package/src/dex/swell/swell-estimation.test.ts +0 -29
- package/src/dex/swell/swell.ts +0 -312
- package/src/dex/swell/sweth-pool.ts +0 -58
- package/src/dex/swell/type.ts +0 -7
- package/src/dex/swell/utils.ts +0 -53
- package/src/dex/synthetix/config.ts +0 -55
- package/src/dex/synthetix/constants.ts +0 -36
- package/src/dex/synthetix/contract-math/DexPriceAggregatorUniswapV3.ts +0 -276
- package/src/dex/synthetix/contract-math/ExchangeRates.ts +0 -117
- package/src/dex/synthetix/contract-math/ExchangeRatesWithDexPricing.ts +0 -278
- package/src/dex/synthetix/contract-math/FullMath.ts +0 -17
- package/src/dex/synthetix/contract-math/OracleLibrary.ts +0 -109
- package/src/dex/synthetix/contract-math/SafeDecimalMath.ts +0 -49
- package/src/dex/synthetix/contract-math/TickMath.ts +0 -72
- package/src/dex/synthetix/contract-math/synthetix-math.ts +0 -266
- package/src/dex/synthetix/synthetix-e2e.test.ts +0 -174
- package/src/dex/synthetix/synthetix-integration.test.ts +0 -293
- package/src/dex/synthetix/synthetix-state.ts +0 -970
- package/src/dex/synthetix/synthetix.ts +0 -420
- package/src/dex/synthetix/types.ts +0 -121
- package/src/dex/synthetix/utils.ts +0 -125
- package/src/dex/trader-joe-v2.1/base.ts +0 -167
- package/src/dex/trader-joe-v2.1/config.ts +0 -14
- package/src/dex/trader-joe-v2.1/trader-joe-v2.1-e2e.test.ts +0 -101
- package/src/dex/trader-joe-v2.1/trader-joe-v2.1-gas-estimation.test.ts +0 -29
- package/src/dex/trader-joe-v2.1/trader-joe-v2.1.ts +0 -23
- package/src/dex/trader-joe-v2.1/trader-joe-v2.2.ts +0 -23
- package/src/dex/trader-joe-v2.1/types.ts +0 -38
- package/src/dex/uniswap-v2/biswap.ts +0 -61
- package/src/dex/uniswap-v2/config.ts +0 -626
- package/src/dex/uniswap-v2/constants.ts +0 -58
- package/src/dex/uniswap-v2/dfyn.ts +0 -128
- package/src/dex/uniswap-v2/excalibur.ts +0 -63
- package/src/dex/uniswap-v2/mdex.ts +0 -66
- package/src/dex/uniswap-v2/nomiswap-v2.ts +0 -73
- package/src/dex/uniswap-v2/optimizer.ts +0 -66
- package/src/dex/uniswap-v2/types.ts +0 -164
- package/src/dex/uniswap-v2/uniswap-v2-constant-product-pool.ts +0 -40
- package/src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts +0 -438
- package/src/dex/uniswap-v2/uniswap-v2-e2e-avalanche.test.ts +0 -1361
- package/src/dex/uniswap-v2/uniswap-v2-e2e-base.test.ts +0 -42
- package/src/dex/uniswap-v2/uniswap-v2-e2e-bsc.test.ts +0 -1295
- package/src/dex/uniswap-v2/uniswap-v2-e2e-fantom.test.ts +0 -1428
- package/src/dex/uniswap-v2/uniswap-v2-e2e-gnosis.test.ts +0 -283
- package/src/dex/uniswap-v2/uniswap-v2-e2e-mainnet.test.ts +0 -1834
- package/src/dex/uniswap-v2/uniswap-v2-e2e-optimism.test.ts +0 -282
- package/src/dex/uniswap-v2/uniswap-v2-e2e-polygon.test.ts +0 -871
- package/src/dex/uniswap-v2/uniswap-v2-factory.ts +0 -70
- package/src/dex/uniswap-v2/uniswap-v2-gas-estimation.test.ts +0 -98
- package/src/dex/uniswap-v2/uniswap-v2-integration.test.ts +0 -63
- package/src/dex/uniswap-v2/uniswap-v2.ts +0 -1122
- package/src/dex/uniswap-v3/config.ts +0 -453
- package/src/dex/uniswap-v3/constants.ts +0 -56
- package/src/dex/uniswap-v3/contract-math/BitMath.ts +0 -90
- package/src/dex/uniswap-v3/contract-math/FixedPoint128.ts +0 -3
- package/src/dex/uniswap-v3/contract-math/FixedPoint96.ts +0 -4
- package/src/dex/uniswap-v3/contract-math/FullMath.ts +0 -30
- package/src/dex/uniswap-v3/contract-math/LiquidityMath.ts +0 -17
- package/src/dex/uniswap-v3/contract-math/Oracle.ts +0 -226
- package/src/dex/uniswap-v3/contract-math/SqrtPriceMath.ts +0 -226
- package/src/dex/uniswap-v3/contract-math/SwapMath.ts +0 -139
- package/src/dex/uniswap-v3/contract-math/Tick.ts +0 -82
- package/src/dex/uniswap-v3/contract-math/TickBitMap.ts +0 -143
- package/src/dex/uniswap-v3/contract-math/TickMath.ts +0 -211
- package/src/dex/uniswap-v3/contract-math/UnsafeMath.ts +0 -5
- package/src/dex/uniswap-v3/contract-math/uniswap-v3-math.ts +0 -668
- package/src/dex/uniswap-v3/contract-math/utils.ts +0 -55
- package/src/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.ts +0 -157
- package/src/dex/uniswap-v3/forks/ramses-v2/utils.ts +0 -72
- package/src/dex/uniswap-v3/forks/velodrome-slipstream/utils.ts +0 -65
- package/src/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-factory.ts +0 -16
- package/src/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-pool.ts +0 -198
- package/src/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream.ts +0 -243
- package/src/dex/uniswap-v3/scripts/check-pool-bitmap-ranges.ts +0 -238
- package/src/dex/uniswap-v3/scripts/measure-calc-time.ts +0 -172
- package/src/dex/uniswap-v3/types.ts +0 -213
- package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +0 -1391
- package/src/dex/uniswap-v3/uniswap-v3-events.test.ts +0 -185
- package/src/dex/uniswap-v3/uniswap-v3-factory.ts +0 -80
- package/src/dex/uniswap-v3/uniswap-v3-gas-estimation.test.ts +0 -98
- package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +0 -2734
- package/src/dex/uniswap-v3/uniswap-v3-pool.ts +0 -564
- package/src/dex/uniswap-v3/uniswap-v3.ts +0 -1493
- package/src/dex/uniswap-v3/utils.ts +0 -83
- package/src/dex/uniswap-v3.ts +0 -242
- package/src/dex/usual/m-wrapped-m.ts +0 -76
- package/src/dex/usual/types.ts +0 -10
- package/src/dex/usual/usual-bond.ts +0 -69
- package/src/dex/usual/usual-e2e.test.ts +0 -169
- package/src/dex/usual/usual-gas-estimation.test.ts +0 -54
- package/src/dex/usual/usual-integration.test.ts +0 -515
- package/src/dex/usual/usual-m-usd0.ts +0 -76
- package/src/dex/usual/usual-m-wrapped-m.ts +0 -71
- package/src/dex/usual/usual.ts +0 -156
- package/src/dex/usual/wrapped-m-m.ts +0 -76
- package/src/dex/usual-pp/config.ts +0 -18
- package/src/dex/usual-pp/pool.ts +0 -77
- package/src/dex/usual-pp/types.ts +0 -12
- package/src/dex/usual-pp/usual-events.test.ts +0 -70
- package/src/dex/usual-pp/usual-integration.test.ts +0 -143
- package/src/dex/usual-pp/usual-pp-gas-estimation.test.ts +0 -29
- package/src/dex/usual-pp/usual-pp.e2e.test.ts +0 -76
- package/src/dex/usual-pp/usual-pp.ts +0 -207
- package/src/dex/usual-pp/utils.ts +0 -27
- package/src/dex/weth/config.ts +0 -87
- package/src/dex/weth/types.ts +0 -34
- package/src/dex/weth/weth-e2e-v6.test.ts +0 -117
- package/src/dex/weth/weth-e2e.test.ts +0 -1032
- package/src/dex/weth/weth-gas-estimation.test.ts +0 -42
- package/src/dex/weth/weth-integration.test.ts +0 -80
- package/src/dex/weth/weth.ts +0 -232
- package/src/dex/wombat/config.ts +0 -77
- package/src/dex/wombat/types.ts +0 -55
- package/src/dex/wombat/utils.ts +0 -82
- package/src/dex/wombat/wombat-bmw.ts +0 -186
- package/src/dex/wombat/wombat-e2e.test.ts +0 -272
- package/src/dex/wombat/wombat-events.test.ts +0 -147
- package/src/dex/wombat/wombat-gas-estimation.test.ts +0 -29
- package/src/dex/wombat/wombat-integration.test.ts +0 -217
- package/src/dex/wombat/wombat-pool.ts +0 -688
- package/src/dex/wombat/wombat-quoter.ts +0 -269
- package/src/dex/wombat/wombat.ts +0 -467
- package/src/dex/woo-fi-v2/config.ts +0 -100
- package/src/dex/woo-fi-v2/constants.ts +0 -22
- package/src/dex/woo-fi-v2/decoders.ts +0 -45
- package/src/dex/woo-fi-v2/types.ts +0 -64
- package/src/dex/woo-fi-v2/utils.ts +0 -19
- package/src/dex/woo-fi-v2/woo-fi-v2-e2e.test.ts +0 -282
- package/src/dex/woo-fi-v2/woo-fi-v2-integration.test.ts +0 -495
- package/src/dex/woo-fi-v2/woo-fi-v2-math.ts +0 -228
- package/src/dex/woo-fi-v2/woo-fi-v2-pool.ts +0 -143
- package/src/dex/woo-fi-v2/woo-fi-v2.ts +0 -528
- package/src/dex/wsteth/config.ts +0 -16
- package/src/dex/wsteth/types.ts +0 -13
- package/src/dex/wsteth/wsteth-e2e.test.ts +0 -96
- package/src/dex/wsteth/wsteth-gas-estimation.test.ts +0 -41
- package/src/dex/wsteth/wsteth-integration.test.ts +0 -200
- package/src/dex/wsteth/wsteth.ts +0 -304
- package/src/dex-helper/dummy-dex-helper.ts +0 -379
- package/src/dex-helper/dummy-limit-order-provider.ts +0 -74
- package/src/dex-helper/iblock-manager.ts +0 -60
- package/src/dex-helper/icache.ts +0 -85
- package/src/dex-helper/idex-helper.ts +0 -27
- package/src/dex-helper/ilimit-order-provider.ts +0 -27
- package/src/dex-helper/index.ts +0 -16
- package/src/dex-helper/irequest-wrapper.ts +0 -67
- package/src/executor/Executor01BytecodeBuilder.ts +0 -479
- package/src/executor/Executor02BytecodeBuilder.ts +0 -1419
- package/src/executor/Executor03BytecodeBuilder.ts +0 -473
- package/src/executor/ExecutorBytecodeBuilder.ts +0 -453
- package/src/executor/ExecutorDetector.ts +0 -131
- package/src/executor/WETHBytecodeBuilder.ts +0 -58
- package/src/executor/__snapshots__/executor01-bytecode-builder-snapshot.test.ts.snap +0 -35
- package/src/executor/__snapshots__/executor02-bytecode-builder-snapshot.test.ts.snap +0 -23
- package/src/executor/constants.ts +0 -66
- package/src/executor/executor01-bytecode-builder-e2e.test.ts +0 -1503
- package/src/executor/executor01-bytecode-builder-snapshot.test.ts +0 -271
- package/src/executor/executor02-bytecode-builder-e2e.test.ts +0 -1578
- package/src/executor/executor02-bytecode-builder-snapshot.test.ts +0 -188
- package/src/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +0 -16
- package/src/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -16
- package/src/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -16
- package/src/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -16
- package/src/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -16
- package/src/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -16
- package/src/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -16
- package/src/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdt-usdc-dai.json +0 -16
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-eth-usdc.json +0 -9
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-eth.json +0 -9
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-wbtc.json +0 -9
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-eth-steth.json +0 -9
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-steth-eth.json +0 -9
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-usdc-usdt.json +0 -9
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-eth-usdc.json +0 -9
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-eth.json +0 -9
- package/src/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-usdt.json +0 -9
- package/src/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -12
- package/src/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -7
- package/src/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -7
- package/src/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -7
- package/src/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -7
- package/src/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -12
- package/src/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-eth-usdc.json +0 -7
- package/src/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-usdc-eth.json +0 -7
- package/src/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +0 -78
- package/src/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -81
- package/src/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -78
- package/src/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -78
- package/src/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -81
- package/src/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -81
- package/src/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -81
- package/src/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdt-usdc-dai.json +0 -81
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-eth-usdc.json +0 -64
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-eth.json +0 -85
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-wbtc.json +0 -64
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-eth-steth.json +0 -52
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-steth-eth.json +0 -52
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-usdc-usdt.json +0 -52
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-eth-usdc.json +0 -55
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-eth.json +0 -55
- package/src/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-usdt.json +0 -55
- package/src/executor/fixtures/executor02/exchange-params/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -23
- package/src/executor/fixtures/executor02/exchange-params/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -37
- package/src/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -23
- package/src/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -23
- package/src/executor/fixtures/executor02/exchange-params/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -51
- package/src/executor/fixtures/executor02/exchange-params/price-route-multiswap-univ3-usdt-dai-eth.json +0 -58
- package/src/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -23
- package/src/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -23
- package/src/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -9
- package/src/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -16
- package/src/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +0 -23
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -12
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -7
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -12
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -12
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -7
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-univ3-usdt-dai-eth.json +0 -7
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -7
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -7
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -7
- package/src/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -7
- package/src/executor/fixtures/executor02/routes/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -130
- package/src/executor/fixtures/executor02/routes/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -136
- package/src/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -100
- package/src/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -100
- package/src/executor/fixtures/executor02/routes/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -166
- package/src/executor/fixtures/executor02/routes/price-route-multiswap-univ3-usdt-dai-eth.json +0 -190
- package/src/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -114
- package/src/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -114
- package/src/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -55
- package/src/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -73
- package/src/executor/fixtures/executor02/routes/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +0 -82
- package/src/executor/types.ts +0 -45
- package/src/executor/utils.ts +0 -62
- package/src/generic-swap-transaction-builder.ts +0 -753
- package/src/implementations/local-paraswap-sdk.ts +0 -342
- package/src/index.ts +0 -38
- package/src/lens.ts +0 -8
- package/src/lib/api3-feed.ts +0 -175
- package/src/lib/benqi/staked-avax.ts +0 -123
- package/src/lib/chainlink.ts +0 -113
- package/src/lib/curve/encoder.ts +0 -19
- package/src/lib/decoders.ts +0 -199
- package/src/lib/erc1271-utils.ts +0 -24
- package/src/lib/fetcher/fetcher.ts +0 -183
- package/src/lib/fetcher/wsFetcher.ts +0 -158
- package/src/lib/generics-events-subscribers/erc20-event-subscriber-factory.ts +0 -18
- package/src/lib/generics-events-subscribers/erc20-event-subscriber.test.ts +0 -126
- package/src/lib/generics-events-subscribers/erc20-event-subscriber.ts +0 -261
- package/src/lib/generics-events-subscribers/types.ts +0 -41
- package/src/lib/generics-events-subscribers/utils.ts +0 -37
- package/src/lib/log-messages-suppressor.ts +0 -173
- package/src/lib/log4js.ts +0 -88
- package/src/lib/multi-wrapper.ts +0 -108
- package/src/lib/promise-scheduler.ts +0 -55
- package/src/lib/pub-sub.ts +0 -232
- package/src/lib/stateful-rpc-poller/state-polling-manager.ts +0 -320
- package/src/lib/stateful-rpc-poller/stateful-rpc-poller.ts +0 -604
- package/src/lib/stateful-rpc-poller/types.ts +0 -66
- package/src/lib/stateful-rpc-poller/utils.ts +0 -23
- package/src/lib/task-scheduler.ts +0 -64
- package/src/lib/token-transfer-fee.ts +0 -42
- package/src/lib/tokens/balancer-fetcher.ts +0 -283
- package/src/lib/tokens/types.ts +0 -102
- package/src/lib/tokens/utils.ts +0 -179
- package/src/lib/utils-interfaces.ts +0 -4
- package/src/lib/validators.ts +0 -34
- package/src/pools-helper.ts +0 -58
- package/src/pricing-helper.ts +0 -328
- package/src/rebase-tokens.json +0 -17
- package/src/router/buy.ts +0 -101
- package/src/router/directswap.ts +0 -101
- package/src/router/index.ts +0 -48
- package/src/router/irouter.ts +0 -20
- package/src/router/megaswap.ts +0 -88
- package/src/router/multiswap.ts +0 -96
- package/src/router/payload-encoder.ts +0 -293
- package/src/router/simpleswap.ts +0 -369
- package/src/router/simpleswapnft.ts +0 -138
- package/src/stateful-event-subscriber.ts +0 -512
- package/src/transaction-builder.ts +0 -129
- package/src/types.ts +0 -357
- package/src/utils.ts +0 -410
- package/tests/constants-e2e.ts +0 -2230
- package/tests/debug-price-route.test.ts +0 -55
- package/tests/generate-new-limit-order.ts +0 -107
- package/tests/payload-encoder.test.ts +0 -49
- package/tests/tenderly-simulation.test.ts +0 -151
- package/tests/tenderly-simulation.ts +0 -698
- package/tests/token-storage-slots.json +0 -738
- package/tests/transaction-builder.test.ts +0 -234
- package/tests/utils-e2e.ts +0 -651
- package/tests/utils-events.ts +0 -186
- package/tests/utils.ts +0 -127
- package/tests/v6/utils-e2e-v6.ts +0 -103
- package/tsconfig.json +0 -23
|
@@ -1,1724 +0,0 @@
|
|
|
1
|
-
import { Interface } from '@ethersproject/abi';
|
|
2
|
-
import { assert, DeepReadonly } from 'ts-essentials';
|
|
3
|
-
import _, { keyBy } from 'lodash';
|
|
4
|
-
import {
|
|
5
|
-
AdapterExchangeParam,
|
|
6
|
-
Address,
|
|
7
|
-
DexExchangeParam,
|
|
8
|
-
ExchangePrices,
|
|
9
|
-
ExchangeTxInfo,
|
|
10
|
-
Log,
|
|
11
|
-
Logger,
|
|
12
|
-
PoolLiquidity,
|
|
13
|
-
PoolPrices,
|
|
14
|
-
PreprocessTransactionOptions,
|
|
15
|
-
SimpleExchangeParam,
|
|
16
|
-
Token,
|
|
17
|
-
TxInfo,
|
|
18
|
-
} from '../../types';
|
|
19
|
-
import {
|
|
20
|
-
ETHER_ADDRESS,
|
|
21
|
-
MAX_INT,
|
|
22
|
-
Network,
|
|
23
|
-
NULL_ADDRESS,
|
|
24
|
-
SUBGRAPH_TIMEOUT,
|
|
25
|
-
SwapSide,
|
|
26
|
-
} from '../../constants';
|
|
27
|
-
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
28
|
-
import { StablePool } from './pools/stable/StablePool';
|
|
29
|
-
import { WeightedPool } from './pools/weighted/WeightedPool';
|
|
30
|
-
import { PhantomStablePool } from './pools/phantom-stable/PhantomStablePool';
|
|
31
|
-
import { LinearPool } from './pools/linear/LinearPool';
|
|
32
|
-
import { Gyro3Pool } from './pools/gyro/Gyro3Pool';
|
|
33
|
-
import { GyroEPool } from './pools/gyro/GyroEPool';
|
|
34
|
-
import VaultABI from '../../abi/balancer-v2/vault.json';
|
|
35
|
-
import DirectSwapABI from '../../abi/DirectSwap.json';
|
|
36
|
-
import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
37
|
-
import {
|
|
38
|
-
getBigIntPow,
|
|
39
|
-
getDexKeysWithNetwork,
|
|
40
|
-
uuidToBytes16,
|
|
41
|
-
} from '../../utils';
|
|
42
|
-
import { Context, IDex } from '../../dex/idex';
|
|
43
|
-
import { IDexHelper } from '../../dex-helper';
|
|
44
|
-
import {
|
|
45
|
-
BalancerV2BatchSwapParam,
|
|
46
|
-
BalancerPoolTypes,
|
|
47
|
-
BalancerSwap,
|
|
48
|
-
BalancerV2Data,
|
|
49
|
-
BalancerV2DirectParam,
|
|
50
|
-
OptimizedBalancerV2Data,
|
|
51
|
-
PoolState,
|
|
52
|
-
PoolStateCache,
|
|
53
|
-
PoolStateMap,
|
|
54
|
-
SubgraphPoolAddressDictionary,
|
|
55
|
-
SubgraphPoolBase,
|
|
56
|
-
SwapTypes,
|
|
57
|
-
BalancerV2DirectParamV6,
|
|
58
|
-
BalancerV2DirectParamV6Swap,
|
|
59
|
-
BalancerV2SwapParam,
|
|
60
|
-
BalancerV2SingleSwap,
|
|
61
|
-
} from './types';
|
|
62
|
-
import {
|
|
63
|
-
getLocalDeadlineAsFriendlyPlaceholder,
|
|
64
|
-
SimpleExchange,
|
|
65
|
-
} from '../simple-exchange';
|
|
66
|
-
import { Adapters, BalancerConfig } from './config';
|
|
67
|
-
import {
|
|
68
|
-
getAllPoolsUsedInPaths,
|
|
69
|
-
isSameAddress,
|
|
70
|
-
poolGetMainTokens,
|
|
71
|
-
poolGetPathForTokenInOut,
|
|
72
|
-
} from './utils';
|
|
73
|
-
import {
|
|
74
|
-
DirectMethods,
|
|
75
|
-
DirectMethodsV6,
|
|
76
|
-
MIN_USD_LIQUIDITY_TO_FETCH,
|
|
77
|
-
STABLE_GAS_COST,
|
|
78
|
-
VARIABLE_GAS_COST_PER_CYCLE,
|
|
79
|
-
} from './constants';
|
|
80
|
-
import { NumberAsString, OptimalSwapExchange } from '@paraswap/core';
|
|
81
|
-
import { hexConcat, hexlify, hexZeroPad, solidityPack } from 'ethers/lib/utils';
|
|
82
|
-
import BalancerVaultABI from '../../abi/balancer-v2/vault.json';
|
|
83
|
-
import { BigNumber } from 'ethers';
|
|
84
|
-
import { SpecialDex } from '../../executor/types';
|
|
85
|
-
import { extractReturnAmountPosition } from '../../executor/utils';
|
|
86
|
-
|
|
87
|
-
// If you disable some pool, don't forget to clear the cache, otherwise changes won't be applied immediately
|
|
88
|
-
const enabledPoolTypes = [
|
|
89
|
-
// BalancerPoolTypes.MetaStable, // BOOSTED POOLS Disabled since vulnerability https://github.com/BalancerMaxis/multisig-ops/blob/main/BIPs/00notGov/2023-08-mitigation.md
|
|
90
|
-
BalancerPoolTypes.Stable,
|
|
91
|
-
BalancerPoolTypes.Weighted,
|
|
92
|
-
BalancerPoolTypes.LiquidityBootstrapping,
|
|
93
|
-
BalancerPoolTypes.Investment,
|
|
94
|
-
BalancerPoolTypes.StablePhantom,
|
|
95
|
-
BalancerPoolTypes.AaveLinear,
|
|
96
|
-
BalancerPoolTypes.ERC4626Linear,
|
|
97
|
-
BalancerPoolTypes.Linear,
|
|
98
|
-
BalancerPoolTypes.ComposableStable,
|
|
99
|
-
BalancerPoolTypes.BeefyLinear,
|
|
100
|
-
BalancerPoolTypes.GearboxLinear,
|
|
101
|
-
BalancerPoolTypes.MidasLinear,
|
|
102
|
-
BalancerPoolTypes.ReaperLinear,
|
|
103
|
-
BalancerPoolTypes.SiloLinear,
|
|
104
|
-
BalancerPoolTypes.TetuLinear,
|
|
105
|
-
BalancerPoolTypes.YearnLinear,
|
|
106
|
-
BalancerPoolTypes.GyroE,
|
|
107
|
-
BalancerPoolTypes.Gyro3,
|
|
108
|
-
];
|
|
109
|
-
|
|
110
|
-
const disabledPoolIds = [
|
|
111
|
-
// broken ?
|
|
112
|
-
'0xbd482ffb3e6e50dc1c437557c3bea2b68f3683ee0000000000000000000003c6',
|
|
113
|
-
|
|
114
|
-
/* DISABLED POOLS SINCE VULNERABILITY https://github.com/BalancerMaxis/multisig-ops/blob/main/BIPs/00notGov/2023-08-mitigation.md*/
|
|
115
|
-
/* START:2023-08-mitigation */
|
|
116
|
-
//mainnet
|
|
117
|
-
'0xbf2ef8bdc2fc0f3203b3a01778e3ec5009aeef3300000000000000000000058d',
|
|
118
|
-
'0x99c88ad7dc566616548adde8ed3effa730eb6c3400000000000000000000049a',
|
|
119
|
-
'0x60683b05e9a39e3509d8fdb9c959f23170f8a0fa000000000000000000000489',
|
|
120
|
-
'0xa13a9247ea42d743238089903570127dda72fe4400000000000000000000035d',
|
|
121
|
-
'0x7b50775383d3d6f0215a8f290f2c9e2eebbeceb20000000000000000000000fe',
|
|
122
|
-
'0x25accb7943fd73dda5e23ba6329085a3c24bfb6a000200000000000000000387',
|
|
123
|
-
'0x50cf90b954958480b8df7958a9e965752f62712400000000000000000000046f',
|
|
124
|
-
'0x133d241f225750d2c92948e464a5a80111920331000000000000000000000476',
|
|
125
|
-
'0x8a6b25e33b12d1bb6929a8793961076bd1f9d3eb0002000000000000000003e8',
|
|
126
|
-
'0x959216bb492b2efa72b15b7aacea5b5c984c3cca000200000000000000000472',
|
|
127
|
-
'0x9b692f571b256140a39a34676bffa30634c586e100000000000000000000059d',
|
|
128
|
-
'0xe7b1d394f3b40abeaa0b64a545dbcf89da1ecb3f00010000000000000000009a',
|
|
129
|
-
|
|
130
|
-
// polygon
|
|
131
|
-
'0xb3d658d5b95bf04e2932370dd1ff976fe18dd66a000000000000000000000ace',
|
|
132
|
-
'0x48e6b98ef6329f8f0a30ebb8c7c960330d64808500000000000000000000075b',
|
|
133
|
-
'0xb54b2125b711cd183edd3dd09433439d5396165200000000000000000000075e',
|
|
134
|
-
|
|
135
|
-
// arbitrum
|
|
136
|
-
'0xa8af146d79ac0bb981e4e0d8b788ec5711b1d5d000000000000000000000047b',
|
|
137
|
-
'0x077794c30afeccdf5ad2abc0588e8cee7197b71a000000000000000000000352',
|
|
138
|
-
'0x519cce718fcd11ac09194cff4517f12d263be067000000000000000000000382',
|
|
139
|
-
|
|
140
|
-
// optimism
|
|
141
|
-
'0x23ca0306b21ea71552b148cf3c4db4fc85ae19290000000000000000000000ac',
|
|
142
|
-
'0x62cf35db540152e94936de63efc90d880d4e241b0000000000000000000000ef',
|
|
143
|
-
'0x098f32d98d0d64dba199fc1923d3bf4192e787190001000000000000000000d2',
|
|
144
|
-
'0x43da214fab3315aa6c02e0b8f2bfb7ef2e3c60a50000000000000000000000ae',
|
|
145
|
-
'0xb1c9ac57594e9b1ec0f3787d9f6744ef4cb0a02400000000000000000000006e',
|
|
146
|
-
'0xde45f101250f2ca1c0f8adfc172576d10c12072d00000000000000000000003f',
|
|
147
|
-
'0x05e7732bf9ae5592e6aa05afe8cd80f7ab0a7bea00020000000000000000005a',
|
|
148
|
-
'0x981fb05b738e981ac532a99e77170ecb4bc27aef00010000000000000000004b',
|
|
149
|
-
'0x6222ae1d2a9f6894da50aa25cb7b303497f9bebd000000000000000000000046',
|
|
150
|
-
'0x3c74c4ed512050eb843d89fb9dcd5ebb4668eb6d0002000000000000000000cc',
|
|
151
|
-
|
|
152
|
-
// fantom
|
|
153
|
-
'0xc0064b291bd3d4ba0e44ccfc81bf8e7f7a579cd200000000000000000000042c',
|
|
154
|
-
'0x6e6dc948ce85c62125ff7a1e543d761a88f0a4cb000000000000000000000743',
|
|
155
|
-
'0x78ab08bf98f90f29a09c9b1d85b3b549369b03a3000100000000000000000354',
|
|
156
|
-
'0x302b8b64795b064cadc32f74993a6372498608070001000000000000000003e0',
|
|
157
|
-
'0x5ddb92a5340fd0ead3987d3661afcd6104c3b757000000000000000000000187',
|
|
158
|
-
'0xdfc65c1f15ad3507754ef0fd4ba67060c108db7e000000000000000000000406',
|
|
159
|
-
'0x6da14f5acd58dd5c8e486cfa1dc1c550f5c61c1c0000000000000000000003cf',
|
|
160
|
-
'0x592fa9f9d58065096f2b7838709c116957d7b5cf00020000000000000000043c',
|
|
161
|
-
'0xf47f4d59c863c02cbfa3eefe6771b9c9fbe7b97800000000000000000000072b',
|
|
162
|
-
'0xff2753aaba51c9f84689b9bd0a21b3cf380a1cff00000000000000000000072e',
|
|
163
|
-
'0x10441785a928040b456a179691141c48356eb3a50001000000000000000002fa',
|
|
164
|
-
'0x64b301e21d640f9bef90458b0987d81fb4cf1b9e00020000000000000000022e',
|
|
165
|
-
'0xba0e9aea8a7fa1daab4edf244191f2387a4e472b000100000000000000000737',
|
|
166
|
-
'0x1e2576344d49779bdbb71b1b76193d27e6f996b700020000000000000000032d',
|
|
167
|
-
'0xa10285f445bcb521f1d623300dc4998b02f11c8f00000000000000000000043b',
|
|
168
|
-
|
|
169
|
-
// zkevm
|
|
170
|
-
'0x6f34a44fce1506352a171232163e7716dd073ade000200000000000000000015',
|
|
171
|
-
'0xe274c9deb6ed34cfe4130f8d0a8a948dea5bb28600000000000000000000000d',
|
|
172
|
-
/* END:2023-08-mitigation */
|
|
173
|
-
];
|
|
174
|
-
|
|
175
|
-
const fetchAllPools = `query ($count: Int) {
|
|
176
|
-
pools: pools(
|
|
177
|
-
first: $count
|
|
178
|
-
orderBy: totalLiquidity
|
|
179
|
-
orderDirection: desc
|
|
180
|
-
where: {
|
|
181
|
-
and: [
|
|
182
|
-
{
|
|
183
|
-
or: [
|
|
184
|
-
{ isInRecoveryMode: false }
|
|
185
|
-
{ isInRecoveryMode: null }
|
|
186
|
-
]
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
totalLiquidity_gt: ${MIN_USD_LIQUIDITY_TO_FETCH.toString()},
|
|
190
|
-
totalShares_not_in: ["0", "0.000000000001"],
|
|
191
|
-
id_not_in: [
|
|
192
|
-
${disabledPoolIds.map(p => `"${p}"`).join(', ')}
|
|
193
|
-
],
|
|
194
|
-
address_not_in: [
|
|
195
|
-
"0x0afbd58beca09545e4fb67772faf3858e610bcd0",
|
|
196
|
-
"0x2ff1a9dbdacd55297452cfd8a4d94724bc22a5f7",
|
|
197
|
-
"0xbc0f2372008005471874e426e86ccfae7b4de79d",
|
|
198
|
-
"0xdba274b4d04097b90a72b62467d828cefd708037",
|
|
199
|
-
"0xf22ff21e17157340575158ad7394e068048dd98b",
|
|
200
|
-
"0xf71d0774b214c4cf51e33eb3d30ef98132e4dbaa",
|
|
201
|
-
],
|
|
202
|
-
swapEnabled: true,
|
|
203
|
-
poolType_in: [
|
|
204
|
-
${enabledPoolTypes.map(p => `"${p}"`).join(', ')}
|
|
205
|
-
]
|
|
206
|
-
}
|
|
207
|
-
]
|
|
208
|
-
}
|
|
209
|
-
) {
|
|
210
|
-
id
|
|
211
|
-
address
|
|
212
|
-
poolType
|
|
213
|
-
poolTypeVersion
|
|
214
|
-
tokens (orderBy: index) {
|
|
215
|
-
address
|
|
216
|
-
decimals
|
|
217
|
-
}
|
|
218
|
-
mainIndex
|
|
219
|
-
wrappedIndex
|
|
220
|
-
|
|
221
|
-
root3Alpha
|
|
222
|
-
}
|
|
223
|
-
}`;
|
|
224
|
-
// skipping low liquidity composableStablePool (0xbd482ffb3e6e50dc1c437557c3bea2b68f3683ee0000000000000000000003c6) with oracle issues. Experimental.
|
|
225
|
-
|
|
226
|
-
const fetchWeightUpdating = `query ($count: Int, $timestampPast: Int, $timestampFuture: Int) {
|
|
227
|
-
gradualWeightUpdates(
|
|
228
|
-
first: $count,
|
|
229
|
-
where: {startTimestamp_lt: $timestampFuture, endTimestamp_gt: $timestampPast }
|
|
230
|
-
) {
|
|
231
|
-
poolId {
|
|
232
|
-
address
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}`;
|
|
236
|
-
|
|
237
|
-
const MAX_POOL_CNT = 1000; // Taken from SOR
|
|
238
|
-
const POOL_CACHE_TTL = 60 * 60; // 1 hr
|
|
239
|
-
const POOL_EVENT_DISABLED_TTL = 5 * 60; // 5 min
|
|
240
|
-
const POOL_EVENT_REENABLE_DELAY = 7 * 24 * 60 * 60; // 1 week
|
|
241
|
-
|
|
242
|
-
function typecastReadOnlyPoolState(pool: DeepReadonly<PoolState>): PoolState {
|
|
243
|
-
return _.cloneDeep(pool) as PoolState;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
export class BalancerV2EventPool extends StatefulEventSubscriber<PoolStateMap> {
|
|
247
|
-
public vaultInterface: Interface;
|
|
248
|
-
|
|
249
|
-
handlers: {
|
|
250
|
-
[event: string]: (event: any, pool: PoolState, log: Log) => PoolState;
|
|
251
|
-
} = {};
|
|
252
|
-
|
|
253
|
-
pools: {
|
|
254
|
-
[type: string]:
|
|
255
|
-
| WeightedPool
|
|
256
|
-
| StablePool
|
|
257
|
-
| LinearPool
|
|
258
|
-
| PhantomStablePool
|
|
259
|
-
| Gyro3Pool
|
|
260
|
-
| GyroEPool;
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
public allPools: SubgraphPoolBase[] = [];
|
|
264
|
-
vaultDecoder: (log: Log) => any;
|
|
265
|
-
|
|
266
|
-
buySupportedPoolTypes: Set<BalancerPoolTypes> = new Set([
|
|
267
|
-
BalancerPoolTypes.Weighted,
|
|
268
|
-
BalancerPoolTypes.GyroE,
|
|
269
|
-
BalancerPoolTypes.ComposableStable,
|
|
270
|
-
]);
|
|
271
|
-
|
|
272
|
-
eventSupportedPoolTypes: BalancerPoolTypes[] = [
|
|
273
|
-
BalancerPoolTypes.Stable,
|
|
274
|
-
BalancerPoolTypes.Weighted,
|
|
275
|
-
BalancerPoolTypes.LiquidityBootstrapping,
|
|
276
|
-
BalancerPoolTypes.Investment,
|
|
277
|
-
|
|
278
|
-
// Need to check if we can support these pools with event base
|
|
279
|
-
// BalancerPoolTypes.ComposableStable,
|
|
280
|
-
// BalancerPoolTypes.Linear,
|
|
281
|
-
// BalancerPoolTypes.MetaStable,
|
|
282
|
-
// BalancerPoolTypes.AaveLinear,
|
|
283
|
-
// BalancerPoolTypes.ERC4626Linear,
|
|
284
|
-
|
|
285
|
-
// If this pool is enabled as event supported, it is failing BeetsFi: can not decode getRate()
|
|
286
|
-
// BalancerPoolTypes.StablePhantom,
|
|
287
|
-
];
|
|
288
|
-
|
|
289
|
-
eventRemovedPools = (
|
|
290
|
-
[
|
|
291
|
-
// Gradual weight changes are not currently handled in event system
|
|
292
|
-
// This pool keeps changing weights and is causing pricing issue
|
|
293
|
-
// But should now be handled by eventDisabledPools so don't need here!
|
|
294
|
-
//'0x34809aEDF93066b49F638562c42A9751eDb36DF5',
|
|
295
|
-
] as Address[]
|
|
296
|
-
).map(s => s.toLowerCase());
|
|
297
|
-
|
|
298
|
-
constructor(
|
|
299
|
-
parentName: string,
|
|
300
|
-
protected network: number,
|
|
301
|
-
public vaultAddress: Address,
|
|
302
|
-
protected subgraphURL: string,
|
|
303
|
-
protected dexHelper: IDexHelper,
|
|
304
|
-
logger: Logger,
|
|
305
|
-
) {
|
|
306
|
-
super(parentName, vaultAddress, dexHelper, logger);
|
|
307
|
-
this.vaultInterface = new Interface(VaultABI);
|
|
308
|
-
const weightedPool = new WeightedPool(
|
|
309
|
-
this.vaultAddress,
|
|
310
|
-
this.vaultInterface,
|
|
311
|
-
);
|
|
312
|
-
const stablePool = new StablePool(this.vaultAddress, this.vaultInterface);
|
|
313
|
-
const stablePhantomPool = new PhantomStablePool(
|
|
314
|
-
this.vaultAddress,
|
|
315
|
-
this.vaultInterface,
|
|
316
|
-
);
|
|
317
|
-
/*
|
|
318
|
-
ComposableStable has same maths as StablePhantom.
|
|
319
|
-
The main difference is that ComposableStables have join/exit functions when StablePhantom did not.
|
|
320
|
-
The difference of note for swaps is ComposableStable must use 'actualSupply' instead of VirtualSupply.
|
|
321
|
-
VirtualSupply could be calculated easily whereas actualSupply cannot hence the use of onchain call.
|
|
322
|
-
*/
|
|
323
|
-
const composableStable = new PhantomStablePool(
|
|
324
|
-
this.vaultAddress,
|
|
325
|
-
this.vaultInterface,
|
|
326
|
-
true,
|
|
327
|
-
);
|
|
328
|
-
const linearPool = new LinearPool(this.vaultAddress, this.vaultInterface);
|
|
329
|
-
const gyro3Pool = new Gyro3Pool(this.vaultAddress, this.vaultInterface);
|
|
330
|
-
const gyroEPool = new GyroEPool(this.vaultAddress, this.vaultInterface);
|
|
331
|
-
|
|
332
|
-
this.pools = {};
|
|
333
|
-
this.pools[BalancerPoolTypes.Weighted] = weightedPool;
|
|
334
|
-
this.pools[BalancerPoolTypes.Stable] = stablePool;
|
|
335
|
-
this.pools[BalancerPoolTypes.MetaStable] = stablePool;
|
|
336
|
-
this.pools[BalancerPoolTypes.LiquidityBootstrapping] = weightedPool;
|
|
337
|
-
this.pools[BalancerPoolTypes.Investment] = weightedPool;
|
|
338
|
-
this.pools[BalancerPoolTypes.StablePhantom] = stablePhantomPool;
|
|
339
|
-
this.pools[BalancerPoolTypes.ComposableStable] = composableStable;
|
|
340
|
-
// All these Linear pool have same maths and ABI as AaveLinear but have different factories
|
|
341
|
-
this.pools[BalancerPoolTypes.AaveLinear] = linearPool;
|
|
342
|
-
this.pools[BalancerPoolTypes.ERC4626Linear] = linearPool;
|
|
343
|
-
this.pools[BalancerPoolTypes.GearboxLinear] = linearPool;
|
|
344
|
-
this.pools[BalancerPoolTypes.MidasLinear] = linearPool;
|
|
345
|
-
this.pools[BalancerPoolTypes.ReaperLinear] = linearPool;
|
|
346
|
-
this.pools[BalancerPoolTypes.SiloLinear] = linearPool;
|
|
347
|
-
this.pools[BalancerPoolTypes.TetuLinear] = linearPool;
|
|
348
|
-
this.pools[BalancerPoolTypes.YearnLinear] = linearPool;
|
|
349
|
-
this.pools[BalancerPoolTypes.BeefyLinear] = linearPool;
|
|
350
|
-
// Beets uses "Linear" generically for all linear pool types
|
|
351
|
-
this.pools[BalancerPoolTypes.Linear] = linearPool;
|
|
352
|
-
|
|
353
|
-
this.pools[BalancerPoolTypes.Gyro3] = gyro3Pool;
|
|
354
|
-
this.pools[BalancerPoolTypes.GyroE] = gyroEPool;
|
|
355
|
-
|
|
356
|
-
this.vaultDecoder = (log: Log) => this.vaultInterface.parseLog(log);
|
|
357
|
-
this.addressesSubscribed = [vaultAddress];
|
|
358
|
-
|
|
359
|
-
// Add default handlers
|
|
360
|
-
this.handlers['Swap'] = this.handleSwap.bind(this);
|
|
361
|
-
this.handlers['PoolBalanceChanged'] =
|
|
362
|
-
this.handlePoolBalanceChanged.bind(this);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
protected processLog(
|
|
366
|
-
state: DeepReadonly<PoolStateMap>,
|
|
367
|
-
log: Readonly<Log>,
|
|
368
|
-
): DeepReadonly<PoolStateMap> | null {
|
|
369
|
-
const _state: PoolStateMap = {};
|
|
370
|
-
for (const [address, pool] of Object.entries(state))
|
|
371
|
-
_state[address] = typecastReadOnlyPoolState(pool);
|
|
372
|
-
|
|
373
|
-
try {
|
|
374
|
-
const event = this.vaultDecoder(log);
|
|
375
|
-
if (event.name in this.handlers) {
|
|
376
|
-
const poolAddress = event.args.poolId.slice(0, 42).toLowerCase();
|
|
377
|
-
// Only update the _state if we are tracking the pool
|
|
378
|
-
if (poolAddress in _state) {
|
|
379
|
-
_state[poolAddress] = this.handlers[event.name](
|
|
380
|
-
event,
|
|
381
|
-
_state[poolAddress],
|
|
382
|
-
log,
|
|
383
|
-
);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
return _state;
|
|
387
|
-
} catch (e) {
|
|
388
|
-
this.logger.error(
|
|
389
|
-
`Error_${this.parentName}_processLog could not parse the log with topic ${log.topics}:`,
|
|
390
|
-
e,
|
|
391
|
-
);
|
|
392
|
-
return null;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
async fetchAllSubgraphPools(): Promise<SubgraphPoolBase[]> {
|
|
397
|
-
const cacheKey = 'BalancerV2SubgraphPools2';
|
|
398
|
-
const cachedPools = await this.dexHelper.cache.get(
|
|
399
|
-
this.parentName,
|
|
400
|
-
this.network,
|
|
401
|
-
cacheKey,
|
|
402
|
-
);
|
|
403
|
-
if (cachedPools) {
|
|
404
|
-
const allPools = JSON.parse(cachedPools);
|
|
405
|
-
this.logger.info(
|
|
406
|
-
`Got ${allPools.length} ${this.parentName}_${this.network} pools from cache`,
|
|
407
|
-
);
|
|
408
|
-
return allPools;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
this.logger.info(
|
|
412
|
-
`Fetching ${this.parentName}_${this.network} Pools from subgraph`,
|
|
413
|
-
);
|
|
414
|
-
|
|
415
|
-
const variables = {
|
|
416
|
-
count: MAX_POOL_CNT,
|
|
417
|
-
};
|
|
418
|
-
const { data } = await this.dexHelper.httpRequest.querySubgraph(
|
|
419
|
-
this.subgraphURL,
|
|
420
|
-
{ query: fetchAllPools, variables },
|
|
421
|
-
{ timeout: SUBGRAPH_TIMEOUT },
|
|
422
|
-
);
|
|
423
|
-
|
|
424
|
-
if (!(data && data.pools))
|
|
425
|
-
throw new Error('Unable to fetch pools from the subgraph');
|
|
426
|
-
|
|
427
|
-
const poolsMap = keyBy(data.pools, 'address');
|
|
428
|
-
const allPools: SubgraphPoolBase[] = data.pools.map(
|
|
429
|
-
(pool: Omit<SubgraphPoolBase, 'mainTokens'>) => ({
|
|
430
|
-
...pool,
|
|
431
|
-
mainTokens: poolGetMainTokens(pool, poolsMap),
|
|
432
|
-
tokensMap: pool.tokens.reduce(
|
|
433
|
-
(acc, token) => ({ ...acc, [token.address.toLowerCase()]: token }),
|
|
434
|
-
{},
|
|
435
|
-
),
|
|
436
|
-
}),
|
|
437
|
-
);
|
|
438
|
-
|
|
439
|
-
this.dexHelper.cache.setex(
|
|
440
|
-
this.parentName,
|
|
441
|
-
this.network,
|
|
442
|
-
cacheKey,
|
|
443
|
-
POOL_CACHE_TTL,
|
|
444
|
-
JSON.stringify(allPools),
|
|
445
|
-
);
|
|
446
|
-
|
|
447
|
-
this.logger.info(
|
|
448
|
-
`Got ${allPools.length} ${this.parentName}_${this.network} pools from subgraph`,
|
|
449
|
-
);
|
|
450
|
-
|
|
451
|
-
return allPools;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
async generateState(blockNumber: number): Promise<Readonly<PoolStateMap>> {
|
|
455
|
-
const allPools = await this.fetchAllSubgraphPools();
|
|
456
|
-
this.allPools = allPools;
|
|
457
|
-
|
|
458
|
-
const eventSupportedPools = allPools.filter(
|
|
459
|
-
pool =>
|
|
460
|
-
this.eventSupportedPoolTypes.includes(pool.poolType) &&
|
|
461
|
-
!this.eventRemovedPools.includes(pool.address.toLowerCase()),
|
|
462
|
-
);
|
|
463
|
-
const allPoolsLatestState = await this.getOnChainState(
|
|
464
|
-
eventSupportedPools,
|
|
465
|
-
blockNumber,
|
|
466
|
-
);
|
|
467
|
-
|
|
468
|
-
return allPoolsLatestState;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
handleSwap(event: any, pool: PoolState, log: Log): PoolState {
|
|
472
|
-
const tokenIn = event.args.tokenIn.toLowerCase();
|
|
473
|
-
const amountIn = BigInt(event.args.amountIn.toString());
|
|
474
|
-
const tokenOut = event.args.tokenOut.toLowerCase();
|
|
475
|
-
const amountOut = BigInt(event.args.amountOut.toString());
|
|
476
|
-
pool.tokens[tokenIn].balance += amountIn;
|
|
477
|
-
pool.tokens[tokenOut].balance -= amountOut;
|
|
478
|
-
return pool;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
handlePoolBalanceChanged(event: any, pool: PoolState, log: Log): PoolState {
|
|
482
|
-
const tokens = event.args.tokens.map((t: string) => t.toLowerCase());
|
|
483
|
-
const deltas = event.args.deltas.map((d: any) => BigInt(d.toString()));
|
|
484
|
-
const fees = event.args.protocolFeeAmounts.map((d: any) =>
|
|
485
|
-
BigInt(d.toString()),
|
|
486
|
-
) as bigint[];
|
|
487
|
-
tokens.forEach((t: string, i: number) => {
|
|
488
|
-
const diff = deltas[i] - fees[i];
|
|
489
|
-
pool.tokens[t].balance += diff;
|
|
490
|
-
});
|
|
491
|
-
return pool;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
isSupportedPool(poolType: string): boolean {
|
|
495
|
-
const supportedPoolTypes: string[] = Object.values(BalancerPoolTypes);
|
|
496
|
-
return supportedPoolTypes.includes(poolType);
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
getPricesPool(
|
|
500
|
-
from: Token,
|
|
501
|
-
to: Token,
|
|
502
|
-
subgraphPool: SubgraphPoolBase,
|
|
503
|
-
poolState: PoolState,
|
|
504
|
-
amounts: bigint[],
|
|
505
|
-
unitVolume: bigint,
|
|
506
|
-
side: SwapSide,
|
|
507
|
-
): { unit: bigint; prices: bigint[] } | null {
|
|
508
|
-
if (!this.isSupportedPool(subgraphPool.poolType)) {
|
|
509
|
-
this.logger.error(`Unsupported Pool Type: ${subgraphPool.poolType}`);
|
|
510
|
-
return null;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
if (
|
|
514
|
-
side === SwapSide.BUY &&
|
|
515
|
-
!this.buySupportedPoolTypes.has(subgraphPool.poolType)
|
|
516
|
-
) {
|
|
517
|
-
return null;
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
const amountWithoutZero = amounts.slice(1);
|
|
521
|
-
const pool = this.pools[subgraphPool.poolType];
|
|
522
|
-
|
|
523
|
-
const poolPairData = pool.parsePoolPairData(
|
|
524
|
-
subgraphPool,
|
|
525
|
-
poolState,
|
|
526
|
-
from.address,
|
|
527
|
-
to.address,
|
|
528
|
-
);
|
|
529
|
-
|
|
530
|
-
const swapMaxAmount = pool.getSwapMaxAmount(
|
|
531
|
-
// Don't like this but don't have time to refactor it properly
|
|
532
|
-
poolPairData as any,
|
|
533
|
-
side,
|
|
534
|
-
);
|
|
535
|
-
|
|
536
|
-
const checkedAmounts: bigint[] = new Array(amountWithoutZero.length).fill(
|
|
537
|
-
0n,
|
|
538
|
-
);
|
|
539
|
-
const checkedUnitVolume = pool._nullifyIfMaxAmountExceeded(
|
|
540
|
-
unitVolume,
|
|
541
|
-
swapMaxAmount,
|
|
542
|
-
);
|
|
543
|
-
|
|
544
|
-
let nonZeroAmountIndex = 0;
|
|
545
|
-
for (const [i, amountIn] of amountWithoutZero.entries()) {
|
|
546
|
-
const checkedOutput = pool._nullifyIfMaxAmountExceeded(
|
|
547
|
-
amountIn,
|
|
548
|
-
swapMaxAmount,
|
|
549
|
-
);
|
|
550
|
-
if (checkedOutput === 0n) {
|
|
551
|
-
// Stop earlier because other values are bigger and for sure wont' be tradable
|
|
552
|
-
break;
|
|
553
|
-
}
|
|
554
|
-
nonZeroAmountIndex = i + 1;
|
|
555
|
-
checkedAmounts[i] = checkedOutput;
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
if (nonZeroAmountIndex === 0) {
|
|
559
|
-
return null;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
const unitResult =
|
|
563
|
-
checkedUnitVolume === 0n
|
|
564
|
-
? 0n
|
|
565
|
-
: side === SwapSide.SELL
|
|
566
|
-
? pool.onSell([checkedUnitVolume], poolPairData as any)[0]
|
|
567
|
-
: pool.onBuy([checkedUnitVolume], poolPairData as any)[0];
|
|
568
|
-
|
|
569
|
-
const prices: bigint[] = new Array(amounts.length).fill(0n);
|
|
570
|
-
|
|
571
|
-
const outputs =
|
|
572
|
-
side === SwapSide.SELL
|
|
573
|
-
? pool.onSell(
|
|
574
|
-
amountWithoutZero.slice(0, nonZeroAmountIndex),
|
|
575
|
-
poolPairData as any,
|
|
576
|
-
)
|
|
577
|
-
: pool.onBuy(
|
|
578
|
-
amountWithoutZero.slice(0, nonZeroAmountIndex),
|
|
579
|
-
poolPairData as any,
|
|
580
|
-
);
|
|
581
|
-
|
|
582
|
-
assert(
|
|
583
|
-
outputs.length <= prices.length,
|
|
584
|
-
`Wrong length logic: outputs.length (${outputs.length}) <= prices.length (${prices.length})`,
|
|
585
|
-
);
|
|
586
|
-
|
|
587
|
-
for (const [i, output] of outputs.entries()) {
|
|
588
|
-
// Outputs shifted right to one to keep first entry as 0
|
|
589
|
-
prices[i + 1] = output;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
return { unit: unitResult, prices };
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
async getOnChainState(
|
|
596
|
-
subgraphPoolBase: SubgraphPoolBase[],
|
|
597
|
-
blockNumber: number,
|
|
598
|
-
): Promise<PoolStateMap> {
|
|
599
|
-
const multiCallData = subgraphPoolBase
|
|
600
|
-
.map(pool => {
|
|
601
|
-
if (!this.isSupportedPool(pool.poolType)) return [];
|
|
602
|
-
|
|
603
|
-
return this.pools[pool.poolType].getOnChainCalls(pool);
|
|
604
|
-
})
|
|
605
|
-
.flat();
|
|
606
|
-
|
|
607
|
-
// 500 is an arbitrary number chosen based on the blockGasLimit
|
|
608
|
-
const slicedMultiCallData = _.chunk(multiCallData, 500);
|
|
609
|
-
|
|
610
|
-
const returnData = (
|
|
611
|
-
await Promise.all(
|
|
612
|
-
slicedMultiCallData.map(async _multiCallData =>
|
|
613
|
-
this.dexHelper.multiContract.methods
|
|
614
|
-
.tryAggregate(false, _multiCallData)
|
|
615
|
-
.call({}, blockNumber),
|
|
616
|
-
),
|
|
617
|
-
)
|
|
618
|
-
).flat();
|
|
619
|
-
|
|
620
|
-
let i = 0;
|
|
621
|
-
const onChainStateMap = subgraphPoolBase.reduce(
|
|
622
|
-
(acc: { [address: string]: PoolState }, pool) => {
|
|
623
|
-
if (!this.isSupportedPool(pool.poolType)) return acc;
|
|
624
|
-
|
|
625
|
-
const [decoded, newIndex] = this.pools[
|
|
626
|
-
pool.poolType
|
|
627
|
-
].decodeOnChainCalls(pool, returnData, i);
|
|
628
|
-
i = newIndex;
|
|
629
|
-
acc = { ...acc, ...decoded };
|
|
630
|
-
return acc;
|
|
631
|
-
},
|
|
632
|
-
{},
|
|
633
|
-
);
|
|
634
|
-
|
|
635
|
-
return onChainStateMap;
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
export class BalancerV2
|
|
640
|
-
extends SimpleExchange
|
|
641
|
-
implements
|
|
642
|
-
IDex<
|
|
643
|
-
BalancerV2Data,
|
|
644
|
-
BalancerV2DirectParam | BalancerV2DirectParamV6Swap,
|
|
645
|
-
OptimizedBalancerV2Data
|
|
646
|
-
>
|
|
647
|
-
{
|
|
648
|
-
public eventPools: BalancerV2EventPool;
|
|
649
|
-
|
|
650
|
-
readonly hasConstantPriceLargeAmounts = false;
|
|
651
|
-
readonly isFeeOnTransferSupported = false;
|
|
652
|
-
readonly needWrapNative = true; // temporary
|
|
653
|
-
|
|
654
|
-
readonly directSwapIface = new Interface(DirectSwapABI);
|
|
655
|
-
readonly balancerVaultInterface = new Interface(BalancerVaultABI);
|
|
656
|
-
|
|
657
|
-
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
658
|
-
getDexKeysWithNetwork(BalancerConfig);
|
|
659
|
-
|
|
660
|
-
logger: Logger;
|
|
661
|
-
|
|
662
|
-
// In memory pool state for non-event pools
|
|
663
|
-
nonEventPoolStateCache: PoolStateCache;
|
|
664
|
-
|
|
665
|
-
eventDisabledPoolsTimer?: NodeJS.Timeout;
|
|
666
|
-
eventDisabledPools: Address[] = [];
|
|
667
|
-
|
|
668
|
-
constructor(
|
|
669
|
-
protected network: Network,
|
|
670
|
-
dexKey: string,
|
|
671
|
-
public dexHelper: IDexHelper,
|
|
672
|
-
public vaultAddress: Address = BalancerConfig[dexKey][network].vaultAddress,
|
|
673
|
-
protected subgraphURL: string = BalancerConfig[dexKey][network].subgraphURL,
|
|
674
|
-
protected adapters = Adapters[network],
|
|
675
|
-
) {
|
|
676
|
-
super(dexHelper, dexKey);
|
|
677
|
-
// Initialise cache - this will hold pool state of non-event pools in memory to be reused if block hasn't expired
|
|
678
|
-
this.nonEventPoolStateCache = { blockNumber: 0, poolState: {} };
|
|
679
|
-
this.logger = dexHelper.getLogger(dexKey);
|
|
680
|
-
this.eventPools = new BalancerV2EventPool(
|
|
681
|
-
dexKey,
|
|
682
|
-
network,
|
|
683
|
-
vaultAddress,
|
|
684
|
-
subgraphURL,
|
|
685
|
-
dexHelper,
|
|
686
|
-
this.logger,
|
|
687
|
-
);
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
async setupEventPools(blockNumber: number) {
|
|
691
|
-
await this.eventPools.initialize(blockNumber);
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
async fetchEventDisabledPools() {
|
|
695
|
-
const cacheKey = 'eventDisabledPools';
|
|
696
|
-
const poolAddressListFromCache = await this.dexHelper.cache.get(
|
|
697
|
-
this.dexKey,
|
|
698
|
-
this.network,
|
|
699
|
-
cacheKey,
|
|
700
|
-
);
|
|
701
|
-
if (poolAddressListFromCache) {
|
|
702
|
-
this.eventDisabledPools = JSON.parse(poolAddressListFromCache);
|
|
703
|
-
return;
|
|
704
|
-
}
|
|
705
|
-
this.logger.info(
|
|
706
|
-
`Fetching ${this.dexKey}_${this.network} Weight Updates from subgraph`,
|
|
707
|
-
);
|
|
708
|
-
const timeNow = Math.floor(Date.now() / 1000);
|
|
709
|
-
const variables = {
|
|
710
|
-
count: MAX_POOL_CNT,
|
|
711
|
-
timestampPast: timeNow - POOL_EVENT_REENABLE_DELAY,
|
|
712
|
-
timestampFuture: timeNow + POOL_EVENT_DISABLED_TTL,
|
|
713
|
-
};
|
|
714
|
-
const { data } = await this.dexHelper.httpRequest.querySubgraph(
|
|
715
|
-
this.subgraphURL,
|
|
716
|
-
{ query: fetchWeightUpdating, variables },
|
|
717
|
-
{ timeout: SUBGRAPH_TIMEOUT },
|
|
718
|
-
);
|
|
719
|
-
|
|
720
|
-
if (!(data && data.gradualWeightUpdates)) {
|
|
721
|
-
throw new Error(
|
|
722
|
-
`${this.dexKey}_${this.network} failed to fetch weight updates from subgraph`,
|
|
723
|
-
);
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
this.eventDisabledPools = _.uniq(
|
|
727
|
-
data.gradualWeightUpdates.map(
|
|
728
|
-
(wu: { poolId: { address: Address } }) => wu.poolId.address,
|
|
729
|
-
),
|
|
730
|
-
);
|
|
731
|
-
const poolAddressList = JSON.stringify(this.eventDisabledPools);
|
|
732
|
-
this.logger.info(
|
|
733
|
-
`Pools blocked from event based on ${this.dexKey}_${this.network}: ${poolAddressList}`,
|
|
734
|
-
);
|
|
735
|
-
this.dexHelper.cache.setex(
|
|
736
|
-
this.dexKey,
|
|
737
|
-
this.network,
|
|
738
|
-
cacheKey,
|
|
739
|
-
POOL_EVENT_DISABLED_TTL,
|
|
740
|
-
poolAddressList,
|
|
741
|
-
);
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
async initializePricing(blockNumber: number) {
|
|
745
|
-
if (!this.eventDisabledPoolsTimer) {
|
|
746
|
-
await this.fetchEventDisabledPools();
|
|
747
|
-
this.eventDisabledPoolsTimer = setInterval(async () => {
|
|
748
|
-
try {
|
|
749
|
-
await this.fetchEventDisabledPools();
|
|
750
|
-
} catch (e) {
|
|
751
|
-
this.logger.error(
|
|
752
|
-
`${this.dexKey}: Failed to update event disabled pools:`,
|
|
753
|
-
e,
|
|
754
|
-
);
|
|
755
|
-
}
|
|
756
|
-
}, POOL_EVENT_DISABLED_TTL * 1000);
|
|
757
|
-
}
|
|
758
|
-
await this.setupEventPools(blockNumber);
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
releaseResources(): void {
|
|
762
|
-
if (this.eventDisabledPoolsTimer) {
|
|
763
|
-
clearInterval(this.eventDisabledPoolsTimer);
|
|
764
|
-
this.eventDisabledPoolsTimer = undefined;
|
|
765
|
-
this.logger.info(
|
|
766
|
-
`${this.dexKey}: cleared eventDisabledPoolsTimer before shutting down`,
|
|
767
|
-
);
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
getPoolsWithTokenPair(from: Token, to: Token): SubgraphPoolBase[] {
|
|
772
|
-
const pools = this.eventPools.allPools.filter(p => {
|
|
773
|
-
const fromMain = p.mainTokens.find(
|
|
774
|
-
token => token.address.toLowerCase() === from.address.toLowerCase(),
|
|
775
|
-
);
|
|
776
|
-
const toMain = p.mainTokens.find(
|
|
777
|
-
token => token.address.toLowerCase() === to.address.toLowerCase(),
|
|
778
|
-
);
|
|
779
|
-
|
|
780
|
-
return (
|
|
781
|
-
fromMain &&
|
|
782
|
-
toMain &&
|
|
783
|
-
// filter instances similar to the following:
|
|
784
|
-
// USDC -> DAI in a pool where bbaUSD is nested (ie: MAI / bbaUSD)
|
|
785
|
-
!(fromMain.isDeeplyNested && toMain.isDeeplyNested)
|
|
786
|
-
);
|
|
787
|
-
});
|
|
788
|
-
|
|
789
|
-
return pools.slice(0, 10);
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
getAdapters(side: SwapSide): { name: string; index: number }[] | null {
|
|
793
|
-
return this.adapters?.[side] ? this.adapters[side] : null;
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
async getPoolIdentifiers(
|
|
797
|
-
from: Token,
|
|
798
|
-
to: Token,
|
|
799
|
-
side: SwapSide,
|
|
800
|
-
blockNumber: number,
|
|
801
|
-
): Promise<string[]> {
|
|
802
|
-
const _from = this.dexHelper.config.wrapETH(from);
|
|
803
|
-
const _to = this.dexHelper.config.wrapETH(to);
|
|
804
|
-
|
|
805
|
-
const pools = this.getPoolsWithTokenPair(_from, _to);
|
|
806
|
-
|
|
807
|
-
return pools.map(
|
|
808
|
-
({ address }) => `${this.dexKey}_${address.toLowerCase()}`,
|
|
809
|
-
);
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
/**
|
|
813
|
-
* Returns cached poolState if blockNumber matches cached value. Resets if not.
|
|
814
|
-
*/
|
|
815
|
-
private getNonEventPoolStateCache(blockNumber: number): PoolStateMap {
|
|
816
|
-
if (this.nonEventPoolStateCache.blockNumber !== blockNumber)
|
|
817
|
-
this.nonEventPoolStateCache.poolState = {};
|
|
818
|
-
return this.nonEventPoolStateCache.poolState;
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
/**
|
|
822
|
-
* Update poolState cache.
|
|
823
|
-
* If same blockNumber as current cache then update with new pool state.
|
|
824
|
-
* If different blockNumber overwrite cache with latest.
|
|
825
|
-
*/
|
|
826
|
-
private updateNonEventPoolStateCache(
|
|
827
|
-
poolState: PoolStateMap,
|
|
828
|
-
blockNumber: number,
|
|
829
|
-
): PoolStateMap {
|
|
830
|
-
if (this.nonEventPoolStateCache.blockNumber !== blockNumber) {
|
|
831
|
-
this.nonEventPoolStateCache.blockNumber = blockNumber;
|
|
832
|
-
this.nonEventPoolStateCache.poolState = poolState;
|
|
833
|
-
} else
|
|
834
|
-
this.nonEventPoolStateCache.poolState = {
|
|
835
|
-
...this.nonEventPoolStateCache.poolState,
|
|
836
|
-
...poolState,
|
|
837
|
-
};
|
|
838
|
-
return this.nonEventPoolStateCache.poolState;
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
async getPricesVolume(
|
|
842
|
-
from: Token,
|
|
843
|
-
to: Token,
|
|
844
|
-
amounts: bigint[],
|
|
845
|
-
side: SwapSide,
|
|
846
|
-
blockNumber: number,
|
|
847
|
-
limitPools?: string[],
|
|
848
|
-
): Promise<null | ExchangePrices<BalancerV2Data>> {
|
|
849
|
-
try {
|
|
850
|
-
const _from = this.dexHelper.config.wrapETH(from);
|
|
851
|
-
const _to = this.dexHelper.config.wrapETH(to);
|
|
852
|
-
|
|
853
|
-
if (_from.address === _to.address) {
|
|
854
|
-
return null;
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
const allPools = this.getPoolsWithTokenPair(_from, _to);
|
|
858
|
-
|
|
859
|
-
const allowedPools = limitPools
|
|
860
|
-
? allPools.filter(({ address }) =>
|
|
861
|
-
limitPools.includes(`${this.dexKey}_${address.toLowerCase()}`),
|
|
862
|
-
)
|
|
863
|
-
: allPools;
|
|
864
|
-
|
|
865
|
-
if (!allowedPools.length) return null;
|
|
866
|
-
|
|
867
|
-
const eventPoolStatesRO = await this.eventPools.getState(blockNumber);
|
|
868
|
-
if (!eventPoolStatesRO) {
|
|
869
|
-
this.logger.error(`getState returned null`);
|
|
870
|
-
}
|
|
871
|
-
const eventPoolStates = { ...(eventPoolStatesRO || {}) };
|
|
872
|
-
|
|
873
|
-
for (const addr of this.eventDisabledPools) delete eventPoolStates[addr];
|
|
874
|
-
|
|
875
|
-
// Fetch previously cached non-event pool states
|
|
876
|
-
let nonEventPoolStates = this.getNonEventPoolStateCache(blockNumber);
|
|
877
|
-
|
|
878
|
-
//get all pools that would be used in the paths, nested pools included
|
|
879
|
-
const poolsFlattened = getAllPoolsUsedInPaths(
|
|
880
|
-
_from.address,
|
|
881
|
-
_to.address,
|
|
882
|
-
allowedPools,
|
|
883
|
-
this.poolAddressMap,
|
|
884
|
-
side,
|
|
885
|
-
);
|
|
886
|
-
|
|
887
|
-
// Missing pools are pools that don't already exist in event or non-event
|
|
888
|
-
const missingPools = poolsFlattened.filter(
|
|
889
|
-
pool =>
|
|
890
|
-
!(
|
|
891
|
-
pool.address.toLowerCase() in eventPoolStates ||
|
|
892
|
-
pool.address.toLowerCase() in nonEventPoolStates
|
|
893
|
-
),
|
|
894
|
-
);
|
|
895
|
-
|
|
896
|
-
// Retrieve onchain state for any missing pools
|
|
897
|
-
if (missingPools.length > 0) {
|
|
898
|
-
const missingPoolsStateMap = await this.eventPools.getOnChainState(
|
|
899
|
-
missingPools,
|
|
900
|
-
blockNumber,
|
|
901
|
-
);
|
|
902
|
-
// Update non-event pool state cache with newly retrieved data so it can be reused in future
|
|
903
|
-
nonEventPoolStates = this.updateNonEventPoolStateCache(
|
|
904
|
-
missingPoolsStateMap,
|
|
905
|
-
blockNumber,
|
|
906
|
-
);
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
const poolPrices = allowedPools
|
|
910
|
-
.map((pool: SubgraphPoolBase) => {
|
|
911
|
-
try {
|
|
912
|
-
const poolAddress = pool.address.toLowerCase();
|
|
913
|
-
|
|
914
|
-
const path = poolGetPathForTokenInOut(
|
|
915
|
-
_from.address,
|
|
916
|
-
_to.address,
|
|
917
|
-
pool,
|
|
918
|
-
this.poolAddressMap,
|
|
919
|
-
side,
|
|
920
|
-
);
|
|
921
|
-
|
|
922
|
-
let pathAmounts = amounts;
|
|
923
|
-
let resOut: { unit: bigint; prices: bigint[] } | null = null;
|
|
924
|
-
|
|
925
|
-
for (let i = 0; i < path.length; i++) {
|
|
926
|
-
const poolAddress = path[i].pool.address.toLowerCase();
|
|
927
|
-
const poolState = (eventPoolStates[poolAddress] ||
|
|
928
|
-
nonEventPoolStates[poolAddress]) as PoolState | undefined;
|
|
929
|
-
if (!poolState) {
|
|
930
|
-
this.logger.error(
|
|
931
|
-
`Unable to find the poolState ${poolAddress}`,
|
|
932
|
-
);
|
|
933
|
-
return null;
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
const unitVolume = getBigIntPow(
|
|
937
|
-
(side === SwapSide.SELL ? path[i].tokenIn : path[i].tokenOut)
|
|
938
|
-
.decimals,
|
|
939
|
-
);
|
|
940
|
-
|
|
941
|
-
const res = this.eventPools.getPricesPool(
|
|
942
|
-
path[i].tokenIn,
|
|
943
|
-
path[i].tokenOut,
|
|
944
|
-
path[i].pool,
|
|
945
|
-
poolState,
|
|
946
|
-
pathAmounts,
|
|
947
|
-
unitVolume,
|
|
948
|
-
side,
|
|
949
|
-
);
|
|
950
|
-
|
|
951
|
-
if (!res) {
|
|
952
|
-
return null;
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
pathAmounts = res.prices;
|
|
956
|
-
|
|
957
|
-
if (i === path.length - 1) {
|
|
958
|
-
resOut = res;
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
if (!resOut) {
|
|
963
|
-
return null;
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
return {
|
|
967
|
-
unit: resOut.unit,
|
|
968
|
-
prices: resOut.prices,
|
|
969
|
-
data: {
|
|
970
|
-
poolId: pool.id,
|
|
971
|
-
},
|
|
972
|
-
poolAddresses: [poolAddress],
|
|
973
|
-
exchange: this.dexKey,
|
|
974
|
-
gasCost:
|
|
975
|
-
STABLE_GAS_COST + VARIABLE_GAS_COST_PER_CYCLE * path.length,
|
|
976
|
-
poolIdentifier: `${this.dexKey}_${poolAddress}`,
|
|
977
|
-
};
|
|
978
|
-
|
|
979
|
-
// TODO: re-check what should be the current block time stamp
|
|
980
|
-
} catch (e) {
|
|
981
|
-
this.logger.warn(
|
|
982
|
-
`Error_getPrices ${from.symbol || from.address}, ${
|
|
983
|
-
to.symbol || to.address
|
|
984
|
-
}, ${side}, ${pool.address}:`,
|
|
985
|
-
e,
|
|
986
|
-
);
|
|
987
|
-
|
|
988
|
-
return;
|
|
989
|
-
}
|
|
990
|
-
})
|
|
991
|
-
.filter(p => !!p);
|
|
992
|
-
return poolPrices as ExchangePrices<BalancerV2Data>;
|
|
993
|
-
} catch (e) {
|
|
994
|
-
this.logger.error(
|
|
995
|
-
`Error_getPrices ${from.symbol || from.address}, ${
|
|
996
|
-
to.symbol || to.address
|
|
997
|
-
}, ${side}:`,
|
|
998
|
-
e,
|
|
999
|
-
);
|
|
1000
|
-
return null;
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
1005
|
-
getCalldataGasCost(
|
|
1006
|
-
poolPrices: PoolPrices<BalancerV2Data>,
|
|
1007
|
-
): number | number[] {
|
|
1008
|
-
return (
|
|
1009
|
-
CALLDATA_GAS_COST.DEX_OVERHEAD +
|
|
1010
|
-
CALLDATA_GAS_COST.LENGTH_LARGE +
|
|
1011
|
-
// ParentStruct header
|
|
1012
|
-
CALLDATA_GAS_COST.OFFSET_SMALL +
|
|
1013
|
-
// ParentStruct -> swaps[] header
|
|
1014
|
-
CALLDATA_GAS_COST.OFFSET_LARGE +
|
|
1015
|
-
// ParentStruct -> assets[] header
|
|
1016
|
-
CALLDATA_GAS_COST.OFFSET_LARGE +
|
|
1017
|
-
// ParentStruct -> funds
|
|
1018
|
-
CALLDATA_GAS_COST.ADDRESS +
|
|
1019
|
-
CALLDATA_GAS_COST.BOOL +
|
|
1020
|
-
CALLDATA_GAS_COST.ADDRESS +
|
|
1021
|
-
CALLDATA_GAS_COST.BOOL +
|
|
1022
|
-
// ParentStruct -> limits[] header
|
|
1023
|
-
CALLDATA_GAS_COST.OFFSET_LARGE +
|
|
1024
|
-
// ParentStruct -> deadline
|
|
1025
|
-
CALLDATA_GAS_COST.TIMESTAMP +
|
|
1026
|
-
// ParentStruct -> swaps[]
|
|
1027
|
-
CALLDATA_GAS_COST.LENGTH_SMALL +
|
|
1028
|
-
// ParentStruct -> swaps[0] header
|
|
1029
|
-
CALLDATA_GAS_COST.OFFSET_SMALL +
|
|
1030
|
-
// ParentStruct -> swaps[0] -> poolId
|
|
1031
|
-
CALLDATA_GAS_COST.FULL_WORD +
|
|
1032
|
-
// ParentStruct -> swaps[0] -> assetInIndex
|
|
1033
|
-
CALLDATA_GAS_COST.INDEX +
|
|
1034
|
-
// ParentStruct -> swaps[0] -> assetOutIndex
|
|
1035
|
-
CALLDATA_GAS_COST.INDEX +
|
|
1036
|
-
// ParentStruct -> swaps[0] -> amount
|
|
1037
|
-
CALLDATA_GAS_COST.AMOUNT +
|
|
1038
|
-
// ParentStruct -> swaps[0] -> userData header
|
|
1039
|
-
CALLDATA_GAS_COST.OFFSET_SMALL +
|
|
1040
|
-
// ParentStruct -> swaps[0] -> userData
|
|
1041
|
-
CALLDATA_GAS_COST.ZERO +
|
|
1042
|
-
// ParentStruct -> assets[]
|
|
1043
|
-
CALLDATA_GAS_COST.LENGTH_SMALL +
|
|
1044
|
-
// ParentStruct -> assets[0:2]
|
|
1045
|
-
CALLDATA_GAS_COST.ADDRESS * 2 +
|
|
1046
|
-
// ParentStruct -> limits[]
|
|
1047
|
-
CALLDATA_GAS_COST.LENGTH_SMALL +
|
|
1048
|
-
// ParentStruct -> limits[0:2]
|
|
1049
|
-
CALLDATA_GAS_COST.FULL_WORD * 2
|
|
1050
|
-
);
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
getAdapterParam(
|
|
1054
|
-
srcToken: string,
|
|
1055
|
-
destToken: string,
|
|
1056
|
-
srcAmount: string,
|
|
1057
|
-
destAmount: string,
|
|
1058
|
-
data: OptimizedBalancerV2Data,
|
|
1059
|
-
side: SwapSide,
|
|
1060
|
-
): AdapterExchangeParam {
|
|
1061
|
-
const params = this.getBalancerV2BatchSwapParam(
|
|
1062
|
-
srcToken,
|
|
1063
|
-
destToken,
|
|
1064
|
-
data,
|
|
1065
|
-
side,
|
|
1066
|
-
this.dexHelper.config.data.augustusAddress!,
|
|
1067
|
-
this.dexHelper.config.data.augustusAddress!,
|
|
1068
|
-
);
|
|
1069
|
-
|
|
1070
|
-
const payload = this.abiCoder.encodeParameter(
|
|
1071
|
-
{
|
|
1072
|
-
ParentStruct: {
|
|
1073
|
-
'swaps[]': {
|
|
1074
|
-
poolId: 'bytes32',
|
|
1075
|
-
assetInIndex: 'uint256',
|
|
1076
|
-
assetOutIndex: 'uint256',
|
|
1077
|
-
amount: 'uint256',
|
|
1078
|
-
userData: 'bytes',
|
|
1079
|
-
},
|
|
1080
|
-
assets: 'address[]',
|
|
1081
|
-
funds: {
|
|
1082
|
-
sender: 'address',
|
|
1083
|
-
fromInternalBalance: 'bool',
|
|
1084
|
-
recipient: 'address',
|
|
1085
|
-
toInternalBalance: 'bool',
|
|
1086
|
-
},
|
|
1087
|
-
limits: 'int256[]',
|
|
1088
|
-
deadline: 'uint256',
|
|
1089
|
-
},
|
|
1090
|
-
},
|
|
1091
|
-
{
|
|
1092
|
-
swaps: params[1],
|
|
1093
|
-
assets: params[2],
|
|
1094
|
-
funds: params[3],
|
|
1095
|
-
limits: params[4],
|
|
1096
|
-
deadline: params[5],
|
|
1097
|
-
},
|
|
1098
|
-
);
|
|
1099
|
-
|
|
1100
|
-
return {
|
|
1101
|
-
targetExchange: this.vaultAddress,
|
|
1102
|
-
payload,
|
|
1103
|
-
networkFee: '0',
|
|
1104
|
-
};
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
public getBalancerV2SwapParam(
|
|
1108
|
-
srcToken: string,
|
|
1109
|
-
destToken: string,
|
|
1110
|
-
data: OptimizedBalancerV2Data,
|
|
1111
|
-
side: SwapSide,
|
|
1112
|
-
recipient: string,
|
|
1113
|
-
sender: string,
|
|
1114
|
-
): BalancerV2SwapParam {
|
|
1115
|
-
assert(data.swaps.length === 1, 'should have exactly one pool');
|
|
1116
|
-
|
|
1117
|
-
const singleSwap: BalancerV2SingleSwap = {
|
|
1118
|
-
poolId: data.swaps[0].poolId,
|
|
1119
|
-
kind:
|
|
1120
|
-
side === SwapSide.SELL ? SwapTypes.SwapExactIn : SwapTypes.SwapExactOut,
|
|
1121
|
-
assetIn:
|
|
1122
|
-
srcToken.toLowerCase() === ETHER_ADDRESS ? NULL_ADDRESS : srcToken,
|
|
1123
|
-
assetOut:
|
|
1124
|
-
destToken.toLowerCase() === ETHER_ADDRESS ? NULL_ADDRESS : destToken,
|
|
1125
|
-
amount: data.swaps[0].amount,
|
|
1126
|
-
userData: '0x',
|
|
1127
|
-
};
|
|
1128
|
-
|
|
1129
|
-
const funds = {
|
|
1130
|
-
sender,
|
|
1131
|
-
recipient,
|
|
1132
|
-
fromInternalBalance: false,
|
|
1133
|
-
toInternalBalance: false,
|
|
1134
|
-
};
|
|
1135
|
-
|
|
1136
|
-
const params: BalancerV2SwapParam = [
|
|
1137
|
-
singleSwap,
|
|
1138
|
-
funds,
|
|
1139
|
-
side === SwapSide.SELL ? '1' : MAX_INT,
|
|
1140
|
-
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
1141
|
-
];
|
|
1142
|
-
|
|
1143
|
-
return params;
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
|
-
/*
|
|
1147
|
-
Algorithm to determine balancer (sender, recipient) params:
|
|
1148
|
-
|
|
1149
|
-
if version = 5
|
|
1150
|
-
sender = recipient = augustusV5
|
|
1151
|
-
else (so V6)
|
|
1152
|
-
if direct swap
|
|
1153
|
-
sender = recipient = augustusV6
|
|
1154
|
-
else (so generic swaps)
|
|
1155
|
-
if sell
|
|
1156
|
-
if swap.destToken = priceRoute.destToken <> ETH (need withdraw for eth currently, need fix in future)
|
|
1157
|
-
sender = executor and recipient = augustusV6 (skip 1 extra transfer)
|
|
1158
|
-
else
|
|
1159
|
-
sender = recipient = executor
|
|
1160
|
-
# note: we pass sender=null then the address of the executor is inferred contract side
|
|
1161
|
-
else (so buy)
|
|
1162
|
-
sender = recipient = executor
|
|
1163
|
-
*/
|
|
1164
|
-
public getBalancerV2BatchSwapParam(
|
|
1165
|
-
srcToken: string,
|
|
1166
|
-
destToken: string,
|
|
1167
|
-
data: OptimizedBalancerV2Data,
|
|
1168
|
-
side: SwapSide,
|
|
1169
|
-
recipient: string,
|
|
1170
|
-
sender: string,
|
|
1171
|
-
shouldWalkAssetsBackward?: boolean, // should do for all buy but prefer keep it under control
|
|
1172
|
-
): BalancerV2BatchSwapParam {
|
|
1173
|
-
let swapOffset = 0;
|
|
1174
|
-
let swaps: BalancerSwap[] = [];
|
|
1175
|
-
let assets: string[] = [];
|
|
1176
|
-
let limits: string[] = [];
|
|
1177
|
-
|
|
1178
|
-
for (const swapData of data.swaps) {
|
|
1179
|
-
const pool = this.poolIdMap[swapData.poolId];
|
|
1180
|
-
const hasEth = [srcToken.toLowerCase(), destToken.toLowerCase()].includes(
|
|
1181
|
-
ETHER_ADDRESS.toLowerCase(),
|
|
1182
|
-
);
|
|
1183
|
-
const _srcToken = this.dexHelper.config.wrapETH({
|
|
1184
|
-
address: srcToken,
|
|
1185
|
-
decimals: 18,
|
|
1186
|
-
}).address;
|
|
1187
|
-
const _destToken = this.dexHelper.config.wrapETH({
|
|
1188
|
-
address: destToken,
|
|
1189
|
-
decimals: 18,
|
|
1190
|
-
}).address;
|
|
1191
|
-
|
|
1192
|
-
let path = poolGetPathForTokenInOut(
|
|
1193
|
-
_srcToken,
|
|
1194
|
-
_destToken,
|
|
1195
|
-
pool,
|
|
1196
|
-
this.poolAddressMap,
|
|
1197
|
-
side,
|
|
1198
|
-
);
|
|
1199
|
-
|
|
1200
|
-
if (side === SwapSide.BUY) {
|
|
1201
|
-
path = path.reverse();
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
const _swaps = path.map((hop, index) => {
|
|
1205
|
-
const assetInIndex = shouldWalkAssetsBackward
|
|
1206
|
-
? swapOffset + path.length - index
|
|
1207
|
-
: swapOffset + index;
|
|
1208
|
-
|
|
1209
|
-
const assetOutIndex = shouldWalkAssetsBackward
|
|
1210
|
-
? swapOffset + path.length - index - 1
|
|
1211
|
-
: swapOffset + index + 1;
|
|
1212
|
-
|
|
1213
|
-
const amount =
|
|
1214
|
-
(side === SwapSide.SELL && index === 0) ||
|
|
1215
|
-
(side === SwapSide.BUY && index === path.length - 1)
|
|
1216
|
-
? swapData.amount
|
|
1217
|
-
: '0';
|
|
1218
|
-
|
|
1219
|
-
if (assetInIndex < 0 || assetOutIndex < 0) {
|
|
1220
|
-
const error = new Error(`Invalid indices in balancer`);
|
|
1221
|
-
this.logger.error(error.message, error);
|
|
1222
|
-
throw error;
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
return {
|
|
1226
|
-
poolId: hop.pool.id,
|
|
1227
|
-
assetInIndex,
|
|
1228
|
-
assetOutIndex,
|
|
1229
|
-
amount,
|
|
1230
|
-
userData: '0x',
|
|
1231
|
-
};
|
|
1232
|
-
});
|
|
1233
|
-
|
|
1234
|
-
swapOffset += path.length + 1;
|
|
1235
|
-
|
|
1236
|
-
// BalancerV2 Uses Address(0) as ETH
|
|
1237
|
-
const _assets = [_srcToken, ...path.map(hop => hop.tokenOut.address)].map(
|
|
1238
|
-
t => (hasEth && this.dexHelper.config.isWETH(t) ? NULL_ADDRESS : t),
|
|
1239
|
-
);
|
|
1240
|
-
|
|
1241
|
-
const _limits = _assets.map(_ => MAX_INT);
|
|
1242
|
-
|
|
1243
|
-
swaps = swaps.concat(_swaps);
|
|
1244
|
-
assets = assets.concat(_assets);
|
|
1245
|
-
limits = limits.concat(_limits);
|
|
1246
|
-
}
|
|
1247
|
-
|
|
1248
|
-
const funds = {
|
|
1249
|
-
sender,
|
|
1250
|
-
recipient,
|
|
1251
|
-
fromInternalBalance: false,
|
|
1252
|
-
toInternalBalance: false,
|
|
1253
|
-
};
|
|
1254
|
-
|
|
1255
|
-
const params: BalancerV2BatchSwapParam = [
|
|
1256
|
-
side === SwapSide.SELL ? SwapTypes.SwapExactIn : SwapTypes.SwapExactOut,
|
|
1257
|
-
side === SwapSide.SELL ? swaps : swaps.reverse(),
|
|
1258
|
-
shouldWalkAssetsBackward ? assets.reverse() : assets,
|
|
1259
|
-
funds,
|
|
1260
|
-
limits,
|
|
1261
|
-
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
1262
|
-
];
|
|
1263
|
-
|
|
1264
|
-
return params;
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
static getDirectFunctionName(): string[] {
|
|
1268
|
-
return [DirectMethods.directSell, DirectMethods.directBuy];
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
getTokenFromAddress(address: Address): Token {
|
|
1272
|
-
// In this Dex decimals are not used
|
|
1273
|
-
return { address, decimals: 0 };
|
|
1274
|
-
}
|
|
1275
|
-
|
|
1276
|
-
async preProcessTransaction(
|
|
1277
|
-
optimalSwapExchange: OptimalSwapExchange<OptimizedBalancerV2Data>,
|
|
1278
|
-
srcToken: Token,
|
|
1279
|
-
_0: Token,
|
|
1280
|
-
_1: SwapSide,
|
|
1281
|
-
options: PreprocessTransactionOptions,
|
|
1282
|
-
): Promise<[OptimalSwapExchange<OptimizedBalancerV2Data>, ExchangeTxInfo]> {
|
|
1283
|
-
if (!options.isDirectMethod) {
|
|
1284
|
-
return [
|
|
1285
|
-
optimalSwapExchange,
|
|
1286
|
-
{
|
|
1287
|
-
deadline: BigInt(getLocalDeadlineAsFriendlyPlaceholder()),
|
|
1288
|
-
},
|
|
1289
|
-
];
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
assert(
|
|
1293
|
-
optimalSwapExchange.data !== undefined,
|
|
1294
|
-
`preProcessTransaction: data field is missing`,
|
|
1295
|
-
);
|
|
1296
|
-
|
|
1297
|
-
let isApproved: boolean | undefined;
|
|
1298
|
-
|
|
1299
|
-
try {
|
|
1300
|
-
isApproved = await this.dexHelper.augustusApprovals.hasApproval(
|
|
1301
|
-
options.executionContractAddress,
|
|
1302
|
-
this.dexHelper.config.wrapETH(srcToken).address,
|
|
1303
|
-
this.vaultAddress,
|
|
1304
|
-
);
|
|
1305
|
-
} catch (e) {
|
|
1306
|
-
this.logger.error(
|
|
1307
|
-
`preProcessTransaction failed to retrieve allowance info: `,
|
|
1308
|
-
e,
|
|
1309
|
-
);
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
return [
|
|
1313
|
-
{
|
|
1314
|
-
...optimalSwapExchange,
|
|
1315
|
-
data: {
|
|
1316
|
-
...optimalSwapExchange.data,
|
|
1317
|
-
isApproved,
|
|
1318
|
-
},
|
|
1319
|
-
},
|
|
1320
|
-
{
|
|
1321
|
-
deadline: BigInt(getLocalDeadlineAsFriendlyPlaceholder()),
|
|
1322
|
-
},
|
|
1323
|
-
];
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
|
-
getDirectParam(
|
|
1327
|
-
srcToken: Address,
|
|
1328
|
-
destToken: Address,
|
|
1329
|
-
srcAmount: NumberAsString,
|
|
1330
|
-
destAmount: NumberAsString,
|
|
1331
|
-
expectedAmount: NumberAsString,
|
|
1332
|
-
data: OptimizedBalancerV2Data,
|
|
1333
|
-
side: SwapSide,
|
|
1334
|
-
permit: string,
|
|
1335
|
-
uuid: string,
|
|
1336
|
-
feePercent: NumberAsString,
|
|
1337
|
-
deadline: NumberAsString,
|
|
1338
|
-
partner: string,
|
|
1339
|
-
beneficiary: string,
|
|
1340
|
-
contractMethod: string,
|
|
1341
|
-
): TxInfo<BalancerV2DirectParam> {
|
|
1342
|
-
if (
|
|
1343
|
-
contractMethod !== DirectMethods.directSell &&
|
|
1344
|
-
contractMethod !== DirectMethods.directBuy
|
|
1345
|
-
) {
|
|
1346
|
-
throw new Error(`Invalid contract method ${contractMethod}`);
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
|
-
let isApproved: boolean = !!data.isApproved;
|
|
1350
|
-
if (data.isApproved === undefined) {
|
|
1351
|
-
this.logger.warn(`isApproved is undefined, defaulting to false`);
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
|
-
const [, swaps, assets, funds, limits, _deadline] =
|
|
1355
|
-
this.getBalancerV2BatchSwapParam(
|
|
1356
|
-
srcToken,
|
|
1357
|
-
destToken,
|
|
1358
|
-
data,
|
|
1359
|
-
side,
|
|
1360
|
-
this.dexHelper.config.data.augustusAddress!,
|
|
1361
|
-
this.dexHelper.config.data.augustusAddress!,
|
|
1362
|
-
);
|
|
1363
|
-
|
|
1364
|
-
const swapParams: BalancerV2DirectParam = [
|
|
1365
|
-
swaps,
|
|
1366
|
-
assets,
|
|
1367
|
-
funds,
|
|
1368
|
-
limits,
|
|
1369
|
-
srcAmount,
|
|
1370
|
-
destAmount,
|
|
1371
|
-
expectedAmount,
|
|
1372
|
-
_deadline,
|
|
1373
|
-
feePercent,
|
|
1374
|
-
this.vaultAddress,
|
|
1375
|
-
partner,
|
|
1376
|
-
isApproved,
|
|
1377
|
-
beneficiary,
|
|
1378
|
-
permit,
|
|
1379
|
-
uuidToBytes16(uuid),
|
|
1380
|
-
];
|
|
1381
|
-
|
|
1382
|
-
const encoder = (...params: BalancerV2DirectParam) => {
|
|
1383
|
-
return this.directSwapIface.encodeFunctionData(
|
|
1384
|
-
side === SwapSide.SELL
|
|
1385
|
-
? DirectMethods.directSell
|
|
1386
|
-
: DirectMethods.directBuy,
|
|
1387
|
-
[params],
|
|
1388
|
-
);
|
|
1389
|
-
};
|
|
1390
|
-
|
|
1391
|
-
return {
|
|
1392
|
-
params: swapParams,
|
|
1393
|
-
encoder,
|
|
1394
|
-
networkFee: '0',
|
|
1395
|
-
};
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
getDirectParamV6(
|
|
1399
|
-
srcToken: Address,
|
|
1400
|
-
destToken: Address,
|
|
1401
|
-
fromAmount: NumberAsString,
|
|
1402
|
-
toAmount: NumberAsString,
|
|
1403
|
-
quotedAmount: NumberAsString,
|
|
1404
|
-
data: OptimizedBalancerV2Data,
|
|
1405
|
-
side: SwapSide,
|
|
1406
|
-
permit: string,
|
|
1407
|
-
uuid: string,
|
|
1408
|
-
partnerAndFee: string,
|
|
1409
|
-
beneficiary: string,
|
|
1410
|
-
blockNumber: number,
|
|
1411
|
-
contractMethod: string,
|
|
1412
|
-
) {
|
|
1413
|
-
if (!contractMethod) throw new Error(`contractMethod need to be passed`);
|
|
1414
|
-
|
|
1415
|
-
if (!BalancerV2.getDirectFunctionNameV6().includes(contractMethod!)) {
|
|
1416
|
-
throw new Error(`Invalid contract method ${contractMethod}`);
|
|
1417
|
-
}
|
|
1418
|
-
|
|
1419
|
-
const metadata = hexConcat([
|
|
1420
|
-
hexZeroPad(uuidToBytes16(uuid), 16),
|
|
1421
|
-
hexZeroPad(hexlify(blockNumber), 16),
|
|
1422
|
-
]);
|
|
1423
|
-
|
|
1424
|
-
const balancerBatchSwapParam = this.getBalancerV2BatchSwapParam(
|
|
1425
|
-
srcToken,
|
|
1426
|
-
destToken,
|
|
1427
|
-
data,
|
|
1428
|
-
side,
|
|
1429
|
-
this.dexHelper.config.data.augustusV6Address!,
|
|
1430
|
-
this.dexHelper.config.data.augustusV6Address!,
|
|
1431
|
-
side === SwapSide.BUY,
|
|
1432
|
-
);
|
|
1433
|
-
|
|
1434
|
-
// after getBalancerV2BatchSwapParam runs we may get more swaps so we can't decide on single vs batch before resolving it
|
|
1435
|
-
const [, swaps] = balancerBatchSwapParam;
|
|
1436
|
-
const isSingleSwap = swaps.length === 1;
|
|
1437
|
-
|
|
1438
|
-
const balancerParams = isSingleSwap
|
|
1439
|
-
? this.getBalancerV2SwapParam(
|
|
1440
|
-
srcToken,
|
|
1441
|
-
destToken,
|
|
1442
|
-
data,
|
|
1443
|
-
side,
|
|
1444
|
-
this.dexHelper.config.data.augustusV6Address!,
|
|
1445
|
-
this.dexHelper.config.data.augustusV6Address!,
|
|
1446
|
-
)
|
|
1447
|
-
: balancerBatchSwapParam;
|
|
1448
|
-
|
|
1449
|
-
const swapParams: BalancerV2DirectParamV6 = [
|
|
1450
|
-
fromAmount,
|
|
1451
|
-
toAmount,
|
|
1452
|
-
quotedAmount,
|
|
1453
|
-
metadata,
|
|
1454
|
-
this.encodeBeneficiaryAndApproveFlag(beneficiary, !data.isApproved),
|
|
1455
|
-
];
|
|
1456
|
-
|
|
1457
|
-
const encodeParams: BalancerV2DirectParamV6Swap = [
|
|
1458
|
-
swapParams,
|
|
1459
|
-
partnerAndFee,
|
|
1460
|
-
permit,
|
|
1461
|
-
balancerParams.length === 4 // TODO: upgrade ts to use isSingleSwap
|
|
1462
|
-
? this.encodeBalancerV2SwapParam(balancerParams)
|
|
1463
|
-
: this.encodeBalancerV2BatchSwapParam(balancerParams),
|
|
1464
|
-
];
|
|
1465
|
-
|
|
1466
|
-
const encoder = (...params: BalancerV2DirectParamV6Swap) => {
|
|
1467
|
-
return this.augustusV6Interface.encodeFunctionData(
|
|
1468
|
-
side === SwapSide.SELL
|
|
1469
|
-
? DirectMethodsV6.directSell
|
|
1470
|
-
: DirectMethodsV6.directBuy,
|
|
1471
|
-
[...params],
|
|
1472
|
-
);
|
|
1473
|
-
};
|
|
1474
|
-
|
|
1475
|
-
return {
|
|
1476
|
-
encoder,
|
|
1477
|
-
params: encodeParams,
|
|
1478
|
-
networkFee: '0',
|
|
1479
|
-
};
|
|
1480
|
-
}
|
|
1481
|
-
|
|
1482
|
-
private encodeBeneficiaryAndApproveFlag(
|
|
1483
|
-
beneficiary: Address,
|
|
1484
|
-
approveFlag: boolean,
|
|
1485
|
-
) {
|
|
1486
|
-
const addressBN = BigNumber.from(beneficiary);
|
|
1487
|
-
const flagBN = approveFlag ? BigNumber.from(1).shl(255) : BigNumber.from(0);
|
|
1488
|
-
|
|
1489
|
-
return addressBN.or(flagBN).toString();
|
|
1490
|
-
}
|
|
1491
|
-
|
|
1492
|
-
private encodeBalancerV2SwapParam(param: BalancerV2SwapParam): string {
|
|
1493
|
-
const [singleSwap, funds, limit, deadline] = param;
|
|
1494
|
-
|
|
1495
|
-
const encoded = this.balancerVaultInterface.encodeFunctionData('swap', [
|
|
1496
|
-
singleSwap,
|
|
1497
|
-
funds,
|
|
1498
|
-
limit,
|
|
1499
|
-
deadline,
|
|
1500
|
-
]);
|
|
1501
|
-
|
|
1502
|
-
return encoded;
|
|
1503
|
-
}
|
|
1504
|
-
|
|
1505
|
-
private encodeBalancerV2BatchSwapParam(
|
|
1506
|
-
param: BalancerV2BatchSwapParam,
|
|
1507
|
-
): string {
|
|
1508
|
-
const [kind, swaps, assets, funds, limits, deadline] = param;
|
|
1509
|
-
|
|
1510
|
-
const encoded = this.balancerVaultInterface.encodeFunctionData(
|
|
1511
|
-
'batchSwap',
|
|
1512
|
-
[kind, swaps, assets, funds, limits, deadline],
|
|
1513
|
-
);
|
|
1514
|
-
return encoded;
|
|
1515
|
-
}
|
|
1516
|
-
|
|
1517
|
-
static getDirectFunctionNameV6(): string[] {
|
|
1518
|
-
return [DirectMethodsV6.directSell, DirectMethodsV6.directBuy];
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1521
|
-
async getSimpleParam(
|
|
1522
|
-
srcToken: string,
|
|
1523
|
-
destToken: string,
|
|
1524
|
-
srcAmount: string,
|
|
1525
|
-
destAmount: string,
|
|
1526
|
-
data: OptimizedBalancerV2Data,
|
|
1527
|
-
side: SwapSide,
|
|
1528
|
-
): Promise<SimpleExchangeParam> {
|
|
1529
|
-
const params = this.getBalancerV2BatchSwapParam(
|
|
1530
|
-
srcToken,
|
|
1531
|
-
destToken,
|
|
1532
|
-
data,
|
|
1533
|
-
side,
|
|
1534
|
-
this.dexHelper.config.data.augustusAddress!,
|
|
1535
|
-
this.dexHelper.config.data.augustusAddress!,
|
|
1536
|
-
);
|
|
1537
|
-
|
|
1538
|
-
const swapData = this.eventPools.vaultInterface.encodeFunctionData(
|
|
1539
|
-
'batchSwap',
|
|
1540
|
-
params,
|
|
1541
|
-
);
|
|
1542
|
-
|
|
1543
|
-
return this.buildSimpleParamWithoutWETHConversion(
|
|
1544
|
-
srcToken,
|
|
1545
|
-
srcAmount,
|
|
1546
|
-
destToken,
|
|
1547
|
-
destAmount,
|
|
1548
|
-
swapData,
|
|
1549
|
-
this.vaultAddress,
|
|
1550
|
-
);
|
|
1551
|
-
}
|
|
1552
|
-
|
|
1553
|
-
getDexParam(
|
|
1554
|
-
srcToken: Address,
|
|
1555
|
-
destToken: Address,
|
|
1556
|
-
srcAmount: NumberAsString,
|
|
1557
|
-
destAmount: NumberAsString,
|
|
1558
|
-
recipient: Address,
|
|
1559
|
-
data: OptimizedBalancerV2Data,
|
|
1560
|
-
side: SwapSide,
|
|
1561
|
-
context: Context,
|
|
1562
|
-
executor: Address,
|
|
1563
|
-
): DexExchangeParam {
|
|
1564
|
-
const balancerBatchSwapParam = this.getBalancerV2BatchSwapParam(
|
|
1565
|
-
srcToken,
|
|
1566
|
-
destToken,
|
|
1567
|
-
data,
|
|
1568
|
-
side,
|
|
1569
|
-
recipient,
|
|
1570
|
-
side === SwapSide.SELL ? NULL_ADDRESS : executor,
|
|
1571
|
-
);
|
|
1572
|
-
|
|
1573
|
-
const [, swaps] = balancerBatchSwapParam;
|
|
1574
|
-
const isSingleSwap = swaps.length === 1;
|
|
1575
|
-
|
|
1576
|
-
if (isSingleSwap) {
|
|
1577
|
-
const balancerSwapParam = this.getBalancerV2SwapParam(
|
|
1578
|
-
srcToken,
|
|
1579
|
-
destToken,
|
|
1580
|
-
data,
|
|
1581
|
-
side,
|
|
1582
|
-
recipient,
|
|
1583
|
-
executor,
|
|
1584
|
-
);
|
|
1585
|
-
|
|
1586
|
-
const exchangeData = this.eventPools.vaultInterface.encodeFunctionData(
|
|
1587
|
-
'swap',
|
|
1588
|
-
balancerSwapParam,
|
|
1589
|
-
);
|
|
1590
|
-
|
|
1591
|
-
return {
|
|
1592
|
-
needWrapNative: this.needWrapNative,
|
|
1593
|
-
dexFuncHasRecipient: true,
|
|
1594
|
-
exchangeData,
|
|
1595
|
-
targetExchange: this.vaultAddress,
|
|
1596
|
-
returnAmountPos:
|
|
1597
|
-
side === SwapSide.SELL
|
|
1598
|
-
? extractReturnAmountPosition(
|
|
1599
|
-
this.balancerVaultInterface,
|
|
1600
|
-
'swap',
|
|
1601
|
-
'amountCalculated',
|
|
1602
|
-
)
|
|
1603
|
-
: undefined,
|
|
1604
|
-
};
|
|
1605
|
-
}
|
|
1606
|
-
|
|
1607
|
-
let exchangeData = this.eventPools.vaultInterface.encodeFunctionData(
|
|
1608
|
-
'batchSwap',
|
|
1609
|
-
balancerBatchSwapParam,
|
|
1610
|
-
);
|
|
1611
|
-
let specialDexFlag = SpecialDex.DEFAULT;
|
|
1612
|
-
|
|
1613
|
-
if (side === SwapSide.SELL) {
|
|
1614
|
-
const totalAmount = swaps.reduce<BigNumber>((acc, swap) => {
|
|
1615
|
-
return acc.add(swap.amount);
|
|
1616
|
-
}, BigNumber.from(0));
|
|
1617
|
-
|
|
1618
|
-
exchangeData = solidityPack(
|
|
1619
|
-
['bytes32', 'bytes'],
|
|
1620
|
-
[hexZeroPad(hexlify(totalAmount), 32), exchangeData],
|
|
1621
|
-
);
|
|
1622
|
-
specialDexFlag = SpecialDex.SWAP_ON_BALANCER_V2;
|
|
1623
|
-
}
|
|
1624
|
-
|
|
1625
|
-
return {
|
|
1626
|
-
needWrapNative: this.needWrapNative,
|
|
1627
|
-
dexFuncHasRecipient: true,
|
|
1628
|
-
exchangeData,
|
|
1629
|
-
specialDexFlag,
|
|
1630
|
-
targetExchange: this.vaultAddress,
|
|
1631
|
-
returnAmountPos: undefined,
|
|
1632
|
-
};
|
|
1633
|
-
}
|
|
1634
|
-
|
|
1635
|
-
async updatePoolState(): Promise<void> {
|
|
1636
|
-
this.eventPools.allPools = await this.eventPools.fetchAllSubgraphPools();
|
|
1637
|
-
}
|
|
1638
|
-
|
|
1639
|
-
async getTopPoolsForToken(
|
|
1640
|
-
tokenAddress: Address,
|
|
1641
|
-
count: number,
|
|
1642
|
-
): Promise<PoolLiquidity[]> {
|
|
1643
|
-
const poolsWithToken = this.eventPools.allPools.filter(pool =>
|
|
1644
|
-
pool.mainTokens.some(mainToken =>
|
|
1645
|
-
isSameAddress(mainToken.address, tokenAddress),
|
|
1646
|
-
),
|
|
1647
|
-
);
|
|
1648
|
-
|
|
1649
|
-
const variables = {
|
|
1650
|
-
poolIds: poolsWithToken.map(pool => pool.id),
|
|
1651
|
-
count,
|
|
1652
|
-
};
|
|
1653
|
-
|
|
1654
|
-
const query = `query ($poolIds: [String!]!, $count: Int) {
|
|
1655
|
-
pools (first: $count, orderBy: totalLiquidity, orderDirection: desc,
|
|
1656
|
-
where: {
|
|
1657
|
-
and: [
|
|
1658
|
-
{
|
|
1659
|
-
or: [
|
|
1660
|
-
{ isInRecoveryMode: false }
|
|
1661
|
-
{ isInRecoveryMode: null }
|
|
1662
|
-
]
|
|
1663
|
-
},
|
|
1664
|
-
{
|
|
1665
|
-
id_in: $poolIds,
|
|
1666
|
-
swapEnabled: true,
|
|
1667
|
-
totalLiquidity_gt: ${MIN_USD_LIQUIDITY_TO_FETCH.toString()}
|
|
1668
|
-
}
|
|
1669
|
-
]
|
|
1670
|
-
}) {
|
|
1671
|
-
address
|
|
1672
|
-
totalLiquidity
|
|
1673
|
-
tokens {
|
|
1674
|
-
address
|
|
1675
|
-
decimals
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
}`;
|
|
1679
|
-
const { data } = await this.dexHelper.httpRequest.querySubgraph<{
|
|
1680
|
-
data: {
|
|
1681
|
-
pools: {
|
|
1682
|
-
address: string;
|
|
1683
|
-
totalLiquidity: string;
|
|
1684
|
-
tokens: { address: string; decimals: number }[];
|
|
1685
|
-
}[];
|
|
1686
|
-
};
|
|
1687
|
-
}>(
|
|
1688
|
-
this.subgraphURL,
|
|
1689
|
-
{
|
|
1690
|
-
query,
|
|
1691
|
-
variables,
|
|
1692
|
-
},
|
|
1693
|
-
{ timeout: SUBGRAPH_TIMEOUT },
|
|
1694
|
-
);
|
|
1695
|
-
|
|
1696
|
-
if (!(data && data.pools))
|
|
1697
|
-
throw new Error(
|
|
1698
|
-
`Error_${this.dexKey}_Subgraph: couldn't fetch the pools from the subgraph`,
|
|
1699
|
-
);
|
|
1700
|
-
|
|
1701
|
-
return _.map(data.pools, pool => {
|
|
1702
|
-
const subgraphPool = poolsWithToken.find(poolWithToken =>
|
|
1703
|
-
isSameAddress(poolWithToken.address, pool.address),
|
|
1704
|
-
)!;
|
|
1705
|
-
|
|
1706
|
-
return {
|
|
1707
|
-
exchange: this.dexKey,
|
|
1708
|
-
address: pool.address.toLowerCase(),
|
|
1709
|
-
connectorTokens: subgraphPool.mainTokens.filter(
|
|
1710
|
-
token => !isSameAddress(tokenAddress, token.address),
|
|
1711
|
-
),
|
|
1712
|
-
liquidityUSD: parseFloat(pool.totalLiquidity),
|
|
1713
|
-
};
|
|
1714
|
-
});
|
|
1715
|
-
}
|
|
1716
|
-
|
|
1717
|
-
private get poolAddressMap(): SubgraphPoolAddressDictionary {
|
|
1718
|
-
return keyBy(this.eventPools.allPools, 'address');
|
|
1719
|
-
}
|
|
1720
|
-
|
|
1721
|
-
private get poolIdMap(): { [poolId: string]: SubgraphPoolBase } {
|
|
1722
|
-
return keyBy(this.eventPools.allPools, 'id');
|
|
1723
|
-
}
|
|
1724
|
-
}
|