@t2000/sdk 0.16.9 → 0.16.11
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 +19 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3437,14 +3437,21 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3437
3437
|
investmentCostBasis += pos.costBasis;
|
|
3438
3438
|
}
|
|
3439
3439
|
}
|
|
3440
|
+
let strategySuiTotal = 0;
|
|
3440
3441
|
for (const key of this.portfolio.getAllStrategyKeys()) {
|
|
3441
3442
|
for (const sp of this.portfolio.getStrategyPositions(key)) {
|
|
3442
3443
|
if (!(sp.asset in INVESTMENT_ASSETS)) continue;
|
|
3443
3444
|
const price = assetPrices[sp.asset] ?? 0;
|
|
3444
3445
|
investmentValue += sp.totalAmount * price;
|
|
3445
3446
|
investmentCostBasis += sp.costBasis;
|
|
3447
|
+
if (sp.asset === "SUI") strategySuiTotal += sp.totalAmount;
|
|
3446
3448
|
}
|
|
3447
3449
|
}
|
|
3450
|
+
if (strategySuiTotal > 0) {
|
|
3451
|
+
const suiPrice2 = assetPrices["SUI"] ?? 0;
|
|
3452
|
+
const gasSui = Math.max(0, bal.gasReserve.sui - strategySuiTotal);
|
|
3453
|
+
bal.gasReserve = { sui: gasSui, usdEquiv: gasSui * suiPrice2 };
|
|
3454
|
+
}
|
|
3448
3455
|
bal.investment = investmentValue;
|
|
3449
3456
|
bal.investmentPnL = investmentValue - investmentCostBasis;
|
|
3450
3457
|
} catch {
|
|
@@ -5058,14 +5065,23 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
5058
5065
|
// -- Helpers --
|
|
5059
5066
|
async getFreeBalance(asset) {
|
|
5060
5067
|
if (!(asset in INVESTMENT_ASSETS)) return Infinity;
|
|
5068
|
+
let walletInvested = 0;
|
|
5061
5069
|
const pos = this.portfolio.getPosition(asset);
|
|
5062
|
-
|
|
5063
|
-
|
|
5070
|
+
if (pos && pos.totalAmount > 0 && !pos.earning) {
|
|
5071
|
+
walletInvested += pos.totalAmount;
|
|
5072
|
+
}
|
|
5073
|
+
for (const key of this.portfolio.getAllStrategyKeys()) {
|
|
5074
|
+
for (const sp of this.portfolio.getStrategyPositions(key)) {
|
|
5075
|
+
if (sp.asset === asset && sp.totalAmount > 0) {
|
|
5076
|
+
walletInvested += sp.totalAmount;
|
|
5077
|
+
}
|
|
5078
|
+
}
|
|
5079
|
+
}
|
|
5080
|
+
if (walletInvested <= 0 && (!pos || pos.totalAmount <= 0)) return Infinity;
|
|
5064
5081
|
const assetInfo = SUPPORTED_ASSETS[asset];
|
|
5065
5082
|
const balance = await this.client.getBalance({ owner: this._address, coinType: assetInfo.type });
|
|
5066
5083
|
const walletAmount = Number(balance.totalBalance) / 10 ** assetInfo.decimals;
|
|
5067
5084
|
const gasReserve = asset === "SUI" ? GAS_RESERVE_MIN : 0;
|
|
5068
|
-
const walletInvested = pos?.earning ? 0 : invested;
|
|
5069
5085
|
return Math.max(0, walletAmount - walletInvested - gasReserve);
|
|
5070
5086
|
}
|
|
5071
5087
|
async resolveLending(protocol, asset, capability) {
|