@curvefi/llamalend-api 1.0.28 → 1.0.30

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.
@@ -518,4 +518,5 @@ export declare class LendMarketTemplate {
518
518
  private leverageRepay;
519
519
  currentLeverage(userAddress?: string): Promise<string>;
520
520
  currentPnL(userAddress?: string): Promise<Record<string, string>>;
521
+ userBoost(address?: string): Promise<string>;
521
522
  }
@@ -2774,4 +2774,29 @@ export class LendMarketTemplate {
2774
2774
  };
2775
2775
  });
2776
2776
  }
2777
+ userBoost() {
2778
+ return __awaiter(this, arguments, void 0, function* (address = "") {
2779
+ if (this.addresses.gauge === this.llamalend.constants.ZERO_ADDRESS) {
2780
+ throw Error(`${this.name} doesn't have gauge`);
2781
+ }
2782
+ if (this.vaultRewardsOnly()) {
2783
+ throw Error(`${this.name} has Rewards-Only Gauge. Use stats.rewardsApy instead`);
2784
+ }
2785
+ address = _getAddress.call(this.llamalend, address);
2786
+ const gaugeContract = this.llamalend.contracts[this.addresses.gauge].multicallContract;
2787
+ const [workingBalanceBN, balanceBN] = (yield this.llamalend.multicallProvider.all([
2788
+ gaugeContract.working_balances(address),
2789
+ gaugeContract.balanceOf(address),
2790
+ ])).map((value) => toBN(value));
2791
+ if (balanceBN.isZero()) {
2792
+ return '1.0';
2793
+ }
2794
+ const boostBN = workingBalanceBN.div(0.4).div(balanceBN);
2795
+ if (boostBN.lt(1))
2796
+ return '1.0';
2797
+ if (boostBN.gt(2.5))
2798
+ return '2.5';
2799
+ return boostBN.toFixed(4).replace(/([0-9])0+$/, '$1');
2800
+ });
2801
+ }
2777
2802
  }
@@ -80,6 +80,7 @@ export declare class MintMarketTemplate {
80
80
  }>;
81
81
  };
