@t2000/sdk 0.18.6 → 0.18.8

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.cjs CHANGED
@@ -3856,48 +3856,45 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
3856
3856
  }
3857
3857
  async balance() {
3858
3858
  const bal = await queryBalance(this.client, this._address);
3859
+ const portfolioPositions = this.portfolio.getPositions();
3859
3860
  const earningAssets = new Set(
3860
- this.portfolio.getPositions().filter((p) => p.earning).map((p) => p.asset)
3861
+ portfolioPositions.filter((p) => p.earning).map((p) => p.asset)
3861
3862
  );
3862
- try {
3863
- const positions = await this.positions();
3864
- const savings = positions.positions.filter((p) => p.type === "save").filter((p) => !earningAssets.has(p.asset)).reduce((sum, p) => sum + p.amount, 0);
3865
- const debt = positions.positions.filter((p) => p.type === "borrow").reduce((sum, p) => sum + p.amount, 0);
3866
- bal.savings = savings;
3867
- bal.debt = debt;
3868
- } catch {
3869
- }
3870
- try {
3871
- const portfolioPositions = this.portfolio.getPositions();
3872
- const suiPrice = bal.gasReserve.sui > 0 ? bal.gasReserve.usdEquiv / bal.gasReserve.sui : 0;
3873
- const assetPrices = { SUI: suiPrice };
3874
- const swapAdapter = this.registry.listSwap()[0];
3875
- const investedAssets = /* @__PURE__ */ new Set();
3876
- for (const pos of portfolioPositions) {
3877
- if (pos.asset in INVESTMENT_ASSETS) investedAssets.add(pos.asset);
3878
- }
3879
- for (const key of this.portfolio.getAllStrategyKeys()) {
3880
- for (const sp of this.portfolio.getStrategyPositions(key)) {
3881
- if (sp.asset in INVESTMENT_ASSETS) investedAssets.add(sp.asset);
3863
+ const suiPrice = bal.gasReserve.sui > 0 ? bal.gasReserve.usdEquiv / bal.gasReserve.sui : 0;
3864
+ const assetPrices = { SUI: suiPrice };
3865
+ const swapAdapter = this.registry.listSwap()[0];
3866
+ for (const asset of Object.keys(INVESTMENT_ASSETS)) {
3867
+ if (asset === "SUI") continue;
3868
+ try {
3869
+ if (swapAdapter) {
3870
+ const quote = await swapAdapter.getQuote("USDC", asset, 1);
3871
+ assetPrices[asset] = quote.expectedOutput > 0 ? 1 / quote.expectedOutput : 0;
3882
3872
  }
3873
+ } catch {
3874
+ assetPrices[asset] = 0;
3883
3875
  }
3884
- for (const asset of Object.keys(INVESTMENT_ASSETS)) {
3885
- if ((bal.assets[asset] ?? 0) > 0) investedAssets.add(asset);
3886
- }
3887
- for (const asset of investedAssets) {
3888
- if (asset === "SUI" || asset in assetPrices) continue;
3889
- try {
3890
- if (swapAdapter) {
3891
- const quote = await swapAdapter.getQuote("USDC", asset, 1);
3892
- assetPrices[asset] = quote.expectedOutput > 0 ? 1 / quote.expectedOutput : 0;
3876
+ }
3877
+ let chainTotal = bal.available + bal.gasReserve.usdEquiv;
3878
+ for (const asset of Object.keys(INVESTMENT_ASSETS)) {
3879
+ if (asset === "SUI") continue;
3880
+ chainTotal += (bal.assets[asset] ?? 0) * (assetPrices[asset] ?? 0);
3881
+ }
3882
+ try {
3883
+ const positions = await this.positions();
3884
+ for (const pos of positions.positions) {
3885
+ if (pos.type === "save") {
3886
+ chainTotal += pos.amount;
3887
+ if (!earningAssets.has(pos.asset)) {
3888
+ bal.savings += pos.amount;
3893
3889
  }
3894
- } catch {
3895
- assetPrices[asset] = 0;
3890
+ } else if (pos.type === "borrow") {
3891
+ chainTotal -= pos.amount;
3892
+ bal.debt += pos.amount;
3896
3893
  }
3897
3894
  }
3898
- let investmentValue = 0;
3899
- let investmentCostBasis = 0;
3900
- let trackedValue = 0;
3895
+ } catch {
3896
+ }
3897
+ try {
3901
3898
  const trackedAmounts = {};
3902
3899
  const trackedCostBasis = {};
3903
3900
  const earningAssetSet = /* @__PURE__ */ new Set();
@@ -3914,6 +3911,9 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
3914
3911
  trackedCostBasis[sp.asset] = (trackedCostBasis[sp.asset] ?? 0) + sp.costBasis;
3915
3912
  }
3916
3913
  }
3914
+ let investmentValue = 0;
3915
+ let investmentCostBasis = 0;
3916
+ let trackedValue = 0;
3917
3917
  for (const asset of Object.keys(INVESTMENT_ASSETS)) {
3918
3918
  const price = assetPrices[asset] ?? 0;
3919
3919
  const tracked = trackedAmounts[asset] ?? 0;
@@ -3951,7 +3951,7 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
3951
3951
  } catch {
3952
3952
  bal.pendingRewards = 0;
3953
3953
  }
3954
- bal.total = bal.available + bal.savings - bal.debt + bal.investment + bal.gasReserve.usdEquiv;
3954
+ bal.total = chainTotal;
3955
3955
  return bal;
3956
3956
  }
3957
3957
  async history(params) {