@strkfarm/sdk 2.0.0-dev.16 → 2.0.0-dev.18

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.
@@ -28659,6 +28659,7 @@ ${r2}}` : "}", l2;
28659
28659
  BaseStrategy: () => BaseStrategy,
28660
28660
  CommonAdapter: () => CommonAdapter,
28661
28661
  ContractAddr: () => ContractAddr,
28662
+ CycleType: () => CycleType,
28662
28663
  ERC20: () => ERC20,
28663
28664
  EXTENDED_CONTRACT: () => EXTENDED_CONTRACT,
28664
28665
  EXTENDED_SANITIZER: () => EXTENDED_SANITIZER,
@@ -92386,9 +92387,7 @@ spurious results.`);
92386
92387
  var MAX_LTV_BTC_USDC = 0.8428;
92387
92388
  var MAX_LIQUIDATION_RATIO = 0.86;
92388
92389
  var VAULT_ID_EXTENDED = process.env.VAULT_ID_EXTENDED ?? 220774;
92389
- var WALLET_ADDRESS = process.env.WALLET_ADDRESS ?? "0x07b84bb6E87588BdAde0bfe6173A615b3C220F9C3803456aE183C50EA1d15Ba1";
92390
- var TESTNET_WALLET_ADDRESS = process.env.TESTNET_WALLET_ADDRESS ?? "0x07b84bb6E87588BdAde0bfe6173A615b3C220F9C3803456aE183C50EA1d15Ba1";
92391
- var TEST_WALLET_2 = process.env.TEST_WALLET_2 ?? "0x004C1bdC61DAc7947F3C93d0163d660012E2aB0521567f7155fcf502848791A7";
92390
+ var WALLET_ADDRESS = process.env.WALLET_ADDRESS ?? "0x007E24592287427aaE9d291770B17d582E8A45f3aE54228F998793Ec769B7D13";
92392
92391
  var STRK_API_TEST_RPC = process.env.STRK_API_TEST_RPC ?? "https://sepolia.starknet.a5a.ch";
92393
92392
  var STRK_API_RPC = process.env.STRK_API_RPC ?? "https://mainnet.starknet.a5a.ch";
92394
92393
  var MAX_RETRIES = Number(process.env.MAX_RETRIES ?? 3);
@@ -93704,7 +93703,7 @@ spurious results.`);
93704
93703
  const amount = holdings.equity;
93705
93704
  return Promise.resolve({
93706
93705
  amount: new Web3Number(amount, 0),
93707
- remarks: `${holdings.availableForWithdrawal} ${holdings.equity}`
93706
+ remarks: `Extended Equity`
93708
93707
  });
93709
93708
  }
93710
93709
  async maxDeposit(amount) {
@@ -94556,7 +94555,7 @@ spurious results.`);
94556
94555
  return Promise.resolve({ apy: 0, type: "base" /* BASE */ });
94557
94556
  }
94558
94557
  async getPosition(supportedPosition) {
94559
- return Promise.resolve({ amount: new Web3Number(0, 0), remarks: "" });
94558
+ return Promise.resolve({ amount: new Web3Number(0, 0), remarks: "Avnu Positions" });
94560
94559
  }
94561
94560
  async maxDeposit(amount) {
94562
94561
  return Promise.resolve({
@@ -98290,6 +98289,16 @@ spurious results.`);
98290
98289
  getStrategySettings("mRe7YIELD", "mRe7YIELD", hypermRe7YIELD, false, false)
98291
98290
  ];
98292
98291
 
98292
+ // src/strategies/vesu-extended-strategy/types/transaction-metadata.ts
98293
+ var CycleType = /* @__PURE__ */ ((CycleType2) => {
98294
+ CycleType2["INVESTMENT"] = "INVESTMENT";
98295
+ CycleType2["REBALANCE_PRICE_DROP"] = "REBALANCE_PRICE_DROP";
98296
+ CycleType2["REBALANCE_PRICE_RISE"] = "REBALANCE_PRICE_RISE";
98297
+ CycleType2["WITHDRAWAL"] = "WITHDRAWAL";
98298
+ CycleType2["DELTA_NEUTRAL_ADJUSTMENT"] = "DELTA_NEUTRAL_ADJUSTMENT";
98299
+ return CycleType2;
98300
+ })(CycleType || {});
98301
+
98293
98302
  // src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx
98294
98303
  var import_jsx_runtime5 = __toESM(require_jsx_runtime());
98295
98304
  var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy extends SVKStrategy {
@@ -98671,7 +98680,8 @@ spurious results.`);
98671
98680
  {
98672
98681
  to: Protocols.VAULT.name,
98673
98682
  from: Protocols.EXTENDED.name,
98674
- amount: extendedAmount.abs()
98683
+ amount: extendedAmount.abs(),
98684
+ cycleType: "INVESTMENT" /* INVESTMENT */
98675
98685
  },
98676
98686
  extendedAdapter,
98677
98687
  vesuAdapter
@@ -98686,11 +98696,11 @@ spurious results.`);
98686
98696
  }
98687
98697
  });
98688
98698
  } else {
98689
- return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: extendedAmount.abs() }, "NONE")];
98699
+ return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: extendedAmount.abs() }, "NONE", "INVESTMENT" /* INVESTMENT */)];
98690
98700
  }
98691
98701
  } catch (err2) {
98692
98702
  logger2.error(`Failed moving assets to vault: ${err2}`);
98693
- return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: extendedAmount.abs() }, "NONE")];
98703
+ return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: extendedAmount.abs() }, "NONE", "INVESTMENT" /* INVESTMENT */)];
98694
98704
  }
98695
98705
  }
98696
98706
  if (vesuAmount.isNegative() && vesuAmount.abs().greaterThan(vesuAdapter.minimumVesuMovementAmount)) {
@@ -98699,13 +98709,14 @@ spurious results.`);
98699
98709
  {
98700
98710
  to: Protocols.EXTENDED.name,
98701
98711
  from: Protocols.VESU.name,
98702
- amount: vesuAmount.abs()
98712
+ amount: vesuAmount.abs(),
98713
+ cycleType: "INVESTMENT" /* INVESTMENT */
98703
98714
  },
98704
98715
  extendedAdapter,
98705
98716
  vesuAdapter
98706
98717
  );
