@strkfarm/sdk 2.0.0-dev.3 → 2.0.0-dev.5

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/dist/index.mjs CHANGED
@@ -28201,11 +28201,12 @@ var calculateAmountDepositOnExtendedWhenIncurringLosses = async (client) => {
28201
28201
  logger.error(`error getting extended position: extendedHoldings=${extendedHoldings}, latestPosition=${latestPosition}`);
28202
28202
  return null;
28203
28203
  }
28204
- const positionValueInUSD = latestPosition.value;
28204
+ const positionValueInUSD = new Web3Number(latestPosition.value, USDC_TOKEN_DECIMALS);
28205
28205
  const equity = extendedHoldings.data.equity;
28206
- const deposit = Number(positionValueInUSD) / extended_leverage - Number(equity);
28207
- return new Web3Number(Math.floor(deposit / 0.2) * 0.2, USDC_TOKEN_DECIMALS);
28206
+ const deposit = positionValueInUSD.dividedBy(extended_leverage).minus(equity).toFixed(2);
28207
+ return new Web3Number(deposit, USDC_TOKEN_DECIMALS);
28208
28208
  } catch (err) {
28209
+ logger.error(`error calculating amount deposit on extended when incurring losses: ${err}`);
28209
28210
  return null;
28210
28211
  }
28211
28212
  };
@@ -28283,21 +28284,35 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28283
28284
  vaultAllocator: config.vaultAllocator,
28284
28285
  id: ""
28285
28286
  });
28286
- this.tokenMarketData = new TokenMarketData(this.config.pricer, this.config.networkConfig);
28287
+ this.tokenMarketData = new TokenMarketData(
28288
+ this.config.pricer,
28289
+ this.config.networkConfig
28290
+ );
28287
28291
  }
