@t2000/sdk 0.17.8 → 0.17.10

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
@@ -4637,16 +4637,20 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
4637
4637
  const usdcOutputs = [];
4638
4638
  for (const pos of stratPositions) {
4639
4639
  const assetInfo = SUPPORTED_ASSETS[pos.asset];
4640
- const coins = await this._fetchCoins(assetInfo.type);
4641
- if (coins.length === 0) {
4642
- throw new T2000Error("INSUFFICIENT_BALANCE", `No ${pos.asset} coins in wallet`);
4643
- }
4644
- const merged = this._mergeCoinsInTx(tx, coins);
4645
4640
  const gasReserve = pos.asset === "SUI" ? GAS_RESERVE_MIN : 0;
4646
4641
  const sellAmount = Math.max(0, pos.totalAmount - gasReserve);
4647
4642
  const rawAmount = BigInt(Math.floor(sellAmount * 10 ** assetInfo.decimals));
4648
- const [splitCoin] = tx.splitCoins(merged, [rawAmount]);
4649
- const assetUsd = sellAmount * (pos.avgPrice || 1);
4643
+ let splitCoin;
4644
+ if (pos.asset === "SUI") {
4645
+ [splitCoin] = tx.splitCoins(tx.gas, [rawAmount]);
4646
+ } else {
4647
+ const coins = await this._fetchCoins(assetInfo.type);
4648
+ if (coins.length === 0) {
4649
+ throw new T2000Error("INSUFFICIENT_BALANCE", `No ${pos.asset} coins in wallet`);
4650
+ }
4651
+ const merged = this._mergeCoinsInTx(tx, coins);
4652
+ [splitCoin] = tx.splitCoins(merged, [rawAmount]);
4653
+ }
4650
4654
  const slippageBps = LOW_LIQUIDITY_ASSETS.has(pos.asset) ? 500 : 300;
4651
4655
  const { outputCoin, estimatedOut, toDecimals } = await swapAdapter.addSwapToTx(
4652
4656
  tx,
@@ -4654,7 +4658,7 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
4654
4658
  splitCoin,
4655
4659
  pos.asset,
4656
4660
  "USDC",
4657
- assetUsd,
4661
+ sellAmount,
4658
4662
  slippageBps
4659
4663
  );
4660
4664
  usdcOutputs.push(outputCoin);
@@ -4773,13 +4777,18 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
4773
4777
  const usdcCoins = [];
4774
4778
  for (const sell of sellOps) {
4775
4779
  const assetInfo = SUPPORTED_ASSETS[sell.asset];
4776
- const coins = await this._fetchCoins(assetInfo.type);
4777
- if (coins.length === 0) continue;
4778
- const merged = this._mergeCoinsInTx(tx, coins);
4779
4780
  const gasReserve = sell.asset === "SUI" ? GAS_RESERVE_MIN : 0;
4780
4781
  const sellAmount = Math.max(0, sell.assetAmount - gasReserve);
4781
4782
  const rawAmount = BigInt(Math.floor(sellAmount * 10 ** assetInfo.decimals));
4782
- const [splitCoin] = tx.splitCoins(merged, [rawAmount]);
4783
+ let splitCoin;
4784
+ if (sell.asset === "SUI") {
4785
+ [splitCoin] = tx.splitCoins(tx.gas, [rawAmount]);
4786
+ } else {
4787
+ const coins = await this._fetchCoins(assetInfo.type);
4788
+ if (coins.length === 0) continue;
4789
+ const merged = this._mergeCoinsInTx(tx, coins);
4790
+ [splitCoin] = tx.splitCoins(merged, [rawAmount]);
4791
+ }
4783
4792
  const slippageBps = LOW_LIQUIDITY_ASSETS.has(sell.asset) ? 500 : 300;
4784
4793
  const { outputCoin, estimatedOut, toDecimals } = await swapAdapter.addSwapToTx(
4785
4794
  tx,
@@ -4787,7 +4796,7 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
4787
4796
  splitCoin,
4788
4797
  sell.asset,
4789
4798
  "USDC",
4790
- sell.usdAmount,
4799
+ sellAmount,
4791
4800
  slippageBps
4792
4801
  );
4793
4802
  usdcCoins.push(outputCoin);