@t2000/sdk 0.16.20 → 0.16.21

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
@@ -4256,16 +4256,22 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
4256
4256
  if (!pos || pos.totalAmount <= 0) {
4257
4257
  throw new T2000Error("INSUFFICIENT_INVESTMENT", `No ${params.asset} position to sell`);
4258
4258
  }
4259
- if (pos.earning && pos.earningProtocol) {
4259
+ const didAutoWithdraw = !!(pos.earning && pos.earningProtocol);
4260
+ if (didAutoWithdraw) {
4260
4261
  await this.investUnearn({ asset: params.asset });
4261
4262
  }
4262
4263
  const assetInfo = SUPPORTED_ASSETS[params.asset];
4263
- const assetBalance = await this.client.getBalance({
4264
- owner: this._address,
4265
- coinType: assetInfo.type
4266
- });
4267
- const walletAmount = Number(assetBalance.totalBalance) / 10 ** assetInfo.decimals;
4268
4264
  const gasReserve = params.asset === "SUI" ? GAS_RESERVE_MIN : 0;
4265
+ let walletAmount = 0;
4266
+ for (let attempt = 0; ; attempt++) {
4267
+ const assetBalance = await this.client.getBalance({
4268
+ owner: this._address,
4269
+ coinType: assetInfo.type
4270
+ });
4271
+ walletAmount = Number(assetBalance.totalBalance) / 10 ** assetInfo.decimals;
4272
+ if (!didAutoWithdraw || walletAmount > gasReserve || attempt >= 3) break;
4273
+ await new Promise((r) => setTimeout(r, 1e3));
4274
+ }
4269
4275
  const maxSellable = Math.max(0, walletAmount - gasReserve);
4270
4276
  let sellAmountAsset;
4271
4277
  if (params.usdAmount === "all") {