@mento-protocol/mento-sdk 3.0.0 → 3.1.0-beta.0
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/dist/cache/routes.js +225 -1
- package/dist/cache/tokens.d.ts +1 -0
- package/dist/cache/tokens.js +31 -1
- package/dist/core/abis/reserve.d.ts +1 -0
- package/dist/core/abis/reserve.js +9 -1
- package/dist/core/constants/addresses.d.ts +5 -0
- package/dist/core/constants/addresses.js +29 -5
- package/dist/core/constants/chainId.d.ts +3 -1
- package/dist/core/constants/chainId.js +2 -0
- package/dist/core/types/pool.d.ts +1 -3
- package/dist/core/types/provider.d.ts +45 -0
- package/dist/core/types/provider.js +3 -0
- package/dist/esm/cache/routes.js +225 -1
- package/dist/esm/cache/tokens.js +31 -1
- package/dist/esm/core/abis/reserve.js +8 -0
- package/dist/esm/core/constants/addresses.js +28 -5
- package/dist/esm/core/constants/chainId.js +2 -0
- package/dist/esm/core/types/provider.js +1 -0
- package/dist/esm/index.js +6 -8
- package/dist/esm/services/index.js +0 -2
- package/dist/esm/services/liquidity/liquidityHelpers.js +2 -4
- package/dist/esm/services/pools/poolDetails.js +4 -10
- package/dist/esm/services/pools/poolDiscovery.js +6 -10
- package/dist/esm/services/tokens/tokenService.js +63 -11
- package/dist/esm/services/trading/TradingLimitsService.js +11 -23
- package/dist/esm/utils/chainConfig.js +49 -0
- package/dist/index.d.ts +6 -8
- package/dist/index.js +6 -8
- package/dist/services/index.d.ts +0 -2
- package/dist/services/index.js +0 -2
- package/dist/services/liquidity/liquidityHelpers.js +2 -4
- package/dist/services/pools/poolDetails.js +4 -10
- package/dist/services/pools/poolDiscovery.js +5 -9
- package/dist/services/tokens/tokenService.d.ts +17 -2
- package/dist/services/tokens/tokenService.js +61 -9
- package/dist/services/trading/TradingLimitsService.js +10 -22
- package/dist/utils/chainConfig.js +49 -0
- package/package.json +1 -1
package/dist/esm/cache/routes.js
CHANGED
|
@@ -1,10 +1,234 @@
|
|
|
1
1
|
// This file is auto-generated. Do not edit manually.
|
|
2
|
-
// Generated on 2026-03-
|
|
2
|
+
// Generated on 2026-03-10T11:55:17.883Z
|
|
3
3
|
/**
|
|
4
4
|
* Cached routes indexed by chain ID
|
|
5
5
|
* Routes that don't exist for a chain will return an empty array
|
|
6
6
|
*/
|
|
7
7
|
export const cachedRoutes = {
|
|
8
|
+
// Chain 143
|
|
9
|
+
143: [],
|
|
10
|
+
// Chain 10143
|
|
11
|
+
10143: [
|
|
12
|
+
{
|
|
13
|
+
"id": "USDC-USDm",
|
|
14
|
+
"tokens": [
|
|
15
|
+
{
|
|
16
|
+
"address": "0x534b2f3A21130d7a60830c2Df862319e593943A3",
|
|
17
|
+
"symbol": "USDC"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"address": "0x5eCc03111ad2A78F981A108759bc73BAE2AB31bc",
|
|
21
|
+
"symbol": "USDm"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"path": [
|
|
25
|
+
{
|
|
26
|
+
"factoryAddr": "0x353ED52bF8482027C0e0b9e3c0e5d96A9F680980",
|
|
27
|
+
"poolAddr": "0x7109E0A9B4623e90755b7e5c4e10F089E5Bf8bDb",
|
|
28
|
+
"token0": "0x534b2f3A21130d7a60830c2Df862319e593943A3",
|
|
29
|
+
"token1": "0x5eCc03111ad2A78F981A108759bc73BAE2AB31bc",
|
|
30
|
+
"poolType": "FPMM"
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
"costData": {
|
|
34
|
+
"totalCostPercent": 0.05,
|
|
35
|
+
"hops": [
|
|
36
|
+
{
|
|
37
|
+
"poolAddress": "0x7109E0A9B4623e90755b7e5c4e10F089E5Bf8bDb",
|
|
38
|
+
"costPercent": 0.05
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"id": "AUSD-USDm",
|
|
45
|
+
"tokens": [
|
|
46
|
+
{
|
|
47
|
+
"address": "0x502E67D3fE9302A5e4Ec1CFCDdbD6F34F9B9484B",
|
|
48
|
+
"symbol": "AUSD"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"address": "0x5eCc03111ad2A78F981A108759bc73BAE2AB31bc",
|
|
52
|
+
"symbol": "USDm"
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
"path": [
|
|
56
|
+
{
|
|
57
|
+
"factoryAddr": "0x353ED52bF8482027C0e0b9e3c0e5d96A9F680980",
|
|
58
|
+
"poolAddr": "0x52716E8F44E417bE8F573F8A85cA8eD3DAe1eAE1",
|
|
59
|
+
"token0": "0x502E67D3fE9302A5e4Ec1CFCDdbD6F34F9B9484B",
|
|
60
|
+
"token1": "0x5eCc03111ad2A78F981A108759bc73BAE2AB31bc",
|
|
61
|
+
"poolType": "FPMM"
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
"costData": {
|
|
65
|
+
"totalCostPercent": 0.05,
|
|
66
|
+
"hops": [
|
|
67
|
+
{
|
|
68
|
+
"poolAddress": "0x52716E8F44E417bE8F573F8A85cA8eD3DAe1eAE1",
|
|
69
|
+
"costPercent": 0.05
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"id": "AUSD-USDC",
|
|
76
|
+
"tokens": [
|
|
77
|
+
{
|
|
78
|
+
"address": "0x502E67D3fE9302A5e4Ec1CFCDdbD6F34F9B9484B",
|
|
79
|
+
"symbol": "AUSD"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"address": "0x534b2f3A21130d7a60830c2Df862319e593943A3",
|
|
83
|
+
"symbol": "USDC"
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
"path": [
|
|
87
|
+
{
|
|
88
|
+
"factoryAddr": "0x353ED52bF8482027C0e0b9e3c0e5d96A9F680980",
|
|
89
|
+
"poolAddr": "0x7109E0A9B4623e90755b7e5c4e10F089E5Bf8bDb",
|
|
90
|
+
"token0": "0x534b2f3A21130d7a60830c2Df862319e593943A3",
|
|
91
|
+
"token1": "0x5eCc03111ad2A78F981A108759bc73BAE2AB31bc",
|
|
92
|
+
"poolType": "FPMM"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"factoryAddr": "0x353ED52bF8482027C0e0b9e3c0e5d96A9F680980",
|
|
96
|
+
"poolAddr": "0x52716E8F44E417bE8F573F8A85cA8eD3DAe1eAE1",
|
|
97
|
+
"token0": "0x502E67D3fE9302A5e4Ec1CFCDdbD6F34F9B9484B",
|
|
98
|
+
"token1": "0x5eCc03111ad2A78F981A108759bc73BAE2AB31bc",
|
|
99
|
+
"poolType": "FPMM"
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
"costData": {
|
|
103
|
+
"totalCostPercent": 0.099975,
|
|
104
|
+
"hops": [
|
|
105
|
+
{
|
|
106
|
+
"poolAddress": "0x7109E0A9B4623e90755b7e5c4e10F089E5Bf8bDb",
|
|
107
|
+
"costPercent": 0.05
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"poolAddress": "0x52716E8F44E417bE8F573F8A85cA8eD3DAe1eAE1",
|
|
111
|
+
"costPercent": 0.05
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"id": "GBPm-USDm",
|
|
118
|
+
"tokens": [
|
|
119
|
+
{
|
|
120
|
+
"address": "0x04de554E875c9797dC4ceBd834A9e99fa8fD5Df9",
|
|
121
|
+
"symbol": "GBPm"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"address": "0x5eCc03111ad2A78F981A108759bc73BAE2AB31bc",
|
|
125
|
+
"symbol": "USDm"
|
|
126
|
+
}
|
|
127
|
+
],
|
|
128
|
+
"path": [
|
|
129
|
+
{
|
|
130
|
+
"factoryAddr": "0x353ED52bF8482027C0e0b9e3c0e5d96A9F680980",
|
|
131
|
+
"poolAddr": "0x550D9EcB4C373510b8A41f5fB7D98E9E1c51A07e",
|
|
132
|
+
"token0": "0x04de554E875c9797dC4ceBd834A9e99fa8fD5Df9",
|
|
133
|
+
"token1": "0x5eCc03111ad2A78F981A108759bc73BAE2AB31bc",
|
|
134
|
+
"poolType": "FPMM"
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
"costData": {
|
|
138
|
+
"totalCostPercent": 0.15,
|
|
139
|
+
"hops": [
|
|
140
|
+
{
|
|
141
|
+
"poolAddress": "0x550D9EcB4C373510b8A41f5fB7D98E9E1c51A07e",
|
|
142
|
+
"costPercent": 0.15
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"id": "GBPm-USDC",
|
|
149
|
+
"tokens": [
|
|
150
|
+
{
|
|
151
|
+
"address": "0x04de554E875c9797dC4ceBd834A9e99fa8fD5Df9",
|
|
152
|
+
"symbol": "GBPm"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"address": "0x534b2f3A21130d7a60830c2Df862319e593943A3",
|
|
156
|
+
"symbol": "USDC"
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
"path": [
|
|
160
|
+
{
|
|
161
|
+
"factoryAddr": "0x353ED52bF8482027C0e0b9e3c0e5d96A9F680980",
|
|
162
|
+
"poolAddr": "0x550D9EcB4C373510b8A41f5fB7D98E9E1c51A07e",
|
|
163
|
+
"token0": "0x04de554E875c9797dC4ceBd834A9e99fa8fD5Df9",
|
|
164
|
+
"token1": "0x5eCc03111ad2A78F981A108759bc73BAE2AB31bc",
|
|
165
|
+
"poolType": "FPMM"
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"factoryAddr": "0x353ED52bF8482027C0e0b9e3c0e5d96A9F680980",
|
|
169
|
+
"poolAddr": "0x7109E0A9B4623e90755b7e5c4e10F089E5Bf8bDb",
|
|
170
|
+
"token0": "0x534b2f3A21130d7a60830c2Df862319e593943A3",
|
|
171
|
+
"token1": "0x5eCc03111ad2A78F981A108759bc73BAE2AB31bc",
|
|
172
|
+
"poolType": "FPMM"
|
|
173
|
+
}
|
|
174
|
+
],
|
|
175
|
+
"costData": {
|
|
176
|
+
"totalCostPercent": 0.199925,
|
|
177
|
+
"hops": [
|
|
178
|
+
{
|
|
179
|
+
"poolAddress": "0x550D9EcB4C373510b8A41f5fB7D98E9E1c51A07e",
|
|
180
|
+
"costPercent": 0.15
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"poolAddress": "0x7109E0A9B4623e90755b7e5c4e10F089E5Bf8bDb",
|
|
184
|
+
"costPercent": 0.05
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"id": "AUSD-GBPm",
|
|
191
|
+
"tokens": [
|
|
192
|
+
{
|
|
193
|
+
"address": "0x502E67D3fE9302A5e4Ec1CFCDdbD6F34F9B9484B",
|
|
194
|
+
"symbol": "AUSD"
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
"address": "0x04de554E875c9797dC4ceBd834A9e99fa8fD5Df9",
|
|
198
|
+
"symbol": "GBPm"
|
|
199
|
+
}
|
|
200
|
+
],
|
|
201
|
+
"path": [
|
|
202
|
+
{
|
|
203
|
+
"factoryAddr": "0x353ED52bF8482027C0e0b9e3c0e5d96A9F680980",
|
|
204
|
+
"poolAddr": "0x550D9EcB4C373510b8A41f5fB7D98E9E1c51A07e",
|
|
205
|
+
"token0": "0x04de554E875c9797dC4ceBd834A9e99fa8fD5Df9",
|
|
206
|
+
"token1": "0x5eCc03111ad2A78F981A108759bc73BAE2AB31bc",
|
|
207
|
+
"poolType": "FPMM"
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
"factoryAddr": "0x353ED52bF8482027C0e0b9e3c0e5d96A9F680980",
|
|
211
|
+
"poolAddr": "0x52716E8F44E417bE8F573F8A85cA8eD3DAe1eAE1",
|
|
212
|
+
"token0": "0x502E67D3fE9302A5e4Ec1CFCDdbD6F34F9B9484B",
|
|
213
|
+
"token1": "0x5eCc03111ad2A78F981A108759bc73BAE2AB31bc",
|
|
214
|
+
"poolType": "FPMM"
|
|
215
|
+
}
|
|
216
|
+
],
|
|
217
|
+
"costData": {
|
|
218
|
+
"totalCostPercent": 0.199925,
|
|
219
|
+
"hops": [
|
|
220
|
+
{
|
|
221
|
+
"poolAddress": "0x550D9EcB4C373510b8A41f5fB7D98E9E1c51A07e",
|
|
222
|
+
"costPercent": 0.15
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
"poolAddress": "0x52716E8F44E417bE8F573F8A85cA8eD3DAe1eAE1",
|
|
226
|
+
"costPercent": 0.05
|
|
227
|
+
}
|
|
228
|
+
]
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
],
|
|
8
232
|
// Chain 42220
|
|
9
233
|
42220: [
|
|
10
234
|
{
|
package/dist/esm/cache/tokens.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// This file is auto-generated. Do not edit manually.
|
|
2
|
-
// Generated on 2026-03-
|
|
2
|
+
// Generated on 2026-03-10T12:14:17.694Z
|
|
3
3
|
/**
|
|
4
4
|
* Enum of all token symbols across all supported chains
|
|
5
5
|
*/
|
|
6
6
|
export var TokenSymbol;
|
|
7
7
|
(function (TokenSymbol) {
|
|
8
8
|
TokenSymbol["AUDm"] = "AUDm";
|
|
9
|
+
TokenSymbol["AUSD"] = "AUSD";
|
|
9
10
|
TokenSymbol["BRLm"] = "BRLm";
|
|
10
11
|
TokenSymbol["CADm"] = "CADm";
|
|
11
12
|
TokenSymbol["CELO"] = "CELO";
|
|
@@ -30,6 +31,29 @@ export var TokenSymbol;
|
|
|
30
31
|
* Cached tokens indexed by chain ID
|
|
31
32
|
*/
|
|
32
33
|
export const cachedTokens = {
|
|
34
|
+
// Chain 143
|
|
35
|
+
143: [],
|
|
36
|
+
// Chain 10143
|
|
37
|
+
10143: [
|
|
38
|
+
{
|
|
39
|
+
address: '0x5eCc03111ad2A78F981A108759bc73BAE2AB31bc',
|
|
40
|
+
symbol: TokenSymbol.USDm,
|
|
41
|
+
name: 'Mento Dollar',
|
|
42
|
+
decimals: 18,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
address: '0x534b2f3A21130d7a60830c2Df862319e593943A3',
|
|
46
|
+
symbol: TokenSymbol.USDC,
|
|
47
|
+
name: 'USDC',
|
|
48
|
+
decimals: 6,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
address: '0x502E67D3fE9302A5e4Ec1CFCDdbD6F34F9B9484B',
|
|
52
|
+
symbol: TokenSymbol.AUSD,
|
|
53
|
+
name: 'Mento Mock AUSD',
|
|
54
|
+
decimals: 6,
|
|
55
|
+
}
|
|
56
|
+
],
|
|
33
57
|
// Chain 42220
|
|
34
58
|
42220: [
|
|
35
59
|
{
|
|
@@ -282,6 +306,12 @@ export const cachedTokens = {
|
|
|
282
306
|
* Useful for quickly looking up a token address by its symbol on a specific chain
|
|
283
307
|
*/
|
|
284
308
|
export const TOKEN_ADDRESSES_BY_CHAIN = {
|
|
309
|
+
143: {},
|
|
310
|
+
10143: {
|
|
311
|
+
[TokenSymbol.USDm]: '0x5eCc03111ad2A78F981A108759bc73BAE2AB31bc',
|
|
312
|
+
[TokenSymbol.USDC]: '0x534b2f3A21130d7a60830c2Df862319e593943A3',
|
|
313
|
+
[TokenSymbol.AUSD]: '0x502E67D3fE9302A5e4Ec1CFCDdbD6F34F9B9484B',
|
|
314
|
+
},
|
|
285
315
|
42220: {
|
|
286
316
|
[TokenSymbol.USDm]: '0x765DE816845861e75A25fCA122bb6898B8B1282a',
|
|
287
317
|
[TokenSymbol.EURm]: '0xD8763CBa276a3738E6DE85b4b3bF5FDed6D6cA73',
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { parseAbi } from 'viem';
|
|
2
|
+
// Legacy Reserve (Celo)
|
|
2
3
|
export const RESERVE_ABI = parseAbi([
|
|
3
4
|
'function getTokens() view returns (address[])',
|
|
4
5
|
'function isToken(address) view returns (bool)',
|
|
5
6
|
'function isCollateralAsset(address) view returns (bool)',
|
|
6
7
|
]);
|
|
8
|
+
// ReserveV2 (Monad)
|
|
9
|
+
export const RESERVE_V2_ABI = parseAbi([
|
|
10
|
+
'function getStableAssets() view returns (address[])',
|
|
11
|
+
'function getCollateralAssets() view returns (address[])',
|
|
12
|
+
'function isStableAsset(address) view returns (bool)',
|
|
13
|
+
'function isCollateralAsset(address) view returns (bool)',
|
|
14
|
+
]);
|
|
@@ -29,6 +29,22 @@ export const addresses = {
|
|
|
29
29
|
ReserveLiquidityStrategy: '0xa0fB8b16ce6AF3634fF9F3f4F40E49E1C1ae4f0B',
|
|
30
30
|
CDPLiquidityStrategy: '0x4e78BD9565341EAbe99cDC024acB044d9BDcB985',
|
|
31
31
|
},
|
|
32
|
+
[ChainId.MONAD_TESTNET]: {
|
|
33
|
+
// Oracles & Breakers
|
|
34
|
+
BreakerBox: '0x88869E30609D2C0E4032463D713328C6f541878e',
|
|
35
|
+
MedianDeltaBreaker: '0xf923C884F319b8866F67C5719A80E5cB4D0FAF2c',
|
|
36
|
+
SortedOracles: '0x85ed9ac57827132B8F60938F3165BC139E1F53cd',
|
|
37
|
+
ValueDeltaBreaker: '0xbbD0D093F5F11D16D4456FBd6229c9a3b70B8Aaf',
|
|
38
|
+
// DEX
|
|
39
|
+
Reserve: '0xbCdc1D0b92DfceEaa0FcD0a0D53355F4bF1DB8a7',
|
|
40
|
+
// Stable Tokens
|
|
41
|
+
StableToken: '0x5eCc03111ad2A78F981A108759bc73BAE2AB31bc', // USDm
|
|
42
|
+
// V3
|
|
43
|
+
FPMMFactory: '0x353ED52bF8482027C0e0b9e3c0e5d96A9F680980',
|
|
44
|
+
Router: '0xcf6cD45210b3ffE3cA28379C4683F1e60D0C2CCd',
|
|
45
|
+
ReserveLiquidityStrategy: '0x734bb3251Ec3f1A83f8f2A8609bcEF649D54EbF8',
|
|
46
|
+
},
|
|
47
|
+
[ChainId.MONAD]: {},
|
|
32
48
|
[ChainId.CELO_SEPOLIA]: {
|
|
33
49
|
// Oracles & Breakers
|
|
34
50
|
BreakerBox: '0x578bD46003B9D3fd4c3C3f47c98B329562a6a1dE',
|
|
@@ -56,6 +72,17 @@ export const addresses = {
|
|
|
56
72
|
CDPLiquidityStrategy: '0x065AE7D4e207C8f4dca112D0B79E668cc7e93e03',
|
|
57
73
|
},
|
|
58
74
|
};
|
|
75
|
+
/**
|
|
76
|
+
* Get the address of a contract for a given chain, returning undefined if not found.
|
|
77
|
+
* Use this when the contract may not be deployed on the target chain.
|
|
78
|
+
*/
|
|
79
|
+
export function tryGetContractAddress(chainId, contractName) {
|
|
80
|
+
const addressesForChain = addresses[chainId];
|
|
81
|
+
if (!addressesForChain) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
return addressesForChain[contractName];
|
|
85
|
+
}
|
|
59
86
|
/**
|
|
60
87
|
* Get the address of a contract for a given chain
|
|
61
88
|
* @param chainId - The chain ID
|
|
@@ -64,11 +91,7 @@ export const addresses = {
|
|
|
64
91
|
* @throws Error if the address is not found for the given chain
|
|
65
92
|
*/
|
|
66
93
|
export function getContractAddress(chainId, contractName) {
|
|
67
|
-
const
|
|
68
|
-
if (!addressesForChain) {
|
|
69
|
-
throw new Error(`No addresses found for chain ID ${chainId}`);
|
|
70
|
-
}
|
|
71
|
-
const address = addressesForChain[contractName];
|
|
94
|
+
const address = tryGetContractAddress(chainId, contractName);
|
|
72
95
|
if (!address) {
|
|
73
96
|
throw new Error(`Address not found for contract ${contractName} on chain ID ${chainId}`);
|
|
74
97
|
}
|
|
@@ -2,4 +2,6 @@ export var ChainId;
|
|
|
2
2
|
(function (ChainId) {
|
|
3
3
|
ChainId[ChainId["CELO"] = 42220] = "CELO";
|
|
4
4
|
ChainId[ChainId["CELO_SEPOLIA"] = 11142220] = "CELO_SEPOLIA";
|
|
5
|
+
ChainId[ChainId["MONAD_TESTNET"] = 10143] = "MONAD_TESTNET";
|
|
6
|
+
ChainId[ChainId["MONAD"] = 143] = "MONAD";
|
|
5
7
|
})(ChainId || (ChainId = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/esm/index.js
CHANGED
|
@@ -49,16 +49,14 @@ import { BorrowService } from './services/borrow';
|
|
|
49
49
|
* const status = await mento.trading.getPoolTradabilityStatus(pool);
|
|
50
50
|
*
|
|
51
51
|
* // Add liquidity to a pool
|
|
52
|
-
* const {
|
|
53
|
-
* poolAddress,
|
|
54
|
-
*
|
|
55
|
-
* });
|
|
52
|
+
* const { approval0, approval1, addLiquidity } = await mento.liquidity.buildAddLiquidityTransaction(
|
|
53
|
+
* poolAddress, amount0, amount1, recipient, owner, { slippageTolerance: 0.5, deadline: deadlineFromMinutes(5) }
|
|
54
|
+
* );
|
|
56
55
|
*
|
|
57
56
|
* // Add liquidity using a single token (zap in)
|
|
58
|
-
* const { approval, zapIn } = await mento.liquidity.buildZapInTransaction(
|
|
59
|
-
* poolAddress, tokenIn, amountIn,
|
|
60
|
-
*
|
|
61
|
-
* });
|
|
57
|
+
* const { approval, zapIn } = await mento.liquidity.buildZapInTransaction(
|
|
58
|
+
* poolAddress, tokenIn, amountIn, 0.5, recipient, owner, { slippageTolerance: 0.5, deadline: deadlineFromMinutes(5) }
|
|
59
|
+
* );
|
|
62
60
|
*/
|
|
63
61
|
export class Mento {
|
|
64
62
|
constructor(chainId, tokens, pools, routes, quotes, swap, trading, liquidity, borrow) {
|
|
@@ -22,13 +22,11 @@ export async function getAllowance(publicClient, token, owner, chainId) {
|
|
|
22
22
|
}));
|
|
23
23
|
}
|
|
24
24
|
export function calculateMinAmount(amount, slippageTolerance) {
|
|
25
|
-
const MAX_SLIPPAGE_TOLERANCE = 20;
|
|
26
25
|
if (slippageTolerance < 0) {
|
|
27
26
|
throw new Error('Slippage tolerance cannot be negative');
|
|
28
27
|
}
|
|
29
|
-
if (slippageTolerance >
|
|
30
|
-
throw new Error(
|
|
31
|
-
'High slippage makes transactions vulnerable to sandwich attacks.');
|
|
28
|
+
if (slippageTolerance > 100) {
|
|
29
|
+
throw new Error('Slippage tolerance cannot exceed 100%');
|
|
32
30
|
}
|
|
33
31
|
const basisPoints = BigInt(Math.floor(slippageTolerance * 100));
|
|
34
32
|
const slippageMultiplier = 10000n - basisPoints;
|
|
@@ -37,7 +37,6 @@ export async function fetchFPMMPoolDetails(publicClient, chainId, pool) {
|
|
|
37
37
|
const liquidityStrategy = activeIndex >= 0 ? knownStrategies[activeIndex] : null;
|
|
38
38
|
// Fetch pricing separately — graceful degradation when FX market is closed
|
|
39
39
|
let pricing = null;
|
|
40
|
-
let pricingUnavailableReason = null;
|
|
41
40
|
let inBand = null;
|
|
42
41
|
try {
|
|
43
42
|
const rebalancingStateResult = await publicClient.readContract({
|
|
@@ -59,8 +58,8 @@ export async function fetchFPMMPoolDetails(publicClient, chainId, pool) {
|
|
|
59
58
|
};
|
|
60
59
|
inBand = priceDifference < BigInt(rebalanceThreshold);
|
|
61
60
|
}
|
|
62
|
-
catch
|
|
63
|
-
|
|
61
|
+
catch {
|
|
62
|
+
// getRebalancingState() failed (likely FXMarketClosed) — pricing stays null
|
|
64
63
|
}
|
|
65
64
|
return {
|
|
66
65
|
...pool,
|
|
@@ -71,7 +70,6 @@ export async function fetchFPMMPoolDetails(publicClient, chainId, pool) {
|
|
|
71
70
|
reserve1,
|
|
72
71
|
blockTimestampLast,
|
|
73
72
|
pricing,
|
|
74
|
-
pricingUnavailableReason,
|
|
75
73
|
fees: {
|
|
76
74
|
lpFeeBps,
|
|
77
75
|
lpFeePercent: Number(lpFeeBps) / 100,
|
|
@@ -92,9 +90,7 @@ export async function fetchFPMMPoolDetails(publicClient, chainId, pool) {
|
|
|
92
90
|
};
|
|
93
91
|
}
|
|
94
92
|
catch (error) {
|
|
95
|
-
|
|
96
|
-
wrapped.cause = error;
|
|
97
|
-
throw wrapped;
|
|
93
|
+
throw new Error(`Failed to fetch FPMM pool details for ${pool.poolAddr}: ${error.message}`);
|
|
98
94
|
}
|
|
99
95
|
}
|
|
100
96
|
/**
|
|
@@ -124,9 +120,7 @@ export async function fetchVirtualPoolDetails(publicClient, pool) {
|
|
|
124
120
|
};
|
|
125
121
|
}
|
|
126
122
|
catch (error) {
|
|
127
|
-
|
|
128
|
-
wrapped.cause = error;
|
|
129
|
-
throw wrapped;
|
|
123
|
+
throw new Error(`Failed to fetch Virtual pool details for ${pool.poolAddr}: ${error.message}`);
|
|
130
124
|
}
|
|
131
125
|
}
|
|
132
126
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { tryGetContractAddress } from '../../core/constants';
|
|
2
2
|
import { PoolType } from '../../core/types';
|
|
3
3
|
import { FPMM_FACTORY_ABI, FPMM_ABI, VIRTUAL_POOL_FACTORY_ABI, VIRTUAL_POOL_ABI, BIPOOL_MANAGER_ABI, } from '../../core/abis';
|
|
4
4
|
import { sortTokenAddresses } from '../../utils/sortUtils';
|
|
@@ -6,7 +6,7 @@ import { sortTokenAddresses } from '../../utils/sortUtils';
|
|
|
6
6
|
* Fetches all FPMM pools from the FPMM Factory
|
|
7
7
|
*/
|
|
8
8
|
export async function fetchFPMMPools(publicClient, chainId) {
|
|
9
|
-
const fpmmFactoryAddress =
|
|
9
|
+
const fpmmFactoryAddress = tryGetContractAddress(chainId, 'FPMMFactory');
|
|
10
10
|
if (!fpmmFactoryAddress) {
|
|
11
11
|
return [];
|
|
12
12
|
}
|
|
@@ -44,9 +44,7 @@ export async function fetchFPMMPools(publicClient, chainId) {
|
|
|
44
44
|
return await Promise.all(poolDataPromises);
|
|
45
45
|
}
|
|
46
46
|
catch (error) {
|
|
47
|
-
|
|
48
|
-
wrapped.cause = error;
|
|
49
|
-
throw wrapped;
|
|
47
|
+
throw new Error(`Failed to fetch FPMM pools: ${error.message}`);
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
50
|
/**
|
|
@@ -54,8 +52,8 @@ export async function fetchFPMMPools(publicClient, chainId) {
|
|
|
54
52
|
* then resolves token pairs and exchange IDs from each pool and BiPoolManager.
|
|
55
53
|
*/
|
|
56
54
|
export async function fetchVirtualPools(publicClient, chainId) {
|
|
57
|
-
const virtualPoolFactoryAddress =
|
|
58
|
-
const biPoolManagerAddress =
|
|
55
|
+
const virtualPoolFactoryAddress = tryGetContractAddress(chainId, 'VirtualPoolFactory');
|
|
56
|
+
const biPoolManagerAddress = tryGetContractAddress(chainId, 'BiPoolManager');
|
|
59
57
|
if (!virtualPoolFactoryAddress || !biPoolManagerAddress) {
|
|
60
58
|
return [];
|
|
61
59
|
}
|
|
@@ -106,8 +104,6 @@ export async function fetchVirtualPools(publicClient, chainId) {
|
|
|
106
104
|
return await Promise.all(poolPromises);
|
|
107
105
|
}
|
|
108
106
|
catch (error) {
|
|
109
|
-
|
|
110
|
-
wrapped.cause = error;
|
|
111
|
-
throw wrapped;
|
|
107
|
+
throw new Error(`Failed to fetch Virtual pools: ${error.message}`);
|
|
112
108
|
}
|
|
113
109
|
}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import { RESERVE_ABI, BIPOOL_MANAGER_ABI, ERC20_ABI } from '../../core/abis';
|
|
2
|
-
import { getContractAddress, RESERVE, BIPOOLMANAGER, } from '../../core/constants';
|
|
1
|
+
import { RESERVE_ABI, RESERVE_V2_ABI, BIPOOL_MANAGER_ABI, ERC20_ABI } from '../../core/abis';
|
|
2
|
+
import { getContractAddress, tryGetContractAddress, ChainId, RESERVE, BIPOOLMANAGER, } from '../../core/constants';
|
|
3
3
|
import { retryOperation } from '../../utils';
|
|
4
|
+
/**
|
|
5
|
+
* Chains that use ReserveV2 (v3) instead of the legacy Reserve contract.
|
|
6
|
+
*/
|
|
7
|
+
const RESERVE_V2_CHAINS = new Set([ChainId.MONAD_TESTNET, ChainId.MONAD]);
|
|
4
8
|
export class TokenService {
|
|
5
9
|
constructor(publicClient, chainId) {
|
|
6
10
|
this.publicClient = publicClient;
|
|
7
11
|
this.chainId = chainId;
|
|
8
12
|
}
|
|
13
|
+
isReserveV2() {
|
|
14
|
+
return RESERVE_V2_CHAINS.has(this.chainId);
|
|
15
|
+
}
|
|
9
16
|
/**
|
|
10
17
|
* Get token metadata (name, symbol, decimals)
|
|
11
18
|
* @param address - Token contract address
|
|
@@ -52,6 +59,26 @@ export class TokenService {
|
|
|
52
59
|
}));
|
|
53
60
|
return totalSupply.toString();
|
|
54
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Get stable token addresses from the Reserve contract.
|
|
64
|
+
* Uses getStableAssets() on ReserveV2, getTokens() on legacy Reserve.
|
|
65
|
+
*/
|
|
66
|
+
async getStableTokenAddresses(reserveAddress) {
|
|
67
|
+
if (this.isReserveV2()) {
|
|
68
|
+
return (await this.publicClient.readContract({
|
|
69
|
+
address: reserveAddress,
|
|
70
|
+
abi: RESERVE_V2_ABI,
|
|
71
|
+
functionName: 'getStableAssets',
|
|
72
|
+
args: [],
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
return (await this.publicClient.readContract({
|
|
76
|
+
address: reserveAddress,
|
|
77
|
+
abi: RESERVE_ABI,
|
|
78
|
+
functionName: 'getTokens',
|
|
79
|
+
args: [],
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
55
82
|
/**
|
|
56
83
|
* Get all stable tokens from the Reserve contract.
|
|
57
84
|
* Returns the actual on-chain ERC20 totalSupply values without adjustments.
|
|
@@ -60,12 +87,7 @@ export class TokenService {
|
|
|
60
87
|
*/
|
|
61
88
|
async getStableTokens(includeSupply = true) {
|
|
62
89
|
const reserveAddress = getContractAddress(this.chainId, RESERVE);
|
|
63
|
-
const tokenAddresses =
|
|
64
|
-
address: reserveAddress,
|
|
65
|
-
abi: RESERVE_ABI,
|
|
66
|
-
functionName: 'getTokens',
|
|
67
|
-
args: [],
|
|
68
|
-
}));
|
|
90
|
+
const tokenAddresses = await this.getStableTokenAddresses(reserveAddress);
|
|
69
91
|
// Fetch metadata and totalSupply for all tokens concurrently
|
|
70
92
|
const tokens = await Promise.all(tokenAddresses.map(async (address) => {
|
|
71
93
|
const [metadata, totalSupply] = await Promise.all([
|
|
@@ -81,12 +103,42 @@ export class TokenService {
|
|
|
81
103
|
return tokens;
|
|
82
104
|
}
|
|
83
105
|
/**
|
|
84
|
-
* Get all collateral assets
|
|
85
|
-
*
|
|
106
|
+
* Get all collateral assets.
|
|
107
|
+
* On ReserveV2 chains, queries the reserve directly.
|
|
108
|
+
* On legacy chains, discovers collateral via BiPoolManager exchanges.
|
|
86
109
|
* @returns Array of collateral assets
|
|
87
110
|
*/
|
|
88
111
|
async getCollateralAssets() {
|
|
89
|
-
|
|
112
|
+
if (this.isReserveV2()) {
|
|
113
|
+
return this.getCollateralAssetsV2();
|
|
114
|
+
}
|
|
115
|
+
return this.getCollateralAssetsLegacy();
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get collateral assets directly from ReserveV2.
|
|
119
|
+
*/
|
|
120
|
+
async getCollateralAssetsV2() {
|
|
121
|
+
const reserveAddress = getContractAddress(this.chainId, RESERVE);
|
|
122
|
+
const collateralAddresses = (await retryOperation(() => this.publicClient.readContract({
|
|
123
|
+
address: reserveAddress,
|
|
124
|
+
abi: RESERVE_V2_ABI,
|
|
125
|
+
functionName: 'getCollateralAssets',
|
|
126
|
+
args: [],
|
|
127
|
+
})));
|
|
128
|
+
const assets = await Promise.all(collateralAddresses.map(async (address) => {
|
|
129
|
+
const metadata = await this.getTokenMetadata(address);
|
|
130
|
+
return { address, ...metadata };
|
|
131
|
+
}));
|
|
132
|
+
return assets;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get collateral assets from legacy Reserve via BiPoolManager exchanges.
|
|
136
|
+
*/
|
|
137
|
+
async getCollateralAssetsLegacy() {
|
|
138
|
+
const biPoolManagerAddress = tryGetContractAddress(this.chainId, BIPOOLMANAGER);
|
|
139
|
+
if (!biPoolManagerAddress) {
|
|
140
|
+
return [];
|
|
141
|
+
}
|
|
90
142
|
const reserveAddress = getContractAddress(this.chainId, RESERVE);
|
|
91
143
|
// Get all exchanges to find unique token addresses
|
|
92
144
|
const exchanges = (await retryOperation(() => this.publicClient.readContract({
|