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