98707
98718
  if (!vesuStatus) {
98708
- return [this.createTransactionResult([], false, { from: Protocols.VESU.name, to: Protocols.EXTENDED.name, amount: vesuAmount.abs() }, "NONE")];
98719
+ return [this.createTransactionResult([], false, { from: Protocols.VESU.name, to: Protocols.EXTENDED.name, amount: vesuAmount.abs() }, "NONE", "INVESTMENT" /* INVESTMENT */)];
98709
98720
  }
98710
98721
  transactionResults.push({
98711
98722
  status: vesuStatus,
@@ -98717,7 +98728,7 @@ spurious results.`);
98717
98728
  });
98718
98729
  } catch (err2) {
98719
98730
  logger2.error(`Failed moving assets to extended via vault allocator: ${err2}`);
98720
- return [this.createTransactionResult([], false, { from: Protocols.VESU.name, to: Protocols.EXTENDED.name, amount: vesuAmount.abs() }, "NONE")];
98731
+ return [this.createTransactionResult([], false, { from: Protocols.VESU.name, to: Protocols.EXTENDED.name, amount: vesuAmount.abs() }, "NONE", "INVESTMENT" /* INVESTMENT */)];
98721
98732
  }
98722
98733
  }
98723
98734
  if (extendedAmountDifferenceAbs.greaterThan(extendedAdapter.minimumExtendedMovementAmount)) {
@@ -98727,7 +98738,8 @@ spurious results.`);
98727
98738
  {
98728
98739
  to: Protocols.EXTENDED.name,
98729
98740
  from: Protocols.VAULT.name,
98730
- amount: extendedAmountDifference
98741
+ amount: extendedAmountDifference,
98742
+ cycleType: "INVESTMENT" /* INVESTMENT */
98731
98743
  },
98732
98744
  extendedAdapter,
98733
98745
  vesuAdapter
@@ -98740,11 +98752,11 @@ spurious results.`);
98740
98752
  });
98741
98753
  } else {
98742
98754
  logger2.error(`Failed to move assets to extended - operation returned false status`);
98743
- return [this.createTransactionResult([], false, { from: Protocols.VAULT.name, to: Protocols.EXTENDED.name, amount: extendedAmountDifference }, "NONE")];
98755
+ return [this.createTransactionResult([], false, { from: Protocols.VAULT.name, to: Protocols.EXTENDED.name, amount: extendedAmountDifference }, "NONE", "INVESTMENT" /* INVESTMENT */)];
98744
98756
  }
98745
98757
  } catch (err2) {
98746
98758
  logger2.error(`Failed moving assets to extended: ${err2}`);
98747
- return [this.createTransactionResult([], false, { from: Protocols.VAULT.name, to: Protocols.EXTENDED.name, amount: extendedAmountDifference }, "NONE")];
98759
+ return [this.createTransactionResult([], false, { from: Protocols.VAULT.name, to: Protocols.EXTENDED.name, amount: extendedAmountDifference }, "NONE", "INVESTMENT" /* INVESTMENT */)];
98748
98760
  }
98749
98761
  } else if (extendedAmountDifference.lessThan(0)) {
98750
98762
  try {
@@ -98752,7 +98764,8 @@ spurious results.`);
98752
98764
  {
98753
98765
  to: Protocols.VAULT.name,
98754
98766
  from: Protocols.EXTENDED.name,
98755
- amount: extendedAmountDifferenceAbs
98767
+ amount: extendedAmountDifferenceAbs,
98768
+ cycleType: "INVESTMENT" /* INVESTMENT */
98756
98769
  },
98757
98770
  extendedAdapter,
98758
98771
  vesuAdapter
