@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.mjs CHANGED
@@ -3245,26 +3245,10 @@ var getPythPrice = async (query, assetCoinName, priceFeedObject) => {
3245
3245
  return 0;
3246
3246
  };
3247
3247
  var getPythPrices = async (query, assetCoinNames) => {
3248
- const seen = {};
3249
- const pythFeedObjectIds = assetCoinNames.map((assetCoinName) => {
3250
- const pythFeedObjectId = query.address.get(
3251
- `core.coins.${assetCoinName}.oracle.pyth.feedObject`
3252
- );
3253
- if (seen[pythFeedObjectId])
3254
- return null;
3255
- seen[pythFeedObjectId] = true;
3256
- return pythFeedObjectId;
3257
- }).filter((item) => !!item);
3258
- const priceFeedObjects = await query.cache.queryGetObjects(
3259
- pythFeedObjectIds,
3260
- {
3261
- showContent: true
3262
- }
3263
- );
3264
3248
  return (await Promise.all(
3265
- priceFeedObjects.map(async (priceFeedObject, idx) => ({
3266
- coinName: assetCoinNames[idx],
3267
- price: await getPythPrice(query, assetCoinNames[idx], priceFeedObject)
3249
+ assetCoinNames.map(async (assetCoinName) => ({
3250
+ coinName: assetCoinName,
3251
+ price: await getPythPrice(query, assetCoinName)
3268
3252
  }))
3269
3253
  )).reduce(
3270
3254
  (prev, curr) => {
@@ -5798,14 +5782,14 @@ var generateSpoolQuickMethod = ({
5798
5782
  );
5799
5783
  }
5800
5784
  },
5801
- unstakeQuick: async (amount, stakeMarketCoinName, stakeAccountId) => {
5785
+ unstakeQuick: async (amount, stakeMarketCoinName, stakeAccountId, returnSCoin = true) => {
5802
5786
  const stakeAccounts = await requireStakeAccounts(
5803
5787
  builder,
5804
5788
  txBlock,
5805
5789
  stakeMarketCoinName,
5806
5790
  stakeAccountId
5807
5791
  );
5808
- const sCoins2 = [];
5792
+ const toTransfer = [];
5809
5793
  for (const account of stakeAccounts) {
5810
5794
  if (account.staked === 0)
5811
5795
  continue;
@@ -5815,29 +5799,47 @@ var generateSpoolQuickMethod = ({
5815
5799
  amountToUnstake,
5816
5800
  stakeMarketCoinName
5817
5801
  );
5818
- const sCoin = txBlock.mintSCoin(stakeMarketCoinName, marketCoin);
5819
- sCoins2.push(sCoin);
5802
+ if (returnSCoin) {
5803
+ const sCoin = txBlock.mintSCoin(stakeMarketCoinName, marketCoin);
5804
+ toTransfer.push(sCoin);
5805
+ } else {
5806
+ toTransfer.push(marketCoin);
5807
+ }
5820
5808
  amount -= amountToUnstake;
5821
5809
  if (amount === 0)
5822
5810
  break;
5823
5811
  }
5824
- if (sCoins2.length > 0) {
5825
- const mergedSCoin = sCoins2[0];
5826
- if (sCoins2.length > 1) {
5827
- txBlock.mergeCoins(mergedSCoin, sCoins2.slice(1));
5812
+ if (toTransfer.length > 0) {
5813
+ const mergedCoin = toTransfer[0];
5814
+ if (toTransfer.length > 1) {
5815
+ txBlock.mergeCoins(mergedCoin, toTransfer.slice(1));
5828
5816
  }
5829
- try {
5830
- const existingCoins = await builder.utils.selectCoins(
5831
- Number.MAX_SAFE_INTEGER,
5832
- builder.utils.parseSCoinType(stakeMarketCoinName),
5833
- requireSender(txBlock)
5834
- );
5835
- if (existingCoins.length > 0) {
5836
- txBlock.mergeCoins(mergedSCoin, existingCoins);
5817
+ if (returnSCoin) {
5818
+ try {
5819
+ const existingCoins = await builder.utils.selectCoins(
5820
+ Number.MAX_SAFE_INTEGER,
5821
+ builder.utils.parseSCoinType(stakeMarketCoinName),
5822
+ requireSender(txBlock)
5823
+ );
5824
+ if (existingCoins.length > 0) {
5825
+ txBlock.mergeCoins(mergedCoin, existingCoins);
5826
+ }
5827
+ } catch (e) {
5828
+ }
5829
+ } else {
5830
+ try {
5831
+ const existingCoins = await builder.utils.selectCoins(
5832
+ Number.MAX_SAFE_INTEGER,
5833
+ builder.utils.parseMarketCoinType(stakeMarketCoinName),
5834
+ requireSender(txBlock)
5835
+ );
5836
+ if (existingCoins.length > 0) {
5837
+ txBlock.mergeCoins(mergedCoin, existingCoins);
5838
+ }
5839
+ } catch (e) {
5837
5840
  }
5838
- } catch (e) {
5839
5841
  }
5840
- return mergedSCoin;
5842
+ return mergedCoin;
5841
5843
  }
5842
5844
  },
5843
5845
  claimQuick: async (stakeMarketCoinName, stakeAccountId) => {
@@ -7248,12 +7250,12 @@ var ScallopClient = class {
7248
7250
  const txBlock = this.builder.createTxBlock();
7249
7251
  const sender = walletAddress || this.walletAddress;
7250
7252
  txBlock.setSender(sender);
7251
- const marketCoin = await txBlock.unstakeQuick(
7253
+ const sCoin = await txBlock.unstakeQuick(
7252
7254
  amount,
7253
7255
  stakeMarketCoinName,
7254
7256
  stakeAccountId
7255
7257
  );
7256
- txBlock.transferObjects([marketCoin], sender);
7258
+ txBlock.transferObjects([sCoin], sender);
7257
7259
  if (sign) {
7258
7260
  return await this.suiKit.signAndSendTxn(
7259
7261
  txBlock
@@ -7269,12 +7271,15 @@ var ScallopClient = class {
7269
7271
  const stakeMarketCoin = await txBlock.unstakeQuick(
7270
7272
  amount,
7271
7273
  stakeMarketCoinName,
7272
- stakeAccountId
7274
+ stakeAccountId,
7275
+ false
7273
7276
  );
7274
7277
  const stakeCoinName = this.utils.parseCoinName(stakeMarketCoinName);
7275
7278
  if (stakeMarketCoin) {
7276
7279
  const coin = txBlock.withdraw(stakeMarketCoin, stakeCoinName);
7277
7280
  txBlock.transferObjects([coin], sender);
7281
+ } else {
7282
+ throw new Error(`No stake found for ${stakeMarketCoinName}`);
7278
7283
  }
7279
7284
  if (sign) {
7280
7285
  return await this.suiKit.signAndSendTxn(