@scallop-io/sui-scallop-sdk 0.46.47 → 0.46.49

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
@@ -3319,26 +3319,10 @@ var getPythPrice = async (query, assetCoinName, priceFeedObject) => {
3319
3319
  return 0;
3320
3320
  };
3321
3321
  var getPythPrices = async (query, assetCoinNames) => {
3322
- const seen = {};
3323
- const pythFeedObjectIds = assetCoinNames.map((assetCoinName) => {
3324
- const pythFeedObjectId = query.address.get(
3325
- `core.coins.${assetCoinName}.oracle.pyth.feedObject`
3326
- );
3327
- if (seen[pythFeedObjectId])
3328
- return null;
3329
- seen[pythFeedObjectId] = true;
3330
- return pythFeedObjectId;
3331
- }).filter((item) => !!item);
3332
- const priceFeedObjects = await query.cache.queryGetObjects(
3333
- pythFeedObjectIds,
3334
- {
3335
- showContent: true
3336
- }
3337
- );
3338
3322
  return (await Promise.all(
3339
- priceFeedObjects.map(async (priceFeedObject, idx) => ({
3340
- coinName: assetCoinNames[idx],
3341
- price: await getPythPrice(query, assetCoinNames[idx], priceFeedObject)
3323
+ assetCoinNames.map(async (assetCoinName) => ({
3324
+ coinName: assetCoinName,
3325
+ price: await getPythPrice(query, assetCoinName)
3342
3326
  }))
3343
3327
  )).reduce(
3344
3328
  (prev, curr) => {
@@ -5869,14 +5853,14 @@ var generateSpoolQuickMethod = ({
5869
5853
  );
5870
5854
  }
5871
5855
  },
5872
- unstakeQuick: async (amount, stakeMarketCoinName, stakeAccountId) => {
5856
+ unstakeQuick: async (amount, stakeMarketCoinName, stakeAccountId, returnSCoin = true) => {
5873
5857
  const stakeAccounts = await requireStakeAccounts(
5874
5858
  builder,
5875
5859
  txBlock,
5876
5860
  stakeMarketCoinName,
5877
5861
  stakeAccountId
5878
5862
  );
5879
- const sCoins2 = [];
5863
+ const toTransfer = [];
5880
5864
  for (const account of stakeAccounts) {
5881
5865
  if (account.staked === 0)
5882
5866
  continue;
@@ -5886,29 +5870,47 @@ var generateSpoolQuickMethod = ({
5886
5870
  amountToUnstake,
5887
5871
  stakeMarketCoinName
5888
5872
  );
5889
- const sCoin = txBlock.mintSCoin(stakeMarketCoinName, marketCoin);
5890
- sCoins2.push(sCoin);
5873
+ if (returnSCoin) {
5874
+ const sCoin = txBlock.mintSCoin(stakeMarketCoinName, marketCoin);
5875
+ toTransfer.push(sCoin);
5876
+ } else {
5877
+ toTransfer.push(marketCoin);
5878
+ }
5891
5879
  amount -= amountToUnstake;
5892
5880
  if (amount === 0)
5893
5881
  break;
5894
5882
  }
5895
- if (sCoins2.length > 0) {
5896
- const mergedSCoin = sCoins2[0];
5897
- if (sCoins2.length > 1) {
5898
- txBlock.mergeCoins(mergedSCoin, sCoins2.slice(1));
5883
+ if (toTransfer.length > 0) {
5884
+ const mergedCoin = toTransfer[0];
5885
+ if (toTransfer.length > 1) {
5886
+ txBlock.mergeCoins(mergedCoin, toTransfer.slice(1));
5899
5887
  }
5900
- try {
5901
- const existingCoins = await builder.utils.selectCoins(
5902
- Number.MAX_SAFE_INTEGER,
5903
- builder.utils.parseSCoinType(stakeMarketCoinName),
5904
- requireSender(txBlock)
5905
- );
5906
- if (existingCoins.length > 0) {
5907
- txBlock.mergeCoins(mergedSCoin, existingCoins);
5888
+ if (returnSCoin) {
5889
+ try {
5890
+ const existingCoins = await builder.utils.selectCoins(
5891
+ Number.MAX_SAFE_INTEGER,
5892
+ builder.utils.parseSCoinType(stakeMarketCoinName),
5893
+ requireSender(txBlock)
5894
+ );
5895
+ if (existingCoins.length > 0) {
5896
+ txBlock.mergeCoins(mergedCoin, existingCoins);
5897
+ }
5898
+ } catch (e) {
5899
+ }
5900
+ } else {
5901
+ try {
5902
+ const existingCoins = await builder.utils.selectCoins(
5903
+ Number.MAX_SAFE_INTEGER,
5904
+ builder.utils.parseMarketCoinType(stakeMarketCoinName),
5905
+ requireSender(txBlock)
5906
+ );
5907
+ if (existingCoins.length > 0) {
5908
+ txBlock.mergeCoins(mergedCoin, existingCoins);
5909
+ }
5910
+ } catch (e) {
5908
5911
  }
5909
- } catch (e) {
5910
5912
  }
5911
- return mergedSCoin;
5913
+ return mergedCoin;
5912
5914
  }
5913
5915
  },
5914
5916
  claimQuick: async (stakeMarketCoinName, stakeAccountId) => {
@@ -7308,12 +7310,12 @@ var ScallopClient = class {
7308
7310
  const txBlock = this.builder.createTxBlock();
7309
7311
  const sender = walletAddress || this.walletAddress;
7310
7312
  txBlock.setSender(sender);
7311
- const marketCoin = await txBlock.unstakeQuick(
7313
+ const sCoin = await txBlock.unstakeQuick(
7312
7314
  amount,
7313
7315
  stakeMarketCoinName,
7314
7316
  stakeAccountId
7315
7317
  );
7316
- txBlock.transferObjects([marketCoin], sender);
7318
+ txBlock.transferObjects([sCoin], sender);
7317
7319
  if (sign) {
7318
7320
  return await this.suiKit.signAndSendTxn(
7319
7321
  txBlock
@@ -7329,12 +7331,15 @@ var ScallopClient = class {
7329
7331
  const stakeMarketCoin = await txBlock.unstakeQuick(
7330
7332
  amount,
7331
7333
  stakeMarketCoinName,
7332
- stakeAccountId
7334
+ stakeAccountId,
7335
+ false
7333
7336
  );
7334
7337
  const stakeCoinName = this.utils.parseCoinName(stakeMarketCoinName);
7335
7338
  if (stakeMarketCoin) {
7336
7339
  const coin = txBlock.withdraw(stakeMarketCoin, stakeCoinName);
7337
7340
  txBlock.transferObjects([coin], sender);
7341
+ } else {
7342
+ throw new Error(`No stake found for ${stakeMarketCoinName}`);
7338
7343
  }
7339
7344
  if (sign) {
7340
7345
  return await this.suiKit.signAndSendTxn(