@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,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TradingService = void 0;
|
|
4
|
+
const types_1 = require("../../core/types");
|
|
5
|
+
const TradingLimitsService_1 = require("./TradingLimitsService");
|
|
6
|
+
const abis_1 = require("../../core/abis");
|
|
7
|
+
const constants_1 = require("../../core/constants");
|
|
8
|
+
/**
|
|
9
|
+
* Service for checking trading status and circuit breaker state in the Mento protocol.
|
|
10
|
+
* Provides methods to query whether trading is enabled for specific rate feeds,
|
|
11
|
+
* token pairs, or routes. Also integrates trading limit checks.
|
|
12
|
+
*/
|
|
13
|
+
class TradingService {
|
|
14
|
+
constructor(publicClient, chainId, routeService) {
|
|
15
|
+
this.publicClient = publicClient;
|
|
16
|
+
this.chainId = chainId;
|
|
17
|
+
this.routeService = routeService;
|
|
18
|
+
this.tradingLimitsService = new TradingLimitsService_1.TradingLimitsService(publicClient, chainId);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Returns the current trading mode for a given rate feed.
|
|
22
|
+
*
|
|
23
|
+
* The BreakerBox uses a bitmask approach where 0 means bidirectional trading
|
|
24
|
+
* is enabled, and any non-zero value means trading is suspended.
|
|
25
|
+
*
|
|
26
|
+
* @param rateFeedId - The address of the rate feed
|
|
27
|
+
* @returns The raw trading mode value from BreakerBox (0 = enabled, non-zero = suspended)
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const mode = await tradingService.getRateFeedTradingMode(rateFeedId)
|
|
32
|
+
* if (mode === TradingMode.BIDIRECTIONAL) {
|
|
33
|
+
* console.log('Trading is enabled')
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
async getRateFeedTradingMode(rateFeedId) {
|
|
38
|
+
const breakerBoxAddr = (0, constants_1.getContractAddress)(this.chainId, 'BreakerBox');
|
|
39
|
+
const mode = await this.publicClient.readContract({
|
|
40
|
+
address: breakerBoxAddr,
|
|
41
|
+
abi: abis_1.BREAKERBOX_ABI,
|
|
42
|
+
functionName: 'getRateFeedTradingMode',
|
|
43
|
+
args: [rateFeedId],
|
|
44
|
+
});
|
|
45
|
+
return Number(mode);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Checks if a trading pair is currently tradable.
|
|
49
|
+
* For multi-hop routes (e.g., CELO → USDm → USDT), checks that ALL
|
|
50
|
+
* intermediate rate feeds are in BIDIRECTIONAL mode.
|
|
51
|
+
*
|
|
52
|
+
* @param tokenIn - Input token address
|
|
53
|
+
* @param tokenOut - Output token address
|
|
54
|
+
* @returns true if the pair is tradable (all rate feeds BIDIRECTIONAL), false otherwise
|
|
55
|
+
* @throws {RouteNotFoundError} If no route exists between the token pair
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const isTradable = await tradingService.isPairTradable(USDm, CELO)
|
|
60
|
+
* if (!isTradable) {
|
|
61
|
+
* console.log('Trading is currently suspended for this pair')
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
async isPairTradable(tokenIn, tokenOut) {
|
|
66
|
+
const route = await this.routeService.findRoute(tokenIn, tokenOut);
|
|
67
|
+
return this.isRouteTradable(route);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Checks if a route is currently tradable.
|
|
71
|
+
* Verifies that all pools in the route's path have their rate feeds
|
|
72
|
+
* in BIDIRECTIONAL mode.
|
|
73
|
+
*
|
|
74
|
+
* @param route - The route to check
|
|
75
|
+
* @returns true if all pools in the route are tradable, false otherwise
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const route = await routeService.findRoute(tokenIn, tokenOut)
|
|
80
|
+
* const isRouteTradable = await tradingService.isRouteTradable(route)
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
async isRouteTradable(route) {
|
|
84
|
+
// Get rate feed IDs for each pool in the path and check trading modes
|
|
85
|
+
const rateFeedChecks = await Promise.all(route.path.map(async (pool) => {
|
|
86
|
+
const rateFeedId = await this.getPoolRateFeedId(pool);
|
|
87
|
+
const tradingMode = await this.getRateFeedTradingMode(rateFeedId);
|
|
88
|
+
return (0, types_1.isTradingEnabled)(tradingMode);
|
|
89
|
+
}));
|
|
90
|
+
// All rate feeds must have trading enabled for the route to be tradable
|
|
91
|
+
return rateFeedChecks.every((isEnabled) => isEnabled);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get trading limits for a pool.
|
|
95
|
+
*
|
|
96
|
+
* @param pool - The pool to get trading limits for
|
|
97
|
+
* @returns Array of TradingLimit objects with maxIn/maxOut/until
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const limits = await tradingService.getPoolTradingLimits(pool)
|
|
102
|
+
* limits.forEach(limit => {
|
|
103
|
+
* console.log(`${limit.asset}: maxIn=${limit.maxIn}, maxOut=${limit.maxOut}`)
|
|
104
|
+
* })
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
async getPoolTradingLimits(pool) {
|
|
108
|
+
return this.tradingLimitsService.getPoolTradingLimits(pool);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get complete tradability status for a pool.
|
|
112
|
+
* Returns separate flags for circuit breaker and trading limits,
|
|
113
|
+
* allowing frontends to show different messages for each condition.
|
|
114
|
+
*
|
|
115
|
+
* @param pool - The pool to check
|
|
116
|
+
* @returns PoolTradabilityStatus with tradable, circuitBreakerOk, limitsOk, and limits
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const status = await tradingService.getPoolTradabilityStatus(pool)
|
|
121
|
+
* if (!status.circuitBreakerOk) {
|
|
122
|
+
* showModal("Trading temporarily suspended (circuit breaker)")
|
|
123
|
+
* } else if (!status.limitsOk) {
|
|
124
|
+
* showModal("Trading limit reached", status.limits)
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
async getPoolTradabilityStatus(pool) {
|
|
129
|
+
const [rateFeedId, limits] = await Promise.all([
|
|
130
|
+
this.getPoolRateFeedId(pool),
|
|
131
|
+
this.tradingLimitsService.getPoolTradingLimits(pool),
|
|
132
|
+
]);
|
|
133
|
+
const tradingMode = await this.getRateFeedTradingMode(rateFeedId);
|
|
134
|
+
const circuitBreakerOk = (0, types_1.isTradingEnabled)(tradingMode);
|
|
135
|
+
// Limits are OK if no limits configured OR all limits have capacity
|
|
136
|
+
const limitsOk = limits.length === 0 || limits.every((l) => l.maxIn > 0n && l.maxOut > 0n);
|
|
137
|
+
return {
|
|
138
|
+
tradable: circuitBreakerOk && limitsOk,
|
|
139
|
+
circuitBreakerOk,
|
|
140
|
+
tradingMode,
|
|
141
|
+
limitsOk,
|
|
142
|
+
limits,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get the reference rate feed ID for a pool.
|
|
147
|
+
* Both FPMM and Virtual pools expose this via the referenceRateFeedID() view function.
|
|
148
|
+
*
|
|
149
|
+
* @param pool - The pool to get rate feed ID for
|
|
150
|
+
* @returns The rate feed ID address
|
|
151
|
+
*/
|
|
152
|
+
async getPoolRateFeedId(pool) {
|
|
153
|
+
const rateFeedId = await this.publicClient.readContract({
|
|
154
|
+
address: pool.poolAddr,
|
|
155
|
+
abi: abis_1.FPMM_ABI,
|
|
156
|
+
functionName: 'referenceRateFeedID',
|
|
157
|
+
});
|
|
158
|
+
return rateFeedId;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.TradingService = TradingService;
|
|
162
|
+
//# sourceMappingURL=TradingService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TradingService.js","sourceRoot":"","sources":["../../../src/services/trading/TradingService.ts"],"names":[],"mappings":";;;AACA,4CAMyB;AAEzB,iEAA6D;AAC7D,0CAA0D;AAC1D,oDAAkE;AAElE;;;;GAIG;AACH,MAAa,cAAc;IAGzB,YACU,YAA0B,EAC1B,OAAe,EACf,YAA0B;QAF1B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,YAAO,GAAP,O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CAAA;IAC7B,CAAC;CACF;AArKD,wCAqKC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/trading/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./TradingService"), exports);
|
|
18
|
+
__exportStar(require("./TradingLimitsService"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/trading/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC;AAChC,yDAAsC"}
|
package/dist/utils/costUtils.js
CHANGED
|
@@ -40,9 +40,9 @@ async function getFPMMCostPercent(poolAddress, publicClient) {
|
|
|
40
40
|
functionName: 'protocolFee',
|
|
41
41
|
}),
|
|
42
42
|
]);
|
|
43
|
-
// Convert from basis points to percentage
|
|
43
|
+
// Convert from basis points to percentage, rounded to 8dp for precision
|
|
44
44
|
const totalBasisPoints = Number(lpFee) + Number(protocolFee);
|
|
45
|
-
return totalBasisPoints / 100;
|
|
45
|
+
return Math.round((totalBasisPoints / 100) * 1e8) / 1e8;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Calculate cost for Virtual pools
|
|
@@ -53,7 +53,7 @@ async function getVirtualPoolCostPercent(poolAddress, publicClient) {
|
|
|
53
53
|
abi: virtualPool_1.VIRTUAL_POOL_ABI,
|
|
54
54
|
functionName: 'protocolFee',
|
|
55
55
|
});
|
|
56
|
-
//
|
|
57
|
-
return Number(protocolFee) / 100;
|
|
56
|
+
// Convert from basis points to percentage, rounded to 8dp for precision
|
|
57
|
+
return Math.round((Number(protocolFee) / 100) * 1e8) / 1e8;
|
|
58
58
|
}
|
|
59
59
|
//# sourceMappingURL=costUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"costUtils.js","sourceRoot":"","sources":["../../src/utils/costUtils.ts"],"names":[],"mappings":";;AAaA,gDAQC;AArBD,yCAA8C;AAC9C,uCAAuC;AAEvC,0DAA2D;AAE3D;;;;;;;GAOG;AACI,KAAK,UAAU,kBAAkB,CAAC,IAAU,EAAE,YAA0B;IAC7E,IAAI,IAAI,CAAC,QAAQ,KAAK,gBAAQ,CAAC,IAAI,EAAE,CAAC;QACpC,OAAO,kBAAkB,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;IACxD,CAAC;SAAM,IAAI,IAAI,CAAC,QAAQ,KAAK,gBAAQ,CAAC,OAAO,EAAE,CAAC;QAC9C,OAAO,yBAAyB,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;IAC/D,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;IACtC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,k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CAAoB;QACrB,YAAY,CAAC,YAAY,CAAC;YACxB,OAAO,EAAE,WAA4B;YACrC,GAAG,EAAE,eAAQ;YACb,YAAY,EAAE,aAAa;SAC5B,CAAoB;KACtB,CAAC,CAAA;IAEF,wEAAwE;IACxE,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA;IAC5D,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,gBAAgB,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAA;AACzD,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,yBAAyB,CAAC,WAAmB,EAAE,YAA0B;IACtF,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,YAAY,CAAC;QAClD,OAAO,EAAE,WAA4B;QACrC,GAAG,EAAE,8BAAgB;QACrB,YAAY,EAAE,aAAa;KAC5B,CAAC,CAAA;IAEF,wEAAwE;IACxE,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAA;AAC5D,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA"}
|
package/dist/utils/index.js
CHANGED
|
@@ -19,4 +19,7 @@ __exportStar(require("./chainConfig"), exports);
|
|
|
19
19
|
__exportStar(require("./routes"), exports);
|
|
20
20
|
__exportStar(require("./sortUtils"), exports);
|
|
21
21
|
__exportStar(require("./pathEncoder"), exports);
|
|
22
|
+
__exportStar(require("./tokens"), exports);
|
|
23
|
+
__exportStar(require("./rateFeed"), exports);
|
|
24
|
+
__exportStar(require("./tradingLimits"), exports);
|
|
22
25
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,gDAA6B;AAC7B,2CAAwB;AACxB,8CAA2B;AAC3B,gDAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,gDAA6B;AAC7B,2CAAwB;AACxB,8CAA2B;AAC3B,gDAA6B;AAC7B,2CAAwB;AACxB,6CAA0B;AAC1B,kDAA+B"}
|
|
@@ -16,11 +16,12 @@ export interface RouterRoute {
|
|
|
16
16
|
* @param tokenIn - The input token address (determines swap direction)
|
|
17
17
|
* @param _tokenOut - The output token address (unused but kept for API clarity)
|
|
18
18
|
* @returns Array of RouterRoute objects for the contract call
|
|
19
|
+
* @throws {Error} If path is empty, too long, or contains invalid pools
|
|
19
20
|
*
|
|
20
21
|
* @example
|
|
21
22
|
* ```typescript
|
|
22
|
-
* const route = await routeService.findRoute(
|
|
23
|
-
* const routerRoutes = encodeRoutePath(route.path,
|
|
23
|
+
* const route = await routeService.findRoute(USDm, CELO)
|
|
24
|
+
* const routerRoutes = encodeRoutePath(route.path, USDm, CELO)
|
|
24
25
|
* // routerRoutes can now be passed to Router.getAmountsOut or Router.swapTokensForTokens
|
|
25
26
|
* ```
|
|
26
27
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathEncoder.d.ts","sourceRoot":"","sources":["../../src/utils/pathEncoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAEpC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,OAAO,CAAA;IACb,EAAE,EAAE,OAAO,CAAA;IACX,OAAO,EAAE,OAAO,CAAA;CACjB;AAED
|
|
1
|
+
{"version":3,"file":"pathEncoder.d.ts","sourceRoot":"","sources":["../../src/utils/pathEncoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAEpC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,OAAO,CAAA;IACb,EAAE,EAAE,OAAO,CAAA;IACX,OAAO,EAAE,OAAO,CAAA;CACjB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,GAAG,WAAW,EAAE,CAmEjG"}
|
|
@@ -9,15 +9,29 @@ exports.encodeRoutePath = encodeRoutePath;
|
|
|
9
9
|
* @param tokenIn - The input token address (determines swap direction)
|
|
10
10
|
* @param _tokenOut - The output token address (unused but kept for API clarity)
|
|
11
11
|
* @returns Array of RouterRoute objects for the contract call
|
|
12
|
+
* @throws {Error} If path is empty, too long, or contains invalid pools
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
14
15
|
* ```typescript
|
|
15
|
-
* const route = await routeService.findRoute(
|
|
16
|
-
* const routerRoutes = encodeRoutePath(route.path,
|
|
16
|
+
* const route = await routeService.findRoute(USDm, CELO)
|
|
17
|
+
* const routerRoutes = encodeRoutePath(route.path, USDm, CELO)
|
|
17
18
|
* // routerRoutes can now be passed to Router.getAmountsOut or Router.swapTokensForTokens
|
|
18
19
|
* ```
|
|
19
20
|
*/
|
|
20
21
|
function encodeRoutePath(path, tokenIn, _tokenOut) {
|
|
22
|
+
// Validate path is not empty
|
|
23
|
+
if (!path || path.length === 0) {
|
|
24
|
+
throw new Error('Internal error: Route path is empty. This should not happen - routes are validated before encoding.');
|
|
25
|
+
}
|
|
26
|
+
// Validate all pools have required structure
|
|
27
|
+
for (let i = 0; i < path.length; i++) {
|
|
28
|
+
const pool = path[i];
|
|
29
|
+
if (!pool.token0 || !pool.token1 || !pool.factoryAddr) {
|
|
30
|
+
throw new Error(`Invalid pool structure at index ${i}: missing required fields. ` +
|
|
31
|
+
`Pool must have token0, token1, and factoryAddr. ` +
|
|
32
|
+
`Got: ${JSON.stringify(pool)}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
21
35
|
const routes = [];
|
|
22
36
|
const tokenInLower = tokenIn.toLowerCase();
|
|
23
37
|
// Check if we need to reverse the path
|
|
@@ -42,7 +56,9 @@ function encodeRoutePath(path, tokenIn, _tokenOut) {
|
|
|
42
56
|
to = pool.token0;
|
|
43
57
|
}
|
|
44
58
|
else {
|
|
45
|
-
throw new Error(`Token ${currentTokenIn} not found in pool ${pool.poolAddr}`
|
|
59
|
+
throw new Error(`Route encoding error: Token ${currentTokenIn} not found in pool ${pool.poolAddr}. ` +
|
|
60
|
+
`Pool contains tokens: ${token0}, ${token1}. ` +
|
|
61
|
+
`This indicates the route path is invalid or tokens don't form a connected path.`);
|
|
46
62
|
}
|
|
47
63
|
routes.push({
|
|
48
64
|
from,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathEncoder.js","sourceRoot":"","sources":["../../src/utils/pathEncoder.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"pathEncoder.js","sourceRoot":"","sources":["../../src/utils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I,WAAW,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAA;QACxC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAA;QAExC,8DAA8D;QAC9D,IAAI,IAAa,CAAA;QACjB,IAAI,EAAW,CAAA;QAEf,IAAI,cAAc,KAAK,MAAM,EAAE,CAAC;YAC9B,IAAI,GAAG,IAAI,CAAC,MAAiB,CAAA;YAC7B,EAAE,GAAG,IAAI,CAAC,MAAiB,CAAA;QAC7B,CAAC;aAAM,IAAI,cAAc,KAAK,MAAM,EAAE,CAAC;YACrC,IAAI,GAAG,IAAI,CAAC,MAAiB,CAAA;YAC7B,EAAE,GAAG,IAAI,CAAC,MAAiB,CAAA;QAC7B,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CACb,+BAA+B,cAAc,sBAAsB,IAAI,CAAC,QAAQ,IAAI;gBACpF,yBAAyB,MAAM,KAAK,MAAM,IAAI;gBAC9C,iFAAiF,CAClF,CAAA;QACH,CAAC;QAED,MAAM,CAAC,IAAI,CAAC;YACV,IAAI;YACJ,EAAE;YACF,OAAO,EAAE,IAAI,CAAC,WAAsB;SACrC,CAAC,CAAA;QAEF,2DAA2D;QAC3D,cAAc,GAAG,EAAE,CAAC,WAAW,EAAE,CAAA;IACnC,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the rate feed ID from a rate feed identifier string.
|
|
3
|
+
* Follows the Solidity formula: address(uint160(uint256(keccak256(abi.encodePacked(rateFeed)))))
|
|
4
|
+
*
|
|
5
|
+
* @param rateFeed - The rate feed identifier string (e.g., "EURUSD", "relayed:COPUSD")
|
|
6
|
+
* @returns The computed rate feed address as a hex string
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const rateFeedId = toRateFeedId('EURUSD')
|
|
11
|
+
* // Returns the computed address for the EURUSD rate feed
|
|
12
|
+
*
|
|
13
|
+
* const relayedRateFeedId = toRateFeedId('relayed:COPUSD')
|
|
14
|
+
* // Returns the computed address for the relayed COPUSD rate feed
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function toRateFeedId(rateFeed: string): `0x${string}`;
|
|
18
|
+
//# sourceMappingURL=rateFeed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rateFeed.d.ts","sourceRoot":"","sources":["../../src/utils/rateFeed.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,MAAM,EAAE,CAM5D"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toRateFeedId = toRateFeedId;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
/**
|
|
6
|
+
* Computes the rate feed ID from a rate feed identifier string.
|
|
7
|
+
* Follows the Solidity formula: address(uint160(uint256(keccak256(abi.encodePacked(rateFeed)))))
|
|
8
|
+
*
|
|
9
|
+
* @param rateFeed - The rate feed identifier string (e.g., "EURUSD", "relayed:COPUSD")
|
|
10
|
+
* @returns The computed rate feed address as a hex string
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const rateFeedId = toRateFeedId('EURUSD')
|
|
15
|
+
* // Returns the computed address for the EURUSD rate feed
|
|
16
|
+
*
|
|
17
|
+
* const relayedRateFeedId = toRateFeedId('relayed:COPUSD')
|
|
18
|
+
* // Returns the computed address for the relayed COPUSD rate feed
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function toRateFeedId(rateFeed) {
|
|
22
|
+
const hashedBytes = (0, viem_1.keccak256)((0, viem_1.toBytes)(rateFeed));
|
|
23
|
+
const hashAsBigInt = BigInt(hashedBytes);
|
|
24
|
+
const maskedToUint160 = hashAsBigInt & ((1n << 160n) - 1n);
|
|
25
|
+
return `0x${maskedToUint160.toString(16).padStart(40, '0')}`;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=rateFeed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rateFeed.js","sourceRoot":"","sources":["../../src/utils/rateFeed.ts"],"names":[],"mappings":";;AAkBA,oCAMC;AAxBD,+BAAyC;AAEzC;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,YAAY,CAAC,QAAgB;IAC3C,MAAM,WAAW,GAAG,IAAA,gBAAS,EAAC,IAAA,cAAO,EAAC,QAAQ,CAAC,CAAC,CAAA;IAChD,MAAM,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA;IACxC,MAAM,eAAe,GAAG,YAAY,GAAG,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;IAE1D,OAAO,KAAK,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAA;AAC9D,CAAC"}
|
|
@@ -27,15 +27,15 @@ type Address = string;
|
|
|
27
27
|
*
|
|
28
28
|
* CONCRETE EXAMPLE:
|
|
29
29
|
* Given these direct trading pairs:
|
|
30
|
-
* -
|
|
31
|
-
* - CELO ↔
|
|
32
|
-
* -
|
|
30
|
+
* - USDm ↔ CELO (direct exchange exists)
|
|
31
|
+
* - CELO ↔ EURm (direct exchange exists)
|
|
32
|
+
* - USDm ↔ BRLm (direct exchange exists)
|
|
33
33
|
*
|
|
34
34
|
* How route finding works:
|
|
35
|
-
* - Direct route:
|
|
36
|
-
* - Two-hop route:
|
|
37
|
-
* -
|
|
38
|
-
* -
|
|
35
|
+
* - Direct route: USDm → EURm? Check token graph: USDm connects to [CELO, BRLm], none is EURm → No direct route
|
|
36
|
+
* - Two-hop route: USDm → ? → EURm?
|
|
37
|
+
* - USDm connects to CELO, CELO connects to EURm → Found route: USDm → CELO → EURm
|
|
38
|
+
* - USDm connects to BRLm, BRLm connects to [USDm] → No route via BRLm
|
|
39
39
|
*
|
|
40
40
|
* The "connectivity" part means we can quickly traverse the network of
|
|
41
41
|
* token connections to find all possible trading paths.
|
|
@@ -44,31 +44,31 @@ export interface ConnectivityData {
|
|
|
44
44
|
/** Maps token address to symbol for efficient lookups
|
|
45
45
|
*
|
|
46
46
|
* ```
|
|
47
|
-
* '0x765D...' → '
|
|
47
|
+
* '0x765D...' → 'USDm'
|
|
48
48
|
* '0x471E...' → 'CELO'
|
|
49
|
-
* '0xD876...' → '
|
|
49
|
+
* '0xD876...' → 'EURm'
|
|
50
50
|
* ```
|
|
51
51
|
*/
|
|
52
52
|
addrToSymbol: Map<Address, TokenSymbol>;
|
|
53
53
|
/** Adjacency list mapping which tokens connect to which
|
|
54
54
|
* Used for finding two-hop routes by traversing token → neighbor → neighbor.
|
|
55
55
|
*
|
|
56
|
-
* Example for a
|
|
57
|
-
* Then we find CELO → [
|
|
56
|
+
* Example for a USDm => EURm swap: First we find USDm → [CELO, KESm, ...]
|
|
57
|
+
* Then we find CELO → [USDm, EURm, ...] = found route via USDm → CELO → EURm
|
|
58
58
|
*
|
|
59
59
|
* ```
|
|
60
|
-
* '
|
|
61
|
-
* 'CELO_addr' → Set(['
|
|
62
|
-
* '
|
|
63
|
-
* '
|
|
60
|
+
* 'USDm_addr' → Set(['CELO_addr', 'KESm_addr']) // USDm connects to CELO and KESm
|
|
61
|
+
* 'CELO_addr' → Set(['USDm_addr', 'EURm_addr']) // CELO connects to USDm and EURm
|
|
62
|
+
* 'EURm_addr' → Set(['CELO_addr']) // EURm connects to CELO
|
|
63
|
+
* 'KESm_addr' → Set(['USDm_addr']) // KESm connects to USDm
|
|
64
64
|
* ```
|
|
65
65
|
*/
|
|
66
66
|
tokenGraph: Map<Address, Set<Address>>;
|
|
67
67
|
/** Maps sorted token address pairs to their direct route details
|
|
68
68
|
* ```
|
|
69
|
-
* 'CELO_addr-
|
|
70
|
-
* 'CELO_addr-
|
|
71
|
-
* '
|
|
69
|
+
* 'CELO_addr-EURm_addr' → { route details for CELO ↔ EURm }
|
|
70
|
+
* 'CELO_addr-USDm_addr' → { route details for CELO ↔ USDm }
|
|
71
|
+
* 'USDm_addr-KESm_addr' → { route details for USDm ↔ KESm }
|
|
72
72
|
* ```
|
|
73
73
|
*/
|
|
74
74
|
directRouteMap: Map<RouteID, Pool>;
|
|
@@ -85,23 +85,23 @@ export interface ConnectivityData {
|
|
|
85
85
|
*
|
|
86
86
|
* ```
|
|
87
87
|
* Input: TradablePairs = [
|
|
88
|
-
* { id: '
|
|
89
|
-
* { id: 'CELO-
|
|
88
|
+
* { id: 'USDm-CELO', assets: [USDm, CELO], path: [exchange1_CELO_USDm] },
|
|
89
|
+
* { id: 'CELO-EURm', assets: [CELO, EURm], path: [exchange2_CELO_EURm] }
|
|
90
90
|
* ]
|
|
91
91
|
*
|
|
92
92
|
* Step 1 - Build addrToSymbol map:
|
|
93
|
-
*
|
|
93
|
+
* USDm.address → 'USDm'
|
|
94
94
|
* CELO.address → 'CELO'
|
|
95
|
-
*
|
|
95
|
+
* EURm.address → 'EURm'
|
|
96
96
|
*
|
|
97
97
|
* Step 2 - Build directPathMap (sorted alphabetically for consistency):
|
|
98
|
-
* 'CELO_addr-
|
|
99
|
-
* 'CELO_addr-
|
|
98
|
+
* 'CELO_addr-EURm_addr' → exchange2_CELO_EURm
|
|
99
|
+
* 'CELO_addr-USDm_addr' → exchange1_CELO_USDm
|
|
100
100
|
*
|
|
101
101
|
* Step 3 - Build bidirectional tokenGraph:
|
|
102
|
-
*
|
|
103
|
-
* CELO.address → Set([
|
|
104
|
-
*
|
|
102
|
+
* USDm.address → Set([CELO.address])
|
|
103
|
+
* CELO.address → Set([USDm.address, EURm.address])
|
|
104
|
+
* EURm.address → Set([CELO.address])
|
|
105
105
|
* ```
|
|
106
106
|
*
|
|
107
107
|
* **Result**: We can now efficiently answer:
|
|
@@ -115,17 +115,17 @@ export interface ConnectivityData {
|
|
|
115
115
|
* @example
|
|
116
116
|
* ```typescript
|
|
117
117
|
* const directPairs = [
|
|
118
|
-
* { id: '
|
|
119
|
-
* { id: 'CELO-
|
|
118
|
+
* { id: 'USDm-CELO', assets: [USDm, CELO], path: [exchange1] },
|
|
119
|
+
* { id: 'CELO-EURm', assets: [CELO, EURm], path: [exchange2] }
|
|
120
120
|
* ]
|
|
121
121
|
*
|
|
122
122
|
* const connectivityData = buildConnectivityStructures(directPairs)
|
|
123
123
|
*
|
|
124
124
|
* // Now we can efficiently find routes:
|
|
125
|
-
* // 1. Check if
|
|
126
|
-
* // 2. Check if CELO connects to
|
|
127
|
-
* // 3. Get exchange details: connectivityData.directPathMap.get('CELO_addr-
|
|
128
|
-
* // Result: Found route
|
|
125
|
+
* // 1. Check if USDm connects to anything: connectivityData.tokenGraph.get(USDm.address) → [CELO.address]
|
|
126
|
+
* // 2. Check if CELO connects to EURm: connectivityData.tokenGraph.get(CELO.address) → [USDm.address, EURm.address] ✓
|
|
127
|
+
* // 3. Get exchange details: connectivityData.directPathMap.get('CELO_addr-EURm_addr') → exchange2_CELO_EURm
|
|
128
|
+
* // Result: Found route USDm → CELO → EURm with exchange details
|
|
129
129
|
* ```
|
|
130
130
|
*/
|
|
131
131
|
export declare function buildConnectivityStructures(directRoutes: Route[]): ConnectivityData;
|
|
@@ -145,21 +145,21 @@ export declare function buildConnectivityStructures(directRoutes: Route[]): Conn
|
|
|
145
145
|
* the best one based on cost data or heuristics.
|
|
146
146
|
*
|
|
147
147
|
* **Canonical Route IDs**: All routes use alphabetically sorted symbols
|
|
148
|
-
* (e.g., '
|
|
148
|
+
* (e.g., 'EURm-USDm' not 'USDm-EURm') for consistent identification.
|
|
149
149
|
*
|
|
150
150
|
* @param connectivityData - The connectivity data from buildConnectivityStructures()
|
|
151
151
|
* @returns Map of route ID -> array of possible routes for that token pair
|
|
152
152
|
*
|
|
153
153
|
* @example
|
|
154
154
|
* ```typescript
|
|
155
|
-
* // Given direct routes:
|
|
155
|
+
* // Given direct routes: USDm-CELO, CELO-EURm, USDm-USDC
|
|
156
156
|
* const allRoutes = generateAllRoutes(connectivityData)
|
|
157
157
|
*
|
|
158
158
|
* // Results might include:
|
|
159
|
-
* // '
|
|
160
|
-
* // '
|
|
161
|
-
* // { path: [
|
|
162
|
-
* // { path: [
|
|
159
|
+
* // 'USDm-CELO' -> [{ path: [USDm->CELO] }] // direct route
|
|
160
|
+
* // 'EURm-USDm' -> [
|
|
161
|
+
* // { path: [USDm->USDC, USDC->EURm] } // two-hop via USDC
|
|
162
|
+
* // { path: [USDm->CELO, CELO->EURm] } // two-hop via CELO
|
|
163
163
|
* // ]
|
|
164
164
|
* ```
|
|
165
165
|
*/
|
|
@@ -187,22 +187,22 @@ export declare function generateAllRoutes(connectivityData: ConnectivityData): M
|
|
|
187
187
|
*
|
|
188
188
|
* @example
|
|
189
189
|
* ```typescript
|
|
190
|
-
* // Create route:
|
|
190
|
+
* // Create route: USDm -> CELO -> EURm
|
|
191
191
|
* const pair = createTwoHopPair(
|
|
192
|
-
* '0x765D...', //
|
|
192
|
+
* '0x765D...', // USDm address
|
|
193
193
|
* '0x471E...', // CELO address
|
|
194
|
-
* '0xD876...', //
|
|
194
|
+
* '0xD876...', // EURm address
|
|
195
195
|
* addrToSymbol,
|
|
196
196
|
* directPathMap
|
|
197
197
|
* )
|
|
198
198
|
*
|
|
199
199
|
* // Result:
|
|
200
200
|
* // {
|
|
201
|
-
* // id: '
|
|
202
|
-
* // assets: [
|
|
201
|
+
* // id: 'EURm-USDm', // alphabetical order
|
|
202
|
+
* // assets: [EURm, USDm], // alphabetical order
|
|
203
203
|
* // path: [ // actual routing path
|
|
204
|
-
* // {
|
|
205
|
-
* // { CELO->
|
|
204
|
+
* // { USDm->CELO exchange },
|
|
205
|
+
* // { CELO->EURm exchange }
|
|
206
206
|
* // ]
|
|
207
207
|
* // }
|
|
208
208
|
* ```
|
|
@@ -229,17 +229,17 @@ export declare function createTwoHopRoute(startAddr: Address, intermediateAddr:
|
|
|
229
229
|
*
|
|
230
230
|
* @example
|
|
231
231
|
* ```typescript
|
|
232
|
-
* // Multiple routes for
|
|
232
|
+
* // Multiple routes for USDm-EURm pair
|
|
233
233
|
* const candidates = new Map([
|
|
234
|
-
* ['
|
|
235
|
-
* { path: [
|
|
236
|
-
* { path: [
|
|
237
|
-
* { path: [
|
|
234
|
+
* ['EURm-USDm', [
|
|
235
|
+
* { path: [USDm->CELO->EURm], costData: { totalCostPercent: 0.5 } },
|
|
236
|
+
* { path: [USDm->BRLm->EURm], costData: { totalCostPercent: 0.3 } },
|
|
237
|
+
* { path: [USDm->EURm] } // direct route, no cost data
|
|
238
238
|
* ]]
|
|
239
239
|
* ])
|
|
240
240
|
*
|
|
241
241
|
* const optimal = selectOptimalRoutes(candidates, false, assetMap)
|
|
242
|
-
* // Returns the
|
|
242
|
+
* // Returns the USDm->BRLm->EURm route (lowest cost: 0.3%)
|
|
243
243
|
* ```
|
|
244
244
|
*/
|
|
245
245
|
export declare function selectOptimalRoutes(allRoutes: Map<RouteID, Route[]>, returnAllRoutes: boolean, addrToSymbol: Map<Address, TokenSymbol>): (Route | RouteWithCost)[];
|
|
@@ -260,7 +260,7 @@ export declare function selectOptimalRoutes(allRoutes: Map<RouteID, Route[]>, re
|
|
|
260
260
|
*
|
|
261
261
|
* **Tier 3 - Major Stablecoin Preference** (Final Fallback):
|
|
262
262
|
* - For two-hop routes, prefer those going through major stablecoins
|
|
263
|
-
* - Major FX currencies like
|
|
263
|
+
* - Major FX currencies like USDm and EURm typically have better liquidity
|
|
264
264
|
*
|
|
265
265
|
* **Tier 4 - First Available** (Last Resort):
|
|
266
266
|
* - If no other heuristics apply, use the first route found
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routeUtils.d.ts","sourceRoot":"","sources":["../../src/utils/routeUtils.ts"],"names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