82
82
  leverage: {
83
+ maxLeverage: (N?: number) => Promise<string>;
83
84
  createLoanMaxRecv: (collateral: number | string, range: number) => Promise<{
84
85
  maxBorrowable: string;
85
86
  maxCollateral: string;
@@ -312,6 +313,8 @@ export declare class MintMarketTemplate {
312
313
  private _leverageCreateLoan;
313
314
  private leverageCreateLoanEstimateGas;
314
315
  private leverageCreateLoan;
316
+ private _get_k_effective_BN;
317
+ private maxLeverage;
315
318
  private _checkDeleverageZap;
316
319
  private deleverageRepayStablecoins;
317
320
  private deleverageGetRouteName;
@@ -294,6 +294,7 @@ export class MintMarketTemplate {
294
294
  balances: this.walletBalances.bind(this),
295
295
  };
296
296
  this.leverage = {
297
+ maxLeverage: this.maxLeverage.bind(this),
297
298
  createLoanMaxRecv: this.leverageCreateLoanMaxRecv.bind(this),
298
299
  createLoanMaxRecvAllRanges: this.leverageCreateLoanMaxRecvAllRanges.bind(this),
299
300
  createLoanCollateral: this.leverageCreateLoanCollateral.bind(this),
@@ -1594,6 +1595,29 @@ export class MintMarketTemplate {
1594
1595
  return yield this._leverageCreateLoan(collateral, debt, range, slippage, false);
1595
1596
  });
1596
1597
  }
1598
+ _get_k_effective_BN(N) {
1599
+ return __awaiter(this, void 0, void 0, function* () {
1600
+ // d_k_effective: uint256 = (1 - loan_discount) * sqrt((A-1)/A) / N
1601
+ // k_effective = d_k_effective * sum_{0..N-1}(((A-1) / A)**k)
1602
+ const { loan_discount } = yield this.statsParameters();
1603
+ const A = this.A;
1604
+ const A_BN = BN(A);
1605
+ const A_ratio_BN = A_BN.minus(1).div(A_BN);
1606
+ const d_k_effective_BN = BN(100).minus(loan_discount).div(100).times(A_ratio_BN.sqrt()).div(N);
1607
+ let S = BN(0);
1608
+ for (let n = 0; n < N; n++) {
1609
+ S = S.plus(A_ratio_BN.pow(n));
1610
+ }
1611
+ return d_k_effective_BN.times(S);
1612
+ });
1613
+ }
1614
+ maxLeverage() {
1615
+ return __awaiter(this, arguments, void 0, function* (N = 4) {
1616
+ // max_leverage = 1 / (k_effective - 1)
1617
+ const k_effective_BN = yield this._get_k_effective_BN(N);
1618
+ return BN(1).div(BN(1).minus(k_effective_BN)).toString();
1619
+ });
1620
+ }
1597
1621
  // ---------------- DELEVERAGE REPAY ----------------
1598
1622
  _checkDeleverageZap() {
1599
1623
  if (this.deleverageZap === "0x0000000000000000000000000000000000000000")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/llamalend-api",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "description": "JavaScript library for Curve Lending",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",
@@ -3134,4 +3134,30 @@ export class LendMarketTemplate {
3134
3134
  percentage: percentage.toFixed(2).toString(),
3135
3135
  };
3136
3136
  }
3137
+
3138
+ public async userBoost(address = ""): Promise<string> {
3139
+ if (this.addresses.gauge === this.llamalend.constants.ZERO_ADDRESS) {
3140
+ throw Error(`${this.name} doesn't have gauge`);
3141
+ }
3142
+ if (this.vaultRewardsOnly()) {
3143
+ throw Error(`${this.name} has Rewards-Only Gauge. Use stats.rewardsApy instead`);
3144
+ }
3145
+ address = _getAddress.call(this.llamalend, address);
3146
+
3147
+ const gaugeContract = this.llamalend.contracts[this.addresses.gauge].multicallContract;
3148
+ const [workingBalanceBN, balanceBN] = (await this.llamalend.multicallProvider.all([
3149
+ gaugeContract.working_balances(address),
3150
+ gaugeContract.balanceOf(address),
3151
+ ]) as bigint[]).map((value: bigint) => toBN(value));
3152
+
3153
+ if (balanceBN.isZero()) {
3154
+ return '1.0';
3155
+ }
3156
+
3157
+ const boostBN = workingBalanceBN.div(0.4).div(balanceBN);
3158
+ if (boostBN.lt(1)) return '1.0';
3159
+ if (boostBN.gt(2.5)) return '2.5';
3160
+
3161
+ return boostBN.toFixed(4).replace(/([0-9])0+$/, '$1');
3162
+ }
3137
3163
  }
@@ -90,6 +90,7 @@ export class MintMarketTemplate {
90
90
  balances: (address?: string) => Promise<{ stablecoin: string, collateral: string }>,
91
91
  };
92
92
  leverage: {
93
+ maxLeverage: (N?: number) => Promise<string>,
93
94
  createLoanMaxRecv: (collateral: number | string, range: number) => Promise<{ maxBorrowable: string, maxCollateral: string, leverage: string, routeIdx: number }>,
94
95
  createLoanMaxRecvAllRanges: (collateral: number | string) => Promise<IDict<{ maxBorrowable: string, maxCollateral: string, leverage: string, routeIdx: number }>>,
95
96
  createLoanCollateral: (userCollateral: number | string, debt: number | string) => Promise<{ collateral: string, leverage: string, routeIdx: number }>,
@@ -185,6 +186,7 @@ export class MintMarketTemplate {
185
186
  balances: this.walletBalances.bind(this),
186
187
  }
187
188
  this.leverage = {
189
+ maxLeverage: this.maxLeverage.bind(this),
188
190
  createLoanMaxRecv: this.leverageCreateLoanMaxRecv.bind(this),
189
191
  createLoanMaxRecvAllRanges: this.leverageCreateLoanMaxRecvAllRanges.bind(this),
190
192
  createLoanCollateral: this.leverageCreateLoanCollateral.bind(this),
@@ -1688,6 +1690,30 @@ export class MintMarketTemplate {
1688
1690
  return await this._leverageCreateLoan(collateral, debt, range, slippage, false) as string;
1689
1691
  }
1690
1692
 
1693
+ private async _get_k_effective_BN(N: number): Promise<BigNumber> {
1694
+ // d_k_effective: uint256 = (1 - loan_discount) * sqrt((A-1)/A) / N
1695
+ // k_effective = d_k_effective * sum_{0..N-1}(((A-1) / A)**k)
1696
+ const { loan_discount } = await this.statsParameters();
1697
+ const A = this.A;
1698
+ const A_BN = BN(A);
1699
+ const A_ratio_BN = A_BN.minus(1).div(A_BN);
1700
+
1701
+ const d_k_effective_BN = BN(100).minus(loan_discount).div(100).times(A_ratio_BN.sqrt()).div(N);
1702
+ let S = BN(0);
1703
+ for (let n = 0; n < N; n++) {
1704
+ S = S.plus(A_ratio_BN.pow(n))
1705
+ }
1706
+
1707
+ return d_k_effective_BN.times(S);
1708
+ }
1709
+
1710
+ private async maxLeverage(N: number = 4): Promise<string> {
1711
+ // max_leverage = 1 / (k_effective - 1)
1712
+ const k_effective_BN = await this._get_k_effective_BN(N);
1713
+
1714
+ return BN(1).div(BN(1).minus(k_effective_BN)).toString()
1715
+ }
1716
+
1691
1717
  // ---------------- DELEVERAGE REPAY ----------------
1692
1718
 
1693
1719
  private _checkDeleverageZap(): void {