@mento-protocol/mento-sdk 3.0.0-beta.1 → 3.0.0-beta.10
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/README.md +34 -0
- package/dist/cache/routes.d.ts +13 -0
- package/dist/cache/routes.d.ts.map +1 -0
- package/dist/cache/routes.js +130 -0
- package/dist/cache/routes.js.map +1 -0
- package/dist/cache/tokens.d.ts +67 -0
- package/dist/cache/tokens.d.ts.map +1 -0
- package/dist/cache/tokens.js +379 -0
- package/dist/cache/tokens.js.map +1 -0
- package/dist/core/abis/breakerbox.d.ts +13 -0
- package/dist/core/abis/breakerbox.d.ts.map +1 -0
- package/dist/core/abis/breakerbox.js +8 -0
- package/dist/core/abis/breakerbox.js.map +1 -0
- package/dist/core/abis/erc20.d.ts +7 -0
- package/dist/core/abis/erc20.d.ts.map +1 -1
- package/dist/core/abis/erc20.js +7 -0
- package/dist/core/abis/erc20.js.map +1 -1
- package/dist/core/abis/fpmm.d.ts +126 -0
- package/dist/core/abis/fpmm.d.ts.map +1 -1
- package/dist/core/abis/fpmm.js +10 -0
- package/dist/core/abis/fpmm.js.map +1 -1
- package/dist/core/abis/index.d.ts +2 -0
- package/dist/core/abis/index.d.ts.map +1 -1
- package/dist/core/abis/index.js +2 -0
- package/dist/core/abis/index.js.map +1 -1
- package/dist/core/abis/virtualPool.d.ts +30 -0
- package/dist/core/abis/virtualPool.d.ts.map +1 -1
- package/dist/core/abis/virtualPool.js +5 -1
- package/dist/core/abis/virtualPool.js.map +1 -1
- package/dist/core/constants/aaveConfig.js +2 -2
- package/dist/core/constants/addresses.d.ts.map +1 -1
- package/dist/core/constants/addresses.js +9 -4
- package/dist/core/constants/addresses.js.map +1 -1
- package/dist/core/types/contractAddresses.d.ts +2 -0
- package/dist/core/types/contractAddresses.d.ts.map +1 -1
- package/dist/core/types/index.d.ts +3 -1
- package/dist/core/types/index.d.ts.map +1 -1
- package/dist/core/types/index.js +3 -1
- package/dist/core/types/index.js.map +1 -1
- package/dist/core/types/pool.d.ts +110 -0
- package/dist/core/types/pool.d.ts.map +1 -1
- package/dist/core/types/provider.d.ts.map +1 -1
- package/dist/core/types/provider.js +0 -1
- package/dist/core/types/provider.js.map +1 -1
- package/dist/core/types/route.d.ts +3 -3
- package/dist/core/types/route.d.ts.map +1 -1
- package/dist/core/types/token.d.ts +13 -3
- package/dist/core/types/token.d.ts.map +1 -1
- package/dist/core/types/tradingLimits.d.ts +91 -0
- package/dist/core/types/tradingLimits.d.ts.map +1 -0
- package/dist/core/types/tradingLimits.js +3 -0
- package/dist/core/types/tradingLimits.js.map +1 -0
- package/dist/core/types/tradingMode.d.ts +24 -0
- package/dist/core/types/tradingMode.d.ts.map +1 -0
- package/dist/core/types/tradingMode.js +31 -0
- package/dist/core/types/tradingMode.js.map +1 -0
- package/dist/core/types/transaction.d.ts +45 -0
- package/dist/core/types/transaction.d.ts.map +1 -0
- package/dist/core/types/transaction.js +3 -0
- package/dist/core/types/transaction.js.map +1 -0
- package/dist/index.d.ts +20 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -10
- package/dist/index.js.map +1 -1
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +1 -0
- package/dist/services/index.js.map +1 -1
- package/dist/services/pools/PoolService.d.ts +22 -10
- package/dist/services/pools/PoolService.d.ts.map +1 -1
- package/dist/services/pools/PoolService.js +44 -110
- package/dist/services/pools/PoolService.js.map +1 -1
- package/dist/services/pools/poolDetails.d.ts +11 -0
- package/dist/services/pools/poolDetails.d.ts.map +1 -0
- package/dist/services/pools/poolDetails.js +136 -0
- package/dist/services/pools/poolDetails.js.map +1 -0
- package/dist/services/pools/poolDiscovery.d.ts +13 -0
- package/dist/services/pools/poolDiscovery.d.ts.map +1 -0
- package/dist/services/pools/poolDiscovery.js +115 -0
- package/dist/services/pools/poolDiscovery.js.map +1 -0
- package/dist/services/quotes/QuoteService.d.ts +21 -12
- package/dist/services/quotes/QuoteService.d.ts.map +1 -1
- package/dist/services/quotes/QuoteService.js +23 -10
- package/dist/services/quotes/QuoteService.js.map +1 -1
- package/dist/services/routes/RouteService.d.ts +3 -3
- package/dist/services/routes/RouteService.d.ts.map +1 -1
- package/dist/services/routes/RouteService.js +3 -5
- package/dist/services/routes/RouteService.js.map +1 -1
- package/dist/services/swap/SwapService.d.ts +18 -14
- package/dist/services/swap/SwapService.d.ts.map +1 -1
- package/dist/services/swap/SwapService.js +31 -11
- package/dist/services/swap/SwapService.js.map +1 -1
- package/dist/services/tokens/supplyAdjustmentService.d.ts +0 -4
- package/dist/services/tokens/supplyAdjustmentService.d.ts.map +1 -1
- package/dist/services/tokens/supplyAdjustmentService.js +3 -8
- package/dist/services/tokens/supplyAdjustmentService.js.map +1 -1
- package/dist/services/tokens/tokenService.d.ts.map +1 -1
- package/dist/services/tokens/tokenService.js +2 -2
- package/dist/services/tokens/tokenService.js.map +1 -1
- package/dist/services/trading/TradingLimitsService.d.ts +38 -0
- package/dist/services/trading/TradingLimitsService.d.ts.map +1 -0
- package/dist/services/trading/TradingLimitsService.js +157 -0
- package/dist/services/trading/TradingLimitsService.js.map +1 -0
- package/dist/services/trading/TradingService.d.ts +110 -0
- package/dist/services/trading/TradingService.d.ts.map +1 -0
- package/dist/services/trading/TradingService.js +162 -0
- package/dist/services/trading/TradingService.js.map +1 -0
- package/dist/services/trading/index.d.ts +3 -0
- package/dist/services/trading/index.d.ts.map +1 -0
- package/dist/services/trading/index.js +19 -0
- package/dist/services/trading/index.js.map +1 -0
- package/dist/utils/costUtils.js +4 -4
- package/dist/utils/costUtils.js.map +1 -1
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/pathEncoder.d.ts +3 -2
- package/dist/utils/pathEncoder.d.ts.map +1 -1
- package/dist/utils/pathEncoder.js +19 -3
- package/dist/utils/pathEncoder.js.map +1 -1
- package/dist/utils/rateFeed.d.ts +18 -0
- package/dist/utils/rateFeed.d.ts.map +1 -0
- package/dist/utils/rateFeed.js +27 -0
- package/dist/utils/rateFeed.js.map +1 -0
- package/dist/utils/routeUtils.d.ts +53 -53
- package/dist/utils/routeUtils.d.ts.map +1 -1
- package/dist/utils/routeUtils.js +41 -41
- package/dist/utils/routeUtils.js.map +1 -1
- package/dist/utils/routes.d.ts +2 -8
- package/dist/utils/routes.d.ts.map +1 -1
- package/dist/utils/routes.js +5 -46
- package/dist/utils/routes.js.map +1 -1
- package/dist/utils/tokens.d.ts +1 -77
- package/dist/utils/tokens.d.ts.map +1 -1
- package/dist/utils/tokens.js +10 -178
- package/dist/utils/tokens.js.map +1 -1
- package/dist/utils/tradingLimits.d.ts +41 -0
- package/dist/utils/tradingLimits.d.ts.map +1 -0
- package/dist/utils/tradingLimits.js +171 -0
- package/dist/utils/tradingLimits.js.map +1 -0
- package/dist/utils/validation.d.ts +19 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +34 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +1 -1
- package/dist/cache/routes.42220.d.ts +0 -3
- package/dist/cache/routes.42220.d.ts.map +0 -1
- package/dist/cache/routes.42220.js +0 -112
- package/dist/cache/routes.42220.js.map +0 -1
- package/dist/cache/tokens.11142220.d.ts +0 -3
- package/dist/cache/tokens.11142220.d.ts.map +0 -1
- package/dist/cache/tokens.11142220.js +0 -129
- package/dist/cache/tokens.11142220.js.map +0 -1
- package/dist/cache/tokens.42220.d.ts +0 -3
- package/dist/cache/tokens.42220.d.ts.map +0 -1
- package/dist/cache/tokens.42220.js +0 -129
- package/dist/cache/tokens.42220.js.map +0 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human-friendly representation of a trading limit.
|
|
3
|
+
* Used by frontends to display limit status and calculate remaining capacity.
|
|
4
|
+
*/
|
|
5
|
+
export interface TradingLimit {
|
|
6
|
+
/** Token address this limit applies to */
|
|
7
|
+
asset: string;
|
|
8
|
+
/** Maximum amount that can flow IN (raw value - V1: 0 decimals, V2: 15 decimals) */
|
|
9
|
+
maxIn: bigint;
|
|
10
|
+
/** Maximum amount that can flow OUT (raw value - V1: 0 decimals, V2: 15 decimals) */
|
|
11
|
+
maxOut: bigint;
|
|
12
|
+
/** Unix timestamp when this limit window resets */
|
|
13
|
+
until: number;
|
|
14
|
+
/** Token decimals for consumer scaling */
|
|
15
|
+
decimals: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Trading limits configuration for V1 (Broker/Virtual pools).
|
|
19
|
+
* Uses configurable timeframes and 0 decimal precision.
|
|
20
|
+
*/
|
|
21
|
+
export interface TradingLimitsConfigV1 {
|
|
22
|
+
/** Time window in seconds for L0 limit */
|
|
23
|
+
timestep0: number;
|
|
24
|
+
/** Time window in seconds for L1 limit */
|
|
25
|
+
timestep1: number;
|
|
26
|
+
/** L0 limit value (0 decimal precision) */
|
|
27
|
+
limit0: bigint;
|
|
28
|
+
/** L1 limit value (0 decimal precision) */
|
|
29
|
+
limit1: bigint;
|
|
30
|
+
/** Global limit value (0 decimal precision) */
|
|
31
|
+
limitGlobal: bigint;
|
|
32
|
+
/** Flags bitmap: bit 0=L0, bit 1=L1, bit 2=LG */
|
|
33
|
+
flags: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Trading limits state for V1 (Broker/Virtual pools).
|
|
37
|
+
*/
|
|
38
|
+
export interface TradingLimitsStateV1 {
|
|
39
|
+
/** Timestamp of last L0 window reset */
|
|
40
|
+
lastUpdated0: number;
|
|
41
|
+
/** Timestamp of last L1 window reset */
|
|
42
|
+
lastUpdated1: number;
|
|
43
|
+
/** Current netflow for L0 (0 decimal precision) */
|
|
44
|
+
netflow0: bigint;
|
|
45
|
+
/** Current netflow for L1 (0 decimal precision) */
|
|
46
|
+
netflow1: bigint;
|
|
47
|
+
/** Current global netflow (0 decimal precision) */
|
|
48
|
+
netflowGlobal: bigint;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Trading limits configuration for V2 (FPMM pools).
|
|
52
|
+
* Uses fixed timeframes (5 min for L0, 1 day for L1) and 15 decimal precision.
|
|
53
|
+
*/
|
|
54
|
+
export interface TradingLimitsConfigV2 {
|
|
55
|
+
/** L0 limit value (15 decimal precision) */
|
|
56
|
+
limit0: bigint;
|
|
57
|
+
/** L1 limit value (15 decimal precision) */
|
|
58
|
+
limit1: bigint;
|
|
59
|
+
/** Token decimals */
|
|
60
|
+
decimals: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Trading limits state for V2 (FPMM pools).
|
|
64
|
+
*/
|
|
65
|
+
export interface TradingLimitsStateV2 {
|
|
66
|
+
/** Timestamp of last L0 window reset */
|
|
67
|
+
lastUpdated0: number;
|
|
68
|
+
/** Timestamp of last L1 window reset */
|
|
69
|
+
lastUpdated1: number;
|
|
70
|
+
/** Current netflow for L0 (15 decimal precision) */
|
|
71
|
+
netflow0: bigint;
|
|
72
|
+
/** Current netflow for L1 (15 decimal precision) */
|
|
73
|
+
netflow1: bigint;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Combined tradability status for a pool.
|
|
77
|
+
* Separates circuit breaker and trading limits for distinct UI messaging.
|
|
78
|
+
*/
|
|
79
|
+
export interface PoolTradabilityStatus {
|
|
80
|
+
/** Overall tradability (circuitBreakerOk AND limitsOk) */
|
|
81
|
+
tradable: boolean;
|
|
82
|
+
/** Circuit breaker status - true if not tripped */
|
|
83
|
+
circuitBreakerOk: boolean;
|
|
84
|
+
/** Raw trading mode value (0 = BIDIRECTIONAL, non-zero = suspended) */
|
|
85
|
+
tradingMode: number;
|
|
86
|
+
/** Trading limits status - true if limits not exhausted */
|
|
87
|
+
limitsOk: boolean;
|
|
88
|
+
/** Detailed limit info for UI display */
|
|
89
|
+
limits: TradingLimit[];
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=tradingLimits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tradingLimits.d.ts","sourceRoot":"","sources":["../../../src/core/types/tradingLimits.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAA;IACb,oFAAoF;IACpF,KAAK,EAAE,MAAM,CAAA;IACb,qFAAqF;IACrF,MAAM,EAAE,MAAM,CAAA;IACd,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAA;IACb,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAA;IACjB,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAA;IACjB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAA;IACd,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAA;IACd,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAA;IACnB,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAA;CACd;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAA;IACpB,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAA;IACpB,mDAAmD;IACnD,QAAQ,EAAE,MAAM,CAAA;IAChB,mDAAmD;IACnD,QAAQ,EAAE,MAAM,CAAA;IAChB,mDAAmD;IACnD,aAAa,EAAE,MAAM,CAAA;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAA;IACd,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAA;IACd,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAA;IACpB,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAA;IACpB,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAA;IAChB,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,0DAA0D;IAC1D,QAAQ,EAAE,OAAO,CAAA;IAEjB,mDAAmD;IACnD,gBAAgB,EAAE,OAAO,CAAA;IACzB,uEAAuE;IACvE,WAAW,EAAE,MAAM,CAAA;IAEnB,2DAA2D;IAC3D,QAAQ,EAAE,OAAO,CAAA;IACjB,yCAAyC;IACzC,MAAM,EAAE,YAAY,EAAE,CAAA;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tradingLimits.js","sourceRoot":"","sources":["../../../src/core/types/tradingLimits.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trading modes for rate feeds in the BreakerBox circuit breaker.
|
|
3
|
+
*
|
|
4
|
+
* The BreakerBox uses a bitmask approach where multiple breakers can
|
|
5
|
+
* contribute to the final trading mode. In practice:
|
|
6
|
+
* - 0 = Bidirectional (trading enabled)
|
|
7
|
+
* - Any non-zero value = Trading suspended
|
|
8
|
+
*
|
|
9
|
+
* For SDK consumers, use isTradingEnabled() helper to check if trading
|
|
10
|
+
* is allowed.
|
|
11
|
+
*/
|
|
12
|
+
export declare enum TradingMode {
|
|
13
|
+
/** Bidirectional trading is enabled (normal operation) */
|
|
14
|
+
BIDIRECTIONAL = 0,
|
|
15
|
+
/** Trading is suspended (circuit breaker tripped) - any non-zero value */
|
|
16
|
+
SUSPENDED = 1
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Check if trading is enabled for a given trading mode.
|
|
20
|
+
* @param mode - The trading mode value from BreakerBox
|
|
21
|
+
* @returns true if trading is enabled (mode === 0)
|
|
22
|
+
*/
|
|
23
|
+
export declare function isTradingEnabled(mode: number): boolean;
|
|
24
|
+
//# sourceMappingURL=tradingMode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tradingMode.d.ts","sourceRoot":"","sources":["../../../src/core/types/tradingMode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,oBAAY,WAAW;IACrB,0DAA0D;IAC1D,aAAa,IAAI;IACjB,0EAA0E;IAC1E,SAAS,IAAI;CACd;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TradingMode = void 0;
|
|
4
|
+
exports.isTradingEnabled = isTradingEnabled;
|
|
5
|
+
/**
|
|
6
|
+
* Trading modes for rate feeds in the BreakerBox circuit breaker.
|
|
7
|
+
*
|
|
8
|
+
* The BreakerBox uses a bitmask approach where multiple breakers can
|
|
9
|
+
* contribute to the final trading mode. In practice:
|
|
10
|
+
* - 0 = Bidirectional (trading enabled)
|
|
11
|
+
* - Any non-zero value = Trading suspended
|
|
12
|
+
*
|
|
13
|
+
* For SDK consumers, use isTradingEnabled() helper to check if trading
|
|
14
|
+
* is allowed.
|
|
15
|
+
*/
|
|
16
|
+
var TradingMode;
|
|
17
|
+
(function (TradingMode) {
|
|
18
|
+
/** Bidirectional trading is enabled (normal operation) */
|
|
19
|
+
TradingMode[TradingMode["BIDIRECTIONAL"] = 0] = "BIDIRECTIONAL";
|
|
20
|
+
/** Trading is suspended (circuit breaker tripped) - any non-zero value */
|
|
21
|
+
TradingMode[TradingMode["SUSPENDED"] = 1] = "SUSPENDED";
|
|
22
|
+
})(TradingMode || (exports.TradingMode = TradingMode = {}));
|
|
23
|
+
/**
|
|
24
|
+
* Check if trading is enabled for a given trading mode.
|
|
25
|
+
* @param mode - The trading mode value from BreakerBox
|
|
26
|
+
* @returns true if trading is enabled (mode === 0)
|
|
27
|
+
*/
|
|
28
|
+
function isTradingEnabled(mode) {
|
|
29
|
+
return mode === TradingMode.BIDIRECTIONAL;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=tradingMode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tradingMode.js","sourceRoot":"","sources":["../../../src/core/types/tradingMode.ts"],"names":[],"mappings":";;;AAuBA,4CAEC;AAzBD;;;;;;;;;;GAUG;AACH,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,0DAA0D;IAC1D,+DAAiB,CAAA;IACjB,0EAA0E;IAC1E,uDAAa,CAAA;AACf,CAAC,EALW,WAAW,2BAAX,WAAW,QAKtB;AAED;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,OAAO,IAAI,KAAK,WAAW,CAAC,aAAa,CAAA;AAC3C,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export interface ContractCallOptions {
|
|
2
|
+
address: string;
|
|
3
|
+
abi: string[] | unknown[];
|
|
4
|
+
functionName: string;
|
|
5
|
+
args?: unknown[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Contract write options for building call parameters
|
|
9
|
+
*
|
|
10
|
+
* Configuration for building transaction call parameters for write operations.
|
|
11
|
+
* These parameters can be used by consumers to execute transactions themselves.
|
|
12
|
+
*/
|
|
13
|
+
export interface ContractWriteOptions extends ContractCallOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Optional gas limit override
|
|
16
|
+
* If not provided, will be estimated automatically
|
|
17
|
+
*/
|
|
18
|
+
gasLimit?: bigint;
|
|
19
|
+
/**
|
|
20
|
+
* Transaction value in wei
|
|
21
|
+
* For payable functions only
|
|
22
|
+
*/
|
|
23
|
+
value?: bigint;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Call parameters for executing a contract transaction
|
|
27
|
+
*
|
|
28
|
+
* Contains all the data needed to execute a contract call.
|
|
29
|
+
* Consumers can use these parameters with their own wallet/signer to execute transactions.
|
|
30
|
+
*/
|
|
31
|
+
export interface CallParams {
|
|
32
|
+
/**
|
|
33
|
+
* Contract address to call
|
|
34
|
+
*/
|
|
35
|
+
to: string;
|
|
36
|
+
/**
|
|
37
|
+
* Encoded function call data (hex string)
|
|
38
|
+
*/
|
|
39
|
+
data: string;
|
|
40
|
+
/**
|
|
41
|
+
* Transaction value in wei (hex string with 0x prefix)
|
|
42
|
+
*/
|
|
43
|
+
value: string;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../../src/core/types/transaction.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,CAAA;IACzB,YAAY,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAA;CACjB;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAC/D;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;IAEV;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;CACd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../src/core/types/transaction.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ContractAddresses } from './core/types';
|
|
2
|
-
import { TokenService } from '
|
|
3
|
-
import { PoolService } from '
|
|
4
|
-
import { RouteService } from '
|
|
5
|
-
import { QuoteService } from '
|
|
6
|
-
import { SwapService } from '
|
|
2
|
+
import { TokenService } from './services/tokens';
|
|
3
|
+
import { PoolService } from './services/pools';
|
|
4
|
+
import { RouteService } from './services/routes';
|
|
5
|
+
import { QuoteService } from './services/quotes';
|
|
6
|
+
import { SwapService } from './services/swap';
|
|
7
|
+
import { TradingService } from './services/trading';
|
|
7
8
|
/**
|
|
8
9
|
* @class Mento
|
|
9
10
|
* @description The main class for the Mento SDK. Initializes a viem PublicClient internally
|
|
@@ -23,13 +24,22 @@ import { SwapService } from '@services/swap';
|
|
|
23
24
|
* const pools = await mento.pools.getPools();
|
|
24
25
|
*
|
|
25
26
|
* // Find a route between tokens
|
|
26
|
-
* const route = await mento.routes.findRoute(
|
|
27
|
+
* const route = await mento.routes.findRoute(USDm, CELO);
|
|
27
28
|
*
|
|
28
29
|
* // Get a quote for a swap
|
|
29
|
-
* const amountOut = await mento.quotes.getAmountOut(
|
|
30
|
+
* const amountOut = await mento.quotes.getAmountOut(USDm, CELO, amountIn);
|
|
30
31
|
*
|
|
31
32
|
* // Build swap parameters
|
|
32
|
-
* const swapDetails = await mento.swap.buildSwapParams(
|
|
33
|
+
* const swapDetails = await mento.swap.buildSwapParams(USDm, CELO, amountIn, { slippageTolerance: 0.5 });
|
|
34
|
+
*
|
|
35
|
+
* // Check if a pair is tradable (circuit breaker check)
|
|
36
|
+
* const isTradable = await mento.trading.isPairTradable(USDm, CELO);
|
|
37
|
+
*
|
|
38
|
+
* // Get trading limits for a pool
|
|
39
|
+
* const limits = await mento.trading.getPoolTradingLimits(pool);
|
|
40
|
+
*
|
|
41
|
+
* // Get full tradability status (circuit breaker + limits)
|
|
42
|
+
* const status = await mento.trading.getPoolTradabilityStatus(pool);
|
|
33
43
|
*/
|
|
34
44
|
export declare class Mento {
|
|
35
45
|
private chainId;
|
|
@@ -38,6 +48,7 @@ export declare class Mento {
|
|
|
38
48
|
routes: RouteService;
|
|
39
49
|
quotes: QuoteService;
|
|
40
50
|
swap: SwapService;
|
|
51
|
+
trading: TradingService;
|
|
41
52
|
private constructor();
|
|
42
53
|
/**
|
|
43
54
|
* Create a new Mento SDK instance
|
|
@@ -57,4 +68,5 @@ export * from './core/constants';
|
|
|
57
68
|
export * from './core/types';
|
|
58
69
|
export * from './core/abis';
|
|
59
70
|
export * from './services';
|
|
71
|
+
export * from './utils';
|
|
60
72
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAIhD,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAIhD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,KAAK;IAEd,OAAO,CAAC,OAAO;IACR,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,WAAW;IAClB,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,YAAY;IACpB,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,cAAc;IAPhC,OAAO;IAUP;;;;;OAKG;WACiB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAqB5E;;;;OAIG;IACI,kBAAkB,CAAC,YAAY,EAAE,MAAM,iBAAiB,GAAG,MAAM;CAGzE;AAED,cAAc,kBAAkB,CAAA;AAChC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -18,11 +18,12 @@ exports.Mento = void 0;
|
|
|
18
18
|
const viem_1 = require("viem");
|
|
19
19
|
const addresses_1 = require("./core/constants/addresses");
|
|
20
20
|
const chainConfig_1 = require("./utils/chainConfig");
|
|
21
|
-
const tokens_1 = require("
|
|
22
|
-
const pools_1 = require("
|
|
23
|
-
const routes_1 = require("
|
|
24
|
-
const quotes_1 = require("
|
|
25
|
-
const swap_1 = require("
|
|
21
|
+
const tokens_1 = require("./services/tokens");
|
|
22
|
+
const pools_1 = require("./services/pools");
|
|
23
|
+
const routes_1 = require("./services/routes");
|
|
24
|
+
const quotes_1 = require("./services/quotes");
|
|
25
|
+
const swap_1 = require("./services/swap");
|
|
26
|
+
const trading_1 = require("./services/trading");
|
|
26
27
|
/**
|
|
27
28
|
* @class Mento
|
|
28
29
|
* @description The main class for the Mento SDK. Initializes a viem PublicClient internally
|
|
@@ -42,22 +43,32 @@ const swap_1 = require("@services/swap");
|
|
|
42
43
|
* const pools = await mento.pools.getPools();
|
|
43
44
|
*
|
|
44
45
|
* // Find a route between tokens
|
|
45
|
-
* const route = await mento.routes.findRoute(
|
|
46
|
+
* const route = await mento.routes.findRoute(USDm, CELO);
|
|
46
47
|
*
|
|
47
48
|
* // Get a quote for a swap
|
|
48
|
-
* const amountOut = await mento.quotes.getAmountOut(
|
|
49
|
+
* const amountOut = await mento.quotes.getAmountOut(USDm, CELO, amountIn);
|
|
49
50
|
*
|
|
50
51
|
* // Build swap parameters
|
|
51
|
-
* const swapDetails = await mento.swap.buildSwapParams(
|
|
52
|
+
* const swapDetails = await mento.swap.buildSwapParams(USDm, CELO, amountIn, { slippageTolerance: 0.5 });
|
|
53
|
+
*
|
|
54
|
+
* // Check if a pair is tradable (circuit breaker check)
|
|
55
|
+
* const isTradable = await mento.trading.isPairTradable(USDm, CELO);
|
|
56
|
+
*
|
|
57
|
+
* // Get trading limits for a pool
|
|
58
|
+
* const limits = await mento.trading.getPoolTradingLimits(pool);
|
|
59
|
+
*
|
|
60
|
+
* // Get full tradability status (circuit breaker + limits)
|
|
61
|
+
* const status = await mento.trading.getPoolTradabilityStatus(pool);
|
|
52
62
|
*/
|
|
53
63
|
class Mento {
|
|
54
|
-
constructor(chainId, tokens, pools, routes, quotes, swap) {
|
|
64
|
+
constructor(chainId, tokens, pools, routes, quotes, swap, trading) {
|
|
55
65
|
this.chainId = chainId;
|
|
56
66
|
this.tokens = tokens;
|
|
57
67
|
this.pools = pools;
|
|
58
68
|
this.routes = routes;
|
|
59
69
|
this.quotes = quotes;
|
|
60
70
|
this.swap = swap;
|
|
71
|
+
this.trading = trading;
|
|
61
72
|
}
|
|
62
73
|
/**
|
|
63
74
|
* Create a new Mento SDK instance
|
|
@@ -78,8 +89,9 @@ class Mento {
|
|
|
78
89
|
const routeService = new routes_1.RouteService(publicClient, chainId, poolService);
|
|
79
90
|
const quoteService = new quotes_1.QuoteService(publicClient, chainId, routeService);
|
|
80
91
|
const swapService = new swap_1.SwapService(publicClient, chainId, routeService, quoteService);
|
|
92
|
+
const tradingService = new trading_1.TradingService(publicClient, chainId, routeService);
|
|
81
93
|
// Return new mento
|
|
82
|
-
return new Mento(chainId, tokenService, poolService, routeService, quoteService, swapService);
|
|
94
|
+
return new Mento(chainId, tokenService, poolService, routeService, quoteService, swapService, tradingService);
|
|
83
95
|
}
|
|
84
96
|
/**
|
|
85
97
|
* Get the address of a contract for the current chain
|
|
@@ -95,4 +107,5 @@ __exportStar(require("./core/constants"), exports);
|
|
|
95
107
|
__exportStar(require("./core/types"), exports);
|
|
96
108
|
__exportStar(require("./core/abis"), exports);
|
|
97
109
|
__exportStar(require("./services"), exports);
|
|
110
|
+
__exportStar(require("./utils"), exports);
|
|
98
111
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+BAAkE;AAGlE,0DAA+D;AAC/D,qDAAsE;AACtE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+BAAkE;AAGlE,0DAA+D;AAC/D,qDAAsE;AACtE,8CAAgD;AAChD,4CAA8C;AAC9C,8CAAgD;AAChD,8CAAgD;AAChD,0CAA6C;AAC7C,gDAAmD;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAa,KAAK;IAChB,YACU,OAAe,EAChB,MAAoB,EACpB,KAAkB,EAClB,MAAoB,EACpB,MAAoB,EACpB,IAAiB,EACjB,OAAuB;QANtB,YAAO,GAAP,OAAO,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAc;QACpB,UAAK,GAAL,KAAK,CAAa;QAClB,WAAM,GAAN,MAAM,CAAc;QACpB,WAAM,GAAN,MAAM,CAAc;QACpB,SAAI,GAAJ,IAAI,CAAa;QACjB,YAAO,GAAP,OAAO,CAAgB;IAC7B,CAAC;IAEJ;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,MAAe;QACzD,gDAAgD;QAChD,MAAM,SAAS,GAAG,IAAA,WAAI,EAAC,MAAM,IAAI,IAAA,8BAAgB,EAAC,OAAO,CAAC,CAAC,CAAA;QAE3D,2BAA2B;QAC3B,MAAM,YAAY,GAAG,IAAA,yBAAkB,EAAC;YACtC,KAAK,EAAE,IAAA,4BAAc,EAAC,OAAO,CAAC;YAC9B,SAAS;SACV,CAAC,CAAA;QAEF,MAAM,YAAY,GAAG,IAAI,qBAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;QAC5D,MAAM,WAAW,GAAG,IAAI,mBAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;QAC1D,MAAM,YAAY,GAAG,IAAI,qBAAY,CAAC,YAAY,EAAE,OAAO,EAAE,WAAW,CAAC,CAAA;QACzE,MAAM,YAAY,GAAG,IAAI,qBAAY,CAAC,YAAY,EAAE,OAAO,EAAE,YAAY,CAAC,CAAA;QAC1E,MAAM,WAAW,GAAG,IAAI,kBAAW,CAAC,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,CAAC,CAAA;QACtF,MAAM,cAAc,GAAG,IAAI,wBAAc,CAAC,YAAY,EAAE,OAAO,EAAE,YAAY,CAAC,CAAA;QAE9E,mBAAmB;QACnB,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,CAAC,CAAA;IAC/G,CAAC;IAED;;;;OAIG;IACI,kBAAkB,CAAC,YAAqC;QAC7D,OAAO,IAAA,8BAAkB,EAAC,IAAI,CAAC,OAAkB,EAAE,YAAY,CAAC,CAAA;IAClE,CAAC;CACF;AA9CD,sBA8CC;AAED,mDAAgC;AAChC,+CAA4B;AAC5B,8CAA2B;AAC3B,6CAA0B;AAC1B,0CAAuB"}
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAA;AAChD,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAA;AAChD,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,WAAW,CAAA"}
|
package/dist/services/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mEAAgD;AAChD,kDAA+B;AAC/B,0CAAuB;AACvB,2CAAwB;AACxB,2CAAwB;AACxB,yCAAsB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mEAAgD;AAChD,kDAA+B;AAC/B,0CAAuB;AACvB,2CAAwB;AACxB,2CAAwB;AACxB,yCAAsB;AACtB,4CAAyB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Pool } from '../../core/types';
|
|
1
|
+
import { Pool, PoolDetails } from '../../core/types';
|
|
2
2
|
import { PublicClient } from 'viem';
|
|
3
3
|
/**
|
|
4
4
|
* Service for discovering liquidity pools in the Mento protocol.
|
|
@@ -14,7 +14,7 @@ export declare class PoolService {
|
|
|
14
14
|
* Results are cached in memory for the service instance lifetime
|
|
15
15
|
*
|
|
16
16
|
* @returns Array of all pools available in the protocol
|
|
17
|
-
* @throws {Error} If
|
|
17
|
+
* @throws {Error} If no pools can be discovered from any factory
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```typescript
|
|
@@ -24,14 +24,26 @@ export declare class PoolService {
|
|
|
24
24
|
*/
|
|
25
25
|
getPools(): Promise<Pool[]>;
|
|
26
26
|
/**
|
|
27
|
-
* Fetches
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
27
|
+
* Fetches enriched on-chain details for a specific pool by address.
|
|
28
|
+
* Resolves the pool type from the discovery cache, then fetches
|
|
29
|
+
* pool-type-specific data (pricing, fees, rebalancing for FPMM; reserves and spread for Virtual).
|
|
30
|
+
*
|
|
31
|
+
* @param poolAddr - The deployed pool contract address
|
|
32
|
+
* @returns Enriched pool details (FPMMPoolDetails or VirtualPoolDetails)
|
|
33
|
+
* @throws {Error} If the pool address is not found in any known factory
|
|
34
|
+
* @throws {Error} If on-chain calls fail
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const details = await poolService.getPoolDetails('0x...')
|
|
39
|
+
* if (details.poolType === 'FPMM') {
|
|
40
|
+
* console.log(details.pricing.oraclePrice)
|
|
41
|
+
* console.log(details.rebalancing.inBand)
|
|
42
|
+
* } else {
|
|
43
|
+
* console.log(details.spreadPercent)
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
34
46
|
*/
|
|
35
|
-
|
|
47
|
+
getPoolDetails(poolAddr: string): Promise<PoolDetails>;
|
|
36
48
|
}
|
|
37
49
|
//# sourceMappingURL=PoolService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PoolService.d.ts","sourceRoot":"","sources":["../../../src/services/pools/PoolService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PoolService.d.ts","sourceRoot":"","sources":["../../../src/services/pools/PoolService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAY,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAInC;;;GAGG;AACH,qBAAa,WAAW;IAGV,OAAO,CAAC,YAAY;IAAgB,OAAO,CAAC,OAAO;IAF/D,OAAO,CAAC,UAAU,CAAsB;gBAEpB,YAAY,EAAE,YAAY,EAAU,OAAO,EAAE,MAAM;IAEvE;;;;;;;;;;;;OAYG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAgCjC;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAc7D"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PoolService = void 0;
|
|
4
|
-
const constants_1 = require("../../core/constants");
|
|
5
4
|
const types_1 = require("../../core/types");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
// TODO: Update to enrich pools with more data as needed. Use optional flag to include more data.
|
|
5
|
+
const poolDiscovery_1 = require("./poolDiscovery");
|
|
6
|
+
const poolDetails_1 = require("./poolDetails");
|
|
9
7
|
/**
|
|
10
8
|
* Service for discovering liquidity pools in the Mento protocol.
|
|
11
9
|
* Aggregates pools from multiple factory contracts (FPMM and VirtualPool).
|
|
@@ -21,7 +19,7 @@ class PoolService {
|
|
|
21
19
|
* Results are cached in memory for the service instance lifetime
|
|
22
20
|
*
|
|
23
21
|
* @returns Array of all pools available in the protocol
|
|
24
|
-
* @throws {Error} If
|
|
22
|
+
* @throws {Error} If no pools can be discovered from any factory
|
|
25
23
|
*
|
|
26
24
|
* @example
|
|
27
25
|
* ```typescript
|
|
@@ -37,120 +35,56 @@ class PoolService {
|
|
|
37
35
|
// for dynamic factory discovery. For now we will use
|
|
38
36
|
// the hardcoded factory addresses for the chain for v1.
|
|
39
37
|
const pools = [];
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
pools.push(...virtualPools);
|
|
44
|
-
this.poolsCache = pools;
|
|
45
|
-
return pools;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Fetches all FPMM pools from the FPMM Factory
|
|
49
|
-
*/
|
|
50
|
-
async fetchFPMMPools() {
|
|
51
|
-
const fpmmFactoryAddress = (0, constants_1.getContractAddress)(this.chainId, 'FPMMFactory');
|
|
52
|
-
if (!fpmmFactoryAddress) {
|
|
53
|
-
console.warn('FPMM Factory address not found for this chain');
|
|
54
|
-
return [];
|
|
38
|
+
try {
|
|
39
|
+
const fpmmPools = await (0, poolDiscovery_1.fetchFPMMPools)(this.publicClient, this.chainId);
|
|
40
|
+
pools.push(...fpmmPools);
|
|
55
41
|
}
|
|
42
|
+
catch { }
|
|
56
43
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
address: fpmmFactoryAddress,
|
|
60
|
-
abi: abis_1.FPMM_FACTORY_ABI,
|
|
61
|
-
functionName: 'deployedFPMMAddresses',
|
|
62
|
-
}));
|
|
63
|
-
if (poolAddresses.length === 0) {
|
|
64
|
-
return [];
|
|
65
|
-
}
|
|
66
|
-
const poolDataPromises = poolAddresses.map(async (poolAddress) => {
|
|
67
|
-
const [token0, token1] = await Promise.all([
|
|
68
|
-
this.publicClient.readContract({
|
|
69
|
-
address: poolAddress,
|
|
70
|
-
abi: abis_1.FPMM_ABI,
|
|
71
|
-
functionName: 'token0',
|
|
72
|
-
}),
|
|
73
|
-
this.publicClient.readContract({
|
|
74
|
-
address: poolAddress,
|
|
75
|
-
abi: abis_1.FPMM_ABI,
|
|
76
|
-
functionName: 'token1',
|
|
77
|
-
}),
|
|
78
|
-
]);
|
|
79
|
-
return {
|
|
80
|
-
factoryAddr: fpmmFactoryAddress,
|
|
81
|
-
poolAddr: poolAddress,
|
|
82
|
-
token0: token0,
|
|
83
|
-
token1: token1,
|
|
84
|
-
poolType: types_1.PoolType.FPMM,
|
|
85
|
-
};
|
|
86
|
-
});
|
|
87
|
-
return await Promise.all(poolDataPromises);
|
|
44
|
+
const virtualPools = await (0, poolDiscovery_1.fetchVirtualPools)(this.publicClient, this.chainId);
|
|
45
|
+
pools.push(...virtualPools);
|
|
88
46
|
}
|
|
89
|
-
catch
|
|
90
|
-
|
|
91
|
-
|
|
47
|
+
catch { }
|
|
48
|
+
// Only throw if NO pools were discovered from any factory
|
|
49
|
+
if (pools.length === 0) {
|
|
50
|
+
throw new Error('Failed to discover any pools from any factory. ' +
|
|
51
|
+
'All pool factory queries failed. Check network connectivity and RPC endpoint.');
|
|
92
52
|
}
|
|
53
|
+
this.poolsCache = pools;
|
|
54
|
+
return pools;
|
|
93
55
|
}
|
|
94
56
|
/**
|
|
95
|
-
* Fetches
|
|
96
|
-
*
|
|
97
|
-
*
|
|
57
|
+
* Fetches enriched on-chain details for a specific pool by address.
|
|
58
|
+
* Resolves the pool type from the discovery cache, then fetches
|
|
59
|
+
* pool-type-specific data (pricing, fees, rebalancing for FPMM; reserves and spread for Virtual).
|
|
60
|
+
*
|
|
61
|
+
* @param poolAddr - The deployed pool contract address
|
|
62
|
+
* @returns Enriched pool details (FPMMPoolDetails or VirtualPoolDetails)
|
|
63
|
+
* @throws {Error} If the pool address is not found in any known factory
|
|
64
|
+
* @throws {Error} If on-chain calls fail
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const details = await poolService.getPoolDetails('0x...')
|
|
69
|
+
* if (details.poolType === 'FPMM') {
|
|
70
|
+
* console.log(details.pricing.oraclePrice)
|
|
71
|
+
* console.log(details.rebalancing.inBand)
|
|
72
|
+
* } else {
|
|
73
|
+
* console.log(details.spreadPercent)
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
98
76
|
*/
|
|
99
|
-
async
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
if (!
|
|
103
|
-
|
|
104
|
-
return [];
|
|
77
|
+
async getPoolDetails(poolAddr) {
|
|
78
|
+
const pools = await this.getPools();
|
|
79
|
+
const pool = pools.find((p) => p.poolAddr.toLowerCase() === poolAddr.toLowerCase());
|
|
80
|
+
if (!pool) {
|
|
81
|
+
throw new Error(`Pool not found: ${poolAddr}. ` + 'Ensure the address is a valid pool discovered by getPools().');
|
|
105
82
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
// we can simplify this by using VirtualPoolFactory.getAllPools() returns(address[])
|
|
109
|
-
// Get all exchanges from BiPoolManager
|
|
110
|
-
const exchangesData = (await this.publicClient.readContract({
|
|
111
|
-
address: biPoolManagerAddress,
|
|
112
|
-
abi: abis_1.BIPOOL_MANAGER_ABI,
|
|
113
|
-
functionName: 'getExchanges',
|
|
114
|
-
}));
|
|
115
|
-
if (exchangesData.length === 0) {
|
|
116
|
-
return [];
|
|
117
|
-
}
|
|
118
|
-
// For each exchange, check if a virtual pool exists, and if so, return the pool address.
|
|
119
|
-
const poolPromises = exchangesData.map(async (exchange) => {
|
|
120
|
-
if (exchange.assets.length !== 2) {
|
|
121
|
-
console.warn(`Skipping invalid exchange ${exchange.exchangeId}: expected 2 assets`);
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
const [token0, token1] = (0, sortUtils_1.sortTokenAddresses)(exchange.assets[0], exchange.assets[1]);
|
|
125
|
-
const poolAddress = (await this.publicClient.readContract({
|
|
126
|
-
address: virtualPoolFactoryAddress,
|
|
127
|
-
abi: abis_1.VIRTUAL_POOL_FACTORY_ABI,
|
|
128
|
-
functionName: 'getOrPrecomputeProxyAddress',
|
|
129
|
-
args: [token0, token1],
|
|
130
|
-
}));
|
|
131
|
-
const isDeployed = (await this.publicClient.readContract({
|
|
132
|
-
address: virtualPoolFactoryAddress,
|
|
133
|
-
abi: abis_1.VIRTUAL_POOL_FACTORY_ABI,
|
|
134
|
-
functionName: 'isPool',
|
|
135
|
-
args: [poolAddress],
|
|
136
|
-
}));
|
|
137
|
-
if (!isDeployed) {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
return {
|
|
141
|
-
factoryAddr: virtualPoolFactoryAddress,
|
|
142
|
-
poolAddr: poolAddress,
|
|
143
|
-
token0: token0,
|
|
144
|
-
token1: token1,
|
|
145
|
-
poolType: types_1.PoolType.Virtual,
|
|
146
|
-
};
|
|
147
|
-
});
|
|
148
|
-
const results = await Promise.all(poolPromises);
|
|
149
|
-
return results.filter((pool) => pool !== null);
|
|
83
|
+
if (pool.poolType === types_1.PoolType.FPMM) {
|
|
84
|
+
return (0, poolDetails_1.fetchFPMMPoolDetails)(this.publicClient, this.chainId, pool);
|
|
150
85
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
throw new Error(`Failed to fetch Virtual pools: ${error.message}`);
|
|
86
|
+
else {
|
|
87
|
+
return (0, poolDetails_1.fetchVirtualPoolDetails)(this.publicClient, pool);
|
|
154
88
|
}
|
|
155
89
|
}
|
|
156
90
|
}
|