@@ -98768,11 +98781,11 @@ spurious results.`);
98768
98781
  });
98769
98782
  } else {
98770
98783
  logger2.error(`Failed to withdraw from extended - operation returned false status`);
98771
- return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: extendedAmountDifferenceAbs }, "NONE")];
98784
+ return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: extendedAmountDifferenceAbs }, "NONE", "INVESTMENT" /* INVESTMENT */)];
98772
98785
  }
98773
98786
  } catch (err2) {
98774
98787
  logger2.error(`Failed moving assets from extended to vault: ${err2}`);
98775
- return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: extendedAmountDifferenceAbs }, "NONE")];
98788
+ return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: extendedAmountDifferenceAbs }, "NONE", "INVESTMENT" /* INVESTMENT */)];
98776
98789
  }
98777
98790
  }
98778
98791
  }
@@ -98787,14 +98800,15 @@ spurious results.`);
98787
98800
  {
98788
98801
  to: Protocols.VAULT.name,
98789
98802
  from: Protocols.EXTENDED.name,
98790
- amount: vesuAmountDifference
98803
+ amount: vesuAmountDifference,
98804
+ cycleType: "INVESTMENT" /* INVESTMENT */
98791
98805
  },
98792
98806
  extendedAdapter,
98793
98807
  vesuAdapter
98794
98808
  );
98795
98809
  if (!vesuStatus) {
98796
98810
  logger2.error(`Failed to move assets to vesu - operation returned false status`);
98797
- return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: vesuAmountDifference }, "NONE")];
98811
+ return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: vesuAmountDifference }, "NONE", "INVESTMENT" /* INVESTMENT */)];
98798
98812
  }
98799
98813
  transactionResults.push({
98800
98814
  status: vesuStatus,
@@ -98806,20 +98820,20 @@ spurious results.`);
98806
98820
  });
98807
98821
  } catch (err2) {
98808
98822
  logger2.error(`Failed moving assets to vault: ${err2}`);
98809
- return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: vesuAmountDifference }, "NONE")];
98823
+ return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: vesuAmountDifference }, "NONE", "INVESTMENT" /* INVESTMENT */)];
98810
98824
  }
98811
98825
  }
98812
98826
  }
98813
98827
  return transactionResults;
98814
98828
  } catch (err2) {
98815
98829
  logger2.error(`Failed moving assets to vesu: ${err2}`);
98816
- return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: new Web3Number(0, USDC_TOKEN_DECIMALS) }, "NONE")];
98830
+ return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: new Web3Number(0, USDC_TOKEN_DECIMALS) }, "NONE", "INVESTMENT" /* INVESTMENT */)];
98817
98831
  }
98818
98832
  }
98819
98833
  /**
98820
98834
  * Helper method to create transaction result with metadata
98821
98835
  */
98822
- createTransactionResult(calls, status, params, transactionType) {
98836
+ createTransactionResult(calls, status, params, transactionType, cycleType) {
98823
98837
  if (status) {
98824
98838
  return {
98825
98839
  calls,
@@ -98829,11 +98843,12 @@ spurious results.`);
98829
98843
  protocolTo: params.to,
98830
98844
  transactionType,
98831
98845
  usdAmount: params.amount.abs().toFixed(),
98832
- status: "PENDING"
98846
+ status: "PENDING",
98847
+ cycleType
98833
98848
  }
98834
98849
  };
98835
98850
  }
98836
- return { calls: [], status: false, transactionMetadata: { protocolFrom: "", protocolTo: "", transactionType: "DEPOSIT", usdAmount: "0", status: "FAILED" } };
98851
+ return { calls: [], status: false, transactionMetadata: { protocolFrom: "", protocolTo: "", transactionType: "DEPOSIT", usdAmount: "0", status: "FAILED", cycleType } };
98837
98852
  }
98838
98853
  async moveAssets(params, extendedAdapter, vesuAdapter) {
98839
98854
  try {
@@ -98841,7 +98856,7 @@ spurious results.`);
98841
98856
  logger2.error(
98842
98857
  `Invalid amount for moveAssets: ${params.amount.toNumber()}. Amount must be positive.`
98843
98858
  );
98844
- return this.createTransactionResult([], false, params, "NONE");
98859
+ return this.createTransactionResult([], false, params, "NONE", params.cycleType);
98845
98860
  }
98846
98861
  const amountAbs = params.amount.abs();
98847
98862
  if (params.from === Protocols.EXTENDED.name || params.to === Protocols.EXTENDED.name) {
@@ -98849,7 +98864,7 @@ spurious results.`);
98849
98864
  logger2.warn(
98850
98865
  `Amount ${amountAbs.toNumber()} is below minimum Extended movement amount ${extendedAdapter.minimumExtendedMovementAmount}. Skipping operation.`
98851
98866
  );
98852
- return this.createTransactionResult([], false, params, "NONE");
98867
+ return this.createTransactionResult([], false, params, "NONE", params.cycleType);
98853
98868
  }
98854
98869
  }
