@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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @layerzerolabs/lz-sui-sdk-v2
2
2
 
3
+ ## 3.0.111
4
+
5
+ ### Patch Changes
6
+
7
+ - e0c412c: Publish new ton packages at July 11 2025
8
+ - Updated dependencies [e0c412c]
9
+ - @layerzerolabs/lz-corekit-sui@3.0.96
10
+ - @layerzerolabs/lz-core@3.0.111
11
+ - @layerzerolabs/lz-definitions@3.0.111
12
+
3
13
  ## 3.0.75
4
14
 
5
15
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -30,22 +30,42 @@ var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
30
30
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
31
31
 
32
32
  // src/modules/simple-message-lib.ts
33
- async function devInspectTransaction(suiClient, tx, sender) {
33
+
34
+ // src/errors.ts
35
+ var MoveAbortError = class extends Error {
36
+ constructor(abortCode, rawMsg) {
37
+ super(`Move abort with code: ${abortCode}. Raw error message: ${rawMsg}`);
38
+ this.abortCode = abortCode;
39
+ }
40
+ };
41
+ var UnclassifiedError = class extends Error {
42
+ };
43
+
44
+ // src/utils.ts
45
+ async function moveView(suiClient, tx, sender) {
46
+ if (sender === void 0) {
47
+ sender = ed25519.Ed25519Keypair.generate().toSuiAddress();
48
+ }
34
49
  const { results, error } = await suiClient.devInspectTransactionBlock({
35
50
  transactionBlock: tx,
36
51
  sender
37
52
  });
38
53
  if (error != void 0 && error != null) {
39
- throw new Error(error);
54
+ throw handleError(error);
40
55
  }
41
- return results;
42
- }
43
- async function moveView(suiClient, tx, sender) {
44
- if (sender === void 0) {
45
- sender = ed25519.Ed25519Keypair.generate().toSuiAddress();
56
+ if (results === void 0 || results === null) {
57
+ throw new Error("No results found");
46
58
  }
47
- const result = await devInspectTransaction(suiClient, tx, sender);
48
- return result ? result[result.length - 1] : null;
59
+ const lastCommandResults = results[results.length - 1];
60
+ if (lastCommandResults.returnValues === void 0) {
61
+ throw new Error("No return values found");
62
+ }
63
+ return lastCommandResults.returnValues.map((result) => {
64
+ return {
65
+ value: new Uint8Array(result[0]),
66
+ type: result[1]
67
+ };
68
+ });
49
69
  }
50
70
  function readAddressFromDeployment(network, name) {
51
71
  const deploymentPath = path__namespace.join(__dirname, "..", "deployments", network, `${name}.json`);
@@ -72,6 +92,25 @@ async function validateTransaction(client, signer, tx) {
72
92
  await client.waitForTransaction({ digest: result.digest });
73
93
  return result;
74
94
  }
95
+ function handleError(e) {
96
+ if (e.includes("ExecutionError")) {
97
+ const majorStatusMatch = e.match(/major_status:\s([A-Z_]+)/);
98
+ if (majorStatusMatch !== null) {
99
+ const major_status = majorStatusMatch[1];
100
+ if (major_status === "ABORTED") {
101
+ const subStatusMatch = e.match(/sub_status:\sSome\((\d+)\)/);
102
+ if (subStatusMatch === null) {
103
+ return new MoveAbortError(Number.NEGATIVE_INFINITY, e);
104
+ } else {
105
+ return new MoveAbortError(Number(subStatusMatch[1]), e);
106
+ }
107
+ }
108
+ } else {
109
+ return new UnclassifiedError(e);
110
+ }
111
+ }
112
+ return new Error(e);
113
+ }
75
114
 
76
115
  // src/modules/simple-message-lib.ts
77
116
  var SimpleMessageLib = class {
@@ -108,8 +147,7 @@ var SimpleMessageLib = class {
108
147
  arguments: [tx.object(this.objects.simple_message_lib)]
109
148
  });
110
149
  const result = await moveView(this.client, tx);
111
- const bytes = new Uint8Array(result?.returnValues[0][0]);
112
- return bcs.bcs.U64.parse(bytes);
150
+ return bcs.bcs.U64.parse(result[0].value);
113
151
  }
114
152
  async getZroFee() {
115
153
  const tx = new transactions.Transaction();
@@ -119,8 +157,7 @@ var SimpleMessageLib = class {
119
157
  arguments: [tx.object(this.objects.simple_message_lib)]
120
158
  });
121
159
  const result = await moveView(this.client, tx);
122
- const bytes = new Uint8Array(result?.returnValues[0][0]);
123
- return bcs.bcs.U64.parse(bytes);
160
+ return bcs.bcs.U64.parse(result[0].value);
124
161
  }
125
162
  async getFeeRecipient() {
126
163
  const tx = new transactions.Transaction();
@@ -130,8 +167,7 @@ var SimpleMessageLib = class {
130
167
  arguments: [tx.object(this.objects.simple_message_lib)]
131
168
  });
132
169
  const result = await moveView(this.client, tx);
133
- const bytes = new Uint8Array(result?.returnValues[0][0]);
134
- return bcs.bcs.Address.parse(bytes);
170
+ return bcs.bcs.Address.parse(result[0].value);
135
171
  }
