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