@curvefi/llamalend-api 1.1.10 → 1.1.13

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.
@@ -3,6 +3,7 @@ name: Release & Publish
3
3
  on:
4
4
  push:
5
5
  branches:
6
+ - v1
6
7
  - main
7
8
 
8
9
  jobs:
@@ -50,4 +51,9 @@ jobs:
50
51
  cache: npm
51
52
  - run: npm ci
52
53
  - run: npm run build
53
- - run: npm publish
54
+ - name: Publish main as latest
55
+ if: github.ref_name == 'main'
56
+ run: npm publish --tag latest
57
+ - name: Publish v1 branch as legacy
58
+ if: github.ref_name == 'v1'
59
+ run: npm publish --tag legacy
@@ -3,7 +3,7 @@ import type { Llamalend } from "../llamalend.js";
3
3
  import { IDict, TGas, TAmount, IReward, IQuoteOdos, IOneWayMarket, IPartialFrac } from "../interfaces.js";
4
4
  import { ILeverageZapV2 } from "./interfaces/leverageZapV2.js";
5
5
  export declare class LendMarketTemplate {
6
- private llamalend;
6
+ llamalend: Llamalend;
7
7
  id: string;
8
8
  name: string;
9
9
  addresses: {
@@ -535,5 +535,6 @@ export declare class LendMarketTemplate {
535
535
  currentPnL(userAddress?: string): Promise<Record<string, string>>;
536
536
  userBoost(address?: string): Promise<string>;
537
537
  forceUpdateUserState(newTx: string, userAddress?: string): Promise<void>;
538
- getLlamalend(): Llamalend;
538
+ /** Clears all memoization caches. */
539
+ clearCache(): void;
539
540
  }
@@ -2925,7 +2925,20 @@ export class LendMarketTemplate {
2925
2925
  yield _getUserCollateralForce(this.llamalend.constants.NETWORK_NAME, this.addresses.controller, address, newTx);
2926
2926
  });
2927
2927
  }
2928
- getLlamalend() {
2929
- return this.llamalend;
2928
+ /** Clears all memoization caches. */
2929
+ clearCache() {
2930
+ this.vaultRewardTokens.clear();
2931
+ this.statsParameters.clear();
2932
+ this.statsBandsInfo.clear();
2933
+ this.A.clear();
2934
+ this.basePrice.clear();
2935
+ this.oraclePrice.clear();
2936
+ this.oracleAddress.clear();
2937
+ this._userState.clear();
2938
+ this.createLoanMaxRecvAllRanges.clear();
2939
+ this.leverageCreateLoanMaxRecvAllRanges.clear();
2940
+ this._leverageCalcN1.clear();
2941
+ this._leverageCalcN1AllRanges.clear();
2942
+ this._leverageRepayBands.clear();
2930
2943
  }
2931
2944
  }
@@ -182,7 +182,7 @@ export class LeverageZapV2Module {
182
182
  maxAge: 5 * 60 * 1000, // 5m
183
183
  });
184
184
  this.market = market;
185
- this.llamalend = market.getLlamalend();
185
+ this.llamalend = market.llamalend;
186
186
  }
