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