@scallop-io/sui-scallop-sdk 0.46.46 → 0.46.48
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 +66 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -38
- 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 +50 -20
- package/src/models/scallopClient.ts +32 -24
- package/src/types/builder/spool.ts +3 -2
|
@@ -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, returnSCoin?: boolean): 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
|
@@ -249,14 +249,19 @@ const generateSpoolQuickMethod: GenerateSpoolQuickMethod = ({
|
|
|
249
249
|
);
|
|
250
250
|
}
|
|
251
251
|
},
|
|
252
|
-
unstakeQuick: async (
|
|
252
|
+
unstakeQuick: async (
|
|
253
|
+
amount,
|
|
254
|
+
stakeMarketCoinName,
|
|
255
|
+
stakeAccountId,
|
|
256
|
+
returnSCoin = true
|
|
257
|
+
) => {
|
|
253
258
|
const stakeAccounts = await requireStakeAccounts(
|
|
254
259
|
builder,
|
|
255
260
|
txBlock,
|
|
256
261
|
stakeMarketCoinName,
|
|
257
262
|
stakeAccountId
|
|
258
263
|
);
|
|
259
|
-
const
|
|
264
|
+
const toTransfer: TransactionResult[] = [];
|
|
260
265
|
for (const account of stakeAccounts) {
|
|
261
266
|
if (account.staked === 0) continue;
|
|
262
267
|
const amountToUnstake = Math.min(amount, account.staked);
|
|
@@ -267,32 +272,57 @@ const generateSpoolQuickMethod: GenerateSpoolQuickMethod = ({
|
|
|
267
272
|
);
|
|
268
273
|
|
|
269
274
|
// convert to new sCoin
|
|
270
|
-
|
|
271
|
-
|
|
275
|
+
if (returnSCoin) {
|
|
276
|
+
const sCoin = txBlock.mintSCoin(stakeMarketCoinName, marketCoin);
|
|
277
|
+
toTransfer.push(sCoin);
|
|
278
|
+
} else {
|
|
279
|
+
toTransfer.push(marketCoin);
|
|
280
|
+
}
|
|
281
|
+
|
|
272
282
|
amount -= amountToUnstake;
|
|
273
283
|
if (amount === 0) break;
|
|
274
284
|
}
|
|
275
285
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
txBlock.mergeCoins(mergedSCoin, sCoins.slice(1));
|
|
279
|
-
}
|
|
286
|
+
if (toTransfer.length > 0) {
|
|
287
|
+
const mergedCoin = toTransfer[0];
|
|
280
288
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
289
|
+
if (toTransfer.length > 1) {
|
|
290
|
+
txBlock.mergeCoins(mergedCoin, toTransfer.slice(1));
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (returnSCoin) {
|
|
294
|
+
// check for existing sCoins
|
|
295
|
+
try {
|
|
296
|
+
const existingCoins = await builder.utils.selectCoins(
|
|
297
|
+
Number.MAX_SAFE_INTEGER,
|
|
298
|
+
builder.utils.parseSCoinType(stakeMarketCoinName),
|
|
299
|
+
requireSender(txBlock)
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
if (existingCoins.length > 0) {
|
|
303
|
+
txBlock.mergeCoins(mergedCoin, existingCoins);
|
|
304
|
+
}
|
|
305
|
+
} catch (e) {
|
|
306
|
+
// ignore
|
|
307
|
+
}
|
|
308
|
+
} else {
|
|
309
|
+
// check for existing market coins
|
|
310
|
+
try {
|
|
311
|
+
const existingCoins = await builder.utils.selectCoins(
|
|
312
|
+
Number.MAX_SAFE_INTEGER,
|
|
313
|
+
builder.utils.parseMarketCoinType(stakeMarketCoinName),
|
|
314
|
+
requireSender(txBlock)
|
|
315
|
+
);
|
|
288
316
|
|
|
289
|
-
|
|
290
|
-
|
|
317
|
+
if (existingCoins.length > 0) {
|
|
318
|
+
txBlock.mergeCoins(mergedCoin, existingCoins);
|
|
319
|
+
}
|
|
320
|
+
} catch (e) {
|
|
321
|
+
// ignore
|
|
322
|
+
}
|
|
291
323
|
}
|
|
292
|
-
|
|
293
|
-
// ignore
|
|
324
|
+
return mergedCoin;
|
|
294
325
|
}
|
|
295
|
-
return mergedSCoin;
|
|
296
326
|
},
|
|
297
327
|
claimQuick: async (stakeMarketCoinName, stakeAccountId) => {
|
|
298
328
|
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
|
);
|
|
@@ -42,8 +42,9 @@ export type SpoolQuickMethods = {
|
|
|
42
42
|
unstakeQuick(
|
|
43
43
|
amount: number,
|
|
44
44
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
45
|
-
stakeAccountId?: SuiAddressArg
|
|
46
|
-
|
|
45
|
+
stakeAccountId?: SuiAddressArg,
|
|
46
|
+
returnSCoin?: boolean
|
|
47
|
+
): Promise<TransactionResult | undefined>;
|
|
47
48
|
claimQuick(
|
|
48
49
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
49
50
|
stakeAccountId?: SuiAddressArg
|