@curvefi/llamalend-api 1.0.29 → 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
  }
@@ -1600,12 +1600,9 @@ export class MintMarketTemplate {
1600
1600
  // d_k_effective: uint256 = (1 - loan_discount) * sqrt((A-1)/A) / N
1601
1601
  // k_effective = d_k_effective * sum_{0..N-1}(((A-1) / A)**k)
1602
1602
  const { loan_discount } = yield this.statsParameters();
1603
- console.log("loan_discount", loan_discount);
1604
1603
  const A = this.A;
1605
- console.log("A", A);
1606
1604
  const A_BN = BN(A);
1607
1605
  const A_ratio_BN = A_BN.minus(1).div(A_BN);
1608
- console.log("A_ratio_BN", A_ratio_BN, A_ratio_BN.toString());
1609
1606
  const d_k_effective_BN = BN(100).minus(loan_discount).div(100).times(A_ratio_BN.sqrt()).div(N);
1610
1607
  let S = BN(0);
1611
1608
  for (let n = 0; n < N; n++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/llamalend-api",
3
- "version": "1.0.29",
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
  }
@@ -1694,12 +1694,9 @@ export class MintMarketTemplate {
1694
1694
  // d_k_effective: uint256 = (1 - loan_discount) * sqrt((A-1)/A) / N
1695
1695
  // k_effective = d_k_effective * sum_{0..N-1}(((A-1) / A)**k)
1696
1696
  const { loan_discount } = await this.statsParameters();
1697
- console.log("loan_discount", loan_discount);
1698
1697
  const A = this.A;
1699
- console.log("A", A);
1700
1698
  const A_BN = BN(A);
1701
1699
  const A_ratio_BN = A_BN.minus(1).div(A_BN);
1702
- console.log("A_ratio_BN", A_ratio_BN, A_ratio_BN.toString());
1703
1700
 
1704
1701
  const d_k_effective_BN = BN(100).minus(loan_discount).div(100).times(A_ratio_BN.sqrt()).div(N);
1705
1702
  let S = BN(0);