@t2000/sdk 0.17.10 → 0.17.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
@@ -4637,17 +4637,18 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
4637
4637
  const usdcOutputs = [];
4638
4638
  for (const pos of stratPositions) {
4639
4639
  const assetInfo = SUPPORTED_ASSETS[pos.asset];
4640
+ const bal = await this.client.getBalance({ owner: this._address, coinType: assetInfo.type });
4641
+ const walletAmount = Number(bal.totalBalance) / 10 ** assetInfo.decimals;
4640
4642
  const gasReserve = pos.asset === "SUI" ? GAS_RESERVE_MIN : 0;
4641
- const sellAmount = Math.max(0, pos.totalAmount - gasReserve);
4643
+ const sellAmount = Math.max(0, Math.min(pos.totalAmount, walletAmount) - gasReserve);
4644
+ if (sellAmount <= 0) continue;
4642
4645
  const rawAmount = BigInt(Math.floor(sellAmount * 10 ** assetInfo.decimals));
4643
4646
  let splitCoin;
4644
4647
  if (pos.asset === "SUI") {
4645
4648
  [splitCoin] = tx.splitCoins(tx.gas, [rawAmount]);
4646
4649
  } else {
4647
4650
  const coins = await this._fetchCoins(assetInfo.type);
4648
- if (coins.length === 0) {
4649
- throw new T2000Error("INSUFFICIENT_BALANCE", `No ${pos.asset} coins in wallet`);
4650
- }
4651
+ if (coins.length === 0) continue;
4651
4652
  const merged = this._mergeCoinsInTx(tx, coins);
4652
4653
  [splitCoin] = tx.splitCoins(merged, [rawAmount]);
4653
4654
  }
@@ -4777,8 +4778,11 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
4777
4778
  const usdcCoins = [];
4778
4779
  for (const sell of sellOps) {
4779
4780
  const assetInfo = SUPPORTED_ASSETS[sell.asset];
4781
+ const bal = await this.client.getBalance({ owner: this._address, coinType: assetInfo.type });
4782
+ const walletAmount = Number(bal.totalBalance) / 10 ** assetInfo.decimals;
4780
4783
  const gasReserve = sell.asset === "SUI" ? GAS_RESERVE_MIN : 0;
4781
- const sellAmount = Math.max(0, sell.assetAmount - gasReserve);
4784
+ const sellAmount = Math.max(0, Math.min(sell.assetAmount, walletAmount) - gasReserve);
4785
+ if (sellAmount <= 0) continue;
4782
4786
  const rawAmount = BigInt(Math.floor(sellAmount * 10 ** assetInfo.decimals));
4783
4787
  let splitCoin;
4784
4788
  if (sell.asset === "SUI") {