187
187
  _checkLeverageZap() {
188
188
  if (!this.hasLeverage()) {
@@ -3,7 +3,7 @@ import type { Llamalend } from "../llamalend.js";
3
3
  import { IDict, ILlamma, TGas, IRates } from "../interfaces.js";
4
4
  import { ILeverageV2 } from "./interfaces/leverage.js";
5
5
  export declare class MintMarketTemplate {
6
- private llamalend;
6
+ llamalend: Llamalend;
7
7
  id: string;
8
8
  address: string;
9
9
  controller: string;
@@ -177,6 +177,8 @@ export declare class MintMarketTemplate {
177
177
  stablecoin: string;
178
178
  debt: string;
179
179
  }>;
180
+ /** Clears all memoization caches. */
181
+ clearCache(): void;
180
182
  userLoss(userAddress?: string): Promise<{
181
183
  deposited_collateral: string;
182
184
  current_collateral_estimation: string;
@@ -187,6 +189,7 @@ export declare class MintMarketTemplate {
187
189
  stablecoin: string;
188
190
  collateral: string;
189
191
  }>>;
192
+ oracleAddress: (() => Promise<string>) & memoize.Memoized<() => Promise<string>>;
190
193
  oraclePrice(): Promise<string>;
191
194
  oraclePriceBand(): Promise<number>;
192
195
  price(): Promise<string>;
@@ -341,5 +344,4 @@ export declare class MintMarketTemplate {
341
344
  private _checkLeverageForStats;
342
345
  currentLeverage(userAddress?: string): Promise<string>;
343
346
  currentPnL(userAddress?: string): Promise<Record<string, string>>;
344
- getLlamalend(): Llamalend;
345
347
  }
@@ -106,6 +106,12 @@ export class MintMarketTemplate {
106
106
  promise: true,
107
107
  maxAge: 60 * 1000, // 1m
108
108
  });
109
+ this.oracleAddress = memoize(() => __awaiter(this, void 0, void 0, function* () {
110
+ const _address = yield this.llamalend.contracts[this.address].contract.price_oracle_contract(this.llamalend.constantOptions);
111
+ return _address;
112
+ }), {
113
+ promise: true,
114
+ });
109
115
  this.basePrice = memoize(() => __awaiter(this, void 0, void 0, function* () {
110
116
  const _price = yield this.llamalend.contracts[this.address].contract.get_base_price(this.llamalend.constantOptions);
111
117
  return formatUnits(_price);
@@ -512,6 +518,25 @@ export class MintMarketTemplate {
512
518
  };
513
519
  });
514
520
  }
521
+ /** Clears all memoization caches. */
522
+ clearCache() {
523
+ this.statsParameters.clear();
524
+ this.statsMaxMinBands.clear();
525
+ this.statsActiveBand.clear();
526
+ this.statsTotalSupply.clear();
527
+ this.statsTotalDebt.clear();
528
+ this.statsTotalStablecoin.clear();
529
+ this.statsTotalCollateral.clear();
530
+ this.statsCapAndAvailable.clear();
531
+ this.oracleAddress.clear();
532
+ this.basePrice.clear();
533
+ this.createLoanMaxRecvAllRanges.clear();
534
+ this.leverageCreateLoanMaxRecvAllRanges.clear();
535
+ this._leverageCreateLoanMaxRecvAllRanges2.clear();
536
+ this._leverageCreateLoanCollateral.clear();
537
+ this.deleverageRepayStablecoins.clear();
538
+ this._deleverageRepayBands.clear();
539
+ }
515
540
  userLoss() {
516
541
  return __awaiter(this, arguments, void 0, function* (userAddress = "") {
517
542
  userAddress = _getAddress.call(this.llamalend, userAddress);
@@ -1855,7 +1880,4 @@ export class MintMarketTemplate {
1855
1880
  };
1856
1881
  });
1857
1882
  }
1858
- getLlamalend() {
1859
- return this.llamalend;
1860
- }
1861
1883
  }
@@ -209,7 +209,7 @@ export class LeverageV2Module {
209
209
  maxAge: 5 * 60 * 1000, // 5m
210
210
  });
211
211
  this.market = market;
212
- this.llamalend = market.getLlamalend();
212
+ this.llamalend = market.llamalend;
213
213
  }
214
214
  // ============ CREATE LOAN METHODS ============
215
215
  // ---------------- LEVERAGE CREATE LOAN ----------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/llamalend-api",
3
- "version": "1.1.10",
3
+ "version": "1.1.13",
4
4
  "description": "JavaScript library for Curve Lending",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",
@@ -36,7 +36,7 @@ const WEEK = 7 * DAY;
36
36
 
37
37
 
