@scallop-io/sui-kit 2.0.1 → 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/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
- import { Transaction } from '@mysten/sui/transactions';
5
- import { SuiAccountManager } from './libs/suiAccountManager/index.js';
6
- import { SuiTxBlock } from './libs/suiTxBuilder/index.js';
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
- SuiInteractor,
9
- getFullnodeUrl,
10
- type SuiObjectDataOptions,
11
- type SimulateTransactionResponse,
12
- } from './libs/suiInteractor/index.js';
13
- import type { SuiSharedObject, SuiOwnedObject } from './libs/suiModel/index.js';
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
- SuiKitParams,
16
- DerivePathParams,
17
- SuiTxArg,
18
- SuiVecTxArg,
19
- SuiKitReturnType,
20
- SuiObjectArg,
21
- SuiAmountsArg,
22
- SuiTransactionBlockResponse,
23
- } from './types/index.js';
24
- import { normalizeStructTag, SUI_TYPE_ARG } from '@mysten/sui/utils';
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
- public accountManager: SuiAccountManager;
32
- public suiInteractor: SuiInteractor;
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
- const network = networkType ?? 'mainnet';
55
+ let suiInteractorParams:
56
+ | {
57
+ fullnodeUrls: string[] | undefined;
58
+ network: NetworkType;
59
+ }
60
+ | {
61
+ suiClients: ClientWithCoreApi[] | undefined;
62
+ };
51
63
 
52
- let suiInteractorParams;
53
- if ('fullnodeUrls' in params) {
54
- suiInteractorParams = {
55
- fullnodeUrls: params.fullnodeUrls,
56
- network,
57
- };
58
- } else if ('suiClients' in params) {
59
- suiInteractorParams = { suiClients: params.suiClients };
60
- } else {
61
- suiInteractorParams = {
62
- fullnodeUrls: [getFullnodeUrl(network)],
63
- network,
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
- this.suiInteractor = new SuiInteractor(suiInteractorParams);
68
- }
78
+ this.suiInteractor = new SuiInteractor(suiInteractorParams);
79
+ }
69
80
 
