@curvefi/llamalend-api 2.0.9 → 2.0.11
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/docs/SUPPORT_LLv2.md +30 -0
- package/lib/lendMarkets/interfaces/common/userPosition.d.ts +2 -0
- package/lib/lendMarkets/modules/common/leverageZapV2Base.js +4 -4
- package/lib/lendMarkets/modules/common/userPosition.d.ts +2 -0
- package/lib/lendMarkets/modules/common/userPosition.js +3 -1
- package/lib/mintMarkets/MintMarketTemplate.d.ts +1 -0
- package/lib/mintMarkets/MintMarketTemplate.js +1 -0
- package/package.json +1 -1
- package/src/lendMarkets/interfaces/common/userPosition.ts +2 -2
- package/src/lendMarkets/modules/common/leverageZapV2Base.ts +4 -4
- package/src/lendMarkets/modules/common/userPosition.ts +5 -3
- package/src/mintMarkets/MintMarketTemplate.ts +2 -1
package/docs/SUPPORT_LLv2.md
CHANGED
|
@@ -469,6 +469,36 @@ market.loan.estimateGas.repay({ debt, address?, shrink? }) // params: { debt: T
|
|
|
469
469
|
| forceUpdateUserState() | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
470
470
|
| getCurrentLeverageParams() | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
471
471
|
|
|
472
|
+
### `isSoftLiquidation` field in `userState` / `userStateBigInt`
|
|
473
|
+
|
|
474
|
+
The `userState` and `userStateBigInt` methods now include an `isSoftLiquidation` field in their return value.
|
|
475
|
+
|
|
476
|
+
**Updated return types:**
|
|
477
|
+
|
|
478
|
+
```ts
|
|
479
|
+
// userState
|
|
480
|
+
market.userPosition.userState(address?: string): Promise<{
|
|
481
|
+
collateral: string,
|
|
482
|
+
borrowed: string,
|
|
483
|
+
debt: string,
|
|
484
|
+
N: string,
|
|
485
|
+
isSoftLiquidation: boolean,
|
|
486
|
+
}>
|
|
487
|
+
|
|
488
|
+
// userStateBigInt
|
|
489
|
+
market.userPosition.userStateBigInt(address?: string): Promise<{
|
|
490
|
+
_collateral: bigint,
|
|
491
|
+
_borrowed: bigint,
|
|
492
|
+
_debt: bigint,
|
|
493
|
+
_N: bigint,
|
|
494
|
+
isSoftLiquidation: boolean,
|
|
495
|
+
}>
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
**Logic:** `isSoftLiquidation` is `true` when the user has an active loan (`debt > 0`) and the AMM has partially converted collateral into the borrowed token (`borrowed > 0`).
|
|
499
|
+
|
|
500
|
+
**Note:** Also applies to mint markets (`MintMarketTemplate`). In mint markets the field is returned by `userState` and is `true` when `stablecoin > 0` (the stablecoin amount reflects converted collateral in the AMM).
|
|
501
|
+
|
|
472
502
|
---
|
|
473
503
|
|
|
474
504
|
## Leverage Module (`market.leverage`)
|
|
@@ -6,6 +6,7 @@ export interface IUserPosition {
|
|
|
6
6
|
_borrowed: bigint;
|
|
7
7
|
_debt: bigint;
|
|
8
8
|
_N: bigint;
|
|
9
|
+
isSoftLiquidation: boolean;
|
|
9
10
|
}>;
|
|
10
11
|
userBandsBigInt: (address: string) => Promise<bigint[]>;
|
|
11
12
|
userState: (address?: string) => Promise<{
|
|
@@ -13,6 +14,7 @@ export interface IUserPosition {
|
|
|
13
14
|
borrowed: string;
|
|
14
15
|
debt: string;
|
|
15
16
|
N: string;
|
|
17
|
+
isSoftLiquidation: boolean;
|
|
16
18
|
}>;
|
|
17
19
|
userHealth: (full?: boolean, address?: string) => Promise<string>;
|
|
18
20
|
userBands: (address?: string) => Promise<number[]>;
|
|
@@ -47,7 +47,7 @@ export class LeverageZapV2BaseModule {
|
|
|
47
47
|
const j = N - this.market.minBands;
|
|
48
48
|
calls.push(contract.max_borrowable(this.market.addresses.controller, _userEffectiveCollateral, _maxLeverageCollateral[j], N, fromBN(pBN)));
|
|
49
49
|
}
|
|
50
|
-
_maxBorrowable = (yield this.llamalend.multicallProvider.all(calls)).map((_mb) => _mb * BigInt(
|
|
50
|
+
_maxBorrowable = (yield this.llamalend.multicallProvider.all(calls)).map((_mb) => _mb * BigInt(970) / BigInt(1000));
|
|
51
51
|
maxBorrowableBN = _maxBorrowable.map((_mb) => toBN(_mb, this.market.borrowed_token.decimals));
|
|
52
52
|
const deltaBN = maxBorrowableBN.map((mb, l) => mb.minus(maxBorrowablePrevBN[l]).abs().div(mb));
|
|
53
53
|
if (BigNumber.max(...deltaBN).lt(0.0005)) {
|
|
@@ -239,7 +239,7 @@ export class LeverageZapV2BaseModule {
|
|
|
239
239
|
maxBorrowablePrevBN = maxBorrowableBN;
|
|
240
240
|
_userEffectiveCollateral = _userCollateral + fromBN(BN(userBorrowed).div(pAvgBN), this.market.collateral_token.decimals);
|
|
241
241
|
let _maxBorrowable = yield contract.max_borrowable(this.market.addresses.controller, _userEffectiveCollateral, _maxLeverageCollateral, range, fromBN(pAvgBN));
|
|
242
|
-
_maxBorrowable = _maxBorrowable * BigInt(
|
|
242
|
+
_maxBorrowable = _maxBorrowable * BigInt(970) / BigInt(1000);
|
|
243
243
|
if (_maxBorrowable === BigInt(0))
|
|
244
244
|
break;
|
|
245
245
|
maxBorrowableBN = toBN(_maxBorrowable, this.market.borrowed_token.decimals);
|
|
@@ -468,7 +468,7 @@ export class LeverageZapV2BaseModule {
|
|
|
468
468
|
maxBorrowablePrevBN = maxBorrowableBN;
|
|
469
469
|
_userEffectiveCollateral = _userCollateral + fromBN(BN(userBorrowed).div(pAvgBN), this.market.collateral_token.decimals);
|
|
470
470
|
let _maxBorrowable = yield contract.max_borrowable(this.market.addresses.controller, _userEffectiveCollateral, _maxLeverageCollateral, _N, fromBN(pAvgBN));
|
|
471
|
-
_maxBorrowable = _maxBorrowable * BigInt(
|
|
471
|
+
_maxBorrowable = _maxBorrowable * BigInt(970) / BigInt(1000);
|
|
472
472
|
if (_maxBorrowable === BigInt(0))
|
|
473
473
|
break;
|
|
474
474
|
maxBorrowableBN = toBN(_maxBorrowable, this.market.borrowed_token.decimals);
|
|
@@ -485,7 +485,7 @@ export class LeverageZapV2BaseModule {
|
|
|
485
485
|
_userEffectiveCollateral = BigInt(0);
|
|
486
486
|
const _maxTotalCollateral = _userEffectiveCollateral + _maxLeverageCollateral;
|
|
487
487
|
let _maxBorrowable = (yield controllerContract.max_borrowable(_stateCollateral + _maxTotalCollateral, _N, _stateDebt, this.llamalend.constantOptions)) - _stateDebt;
|
|
488
|
-
_maxBorrowable = _maxBorrowable * BigInt(
|
|
488
|
+
_maxBorrowable = _maxBorrowable * BigInt(970) / BigInt(1000);
|
|
489
489
|
return {
|
|
490
490
|
maxDebt: formatUnits(_maxBorrowable, this.market.borrowed_token.decimals),
|
|
491
491
|
maxTotalCollateral: formatUnits(_maxTotalCollateral, this.market.collateral_token.decimals),
|
|
@@ -12,12 +12,14 @@ export declare class UserPositionModule implements IUserPosition {
|
|
|
12
12
|
borrowed: string;
|
|
13
13
|
debt: string;
|
|
14
14
|
N: string;
|
|
15
|
+
isSoftLiquidation: boolean;
|
|
15
16
|
}>;
|
|
16
17
|
userStateBigInt(address?: string): Promise<{
|
|
17
18
|
_collateral: bigint;
|
|
18
19
|
_borrowed: bigint;
|
|
19
20
|
_debt: bigint;
|
|
20
21
|
_N: bigint;
|
|
22
|
+
isSoftLiquidation: boolean;
|
|
21
23
|
}>;
|
|
22
24
|
userHealth(full?: boolean, address?: string): Promise<string>;
|
|
23
25
|
private _userBands;
|
|
@@ -38,12 +38,14 @@ export class UserPositionModule {
|
|
|
38
38
|
borrowed: formatUnits(_borrowed, this.market.borrowed_token.decimals),
|
|
39
39
|
debt: formatUnits(_debt, this.market.borrowed_token.decimals),
|
|
40
40
|
N: formatUnits(_N, 0),
|
|
41
|
+
isSoftLiquidation: !!_debt && !!_borrowed,
|
|
41
42
|
};
|
|
42
43
|
});
|
|
43
44
|
}
|
|
44
45
|
userStateBigInt() {
|
|
45
46
|
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
46
|
-
|
|
47
|
+
const state = yield this._userState(address);
|
|
48
|
+
return Object.assign(Object.assign({}, state), { isSoftLiquidation: !!state._debt && !!state._borrowed });
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
51
|
userHealth() {
|
package/package.json
CHANGED
|
@@ -2,9 +2,9 @@ import {IDict} from "../../../interfaces";
|
|
|
2
2
|
|
|
3
3
|
export interface IUserPosition {
|
|
4
4
|
userLoanExists: (address?: string) => Promise<boolean>,
|
|
5
|
-
userStateBigInt: (address?: string) => Promise<{ _collateral: bigint, _borrowed: bigint, _debt: bigint, _N: bigint }>,
|
|
5
|
+
userStateBigInt: (address?: string) => Promise<{ _collateral: bigint, _borrowed: bigint, _debt: bigint, _N: bigint, isSoftLiquidation: boolean }>,
|
|
6
6
|
userBandsBigInt:(address: string) => Promise<bigint[]>,
|
|
7
|
-
userState: (address?: string) => Promise<{ collateral: string, borrowed: string, debt: string, N: string }>,
|
|
7
|
+
userState: (address?: string) => Promise<{ collateral: string, borrowed: string, debt: string, N: string, isSoftLiquidation: boolean }>,
|
|
8
8
|
userHealth: (full?: boolean, address?: string) => Promise<string>,
|
|
9
9
|
userBands: (address?: string) => Promise<number[]>,
|
|
10
10
|
userRange: (address?: string) => Promise<number>,
|
|
@@ -111,7 +111,7 @@ export class LeverageZapV2BaseModule {
|
|
|
111
111
|
maxBorrowablePrevBN = maxBorrowableBN;
|
|
112
112
|
_userEffectiveCollateral = _userCollateral + fromBN(BN(userBorrowed).div(pAvgBN), this.market.collateral_token.decimals);
|
|
113
113
|
let _maxBorrowable = await contract.max_borrowable(this.market.addresses.controller, _userEffectiveCollateral, _maxLeverageCollateral, range, fromBN(pAvgBN));
|
|
114
|
-
_maxBorrowable = _maxBorrowable * BigInt(
|
|
114
|
+
_maxBorrowable = _maxBorrowable * BigInt(970) / BigInt(1000)
|
|
115
115
|
if (_maxBorrowable === BigInt(0)) break;
|
|
116
116
|
maxBorrowableBN = toBN(_maxBorrowable, this.market.borrowed_token.decimals);
|
|
117
117
|
|
|
@@ -182,7 +182,7 @@ export class LeverageZapV2BaseModule {
|
|
|
182
182
|
const j = N - this.market.minBands;
|
|
183
183
|
calls.push(contract.max_borrowable(this.market.addresses.controller, _userEffectiveCollateral, _maxLeverageCollateral[j], N, fromBN(pBN)));
|
|
184
184
|
}
|
|
185
|
-
_maxBorrowable = (await this.llamalend.multicallProvider.all(calls) as bigint[]).map((_mb) => _mb * BigInt(
|
|
185
|
+
_maxBorrowable = (await this.llamalend.multicallProvider.all(calls) as bigint[]).map((_mb) => _mb * BigInt(970) / BigInt(1000));
|
|
186
186
|
maxBorrowableBN = _maxBorrowable.map((_mb) => toBN(_mb, this.market.borrowed_token.decimals));
|
|
187
187
|
|
|
188
188
|
const deltaBN = maxBorrowableBN.map((mb, l) => mb.minus(maxBorrowablePrevBN[l]).abs().div(mb));
|
|
@@ -599,7 +599,7 @@ export class LeverageZapV2BaseModule {
|
|
|
599
599
|
maxBorrowablePrevBN = maxBorrowableBN;
|
|
600
600
|
_userEffectiveCollateral = _userCollateral + fromBN(BN(userBorrowed).div(pAvgBN), this.market.collateral_token.decimals);
|
|
601
601
|
let _maxBorrowable = await contract.max_borrowable(this.market.addresses.controller, _userEffectiveCollateral, _maxLeverageCollateral, _N, fromBN(pAvgBN));
|
|
602
|
-
_maxBorrowable = _maxBorrowable * BigInt(
|
|
602
|
+
_maxBorrowable = _maxBorrowable * BigInt(970) / BigInt(1000);
|
|
603
603
|
if (_maxBorrowable === BigInt(0)) break;
|
|
604
604
|
maxBorrowableBN = toBN(_maxBorrowable, this.market.borrowed_token.decimals);
|
|
605
605
|
|
|
@@ -618,7 +618,7 @@ export class LeverageZapV2BaseModule {
|
|
|
618
618
|
if (maxBorrowableBN.eq(0)) _userEffectiveCollateral = BigInt(0);
|
|
619
619
|
const _maxTotalCollateral = _userEffectiveCollateral + _maxLeverageCollateral
|
|
620
620
|
let _maxBorrowable = await controllerContract.max_borrowable(_stateCollateral + _maxTotalCollateral, _N, _stateDebt, this.llamalend.constantOptions) - _stateDebt;
|
|
621
|
-
_maxBorrowable = _maxBorrowable * BigInt(
|
|
621
|
+
_maxBorrowable = _maxBorrowable * BigInt(970) / BigInt(1000);
|
|
622
622
|
|
|
623
623
|
return {
|
|
624
624
|
maxDebt: formatUnits(_maxBorrowable, this.market.borrowed_token.decimals),
|
|
@@ -36,7 +36,7 @@ export class UserPositionModule implements IUserPosition {
|
|
|
36
36
|
maxAge: 10 * 1000, // 10s
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
public async userState(address = ""): Promise<{ collateral: string, borrowed: string, debt: string, N: string }> {
|
|
39
|
+
public async userState(address = ""): Promise<{ collateral: string, borrowed: string, debt: string, N: string, isSoftLiquidation: boolean }> {
|
|
40
40
|
const { _collateral, _borrowed, _debt, _N } = await this._userState(address);
|
|
41
41
|
|
|
42
42
|
return {
|
|
@@ -44,11 +44,13 @@ export class UserPositionModule implements IUserPosition {
|
|
|
44
44
|
borrowed: formatUnits(_borrowed, this.market.borrowed_token.decimals),
|
|
45
45
|
debt: formatUnits(_debt, this.market.borrowed_token.decimals),
|
|
46
46
|
N: formatUnits(_N, 0),
|
|
47
|
+
isSoftLiquidation: !!_debt && !!_borrowed,
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
public async userStateBigInt(address = ""): Promise<{ _collateral: bigint, _borrowed: bigint, _debt: bigint, _N: bigint }> {
|
|
51
|
-
|
|
51
|
+
public async userStateBigInt(address = ""): Promise<{ _collateral: bigint, _borrowed: bigint, _debt: bigint, _N: bigint, isSoftLiquidation: boolean }> {
|
|
52
|
+
const state = await this._userState(address);
|
|
53
|
+
return { ...state, isSoftLiquidation: !!state._debt && !!state._borrowed };
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
public async userHealth(full = true, address = ""): Promise<string> {
|
|
@@ -536,13 +536,14 @@ export class MintMarketTemplate {
|
|
|
536
536
|
return { _collateral, _stablecoin, _debt }
|
|
537
537
|
}
|
|
538
538
|
|
|
539
|
-
public async userState(address = ""): Promise<{ collateral: string, stablecoin: string, debt: string }> {
|
|
539
|
+
public async userState(address = ""): Promise<{ collateral: string, stablecoin: string, debt: string, isSoftLiquidation: boolean }> {
|
|
540
540
|
const { _collateral, _stablecoin, _debt } = await this._userState(address);
|
|
541
541
|
|
|
542
542
|
return {
|
|
543
543
|
collateral: formatUnits(_collateral, this.collateralDecimals),
|
|
544
544
|
stablecoin: formatUnits(_stablecoin),
|
|
545
545
|
debt: formatUnits(_debt),
|
|
546
|
+
isSoftLiquidation: !!_debt && !!_stablecoin,
|
|
546
547
|
};
|
|
547
548
|
}
|
|
548
549
|
|