@scallop-io/sui-scallop-sdk 0.46.52 → 0.46.53

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "0.46.52",
3
+ "version": "0.46.53",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -90,15 +90,15 @@ const stakeHelper = async (
90
90
  builder: ScallopBuilder,
91
91
  txBlock: SuiTxBlockWithSpoolNormalMethods,
92
92
  stakeAccount: SuiAddressArg,
93
- coinType: string,
94
93
  coinName: SupportStakeMarketCoins,
95
94
  amount: number,
96
95
  sender: string,
97
96
  isSCoin: boolean = false
98
97
  ) => {
99
98
  try {
100
- const coins = await builder.utils.selectCoins(amount, coinType, sender);
101
- const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
99
+ const { takeCoin, leftCoin, totalAmount } = isSCoin
100
+ ? await builder.selectSCoin(txBlock, coinName, amount, sender)
101
+ : await builder.selectMarketCoin(txBlock, coinName, amount, sender);
102
102
  if (isSCoin) {
103
103
  const marketCoin = txBlock.burnSCoin(coinName, takeCoin);
104
104
  txBlock.stake(stakeAccount, marketCoin, coinName);
@@ -106,9 +106,9 @@ const stakeHelper = async (
106
106
  txBlock.stake(stakeAccount, takeCoin, coinName);
107
107
  }
108
108
  txBlock.transferObjects([leftCoin], sender);
109
- return true;
109
+ return totalAmount;
110
110
  } catch (e) {
111
- return false;
111
+ return 0;
112
112
  }
113
113
  };
114
114
 
@@ -213,28 +213,24 @@ const generateSpoolQuickMethod: GenerateSpoolQuickMethod = ({
213
213
  stakeAccountId
214
214
  );
215
215
 
216
- const marketCoinType =
217
- builder.utils.parseMarketCoinType(stakeMarketCoinName);
218
- const sCoinType = builder.utils.parseSCoinType(stakeMarketCoinName);
219
216
  if (typeof amountOrMarketCoin === 'number') {
220
217
  // try stake market coin
221
- const stakeMarketCoinRes = await stakeHelper(
218
+ const stakedMarketCoinAmount = await stakeHelper(
222
219
  builder,
223
220
  txBlock,
224
221
  stakeAccountIds[0],
225
- marketCoinType,
226
222
  stakeMarketCoinName,
227
223
  amountOrMarketCoin,
228
224
  sender
229
225
  );
230
226
 
227
+ amountOrMarketCoin -= stakedMarketCoinAmount;
231
228
  // no market coin, try sCoin
232
- if (!stakeMarketCoinRes) {
229
+ if (amountOrMarketCoin > 0) {
233
230
  await stakeHelper(
234
231
  builder,
235
232
  txBlock,
236
233
  stakeAccountIds[0],
237
- sCoinType,
238
234
  stakeMarketCoinName,
239
235
  amountOrMarketCoin,
240
236
  sender,
@@ -991,12 +991,10 @@ export class ScallopClient {
991
991
  this.walletAddress
992
992
  ); // throw error no coins found
993
993
 
994
- const mergedMarketCoin = marketCoins[0];
994
+ toDestroyMarketCoin = marketCoins[0];
995
995
  if (marketCoins.length > 1) {
996
- txBlock.mergeCoins(mergedMarketCoin, marketCoins.slice(1));
996
+ txBlock.mergeCoins(toDestroyMarketCoin, marketCoins.slice(1));
997
997
  }
998
-
999
- toDestroyMarketCoin = mergedMarketCoin;
1000
998
  } catch (e: any) {
1001
999
  // Ignore
1002
1000
  const errMsg = e.toString() as String;
@@ -1018,23 +1016,13 @@ export class ScallopClient {
1018
1016
  Number.MAX_SAFE_INTEGER,
1019
1017
  this.utils.parseSCoinType(sCoinName as SupportSCoin),
1020
1018
  this.walletAddress
1021
- ); // throw error on no coins found
1022
- const mergedSCoin = existSCoins[0];
1023
- if (existSCoins.length > 1) {
1024
- txBlock.mergeCoins(mergedSCoin, existSCoins.slice(1));
1025
- }
1026
-
1027
- // merge existing sCoin to new sCoin
1028
- txBlock.mergeCoins(sCoin, [mergedSCoin]);
1019
+ );
1020
+ txBlock.mergeCoins(sCoin, existSCoins);
1029
1021
  } catch (e: any) {
1030
1022
  // ignore
1031
- const errMsg = e.toString() as String;
1032
- if (!errMsg.includes('No valid coins found for the transaction'))
1033
- throw e;
1034
1023
  }
1035
1024
  sCoins.push(sCoin);
1036
1025
  }
1037
-
1038
1026
  // check for staked market coin in spool
1039
1027
  if (SUPPORT_SPOOLS.includes(sCoinName as SupportStakeMarketCoins)) {
1040
1028
  try {
@@ -1047,8 +1035,6 @@ export class ScallopClient {
1047
1035
  }
1048
1036
  } catch (e: any) {
1049
1037
  // ignore
1050
- const errMsg = e.toString();
1051
- if (!errMsg.includes('No stake account found')) throw e;
1052
1038
  }
1053
1039
  }
1054
1040