70
- /**
71
- * Create SuiTxBlock with sender set to the current signer
72
- * @returns SuiTxBlock with sender set to the current signer
73
- */
74
- createTxBlock(): SuiTxBlock {
75
- const txb = new SuiTxBlock();
76
- txb.setSender(this.accountManager.currentAddress);
77
- return txb;
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
- * if derivePathParams is not provided or mnemonics is empty, it will return the keypair.
82
- * else:
83
- * it will generate signer from the mnemonic with the given derivePathParams.
84
- * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
85
- */
86
- getKeypair(derivePathParams?: DerivePathParams) {
87
- return this.accountManager.getKeyPair(derivePathParams);
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
- * @description Switch the current account with the given derivePathParams
92
- * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
93
- */
94
- switchAccount(derivePathParams: DerivePathParams) {
95
- this.accountManager.switchAccount(derivePathParams);
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
- * @description Get the address of the account for the given derivePathParams
100
- * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
101
- */
102
- getAddress(derivePathParams?: DerivePathParams) {
103
- return this.accountManager.getAddress(derivePathParams);
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
- get currentAddress() {
107
- return this.accountManager.currentAddress;
108
- }
117
+ get currentAddress() {
118
+ return this.accountManager.currentAddress;
119
+ }
109
120
 
110
- async getBalance(coinType?: string, derivePathParams?: DerivePathParams) {
111
- const owner = this.accountManager.getAddress(derivePathParams);
112
- const { balance } = await this.suiInteractor.currentClient.core.getBalance({
113
- owner,
114
- coinType,
115
- });
116
- return balance;
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
- get client() {
120
- return this.suiInteractor.currentClient;
121
- }
130
+ get client() {
131
+ return this.suiInteractor.currentClient;
132
+ }
122
133
 
123
- async getObjects(
124
- objectIds: string[],
125
- options?: {
126
- include?: SuiObjectDataOptions;
127
- batchSize?: number;
128
- switchClientDelay?: number;
129
- }
130
- ) {
131
- return this.suiInteractor.getObjects(objectIds, options);
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
- * @description Update objects in a batch
136
- * @param suiObjects
137
- */
138
- async updateObjects(suiObjects: (SuiSharedObject | SuiOwnedObject)[]) {
139
- return this.suiInteractor.updateObjects(suiObjects);
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
- async signTxn(
143
- tx: Uint8Array | Transaction | SuiTxBlock,
144
- derivePathParams?: DerivePathParams
145
- ) {
146
- if (tx instanceof SuiTxBlock) {
147
- tx.setSender(this.getAddress(derivePathParams));
148
- }
149
- const txBlock = tx instanceof SuiTxBlock ? tx.txBlock : tx;
150
- const txBytes =
151
- txBlock instanceof Uint8Array
152
- ? txBlock
153
- : await txBlock.build({ client: this.client });
154
- const keyPair = this.getKeypair(derivePathParams);
155
- return await keyPair.signTransaction(txBytes);
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
- async signAndSendTxn(
159
- tx: Uint8Array | Transaction | SuiTxBlock,
160
- derivePathParams?: DerivePathParams
161
- ): Promise<SuiTransactionBlockResponse> {
162
- const { bytes, signature } = await this.signTxn(tx, derivePathParams);
163
- return this.suiInteractor.sendTx(bytes, signature);
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
- async dryRunTxn(
167
- tx: Uint8Array | Transaction | SuiTxBlock,
168
- derivePathParams?: DerivePathParams
169
- ): Promise<SimulateTransactionResponse> {
170
- if (tx instanceof SuiTxBlock) {
171
- tx.setSender(this.getAddress(derivePathParams));
172
- }
173
- const txBlock = tx instanceof SuiTxBlock ? tx.txBlock : tx;
174
- const txBytes =
175
- txBlock instanceof Uint8Array
176
- ? txBlock
177
- : await txBlock.build({ client: this.client });
178
- return this.suiInteractor.dryRunTx(txBytes);
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
- * Transfer the given amount of SUI to the recipient
183
- * @param recipient
184
- * @param amount
185
- * @param derivePathParams
186
- */
187
- async transferSui(
188
- recipient: string,
189
- amount: number,
190
- derivePathParams?: DerivePathParams
191
- ): Promise<SuiTransactionBlockResponse>;
192
- async transferSui<S extends boolean>(
193
- recipient: string,
194
- amount: number,
195
- sign?: S,
196
- derivePathParams?: DerivePathParams
197
- ): Promise<SuiKitReturnType<S>>;
198
- async transferSui<S extends boolean>(
199
- recipient: string,
200
- amount: number,
201
- sign: S = true as S,
202
- derivePathParams?: DerivePathParams
203
- ) {
204
- const tx = new SuiTxBlock();
205
- tx.transferSui(recipient, amount);
206
- return sign
207
- ? ((await this.signAndSendTxn(
208
- tx,
209
- derivePathParams
210
- )) as SuiKitReturnType<S>)
211
- : (tx as SuiKitReturnType<S>);
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
- * Transfer to mutliple recipients
216
- * @param recipients the recipients addresses
217
- * @param amounts the amounts of SUI to transfer to each recipient, the length of amounts should be the same as the length of recipients
218
- * @param derivePathParams
219
- */
220
- async transferSuiToMany(
221
- recipients: string[],
222
- amounts: number[],
223
- derivePathParams?: DerivePathParams
224
- ): Promise<SuiTransactionBlockResponse>;
225
- async transferSuiToMany<S extends boolean>(
226
- recipients: string[],
227
- amounts: number[],
228
- sign?: S,
229
- derivePathParams?: DerivePathParams
230
- ): Promise<SuiKitReturnType<S>>;
231
- async transferSuiToMany<S extends boolean>(
232
- recipients: string[],
233
- amounts: number[],
234
- sign: S = true as S,
235
- derivePathParams?: DerivePathParams
236
- ) {
237
- const tx = new SuiTxBlock();
238
- tx.transferSuiToMany(recipients, amounts);
239
- return sign
240
- ? ((await this.signAndSendTxn(
241
- tx,
242
- derivePathParams
243
- )) as SuiKitReturnType<S>)
244
- : (tx as SuiKitReturnType<S>);
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
- * Transfer the given amounts of coin to multiple recipients
249
- * @param recipients the list of recipient address
250
- * @param amounts the amounts to transfer for each recipient
251
- * @param coinType any custom coin type but not SUI
252
- * @param derivePathParams the derive path params for the current signer
253
- */
254
- async transferCoinToMany(
255
- recipients: string[],
256
- amounts: number[],
257
- coinType: string,
258
- derivePathParams?: DerivePathParams
259
- ): Promise<SuiTransactionBlockResponse>;
260
- async transferCoinToMany<S extends boolean>(
261
- recipients: string[],
262
- amounts: number[],
263
- coinType: string,
264
- sign?: S,
265
- derivePathParams?: DerivePathParams
266
- ): Promise<SuiKitReturnType<S>>;
267
- async transferCoinToMany<S extends boolean>(
268
- recipients: string[],
269
- amounts: number[],
270
- coinType: string,
271
- sign: S = true as S,
272
- derivePathParams?: DerivePathParams
273
- ) {
274
- const tx = new SuiTxBlock();
275
- const owner = this.accountManager.getAddress(derivePathParams);
276
- const totalAmount = amounts.reduce((a, b) => a + b, 0);
277
- if (normalizeStructTag(coinType) === normalizeStructTag(SUI_TYPE_ARG)) {
278
- tx.transferSuiToMany(recipients, amounts);
279
- } else {
280
- const coins = await this.suiInteractor.selectCoins(
281
- owner,
282
- totalAmount,
283
- coinType
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
- tx.transferCoinToMany(
287
- coins.map((coin) => ('objectId' in coin ? tx.objectRef(coin) : coin)),
288
- owner,
289
- recipients,
290
- amounts
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
- return sign
295
- ? ((await this.signAndSendTxn(
296
- tx,
297
- derivePathParams
298
- )) as SuiKitReturnType<S>)
299
- : (tx as SuiKitReturnType<S>);
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
- async transferCoin(
303
- recipient: string,
304
- amount: number,
305
- coinType: string,
306
- derivePathParams?: DerivePathParams
307
- ): Promise<SuiTransactionBlockResponse>;
308
- async transferCoin<S extends boolean>(
309
- recipient: string,
310
- amount: number,
311
- coinType: string,
312
- sign?: S,
313
- derivePathParams?: DerivePathParams
314
- ): Promise<SuiKitReturnType<S>>;
315
- async transferCoin<S extends boolean>(
316
- recipient: string,
317
- amount: number,
318
- coinType: string,
319
- sign: S = true as S,
320
- derivePathParams?: DerivePathParams
321
- ) {
322
- return this.transferCoinToMany(
323
- [recipient],
324
- [amount],
325
- coinType,
326
- sign,
327
- derivePathParams
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
- async transferObjects(
332
- objects: SuiObjectArg[],
333
- recipient: string,
334
- derivePathParams?: DerivePathParams
335
- ): Promise<SuiTransactionBlockResponse>;
336
- async transferObjects<S extends boolean>(
337
- objects: SuiObjectArg[],
338
- recipient: string,
339
- sign?: S,
340
- derivePathParams?: DerivePathParams
341
- ): Promise<SuiKitReturnType<S>>;
342
- async transferObjects<S extends boolean>(
343
- objects: SuiObjectArg[],
344
- recipient: string,
345
- sign: S = true as S,
346
- derivePathParams?: DerivePathParams
347
- ) {
348
- const tx = new SuiTxBlock();
349
- tx.transferObjects(objects, recipient);
350
- return sign ? await this.signAndSendTxn(tx, derivePathParams) : tx;
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
- async moveCall(callParams: {
354
- target: string;
355
- arguments?: (SuiTxArg | SuiVecTxArg | SuiObjectArg | SuiAmountsArg)[];
356
- typeArguments?: string[];
357
- derivePathParams?: DerivePathParams;
358
- }) {
359
- const {
360
- target,
361
- arguments: args = [],
362
- typeArguments = [],
363
- derivePathParams,
364
- } = callParams;
365
- const tx = new SuiTxBlock();
366
- tx.moveCall(target, args, typeArguments);
367
- return this.signAndSendTxn(tx, derivePathParams);
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
- * Select coins with the given amount and coin type, the total amount is greater than or equal to the given amount
372
- * @param amount
373
- * @param coinType
374
- * @param owner
375
- */
376
- async selectCoinsWithAmount(
377
- amount: number,
378
- coinType: string,
379
- owner?: string
380
- ) {
381
- owner = owner || this.accountManager.currentAddress;
382
- const coins = await this.suiInteractor.selectCoins(owner, amount, coinType);
383
- return coins;
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
- * stake the given amount of SUI to the validator
388
- * @param amount the amount of SUI to stake
389
- * @param validatorAddr the validator address
390
- * @param sign whether to sign and send the transaction, default is true
391
- * @param derivePathParams the derive path params for the current signer
392
- */
393
- async stakeSui(
394
- amount: number,
395
- validatorAddr: string,
396
- derivePathParams?: DerivePathParams
397
- ): Promise<SuiTransactionBlockResponse>;
398
- async stakeSui<S extends boolean>(
399
- amount: number,
400
- validatorAddr: string,
401
- sign?: S,
402
- derivePathParams?: DerivePathParams
403
- ): Promise<SuiKitReturnType<S>>;
404
- async stakeSui<S extends boolean>(
405
- amount: number,
406
- validatorAddr: string,
407
- sign: S = true as S,
408
- derivePathParams?: DerivePathParams
409
- ) {
410
- const tx = new SuiTxBlock();
411
- tx.stakeSui(amount, validatorAddr);
412
- return sign
413
- ? ((await this.signAndSendTxn(
414
- tx,
415
- derivePathParams
416
- )) as SuiKitReturnType<S>)
417
- : (tx as SuiKitReturnType<S>);
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
- * Execute the transaction with on-chain data but without really submitting. Useful for querying the effects of a transaction.
422
- * Since the transaction is not submitted, its gas cost is not charged.
423
- * @param tx the transaction to execute
424
- * @param derivePathParams the derive path params
425
- * @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.
426
- */
427
- async inspectTxn(
428
- tx: Uint8Array | Transaction | SuiTxBlock,
429
- derivePathParams?: DerivePathParams
430
- ): Promise<SimulateTransactionResponse> {
431
- if (tx instanceof SuiTxBlock) {
432
- tx.setSender(this.getAddress(derivePathParams));
433
- }
434
- const txBlock = tx instanceof SuiTxBlock ? tx.txBlock : tx;
435
- const txBytes =
436
- txBlock instanceof Uint8Array
437
- ? txBlock
438
- : await txBlock.build({ client: this.client });
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
- return this.suiInteractor.currentClient.core.simulateTransaction({
441
- transaction: txBytes,
442
- include: {
443
- effects: true,
444
- events: true,
445
- balanceChanges: true,
446
- commandResults: true,
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
  }