38
38
  export class LendMarketTemplate {
39
- private llamalend: Llamalend;
39
+ llamalend: Llamalend;
40
40
  id: string;
41
41
  name: string
42
42
  addresses: {
@@ -3333,7 +3333,20 @@ export class LendMarketTemplate {
3333
3333
  );
3334
3334
  }
3335
3335
 
3336
- public getLlamalend(): Llamalend {
3337
- return this.llamalend;
3336
+ /** Clears all memoization caches. */
3337
+ public clearCache(): void {
3338
+ this.vaultRewardTokens.clear();
3339
+ this.statsParameters.clear();
3340
+ this.statsBandsInfo.clear();
3341
+ this.A.clear();
3342
+ this.basePrice.clear();
3343
+ this.oraclePrice.clear();
3344
+ this.oracleAddress.clear();
3345
+ this._userState.clear();
3346
+ this.createLoanMaxRecvAllRanges.clear();
3347
+ this.leverageCreateLoanMaxRecvAllRanges.clear();
3348
+ this._leverageCalcN1.clear();
3349
+ this._leverageCalcN1AllRanges.clear();
3350
+ this._leverageRepayBands.clear();
3338
3351
  }
3339
3352
  }
@@ -29,7 +29,7 @@ export class LeverageZapV2Module {
29
29
 
30
30
  constructor(market: LendMarketTemplate) {
31
31
  this.market = market;
32
- this.llamalend = market.getLlamalend();
32
+ this.llamalend = market.llamalend;
33
33
  }
34
34
 
35
35
  private _getMarketId = (): number => Number(this.market.id.split("-").slice(-1)[0]);
@@ -28,7 +28,7 @@ import { LeverageV2Module } from "./modules/index.js";
28
28
 
29
29
 
30
30
  export class MintMarketTemplate {
31
- private llamalend: Llamalend;
31
+ llamalend: Llamalend;
32
32
  id: string;
33
33
  address: string;
34
34
  controller: string;
@@ -546,6 +546,26 @@ export class MintMarketTemplate {
546
546
  };
547
547
  }
548
548
 
549
+ /** Clears all memoization caches. */
550
+ public clearCache(): void {
551
+ this.statsParameters.clear();
552
+ this.statsMaxMinBands.clear();
553
+ this.statsActiveBand.clear();
554
+ this.statsTotalSupply.clear();
555
+ this.statsTotalDebt.clear();
556
+ this.statsTotalStablecoin.clear();
557
+ this.statsTotalCollateral.clear();
558
+ this.statsCapAndAvailable.clear();
559
+ this.oracleAddress.clear();
560
+ this.basePrice.clear();
561
+ this.createLoanMaxRecvAllRanges.clear();
562
+ this.leverageCreateLoanMaxRecvAllRanges.clear();
563
+ this._leverageCreateLoanMaxRecvAllRanges2.clear();
564
+ this._leverageCreateLoanCollateral.clear();
565
+ this.deleverageRepayStablecoins.clear();
566
+ this._deleverageRepayBands.clear();
567
+ }
568
+
549
569
  public async userLoss(userAddress = ""): Promise<{ deposited_collateral: string, current_collateral_estimation: string, loss: string, loss_pct: string }> {
550
570
  userAddress = _getAddress.call(this.llamalend, userAddress);
551
571
  const [deposited_collateral, _current_collateral_estimation] = await Promise.all([
@@ -592,6 +612,14 @@ export class MintMarketTemplate {
592
612
  return res
593
613
  }
594
614
 
615
+ public oracleAddress = memoize(async (): Promise<string> => {
616
+ const _address = await this.llamalend.contracts[this.address].contract.price_oracle_contract(this.llamalend.constantOptions) as string;
617
+ return _address;
618
+ },
619
+ {
620
+ promise: true,
621
+ });
622
+
595
623
  public async oraclePrice(): Promise<string> {
596
624
  const _price = await this.llamalend.contracts[this.address].contract.price_oracle(this.llamalend.constantOptions) as bigint;
597
625
  return formatUnits(_price);
@@ -1999,8 +2027,4 @@ export class MintMarketTemplate {
1999
2027
  percentage: percentage.toString(),
2000
2028
  };
2001
2029
  }
2002
-
2003
- public getLlamalend(): Llamalend {
2004
- return this.llamalend;
2005
- }
2006
2030
  }
@@ -31,7 +31,7 @@ export class LeverageV2Module {
31
31
 
32
32
  constructor(market: MintMarketTemplate) {
33
33
  this.market = market;
34
- this.llamalend = market.getLlamalend();
34
+ this.llamalend = market.llamalend;
35
35
  }
36
36
 
37
37
  private _getMarketId = (): number => {