98855
98870
  if (params.from === Protocols.VESU.name || params.to === Protocols.VESU.name) {
@@ -98857,13 +98872,13 @@ spurious results.`);
98857
98872
  logger2.warn(
98858
98873
  `Amount ${amountAbs.toNumber()} is below minimum Vesu movement amount ${vesuAdapter.minimumVesuMovementAmount}. Skipping operation.`
98859
98874
  );
98860
- return this.createTransactionResult([], false, params, "NONE");
98875
+ return this.createTransactionResult([], false, params, "NONE", params.cycleType);
98861
98876
  }
98862
98877
  }
98863
98878
  const avnuAdapter = await this.getAvnuAdapter();
98864
98879
  if (!avnuAdapter) {
98865
98880
  logger2.error(`avnu adapter not found: ${avnuAdapter}`);
98866
- return this.createTransactionResult([], false, params, "NONE");
98881
+ return this.createTransactionResult([], false, params, "NONE", params.cycleType);
98867
98882
  }
98868
98883
  logger2.info(`moveAssets params, ${JSON.stringify(params)}`);
98869
98884
  const collateralToken = vesuAdapter.config.supportedPositions[0].asset;
@@ -98882,13 +98897,13 @@ spurious results.`);
98882
98897
  await proofsInfo.callConstructor({ amount: params.amount })
98883
98898
  );
98884
98899
  calls.push(call);
98885
- return this.createTransactionResult(calls, true, params, "DEPOSIT");
98900
+ return this.createTransactionResult(calls, true, params, "DEPOSIT", params.cycleType);
98886
98901
  } else if (params.to === Protocols.VAULT.name && params.from === Protocols.EXTENDED.name) {
98887
98902
  const extendedLeverage = calculateExtendedLevergae();
98888
98903
  const extendedHoldings = await extendedAdapter.getExtendedDepositAmount();
98889
98904
  if (!extendedHoldings) {
98890
98905
  logger2.error(`error getting extended holdings: ${extendedHoldings}`);
98891
- return this.createTransactionResult([], false, params, "NONE");
98906
+ return this.createTransactionResult([], false, params, "NONE", params.cycleType);
98892
98907
  }
98893
98908
  const extendedHoldingAmount = new Web3Number(
98894
98909
  extendedHoldings.availableForWithdrawal,
@@ -98905,7 +98920,7 @@ spurious results.`);
98905
98920
  "BUY" /* BUY */
98906
98921
  ) : await extendedAdapter.createOrder(
98907
98922
  extendedLeverage.toString(),
98908
- 35e-6,
98923
+ 34e-6,
98909
98924
  // just in case amount falls short then we need to create a withdrawal
98910
98925
  "BUY" /* BUY */
98911
98926
  );
@@ -98915,7 +98930,7 @@ spurious results.`);
98915
98930
  const updatedHoldings = await extendedAdapter.getExtendedDepositAmount();
98916
98931
  if (!updatedHoldings || new Web3Number(updatedHoldings.availableForWithdrawal, USDC_TOKEN_DECIMALS).lessThan(params.amount.abs())) {
98917
98932
  logger2.error(`Insufficient balance after opening position. Available: ${updatedHoldings?.availableForWithdrawal}, Needed: ${params.amount.abs()}`);
98918
- return this.createTransactionResult([], false, params, "NONE");
98933
+ return this.createTransactionResult([], false, params, "NONE", params.cycleType);
98919
98934
  }
98920
98935
  }
98921
98936
  const {
@@ -98929,22 +98944,22 @@ spurious results.`);
98929
98944
  await new Promise((resolve) => setTimeout(resolve, 5e3));
98930
98945
  const { calls, status } = await this.moveAssetsToVaultAllocator(params.amount, extendedAdapter);
98931
98946
  if (calls.length > 0 && status) {
98932
- return this.createTransactionResult(calls, true, params, "WITHDRAWAL");
98947
+ return this.createTransactionResult(calls, true, params, "WITHDRAWAL", params.cycleType);
98933
98948
  } else {
98934
- return this.createTransactionResult([], true, params, "WITHDRAWAL");
98949
+ return this.createTransactionResult([], true, params, "WITHDRAWAL", params.cycleType);
98935
98950
  }
98936
98951
  } else if (withdrawalFromExtendedStatus && !withdrawalFromExtendedTxnHash) {
98937
98952
  logger2.error("withdrawal from extended successful, but funds didn't get transferred to the wallet");
98938
- return this.createTransactionResult([], true, params, "WITHDRAWAL");
98953
+ return this.createTransactionResult([], true, params, "WITHDRAWAL", params.cycleType);
98939
98954
  } else {
98940
98955
  logger2.error("withdrawal from extended failed");
98941
- return this.createTransactionResult([], false, params, "NONE");
98956
+ return this.createTransactionResult([], false, params, "NONE", params.cycleType);
98942
98957
  }
98943
98958
  } else if (params.to === Protocols.VAULT.name && params.from === Protocols.VESU.name) {
98944
98959
  const isPriceDifferenceBetweenAvnuAndExtended = await this.checkPriceDifferenceBetweenAvnuAndExtended(extendedAdapter, vesuAdapter, avnuAdapter, "close" /* CLOSE */);
98945
98960
  if (!isPriceDifferenceBetweenAvnuAndExtended) {
98946
98961
  logger2.warn(`price difference between avnu and extended doesn't fit the range for close position, ${avnuAdapter.config.maximumExtendedPriceDifferenceForSwapClosing}`);
98947
- return this.createTransactionResult([], false, params, "NONE");
98962
+ return this.createTransactionResult([], false, params, "NONE", params.cycleType);
98948
98963
  }