28288
28292
  async getAPY(supportedPosition) {
28289
28293
  const CACHE_KEY = `apy_${this.config.poolId.address}_${supportedPosition.asset.symbol}`;
28290
28294
  const cacheData = this.getCache(CACHE_KEY);
28291
- console.log(`${_VesuMultiplyAdapter.name}::getAPY cacheData: ${JSON.stringify(cacheData)}`, this.vesuAdapter.config.poolId.shortString(), this.vesuAdapter.config.collateral.symbol, this.vesuAdapter.config.debt.symbol);
28295
+ console.log(
28296
+ `${_VesuMultiplyAdapter.name}::getAPY cacheData: ${JSON.stringify(
28297
+ cacheData
28298
+ )}`,
28299
+ this.vesuAdapter.config.poolId.shortString(),
28300
+ this.vesuAdapter.config.collateral.symbol,
28301
+ this.vesuAdapter.config.debt.symbol
28302
+ );
28292
28303
  if (cacheData) {
28293
28304
  return cacheData;
28294
28305
  }
28295
28306
  try {
28296
28307
  const allVesuPools = await VesuAdapter.getVesuPools();
28297
28308
  const asset = supportedPosition.asset;
28298
- const pool = allVesuPools.pools.find((p) => this.vesuAdapter.config.poolId.eqString(num9.getHexString(p.id)));
28309
+ const pool = allVesuPools.pools.find(
28310
+ (p) => this.vesuAdapter.config.poolId.eqString(num9.getHexString(p.id))
28311
+ );
28299
28312
  if (!pool) {
28300
- logger.warn(`VesuMultiplyAdapter: Pool not found for token ${asset.symbol}`);
28313
+ logger.warn(
28314
+ `VesuMultiplyAdapter: Pool not found for token ${asset.symbol}`
28315
+ );
28301
28316
  return {
28302
28317
  apy: 0,
28303
28318
  type: "base" /* BASE */
@@ -28307,7 +28322,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28307
28322
  (a) => a.symbol.toLowerCase() === asset.symbol.toLowerCase()
28308
28323
  )?.stats;
28309
28324
  if (!assetStats) {
28310
- logger.warn(`VesuMultiplyAdapter: Asset stats not found for token ${asset.symbol}`);
28325
+ logger.warn(
28326
+ `VesuMultiplyAdapter: Asset stats not found for token ${asset.symbol}`
28327
+ );
28311
28328
  return {
28312
28329
  apy: 0,
28313
28330
  type: "base" /* BASE */
@@ -28318,7 +28335,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28318
28335
  apy = Number(assetStats.borrowApr?.value || 0) / 1e18;
28319
28336
  } else {
28320
28337
  const isAssetBTC = asset.symbol.toLowerCase().includes("btc");
28321
- const baseAPY = Number(isAssetBTC ? assetStats.btcFiSupplyApr?.value + assetStats.supplyApy?.value : assetStats.supplyApy?.value || 0) / 1e18;
28338
+ const baseAPY = Number(
28339
+ isAssetBTC ? assetStats.btcFiSupplyApr?.value + assetStats.supplyApy?.value : assetStats.supplyApy?.value || 0
28340
+ ) / 1e18;
28322
28341
  const rewardAPY = Number(assetStats.defiSpringSupplyApr?.value || "0") / 1e18;
28323
28342
  const isSupported = this.tokenMarketData.isAPYSupported(asset);
28324
28343
  apy = baseAPY + rewardAPY;
@@ -28334,7 +28353,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28334
28353
  this.setCache(CACHE_KEY, result, 3e5);
28335
28354
  return result;
28336
28355
  } catch (error) {
28337
- logger.error(`VesuMultiplyAdapter: Error getting APY for ${supportedPosition.asset.symbol}:`, error);
28356
+ logger.error(
28357
+ `VesuMultiplyAdapter: Error getting APY for ${supportedPosition.asset.symbol}:`,
28358
+ error
28359
+ );
28338
28360
  throw error;
28339
28361
  }
28340
28362
  }
@@ -28347,12 +28369,16 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28347
28369
  try {
28348
28370
  this.vesuAdapter.networkConfig = this.config.networkConfig;
28349
28371
  this.vesuAdapter.pricer = this.config.pricer;
28350
- const positions = await this.vesuAdapter.getPositions(this.config.networkConfig);
28372
+ const positions = await this.vesuAdapter.getPositions(
28373
+ this.config.networkConfig
28374
+ );
28351
28375
  let position = positions.find(
28352
28376
  (p) => p.token.address.eq(supportedPosition.asset.address)
28353
28377
  );
28354
28378
  if (!position) {
28355
- logger.warn(`VesuMultiplyAdapter: Position not found for token ${supportedPosition.asset.symbol}`);
28379
+ logger.warn(
28380
+ `VesuMultiplyAdapter: Position not found for token ${supportedPosition.asset.symbol}`
28381
+ );
28356
28382
  return {
28357
28383
  amount: new Web3Number("0", supportedPosition.asset.decimals),
28358
28384
  remarks: "Position not found"
@@ -28365,12 +28391,18 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28365
28391
  this.setCache(CACHE_KEY, position, 6e4);
28366
28392
  return position;
28367
28393
  } catch (error) {
28368
- logger.error(`VesuMultiplyAdapter: Error getting position for ${supportedPosition.asset.symbol}:`, error);
28394
+ logger.error(
28395
+ `VesuMultiplyAdapter: Error getting position for ${supportedPosition.asset.symbol}:`,
28396
+ error
28397
+ );
28369
28398
  throw error;
28370
28399
  }
28371
28400
  }
28372
28401
  async maxBorrowableAPY() {
28373
- const collateralAPY = await this.getAPY({ asset: this.config.collateral, isDebt: false });
28402
+ const collateralAPY = await this.getAPY({
28403
+ asset: this.config.collateral,
28404
+ isDebt: false
28405
+ });
28374
28406
  const apy = collateralAPY.apy * 0.8;
28375
28407
  return apy;
28376
28408
  }
@@ -28380,9 +28412,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28380
28412
  try {
28381
28413
  this.vesuAdapter.networkConfig = this.config.networkConfig;
28382
28414
  this.vesuAdapter.pricer = this.config.pricer;
28383
- const positions = await this.vesuAdapter.getPositions(this.config.networkConfig);
28384
- const collateralPosition = positions.find((p) => p.token.address.eq(collateral.address));
28385
- const debtPosition = positions.find((p) => p.token.address.eq(debt.address));
28415
+ const positions = await this.vesuAdapter.getPositions(
28416
+ this.config.networkConfig
28417
+ );
28418
+ const collateralPosition = positions.find(
28419
+ (p) => p.token.address.eq(collateral.address)
28420
+ );
28421
+ const debtPosition = positions.find(
28422
+ (p) => p.token.address.eq(debt.address)
28423
+ );
28386
28424
  if (!collateralPosition || !debtPosition) {
28387
28425
  throw new Error("Could not find current positions");
28388
28426
  }
@@ -28392,13 +28430,23 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28392
28430
  debt,
28393
28431
  maxBorrowableAPY
28394
28432
  );
28395
- logger.verbose(`VesuMultiplyAdapter: Max borrowable: ${maxBorrowable.toNumber()}`);
28396
- const debtCap = await this.vesuAdapter.getDebtCap(this.config.networkConfig);
28433
+ logger.verbose(
28434
+ `VesuMultiplyAdapter: Max borrowable: ${maxBorrowable.toNumber()}`
28435
+ );
28436
+ const debtCap = await this.vesuAdapter.getDebtCap(
28437
+ this.config.networkConfig
28438
+ );
28397
28439
  logger.verbose(`VesuMultiplyAdapter: Debt cap: ${debtCap.toNumber()}`);
28398
28440
  const actualMaxBorrowable = maxBorrowable.minimum(debtCap);
28399
- logger.verbose(`VesuMultiplyAdapter: Actual max borrowable: ${actualMaxBorrowable.toNumber()}`);
28400
- const maxLTV = await this.vesuAdapter.getLTVConfig(this.config.networkConfig);
28401
- const collateralPrice = await this.config.pricer.getPrice(collateral.symbol);
28441
+ logger.verbose(
28442
+ `VesuMultiplyAdapter: Actual max borrowable: ${actualMaxBorrowable.toNumber()}`
28443
+ );
28444
+ const maxLTV = await this.vesuAdapter.getLTVConfig(
28445
+ this.config.networkConfig
28446
+ );
28447
+ const collateralPrice = await this.config.pricer.getPrice(
28448
+ collateral.symbol
28449
+ );
28402
28450
  if (collateralPrice.price === 0) {
28403
28451
  throw new Error("Collateral price is 0");
28404
28452
  }
@@ -28416,14 +28464,25 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28416
28464
  );
28417
28465
  const maxDepositAmount = amount ? amount.minimum(maxCollateralFromDebt) : maxCollateralFromDebt;
28418
28466
  const usdValue = await this.getUSDValue(collateral, maxDepositAmount);
28419
- logger.verbose(`VesuMultiplyAdapter: Max deposit::USD value: ${usdValue}, amount: ${maxDepositAmount.toNumber()}`);
28420
- const apys = await Promise.all([this.getAPY({ asset: collateral, isDebt: false }), this.getAPY({ asset: debt, isDebt: true })]);
28421
- logger.verbose(`VesuMultiplyAdapter: Apys: ${apys[0].apy}, ${apys[1].apy}`);
28467
+ logger.verbose(
28468
+ `VesuMultiplyAdapter: Max deposit::USD value: ${usdValue}, amount: ${maxDepositAmount.toNumber()}`
28469
+ );
28470
+ const apys = await Promise.all([
28471
+ this.getAPY({ asset: collateral, isDebt: false }),
28472
+ this.getAPY({ asset: debt, isDebt: true })
28473
+ ]);
28474
+ logger.verbose(
28475
+ `VesuMultiplyAdapter: Apys: ${apys[0].apy}, ${apys[1].apy}`
28476
+ );
28422
28477
  const borrowAmountUSD = actualMaxBorrowable.multipliedBy(debtPrice.price);
28423
- logger.verbose(`VesuMultiplyAdapter: Borrow amount: ${actualMaxBorrowable.toNumber()}, borrow amount USD: ${borrowAmountUSD.toNumber()}`);
28478
+ logger.verbose(
28479
+ `VesuMultiplyAdapter: Borrow amount: ${actualMaxBorrowable.toNumber()}, borrow amount USD: ${borrowAmountUSD.toNumber()}`
28480
+ );
28424
28481
  const netCollateralUSD = usdValue + borrowAmountUSD.toNumber();
28425
28482
  const netAPY = (apys[0].apy * netCollateralUSD + apys[1].apy * borrowAmountUSD.toNumber()) / usdValue;
28426
- logger.verbose(`VesuMultiplyAdapter: Max deposit amount: ${maxDepositAmount.toNumber()}, netAPY: ${netAPY}`);
28483
+ logger.verbose(
28484
+ `VesuMultiplyAdapter: Max deposit amount: ${maxDepositAmount.toNumber()}, netAPY: ${netAPY}`
28485
+ );
28427
28486
  return {
28428
28487
  tokenInfo: collateral,
28429
28488
  amount: maxDepositAmount,
@@ -28436,7 +28495,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28436
28495
  protocol: this.protocol
28437
28496
  };
28438
28497
  } catch (error) {
28439
- logger.error(`VesuMultiplyAdapter: Error calculating max deposit:`, error);
28498
+ logger.error(
28499
+ `VesuMultiplyAdapter: Error calculating max deposit:`,
28500
+ error
28501
+ );
28440
28502
  throw error;
28441
28503
  }
28442
28504
  }
@@ -28446,9 +28508,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28446
28508
  try {
28447
28509
  this.vesuAdapter.networkConfig = this.config.networkConfig;
28448
28510
  this.vesuAdapter.pricer = this.config.pricer;
28449
- const positions = await this.vesuAdapter.getPositions(this.config.networkConfig);
28450
- const collateralPosition = positions.find((p) => p.token.address.eq(collateral.address));
28451
- const debtPosition = positions.find((p) => p.token.address.eq(this.config.debt.address));
28511
+ const positions = await this.vesuAdapter.getPositions(
28512
+ this.config.networkConfig
28513
+ );
28514
+ const collateralPosition = positions.find(
28515
+ (p) => p.token.address.eq(collateral.address)
28516
+ );
28517
+ const debtPosition = positions.find(
28518
+ (p) => p.token.address.eq(this.config.debt.address)
28519
+ );
28452
28520
  if (!collateralPosition || !debtPosition) {
28453
28521
  throw new Error("Could not find current positions");
28454
28522
  }
@@ -28458,11 +28526,20 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28458
28526
  const result = maxWithdrawable.greaterThan(0) ? maxWithdrawable : new Web3Number("0", collateral.decimals);
28459
28527
  const usdValue = await this.getUSDValue(collateral, result);
28460
28528
  const debtUSD = debtPosition.usdValue;
28461
- logger.verbose(`VesuMultiplyAdapter: Debt USD: ${debtUSD}, collateral USD: ${usdValue}`);
28462
- const apys = await Promise.all([this.getAPY({ asset: collateral, isDebt: false }), this.getAPY({ asset: debt, isDebt: true })]);
28463
- logger.verbose(`VesuMultiplyAdapter: Apys: ${apys[0].apy}, ${apys[1].apy}`);
28529
+ logger.verbose(
28530
+ `VesuMultiplyAdapter: Debt USD: ${debtUSD}, collateral USD: ${usdValue}`
28531
+ );
28532
+ const apys = await Promise.all([
28533
+ this.getAPY({ asset: collateral, isDebt: false }),
28534
+ this.getAPY({ asset: debt, isDebt: true })
28535
+ ]);
28536
+ logger.verbose(
28537
+ `VesuMultiplyAdapter: Apys: ${apys[0].apy}, ${apys[1].apy}`
28538
+ );
28464
28539
  const netAPY = usdValue - debtUSD > 0 ? (apys[0].apy * usdValue + apys[1].apy * debtUSD) / (usdValue - debtUSD) : 0;
28465
- logger.verbose(`VesuMultiplyAdapter: Max withdraw amount: ${result.toNumber()}, netAPY: ${netAPY}`);
28540
+ logger.verbose(
28541
+ `VesuMultiplyAdapter: Max withdraw amount: ${result.toNumber()}, netAPY: ${netAPY}`
28542
+ );
28466
28543
  return {
28467
28544
  tokenInfo: collateral,
28468
28545
  amount: result,
@@ -28475,14 +28552,19 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28475
28552
  protocol: this.protocol
28476
28553
  };
28477
28554
  } catch (error) {
28478
- logger.error(`VesuMultiplyAdapter: Error calculating max withdraw:`, error);
28555
+ logger.error(
28556
+ `VesuMultiplyAdapter: Error calculating max withdraw:`,
28557
+ error
28558
+ );
28479
28559
  throw error;
28480
28560
  }
28481
28561
  }