136
172
  async isRegistered() {
137
173
  const tx = new transactions.Transaction();
@@ -141,8 +177,7 @@ var SimpleMessageLib = class {
141
177
  arguments: [tx.object(this.objects.simple_message_lib), tx.object(this.objects.endpoint_v2)]
142
178
  });
143
179
  const result = await moveView(this.client, tx);
144
- const bytes = new Uint8Array(result?.returnValues[0][0]);
145
- return bcs.bcs.Bool.parse(bytes);
180
+ return bcs.bcs.Bool.parse(result[0].value);
146
181
  }
147
182
  // === Admin Functions ===
148
183
  populateRegisterLibraryTransaction() {
@@ -260,6 +295,12 @@ var SimpleMessageLib = class {
260
295
  populateGetConfigTransaction(tx) {
261
296
  }
262
297
  };
298
+ var EndpointErrorCode = /* @__PURE__ */ ((EndpointErrorCode2) => {
299
+ EndpointErrorCode2[EndpointErrorCode2["EDefaultReceiveLibUnavailable"] = 2] = "EDefaultReceiveLibUnavailable";
300
+ EndpointErrorCode2[EndpointErrorCode2["EDefaultSendLibUnavailable"] = 3] = "EDefaultSendLibUnavailable";
301
+ EndpointErrorCode2[EndpointErrorCode2["ENotInitialized"] = 4] = "ENotInitialized";
302
+ return EndpointErrorCode2;
303
+ })(EndpointErrorCode || {});
263
304
  var Endpoint = class {
264
305
  constructor(packageId, client, objects, context) {
265
306
  this.context = context;
@@ -282,10 +323,12 @@ var Endpoint = class {
282
323
  });
283
324
  try {
284
325
  const result = await moveView(this.client, tx);
285
- const bytes = new Uint8Array(result?.returnValues[0][0]);
286
- return bcs.bcs.U32.parse(bytes);
326
+ return bcs.bcs.U32.parse(result[0].value);
287
327
  } catch (e) {
288
- return 0;
328
+ if (e instanceof MoveAbortError && e.abortCode === 4 /* ENotInitialized */.valueOf()) {
329
+ return 0;
330
+ }
331
+ throw e;
289
332
  }
290
333
  }
291
334
  populateInitEidTransaction(eid) {
@@ -310,10 +353,12 @@ var Endpoint = class {
310
353
  });
311
354
  try {
312
355
  const result = await moveView(this.client, tx);
313
- const bytes = new Uint8Array(result?.returnValues[0][0]);
314
- return bcs.bcs.Address.parse(bytes);
315
- } catch (error) {
316
- return "0x0";
356
+ return bcs.bcs.Address.parse(result[0].value);
357
+ } catch (e) {
358
+ if (e instanceof MoveAbortError && e.abortCode === 3 /* EDefaultSendLibUnavailable */.valueOf()) {
359
+ return "0x0";
360
+ }
361
+ throw e;
317
362
  }
318
363
  }
319
364
  populateSetDefaultSendLibraryTransaction(dstEid, newLib) {
@@ -339,10 +384,12 @@ var Endpoint = class {
339
384
  });
340
385
  try {
341
386
  const result = await moveView(this.client, tx);
342
- const bytes = new Uint8Array(result?.returnValues[0][0]);
343
- return bcs.bcs.Address.parse(bytes);
344
- } catch (error) {
345
- return "0x";
387
+ return bcs.bcs.Address.parse(result[0].value);
388
+ } catch (e) {
389
+ if (e instanceof MoveAbortError && e.abortCode === 2 /* EDefaultReceiveLibUnavailable */.valueOf()) {
390
+ return "0x0";
391
+ }
392
+ throw e;
346
393
  }
347
394
  }
