@curvefi/llamalend-api 2.3.0 → 2.3.2
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/.yarn/install-state.gz +0 -0
- package/docs/SUPPORT_LLv2.md +3 -2
- package/lib/constants/aliases.js +1 -1
- package/lib/lendMarkets/LendMarketTemplate.js +1 -0
- package/lib/lendMarkets/interfaces/v1/loanV1.d.ts +1 -0
- package/lib/lendMarkets/interfaces/v2/loanV2.d.ts +1 -0
- package/lib/lendMarkets/modules/common/loanBase.d.ts +1 -0
- package/lib/lendMarkets/modules/v1/loanV1.d.ts +1 -0
- package/lib/lendMarkets/modules/v1/loanV1.js +5 -0
- package/lib/lendMarkets/modules/v2/loanV2.d.ts +1 -0
- package/lib/lendMarkets/modules/v2/loanV2.js +11 -0
- package/package.json +2 -2
- package/src/constants/aliases.ts +1 -1
- package/src/lendMarkets/LendMarketTemplate.ts +1 -0
- package/src/lendMarkets/interfaces/v1/loanV1.ts +1 -0
- package/src/lendMarkets/interfaces/v2/loanV2.ts +1 -0
- package/src/lendMarkets/modules/common/loanBase.ts +2 -0
- package/src/lendMarkets/modules/v1/loanV1.ts +4 -0
- package/src/lendMarkets/modules/v2/loanV2.ts +11 -0
|
Binary file
|
package/docs/SUPPORT_LLv2.md
CHANGED
|
@@ -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 `
|
|
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
|
|
package/lib/constants/aliases.js
CHANGED
|
@@ -32,7 +32,7 @@ export const ALIASES_OPTIMISM = lowerCaseValues({
|
|
|
32
32
|
"old_gauge_end_index": "4",
|
|
33
33
|
"leverage_zap_deprecated": "0xBFab8ebc836E1c4D81837798FC076D219C9a1855", // odos v3
|
|
34
34
|
"leverage_zap_v2": "0x56C526b0159a258887e0d79ec3a80dfb940d0cD7",
|
|
35
|
-
"leverage_zap_v2_llv2": "
|
|
35
|
+
"leverage_zap_v2_llv2": "0xdbeBDaE6f2D47B553B984E4091693824cf38584a",
|
|
36
36
|
"leverage_markets_start_id": "0",
|
|
37
37
|
"gas_oracle": '0xc0d3C0d3C0d3c0D3C0D3C0d3C0d3C0D3C0D3000f',
|
|
38
38
|
"gas_oracle_blob": '0x420000000000000000000000000000000000000f',
|
|
@@ -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),
|
|
@@ -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<{
|
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@curvefi/llamalend-api",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"description": "JavaScript library for Curve Lending",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"author": "Macket",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@curvefi/ethcall": "6.0.16",
|
|
50
50
|
"bignumber.js": "9.3.1",
|
|
51
|
-
"ethers": "6.
|
|
51
|
+
"ethers": "6.17.0",
|
|
52
52
|
"memoizee": "0.4.17"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/src/constants/aliases.ts
CHANGED
|
@@ -36,7 +36,7 @@ export const ALIASES_OPTIMISM = lowerCaseValues({
|
|
|
36
36
|
"old_gauge_end_index": "4",
|
|
37
37
|
"leverage_zap_deprecated": "0xBFab8ebc836E1c4D81837798FC076D219C9a1855", // odos v3
|
|
38
38
|
"leverage_zap_v2": "0x56C526b0159a258887e0d79ec3a80dfb940d0cD7",
|
|
39
|
-
"leverage_zap_v2_llv2": "
|
|
39
|
+
"leverage_zap_v2_llv2": "0xdbeBDaE6f2D47B553B984E4091693824cf38584a",
|
|
40
40
|
"leverage_markets_start_id": "0",
|
|
41
41
|
"gas_oracle": '0xc0d3C0d3C0d3c0D3C0D3C0d3C0d3C0D3C0D3000f',
|
|
42
42
|
"gas_oracle_blob": '0x420000000000000000000000000000000000000f',
|
|
@@ -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
|
|
|
@@ -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}`);
|
|
@@ -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();
|