@curvefi/llamalend-api 2.3.1 → 2.3.3

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.
@@ -378,6 +378,7 @@ On the frontend, the value that we now return as **`totalAssets`** corresponds t
378
378
  | repay() | ✅ | ✅ | ❌ | ❌ | ✅ |
379
379
  | repayFutureLeverage() | ✅ | ✅ | ✅ | ✅ | ✅ |
380
380
 
381
+
381
382
  #### Shrink mechanism (v2 only)
382
383
 
383
384
  In v2, the `repay` operation supports a new **shrink** mode that allows users to exit soft-liquidation by cutting the converted part of their position.
@@ -391,8 +392,8 @@ Before shrink: `| c | c | c | c | c | c | c_a + b_a | b | b | b |`
391
392
  After shrink (6 bands): `| c + c_a/6 | c + c_a/6 | c + c_a/6 | c + c_a/6 | c + c_a/6 | c + c_a/6 |`
392
393
 
393
394
  **Constraints:**
394
- - User must have at least 4 unconverted bands to shrink
395
- - Additional borrowed tokens may be required (use `tokens_to_shrink` on the controller contract to check)
395
+ - User must have at least 4 unconverted bands to shrink and have soft-liquidation mode. Use `loan.isRepayWithShrinkAvailable()`
396
+ - Additional borrowed tokens may be required (use `loan.tokensToShrink` to check). And provide this value into `loan.repay()`
396
397
 
397
398
  **Updated method signatures (v2):**
398
399
 
