@mento-protocol/mento-sdk 3.0.0-beta.6 → 3.0.0-beta.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/README.md +34 -0
- package/dist/cache/routes.d.ts.map +1 -1
- package/dist/cache/routes.js +2 -4
- package/dist/cache/routes.js.map +1 -1
- 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/constants/aaveConfig.js +2 -2
- package/dist/core/constants/addresses.d.ts.map +1 -1
- package/dist/core/constants/addresses.js +3 -1
- package/dist/core/constants/addresses.js.map +1 -1
- package/dist/core/types/provider.d.ts +45 -0
- package/dist/core/types/provider.d.ts.map +1 -0
- package/dist/core/types/provider.js +3 -0
- package/dist/core/types/provider.js.map +1 -0
- 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/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/services/pools/PoolService.d.ts +1 -1
- package/dist/services/pools/PoolService.d.ts.map +1 -1
- package/dist/services/pools/PoolService.js +17 -11
- package/dist/services/pools/PoolService.js.map +1 -1
- 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 -11
- 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 -14
- 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/TradingService.d.ts +1 -1
- package/dist/services/trading/TradingService.js +1 -1
- package/dist/utils/costUtils.js +4 -4
- package/dist/utils/costUtils.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/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/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
|
@@ -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":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,
|
|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GACjC,KAAK,GAAG,IAAI,CAgCd;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,EAChC,eAAe,EAAE,OAAO,EACxB,YAAY,EAAE,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,GACtC,CAAC,KAAK,GAAG,aAAa,CAAC,EAAE,CAoB3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,YAAY,EAAE,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,KAAK,GAAG,aAAa,CAwBnH;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,GAAG,SAAS,CAMtE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,KAAK,GAAG,aAAa,GAAG,IAAI,IAAI,aAAa,CAE9E"}
|
package/dist/utils/routeUtils.js
CHANGED
|
@@ -18,23 +18,23 @@ const sortUtils_1 = require("./sortUtils");
|
|
|
18
18
|
*
|
|
19
19
|
* ```
|
|
20
20
|
* Input: TradablePairs = [
|
|
21
|
-
* { id: '
|
|
22
|
-
* { id: 'CELO-
|
|
21
|
+
* { id: 'USDm-CELO', assets: [USDm, CELO], path: [exchange1_CELO_USDm] },
|
|
22
|
+
* { id: 'CELO-EURm', assets: [CELO, EURm], path: [exchange2_CELO_EURm] }
|
|
23
23
|
* ]
|
|
24
24
|
*
|
|
25
25
|
* Step 1 - Build addrToSymbol map:
|
|
26
|
-
*
|
|
26
|
+
* USDm.address → 'USDm'
|
|
27
27
|
* CELO.address → 'CELO'
|
|
28
|
-
*
|
|
28
|
+
* EURm.address → 'EURm'
|
|
29
29
|
*
|
|
30
30
|
* Step 2 - Build directPathMap (sorted alphabetically for consistency):
|
|
31
|
-
* 'CELO_addr-
|
|
32
|
-
* 'CELO_addr-
|
|
31
|
+
* 'CELO_addr-EURm_addr' → exchange2_CELO_EURm
|
|
32
|
+
* 'CELO_addr-USDm_addr' → exchange1_CELO_USDm
|
|
33
33
|
*
|
|
34
34
|
* Step 3 - Build bidirectional tokenGraph:
|
|
35
|
-
*
|
|
36
|
-
* CELO.address → Set([
|
|
37
|
-
*
|
|
35
|
+
* USDm.address → Set([CELO.address])
|
|
36
|
+
* CELO.address → Set([USDm.address, EURm.address])
|
|
37
|
+
* EURm.address → Set([CELO.address])
|
|
38
38
|
* ```
|
|
39
39
|
*
|
|
40
40
|
* **Result**: We can now efficiently answer:
|
|
@@ -48,17 +48,17 @@ const sortUtils_1 = require("./sortUtils");
|
|
|
48
48
|
* @example
|
|
49
49
|
* ```typescript
|
|
50
50
|
* const directPairs = [
|
|
51
|
-
* { id: '
|
|
52
|
-
* { id: 'CELO-
|
|
51
|
+
* { id: 'USDm-CELO', assets: [USDm, CELO], path: [exchange1] },
|
|
52
|
+
* { id: 'CELO-EURm', assets: [CELO, EURm], path: [exchange2] }
|
|
53
53
|
* ]
|
|
54
54
|
*
|
|
55
55
|
* const connectivityData = buildConnectivityStructures(directPairs)
|
|
56
56
|
*
|
|
57
57
|
* // Now we can efficiently find routes:
|
|
58
|
-
* // 1. Check if
|
|
59
|
-
* // 2. Check if CELO connects to
|
|
60
|
-
* // 3. Get exchange details: connectivityData.directPathMap.get('CELO_addr-
|
|
61
|
-
* // Result: Found route
|
|
58
|
+
* // 1. Check if USDm connects to anything: connectivityData.tokenGraph.get(USDm.address) → [CELO.address]
|
|
59
|
+
* // 2. Check if CELO connects to EURm: connectivityData.tokenGraph.get(CELO.address) → [USDm.address, EURm.address] ✓
|
|
60
|
+
* // 3. Get exchange details: connectivityData.directPathMap.get('CELO_addr-EURm_addr') → exchange2_CELO_EURm
|
|
61
|
+
* // Result: Found route USDm → CELO → EURm with exchange details
|
|
62
62
|
* ```
|
|
63
63
|
*/
|
|
64
64
|
function buildConnectivityStructures(directRoutes) {
|
|
@@ -103,21 +103,21 @@ function buildConnectivityStructures(directRoutes) {
|
|
|
103
103
|
* the best one based on cost data or heuristics.
|
|
104
104
|
*
|
|
105
105
|
* **Canonical Route IDs**: All routes use alphabetically sorted symbols
|
|
106
|
-
* (e.g., '
|
|
106
|
+
* (e.g., 'EURm-USDm' not 'USDm-EURm') for consistent identification.
|
|
107
107
|
*
|
|
108
108
|
* @param connectivityData - The connectivity data from buildConnectivityStructures()
|
|
109
109
|
* @returns Map of route ID -> array of possible routes for that token pair
|
|
110
110
|
*
|
|
111
111
|
* @example
|
|
112
112
|
* ```typescript
|
|
113
|
-
* // Given direct routes:
|
|
113
|
+
* // Given direct routes: USDm-CELO, CELO-EURm, USDm-USDC
|
|
114
114
|
* const allRoutes = generateAllRoutes(connectivityData)
|
|
115
115
|
*
|
|
116
116
|
* // Results might include:
|
|
117
|
-
* // '
|
|
118
|
-
* // '
|
|
119
|
-
* // { path: [
|
|
120
|
-
* // { path: [
|
|
117
|
+
* // 'USDm-CELO' -> [{ path: [USDm->CELO] }] // direct route
|
|
118
|
+
* // 'EURm-USDm' -> [
|
|
119
|
+
* // { path: [USDm->USDC, USDC->EURm] } // two-hop via USDC
|
|
120
|
+
* // { path: [USDm->CELO, CELO->EURm] } // two-hop via CELO
|
|
121
121
|
* // ]
|
|
122
122
|
* ```
|
|
123
123
|
*/
|
|
@@ -133,23 +133,23 @@ function generateAllRoutes(connectivityData) {
|
|
|
133
133
|
}
|
|
134
134
|
// Step 2: Generate two-hop routes using graph traversal
|
|
135
135
|
// Algorithm: For each token, explore all paths of length 2
|
|
136
|
-
// OUTER LOOP: "For each starting token..." (e.g.,
|
|
136
|
+
// OUTER LOOP: "For each starting token..." (e.g., USDm, CELO, EURm, etc.)
|
|
137
137
|
for (const [start, neighbors] of tokenGraph.entries()) {
|
|
138
138
|
// MIDDLE LOOP: "Where can I go from the starting token?" (first hop)
|
|
139
|
-
// Example: If start =
|
|
139
|
+
// Example: If start = USDm, neighbors might be [CELO, USDC, KESm]
|
|
140
140
|
for (const intermediate of neighbors) {
|
|
141
141
|
// Get all tokens reachable from this intermediate token (second hop destinations)
|
|
142
142
|
const secondHopNeighbors = tokenGraph.get(intermediate);
|
|
143
143
|
if (!secondHopNeighbors)
|
|
144
144
|
continue;
|
|
145
145
|
// INNER LOOP: "From the intermediate token, where can I go?" (second hop)
|
|
146
|
-
// Example: If intermediate = CELO, secondHopNeighbors might be [
|
|
146
|
+
// Example: If intermediate = CELO, secondHopNeighbors might be [USDm, EURm, BRLm]
|
|
147
147
|
for (const end of secondHopNeighbors) {
|
|
148
|
-
// Skip circular routes like
|
|
148
|
+
// Skip circular routes like USDm → CELO → USDm (pointless)
|
|
149
149
|
if (end === start)
|
|
150
150
|
continue;
|
|
151
151
|
// At this point we have a potential route: start → intermediate → end
|
|
152
|
-
// Example:
|
|
152
|
+
// Example: USDm → CELO → EURm
|
|
153
153
|
// Try to create a valid two-hop trading pair from this route
|
|
154
154
|
const twoHopRoute = createTwoHopRoute(start, intermediate, end, addrToSymbol, directRouteMap);
|
|
155
155
|
// If we successfully created the pair, add it to our collection
|
|
@@ -187,22 +187,22 @@ function generateAllRoutes(connectivityData) {
|
|
|
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
|
* ```
|
|
@@ -257,17 +257,17 @@ function createTwoHopRoute(startAddr, intermediateAddr, endAddr, addrToSymbol, d
|
|
|
257
257
|
*
|
|
258
258
|
* @example
|
|
259
259
|
* ```typescript
|
|
260
|
-
* // Multiple routes for
|
|
260
|
+
* // Multiple routes for USDm-EURm pair
|
|
261
261
|
* const candidates = new Map([
|
|
262
|
-
* ['
|
|
263
|
-
* { path: [
|
|
264
|
-
* { path: [
|
|
265
|
-
* { path: [
|
|
262
|
+
* ['EURm-USDm', [
|
|
263
|
+
* { path: [USDm->CELO->EURm], costData: { totalCostPercent: 0.5 } },
|
|
264
|
+
* { path: [USDm->BRLm->EURm], costData: { totalCostPercent: 0.3 } },
|
|
265
|
+
* { path: [USDm->EURm] } // direct route, no cost data
|
|
266
266
|
* ]]
|
|
267
267
|
* ])
|
|
268
268
|
*
|
|
269
269
|
* const optimal = selectOptimalRoutes(candidates, false, assetMap)
|
|
270
|
-
* // Returns the
|
|
270
|
+
* // Returns the USDm->BRLm->EURm route (lowest cost: 0.3%)
|
|
271
271
|
* ```
|
|
272
272
|
*/
|
|
273
273
|
function selectOptimalRoutes(allRoutes, returnAllRoutes, addrToSymbol) {
|
|
@@ -308,7 +308,7 @@ function selectOptimalRoutes(allRoutes, returnAllRoutes, addrToSymbol) {
|
|
|
308
308
|
*
|
|
309
309
|
* **Tier 3 - Major Stablecoin Preference** (Final Fallback):
|
|
310
310
|
* - For two-hop routes, prefer those going through major stablecoins
|
|
311
|
-
* - Major FX currencies like
|
|
311
|
+
* - Major FX currencies like USDm and EURm typically have better liquidity
|
|
312
312
|
*
|
|
313
313
|
* **Tier 4 - First Available** (Last Resort):
|
|
314
314
|
* - If no other heuristics apply, use the first route found
|
|
@@ -340,7 +340,7 @@ function selectBestRoute(candidates, addrToSymbol) {
|
|
|
340
340
|
if (directRoute)
|
|
341
341
|
return directRoute;
|
|
342
342
|
// Tier 3: Prefer routes through major stablecoins (better liquidity)
|
|
343
|
-
const stablecoins = ['
|
|
343
|
+
const stablecoins = ['USDm', 'EURm', 'USDC', 'USDT'];
|
|
344
344
|
const routeWithStablecoin = candidates.find((candidate) => {
|
|
345
345
|
const intermediateToken = getIntermediateToken(candidate);
|
|
346
346
|
if (!intermediateToken)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routeUtils.js","sourceRoot":"","sources":["../../src/utils/routeUtils.ts"],"names":[],"mappings":";;AA4IA,kEA4BC;AAoCD,8CAgDC;AA6CD,8CAsCC;AAoCD,kDAwBC;AAwCD,0CAwBC;AAMD,oDAMC;AAKD,kCAEC;AA7dD,2CAAqE;AAsFrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,SAAgB,2BAA2B,CAAC,YAAqB;IAC/D,MAAM,YAAY,GAAG,IAAI,GAAG,EAAwB,CAAA;IACpD,MAAM,cAAc,GAAG,IAAI,GAAG,EAAiB,CAAA;IAC/C,MAAM,UAAU,GAAG,IAAI,GAAG,EAAuB,CAAA;IAEjD,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE,CAAC;QACjC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAA;QAErC,uDAAuD;QACvD,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;QAC/C,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;QAE/C,kEAAkE;QAClE,0DAA0D;QAC1D,MAAM,OAAO,GAAG,IAAA,8BAAkB,EAAC,MAAM,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G,oBAAoB,CAAC,SAAS,CAAC,CAAA;QACzD,IAAI,CAAC,iBAAiB;YAAE,OAAO,KAAK,CAAA;QACpC,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;QAClD,OAAO,MAAM,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IAC/C,CAAC,CAAC,CAAA;IAEF,mDAAmD;IACnD,OAAO,mBAAmB,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA;AAC7C,CAAC;AAED;;;GAGG;AACH,SAAgB,oBAAoB,CAAC,KAAY;IAC/C,6CAA6C;IAC7C,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,CAAA;IAC/B,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IAC7C,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IAC7C,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;AAC7D,CAAC;AAED;;GAEG;AACH,SAAgB,WAAW,CAAC,IAA2B;IACrD,OAAO,UAAU,IAAI,IAAI,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAA;AAC1D,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates an Ethereum address format using viem's isAddress utility
|
|
3
|
+
*
|
|
4
|
+
* @param address - The address string to validate
|
|
5
|
+
* @param paramName - Optional parameter name for better error messages
|
|
6
|
+
* @returns True if valid (type guard for `0x${string}`)
|
|
7
|
+
* @throws Error if address is invalid
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* validateAddress('0x765DE816845861e75A25fCA122bb6898B8B1282a')
|
|
12
|
+
* // Returns true
|
|
13
|
+
*
|
|
14
|
+
* validateAddress('invalid', 'tokenIn')
|
|
15
|
+
* // Throws: "Invalid address for tokenIn: invalid"
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function validateAddress(address: string, paramName?: string): address is `0x${string}`;
|
|
19
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,IAAI,KAAK,MAAM,EAAE,CAe7F"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateAddress = validateAddress;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
/**
|
|
6
|
+
* Validates an Ethereum address format using viem's isAddress utility
|
|
7
|
+
*
|
|
8
|
+
* @param address - The address string to validate
|
|
9
|
+
* @param paramName - Optional parameter name for better error messages
|
|
10
|
+
* @returns True if valid (type guard for `0x${string}`)
|
|
11
|
+
* @throws Error if address is invalid
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* validateAddress('0x765DE816845861e75A25fCA122bb6898B8B1282a')
|
|
16
|
+
* // Returns true
|
|
17
|
+
*
|
|
18
|
+
* validateAddress('invalid', 'tokenIn')
|
|
19
|
+
* // Throws: "Invalid address for tokenIn: invalid"
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function validateAddress(address, paramName) {
|
|
23
|
+
if (typeof address !== 'string') {
|
|
24
|
+
const param = paramName ? ` for ${paramName}` : '';
|
|
25
|
+
throw new Error(`Address${param} must be a string, got ${typeof address}`);
|
|
26
|
+
}
|
|
27
|
+
// Use viem's isAddress with strict: false to allow both checksummed and non-checksummed addresses
|
|
28
|
+
if (!(0, viem_1.isAddress)(address, { strict: false })) {
|
|
29
|
+
const param = paramName ? ` for ${paramName}` : '';
|
|
30
|
+
throw new Error(`Invalid address${param}: ${address}. Expected 0x followed by 40 hex characters`);
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":";;AAmBA,0CAeC;AAlCD,+BAAgC;AAEhC;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,eAAe,CAAC,OAAe,EAAE,SAAkB;IACjE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,QAAQ,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;QAClD,MAAM,IAAI,KAAK,CAAC,UAAU,KAAK,0BAA0B,OAAO,OAAO,EAAE,CAAC,CAAA;IAC5E,CAAC;IAED,kGAAkG;IAClG,IAAI,CAAC,IAAA,gBAAS,EAAC,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QAC3C,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,QAAQ,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;QAClD,MAAM,IAAI,KAAK,CACb,kBAAkB,KAAK,KAAK,OAAO,6CAA6C,CACjF,CAAA;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
|