@layerzerolabs/lz-sui-sdk-v2 3.0.111-sui.0 → 3.0.111

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 (33) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/index.cjs +105 -68
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.mts +23 -4
  5. package/dist/index.d.ts +23 -4
  6. package/dist/index.mjs +101 -68
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +6 -6
  9. package/src/errors.ts +9 -0
  10. package/src/index.ts +1 -0
  11. package/src/modules/counter.ts +17 -28
  12. package/src/modules/endpoint.ts +36 -43
  13. package/src/modules/simple-message-lib.ts +4 -12
  14. package/src/types.ts +5 -0
  15. package/src/utils.ts +42 -18
  16. package/deployments/placeholder0-sandbox-local/blocked_message_lib.json +0 -58
  17. package/deployments/placeholder0-sandbox-local/counter.json +0 -98
  18. package/deployments/placeholder0-sandbox-local/endpoint_v2.json +0 -84
  19. package/deployments/placeholder0-sandbox-local/message_lib_types.json +0 -47
  20. package/deployments/placeholder0-sandbox-local/oapp_core.json +0 -47
  21. package/deployments/placeholder0-sandbox-local/oapp_discovery.json +0 -58
  22. package/deployments/placeholder0-sandbox-local/object-Counter.json +0 -9
  23. package/deployments/placeholder0-sandbox-local/object-CounterAdminCap.json +0 -9
  24. package/deployments/placeholder0-sandbox-local/object-CounterOappCap.json +0 -5
  25. package/deployments/placeholder0-sandbox-local/object-CounterOappCore.json +0 -5
  26. package/deployments/placeholder0-sandbox-local/object-EndpointV2.json +0 -9
  27. package/deployments/placeholder0-sandbox-local/object-EndpointV2AdminCap.json +0 -9
  28. package/deployments/placeholder0-sandbox-local/object-SimpleMessageLib.json +0 -9
  29. package/deployments/placeholder0-sandbox-local/object-SimpleMessageLibCap.json +0 -5
  30. package/deployments/placeholder0-sandbox-local/protocol_discovery.json +0 -49
  31. package/deployments/placeholder0-sandbox-local/simple_message_lib.json +0 -58
  32. package/deployments/placeholder0-sandbox-local/utils.json +0 -112
  33. package/deployments/placeholder0-sandbox-local/zro.json +0 -67
package/dist/index.mjs CHANGED
@@ -7,22 +7,42 @@ import { SuiProvider } from '@layerzerolabs/lz-corekit-sui';
7
7
  import { Chain, Stage, chainAndStageToNetwork } from '@layerzerolabs/lz-definitions';
8
8
 
9
9
  // src/modules/simple-message-lib.ts
