@strkfarm/sdk 1.1.10 → 1.1.12

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.
@@ -6,7 +6,7 @@ import { Global } from "@/global";
6
6
  import { ApproveCallParams, CommonAdapter, ManageCall, Swap, VesuAdapter, VesuModifyDelegationCallParams, VesuMultiplyCallParams, VesuPools } from "./universal-adapters";
7
7
  import { AVNU_MIDDLEWARE } from "./universal-adapters/adapter-utils";
8
8
  import { LiquidationRiskLevel, SmartContractRiskLevel, TechnicalRiskLevel } from "@/interfaces/risks";
9
- import { EkuboQuoter, ERC20 } from "@/modules";
9
+ import { EkuboQuoter, ERC20, PricerLST } from "@/modules";
10
10
  import { assert, logger } from "@/utils";
11
11
  import { SingleTokenInfo } from "./base-strategy";
12
12
  import { Call, Contract, uint256 } from "starknet";
@@ -17,7 +17,7 @@ export class UniversalLstMultiplierStrategy extends UniversalStrategy<UniversalS
17
17
 
18
18
  private quoteAmountToFetchPrice = new Web3Number(1, 18);
19
19
 
20
- constructor(config: IConfig, pricer: PricerBase, metadata: IStrategyMetadata<UniversalStrategySettings>) {
20
+ constructor(config: IConfig, pricer: PricerLST, metadata: IStrategyMetadata<UniversalStrategySettings>) {
21
21
  super(config, pricer, metadata);
22
22
 
23
23
  const STRKToken = Global.getDefaultTokens().find(token => token.symbol === 'STRK')!;
@@ -42,9 +42,9 @@ export class UniversalLstMultiplierStrategy extends UniversalStrategy<UniversalS
42
42
 
43
43
  // not applicable for this strategy
44
44
  // No rewards on collateral or borrowing of LST assets
45
- protected async getRewardsAUM(prevAum: Web3Number): Promise<Web3Number> {
46
- return Web3Number.fromWei("0", this.asset().decimals);
47
- }
45
+ // protected async getRewardsAUM(prevAum: Web3Number): Promise<Web3Number> {
46
+ // return Web3Number.fromWei("0", this.asset().decimals);
47
+ // }
48
48
 
49
49
  async getLSTDexPrice() {
50
50
  const ekuboQuoter = new EkuboQuoter(this.config);
@@ -82,12 +82,16 @@ export class UniversalLstMultiplierStrategy extends UniversalStrategy<UniversalS
82
82
  logger.debug(`${this.getTag()}::getVesuMultiplyCall existingCollateralInfo: ${JSON.stringify(existingCollateralInfo)},
83
83
  existingDebtInfo: ${JSON.stringify(existingDebtInfo)}, collateralisation: ${JSON.stringify(collateralisation)}`);
84
84
 
85
+ // - Prices as seen by Vesu contracts, ideal for HF math
85
86
  // Price 1 is ok as fallback bcz that would relatively price the
86
87
  // collateral and debt as equal.
87
88
  const collateralPrice = collateralisation[0].usdValue > 0 ? collateralisation[0].usdValue / existingCollateralInfo.amount.toNumber() : 1;
88
89
  const debtPrice = collateralisation[1].usdValue > 0 ? collateralisation[1].usdValue / existingDebtInfo.amount.toNumber() : 1;
89
90
  logger.debug(`${this.getTag()}::getVesuMultiplyCall collateralPrice: ${collateralPrice}, debtPrice: ${debtPrice}`);
90
91
 
92
+ // - Prices as seen by actual swap price
93
+ const dexPrice = await this.getLSTDexPrice();
94
+
91
95
  // compute optimal amount of collateral and debt post addition/removal
92
96
  // target hf = collateral * collateralPrice * ltv / debt * debtPrice
93
97
  // assuming X to be the usd amount of debt borrowed or repaied (negative).
@@ -97,11 +101,10 @@ export class UniversalLstMultiplierStrategy extends UniversalStrategy<UniversalS
97
101
  // => X = (((collateral + legDepositAmount) * collateralPrice * ltv) - (debt * debtPrice * target hf)) / (target hf - ltv)
98
102
  const addedCollateral = params.leg1DepositAmount
99
103
  .multipliedBy(params.isDeposit ? 1 : -1)
100
- const DEXPrice = await this.getLSTDexPrice();
101
104
  logger.verbose(`${this.getTag()}::getVesuMultiplyCall addedCollateral: ${addedCollateral}`);
102
105
  const numeratorPart1 = (existingCollateralInfo.amount.plus((addedCollateral))).multipliedBy(collateralPrice).multipliedBy(legLTV);
103
106
  const numeratorPart2 = existingDebtInfo.amount.multipliedBy(debtPrice).multipliedBy(this.metadata.additionalInfo.targetHealthFactor);
104
- const denominatorPart = this.metadata.additionalInfo.targetHealthFactor - (legLTV / DEXPrice);
107
+ const denominatorPart = this.metadata.additionalInfo.targetHealthFactor - (legLTV / dexPrice);
105
108
  const x_debt_usd = numeratorPart1.minus(numeratorPart2).dividedBy(denominatorPart);
106
109
  logger.verbose(`${this.getTag()}::getVesuMultiplyCall x_debt_usd: ${x_debt_usd}`);
107
110
  logger.debug(`${this.getTag()}::getVesuMultiplyCall numeratorPart1: ${numeratorPart1}, numeratorPart2: ${numeratorPart2}, denominatorPart: ${denominatorPart}`);
@@ -121,6 +124,7 @@ export class UniversalLstMultiplierStrategy extends UniversalStrategy<UniversalS
121
124
  return this.getModifyLeverCall({
122
125
  marginAmount,
123
126
  debtAmount,
127
+ lstDexPriceInUnderlying: dexPrice,
124
128
  isIncrease: debtAmount.greaterThan(0)
125
129
  });
126
130
  }
@@ -152,6 +156,7 @@ export class UniversalLstMultiplierStrategy extends UniversalStrategy<UniversalS
152
156
  async getModifyLeverCall(params: {
153
157
  marginAmount: Web3Number, // >0 during deposit
154
158
  debtAmount: Web3Number,
159
+ lstDexPriceInUnderlying: number,
155
160
  isIncrease: boolean
156
161
  }): Promise<Call[]> {
157
162
  assert(!params.marginAmount.isZero() || !params.debtAmount.isZero(), 'Deposit/debt must be non-0');
@@ -175,13 +180,12 @@ export class UniversalLstMultiplierStrategy extends UniversalStrategy<UniversalS
175
180
  manageCalls.push(manageCall1);
176
181
  }
177
182
 
183
+ const lstDexPriceInUnderlying = params.lstDexPriceInUnderlying;
178
184
  const ekuboQuoter = new EkuboQuoter(this.config);
179
185
 
180
186
  // compute quotes for margin swap
181
- const lstPrice = await this.getLSTExchangeRate();
182
187
  const marginSwap: Swap[] = [];
183
188
 
184
-
185
189
  // compute quotes for lever swap
186
190
  const MAX_SLIPPAGE = 0.01;
187
191
  // when increasing, debt is swapped to collateral (LST)
@@ -196,8 +200,8 @@ export class UniversalLstMultiplierStrategy extends UniversalStrategy<UniversalS
196
200
  );
197
201
  assert(leverSwapQuote.price_impact < MAX_SLIPPAGE, 'getIncreaseLeverCall: Price impact is too high [Debt swap]');
198
202
  const leverSwap = ekuboQuoter.getVesuMultiplyQuote(leverSwapQuote, fromToken, toToken);
199
- const minExpectedDebt = params.debtAmount.dividedBy(lstPrice).multipliedBy(1 - MAX_SLIPPAGE); // used for increase
200
- const maxUsedCollateral = params.debtAmount.abs().dividedBy(lstPrice).multipliedBy(1 + MAX_SLIPPAGE); // +ve for exact amount out, used for decrease
203
+ const minExpectedDebt = params.debtAmount.dividedBy(lstDexPriceInUnderlying).multipliedBy(1 - MAX_SLIPPAGE); // used for increase
204
+ const maxUsedCollateral = params.debtAmount.abs().dividedBy(lstDexPriceInUnderlying).multipliedBy(1 + MAX_SLIPPAGE); // +ve for exact amount out, used for decrease
201
205
 
202
206
  const STEP2_ID = LST_MULTIPLIER_MANAGE_IDS.SWITCH_DELEGATION_ON;
203
207
  const manage2Info = this.getProofs<VesuModifyDelegationCallParams>(STEP2_ID);
@@ -452,6 +456,18 @@ const hyperxsBTC: UniversalStrategySettings = {
452
456
  minHealthFactor: 1.05
453
457
  }
454
458
 
459
+ const hyperxLBTC: UniversalStrategySettings = {
460
+ vaultAddress: ContractAddr.from('0x38e96a301428d204ab4553799aa386a0f14a5ef9b30a5830be1814e4fb8da1c'),
461
+ manager: ContractAddr.from('0x18d376446d9df1f783e17aff1f21bac3d97aa3ba378e367742cdd744468ad35'),
462
+ vaultAllocator: ContractAddr.from('0x3e98774ca0508505ba6d7f17d95ec391648f44f947b0d211241464a4f5b9b20'),
463
+ redeemRequestNFT: ContractAddr.from('0x268017b4c8b2117ca0136d9a77e3666db44b143447566f0746ca0b1c9ab1e72'),
464
+ aumOracle: ContractAddr.from('0x521a3f339c65e918e0d8a065b14baef1ea25676bb7fca1e0238ac47e20d7755'),
465
+ leafAdapters: [],
466
+ adapters: [],
467
+ targetHealthFactor: 1.1,
468
+ minHealthFactor: 1.05
469
+ }
470
+
455
471
  function getInvestmentSteps(lstSymbol: string, underlyingSymbol: string) {
456
472
  return [
457
473
  `Deposit ${underlyingSymbol} into the vault`,
@@ -494,4 +510,5 @@ export const HyperLSTStrategies: IStrategyMetadata<UniversalStrategySettings>[]
494
510
  getStrategySettings('xWBTC', 'WBTC', hyperxWBTC, true),
495
511
  getStrategySettings('xtBTC', 'tBTC', hyperxtBTC, true),
496
512
  getStrategySettings('xsBTC', 'solvBTC', hyperxsBTC, true),
513
+ getStrategySettings('xLBTC', 'LBTC', hyperxLBTC, true),
497
514
  ]
@@ -310,20 +310,20 @@ export class UniversalStrategy<
310
310
  const underlying = this.asset();
311
311
  let vesuAum = Web3Number.fromWei("0", underlying.decimals);
312
312
 
313
+ let tokenUnderlyingPrice = await this.pricer.getPrice(this.asset().symbol);
314
+
313
315
  // handle collateral
314
316
  if (legAUM[0].token.address.eq(underlying.address)) {
315
317
  vesuAum = vesuAum.plus(legAUM[0].amount);
316
318
  } else {
317
- const tokenPrice = await this.pricer.getPrice(legAUM[1].token.symbol);
318
- vesuAum = vesuAum.plus(legAUM[1].usdValue / tokenPrice.price);
319
+ vesuAum = vesuAum.plus(legAUM[1].usdValue / tokenUnderlyingPrice.price);
319
320
  }
320
321
 
321
322
  // handle debt
322
323
  if (legAUM[1].token.address.eq(underlying.address)) {
323
324
  vesuAum = vesuAum.minus(legAUM[1].amount);
324
325
  } else {
325
- const tokenPrice = await this.pricer.getPrice(legAUM[1].token.symbol);
326
- vesuAum = vesuAum.minus(legAUM[1].usdValue / tokenPrice.price);
326
+ vesuAum = vesuAum.minus(legAUM[1].usdValue / tokenUnderlyingPrice.price);
327
327
  };
328
328
 
329
329
  logger.verbose(`${this.getTag()} Vesu AUM: ${vesuAum}, legCollateral: ${legAUM[0].amount.toNumber()}, legDebt: ${legAUM[1].amount.toNumber()}`);