@scallop-io/sui-scallop-sdk 0.46.45 → 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 +46 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -40
- 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 +35 -31
- 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(
|
|
@@ -742,12 +742,12 @@ export class ScallopClient {
|
|
|
742
742
|
const sender = walletAddress || this.walletAddress;
|
|
743
743
|
txBlock.setSender(sender);
|
|
744
744
|
|
|
745
|
-
const
|
|
745
|
+
const marketCoin = await txBlock.unstakeQuick(
|
|
746
746
|
amount,
|
|
747
747
|
stakeMarketCoinName,
|
|
748
748
|
stakeAccountId
|
|
749
749
|
);
|
|
750
|
-
txBlock.transferObjects(
|
|
750
|
+
txBlock.transferObjects([marketCoin], sender);
|
|
751
751
|
|
|
752
752
|
if (sign) {
|
|
753
753
|
return (await this.suiKit.signAndSendTxn(
|
|
@@ -790,20 +790,17 @@ export class ScallopClient {
|
|
|
790
790
|
const sender = walletAddress || this.walletAddress;
|
|
791
791
|
txBlock.setSender(sender);
|
|
792
792
|
|
|
793
|
-
const
|
|
793
|
+
const stakeMarketCoin = await txBlock.unstakeQuick(
|
|
794
794
|
amount,
|
|
795
795
|
stakeMarketCoinName,
|
|
796
796
|
stakeAccountId
|
|
797
797
|
);
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
const stakeCoinName =
|
|
802
|
-
this.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName);
|
|
798
|
+
const stakeCoinName =
|
|
799
|
+
this.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName);
|
|
800
|
+
if (stakeMarketCoin) {
|
|
803
801
|
const coin = txBlock.withdraw(stakeMarketCoin, stakeCoinName);
|
|
804
|
-
|
|
802
|
+
txBlock.transferObjects([coin], sender);
|
|
805
803
|
}
|
|
806
|
-
txBlock.transferObjects(coins, sender);
|
|
807
804
|
|
|
808
805
|
if (sign) {
|
|
809
806
|
return (await this.suiKit.signAndSendTxn(
|
|
@@ -980,6 +977,7 @@ export class ScallopClient {
|
|
|
980
977
|
* First check marketCoin inside mini wallet
|
|
981
978
|
* Then check stakedMarketCoin inside spool
|
|
982
979
|
*/
|
|
980
|
+
const sCoins: SuiObjectArg[] = [];
|
|
983
981
|
let toDestroyMarketCoin: SuiObjectArg | undefined;
|
|
984
982
|
|
|
985
983
|
// check market coin in mini wallet
|
|
@@ -1003,26 +1001,6 @@ export class ScallopClient {
|
|
|
1003
1001
|
throw e;
|
|
1004
1002
|
}
|
|
1005
1003
|
|
|
1006
|
-
// check for staked market coin in spool
|
|
1007
|
-
if (SUPPORT_SPOOLS.includes(sCoinName as SupportStakeMarketCoins)) {
|
|
1008
|
-
try {
|
|
1009
|
-
const stakedMarketCoin = await txBlock.unstakeQuick(
|
|
1010
|
-
Number.MAX_SAFE_INTEGER,
|
|
1011
|
-
sCoinName as SupportStakeMarketCoins
|
|
1012
|
-
);
|
|
1013
|
-
// merge with takeMarketCoin
|
|
1014
|
-
if (toDestroyMarketCoin) {
|
|
1015
|
-
txBlock.mergeCoins(toDestroyMarketCoin, [stakedMarketCoin]);
|
|
1016
|
-
} else {
|
|
1017
|
-
toDestroyMarketCoin = stakedMarketCoin;
|
|
1018
|
-
}
|
|
1019
|
-
} catch (e: any) {
|
|
1020
|
-
// ignore
|
|
1021
|
-
const errMsg = e.toString();
|
|
1022
|
-
if (!errMsg.includes('No stake account found')) throw e;
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
1004
|
// if market coin found, mint sCoin
|
|
1027
1005
|
if (toDestroyMarketCoin) {
|
|
1028
1006
|
// mint new sCoin
|
|
@@ -1051,7 +1029,33 @@ export class ScallopClient {
|
|
|
1051
1029
|
if (!errMsg.includes('No valid coins found for the transaction'))
|
|
1052
1030
|
throw e;
|
|
1053
1031
|
}
|
|
1054
|
-
|
|
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);
|
|
1055
1059
|
}
|
|
1056
1060
|
})
|
|
1057
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
|