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