@curvefi/llamalend-api 1.0.11 → 1.0.12

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.
@@ -29,6 +29,8 @@ export interface ILlamma {
29
29
  default_bands: number;
30
30
  A: number;
31
31
  monetary_policy_abi: any;
32
+ is_deleverage_supported?: boolean;
33
+ index?: number;
32
34
  }
33
35
  export interface ICoin {
34
36
  address: string;
package/lib/llamalend.js CHANGED
@@ -602,6 +602,8 @@ class Llamalend {
602
602
  default_bands: 10,
603
603
  A: AParams[i],
604
604
  monetary_policy_abi: MonetaryPolicy2ABI,
605
+ is_deleverage_supported: true,
606
+ index: N1 + i,
605
607
  };
606
608
  }
607
609
  }
@@ -19,6 +19,8 @@ export declare class MintMarketTemplate {
19
19
  defaultBands: number;
20
20
  A: number;
21
21
  tickSpace: number;
22
+ isDeleverageSupported: boolean;
23
+ index?: number;
22
24
  estimateGas: {
23
25
  createLoanApprove: (collateral: number | string) => Promise<TGas>;
24
26
  createLoan: (collateral: number | string, debt: number | string, range: number) => Promise<TGas>;
@@ -14,6 +14,7 @@ import { _getAddress, parseUnits, BN, toBN, fromBN, getBalances, ensureAllowance
14
14
  import { _getUserCollateralCrvUsd } from "../external-api.js";
15
15
  export class MintMarketTemplate {
16
16
  constructor(id) {
17
+ var _a;
17
18
  // ---------------- STATS ----------------
18
19
  this.statsParameters = memoize(() => __awaiter(this, void 0, void 0, function* () {
19
20
  const llammaContract = llamalend.contracts[this.address].multicallContract;
@@ -254,6 +255,8 @@ export class MintMarketTemplate {
254
255
  this.defaultBands = llammaData.default_bands;
255
256
  this.A = llammaData.A;
256
257
  this.tickSpace = 1 / llammaData.A * 100;
258
+ this.isDeleverageSupported = (_a = llammaData.is_deleverage_supported) !== null && _a !== void 0 ? _a : false;
259
+ this.index = llammaData.index;
257
260
  this.estimateGas = {
258
261
  createLoanApprove: this.createLoanApproveEstimateGas.bind(this),
259
262
  createLoan: this.createLoanEstimateGas.bind(this),
@@ -961,12 +964,12 @@ export class MintMarketTemplate {
961
964
  throw Error(`User ${llamalend.signerAddress} is already in liquidation mode`);
962
965
  const _collateral = parseUnits(collateral, this.collateralDecimals);
963
966
  const contract = llamalend.contracts[this.controller].contract;
964
- const gas = yield contract.remove_collateral.estimateGas(_collateral, isEth(this.collateral), llamalend.constantOptions);
967
+ const gas = this.isDeleverageSupported ? yield contract.remove_collateral.estimateGas(_collateral, llamalend.constantOptions) : yield contract.remove_collateral.estimateGas(_collateral, isEth(this.collateral), llamalend.constantOptions);
965
968
  if (estimateGas)
966
969
  return smartNumber(gas);
967
970
  yield llamalend.updateFeeData();
968
971
  const gasLimit = _mulBy1_3(DIGas(gas));
969
- return (yield contract.remove_collateral(_collateral, isEth(this.collateral), Object.assign(Object.assign({}, llamalend.options), { gasLimit }))).hash;
972
+ return (this.isDeleverageSupported ? yield contract.remove_collateral(_collateral, Object.assign(Object.assign({}, llamalend.options), { gasLimit })) : yield contract.remove_collateral(_collateral, isEth(this.collateral), Object.assign(Object.assign({}, llamalend.options), { gasLimit }))).hash;
970
973
  });
971
974
  }
972
975
  removeCollateralEstimateGas(collateral) {
@@ -1041,12 +1044,12 @@ export class MintMarketTemplate {
1041
1044
  const [, n1] = yield this.userBands(address);
1042
1045
  const { stablecoin } = yield this.userState(address);
1043
1046
  const n = (BN(stablecoin).gt(0)) ? MAX_ACTIVE_BAND : n1 - 1; // In liquidation mode it doesn't matter if active band moves
1044
- const gas = yield contract.repay.estimateGas(_debt, address, n, isEth(this.collateral), llamalend.constantOptions);
1047
+ const gas = this.isDeleverageSupported ? yield contract.repay.estimateGas(_debt, address, n, llamalend.constantOptions) : yield contract.repay.estimateGas(_debt, address, n, isEth(this.collateral), llamalend.constantOptions);
1045
1048
  if (estimateGas)
1046
1049
  return smartNumber(gas);
1047
1050
  yield llamalend.updateFeeData();
1048
1051
  const gasLimit = _mulBy1_3(DIGas(gas));
1049
- return (yield contract.repay(_debt, address, n, isEth(this.collateral), Object.assign(Object.assign({}, llamalend.options), { gasLimit }))).hash;
1052
+ return (this.isDeleverageSupported ? yield contract.repay(_debt, address, n, Object.assign(Object.assign({}, llamalend.options), { gasLimit })) : yield contract.repay(_debt, address, n, isEth(this.collateral), Object.assign(Object.assign({}, llamalend.options), { gasLimit }))).hash;
1050
1053
  });
1051
1054
  }
1052
1055
  repayEstimateGas(debt_1) {
@@ -1269,12 +1272,12 @@ export class MintMarketTemplate {
1269
1272
  const minAmountBN = BN(stablecoin).times(100 - slippage).div(100);
1270
1273
  const _minAmount = fromBN(minAmountBN);
1271
1274
  const contract = llamalend.contracts[this.controller].contract;
1272
- const gas = (yield contract.liquidate.estimateGas(address, _minAmount, isEth(this.collateral), llamalend.constantOptions));
1275
+ const gas = this.isDeleverageSupported ? (yield contract.liquidate.estimateGas(address, _minAmount, llamalend.constantOptions)) : (yield contract.liquidate.estimateGas(address, _minAmount, isEth(this.collateral), llamalend.constantOptions));
1273
1276
  if (estimateGas)
1274
1277
  return smartNumber(gas);
1275
1278
  yield llamalend.updateFeeData();
1276
1279
  const gasLimit = _mulBy1_3(DIGas(gas));
1277
- return (yield contract.liquidate(address, _minAmount, isEth(this.collateral), Object.assign(Object.assign({}, llamalend.options), { gasLimit }))).hash;
1280
+ return (this.isDeleverageSupported ? yield contract.liquidate(address, _minAmount, Object.assign(Object.assign({}, llamalend.options), { gasLimit })) : yield contract.liquidate(address, _minAmount, isEth(this.collateral), Object.assign(Object.assign({}, llamalend.options), { gasLimit }))).hash;
1278
1281
  });
1279
1282
  }
1280
1283
  liquidateEstimateGas(address_1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/llamalend-api",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "JavaScript library for Curve Lending",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",
package/src/interfaces.ts CHANGED
@@ -33,6 +33,8 @@ export interface ILlamma {
33
33
  default_bands: number,
34
34
  A: number,
35
35
  monetary_policy_abi: any
36
+ is_deleverage_supported?: boolean
37
+ index?: number
36
38
  }
37
39
 
38
40
  export interface ICoin {
package/src/llamalend.ts CHANGED
@@ -474,6 +474,8 @@ class Llamalend implements ILlamalend {
474
474
  default_bands: 10,
475
475
  A: AParams[i],
476
476
  monetary_policy_abi: MonetaryPolicy2ABI,
477
+ is_deleverage_supported: true,
478
+ index: N1 + i,
477
479
  }
478
480
  }
479
481
  }
@@ -16,7 +16,9 @@ import {
16
16
  formatUnits,
17
17
  smartNumber,
18
18
  MAX_ALLOWANCE,
19
- MAX_ACTIVE_BAND, _mulBy1_3, DIGas,
19
+ MAX_ACTIVE_BAND,
20
+ _mulBy1_3,
21
+ DIGas,
20
22
  } from "../utils";
21
23
  import {IDict, TGas} from "../interfaces";
22
24
  import {_getUserCollateralCrvUsd} from "../external-api.js";
@@ -41,6 +43,8 @@ export class MintMarketTemplate {
41
43
  defaultBands: number;
42
44
  A: number;
43
45
  tickSpace: number; // %
46
+ isDeleverageSupported: boolean;
47
+ index?: number;
44
48
  estimateGas: {
45
49
  createLoanApprove: (collateral: number | string) => Promise<TGas>,
46
50
  createLoan: (collateral: number | string, debt: number | string, range: number) => Promise<TGas>,
@@ -138,6 +142,8 @@ export class MintMarketTemplate {
138
142
  this.defaultBands = llammaData.default_bands;
139
143
  this.A = llammaData.A;
140
144
  this.tickSpace = 1 / llammaData.A * 100;
145
+ this.isDeleverageSupported = llammaData.is_deleverage_supported ?? false;
146
+ this.index = llammaData.index;
141
147
  this.estimateGas = {
142
148
  createLoanApprove: this.createLoanApproveEstimateGas.bind(this),
143
149
  createLoan: this.createLoanEstimateGas.bind(this),
@@ -985,12 +991,12 @@ export class MintMarketTemplate {
985
991
 
986
992
  const _collateral = parseUnits(collateral, this.collateralDecimals);
987
993
  const contract = llamalend.contracts[this.controller].contract;
988
- const gas = await contract.remove_collateral.estimateGas(_collateral, isEth(this.collateral), llamalend.constantOptions);
994
+ const gas = this.isDeleverageSupported ? await contract.remove_collateral.estimateGas(_collateral, llamalend.constantOptions) : await contract.remove_collateral.estimateGas(_collateral, isEth(this.collateral), llamalend.constantOptions);
989
995
  if (estimateGas) return smartNumber(gas);
990
996
 
991
997
  await llamalend.updateFeeData();
992
998
  const gasLimit = _mulBy1_3(DIGas(gas));
993
- return (await contract.remove_collateral(_collateral, isEth(this.collateral), { ...llamalend.options, gasLimit })).hash
999
+ return (this.isDeleverageSupported ? await contract.remove_collateral(_collateral, { ...llamalend.options, gasLimit }) : await contract.remove_collateral(_collateral, isEth(this.collateral), { ...llamalend.options, gasLimit })).hash
994
1000
  }
995
1001
 
996
1002
  public async removeCollateralEstimateGas(collateral: number | string): Promise<number> {
@@ -1060,12 +1066,12 @@ export class MintMarketTemplate {
1060
1066
  const [, n1] = await this.userBands(address);
1061
1067
  const { stablecoin } = await this.userState(address);
1062
1068
  const n = (BN(stablecoin).gt(0)) ? MAX_ACTIVE_BAND : n1 - 1; // In liquidation mode it doesn't matter if active band moves
1063
- const gas = await contract.repay.estimateGas(_debt, address, n, isEth(this.collateral), llamalend.constantOptions);
1069
+ const gas = this.isDeleverageSupported ? await contract.repay.estimateGas(_debt, address, n, llamalend.constantOptions) : await contract.repay.estimateGas(_debt, address, n, isEth(this.collateral), llamalend.constantOptions);
1064
1070
  if (estimateGas) return smartNumber(gas);
1065
1071
 
1066
1072
  await llamalend.updateFeeData();
1067
1073
  const gasLimit = _mulBy1_3(DIGas(gas));
1068
- return (await contract.repay(_debt, address, n, isEth(this.collateral), { ...llamalend.options, gasLimit })).hash
1074
+ return (this.isDeleverageSupported ? await contract.repay(_debt, address, n, { ...llamalend.options, gasLimit }) : await contract.repay(_debt, address, n, isEth(this.collateral), { ...llamalend.options, gasLimit })).hash
1069
1075
  }
1070
1076
 
1071
1077
  public async repayEstimateGas(debt: number | string, address = ""): Promise<number> {
@@ -1264,12 +1270,12 @@ export class MintMarketTemplate {
1264
1270
  const minAmountBN: BigNumber = BN(stablecoin).times(100 - slippage).div(100);
1265
1271
  const _minAmount = fromBN(minAmountBN);
1266
1272
  const contract = llamalend.contracts[this.controller].contract;
1267
- const gas = (await contract.liquidate.estimateGas(address, _minAmount, isEth(this.collateral), llamalend.constantOptions))
1273
+ const gas = this.isDeleverageSupported ? (await contract.liquidate.estimateGas(address, _minAmount, llamalend.constantOptions)) : (await contract.liquidate.estimateGas(address, _minAmount, isEth(this.collateral), llamalend.constantOptions))
1268
1274
  if (estimateGas) return smartNumber(gas);
1269
1275
 
1270
1276
  await llamalend.updateFeeData();
1271
1277
  const gasLimit = _mulBy1_3(DIGas(gas));
1272
- return (await contract.liquidate(address, _minAmount, isEth(this.collateral), { ...llamalend.options, gasLimit })).hash
1278
+ return (this.isDeleverageSupported ? await contract.liquidate(address, _minAmount, { ...llamalend.options, gasLimit }) : await contract.liquidate(address, _minAmount, isEth(this.collateral), { ...llamalend.options, gasLimit })).hash
1273
1279
  }
1274
1280
 
1275
1281
  public async liquidateEstimateGas(address: string, slippage = 0.1): Promise<number> {