@layerzerolabs/common-suimove 1.2.69 → 1.2.71

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.
Files changed (55) hide show
  1. package/dist/2RWPJSYR.js +11 -0
  2. package/dist/2RWPJSYR.js.map +1 -0
  3. package/dist/DMFKLZKD.js +3 -0
  4. package/dist/DMFKLZKD.js.map +1 -0
  5. package/dist/JZMKCXBO.js +25 -0
  6. package/dist/JZMKCXBO.js.map +1 -0
  7. package/dist/QRJFMNTB.js +3 -0
  8. package/dist/QRJFMNTB.js.map +1 -0
  9. package/dist/UWX3Y5ZB.js +273 -0
  10. package/dist/UWX3Y5ZB.js.map +1 -0
  11. package/dist/VABOX5FT.js +22 -0
  12. package/dist/VABOX5FT.js.map +1 -0
  13. package/dist/VUOMXK5T.js +6 -0
  14. package/dist/VUOMXK5T.js.map +1 -0
  15. package/dist/Y5EOMP5J.js +3 -0
  16. package/dist/Y5EOMP5J.js.map +1 -0
  17. package/dist/error.d.ts +7 -0
  18. package/dist/error.d.ts.map +1 -0
  19. package/dist/error.js +4 -0
  20. package/dist/error.js.map +1 -0
  21. package/{src/index.ts → dist/index.d.ts} +1 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/multiSigTransaction.d.ts +90 -0
  25. package/dist/multiSigTransaction.d.ts.map +1 -0
  26. package/dist/multiSigTransaction.js +4 -0
  27. package/dist/multiSigTransaction.js.map +1 -0
  28. package/{src/provider.ts → dist/provider.d.ts} +11 -44
  29. package/dist/provider.d.ts.map +1 -0
  30. package/dist/provider.js +3 -0
  31. package/dist/provider.js.map +1 -0
  32. package/dist/transaction.d.ts +117 -0
  33. package/dist/transaction.d.ts.map +1 -0
  34. package/dist/transaction.js +3 -0
  35. package/dist/transaction.js.map +1 -0
  36. package/dist/types.d.ts +73 -0
  37. package/dist/types.d.ts.map +1 -0
  38. package/dist/types.js +3 -0
  39. package/dist/types.js.map +1 -0
  40. package/dist/utils.d.ts +83 -0
  41. package/dist/utils.d.ts.map +1 -0
  42. package/dist/utils.js +5 -0
  43. package/dist/utils.js.map +1 -0
  44. package/{src/verification.ts → dist/verification.d.ts} +6 -8
  45. package/dist/verification.d.ts.map +1 -0
  46. package/dist/verification.js +4 -0
  47. package/dist/verification.js.map +1 -0
  48. package/package.json +9 -6
  49. package/src/error.ts +0 -9
  50. package/src/multiSigTransaction.ts +0 -39
  51. package/src/transaction.ts +0 -137
  52. package/src/types.ts +0 -163
  53. package/src/utils.ts +0 -488
  54. package/tsconfig.json +0 -20
  55. package/tsup.config.ts +0 -8