10
- async function devInspectTransaction(suiClient, tx, sender) {
10
+
11
+ // src/errors.ts
12
+ var MoveAbortError = class extends Error {
13
+ constructor(abortCode, rawMsg) {
14
+ super(`Move abort with code: ${abortCode}. Raw error message: ${rawMsg}`);
15
+ this.abortCode = abortCode;
16
+ }
17
+ };
18
+ var UnclassifiedError = class extends Error {
19
+ };
20
+
21
+ // src/utils.ts
22
+ async function moveView(suiClient, tx, sender) {
23
+ if (sender === void 0) {
24
+ sender = Ed25519Keypair.generate().toSuiAddress();
25
+ }
11
26
  const { results, error } = await suiClient.devInspectTransactionBlock({
12
27
  transactionBlock: tx,
13
28
  sender
14
29
  });
15
30
  if (error != void 0 && error != null) {
16
- throw new Error(error);
31
+ throw handleError(error);
17
32
  }
18
- return results;
19
- }
20
- async function moveView(suiClient, tx, sender) {
21
- if (sender === void 0) {
22
- sender = Ed25519Keypair.generate().toSuiAddress();
33
+ if (results === void 0 || results === null) {
34
+ throw new Error("No results found");
23
35
  }
24
- const result = await devInspectTransaction(suiClient, tx, sender);
25
- return result ? result[result.length - 1] : null;
36
+ const lastCommandResults = results[results.length - 1];
37
+ if (lastCommandResults.returnValues === void 0) {
38
+ throw new Error("No return values found");
39
+ }
40
+ return lastCommandResults.returnValues.map((result) => {
41
+ return {
42
+ value: new Uint8Array(result[0]),
43
+ type: result[1]
44
+ };
45
+ });
26
46
  }
27
47
  function readAddressFromDeployment(network, name) {
28
48
  const deploymentPath = path.join(__dirname, "..", "deployments", network, `${name}.json`);
@@ -49,6 +69,25 @@ async function validateTransaction(client, signer, tx) {
49
69
  await client.waitForTransaction({ digest: result.digest });
50
70
  return result;
51
71
  }
72
+ function handleError(e) {
73
+ if (e.includes("ExecutionError")) {
74
+ const majorStatusMatch = e.match(/major_status:\s([A-Z_]+)/);
75
+ if (majorStatusMatch !== null) {
76
+ const major_status = majorStatusMatch[1];
77
+ if (major_status === "ABORTED") {
78
+ const subStatusMatch = e.match(/sub_status:\sSome\((\d+)\)/);
79
+ if (subStatusMatch === null) {
80
+ return new MoveAbortError(Number.NEGATIVE_INFINITY, e);
81
+ } else {
82
+ return new MoveAbortError(Number(subStatusMatch[1]), e);
83
+ }
84
+ }
85
+ } else {
86
+ return new UnclassifiedError(e);
87
+ }
88
+ }
89
+ return new Error(e);
90
+ }
52
91
 
53
92
  // src/modules/simple-message-lib.ts
54
93
  var SimpleMessageLib = class {
@@ -85,8 +124,7 @@ var SimpleMessageLib = class {
85
124
  arguments: [tx.object(this.objects.simple_message_lib)]
86
125
  });
87
126
  const result = await moveView(this.client, tx);
88
- const bytes = new Uint8Array(result?.returnValues[0][0]);
89
- return bcs.U64.parse(bytes);
127
+ return bcs.U64.parse(result[0].value);
90
128
  }
91
129
  async getZroFee() {
92
130
  const tx = new Transaction();
@@ -96,8 +134,7 @@ var SimpleMessageLib = class {
96
134
  arguments: [tx.object(this.objects.simple_message_lib)]
97
135
  });
98
136
  const result = await moveView(this.client, tx);
99
- const bytes = new Uint8Array(result?.returnValues[0][0]);
100
- return bcs.U64.parse(bytes);
137
+ return bcs.U64.parse(result[0].value);
101
138
  }
102
139
  async getFeeRecipient() {
103
140
  const tx = new Transaction();
@@ -107,8 +144,7 @@ var SimpleMessageLib = class {
107
144
  arguments: [tx.object(this.objects.simple_message_lib)]
108
145
  });
109
146
  const result = await moveView(this.client, tx);
110
- const bytes = new Uint8Array(result?.returnValues[0][0]);
111
- return bcs.Address.parse(bytes);
147
+ return bcs.Address.parse(result[0].value);
112
148
  }
113
149
  async isRegistered() {
114
150
  const tx = new Transaction();
@@ -118,8 +154,7 @@ var SimpleMessageLib = class {
118
154
  arguments: [tx.object(this.objects.simple_message_lib), tx.object(this.objects.endpoint_v2)]
119
155
  });
120
156
  const result = await moveView(this.client, tx);
121
- const bytes = new Uint8Array(result?.returnValues[0][0]);
122
- return bcs.Bool.parse(bytes);
157
+ return bcs.Bool.parse(result[0].value);
123
158
  }
124
159
  // === Admin Functions ===
