@curvefi/llamalend-api 1.1.8 → 1.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -986,15 +986,15 @@ interface ILeverageMetrics {
986
986
  }
987
987
  ```
988
988
 
989
- **2. Final methods now require `router` and `calldata` parameters**
989
+ **2. Final methods now require `router`, `calldata` and `minRecv` parameters**
990
990
  - **Before**: `createLoan(userCollateral, userBorrowed, debt, range)`
991
- - **Now**: `createLoan(userCollateral, userBorrowed, debt, range, router, calldata)`
991
+ - **Now**: `createLoan(userCollateral, userBorrowed, debt, range, minRecv, router, calldata)`
992
992
  - **Before**: `borrowMore(userCollateral, userBorrowed, debt, slippage)`
993
- - **Now**: `borrowMore(userCollateral, userBorrowed, debt, router, calldata)`
993
+ - **Now**: `borrowMore(userCollateral, userBorrowed, debt, minRecv, router, calldata)`
994
994
  - **Before**: `repay(stateCollateral, userCollateral, userBorrowed, slippage)`
995
- - **Now**: `repay(stateCollateral, userCollateral, userBorrowed, router, calldata)`
995
+ - **Now**: `repay(stateCollateral, userCollateral, userBorrowed, minRecv, router, calldata)`
996
996
 
997
- where `router` - address of router, `calldata` - calldata byte code
997
+ where `router` - address of router, `calldata` - calldata byte code, `minRecv` - minimum amount of tokens to receive (see [Security Improvements](#security-improvements))
998
998
 
999
999
  #### Understanding Callback Functions and Quotes
1000
1000
 
@@ -1037,6 +1037,24 @@ interface IQuote {
1037
1037
  - Example: For stateCollateral=2 and userCollateral=1, get quote for swapping 3 collateral tokens to borrowed tokens
1038
1038
 
1039
1039
 
1040
+ #### Security Improvements
1041
+
1042
+ Execution methods (`createLoan`, `borrowMore`, `repay`) accept a `minRecv` parameter that guarantees the minimum amount of tokens received after the swap. This protects the user from slippage and frontrunning.
1043
+
1044
+ Use `calcMinRecv(expected, slippage)` to compute the minimum acceptable amount:
1045
+
1046
+ **Formula:** `minRecv = expected * (100 - slippage) / 100`
1047
+
1048
+ - `expected` — expected amount of tokens from the swap
1049
+ - `slippage` — allowed slippage in percent (e.g. `0.5` for 0.5%)
1050
+
1051
+ ```ts
1052
+ // quote.outAmount — the expected amount from your router (computed on your side)
1053
+ const minRecv = lendMarket.leverageZapV2.calcMinRecv(quote.outAmount, 0.5); // 0.5% slippage
1054
+ await lendMarket.leverageZapV2.createLoan({ userCollateral, userBorrowed, debt, range, minRecv, router, calldata });
1055
+ ```
1056
+
1057
+
1040
1058
  #### Leverage operations with routers
1041
1059
 
1042
1060
  ```ts