28482
28562
  _getDepositLeaf() {
28483
28563
  const collateral = this.config.collateral;
28484
28564
  const debt = this.config.debt;
28485
- const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(this.config.poolId);
28565
+ const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
28566
+ this.config.poolId
28567
+ );
28486
28568
  const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
28487
28569
  return [
28488
28570
  // Approval step for collateral
@@ -28546,7 +28628,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28546
28628
  ];
28547
28629
  }
28548
28630
  _getWithdrawLeaf() {
28549
- const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(this.config.poolId);
28631
+ const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
28632
+ this.config.poolId
28633
+ );
28550
28634
  const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
28551
28635
  const collateral = this.config.collateral;
28552
28636
  const debt = this.config.debt;
@@ -28603,33 +28687,51 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28603
28687
  const leafConfigs = this._getDepositLeaf();
28604
28688
  const leaves = leafConfigs.map((config) => {
28605
28689
  const { target, method, packedArguments, sanitizer, id } = config;
28606
- const leaf = this.constructSimpleLeafData({
28607
- id,
28608
- target,
28609
- method,
28610
- packedArguments
28611
- }, sanitizer);
28690
+ const leaf = this.constructSimpleLeafData(
28691
+ {
28692
+ id,
28693
+ target,
28694
+ method,
28695
+ packedArguments
28696
+ },
28697
+ sanitizer
28698
+ );
28612
28699
  return leaf;
28613
28700
  });
