@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,1169 +0,0 @@
|
|
|
1
|
-
import { BytesLike } from 'ethers/lib/utils';
|
|
2
|
-
import { Interface } from '@ethersproject/abi';
|
|
3
|
-
import {
|
|
4
|
-
Token,
|
|
5
|
-
Address,
|
|
6
|
-
ExchangePrices,
|
|
7
|
-
PoolPrices,
|
|
8
|
-
AdapterExchangeParam,
|
|
9
|
-
PoolLiquidity,
|
|
10
|
-
DexExchangeParam,
|
|
11
|
-
Logger,
|
|
12
|
-
} from '../../types';
|
|
13
|
-
import { SwapSide, Network } from '../../constants';
|
|
14
|
-
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
15
|
-
import { Context, IDex } from '../../dex/idex';
|
|
16
|
-
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
17
|
-
import {
|
|
18
|
-
CollateralReserves,
|
|
19
|
-
DebtReserves,
|
|
20
|
-
FluidDexData,
|
|
21
|
-
FluidDexPool,
|
|
22
|
-
Pool,
|
|
23
|
-
DexLimits,
|
|
24
|
-
TokenLimit,
|
|
25
|
-
} from './types';
|
|
26
|
-
import { SimpleExchange } from '../simple-exchange';
|
|
27
|
-
import FluidDexPoolABI from '../../abi/fluid-dex/fluid-dex.abi.json';
|
|
28
|
-
import { FluidDexConfig, FLUID_DEX_GAS_COST } from './config';
|
|
29
|
-
import { FluidDexFactory } from './fluid-dex-factory';
|
|
30
|
-
import { getDexKeysWithNetwork, getBigIntPow } from '../../utils';
|
|
31
|
-
import { extractReturnAmountPosition } from '../../executor/utils';
|
|
32
|
-
import { MultiResult } from '../../lib/multi-wrapper';
|
|
33
|
-
import { generalDecoder } from '../../lib/decoders';
|
|
34
|
-
import { BigNumber } from 'ethers';
|
|
35
|
-
import { sqrt } from './utils';
|
|
36
|
-
import { FluidDexLiquidityProxy } from './fluid-dex-liquidity-proxy';
|
|
37
|
-
import { FluidDexEventPool } from './fluid-dex-pool';
|
|
38
|
-
import { MIN_SWAP_LIQUIDITY } from './constants';
|
|
39
|
-
|
|
40
|
-
export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
|
|
41
|
-
readonly hasConstantPriceLargeAmounts = false;
|
|
42
|
-
readonly needWrapNative = false;
|
|
43
|
-
readonly isFeeOnTransferSupported = false;
|
|
44
|
-
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
45
|
-
getDexKeysWithNetwork(FluidDexConfig);
|
|
46
|
-
|
|
47
|
-
logger: Logger;
|
|
48
|
-
|
|
49
|
-
pools: FluidDexPool[] = [];
|
|
50
|
-
|
|
51
|
-
eventPools: FluidDexEventPool[] = [];
|
|
52
|
-
|
|
53
|
-
readonly factory: FluidDexFactory;
|
|
54
|
-
|
|
55
|
-
readonly liquidityProxy: FluidDexLiquidityProxy;
|
|
56
|
-
|
|
57
|
-
readonly fluidDexPoolIface: Interface;
|
|
58
|
-
|
|
59
|
-
constructor(
|
|
60
|
-
readonly network: Network,
|
|
61
|
-
readonly dexKey: string,
|
|
62
|
-
readonly dexHelper: IDexHelper,
|
|
63
|
-
) {
|
|
64
|
-
super(dexHelper, dexKey);
|
|
65
|
-
this.logger = dexHelper.getLogger(dexKey);
|
|
66
|
-
this.factory = new FluidDexFactory(
|
|
67
|
-
dexKey,
|
|
68
|
-
FluidDexConfig[dexKey][network].commonAddresses,
|
|
69
|
-
network,
|
|
70
|
-
dexHelper,
|
|
71
|
-
this.logger,
|
|
72
|
-
this.onPoolCreatedUpdatePools.bind(this),
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
this.liquidityProxy = new FluidDexLiquidityProxy(
|
|
76
|
-
dexKey,
|
|
77
|
-
this.factory.commonAddresses,
|
|
78
|
-
this.network,
|
|
79
|
-
this.dexHelper,
|
|
80
|
-
this.logger,
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
this.fluidDexPoolIface = new Interface(FluidDexPoolABI);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private async fetchFluidDexPools(
|
|
87
|
-
blockNumber: number,
|
|
88
|
-
): Promise<FluidDexPool[]> {
|
|
89
|
-
const poolsFromFactory = await this.factory.getStateOrGenerate(
|
|
90
|
-
blockNumber,
|
|
91
|
-
false,
|
|
92
|
-
);
|
|
93
|
-
return this.generateFluidDexPoolsFromPoolsFactory(poolsFromFactory);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private generateFluidDexPoolsFromPoolsFactory(
|
|
97
|
-
pools: readonly Pool[],
|
|
98
|
-
): FluidDexPool[] {
|
|
99
|
-
return pools.map(pool => ({
|
|
100
|
-
id: `FluidDex_${pool.address.toLowerCase()}`,
|
|
101
|
-
address: pool.address.toLowerCase(),
|
|
102
|
-
token0: pool.token0.toLowerCase(),
|
|
103
|
-
token1: pool.token1.toLowerCase(),
|
|
104
|
-
}));
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Initialize pricing is called once in the start of
|
|
108
|
-
// pricing service. It is intended to setup the integration
|
|
109
|
-
// for pricing requests. It is optional for a DEX to
|
|
110
|
-
// implement this function
|
|
111
|
-
async initializePricing(blockNumber: number) {
|
|
112
|
-
await this.factory.initialize(blockNumber);
|
|
113
|
-
this.pools = await this.fetchFluidDexPools(blockNumber);
|
|
114
|
-
this.eventPools = await Promise.all(
|
|
115
|
-
this.pools.map(async pool => {
|
|
116
|
-
const eventPool = new FluidDexEventPool(
|
|
117
|
-
this.dexKey,
|
|
118
|
-
pool.address,
|
|
119
|
-
this.network,
|
|
120
|
-
this.dexHelper,
|
|
121
|
-
this.logger,
|
|
122
|
-
);
|
|
123
|
-
await eventPool.initialize(blockNumber);
|
|
124
|
-
return eventPool;
|
|
125
|
-
}),
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
await this.liquidityProxy.initialize(blockNumber);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
getAdapters(side: SwapSide) {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
protected onPoolCreatedUpdatePools(poolsFromFactory: readonly Pool[]) {
|
|
136
|
-
this.pools = this.generateFluidDexPoolsFromPoolsFactory(poolsFromFactory);
|
|
137
|
-
this.logger.info(`${this.dexKey}: pools list was updated ...`);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
decodePools = (result: MultiResult<BytesLike> | BytesLike): Pool[] => {
|
|
141
|
-
return generalDecoder(
|
|
142
|
-
result,
|
|
143
|
-
['tuple(address pool, address token0, address token1)[]'],
|
|
144
|
-
undefined,
|
|
145
|
-
decoded => {
|
|
146
|
-
return decoded.map((decodedPool: any) => ({
|
|
147
|
-
address: decodedPool[0][0].toLowerCase(),
|
|
148
|
-
token0: decodedPool[0][1].toLowerCase(),
|
|
149
|
-
token1: decodedPool[0][2].toLowerCase(),
|
|
150
|
-
}));
|
|
151
|
-
},
|
|
152
|
-
);
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
// Returns list of pool identifiers that can be used
|
|
156
|
-
// for a given swap. poolIdentifiers must be unique
|
|
157
|
-
// across DEXes. It is recommended to use
|
|
158
|
-
// ${dexKey}_${poolAddress} as a poolIdentifier
|
|
159
|
-
async getPoolIdentifiers(
|
|
160
|
-
srcToken: Token,
|
|
161
|
-
destToken: Token,
|
|
162
|
-
side: SwapSide,
|
|
163
|
-
blockNumber: number,
|
|
164
|
-
): Promise<string[]> {
|
|
165
|
-
const pools = this.getPoolsByTokenPair(srcToken.address, destToken.address);
|
|
166
|
-
return pools.map(pool => pool.id);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
getPoolsByTokenPair(srcToken: Address, destToken: Address): FluidDexPool[] {
|
|
170
|
-
const srcAddress = srcToken.toLowerCase();
|
|
171
|
-
const destAddress = destToken.toLowerCase();
|
|
172
|
-
|
|
173
|
-
// A pair must have 2 different tokens.
|
|
174
|
-
if (srcAddress === destAddress) return [];
|
|
175
|
-
|
|
176
|
-
const pools = this.pools.filter(
|
|
177
|
-
pool =>
|
|
178
|
-
(srcAddress === pool.token0 && destAddress === pool.token1) ||
|
|
179
|
-
(srcAddress === pool.token1 && destAddress === pool.token0),
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
return pools;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Returns pool prices for amounts.
|
|
186
|
-
// If limitPools is defined only pools in limitPools
|
|
187
|
-
// should be used. If limitPools is undefined then
|
|
188
|
-
// any pools can be used.
|
|
189
|
-
async getPricesVolume(
|
|
190
|
-
srcToken: Token,
|
|
191
|
-
destToken: Token,
|
|
192
|
-
amounts: bigint[],
|
|
193
|
-
side: SwapSide,
|
|
194
|
-
blockNumber: number,
|
|
195
|
-
limitPools?: string[],
|
|
196
|
-
): Promise<null | ExchangePrices<FluidDexData>> {
|
|
197
|
-
try {
|
|
198
|
-
if (srcToken.address.toLowerCase() === destToken.address.toLowerCase())
|
|
199
|
-
return null;
|
|
200
|
-
|
|
201
|
-
// Get the pools to use.
|
|
202
|
-
let pools = this.getPoolsByTokenPair(srcToken.address, destToken.address);
|
|
203
|
-
|
|
204
|
-
if (limitPools) {
|
|
205
|
-
pools = pools.filter(pool => limitPools.includes(pool.id));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (!pools.length) return null;
|
|
209
|
-
|
|
210
|
-
const liquidityProxyState = await this.liquidityProxy.getStateOrGenerate(
|
|
211
|
-
blockNumber,
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
const poolsPrices = await Promise.all(
|
|
215
|
-
pools.map(async pool => {
|
|
216
|
-
const currentPoolReserves = liquidityProxyState.poolsReserves.find(
|
|
217
|
-
poolReserve =>
|
|
218
|
-
poolReserve.pool.toLowerCase() === pool.address.toLowerCase(),
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
const eventPool = this.eventPools.find(
|
|
222
|
-
eventPool =>
|
|
223
|
-
eventPool.poolAddress.toLowerCase() ===
|
|
224
|
-
pool.address.toLowerCase(),
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
if (!eventPool) {
|
|
228
|
-
this.logger.warn(
|
|
229
|
-
`${this.dexKey}-${this.network}: Event pool ${pool.address} was not found...`,
|
|
230
|
-
);
|
|
231
|
-
return null;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const state = await eventPool.getStateOrGenerate(blockNumber);
|
|
235
|
-
|
|
236
|
-
if (!currentPoolReserves || state.isSwapAndArbitragePaused === true) {
|
|
237
|
-
return null;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const prices = amounts.map(amount => {
|
|
241
|
-
if (side === SwapSide.SELL) {
|
|
242
|
-
return this.swapIn(
|
|
243
|
-
srcToken.address.toLowerCase() === pool.token0.toLowerCase(),
|
|
244
|
-
amount,
|
|
245
|
-
currentPoolReserves.collateralReserves,
|
|
246
|
-
currentPoolReserves.debtReserves,
|
|
247
|
-
srcToken.decimals,
|
|
248
|
-
destToken.decimals,
|
|
249
|
-
BigInt(currentPoolReserves.fee),
|
|
250
|
-
currentPoolReserves.dexLimits,
|
|
251
|
-
BigInt(currentPoolReserves.centerPrice),
|
|
252
|
-
Math.floor(Date.now() / 1000),
|
|
253
|
-
);
|
|
254
|
-
} else {
|
|
255
|
-
return this.swapOut(
|
|
256
|
-
srcToken.address.toLowerCase() === pool.token0.toLowerCase(),
|
|
257
|
-
amount,
|
|
258
|
-
currentPoolReserves.collateralReserves,
|
|
259
|
-
currentPoolReserves.debtReserves,
|
|
260
|
-
srcToken.decimals,
|
|
261
|
-
destToken.decimals,
|
|
262
|
-
BigInt(currentPoolReserves.fee),
|
|
263
|
-
currentPoolReserves.dexLimits,
|
|
264
|
-
BigInt(currentPoolReserves.centerPrice),
|
|
265
|
-
Math.floor(Date.now() / 1000),
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
return {
|
|
271
|
-
prices: prices,
|
|
272
|
-
unit: getBigIntPow(destToken.decimals),
|
|
273
|
-
data: {
|
|
274
|
-
poolId: pool.id,
|
|
275
|
-
},
|
|
276
|
-
exchange: this.dexKey,
|
|
277
|
-
poolIdentifier: pool.id,
|
|
278
|
-
gasCost: FLUID_DEX_GAS_COST,
|
|
279
|
-
poolAddresses: [pool.address],
|
|
280
|
-
};
|
|
281
|
-
}),
|
|
282
|
-
);
|
|
283
|
-
|
|
284
|
-
const notNullResults = poolsPrices.filter(
|
|
285
|
-
res => res !== null,
|
|
286
|
-
) as ExchangePrices<FluidDexData>;
|
|
287
|
-
|
|
288
|
-
return notNullResults;
|
|
289
|
-
} catch (e) {
|
|
290
|
-
this.logger.error(
|
|
291
|
-
`Error_getPricesVolume ${srcToken.address || srcToken.symbol}, ${
|
|
292
|
-
destToken.address || destToken.symbol
|
|
293
|
-
}, ${side}:`,
|
|
294
|
-
e,
|
|
295
|
-
);
|
|
296
|
-
return null;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
301
|
-
getCalldataGasCost(poolPrices: PoolPrices<FluidDexData>): number | number[] {
|
|
302
|
-
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// Encode params required by the exchange adapter
|
|
306
|
-
// V5: Used for multiSwap, buy & megaSwap
|
|
307
|
-
// V6: Not used, can be left blank
|
|
308
|
-
// Hint: abiCoder.encodeParameter() could be useful
|
|
309
|
-
getAdapterParam(
|
|
310
|
-
srcToken: string,
|
|
311
|
-
destToken: string,
|
|
312
|
-
srcAmount: string,
|
|
313
|
-
destAmount: string,
|
|
314
|
-
data: FluidDexData,
|
|
315
|
-
side: SwapSide,
|
|
316
|
-
): AdapterExchangeParam {
|
|
317
|
-
// Encode here the payload for adapter
|
|
318
|
-
const payload = '';
|
|
319
|
-
|
|
320
|
-
return {
|
|
321
|
-
targetExchange: '0x',
|
|
322
|
-
payload,
|
|
323
|
-
networkFee: '0',
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// Returns list of top pools based on liquidity. Max
|
|
328
|
-
// limit number pools should be returned.
|
|
329
|
-
async getTopPoolsForToken(
|
|
330
|
-
tokenAddress: Address,
|
|
331
|
-
limit: number,
|
|
332
|
-
): Promise<PoolLiquidity[]> {
|
|
333
|
-
//@TODO
|
|
334
|
-
return [];
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
async getDexParam(
|
|
338
|
-
srcToken: Address,
|
|
339
|
-
destToken: Address,
|
|
340
|
-
srcAmount: string,
|
|
341
|
-
destAmount: string,
|
|
342
|
-
recipient: Address,
|
|
343
|
-
data: FluidDexData,
|
|
344
|
-
side: SwapSide,
|
|
345
|
-
context: Context,
|
|
346
|
-
executorAddress: Address,
|
|
347
|
-
): Promise<DexExchangeParam> {
|
|
348
|
-
let args: any;
|
|
349
|
-
let returnAmountPos: number | undefined;
|
|
350
|
-
|
|
351
|
-
const method = side === SwapSide.SELL ? 'swapIn' : 'swapOut';
|
|
352
|
-
|
|
353
|
-
returnAmountPos = extractReturnAmountPosition(
|
|
354
|
-
this.fluidDexPoolIface,
|
|
355
|
-
method,
|
|
356
|
-
side === SwapSide.SELL ? 'amountOut_' : 'amountIn_',
|
|
357
|
-
);
|
|
358
|
-
|
|
359
|
-
const pool = this.pools.find(pool => pool.id === data.poolId);
|
|
360
|
-
if (!pool)
|
|
361
|
-
throw new Error(
|
|
362
|
-
`${this.dexKey}-${this.network}: Pool with id: ${data.poolId} was not found`,
|
|
363
|
-
);
|
|
364
|
-
|
|
365
|
-
if (side === SwapSide.SELL) {
|
|
366
|
-
if (pool!.token0.toLowerCase() !== srcToken.toLowerCase()) {
|
|
367
|
-
args = [false, BigInt(srcAmount), BigInt(destAmount), recipient];
|
|
368
|
-
} else {
|
|
369
|
-
args = [true, BigInt(srcAmount), BigInt(destAmount), recipient];
|
|
370
|
-
}
|
|
371
|
-
} else {
|
|
372
|
-
if (pool!.token0.toLowerCase() !== srcToken.toLowerCase()) {
|
|
373
|
-
args = [
|
|
374
|
-
false,
|
|
375
|
-
(BigInt(destAmount) * 1000001n) / 1000000n, // 0.0001% increase target out amount when calling Fluid Dex as it is not 100% exact. Guarantees meeting reaching exact out amount condition
|
|
376
|
-
BigInt(srcAmount),
|
|
377
|
-
recipient,
|
|
378
|
-
];
|
|
379
|
-
} else {
|
|
380
|
-
args = [
|
|
381
|
-
true,
|
|
382
|
-
(BigInt(destAmount) * 1000001n) / 1000000n, // 0.0001% increase target out amount when calling Fluid Dex as it is not 100% exact. Guarantees meeting reaching exact out amount condition
|
|
383
|
-
BigInt(srcAmount),
|
|
384
|
-
recipient,
|
|
385
|
-
];
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
const swapData = this.fluidDexPoolIface.encodeFunctionData(method, args);
|
|
389
|
-
return {
|
|
390
|
-
needWrapNative: this.needWrapNative,
|
|
391
|
-
dexFuncHasRecipient: true,
|
|
392
|
-
exchangeData: swapData,
|
|
393
|
-
targetExchange: pool!.address,
|
|
394
|
-
returnAmountPos,
|
|
395
|
-
sendEthButSupportsInsertFromAmount: true,
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Calculates the output amount for a given input amount in a swap operation.
|
|
401
|
-
* @param swap0To1 - Direction of the swap. True if swapping token0 for token1, false otherwise.
|
|
402
|
-
* @param amountIn - The amount of input token to be swapped (as a BigInt).
|
|
403
|
-
* @param colReserves - The reserves of the collateral pool.
|
|
404
|
-
* @param debtReserves - The reserves of the debt pool.
|
|
405
|
-
* @param inDecimals - The number of decimals for the input token.
|
|
406
|
-
* @param outDecimals - The number of decimals for the output token.
|
|
407
|
-
* @returns The calculated output amount (as a BigInt).
|
|
408
|
-
*/
|
|
409
|
-
public swapIn(
|
|
410
|
-
swap0To1: boolean,
|
|
411
|
-
amountIn: bigint,
|
|
412
|
-
colReserves: CollateralReserves,
|
|
413
|
-
debtReserves: DebtReserves,
|
|
414
|
-
inDecimals: number,
|
|
415
|
-
outDecimals: number,
|
|
416
|
-
fee: bigint,
|
|
417
|
-
currentLimits: DexLimits,
|
|
418
|
-
centerPrice: bigint,
|
|
419
|
-
syncTime: number,
|
|
420
|
-
): bigint {
|
|
421
|
-
if (amountIn === 0n) {
|
|
422
|
-
return 0n; // Return 0 if input amount is 0
|
|
423
|
-
}
|
|
424
|
-
if (
|
|
425
|
-
colReserves.token0RealReserves + debtReserves.token0RealReserves == 0n &&
|
|
426
|
-
colReserves.token1RealReserves + debtReserves.token1RealReserves == 0n
|
|
427
|
-
) {
|
|
428
|
-
return 0n;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
const amountInAdjusted =
|
|
432
|
-
(amountIn * BigInt(10 ** 12)) / BigInt(10 ** inDecimals);
|
|
433
|
-
|
|
434
|
-
const amountOut = this.swapInAdjusted(
|
|
435
|
-
swap0To1,
|
|
436
|
-
amountInAdjusted,
|
|
437
|
-
colReserves,
|
|
438
|
-
debtReserves,
|
|
439
|
-
fee,
|
|
440
|
-
outDecimals,
|
|
441
|
-
currentLimits,
|
|
442
|
-
centerPrice,
|
|
443
|
-
syncTime,
|
|
444
|
-
);
|
|
445
|
-
return (amountOut * BigInt(10 ** outDecimals)) / BigInt(10 ** 12);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* Calculates the output amount for a given input amount in a swap operation.
|
|
450
|
-
* @param swap0To1 - Direction of the swap. True if swapping token0 for token1, false otherwise.
|
|
451
|
-
* @param amountToSwap - The amount of input token to be swapped.
|
|
452
|
-
* @param colReserves - The reserves of the collateral pool.
|
|
453
|
-
* @param debtReserves - The reserves of the debt pool.
|
|
454
|
-
* @returns The calculated output amount.
|
|
455
|
-
*/
|
|
456
|
-
public swapInAdjusted(
|
|
457
|
-
swap0To1: boolean,
|
|
458
|
-
amountToSwap: bigint,
|
|
459
|
-
colReserves: CollateralReserves,
|
|
460
|
-
debtReserves: DebtReserves,
|
|
461
|
-
fee: bigint,
|
|
462
|
-
outDecimals: number,
|
|
463
|
-
currentLimits: DexLimits,
|
|
464
|
-
centerPrice: bigint,
|
|
465
|
-
syncTime: number,
|
|
466
|
-
): bigint {
|
|
467
|
-
const {
|
|
468
|
-
token0RealReserves,
|
|
469
|
-
token1RealReserves,
|
|
470
|
-
token0ImaginaryReserves,
|
|
471
|
-
token1ImaginaryReserves,
|
|
472
|
-
} = colReserves;
|
|
473
|
-
const {
|
|
474
|
-
token0RealReserves: debtToken0RealReserves,
|
|
475
|
-
token1RealReserves: debtToken1RealReserves,
|
|
476
|
-
token0ImaginaryReserves: debtToken0ImaginaryReserves,
|
|
477
|
-
token1ImaginaryReserves: debtToken1ImaginaryReserves,
|
|
478
|
-
} = debtReserves;
|
|
479
|
-
|
|
480
|
-
// Check if all reserves of collateral pool are greater than 0
|
|
481
|
-
const colPoolEnabled =
|
|
482
|
-
token0RealReserves > 0 &&
|
|
483
|
-
token1RealReserves > 0 &&
|
|
484
|
-
token0ImaginaryReserves > 0 &&
|
|
485
|
-
token1ImaginaryReserves > 0;
|
|
486
|
-
|
|
487
|
-
// Check if all reserves of debt pool are greater than 0
|
|
488
|
-
const debtPoolEnabled =
|
|
489
|
-
debtToken0RealReserves > 0 &&
|
|
490
|
-
debtToken1RealReserves > 0 &&
|
|
491
|
-
debtToken0ImaginaryReserves > 0 &&
|
|
492
|
-
debtToken1ImaginaryReserves > 0;
|
|
493
|
-
|
|
494
|
-
let colReserveIn, colReserveOut, debtReserveIn, debtReserveOut;
|
|
495
|
-
let colIReserveIn, colIReserveOut, debtIReserveIn, debtIReserveOut;
|
|
496
|
-
let borrowable, withdrawable;
|
|
497
|
-
|
|
498
|
-
if (swap0To1) {
|
|
499
|
-
colReserveIn = token0RealReserves;
|
|
500
|
-
colReserveOut = token1RealReserves;
|
|
501
|
-
colIReserveIn = token0ImaginaryReserves;
|
|
502
|
-
colIReserveOut = token1ImaginaryReserves;
|
|
503
|
-
debtReserveIn = debtToken0RealReserves;
|
|
504
|
-
debtReserveOut = debtToken1RealReserves;
|
|
505
|
-
debtIReserveIn = debtToken0ImaginaryReserves;
|
|
506
|
-
debtIReserveOut = debtToken1ImaginaryReserves;
|
|
507
|
-
borrowable = this.getExpandedLimit(
|
|
508
|
-
syncTime,
|
|
509
|
-
currentLimits.borrowableToken1,
|
|
510
|
-
);
|
|
511
|
-
withdrawable = this.getExpandedLimit(
|
|
512
|
-
syncTime,
|
|
513
|
-
currentLimits.withdrawableToken1,
|
|
514
|
-
);
|
|
515
|
-
} else {
|
|
516
|
-
colReserveIn = token1RealReserves;
|
|
517
|
-
colReserveOut = token0RealReserves;
|
|
518
|
-
colIReserveIn = token1ImaginaryReserves;
|
|
519
|
-
colIReserveOut = token0ImaginaryReserves;
|
|
520
|
-
debtReserveIn = debtToken1RealReserves;
|
|
521
|
-
debtReserveOut = debtToken0RealReserves;
|
|
522
|
-
debtIReserveIn = debtToken1ImaginaryReserves;
|
|
523
|
-
debtIReserveOut = debtToken0ImaginaryReserves;
|
|
524
|
-
borrowable = this.getExpandedLimit(
|
|
525
|
-
syncTime,
|
|
526
|
-
currentLimits.borrowableToken0,
|
|
527
|
-
);
|
|
528
|
-
withdrawable = this.getExpandedLimit(
|
|
529
|
-
syncTime,
|
|
530
|
-
currentLimits.withdrawableToken0,
|
|
531
|
-
);
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
// bring borrowable and withdrawable from token decimals to 1e12 decimals, same as amounts
|
|
535
|
-
borrowable = (borrowable * BigInt(10 ** 12)) / BigInt(10 ** outDecimals);
|
|
536
|
-
withdrawable =
|
|
537
|
-
(withdrawable * BigInt(10 ** 12)) / BigInt(10 ** outDecimals);
|
|
538
|
-
|
|
539
|
-
let a: bigint;
|
|
540
|
-
if (colPoolEnabled && debtPoolEnabled) {
|
|
541
|
-
a = this.swapRoutingIn(
|
|
542
|
-
amountToSwap,
|
|
543
|
-
colIReserveOut,
|
|
544
|
-
colIReserveIn,
|
|
545
|
-
debtIReserveOut,
|
|
546
|
-
debtIReserveIn,
|
|
547
|
-
);
|
|
548
|
-
} else if (debtPoolEnabled) {
|
|
549
|
-
a = -1n; // Route from debt pool
|
|
550
|
-
} else if (colPoolEnabled) {
|
|
551
|
-
a = amountToSwap + 1n; // Route from collateral pool
|
|
552
|
-
} else {
|
|
553
|
-
throw new Error('No pools are enabled');
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
let amountOutCollateral = 0n;
|
|
557
|
-
let amountOutDebt = 0n;
|
|
558
|
-
let amountInCollateral = 0n;
|
|
559
|
-
let amountInDebt = 0n;
|
|
560
|
-
|
|
561
|
-
if (a <= 0n) {
|
|
562
|
-
// Entire trade routes through debt pool
|
|
563
|
-
amountInDebt = amountToSwap;
|
|
564
|
-
|
|
565
|
-
amountOutDebt = this.getAmountOut(
|
|
566
|
-
this.applyFeeForSell(amountToSwap, fee),
|
|
567
|
-
debtIReserveIn,
|
|
568
|
-
debtIReserveOut,
|
|
569
|
-
);
|
|
570
|
-
} else if (a >= amountToSwap) {
|
|
571
|
-
// Entire trade routes through collateral pool
|
|
572
|
-
amountInCollateral = amountToSwap;
|
|
573
|
-
amountOutCollateral = this.getAmountOut(
|
|
574
|
-
this.applyFeeForSell(amountToSwap, fee),
|
|
575
|
-
colIReserveIn,
|
|
576
|
-
colIReserveOut,
|
|
577
|
-
);
|
|
578
|
-
} else {
|
|
579
|
-
// Trade routes through both pools
|
|
580
|
-
amountInCollateral = a;
|
|
581
|
-
amountOutCollateral = this.getAmountOut(
|
|
582
|
-
this.applyFeeForSell(a, fee),
|
|
583
|
-
colIReserveIn,
|
|
584
|
-
colIReserveOut,
|
|
585
|
-
);
|
|
586
|
-
amountInDebt = amountToSwap - a;
|
|
587
|
-
amountOutDebt = this.getAmountOut(
|
|
588
|
-
this.applyFeeForSell(amountInDebt, fee),
|
|
589
|
-
debtIReserveIn,
|
|
590
|
-
debtIReserveOut,
|
|
591
|
-
);
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
if (amountOutDebt > debtReserveOut) {
|
|
595
|
-
return 0n;
|
|
596
|
-
}
|
|
597
|
-
if (amountOutDebt > borrowable) {
|
|
598
|
-
return 0n;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
if (amountOutCollateral > colReserveOut) {
|
|
602
|
-
return 0n;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
if (amountOutCollateral > withdrawable) {
|
|
606
|
-
return 0n;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
if (amountInCollateral > 0) {
|
|
610
|
-
let reservesRatioValid = swap0To1
|
|
611
|
-
? this.verifyToken1Reserves(
|
|
612
|
-
colReserveIn + amountInCollateral,
|
|
613
|
-
colReserveOut - amountOutCollateral,
|
|
614
|
-
centerPrice,
|
|
615
|
-
)
|
|
616
|
-
: this.verifyToken0Reserves(
|
|
617
|
-
colReserveOut - amountOutCollateral,
|
|
618
|
-
colReserveIn + amountInCollateral,
|
|
619
|
-
centerPrice,
|
|
620
|
-
);
|
|
621
|
-
if (!reservesRatioValid) {
|
|
622
|
-
return 0n;
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
if (amountInDebt > 0) {
|
|
627
|
-
let reservesRatioValid = swap0To1
|
|
628
|
-
? this.verifyToken1Reserves(
|
|
629
|
-
debtReserveIn + amountInDebt,
|
|
630
|
-
debtReserveOut - amountOutDebt,
|
|
631
|
-
centerPrice,
|
|
632
|
-
)
|
|
633
|
-
: this.verifyToken0Reserves(
|
|
634
|
-
debtReserveOut - amountOutDebt,
|
|
635
|
-
debtReserveIn + amountInDebt,
|
|
636
|
-
centerPrice,
|
|
637
|
-
);
|
|
638
|
-
if (!reservesRatioValid) {
|
|
639
|
-
return 0n;
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
// For price calculations, we'll use a precision factor for bigint division
|
|
644
|
-
const PRECISION = 1000000000000000000000000000n; // 1e27
|
|
645
|
-
|
|
646
|
-
let oldPrice: bigint;
|
|
647
|
-
let newPrice: bigint;
|
|
648
|
-
|
|
649
|
-
if (amountInCollateral > amountInDebt) {
|
|
650
|
-
// new pool price from col pool
|
|
651
|
-
oldPrice = swap0To1
|
|
652
|
-
? (colIReserveOut * PRECISION) / colIReserveIn
|
|
653
|
-
: (colIReserveIn * PRECISION) / colIReserveOut;
|
|
654
|
-
|
|
655
|
-
newPrice = swap0To1
|
|
656
|
-
? ((colIReserveOut - amountOutCollateral) * PRECISION) /
|
|
657
|
-
(colIReserveIn + amountInCollateral)
|
|
658
|
-
: ((colIReserveIn + amountInCollateral) * PRECISION) /
|
|
659
|
-
(colIReserveOut - amountOutCollateral);
|
|
660
|
-
} else {
|
|
661
|
-
// new pool price from debt pool
|
|
662
|
-
oldPrice = swap0To1
|
|
663
|
-
? (debtIReserveOut * PRECISION) / debtIReserveIn
|
|
664
|
-
: (debtIReserveIn * PRECISION) / debtIReserveOut;
|
|
665
|
-
|
|
666
|
-
newPrice = swap0To1
|
|
667
|
-
? ((debtIReserveOut - amountOutDebt) * PRECISION) /
|
|
668
|
-
(debtIReserveIn + amountInDebt)
|
|
669
|
-
: ((debtIReserveIn + amountInDebt) * PRECISION) /
|
|
670
|
-
(debtIReserveOut - amountOutDebt);
|
|
671
|
-
}
|
|
672
|
-
// Calculate price difference using bigint arithmetic
|
|
673
|
-
const MAX_PRICE_DIFF = 5n; // 5%
|
|
674
|
-
const priceDiff =
|
|
675
|
-
oldPrice > newPrice ? oldPrice - newPrice : newPrice - oldPrice;
|
|
676
|
-
const maxAllowedDiff = (oldPrice * MAX_PRICE_DIFF) / 100n;
|
|
677
|
-
|
|
678
|
-
if (priceDiff > maxAllowedDiff) {
|
|
679
|
-
return 0n;
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
const totalAmountOut = amountOutCollateral + amountOutDebt;
|
|
683
|
-
|
|
684
|
-
return totalAmountOut;
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
/**
|
|
688
|
-
* Checks if token0 reserves are sufficient compared to token1 reserves.
|
|
689
|
-
* This helps prevent edge cases and ensures high precision in calculations.
|
|
690
|
-
* @param {number} token0Reserves - The reserves of token0.
|
|
691
|
-
* @param {number} token1Reserves - The reserves of token1.
|
|
692
|
-
* @param {number} price - The current price used for calculation.
|
|
693
|
-
* @returns {boolean} - Returns false if token0 reserves are too low, true otherwise.
|
|
694
|
-
*/
|
|
695
|
-
protected verifyToken0Reserves(
|
|
696
|
-
token0Reserves: bigint,
|
|
697
|
-
token1Reserves: bigint,
|
|
698
|
-
price: bigint,
|
|
699
|
-
): boolean {
|
|
700
|
-
return (
|
|
701
|
-
token0Reserves >=
|
|
702
|
-
(token1Reserves * 10n ** 27n) / (price * MIN_SWAP_LIQUIDITY)
|
|
703
|
-
);
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
/**
|
|
707
|
-
* Checks if token1 reserves are sufficient compared to token0 reserves.
|
|
708
|
-
* This helps prevent edge cases and ensures high precision in calculations.
|
|
709
|
-
* @param {number} token0Reserves - The reserves of token0.
|
|
710
|
-
* @param {number} token1Reserves - The reserves of token1.
|
|
711
|
-
* @param {number} price - The current price used for calculation.
|
|
712
|
-
* @returns {boolean} - Returns false if token1 reserves are too low, true otherwise.
|
|
713
|
-
*/
|
|
714
|
-
protected verifyToken1Reserves(
|
|
715
|
-
token0Reserves: bigint,
|
|
716
|
-
token1Reserves: bigint,
|
|
717
|
-
price: bigint,
|
|
718
|
-
): boolean {
|
|
719
|
-
return (
|
|
720
|
-
token1Reserves >=
|
|
721
|
-
(token0Reserves * price) / (10n ** 27n * MIN_SWAP_LIQUIDITY)
|
|
722
|
-
);
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
/**
|
|
726
|
-
* Calculates the currently available swappable amount for a token limit considering expansion since last syncTime.
|
|
727
|
-
* @param syncTime - timestamp in seconds when the limits were synced
|
|
728
|
-
* @param limit - token limit object containing available amount, expandsTo amount, and expandDuration
|
|
729
|
-
* @returns The calculated available swappable amount (borrowable or withdrawable)
|
|
730
|
-
*/
|
|
731
|
-
public getExpandedLimit(syncTime: number, limit: TokenLimit): bigint {
|
|
732
|
-
const currentTime = Math.floor(Date.now() / 1000); // convert milliseconds to seconds
|
|
733
|
-
const elapsedTime = currentTime - syncTime;
|
|
734
|
-
limit.expandsDuration = limit.expandsDuration || 0n;
|
|
735
|
-
if (elapsedTime < 10n) {
|
|
736
|
-
// if almost no time has elapsed, return available amount
|
|
737
|
-
return limit.available;
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
if (elapsedTime >= limit.expandsDuration) {
|
|
741
|
-
// if duration has passed, return max amount
|
|
742
|
-
return limit.expandsTo;
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
// Calculate expansion ratio using bigint arithmetic
|
|
746
|
-
// Multiply by a large factor for precision in integer arithmetic
|
|
747
|
-
const PRECISION = 1000000;
|
|
748
|
-
const ratio = BigInt(elapsedTime * PRECISION) / limit.expandsDuration;
|
|
749
|
-
|
|
750
|
-
// Calculate expanded amount with precision factor
|
|
751
|
-
const expansion =
|
|
752
|
-
((limit.expandsTo - limit.available) * ratio) / BigInt(PRECISION);
|
|
753
|
-
const expandedAmount = limit.available + expansion;
|
|
754
|
-
return expandedAmount;
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
/**
|
|
758
|
-
* Given an input amount of asset and pair reserves, returns the maximum output amount of the other asset.
|
|
759
|
-
* @param amountIn - The amount of input asset.
|
|
760
|
-
* @param iReserveIn - Imaginary token reserve with input amount.
|
|
761
|
-
* @param iReserveOut - Imaginary token reserve of output amount.
|
|
762
|
-
* @returns The maximum output amount of the other asset.
|
|
763
|
-
*/
|
|
764
|
-
public getAmountOut(
|
|
765
|
-
amountIn: bigint,
|
|
766
|
-
iReserveIn: bigint,
|
|
767
|
-
iReserveOut: bigint,
|
|
768
|
-
): bigint {
|
|
769
|
-
// Both numerator and denominator are scaled to 1e6 to factor in fee scaling.
|
|
770
|
-
const numerator = amountIn * iReserveOut;
|
|
771
|
-
const denominator = iReserveIn + amountIn;
|
|
772
|
-
|
|
773
|
-
// Using the swap formula: (AmountIn * iReserveY) / (iReserveX + AmountIn)
|
|
774
|
-
// We use division with rounding down, which is the default for bigint division
|
|
775
|
-
|
|
776
|
-
return numerator / denominator;
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
/**
|
|
780
|
-
* Given an output amount of asset and pair reserves, returns the input amount of the other asset
|
|
781
|
-
* @param amountOut - Desired output amount of the asset.
|
|
782
|
-
* @param iReserveIn - Imaginary token reserve of input amount.
|
|
783
|
-
* @param iReserveOut - Imaginary token reserve of output amount.
|
|
784
|
-
* @returns The input amount of the other asset.
|
|
785
|
-
*/
|
|
786
|
-
public getAmountIn(
|
|
787
|
-
amountOut: bigint,
|
|
788
|
-
iReserveIn: bigint,
|
|
789
|
-
iReserveOut: bigint,
|
|
790
|
-
): bigint {
|
|
791
|
-
// Both numerator and denominator are scaled to 1e6 to factor in fee scaling.
|
|
792
|
-
const numerator = amountOut * iReserveIn;
|
|
793
|
-
const denominator = iReserveOut - amountOut;
|
|
794
|
-
|
|
795
|
-
// Using the swap formula: (AmountOut * iReserveX) / (iReserveY - AmountOut)
|
|
796
|
-
return numerator / denominator;
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
/**
|
|
800
|
-
* Calculates how much of a swap should go through the collateral pool for output amount.
|
|
801
|
-
* @param t - Total amount out.
|
|
802
|
-
* @param x - Imaginary reserves of token in of collateral.
|
|
803
|
-
* @param y - Imaginary reserves of token out of collateral.
|
|
804
|
-
* @param x2 - Imaginary reserves of token in of debt.
|
|
805
|
-
* @param y2 - Imaginary reserves of token out of debt.
|
|
806
|
-
* @returns How much swap should go through collateral pool. Remaining will go from debt.
|
|
807
|
-
* @note If a < 0 then entire trade route through debt pool and debt pool arbitrage with col pool.
|
|
808
|
-
* @note If a > t then entire trade route through col pool and col pool arbitrage with debt pool.
|
|
809
|
-
* @note If a > 0 & a < t then swap will route through both pools.
|
|
810
|
-
*/
|
|
811
|
-
public swapRoutingOut(
|
|
812
|
-
t: bigint,
|
|
813
|
-
x: bigint,
|
|
814
|
-
y: bigint,
|
|
815
|
-
x2: bigint,
|
|
816
|
-
y2: bigint,
|
|
817
|
-
): bigint {
|
|
818
|
-
// Adding 1e18 precision
|
|
819
|
-
const xyRoot = sqrt(BigNumber.from(x).mul(y).mul(BigInt(1e18))).toBigInt();
|
|
820
|
-
const x2y2Root = sqrt(
|
|
821
|
-
BigNumber.from(x2).mul(y2).mul(BigInt(1e18)),
|
|
822
|
-
).toBigInt();
|
|
823
|
-
|
|
824
|
-
// 1e18 precision gets cancelled out in division
|
|
825
|
-
const numerator = t * xyRoot + y * x2y2Root - y2 * xyRoot;
|
|
826
|
-
const denominator = xyRoot + x2y2Root;
|
|
827
|
-
|
|
828
|
-
// Use integer division (rounds down)
|
|
829
|
-
const a = numerator / denominator;
|
|
830
|
-
|
|
831
|
-
return a;
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
/**
|
|
835
|
-
* Calculates how much of a swap should go through the collateral pool.
|
|
836
|
-
* @param t - Total amount in.
|
|
837
|
-
* @param x - Imaginary reserves of token out of collateral.
|
|
838
|
-
* @param y - Imaginary reserves of token in of collateral.
|
|
839
|
-
* @param x2 - Imaginary reserves of token out of debt.
|
|
840
|
-
* @param y2 - Imaginary reserves of token in of debt.
|
|
841
|
-
* @returns How much swap should go through collateral pool. Remaining will go from debt.
|
|
842
|
-
* @note If a < 0 then entire trade route through debt pool and debt pool arbitrage with col pool.
|
|
843
|
-
* @note If a > t then entire trade route through col pool and col pool arbitrage with debt pool.
|
|
844
|
-
* @note If a > 0 & a < t then swap will route through both pools.
|
|
845
|
-
*/
|
|
846
|
-
public swapRoutingIn(
|
|
847
|
-
t: bigint,
|
|
848
|
-
x: bigint,
|
|
849
|
-
y: bigint,
|
|
850
|
-
x2: bigint,
|
|
851
|
-
y2: bigint,
|
|
852
|
-
): bigint {
|
|
853
|
-
// Adding 1e18 precision
|
|
854
|
-
|
|
855
|
-
const xyRoot = sqrt(BigNumber.from(x).mul(y).mul(BigInt(1e18))).toBigInt();
|
|
856
|
-
const x2y2Root = sqrt(
|
|
857
|
-
BigNumber.from(x2).mul(y2).mul(BigInt(1e18)),
|
|
858
|
-
).toBigInt();
|
|
859
|
-
|
|
860
|
-
// Calculating 'a' using the given formula
|
|
861
|
-
const a = (y2 * xyRoot + t * xyRoot - y * x2y2Root) / (xyRoot + x2y2Root);
|
|
862
|
-
return a;
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
/**
|
|
866
|
-
* Calculates the input amount for a given output amount in a swap operation.
|
|
867
|
-
* @param {boolean} swap0to1 - Direction of the swap. True if swapping token0 for token1, false otherwise.
|
|
868
|
-
* @param {bigint} amountOut - The amount of output token to be swapped.
|
|
869
|
-
* @param {Reserves} colReserves - The reserves of the collateral pool.
|
|
870
|
-
* @param {Reserves} debtReserves - The reserves of the debt pool.
|
|
871
|
-
* @param {number} inDecimals - The number of decimals for the input token.
|
|
872
|
-
* @param {number} outDecimals - The number of decimals for the output token.
|
|
873
|
-
* @param {number} fee - The fee for the swap. 1e4 = 1%
|
|
874
|
-
* @returns {bigint} amountIn - The calculated input amount required for the swap.
|
|
875
|
-
*/
|
|
876
|
-
public swapOut(
|
|
877
|
-
swap0to1: boolean,
|
|
878
|
-
amountOut: bigint,
|
|
879
|
-
colReserves: CollateralReserves,
|
|
880
|
-
debtReserves: DebtReserves,
|
|
881
|
-
inDecimals: number,
|
|
882
|
-
outDecimals: number,
|
|
883
|
-
fee: bigint,
|
|
884
|
-
currentLimits: DexLimits,
|
|
885
|
-
centerPrice: bigint,
|
|
886
|
-
syncTime: number,
|
|
887
|
-
): bigint {
|
|
888
|
-
const amountOutAdjusted =
|
|
889
|
-
(amountOut * BigInt(10 ** 12)) / BigInt(10 ** outDecimals);
|
|
890
|
-
|
|
891
|
-
const amountIn = this.swapOutAdjusted(
|
|
892
|
-
swap0to1,
|
|
893
|
-
amountOutAdjusted,
|
|
894
|
-
colReserves,
|
|
895
|
-
debtReserves,
|
|
896
|
-
fee,
|
|
897
|
-
outDecimals,
|
|
898
|
-
currentLimits,
|
|
899
|
-
centerPrice,
|
|
900
|
-
syncTime,
|
|
901
|
-
);
|
|
902
|
-
|
|
903
|
-
const ans = (amountIn * BigInt(10 ** inDecimals)) / BigInt(10 ** 12);
|
|
904
|
-
return ans;
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
/**
|
|
908
|
-
* Calculates the input amount for a given output amount in a swap operation.
|
|
909
|
-
* @param {boolean} swap0to1 - Direction of the swap. True if swapping token0 for token1, false otherwise.
|
|
910
|
-
* @param {bigint} amountOut - The amount of output token to be swapped.
|
|
911
|
-
* @param {CollateralReserves} colReserves - The reserves of the collateral pool.
|
|
912
|
-
* @param {DebtReserves} debtReserves - The reserves of the debt pool.
|
|
913
|
-
* @returns {bigint} The calculated input amount required for the swap.
|
|
914
|
-
*/
|
|
915
|
-
public swapOutAdjusted(
|
|
916
|
-
swap0to1: boolean,
|
|
917
|
-
amountOut: bigint,
|
|
918
|
-
colReserves: CollateralReserves,
|
|
919
|
-
debtReserves: DebtReserves,
|
|
920
|
-
fee: bigint,
|
|
921
|
-
outDecimals: number,
|
|
922
|
-
currentLimits: DexLimits,
|
|
923
|
-
centerPrice: bigint,
|
|
924
|
-
syncTime: number,
|
|
925
|
-
): bigint {
|
|
926
|
-
if (amountOut === 0n) {
|
|
927
|
-
return 0n; // Return 0 if output amount is 0
|
|
928
|
-
}
|
|
929
|
-
const {
|
|
930
|
-
token0RealReserves,
|
|
931
|
-
token1RealReserves,
|
|
932
|
-
token0ImaginaryReserves,
|
|
933
|
-
token1ImaginaryReserves,
|
|
934
|
-
} = colReserves;
|
|
935
|
-
|
|
936
|
-
const {
|
|
937
|
-
token0RealReserves: debtToken0RealReserves,
|
|
938
|
-
token1RealReserves: debtToken1RealReserves,
|
|
939
|
-
token0ImaginaryReserves: debtToken0ImaginaryReserves,
|
|
940
|
-
token1ImaginaryReserves: debtToken1ImaginaryReserves,
|
|
941
|
-
} = debtReserves;
|
|
942
|
-
|
|
943
|
-
// Check if all reserves of collateral pool are greater than 0
|
|
944
|
-
const colPoolEnabled =
|
|
945
|
-
token0RealReserves > 0n &&
|
|
946
|
-
token1RealReserves > 0n &&
|
|
947
|
-
token0ImaginaryReserves > 0n &&
|
|
948
|
-
token1ImaginaryReserves > 0n;
|
|
949
|
-
|
|
950
|
-
// Check if all reserves of debt pool are greater than 0
|
|
951
|
-
const debtPoolEnabled =
|
|
952
|
-
debtToken0RealReserves > 0n &&
|
|
953
|
-
debtToken1RealReserves > 0n &&
|
|
954
|
-
debtToken0ImaginaryReserves > 0n &&
|
|
955
|
-
debtToken1ImaginaryReserves > 0n;
|
|
956
|
-
|
|
957
|
-
let colReserveIn: bigint,
|
|
958
|
-
colReserveOut: bigint,
|
|
959
|
-
debtReserveIn: bigint,
|
|
960
|
-
debtReserveOut: bigint;
|
|
961
|
-
let colIReserveIn: bigint,
|
|
962
|
-
colIReserveOut: bigint,
|
|
963
|
-
debtIReserveIn: bigint,
|
|
964
|
-
debtIReserveOut: bigint;
|
|
965
|
-
let borrowable: bigint, withdrawable: bigint;
|
|
966
|
-
|
|
967
|
-
if (swap0to1) {
|
|
968
|
-
colReserveIn = token0RealReserves;
|
|
969
|
-
colReserveOut = token1RealReserves;
|
|
970
|
-
colIReserveIn = token0ImaginaryReserves;
|
|
971
|
-
colIReserveOut = token1ImaginaryReserves;
|
|
972
|
-
debtReserveIn = debtToken0RealReserves;
|
|
973
|
-
debtReserveOut = debtToken1RealReserves;
|
|
974
|
-
debtIReserveIn = debtToken0ImaginaryReserves;
|
|
975
|
-
debtIReserveOut = debtToken1ImaginaryReserves;
|
|
976
|
-
borrowable = this.getExpandedLimit(
|
|
977
|
-
syncTime,
|
|
978
|
-
currentLimits.borrowableToken1,
|
|
979
|
-
);
|
|
980
|
-
withdrawable = this.getExpandedLimit(
|
|
981
|
-
syncTime,
|
|
982
|
-
currentLimits.withdrawableToken1,
|
|
983
|
-
);
|
|
984
|
-
} else {
|
|
985
|
-
colReserveIn = token1RealReserves;
|
|
986
|
-
colReserveOut = token0RealReserves;
|
|
987
|
-
colIReserveIn = token1ImaginaryReserves;
|
|
988
|
-
colIReserveOut = token0ImaginaryReserves;
|
|
989
|
-
debtReserveIn = debtToken1RealReserves;
|
|
990
|
-
debtReserveOut = debtToken0RealReserves;
|
|
991
|
-
debtIReserveIn = debtToken1ImaginaryReserves;
|
|
992
|
-
debtIReserveOut = debtToken0ImaginaryReserves;
|
|
993
|
-
borrowable = this.getExpandedLimit(
|
|
994
|
-
syncTime,
|
|
995
|
-
currentLimits.borrowableToken0,
|
|
996
|
-
);
|
|
997
|
-
withdrawable = this.getExpandedLimit(
|
|
998
|
-
syncTime,
|
|
999
|
-
currentLimits.withdrawableToken0,
|
|
1000
|
-
);
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
// bring borrowable and withdrawable from token decimals to 1e12 decimals, same as amounts
|
|
1004
|
-
borrowable = (borrowable * BigInt(10 ** 12)) / BigInt(10 ** outDecimals);
|
|
1005
|
-
withdrawable =
|
|
1006
|
-
(withdrawable * BigInt(10 ** 12)) / BigInt(10 ** outDecimals);
|
|
1007
|
-
|
|
1008
|
-
let a: bigint;
|
|
1009
|
-
if (colPoolEnabled && debtPoolEnabled) {
|
|
1010
|
-
a = this.swapRoutingOut(
|
|
1011
|
-
amountOut,
|
|
1012
|
-
colIReserveIn,
|
|
1013
|
-
colIReserveOut,
|
|
1014
|
-
debtIReserveIn,
|
|
1015
|
-
debtIReserveOut,
|
|
1016
|
-
);
|
|
1017
|
-
} else if (debtPoolEnabled) {
|
|
1018
|
-
a = -1n; // Route from debt pool
|
|
1019
|
-
} else if (colPoolEnabled) {
|
|
1020
|
-
a = amountOut + 1n; // Route from collateral pool
|
|
1021
|
-
} else {
|
|
1022
|
-
throw new Error('No pools are enabled');
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
let amountInCollateral: bigint = 0n;
|
|
1026
|
-
let amountInDebt: bigint = 0n;
|
|
1027
|
-
let amountOutCollateral: bigint = 0n;
|
|
1028
|
-
let amountOutDebt: bigint = 0n;
|
|
1029
|
-
|
|
1030
|
-
if (a <= 0n) {
|
|
1031
|
-
// Entire trade routes through debt pool
|
|
1032
|
-
|
|
1033
|
-
amountOutDebt = amountOut;
|
|
1034
|
-
amountInDebt = this.getAmountIn(
|
|
1035
|
-
amountOut,
|
|
1036
|
-
debtIReserveIn,
|
|
1037
|
-
debtIReserveOut,
|
|
1038
|
-
);
|
|
1039
|
-
amountInDebt = this.applyFeeForBuy(amountInDebt, fee);
|
|
1040
|
-
if (amountOut > debtReserveOut) {
|
|
1041
|
-
return 0n;
|
|
1042
|
-
}
|
|
1043
|
-
if (amountOut > borrowable) {
|
|
1044
|
-
return 0n;
|
|
1045
|
-
}
|
|
1046
|
-
} else if (a >= amountOut) {
|
|
1047
|
-
// Entire trade routes through collateral pool
|
|
1048
|
-
amountOutCollateral = amountOut;
|
|
1049
|
-
amountInCollateral = this.getAmountIn(
|
|
1050
|
-
amountOut,
|
|
1051
|
-
colIReserveIn,
|
|
1052
|
-
colIReserveOut,
|
|
1053
|
-
);
|
|
1054
|
-
amountInCollateral = this.applyFeeForBuy(amountInCollateral, fee);
|
|
1055
|
-
if (amountOut > colReserveOut) {
|
|
1056
|
-
return 0n;
|
|
1057
|
-
}
|
|
1058
|
-
if (amountOut > withdrawable) {
|
|
1059
|
-
return 0n;
|
|
1060
|
-
}
|
|
1061
|
-
} else {
|
|
1062
|
-
// Trade routes through both pools
|
|
1063
|
-
amountOutCollateral = a;
|
|
1064
|
-
amountInCollateral = this.getAmountIn(a, colIReserveIn, colIReserveOut);
|
|
1065
|
-
const amountOutDebtAdjusted = amountOut - a;
|
|
1066
|
-
|
|
1067
|
-
amountInCollateral = this.applyFeeForBuy(amountInCollateral, fee);
|
|
1068
|
-
|
|
1069
|
-
amountInDebt = this.getAmountIn(
|
|
1070
|
-
amountOutDebtAdjusted,
|
|
1071
|
-
debtIReserveIn,
|
|
1072
|
-
debtIReserveOut,
|
|
1073
|
-
);
|
|
1074
|
-
|
|
1075
|
-
amountInDebt = this.applyFeeForBuy(amountInDebt, fee);
|
|
1076
|
-
if (amountOutDebt > debtReserveOut || a > colReserveOut) {
|
|
1077
|
-
return 0n;
|
|
1078
|
-
}
|
|
1079
|
-
if (amountOutDebt > borrowable || a > withdrawable) {
|
|
1080
|
-
return 0n;
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
if (amountInCollateral > 0) {
|
|
1085
|
-
let reservesRatioValid = swap0to1
|
|
1086
|
-
? this.verifyToken1Reserves(
|
|
1087
|
-
colReserveIn + amountInCollateral,
|
|
1088
|
-
colReserveOut - amountOutCollateral,
|
|
1089
|
-
centerPrice,
|
|
1090
|
-
)
|
|
1091
|
-
: this.verifyToken0Reserves(
|
|
1092
|
-
colReserveOut - amountOutCollateral,
|
|
1093
|
-
colReserveIn + amountInCollateral,
|
|
1094
|
-
centerPrice,
|
|
1095
|
-
);
|
|
1096
|
-
if (!reservesRatioValid) {
|
|
1097
|
-
return 0n;
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
if (amountInDebt > 0) {
|
|
1101
|
-
let reservesRatioValid = swap0to1
|
|
1102
|
-
? this.verifyToken1Reserves(
|
|
1103
|
-
debtReserveIn + amountInDebt,
|
|
1104
|
-
debtReserveOut - amountOutDebt,
|
|
1105
|
-
centerPrice,
|
|
1106
|
-
)
|
|
1107
|
-
: this.verifyToken0Reserves(
|
|
1108
|
-
debtReserveOut - amountOutDebt,
|
|
1109
|
-
debtReserveIn + amountInDebt,
|
|
1110
|
-
centerPrice,
|
|
1111
|
-
);
|
|
1112
|
-
if (!reservesRatioValid) {
|
|
1113
|
-
return 0n;
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
|
-
let oldPrice: bigint;
|
|
1118
|
-
let newPrice: bigint;
|
|
1119
|
-
const SCALE = BigInt(1e27);
|
|
1120
|
-
|
|
1121
|
-
// from whatever pool higher amount of swap is routing we are taking that as final price, does not matter much because both pools final price should be same
|
|
1122
|
-
if (amountOutCollateral > amountOutDebt) {
|
|
1123
|
-
// new pool price from col pool
|
|
1124
|
-
oldPrice = swap0to1
|
|
1125
|
-
? (colIReserveOut * SCALE) / colIReserveIn
|
|
1126
|
-
: (colIReserveIn * SCALE) / colIReserveOut;
|
|
1127
|
-
newPrice = swap0to1
|
|
1128
|
-
? ((colIReserveOut - amountOutCollateral) * SCALE) /
|
|
1129
|
-
(colIReserveIn + amountInCollateral)
|
|
1130
|
-
: ((colIReserveIn + amountInCollateral) * SCALE) /
|
|
1131
|
-
(colIReserveOut - amountOutCollateral);
|
|
1132
|
-
} else {
|
|
1133
|
-
// new pool price from debt pool
|
|
1134
|
-
oldPrice = swap0to1
|
|
1135
|
-
? (debtIReserveOut * SCALE) / debtIReserveIn
|
|
1136
|
-
: (debtIReserveIn * SCALE) / debtIReserveOut;
|
|
1137
|
-
newPrice = swap0to1
|
|
1138
|
-
? ((debtIReserveOut - amountOutDebt) * SCALE) /
|
|
1139
|
-
(debtIReserveIn + amountInDebt)
|
|
1140
|
-
: ((debtIReserveIn + amountInDebt) * SCALE) /
|
|
1141
|
-
(debtIReserveOut - amountOutDebt);
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
const MAX_PRICE_DIFF = BigInt(5); // 5%
|
|
1145
|
-
if (
|
|
1146
|
-
this.abs(oldPrice - newPrice) >
|
|
1147
|
-
(oldPrice / BigInt(100)) * MAX_PRICE_DIFF
|
|
1148
|
-
) {
|
|
1149
|
-
// if price diff is > 5% then swap would revert.
|
|
1150
|
-
return 0n;
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
|
-
const totalAmountIn = amountInCollateral + amountInDebt;
|
|
1154
|
-
|
|
1155
|
-
return totalAmountIn;
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
private applyFeeForBuy(amount: bigint, fee: bigint): bigint {
|
|
1159
|
-
return (amount * 10n ** 6n) / (10n ** 6n - fee);
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
private applyFeeForSell(amount: bigint, fee: bigint): bigint {
|
|
1163
|
-
return (amount * (10n ** 6n - fee)) / 10n ** 6n;
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
private abs(value: bigint): bigint {
|
|
1167
|
-
return value < 0 ? -value : value;
|
|
1168
|
-
}
|
|
1169
|
-
}
|