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