125
160
  populateRegisterLibraryTransaction() {
@@ -237,6 +272,12 @@ var SimpleMessageLib = class {
237
272
  populateGetConfigTransaction(tx) {
238
273
  }
239
274
  };
275
+ var EndpointErrorCode = /* @__PURE__ */ ((EndpointErrorCode2) => {
276
+ EndpointErrorCode2[EndpointErrorCode2["EDefaultReceiveLibUnavailable"] = 2] = "EDefaultReceiveLibUnavailable";
277
+ EndpointErrorCode2[EndpointErrorCode2["EDefaultSendLibUnavailable"] = 3] = "EDefaultSendLibUnavailable";
278
+ EndpointErrorCode2[EndpointErrorCode2["ENotInitialized"] = 4] = "ENotInitialized";
279
+ return EndpointErrorCode2;
280
+ })(EndpointErrorCode || {});
240
281
  var Endpoint = class {
241
282
  constructor(packageId, client, objects, context) {
242
283
  this.context = context;
@@ -259,10 +300,12 @@ var Endpoint = class {
259
300
  });
260
301
  try {
261
302
  const result = await moveView(this.client, tx);
262
- const bytes = new Uint8Array(result?.returnValues[0][0]);
263
- return bcs.U32.parse(bytes);
303
+ return bcs.U32.parse(result[0].value);
264
304
  } catch (e) {
265
- return 0;
305
+ if (e instanceof MoveAbortError && e.abortCode === 4 /* ENotInitialized */.valueOf()) {
306
+ return 0;
307
+ }
308
+ throw e;
266
309
  }
267
310
  }
268
311
  populateInitEidTransaction(eid) {
@@ -287,10 +330,12 @@ var Endpoint = class {
287
330
  });
288
331
  try {
289
332
  const result = await moveView(this.client, tx);
290
- const bytes = new Uint8Array(result?.returnValues[0][0]);
291
- return bcs.Address.parse(bytes);
292
- } catch (error) {
293
- return "0x0";
333
+ return bcs.Address.parse(result[0].value);
334
+ } catch (e) {
335
+ if (e instanceof MoveAbortError && e.abortCode === 3 /* EDefaultSendLibUnavailable */.valueOf()) {
336
+ return "0x0";
337
+ }
338
+ throw e;
294
339
  }
295
340
  }
296
341
  populateSetDefaultSendLibraryTransaction(dstEid, newLib) {
@@ -316,10 +361,12 @@ var Endpoint = class {
316
361
  });
317
362
  try {
318
363
  const result = await moveView(this.client, tx);
319
- const bytes = new Uint8Array(result?.returnValues[0][0]);
320
- return bcs.Address.parse(bytes);
321
- } catch (error) {
322
- return "0x";
364
+ return bcs.Address.parse(result[0].value);
365
+ } catch (e) {
366
+ if (e instanceof MoveAbortError && e.abortCode === 2 /* EDefaultReceiveLibUnavailable */.valueOf()) {
367
+ return "0x0";
368
+ }
369
+ throw e;
323
370
  }
324
371
  }
325
372
  populateSetDefaultReceiveLibraryTransaction(srcEid, newLib, gracePeriod) {
@@ -362,10 +409,8 @@ var Endpoint = class {
362
409
  arguments: [tx.object(this.objects.endpoint_v2), tx.pure.address(sender), tx.pure.u32(dstEid)]
363
410
  });
364
411
  const result = await moveView(this.client, tx);
365
- const bytes = new Uint8Array(result?.returnValues[0][0]);
366
- const lib = bcs.Address.parse(bytes);
367
- const isDefaultBytes = new Uint8Array(result?.returnValues[1][0]);
368
- const isDefault = bcs.Bool.parse(isDefaultBytes);
412
+ const lib = bcs.Address.parse(result[0].value);
413
+ const isDefault = bcs.Bool.parse(result[1].value);
369
414
  return [lib, isDefault];
