@scallop-io/sui-scallop-sdk 0.46.46 → 0.46.48

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
@@ -5869,14 +5869,14 @@ var generateSpoolQuickMethod = ({
5869
5869
  );
5870
5870
  }
5871
5871
  },
5872
- unstakeQuick: async (amount, stakeMarketCoinName, stakeAccountId) => {
5872
+ unstakeQuick: async (amount, stakeMarketCoinName, stakeAccountId, returnSCoin = true) => {
5873
5873
  const stakeAccounts = await requireStakeAccounts(
5874
5874
  builder,
5875
5875
  txBlock,
5876
5876
  stakeMarketCoinName,
5877
5877
  stakeAccountId
5878
5878
  );
5879
- const sCoins2 = [];
5879
+ const toTransfer = [];
5880
5880
  for (const account of stakeAccounts) {
5881
5881
  if (account.staked === 0)
5882
5882
  continue;
@@ -5886,28 +5886,48 @@ var generateSpoolQuickMethod = ({
5886
5886
  amountToUnstake,
5887
5887
  stakeMarketCoinName
5888
5888
  );
5889
- const sCoin = txBlock.mintSCoin(stakeMarketCoinName, marketCoin);
5890
- sCoins2.push(sCoin);
5889
+ if (returnSCoin) {
5890
+ const sCoin = txBlock.mintSCoin(stakeMarketCoinName, marketCoin);
5891
+ toTransfer.push(sCoin);
5892
+ } else {
5893
+ toTransfer.push(marketCoin);
5894
+ }
5891
5895
  amount -= amountToUnstake;
5892
5896
  if (amount === 0)
5893
5897
  break;
5894
5898
  }
5895
- const mergedSCoin = sCoins2[0];
5896
- if (sCoins2.length > 1) {
5897
- txBlock.mergeCoins(mergedSCoin, sCoins2.slice(1));
5898
- }
5899
- try {
5900
- const existingCoins = await builder.utils.selectCoins(
5901
- Number.MAX_SAFE_INTEGER,
5902
- builder.utils.parseSCoinType(stakeMarketCoinName),
5903
- requireSender(txBlock)
5904
- );
5905
- if (existingCoins.length > 0) {
5906
- txBlock.mergeCoins(mergedSCoin, existingCoins);
5899
+ if (toTransfer.length > 0) {
5900
+ const mergedCoin = toTransfer[0];
5901
+ if (toTransfer.length > 1) {
5902
+ txBlock.mergeCoins(mergedCoin, toTransfer.slice(1));
5907
5903
  }
5908
- } catch (e) {
5904
+ if (returnSCoin) {
5905
+ try {
5906
+ const existingCoins = await builder.utils.selectCoins(
5907
+ Number.MAX_SAFE_INTEGER,
5908
+ builder.utils.parseSCoinType(stakeMarketCoinName),
5909
+ requireSender(txBlock)
5910
+ );
5911
+ if (existingCoins.length > 0) {
5912
+ txBlock.mergeCoins(mergedCoin, existingCoins);
5913
+ }
5914
+ } catch (e) {
5915
+ }
5916
+ } else {
5917
+ try {
5918
+ const existingCoins = await builder.utils.selectCoins(
5919
+ Number.MAX_SAFE_INTEGER,
5920
+ builder.utils.parseMarketCoinType(stakeMarketCoinName),
5921
+ requireSender(txBlock)
5922
+ );
5923
+ if (existingCoins.length > 0) {
5924
+ txBlock.mergeCoins(mergedCoin, existingCoins);
5925
+ }
5926
+ } catch (e) {
5927
+ }
5928
+ }
5929
+ return mergedCoin;
5909
5930
  }
5910
- return mergedSCoin;
5911
5931
  },
5912
5932
  claimQuick: async (stakeMarketCoinName, stakeAccountId) => {
5913
5933
  const stakeAccountIds = await requireStakeAccountIds(
@@ -7330,8 +7350,10 @@ var ScallopClient = class {
7330
7350
  stakeAccountId
7331
7351
  );
7332
7352
  const stakeCoinName = this.utils.parseCoinName(stakeMarketCoinName);
7333
- const coin = txBlock.withdraw(stakeMarketCoin, stakeCoinName);
7334
- txBlock.transferObjects([coin], sender);
7353
+ if (stakeMarketCoin) {
7354
+ const coin = txBlock.withdraw(stakeMarketCoin, stakeCoinName);
7355
+ txBlock.transferObjects([coin], sender);
7356
+ }
7335
7357
  if (sign) {
7336
7358
  return await this.suiKit.signAndSendTxn(
7337
7359
  txBlock
@@ -7446,6 +7468,7 @@ var ScallopClient = class {
7446
7468
  const toTransfer = [];
7447
7469
  await Promise.all(
7448
7470
  SUPPORT_SCOIN.map(async (sCoinName) => {
7471
+ const sCoins2 = [];
7449
7472
  let toDestroyMarketCoin;
7450
7473
  try {
7451
7474
  const marketCoins2 = await this.utils.selectCoins(
@@ -7463,23 +7486,6 @@ var ScallopClient = class {
7463
7486
  if (!errMsg.includes("No valid coins found for the transaction"))
7464
7487
  throw e;
7465
7488
  }
7466
- if (SUPPORT_SPOOLS.includes(sCoinName)) {
7467
- try {
7468
- const stakedMarketCoin = await txBlock.unstakeQuick(
7469
- Number.MAX_SAFE_INTEGER,
7470
- sCoinName
7471
- );
7472
- if (toDestroyMarketCoin) {
7473
- txBlock.mergeCoins(toDestroyMarketCoin, [stakedMarketCoin]);
7474
- } else {
7475
- toDestroyMarketCoin = stakedMarketCoin;
7476
- }
7477
- } catch (e) {
7478
- const errMsg = e.toString();
7479
- if (!errMsg.includes("No stake account found"))
7480
- throw e;
7481
- }
7482
- }
7483
7489
  if (toDestroyMarketCoin) {
7484
7490
  const sCoin = txBlock.mintSCoin(
7485
7491
  sCoinName,
@@ -7501,7 +7507,29 @@ var ScallopClient = class {
7501
7507
  if (!errMsg.includes("No valid coins found for the transaction"))
7502
7508
  throw e;
7503
7509
  }
7504
- toTransfer.push(sCoin);
7510
+ sCoins2.push(sCoin);
7511
+ }
7512
+ if (SUPPORT_SPOOLS.includes(sCoinName)) {
7513
+ try {
7514
+ const sCoin = await txBlock.unstakeQuick(
7515
+ Number.MAX_SAFE_INTEGER,
7516
+ sCoinName
7517
+ );
7518
+ if (sCoin) {
7519
+ sCoins2.push(sCoin);
7520
+ }
7521
+ } catch (e) {
7522
+ const errMsg = e.toString();
7523
+ if (!errMsg.includes("No stake account found"))
7524
+ throw e;
7525
+ }
7526
+ }
7527
+ if (sCoins2.length > 0) {
7528
+ const mergedSCoin = sCoins2[0];
7529
+ if (sCoins2.length > 1) {
7530
+ txBlock.mergeCoins(mergedSCoin, sCoins2.slice(1));
7531
+ }
7532
+ toTransfer.push(mergedSCoin);
7505
7533
  }
7506
7534
  })
7507
7535
  );