@mento-protocol/mento-sdk 3.2.6 → 3.2.7
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/package.json +7 -1
- package/dist/cache/routes.d.ts +0 -13
- package/dist/cache/routes.js +0 -14649
- package/dist/cache/tokens.d.ts +0 -68
- package/dist/cache/tokens.js +0 -488
- package/dist/core/abis/activePool.d.ts +0 -2
- package/dist/core/abis/activePool.js +0 -14
- package/dist/core/abis/addressesRegistry.d.ts +0 -2
- package/dist/core/abis/addressesRegistry.js +0 -26
- package/dist/core/abis/bipoolmanager.d.ts +0 -34
- package/dist/core/abis/bipoolmanager.js +0 -72
- package/dist/core/abis/borrowerOperations.d.ts +0 -9
- package/dist/core/abis/borrowerOperations.js +0 -89
- package/dist/core/abis/breakerbox.d.ts +0 -13
- package/dist/core/abis/breakerbox.js +0 -8
- package/dist/core/abis/broker.d.ts +0 -2
- package/dist/core/abis/broker.js +0 -9
- package/dist/core/abis/erc20.d.ts +0 -9
- package/dist/core/abis/erc20.js +0 -21
- package/dist/core/abis/fpmm.d.ts +0 -270
- package/dist/core/abis/fpmm.js +0 -49
- package/dist/core/abis/fpmmFactory.d.ts +0 -85
- package/dist/core/abis/fpmmFactory.js +0 -26
- package/dist/core/abis/hintHelpers.d.ts +0 -2
- package/dist/core/abis/hintHelpers.js +0 -14
- package/dist/core/abis/index.d.ts +0 -22
- package/dist/core/abis/index.js +0 -38
- package/dist/core/abis/liquidityStrategy.d.ts +0 -132
- package/dist/core/abis/liquidityStrategy.js +0 -10
- package/dist/core/abis/multiTroveGetter.d.ts +0 -8
- package/dist/core/abis/multiTroveGetter.js +0 -15
- package/dist/core/abis/priceFeed.d.ts +0 -7
- package/dist/core/abis/priceFeed.js +0 -16
- package/dist/core/abis/pricingmodule.d.ts +0 -2
- package/dist/core/abis/pricingmodule.js +0 -6
- package/dist/core/abis/reserve.d.ts +0 -3
- package/dist/core/abis/reserve.js +0 -18
- package/dist/core/abis/router.d.ts +0 -521
- package/dist/core/abis/router.js +0 -45
- package/dist/core/abis/sortedTroves.d.ts +0 -2
- package/dist/core/abis/sortedTroves.js +0 -15
- package/dist/core/abis/systemParams.d.ts +0 -2
- package/dist/core/abis/systemParams.js +0 -14
- package/dist/core/abis/troveManager.d.ts +0 -2
- package/dist/core/abis/troveManager.js +0 -27
- package/dist/core/abis/troveNFT.d.ts +0 -2
- package/dist/core/abis/troveNFT.js +0 -9
- package/dist/core/abis/virtualPool.d.ts +0 -50
- package/dist/core/abis/virtualPool.js +0 -11
- package/dist/core/abis/virtualPoolFactory.d.ts +0 -59
- package/dist/core/abis/virtualPoolFactory.js +0 -17
- package/dist/core/constants/addresses.d.ts +0 -18
- package/dist/core/constants/addresses.js +0 -113
- package/dist/core/constants/borrowConstants.d.ts +0 -10
- package/dist/core/constants/borrowConstants.js +0 -16
- package/dist/core/constants/borrowRegistries.d.ts +0 -7
- package/dist/core/constants/borrowRegistries.js +0 -34
- package/dist/core/constants/chainId.d.ts +0 -7
- package/dist/core/constants/chainId.js +0 -11
- package/dist/core/constants/contractNames.d.ts +0 -21
- package/dist/core/constants/contractNames.js +0 -24
- package/dist/core/constants/index.d.ts +0 -6
- package/dist/core/constants/index.js +0 -22
- package/dist/core/errors/base.d.ts +0 -8
- package/dist/core/errors/base.js +0 -17
- package/dist/core/errors/index.d.ts +0 -4
- package/dist/core/errors/index.js +0 -20
- package/dist/core/errors/oracle.d.ts +0 -9
- package/dist/core/errors/oracle.js +0 -15
- package/dist/core/errors/router.d.ts +0 -14
- package/dist/core/errors/router.js +0 -24
- package/dist/core/types/borrow.d.ts +0 -87
- package/dist/core/types/borrow.js +0 -3
- package/dist/core/types/contractAddresses.d.ts +0 -42
- package/dist/core/types/contractAddresses.js +0 -3
- package/dist/core/types/index.d.ts +0 -10
- package/dist/core/types/index.js +0 -26
- package/dist/core/types/liquidity.d.ts +0 -194
- package/dist/core/types/liquidity.js +0 -3
- package/dist/core/types/pool.d.ts +0 -208
- package/dist/core/types/pool.js +0 -14
- package/dist/core/types/provider.d.ts +0 -45
- package/dist/core/types/provider.js +0 -3
- package/dist/core/types/route.d.ts +0 -62
- package/dist/core/types/route.js +0 -3
- package/dist/core/types/token.d.ts +0 -21
- package/dist/core/types/token.js +0 -3
- package/dist/core/types/tradingLimits.d.ts +0 -91
- package/dist/core/types/tradingLimits.js +0 -3
- package/dist/core/types/tradingMode.d.ts +0 -24
- package/dist/core/types/tradingMode.js +0 -31
- package/dist/core/types/transaction.d.ts +0 -45
- package/dist/core/types/transaction.js +0 -3
- package/dist/esm/cache/routes.js +0 -14644
- package/dist/esm/cache/tokens.js +0 -480
- package/dist/esm/core/abis/activePool.js +0 -10
- package/dist/esm/core/abis/addressesRegistry.js +0 -22
- package/dist/esm/core/abis/bipoolmanager.js +0 -68
- package/dist/esm/core/abis/borrowerOperations.js +0 -85
- package/dist/esm/core/abis/breakerbox.js +0 -4
- package/dist/esm/core/abis/broker.js +0 -5
- package/dist/esm/core/abis/erc20.js +0 -17
- package/dist/esm/core/abis/fpmm.js +0 -45
- package/dist/esm/core/abis/fpmmFactory.js +0 -22
- package/dist/esm/core/abis/hintHelpers.js +0 -10
- package/dist/esm/core/abis/index.js +0 -21
- package/dist/esm/core/abis/liquidityStrategy.js +0 -6
- package/dist/esm/core/abis/multiTroveGetter.js +0 -11
- package/dist/esm/core/abis/priceFeed.js +0 -12
- package/dist/esm/core/abis/pricingmodule.js +0 -2
- package/dist/esm/core/abis/reserve.js +0 -14
- package/dist/esm/core/abis/router.js +0 -41
- package/dist/esm/core/abis/sortedTroves.js +0 -11
- package/dist/esm/core/abis/systemParams.js +0 -10
- package/dist/esm/core/abis/troveManager.js +0 -23
- package/dist/esm/core/abis/troveNFT.js +0 -5
- package/dist/esm/core/abis/virtualPool.js +0 -7
- package/dist/esm/core/abis/virtualPoolFactory.js +0 -13
- package/dist/esm/core/constants/addresses.js +0 -107
- package/dist/esm/core/constants/borrowConstants.js +0 -12
- package/dist/esm/core/constants/borrowRegistries.js +0 -29
- package/dist/esm/core/constants/chainId.js +0 -7
- package/dist/esm/core/constants/contractNames.js +0 -20
- package/dist/esm/core/constants/index.js +0 -5
- package/dist/esm/core/errors/base.js +0 -12
- package/dist/esm/core/errors/index.js +0 -3
- package/dist/esm/core/errors/oracle.js +0 -10
- package/dist/esm/core/errors/router.js +0 -18
- package/dist/esm/core/types/borrow.js +0 -1
- package/dist/esm/core/types/contractAddresses.js +0 -1
- package/dist/esm/core/types/index.js +0 -9
- package/dist/esm/core/types/liquidity.js +0 -1
- package/dist/esm/core/types/pool.js +0 -10
- package/dist/esm/core/types/provider.js +0 -1
- package/dist/esm/core/types/route.js +0 -1
- package/dist/esm/core/types/token.js +0 -1
- package/dist/esm/core/types/tradingLimits.js +0 -1
- package/dist/esm/core/types/tradingMode.js +0 -26
- package/dist/esm/core/types/transaction.js +0 -1
- package/dist/esm/index.js +0 -139
- package/dist/esm/package.json +0 -1
- package/dist/esm/services/borrow/BorrowService.js +0 -455
- package/dist/esm/services/borrow/borrowHelpers.js +0 -3
- package/dist/esm/services/borrow/borrowMath.js +0 -127
- package/dist/esm/services/borrow/index.js +0 -3
- package/dist/esm/services/borrow/internal/borrowApprovalService.js +0 -48
- package/dist/esm/services/borrow/internal/borrowContextStore.js +0 -35
- package/dist/esm/services/borrow/internal/borrowErc20.js +0 -38
- package/dist/esm/services/borrow/internal/borrowHints.js +0 -27
- package/dist/esm/services/borrow/internal/borrowPositionParser.js +0 -82
- package/dist/esm/services/borrow/internal/borrowReadService.js +0 -271
- package/dist/esm/services/borrow/internal/borrowRegistryReader.js +0 -108
- package/dist/esm/services/borrow/internal/borrowTransactionService.js +0 -271
- package/dist/esm/services/borrow/internal/borrowTypes.js +0 -1
- package/dist/esm/services/borrow/internal/borrowValidation.js +0 -89
- package/dist/esm/services/index.js +0 -8
- package/dist/esm/services/liquidity/LiquidityService.js +0 -163
- package/dist/esm/services/liquidity/basicLiquidity.js +0 -162
- package/dist/esm/services/liquidity/index.js +0 -1
- package/dist/esm/services/liquidity/liquidityHelpers.js +0 -95
- package/dist/esm/services/liquidity/rebalance.js +0 -59
- package/dist/esm/services/liquidity/zapHelpers.js +0 -120
- package/dist/esm/services/liquidity/zapIn.js +0 -112
- package/dist/esm/services/liquidity/zapOut.js +0 -248
- package/dist/esm/services/pools/PoolService.js +0 -204
- package/dist/esm/services/pools/index.js +0 -1
- package/dist/esm/services/pools/poolDetails.js +0 -209
- package/dist/esm/services/pools/poolDiscovery.js +0 -112
- package/dist/esm/services/pools/rebalancePreview.js +0 -181
- package/dist/esm/services/quotes/QuoteService.js +0 -85
- package/dist/esm/services/quotes/index.js +0 -1
- package/dist/esm/services/routes/RouteService.js +0 -268
- package/dist/esm/services/routes/index.js +0 -1
- package/dist/esm/services/swap/SwapService.js +0 -247
- package/dist/esm/services/swap/index.js +0 -1
- package/dist/esm/services/tokens/index.js +0 -1
- package/dist/esm/services/tokens/tokenService.js +0 -285
- package/dist/esm/services/trading/TradingLimitsService.js +0 -154
- package/dist/esm/services/trading/TradingService.js +0 -222
- package/dist/esm/services/trading/index.js +0 -2
- package/dist/esm/utils/chainConfig.js +0 -118
- package/dist/esm/utils/costUtils.js +0 -56
- package/dist/esm/utils/deadline.js +0 -22
- package/dist/esm/utils/index.js +0 -9
- package/dist/esm/utils/multicall.js +0 -47
- package/dist/esm/utils/pathEncoder.js +0 -69
- package/dist/esm/utils/rateFeed.js +0 -23
- package/dist/esm/utils/retry.js +0 -24
- package/dist/esm/utils/routeUtils.js +0 -361
- package/dist/esm/utils/routes.js +0 -2
- package/dist/esm/utils/sortUtils.js +0 -33
- package/dist/esm/utils/tokens.js +0 -2
- package/dist/esm/utils/tradingLimits.js +0 -163
- package/dist/esm/utils/validation.js +0 -30
- package/dist/index.d.ts +0 -101
- package/dist/index.js +0 -158
- package/dist/services/borrow/BorrowService.d.ts +0 -381
- package/dist/services/borrow/BorrowService.js +0 -460
- package/dist/services/borrow/borrowHelpers.d.ts +0 -4
- package/dist/services/borrow/borrowHelpers.js +0 -13
- package/dist/services/borrow/borrowMath.d.ts +0 -21
- package/dist/services/borrow/borrowMath.js +0 -137
- package/dist/services/borrow/index.d.ts +0 -4
- package/dist/services/borrow/index.js +0 -20
- package/dist/services/borrow/internal/borrowApprovalService.d.ts +0 -14
- package/dist/services/borrow/internal/borrowApprovalService.js +0 -53
- package/dist/services/borrow/internal/borrowContextStore.d.ts +0 -11
- package/dist/services/borrow/internal/borrowContextStore.js +0 -40
- package/dist/services/borrow/internal/borrowErc20.d.ts +0 -5
- package/dist/services/borrow/internal/borrowErc20.js +0 -43
- package/dist/services/borrow/internal/borrowHints.d.ts +0 -7
- package/dist/services/borrow/internal/borrowHints.js +0 -31
- package/dist/services/borrow/internal/borrowPositionParser.d.ts +0 -4
- package/dist/services/borrow/internal/borrowPositionParser.js +0 -87
- package/dist/services/borrow/internal/borrowReadService.d.ts +0 -31
- package/dist/services/borrow/internal/borrowReadService.js +0 -276
- package/dist/services/borrow/internal/borrowRegistryReader.d.ts +0 -5
- package/dist/services/borrow/internal/borrowRegistryReader.js +0 -113
- package/dist/services/borrow/internal/borrowTransactionService.d.ts +0 -23
- package/dist/services/borrow/internal/borrowTransactionService.js +0 -276
- package/dist/services/borrow/internal/borrowTypes.d.ts +0 -15
- package/dist/services/borrow/internal/borrowTypes.js +0 -3
- package/dist/services/borrow/internal/borrowValidation.d.ts +0 -14
- package/dist/services/borrow/internal/borrowValidation.js +0 -104
- package/dist/services/index.d.ts +0 -9
- package/dist/services/index.js +0 -25
- package/dist/services/liquidity/LiquidityService.d.ts +0 -139
- package/dist/services/liquidity/LiquidityService.js +0 -168
- package/dist/services/liquidity/basicLiquidity.d.ts +0 -11
- package/dist/services/liquidity/basicLiquidity.js +0 -172
- package/dist/services/liquidity/index.d.ts +0 -2
- package/dist/services/liquidity/index.js +0 -18
- package/dist/services/liquidity/liquidityHelpers.d.ts +0 -19
- package/dist/services/liquidity/liquidityHelpers.js +0 -104
- package/dist/services/liquidity/rebalance.d.ts +0 -6
- package/dist/services/liquidity/rebalance.js +0 -64
- package/dist/services/liquidity/zapHelpers.d.ts +0 -66
- package/dist/services/liquidity/zapHelpers.js +0 -129
- package/dist/services/liquidity/zapIn.d.ts +0 -18
- package/dist/services/liquidity/zapIn.js +0 -119
- package/dist/services/liquidity/zapOut.d.ts +0 -9
- package/dist/services/liquidity/zapOut.js +0 -255
- package/dist/services/pools/PoolService.d.ts +0 -69
- package/dist/services/pools/PoolService.js +0 -209
- package/dist/services/pools/index.d.ts +0 -2
- package/dist/services/pools/index.js +0 -18
- package/dist/services/pools/poolDetails.d.ts +0 -13
- package/dist/services/pools/poolDetails.js +0 -216
- package/dist/services/pools/poolDiscovery.d.ts +0 -12
- package/dist/services/pools/poolDiscovery.js +0 -117
- package/dist/services/pools/rebalancePreview.d.ts +0 -5
- package/dist/services/pools/rebalancePreview.js +0 -186
- package/dist/services/quotes/QuoteService.d.ts +0 -51
- package/dist/services/quotes/QuoteService.js +0 -91
- package/dist/services/quotes/index.d.ts +0 -2
- package/dist/services/quotes/index.js +0 -18
- package/dist/services/routes/RouteService.d.ts +0 -117
- package/dist/services/routes/RouteService.js +0 -306
- package/dist/services/routes/index.d.ts +0 -2
- package/dist/services/routes/index.js +0 -18
- package/dist/services/swap/SwapService.d.ts +0 -198
- package/dist/services/swap/SwapService.js +0 -252
- package/dist/services/swap/index.d.ts +0 -2
- package/dist/services/swap/index.js +0 -18
- package/dist/services/tokens/index.d.ts +0 -2
- package/dist/services/tokens/index.js +0 -18
- package/dist/services/tokens/tokenService.d.ts +0 -55
- package/dist/services/tokens/tokenService.js +0 -290
- package/dist/services/trading/TradingLimitsService.d.ts +0 -38
- package/dist/services/trading/TradingLimitsService.js +0 -159
- package/dist/services/trading/TradingService.d.ts +0 -115
- package/dist/services/trading/TradingService.js +0 -227
- package/dist/services/trading/index.d.ts +0 -3
- package/dist/services/trading/index.js +0 -19
- package/dist/utils/chainConfig.d.ts +0 -16
- package/dist/utils/chainConfig.js +0 -123
- package/dist/utils/costUtils.d.ts +0 -12
- package/dist/utils/costUtils.js +0 -60
- package/dist/utils/deadline.d.ts +0 -21
- package/dist/utils/deadline.js +0 -26
- package/dist/utils/index.d.ts +0 -10
- package/dist/utils/index.js +0 -26
- package/dist/utils/multicall.d.ts +0 -30
- package/dist/utils/multicall.js +0 -52
- package/dist/utils/pathEncoder.d.ts +0 -34
- package/dist/utils/pathEncoder.js +0 -73
- package/dist/utils/rateFeed.d.ts +0 -18
- package/dist/utils/rateFeed.js +0 -27
- package/dist/utils/retry.d.ts +0 -12
- package/dist/utils/retry.js +0 -28
- package/dist/utils/routeUtils.d.ts +0 -295
- package/dist/utils/routeUtils.js +0 -371
- package/dist/utils/routes.d.ts +0 -3
- package/dist/utils/routes.js +0 -8
- package/dist/utils/sortUtils.d.ts +0 -24
- package/dist/utils/sortUtils.js +0 -39
- package/dist/utils/tokens.d.ts +0 -2
- package/dist/utils/tokens.js +0 -13
- package/dist/utils/tradingLimits.d.ts +0 -41
- package/dist/utils/tradingLimits.js +0 -171
- package/dist/utils/validation.d.ts +0 -19
- package/dist/utils/validation.js +0 -34
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Pool, PoolDetails, PoolRebalancePreview } from '../../core/types';
|
|
2
|
-
import { PublicClient } from 'viem';
|
|
3
|
-
/**
|
|
4
|
-
* Result of pool discovery including any warnings from failed factories
|
|
5
|
-
*/
|
|
6
|
-
export interface PoolDiscoveryResult {
|
|
7
|
-
pools: Pool[];
|
|
8
|
-
warnings: string[];
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Service for discovering liquidity pools in the Mento protocol.
|
|
12
|
-
* Aggregates pools from multiple factory contracts (FPMM and VirtualPool).
|
|
13
|
-
*/
|
|
14
|
-
export declare class PoolService {
|
|
15
|
-
private publicClient;
|
|
16
|
-
private chainId;
|
|
17
|
-
private poolsCache;
|
|
18
|
-
private discoveryWarnings;
|
|
19
|
-
private poolsPromise;
|
|
20
|
-
private poolDetailsCache;
|
|
21
|
-
private poolDetailPromises;
|
|
22
|
-
constructor(publicClient: PublicClient, chainId: number);
|
|
23
|
-
/**
|
|
24
|
-
* Returns any warnings from the last pool discovery operation.
|
|
25
|
-
* Useful for debugging when some factories fail but others succeed.
|
|
26
|
-
*/
|
|
27
|
-
getDiscoveryWarnings(): string[];
|
|
28
|
-
/**
|
|
29
|
-
* Fetches all pools available in the protocol from both FPMM and Virtual pool factories
|
|
30
|
-
* Results are cached in memory for the service instance lifetime
|
|
31
|
-
*
|
|
32
|
-
* @returns Array of all pools available in the protocol
|
|
33
|
-
* @throws {Error} If no pools can be discovered from any factory
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```typescript
|
|
37
|
-
* const pools = await poolService.getPools()
|
|
38
|
-
* console.log(`Found ${pools.length} pools`)
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
getPools(): Promise<Pool[]>;
|
|
42
|
-
private loadPools;
|
|
43
|
-
/**
|
|
44
|
-
* Fetches enriched on-chain details for a specific pool by address.
|
|
45
|
-
* Resolves the pool type from the discovery cache, then fetches
|
|
46
|
-
* pool-type-specific data (pricing, fees, rebalancing for FPMM; reserves and spread for Virtual).
|
|
47
|
-
*
|
|
48
|
-
* @param poolAddr - The deployed pool contract address
|
|
49
|
-
* @returns Enriched pool details (FPMMPoolDetails or VirtualPoolDetails)
|
|
50
|
-
* @throws {Error} If the pool address is not found in any known factory
|
|
51
|
-
* @throws {Error} If on-chain calls fail
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* const details = await poolService.getPoolDetails('0x...')
|
|
56
|
-
* if (details.poolType === 'FPMM') {
|
|
57
|
-
* console.log(details.pricing.oraclePrice)
|
|
58
|
-
* console.log(details.rebalancing.inBand)
|
|
59
|
-
* } else {
|
|
60
|
-
* console.log(details.spreadPercent)
|
|
61
|
-
* }
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
getPoolDetails(poolAddr: string): Promise<PoolDetails>;
|
|
65
|
-
getPoolRebalancePreview(poolAddr: string): Promise<PoolRebalancePreview | null>;
|
|
66
|
-
getPoolRebalancePreviewBatch(poolAddresses?: string[]): Promise<Array<PoolRebalancePreview | null>>;
|
|
67
|
-
getPoolDetailsBatch(poolAddresses?: string[]): Promise<PoolDetails[]>;
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=PoolService.d.ts.map
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PoolService = void 0;
|
|
4
|
-
const types_1 = require("../../core/types");
|
|
5
|
-
const poolDiscovery_1 = require("./poolDiscovery");
|
|
6
|
-
const poolDetails_1 = require("./poolDetails");
|
|
7
|
-
const rebalancePreview_1 = require("./rebalancePreview");
|
|
8
|
-
/**
|
|
9
|
-
* Service for discovering liquidity pools in the Mento protocol.
|
|
10
|
-
* Aggregates pools from multiple factory contracts (FPMM and VirtualPool).
|
|
11
|
-
*/
|
|
12
|
-
class PoolService {
|
|
13
|
-
constructor(publicClient, chainId) {
|
|
14
|
-
this.publicClient = publicClient;
|
|
15
|
-
this.chainId = chainId;
|
|
16
|
-
this.poolsCache = null;
|
|
17
|
-
this.discoveryWarnings = [];
|
|
18
|
-
this.poolsPromise = null;
|
|
19
|
-
this.poolDetailsCache = new Map();
|
|
20
|
-
this.poolDetailPromises = new Map();
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Returns any warnings from the last pool discovery operation.
|
|
24
|
-
* Useful for debugging when some factories fail but others succeed.
|
|
25
|
-
*/
|
|
26
|
-
getDiscoveryWarnings() {
|
|
27
|
-
return [...this.discoveryWarnings];
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Fetches all pools available in the protocol from both FPMM and Virtual pool factories
|
|
31
|
-
* Results are cached in memory for the service instance lifetime
|
|
32
|
-
*
|
|
33
|
-
* @returns Array of all pools available in the protocol
|
|
34
|
-
* @throws {Error} If no pools can be discovered from any factory
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* const pools = await poolService.getPools()
|
|
39
|
-
* console.log(`Found ${pools.length} pools`)
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
async getPools() {
|
|
43
|
-
if (this.poolsCache) {
|
|
44
|
-
return this.poolsCache;
|
|
45
|
-
}
|
|
46
|
-
if (this.poolsPromise) {
|
|
47
|
-
return this.poolsPromise;
|
|
48
|
-
}
|
|
49
|
-
this.poolsPromise = this.loadPools();
|
|
50
|
-
try {
|
|
51
|
-
return await this.poolsPromise;
|
|
52
|
-
}
|
|
53
|
-
finally {
|
|
54
|
-
this.poolsPromise = null;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
async loadPools() {
|
|
58
|
-
const warnings = [];
|
|
59
|
-
const settled = await Promise.allSettled([
|
|
60
|
-
(0, poolDiscovery_1.fetchFPMMPools)(this.publicClient, this.chainId),
|
|
61
|
-
(0, poolDiscovery_1.fetchVirtualPools)(this.publicClient, this.chainId),
|
|
62
|
-
]);
|
|
63
|
-
const pools = [];
|
|
64
|
-
const [fpmmResult, virtualResult] = settled;
|
|
65
|
-
if (fpmmResult.status === 'fulfilled') {
|
|
66
|
-
pools.push(...fpmmResult.value);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
warnings.push(`Failed to fetch FPMM pools: ${fpmmResult.reason instanceof Error ? fpmmResult.reason.message : String(fpmmResult.reason)}`);
|
|
70
|
-
}
|
|
71
|
-
if (virtualResult.status === 'fulfilled') {
|
|
72
|
-
pools.push(...virtualResult.value);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
warnings.push(`Failed to fetch Virtual pools: ${virtualResult.reason instanceof Error ? virtualResult.reason.message : String(virtualResult.reason)}`);
|
|
76
|
-
}
|
|
77
|
-
this.discoveryWarnings = warnings;
|
|
78
|
-
// Only throw if NO pools were discovered from any factory
|
|
79
|
-
if (pools.length === 0) {
|
|
80
|
-
throw new Error('Failed to discover any pools from any factory. ' +
|
|
81
|
-
'All pool factory queries failed. Check network connectivity and RPC endpoint.');
|
|
82
|
-
}
|
|
83
|
-
this.poolsCache = pools;
|
|
84
|
-
return pools;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Fetches enriched on-chain details for a specific pool by address.
|
|
88
|
-
* Resolves the pool type from the discovery cache, then fetches
|
|
89
|
-
* pool-type-specific data (pricing, fees, rebalancing for FPMM; reserves and spread for Virtual).
|
|
90
|
-
*
|
|
91
|
-
* @param poolAddr - The deployed pool contract address
|
|
92
|
-
* @returns Enriched pool details (FPMMPoolDetails or VirtualPoolDetails)
|
|
93
|
-
* @throws {Error} If the pool address is not found in any known factory
|
|
94
|
-
* @throws {Error} If on-chain calls fail
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* ```typescript
|
|
98
|
-
* const details = await poolService.getPoolDetails('0x...')
|
|
99
|
-
* if (details.poolType === 'FPMM') {
|
|
100
|
-
* console.log(details.pricing.oraclePrice)
|
|
101
|
-
* console.log(details.rebalancing.inBand)
|
|
102
|
-
* } else {
|
|
103
|
-
* console.log(details.spreadPercent)
|
|
104
|
-
* }
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
async getPoolDetails(poolAddr) {
|
|
108
|
-
const [details] = await this.getPoolDetailsBatch([poolAddr]);
|
|
109
|
-
return details;
|
|
110
|
-
}
|
|
111
|
-
async getPoolRebalancePreview(poolAddr) {
|
|
112
|
-
const details = await this.getPoolDetails(poolAddr);
|
|
113
|
-
return (0, rebalancePreview_1.fetchPoolRebalancePreview)(this.publicClient, details);
|
|
114
|
-
}
|
|
115
|
-
async getPoolRebalancePreviewBatch(poolAddresses) {
|
|
116
|
-
const details = await this.getPoolDetailsBatch(poolAddresses);
|
|
117
|
-
return (0, rebalancePreview_1.fetchPoolRebalancePreviewBatch)(this.publicClient, details);
|
|
118
|
-
}
|
|
119
|
-
async getPoolDetailsBatch(poolAddresses) {
|
|
120
|
-
const pools = await this.getPools();
|
|
121
|
-
const targets = poolAddresses
|
|
122
|
-
? poolAddresses.map((poolAddress) => {
|
|
123
|
-
const pool = pools.find((candidate) => candidate.poolAddr.toLowerCase() === poolAddress.toLowerCase());
|
|
124
|
-
if (!pool) {
|
|
125
|
-
throw new Error(`Pool not found: ${poolAddress}. Ensure the address is a valid pool discovered by getPools().`);
|
|
126
|
-
}
|
|
127
|
-
return pool;
|
|
128
|
-
})
|
|
129
|
-
: pools;
|
|
130
|
-
const results = new Array(targets.length);
|
|
131
|
-
const pendingResults = [];
|
|
132
|
-
const missingTargets = [];
|
|
133
|
-
for (const [index, pool] of targets.entries()) {
|
|
134
|
-
const key = pool.poolAddr.toLowerCase();
|
|
135
|
-
const cached = this.poolDetailsCache.get(key);
|
|
136
|
-
if (cached) {
|
|
137
|
-
results[index] = cached;
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
const inFlight = this.poolDetailPromises.get(key);
|
|
141
|
-
if (inFlight) {
|
|
142
|
-
pendingResults.push(inFlight.then((detail) => {
|
|
143
|
-
results[index] = detail;
|
|
144
|
-
}));
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
missingTargets.push({ pool, index, key });
|
|
148
|
-
}
|
|
149
|
-
if (missingTargets.length > 0) {
|
|
150
|
-
const grouped = {
|
|
151
|
-
fpmm: missingTargets.filter(({ pool }) => pool.poolType === types_1.PoolType.FPMM),
|
|
152
|
-
virtual: missingTargets.filter(({ pool }) => pool.poolType !== types_1.PoolType.FPMM),
|
|
153
|
-
};
|
|
154
|
-
const createdPromises = new Map();
|
|
155
|
-
const createdPendingResults = [];
|
|
156
|
-
for (const target of missingTargets) {
|
|
157
|
-
const deferred = createDeferred();
|
|
158
|
-
this.poolDetailPromises.set(target.key, deferred.promise);
|
|
159
|
-
createdPromises.set(target.key, deferred);
|
|
160
|
-
const pendingResult = deferred.promise.then((detail) => {
|
|
161
|
-
results[target.index] = detail;
|
|
162
|
-
});
|
|
163
|
-
pendingResults.push(pendingResult);
|
|
164
|
-
createdPendingResults.push(pendingResult);
|
|
165
|
-
}
|
|
166
|
-
try {
|
|
167
|
-
const [fpmmDetails, virtualDetails] = await Promise.all([
|
|
168
|
-
(0, poolDetails_1.fetchFPMMPoolDetailsBatch)(this.publicClient, this.chainId, grouped.fpmm.map(({ pool }) => pool)),
|
|
169
|
-
(0, poolDetails_1.fetchVirtualPoolDetailsBatch)(this.publicClient, grouped.virtual.map(({ pool }) => pool)),
|
|
170
|
-
]);
|
|
171
|
-
for (const [groupIndex, detail] of fpmmDetails.entries()) {
|
|
172
|
-
const target = grouped.fpmm[groupIndex];
|
|
173
|
-
this.poolDetailsCache.set(target.key, detail);
|
|
174
|
-
createdPromises.get(target.key)?.resolve(detail);
|
|
175
|
-
}
|
|
176
|
-
for (const [groupIndex, detail] of virtualDetails.entries()) {
|
|
177
|
-
const target = grouped.virtual[groupIndex];
|
|
178
|
-
this.poolDetailsCache.set(target.key, detail);
|
|
179
|
-
createdPromises.get(target.key)?.resolve(detail);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
catch (error) {
|
|
183
|
-
for (const target of missingTargets) {
|
|
184
|
-
createdPromises.get(target.key)?.reject(error);
|
|
185
|
-
}
|
|
186
|
-
await Promise.allSettled(createdPendingResults);
|
|
187
|
-
throw error;
|
|
188
|
-
}
|
|
189
|
-
finally {
|
|
190
|
-
for (const target of missingTargets) {
|
|
191
|
-
this.poolDetailPromises.delete(target.key);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
await Promise.all(pendingResults);
|
|
196
|
-
return results;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
exports.PoolService = PoolService;
|
|
200
|
-
function createDeferred() {
|
|
201
|
-
let resolve;
|
|
202
|
-
let reject;
|
|
203
|
-
const promise = new Promise((resolvePromise, rejectPromise) => {
|
|
204
|
-
resolve = resolvePromise;
|
|
205
|
-
reject = rejectPromise;
|
|
206
|
-
});
|
|
207
|
-
return { promise, resolve, reject };
|
|
208
|
-
}
|
|
209
|
-
//# sourceMappingURL=PoolService.js.map
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./PoolService"), exports);
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Pool, FPMMPoolDetails, VirtualPoolDetails } from '../../core/types';
|
|
2
|
-
import { PublicClient } from 'viem';
|
|
3
|
-
/**
|
|
4
|
-
* Fetches enriched details for an FPMM pool
|
|
5
|
-
*/
|
|
6
|
-
export declare function fetchFPMMPoolDetails(publicClient: PublicClient, chainId: number, pool: Pool): Promise<FPMMPoolDetails>;
|
|
7
|
-
export declare function fetchFPMMPoolDetailsBatch(publicClient: PublicClient, chainId: number, pools: Pool[]): Promise<FPMMPoolDetails[]>;
|
|
8
|
-
/**
|
|
9
|
-
* Fetches enriched details for a Virtual pool
|
|
10
|
-
*/
|
|
11
|
-
export declare function fetchVirtualPoolDetails(publicClient: PublicClient, pool: Pool): Promise<VirtualPoolDetails>;
|
|
12
|
-
export declare function fetchVirtualPoolDetailsBatch(publicClient: PublicClient, pools: Pool[]): Promise<VirtualPoolDetails[]>;
|
|
13
|
-
//# sourceMappingURL=poolDetails.d.ts.map
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchFPMMPoolDetails = fetchFPMMPoolDetails;
|
|
4
|
-
exports.fetchFPMMPoolDetailsBatch = fetchFPMMPoolDetailsBatch;
|
|
5
|
-
exports.fetchVirtualPoolDetails = fetchVirtualPoolDetails;
|
|
6
|
-
exports.fetchVirtualPoolDetailsBatch = fetchVirtualPoolDetailsBatch;
|
|
7
|
-
const constants_1 = require("../../core/constants");
|
|
8
|
-
const abis_1 = require("../../core/abis");
|
|
9
|
-
const viem_1 = require("viem");
|
|
10
|
-
const multicall_1 = require("../../utils/multicall");
|
|
11
|
-
const FPMM_FIXED_RESULT_COUNT = 8;
|
|
12
|
-
const VIRTUAL_RESULT_COUNT = 3;
|
|
13
|
-
/**
|
|
14
|
-
* Fetches enriched details for an FPMM pool
|
|
15
|
-
*/
|
|
16
|
-
async function fetchFPMMPoolDetails(publicClient, chainId, pool) {
|
|
17
|
-
const [details] = await fetchFPMMPoolDetailsBatch(publicClient, chainId, [pool]);
|
|
18
|
-
return details;
|
|
19
|
-
}
|
|
20
|
-
async function fetchFPMMPoolDetailsBatch(publicClient, chainId, pools) {
|
|
21
|
-
if (pools.length === 0) {
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
24
|
-
const openLiquidityStrategy = getOpenLiquidityStrategy(chainId);
|
|
25
|
-
const contracts = pools.flatMap((pool) => buildFPMMContracts(pool, openLiquidityStrategy));
|
|
26
|
-
const results = await (0, multicall_1.multicall)(publicClient, contracts);
|
|
27
|
-
const strategyCheckCount = openLiquidityStrategy ? 1 : 0;
|
|
28
|
-
const perPoolResultCount = FPMM_FIXED_RESULT_COUNT + strategyCheckCount + 1;
|
|
29
|
-
return pools.map((pool, index) => {
|
|
30
|
-
const offset = index * perPoolResultCount;
|
|
31
|
-
const poolResults = results.slice(offset, offset + perPoolResultCount);
|
|
32
|
-
return parseFPMMPoolDetails(pool, openLiquidityStrategy, poolResults);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function buildFPMMContracts(pool, openLiquidityStrategy) {
|
|
36
|
-
const address = pool.poolAddr;
|
|
37
|
-
return [
|
|
38
|
-
{ address, abi: abis_1.FPMM_ABI, functionName: 'getReserves' },
|
|
39
|
-
{ address, abi: abis_1.FPMM_ABI, functionName: 'decimals0' },
|
|
40
|
-
{ address, abi: abis_1.FPMM_ABI, functionName: 'decimals1' },
|
|
41
|
-
{ address, abi: abis_1.FPMM_ABI, functionName: 'lpFee' },
|
|
42
|
-
{ address, abi: abis_1.FPMM_ABI, functionName: 'protocolFee' },
|
|
43
|
-
{ address, abi: abis_1.FPMM_ABI, functionName: 'rebalanceIncentive' },
|
|
44
|
-
{ address, abi: abis_1.FPMM_ABI, functionName: 'rebalanceThresholdAbove' },
|
|
45
|
-
{ address, abi: abis_1.FPMM_ABI, functionName: 'rebalanceThresholdBelow' },
|
|
46
|
-
...(openLiquidityStrategy
|
|
47
|
-
? [{
|
|
48
|
-
address,
|
|
49
|
-
abi: abis_1.FPMM_ABI,
|
|
50
|
-
functionName: 'liquidityStrategy',
|
|
51
|
-
args: [openLiquidityStrategy],
|
|
52
|
-
}]
|
|
53
|
-
: []),
|
|
54
|
-
{ address, abi: abis_1.FPMM_ABI, functionName: 'getRebalancingState' },
|
|
55
|
-
];
|
|
56
|
-
}
|
|
57
|
-
function parseFPMMPoolDetails(pool, openLiquidityStrategy, results) {
|
|
58
|
-
try {
|
|
59
|
-
const reservesRes = results[0];
|
|
60
|
-
const decimals0Res = results[1];
|
|
61
|
-
const decimals1Res = results[2];
|
|
62
|
-
const lpFeeRes = results[3];
|
|
63
|
-
const protocolFeeRes = results[4];
|
|
64
|
-
const rebalanceIncentiveRes = results[5];
|
|
65
|
-
const thresholdAboveRes = results[6];
|
|
66
|
-
const thresholdBelowRes = results[7];
|
|
67
|
-
if (!reservesRes ||
|
|
68
|
-
!decimals0Res ||
|
|
69
|
-
!decimals1Res ||
|
|
70
|
-
!lpFeeRes ||
|
|
71
|
-
!protocolFeeRes ||
|
|
72
|
-
!rebalanceIncentiveRes ||
|
|
73
|
-
!thresholdAboveRes ||
|
|
74
|
-
!thresholdBelowRes ||
|
|
75
|
-
reservesRes.status === 'failure' ||
|
|
76
|
-
decimals0Res.status === 'failure' ||
|
|
77
|
-
decimals1Res.status === 'failure' ||
|
|
78
|
-
lpFeeRes.status === 'failure' ||
|
|
79
|
-
protocolFeeRes.status === 'failure' ||
|
|
80
|
-
rebalanceIncentiveRes.status === 'failure' ||
|
|
81
|
-
thresholdAboveRes.status === 'failure' ||
|
|
82
|
-
thresholdBelowRes.status === 'failure') {
|
|
83
|
-
throw new Error('One or more core pool reads failed');
|
|
84
|
-
}
|
|
85
|
-
const [reserve0, reserve1, blockTimestampLast] = reservesRes.result;
|
|
86
|
-
const lpFeeBps = lpFeeRes.result;
|
|
87
|
-
const protocolFeeBps = protocolFeeRes.result;
|
|
88
|
-
const rebalanceIncentiveBps = rebalanceIncentiveRes.result;
|
|
89
|
-
const thresholdAboveBps = thresholdAboveRes.result;
|
|
90
|
-
const thresholdBelowBps = thresholdBelowRes.result;
|
|
91
|
-
const strategyCheckCount = openLiquidityStrategy ? 1 : 0;
|
|
92
|
-
const openStrategyResult = strategyCheckCount > 0 ? results[FPMM_FIXED_RESULT_COUNT] : null;
|
|
93
|
-
const liquidityStrategy = openLiquidityStrategy &&
|
|
94
|
-
openStrategyResult?.status === 'success' &&
|
|
95
|
-
openStrategyResult.result === true
|
|
96
|
-
? openLiquidityStrategy
|
|
97
|
-
: null;
|
|
98
|
-
const rebalancingRes = results[FPMM_FIXED_RESULT_COUNT + strategyCheckCount];
|
|
99
|
-
let pricing = null;
|
|
100
|
-
let inBand = null;
|
|
101
|
-
if (rebalancingRes?.status === 'success') {
|
|
102
|
-
const [oraclePriceNum, oraclePriceDen, reservePriceNum, reservePriceDen, reservePriceAboveOraclePrice, rebalanceThreshold, priceDifference,] = rebalancingRes.result;
|
|
103
|
-
pricing = {
|
|
104
|
-
oraclePriceNum,
|
|
105
|
-
oraclePriceDen,
|
|
106
|
-
oraclePrice: Number(oraclePriceNum) / Number(oraclePriceDen),
|
|
107
|
-
reservePriceNum,
|
|
108
|
-
reservePriceDen,
|
|
109
|
-
reservePrice: Number(reservePriceNum) / Number(reservePriceDen),
|
|
110
|
-
priceDifferenceBps: priceDifference,
|
|
111
|
-
priceDifferencePercent: Number(priceDifference) / 100,
|
|
112
|
-
reservePriceAboveOraclePrice,
|
|
113
|
-
};
|
|
114
|
-
inBand = priceDifference < BigInt(rebalanceThreshold);
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
...pool,
|
|
118
|
-
poolType: 'FPMM',
|
|
119
|
-
scalingFactor0: decimals0Res.result,
|
|
120
|
-
scalingFactor1: decimals1Res.result,
|
|
121
|
-
reserve0,
|
|
122
|
-
reserve1,
|
|
123
|
-
blockTimestampLast,
|
|
124
|
-
pricing,
|
|
125
|
-
fees: {
|
|
126
|
-
lpFeeBps,
|
|
127
|
-
lpFeePercent: Number(lpFeeBps) / 100,
|
|
128
|
-
protocolFeeBps,
|
|
129
|
-
protocolFeePercent: Number(protocolFeeBps) / 100,
|
|
130
|
-
totalFeePercent: (Number(lpFeeBps) + Number(protocolFeeBps)) / 100,
|
|
131
|
-
},
|
|
132
|
-
rebalancing: {
|
|
133
|
-
rebalanceIncentiveBps,
|
|
134
|
-
rebalanceIncentivePercent: Number(rebalanceIncentiveBps) / 100,
|
|
135
|
-
rebalanceThresholdAboveBps: thresholdAboveBps,
|
|
136
|
-
rebalanceThresholdAbovePercent: Number(thresholdAboveBps) / 100,
|
|
137
|
-
rebalanceThresholdBelowBps: thresholdBelowBps,
|
|
138
|
-
rebalanceThresholdBelowPercent: Number(thresholdBelowBps) / 100,
|
|
139
|
-
inBand,
|
|
140
|
-
liquidityStrategy,
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
throw new Error(`Failed to fetch FPMM pool details for ${pool.poolAddr}: ${error.message}`);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Fetches enriched details for a Virtual pool
|
|
150
|
-
*/
|
|
151
|
-
async function fetchVirtualPoolDetails(publicClient, pool) {
|
|
152
|
-
const [details] = await fetchVirtualPoolDetailsBatch(publicClient, [pool]);
|
|
153
|
-
return details;
|
|
154
|
-
}
|
|
155
|
-
async function fetchVirtualPoolDetailsBatch(publicClient, pools) {
|
|
156
|
-
if (pools.length === 0) {
|
|
157
|
-
return [];
|
|
158
|
-
}
|
|
159
|
-
const contracts = pools.flatMap((pool) => buildVirtualContracts(pool));
|
|
160
|
-
const results = await (0, multicall_1.multicall)(publicClient, contracts);
|
|
161
|
-
return pools.map((pool, index) => {
|
|
162
|
-
const offset = index * VIRTUAL_RESULT_COUNT;
|
|
163
|
-
const poolResults = results.slice(offset, offset + VIRTUAL_RESULT_COUNT);
|
|
164
|
-
return parseVirtualPoolDetails(pool, poolResults);
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
function buildVirtualContracts(pool) {
|
|
168
|
-
const address = pool.poolAddr;
|
|
169
|
-
return [
|
|
170
|
-
{ address, abi: abis_1.VIRTUAL_POOL_ABI, functionName: 'getReserves' },
|
|
171
|
-
{ address, abi: abis_1.VIRTUAL_POOL_ABI, functionName: 'protocolFee' },
|
|
172
|
-
{ address, abi: abis_1.VIRTUAL_POOL_ABI, functionName: 'metadata' },
|
|
173
|
-
];
|
|
174
|
-
}
|
|
175
|
-
function parseVirtualPoolDetails(pool, results) {
|
|
176
|
-
try {
|
|
177
|
-
if (results.length !== VIRTUAL_RESULT_COUNT ||
|
|
178
|
-
results[0].status === 'failure' ||
|
|
179
|
-
results[1].status === 'failure' ||
|
|
180
|
-
results[2].status === 'failure') {
|
|
181
|
-
throw new Error('One or more virtual pool reads failed');
|
|
182
|
-
}
|
|
183
|
-
const [reserve0, reserve1, blockTimestampLast] = results[0].result;
|
|
184
|
-
const [dec0, dec1] = results[2].result;
|
|
185
|
-
const spreadBps = results[1].result;
|
|
186
|
-
return {
|
|
187
|
-
...pool,
|
|
188
|
-
poolType: 'Virtual',
|
|
189
|
-
scalingFactor0: dec0,
|
|
190
|
-
scalingFactor1: dec1,
|
|
191
|
-
reserve0,
|
|
192
|
-
reserve1,
|
|
193
|
-
blockTimestampLast,
|
|
194
|
-
spreadBps,
|
|
195
|
-
spreadPercent: Number(spreadBps) / 100,
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
catch (error) {
|
|
199
|
-
throw new Error(`Failed to fetch Virtual pool details for ${pool.poolAddr}: ${error.message}`);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Returns the configured Open Liquidity Strategy for the given chain.
|
|
204
|
-
*/
|
|
205
|
-
function getOpenLiquidityStrategy(chainId) {
|
|
206
|
-
const strategyAddress = (0, constants_1.tryGetContractAddress)(chainId, 'OpenLiquidityStrategy');
|
|
207
|
-
if (!strategyAddress)
|
|
208
|
-
return null;
|
|
209
|
-
try {
|
|
210
|
-
return (0, viem_1.getAddress)(strategyAddress);
|
|
211
|
-
}
|
|
212
|
-
catch {
|
|
213
|
-
return null;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
//# sourceMappingURL=poolDetails.js.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Pool } from '../../core/types';
|
|
2
|
-
import { PublicClient } from 'viem';
|
|
3
|
-
/**
|
|
4
|
-
* Fetches all FPMM pools from the FPMM Factory
|
|
5
|
-
*/
|
|
6
|
-
export declare function fetchFPMMPools(publicClient: PublicClient, chainId: number): Promise<Pool[]>;
|
|
7
|
-
/**
|
|
8
|
-
* Fetches all active Virtual pools from the VirtualPoolFactory,
|
|
9
|
-
* then resolves token pairs and exchange IDs from each pool and BiPoolManager.
|
|
10
|
-
*/
|
|
11
|
-
export declare function fetchVirtualPools(publicClient: PublicClient, chainId: number): Promise<Pool[]>;
|
|
12
|
-
//# sourceMappingURL=poolDiscovery.d.ts.map
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchFPMMPools = fetchFPMMPools;
|
|
4
|
-
exports.fetchVirtualPools = fetchVirtualPools;
|
|
5
|
-
const constants_1 = require("../../core/constants");
|
|
6
|
-
const types_1 = require("../../core/types");
|
|
7
|
-
const abis_1 = require("../../core/abis");
|
|
8
|
-
const sortUtils_1 = require("../../utils/sortUtils");
|
|
9
|
-
const multicall_1 = require("../../utils/multicall");
|
|
10
|
-
/**
|
|
11
|
-
* Fetches all FPMM pools from the FPMM Factory
|
|
12
|
-
*/
|
|
13
|
-
async function fetchFPMMPools(publicClient, chainId) {
|
|
14
|
-
const fpmmFactoryAddress = (0, constants_1.tryGetContractAddress)(chainId, 'FPMMFactory');
|
|
15
|
-
if (!fpmmFactoryAddress) {
|
|
16
|
-
return [];
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
// Get all deployed FPMM pool addresses
|
|
20
|
-
const poolAddresses = (await publicClient.readContract({
|
|
21
|
-
address: fpmmFactoryAddress,
|
|
22
|
-
abi: abis_1.FPMM_FACTORY_ABI,
|
|
23
|
-
functionName: 'deployedFPMMAddresses',
|
|
24
|
-
}));
|
|
25
|
-
if (poolAddresses.length === 0) {
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
// Batch all token0/token1 reads into a single multicall
|
|
29
|
-
const contracts = poolAddresses.flatMap((poolAddress) => [
|
|
30
|
-
{ address: poolAddress, abi: abis_1.FPMM_ABI, functionName: 'token0' },
|
|
31
|
-
{ address: poolAddress, abi: abis_1.FPMM_ABI, functionName: 'token1' },
|
|
32
|
-
]);
|
|
33
|
-
const results = await (0, multicall_1.multicall)(publicClient, contracts);
|
|
34
|
-
return poolAddresses.map((poolAddress, i) => {
|
|
35
|
-
const token0Result = results[i * 2];
|
|
36
|
-
const token1Result = results[i * 2 + 1];
|
|
37
|
-
if (token0Result.status === 'failure' || token1Result.status === 'failure') {
|
|
38
|
-
throw new Error(`Failed to read token addresses for pool ${poolAddress}`);
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
factoryAddr: fpmmFactoryAddress,
|
|
42
|
-
poolAddr: poolAddress,
|
|
43
|
-
token0: token0Result.result,
|
|
44
|
-
token1: token1Result.result,
|
|
45
|
-
poolType: types_1.PoolType.FPMM,
|
|
46
|
-
};
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
throw new Error(`Failed to fetch FPMM pools: ${error.message}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Fetches all active Virtual pools from the VirtualPoolFactory,
|
|
55
|
-
* then resolves token pairs and exchange IDs from each pool and BiPoolManager.
|
|
56
|
-
*/
|
|
57
|
-
async function fetchVirtualPools(publicClient, chainId) {
|
|
58
|
-
const virtualPoolFactoryAddress = (0, constants_1.tryGetContractAddress)(chainId, 'VirtualPoolFactory');
|
|
59
|
-
const biPoolManagerAddress = (0, constants_1.tryGetContractAddress)(chainId, 'BiPoolManager');
|
|
60
|
-
if (!virtualPoolFactoryAddress || !biPoolManagerAddress) {
|
|
61
|
-
return [];
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
// Fetch active pool addresses and all exchanges in parallel
|
|
65
|
-
const [poolAddresses, exchangesData] = await Promise.all([
|
|
66
|
-
publicClient.readContract({
|
|
67
|
-
address: virtualPoolFactoryAddress,
|
|
68
|
-
abi: abis_1.VIRTUAL_POOL_FACTORY_ABI,
|
|
69
|
-
functionName: 'getAllPools',
|
|
70
|
-
}),
|
|
71
|
-
publicClient.readContract({
|
|
72
|
-
address: biPoolManagerAddress,
|
|
73
|
-
abi: abis_1.BIPOOL_MANAGER_ABI,
|
|
74
|
-
functionName: 'getExchanges',
|
|
75
|
-
}),
|
|
76
|
-
]);
|
|
77
|
-
if (poolAddresses.length === 0) {
|
|
78
|
-
return [];
|
|
79
|
-
}
|
|
80
|
-
// Build a lookup from sorted token pair to exchangeId
|
|
81
|
-
const tokenPairToExchangeId = new Map();
|
|
82
|
-
for (const exchange of exchangesData) {
|
|
83
|
-
if (exchange.assets.length === 2) {
|
|
84
|
-
const [t0, t1] = (0, sortUtils_1.sortTokenAddresses)(exchange.assets[0], exchange.assets[1]);
|
|
85
|
-
tokenPairToExchangeId.set(`${t0}:${t1}`, exchange.exchangeId);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
// Batch all tokens() reads into a single multicall
|
|
89
|
-
const contracts = poolAddresses.map((poolAddress) => ({
|
|
90
|
-
address: poolAddress,
|
|
91
|
-
abi: abis_1.VIRTUAL_POOL_ABI,
|
|
92
|
-
functionName: 'tokens',
|
|
93
|
-
}));
|
|
94
|
-
const results = await (0, multicall_1.multicall)(publicClient, contracts);
|
|
95
|
-
return poolAddresses.map((poolAddress, i) => {
|
|
96
|
-
const result = results[i];
|
|
97
|
-
if (result.status === 'failure') {
|
|
98
|
-
throw new Error(`Failed to read token addresses for virtual pool ${poolAddress}`);
|
|
99
|
-
}
|
|
100
|
-
const [token0, token1] = result.result;
|
|
101
|
-
const [sorted0, sorted1] = (0, sortUtils_1.sortTokenAddresses)(token0, token1);
|
|
102
|
-
const exchangeId = tokenPairToExchangeId.get(`${sorted0}:${sorted1}`);
|
|
103
|
-
return {
|
|
104
|
-
factoryAddr: virtualPoolFactoryAddress,
|
|
105
|
-
poolAddr: poolAddress,
|
|
106
|
-
token0: sorted0,
|
|
107
|
-
token1: sorted1,
|
|
108
|
-
poolType: types_1.PoolType.Virtual,
|
|
109
|
-
exchangeId,
|
|
110
|
-
};
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
throw new Error(`Failed to fetch Virtual pools: ${error.message}`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
//# sourceMappingURL=poolDiscovery.js.map
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { type PublicClient } from 'viem';
|
|
2
|
-
import type { PoolDetails, PoolRebalancePreview } from '../../core/types';
|
|
3
|
-
export declare function fetchPoolRebalancePreview(publicClient: PublicClient, detail: PoolDetails): Promise<PoolRebalancePreview | null>;
|
|
4
|
-
export declare function fetchPoolRebalancePreviewBatch(publicClient: PublicClient, details: PoolDetails[]): Promise<Array<PoolRebalancePreview | null>>;
|
|
5
|
-
//# sourceMappingURL=rebalancePreview.d.ts.map
|