370
415
  }
371
416
  async getReceiveLibrary(receiver, srcEid) {
@@ -376,10 +421,8 @@ var Endpoint = class {
376
421
  arguments: [tx.object(this.objects.endpoint_v2), tx.pure.address(receiver), tx.pure.u32(srcEid)]
377
422
  });
378
423
  const result = await moveView(this.client, tx);
379
- const bytes = new Uint8Array(result?.returnValues[0][0]);
380
- const lib = bcs.Address.parse(bytes);
381
- const isDefaultBytes = new Uint8Array(result?.returnValues[1][0]);
382
- const isDefault = bcs.Bool.parse(isDefaultBytes);
424
+ const lib = bcs.Address.parse(result[0].value);
425
+ const isDefault = bcs.Bool.parse(result[1].value);
383
426
  return [lib, isDefault];
384
427
  }
385
428
  async getInboundNonce(receiver, srcEid, sender) {
@@ -395,8 +438,7 @@ var Endpoint = class {
395
438
  ]
396
439
  });
397
440
  const result = await moveView(this.client, tx);
398
- const bytes = new Uint8Array(result?.returnValues[0][0]);
399
- return BigInt(bcs.U64.parse(bytes));
441
+ return BigInt(bcs.U64.parse(result[0].value));
400
442
  }
401
443
  async getLazyInboundNonce(receiver, srcEid, sender) {
402
444
  const tx = new Transaction();
@@ -411,8 +453,7 @@ var Endpoint = class {
411
453
  ]
412
454
  });
413
455
  const result = await moveView(this.client, tx);
414
- const bytes = new Uint8Array(result?.returnValues[0][0]);
415
- return BigInt(bcs.U64.parse(bytes));
456
+ return BigInt(bcs.U64.parse(result[0].value));
416
457
  }
417
458
  async getOutboundNonce(sender, dstEid, receiver) {
418
459
  const tx = new Transaction();
@@ -427,8 +468,7 @@ var Endpoint = class {
427
468
  ]
428
469
  });
429
470
  const result = await moveView(this.client, tx);
430
- const bytes = new Uint8Array(result?.returnValues[0][0]);
431
- return BigInt(bcs.U64.parse(bytes));
471
+ return BigInt(bcs.U64.parse(result[0].value));
432
472
  }
433
473
  async getInboundPayloadHash(receiver, srcEid, sender, nonce) {
434
474
  const tx = new Transaction();
@@ -445,8 +485,7 @@ var Endpoint = class {
445
485
  });
446
486
  try {
447
487
  const result = await moveView(this.client, tx);
448
- const bytes = new Uint8Array(result?.returnValues[0][0]);
449
- const parsed = bcs.vector(bcs.u8()).parse(bytes);
488
+ const parsed = bcs.vector(bcs.u8()).parse(result[0].value);
450
489
  return Buffer.from(parsed);
451
490
  } catch (error) {
452
491
  return null;
@@ -466,8 +505,7 @@ var Endpoint = class {
466
505
  ]
467
506
  });
468
507
  const result = await moveView(this.client, tx);
469
- const bytes = new Uint8Array(result?.returnValues[0][0]);
470
- const parsed = bcs.vector(bcs.u8()).parse(bytes);
508
+ const parsed = bcs.vector(bcs.u8()).parse(result[0].value);
471
509
  return Buffer.from(parsed);
472
510
  }
473
511
  // TODO: more view functions to be added here
@@ -486,6 +524,10 @@ var MessagingFeeBcs = bcs.struct("MessagingFee", {
486
524
  });
487
525
 
488
526
  // src/modules/counter.ts
