@t2000/sdk 0.18.30 → 0.18.31

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
@@ -57127,13 +57127,6 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
57127
57127
  trackedCostBasis[pos.asset] = (trackedCostBasis[pos.asset] ?? 0) + pos.costBasis;
57128
57128
  if (pos.earning) earningAssetSet.add(pos.asset);
57129
57129
  }
57130
- for (const key of this.portfolio.getAllStrategyKeys()) {
57131
- for (const sp of this.portfolio.getStrategyPositions(key)) {
57132
- if (!(sp.asset in INVESTMENT_ASSETS)) continue;
57133
- trackedAmounts[sp.asset] = (trackedAmounts[sp.asset] ?? 0) + sp.totalAmount;
57134
- trackedCostBasis[sp.asset] = (trackedCostBasis[sp.asset] ?? 0) + sp.costBasis;
57135
- }
57136
- }
57137
57130
  let investmentValue = 0;
57138
57131
  let investmentCostBasis = 0;
57139
57132
  let trackedValue = 0;
@@ -58943,13 +58936,38 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
58943
58936
  strategyPositions[key] = enrichedStrat;
58944
58937
  }
58945
58938
  }
58946
- const allPositions = [...enriched, ...Object.values(strategyPositions).flat()];
58947
- const totalInvested = allPositions.reduce((sum, p) => sum + p.costBasis, 0);
58948
- const totalValue = allPositions.reduce((sum, p) => sum + p.currentValue, 0);
58939
+ const strategyAmountByAsset = {};
58940
+ for (const strats of Object.values(strategyPositions)) {
58941
+ for (const sp of strats) {
58942
+ const prev = strategyAmountByAsset[sp.asset] ?? { amount: 0, costBasis: 0 };
58943
+ strategyAmountByAsset[sp.asset] = {
58944
+ amount: prev.amount + sp.totalAmount,
58945
+ costBasis: prev.costBasis + sp.costBasis
58946
+ };
58947
+ }
58948
+ }
58949
+ const directOnly = enriched.map((pos) => {
58950
+ const strat = strategyAmountByAsset[pos.asset];
58951
+ if (!strat) return pos;
58952
+ const directAmt = pos.totalAmount - strat.amount;
58953
+ if (directAmt <= 1e-6) return null;
58954
+ const directCost = pos.costBasis - strat.costBasis;
58955
+ const currentValue = directAmt * (pos.currentPrice ?? 0);
58956
+ return {
58957
+ ...pos,
58958
+ totalAmount: directAmt,
58959
+ costBasis: directCost,
58960
+ currentValue,
58961
+ unrealizedPnL: currentValue - directCost,
58962
+ unrealizedPnLPct: directCost > 0 ? (currentValue - directCost) / directCost * 100 : 0
58963
+ };
58964
+ }).filter((p) => p !== null);
58965
+ const totalInvested = enriched.reduce((sum, p) => sum + p.costBasis, 0);
58966
+ const totalValue = enriched.reduce((sum, p) => sum + p.currentValue, 0);
58949
58967
  const totalUnrealizedPnL = totalValue - totalInvested;
58950
58968
  const totalUnrealizedPnLPct = totalInvested > 0 ? totalUnrealizedPnL / totalInvested * 100 : 0;
58951
58969
  const result = {
58952
- positions: enriched,
58970
+ positions: directOnly,
58953
58971
  totalInvested,
58954
58972
  totalValue,
58955
58973
  unrealizedPnL: totalUnrealizedPnL,
@@ -59301,16 +59319,7 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
59301
59319
  async getFreeBalance(asset) {
59302
59320
  if (!(asset in INVESTMENT_ASSETS)) return Infinity;
59303
59321
  const pos = this.portfolio.getPosition(asset);
59304
- const directAmount = pos && pos.totalAmount > 0 && !pos.earning ? pos.totalAmount : 0;
59305
- let strategyTotal = 0;
59306
- for (const key of this.portfolio.getAllStrategyKeys()) {
59307
- for (const sp of this.portfolio.getStrategyPositions(key)) {
59308
- if (sp.asset === asset && sp.totalAmount > 0) {
59309
- strategyTotal += sp.totalAmount;
59310
- }
59311
- }
59312
- }
59313
- const walletInvested = Math.max(directAmount, strategyTotal);
59322
+ const walletInvested = pos && pos.totalAmount > 0 && !pos.earning ? pos.totalAmount : 0;
59314
59323
  if (walletInvested <= 0) return Infinity;
59315
59324
  const assetInfo = SUPPORTED_ASSETS[asset];
59316
59325
  const balance = await this.client.getBalance({ owner: this._address, coinType: assetInfo.type });