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

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.
@@ -91443,11 +91443,6 @@ spurious results.`);
91443
91443
  if (!this.pricer) {
91444
91444
  throw new Error("Pricer is not initialized");
91445
91445
  }
91446
- const CACHE_KEY = `positions_${blockNumber}_${this.config.poolId.shortString()}_${this.config.collateral.symbol}_${this.config.debt.symbol}`;
91447
- const cacheData = this.getCache(CACHE_KEY);
91448
- if (cacheData) {
91449
- return cacheData;
91450
- }
91451
91446
  const { contract, isV2 } = this.getVesuSingletonContract(config3, this.config.poolId);
91452
91447
  const output = await contract.call(isV2 ? "position" : "position_unsafe", [
91453
91448
  ...isV2 ? [] : [this.config.poolId.address],
@@ -91473,7 +91468,6 @@ spurious results.`);
91473
91468
  usdValue: debtAmount.multipliedBy(token2Price.price).toNumber(),
91474
91469
  remarks: "Debt"
91475
91470
  }];
91476
- this.setCache(CACHE_KEY, value, 6e4);
91477
91471
  return value.map((v) => ({ ...v, protocol: Protocols.VESU }));
91478
91472
  }
91479
91473
  async getCollateralization(config3, blockNumber = "latest") {
@@ -93981,26 +93975,38 @@ spurious results.`);
93981
93975
  try {
93982
93976
  if (!this.client) {
93983
93977
  logger2.error("Client not initialized");
93984
- return false;
93978
+ return {
93979
+ status: false,
93980
+ receivedTxnHash: false
93981
+ };
93985
93982
  }
93986
93983
  if (amount.lessThanOrEqualTo(0)) {
93987
93984
  logger2.error(
93988
93985
  `Invalid withdrawal amount: ${amount.toNumber()}. Amount must be positive.`
93989
93986
  );
93990
- return false;
93987
+ return {
93988
+ status: false,
93989
+ receivedTxnHash: false
93990
+ };
93991
93991
  }
93992
93992
  if (amount.lessThanOrEqualTo(this.minimumExtendedMovementAmount)) {
93993
93993
  logger2.warn(
93994
93994
  `Withdrawal amount ${amount.toNumber()} is below minimum Extended movement amount ${this.minimumExtendedMovementAmount}. Skipping withdrawal.`
93995
93995
  );
93996
- return false;
93996
+ return {
93997
+ status: false,
93998
+ receivedTxnHash: false
93999
+ };
93997
94000
  }
93998
94001
  const holdings = await this.getExtendedDepositAmount();
93999
94002
  if (!holdings) {
94000
94003
  logger2.error(
94001
94004
  "Cannot get holdings - unable to validate withdrawal amount"
94002
94005
  );
94003
- return false;
94006
+ return {
94007
+ status: false,
94008
+ receivedTxnHash: false
94009
+ };
94004
94010
  }
94005
94011
  const availableForWithdrawal = parseFloat(
94006
94012
  holdings.availableForWithdrawal
@@ -94009,14 +94015,20 @@ spurious results.`);
94009
94015
  logger2.error(
94010
94016
  `Invalid availableForWithdrawal: ${holdings.availableForWithdrawal}. Expected a finite, non-negative number.`
94011
94017
  );
94012
- return false;
94018
+ return {
94019
+ status: false,
94020
+ receivedTxnHash: false
94021
+ };
94013
94022
  }
94014
94023
  const withdrawalAmount = amount.toNumber();
94015
94024
  if (withdrawalAmount > availableForWithdrawal) {
94016
94025
  logger2.error(
94017
94026
  `Withdrawal amount ${withdrawalAmount} exceeds available balance ${availableForWithdrawal}`
94018
94027
  );
94019
- return false;
94028
+ return {
94029
+ status: false,
94030
+ receivedTxnHash: false
94031
+ };
94020
94032
  }
94021
94033
  logger2.info(
94022
94034
  `Withdrawing ${withdrawalAmount} from Extended. Available balance: ${availableForWithdrawal}`
@@ -94029,15 +94041,24 @@ spurious results.`);
94029
94041
  withdrawalRequest.data,
94030
94042
  "WITHDRAWAL" /* WITHDRAWAL */
94031
94043
  );
94032
- return withdrawalStatus;
94044
+ return {
94045
+ status: true,
94046
+ receivedTxnHash: withdrawalStatus
94047
+ };
94033
94048
  }
94034
94049
  logger2.error(
94035
94050
  `Withdrawal request failed with status: ${withdrawalRequest.status}`
94036
94051
  );
94037
- return false;
94052
+ return {
94053
+ status: false,
94054
+ receivedTxnHash: false
94055
+ };
94038
94056
  } catch (error2) {
94039
94057
  logger2.error(`Error creating Withdraw Call: ${error2}`);
94040
- return false;
94058
+ return {
94059
+ status: false,
94060
+ receivedTxnHash: false
94061
+ };
94041
94062
  }
94042
94063
  }
94043
94064
  async getHealthFactor() {
@@ -98385,10 +98406,16 @@ spurious results.`);
98385
98406
  proofGroups,