527
+ var CounterErrorCode = /* @__PURE__ */ ((CounterErrorCode2) => {
528
+ CounterErrorCode2[CounterErrorCode2["EPeerNotFound"] = 0] = "EPeerNotFound";
529
+ return CounterErrorCode2;
530
+ })(CounterErrorCode || {});
489
531
  var Counter = class {
490
532
  constructor(packageId, utilsPkgId, client, objects, context) {
491
533
  this.context = context;
@@ -508,10 +550,12 @@ var Counter = class {
508
550
  });
509
551
  try {
510
552
  const result = await moveView(this.client, tx);
511
- const bytes = new Uint8Array(result?.returnValues[0][0]);
512
- return bcs.Address.parse(bytes);
553
+ return bcs.Address.parse(result[0].value);
513
554
  } catch (e) {
514
- return "";
555
+ if (e instanceof MoveAbortError && e.abortCode === 0 /* EPeerNotFound */.valueOf()) {
556
+ return "0x0";
557
+ }
558
+ throw e;
515
559
  }
516
560
  }
517
561
  async getCount() {
@@ -521,14 +565,9 @@ var Counter = class {
521
565
  typeArguments: [],
522
566
  arguments: [tx.object(this.objects.counter)]
523
567
  });
524
- try {
525
- const result = await moveView(this.client, tx);
526
- const bytes = new Uint8Array(result?.returnValues[0][0]);
527
- const counterStr = bcs.U64.parse(bytes);
528
- return Number(counterStr);
529
- } catch (e) {
530
- return 0;
531
- }
568
+ const result = await moveView(this.client, tx);
569
+ const counterStr = bcs.U64.parse(result[0].value);
570
+ return Number(counterStr);
532
571
  }
533
572
  async getComposedCount() {
534
573
  const tx = new Transaction();
@@ -537,14 +576,9 @@ var Counter = class {
537
576
  typeArguments: [],
538
577
  arguments: [tx.object(this.objects.counter)]
539
578
  });
540
- try {
541
- const result = await moveView(this.client, tx);
542
- const bytes = new Uint8Array(result?.returnValues[0][0]);
543
- const counterStr = bcs.U64.parse(bytes);
544
- return Number(counterStr);
545
- } catch (e) {
546
- return 0;
547
- }
579
+ const result = await moveView(this.client, tx);
580
+ const counterStr = bcs.U64.parse(result[0].value);
581
+ return Number(counterStr);
548
582
  }
549
583
  populateSetPeerTransaction(dstEid, peer) {
550
584
  const tx = new Transaction();
@@ -617,8 +651,7 @@ var Counter = class {
617
651
  const executedCall = this.context.simpleMessageLib.quoteMoveCall(tx, quoteCall);
618
652
  this.context.endpoint.confirmQuoteMoveCall(tx, executedCall);
619
653
  const result = await moveView(this.client, tx);
620
- const bytes = new Uint8Array(result?.returnValues[0][0]);
621
- const messageFee = MessagingFeeBcs.parse(bytes);
654
+ const messageFee = MessagingFeeBcs.parse(result[0].value);
622
655
  return [BigInt(messageFee.native_fee), BigInt(messageFee.zro_fee)];
623
656
  }
624
657
  async send(sender, dstEid, msgType, options, sendValue, nativeFee, zroFee) {
@@ -1143,6 +1176,6 @@ var SDK = class {
1143
1176
  }
1144
1177
  };
1145
1178
 
1146
- export { Counter, Endpoint, MessagingFeeBcs, SDK, SimpleMessageLib, Utils, Zro, devInspectTransaction, getSDKFromProvider, moveView, readAddressFromDeployment, validateTransaction };
1179
+ export { Counter, CounterErrorCode, Endpoint, EndpointErrorCode, MessagingFeeBcs, MoveAbortError, SDK, SimpleMessageLib, UnclassifiedError, Utils, Zro, getSDKFromProvider, handleError, moveView, readAddressFromDeployment, validateTransaction };
1147
1180
  //# sourceMappingURL=index.mjs.map
1148
1181
  //# sourceMappingURL=index.mjs.map