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