@scallop-io/sui-kit 2.1.0 → 2.2.0
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/README.md +6 -6
- package/dist/index.cjs +11 -11
- package/dist/index.d.cts +69 -69
- package/dist/index.d.ts +69 -69
- package/dist/index.js +7 -7
- package/package.json +163 -164
- package/src/index.ts +11 -11
- package/src/libs/multiSig/client.ts +35 -35
- package/src/libs/multiSig/index.ts +1 -1
- package/src/libs/multiSig/publickey.ts +8 -8
- package/src/libs/suiAccountManager/crypto.ts +4 -4
- package/src/libs/suiAccountManager/index.ts +82 -82
- package/src/libs/suiAccountManager/keypair.ts +13 -13
- package/src/libs/suiAccountManager/util.ts +20 -20
- package/src/libs/suiInteractor/index.ts +6 -6
- package/src/libs/suiInteractor/suiInteractor.ts +279 -272
- package/src/libs/suiInteractor/util.ts +6 -6
- package/src/libs/suiModel/index.ts +2 -2
- package/src/libs/suiModel/suiOwnedObject.ts +57 -57
- package/src/libs/suiModel/suiSharedObject.ts +27 -27
- package/src/libs/suiTxBuilder/index.ts +303 -302
- package/src/libs/suiTxBuilder/util.ts +185 -183
- package/src/suiKit.ts +422 -410
- package/src/types/index.ts +71 -76
package/src/suiKit.ts
CHANGED
|
@@ -1,450 +1,462 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description This file is used to aggregate the tools that used to interact with SUI network.
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
|
|
5
|
+
import type { ClientWithCoreApi } from "@mysten/sui/client";
|
|
6
|
+
import type { Transaction } from "@mysten/sui/transactions";
|
|
7
|
+
import { normalizeStructTag, SUI_TYPE_ARG } from "@mysten/sui/utils";
|
|
8
|
+
import { SuiAccountManager } from "./libs/suiAccountManager/index.js";
|
|
7
9
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from
|
|
13
|
-
import type {
|
|
10
|
+
getFullnodeUrl,
|
|
11
|
+
type SimulateTransactionResponse,
|
|
12
|
+
SuiInteractor,
|
|
13
|
+
type SuiObjectDataOptions,
|
|
14
|
+
} from "./libs/suiInteractor/index.js";
|
|
15
|
+
import type { SuiOwnedObject, SuiSharedObject } from "./libs/suiModel/index.js";
|
|
16
|
+
import { SuiTxBlock } from "./libs/suiTxBuilder/index.js";
|
|
14
17
|
import type {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
DerivePathParams,
|
|
19
|
+
NetworkType,
|
|
20
|
+
SuiAmountsArg,
|
|
21
|
+
SuiKitParams,
|
|
22
|
+
SuiKitReturnType,
|
|
23
|
+
SuiObjectArg,
|
|
24
|
+
SuiTransactionBlockResponse,
|
|
25
|
+
SuiTxArg,
|
|
26
|
+
SuiVecTxArg,
|
|
27
|
+
} from "./types/index.js";
|
|
25
28
|
|
|
26
29
|
/**
|
|
27
30
|
* @class SuiKit
|
|
28
31
|
* @description This class is used to aggregate the tools that used to interact with SUI network.
|
|
29
32
|
*/
|
|
30
33
|
export class SuiKit {
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
public accountManager: SuiAccountManager;
|
|
35
|
+
public suiInteractor: SuiInteractor;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Support the following ways to init the SuiToolkit:
|
|
39
|
+
* 1. mnemonics
|
|
40
|
+
* 2. secretKey (base64 or hex)
|
|
41
|
+
* If none of them is provided, will generate a random mnemonics with 24 words.
|
|
42
|
+
*
|
|
43
|
+
* @param mnemonics, 12 or 24 mnemonics words, separated by space
|
|
44
|
+
* @param secretKey, base64 or hex string or bech32, when mnemonics is provided, secretKey will be ignored
|
|
45
|
+
* @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'mainnet'
|
|
46
|
+
* @param fullnodeUrls, the fullnode url, default is the preconfig fullnode url for the given network type
|
|
47
|
+
*/
|
|
48
|
+
constructor(params: SuiKitParams) {
|
|
49
|
+
const { mnemonics, secretKey, networkType } = params;
|
|
50
|
+
// Init the account manager
|
|
51
|
+
this.accountManager = new SuiAccountManager({ mnemonics, secretKey });
|
|
33
52
|
|
|
34
|
-
|
|
35
|
-
* Support the following ways to init the SuiToolkit:
|
|
36
|
-
* 1. mnemonics
|
|
37
|
-
* 2. secretKey (base64 or hex)
|
|
38
|
-
* If none of them is provided, will generate a random mnemonics with 24 words.
|
|
39
|
-
*
|
|
40
|
-
* @param mnemonics, 12 or 24 mnemonics words, separated by space
|
|
41
|
-
* @param secretKey, base64 or hex string or bech32, when mnemonics is provided, secretKey will be ignored
|
|
42
|
-
* @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'mainnet'
|
|
43
|
-
* @param fullnodeUrls, the fullnode url, default is the preconfig fullnode url for the given network type
|
|
44
|
-
*/
|
|
45
|
-
constructor(params: SuiKitParams) {
|
|
46
|
-
const { mnemonics, secretKey, networkType } = params;
|
|
47
|
-
// Init the account manager
|
|
48
|
-
this.accountManager = new SuiAccountManager({ mnemonics, secretKey });
|
|
53
|
+
const network = networkType ?? "mainnet";
|
|
49
54
|
|
|
50
|
-
|
|
55
|
+
let suiInteractorParams:
|
|
56
|
+
| {
|
|
57
|
+
fullnodeUrls: string[] | undefined;
|
|
58
|
+
network: NetworkType;
|
|
59
|
+
}
|
|
60
|
+
| {
|
|
61
|
+
suiClients: ClientWithCoreApi[] | undefined;
|
|
62
|
+
};
|
|
51
63
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
64
|
+
if ("fullnodeUrls" in params) {
|
|
65
|
+
suiInteractorParams = {
|
|
66
|
+
fullnodeUrls: params.fullnodeUrls,
|
|
67
|
+
network,
|
|
68
|
+
};
|
|
69
|
+
} else if ("suiClients" in params) {
|
|
70
|
+
suiInteractorParams = { suiClients: params.suiClients };
|
|
71
|
+
} else {
|
|
72
|
+
suiInteractorParams = {
|
|
73
|
+
fullnodeUrls: [getFullnodeUrl(network)],
|
|
74
|
+
network,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
66
77
|
|
|
67
|
-
|
|
68
|
-
|
|
78
|
+
this.suiInteractor = new SuiInteractor(suiInteractorParams);
|
|
79
|
+
}
|
|
69
80
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Create SuiTxBlock with sender set to the current signer
|
|
83
|
+
* @returns SuiTxBlock with sender set to the current signer
|
|
84
|
+
*/
|
|
85
|
+
createTxBlock(): SuiTxBlock {
|
|
86
|
+
const txb = new SuiTxBlock();
|
|
87
|
+
txb.setSender(this.accountManager.currentAddress);
|
|
88
|
+
return txb;
|
|
89
|
+
}
|
|
79
90
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
/**
|
|
92
|
+
* if derivePathParams is not provided or mnemonics is empty, it will return the keypair.
|
|
93
|
+
* else:
|
|
94
|
+
* it will generate signer from the mnemonic with the given derivePathParams.
|
|
95
|
+
* @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
|
|
96
|
+
*/
|
|
97
|
+
getKeypair(derivePathParams?: DerivePathParams) {
|
|
98
|
+
return this.accountManager.getKeyPair(derivePathParams);
|
|
99
|
+
}
|
|
89
100
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
101
|
+
/**
|
|
102
|
+
* @description Switch the current account with the given derivePathParams
|
|
103
|
+
* @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
|
|
104
|
+
*/
|
|
105
|
+
switchAccount(derivePathParams: DerivePathParams) {
|
|
106
|
+
this.accountManager.switchAccount(derivePathParams);
|
|
107
|
+
}
|
|
97
108
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
109
|
+
/**
|
|
110
|
+
* @description Get the address of the account for the given derivePathParams
|
|
111
|
+
* @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
|
|
112
|
+
*/
|
|
113
|
+
getAddress(derivePathParams?: DerivePathParams) {
|
|
114
|
+
return this.accountManager.getAddress(derivePathParams);
|
|
115
|
+
}
|
|
105
116
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
117
|
+
get currentAddress() {
|
|
118
|
+
return this.accountManager.currentAddress;
|
|
119
|
+
}
|
|
109
120
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
121
|
+
async getBalance(coinType?: string, derivePathParams?: DerivePathParams) {
|
|
122
|
+
const owner = this.accountManager.getAddress(derivePathParams);
|
|
123
|
+
const { balance } = await this.suiInteractor.currentClient.core.getBalance({
|
|
124
|
+
owner,
|
|
125
|
+
coinType,
|
|
126
|
+
});
|
|
127
|
+
return balance;
|
|
128
|
+
}
|
|
118
129
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
130
|
+
get client() {
|
|
131
|
+
return this.suiInteractor.currentClient;
|
|
132
|
+
}
|
|
122
133
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
134
|
+
async getObjects(
|
|
135
|
+
objectIds: string[],
|
|
136
|
+
options?: {
|
|
137
|
+
include?: SuiObjectDataOptions;
|
|
138
|
+
batchSize?: number;
|
|
139
|
+
switchClientDelay?: number;
|
|
140
|
+
},
|
|
141
|
+
) {
|
|
142
|
+
return this.suiInteractor.getObjects(objectIds, options);
|
|
143
|
+
}
|
|
133
144
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
145
|
+
/**
|
|
146
|
+
* @description Update objects in a batch
|
|
147
|
+
* @param suiObjects
|
|
148
|
+
*/
|
|
149
|
+
async updateObjects(suiObjects: (SuiSharedObject | SuiOwnedObject)[]) {
|
|
150
|
+
return this.suiInteractor.updateObjects(suiObjects);
|
|
151
|
+
}
|
|
141
152
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
async signTxn(
|
|
154
|
+
tx: Uint8Array | Transaction | SuiTxBlock,
|
|
155
|
+
derivePathParams?: DerivePathParams,
|
|
156
|
+
) {
|
|
157
|
+
if (tx instanceof SuiTxBlock) {
|
|
158
|
+
tx.setSender(this.getAddress(derivePathParams));
|
|
159
|
+
}
|
|
160
|
+
const txBlock = tx instanceof SuiTxBlock ? tx.txBlock : tx;
|
|
161
|
+
const txBytes =
|
|
162
|
+
txBlock instanceof Uint8Array
|
|
163
|
+
? txBlock
|
|
164
|
+
: await txBlock.build({ client: this.client });
|
|
165
|
+
const keyPair = this.getKeypair(derivePathParams);
|
|
166
|
+
return await keyPair.signTransaction(txBytes);
|
|
167
|
+
}
|
|
157
168
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
169
|
+
async signAndSendTxn(
|
|
170
|
+
tx: Uint8Array | Transaction | SuiTxBlock,
|
|
171
|
+
derivePathParams?: DerivePathParams,
|
|
172
|
+
): Promise<SuiTransactionBlockResponse> {
|
|
173
|
+
const { bytes, signature } = await this.signTxn(tx, derivePathParams);
|
|
174
|
+
return this.suiInteractor.sendTx(bytes, signature);
|
|
175
|
+
}
|
|
165
176
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
177
|
+
async dryRunTxn(
|
|
178
|
+
tx: Uint8Array | Transaction | SuiTxBlock,
|
|
179
|
+
derivePathParams?: DerivePathParams,
|
|
180
|
+
): Promise<SimulateTransactionResponse> {
|
|
181
|
+
if (tx instanceof SuiTxBlock) {
|
|
182
|
+
tx.setSender(this.getAddress(derivePathParams));
|
|
183
|
+
}
|
|
184
|
+
const txBlock = tx instanceof SuiTxBlock ? tx.txBlock : tx;
|
|
185
|
+
const txBytes =
|
|
186
|
+
txBlock instanceof Uint8Array
|
|
187
|
+
? txBlock
|
|
188
|
+
: await txBlock.build({ client: this.client });
|
|
189
|
+
return this.suiInteractor.dryRunTx(txBytes);
|
|
190
|
+
}
|
|
180
191
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
192
|
+
/**
|
|
193
|
+
* Transfer the given amount of SUI to the recipient
|
|
194
|
+
* @param recipient
|
|
195
|
+
* @param amount
|
|
196
|
+
* @param derivePathParams
|
|
197
|
+
*/
|
|
198
|
+
async transferSui(
|
|
199
|
+
recipient: string,
|
|
200
|
+
amount: number,
|
|
201
|
+
derivePathParams?: DerivePathParams,
|
|
202
|
+
): Promise<SuiTransactionBlockResponse>;
|
|
203
|
+
async transferSui<S extends boolean>(
|
|
204
|
+
recipient: string,
|
|
205
|
+
amount: number,
|
|
206
|
+
sign?: S,
|
|
207
|
+
derivePathParams?: DerivePathParams,
|
|
208
|
+
): Promise<SuiKitReturnType<S>>;
|
|
209
|
+
async transferSui<S extends boolean>(
|
|
210
|
+
recipient: string,
|
|
211
|
+
amount: number,
|
|
212
|
+
sign: S = true as S,
|
|
213
|
+
derivePathParams?: DerivePathParams,
|
|
214
|
+
) {
|
|
215
|
+
const tx = new SuiTxBlock();
|
|
216
|
+
tx.transferSui(recipient, amount);
|
|
217
|
+
return sign
|
|
218
|
+
? ((await this.signAndSendTxn(
|
|
219
|
+
tx,
|
|
220
|
+
derivePathParams,
|
|
221
|
+
)) as SuiKitReturnType<S>)
|
|
222
|
+
: (tx as SuiKitReturnType<S>);
|
|
223
|
+
}
|
|
213
224
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
225
|
+
/**
|
|
226
|
+
* Transfer to mutliple recipients
|
|
227
|
+
* @param recipients the recipients addresses
|
|
228
|
+
* @param amounts the amounts of SUI to transfer to each recipient, the length of amounts should be the same as the length of recipients
|
|
229
|
+
* @param derivePathParams
|
|
230
|
+
*/
|
|
231
|
+
async transferSuiToMany(
|
|
232
|
+
recipients: string[],
|
|
233
|
+
amounts: number[],
|
|
234
|
+
derivePathParams?: DerivePathParams,
|
|
235
|
+
): Promise<SuiTransactionBlockResponse>;
|
|
236
|
+
async transferSuiToMany<S extends boolean>(
|
|
237
|
+
recipients: string[],
|
|
238
|
+
amounts: number[],
|
|
239
|
+
sign?: S,
|
|
240
|
+
derivePathParams?: DerivePathParams,
|
|
241
|
+
): Promise<SuiKitReturnType<S>>;
|
|
242
|
+
async transferSuiToMany<S extends boolean>(
|
|
243
|
+
recipients: string[],
|
|
244
|
+
amounts: number[],
|
|
245
|
+
sign: S = true as S,
|
|
246
|
+
derivePathParams?: DerivePathParams,
|
|
247
|
+
) {
|
|
248
|
+
const tx = new SuiTxBlock();
|
|
249
|
+
tx.transferSuiToMany(recipients, amounts);
|
|
250
|
+
return sign
|
|
251
|
+
? ((await this.signAndSendTxn(
|
|
252
|
+
tx,
|
|
253
|
+
derivePathParams,
|
|
254
|
+
)) as SuiKitReturnType<S>)
|
|
255
|
+
: (tx as SuiKitReturnType<S>);
|
|
256
|
+
}
|
|
246
257
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
258
|
+
/**
|
|
259
|
+
* Transfer the given amounts of coin to multiple recipients
|
|
260
|
+
* @param recipients the list of recipient address
|
|
261
|
+
* @param amounts the amounts to transfer for each recipient
|
|
262
|
+
* @param coinType any custom coin type but not SUI
|
|
263
|
+
* @param derivePathParams the derive path params for the current signer
|
|
264
|
+
*/
|
|
265
|
+
async transferCoinToMany(
|
|
266
|
+
recipients: string[],
|
|
267
|
+
amounts: number[],
|
|
268
|
+
coinType: string,
|
|
269
|
+
derivePathParams?: DerivePathParams,
|
|
270
|
+
): Promise<SuiTransactionBlockResponse>;
|
|
271
|
+
async transferCoinToMany<S extends boolean>(
|
|
272
|
+
recipients: string[],
|
|
273
|
+
amounts: number[],
|
|
274
|
+
coinType: string,
|
|
275
|
+
sign?: S,
|
|
276
|
+
derivePathParams?: DerivePathParams,
|
|
277
|
+
): Promise<SuiKitReturnType<S>>;
|
|
278
|
+
async transferCoinToMany<S extends boolean>(
|
|
279
|
+
recipients: string[],
|
|
280
|
+
amounts: number[],
|
|
281
|
+
coinType: string,
|
|
282
|
+
sign: S = true as S,
|
|
283
|
+
derivePathParams?: DerivePathParams,
|
|
284
|
+
) {
|
|
285
|
+
const tx = new SuiTxBlock();
|
|
286
|
+
const owner = this.accountManager.getAddress(derivePathParams);
|
|
287
|
+
const totalAmount = amounts.reduce((a, b) => a + b, 0);
|
|
288
|
+
if (normalizeStructTag(coinType) === normalizeStructTag(SUI_TYPE_ARG)) {
|
|
289
|
+
tx.transferSuiToMany(recipients, amounts);
|
|
290
|
+
} else {
|
|
291
|
+
const coins = await this.suiInteractor.selectCoins(
|
|
292
|
+
owner,
|
|
293
|
+
totalAmount,
|
|
294
|
+
coinType,
|
|
295
|
+
);
|
|
285
296
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
297
|
+
tx.transferCoinToMany(
|
|
298
|
+
coins.map((coin) => ("objectId" in coin ? tx.objectRef(coin) : coin)),
|
|
299
|
+
owner,
|
|
300
|
+
recipients,
|
|
301
|
+
amounts,
|
|
302
|
+
);
|
|
303
|
+
}
|
|
293
304
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
305
|
+
return sign
|
|
306
|
+
? ((await this.signAndSendTxn(
|
|
307
|
+
tx,
|
|
308
|
+
derivePathParams,
|
|
309
|
+
)) as SuiKitReturnType<S>)
|
|
310
|
+
: (tx as SuiKitReturnType<S>);
|
|
311
|
+
}
|
|
301
312
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
313
|
+
async transferCoin(
|
|
314
|
+
recipient: string,
|
|
315
|
+
amount: number,
|
|
316
|
+
coinType: string,
|
|
317
|
+
derivePathParams?: DerivePathParams,
|
|
318
|
+
): Promise<SuiTransactionBlockResponse>;
|
|
319
|
+
async transferCoin<S extends boolean>(
|
|
320
|
+
recipient: string,
|
|
321
|
+
amount: number,
|
|
322
|
+
coinType: string,
|
|
323
|
+
sign?: S,
|
|
324
|
+
derivePathParams?: DerivePathParams,
|
|
325
|
+
): Promise<SuiKitReturnType<S>>;
|
|
326
|
+
async transferCoin<S extends boolean>(
|
|
327
|
+
recipient: string,
|
|
328
|
+
amount: number,
|
|
329
|
+
coinType: string,
|
|
330
|
+
sign: S = true as S,
|
|
331
|
+
derivePathParams?: DerivePathParams,
|
|
332
|
+
) {
|
|
333
|
+
return this.transferCoinToMany(
|
|
334
|
+
[recipient],
|
|
335
|
+
[amount],
|
|
336
|
+
coinType,
|
|
337
|
+
sign,
|
|
338
|
+
derivePathParams,
|
|
339
|
+
);
|
|
340
|
+
}
|
|
330
341
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
342
|
+
async transferObjects(
|
|
343
|
+
objects: SuiObjectArg[],
|
|
344
|
+
recipient: string,
|
|
345
|
+
derivePathParams?: DerivePathParams,
|
|
346
|
+
): Promise<SuiTransactionBlockResponse>;
|
|
347
|
+
async transferObjects<S extends boolean>(
|
|
348
|
+
objects: SuiObjectArg[],
|
|
349
|
+
recipient: string,
|
|
350
|
+
sign?: S,
|
|
351
|
+
derivePathParams?: DerivePathParams,
|
|
352
|
+
): Promise<SuiKitReturnType<S>>;
|
|
353
|
+
async transferObjects<S extends boolean>(
|
|
354
|
+
objects: SuiObjectArg[],
|
|
355
|
+
recipient: string,
|
|
356
|
+
sign: S = true as S,
|
|
357
|
+
derivePathParams?: DerivePathParams,
|
|
358
|
+
) {
|
|
359
|
+
const tx = new SuiTxBlock();
|
|
360
|
+
tx.transferObjects(objects, recipient);
|
|
361
|
+
return sign ? await this.signAndSendTxn(tx, derivePathParams) : tx;
|
|
362
|
+
}
|
|
352
363
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
364
|
+
async moveCall(callParams: {
|
|
365
|
+
target: string;
|
|
366
|
+
arguments?: (SuiTxArg | SuiVecTxArg | SuiObjectArg | SuiAmountsArg)[];
|
|
367
|
+
typeArguments?: string[];
|
|
368
|
+
derivePathParams?: DerivePathParams;
|
|
369
|
+
}) {
|
|
370
|
+
const {
|
|
371
|
+
target,
|
|
372
|
+
arguments: args = [],
|
|
373
|
+
typeArguments = [],
|
|
374
|
+
derivePathParams,
|
|
375
|
+
} = callParams;
|
|
376
|
+
const tx = new SuiTxBlock();
|
|
377
|
+
tx.moveCall(target, args, typeArguments);
|
|
378
|
+
return this.signAndSendTxn(tx, derivePathParams);
|
|
379
|
+
}
|
|
369
380
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
381
|
+
/**
|
|
382
|
+
* Select coins with the given amount and coin type, the total amount is greater than or equal to the given amount
|
|
383
|
+
* @param amount
|
|
384
|
+
* @param coinType
|
|
385
|
+
* @param owner
|
|
386
|
+
*/
|
|
387
|
+
async selectCoinsWithAmount(
|
|
388
|
+
amount: number,
|
|
389
|
+
coinType: string,
|
|
390
|
+
owner?: string,
|
|
391
|
+
) {
|
|
392
|
+
owner = owner || this.accountManager.currentAddress;
|
|
393
|
+
const coins = await this.suiInteractor.selectCoins(owner, amount, coinType);
|
|
394
|
+
return coins;
|
|
395
|
+
}
|
|
385
396
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
397
|
+
/**
|
|
398
|
+
* stake the given amount of SUI to the validator
|
|
399
|
+
* @param amount the amount of SUI to stake
|
|
400
|
+
* @param validatorAddr the validator address
|
|
401
|
+
* @param sign whether to sign and send the transaction, default is true
|
|
402
|
+
* @param derivePathParams the derive path params for the current signer
|
|
403
|
+
*/
|
|
404
|
+
async stakeSui(
|
|
405
|
+
amount: number,
|
|
406
|
+
validatorAddr: string,
|
|
407
|
+
derivePathParams?: DerivePathParams,
|
|
408
|
+
): Promise<SuiTransactionBlockResponse>;
|
|
409
|
+
async stakeSui<S extends boolean>(
|
|
410
|
+
amount: number,
|
|
411
|
+
validatorAddr: string,
|
|
412
|
+
sign?: S,
|
|
413
|
+
derivePathParams?: DerivePathParams,
|
|
414
|
+
): Promise<SuiKitReturnType<S>>;
|
|
415
|
+
async stakeSui<S extends boolean>(
|
|
416
|
+
amount: number,
|
|
417
|
+
validatorAddr: string,
|
|
418
|
+
sign: S = true as S,
|
|
419
|
+
derivePathParams?: DerivePathParams,
|
|
420
|
+
) {
|
|
421
|
+
const tx = new SuiTxBlock();
|
|
422
|
+
tx.stakeSui(amount, validatorAddr);
|
|
423
|
+
return sign
|
|
424
|
+
? ((await this.signAndSendTxn(
|
|
425
|
+
tx,
|
|
426
|
+
derivePathParams,
|
|
427
|
+
)) as SuiKitReturnType<S>)
|
|
428
|
+
: (tx as SuiKitReturnType<S>);
|
|
429
|
+
}
|
|
419
430
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
431
|
+
/**
|
|
432
|
+
* Execute the transaction with on-chain data but without really submitting. Useful for querying the effects of a transaction.
|
|
433
|
+
* Since the transaction is not submitted, its gas cost is not charged.
|
|
434
|
+
* @param tx the transaction to execute
|
|
435
|
+
* @param derivePathParams the derive path params
|
|
436
|
+
* @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.
|
|
437
|
+
*/
|
|
438
|
+
async inspectTxn(
|
|
439
|
+
tx: Uint8Array | Transaction | SuiTxBlock,
|
|
440
|
+
derivePathParams?: DerivePathParams,
|
|
441
|
+
): Promise<SimulateTransactionResponse> {
|
|
442
|
+
if (tx instanceof SuiTxBlock) {
|
|
443
|
+
tx.setSender(this.getAddress(derivePathParams));
|
|
444
|
+
}
|
|
445
|
+
const txBlock = tx instanceof SuiTxBlock ? tx.txBlock : tx;
|
|
446
|
+
const txBytes =
|
|
447
|
+
txBlock instanceof Uint8Array
|
|
448
|
+
? txBlock
|
|
449
|
+
: await txBlock.build({ client: this.client });
|
|
439
450
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
451
|
+
return this.suiInteractor.currentClient.core.simulateTransaction({
|
|
452
|
+
transaction: txBytes,
|
|
453
|
+
include: {
|
|
454
|
+
effects: true,
|
|
455
|
+
events: true,
|
|
456
|
+
balanceChanges: true,
|
|
457
|
+
commandResults: true,
|
|
458
|
+
},
|
|
459
|
+
checksEnabled: false,
|
|
460
|
+
});
|
|
461
|
+
}
|
|
450
462
|
}
|