28614
- return { leaves, callConstructor: this.getDepositCall.bind(this) };
28701
+ return {
28702
+ leaves,
28703
+ callConstructor: this.getDepositCall.bind(
28704
+ this
28705
+ )
28706
+ };
28615
28707
  }
28616
28708
  getWithdrawAdapter() {
28617
28709
  const leafConfigs = this._getWithdrawLeaf();
28618
28710
  const leaves = leafConfigs.map((config) => {
28619
28711
  const { target, method, packedArguments, sanitizer, id } = config;
28620
- const leaf = this.constructSimpleLeafData({
28621
- id,
28622
- target,
28623
- method,
28624
- packedArguments
28625
- }, sanitizer);
28712
+ const leaf = this.constructSimpleLeafData(
28713
+ {
28714
+ id,
28715
+ target,
28716
+ method,
28717
+ packedArguments
28718
+ },
28719
+ sanitizer
28720
+ );
28626
28721
  return leaf;
28627
28722
  });
28628
- return { leaves, callConstructor: this.getWithdrawCall.bind(this) };
28723
+ return {
28724
+ leaves,
28725
+ callConstructor: this.getWithdrawCall.bind(
28726
+ this
28727
+ )
28728
+ };
28629
28729
  }
28630
28730
  async getDepositCall(params) {
28631
28731
  const collateral = this.config.collateral;
28632
- const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(this.config.poolId);
28732
+ const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
28733
+ this.config.poolId
28734
+ );
28633
28735
  const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
28634
28736
  const uint256MarginAmount = uint25612.bnToUint256(params.amount.toWei());
28635
28737
  return [
@@ -28701,7 +28803,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28701
28803
  ];
28702
28804
  }
28703
28805
  async getWithdrawCall(params) {
28704
- const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(this.config.poolId);
28806
+ const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
28807
+ this.config.poolId
28808
+ );
28705
28809
  const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
28706
28810
  return [
28707
28811
  // Switch delegation on
@@ -28756,7 +28860,11 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28756
28860
  ];
28757
28861
  }