98949
98964
  const vesuAmountInBTC = new Web3Number(
98950
98965
  params.amount.dividedBy(collateralPrice.price).toFixed(WBTC_TOKEN_DECIMALS),
@@ -98965,12 +98980,12 @@ spurious results.`);
98965
98980
  await swapProofsInfo.callConstructor({ amount: vesuAmountInBTC })
98966
98981
  );
98967
98982
  calls.push(swapCall);
98968
- return this.createTransactionResult(calls, true, params, "WITHDRAWAL");
98983
+ return this.createTransactionResult(calls, true, params, "WITHDRAWAL", params.cycleType);
98969
98984
  } else if (params.to === Protocols.EXTENDED.name && params.from === Protocols.VESU.name) {
98970
98985
  const isPriceDifferenceBetweenAvnuAndExtended = await this.checkPriceDifferenceBetweenAvnuAndExtended(extendedAdapter, vesuAdapter, avnuAdapter, "close" /* CLOSE */);
98971
98986
  if (!isPriceDifferenceBetweenAvnuAndExtended) {
98972
98987
  logger2.warn(`price difference between avnu and extended doesn't fit the range for close position, ${avnuAdapter.config.maximumExtendedPriceDifferenceForSwapClosing}`);
98973
- return this.createTransactionResult([], false, params, "NONE");
98988
+ return this.createTransactionResult([], false, params, "NONE", params.cycleType);
98974
98989
  }
98975
98990
  const vesuAmountInBTC = new Web3Number(
98976
98991
  params.amount.dividedBy(collateralPrice.price).toNumber(),
@@ -99001,23 +99016,31 @@ spurious results.`);
99001
99016
  await proofsInfoDeposit.callConstructor({ amount: params.amount })
99002
99017
  );
99003
99018
  calls.push(callDeposit);
99004
- return this.createTransactionResult(calls, true, params, "DEPOSIT");
99019
+ return this.createTransactionResult(calls, true, params, "DEPOSIT", params.cycleType);
99005
99020
  }
99006
99021
  logger2.error(`Unsupported assets movement: ${params.from} to ${params.to}`);
99007
- return this.createTransactionResult([], false, params, "NONE");
99022
+ return this.createTransactionResult([], false, params, "NONE", params.cycleType);
99008
99023
  } catch (err2) {
99009
99024
  logger2.error(`error moving assets: ${err2}`);
99010
- return this.createTransactionResult([], false, params, "NONE");
99025
+ return this.createTransactionResult([], false, params, "NONE", params.cycleType);
99011
99026
  }
99012
99027
  }
99013
99028
  async handleDeposit() {
99014
99029
  try {
99015
- return this.createTransactionResult([], false, { from: Protocols.VAULT.name, to: Protocols.VAULT.name, amount: new Web3Number(0, 0) }, "NONE");
99030
+ return this.createTransactionResult([], false, { from: Protocols.VAULT.name, to: Protocols.VAULT.name, amount: new Web3Number(0, 0) }, "NONE", "INVESTMENT" /* INVESTMENT */);
99016
99031
  } catch (err2) {
99017
99032
  logger2.error(`error handling deposit: ${err2}`);
99018
- return this.createTransactionResult([], false, { from: Protocols.VAULT.name, to: Protocols.VAULT.name, amount: new Web3Number(0, 0) }, "NONE");
99033
+ return this.createTransactionResult([], false, { from: Protocols.VAULT.name, to: Protocols.VAULT.name, amount: new Web3Number(0, 0) }, "NONE", "INVESTMENT" /* INVESTMENT */);
99019
99034
  }
99020
99035
  }
99036
+ /**
99037
+ * Check if the price difference between avnu and extended is within the acceptable range to enhance the position size or close the position
99038
+ * @param extendedAdapter - the extended adapter
99039
+ * @param vesuAdapter - the vesu adapter
99040
+ * @param avnuAdapter - the avnu adapter
99041
+ * @param positionType - the position type (open or close)
99042
+ * @returns true if the price difference is within the acceptable range, false otherwise
99043
+ */
99021
99044
  async checkPriceDifferenceBetweenAvnuAndExtended(extendedAdapter, vesuAdapter, avnuAdapter, positionType) {
99022
99045
  const {
99023
99046
  ask,
@@ -99049,6 +99072,11 @@ spurious results.`);
99049
99072
  return result2;
99050
99073
  }
99051
99074
  }
