@mento-protocol/mento-sdk 3.2.0 → 3.2.2-beta0

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.
@@ -6,16 +6,18 @@ import { AdjustTroveParams, BorrowPosition, CallParams, InterestRateBracket, Ope
6
6
  * handle interest rates and batch managers, and query position data.
7
7
  *
8
8
  * All `build*` methods return `CallParams` ({ to, data, value }) that can be
9
- * executed with any wallet client. The `debtTokenSymbol` parameter (e.g., 'USDm')
9
+ * executed with any wallet client. The `debtTokenSymbol` parameter (e.g., 'GBPm')
10
10
  * identifies which borrowing deployment to interact with.
11
11
  *
12
12
  * @example
13
13
  * ```typescript
14
14
  * const mento = await Mento.create(ChainId.CELO)
15
15
  *
16
+ * const ownerIndex = await mento.borrow.findNextAvailableOwnerIndex('GBPm', '0x...', '0x...')
17
+ *
16
18
  * // Open a trove
17
- * const tx = await mento.borrow.buildOpenTroveTransaction('USDm', {
18
- * owner: '0x...', ownerIndex: 0,
19
+ * const tx = await mento.borrow.buildOpenTroveTransaction('GBPm', {
20
+ * owner: '0x...', ownerIndex,
19
21
  * collAmount: parseUnits('10', 18),
20
22
  * boldAmount: parseUnits('1000', 18),
21
23
  * annualInterestRate: parseUnits('0.05', 18),
@@ -34,7 +36,7 @@ export declare class BorrowService {
34
36
  * Builds a transaction to open a new trove (borrowing position).
35
37
  * Requires prior collateral approval via `buildCollateralApprovalParams`.
36
38
  *
37
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
39
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
38
40
  * @param params - Trove opening parameters including collateral, debt amount, and interest rate
39
41
  * @returns Transaction parameters ready to send
40
42
  */
@@ -42,16 +44,19 @@ export declare class BorrowService {
42
44
  /**
43
45
  * Builds a transaction to adjust an existing trove's collateral and/or debt.
44
46
  *
45
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
47
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
46
48
  * @param params - Adjustment parameters specifying collateral/debt changes
47
49
  * @returns Transaction parameters ready to send
48
50
  */
49
51
  buildAdjustTroveTransaction(debtTokenSymbol: string, params: AdjustTroveParams): Promise<CallParams>;
50
52
  /**
51
- * Builds a transaction to adjust a zombie trove (a trove that fell below minimum debt
52
- * after a liquidation). Same parameters as `buildAdjustTroveTransaction`.
53
+ * Builds a transaction to adjust a zombie trove. Zombie troves are still-open troves whose
54
+ * debt fell below the branch minimum debt, typically after a redemption.
55
+ *
56
+ * Use this when `getTroveData()` or `getUserTroves()` returns `status === 'zombie'`.
57
+ * Same parameters as `buildAdjustTroveTransaction`.
53
58
  *
54
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
59
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
55
60
  * @param params - Adjustment parameters specifying collateral/debt changes
56
61
  * @returns Transaction parameters ready to send
57
62
  */
@@ -59,7 +64,7 @@ export declare class BorrowService {
59
64
  /**
60
65
  * Builds a transaction to close a trove, repaying all debt and reclaiming collateral.
61
66
  *
62
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
67
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
63
68
  * @param troveId - The NFT token ID identifying the trove
64
69
  * @returns Transaction parameters ready to send
65
70
  */
@@ -68,7 +73,7 @@ export declare class BorrowService {
68
73
  * Builds a transaction to add collateral to an existing trove.
69
74
  * Requires prior collateral approval via `buildCollateralApprovalParams`.
70
75
  *
71
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
76
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
72
77
  * @param troveId - The NFT token ID identifying the trove
73
78
  * @param amount - Amount of collateral to add (in wei)
74
79
  * @returns Transaction parameters ready to send
@@ -77,7 +82,7 @@ export declare class BorrowService {
77
82
  /**
78
83
  * Builds a transaction to withdraw collateral from an existing trove.
79
84
  *
80
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
85
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
81
86
  * @param troveId - The NFT token ID identifying the trove
82
87
  * @param amount - Amount of collateral to withdraw (in wei)
83
88
  * @returns Transaction parameters ready to send
@@ -86,7 +91,7 @@ export declare class BorrowService {
86
91
  /**
87
92
  * Builds a transaction to borrow additional debt against an existing trove.
88
93
  *
89
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
94
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
90
95
  * @param troveId - The NFT token ID identifying the trove
91
96
  * @param amount - Additional debt amount to borrow (in wei)
92
97
  * @param maxFee - Maximum upfront fee the borrower is willing to pay (in wei)
@@ -96,7 +101,7 @@ export declare class BorrowService {
96
101
  /**
97
102
  * Builds a transaction to repay debt on an existing trove.
98
103
  *
99
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
104
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
100
105
  * @param troveId - The NFT token ID identifying the trove
101
106
  * @param amount - Amount of debt to repay (in wei)
102
107
  * @returns Transaction parameters ready to send
@@ -105,7 +110,7 @@ export declare class BorrowService {
105
110
  /**
106
111
  * Builds a transaction to change the annual interest rate on a trove.
107
112
  *
108
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
113
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
109
114
  * @param troveId - The NFT token ID identifying the trove
110
115
  * @param newRate - New annual interest rate (18-decimal fixed-point, e.g., parseUnits('0.05', 18) for 5%)
111
116
  * @param maxFee - Maximum upfront fee the borrower is willing to pay (in wei)
@@ -114,15 +119,17 @@ export declare class BorrowService {
114
119
  buildAdjustInterestRateTransaction(debtTokenSymbol: string, troveId: string, newRate: bigint, maxFee: bigint): Promise<CallParams>;
115
120
  /**
116
121
  * Builds a transaction to claim collateral surplus after a liquidation.
122
+ * This is for collateral held in the surplus pool after `closedByLiquidation`.
123
+ * Zombie troves with remaining collateral should usually be closed or adjusted instead.
117
124
  *
118
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
125
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
119
126
  * @returns Transaction parameters ready to send
120
127
  */
121
128
  buildClaimCollateralTransaction(debtTokenSymbol: string): Promise<CallParams>;
122
129
  /**
123
130
  * Builds a transaction to delegate interest rate management to a batch manager.
124
131
  *
125
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
132
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
126
133
  * @param troveId - The NFT token ID identifying the trove
127
134
  * @param manager - Address of the batch manager contract
128
135
  * @param maxFee - Maximum upfront fee the borrower is willing to pay (in wei)
@@ -132,7 +139,7 @@ export declare class BorrowService {
132
139
  /**
133
140
  * Builds a transaction to remove a trove from a batch manager, setting a new individual rate.
134
141
  *
135
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
142
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
136
143
  * @param troveId - The NFT token ID identifying the trove
137
144
  * @param newRate - New individual annual interest rate (18-decimal fixed-point)
138
145
  * @param maxFee - Maximum upfront fee the borrower is willing to pay (in wei)
@@ -142,7 +149,7 @@ export declare class BorrowService {
142
149
  /**
143
150
  * Builds a transaction to switch a trove to a different batch manager.
144
151
  *
145
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
152
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
146
153
  * @param troveId - The NFT token ID identifying the trove
147
154
  * @param newManager - Address of the new batch manager contract
148
155
  * @param maxFee - Maximum upfront fee the borrower is willing to pay (in wei)
@@ -153,7 +160,7 @@ export declare class BorrowService {
153
160
  * Builds a transaction to delegate interest rate management to another address
154
161
  * with bounded rate constraints.
155
162
  *
156
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
163
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
157
164
  * @param troveId - The NFT token ID identifying the trove
158
165
  * @param delegate - Address to delegate interest rate management to
159
166
  * @param minRate - Minimum allowed annual interest rate (18-decimal fixed-point)
@@ -167,7 +174,7 @@ export declare class BorrowService {
167
174
  /**
168
175
  * Builds a transaction to remove the interest rate delegate from a trove.
169
176
  *
170
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
177
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
171
178
  * @param troveId - The NFT token ID identifying the trove
172
179
  * @returns Transaction parameters ready to send
173
180
  */
@@ -176,7 +183,7 @@ export declare class BorrowService {
176
183
  * Builds approval params to allow BorrowerOperations to spend collateral tokens.
177
184
  * Must be executed before `buildOpenTroveTransaction` or `buildAddCollTransaction`.
178
185
  *
179
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
186
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
180
187
  * @param amount - Amount of collateral to approve (in wei)
181
188
  * @returns Transaction parameters for the ERC-20 approve call
182
189
  */
@@ -184,7 +191,7 @@ export declare class BorrowService {
184
191
  /**
185
192
  * Builds approval params for the debt token (e.g., for repayment or closing).
186
193
  *
187
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
194
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
188
195
  * @param spender - Address to approve as spender
189
196
  * @param amount - Amount of debt tokens to approve (in wei)
190
197
  * @returns Transaction parameters for the ERC-20 approve call
@@ -193,7 +200,7 @@ export declare class BorrowService {
193
200
  /**
194
201
  * Builds approval params for the gas compensation token (required when opening a trove).
195
202
  *
196
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
203
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
197
204
  * @param amount - Amount to approve (in wei). If omitted, approves the gas compensation amount.
198
205
  * @returns Transaction parameters for the ERC-20 approve call
199
206
  */
@@ -201,7 +208,7 @@ export declare class BorrowService {
201
208
  /**
202
209
  * Gets the current collateral token allowance for BorrowerOperations.
203
210
  *
204
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
211
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
205
212
  * @param owner - Address to check allowance for
206
213
  * @returns Current allowance in wei
207
214
  */
@@ -209,7 +216,7 @@ export declare class BorrowService {
209
216
  /**
210
217
  * Gets the current debt token allowance for a specific spender.
211
218
  *
212
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
219
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
213
220
  * @param owner - Address to check allowance for
214
221
  * @param spender - Address of the approved spender
215
222
  * @returns Current allowance in wei
@@ -218,31 +225,36 @@ export declare class BorrowService {
218
225
  /**
219
226
  * Gets the current gas compensation token allowance.
220
227
  *
221
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
228
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
222
229
  * @param owner - Address to check allowance for
223
230
  * @returns Current allowance in wei
224
231
  */
225
232
  getGasTokenAllowance(debtTokenSymbol: string, owner: string): Promise<bigint>;
226
233
  /**
227
234
  * Fetches on-chain data for a specific trove.
235
+ * The returned position reflects the trove's current lifecycle status, including
236
+ * zombie troves that may still hold collateral even when their debt is zero.
228
237
  *
229
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
238
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
230
239
  * @param troveId - The NFT token ID identifying the trove
231
240
  * @returns Trove position data including collateral, debt, interest rate, and status
232
241
  */
233
242
  getTroveData(debtTokenSymbol: string, troveId: string): Promise<BorrowPosition>;
234
243
  /**
235
- * Fetches all troves owned by an address.
244
+ * Fetches troves currently owned by an address via the Trove NFT.
245
+ * This includes zombie troves that have been removed from `SortedTroves` but are still owned
246
+ * by the address. Closed or liquidated troves are not returned once their Trove NFT is burned
247
+ * or transferred away.
236
248
  *
237
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
249
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
238
250
  * @param owner - Address to query troves for
239
- * @returns Array of trove positions owned by the address
251
+ * @returns Array of trove positions currently owned by the address
240
252
  */
241
253
  getUserTroves(debtTokenSymbol: string, owner: string): Promise<BorrowPosition[]>;
242
254
  /**
243
255
  * Gets the current collateral token price from the price feed.
244
256
  *
245
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
257
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
246
258
  * @returns Collateral price in 18-decimal fixed-point format
247
259
  */
248
260
  getCollateralPrice(debtTokenSymbol: string): Promise<bigint>;
@@ -250,21 +262,21 @@ export declare class BorrowService {
250
262
  * Gets the system parameters for a borrowing deployment.
251
263
  * Returns MCR, CCR, SCR, BCR, minimum debt, gas compensation, and minimum interest rate.
252
264
  *
253
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
265
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
254
266
  * @returns System parameters (all values in 18-decimal fixed-point)
255
267
  */
256
268
  getSystemParams(debtTokenSymbol: string): Promise<SystemParams>;
257
269
  /**
258
270
  * Checks whether the borrowing system has been shut down (e.g., during a crisis).
259
271
  *
260
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
272
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
261
273
  * @returns true if the system is shut down, false otherwise
262
274
  */
263
275
  isSystemShutDown(debtTokenSymbol: string): Promise<boolean>;
264
276
  /**
265
277
  * Gets aggregate collateral and debt statistics for the borrowing branch.
266
278
  *
267
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
279
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
268
280
  * @returns Total collateral and total debt across all troves (in wei)
269
281
  */
270
282
  getBranchStats(debtTokenSymbol: string): Promise<{
@@ -274,21 +286,21 @@ export declare class BorrowService {
274
286
  /**
275
287
  * Gets the distribution of debt across interest rate brackets.
276
288
  *
277
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
289
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
278
290
  * @returns Array of brackets, each with a rate and total debt at that rate
279
291
  */
280
292
  getInterestRateBrackets(debtTokenSymbol: string): Promise<InterestRateBracket[]>;
281
293
  /**
282
294
  * Gets the weighted average interest rate across all active troves.
283
295
  *
284
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
296
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
285
297
  * @returns Average annual interest rate in 18-decimal fixed-point
286
298
  */
287
299
  getAverageInterestRate(debtTokenSymbol: string): Promise<bigint>;
288
300
  /**
289
301
  * Gets information about a batch manager's configuration.
290
302
  *
291
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
303
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
292
304
  * @param address - Address of the batch manager
293
305
  * @returns Batch manager config (min/max rate, min change period), or null if not a valid manager
294
306
  */
@@ -300,7 +312,7 @@ export declare class BorrowService {
300
312
  /**
301
313
  * Estimates the upfront fee for opening a new trove.
302
314
  *
303
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
315
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
304
316
  * @param amount - Debt amount to borrow (in wei)
305
317
  * @param rate - Annual interest rate (18-decimal fixed-point)
306
318
  * @returns Estimated upfront fee in wei
@@ -309,7 +321,7 @@ export declare class BorrowService {
309
321
  /**
310
322
  * Estimates the upfront fee for increasing debt on an existing trove.
311
323
  *
312
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
324
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
313
325
  * @param troveId - The NFT token ID identifying the trove
314
326
  * @param debtIncrease - Amount of additional debt (in wei)
315
327
  * @returns Estimated upfront fee in wei
@@ -318,7 +330,7 @@ export declare class BorrowService {
318
330
  /**
319
331
  * Estimates the upfront fee for changing a trove's interest rate.
320
332
  *
321
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
333
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
322
334
  * @param troveId - The NFT token ID identifying the trove
323
335
  * @param newRate - New annual interest rate (18-decimal fixed-point)
324
336
  * @returns Estimated upfront fee in wei
@@ -327,19 +339,40 @@ export declare class BorrowService {
327
339
  /**
328
340
  * Estimates the upfront fee for joining a batch manager.
329
341
  *
330
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
342
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
331
343
  * @param troveId - The NFT token ID identifying the trove
332
344
  * @param batchAddress - Address of the batch manager to join
333
345
  * @returns Estimated upfront fee in wei
334
346
  */
335
347
  predictJoinBatchUpfrontFee(debtTokenSymbol: string, troveId: string, batchAddress: string): Promise<bigint>;
336
348
  /**
337
- * Gets the next available owner index for opening a new trove.
338
- * Each owner can have multiple troves, indexed starting from 0.
349
+ * Gets the current number of troves owned by an address via the Trove NFT.
350
+ *
351
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
352
+ * @param owner - Address of the trove owner
353
+ * @returns The number of troves currently owned by the address
354
+ */
355
+ getOwnedTroveCount(debtTokenSymbol: string, owner: string): Promise<number>;
356
+ /**
357
+ * Finds the first safe owner index for opening a trove with the given transaction sender.
358
+ *
359
+ * The `opener` must be the address that will call BorrowerOperations on-chain.
360
+ * For smart accounts, pass the smart account address rather than the controlling EOA.
361
+ *
362
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
363
+ * @param owner - Address that will own the trove NFT
364
+ * @param opener - Address that will submit the open-trove transaction on-chain
365
+ * @returns The first owner index that does not already map to an existing trove
366
+ */
367
+ findNextAvailableOwnerIndex(debtTokenSymbol: string, owner: string, opener: string): Promise<number>;
368
+ /**
369
+ * Gets the current number of troves owned by an address via the Trove NFT.
370
+ *
371
+ * @deprecated Use `findNextAvailableOwnerIndex` when preparing an open-trove transaction.
339
372
  *
340
- * @param debtTokenSymbol - The debt token symbol (e.g., 'USDm')
373
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
341
374
  * @param owner - Address of the trove owner
342
- * @returns The next available index (pass to OpenTroveParams.ownerIndex)
375
+ * @returns The number of troves currently owned by the address
343
376
  */
344
377
  getNextOwnerIndex(debtTokenSymbol: string, owner: string): Promise<number>;
345
378
  private withContext;