@curvefi/llamalend-api 2.2.5 → 2.2.6

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.
@@ -1191,23 +1191,6 @@
1191
1191
  "stateMutability": "view",
1192
1192
  "type": "function"
1193
1193
  },
1194
- {
1195
- "inputs": [
1196
- {
1197
- "name": "_user",
1198
- "type": "address"
1199
- }
1200
- ],
1201
- "name": "tokens_to_shrink",
1202
- "outputs": [
1203
- {
1204
- "name": "",
1205
- "type": "uint256"
1206
- }
1207
- ],
1208
- "stateMutability": "view",
1209
- "type": "function"
1210
- },
1211
1194
  {
1212
1195
  "inputs": [
1213
1196
  {
@@ -142,6 +142,7 @@ export class LendMarketTemplate {
142
142
  removeCollateralBands: loan.removeCollateralBands.bind(loan),
143
143
  removeCollateralPrices: loan.removeCollateralPrices.bind(loan),
144
144
  removeCollateralHealth: loan.removeCollateralHealth.bind(loan),
145
+ tokensToShrink: loan.tokensToShrink.bind(loan),
145
146
  removeCollateral: loan.removeCollateral.bind(loan),
146
147
  removeCollateralFutureLeverage: loan.removeCollateralFutureLeverage.bind(loan),
147
148
  repayBands: loan.repayBands.bind(loan),
@@ -32,6 +32,7 @@ export interface ILoanV1 {
32
32
  addCollateralApprove: (collateral: TAmount) => Promise<string[]>;
33
33
  addCollateral: (collateral: TAmount, address?: string) => Promise<string>;
34
34
  addCollateralFutureLeverage: (collateral: TAmount, userAddress?: string) => Promise<string>;
35
+ tokensToShrink: (dCollateral?: TAmount, address?: string) => Promise<string>;
35
36
  maxRemovable: () => Promise<string>;
36
37
  removeCollateralBands: (collateral: TAmount) => Promise<[number, number]>;
37
38
  removeCollateralPrices: (collateral: TAmount) => Promise<string[]>;
@@ -32,6 +32,7 @@ export interface ILoanV2 {
32
32
  addCollateralApprove: (collateral: TAmount) => Promise<string[]>;
33
33
  addCollateral: (collateral: TAmount, address?: string) => Promise<string>;
34
34
  addCollateralFutureLeverage: (collateral: TAmount, userAddress?: string) => Promise<string>;
35
+ tokensToShrink: (dCollateral?: TAmount, address?: string) => Promise<string>;
35
36
  maxRemovable: () => Promise<string>;
36
37
  removeCollateralBands: (collateral: TAmount) => Promise<[number, number]>;
37
38
  removeCollateralPrices: (collateral: TAmount) => Promise<string[]>;
@@ -39,6 +39,7 @@ export declare abstract class LoanBaseModule {
39
39
  abstract borrowMoreHealth(collateral: number | string, debt: number | string, full?: boolean, address?: string): Promise<string>;
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
+ abstract tokensToShrink(dCollateral?: number | string, address?: string): Promise<string>;
42
43
  _checkRange(range: number): void;
43
44
  createLoanMaxRecv(collateral: TAmount, range: number): Promise<string>;
44
45
  createLoanMaxRecvAllRanges: ((collateral: number | string) => Promise<{
@@ -10,6 +10,7 @@ export declare class LoanV1Module extends LoanBaseModule implements ILoanV1 {
10
10
  borrowMoreHealth(collateral: number | string, debt: number | string, full?: boolean, address?: string): Promise<string>;
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
+ tokensToShrink(): Promise<string>;
13
14
  protected _repayBands({ debt, address }: {
14
15
  debt: number | string;
15
16
  address: string;
@@ -75,6 +75,11 @@ export class LoanV1Module extends LoanBaseModule {
75
75
  return formatUnits(_health * BigInt(100));
76
76
  });
77
77
  }
78
+ tokensToShrink() {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ throw Error("tokensToShrink is not supported for v1 markets");
81
+ });
82
+ }
78
83
  _repayBands(_a) {
79
84
  return __awaiter(this, arguments, void 0, function* ({ debt, address }) {
80
85
  const { _collateral: _currentCollateral, _borrowed, _debt: _currentDebt, _N } = yield this.market.userPosition.userStateBigInt(address);
@@ -5,6 +5,7 @@ export declare class LoanV2Module extends LoanBaseModule implements ILoanV2 {
5
5
  createLoanHealth(collateral: number | string, debt: number | string, range: number, full?: boolean): Promise<string>;
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
+ tokensToShrink(dCollateral?: number | string, address?: string): Promise<string>;
8
9
  maxRemovable(): Promise<string>;
9
10
  borrowMoreHealth(collateral: number | string, debt: number | string, full?: boolean, address?: string): Promise<string>;
10
11
  repayHealth({ debt, shrink, full, address }: {
@@ -48,6 +48,15 @@ export class LoanV2Module extends LoanBaseModule {
48
48
  return formatUnits(_health * BigInt(100));
49
49
  });
50
50
  }
51
+ tokensToShrink() {
52
+ return __awaiter(this, arguments, void 0, function* (dCollateral = 0, address = "") {
53
+ address = _getAddress.call(this.llamalend, address);
54
+ const _dCollateral = parseUnits(dCollateral, this.market.collateral_token.decimals);
55
+ const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
56
+ const _tokens = yield contract.tokens_to_shrink(address, _dCollateral, this.llamalend.constantOptions);
57
+ return formatUnits(_tokens, this.market.borrowed_token.decimals);
58
+ });
59
+ }
51
60
  maxRemovable() {
52
61
  return __awaiter(this, void 0, void 0, function* () {
53
62
  const address = _getAddress.call(this.llamalend, '');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/llamalend-api",
3
- "version": "2.2.5",
3
+ "version": "2.2.6",
4
4
  "description": "JavaScript library for Curve Lending",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",
@@ -1191,23 +1191,6 @@
1191
1191
  "stateMutability": "view",
1192
1192
  "type": "function"
1193
1193
  },
1194
- {
1195
- "inputs": [
1196
- {
1197
- "name": "_user",
1198
- "type": "address"
1199
- }
1200
- ],
1201
- "name": "tokens_to_shrink",
1202
- "outputs": [
1203
- {
1204
- "name": "",
1205
- "type": "uint256"
1206
- }
1207
- ],
1208
- "stateMutability": "view",
1209
- "type": "function"
1210
- },
1211
1194
  {
1212
1195
  "inputs": [
1213
1196
  {
@@ -249,6 +249,7 @@ export class LendMarketTemplate<V extends 'v1' | 'v2' = 'v1' | 'v2'> {
249
249
  removeCollateralBands: loan.removeCollateralBands.bind(loan),
250
250
  removeCollateralPrices: loan.removeCollateralPrices.bind(loan),
251
251
  removeCollateralHealth: loan.removeCollateralHealth.bind(loan),
252
+ tokensToShrink: loan.tokensToShrink.bind(loan),
252
253
  removeCollateral: loan.removeCollateral.bind(loan),
253
254
  removeCollateralFutureLeverage: loan.removeCollateralFutureLeverage.bind(loan),
254
255
 
@@ -30,6 +30,8 @@ export interface ILoanV1 {
30
30
  addCollateral: (collateral: TAmount, address?: string) => Promise<string>;
31
31
  addCollateralFutureLeverage: (collateral: TAmount, userAddress?: string) => Promise<string>;
32
32
 
33
+ tokensToShrink: (dCollateral?: TAmount, address?: string) => Promise<string>;
34
+
33
35
  maxRemovable: () => Promise<string>;
34
36
  removeCollateralBands: (collateral: TAmount) => Promise<[number, number]>;
35
37
  removeCollateralPrices: (collateral: TAmount) => Promise<string[]>;
@@ -30,6 +30,8 @@ export interface ILoanV2 {
30
30
  addCollateral: (collateral: TAmount, address?: string) => Promise<string>;
31
31
  addCollateralFutureLeverage: (collateral: TAmount, userAddress?: string) => Promise<string>;
32
32
 
33
+ tokensToShrink: (dCollateral?: TAmount, address?: string) => Promise<string>;
34
+
33
35
  maxRemovable: () => Promise<string>;
34
36
  removeCollateralBands: (collateral: TAmount) => Promise<[number, number]>;
35
37
  removeCollateralPrices: (collateral: TAmount) => Promise<string[]>;
@@ -56,6 +56,8 @@ export abstract class LoanBaseModule {
56
56
 
57
57
  public abstract removeCollateralHealth(collateral: number | string, full?: boolean, address?: string): Promise<string>;
58
58
 
59
+ public abstract tokensToShrink(dCollateral?: number | string, address?: string): Promise<string>;
60
+
59
61
  public _checkRange(range: number): void {
60
62
  if (range < this.market.minBands) throw Error(`range must be >= ${this.market.minBands}`);
61
63
  if (range > this.market.maxBands) throw Error(`range must be <= ${this.market.maxBands}`);
@@ -80,6 +80,10 @@ export class LoanV1Module extends LoanBaseModule implements ILoanV1 {
80
80
  return formatUnits(_health * BigInt(100));
81
81
  }
82
82
 
83
+ public async tokensToShrink(): Promise<string> {
84
+ throw Error("tokensToShrink is not supported for v1 markets");
85
+ }
86
+
83
87
  protected async _repayBands({ debt, address }: { debt: number | string, address: string, shrink?: boolean }): Promise<[bigint, bigint]> {
84
88
  const { _collateral: _currentCollateral, _borrowed, _debt: _currentDebt, _N } = await this.market.userPosition.userStateBigInt(address);
85
89
  if (_currentDebt === BigInt(0)) throw Error(`Loan for ${address} does not exist`);
@@ -43,6 +43,16 @@ export class LoanV2Module extends LoanBaseModule implements ILoanV2 {
43
43
  return formatUnits(_health * BigInt(100));
44
44
  }
45
45
 
46
+ public async tokensToShrink(dCollateral: number | string = 0, address = ""): Promise<string> {
47
+ address = _getAddress.call(this.llamalend, address);
48
+ const _dCollateral = parseUnits(dCollateral, this.market.collateral_token.decimals);
49
+
50
+ const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
51
+ const _tokens = await contract.tokens_to_shrink(address, _dCollateral, this.llamalend.constantOptions) as bigint;
52
+
53
+ return formatUnits(_tokens, this.market.borrowed_token.decimals);
54
+ }
55
+
46
56
  public async maxRemovable(): Promise<string> {
47
57
  const address = _getAddress.call(this.llamalend, '');
48
58
  const { _collateral: _currentCollateral, _debt: _currentDebt, _N } = await this.market.userPosition.userStateBigInt();