@@ -1120,8 +1138,12 @@ interface IQuote {
1120
1138
  // ]
1121
1139
 
1122
1140
 
1141
+ // Calculate minRecv with slippage protection (see Security Improvements)
1142
+ // expected — amount from your router quote
1143
+ const minRecv = lendMarket.leverageZapV2.calcMinRecv(quote.outAmount, 0.5); // 0.5% slippage
1144
+
1123
1145
  // Create loan, passing router address and calldata from router
1124
- await lendMarket.leverageZapV2.createLoan({ userCollateral, userBorrowed, debt, range, router, calldata });
1146
+ await lendMarket.leverageZapV2.createLoan({ userCollateral, userBorrowed, debt, range, minRecv, router, calldata });
1125
1147
  // 0xeb1b7a92bcb02598f00dc8bbfe8fa3a554e7a2b1ca764e0ee45e2bf583edf731
1126
1148
 
1127
1149
  await lendMarket.wallet.balances();
@@ -1207,8 +1229,11 @@ interface IQuote {
1207
1229
  await lendMarket.leverageZapV2.borrowMoreApprove({ userCollateral, userBorrowed });
1208
1230
  // []
1209
1231
 
1232
+ // Calculate minRecv with slippage protection (see Security Improvements)
1233
+ const minRecvBM = lendMarket.leverageZapV2.calcMinRecv(quote.outAmount, 0.5); // 0.5% slippage
1234
+
1210
1235
  // Execute borrowMore, passing router address and calldata from router
1211
- await lendMarket.leverageZapV2.borrowMore({ userCollateral, userBorrowed, debt, router, calldata });
1236
+ await lendMarket.leverageZapV2.borrowMore({ userCollateral, userBorrowed, debt, minRecv: minRecvBM, router, calldata });
1212
1237
  // 0x6357dd6ea7250d7adb2344cd9295f8255fd8fbbe85f00120fbcd1ebf139e057c
1213
1238
 
1214
1239
  await lendMarket.wallet.balances();
@@ -1292,8 +1317,11 @@ interface IQuote {
1292
1317
  await lendMarket.leverageZapV2.repayApprove({ userCollateral, userBorrowed });
1293
1318
  // ['0xd8a8d3b3f67395e1a4f4d4f95b041edcaf1c9f7bab5eb8a8a767467678295498']
1294
1319
 
1320
+ // Calculate minRecv with slippage protection (see Security Improvements)
1321
+ const minRecvRepay = lendMarket.leverageZapV2.calcMinRecv(quote.outAmount, 0.5); // 0.5% slippage
1322
+
1295
1323
  // Execute repay, passing router address and calldata from router
1296
- await lendMarket.leverageZapV2.repay({ stateCollateral, userCollateral, userBorrowed, router, calldata });
1324
+ await lendMarket.leverageZapV2.repay({ stateCollateral, userCollateral, userBorrowed, minRecv: minRecvRepay, router, calldata });
1297
1325
  // 0xe48a97fef1c54180a2c7d104d210a95ac1a516fdd22109682179f1582da23a82
1298
1326
 
1299
1327
  await lendMarket.wallet.balances();
@@ -43,7 +43,7 @@ export const ALIASES_ARBITRUM = lowerCaseValues({
43
43
  "gauge_factory": "0xabC000d88f23Bb45525E447528DBF656A9D55bf5",
44
44
  // "leverage_zap": "0x61C404B60ee9c5fB09F70F9A645DD38fE5b3A956", // 1inch
45
45
  "leverage_zap": "0xFE02553d3Ba4c3f39F36a4632F91404DF94b9AE2", // odos v3
46
- "leverage_zap_v2": "0x5b07Db9a85992c877b9fBeA6DCC4F79292577640",
46
+ "leverage_zap_v2": "0x9577086c6E38d38359872F903Da201f1bdCc0323",
47
47
  "leverage_markets_start_id": "9",
48
48
  });
49
49
  export const ALIASES_OPTIMISM = lowerCaseValues({
@@ -322,6 +322,7 @@ export declare class LendMarketTemplate {
322
322
  A: (() => Promise<string>) & memoize.Memoized<() => Promise<string>>;
323
323
  basePrice: (() => Promise<string>) & memoize.Memoized<() => Promise<string>>;
324
324
  oraclePrice: (() => Promise<string>) & memoize.Memoized<() => Promise<string>>;
325
+ oracleAddress: (() => Promise<string>) & memoize.Memoized<() => Promise<string>>;
325
326
  oraclePriceBand(): Promise<number>;
326
327
  price(): Promise<string>;
327
328
  calcTickPrice(n: number): Promise<string>;
@@ -270,6 +270,12 @@ export class LendMarketTemplate {
270
270
  promise: true,
271
271
  maxAge: 60 * 1000, // 1m
272
272
  });
273
+ this.oracleAddress = memoize(() => __awaiter(this, void 0, void 0, function* () {
274
+ const _address = yield this.llamalend.contracts[this.addresses.amm].contract.price_oracle_contract(this.llamalend.constantOptions);
275
+ return _address;
276
+ }), {
277
+ promise: true,
278
+ });
273
279
  this._userState = memoize((...args_1) => __awaiter(this, [...args_1], void 0, function* (address = "") {
274
280
  address = _getAddress.call(this.llamalend, address);
275
281
  const contract = this.llamalend.contracts[this.addresses.controller].contract;
@@ -635,6 +641,7 @@ export class LendMarketTemplate {
635
641
  createLoanIsApproved: leverageZapV2.leverageCreateLoanIsApproved.bind(leverageZapV2),
636
642
  createLoanApprove: leverageZapV2.leverageCreateLoanApprove.bind(leverageZapV2),
637
643
  createLoanExpectedMetrics: leverageZapV2.leverageCreateLoanExpectedMetrics.bind(leverageZapV2),
644
+ calcMinRecv: leverageZapV2.calcMinRecv.bind(leverageZapV2),
638
645
  createLoan: leverageZapV2.leverageCreateLoan.bind(leverageZapV2),
639
646
  borrowMoreMaxRecv: leverageZapV2.leverageBorrowMoreMaxRecv.bind(leverageZapV2),
640
647
  borrowMoreExpectedCollateral: leverageZapV2.leverageBorrowMoreExpectedCollateral.bind(leverageZapV2),
@@ -78,11 +78,13 @@ export interface ILeverageZapV2 {
78
78
  userCollateral: TAmount;
79
79
  userBorrowed: TAmount;
80
80
  }) => Promise<string[]>;
81
- createLoan: ({ userCollateral, userBorrowed, debt, range, router, calldata, }: {
81
+ calcMinRecv: (expected: TAmount, slippage: number) => string;
82
+ createLoan: ({ userCollateral, userBorrowed, debt, range, minRecv, router, calldata, }: {
82
83
  userCollateral: TAmount;
83
84
  userBorrowed: TAmount;
84
85
  debt: TAmount;
85
86
  range: number;
87
+ minRecv: TAmount;
86
88
  router: string;
87
89
  calldata: string;
88
90
  }) => Promise<string>;
@@ -128,10 +130,11 @@ export interface ILeverageZapV2 {
128
130
  userCollateral: TAmount;
129
131
  userBorrowed: TAmount;
130
132
  }) => Promise<string[]>;
131
- borrowMore: ({ userCollateral, userBorrowed, debt, router, calldata }: {
133
+ borrowMore: ({ userCollateral, userBorrowed, debt, minRecv, router, calldata }: {
132
134
  userCollateral: TAmount;
133
135
  userBorrowed: TAmount;
134
136
  debt: TAmount;
137
+ minRecv: TAmount;
135
138
  router: string;
136
139
  calldata: string;
137
140
  }) => Promise<string>;
@@ -184,10 +187,11 @@ export interface ILeverageZapV2 {
184
187
  userCollateral: TAmount;
185
188
  userBorrowed: TAmount;
186
189
  }) => Promise<string[]>;
187
- repay: ({ stateCollateral, userCollateral, userBorrowed, router, calldata }: {
190
+ repay: ({ stateCollateral, userCollateral, userBorrowed, minRecv, router, calldata }: {
188
191
  stateCollateral: TAmount;
189
192
  userCollateral: TAmount;
190
193
  userBorrowed: TAmount;
194
+ minRecv: TAmount;
191
195
  router: string;
192
196
  calldata: string;
193
197
  }) => Promise<string>;
@@ -203,11 +207,12 @@ export interface ILeverageZapV2 {
203
207
  userCollateral: TAmount;
204
208
  userBorrowed: TAmount;
205
209
  }) => Promise<TGas>;
206
- createLoan: ({ userCollateral, userBorrowed, debt, range, router, calldata }: {
210
+ createLoan: ({ userCollateral, userBorrowed, debt, range, minRecv, router, calldata }: {
207
211
  userCollateral: TAmount;
208
212
  userBorrowed: TAmount;
209
213
  debt: TAmount;
210
214
  range: number;
215
+ minRecv: TAmount;
211
216
  router: string;
212
217
  calldata: string;
213
218
  }) => Promise<number>;
@@ -215,10 +220,11 @@ export interface ILeverageZapV2 {
215
220
  userCollateral: TAmount;
216
221
  userBorrowed: TAmount;
217
222
  }) => Promise<TGas>;
218
- borrowMore: ({ userCollateral, userBorrowed, debt, router, calldata }: {
223
+ borrowMore: ({ userCollateral, userBorrowed, debt, minRecv, router, calldata }: {
219
224
  userCollateral: TAmount;
220
225
  userBorrowed: TAmount;
221
226
  debt: TAmount;
227
+ minRecv: TAmount;
222
228
  router: string;
223
229
  calldata: string;
224
230
  }) => Promise<number>;
@@ -226,10 +232,11 @@ export interface ILeverageZapV2 {
226
232
  userCollateral: TAmount;
227
233
  userBorrowed: TAmount;
228
234
  }) => Promise<TGas>;
229
- repay: ({ stateCollateral, userCollateral, userBorrowed, router, calldata }: {
235
+ repay: ({ stateCollateral, userCollateral, userBorrowed, minRecv, router, calldata }: {
230
236
  stateCollateral: TAmount;
231
237
  userCollateral: TAmount;
232
238
  userBorrowed: TAmount;
239
+ minRecv: TAmount;
233
240
  router: string;
234
241
  calldata: string;
235
242
  }) => Promise<number>;
@@ -14,6 +14,7 @@ export declare class LeverageZapV2Module {
14
14
  _checkLeverageZap(): void;
15
15
  _get_k_effective_BN(N: number): Promise<BigNumber>;
16
16
  maxLeverage(N: number): Promise<string>;
17
+ calcMinRecv(expected: TAmount, slippage: number): string;
17
18
  leverageCreateLoanMaxRecv({ userCollateral, userBorrowed, range, getExpected }: {
18
19
  userCollateral: TAmount;
19
20
  userBorrowed: TAmount;
@@ -113,19 +114,21 @@ export declare class LeverageZapV2Module {
113
114
  userBorrowed: TAmount;
114
115
  }): Promise<string[]>;
115
116
  private _leverageCreateLoan;
116
- leverageCreateLoanEstimateGas({ userCollateral, userBorrowed, debt, range, router, calldata }: {
117
+ leverageCreateLoanEstimateGas({ userCollateral, userBorrowed, debt, range, minRecv, router, calldata }: {
117
118
  userCollateral: TAmount;
118
119
  userBorrowed: TAmount;
119
120
  debt: TAmount;
120
121
  range: number;
122
+ minRecv: TAmount;
121
123
  router: string;
122
124
  calldata: string;
123
125
  }): Promise<number>;
124
- leverageCreateLoan({ userCollateral, userBorrowed, debt, range, router, calldata }: {
126
+ leverageCreateLoan({ userCollateral, userBorrowed, debt, range, minRecv, router, calldata }: {
125
127
  userCollateral: TAmount;
126
128
  userBorrowed: TAmount;
127
129
  debt: TAmount;
128
130
  range: number;
131
+ minRecv: TAmount;
129
132
  router: string;
130
133
  calldata: string;
131
134
  }): Promise<string>;
@@ -172,17 +175,19 @@ export declare class LeverageZapV2Module {
172
175
  userCollateral: TAmount;
173
176
  userBorrowed: TAmount;
174
177
  }): Promise<string[]>;
175
- leverageBorrowMoreEstimateGas({ userCollateral, userBorrowed, debt, router, calldata }: {
178
+ leverageBorrowMoreEstimateGas({ userCollateral, userBorrowed, debt, minRecv, router, calldata }: {
176
179
  userCollateral: TAmount;
177
180
  userBorrowed: TAmount;
178
181
  debt: TAmount;
182
+ minRecv: TAmount;
179
183
  router: string;
180
184
  calldata: string;
181
185
  }): Promise<number>;
182
- leverageBorrowMore({ userCollateral, userBorrowed, debt, router, calldata }: {
186
+ leverageBorrowMore({ userCollateral, userBorrowed, debt, minRecv, router, calldata }: {
183
187
  userCollateral: TAmount;
184
188
  userBorrowed: TAmount;
185
189
  debt: TAmount;
190
+ minRecv: TAmount;
186
191
  router: string;
187
192
  calldata: string;
188
193
  }): Promise<string>;
@@ -243,17 +248,19 @@ export declare class LeverageZapV2Module {
243
248
  userBorrowed: TAmount;
244
249
  }): Promise<string[]>;
245
250
  private _leverageRepay;
246
- leverageRepayEstimateGas({ stateCollateral, userCollateral, userBorrowed, router, calldata }: {
251
+ leverageRepayEstimateGas({ stateCollateral, userCollateral, userBorrowed, minRecv, router, calldata }: {
247
252
  stateCollateral: TAmount;
248
253
  userCollateral: TAmount;
249
254
  userBorrowed: TAmount;
255
+ minRecv: TAmount;
250
256
  router: string;
251
257
  calldata: string;
252
258
  }): Promise<number>;
253
- leverageRepay({ stateCollateral, userCollateral, userBorrowed, router, calldata }: {
259
+ leverageRepay({ stateCollateral, userCollateral, userBorrowed, minRecv, router, calldata }: {
254
260
  stateCollateral: TAmount;
255
261
  userCollateral: TAmount;
256
262
  userBorrowed: TAmount;
263
+ minRecv: TAmount;
257
264
  router: string;
258
265
  calldata: string;
259
266
  }): Promise<string>;
@@ -211,6 +211,11 @@ export class LeverageZapV2Module {
211
211
  return BN(1).div(BN(1).minus(k_effective_BN)).toString();
212
212
  });
213
213
  }
214
+ calcMinRecv(expected, slippage) {
215
+ if (slippage < 0 || slippage > 100)
216
+ throw Error("Slippage must be between 0 and 100");
217
+ return BN(expected).times(BN(100).minus(slippage)).div(100).toString();
218
+ }
214
219
  leverageCreateLoanMaxRecv(_a) {
215
220
  return __awaiter(this, arguments, void 0, function* ({ userCollateral, userBorrowed, range, getExpected }) {
216
221
  // max_borrowable = userCollateral / (1 / (k_effective * max_p_base) - 1 / p_avg)
@@ -400,7 +405,7 @@ export class LeverageZapV2Module {
400
405
  return [...collateralApproveTx, ...borrowedApproveTx];
401
406
  });
402
407
  }
403
- _leverageCreateLoan(userCollateral, userBorrowed, debt, range, router, calldata, estimateGas) {
408
+ _leverageCreateLoan(userCollateral, userBorrowed, debt, range, minRecv, router, calldata, estimateGas) {
404
409
  return __awaiter(this, void 0, void 0, function* () {
405
410
  if (yield this.market.userLoanExists())
406
411
  throw Error("Loan already created");
@@ -408,29 +413,30 @@ export class LeverageZapV2Module {
408
413
  const _userCollateral = parseUnits(userCollateral, this.market.collateral_token.decimals);
409
414
  const _userBorrowed = parseUnits(userBorrowed, this.market.borrowed_token.decimals);
410
415
  const _debt = parseUnits(debt, this.market.borrowed_token.decimals);
416
+ const _minRecv = parseUnits(minRecv, this.market.collateral_token.decimals);
411
417
  const zapCalldata = buildCalldataForLeverageZapV2(router, calldata);
412
418
  const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
413
- const gas = yield contract.create_loan_extended.estimateGas(_userCollateral, _debt, range, this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userBorrowed], zapCalldata, Object.assign({}, this.llamalend.constantOptions));
419
+ const gas = yield contract.create_loan_extended.estimateGas(_userCollateral, _debt, range, this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userBorrowed, _minRecv], zapCalldata, Object.assign({}, this.llamalend.constantOptions));
414
420
  if (estimateGas)
415
421
  return smartNumber(gas);
416
422
  yield this.llamalend.updateFeeData();
417
423
  const gasLimit = _mulBy1_3(DIGas(gas));
418
- return (yield contract.create_loan_extended(_userCollateral, _debt, range, this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userBorrowed], zapCalldata, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
424
+ return (yield contract.create_loan_extended(_userCollateral, _debt, range, this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userBorrowed, _minRecv], zapCalldata, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
419
425
  });
420
426
  }
421
427
  leverageCreateLoanEstimateGas(_a) {
422
- return __awaiter(this, arguments, void 0, function* ({ userCollateral, userBorrowed, debt, range, router, calldata }) {
428
+ return __awaiter(this, arguments, void 0, function* ({ userCollateral, userBorrowed, debt, range, minRecv, router, calldata }) {
423
429
  this._checkLeverageZap();
424
430
  if (!(yield this.leverageCreateLoanIsApproved({ userCollateral, userBorrowed })))
425
431
  throw Error("Approval is needed for gas estimation");
426
- return yield this._leverageCreateLoan(userCollateral, userBorrowed, debt, range, router, calldata, true);
432
+ return yield this._leverageCreateLoan(userCollateral, userBorrowed, debt, range, minRecv, router, calldata, true);
427
433
  });
428
434
  }
429
435
  leverageCreateLoan(_a) {
430
- return __awaiter(this, arguments, void 0, function* ({ userCollateral, userBorrowed, debt, range, router, calldata }) {
436
+ return __awaiter(this, arguments, void 0, function* ({ userCollateral, userBorrowed, debt, range, minRecv, router, calldata }) {
431
437
  this._checkLeverageZap();
432
438
  yield this.leverageCreateLoanApprove({ userCollateral, userBorrowed });
433
- return yield this._leverageCreateLoan(userCollateral, userBorrowed, debt, range, router, calldata, false);
439
+ return yield this._leverageCreateLoan(userCollateral, userBorrowed, debt, range, minRecv, router, calldata, false);
434
440
  });
435
441
  }
436
442
  // ---------------- LEVERAGE BORROW MORE ----------------
@@ -515,21 +521,22 @@ export class LeverageZapV2Module {
515
521
  };
516
522
  });
517
523
  }
518
- _leverageBorrowMore(userCollateral, userBorrowed, debt, router, calldata, estimateGas) {
524
+ _leverageBorrowMore(userCollateral, userBorrowed, debt, minRecv, router, calldata, estimateGas) {
519
525
  return __awaiter(this, void 0, void 0, function* () {
520
526
  if (!(yield this.market.userLoanExists()))
521
527
  throw Error("Loan does not exist");
522
528
  const _userCollateral = parseUnits(userCollateral, this.market.collateral_token.decimals);
523
529
  const _userBorrowed = parseUnits(userBorrowed, this.market.borrowed_token.decimals);
524
530
  const _debt = parseUnits(debt, this.market.borrowed_token.decimals);
531
+ const _minRecv = parseUnits(minRecv, this.market.collateral_token.decimals);
525
532
  const zapCalldata = buildCalldataForLeverageZapV2(router, calldata);
526
533
  const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
527
- const gas = yield contract.borrow_more_extended.estimateGas(_userCollateral, _debt, this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userBorrowed], zapCalldata, Object.assign({}, this.llamalend.constantOptions));
534
+ const gas = yield contract.borrow_more_extended.estimateGas(_userCollateral, _debt, this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userBorrowed, _minRecv], zapCalldata, Object.assign({}, this.llamalend.constantOptions));
528
535
  if (estimateGas)
529
536
  return smartNumber(gas);
530
537
  yield this.llamalend.updateFeeData();
531
538
  const gasLimit = _mulBy1_3(DIGas(gas));
532
- return (yield contract.borrow_more_extended(_userCollateral, _debt, this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userBorrowed], zapCalldata, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
539
+ return (yield contract.borrow_more_extended(_userCollateral, _debt, this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userBorrowed, _minRecv], zapCalldata, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
533
540
  });
534
541
  }
535
542
  leverageBorrowMoreIsApproved(_a) {
@@ -543,18 +550,18 @@ export class LeverageZapV2Module {
543
550
  });
544
551
  }
545
552
  leverageBorrowMoreEstimateGas(_a) {
546
- return __awaiter(this, arguments, void 0, function* ({ userCollateral, userBorrowed, debt, router, calldata }) {
553
+ return __awaiter(this, arguments, void 0, function* ({ userCollateral, userBorrowed, debt, minRecv, router, calldata }) {
547
554
  this._checkLeverageZap();
548
555
  if (!(yield this.leverageCreateLoanIsApproved({ userCollateral, userBorrowed })))
549
556
  throw Error("Approval is needed for gas estimation");
550
- return yield this._leverageBorrowMore(userCollateral, userBorrowed, debt, router, calldata, true);
557
+ return yield this._leverageBorrowMore(userCollateral, userBorrowed, debt, minRecv, router, calldata, true);
551
558
  });
552
559
  }
553
560
  leverageBorrowMore(_a) {
554
- return __awaiter(this, arguments, void 0, function* ({ userCollateral, userBorrowed, debt, router, calldata }) {
561
+ return __awaiter(this, arguments, void 0, function* ({ userCollateral, userBorrowed, debt, minRecv, router, calldata }) {
555
562
  this._checkLeverageZap();
556
563
  yield this.leverageCreateLoanApprove({ userCollateral, userBorrowed });
557
- return yield this._leverageBorrowMore(userCollateral, userBorrowed, debt, router, calldata, false);
564
+ return yield this._leverageBorrowMore(userCollateral, userBorrowed, debt, minRecv, router, calldata, false);
558
565
  });
559
566
  }
560
567
  leverageBorrowMoreFutureLeverage(_a) {
@@ -660,39 +667,40 @@ export class LeverageZapV2Module {
660
667
  return yield ensureAllowance.call(this.llamalend, [this.market.collateral_token.address, this.market.borrowed_token.address], [userCollateral, userBorrowed], this.llamalend.constants.ALIASES.leverage_zap_v2);
661
668
  });
662
669
  }
663
- _leverageRepay(stateCollateral, userCollateral, userBorrowed, router, calldata, estimateGas) {
670
+ _leverageRepay(stateCollateral, userCollateral, userBorrowed, minRecv, router, calldata, estimateGas) {
664
671
  return __awaiter(this, void 0, void 0, function* () {
665
672
  if (!(yield this.market.userLoanExists()))
666
673
  throw Error("Loan does not exist");
667
674
  const _stateCollateral = parseUnits(stateCollateral, this.market.collateral_token.decimals);
668
675
  const _userCollateral = parseUnits(userCollateral, this.market.collateral_token.decimals);
669
676
  const _userBorrowed = parseUnits(userBorrowed, this.market.borrowed_token.decimals);
677
+ const _minRecv = parseUnits(minRecv, this.market.borrowed_token.decimals);
670
678
  let zapCalldata = buildCalldataForLeverageZapV2(router, "0x");
671
679
  if (_stateCollateral + _userCollateral > BigInt(0)) {
672
680
  zapCalldata = buildCalldataForLeverageZapV2(router, calldata);
673
681
  }
674
682
  const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
675
- const gas = yield contract.repay_extended.estimateGas(this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userCollateral, _userBorrowed], zapCalldata);
683
+ const gas = yield contract.repay_extended.estimateGas(this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userCollateral, _userBorrowed, _minRecv], zapCalldata);
676
684
  if (estimateGas)
677
685
  return smartNumber(gas);
678
686
  yield this.llamalend.updateFeeData();
679
687
  const gasLimit = _mulBy1_3(DIGas(gas));
680
- return (yield contract.repay_extended(this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userCollateral, _userBorrowed], zapCalldata, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
688
+ return (yield contract.repay_extended(this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userCollateral, _userBorrowed, _minRecv], zapCalldata, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
681
689
  });
682
690
  }
683
691
  leverageRepayEstimateGas(_a) {
684
- return __awaiter(this, arguments, void 0, function* ({ stateCollateral, userCollateral, userBorrowed, router, calldata }) {
692
+ return __awaiter(this, arguments, void 0, function* ({ stateCollateral, userCollateral, userBorrowed, minRecv, router, calldata }) {
685
693
  this._checkLeverageZap();
686
694
  if (!(yield this.leverageRepayIsApproved({ userCollateral, userBorrowed })))
687
695
  throw Error("Approval is needed for gas estimation");
688
- return yield this._leverageRepay(stateCollateral, userCollateral, userBorrowed, router, calldata, true);
696
+ return yield this._leverageRepay(stateCollateral, userCollateral, userBorrowed, minRecv, router, calldata, true);
689
697
  });
690
698
  }
691
699
  leverageRepay(_a) {
692
- return __awaiter(this, arguments, void 0, function* ({ stateCollateral, userCollateral, userBorrowed, router, calldata }) {
700
+ return __awaiter(this, arguments, void 0, function* ({ stateCollateral, userCollateral, userBorrowed, minRecv, router, calldata }) {
693
701
  this._checkLeverageZap();
694
702
  yield this.leverageRepayApprove({ userCollateral, userBorrowed });
695
- return yield this._leverageRepay(stateCollateral, userCollateral, userBorrowed, router, calldata, false);
703
+ return yield this._leverageRepay(stateCollateral, userCollateral, userBorrowed, minRecv, router, calldata, false);
696
704
  });
697
705
  }
698
706
  leverageRepayFutureLeverage(_a) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/llamalend-api",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "description": "JavaScript library for Curve Lending",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",
@@ -49,7 +49,7 @@ export const ALIASES_ARBITRUM = lowerCaseValues({
49
49
  "gauge_factory": "0xabC000d88f23Bb45525E447528DBF656A9D55bf5",
50
50
  // "leverage_zap": "0x61C404B60ee9c5fB09F70F9A645DD38fE5b3A956", // 1inch
51
51
  "leverage_zap": "0xFE02553d3Ba4c3f39F36a4632F91404DF94b9AE2", // odos v3
52
- "leverage_zap_v2": "0x5b07Db9a85992c877b9fBeA6DCC4F79292577640",
52
+ "leverage_zap_v2": "0x9577086c6E38d38359872F903Da201f1bdCc0323",
53
53
  "leverage_markets_start_id": "9",
54
54
  });
55
55
 
@@ -410,6 +410,7 @@ export class LendMarketTemplate {
410
410
  createLoanIsApproved: leverageZapV2.leverageCreateLoanIsApproved.bind(leverageZapV2),
411
411
  createLoanApprove: leverageZapV2.leverageCreateLoanApprove.bind(leverageZapV2),
412
412
  createLoanExpectedMetrics: leverageZapV2.leverageCreateLoanExpectedMetrics.bind(leverageZapV2),
413
+ calcMinRecv: leverageZapV2.calcMinRecv.bind(leverageZapV2),
413
414
  createLoan: leverageZapV2.leverageCreateLoan.bind(leverageZapV2),
414
415
 
415
416
  borrowMoreMaxRecv: leverageZapV2.leverageBorrowMoreMaxRecv.bind(leverageZapV2),
@@ -1285,6 +1286,14 @@ export class LendMarketTemplate {
1285
1286
  maxAge: 60 * 1000, // 1m
1286
1287
  });
1287
1288
 
1289
+ public oracleAddress = memoize(async (): Promise<string> => {
1290
+ const _address = await this.llamalend.contracts[this.addresses.amm].contract.price_oracle_contract(this.llamalend.constantOptions) as string;
1291
+ return _address;
1292
+ },
1293
+ {
1294
+ promise: true,
1295
+ });
1296
+
1288
1297
  public async oraclePriceBand(): Promise<number> {
1289
1298
  const oraclePriceBN = BN(await this.oraclePrice());
1290
1299
  const basePriceBN = BN(await this.basePrice());
@@ -125,11 +125,13 @@ export interface ILeverageZapV2 {
125
125
  userCollateral: TAmount,
126
126
  userBorrowed: TAmount
127
127
  }) => Promise<string[]>,
128
+ calcMinRecv: (expected: TAmount, slippage: number) => string,
128
129
  createLoan: ({
129
130
  userCollateral,
130
131
  userBorrowed,
131
132
  debt,
132
133
  range,
134
+ minRecv,
133
135
  router,
134
136
  calldata,
135
137
  }: {
@@ -137,6 +139,7 @@ export interface ILeverageZapV2 {
137
139
  userBorrowed: TAmount,
138
140
  debt: TAmount,
139
141
  range: number,
142
+ minRecv: TAmount,
140
143
  router: string,
141
144
  calldata: string
142
145
  }) => Promise<string>,
@@ -183,10 +186,11 @@ export interface ILeverageZapV2 {
183
186
  userCollateral: TAmount,
184
187
  userBorrowed: TAmount
185
188
  }) => Promise<string[]>,
186
- borrowMore: ({ userCollateral, userBorrowed, debt, router, calldata }: {
189
+ borrowMore: ({ userCollateral, userBorrowed, debt, minRecv, router, calldata }: {
187
190
  userCollateral: TAmount,
188
191
  userBorrowed: TAmount,
189
192
  debt: TAmount,
193
+ minRecv: TAmount,
190
194
  router: string,
191
195
  calldata: string
192
196
  }) => Promise<string>,
@@ -240,10 +244,11 @@ export interface ILeverageZapV2 {
240
244
  userCollateral: TAmount,
241
245
  userBorrowed: TAmount
242
246
  }) => Promise<string[]>,
243
- repay: ({ stateCollateral, userCollateral, userBorrowed, router, calldata }: {
247
+ repay: ({ stateCollateral, userCollateral, userBorrowed, minRecv, router, calldata }: {
244
248
  stateCollateral: TAmount,
245
249
  userCollateral: TAmount,
246
250
  userBorrowed: TAmount,
251
+ minRecv: TAmount,
247
252
  router: string,
248
253
  calldata: string
249
254
  }) => Promise<string>,
@@ -260,11 +265,12 @@ export interface ILeverageZapV2 {
260
265
  userCollateral: TAmount,
261
266
  userBorrowed: TAmount
262
267
  }) => Promise<TGas>,
263
- createLoan: ({ userCollateral, userBorrowed, debt, range, router, calldata }: {
268
+ createLoan: ({ userCollateral, userBorrowed, debt, range, minRecv, router, calldata }: {
264
269
  userCollateral: TAmount,
265
270
  userBorrowed: TAmount,
266
271
  debt: TAmount,
267
272
  range: number,
273
+ minRecv: TAmount,
268
274
  router: string,
269
275
  calldata: string
270
276
  }) => Promise<number>,
@@ -273,10 +279,11 @@ export interface ILeverageZapV2 {
273
279
  userCollateral: TAmount,
274
280
  userBorrowed: TAmount
275
281
  }) => Promise<TGas>,
276
- borrowMore: ({ userCollateral, userBorrowed, debt, router, calldata }: {
282
+ borrowMore: ({ userCollateral, userBorrowed, debt, minRecv, router, calldata }: {
277
283
  userCollateral: TAmount,
278
284
  userBorrowed: TAmount,
279
285
  debt: TAmount,
286
+ minRecv: TAmount,
280
287
  router: string,
281
288
  calldata: string
282
289
  }) => Promise<number>,
@@ -285,10 +292,11 @@ export interface ILeverageZapV2 {
285
292
  userCollateral: TAmount,
286
293
  userBorrowed: TAmount
287
294
  }) => Promise<TGas>,
288
- repay: ({ stateCollateral, userCollateral, userBorrowed, router, calldata }: {
295
+ repay: ({ stateCollateral, userCollateral, userBorrowed, minRecv, router, calldata }: {
289
296
  stateCollateral: TAmount,
290
297
  userCollateral: TAmount,
291
298
  userBorrowed: TAmount,
299
+ minRecv: TAmount,
292
300
  router: string,
293
301
  calldata: string
294
302
  }) => Promise<number>,
@@ -70,6 +70,11 @@ export class LeverageZapV2Module {
70
70
  return BN(1).div(BN(1).minus(k_effective_BN)).toString()
71
71
  }
72
72
 
73
+ public calcMinRecv(expected: TAmount, slippage: number): string {
74
+ if (slippage < 0 || slippage > 100) throw Error("Slippage must be between 0 and 100");
75
+ return BN(expected).times(BN(100).minus(slippage)).div(100).toString();
76
+ }
77
+
73
78
  public async leverageCreateLoanMaxRecv({ userCollateral, userBorrowed, range, getExpected }: {
74
79
  userCollateral: TAmount,
75
80
  userBorrowed: TAmount,
@@ -484,6 +489,7 @@ export class LeverageZapV2Module {
484
489
  userBorrowed: TAmount,
485
490
  debt: TAmount,
486
491
  range: number,
492
+ minRecv: TAmount,
487
493
  router: string,
488
494
  calldata: string,
489
495
  estimateGas: boolean
@@ -494,6 +500,7 @@ export class LeverageZapV2Module {
494
500
  const _userCollateral = parseUnits(userCollateral, this.market.collateral_token.decimals);
495
501
  const _userBorrowed = parseUnits(userBorrowed, this.market.borrowed_token.decimals);
496
502
  const _debt = parseUnits(debt, this.market.borrowed_token.decimals);
503
+ const _minRecv = parseUnits(minRecv, this.market.collateral_token.decimals);
497
504
 
498
505
 
499
506
  const zapCalldata = buildCalldataForLeverageZapV2(router, calldata)
@@ -503,7 +510,7 @@ export class LeverageZapV2Module {
503
510
  _debt,
504
511
  range,
505
512
  this.llamalend.constants.ALIASES.leverage_zap_v2,
506
- [0, parseUnits(this._getMarketId(), 0), _userBorrowed],
513
+ [0, parseUnits(this._getMarketId(), 0), _userBorrowed, _minRecv],
507
514
  zapCalldata,
508
515
  { ...this.llamalend.constantOptions }
509
516
  );
@@ -516,36 +523,38 @@ export class LeverageZapV2Module {
516
523
  _debt,
517
524
  range,
518
525
  this.llamalend.constants.ALIASES.leverage_zap_v2,
519
- [0, parseUnits(this._getMarketId(), 0), _userBorrowed],
526
+ [0, parseUnits(this._getMarketId(), 0), _userBorrowed, _minRecv],
520
527
  zapCalldata,
521
528
  { ...this.llamalend.options, gasLimit }
522
529
  )).hash
523
530
  }
524
531
 
525
- public async leverageCreateLoanEstimateGas({ userCollateral, userBorrowed, debt, range, router, calldata }: {
532
+ public async leverageCreateLoanEstimateGas({ userCollateral, userBorrowed, debt, range, minRecv, router, calldata }: {
526
533
  userCollateral: TAmount,
527
534
  userBorrowed: TAmount,
528
535
  debt: TAmount,
529
536
  range: number,
537
+ minRecv: TAmount,
530
538
  router: string,
531
539
  calldata: string
532
540
  }): Promise<number> {
533
541
  this._checkLeverageZap();
534
542
  if (!(await this.leverageCreateLoanIsApproved({ userCollateral, userBorrowed }))) throw Error("Approval is needed for gas estimation");
535
- return await this._leverageCreateLoan(userCollateral, userBorrowed, debt, range, router, calldata, true) as number;
543
+ return await this._leverageCreateLoan(userCollateral, userBorrowed, debt, range, minRecv, router, calldata, true) as number;
536
544
  }
537
545
 
538
- public async leverageCreateLoan({ userCollateral, userBorrowed, debt, range, router, calldata }: {
546
+ public async leverageCreateLoan({ userCollateral, userBorrowed, debt, range, minRecv, router, calldata }: {
539
547
  userCollateral: TAmount,
540
548
  userBorrowed: TAmount,
541
549
  debt: TAmount,
542
550
  range: number,
551
+ minRecv: TAmount,
543
552
  router: string,
544
553
  calldata: string
545
554
  }): Promise<string> {
546
555
  this._checkLeverageZap();
547
556
  await this.leverageCreateLoanApprove({ userCollateral, userBorrowed });
548
- return await this._leverageCreateLoan(userCollateral, userBorrowed, debt, range, router, calldata, false) as string;
557
+ return await this._leverageCreateLoan(userCollateral, userBorrowed, debt, range, minRecv, router, calldata, false) as string;
549
558
  }
550
559
 
551
560
  // ---------------- LEVERAGE BORROW MORE ----------------
@@ -667,6 +676,7 @@ export class LeverageZapV2Module {
667
676
  userCollateral: TAmount,
668
677
  userBorrowed: TAmount,
669
678
  debt: TAmount,
679
+ minRecv: TAmount,
670
680
  router: string,
671
681
  calldata: string,
672
682
  estimateGas: boolean
@@ -675,6 +685,7 @@ export class LeverageZapV2Module {
675
685
  const _userCollateral = parseUnits(userCollateral, this.market.collateral_token.decimals);
676
686
  const _userBorrowed = parseUnits(userBorrowed, this.market.borrowed_token.decimals);
677
687
  const _debt = parseUnits(debt, this.market.borrowed_token.decimals);
688
+ const _minRecv = parseUnits(minRecv, this.market.collateral_token.decimals);
678
689
 
679
690
  const zapCalldata = buildCalldataForLeverageZapV2(router, calldata);
680
691
 
@@ -683,7 +694,7 @@ export class LeverageZapV2Module {
683
694
  _userCollateral,
684
695
  _debt,
685
696
  this.llamalend.constants.ALIASES.leverage_zap_v2,
686
- [0, parseUnits(this._getMarketId(), 0), _userBorrowed],
697
+ [0, parseUnits(this._getMarketId(), 0), _userBorrowed, _minRecv],
687
698
  zapCalldata,
688
699
  { ...this.llamalend.constantOptions }
689
700
  );
@@ -696,7 +707,7 @@ export class LeverageZapV2Module {
696
707
  _userCollateral,
697
708
  _debt,
698
709
  this.llamalend.constants.ALIASES.leverage_zap_v2,
699
- [0, parseUnits(this._getMarketId(), 0), _userBorrowed],
710
+ [0, parseUnits(this._getMarketId(), 0), _userBorrowed, _minRecv],
700
711
  zapCalldata,
701
712
  { ...this.llamalend.options, gasLimit }
702
713
  )).hash
@@ -716,28 +727,30 @@ export class LeverageZapV2Module {
716
727
  return await this.leverageCreateLoanApprove({ userCollateral, userBorrowed });
717
728
  }
718
729
 
719
- public async leverageBorrowMoreEstimateGas({ userCollateral, userBorrowed, debt, router, calldata }: {
730
+ public async leverageBorrowMoreEstimateGas({ userCollateral, userBorrowed, debt, minRecv, router, calldata }: {
720
731
  userCollateral: TAmount,
721
732
  userBorrowed: TAmount,
722
733
  debt: TAmount,
734
+ minRecv: TAmount,
723
735
  router: string,
724
736
  calldata: string
725
737
  }): Promise<number> {
726
738
  this._checkLeverageZap();
727
739
  if (!(await this.leverageCreateLoanIsApproved({ userCollateral, userBorrowed }))) throw Error("Approval is needed for gas estimation");
728
- return await this._leverageBorrowMore(userCollateral, userBorrowed, debt, router, calldata, true) as number;
740
+ return await this._leverageBorrowMore(userCollateral, userBorrowed, debt, minRecv, router, calldata, true) as number;
729
741
  }
730
742
 
731
- public async leverageBorrowMore({ userCollateral, userBorrowed, debt, router, calldata }: {
743
+ public async leverageBorrowMore({ userCollateral, userBorrowed, debt, minRecv, router, calldata }: {
732
744
  userCollateral: TAmount,
733
745
  userBorrowed: TAmount,
734
746
  debt: TAmount,
747
+ minRecv: TAmount,
735
748
  router: string,
736
749
  calldata: string
737
750
  }): Promise<string> {
738
751
  this._checkLeverageZap();
739
752
  await this.leverageCreateLoanApprove({ userCollateral, userBorrowed });
740
- return await this._leverageBorrowMore(userCollateral, userBorrowed, debt, router, calldata, false) as string;
753
+ return await this._leverageBorrowMore(userCollateral, userBorrowed, debt, minRecv, router, calldata, false) as string;
741
754
  }
742
755
 
743
756
  public async leverageBorrowMoreFutureLeverage({ userCollateral, userBorrowed, debt, quote, address = "" }: {
@@ -959,6 +972,7 @@ export class LeverageZapV2Module {
959
972
  stateCollateral: TAmount,
960
973
  userCollateral: TAmount,
961
974
  userBorrowed: TAmount,
975
+ minRecv: TAmount,
962
976
  router: string,
963
977
  calldata: string,
964
978
  estimateGas: boolean
@@ -967,6 +981,8 @@ export class LeverageZapV2Module {
967
981
  const _stateCollateral = parseUnits(stateCollateral, this.market.collateral_token.decimals);
968
982
  const _userCollateral = parseUnits(userCollateral, this.market.collateral_token.decimals);
969
983
  const _userBorrowed = parseUnits(userBorrowed, this.market.borrowed_token.decimals);
984
+ const _minRecv = parseUnits(minRecv, this.market.borrowed_token.decimals);
985
+
970
986
  let zapCalldata = buildCalldataForLeverageZapV2(router, "0x");
971
987
  if (_stateCollateral + _userCollateral > BigInt(0)) {
972
988
  zapCalldata = buildCalldataForLeverageZapV2(router, calldata)
@@ -975,7 +991,7 @@ export class LeverageZapV2Module {
975
991
  const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
976
992
  const gas = await contract.repay_extended.estimateGas(
977
993
  this.llamalend.constants.ALIASES.leverage_zap_v2,
978
- [0, parseUnits(this._getMarketId(), 0), _userCollateral, _userBorrowed],
994
+ [0, parseUnits(this._getMarketId(), 0), _userCollateral, _userBorrowed, _minRecv],
979
995
  zapCalldata
980
996
  );
981
997
  if (estimateGas) return smartNumber(gas);
@@ -985,34 +1001,36 @@ export class LeverageZapV2Module {
985
1001
 
986
1002
  return (await contract.repay_extended(
987
1003
  this.llamalend.constants.ALIASES.leverage_zap_v2,
988
- [0, parseUnits(this._getMarketId(), 0), _userCollateral, _userBorrowed],
1004
+ [0, parseUnits(this._getMarketId(), 0), _userCollateral, _userBorrowed, _minRecv],
989
1005
  zapCalldata,
990
1006
  { ...this.llamalend.options, gasLimit }
991
1007
  )).hash
992
1008
  }
993
1009
 
994
- public async leverageRepayEstimateGas({ stateCollateral, userCollateral, userBorrowed, router, calldata }: {
1010
+ public async leverageRepayEstimateGas({ stateCollateral, userCollateral, userBorrowed, minRecv, router, calldata }: {
995
1011
  stateCollateral: TAmount,
996
1012
  userCollateral: TAmount,
997
1013
  userBorrowed: TAmount,
1014
+ minRecv: TAmount,
998
1015
  router: string,
999
1016
  calldata: string
1000
1017
  }): Promise<number> {
1001
1018
  this._checkLeverageZap();
1002
1019
  if (!(await this.leverageRepayIsApproved({ userCollateral, userBorrowed }))) throw Error("Approval is needed for gas estimation");
1003
- return await this._leverageRepay(stateCollateral, userCollateral, userBorrowed, router, calldata, true) as number;
1020
+ return await this._leverageRepay(stateCollateral, userCollateral, userBorrowed, minRecv, router, calldata, true) as number;
1004
1021
  }
1005
1022
 
1006
- public async leverageRepay({ stateCollateral, userCollateral, userBorrowed, router, calldata }: {
1023
+ public async leverageRepay({ stateCollateral, userCollateral, userBorrowed, minRecv, router, calldata }: {
1007
1024
  stateCollateral: TAmount,
1008
1025
  userCollateral: TAmount,
1009
1026
  userBorrowed: TAmount,
1027
+ minRecv: TAmount,
1010
1028
  router: string,
1011
1029
  calldata: string
1012
1030
  }): Promise<string> {
1013
1031
  this._checkLeverageZap();
1014
1032
  await this.leverageRepayApprove({ userCollateral, userBorrowed });
1015
- return await this._leverageRepay(stateCollateral, userCollateral, userBorrowed, router, calldata, false) as string;
1033
+ return await this._leverageRepay(stateCollateral, userCollateral, userBorrowed, minRecv, router, calldata, false) as string;
1016
1034
  }
1017
1035
 
1018
1036
  public async leverageRepayFutureLeverage({ stateCollateral, userCollateral, userBorrowed, address = "" }: {