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