98386
98407
  await proofsInfo.callConstructor({ amount })
98387
98408
  );
98388
- return [approveCall, transferCall, call];
98409
+ return {
98410
+ calls: [approveCall, transferCall, call],
98411
+ status: true
98412
+ };
98389
98413
  } catch (err2) {
98390
98414
  logger2.error(`error moving assets to vault allocator: ${err2}`);
98391
- return [];
98415
+ return {
98416
+ calls: [],
98417
+ status: false
98418
+ };
98392
98419
  }
98393
98420
  }
98394
98421
  async shouldInvest() {
@@ -98637,9 +98664,10 @@ spurious results.`);
98637
98664
  const vesuAmountDifferenceAbs = vesuAmountDifference.abs();
98638
98665
  logger2.info(`${_VesuExtendedMultiplierStrategy.name}::shouldMoveAssets calculated movements - Extended withdrawal: ${totalExtendedWithdrawal.toNumber()}, Extended deposit: ${totalExtendedDeposit.toNumber()}, Extended diff: ${extendedAmountDifference.toNumber()}, Projected wallet: ${projectedWalletBalance.toNumber()}, Vesu diff: ${vesuAmountDifference.toNumber()}`);
98639
98666
  let calls = [];
98667
+ let transactionResults = [];
98640
98668
  if (extendedAmount.isNegative() && extendedAmount.abs().greaterThan(extendedAdapter.minimumExtendedMovementAmount)) {
98641
98669
  try {
98642
- const { calls: extendedCalls, status: extendedStatus } = await this.moveAssets(
98670
+ const { calls: extendedCalls, status: extendedStatus, transactionMetadata: extendedTransactionMetadata } = await this.moveAssets(
98643
98671
  {
98644
98672
  to: Protocols.VAULT.name,
98645
98673
  from: Protocols.EXTENDED.name,
@@ -98649,17 +98677,25 @@ spurious results.`);
98649
98677
  vesuAdapter
98650
98678
  );
98651
98679
  if (extendedStatus) {
98652
- calls.push(...extendedCalls);
98680
+ transactionResults.push({
98681
+ status: extendedStatus,
98682
+ calls: extendedCalls,
98683
+ transactionMetadata: {
98684
+ ...extendedTransactionMetadata,
98685
+ transactionType: "DEPOSIT"
98686
+ }
98687
+ });
98653
98688
  } else {
98654
- return [];
98689
+ return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: extendedAmount.abs() }, "NONE")];
98655
98690
  }
98656
98691
  } catch (err2) {
98657
98692
  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")];
98658
98694
  }
98659
98695
  }