348
395
  populateSetDefaultReceiveLibraryTransaction(srcEid, newLib, gracePeriod) {
@@ -385,10 +432,8 @@ var Endpoint = class {
385
432
  arguments: [tx.object(this.objects.endpoint_v2), tx.pure.address(sender), tx.pure.u32(dstEid)]
386
433
  });
387
434
  const result = await moveView(this.client, tx);
388
- const bytes = new Uint8Array(result?.returnValues[0][0]);
389
- const lib = bcs.bcs.Address.parse(bytes);
390
- const isDefaultBytes = new Uint8Array(result?.returnValues[1][0]);
391
- const isDefault = bcs.bcs.Bool.parse(isDefaultBytes);
435
+ const lib = bcs.bcs.Address.parse(result[0].value);
436
+ const isDefault = bcs.bcs.Bool.parse(result[1].value);
392
437
  return [lib, isDefault];
393
438
  }
394
439
  async getReceiveLibrary(receiver, srcEid) {
@@ -399,10 +444,8 @@ var Endpoint = class {
399
444
  arguments: [tx.object(this.objects.endpoint_v2), tx.pure.address(receiver), tx.pure.u32(srcEid)]
400
445
  });
401
446
  const result = await moveView(this.client, tx);
402
- const bytes = new Uint8Array(result?.returnValues[0][0]);
403
- const lib = bcs.bcs.Address.parse(bytes);
404
- const isDefaultBytes = new Uint8Array(result?.returnValues[1][0]);
405
- const isDefault = bcs.bcs.Bool.parse(isDefaultBytes);
447
+ const lib = bcs.bcs.Address.parse(result[0].value);
448
+ const isDefault = bcs.bcs.Bool.parse(result[1].value);
406
449
  return [lib, isDefault];
407
450
  }
408
451
  async getInboundNonce(receiver, srcEid, sender) {
@@ -418,8 +461,7 @@ var Endpoint = class {
418
461
  ]
419
462
  });
420
463
  const result = await moveView(this.client, tx);
421
- const bytes = new Uint8Array(result?.returnValues[0][0]);
422
- return BigInt(bcs.bcs.U64.parse(bytes));
464
+ return BigInt(bcs.bcs.U64.parse(result[0].value));
423
465
  }
424
466
  async getLazyInboundNonce(receiver, srcEid, sender) {
425
467
  const tx = new transactions.Transaction();
@@ -434,8 +476,7 @@ var Endpoint = class {
434
476
  ]
435
477
  });
436
478
  const result = await moveView(this.client, tx);
437
- const bytes = new Uint8Array(result?.returnValues[0][0]);
438
- return BigInt(bcs.bcs.U64.parse(bytes));
479
+ return BigInt(bcs.bcs.U64.parse(result[0].value));
439
480
  }
440
481
  async getOutboundNonce(sender, dstEid, receiver) {
441
482
  const tx = new transactions.Transaction();
@@ -450,8 +491,7 @@ var Endpoint = class {
450
491
  ]
451
492
  });
452
493
  const result = await moveView(this.client, tx);
453
- const bytes = new Uint8Array(result?.returnValues[0][0]);
454
- return BigInt(bcs.bcs.U64.parse(bytes));
494
+ return BigInt(bcs.bcs.U64.parse(result[0].value));
455
495
  }
456
496
  async getInboundPayloadHash(receiver, srcEid, sender, nonce) {
457
497
  const tx = new transactions.Transaction();
@@ -468,8 +508,7 @@ var Endpoint = class {
468
508
  });
469
509
  try {
470
510
  const result = await moveView(this.client, tx);
471
- const bytes = new Uint8Array(result?.returnValues[0][0]);
472
- const parsed = bcs.bcs.vector(bcs.bcs.u8()).parse(bytes);
511
+ const parsed = bcs.bcs.vector(bcs.bcs.u8()).parse(result[0].value);
473
512
  return Buffer.from(parsed);
474
513
  } catch (error) {
475
514
  return null;
@@ -489,8 +528,7 @@ var Endpoint = class {
489
528
  ]
490
529
  });
491
530
  const result = await moveView(this.client, tx);
492
- const bytes = new Uint8Array(result?.returnValues[0][0]);
493
- const parsed = bcs.bcs.vector(bcs.bcs.u8()).parse(bytes);
531
+ const parsed = bcs.bcs.vector(bcs.bcs.u8()).parse(result[0].value);
494
532
  return Buffer.from(parsed);
495
533
  }
496
534
  // TODO: more view functions to be added here
@@ -509,6 +547,10 @@ var MessagingFeeBcs = bcs.bcs.struct("MessagingFee", {
509
547
  });
510
548
 
511
549
  // src/modules/counter.ts
