@scallop-io/sui-scallop-sdk 0.46.46 → 0.46.47
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 +44 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -34
- package/dist/index.mjs.map +1 -1
- package/dist/types/builder/spool.d.ts +1 -1
- package/package.json +1 -1
- package/src/builders/spoolBuilder.ts +18 -16
- package/src/models/scallopClient.ts +32 -24
- package/src/types/builder/spool.ts +1 -1
|
@@ -14,7 +14,7 @@ export type SpoolNormalMethods = {
|
|
|
14
14
|
};
|
|
15
15
|
export type SpoolQuickMethods = {
|
|
16
16
|
stakeQuick(amountOrMarketCoin: SuiObjectArg | number, stakeMarketCoinName: SupportStakeMarketCoins, stakeAccountId?: SuiAddressArg): Promise<void>;
|
|
17
|
-
unstakeQuick(amount: number, stakeMarketCoinName: SupportStakeMarketCoins, stakeAccountId?: SuiAddressArg): Promise<TransactionResult>;
|
|
17
|
+
unstakeQuick(amount: number, stakeMarketCoinName: SupportStakeMarketCoins, stakeAccountId?: SuiAddressArg): Promise<TransactionResult | undefined>;
|
|
18
18
|
claimQuick(stakeMarketCoinName: SupportStakeMarketCoins, stakeAccountId?: SuiAddressArg): Promise<TransactionResult[]>;
|
|
19
19
|
};
|
|
20
20
|
export type SuiTxBlockWithSpoolNormalMethods = SuiKitTxBlock & SuiTxBlockWithSCoin & SpoolNormalMethods;
|
package/package.json
CHANGED
|
@@ -273,26 +273,28 @@ const generateSpoolQuickMethod: GenerateSpoolQuickMethod = ({
|
|
|
273
273
|
if (amount === 0) break;
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
txBlock.mergeCoins(mergedSCoin, sCoins.slice(1));
|
|
279
|
-
}
|
|
276
|
+
if (sCoins.length > 0) {
|
|
277
|
+
const mergedSCoin = sCoins[0];
|
|
280
278
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
279
|
+
if (sCoins.length > 1) {
|
|
280
|
+
txBlock.mergeCoins(mergedSCoin, sCoins.slice(1));
|
|
281
|
+
}
|
|
282
|
+
// check for existing sCoins
|
|
283
|
+
try {
|
|
284
|
+
const existingCoins = await builder.utils.selectCoins(
|
|
285
|
+
Number.MAX_SAFE_INTEGER,
|
|
286
|
+
builder.utils.parseSCoinType(stakeMarketCoinName),
|
|
287
|
+
requireSender(txBlock)
|
|
288
|
+
);
|
|
288
289
|
|
|
289
|
-
|
|
290
|
-
|
|
290
|
+
if (existingCoins.length > 0) {
|
|
291
|
+
txBlock.mergeCoins(mergedSCoin, existingCoins);
|
|
292
|
+
}
|
|
293
|
+
} catch (e) {
|
|
294
|
+
// ignore
|
|
291
295
|
}
|
|
292
|
-
|
|
293
|
-
// ignore
|
|
296
|
+
return mergedSCoin;
|
|
294
297
|
}
|
|
295
|
-
return mergedSCoin;
|
|
296
298
|
},
|
|
297
299
|
claimQuick: async (stakeMarketCoinName, stakeAccountId) => {
|
|
298
300
|
const stakeAccountIds = await requireStakeAccountIds(
|
|
@@ -797,9 +797,10 @@ export class ScallopClient {
|
|
|
797
797
|
);
|
|
798
798
|
const stakeCoinName =
|
|
799
799
|
this.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName);
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
800
|
+
if (stakeMarketCoin) {
|
|
801
|
+
const coin = txBlock.withdraw(stakeMarketCoin, stakeCoinName);
|
|
802
|
+
txBlock.transferObjects([coin], sender);
|
|
803
|
+
}
|
|
803
804
|
|
|
804
805
|
if (sign) {
|
|
805
806
|
return (await this.suiKit.signAndSendTxn(
|
|
@@ -976,6 +977,7 @@ export class ScallopClient {
|
|
|
976
977
|
* First check marketCoin inside mini wallet
|
|
977
978
|
* Then check stakedMarketCoin inside spool
|
|
978
979
|
*/
|
|
980
|
+
const sCoins: SuiObjectArg[] = [];
|
|
979
981
|
let toDestroyMarketCoin: SuiObjectArg | undefined;
|
|
980
982
|
|
|
981
983
|
// check market coin in mini wallet
|
|
@@ -999,26 +1001,6 @@ export class ScallopClient {
|
|
|
999
1001
|
throw e;
|
|
1000
1002
|
}
|
|
1001
1003
|
|
|
1002
|
-
// check for staked market coin in spool
|
|
1003
|
-
if (SUPPORT_SPOOLS.includes(sCoinName as SupportStakeMarketCoins)) {
|
|
1004
|
-
try {
|
|
1005
|
-
const stakedMarketCoin = await txBlock.unstakeQuick(
|
|
1006
|
-
Number.MAX_SAFE_INTEGER,
|
|
1007
|
-
sCoinName as SupportStakeMarketCoins
|
|
1008
|
-
);
|
|
1009
|
-
// merge with takeMarketCoin
|
|
1010
|
-
if (toDestroyMarketCoin) {
|
|
1011
|
-
txBlock.mergeCoins(toDestroyMarketCoin, [stakedMarketCoin]);
|
|
1012
|
-
} else {
|
|
1013
|
-
toDestroyMarketCoin = stakedMarketCoin;
|
|
1014
|
-
}
|
|
1015
|
-
} catch (e: any) {
|
|
1016
|
-
// ignore
|
|
1017
|
-
const errMsg = e.toString();
|
|
1018
|
-
if (!errMsg.includes('No stake account found')) throw e;
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
1004
|
// if market coin found, mint sCoin
|
|
1023
1005
|
if (toDestroyMarketCoin) {
|
|
1024
1006
|
// mint new sCoin
|
|
@@ -1047,7 +1029,33 @@ export class ScallopClient {
|
|
|
1047
1029
|
if (!errMsg.includes('No valid coins found for the transaction'))
|
|
1048
1030
|
throw e;
|
|
1049
1031
|
}
|
|
1050
|
-
|
|
1032
|
+
sCoins.push(sCoin);
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
// check for staked market coin in spool
|
|
1036
|
+
if (SUPPORT_SPOOLS.includes(sCoinName as SupportStakeMarketCoins)) {
|
|
1037
|
+
try {
|
|
1038
|
+
const sCoin = await txBlock.unstakeQuick(
|
|
1039
|
+
Number.MAX_SAFE_INTEGER,
|
|
1040
|
+
sCoinName as SupportStakeMarketCoins
|
|
1041
|
+
);
|
|
1042
|
+
if (sCoin) {
|
|
1043
|
+
sCoins.push(sCoin);
|
|
1044
|
+
}
|
|
1045
|
+
} catch (e: any) {
|
|
1046
|
+
// ignore
|
|
1047
|
+
const errMsg = e.toString();
|
|
1048
|
+
if (!errMsg.includes('No stake account found')) throw e;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
if (sCoins.length > 0) {
|
|
1053
|
+
const mergedSCoin = sCoins[0];
|
|
1054
|
+
if (sCoins.length > 1) {
|
|
1055
|
+
txBlock.mergeCoins(mergedSCoin, sCoins.slice(1));
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
toTransfer.push(mergedSCoin);
|
|
1051
1059
|
}
|
|
1052
1060
|
})
|
|
1053
1061
|
);
|
|
@@ -43,7 +43,7 @@ export type SpoolQuickMethods = {
|
|
|
43
43
|
amount: number,
|
|
44
44
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
45
45
|
stakeAccountId?: SuiAddressArg
|
|
46
|
-
): Promise<TransactionResult>;
|
|
46
|
+
): Promise<TransactionResult | undefined>;
|
|
47
47
|
claimQuick(
|
|
48
48
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
49
49
|
stakeAccountId?: SuiAddressArg
|