98660
98696
  if (vesuAmount.isNegative() && vesuAmount.abs().greaterThan(vesuAdapter.minimumVesuMovementAmount)) {
98661
98697
  try {
98662
- const { calls: vesuCalls, status: vesuStatus } = await this.moveAssets(
98698
+ const { calls: vesuCalls, status: vesuStatus, transactionMetadata: vesuTransactionMetadata } = await this.moveAssets(
98663
98699
  {
98664
98700
  to: Protocols.EXTENDED.name,
98665
98701
  from: Protocols.VESU.name,
@@ -98668,18 +98704,26 @@ spurious results.`);
98668
98704
  extendedAdapter,
98669
98705
  vesuAdapter
98670
98706
  );
98671
- calls.push(...vesuCalls);
98672
98707
  if (!vesuStatus) {
98673
- return [];
98674
- }
98708
+ return [this.createTransactionResult([], false, { from: Protocols.VESU.name, to: Protocols.EXTENDED.name, amount: vesuAmount.abs() }, "NONE")];
98709
+ }
98710
+ transactionResults.push({
98711
+ status: vesuStatus,
98712
+ calls: vesuCalls,
98713
+ transactionMetadata: {
98714
+ ...vesuTransactionMetadata,
98715
+ transactionType: "DEPOSIT"
98716
+ }
98717
+ });
98675
98718
  } catch (err2) {
98676
- logger2.error(`Failed moving assets to vault: ${err2}`);
98719
+ 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")];
98677
98721
  }
98678
98722
  }
98679
98723
  if (extendedAmountDifferenceAbs.greaterThan(extendedAdapter.minimumExtendedMovementAmount)) {
98680
98724
  if (extendedAmountDifference.greaterThan(0)) {
98681
98725
  try {
98682
- const { calls: extendedCalls, status: extendedStatus } = await this.moveAssets(
98726
+ const { calls: extendedCalls, status: extendedStatus, transactionMetadata: extendedTransactionMetadata } = await this.moveAssets(
98683
98727
  {
98684
98728
  to: Protocols.EXTENDED.name,
98685
98729
  from: Protocols.VAULT.name,
@@ -98689,18 +98733,22 @@ spurious results.`);
98689
98733
  vesuAdapter
98690
98734
  );
98691
98735
  if (extendedStatus) {
98692
- calls.push(...extendedCalls);
98736
+ transactionResults.push({
98737
+ status: extendedStatus,
98738
+ calls: extendedCalls,
98739
+ transactionMetadata: extendedTransactionMetadata
98740
+ });
98693
98741
  } else {
98694
98742
  logger2.error(`Failed to move assets to extended - operation returned false status`);
98695
- return [];
98743
+ return [this.createTransactionResult([], false, { from: Protocols.VAULT.name, to: Protocols.EXTENDED.name, amount: extendedAmountDifference }, "NONE")];
98696
98744
  }
98697
98745
  } catch (err2) {
98698
98746
  logger2.error(`Failed moving assets to extended: ${err2}`);
98699
- return [];
98747
+ return [this.createTransactionResult([], false, { from: Protocols.VAULT.name, to: Protocols.EXTENDED.name, amount: extendedAmountDifference }, "NONE")];
98700
98748
  }
98701
98749
  } else if (extendedAmountDifference.lessThan(0)) {
98702
98750
  try {
98703
- const { calls: extendedCalls, status: extendedStatus } = await this.moveAssets(
98751
+ const { calls: extendedCalls, status: extendedStatus, transactionMetadata: extendedTransactionMetadata } = await this.moveAssets(
98704
98752
  {
98705
98753
  to: Protocols.VAULT.name,
98706
98754
  from: Protocols.EXTENDED.name,
@@ -98710,14 +98758,21 @@ spurious results.`);
98710
98758
  vesuAdapter
98711
98759
  );
98712
98760
  if (extendedStatus) {
98713
- calls.push(...extendedCalls);
98761
+ transactionResults.push({
98762
+ status: extendedStatus,
98763
+ calls: extendedCalls,
98764
+ transactionMetadata: {
98765
+ ...extendedTransactionMetadata,
98766
+ transactionType: "DEPOSIT"
98767
+ }
98768
+ });
98714
98769
  } else {
98715
98770
  logger2.error(`Failed to withdraw from extended - operation returned false status`);
98716
- return [];
98771
+ return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: extendedAmountDifferenceAbs }, "NONE")];
98717
98772
  }
98718
98773
  } catch (err2) {
98719
98774
  logger2.error(`Failed moving assets from extended to vault: ${err2}`);
98720
- return [];
98775
+ return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: extendedAmountDifferenceAbs }, "NONE")];
98721
98776
  }
98722
98777
  }
98723
98778
  }
@@ -98728,7 +98783,7 @@ spurious results.`);
98728
98783
  );
98729
98784
  } else {
98730
98785
  try {
98731
- const { calls: vesuCalls, status: vesuStatus } = await this.moveAssets(
98786
+ const { calls: vesuCalls, status: vesuStatus, transactionMetadata: vesuTransactionMetadata } = await this.moveAssets(
98732
98787
  {
98733
98788
  to: Protocols.VAULT.name,
98734
98789
  from: Protocols.EXTENDED.name,
@@ -98739,31 +98794,54 @@ spurious results.`);
98739
98794
  );
98740
98795
  if (!vesuStatus) {
98741
98796
  logger2.error(`Failed to move assets to vesu - operation returned false status`);
98742
- return [];
98797
+ return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: vesuAmountDifference }, "NONE")];
98743
98798
  }
98744
- calls.push(...vesuCalls);
98799
+ transactionResults.push({
98800
+ status: vesuStatus,
98801
+ calls: vesuCalls,
98802
+ transactionMetadata: {
98803
+ ...vesuTransactionMetadata,
98804
+ transactionType: "DEPOSIT"
98805
+ }
98806
+ });
98745
98807
  } catch (err2) {
98746
98808
  logger2.error(`Failed moving assets to vault: ${err2}`);
98747
- return [];
98809
+ return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: vesuAmountDifference }, "NONE")];
98748
98810
  }
98749
98811
  }
98750
98812
  }
98751
- return calls;
98813
+ return transactionResults;
98752
98814
  } catch (err2) {
98753
98815
  logger2.error(`Failed moving assets to vesu: ${err2}`);
98754
- return [];
98816
+ return [this.createTransactionResult([], false, { from: Protocols.EXTENDED.name, to: Protocols.VAULT.name, amount: new Web3Number(0, USDC_TOKEN_DECIMALS) }, "NONE")];
98755
98817
  }
98756
98818
  }
98819
+ /**
98820
+ * Helper method to create transaction result with metadata
98821
+ */
98822
+ createTransactionResult(calls, status, params, transactionType) {
98823
+ if (status) {
98824
+ return {
98825
+ calls,
98826
+ status,
98827
+ transactionMetadata: {
98828
+ protocolFrom: params.from,
98829
+ protocolTo: params.to,
98830
+ transactionType,
98831
+ usdAmount: params.amount.abs().toFixed(),
98832
+ status: "PENDING"
98833
+ }
98834
+ };
98835
+ }
98836
+ return { calls: [], status: false, transactionMetadata: { protocolFrom: "", protocolTo: "", transactionType: "DEPOSIT", usdAmount: "0", status: "FAILED" } };
98837
+ }
98757
98838
  async moveAssets(params, extendedAdapter, vesuAdapter) {
98758
98839
  try {
98759
98840
  if (params.amount.lessThanOrEqualTo(0)) {
98760
98841
  logger2.error(
98761
98842
  `Invalid amount for moveAssets: ${params.amount.toNumber()}. Amount must be positive.`
98762
98843
  );
98763
- return {
98764
- calls: [],
98765
- status: false
98766
- };
98844
+ return this.createTransactionResult([], false, params, "NONE");
98767
98845
  }
98768
98846
  const amountAbs = params.amount.abs();
98769
98847
  if (params.from === Protocols.EXTENDED.name || params.to === Protocols.EXTENDED.name) {
@@ -98771,10 +98849,7 @@ spurious results.`);
98771
98849
  logger2.warn(
98772
98850
  `Amount ${amountAbs.toNumber()} is below minimum Extended movement amount ${extendedAdapter.minimumExtendedMovementAmount}. Skipping operation.`
98773
98851
  );
98774
- return {
98775
- calls: [],
98776
- status: false
98777
- };
98852
+ return this.createTransactionResult([], false, params, "NONE");
98778
98853
  }
98779
98854
  }
98780
98855
  if (params.from === Protocols.VESU.name || params.to === Protocols.VESU.name) {
@@ -98782,19 +98857,13 @@ spurious results.`);
98782
98857
  logger2.warn(
98783
98858
  `Amount ${amountAbs.toNumber()} is below minimum Vesu movement amount ${vesuAdapter.minimumVesuMovementAmount}. Skipping operation.`
98784
98859
  );
98785
- return {
98786
- calls: [],
98787
- status: false
98788
- };
98860
+ return this.createTransactionResult([], false, params, "NONE");
98789
98861
  }
98790
98862
  }
98791
98863
  const avnuAdapter = await this.getAvnuAdapter();
98792
98864
  if (!avnuAdapter) {
98793
98865
  logger2.error(`avnu adapter not found: ${avnuAdapter}`);
98794
- return {
98795
- calls: [],
98796
- status: false
98797
- };
98866
+ return this.createTransactionResult([], false, params, "NONE");
98798
98867
  }
98799
98868
  logger2.info(`moveAssets params, ${JSON.stringify(params)}`);
98800
98869
  const collateralToken = vesuAdapter.config.supportedPositions[0].asset;
@@ -98813,19 +98882,13 @@ spurious results.`);
98813
98882
  await proofsInfo.callConstructor({ amount: params.amount })
98814
98883
  );
98815
98884
  calls.push(call);
98816
- return {
98817
- calls: [call],
98818
- status: true
98819
- };
98885
+ return this.createTransactionResult(calls, true, params, "DEPOSIT");
98820
98886
  } else if (params.to === Protocols.VAULT.name && params.from === Protocols.EXTENDED.name) {
98821
98887
  const extendedLeverage = calculateExtendedLevergae();
98822
98888
  const extendedHoldings = await extendedAdapter.getExtendedDepositAmount();
98823
98889
  if (!extendedHoldings) {
98824
98890
  logger2.error(`error getting extended holdings: ${extendedHoldings}`);
98825
- return {
98826
- calls: [],
98827
- status: false
98828
- };
98891
+ return this.createTransactionResult([], false, params, "NONE");
98829
98892
  }
98830
98893
  const extendedHoldingAmount = new Web3Number(
98831
98894
  extendedHoldings.availableForWithdrawal,
@@ -98852,36 +98915,36 @@ spurious results.`);
98852
98915
  const updatedHoldings = await extendedAdapter.getExtendedDepositAmount();
98853
98916
  if (!updatedHoldings || new Web3Number(updatedHoldings.availableForWithdrawal, USDC_TOKEN_DECIMALS).lessThan(params.amount.abs())) {
98854
98917
  logger2.error(`Insufficient balance after opening position. Available: ${updatedHoldings?.availableForWithdrawal}, Needed: ${params.amount.abs()}`);
98855
- return { calls: [], status: false };
98918
+ return this.createTransactionResult([], false, params, "NONE");
98856
98919
  }
98857
98920
  }
98858
- const withdrawalFromExtended = await extendedAdapter.withdrawFromExtended(params.amount);
98859
- if (withdrawalFromExtended) {
98921
+ const {
98922
+ status: withdrawalFromExtendedStatus,
98923
+ receivedTxnHash: withdrawalFromExtendedTxnHash
98924
+ } = await extendedAdapter.withdrawFromExtended(params.amount);
98925
+ logger2.info(`withdrawalFromExtendedStatus: ${withdrawalFromExtendedStatus}, withdrawalFromExtendedTxnHash: ${withdrawalFromExtendedTxnHash}`);
98926
+ if (withdrawalFromExtendedStatus && withdrawalFromExtendedTxnHash) {
98860
98927
  const extendedHoldings2 = await extendedAdapter.getExtendedDepositAmount();
98861
98928
  logger2.info(`extendedHoldings after withdrawal ${extendedHoldings2?.availableForWithdrawal}`);
98862
98929
  await new Promise((resolve) => setTimeout(resolve, 5e3));
98863
- const calls = await this.moveAssetsToVaultAllocator(params.amount, extendedAdapter);
98864
- if (calls.length > 0) {
98865
- return {
98866
- calls,
98867
- status: true
98868
- };
98930
+ const { calls, status } = await this.moveAssetsToVaultAllocator(params.amount, extendedAdapter);
98931
+ if (calls.length > 0 && status) {
98932
+ return this.createTransactionResult(calls, true, params, "WITHDRAWAL");
98933
+ } else {
98934
+ return this.createTransactionResult([], true, params, "WITHDRAWAL");
98869
98935
  }
98936
+ } else if (withdrawalFromExtendedStatus && !withdrawalFromExtendedTxnHash) {
98937
+ logger2.error("withdrawal from extended successful, but funds didn't get transferred to the wallet");
98938
+ return this.createTransactionResult([], true, params, "WITHDRAWAL");
98870
98939
  } else {
98871
98940
  logger2.error("withdrawal from extended failed");
98872
- return {
98873
- calls: [],
98874
- status: false
98875
- };
98941
+ return this.createTransactionResult([], false, params, "NONE");
98876
98942
  }
98877
98943
  } else if (params.to === Protocols.VAULT.name && params.from === Protocols.VESU.name) {
98878
98944
  const isPriceDifferenceBetweenAvnuAndExtended = await this.checkPriceDifferenceBetweenAvnuAndExtended(extendedAdapter, vesuAdapter, avnuAdapter, "close" /* CLOSE */);
98879
98945
  if (!isPriceDifferenceBetweenAvnuAndExtended) {
98880
98946
  logger2.warn(`price difference between avnu and extended doesn't fit the range for close position, ${avnuAdapter.config.maximumExtendedPriceDifferenceForSwapClosing}`);
98881
- return {
98882
- calls: [],
98883
- status: false
98884
- };
98947
+ return this.createTransactionResult([], false, params, "NONE");
98885
98948
  }
98886
98949
  const vesuAmountInBTC = new Web3Number(
98887
98950
  params.amount.dividedBy(collateralPrice.price).toFixed(WBTC_TOKEN_DECIMALS),
@@ -98902,18 +98965,12 @@ spurious results.`);
98902
98965
  await swapProofsInfo.callConstructor({ amount: vesuAmountInBTC })
98903
98966
  );
98904
98967
  calls.push(swapCall);
98905
- return {
98906
- calls,
98907
- status: true
98908
- };
98968
+ return this.createTransactionResult(calls, true, params, "WITHDRAWAL");
98909
98969
  } else if (params.to === Protocols.EXTENDED.name && params.from === Protocols.VESU.name) {
98910
98970
  const isPriceDifferenceBetweenAvnuAndExtended = await this.checkPriceDifferenceBetweenAvnuAndExtended(extendedAdapter, vesuAdapter, avnuAdapter, "close" /* CLOSE */);
98911
98971
  if (!isPriceDifferenceBetweenAvnuAndExtended) {
98912
98972
  logger2.warn(`price difference between avnu and extended doesn't fit the range for close position, ${avnuAdapter.config.maximumExtendedPriceDifferenceForSwapClosing}`);
98913
- return {
98914
- calls: [],
98915
- status: false
98916
- };
98973
+ return this.createTransactionResult([], false, params, "NONE");
98917
98974
  }
98918
98975
  const vesuAmountInBTC = new Web3Number(
98919
98976
  params.amount.dividedBy(collateralPrice.price).toNumber(),
@@ -98944,127 +99001,21 @@ spurious results.`);
98944
99001
  await proofsInfoDeposit.callConstructor({ amount: params.amount })
98945
99002
  );
98946
99003
  calls.push(callDeposit);
98947
- return {
98948
- calls,
98949
- status: true
98950
- };
99004
+ return this.createTransactionResult(calls, true, params, "DEPOSIT");
98951
99005
  }
98952
- return {
98953
- calls: [],
98954
- status: false
98955
- };
99006
+ logger2.error(`Unsupported assets movement: ${params.from} to ${params.to}`);
99007
+ return this.createTransactionResult([], false, params, "NONE");
98956
99008
  } catch (err2) {
98957
99009
  logger2.error(`error moving assets: ${err2}`);
98958
- return {
98959
- calls: [],
98960
- status: false
98961
- };
99010
+ return this.createTransactionResult([], false, params, "NONE");
98962
99011
  }
98963
99012
  }
98964
99013
  async handleDeposit() {
98965
99014
  try {
98966
- const vesuAdapter = await this.getVesuAdapter();
98967
- const extendedAdapter = await this.getExtendedAdapter();
98968
- const avnuAdapter = await this.getAvnuAdapter();
98969
- if (!vesuAdapter || !extendedAdapter || !extendedAdapter.client || !avnuAdapter) {
98970
- logger2.error(
98971
- "vesu or extended adapter not found",
98972
- vesuAdapter,
98973
- extendedAdapter
98974
- );
98975
- return {
98976
- extendedAmountInBTC: new Web3Number(0, 0),
98977
- calls: []
98978
- };
98979
- }
98980
- const extendedLeverage = calculateExtendedLevergae();
98981
- const isPriceDifferenceBetweenAvnuAndExtended = await this.checkPriceDifferenceBetweenAvnuAndExtended(extendedAdapter, vesuAdapter, avnuAdapter, "open" /* OPEN */);
98982
- if (!isPriceDifferenceBetweenAvnuAndExtended) {
98983
- logger2.error("price difference between avnu and extended doesn't fit the range");
98984
- return {
98985
- extendedAmountInBTC: new Web3Number(0, 0),
98986
- calls: []
98987
- };
98988
- }
98989
- const position = await extendedAdapter.getAllOpenPositions();
98990
- if (!position) {
98991
- logger2.error("error getting extended position", position);
98992
- return {
98993
- extendedAmountInBTC: new Web3Number(0, 0),
98994
- calls: []
98995
- };
98996
- }
98997
- const extendedPositionValue = position.length > 0 ? parseFloat(position[0].value) : 0;
98998
- const BUFFER_AMOUNT_IN_AVAILABLE_FOR_TRADE = BUFFER_USDC_IN_WITHDRAWAL;
98999
- const extendedHoldings = await extendedAdapter.getExtendedDepositAmount();
99000
- if (!extendedHoldings) {
99001
- logger2.error(`error getting extended holdings: ${extendedHoldings}`);
99002
- return {
99003
- extendedAmountInBTC: new Web3Number(0, 0),
99004
- calls: []
99005
- };
99006
- }
99007
- const extendedHoldingAmount = new Web3Number(
99008
- extendedHoldings.availableForWithdrawal,
99009
- USDC_TOKEN_DECIMALS
99010
- );
99011
- const {
99012
- collateralTokenAmount
99013
- } = await vesuAdapter.vesuAdapter.getAssetPrices();
99014
- const { collateralPrice } = await this.getAssetPrices();
99015
- const { vesuAmountInBTC, extendedAmountInBTC } = calculateVesUPositionSizeGivenExtended(
99016
- extendedPositionValue,
99017
- extendedHoldingAmount.minus(BUFFER_AMOUNT_IN_AVAILABLE_FOR_TRADE),
99018
- collateralTokenAmount,
99019
- collateralPrice.price
99020
- );
99021
- logger2.info(`vesuAmountInBTC ${vesuAmountInBTC}, extendedAmountInBTC ${extendedAmountInBTC}`);
99022
- let calls = [];
99023
- if (vesuAmountInBTC.greaterThan(MINIMUM_EXTENDED_POSITION_SIZE)) {
99024
- const proofsInfo = vesuAdapter.getProofs(true, this.getMerkleTree());
99025
- const proofGroups = proofsInfo.proofs;
99026
- const call = this.getManageCall(
99027
- proofGroups,
99028
- await proofsInfo.callConstructor({
99029
- amount: vesuAmountInBTC
99030
- })
99031
- );
99032
- const { amount: wbtcAmountInVaultAllocator } = await this.getUnusedBalanceWBTC();
99033
- if (wbtcAmountInVaultAllocator.lessThan(vesuAmountInBTC)) {
99034
- const swapProofsInfo = avnuAdapter.getProofs(true, this.getMerkleTree());
99035
- const swapProofGroups = swapProofsInfo.proofs;
99036
- const swapCall = this.getManageCall(
99037
- swapProofGroups,
99038
- await swapProofsInfo.callConstructor({
99039
- amount: vesuAmountInBTC
99040
- })
99041
- );
99042
- calls.push(swapCall);
99043
- }
99044
- calls.push(call);
99045
- }
99046
- const shortPosition = extendedAmountInBTC.multipliedBy(3).abs().greaterThan(MINIMUM_EXTENDED_POSITION_SIZE) ? await extendedAdapter.createOrder(
99047
- extendedLeverage.toString(),
99048
- extendedAmountInBTC.toNumber(),
99049
- "SELL" /* SELL */
99050
- ) : null;
99051
- if (!shortPosition && extendedAmountInBTC.multipliedBy(3).abs().greaterThan(MINIMUM_EXTENDED_POSITION_SIZE)) {
99052
- logger2.error(`error creating short position thus no position to be opened on vesu: ${shortPosition}`);
99053
- return {
99054
- extendedAmountInBTC: new Web3Number(0, 0),
99055
- calls: []
99056
- };
99057
- }
99058
- return {
99059
- extendedAmountInBTC,
99060
- calls
99061
- };
99015
+ return this.createTransactionResult([], false, { from: Protocols.VAULT.name, to: Protocols.VAULT.name, amount: new Web3Number(0, 0) }, "NONE");
99062
99016
  } catch (err2) {
99063
99017
  logger2.error(`error handling deposit: ${err2}`);
99064
- return {
99065
- extendedAmountInBTC: new Web3Number(0, 0),
99066
- calls: []
99067
- };
99018
+ return this.createTransactionResult([], false, { from: Protocols.VAULT.name, to: Protocols.VAULT.name, amount: new Web3Number(0, 0) }, "NONE");
99068
99019
  }
99069
99020
  }
99070
99021
  async checkPriceDifferenceBetweenAvnuAndExtended(extendedAdapter, vesuAdapter, avnuAdapter, positionType) {
@@ -99109,12 +99060,8 @@ spurious results.`);
99109
99060
  const withdrawCall2 = await this.getBringLiquidityCall({
99110
99061
  amount: usdcBalanceVaultAllocator.amount
99111
99062
  });
99112
- logger2.info("withdraw call", withdrawCall2);
99113
99063
  calls.push(withdrawCall2);
99114
- return {
99115
- calls,
99116
- status: true
99117
- };
99064
+ return [this.createTransactionResult(calls, true, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "WITHDRAWAL")];
99118
99065
  }
99119
99066
  const vesuAdapter = await this.getVesuAdapter();
99120
99067
  const extendedAdapter = await this.getExtendedAdapter();
@@ -99123,11 +99070,9 @@ spurious results.`);
99123
99070
  logger2.error(
99124
99071
  `vesu or extended adapter not found: vesuAdapter=${vesuAdapter}, extendedAdapter=${extendedAdapter}`
99125
99072
  );
99126
- return {
99127
- calls,
99128
- status
99129
- };
99073
+ return [this.createTransactionResult(calls, status, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "NONE")];
99130
99074
  }
99075
+ let transactionResults = [];
99131
99076
  const { collateralTokenAmount } = await vesuAdapter.vesuAdapter.getAssetPrices();
99132
99077
  const {
99133
99078
  collateralPrice
@@ -99136,10 +99081,7 @@ spurious results.`);
99136
99081
  if (!extendedPositon) {
99137
99082
  status = false;
99138
99083
  logger2.error("error getting extended position", extendedPositon);
99139
- return {
99140
- calls,
99141
- status
99142
- };
99084
+ return [this.createTransactionResult(calls, status, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "NONE")];
99143
99085
  }
99144
99086
  const amountDistributionForWithdrawal = await calculateAmountDistributionForWithdrawal(
99145
99087
  usdcBalanceDifference,
@@ -99152,14 +99094,11 @@ spurious results.`);
99152
99094
  logger2.error(
99153
99095
  `error calculating amount distribution for withdrawal: ${amountDistributionForWithdrawal}`
99154
99096
  );
99155
- return {
99156
- calls,
99157
- status
99158
- };
99097
+ return [this.createTransactionResult(calls, status, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "NONE")];
99159
99098
  }
99160
99099
  const { vesu_amount, extended_amount } = amountDistributionForWithdrawal;
99161
99100
  if (status && vesu_amount.greaterThan(0)) {
99162
- const { calls: vesuCalls, status: vesuStatus } = await this.moveAssets(
99101
+ const { calls: vesuCalls, status: vesuStatus, transactionMetadata: vesuTransactionMetadata } = await this.moveAssets(
99163
99102
  {
99164
99103
  amount: vesu_amount,
99165
99104
  from: Protocols.VESU.name,
@@ -99169,10 +99108,14 @@ spurious results.`);
99169
99108
  vesuAdapter
99170
99109
  );
99171
99110
  status = vesuStatus;
99172
- calls.push(...vesuCalls);
99111
+ transactionResults.push({
99112
+ status: vesuStatus,
99113
+ calls: vesuCalls,
99114
+ transactionMetadata: vesuTransactionMetadata
99115
+ });
99173
99116
  }
