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