@@ -143,6 +143,7 @@ export class LendMarketTemplate {
143
143
  removeCollateralPrices: loan.removeCollateralPrices.bind(loan),
144
144
  removeCollateralHealth: loan.removeCollateralHealth.bind(loan),
145
145
  tokensToShrink: loan.tokensToShrink.bind(loan),
146
+ isRepayWithShrinkAvailable: loan.isRepayWithShrinkAvailable.bind(loan),
146
147
  removeCollateral: loan.removeCollateral.bind(loan),
147
148
  removeCollateralFutureLeverage: loan.removeCollateralFutureLeverage.bind(loan),
148
149
  repayBands: loan.repayBands.bind(loan),
@@ -1,21 +1,21 @@
1
1
  import { IReward, TAmount, TGas } from "../../../interfaces";
2
2
  export interface IVault {
3
3
  maxDeposit: (address?: string) => Promise<string>;
4
- previewDeposit: (amount: TAmount) => Promise<string>;
4
+ previewDeposit: (borrowed: TAmount) => Promise<string>;
5
5
  depositIsApproved: (borrowed: TAmount) => Promise<boolean>;
6
6
  depositApprove: (borrowed: TAmount) => Promise<string[]>;
7
- deposit: (amount: TAmount) => Promise<string>;
7
+ deposit: (borrowed: TAmount) => Promise<string>;
8
8
  maxMint: (address?: string) => Promise<string>;
9
- previewMint: (amount: TAmount) => Promise<string>;
9
+ previewMint: (shares: TAmount) => Promise<string>;
10
10
  mintIsApproved: (borrowed: TAmount) => Promise<boolean>;
11
11
  mintApprove: (borrowed: TAmount) => Promise<string[]>;
12
- mint: (amount: TAmount) => Promise<string>;
12
+ mint: (shares: TAmount) => Promise<string>;
13
13
  maxWithdraw: (address?: string) => Promise<string>;
14
- previewWithdraw: (amount: TAmount) => Promise<string>;
15
- withdraw: (amount: TAmount) => Promise<string>;
14
+ previewWithdraw: (borrowed: TAmount) => Promise<string>;
15
+ withdraw: (borrowed: TAmount) => Promise<string>;
16
16
  maxRedeem: (address?: string) => Promise<string>;
17
- previewRedeem: (amount: TAmount) => Promise<string>;
18
- redeem: (amount: TAmount) => Promise<string>;
17
+ previewRedeem: (shares: TAmount) => Promise<string>;
18
+ redeem: (shares: TAmount) => Promise<string>;
19
19
  convertToShares: (assets: TAmount) => Promise<string>;
20
20
  convertToAssets: (shares: TAmount) => Promise<string>;
21
21
  stakeIsApproved: (vaultShares: number | string) => Promise<boolean>;
@@ -40,12 +40,12 @@ export interface IVault {
40
40
  }[]>;
41
41
  claimRewards: () => Promise<string>;
42
42
  estimateGas: {
43
- depositApprove: (amount: TAmount) => Promise<TGas>;
44
- deposit: (amount: TAmount) => Promise<TGas>;
45
- mintApprove: (amount: TAmount) => Promise<TGas>;
46
- mint: (amount: TAmount) => Promise<TGas>;
47
- withdraw: (amount: TAmount) => Promise<TGas>;
48
- redeem: (amount: TAmount) => Promise<TGas>;
43
+ depositApprove: (borrowed: TAmount) => Promise<TGas>;
44
+ deposit: (borrowed: TAmount) => Promise<TGas>;
45
+ mintApprove: (borrowed: TAmount) => Promise<TGas>;
46
+ mint: (shares: TAmount) => Promise<TGas>;
47
+ withdraw: (borrowed: TAmount) => Promise<TGas>;
48
+ redeem: (shares: TAmount) => Promise<TGas>;
49
49
  stakeApprove: (vaultShares: number | string) => Promise<TGas>;
50
50
  stake: (vaultShares: number | string) => Promise<TGas>;
51
51
  unstake: (vaultShares: number | string) => Promise<TGas>;
@@ -33,6 +33,7 @@ export interface ILoanV1 {
33
33
  addCollateral: (collateral: TAmount, address?: string) => Promise<string>;
34
34
  addCollateralFutureLeverage: (collateral: TAmount, userAddress?: string) => Promise<string>;
35
35
  tokensToShrink: (dCollateral?: TAmount, address?: string) => Promise<string>;
36
+ isRepayWithShrinkAvailable: (address?: string) => Promise<boolean>;
36
37
  maxRemovable: () => Promise<string>;
37
38
  removeCollateralBands: (collateral: TAmount) => Promise<[number, number]>;
38
39
  removeCollateralPrices: (collateral: TAmount) => Promise<string[]>;
@@ -33,6 +33,7 @@ export interface ILoanV2 {
33
33
  addCollateral: (collateral: TAmount, address?: string) => Promise<string>;
34
34
  addCollateralFutureLeverage: (collateral: TAmount, userAddress?: string) => Promise<string>;
35
35
  tokensToShrink: (dCollateral?: TAmount, address?: string) => Promise<string>;
36
+ isRepayWithShrinkAvailable: (address?: string) => Promise<boolean>;
36
37
  maxRemovable: () => Promise<string>;
37
38
  removeCollateralBands: (collateral: TAmount) => Promise<[number, number]>;
38
39
  removeCollateralPrices: (collateral: TAmount) => Promise<string[]>;
@@ -40,6 +40,7 @@ export declare abstract class LoanBaseModule {
40
40
  abstract addCollateralHealth(collateral: number | string, full?: boolean, address?: string): Promise<string>;
41
41
  abstract removeCollateralHealth(collateral: number | string, full?: boolean, address?: string): Promise<string>;
42
42
  abstract tokensToShrink(dCollateral?: number | string, address?: string): Promise<string>;
43
+ abstract isRepayWithShrinkAvailable(address?: string): Promise<boolean>;
43
44
  _checkRange(range: number): void;
44
45
  createLoanMaxRecv(collateral: TAmount, range: number): Promise<string>;
45
46
  createLoanMaxRecvAllRanges: ((collateral: number | string) => Promise<{
@@ -6,31 +6,31 @@ export declare class VaultModule {
6
6
  private llamalend;
7
7
  constructor(market: LendMarketTemplate);
8
8
  vaultMaxDeposit(address?: string): Promise<string>;
9
- vaultPreviewDeposit(amount: TAmount): Promise<string>;
9
+ vaultPreviewDeposit(borrowed: TAmount): Promise<string>;
10
10
  vaultDepositIsApproved(borrowed: TAmount): Promise<boolean>;
11
11
  vaultDepositApproveEstimateGas(borrowed: TAmount): Promise<TGas>;
12
12
  vaultDepositApprove(borrowed: TAmount): Promise<string[]>;
13
13
  private _vaultDeposit;
14
- vaultDepositEstimateGas(amount: TAmount): Promise<TGas>;
15
- vaultDeposit(amount: TAmount): Promise<string>;
14
+ vaultDepositEstimateGas(borrowed: TAmount): Promise<TGas>;
15
+ vaultDeposit(borrowed: TAmount): Promise<string>;
16
16
  vaultMaxMint(address?: string): Promise<string>;
17
- vaultPreviewMint(amount: TAmount): Promise<string>;
17
+ vaultPreviewMint(shares: TAmount): Promise<string>;
18
18
  vaultMintIsApproved(borrowed: TAmount): Promise<boolean>;
19
19
  vaultMintApproveEstimateGas(borrowed: TAmount): Promise<TGas>;
20
20
  vaultMintApprove(borrowed: TAmount): Promise<string[]>;
21
21
  private _vaultMint;
22
- vaultMintEstimateGas(amount: TAmount): Promise<TGas>;
23
- vaultMint(amount: TAmount): Promise<string>;
22
+ vaultMintEstimateGas(shares: TAmount): Promise<TGas>;
23
+ vaultMint(shares: TAmount): Promise<string>;
24
24
  vaultMaxWithdraw(address?: string): Promise<string>;
25
- vaultPreviewWithdraw(amount: TAmount): Promise<string>;
25
+ vaultPreviewWithdraw(borrowed: TAmount): Promise<string>;
26
26
  private _vaultWithdraw;
27
- vaultWithdrawEstimateGas(amount: TAmount): Promise<TGas>;
28
- vaultWithdraw(amount: TAmount): Promise<string>;
27
+ vaultWithdrawEstimateGas(borrowed: TAmount): Promise<TGas>;
28
+ vaultWithdraw(borrowed: TAmount): Promise<string>;
29
29
  vaultMaxRedeem(address?: string): Promise<string>;
30
- vaultPreviewRedeem(amount: TAmount): Promise<string>;
30
+ vaultPreviewRedeem(shares: TAmount): Promise<string>;
31
31
  private _vaultRedeem;
32
- vaultRedeemEstimateGas(amount: TAmount): Promise<TGas>;
33
- vaultRedeem(amount: TAmount): Promise<string>;
32
+ vaultRedeemEstimateGas(shares: TAmount): Promise<TGas>;
33
+ vaultRedeem(shares: TAmount): Promise<string>;
34
34
  vaultConvertToShares(assets: TAmount): Promise<string>;
35
35
  vaultConvertToAssets(shares: TAmount): Promise<string>;
36
36
  vaultStakeIsApproved(vaultShares: number | string): Promise<boolean>;
@@ -154,9 +154,9 @@ export class VaultModule {
154
154
  return formatUnits(_amount, this.market.borrowed_token.decimals);
155
155
  });
156
156
  }
157
- vaultPreviewDeposit(amount) {
157
+ vaultPreviewDeposit(borrowed) {
158
158
  return __awaiter(this, void 0, void 0, function* () {
159
- const _amount = parseUnits(amount, this.market.borrowed_token.decimals);
159
+ const _amount = parseUnits(borrowed, this.market.borrowed_token.decimals);
160
160
  const _shares = yield this.llamalend.contracts[this.market.addresses.vault].contract.previewDeposit(_amount);
161
161
  return formatUnits(_shares, 18);
162
162
  });
@@ -176,9 +176,9 @@ export class VaultModule {
176
176
  return yield ensureAllowance.call(this.llamalend, [this.market.borrowed_token.address], [borrowed], this.market.addresses.vault);
177
177
  });
178
178
  }
179
- _vaultDeposit(amount_1) {
180
- return __awaiter(this, arguments, void 0, function* (amount, estimateGas = false) {
181
- const _amount = parseUnits(amount, this.market.borrowed_token.decimals);
179
+ _vaultDeposit(borrowed_1) {
180
+ return __awaiter(this, arguments, void 0, function* (borrowed, estimateGas = false) {
181
+ const _amount = parseUnits(borrowed, this.market.borrowed_token.decimals);
182
182
  const gas = yield this.llamalend.contracts[this.market.addresses.vault].contract.deposit.estimateGas(_amount, Object.assign({}, this.llamalend.constantOptions));
183
183
  if (estimateGas)
184
184
  return smartNumber(gas);
@@ -187,17 +187,17 @@ export class VaultModule {
187
187
  return (yield this.llamalend.contracts[this.market.addresses.vault].contract.deposit(_amount, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
188
188
  });
189
189
  }
190
- vaultDepositEstimateGas(amount) {
190
+ vaultDepositEstimateGas(borrowed) {
191
191
  return __awaiter(this, void 0, void 0, function* () {
192
- if (!(yield this.vaultDepositIsApproved(amount)))
192
+ if (!(yield this.vaultDepositIsApproved(borrowed)))
193
193
  throw Error("Approval is needed for gas estimation");
194
- return yield this._vaultDeposit(amount, true);
194
+ return yield this._vaultDeposit(borrowed, true);
195
195
  });
196
196
  }
197
- vaultDeposit(amount) {
197
+ vaultDeposit(borrowed) {
198
198
  return __awaiter(this, void 0, void 0, function* () {
199
- yield this.vaultDepositApprove(amount);
200
- return yield this._vaultDeposit(amount, false);
199
+ yield this.vaultDepositApprove(borrowed);
200
+ return yield this._vaultDeposit(borrowed, false);
201
201
  });
202
202
  }
203
203
  vaultMaxMint() {
@@ -209,9 +209,9 @@ export class VaultModule {
209
209
  return formatUnits(_shares, 18);
210
210
  });
211
211
  }
212
- vaultPreviewMint(amount) {
212
+ vaultPreviewMint(shares) {
213
213
  return __awaiter(this, void 0, void 0, function* () {
214
- const _amount = parseUnits(amount, 18);
214
+ const _amount = parseUnits(shares, 18);
215
215
  const _assets = yield this.llamalend.contracts[this.market.addresses.vault].contract.previewMint(_amount);
216
216
  return formatUnits(_assets, this.market.borrowed_token.decimals);
217
217
  });
@@ -231,9 +231,9 @@ export class VaultModule {
231
231
  return yield ensureAllowance.call(this.llamalend, [this.market.borrowed_token.address], [borrowed], this.market.addresses.vault);
232
232
  });
233
233
  }
234
- _vaultMint(amount_1) {
235
- return __awaiter(this, arguments, void 0, function* (amount, estimateGas = false) {
236
- const _amount = parseUnits(amount, 18);
234
+ _vaultMint(shares_1) {
235
+ return __awaiter(this, arguments, void 0, function* (shares, estimateGas = false) {
236
+ const _amount = parseUnits(shares, 18);
237
237
  const gas = yield this.llamalend.contracts[this.market.addresses.vault].contract.mint.estimateGas(_amount, Object.assign({}, this.llamalend.constantOptions));
238
238
  if (estimateGas)
239
239
  return smartNumber(gas);
@@ -242,17 +242,17 @@ export class VaultModule {
242
242
  return (yield this.llamalend.contracts[this.market.addresses.vault].contract.mint(_amount, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
243
243
  });
244
244
  }
245
- vaultMintEstimateGas(amount) {
245
+ vaultMintEstimateGas(shares) {
246
246
  return __awaiter(this, void 0, void 0, function* () {
247
- if (!(yield this.vaultMintIsApproved(amount)))
247
+ if (!(yield this.vaultMintIsApproved(shares)))
248
248
  throw Error("Approval is needed for gas estimation");
249
- return yield this._vaultMint(amount, true);
249
+ return yield this._vaultMint(shares, true);
250
250
  });
251
251
  }
252
- vaultMint(amount) {
252
+ vaultMint(shares) {
253
253
  return __awaiter(this, void 0, void 0, function* () {
254
- yield this.vaultMintApprove(amount);
255
- return yield this._vaultMint(amount, false);
254
+ yield this.vaultMintApprove(shares);
255
+ return yield this._vaultMint(shares, false);
256
256
  });
257
257
  }
258
258
  vaultMaxWithdraw() {
@@ -262,16 +262,16 @@ export class VaultModule {
262
262
  return formatUnits(_assets, this.market.borrowed_token.decimals);
263
263
  });
264
264
  }
265
- vaultPreviewWithdraw(amount) {
265
+ vaultPreviewWithdraw(borrowed) {
266
266
  return __awaiter(this, void 0, void 0, function* () {
267
- const _amount = parseUnits(amount, this.market.borrowed_token.decimals);
267
+ const _amount = parseUnits(borrowed, this.market.borrowed_token.decimals);
268
268
  const _shares = yield this.llamalend.contracts[this.market.addresses.vault].contract.previewWithdraw(_amount);
269
269
  return formatUnits(_shares, 18);
270
270
  });
271
271
  }
272
- _vaultWithdraw(amount_1) {
273
- return __awaiter(this, arguments, void 0, function* (amount, estimateGas = false) {
274
- const _amount = parseUnits(amount, this.market.borrowed_token.decimals);
272
+ _vaultWithdraw(borrowed_1) {
273
+ return __awaiter(this, arguments, void 0, function* (borrowed, estimateGas = false) {
274
+ const _amount = parseUnits(borrowed, this.market.borrowed_token.decimals);
275
275
  const gas = yield this.llamalend.contracts[this.market.addresses.vault].contract.withdraw.estimateGas(_amount, Object.assign({}, this.llamalend.constantOptions));
276
276
  if (estimateGas)
277
277
  return smartNumber(gas);
@@ -280,14 +280,14 @@ export class VaultModule {
280
280
  return (yield this.llamalend.contracts[this.market.addresses.vault].contract.withdraw(_amount, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
281
281
  });
282
282
  }
283
- vaultWithdrawEstimateGas(amount) {
283
+ vaultWithdrawEstimateGas(borrowed) {
284
284
  return __awaiter(this, void 0, void 0, function* () {
285
- return yield this._vaultWithdraw(amount, true);
285
+ return yield this._vaultWithdraw(borrowed, true);
286
286
  });
287
287
  }
288
- vaultWithdraw(amount) {
288
+ vaultWithdraw(borrowed) {
289
289
  return __awaiter(this, void 0, void 0, function* () {
290
- return yield this._vaultWithdraw(amount, false);
290
+ return yield this._vaultWithdraw(borrowed, false);
291
291
  });
292
292
  }
293
293
  vaultMaxRedeem() {
@@ -297,16 +297,16 @@ export class VaultModule {
297
297
  return formatUnits(_shares, 18);
298
298
  });
299
299
  }
300
- vaultPreviewRedeem(amount) {
300
+ vaultPreviewRedeem(shares) {
301
301
  return __awaiter(this, void 0, void 0, function* () {
302
- const _amount = parseUnits(amount, 18);
302
+ const _amount = parseUnits(shares, 18);
303
303
  const _assets = yield this.llamalend.contracts[this.market.addresses.vault].contract.previewRedeem(_amount);
304
304
  return formatUnits(_assets, this.market.borrowed_token.decimals);
305
305
  });
306
306
  }
307
- _vaultRedeem(amount_1) {
308
- return __awaiter(this, arguments, void 0, function* (amount, estimateGas = false) {
309
- const _amount = parseUnits(amount, 18);
307
+ _vaultRedeem(shares_1) {
308
+ return __awaiter(this, arguments, void 0, function* (shares, estimateGas = false) {
309
+ const _amount = parseUnits(shares, 18);
310
310
  const gas = yield this.llamalend.contracts[this.market.addresses.vault].contract.redeem.estimateGas(_amount, Object.assign({}, this.llamalend.constantOptions));
311
311
  if (estimateGas)
312
312
  return smartNumber(gas);
@@ -315,14 +315,14 @@ export class VaultModule {
315
315
  return (yield this.llamalend.contracts[this.market.addresses.vault].contract.redeem(_amount, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
316
316
  });
317
317
  }
318
- vaultRedeemEstimateGas(amount) {
318
+ vaultRedeemEstimateGas(shares) {
319
319
  return __awaiter(this, void 0, void 0, function* () {
320
- return yield this._vaultRedeem(amount, true);
320
+ return yield this._vaultRedeem(shares, true);
321
321
  });
322
322
  }
323
- vaultRedeem(amount) {
323
+ vaultRedeem(shares) {
324
324
  return __awaiter(this, void 0, void 0, function* () {
325
- return yield this._vaultRedeem(amount, false);
325
+ return yield this._vaultRedeem(shares, false);
326
326
  });
327
327
  }
328
328
  // ---------------- VAULT UTILS ----------------
@@ -11,6 +11,7 @@ export declare class LoanV1Module extends LoanBaseModule implements ILoanV1 {
11
11
  addCollateralHealth(collateral: number | string, full?: boolean, address?: string): Promise<string>;
12
12
  removeCollateralHealth(collateral: number | string, full?: boolean, address?: string): Promise<string>;
13
13
  tokensToShrink(): Promise<string>;
14
+ isRepayWithShrinkAvailable(): Promise<boolean>;
14
15
  protected _repayBands({ debt, address }: {
15
16
  debt: number | string;
16
17
  address: string;
@@ -80,6 +80,11 @@ export class LoanV1Module extends LoanBaseModule {
80
80
  throw Error("tokensToShrink is not supported for v1 markets");
81
81
  });
82
82
  }
83
+ isRepayWithShrinkAvailable() {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ return false;
86
+ });
87
+ }
83
88
  _repayBands(_a) {
84
89
  return __awaiter(this, arguments, void 0, function* ({ debt, address }) {
85
90
  const { _collateral: _currentCollateral, _borrowed, _debt: _currentDebt, _N } = yield this.market.userPosition.userStateBigInt(address);
@@ -6,6 +6,7 @@ export declare class LoanV2Module extends LoanBaseModule implements ILoanV2 {
6
6
  addCollateralHealth(collateral: number | string, full?: boolean, address?: string): Promise<string>;
7
7
  removeCollateralHealth(collateral: number | string, full?: boolean, address?: string): Promise<string>;
8
8
  tokensToShrink(dCollateral?: number | string, address?: string): Promise<string>;
9
+ isRepayWithShrinkAvailable(address?: string): Promise<boolean>;
9
10
  maxRemovable(): Promise<string>;
10
11
  borrowMoreHealth(collateral: number | string, debt: number | string, full?: boolean, address?: string): Promise<string>;
11
12
  repayHealth({ debt, shrink, full, address }: {
@@ -57,6 +57,17 @@ export class LoanV2Module extends LoanBaseModule {
57
57
  return formatUnits(_tokens, this.market.borrowed_token.decimals);
58
58
  });
59
59
  }
60
+ isRepayWithShrinkAvailable() {
61
+ return __awaiter(this, arguments, void 0, function* (address = "") {
62
+ address = _getAddress.call(this.llamalend, address);
63
+ const { isSoftLiquidation } = yield this.market.userPosition.userState(address);
64
+ if (!isSoftLiquidation)
65
+ return false;
66
+ const bandsBalances = yield this.market.userPosition.userBandsBalances(address);
67
+ const bandsWithoutConversion = Object.values(bandsBalances).filter(({ borrowed }) => Number(borrowed) === 0).length;
68
+ return bandsWithoutConversion >= this.market.minBands;
69
+ });
70
+ }
60
71
  maxRemovable() {
61
72
  return __awaiter(this, void 0, void 0, function* () {
62
73
  const address = _getAddress.call(this.llamalend, '');
package/lib/st-crvUSD.js CHANGED
@@ -76,7 +76,7 @@ export function depositApproveEstimateGas(assets) {
76
76
  });
77
77
  }
78
78
  export function depositApprove(assets_1) {
79
- return __awaiter(this, arguments, void 0, function* (assets, isMax = true) {
79
+ return __awaiter(this, arguments, void 0, function* (assets, isMax = false) {
80
80
  return yield ensureAllowance.call(this, [this.constants.ALIASES.crvUSD], [assets], this.constants.ALIASES.st_crvUSD, isMax);
81
81
  });
82
82
  }
@@ -147,7 +147,7 @@ export function mintApproveEstimateGas(shares) {
147
147
  });
148
148
  }
149
149
  export function mintApprove(shares_1) {
150
- return __awaiter(this, arguments, void 0, function* (shares, isMax = true) {
150
+ return __awaiter(this, arguments, void 0, function* (shares, isMax = false) {
151
151
  const assets = yield previewMint.call(this, shares);
152
152
  return yield ensureAllowance.call(this, [this.constants.ALIASES.crvUSD], [assets], this.constants.ALIASES.st_crvUSD, isMax);
153
153
  });
package/lib/utils.js CHANGED
@@ -214,7 +214,7 @@ export const hasAllowance = function (coins, amounts, address, spender) {
214
214
  });
215
215
  };
216
216
  export const _ensureAllowance = function (coins_1, _amounts_1, spender_1) {
217
- return __awaiter(this, arguments, void 0, function* (coins, _amounts, spender, isMax = true) {
217
+ return __awaiter(this, arguments, void 0, function* (coins, _amounts, spender, isMax = false) {
218
218
  const address = this.signerAddress;
219
219
  const _allowance = yield _getAllowance.call(this, coins, address, spender);
220
220
  const txHashes = [];
@@ -232,7 +232,7 @@ export const _ensureAllowance = function (coins_1, _amounts_1, spender_1) {
232
232
  };
233
233
  // coins can be either addresses or symbols
234
234
  export const ensureAllowanceEstimateGas = function (coins_1, amounts_1, spender_1) {
235
- return __awaiter(this, arguments, void 0, function* (coins, amounts, spender, isMax = true) {
235
+ return __awaiter(this, arguments, void 0, function* (coins, amounts, spender, isMax = false) {
236
236
  const coinAddresses = _getCoinAddresses.call(this, coins);
237
237
  const decimals = _getCoinDecimals.call(this, coinAddresses).map((item) => Number(item));
238
238
  const _amounts = amounts.map((a, i) => parseUnits(a, decimals[i]));
@@ -251,7 +251,7 @@ export const ensureAllowanceEstimateGas = function (coins_1, amounts_1, spender_
251
251
  };
252
252
  // coins can be either addresses or symbols
253
253
  export const ensureAllowance = function (coins_1, amounts_1, spender_1) {
254
- return __awaiter(this, arguments, void 0, function* (coins, amounts, spender, isMax = true) {
254
+ return __awaiter(this, arguments, void 0, function* (coins, amounts, spender, isMax = false) {
255
255
  const coinAddresses = _getCoinAddresses.call(this, coins);
256
256
  const decimals = _getCoinDecimals.call(this, coinAddresses).map((item) => Number(item));
257
257
  const _amounts = amounts.map((a, i) => parseUnits(a, decimals[i]));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/llamalend-api",
3
- "version": "2.3.1",
3
+ "version": "2.3.3",
4
4
  "description": "JavaScript library for Curve Lending",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",
@@ -37,16 +37,15 @@
37
37
  "chai": "^5.3.3",
38
38
  "eslint": "^9.38.0",
39
39
  "globals": "^16.4.0",
40
- "mocha": "^11.7.5",
40
+ "mocha": "^11.7.6",
41
41
  "typescript": "^5.9.3",
42
42
  "vue-eslint-parser": "^10.2.0"
43
43
  },
44
44
  "overrides": {
45
- "serialize-javascript": "^7.0.4",
46
- "diff": "^8.0.3"
45
+ "serialize-javascript": "^7.0.4"
47
46
  },
48
47
  "dependencies": {
49
- "@curvefi/ethcall": "6.0.16",
48
+ "@curvefi/ethcall": "6.0.20",
50
49
  "bignumber.js": "9.3.1",
51
50
  "ethers": "6.17.0",
52
51
  "memoizee": "0.4.17"
@@ -250,6 +250,7 @@ export class LendMarketTemplate<V extends 'v1' | 'v2' = 'v1' | 'v2'> {
250
250
  removeCollateralPrices: loan.removeCollateralPrices.bind(loan),
251
251
  removeCollateralHealth: loan.removeCollateralHealth.bind(loan),
252
252
  tokensToShrink: loan.tokensToShrink.bind(loan),
253
+ isRepayWithShrinkAvailable: loan.isRepayWithShrinkAvailable.bind(loan),
253
254
  removeCollateral: loan.removeCollateral.bind(loan),
254
255
  removeCollateralFutureLeverage: loan.removeCollateralFutureLeverage.bind(loan),
255
256
 
@@ -2,21 +2,21 @@ import {IReward, TAmount, TGas} from "../../../interfaces";
2
2
 
3
3
  export interface IVault {
4
4
  maxDeposit: (address?: string) => Promise<string>,
5
- previewDeposit: (amount: TAmount) => Promise<string>,
5
+ previewDeposit: (borrowed: TAmount) => Promise<string>,
6
6
  depositIsApproved: (borrowed: TAmount) => Promise<boolean>
7
7
  depositApprove: (borrowed: TAmount) => Promise<string[]>
8
- deposit: (amount: TAmount) => Promise<string>,
8
+ deposit: (borrowed: TAmount) => Promise<string>,
9
9
  maxMint: (address?: string) => Promise<string>,
10
- previewMint: (amount: TAmount) => Promise<string>,
10
+ previewMint: (shares: TAmount) => Promise<string>,
11
11
  mintIsApproved: (borrowed: TAmount) => Promise<boolean>
12
12
  mintApprove: (borrowed: TAmount) => Promise<string[]>
13
- mint: (amount: TAmount) => Promise<string>,
13
+ mint: (shares: TAmount) => Promise<string>,
14
14
  maxWithdraw: (address?: string) => Promise<string>,
15
- previewWithdraw: (amount: TAmount) => Promise<string>,
16
- withdraw: (amount: TAmount) => Promise<string>,
15
+ previewWithdraw: (borrowed: TAmount) => Promise<string>,
16
+ withdraw: (borrowed: TAmount) => Promise<string>,
17
17
  maxRedeem: (address?: string) => Promise<string>,
18
- previewRedeem: (amount: TAmount) => Promise<string>,
19
- redeem: (amount: TAmount) => Promise<string>,
18
+ previewRedeem: (shares: TAmount) => Promise<string>,
19
+ redeem: (shares: TAmount) => Promise<string>,
20
20
  convertToShares: (assets: TAmount) => Promise<string>,
21
21
  convertToAssets: (shares: TAmount) => Promise<string>,
22
22
  stakeIsApproved: (vaultShares: number | string) => Promise<boolean>,
@@ -33,12 +33,12 @@ export interface IVault {
33
33
  claimableRewards: (address?: string) => Promise<{token: string, symbol: string, amount: string}[]>,
34
34
  claimRewards: () => Promise<string>,
35
35
  estimateGas: {
36
- depositApprove: (amount: TAmount) => Promise<TGas>,
37
- deposit: (amount: TAmount) => Promise<TGas>,
38
- mintApprove: (amount: TAmount) => Promise<TGas>,
39
- mint: (amount: TAmount) => Promise<TGas>,
40
- withdraw: (amount: TAmount) => Promise<TGas>,
41
- redeem: (amount: TAmount) => Promise<TGas>,
36
+ depositApprove: (borrowed: TAmount) => Promise<TGas>,
37
+ deposit: (borrowed: TAmount) => Promise<TGas>,
38
+ mintApprove: (borrowed: TAmount) => Promise<TGas>,
39
+ mint: (shares: TAmount) => Promise<TGas>,
40
+ withdraw: (borrowed: TAmount) => Promise<TGas>,
41
+ redeem: (shares: TAmount) => Promise<TGas>,
42
42
  stakeApprove: (vaultShares: number | string) => Promise<TGas>,
43
43
  stake: (vaultShares: number | string) => Promise<TGas>,
44
44
  unstake: (vaultShares: number | string) => Promise<TGas>,
@@ -31,6 +31,7 @@ export interface ILoanV1 {
31
31
  addCollateralFutureLeverage: (collateral: TAmount, userAddress?: string) => Promise<string>;
32
32
 
33
33
  tokensToShrink: (dCollateral?: TAmount, address?: string) => Promise<string>;
34
+ isRepayWithShrinkAvailable: (address?: string) => Promise<boolean>;
34
35
 
35
36
  maxRemovable: () => Promise<string>;
36
37
  removeCollateralBands: (collateral: TAmount) => Promise<[number, number]>;
@@ -31,6 +31,7 @@ export interface ILoanV2 {
31
31
  addCollateralFutureLeverage: (collateral: TAmount, userAddress?: string) => Promise<string>;
32
32
 
33
33
  tokensToShrink: (dCollateral?: TAmount, address?: string) => Promise<string>;
34
+ isRepayWithShrinkAvailable: (address?: string) => Promise<boolean>;
34
35
 
35
36
  maxRemovable: () => Promise<string>;
36
37
  removeCollateralBands: (collateral: TAmount) => Promise<[number, number]>;
@@ -58,6 +58,8 @@ export abstract class LoanBaseModule {
58
58
 
59
59
  public abstract tokensToShrink(dCollateral?: number | string, address?: string): Promise<string>;
60
60
 
61
+ public abstract isRepayWithShrinkAvailable(address?: string): Promise<boolean>;
62
+
61
63
  public _checkRange(range: number): void {
62
64
  if (range < this.market.minBands) throw Error(`range must be >= ${this.market.minBands}`);
63
65
  if (range > this.market.maxBands) throw Error(`range must be <= ${this.market.maxBands}`);
@@ -39,8 +39,8 @@ export class VaultModule {
39
39
  return formatUnits(_amount, this.market.borrowed_token.decimals);
40
40
  }
41
41
 
42
- public async vaultPreviewDeposit(amount: TAmount): Promise<string> {
43
- const _amount = parseUnits(amount, this.market.borrowed_token.decimals);
42
+ public async vaultPreviewDeposit(borrowed: TAmount): Promise<string> {
43
+ const _amount = parseUnits(borrowed, this.market.borrowed_token.decimals);
44
44
  const _shares = await this.llamalend.contracts[this.market.addresses.vault].contract.previewDeposit(_amount);
45
45
 
46
46
  return formatUnits(_shares, 18);
@@ -58,8 +58,8 @@ export class VaultModule {
58
58
  return await ensureAllowance.call(this.llamalend, [this.market.borrowed_token.address], [borrowed], this.market.addresses.vault);
59
59
  }
60
60
 
61
- private async _vaultDeposit(amount: TAmount, estimateGas = false): Promise<string | TGas> {
62
- const _amount = parseUnits(amount, this.market.borrowed_token.decimals);
61
+ private async _vaultDeposit(borrowed: TAmount, estimateGas = false): Promise<string | TGas> {
62
+ const _amount = parseUnits(borrowed, this.market.borrowed_token.decimals);
63
63
  const gas = await this.llamalend.contracts[this.market.addresses.vault].contract.deposit.estimateGas(_amount, { ...this.llamalend.constantOptions });
64
64
  if (estimateGas) return smartNumber(gas);
65
65
 
@@ -70,14 +70,14 @@ export class VaultModule {
70
70
  return (await this.llamalend.contracts[this.market.addresses.vault].contract.deposit(_amount, { ...this.llamalend.options, gasLimit })).hash;
71
71
  }
72
72
 
73
- public async vaultDepositEstimateGas(amount: TAmount): Promise<TGas> {
74
- if (!(await this.vaultDepositIsApproved(amount))) throw Error("Approval is needed for gas estimation");
75
- return await this._vaultDeposit(amount, true) as number;
73
+ public async vaultDepositEstimateGas(borrowed: TAmount): Promise<TGas> {
74
+ if (!(await this.vaultDepositIsApproved(borrowed))) throw Error("Approval is needed for gas estimation");
75
+ return await this._vaultDeposit(borrowed, true) as number;
76
76
  }
77
77
 
78
- public async vaultDeposit(amount: TAmount): Promise<string> {
79
- await this.vaultDepositApprove(amount);
80
- return await this._vaultDeposit(amount, false) as string;
78
+ public async vaultDeposit(borrowed: TAmount): Promise<string> {
79
+ await this.vaultDepositApprove(borrowed);
80
+ return await this._vaultDeposit(borrowed, false) as string;
81
81
  }
82
82
 
83
83
 
@@ -90,8 +90,8 @@ export class VaultModule {
90
90
  return formatUnits(_shares, 18);
91
91
  }
92
92
 
93
- public async vaultPreviewMint(amount: TAmount): Promise<string> {
94
- const _amount = parseUnits(amount, 18);
93
+ public async vaultPreviewMint(shares: TAmount): Promise<string> {
94
+ const _amount = parseUnits(shares, 18);
95
95
  const _assets = await this.llamalend.contracts[this.market.addresses.vault].contract.previewMint(_amount);
96
96
 
97
97
  return formatUnits(_assets, this.market.borrowed_token.decimals);
@@ -109,8 +109,8 @@ export class VaultModule {
109
109
  return await ensureAllowance.call(this.llamalend, [this.market.borrowed_token.address], [borrowed], this.market.addresses.vault);
110
110
  }
111
111
 
112
- private async _vaultMint(amount: TAmount, estimateGas = false): Promise<string | TGas> {
113
- const _amount = parseUnits(amount, 18);
112
+ private async _vaultMint(shares: TAmount, estimateGas = false): Promise<string | TGas> {
113
+ const _amount = parseUnits(shares, 18);
114
114
  const gas = await this.llamalend.contracts[this.market.addresses.vault].contract.mint.estimateGas(_amount, { ...this.llamalend.constantOptions });
115
115
  if (estimateGas) return smartNumber(gas);
116
116
 
@@ -121,14 +121,14 @@ export class VaultModule {
121
121
  return (await this.llamalend.contracts[this.market.addresses.vault].contract.mint(_amount, { ...this.llamalend.options, gasLimit })).hash;
122
122
  }
123
123
 
124
- public async vaultMintEstimateGas(amount: TAmount): Promise<TGas> {
125
- if (!(await this.vaultMintIsApproved(amount))) throw Error("Approval is needed for gas estimation");
126
- return await this._vaultMint(amount, true) as number;
124
+ public async vaultMintEstimateGas(shares: TAmount): Promise<TGas> {
125
+ if (!(await this.vaultMintIsApproved(shares))) throw Error("Approval is needed for gas estimation");
126
+ return await this._vaultMint(shares, true) as number;
127
127
  }
128
128
 
129
- public async vaultMint(amount: TAmount): Promise<string> {
130
- await this.vaultMintApprove(amount);
131
- return await this._vaultMint(amount, false) as string;
129
+ public async vaultMint(shares: TAmount): Promise<string> {
130
+ await this.vaultMintApprove(shares);
131
+ return await this._vaultMint(shares, false) as string;
132
132
  }
133
133
 
134
134
 
@@ -139,15 +139,15 @@ export class VaultModule {
139
139
  return formatUnits(_assets, this.market.borrowed_token.decimals);
140
140
  }
141
141
 
142
- public async vaultPreviewWithdraw(amount: TAmount): Promise<string> {
143
- const _amount = parseUnits(amount, this.market.borrowed_token.decimals);
142
+ public async vaultPreviewWithdraw(borrowed: TAmount): Promise<string> {
143
+ const _amount = parseUnits(borrowed, this.market.borrowed_token.decimals);
144
144
  const _shares = await this.llamalend.contracts[this.market.addresses.vault].contract.previewWithdraw(_amount);
145
145
 
146
146
  return formatUnits(_shares, 18);
147
147
  }
148
148
 
149
- private async _vaultWithdraw(amount: TAmount, estimateGas = false): Promise<string | TGas> {
150
- const _amount = parseUnits(amount, this.market.borrowed_token.decimals);
149
+ private async _vaultWithdraw(borrowed: TAmount, estimateGas = false): Promise<string | TGas> {
150
+ const _amount = parseUnits(borrowed, this.market.borrowed_token.decimals);
151
151
  const gas = await this.llamalend.contracts[this.market.addresses.vault].contract.withdraw.estimateGas(_amount, { ...this.llamalend.constantOptions });
152
152
  if (estimateGas) return smartNumber(gas);
153
153
 
@@ -158,12 +158,12 @@ export class VaultModule {
158
158
  return (await this.llamalend.contracts[this.market.addresses.vault].contract.withdraw(_amount, { ...this.llamalend.options, gasLimit })).hash;
159
159
  }
160
160
 
161
- public async vaultWithdrawEstimateGas(amount: TAmount): Promise<TGas> {
162
- return await this._vaultWithdraw(amount, true) as number;
161
+ public async vaultWithdrawEstimateGas(borrowed: TAmount): Promise<TGas> {
162
+ return await this._vaultWithdraw(borrowed, true) as number;
163
163
  }
164
164
 
165
- public async vaultWithdraw(amount: TAmount): Promise<string> {
166
- return await this._vaultWithdraw(amount, false) as string;
165
+ public async vaultWithdraw(borrowed: TAmount): Promise<string> {
166
+ return await this._vaultWithdraw(borrowed, false) as string;
167
167
  }
168
168
 
169
169
 
@@ -174,15 +174,15 @@ export class VaultModule {
174
174
  return formatUnits(_shares, 18);
175
175
  }
176
176
 
177
- public async vaultPreviewRedeem(amount: TAmount): Promise<string> {
178
- const _amount = parseUnits(amount, 18);
177
+ public async vaultPreviewRedeem(shares: TAmount): Promise<string> {
178
+ const _amount = parseUnits(shares, 18);
179
179
  const _assets = await this.llamalend.contracts[this.market.addresses.vault].contract.previewRedeem(_amount);
180
180
 
181
181
  return formatUnits(_assets, this.market.borrowed_token.decimals);
182
182
  }
183
183
 
184
- private async _vaultRedeem(amount: TAmount, estimateGas = false): Promise<string | TGas> {
185
- const _amount = parseUnits(amount, 18);
184
+ private async _vaultRedeem(shares: TAmount, estimateGas = false): Promise<string | TGas> {
185
+ const _amount = parseUnits(shares, 18);
186
186
  const gas = await this.llamalend.contracts[this.market.addresses.vault].contract.redeem.estimateGas(_amount, { ...this.llamalend.constantOptions });
187
187
  if (estimateGas) return smartNumber(gas);
188
188
 
@@ -193,12 +193,12 @@ export class VaultModule {
193
193
  return (await this.llamalend.contracts[this.market.addresses.vault].contract.redeem(_amount, { ...this.llamalend.options, gasLimit })).hash;
194
194
  }
195
195
 
196
- public async vaultRedeemEstimateGas(amount: TAmount): Promise<TGas> {
197
- return await this._vaultRedeem(amount, true) as number;
196
+ public async vaultRedeemEstimateGas(shares: TAmount): Promise<TGas> {
197
+ return await this._vaultRedeem(shares, true) as number;
198
198
  }
199
199
 
200
- public async vaultRedeem(amount: TAmount): Promise<string> {
201
- return await this._vaultRedeem(amount, false) as string;
200
+ public async vaultRedeem(shares: TAmount): Promise<string> {
201
+ return await this._vaultRedeem(shares, false) as string;
202
202
  }
203
203
 
204
204
  // ---------------- VAULT UTILS ----------------
@@ -84,6 +84,10 @@ export class LoanV1Module extends LoanBaseModule implements ILoanV1 {
84
84
  throw Error("tokensToShrink is not supported for v1 markets");
85
85
  }
86
86
 
87
+ public async isRepayWithShrinkAvailable(): Promise<boolean> {
88
+ return false;
89
+ }
90
+
87
91
  protected async _repayBands({ debt, address }: { debt: number | string, address: string, shrink?: boolean }): Promise<[bigint, bigint]> {
88
92
  const { _collateral: _currentCollateral, _borrowed, _debt: _currentDebt, _N } = await this.market.userPosition.userStateBigInt(address);
89
93
  if (_currentDebt === BigInt(0)) throw Error(`Loan for ${address} does not exist`);
@@ -53,6 +53,17 @@ export class LoanV2Module extends LoanBaseModule implements ILoanV2 {
53
53
  return formatUnits(_tokens, this.market.borrowed_token.decimals);
54
54
  }
55
55
 
56
+ public async isRepayWithShrinkAvailable(address = ""): Promise<boolean> {
57
+ address = _getAddress.call(this.llamalend, address);
58
+ const { isSoftLiquidation } = await this.market.userPosition.userState(address);
59
+ if (!isSoftLiquidation) return false;
60
+
61
+ const bandsBalances = await this.market.userPosition.userBandsBalances(address);
62
+ const bandsWithoutConversion = Object.values(bandsBalances).filter(({ borrowed }) => Number(borrowed) === 0).length;
63
+
64
+ return bandsWithoutConversion >= this.market.minBands;
65
+ }
66
+
56
67
  public async maxRemovable(): Promise<string> {
57
68
  const address = _getAddress.call(this.llamalend, '');
58
69
  const { _collateral: _currentCollateral, _debt: _currentDebt, _N } = await this.market.userPosition.userStateBigInt();
package/src/st-crvUSD.ts CHANGED
@@ -78,7 +78,7 @@ export async function depositApproveEstimateGas(this: Llamalend, assets: TAmount
78
78
  return await ensureAllowanceEstimateGas.call(this, [this.constants.ALIASES.crvUSD], [assets], this.constants.ALIASES.st_crvUSD);
79
79
  }
80
80
 
81
- export async function depositApprove(this: Llamalend, assets: TAmount, isMax = true): Promise<string[]> {
81
+ export async function depositApprove(this: Llamalend, assets: TAmount, isMax = false): Promise<string[]> {
82
82
  return await ensureAllowance.call(this, [this.constants.ALIASES.crvUSD], [assets], this.constants.ALIASES.st_crvUSD, isMax);
83
83
  }
84
84
 
@@ -142,7 +142,7 @@ export async function mintApproveEstimateGas(this: Llamalend, shares: TAmount):
142
142
  return await ensureAllowanceEstimateGas.call(this, [this.constants.ALIASES.crvUSD], [assets], this.constants.ALIASES.st_crvUSD);
143
143
  }
144
144
 
145
- export async function mintApprove(this: Llamalend, shares: TAmount, isMax = true): Promise<string[]> {
145
+ export async function mintApprove(this: Llamalend, shares: TAmount, isMax = false): Promise<string[]> {
146
146
  const assets = await previewMint.call(this, shares);
147
147
  return await ensureAllowance.call(this, [this.constants.ALIASES.crvUSD], [assets], this.constants.ALIASES.st_crvUSD, isMax);
148
148
  }
package/src/utils.ts CHANGED
@@ -235,7 +235,7 @@ export const hasAllowance = async function (this: Llamalend, coins: string[], am
235
235
  return _allowance.map((a, i) => a >= _amounts[i]).reduce((a, b) => a && b);
236
236
  }
237
237
 
238
- export const _ensureAllowance = async function (this: Llamalend, coins: string[], _amounts: bigint[], spender: string, isMax = true): Promise<string[]> {
238
+ export const _ensureAllowance = async function (this: Llamalend, coins: string[], _amounts: bigint[], spender: string, isMax = false): Promise<string[]> {
239
239
  const address = this.signerAddress;
240
240
  const _allowance: bigint[] = await _getAllowance.call(this, coins, address, spender);
241
241
 
@@ -254,7 +254,7 @@ export const _ensureAllowance = async function (this: Llamalend, coins: string[]
254
254
  }
255
255
 
256
256
  // coins can be either addresses or symbols
257
- export const ensureAllowanceEstimateGas = async function (this: Llamalend, coins: string[], amounts: (number | string)[], spender: string, isMax = true): Promise<TGas> {
257
+ export const ensureAllowanceEstimateGas = async function (this: Llamalend, coins: string[], amounts: (number | string)[], spender: string, isMax = false): Promise<TGas> {
258
258
  const coinAddresses = _getCoinAddresses.call(this, coins);
259
259
  const decimals = _getCoinDecimals.call(this, coinAddresses).map((item) => Number(item));
260
260
  const _amounts = amounts.map((a, i) => parseUnits(a, decimals[i]));
@@ -274,7 +274,7 @@ export const ensureAllowanceEstimateGas = async function (this: Llamalend, coins
274
274
  }
275
275
 
276
276
  // coins can be either addresses or symbols
277
- export const ensureAllowance = async function (this: Llamalend, coins: string[], amounts: (number | string)[], spender: string, isMax = true): Promise<string[]> {
277
+ export const ensureAllowance = async function (this: Llamalend, coins: string[], amounts: (number | string)[], spender: string, isMax = false): Promise<string[]> {
278
278
  const coinAddresses = _getCoinAddresses.call(this, coins);
279
279
  const decimals = _getCoinDecimals.call(this, coinAddresses).map((item) => Number(item));
280
280
  const _amounts = amounts.map((a, i) => parseUnits(a, decimals[i]));