@t2000/sdk 0.16.9 → 0.16.10

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