@t2000/sdk 0.16.20 → 0.16.22

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