99075
+ /**
99076
+ * Handle the withdrawal of assets from the vault
99077
+ * @param amount - the amount to withdraw in USDC
99078
+ * @returns the calls to be executed and the status of the calls generated along with the metadata for the calls
99079
+ */
99052
99080
  async handleWithdraw(amount) {
99053
99081
  try {
99054
99082
  const usdcBalanceVaultAllocator = await this.getUnusedBalance();
@@ -99061,7 +99089,7 @@ spurious results.`);
99061
99089
  amount: usdcBalanceVaultAllocator.amount
99062
99090
  });
99063
99091
  calls.push(withdrawCall2);
99064
- return [this.createTransactionResult(calls, true, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "WITHDRAWAL")];
99092
+ return [this.createTransactionResult(calls, true, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "WITHDRAWAL", "WITHDRAWAL" /* WITHDRAWAL */)];
99065
99093
  }
99066
99094
  const vesuAdapter = await this.getVesuAdapter();
99067
99095
  const extendedAdapter = await this.getExtendedAdapter();
@@ -99070,7 +99098,7 @@ spurious results.`);
99070
99098
  logger2.error(
99071
99099
  `vesu or extended adapter not found: vesuAdapter=${vesuAdapter}, extendedAdapter=${extendedAdapter}`
99072
99100
  );
99073
- return [this.createTransactionResult(calls, status, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "NONE")];
99101
+ return [this.createTransactionResult(calls, status, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "NONE", "WITHDRAWAL" /* WITHDRAWAL */)];
99074
99102
  }
99075
99103
  let transactionResults = [];
99076
99104
  const { collateralTokenAmount } = await vesuAdapter.vesuAdapter.getAssetPrices();
@@ -99081,7 +99109,7 @@ spurious results.`);
99081
99109
  if (!extendedPositon) {
99082
99110
  status = false;
99083
99111
  logger2.error("error getting extended position", extendedPositon);
99084
- return [this.createTransactionResult(calls, status, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "NONE")];
99112
+ return [this.createTransactionResult(calls, status, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "NONE", "WITHDRAWAL" /* WITHDRAWAL */)];
99085
99113
  }
99086
99114
  const amountDistributionForWithdrawal = await calculateAmountDistributionForWithdrawal(
99087
99115
  usdcBalanceDifference,
@@ -99094,7 +99122,7 @@ spurious results.`);
99094
99122
  logger2.error(
99095
99123
  `error calculating amount distribution for withdrawal: ${amountDistributionForWithdrawal}`
99096
99124
  );
99097
- return [this.createTransactionResult(calls, status, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "NONE")];
99125
+ return [this.createTransactionResult(calls, status, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "NONE", "WITHDRAWAL" /* WITHDRAWAL */)];
99098
99126
  }
99099
99127
  const { vesu_amount, extended_amount } = amountDistributionForWithdrawal;
99100
99128
  if (status && vesu_amount.greaterThan(0)) {
@@ -99102,7 +99130,8 @@ spurious results.`);
99102
99130
  {
99103
99131
  amount: vesu_amount,
99104
99132
  from: Protocols.VESU.name,
99105
- to: Protocols.VAULT.name
99133
+ to: Protocols.VAULT.name,
99134
+ cycleType: "WITHDRAWAL" /* WITHDRAWAL */
99106
99135
  },
99107
99136
  extendedAdapter,
99108
99137
  vesuAdapter
@@ -99119,7 +99148,8 @@ spurious results.`);
99119
99148
  {
99120
99149
  amount: extended_amount,
99121
99150
  from: Protocols.EXTENDED.name,
99122
- to: Protocols.VAULT.name
99151
+ to: Protocols.VAULT.name,
99152
+ cycleType: "WITHDRAWAL" /* WITHDRAWAL */
99123
99153
  },
99124
99154
  extendedAdapter,
99125
99155
  vesuAdapter
@@ -99133,7 +99163,7 @@ spurious results.`);
99133
99163
  });
99134
99164
  } else {
99135
99165
  logger2.error("error moving assets to vault: extendedStatus: ${extendedStatus}");
99136
- return [this.createTransactionResult([], status, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "NONE")];
99166
+ return [this.createTransactionResult([], status, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "NONE", "WITHDRAWAL" /* WITHDRAWAL */)];
99137
99167
  }
99138
99168
  }
99139
99169
  const withdrawCall = await this.getBringLiquidityCall({
@@ -99148,13 +99178,14 @@ spurious results.`);
99148
99178
  protocolTo: Protocols.NONE.name,
99149
99179
  transactionType: "WITHDRAWAL",
99150
99180
  usdAmount: amount.toFixed(),
99151
- status: "PENDING"
99181
+ status: "PENDING",
99182
+ cycleType: "WITHDRAWAL" /* WITHDRAWAL */
99152
99183
  }
99153
99184
  });
99154
99185
  return transactionResults;
99155
99186
  } catch (err2) {
99156
99187
  logger2.error(`error handling withdrawal: ${err2}`);
99157
- return [this.createTransactionResult([], false, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "NONE")];
99188
+ return [this.createTransactionResult([], false, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "NONE", "WITHDRAWAL" /* WITHDRAWAL */)];
99158
99189
  }
99159
99190
  }