28758
28862
  async getMultiplyCallCalldata(params, isDeposit) {
28759
- logger.verbose(`${_VesuMultiplyAdapter.name}::getMultiplyCallCalldata params: ${JSON.stringify(params)}, isDeposit: ${isDeposit}, collateral: ${this.config.collateral.symbol}, debt: ${this.config.debt.symbol}`);
28863
+ logger.verbose(
28864
+ `${_VesuMultiplyAdapter.name}::getMultiplyCallCalldata params: ${JSON.stringify(
28865
+ params
28866
+ )}, isDeposit: ${isDeposit}, collateral: ${this.config.collateral.symbol}, debt: ${this.config.debt.symbol}`
28867
+ );
28760
28868
  const { isV2 } = getVesuSingletonAddress(this.config.poolId);
28761
28869
  const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
28762
28870
  const multiplyContract = new Contract12({
@@ -28766,42 +28874,83 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28766
28874
  });
28767
28875
  let leverSwap = [];
28768
28876
  let leverSwapLimitAmount = Web3Number.fromWei(0, this.config.debt.decimals);
28769
- const existingPositions = await this.vesuAdapter.getPositions(this.config.networkConfig);
28770
- const collateralisation = await this.vesuAdapter.getCollateralization(this.config.networkConfig);
28877
+ const existingPositions = await this.vesuAdapter.getPositions(
28878
+ this.config.networkConfig
28879
+ );
28880
+ const collateralisation = await this.vesuAdapter.getCollateralization(
28881
+ this.config.networkConfig
28882
+ );
28771
28883
  const existingCollateralInfo = existingPositions[0];
28772
28884
  const existingDebtInfo = existingPositions[1];
28773
28885
  const isDexPriceRequired = existingDebtInfo.token.symbol !== "USDC";
28774
- logger.debug(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall existingCollateralInfo: ${JSON.stringify(existingCollateralInfo)},
28775
- existingDebtInfo: ${JSON.stringify(existingDebtInfo)}, collateralisation: ${JSON.stringify(collateralisation)}`);
28886
+ logger.debug(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall existingCollateralInfo: ${JSON.stringify(
28887
+ existingCollateralInfo
28888
+ )},
28889
+ existingDebtInfo: ${JSON.stringify(
28890
+ existingDebtInfo
28891
+ )}, collateralisation: ${JSON.stringify(collateralisation)}`);
28776
28892
  const collateralPrice = collateralisation[0].usdValue > 0 ? collateralisation[0].usdValue / existingCollateralInfo.amount.toNumber() : (await this.config.pricer.getPrice(this.config.collateral.symbol)).price;
28777
28893
  const debtPrice = collateralisation[1].usdValue > 0 ? collateralisation[1].usdValue / existingDebtInfo.amount.toNumber() : (await this.config.pricer.getPrice(this.config.debt.symbol)).price;
28778
- logger.debug(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall collateralPrice: ${collateralPrice}, debtPrice: ${debtPrice}`);
28779
- const legLTV = await this.vesuAdapter.getLTVConfig(this.config.networkConfig);
28780
- const ekuboQuoter = new EkuboQuoter(this.config.networkConfig, this.config.pricer);
28781
- const dexPrice = isDexPriceRequired ? await ekuboQuoter.getDexPrice(this.config.collateral, this.config.debt, this.config.quoteAmountToFetchPrice) : 1;
28782
- logger.verbose(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall dexPrice: ${dexPrice}, ltv: ${legLTV}`);
28894
+ logger.debug(
28895
+ `${_VesuMultiplyAdapter.name}::getVesuMultiplyCall collateralPrice: ${collateralPrice}, debtPrice: ${debtPrice}`
28896
+ );
28897
+ const legLTV = await this.vesuAdapter.getLTVConfig(
28898
+ this.config.networkConfig
28899
+ );
28900
+ const ekuboQuoter = new EkuboQuoter(
28901
+ this.config.networkConfig,
28902
+ this.config.pricer
28903
+ );
28904
+ const dexPrice = isDexPriceRequired ? await ekuboQuoter.getDexPrice(
28905
+ this.config.collateral,
28906
+ this.config.debt,
28907
+ this.config.quoteAmountToFetchPrice
28908
+ ) : 1;
28909
+ logger.verbose(
28910
+ `${_VesuMultiplyAdapter.name}::getVesuMultiplyCall dexPrice: ${dexPrice}, ltv: ${legLTV}`
28911
+ );
28783
28912
  const addedCollateral = params.amount.multipliedBy(isDeposit ? 1 : -1);
28784
- logger.verbose(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall addedCollateral: ${addedCollateral}`);
28913
+ logger.verbose(
28914
+ `${_VesuMultiplyAdapter.name}::getVesuMultiplyCall addedCollateral: ${addedCollateral}`
28915
+ );
28785
28916
  const numeratorPart1 = existingCollateralInfo.amount.plus(addedCollateral).multipliedBy(collateralPrice).multipliedBy(legLTV);
28786
- logger.verbose(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart1: ${numeratorPart1}`);
28917
+ logger.verbose(
28918
+ `${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart1: ${numeratorPart1}`
28919
+ );
28787
28920
  const numeratorPart2 = existingDebtInfo.amount.multipliedBy(debtPrice).multipliedBy(this.config.targetHealthFactor);
28788
- logger.verbose(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart2: ${numeratorPart2}`);
28921
+ logger.verbose(
28922
+ `${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart2: ${numeratorPart2}`
28923
+ );
28789
28924
  const denominatorPart = this.config.targetHealthFactor - legLTV / dexPrice;
28790
- logger.verbose(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall denominatorPart: ${denominatorPart}`);
28925
+ logger.verbose(
28926
+ `${_VesuMultiplyAdapter.name}::getVesuMultiplyCall denominatorPart: ${denominatorPart}`
28927
+ );
28791
28928
  const x_debt_usd = numeratorPart1.minus(numeratorPart2).dividedBy(denominatorPart);
28792
- logger.verbose(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall x_debt_usd: ${x_debt_usd}`);
28793
- logger.debug(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart1: ${numeratorPart1}, numeratorPart2: ${numeratorPart2}, denominatorPart: ${denominatorPart}`);
28794
- let debtAmount = new Web3Number(x_debt_usd.dividedBy(debtPrice).toFixed(this.config.debt.decimals), this.config.debt.decimals);
28929
+ logger.verbose(
28930
+ `${_VesuMultiplyAdapter.name}::getVesuMultiplyCall x_debt_usd: ${x_debt_usd}`
28931
+ );
28932
+ logger.debug(
28933
+ `${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart1: ${numeratorPart1}, numeratorPart2: ${numeratorPart2}, denominatorPart: ${denominatorPart}`
28934
+ );
28935
+ let debtAmount = new Web3Number(
28936
+ x_debt_usd.dividedBy(debtPrice).toFixed(this.config.debt.decimals),
28937
+ this.config.debt.decimals
28938
+ );
28795
28939
  const marginAmount = addedCollateral;
28796
28940
  const collateralToken = this.config.collateral;
28797
28941
  const debtToken = this.config.debt;
28798
- const debtAmountInCollateralUnits = new Web3Number(debtAmount.multipliedBy(debtPrice).dividedBy(collateralPrice).multipliedBy(10 ** collateralToken.decimals).toFixed(0), collateralToken.decimals);
28942
+ const debtAmountInCollateralUnits = new Web3Number(
28943
+ debtAmount.multipliedBy(debtPrice).dividedBy(collateralPrice).multipliedBy(10 ** collateralToken.decimals).toFixed(0),
28944
+ collateralToken.decimals
28945
+ );
28799
28946
  const isIncrease = debtAmount.greaterThanOrEqualTo(0);
28800
28947
  if (isIncrease && debtAmount.lessThan(0)) {
28801
28948
  } else if (!isIncrease && debtAmount.greaterThan(0)) {
28802
28949
  debtAmount = Web3Number.fromWei(0, this.config.debt.decimals);
28803
28950
  }
28804
- logger.verbose(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall debtAmount: ${debtAmount}, marginAmount: ${marginAmount}`);
28951
+ logger.verbose(
28952
+ `${_VesuMultiplyAdapter.name}::getVesuMultiplyCall debtAmount: ${debtAmount}, marginAmount: ${marginAmount}`
28953
+ );
28805
28954
  if (!debtAmount.isZero()) {
28806
28955
  try {
28807
28956
  const swapQuote = await ekuboQuoter.getQuote(
@@ -28811,26 +28960,49 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28811
28960
  // negative for exact amount out
28812
28961
  );
28813
28962
  if (swapQuote.price_impact < 0.01) {
28814
- leverSwap = ekuboQuoter.getVesuMultiplyQuote(swapQuote, debtToken, collateralToken);
28963
+ leverSwap = debtAmount.isNegative() ? ekuboQuoter.getVesuMultiplyQuote(
28964
+ swapQuote,
28965
+ collateralToken,
28966
+ debtToken
28967
+ ) : ekuboQuoter.getVesuMultiplyQuote(
28968
+ swapQuote,
28969
+ debtToken,
28970
+ collateralToken
28971
+ );
28815
28972
  const MAX_SLIPPAGE = 2e-3;
28816
28973
  if (debtAmount.greaterThan(0)) {
28817
28974
  leverSwapLimitAmount = debtAmount.multipliedBy(1 + MAX_SLIPPAGE);
28818
28975
  } else if (debtAmount.lessThan(0)) {
28819
28976
  leverSwapLimitAmount = debtAmount.abs().multipliedBy(1 - MAX_SLIPPAGE);
28820
28977
  } else {
28821
- leverSwapLimitAmount = Web3Number.fromWei(0, this.config.debt.decimals);
28978
+ leverSwapLimitAmount = Web3Number.fromWei(
28979
+ 0,
28980
+ this.config.debt.decimals
28981
+ );
28822
28982
  }
28823
28983
  await new Promise((resolve) => setTimeout(resolve, 1e4));
28824
28984
  } else {
28825
- throw new Error(`VesuMultiplyAdapter: Price impact too high (${swapQuote.price_impact}), skipping swap`);
28985
+ throw new Error(
28986
+ `VesuMultiplyAdapter: Price impact too high (${swapQuote.price_impact}), skipping swap`
28987
+ );
28826
28988
  }
28827
28989
  } catch (error) {
28828
- throw new Error(`VesuMultiplyAdapter: Failed to get swap quote: ${error}`);
28990
+ throw new Error(
28991
+ `VesuMultiplyAdapter: Failed to get swap quote: ${error}`
28992
+ );
28829
28993
  }
28830
28994
  }
28831
- const multiplyParams = await this.getLeverParams(isIncrease, params, leverSwap, leverSwapLimitAmount);
28995
+ const multiplyParams = await this.getLeverParams(
28996
+ isIncrease,
28997
+ params,
28998
+ leverSwap,
28999
+ leverSwapLimitAmount
29000
+ );
28832
29001
  const call = multiplyContract.populate("modify_lever", {
28833
- modify_lever_params: this.formatMultiplyParams(isIncrease, multiplyParams)
29002
+ modify_lever_params: this.formatMultiplyParams(
29003
+ isIncrease,
29004
+ multiplyParams
29005
+ )
28834
29006
  });
28835
29007
  return call.calldata;
28836
29008
  }
@@ -28844,7 +29016,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28844
29016
  add_margin: params.amount,
28845
29017
  // multiplied by collateral decimals in format
28846
29018
  margin_swap: [],
28847
- margin_swap_limit_amount: Web3Number.fromWei(0, this.config.collateral.decimals),
29019
+ margin_swap_limit_amount: Web3Number.fromWei(
29020
+ 0,
29021
+ this.config.collateral.decimals
29022
+ ),
28848
29023
  lever_swap: leverSwap,
28849
29024
  lever_swap_limit_amount: leverSwapLimitAmount
28850
29025
  } : {
@@ -28858,7 +29033,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28858
29033
  lever_swap_limit_amount: leverSwapLimitAmount,
28859
29034
  lever_swap_weights: [],
28860
29035
  withdraw_swap: [],
28861
- withdraw_swap_limit_amount: Web3Number.fromWei(0, this.config.collateral.decimals),
29036
+ withdraw_swap_limit_amount: Web3Number.fromWei(
29037
+ 0,
29038
+ this.config.collateral.decimals
29039
+ ),
28862
29040
  withdraw_swap_weights: [],
28863
29041
  close_position: false
28864
29042
  };
@@ -28874,12 +29052,16 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28874
29052
  });
28875
29053
  let leverSwap = [];
28876
29054
  let leverSwapLimitAmount = Web3Number.fromWei(0, this.config.debt.decimals);
28877
- const existingPositions = await this.vesuAdapter.getPositions(this.config.networkConfig);
29055
+ const existingPositions = await this.vesuAdapter.getPositions(
29056
+ this.config.networkConfig
29057
+ );
28878
29058
  const existingCollateralInfo = existingPositions[0];
28879
29059
  const existingDebtInfo = existingPositions[1];
28880
29060
  const collateralToken = this.config.collateral;
28881
29061
  const debtToken = this.config.debt;
28882
- const collateralPrice = await this.config.pricer.getPrice(collateralToken.symbol);
29062
+ const collateralPrice = await this.config.pricer.getPrice(
29063
+ collateralToken.symbol
29064
+ );
28883
29065
  const debtPrice = await this.config.pricer.getPrice(debtToken.symbol);
28884
29066
  const { deltadebtAmountUnits: debtAmountToRepay } = calculateDebtReductionAmountForWithdrawal(
28885
29067
  existingDebtInfo.amount,
@@ -28893,8 +29075,14 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28893
29075
  if (!debtAmountToRepay) {
28894
29076
  throw new Error("error calculating debt amount to repay");
28895
29077
  }
28896
- const ekuboQuoter = new EkuboQuoter(this.config.networkConfig, this.config.pricer);
28897
- const debtInDebtUnits = new Web3Number(debtAmountToRepay, debtToken.decimals).dividedBy(debtPrice.price).multipliedBy(10 ** debtToken.decimals);
29078
+ const ekuboQuoter = new EkuboQuoter(
29079
+ this.config.networkConfig,
29080
+ this.config.pricer
29081
+ );
29082
+ const debtInDebtUnits = new Web3Number(
29083
+ debtAmountToRepay,
29084
+ debtToken.decimals
29085
+ ).dividedBy(debtPrice.price).multipliedBy(10 ** debtToken.decimals);
28898
29086
  const swapQuote = await ekuboQuoter.getQuote(
28899
29087
  debtToken.address.address,
28900
29088
  collateralToken.address.address,
@@ -28902,12 +29090,23 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28902
29090
  );
28903
29091
  const MAX_SLIPPAGE = 2e-3;
28904
29092
  if (swapQuote.price_impact < 25e-4) {
28905
- leverSwap = ekuboQuoter.getVesuMultiplyQuote(swapQuote, collateralToken, debtToken);
29093
+ leverSwap = ekuboQuoter.getVesuMultiplyQuote(
29094
+ swapQuote,
29095
+ collateralToken,
29096
+ debtToken
29097
+ );
28906
29098
  } else {
28907
- logger.error(`VesuMultiplyAdapter: Price impact too high (${swapQuote.price_impact}), skipping swap`);
29099
+ logger.error(
29100
+ `VesuMultiplyAdapter: Price impact too high (${swapQuote.price_impact}), skipping swap`
29101
+ );
28908
29102
  }
28909
29103
  leverSwapLimitAmount = new Web3Number(debtAmountToRepay, debtToken.decimals).abs().multipliedBy(1 + MAX_SLIPPAGE);
28910
- const multiplyParams = await this.getLeverParams(false, params, leverSwap, leverSwapLimitAmount);
29104
+ const multiplyParams = await this.getLeverParams(
29105
+ false,
29106
+ params,
29107
+ leverSwap,
29108
+ leverSwapLimitAmount
29109
+ );
28911
29110
  const call = multiplyContract.populate("modify_lever", {
28912
29111
  modify_lever_params: this.formatMultiplyParams(false, multiplyParams)
28913
29112
  });
@@ -28917,100 +29116,132 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
28917
29116
  if (isIncrease) {
28918
29117
  const _params2 = params;
28919
29118
  return {
28920
- action: new CairoCustomEnum3({ IncreaseLever: {
28921
- pool_id: _params2.pool_id.toBigInt(),
28922
- collateral_asset: _params2.collateral_asset.toBigInt(),
28923
- debt_asset: _params2.debt_asset.toBigInt(),
28924
- user: _params2.user.toBigInt(),
28925
- add_margin: BigInt(_params2.add_margin.toWei()),
28926
- margin_swap: _params2.margin_swap.map((swap) => ({
29119
+ action: new CairoCustomEnum3({
29120
+ IncreaseLever: {
29121
+ pool_id: _params2.pool_id.toBigInt(),
29122
+ collateral_asset: _params2.collateral_asset.toBigInt(),
29123
+ debt_asset: _params2.debt_asset.toBigInt(),
29124
+ user: _params2.user.toBigInt(),
29125
+ add_margin: BigInt(_params2.add_margin.toWei()),
29126
+ margin_swap: _params2.margin_swap.map((swap) => ({
29127
+ route: swap.route.map((route) => ({
29128
+ pool_key: {
29129
+ token0: route.pool_key.token0.toBigInt(),
29130
+ token1: route.pool_key.token1.toBigInt(),
29131
+ fee: route.pool_key.fee,
29132
+ tick_spacing: route.pool_key.tick_spacing,
29133
+ extension: BigInt(
29134
+ num9.hexToDecimalString(route.pool_key.extension)
29135
+ )
29136
+ },
29137
+ sqrt_ratio_limit: uint25612.bnToUint256(
29138
+ route.sqrt_ratio_limit.toWei()
29139
+ ),
29140
+ skip_ahead: BigInt(100)
29141
+ })),
29142
+ token_amount: {
29143
+ token: swap.token_amount.token.toBigInt(),
29144
+ amount: swap.token_amount.amount.toI129()
29145
+ }
29146
+ })),
29147
+ margin_swap_limit_amount: BigInt(
29148
+ _params2.margin_swap_limit_amount.toWei()
29149
+ ),
29150
+ lever_swap: _params2.lever_swap.map((swap) => ({
29151
+ route: swap.route.map((route) => ({
29152
+ pool_key: {
29153
+ token0: route.pool_key.token0.toBigInt(),
29154
+ token1: route.pool_key.token1.toBigInt(),
29155
+ fee: route.pool_key.fee,
29156
+ tick_spacing: route.pool_key.tick_spacing,
29157
+ extension: BigInt(
29158
+ num9.hexToDecimalString(route.pool_key.extension)
29159
+ )
29160
+ },
29161
+ sqrt_ratio_limit: uint25612.bnToUint256(
29162
+ route.sqrt_ratio_limit.toWei()
29163
+ ),
29164
+ skip_ahead: BigInt(0)
29165
+ })),
29166
+ token_amount: {
29167
+ token: swap.token_amount.token.toBigInt(),
29168
+ amount: swap.token_amount.amount.toI129()
29169
+ }
29170
+ })),
29171
+ lever_swap_limit_amount: BigInt(
29172
+ _params2.lever_swap_limit_amount.toWei()
29173
+ )
29174
+ }
29175
+ })
29176
+ };
29177
+ }
29178
+ const _params = params;
29179
+ return {
29180
+ action: new CairoCustomEnum3({
29181
+ DecreaseLever: {
29182
+ pool_id: _params.pool_id.toBigInt(),
29183
+ collateral_asset: _params.collateral_asset.toBigInt(),
29184
+ debt_asset: _params.debt_asset.toBigInt(),
29185
+ user: _params.user.toBigInt(),
29186
+ sub_margin: BigInt(_params.sub_margin.toWei()),
29187
+ recipient: _params.recipient.toBigInt(),
29188
+ lever_swap: _params.lever_swap.map((swap) => ({
28927
29189
  route: swap.route.map((route) => ({
28928
29190
  pool_key: {
28929
29191
  token0: route.pool_key.token0.toBigInt(),
28930
29192
  token1: route.pool_key.token1.toBigInt(),
28931
29193
  fee: route.pool_key.fee,
28932
29194
  tick_spacing: route.pool_key.tick_spacing,
28933
- extension: BigInt(num9.hexToDecimalString(route.pool_key.extension))
29195
+ extension: ContractAddr.from(
29196
+ route.pool_key.extension
29197
+ ).toBigInt()
28934
29198
  },
28935
- sqrt_ratio_limit: uint25612.bnToUint256(route.sqrt_ratio_limit.toWei()),
28936
- skip_ahead: BigInt(100)
29199
+ sqrt_ratio_limit: uint25612.bnToUint256(
29200
+ route.sqrt_ratio_limit.toWei()
29201
+ ),
29202
+ skip_ahead: BigInt(route.skip_ahead.toWei())
28937
29203
  })),
28938
29204
  token_amount: {
28939
29205
  token: swap.token_amount.token.toBigInt(),
28940
29206
  amount: swap.token_amount.amount.toI129()
28941
29207
  }
28942
29208
  })),
28943
- margin_swap_limit_amount: BigInt(_params2.margin_swap_limit_amount.toWei()),
28944
- lever_swap: _params2.lever_swap.map((swap) => ({
29209
+ lever_swap_limit_amount: BigInt(
29210
+ _params.lever_swap_limit_amount.toWei()
29211
+ ),
29212
+ lever_swap_weights: _params.lever_swap_weights.map(
29213
+ (weight) => BigInt(weight.toWei())
29214
+ ),
29215
+ withdraw_swap: _params.withdraw_swap.map((swap) => ({
28945
29216
  route: swap.route.map((route) => ({
28946
29217
  pool_key: {
28947
29218
  token0: route.pool_key.token0.toBigInt(),
28948
29219
  token1: route.pool_key.token1.toBigInt(),
28949
29220
  fee: route.pool_key.fee,
28950
29221
  tick_spacing: route.pool_key.tick_spacing,
28951
- extension: BigInt(num9.hexToDecimalString(route.pool_key.extension))
29222
+ extension: ContractAddr.from(
29223
+ route.pool_key.extension
29224
+ ).toBigInt()
28952
29225
  },
28953
- sqrt_ratio_limit: uint25612.bnToUint256(route.sqrt_ratio_limit.toWei()),
28954
- skip_ahead: BigInt(0)
29226
+ sqrt_ratio_limit: uint25612.bnToUint256(
29227
+ route.sqrt_ratio_limit.toWei()
29228
+ ),
29229
+ skip_ahead: BigInt(route.skip_ahead.toWei())
28955
29230
  })),
28956
29231
  token_amount: {
28957
29232
  token: swap.token_amount.token.toBigInt(),
28958
29233
  amount: swap.token_amount.amount.toI129()
28959
29234
  }
28960
29235
  })),
28961
- lever_swap_limit_amount: BigInt(_params2.lever_swap_limit_amount.toWei())
28962
- } })
28963
- };
28964
- }
28965
- const _params = params;
28966
- return {
28967
- action: new CairoCustomEnum3({ DecreaseLever: {
28968
- pool_id: _params.pool_id.toBigInt(),
28969
- collateral_asset: _params.collateral_asset.toBigInt(),
28970
- debt_asset: _params.debt_asset.toBigInt(),
28971
- user: _params.user.toBigInt(),
28972
- sub_margin: BigInt(_params.sub_margin.toWei()),
28973
- recipient: _params.recipient.toBigInt(),
28974
- lever_swap: _params.lever_swap.map((swap) => ({
28975
- route: swap.route.map((route) => ({
28976
- pool_key: {
28977
- token0: route.pool_key.token0.toBigInt(),
28978
- token1: route.pool_key.token1.toBigInt(),
28979
- fee: route.pool_key.fee,
28980
- tick_spacing: route.pool_key.tick_spacing,
28981
- extension: ContractAddr.from(route.pool_key.extension).toBigInt()
28982
- },
28983
- sqrt_ratio_limit: uint25612.bnToUint256(route.sqrt_ratio_limit.toWei()),
28984
- skip_ahead: BigInt(route.skip_ahead.toWei())
28985
- })),
28986
- token_amount: {
28987
- token: swap.token_amount.token.toBigInt(),
28988
- amount: swap.token_amount.amount.toI129()
28989
- }
28990
- })),
28991
- lever_swap_limit_amount: BigInt(_params.lever_swap_limit_amount.toWei()),
28992
- lever_swap_weights: _params.lever_swap_weights.map((weight) => BigInt(weight.toWei())),
28993
- withdraw_swap: _params.withdraw_swap.map((swap) => ({
28994
- route: swap.route.map((route) => ({
28995
- pool_key: {
28996
- token0: route.pool_key.token0.toBigInt(),
28997
- token1: route.pool_key.token1.toBigInt(),
28998
- fee: route.pool_key.fee,
28999
- tick_spacing: route.pool_key.tick_spacing,
29000
- extension: ContractAddr.from(route.pool_key.extension).toBigInt()
29001
- },
29002
- sqrt_ratio_limit: uint25612.bnToUint256(route.sqrt_ratio_limit.toWei()),
29003
- skip_ahead: BigInt(route.skip_ahead.toWei())
29004
- })),
29005
- token_amount: {
29006
- token: swap.token_amount.token.toBigInt(),
29007
- amount: swap.token_amount.amount.toI129()
29008
- }
29009
- })),
29010
- withdraw_swap_limit_amount: BigInt(_params.withdraw_swap_limit_amount.toWei()),
29011
- withdraw_swap_weights: _params.withdraw_swap_weights.map((weight) => BigInt(weight.toWei())),
29012
- close_position: _params.close_position
29013
- } })
29236
+ withdraw_swap_limit_amount: BigInt(
29237
+ _params.withdraw_swap_limit_amount.toWei()
29238
+ ),
29239
+ withdraw_swap_weights: _params.withdraw_swap_weights.map(
29240
+ (weight) => BigInt(weight.toWei())
29241
+ ),
29242
+ close_position: _params.close_position
29243
+ }
29244
+ })
29014
29245
  };
29015
29246
  }
29016
29247
  async getHealthFactor() {
@@ -29019,11 +29250,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
29019
29250
  }
29020
29251
  async getNetAPY() {
29021
29252
  const positions = await this.getPositions();
29022
- logger.verbose(`${this.name}::getNetAPY: positions: ${JSON.stringify(positions)}`);
29253
+ logger.verbose(
29254
+ `${this.name}::getNetAPY: positions: ${JSON.stringify(positions)}`
29255
+ );
29023
29256
  const allZero = positions.every((p) => p.usdValue === 0);
29024
29257
  if (allZero) {
29025
29258
  const collateralUSD = 1e3;
29026
- const maxLTV = await this.vesuAdapter.getLTVConfig(this.config.networkConfig);
29259
+ const maxLTV = await this.vesuAdapter.getLTVConfig(
29260
+ this.config.networkConfig
29261
+ );
29027
29262
  const targetHF = this.config.targetHealthFactor;
29028
29263
  const maxDebt = HealthFactorMath.getMaxDebtAmountOnLooping(
29029
29264
  new Web3Number(collateralUSD, this.config.collateral.decimals),
@@ -29749,6 +29984,7 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
29749
29984
  logger.error("error initializing client");
29750
29985
  return null;
29751
29986
  }
29987
+ await new Promise((resolve) => setTimeout(resolve, 5e3));
29752
29988
  const orderhistory = await this.getOrderHistory(marketName);
29753
29989
  if (!orderhistory || orderhistory.length === 0) {
29754
29990
  logger.error(`error getting order: ${orderId}`);
@@ -34129,7 +34365,7 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
34129
34365
  const withdrawalFromExtended = await extendedAdapter.withdrawFromExtended(params.amount);
34130
34366
  if (withdrawalFromExtended) {
34131
34367
  const extendedHoldings2 = await extendedAdapter.getExtendedDepositAmount();
34132
- logger.info(`extendedHoldings after withdrawal ${extendedHoldings2}`);
34368
+ logger.info(`extendedHoldings after withdrawal ${extendedHoldings2?.availableForWithdrawal}`);
34133
34369
  await new Promise((resolve) => setTimeout(resolve, 1e4));
34134
34370
  const calls = await this.moveAssetsToVaultAllocator(params.amount, extendedAdapter);
34135
34371
  if (calls.length > 0) {