package/src/utils.ts DELETED
@@ -1,488 +0,0 @@
1
- import { normalizeIotaAddress } from '@iota/iota-sdk/utils';
2
- import type {
3
- CoinStruct,
4
- GetObjectParams,
5
- GetTransactionBlockParams,
6
- SuiObjectChange,
7
- SuiObjectDataOptions,
8
- SuiTransactionBlockResponseOptions,
9
- } from '@mysten/sui/client';
10
- import { fromBase64, normalizeSuiAddress, parseStructTag } from '@mysten/sui/utils';
11
-
12
- import { ChainName } from '@layerzerolabs/layerzero-definitions';
13
- import type {
14
- AllRequired,
15
- MaybePartial,
16
- Prettify,
17
- RemoveNever,
18
- } from '@layerzerolabs/typescript-utils';
19
-
20
- import { SuiMoveAbortError, SuiMoveUnclassifiedError } from './error';
21
- import type { SuiMoveProvider } from './provider';
22
- import type { SuiMoveTransaction } from './transaction';
23
- import type {
24
- SuiMoveEvent,
25
- SuiMoveExecutionResult,
26
- SuiMoveObjectResponse,
27
- SuiMoveTransactionBlockResponse,
28
- SuiMoveViewResult,
29
- } from './types';
30
-
31
- const MOCK_SENDER = '0x1234567890123456789012345678901234567890123456789012345678901234';
32
-
33
- export interface MatchQuery {
34
- type: string;
35
- check: 'includes' | 'startsWith' | 'endsWith' | 'equals' | 'regex';
36
- }
37
-
38
- type FullObjectOptions = AllRequired<SuiObjectDataOptions>;
39
- type FullBlockResponseOptions = AllRequired<SuiTransactionBlockResponseOptions>;
40
-
41
- type ObjectChangeTypes = SuiObjectChange['type'];
42
- type ObjectChangeTypesOptions = {
43
- [K in ObjectChangeTypes as `show${Capitalize<K>}`]?: boolean;
44
- };
45
-
46
- type ObjectChangeTypeResults<Options extends ObjectChangeTypesOptions> = Prettify<
47
- RemoveNever<{
48
- [K in ObjectChangeTypes]: `show${Capitalize<K>}` extends keyof Options
49
- ? Options[`show${Capitalize<K>}`] extends true
50
- ? Extract<SuiObjectChange, { type: K }>[]
51
- : never
52
- : never;
53
- }>
54
- >;
55
-
56
- const objectOptionKeys: (keyof FullObjectOptions)[] = [
57
- 'showBcs',
58
- 'showContent',
59
- 'showType',
60
- 'showDisplay',
61
- 'showOwner',
62
- 'showPreviousTransaction',
63
- 'showStorageRebate',
64
- ] as const;
65
-
66
- const blockResponseOptionsKeys: (keyof FullBlockResponseOptions)[] = [
67
- 'showBalanceChanges',
68
- 'showEffects',
69
- 'showEvents',
70
- 'showObjectChanges',
71
- 'showRawEffects',
72
- ] as const;
73
-
74
- type OptionsValidated<
75
- FullOptions extends Record<string, any>,
76
- CurrentOptions extends Record<string, any>,
77
- Data extends Record<string, any>,
78
- > = Prettify<
79
- RemoveNever<{
80
- [key in keyof AllRequired<Data>]: key extends string
81
- ? `show${Capitalize<key>}` extends keyof FullOptions
82
- ? CurrentOptions[`show${Capitalize<key>}`] extends true
83
- ? NonNullable<Data[key]>
84
- : never
85
- : Data[key]
86
- : never;
87
- }>
88
- >;
89
-
90
- const validateOptions = <
91
- FullOptions extends Record<string, any>,
92
- Options extends Record<string, any>,
93
- Data extends Record<string, any>,
94
- >(
95
- data: Data,
96
- fullOptionKeys: string[],
97
- options?: Options,
98
- ): OptionsValidated<FullOptions, Options, Data> => {
99
- // check inclusion of all options
100
- fullOptionKeys.forEach((option) => {
101
- // Remove 'show' prefix and convert first letter to lowercase for camelCase
102
- const fieldName = option.slice('show'.length);
103
- const field = fieldName.charAt(0).toLowerCase() + fieldName.slice(1);
104
- if (options?.[option] && !data[field]) {
105
- throw new Error(`Missing required field ${field} on data object ${data}`);
106
- }
107
- });
108
-
109
- // check validity of inclusions:
110
- return Object.fromEntries(
111
- Object.entries(data).map(([key, value]) => {
112
- for (const option of fullOptionKeys) {
113
- // Convert option to expected field name
114
- const fieldName = option.slice('show'.length);
115
- const expectedField = fieldName.charAt(0).toLowerCase() + fieldName.slice(1);
116
- if (expectedField === key && options?.[option] && !value) {
117
- throw new Error(
118
- `Failed fetching data for option ${option} on object ${data.objectId}`,
119
- );
120
- }
121
- }
122
- return [key, value];
123
- }),
124
- ) as OptionsValidated<FullObjectOptions, Options, Data>;
125
- };
126
-
127
- export const checkInclusion = (objectType: string, query: MatchQuery) => {
128
- const check = query.check;
129
- const type = query.type;
130
- switch (check) {
131
- case 'includes':
132
- return objectType.includes(type);
133
- case 'startsWith':
134
- return objectType.startsWith(type);
135
- case 'endsWith':
136
- return objectType.endsWith(type);
137
- case 'equals':
138
- return objectType === type;
139
- case 'regex':
140
- return new RegExp(type).test(objectType);
141
- default:
142
- throw new Error(`Unknown check type: ${check}`);
143
- }
144
- };
145
-
146
- export const filterObjectChanges = <Options extends ObjectChangeTypesOptions>(
147
- objectChanges: SuiObjectChange[],
148
- query: MatchQuery | 'all',
149
- options?: Options,
150
- ): ObjectChangeTypeResults<Options> => {
151
- const result = {} as ObjectChangeTypeResults<Options>;
152
- type key = keyof ObjectChangeTypeResults<Options>;
153
- const capitalize = (s: string) => s.slice(0, 1).toUpperCase() + s.slice(1);
154
-
155
- for (const objectChange of objectChanges) {
156
- // Published has packageId
157
- if (objectChange.type === 'published') {
158
- if (
159
- options?.showPublished &&
160
- (query === 'all' || checkInclusion(objectChange.packageId, query))
161
- ) {
162
- // TODO: consider removing `as` casts
163
- result['published' as key] ??= [] as any;
164
- result['published' as key].push(objectChange as any);
165
- }
166
- } else {
167
- // Everyone else has objectType
168
- const show = `show${capitalize(objectChange.type)}` as keyof Options;
169
- if (
170
- options?.[show] &&
171
- (query === 'all' || checkInclusion(objectChange.objectType, query))
172
- ) {
173
- // TODO: consider removing `as` casts
174
- result[objectChange.type as key] ??= [] as any;
175
- result[objectChange.type as key].push(objectChange as any);
176
- }
177
- }
178
- }
179
-
180
- return result;
181
- };
182
-
183
- /**
184
- * Converts raw Sui move events to SuiMoveEvent format
185
- */
186
- export const convertToSuiMoveEvents = (rawEvents: any[]): SuiMoveEvent[] => {
187
- return rawEvents.map((event) => ({
188
- type: event.type,
189
- data: event.parsedJson,
190
- txHash: event.id.txDigest,
191
- }));
192
- };
193
-
194
- export function handleError(e: string): unknown {
195
- if (e.includes('ExecutionError')) {
196
- const majorStatusMatch = e.match(/major_status:\s([A-Z_]+)/);
197
- if (majorStatusMatch !== null) {
198
- const major_status = majorStatusMatch[1];
199
- if (major_status === 'ABORTED') {
200
- const subStatusMatch = e.match(/sub_status:\sSome\((\d+)\)/);
201
- if (subStatusMatch === null) {
202
- return new SuiMoveAbortError(Number.NEGATIVE_INFINITY, e);
203
- } else {
204
- return new SuiMoveAbortError(Number(subStatusMatch[1]), e);
205
- }
206
- }
207
- } else {
208
- return new SuiMoveUnclassifiedError(e);
209
- }
210
- }
211
- return new Error(e);
212
- }
213
-
214
- export async function suiMoveViewMultiResult(
215
- client: SuiMoveProvider,
216
- tx: SuiMoveTransaction,
217
- resultIndex: number[],
218
- ): Promise<SuiMoveViewResult[][]> {
219
- const { results, error } = await client.devInspectSuiMoveTransactionBlock({
220
- transactionBlock: tx,
221
- sender: MOCK_SENDER,
222
- });
223
-
224
- if (error != undefined && error != null) {
225
- throw handleError(error);
226
- }
227
- if (results === undefined || results === null) {
228
- throw new Error('No results found');
229
- }
230
-
231
- const selectedResults: SuiMoveExecutionResult[] = resultIndex.map((idx) => {
232
- return results[idx];
233
- });
234
-
235
- return selectedResults.map((result) => {
236
- if (result.returnValues === undefined) {
237
- throw new Error('No return values found');
238
- }
239
- return result.returnValues.map((result) => {
240
- return {
241
- value:
242
- typeof result[0] === 'string'
243
- ? fromBase64(result[0])
244
- : new Uint8Array(result[0]),
245
- type: result[1],
246
- };
247
- });
248
- });
249
- }
250
-
251
- export async function suiMoveView(
252
- suiClient: SuiMoveProvider,
253
- tx: SuiMoveTransaction,
254
- ): Promise<SuiMoveViewResult[]> {
255
- const results = await suiMoveViewMultiResult(suiClient, tx, [
256
- tx.getData().commands.length - 1, // last command
257
- ]);
258
- return results[0];
259
- }
260
-
261
- export async function suiMoveViewParsed<T>({
262
- client,
263
- tx,
264
- parser,
265
- }: {
266
- client: SuiMoveProvider;
267
- tx: SuiMoveTransaction;
268
- parser: (result: { value: Uint8Array }[]) => T;
269
- }): Promise<T> {
270
- const results = await suiMoveViewMultiResult(client, tx, [
271
- tx.getData().commands.length - 1, // last command
272
- ]);
273
- return parser(results[0]);
274
- }
275
-
276
- /**
277
- * Returns the defining package ID for a given object type. This is the package
278
- * that defined the object's Move type at the time the object was created.
279
- *
280
- * @param objectType The object type, e.g. 0xc6b8aab4e0124a27071228cb4c2b422344cb13574a9641ed0d9177c7111ed7::my_coin::MY_COIN
281
- * @returns The defining package ID, e.g. 0xc6b8aab4e0124a27071228cb4c2b422344cb13574a9641ed0d9177c7111ed7
282
- */
283
- export function getDefiningPackageIdFromObjectType(
284
- chainName: ChainName,
285
- objectType: string,
286
- ): string {
287
- const address = parseStructTag(objectType).address;
288
- return normalizeSuiMoveAddress(address, chainName);
289
- }
290
-
291
- export async function getSuiMoveObjectValidated<const Options extends SuiObjectDataOptions>(
292
- args: Omit<GetObjectParams, 'options'> & { options?: Options; client: SuiMoveProvider },
293
- ): Promise<
294
- OptionsValidated<FullObjectOptions, Options, NonNullable<SuiMoveObjectResponse['data']>>
295
- > {
296
- const object = await args.client.getSuiMoveObject(args);
297
- if (object.error) {
298
- throw new Error(`Failed to get object ${args.id}`, { cause: object.error });
299
- } else if (!object.data) {
300
- throw new Error(`Object not found: ${args.id}`);
301
- }
302
-
303
- return validateOptions<FullObjectOptions, Options, NonNullable<SuiMoveObjectResponse['data']>>(
304
- object.data,
305
- objectOptionKeys,
306
- args.options,
307
- );
308
- }
309
-
310
- export async function getSuiMoveTransactionBlockValidated<
311
- const Options extends SuiTransactionBlockResponseOptions,
312
- >(
313
- args: Omit<GetTransactionBlockParams, 'options'> & {
314
- options?: Options;
315
- client: SuiMoveProvider;
316
- },
317
- ): Promise<OptionsValidated<FullBlockResponseOptions, Options, SuiMoveTransactionBlockResponse>> {
318
- const txBlock = await args.client.getSuiMoveTransactionBlock(args);
319
- if (txBlock.errors?.length) {
320
- throw new Error(`Couldn't fetch transaction block due to errors: ${txBlock.errors}`);
321
- }
322
-
323
- return validateOptions<FullBlockResponseOptions, Options, SuiMoveTransactionBlockResponse>(
324
- txBlock,
325
- blockResponseOptionsKeys,
326
- args.options,
327
- );
328
- }
329
-
330
- /**
331
- * Fetches all owned coins that have the specified package id
332
- * @param chainName chainName to denormalize the addresses
333
- * @param normalizedCoinPackageId Coin package id to search for
334
- * @param normalizedWalletAddress Wallet address to search for coins on
335
- * @returns Array of all found coin objects, sorted by balance
336
- */
337
- export async function searchForCoinTypeInWallet(
338
- chainName: ChainName,
339
- coinPackageId: string,
340
- walletAddress: string,
341
- client: SuiMoveProvider,
342
- ): Promise<CoinStruct[]> {
343
- let cursor: string | undefined | null = undefined;
344
- let hasNextPage = true;
345
- let coinObjects = [] as CoinStruct[];
346
-
347
- while (hasNextPage) {
348
- const coins = await client.getAllSuiMoveCoins({
349
- owner: walletAddress,
350
- limit: 50,
351
- cursor,
352
- });
353
-
354
- // Sui has its own normalization for addresses that we need to use to compare addresses
355
- const normalizedCoinPackageId = normalizeSuiMoveAddress(coinPackageId, chainName);
356
-
357
- const matchedCoins = coins.data.filter((coin) => {
358
- const coinType = coin.coinType;
359
- const definingPackageId = getDefiningPackageIdFromObjectType(chainName, coinType);
360
- return definingPackageId === normalizedCoinPackageId;
361
- });
362
-
363
- coinObjects = coinObjects.concat(matchedCoins);
364
- cursor = coins.nextCursor;
365
- hasNextPage = coins.hasNextPage;
366
- }
367
- return coinObjects.sort((a, b) => Number(BigInt(b.balance) - BigInt(a.balance)));
368
- }
369
-
370
- export async function getSuiMoveOwnedObjectsByType<
371
- T extends Record<string, MatchQuery>,
372
- Options extends SuiObjectDataOptions,
373
- AllowPartial extends boolean = false,
374
- >({
375
- walletAddress,
376
- typeInclusions,
377
- options,
378
- client,
379
- }: {
380
- walletAddress: string;
381
- typeInclusions: T;
382
- options?: Omit<Options, 'showType'> & { allowPartial?: AllowPartial };
383
- client: SuiMoveProvider;
384
- }): Promise<
385
- Record<
386
- keyof T,
387
- MaybePartial<
388
- OptionsValidated<
389
- FullObjectOptions,
390
- Options & { showType: true },
391
- NonNullable<SuiMoveObjectResponse['data']>
392
- >[],
393
- AllowPartial
394
- >
395
- >
396
- > {
397
- let cursor: string | undefined | null = undefined;
398
- let hasNextPage = true;
399
- const result = {} as Record<
400
- keyof T,
401
- OptionsValidated<
402
- FullObjectOptions,
403
- Options & { showType: true },
404
- NonNullable<SuiMoveObjectResponse['data']>
405
- >[]
406
- >;
407
- const typeInclusionsArray = Object.entries(typeInclusions);
408
-
409
- while (hasNextPage) {
410
- const objects = await client.getSuiMoveOwnedObject({
411
- owner: walletAddress,
412
- options: {
413
- ...options,
414
- showType: true,
415
- },
416
- cursor,
417
- limit: 50,
418
- });
419
- for (const object of objects.data) {
420
- if (!object.data) continue;
421
- const objectType = object.data.type;
422
- if (!objectType) {
423
- continue;
424
- }
425
- for (const [key, query] of typeInclusionsArray) {
426
- if (checkInclusion(objectType, query)) {
427
- const validated = validateOptions<
428
- FullObjectOptions,
429
- Options,
430
- NonNullable<SuiMoveObjectResponse['data']>
431
- >(object.data, objectOptionKeys, options as Options | undefined);
432
- result[key as keyof T] ??= [];
433
- result[key as keyof T].push(validated);
434
- }
435
- }
436
- }
437
- cursor = objects.nextCursor;
438
- hasNextPage = objects.hasNextPage;
439
- }
440
-
441
- if (!options?.allowPartial && Object.keys(result).length !== typeInclusionsArray.length) {
442
- const difference = new Set(typeInclusionsArray.map(([k]) => k));
443
- Object.keys(result).forEach((key) => difference.delete(key));
444
- throw new Error(`Couldn't find all objects, missing: ${[...difference]}`);
445
- }
446
-
447
- return result;
448
- }
449
-
450
- export async function getSuiMovePackagePublishObjectChanges<
451
- Queries extends Record<string, MatchQuery | 'all'>,
452
- ChangeOptions extends ObjectChangeTypesOptions,
453
- >({
454
- packageId,
455
- queries,
456
- options,
457
- client,
458
- }: {
459
- packageId: string;
460
- queries: Queries;
461
- client: SuiMoveProvider;
462
- options?: ChangeOptions;
463
- }): Promise<Record<keyof Queries, ObjectChangeTypeResults<ChangeOptions>>> {
464
- const pkgObject = await getSuiMoveObjectValidated({
465
- id: packageId,
466
- client,
467
- options: { showPreviousTransaction: true },
468
- });
469
-
470
- const txBlock = await getSuiMoveTransactionBlockValidated({
471
- digest: pkgObject.previousTransaction,
472
- options: { showObjectChanges: true },
473
- client,
474
- });
475
-
476
- return Object.fromEntries(
477
- Object.entries(queries).map(([k, query]) => {
478
- return [k, filterObjectChanges(txBlock.objectChanges, query, options)];
479
- }),
480
- ) as Record<keyof Queries, ObjectChangeTypeResults<ChangeOptions>>;
481
- }
482
-
483
- export const normalizeSuiMoveAddress = (address: string, chainName: ChainName) => {
484
- if (chainName === ChainName.IOTAL1) {
485
- return normalizeIotaAddress(address);
486
- }
487
- return normalizeSuiAddress(address);
488
- };
package/tsconfig.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "extends": "@layerzerolabs/typescript-configuration/tsconfig.base.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./dist",
6
- "strictPropertyInitialization": false,
7
- "noUnusedLocals": false,
8
- "noUnusedParameters": false,
9
- "jsx": "react-jsx"
10
- },
11
- "exclude": [
12
- "node_modules",
13
- "**/__mocks__/*",
14
- "**/__tests__/*",
15
- "**/*.spec.ts",
16
- "**/*.test.ts",
17
- "dist"
18
- ],
19
- "include": ["src/**/*"]
20
- }
package/tsup.config.ts DELETED
@@ -1,8 +0,0 @@
1
- import { defineConfig } from 'tsup';
2
-
3
- import { createPackageTsupConfig } from '@layerzerolabs/tsup-configuration';
4
-
5
- export default defineConfig(({ watch }) => ({
6
- ...createPackageTsupConfig(),
7
- clean: !watch,
8
- }));