99174
99117
  if (status && extended_amount.greaterThan(0)) {
99175
- const { calls: extendedCalls, status: extendedStatus } = await this.moveAssets(
99118
+ const { calls: extendedCalls, status: extendedStatus, transactionMetadata: extendedTransactionMetadata } = await this.moveAssets(
99176
99119
  {
99177
99120
  amount: extended_amount,
99178
99121
  from: Protocols.EXTENDED.name,
@@ -99183,30 +99126,35 @@ spurious results.`);
99183
99126
  );
99184
99127
  status = extendedStatus;
99185
99128
  if (status) {
99186
- calls.push(...extendedCalls);
99129
+ transactionResults.push({
99130
+ status: extendedStatus,
99131
+ calls: extendedCalls,
99132
+ transactionMetadata: extendedTransactionMetadata
99133
+ });
99187
99134
  } else {
99188
99135
  logger2.error("error moving assets to vault: extendedStatus: ${extendedStatus}");
99189
- return {
99190
- calls: [],
99191
- status
99192
- };
99136
+ return [this.createTransactionResult([], status, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "NONE")];
99193
99137
  }
99194
99138
  }
99195
99139
  const withdrawCall = await this.getBringLiquidityCall({
99196
99140
  amount
99197
99141
  });
99198
99142
  logger2.info("withdraw call", withdrawCall);
99199
- calls.push(withdrawCall);
99200
- return {
99201
- calls,
99202
- status
99203
- };
99143
+ transactionResults.push({
99144
+ status,
99145
+ calls: [withdrawCall],
99146
+ transactionMetadata: {
99147
+ protocolFrom: Protocols.VAULT.name,
99148
+ protocolTo: Protocols.NONE.name,
99149
+ transactionType: "WITHDRAWAL",
99150
+ usdAmount: amount.toFixed(),
99151
+ status: "PENDING"
99152
+ }
99153
+ });
99154
+ return transactionResults;
99204
99155
  } catch (err2) {
99205
99156
  logger2.error(`error handling withdrawal: ${err2}`);
99206
- return {
99207
- calls: [],
99208
- status: false
99209
- };
99157
+ return [this.createTransactionResult([], false, { from: Protocols.VAULT.name, to: Protocols.NONE.name, amount }, "NONE")];
99210
99158
  }
99211
99159
  }
99212
99160
  async getAUM() {
@@ -99253,6 +99201,36 @@ spurious results.`);
99253
99201
  splits: [realAUM, estimatedAUMDelta]
99254
99202
  };
99255
99203
  }
99204
+ async processTransactionDataFromSDK(txnData) {
99205
+ try {
99206
+ const txnsToBeExecuted = txnData.filter((txn) => {
99207
+ return txn.transactionMetadata.transactionType !== "NONE" && txn.transactionMetadata.protocolFrom !== "" && txn.transactionMetadata.protocolTo !== "";
99208
+ });
99209
+ const callsToBeExecutedFinal = txnsToBeExecuted.flatMap((txn) => txn.calls);
99210
+ const txnMetadata = txnsToBeExecuted.map((txn) => txn.transactionMetadata);
99211
+ return { callsToBeExecutedFinal, txnMetadata };
99212
+ } catch (err2) {
99213
+ logger2.error(`error processing transaction data from SDK: ${err2}`);
99214
+ return null;
99215
+ }
99216
+ }
99217
+ async processTransactionMetadata(txnMetadata, extendedIntentFulfilled) {
99218
+ try {
99219
+ const txnMetadataNew = txnMetadata.map((txn) => {
99220
+ const isExtendedProtocol = txn.protocolFrom === Protocols.EXTENDED.name || txn.protocolTo === Protocols.EXTENDED.name;
99221
+ if (isExtendedProtocol) {
99222
+ txn.status = extendedIntentFulfilled ? "COMPLETED" : "PENDING";
99223
+ } else {
99224
+ txn.status = "COMPLETED";
99225
+ }
99226
+ return txn;
99227
+ });
99228
+ return txnMetadataNew;
99229
+ } catch (err2) {
99230
+ logger2.error(`error processing transaction data from SDK: ${err2}`);
99231
+ return null;
99232
+ }
99233
+ }
99256
99234
  };
99257
99235
  function getLooperSettings2(lstSymbol, underlyingSymbol, vaultSettings, pool1, extendedBackendUrl, extendedApiKey, vaultIdExtended, minimumExtendedMovementAmount, minimumVesuMovementAmount, minimumExtendedRetriesDelayForOrderStatus, minimumExtendedPriceDifferenceForSwapOpen, maximumExtendedPriceDifferenceForSwapClosing) {
99258
99236
  vaultSettings.leafAdapters = [];