550
+ var CounterErrorCode = /* @__PURE__ */ ((CounterErrorCode2) => {
551
+ CounterErrorCode2[CounterErrorCode2["EPeerNotFound"] = 0] = "EPeerNotFound";
552
+ return CounterErrorCode2;
553
+ })(CounterErrorCode || {});
512
554
  var Counter = class {
513
555
  constructor(packageId, utilsPkgId, client, objects, context) {
514
556
  this.context = context;
@@ -531,10 +573,12 @@ var Counter = class {
531
573
  });
532
574
  try {
533
575
  const result = await moveView(this.client, tx);
534
- const bytes = new Uint8Array(result?.returnValues[0][0]);
535
- return bcs.bcs.Address.parse(bytes);
576
+ return bcs.bcs.Address.parse(result[0].value);
536
577
  } catch (e) {
537
- return "";
578
+ if (e instanceof MoveAbortError && e.abortCode === 0 /* EPeerNotFound */.valueOf()) {
579
+ return "0x0";
580
+ }
581
+ throw e;
538
582
  }
539
583
  }
540
584
  async getCount() {
@@ -544,14 +588,9 @@ var Counter = class {
544
588
  typeArguments: [],
545
589
  arguments: [tx.object(this.objects.counter)]
546
590
  });
547
- try {
548
- const result = await moveView(this.client, tx);
549
- const bytes = new Uint8Array(result?.returnValues[0][0]);
550
- const counterStr = bcs.bcs.U64.parse(bytes);
551
- return Number(counterStr);
552
- } catch (e) {
553
- return 0;
554
- }
591
+ const result = await moveView(this.client, tx);
592
+ const counterStr = bcs.bcs.U64.parse(result[0].value);
593
+ return Number(counterStr);
555
594
  }
556
595
  async getComposedCount() {
557
596
  const tx = new transactions.Transaction();
@@ -560,14 +599,9 @@ var Counter = class {
560
599
  typeArguments: [],
561
600
  arguments: [tx.object(this.objects.counter)]
562
601
  });
563
- try {
564
- const result = await moveView(this.client, tx);
565
- const bytes = new Uint8Array(result?.returnValues[0][0]);
566
- const counterStr = bcs.bcs.U64.parse(bytes);
567
- return Number(counterStr);
568
- } catch (e) {
569
- return 0;
570
- }
602
+ const result = await moveView(this.client, tx);
603
+ const counterStr = bcs.bcs.U64.parse(result[0].value);
604
+ return Number(counterStr);
571
605
  }
572
606
  populateSetPeerTransaction(dstEid, peer) {
573
607
  const tx = new transactions.Transaction();
@@ -640,8 +674,7 @@ var Counter = class {
640
674
  const executedCall = this.context.simpleMessageLib.quoteMoveCall(tx, quoteCall);
641
675
  this.context.endpoint.confirmQuoteMoveCall(tx, executedCall);
642
676
  const result = await moveView(this.client, tx);
643
- const bytes = new Uint8Array(result?.returnValues[0][0]);
644
- const messageFee = MessagingFeeBcs.parse(bytes);
677
+ const messageFee = MessagingFeeBcs.parse(result[0].value);
645
678
  return [BigInt(messageFee.native_fee), BigInt(messageFee.zro_fee)];
646
679
  }
647
680
  async send(sender, dstEid, msgType, options, sendValue, nativeFee, zroFee) {
@@ -1167,14 +1200,18 @@ var SDK = class {
1167
1200
  };
1168
1201
 
1169
1202
  exports.Counter = Counter;
1203
+ exports.CounterErrorCode = CounterErrorCode;
1170
1204
  exports.Endpoint = Endpoint;
1205
+ exports.EndpointErrorCode = EndpointErrorCode;
1171
1206
  exports.MessagingFeeBcs = MessagingFeeBcs;
1207
+ exports.MoveAbortError = MoveAbortError;
1172
1208
  exports.SDK = SDK;
1173
1209
  exports.SimpleMessageLib = SimpleMessageLib;
1210
+ exports.UnclassifiedError = UnclassifiedError;
1174
1211
  exports.Utils = Utils;
1175
1212
  exports.Zro = Zro;
1176
- exports.devInspectTransaction = devInspectTransaction;
1177
1213
  exports.getSDKFromProvider = getSDKFromProvider;
1214
+ exports.handleError = handleError;
1178
1215
  exports.moveView = moveView;
1179
1216
  exports.readAddressFromDeployment = readAddressFromDeployment;
1180
1217
  exports.validateTransaction = validateTransaction;