@scallop-io/sui-scallop-sdk 2.0.7 → 2.0.8
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.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/models/scallopClient.ts +66 -77
package/package.json
CHANGED
|
@@ -1001,89 +1001,80 @@ export class ScallopClient {
|
|
|
1001
1001
|
*/
|
|
1002
1002
|
public async migrateAllMarketCoin<S extends boolean>(
|
|
1003
1003
|
includeStakePool: boolean = true,
|
|
1004
|
-
sign: S = true as S
|
|
1004
|
+
sign: S = true as S,
|
|
1005
|
+
walletAddress?: string
|
|
1005
1006
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
1007
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
1006
1008
|
const txBlock = this.builder.createTxBlock();
|
|
1007
|
-
txBlock.setSender(
|
|
1009
|
+
txBlock.setSender(sender);
|
|
1008
1010
|
|
|
1009
1011
|
const toTransfer: SuiObjectArg[] = [];
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
toDestroyMarketCoin = marketCoins[0];
|
|
1028
|
-
if (marketCoins.length > 1) {
|
|
1029
|
-
txBlock.mergeCoins(toDestroyMarketCoin, marketCoins.slice(1));
|
|
1030
|
-
}
|
|
1031
|
-
} catch (e: any) {
|
|
1032
|
-
// Ignore
|
|
1033
|
-
const errMsg = e.toString() as String;
|
|
1034
|
-
if (!errMsg.includes('No valid coins found for the transaction'))
|
|
1035
|
-
throw e;
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
// if market coin found, mint sCoin
|
|
1039
|
-
if (toDestroyMarketCoin) {
|
|
1012
|
+
for (const sCoinName of this.constants.whitelist.scoin) {
|
|
1013
|
+
/**
|
|
1014
|
+
* First check marketCoin inside mini wallet
|
|
1015
|
+
* Then check stakedMarketCoin inside spool
|
|
1016
|
+
*/
|
|
1017
|
+
const sCoins: SuiObjectArg[] = [];
|
|
1018
|
+
|
|
1019
|
+
// check market coin in mini wallet
|
|
1020
|
+
try {
|
|
1021
|
+
const { takeCoin } = await this.builder.selectMarketCoin(
|
|
1022
|
+
txBlock,
|
|
1023
|
+
sCoinName,
|
|
1024
|
+
Number.MAX_SAFE_INTEGER,
|
|
1025
|
+
sender
|
|
1026
|
+
); // throw error no coins found
|
|
1027
|
+
|
|
1028
|
+
if (takeCoin) {
|
|
1040
1029
|
// mint new sCoin
|
|
1041
|
-
const sCoin = txBlock.mintSCoin(
|
|
1042
|
-
sCoinName as string,
|
|
1043
|
-
toDestroyMarketCoin
|
|
1044
|
-
);
|
|
1045
|
-
|
|
1046
|
-
const sCoinType = this.utils.parseSCoinType(sCoinName as string);
|
|
1047
|
-
if (!sCoinType) throw new Error('Invalid sCoin type');
|
|
1048
|
-
// Merge with existing sCoin
|
|
1049
|
-
await this.utils.mergeSimilarCoins(
|
|
1050
|
-
txBlock,
|
|
1051
|
-
sCoin,
|
|
1052
|
-
sCoinType,
|
|
1053
|
-
requireSender(txBlock)
|
|
1054
|
-
);
|
|
1030
|
+
const sCoin = txBlock.mintSCoin(sCoinName as string, takeCoin);
|
|
1055
1031
|
sCoins.push(sCoin);
|
|
1056
1032
|
}
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1033
|
+
} catch (e: any) {
|
|
1034
|
+
// Ignore
|
|
1035
|
+
const errMsg = e.toString() as String;
|
|
1036
|
+
if (!errMsg.includes('No valid coins found for the transaction'))
|
|
1037
|
+
throw e;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
// if market coin found, mint sCoin
|
|
1041
|
+
if (includeStakePool) {
|
|
1042
|
+
// check for staked market coin in spool
|
|
1043
|
+
if (this.constants.whitelist.spool.has(sCoinName as string)) {
|
|
1044
|
+
try {
|
|
1045
|
+
const sCoin = await txBlock.unstakeQuick(
|
|
1046
|
+
Number.MAX_SAFE_INTEGER,
|
|
1047
|
+
sCoinName as string
|
|
1048
|
+
);
|
|
1049
|
+
if (sCoin) {
|
|
1050
|
+
sCoins.push(sCoin);
|
|
1070
1051
|
}
|
|
1052
|
+
} catch (_e: any) {
|
|
1053
|
+
// ignore
|
|
1071
1054
|
}
|
|
1072
1055
|
}
|
|
1056
|
+
}
|
|
1073
1057
|
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
toTransfer.push(mergedSCoin);
|
|
1058
|
+
if (sCoins.length > 0) {
|
|
1059
|
+
const mergedSCoin = sCoins[0];
|
|
1060
|
+
if (sCoins.length > 1) {
|
|
1061
|
+
txBlock.mergeCoins(mergedSCoin, sCoins.slice(1));
|
|
1081
1062
|
}
|
|
1082
|
-
|
|
1083
|
-
|
|
1063
|
+
const sCoinType = this.utils.parseSCoinType(sCoinName as string);
|
|
1064
|
+
|
|
1065
|
+
// Merge with existing sCoin in wallet
|
|
1066
|
+
await this.utils.mergeSimilarCoins(
|
|
1067
|
+
txBlock,
|
|
1068
|
+
mergedSCoin,
|
|
1069
|
+
sCoinType,
|
|
1070
|
+
sender
|
|
1071
|
+
);
|
|
1072
|
+
toTransfer.push(mergedSCoin);
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1084
1075
|
|
|
1085
1076
|
if (toTransfer.length > 0) {
|
|
1086
|
-
txBlock.transferObjects(toTransfer,
|
|
1077
|
+
txBlock.transferObjects(toTransfer, sender);
|
|
1087
1078
|
}
|
|
1088
1079
|
|
|
1089
1080
|
if (sign) {
|
|
@@ -1101,15 +1092,18 @@ export class ScallopClient {
|
|
|
1101
1092
|
*/
|
|
1102
1093
|
public async claimAllUnlockedSca(): Promise<SuiTransactionBlockResponse>;
|
|
1103
1094
|
public async claimAllUnlockedSca<S extends boolean>(
|
|
1095
|
+
walletAddress?: string,
|
|
1104
1096
|
sign?: S
|
|
1105
1097
|
): Promise<ScallopClientVeScaReturnType<S>>;
|
|
1106
1098
|
public async claimAllUnlockedSca<S extends boolean>(
|
|
1099
|
+
walletAddress?: string,
|
|
1107
1100
|
sign: S = true as S
|
|
1108
1101
|
): Promise<ScallopClientVeScaReturnType<S>> {
|
|
1102
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
1109
1103
|
// get all veSca keys
|
|
1110
1104
|
const veScaKeys = (
|
|
1111
1105
|
(await this.query.getVeScas({
|
|
1112
|
-
walletAddress:
|
|
1106
|
+
walletAddress: sender,
|
|
1113
1107
|
})) ?? []
|
|
1114
1108
|
).map(({ keyObject }) => keyObject);
|
|
1115
1109
|
if (veScaKeys.length === 0) {
|
|
@@ -1118,7 +1112,7 @@ export class ScallopClient {
|
|
|
1118
1112
|
|
|
1119
1113
|
const scaCoins: TransactionResult[] = [];
|
|
1120
1114
|
const tx = this.builder.createTxBlock();
|
|
1121
|
-
tx.setSender(
|
|
1115
|
+
tx.setSender(sender);
|
|
1122
1116
|
|
|
1123
1117
|
await Promise.all(
|
|
1124
1118
|
veScaKeys.map(async (key) => {
|
|
@@ -1139,12 +1133,7 @@ export class ScallopClient {
|
|
|
1139
1133
|
if (scaCoins.length > 1) {
|
|
1140
1134
|
tx.mergeCoins(scaCoins[0], scaCoins.slice(1));
|
|
1141
1135
|
}
|
|
1142
|
-
await this.utils.mergeSimilarCoins(
|
|
1143
|
-
tx,
|
|
1144
|
-
scaCoins[0],
|
|
1145
|
-
'sca',
|
|
1146
|
-
this.walletAddress
|
|
1147
|
-
);
|
|
1136
|
+
await this.utils.mergeSimilarCoins(tx, scaCoins[0], 'sca', sender);
|
|
1148
1137
|
|
|
1149
1138
|
if (sign) {
|
|
1150
1139
|
return (await this.suiKit.signAndSendTxn(
|