99160
99191
  async getAUM() {
@@ -99231,6 +99262,150 @@ spurious results.`);
99231
99262
  return null;
99232
99263
  }
99233
99264
  }
99265
+ async getMaxBorrowableAmount() {
99266
+ const vesuAdapter = await this.getVesuAdapter();
99267
+ const extendedAdapter = await this.getExtendedAdapter();
99268
+ if (!vesuAdapter || !extendedAdapter) {
99269
+ return new Web3Number(0, 0);
99270
+ }
99271
+ const extendedFundingRate = new Web3Number((await extendedAdapter.getNetAPY()).toFixed(4), 0);
99272
+ const extendedPositions = await extendedAdapter.getAllOpenPositions();
99273
+ if (!extendedPositions || extendedPositions.length === 0) {
99274
+ logger2.info(`no extended positions found`);
99275
+ return new Web3Number(0, 0);
99276
+ }
99277
+ const extendePositionSizeUSD = new Web3Number(extendedPositions[0].value || 0, 0);
99278
+ const vesuPositions = await vesuAdapter.getPositions();
99279
+ const vesuSupplyApy = vesuPositions[0].apy.apy;
99280
+ const vesuCollateralSizeUSD = new Web3Number(vesuPositions[0].usdValue.toFixed(USDC_TOKEN_DECIMALS), USDC_TOKEN_DECIMALS);
99281
+ const vesuDebtSizeUSD = new Web3Number(vesuPositions[1].usdValue.toFixed(USDC_TOKEN_DECIMALS), USDC_TOKEN_DECIMALS);
99282
+ const num1 = extendePositionSizeUSD.multipliedBy(extendedFundingRate);
99283
+ const num2 = vesuCollateralSizeUSD.multipliedBy(vesuSupplyApy);
99284
+ const num3 = vesuDebtSizeUSD.abs();
99285
+ const maxBorrowApy = num1.plus(num2).minus(0.1).dividedBy(num3);
99286
+ const vesuMaxBorrowableAmount = await vesuAdapter.vesuAdapter.getMaxBorrowableByInterestRate(this.config, vesuAdapter.config.debt, maxBorrowApy.toNumber());
99287
+ return new Web3Number(vesuMaxBorrowableAmount.toFixed(USDC_TOKEN_DECIMALS), USDC_TOKEN_DECIMALS);
99288
+ }
99289
+ async getVesuHealthFactors() {
99290
+ const vesuAdapter = await this.getVesuAdapter();
99291
+ const extendedAdapter = await this.getExtendedAdapter();
99292
+ if (!vesuAdapter || !extendedAdapter) {
99293
+ return [0, 0];
99294
+ }
99295
+ const vesuPositions = await vesuAdapter.getPositions();
99296
+ const vesuCollateralSizeUSD = new Web3Number(vesuPositions[0].usdValue.toFixed(USDC_TOKEN_DECIMALS), 0);
99297
+ const vesuDebtSizeUSD = new Web3Number(vesuPositions[1].usdValue.toFixed(USDC_TOKEN_DECIMALS), 0);
99298
+ const actualLtv = vesuDebtSizeUSD.dividedBy(vesuCollateralSizeUSD).abs();
99299
+ logger2.info(`actualLtv: ${actualLtv.toNumber()}`);
99300
+ const maxLtv = new Web3Number(await vesuAdapter.vesuAdapter.getLTVConfig(this.config), 4);
99301
+ const healthFactor = new Web3Number(maxLtv.dividedBy(actualLtv).toFixed(4), 4);
99302
+ logger2.info(`healthFactor: ${healthFactor.toNumber()}`);
99303
+ const extendedBalance = await extendedAdapter.getExtendedDepositAmount();
99304
+ if (!extendedBalance) {
99305
+ return [0, 0];
99306
+ }
99307
+ const extendedLeverage = new Web3Number((Number(extendedBalance.marginRatio) * 100).toFixed(4), 4);
99308
+ logger2.info(`extendedLeverage: ${extendedLeverage.toNumber()}`);
99309
+ return [healthFactor.toNumber(), extendedLeverage.toNumber()];
99310
+ }
99311
+ async netAPY() {
99312
+ const allPositions = [];
99313
+ for (let adapter2 of this.metadata.additionalInfo.adapters) {
99314
+ if (adapter2.adapter.name !== ExtendedAdapter.name) {
99315
+ let positions = await adapter2.adapter.getPositions();
99316
+ if (positions.length > 0) {
99317
+ allPositions.push(...positions);
99318
+ }
99319
+ }
99320
+ }
99321
+ const extendedAdapter = await this.getExtendedAdapter();
99322
+ if (!extendedAdapter) {
99323
+ return {
99324
+ net: 0,
99325
+ splits: []
99326
+ };
99327
+ }
99328
+ let vesuPositions = allPositions.filter((item) => item.protocol === Protocols.VESU);
99329
+ vesuPositions.map((item) => {
99330
+ item.apy.apy = item.apy.apy * 0.1;
99331
+ });
99332
+ const extendedPositions = await extendedAdapter.getAllOpenPositions();
99333
+ const usdcToken = Global.getDefaultTokens().find((token) => token.symbol === "USDC");
99334
+ if (!extendedPositions || !usdcToken) {
99335
+ return {
99336
+ net: 0,
99337
+ splits: []
99338
+ };
99339
+ }
99340
+ const extendedPosition = extendedPositions[0] || 0;
99341
+ const extendedEquity = (await extendedAdapter.getExtendedDepositAmount())?.equity || 0;
99342
+ const extendedApy = await extendedAdapter.getNetAPY();
99343
+ const totalHoldingsUSDValue = allPositions.reduce((acc, curr) => acc + curr.usdValue, 0) + Number(extendedEquity);
99344
+ console.log(totalHoldingsUSDValue);
99345
+ const extendedPositionSizeMultipliedByApy = Number(extendedPosition.value) * extendedApy;
99346
+ let weightedAPYs = allPositions.reduce((acc, curr) => acc + curr.apy.apy * curr.usdValue, 0) + extendedPositionSizeMultipliedByApy;
99347
+ console.log(weightedAPYs);
99348
+ const netAPY = weightedAPYs / totalHoldingsUSDValue;
99349
+ console.log(netAPY);
99350
+ allPositions.push({
99351
+ tokenInfo: usdcToken,
99352
+ amount: new Web3Number(extendedPosition.size, 0),
99353
+ usdValue: Number(extendedEquity),
99354
+ apy: { apy: extendedApy, type: "base" /* BASE */ },
99355
+ remarks: "finalised" /* FINALISED */,
99356
+ protocol: Protocols.EXTENDED
99357
+ });
99358
+ return {
99359
+ net: netAPY,
99360
+ splits: allPositions.map((p) => ({ apy: p.apy.apy, id: p.remarks ?? "" }))
99361
+ };
99362
+ }
99363
+ async getWalletHoldings() {
99364
+ const usdceToken = Global.getDefaultTokens().find((token) => token.symbol === "USDCe");
99365
+ const wbtcToken = Global.getDefaultTokens().find((token) => token.symbol === "WBTC");
99366
+ const usdcToken = Global.getDefaultTokens().find((token) => token.symbol === "USDC");
99367
+ if (!usdceToken || !wbtcToken || !usdcToken) {
99368
+ return [];
99369
+ }
99370
+ const walletAddress = this.metadata.additionalInfo.walletAddress;
99371
+ const usdceWalletBalance = await new ERC20(this.config).balanceOf(
99372
+ usdceToken.address,
99373
+ walletAddress,
99374
+ usdceToken.decimals
99375
+ );
99376
+ const usdcWalletBalance = await new ERC20(this.config).balanceOf(
99377
+ usdcToken.address,
99378
+ walletAddress,
99379
+ usdcToken.decimals
99380
+ );
99381
+ const wbtcWalletBalance = await new ERC20(this.config).balanceOf(
99382
+ wbtcToken.address,
99383
+ walletAddress,
99384
+ wbtcToken.decimals
99385
+ );
99386
+ const price = await this.pricer.getPrice(usdceToken.symbol);
99387
+ const wbtcPrice = await this.pricer.getPrice(wbtcToken.symbol);
99388
+ const usdceUsdValue = Number(usdceWalletBalance.toFixed(usdceToken.decimals)) * price.price;
99389
+ const usdcUsdValue = Number(usdcWalletBalance.toFixed(usdcToken.decimals)) * price.price;
99390
+ const wbtcUsdValue = Number(wbtcWalletBalance.toFixed(wbtcToken.decimals)) * wbtcPrice.price;
99391
+ return [
99392
+ {
99393
+ tokenInfo: usdceToken,
99394
+ amount: usdceWalletBalance,
99395
+ usdValue: usdceUsdValue
99396
+ },
99397
+ {
99398
+ tokenInfo: usdcToken,
99399
+ amount: usdcWalletBalance,
99400
+ usdValue: usdcUsdValue
99401
+ },
99402
+ {
99403
+ tokenInfo: wbtcToken,
99404
+ amount: wbtcWalletBalance,
99405
+ usdValue: wbtcUsdValue
99406
+ }
99407
+ ];
99408
+ }
99234
99409
  };
99235
99410
  function getLooperSettings2(lstSymbol, underlyingSymbol, vaultSettings, pool1, extendedBackendUrl, extendedApiKey, vaultIdExtended, minimumExtendedMovementAmount, minimumVesuMovementAmount, minimumExtendedRetriesDelayForOrderStatus, minimumExtendedPriceDifferenceForSwapOpen, maximumExtendedPriceDifferenceForSwapClosing) {
99236
99411
  vaultSettings.leafAdapters = [];
@@ -99405,7 +99580,8 @@ spurious results.`);
99405
99580
  Global.getDefaultTokens().find((token) => token.symbol === "WBTC").decimals
99406
99581
  ),
99407
99582
  borrowable_assets: [Global.getDefaultTokens().find((token) => token.symbol === "WBTC")],
99408
- minimumWBTCDifferenceForAvnuSwap: MINIMUM_WBTC_DIFFERENCE_FOR_AVNU_SWAP
99583
+ minimumWBTCDifferenceForAvnuSwap: MINIMUM_WBTC_DIFFERENCE_FOR_AVNU_SWAP,
99584
+ walletAddress: WALLET_ADDRESS
99409
99585
  };
99410
99586
  var VesuExtendedTestStrategies = (extendedBackendUrl, extendedApiKey, vaultIdExtended, minimumExtendedMovementAmount, minimumVesuMovementAmount, minimumExtendedRetriesDelayForOrderStatus, minimumExtendedPriceDifferenceForSwapOpen, maximumExtendedPriceDifferenceForSwapClosing) => {
99411
99587
  return [