@0xobelisk/sui-client 1.2.0-pre.71 → 1.2.0-pre.72

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.
@@ -6,9 +6,7 @@ export class ContractDataParsingError extends Error {
6
6
 
7
7
  constructor(dryResult: any) {
8
8
  const error = dryResult?.effects?.status?.error || '';
9
- const functionMatch = error
10
- ? error.match(/function_name: Some\("([^"]+)"\)/)
11
- : null;
9
+ const functionMatch = error ? error.match(/function_name: Some\("([^"]+)"\)/) : null;
12
10
  const moduleMatch = error ? error.match(/address: ([a-fA-F0-9]+)/) : null;
13
11
 
14
12
  const functionName = functionMatch ? functionMatch[1] : 'unknown';
@@ -18,7 +16,7 @@ export class ContractDataParsingError extends Error {
18
16
  const message = [
19
17
  `\n- Function: ${functionName}`,
20
18
  `- Module Address: ${moduleAddress}`,
21
- `- Error Message: ${errorMessage}`,
19
+ `- Error Message: ${errorMessage}`
22
20
  ].join('\n');
23
21
 
24
22
  super(message);
@@ -16,7 +16,7 @@ export class MultiSigClient {
16
16
  this.threshold = threshold;
17
17
  this.multiSigPublicKey = MultiSigPublicKey.fromPublicKeys({
18
18
  threshold: this.threshold,
19
- publicKeys: this.pksWeightPairs,
19
+ publicKeys: this.pksWeightPairs
20
20
  });
21
21
  }
22
22
 
@@ -28,7 +28,7 @@ export class MultiSigClient {
28
28
  const pks = rawPublicKeys.map((rawPublicKey, i) => {
29
29
  return {
30
30
  publicKey: ed25519PublicKeyFromBase64(rawPublicKey),
31
- weight: weights[i],
31
+ weight: weights[i]
32
32
  };
33
33
  });
34
34
  return new MultiSigClient(pks, threshold);
@@ -3,10 +3,7 @@ import { getKeyPair } from './keypair';
3
3
  import { hexOrBase64ToUint8Array, normalizePrivateKey } from './util';
4
4
  import { generateMnemonic } from './crypto';
5
5
  import type { AccountMangerParams, DerivePathParams } from 'src/types';
6
- import {
7
- SUI_PRIVATE_KEY_PREFIX,
8
- decodeSuiPrivateKey,
9
- } from '@mysten/sui/cryptography';
6
+ import { SUI_PRIVATE_KEY_PREFIX, decodeSuiPrivateKey } from '@mysten/sui/cryptography';
10
7
 
11
8
  export class SuiAccountManager {
12
9
  private mnemonics: string;
@@ -45,14 +42,10 @@ export class SuiAccountManager {
45
42
  parseSecretKey(secretKey: string) {
46
43
  if (secretKey.startsWith(SUI_PRIVATE_KEY_PREFIX)) {
47
44
  const { secretKey: uint8ArraySecretKey } = decodeSuiPrivateKey(secretKey);
48
- return Ed25519Keypair.fromSecretKey(
49
- normalizePrivateKey(uint8ArraySecretKey)
50
- );
45
+ return Ed25519Keypair.fromSecretKey(normalizePrivateKey(uint8ArraySecretKey));
51
46
  }
52
47
 
53
- return Ed25519Keypair.fromSecretKey(
54
- normalizePrivateKey(hexOrBase64ToUint8Array(secretKey))
55
- );
48
+ return Ed25519Keypair.fromSecretKey(normalizePrivateKey(hexOrBase64ToUint8Array(secretKey)));
56
49
  }
57
50
 
58
51
  /**
@@ -72,9 +65,7 @@ export class SuiAccountManager {
72
65
  */
73
66
  getAddress(derivePathParams?: DerivePathParams) {
74
67
  if (!derivePathParams || !this.mnemonics) return this.currentAddress;
75
- return getKeyPair(this.mnemonics, derivePathParams)
76
- .getPublicKey()
77
- .toSuiAddress();
68
+ return getKeyPair(this.mnemonics, derivePathParams).getPublicKey().toSuiAddress();
78
69
  }
79
70
 
80
71
  /**
@@ -5,14 +5,8 @@ import type { DerivePathParams } from '../../types';
5
5
  * @description Get ed25519 derive path for SUI
6
6
  * @param derivePathParams
7
7
  */
8
- export const getDerivePathForSUI = (
9
- derivePathParams: DerivePathParams = {}
10
- ) => {
11
- const {
12
- accountIndex = 0,
13
- isExternal = false,
14
- addressIndex = 0,
15
- } = derivePathParams;
8
+ export const getDerivePathForSUI = (derivePathParams: DerivePathParams = {}) => {
9
+ const { accountIndex = 0, isExternal = false, addressIndex = 0 } = derivePathParams;
16
10
  return `m/44'/784'/${accountIndex}'/${isExternal ? 1 : 0}'/${addressIndex}'`;
17
11
  };
18
12
 
@@ -29,10 +23,7 @@ export const getDerivePathForSUI = (
29
23
  * @param mnemonics
30
24
  * @param derivePathParams
31
25
  */
32
- export const getKeyPair = (
33
- mnemonics: string,
34
- derivePathParams: DerivePathParams = {}
35
- ) => {
26
+ export const getKeyPair = (mnemonics: string, derivePathParams: DerivePathParams = {}) => {
36
27
  const derivePath = getDerivePathForSUI(derivePathParams);
37
28
  return Ed25519Keypair.deriveKeypair(mnemonics, derivePath);
38
29
  };
@@ -4,8 +4,7 @@ import { fromB64 } from '@mysten/sui/utils';
4
4
  * @description This regular expression matches any string that contains only hexadecimal digits (0-9, A-F, a-f).
5
5
  * @param str
6
6
  */
7
- export const isHex = (str: string) =>
8
- /^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(str);
7
+ export const isHex = (str: string) => /^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(str);
9
8
 
10
9
  /**
11
10
  * @description This regular expression matches any string that contains only base64 digits (0-9, A-Z, a-z, +, /, =).
@@ -46,47 +46,41 @@ export class SuiContractFactory {
46
46
  this.metadata = metadata || undefined;
47
47
  }
48
48
 
49
- getFuncByModuleName(moduleName: string) {
50
- Object.values(this.metadata as SuiMoveNormalizedModules).forEach(
51
- (value) => {
52
- const data = value as SuiMoveMoudleValueType;
53
- console.log(`moudle name: ${data.name}`);
54
- // console.log(data.exposedFunctions)
55
- Object.entries(data.exposedFunctions).forEach(([key, value]) => {
56
- console.log(`\tfunc name: ${key}`);
57
- Object.values(value.parameters).forEach((values) => {
58
- // console.log(values)
59
- });
49
+ getFuncByModuleName(_moduleName: string) {
50
+ Object.values(this.metadata as SuiMoveNormalizedModules).forEach((value) => {
51
+ const data = value as SuiMoveMoudleValueType;
52
+ console.log(`moudle name: ${data.name}`);
53
+ // console.log(data.exposedFunctions)
54
+ Object.entries(data.exposedFunctions).forEach(([key, value]) => {
55
+ console.log(`\tfunc name: ${key}`);
56
+ Object.values(value.parameters).forEach((_values) => {
57
+ // console.log(values)
60
58
  });
61
- }
62
- );
59
+ });
60
+ });
63
61
  }
64
62
 
65
63
  getAllFunc() {
66
- Object.values(this.metadata as SuiMoveNormalizedModules).forEach(
67
- (value) => {
68
- const data = value as SuiMoveMoudleValueType;
69
- console.log(`moudle name: ${data.name}`);
70
- // console.log(data.exposedFunctions)
71
- Object.entries(data.exposedFunctions).forEach(([key, value]) => {
72
- console.log(`\tfunc name: ${key}`);
73
- console.log(`\t\t${value.parameters.length}`);
74
- Object.values(value.parameters).forEach((values) => {
75
- // console.log(values)
76
- console.log(`\t\targs: ${values}`);
77
- });
64
+ Object.values(this.metadata as SuiMoveNormalizedModules).forEach((value) => {
65
+ const data = value as SuiMoveMoudleValueType;
66
+ console.log(`moudle name: ${data.name}`);
67
+ // console.log(data.exposedFunctions)
68
+ Object.entries(data.exposedFunctions).forEach(([key, value]) => {
69
+ console.log(`\tfunc name: ${key}`);
70
+ console.log(`\t\t${value.parameters.length}`);
71
+ Object.values(value.parameters).forEach((values) => {
72
+ // console.log(values)
73
+ console.log(`\t\targs: ${values}`);
78
74
  });
79
- }
80
- );
75
+ });
76
+ });
81
77
  }
82
78
 
83
79
  getAllModule() {
84
- Object.values(this.metadata as SuiMoveNormalizedModules).forEach(
85
- (value, index) => {
86
- const data = value as SuiMoveMoudleValueType;
87
- console.log(`${index}. ${data.name}`);
88
- }
89
- );
80
+ Object.values(this.metadata as SuiMoveNormalizedModules).forEach((value, index) => {
81
+ const data = value as SuiMoveMoudleValueType;
82
+ console.log(`${index}. ${data.name}`);
83
+ });
90
84
  }
91
85
 
92
86
  // async call(arguments: ({
@@ -1,7 +1,4 @@
1
- import type {
2
- SuiMoveNormalizedModules,
3
- SuiMoveNormalizedType,
4
- } from '@mysten/sui/client';
1
+ import type { SuiMoveNormalizedModules, SuiMoveNormalizedType } from '@mysten/sui/client';
5
2
 
6
3
  export type ContractFactoryParams = {
7
4
  packageId?: string;
@@ -10,21 +10,17 @@ export interface NetworkConfig {
10
10
  indexerUrl: string;
11
11
  }
12
12
 
13
- export const getDefaultURL = (
14
- networkType: NetworkType = 'testnet'
15
- ): NetworkConfig => {
13
+ export const getDefaultURL = (networkType: NetworkType = 'testnet'): NetworkConfig => {
16
14
  switch (networkType) {
17
15
  case 'localnet':
18
16
  return {
19
17
  fullNode: 'http://127.0.0.1:9000',
20
18
  graphql: 'http://127.0.0.1:9125',
21
19
  network: 'localnet',
22
- txExplorer:
23
- 'https://explorer.polymedia.app/txblock/:txHash?network=local',
24
- accountExplorer:
25
- 'https://explorer.polymedia.app/address/:address?network=local',
20
+ txExplorer: 'https://explorer.polymedia.app/txblock/:txHash?network=local',
21
+ accountExplorer: 'https://explorer.polymedia.app/address/:address?network=local',
26
22
  explorer: 'https://explorer.polymedia.app?network=local',
27
- indexerUrl: 'http://127.0.0.1:3001',
23
+ indexerUrl: 'http://127.0.0.1:3001'
28
24
  };
29
25
  case 'devnet':
30
26
  return {
@@ -33,7 +29,7 @@ export const getDefaultURL = (
33
29
  txExplorer: 'https://suiscan.xyz/devnet/tx/:txHash',
34
30
  accountExplorer: 'https://suiscan.xyz/devnet/address/:address',
35
31
  explorer: 'https://suiscan.xyz/devnet',
36
- indexerUrl: 'http://127.0.0.1:3001',
32
+ indexerUrl: 'http://127.0.0.1:3001'
37
33
  };
38
34
  case 'testnet':
39
35
  return {
@@ -43,7 +39,7 @@ export const getDefaultURL = (
43
39
  txExplorer: 'https://suiscan.xyz/testnet/tx/:txHash',
44
40
  accountExplorer: 'https://suiscan.xyz/testnet/address/:address',
45
41
  explorer: 'https://suiscan.xyz/testnet',
46
- indexerUrl: 'http://127.0.0.1:3001',
42
+ indexerUrl: 'http://127.0.0.1:3001'
47
43
  };
48
44
  case 'mainnet':
49
45
  return {
@@ -53,7 +49,7 @@ export const getDefaultURL = (
53
49
  txExplorer: 'https://suiscan.xyz/mainnet/tx/:txHash',
54
50
  accountExplorer: 'https://suiscan.xyz/mainnet/address/:address',
55
51
  explorer: 'https://suiscan.xyz/mainnet',
56
- indexerUrl: 'http://127.0.0.1:3001',
52
+ indexerUrl: 'http://127.0.0.1:3001'
57
53
  };
58
54
  default:
59
55
  return {
@@ -63,7 +59,7 @@ export const getDefaultURL = (
63
59
  txExplorer: 'https://suiscan.xyz/testnet/tx/:txHash',
64
60
  accountExplorer: 'https://suiscan.xyz/testnet/address/:address',
65
61
  explorer: 'https://suiscan.xyz/testnet',
66
- indexerUrl: 'http://127.0.0.1:3001',
62
+ indexerUrl: 'http://127.0.0.1:3001'
67
63
  };
68
64
  }
69
65
  };
@@ -3,11 +3,11 @@ import type {
3
3
  SuiTransactionBlockResponseOptions,
4
4
  SuiTransactionBlockResponse,
5
5
  SuiObjectDataOptions,
6
- SuiObjectData,
6
+ SuiObjectData
7
7
  } from '@mysten/sui/client';
8
8
  import type * as RpcTypes from '@mysten/sui/dist/cjs/client/types/generated';
9
9
  import { requestSuiFromFaucetV0, getFaucetHost } from '@mysten/sui/faucet';
10
- import { FaucetNetworkType, NetworkType, ObjectData } from '../../types';
10
+ import { FaucetNetworkType, NetworkType } from '../../types';
11
11
  import { SuiOwnedObject, SuiSharedObject } from '../suiModel';
12
12
  import { delay } from './util';
13
13
 
@@ -25,8 +25,7 @@ export class SuiInteractor {
25
25
  public network?: NetworkType;
26
26
 
27
27
  constructor(fullNodeUrls: string[], network?: NetworkType) {
28
- if (fullNodeUrls.length === 0)
29
- throw new Error('fullNodeUrls must not be empty');
28
+ if (fullNodeUrls.length === 0) throw new Error('fullNodeUrls must not be empty');
30
29
  this.fullNodes = fullNodeUrls;
31
30
  this.clients = fullNodeUrls.map((url) => new SuiClient({ url }));
32
31
  this.currentFullNode = fullNodeUrls[0];
@@ -36,10 +35,8 @@ export class SuiInteractor {
36
35
 
37
36
  switchToNextClient() {
38
37
  const currentClientIdx = this.clients.indexOf(this.currentClient);
39
- this.currentClient =
40
- this.clients[(currentClientIdx + 1) % this.clients.length];
41
- this.currentFullNode =
42
- this.fullNodes[(currentClientIdx + 1) % this.clients.length];
38
+ this.currentClient = this.clients[(currentClientIdx + 1) % this.clients.length];
39
+ this.currentFullNode = this.fullNodes[(currentClientIdx + 1) % this.clients.length];
43
40
  }
44
41
 
45
42
  async sendTx(
@@ -50,7 +47,7 @@ export class SuiInteractor {
50
47
  showEvents: true,
51
48
  showEffects: true,
52
49
  showObjectChanges: true,
53
- showBalanceChanges: true,
50
+ showBalanceChanges: true
54
51
  };
55
52
 
56
53
  // const currentProviderIdx = this.providers.indexOf(this.currentProvider);
@@ -64,7 +61,7 @@ export class SuiInteractor {
64
61
  return await this.clients[clientIdx].executeTransactionBlock({
65
62
  transactionBlock,
66
63
  signature,
67
- options: txResOptions,
64
+ options: txResOptions
68
65
  });
69
66
  } catch (err) {
70
67
  console.warn(
@@ -79,7 +76,7 @@ export class SuiInteractor {
79
76
  async waitForTransaction({
80
77
  digest,
81
78
  timeout = 60 * 1000,
82
- pollInterval = 2 * 1000,
79
+ pollInterval = 2 * 1000
83
80
  }: {
84
81
  digest: string;
85
82
  timeout?: number;
@@ -91,14 +88,14 @@ export class SuiInteractor {
91
88
  showEvents: true,
92
89
  showEffects: true,
93
90
  showObjectChanges: true,
94
- showBalanceChanges: true,
91
+ showBalanceChanges: true
95
92
  };
96
93
 
97
94
  return await this.clients[clientIdx].waitForTransaction({
98
95
  digest,
99
96
  timeout,
100
97
  pollInterval,
101
- options: txResOptions,
98
+ options: txResOptions
102
99
  });
103
100
  } catch (err) {
104
101
  console.warn(
@@ -110,22 +107,19 @@ export class SuiInteractor {
110
107
  throw new Error('Failed to wait for transaction with all fullnodes');
111
108
  }
112
109
 
113
- async getObjects(
114
- ids: string[],
115
- options?: SuiObjectDataOptions
116
- ): Promise<SuiObjectData[]> {
110
+ async getObjects(ids: string[], options?: SuiObjectDataOptions): Promise<SuiObjectData[]> {
117
111
  const opts: SuiObjectDataOptions = options ?? {
118
112
  showContent: true,
119
113
  showDisplay: true,
120
114
  showType: true,
121
- showOwner: true,
115
+ showOwner: true
122
116
  };
123
117
 
124
118
  for (const clientIdx in this.clients) {
125
119
  try {
126
120
  const objects = await this.clients[clientIdx].multiGetObjects({
127
121
  ids,
128
- options: opts,
122
+ options: opts
129
123
  });
130
124
  const parsedObjects = objects
131
125
  .map((object) => {
@@ -135,9 +129,7 @@ export class SuiInteractor {
135
129
  return parsedObjects as SuiObjectData[];
136
130
  } catch (err) {
137
131
  await delay(2000);
138
- console.warn(
139
- `Failed to get objects with fullnode ${this.fullNodes[clientIdx]}: ${err}`
140
- );
132
+ console.warn(`Failed to get objects with fullnode ${this.fullNodes[clientIdx]}: ${err}`);
141
133
  }
142
134
  }
143
135
  throw new Error('Failed to get objects with all fullnodes');
@@ -148,15 +140,12 @@ export class SuiInteractor {
148
140
  return objects[0];
149
141
  }
150
142
 
151
- async getDynamicFieldObject(
152
- parentId: string,
153
- name: RpcTypes.DynamicFieldName
154
- ) {
143
+ async getDynamicFieldObject(parentId: string, name: RpcTypes.DynamicFieldName) {
155
144
  for (const clientIdx in this.clients) {
156
145
  try {
157
146
  return await this.clients[clientIdx].getDynamicFieldObject({
158
147
  parentId,
159
- name,
148
+ name
160
149
  });
161
150
  } catch (err) {
162
151
  await delay(2000);
@@ -174,7 +163,7 @@ export class SuiInteractor {
174
163
  return await this.clients[clientIdx].getDynamicFields({
175
164
  parentId,
176
165
  cursor,
177
- limit,
166
+ limit
178
167
  });
179
168
  } catch (err) {
180
169
  await delay(2000);
@@ -193,12 +182,12 @@ export class SuiInteractor {
193
182
  showEvents: true,
194
183
  showEffects: true,
195
184
  showObjectChanges: true,
196
- showBalanceChanges: true,
185
+ showBalanceChanges: true
197
186
  };
198
187
 
199
188
  return await this.clients[clientIdx].getTransactionBlock({
200
189
  digest,
201
- options: txResOptions,
190
+ options: txResOptions
202
191
  });
203
192
  } catch (err) {
204
193
  await delay(2000);
@@ -216,7 +205,7 @@ export class SuiInteractor {
216
205
  return await this.clients[clientIdx].getOwnedObjects({
217
206
  owner,
218
207
  cursor,
219
- limit,
208
+ limit
220
209
  });
221
210
  } catch (err) {
222
211
  await delay(2000);
@@ -232,7 +221,7 @@ export class SuiInteractor {
232
221
  for (const clientIdx in this.clients) {
233
222
  try {
234
223
  return await this.clients[clientIdx].getNormalizedMoveModulesByPackage({
235
- package: packageId,
224
+ package: packageId
236
225
  });
237
226
  } catch (err) {
238
227
  await delay(2000);
@@ -252,17 +241,10 @@ export class SuiInteractor {
252
241
  const objectIds = suiObjects.map((obj) => obj.objectId);
253
242
  const objects = await this.getObjects(objectIds);
254
243
  for (const object of objects) {
255
- const suiObject = suiObjects.find(
256
- (obj) => obj.objectId === object?.objectId
257
- );
244
+ const suiObject = suiObjects.find((obj) => obj.objectId === object?.objectId);
258
245
  if (suiObject instanceof SuiSharedObject) {
259
- if (
260
- object.owner &&
261
- typeof object.owner === 'object' &&
262
- 'Shared' in object.owner
263
- ) {
264
- suiObject.initialSharedVersion =
265
- object.owner.Shared.initial_shared_version;
246
+ if (object.owner && typeof object.owner === 'object' && 'Shared' in object.owner) {
247
+ suiObject.initialSharedVersion = object.owner.Shared.initial_shared_version;
266
248
  } else {
267
249
  suiObject.initialSharedVersion = undefined;
268
250
  }
@@ -279,11 +261,7 @@ export class SuiInteractor {
279
261
  * @param amount the amount that is needed for the coin
280
262
  * @param coinType the coin type, default is '0x2::SUI::SUI'
281
263
  */
282
- async selectCoins(
283
- addr: string,
284
- amount: number,
285
- coinType: string = '0x2::SUI::SUI'
286
- ) {
264
+ async selectCoins(addr: string, amount: number, coinType: string = '0x2::SUI::SUI') {
287
265
  const selectedCoins: {
288
266
  objectId: string;
289
267
  digest: string;
@@ -297,7 +275,7 @@ export class SuiInteractor {
297
275
  const coins = await this.currentClient.getCoins({
298
276
  owner: addr,
299
277
  coinType: coinType,
300
- cursor: nextCursor,
278
+ cursor: nextCursor
301
279
  });
302
280
  // Sort the coins by balance in descending order
303
281
  coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance));
@@ -306,7 +284,7 @@ export class SuiInteractor {
306
284
  objectId: coinData.coinObjectId,
307
285
  digest: coinData.digest,
308
286
  version: coinData.version,
309
- balance: coinData.balance,
287
+ balance: coinData.balance
310
288
  });
311
289
  totalAmount = totalAmount + parseInt(coinData.balance);
312
290
  if (totalAmount >= amount) {
@@ -336,7 +314,7 @@ export class SuiInteractor {
336
314
  while (hasNext) {
337
315
  const ownedObjects = await this.currentClient.getOwnedObjects({
338
316
  owner: addr,
339
- cursor: nextCursor,
317
+ cursor: nextCursor
340
318
  });
341
319
 
342
320
  for (const objectData of ownedObjects.data) {
@@ -359,7 +337,7 @@ export class SuiInteractor {
359
337
  async requestFaucet(address: string, network: FaucetNetworkType) {
360
338
  await requestSuiFromFaucetV0({
361
339
  host: getFaucetHost(network),
362
- recipient: address,
340
+ recipient: address
363
341
  });
364
342
  }
365
343
  }
@@ -1,2 +1 @@
1
- export const delay = (ms: number) =>
2
- new Promise((resolve) => setTimeout(resolve, ms));
1
+ export const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -32,9 +32,9 @@ export class SuiOwnedObject {
32
32
  ImmOrOwnedObject: {
33
33
  objectId: this.objectId,
34
34
  version: this.version,
35
- digest: this.digest,
36
- },
37
- },
35
+ digest: this.digest
36
+ }
37
+ }
38
38
  };
39
39
  }
40
40
 
@@ -4,11 +4,7 @@ export class SuiSharedObject {
4
4
  public readonly objectId: string;
5
5
  public initialSharedVersion?: string;
6
6
 
7
- constructor(param: {
8
- objectId: string;
9
- initialSharedVersion?: string;
10
- mutable?: boolean;
11
- }) {
7
+ constructor(param: { objectId: string; initialSharedVersion?: string; mutable?: boolean }) {
12
8
  this.objectId = param.objectId;
13
9
  this.initialSharedVersion = param.initialSharedVersion;
14
10
  }
@@ -24,9 +20,9 @@ export class SuiSharedObject {
24
20
  SharedObject: {
25
21
  objectId: this.objectId,
26
22
  initialSharedVersion: this.initialSharedVersion,
27
- mutable,
28
- },
29
- },
23
+ mutable
24
+ }
25
+ }
30
26
  };
31
27
  }
32
28
  }