@layerzerolabs/lz-sui-sdk-v2 3.0.116 → 3.0.117

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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @layerzerolabs/lz-sui-sdk-v2
2
2
 
3
+ ## 3.0.117
4
+
5
+ ### Patch Changes
6
+
7
+ - fd54ee9: fix bugs that caused TypeScript SDK to behave differently from Rust contracts.
8
+ - Updated dependencies [fd54ee9]
9
+ - @layerzerolabs/lz-corekit-sui@3.0.102
10
+ - @layerzerolabs/lz-core@3.0.117
11
+ - @layerzerolabs/lz-definitions@3.0.117
12
+ - @layerzerolabs/lz-utilities@3.0.117
13
+
3
14
  ## 3.0.116
4
15
 
5
16
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -111,6 +111,9 @@ function handleError(e) {
111
111
  }
112
112
  return new Error(e);
113
113
  }
114
+ function convertStringToUint8Array(str) {
115
+ return new TextEncoder().encode(str);
116
+ }
114
117
 
115
118
  // src/modules/simple-message-lib.ts
116
119
  var SimpleMessageLib = class {
@@ -139,6 +142,16 @@ var SimpleMessageLib = class {
139
142
  return tx;
140
143
  }
141
144
  // === View Functions ===
145
+ async getCallCap() {
146
+ const tx = new transactions.Transaction();
147
+ tx.moveCall({
148
+ target: `${this.packageId}::simple_message_lib::call_cap`,
149
+ typeArguments: [],
150
+ arguments: [tx.object(this.objects.simple_message_lib)]
151
+ });
152
+ const result = await moveView(this.client, tx);
153
+ return bcs.bcs.Address.parse(result[0].value);
154
+ }
142
155
  async getNativeFee() {
143
156
  const tx = new transactions.Transaction();
144
157
  tx.moveCall({
@@ -236,7 +249,7 @@ var SimpleMessageLib = class {
236
249
  return tx;
237
250
  }
238
251
  // === Endpoint Validation ===
239
- populateValidatePacketTransaction(packetHeader, payloadHash) {
252
+ populateValidatePacketTransaction(messagingChannel, packetHeader, payloadHash) {
240
253
  const tx = new transactions.Transaction();
241
254
  const payloadHashBytes32 = this.context.utils.fromBytesMoveCall(tx, payloadHash);
242
255
  tx.moveCall({
@@ -246,10 +259,10 @@ var SimpleMessageLib = class {
246
259
  tx.object(this.objects.simple_message_lib),
247
260
  tx.object(this.objects.endpoint_v2),
248
261
  tx.object(this.objects.endpoint_admin_cap),
262
+ tx.object(messagingChannel),
249
263
  tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(packetHeader)),
250
264
  payloadHashBytes32,
251
- tx.object("0x6")
252
- // Clock Object TODO try to get it from the client or sdk
265
+ tx.object.clock()
253
266
  ]
254
267
  });
255
268
  return tx;
@@ -269,18 +282,29 @@ var SimpleMessageLib = class {
269
282
  });
270
283
  return tx;
271
284
  }
272
- quoteMoveCall(tx, quoteCall) {
273
- return tx.moveCall({
285
+ quoteMoveCall(tx, endpoint_call, message_lib_call) {
286
+ tx.moveCall({
274
287
  target: `${this.packageId}::simple_message_lib::quote`,
275
288
  typeArguments: [],
276
- arguments: [tx.object(this.objects.simple_message_lib), quoteCall]
289
+ arguments: [
290
+ tx.object(this.objects.simple_message_lib),
291
+ tx.object(this.objects.endpoint_v2),
292
+ endpoint_call,
293
+ message_lib_call
294
+ ]
277
295
  });
278
296
  }
279
- sendMoveCall(tx, sendCall) {
280
- return tx.moveCall({
297
+ sendMoveCall(tx, messageChannel, endpointCall, messageLibCall) {
298
+ tx.moveCall({
281
299
  target: `${this.packageId}::simple_message_lib::send`,
282
300
  typeArguments: [],
283
- arguments: [tx.object(this.objects.simple_message_lib), tx.object(this.objects.endpoint_v2), sendCall]
301
+ arguments: [
302
+ tx.object(this.objects.simple_message_lib),
303
+ tx.object(this.objects.endpoint_v2),
304
+ tx.object(messageChannel),
305
+ endpointCall,
306
+ messageLibCall
307
+ ]
284
308
  });
285
309
  }
286
310
  // === TODO: Core Message Lib Functions ===
@@ -334,6 +358,36 @@ var Endpoint = class {
334
358
  throw e;
335
359
  }
336
360
  }
361
+ async isOappRegistered(oapp) {
362
+ const tx = new transactions.Transaction();
363
+ tx.moveCall({
364
+ target: `${this.packageId}::endpoint_v2::is_oapp_registered`,
365
+ typeArguments: [],
366
+ arguments: [tx.object(this.objects.endpoint_v2), tx.pure.address(oapp)]
367
+ });
368
+ const result = await moveView(this.client, tx);
369
+ return bcs.bcs.Bool.parse(result[0].value);
370
+ }
371
+ async isComposerRegistered(composer) {
372
+ const tx = new transactions.Transaction();
373
+ tx.moveCall({
374
+ target: `${this.packageId}::endpoint_v2::is_composer_registered`,
375
+ typeArguments: [],
376
+ arguments: [tx.object(this.objects.endpoint_v2), tx.pure.address(composer)]
377
+ });
378
+ const result = await moveView(this.client, tx);
379
+ return bcs.bcs.Bool.parse(result[0].value);
380
+ }
381
+ async isLibraryRegistered(messageLib) {
382
+ const tx = new transactions.Transaction();
383
+ tx.moveCall({
384
+ target: `${this.packageId}::endpoint_v2::is_registered_library`,
385
+ typeArguments: [],
386
+ arguments: [tx.object(this.objects.endpoint_v2), tx.pure.address(messageLib)]
387
+ });
388
+ const result = await moveView(this.client, tx);
389
+ return bcs.bcs.Bool.parse(result[0].value);
390
+ }
337
391
  populateInitEidTransaction(eid) {
338
392
  const tx = new transactions.Transaction();
339
393
  tx.moveCall({
@@ -364,6 +418,26 @@ var Endpoint = class {
364
418
  throw e;
365
419
  }
366
420
  }
421
+ populateRegisterLibraryTransaction() {
422
+ const tx = new transactions.Transaction();
423
+ const libType = tx.moveCall({
424
+ target: `${this.packageId}::message_lib_type::send_and_receive`,
425
+ typeArguments: [],
426
+ arguments: []
427
+ });
428
+ tx.moveCall({
429
+ target: `${this.packageId}::endpoint_v2::register_library`,
430
+ typeArguments: [],
431
+ arguments: [
432
+ tx.object(this.objects.endpoint_v2),
433
+ tx.object(this.objects.endpoint_admin_cap),
434
+ tx.pure.address(this.objects.simple_message_lib_cap),
435
+ tx.pure.address(this.context.simpleMessageLib.packageId),
436
+ libType
437
+ ]
438
+ });
439
+ return tx;
440
+ }
367
441
  populateSetDefaultSendLibraryTransaction(dstEid, newLib) {
368
442
  const tx = new transactions.Transaction();
369
443
  tx.moveCall({
@@ -406,12 +480,77 @@ var Endpoint = class {
406
480
  tx.pure.u32(srcEid),
407
481
  tx.pure.address(newLib),
408
482
  tx.pure.u64(gracePeriod),
409
- tx.object("0x6")
410
- // Clock Object TODO try to get it from the client or sdk
483
+ tx.object.clock()
411
484
  ]
412
485
  });
413
486
  return tx;
414
487
  }
488
+ populateLzReceiveTransaction(tx, messagingChannel, srcEid, sender, nonce, guid, message, value, extraData = new Uint8Array()) {
489
+ const senderBytes32 = this.context.utils.fromBytesMoveCall(tx, sender);
490
+ const guidBytes32 = this.context.utils.fromBytesMoveCall(tx, guid);
491
+ const cap = this.context.call.createCapMoveCall(tx);
492
+ const result = tx.moveCall({
493
+ target: `${this.packageId}::endpoint_v2::lz_receive`,
494
+ typeArguments: [],
495
+ arguments: [
496
+ tx.object(this.objects.endpoint_v2),
497
+ cap,
498
+ tx.object(messagingChannel),
499
+ tx.pure.u32(srcEid),
500
+ senderBytes32,
501
+ tx.pure.u64(nonce),
502
+ guidBytes32,
503
+ tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(message)),
504
+ tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(extraData)),
505
+ this.createCoinOptionMoveCall(tx, value)
506
+ ]
507
+ });
508
+ tx.transferObjects([cap], tx.pure.address("0x0"));
509
+ return result;
510
+ }
511
+ populateLzComposeTransaction(tx, messagingComposer, from, guid, index, message, value, extraData = new Uint8Array()) {
512
+ const guidBytes32 = this.context.utils.fromBytesMoveCall(tx, guid);
513
+ const cap = this.context.call.createCapMoveCall(tx);
514
+ const result = tx.moveCall({
515
+ target: `${this.packageId}::endpoint_v2::lz_compose`,
516
+ typeArguments: [],
517
+ arguments: [
518
+ tx.object(this.objects.endpoint_v2),
519
+ cap,
520
+ tx.object(messagingComposer),
521
+ tx.pure.address(from),
522
+ guidBytes32,
523
+ tx.pure.u16(index),
524
+ tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(message)),
525
+ tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(extraData)),
526
+ this.createCoinOptionMoveCall(tx, value)
527
+ ]
528
+ });
529
+ tx.transferObjects([cap], tx.pure.address("0x0"));
530
+ return result;
531
+ }
532
+ createCoinOptionMoveCall(tx, value) {
533
+ const coin = tx.splitCoins(tx.gas, [tx.pure.u64(value)]);
534
+ return tx.moveCall({
535
+ target: `0x1::option::some`,
536
+ typeArguments: [`0x2::coin::Coin<0x2::sui::SUI>`],
537
+ arguments: [coin]
538
+ });
539
+ }
540
+ quoteMoveCall(tx, messagingChannel, call) {
541
+ return tx.moveCall({
542
+ target: `${this.packageId}::endpoint_v2::quote`,
543
+ typeArguments: [],
544
+ arguments: [tx.object(this.objects.endpoint_v2), tx.object(messagingChannel), call]
545
+ });
546
+ }
547
+ sendMoveCall(tx, messagingChannel, call) {
548
+ return tx.moveCall({
549
+ target: `${this.packageId}::endpoint_v2::send`,
550
+ typeArguments: [],
551
+ arguments: [tx.object(this.objects.endpoint_v2), tx.object(messagingChannel), call]
552
+ });
553
+ }
415
554
  confirmQuoteMoveCall(tx, executedCall) {
416
555
  return tx.moveCall({
417
556
  target: `${this.packageId}::endpoint_v2::confirm_quote`,
@@ -426,12 +565,25 @@ var Endpoint = class {
426
565
  arguments: [tx.object(this.objects.endpoint_v2), executedCall]
427
566
  });
428
567
  }
429
- getMessagingChannel(tx, oapp) {
430
- return tx.moveCall({
568
+ async getMessagingChannel(oapp) {
569
+ const tx = new transactions.Transaction();
570
+ tx.moveCall({
431
571
  target: `${this.packageId}::endpoint_v2::get_messaging_channel`,
432
572
  typeArguments: [],
433
573
  arguments: [tx.object(this.objects.endpoint_v2), tx.pure.address(oapp)]
434
574
  });
575
+ const result = await moveView(this.client, tx);
576
+ return bcs.bcs.Address.parse(result[0].value);
577
+ }
578
+ async getMessagingComposer(oapp) {
579
+ const tx = new transactions.Transaction();
580
+ tx.moveCall({
581
+ target: `${this.packageId}::endpoint_v2::get_compose_queue`,
582
+ typeArguments: [],
583
+ arguments: [tx.object(this.objects.endpoint_v2), tx.pure.address(oapp)]
584
+ });
585
+ const result = await moveView(this.client, tx);
586
+ return bcs.bcs.Address.parse(result[0].value);
435
587
  }
436
588
  // === Worker Endpoint Required Methods ===
437
589
  async getSendLibrary(sender, dstEid) {
@@ -458,14 +610,13 @@ var Endpoint = class {
458
610
  const isDefault = bcs.bcs.Bool.parse(result[1].value);
459
611
  return [lib, isDefault];
460
612
  }
461
- async getInboundNonce(receiver, srcEid, sender) {
613
+ async getInboundNonce(messagingChannel, srcEid, sender) {
462
614
  const tx = new transactions.Transaction();
463
615
  tx.moveCall({
464
616
  target: `${this.packageId}::endpoint_v2::get_inbound_nonce`,
465
617
  typeArguments: [],
466
618
  arguments: [
467
- tx.object(this.objects.endpoint_v2),
468
- tx.pure.address(receiver),
619
+ tx.object(messagingChannel),
469
620
  tx.pure.u32(srcEid),
470
621
  tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(sender))
471
622
  ]
@@ -473,14 +624,13 @@ var Endpoint = class {
473
624
  const result = await moveView(this.client, tx);
474
625
  return BigInt(bcs.bcs.U64.parse(result[0].value));
475
626
  }
476
- async getLazyInboundNonce(receiver, srcEid, sender) {
627
+ async getLazyInboundNonce(messagingChannel, srcEid, sender) {
477
628
  const tx = new transactions.Transaction();
478
629
  tx.moveCall({
479
630
  target: `${this.packageId}::endpoint_v2::get_lazy_inbound_nonce`,
480
631
  typeArguments: [],
481
632
  arguments: [
482
- tx.object(this.objects.endpoint_v2),
483
- tx.pure.address(receiver),
633
+ tx.object(messagingChannel),
484
634
  tx.pure.u32(srcEid),
485
635
  tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(sender))
486
636
  ]
@@ -488,14 +638,13 @@ var Endpoint = class {
488
638
  const result = await moveView(this.client, tx);
489
639
  return BigInt(bcs.bcs.U64.parse(result[0].value));
490
640
  }
491
- async getOutboundNonce(sender, dstEid, receiver) {
641
+ async getOutboundNonce(messagingChannel, dstEid, receiver) {
492
642
  const tx = new transactions.Transaction();
493
643
  tx.moveCall({
494
644
  target: `${this.packageId}::endpoint_v2::get_outbound_nonce`,
495
645
  typeArguments: [],
496
646
  arguments: [
497
- tx.object(this.objects.endpoint_v2),
498
- tx.pure.address(sender),
647
+ tx.object(messagingChannel),
499
648
  tx.pure.u32(dstEid),
500
649
  tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(receiver))
501
650
  ]
@@ -503,14 +652,13 @@ var Endpoint = class {
503
652
  const result = await moveView(this.client, tx);
504
653
  return BigInt(bcs.bcs.U64.parse(result[0].value));
505
654
  }
506
- async getInboundPayloadHash(receiver, srcEid, sender, nonce) {
655
+ async getInboundPayloadHash(messagingChannel, srcEid, sender, nonce) {
507
656
  const tx = new transactions.Transaction();
508
657
  tx.moveCall({
509
658
  target: `${this.packageId}::endpoint_v2::get_inbound_payload_hash`,
510
659
  typeArguments: [],
511
660
  arguments: [
512
- tx.object(this.objects.endpoint_v2),
513
- tx.pure.address(receiver),
661
+ tx.object(messagingChannel),
514
662
  tx.pure.u32(srcEid),
515
663
  tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(sender)),
516
664
  tx.pure.u64(nonce)
@@ -524,15 +672,14 @@ var Endpoint = class {
524
672
  return null;
525
673
  }
526
674
  }
527
- async getComposeMessageHash(from, to, guid, index) {
675
+ async getComposeMessageHash(messagingComposer, from, guid, index) {
528
676
  const tx = new transactions.Transaction();
529
677
  tx.moveCall({
530
678
  target: `${this.packageId}::endpoint_v2::get_compose_message_hash`,
531
679
  typeArguments: [],
532
680
  arguments: [
533
- tx.object(this.objects.endpoint_v2),
681
+ tx.object(messagingComposer),
534
682
  tx.pure.address(from),
535
- tx.pure.address(to),
536
683
  tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(guid)),
537
684
  tx.pure.u16(index)
538
685
  ]
@@ -591,6 +738,26 @@ var Counter = class {
591
738
  throw e;
592
739
  }
593
740
  }
741
+ async getCounterId() {
742
+ const tx = new transactions.Transaction();
743
+ tx.moveCall({
744
+ target: `${this.packageId}::counter::get_counter_id`,
745
+ typeArguments: [],
746
+ arguments: [tx.object(this.objects.counter)]
747
+ });
748
+ const result = await moveView(this.client, tx);
749
+ return bcs.bcs.Address.parse(result[0].value);
750
+ }
751
+ async getComposerId() {
752
+ const tx = new transactions.Transaction();
753
+ tx.moveCall({
754
+ target: `${this.packageId}::counter::get_composer_id`,
755
+ typeArguments: [],
756
+ arguments: [tx.object(this.objects.counter)]
757
+ });
758
+ const result = await moveView(this.client, tx);
759
+ return bcs.bcs.Address.parse(result[0].value);
760
+ }
594
761
  async getCount() {
595
762
  const tx = new transactions.Transaction();
596
763
  tx.moveCall({
@@ -613,27 +780,59 @@ var Counter = class {
613
780
  const counterStr = bcs.bcs.U64.parse(result[0].value);
614
781
  return Number(counterStr);
615
782
  }
616
- populateSetPeerTransaction(dstEid, peer) {
783
+ async populateSetPeerTransaction(dstEid, peer) {
617
784
  const tx = new transactions.Transaction();
618
785
  const peerBytes32 = tx.moveCall({
619
786
  target: `${this.utilsPkgId}::bytes32::from_bytes`,
620
787
  typeArguments: [],
621
788
  arguments: [tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(peer))]
622
789
  });
623
- const messagingChannel = this.context.endpoint.getMessagingChannel(tx, this.objects.counter_cap);
790
+ const messagingChannel = await this.context.endpoint.getMessagingChannel(this.objects.counter_cap);
624
791
  tx.moveCall({
625
792
  target: `${this.packageId}::counter::set_peer`,
626
793
  typeArguments: [],
627
794
  arguments: [
628
795
  tx.object(this.objects.counter),
629
796
  tx.object(this.objects.counter_admin_cap),
630
- messagingChannel,
797
+ tx.object(messagingChannel),
631
798
  tx.pure.u32(dstEid),
632
799
  peerBytes32
633
800
  ]
634
801
  });
635
802
  return tx;
636
803
  }
804
+ populateRegisterOappTransaction() {
805
+ const tx = new transactions.Transaction();
806
+ tx.moveCall({
807
+ target: `${this.packageId}::counter::register_oapp`,
808
+ typeArguments: [],
809
+ arguments: [
810
+ tx.object(this.objects.counter),
811
+ tx.object(this.objects.counter_admin_cap),
812
+ tx.object(this.objects.endpoint_v2),
813
+ tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(convertStringToUint8Array("lz_receive_info")))
814
+ ]
815
+ });
816
+ return tx;
817
+ }
818
+ async registerOapp(sender) {
819
+ const tx = this.populateRegisterOappTransaction();
820
+ return validateTransaction(this.client, sender, tx);
821
+ }
822
+ populateRegisterComposerTransaction() {
823
+ const tx = new transactions.Transaction();
824
+ tx.moveCall({
825
+ target: `${this.packageId}::counter::register_composer`,
826
+ typeArguments: [],
827
+ arguments: [
828
+ tx.object(this.objects.counter),
829
+ tx.object(this.objects.counter_admin_cap),
830
+ tx.object(this.objects.endpoint_v2),
831
+ tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(convertStringToUint8Array("lz_compose_info")))
832
+ ]
833
+ });
834
+ return tx;
835
+ }
637
836
  /**
638
837
  * Builds a transaction for calling the lz_receive function on the counter contract.
639
838
  *
@@ -646,28 +845,50 @@ var Counter = class {
646
845
  * @param extraData - Extra data as vector<u8>
647
846
  * @returns A Transaction object ready to be executed
648
847
  */
649
- populateLzReceiveTransaction(srcEid, sender, nonce, guid, message, value, extraData = new Uint8Array()) {
848
+ populateLzReceiveTransaction(messagingChannel, messagingComposer, srcEid, sender, nonce, guid, message, value, extraData = new Uint8Array()) {
650
849
  const tx = new transactions.Transaction();
651
- const senderBytes32 = this.context.utils.fromBytesMoveCall(tx, sender);
652
- const guidBytes32 = this.context.utils.fromBytesMoveCall(tx, guid);
653
- const coin = tx.splitCoins(tx.gas, [tx.pure.u64(value)]);
850
+ const receiveCall = this.context.endpoint.populateLzReceiveTransaction(
851
+ tx,
852
+ messagingChannel,
853
+ srcEid,
854
+ sender,
855
+ nonce,
856
+ guid,
857
+ message,
858
+ value,
859
+ extraData
860
+ );
654
861
  tx.moveCall({
655
862
  target: `${this.packageId}::counter::lz_receive`,
656
863
  typeArguments: [],
657
864
  arguments: [
658
865
  tx.object(this.objects.counter),
659
866
  tx.object(this.objects.endpoint_v2),
660
- tx.pure.u32(srcEid),
661
- senderBytes32,
662
- tx.pure.u64(nonce),
663
- guidBytes32,
664
- tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(message)),
665
- coin,
666
- tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(extraData))
867
+ tx.object(messagingComposer),
868
+ receiveCall
667
869
  ]
668
870
  });
669
871
  return tx;
670
872
  }
873
+ populateLzComposeTransaction(messagingComposer, from, guid, index, message, value, extraData = new Uint8Array()) {
874
+ const tx = new transactions.Transaction();
875
+ const composeCall = this.context.endpoint.populateLzComposeTransaction(
876
+ tx,
877
+ messagingComposer,
878
+ from,
879
+ guid,
880
+ index,
881
+ message,
882
+ value,
883
+ extraData
884
+ );
885
+ tx.moveCall({
886
+ target: `${this.packageId}::counter::lz_compose`,
887
+ typeArguments: [],
888
+ arguments: [tx.object(this.objects.counter), tx.object(this.objects.endpoint_v2), composeCall]
889
+ });
890
+ return tx;
891
+ }
671
892
  async quote(dstEid, msgType, options, payInZero) {
672
893
  const tx = new transactions.Transaction();
673
894
  const quoteCall = tx.moveCall({
@@ -676,14 +897,17 @@ var Counter = class {
676
897
  arguments: [
677
898
  tx.object(this.objects.counter),
678
899
  tx.object(this.objects.endpoint_v2),
900
+ tx.object(this.objects.oapp_helper),
679
901
  tx.pure.u32(dstEid),
680
902
  tx.pure.u8(msgType),
681
903
  tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(options)),
682
904
  tx.pure.bool(payInZero)
683
905
  ]
684
906
  });
685
- const executedCall = this.context.simpleMessageLib.quoteMoveCall(tx, quoteCall);
686
- this.context.endpoint.confirmQuoteMoveCall(tx, executedCall);
907
+ const messagingChannel = await this.context.endpoint.getMessagingChannel(this.objects.counter_cap);
908
+ const messageLibCall = this.context.endpoint.quoteMoveCall(tx, messagingChannel, quoteCall);
909
+ this.context.simpleMessageLib.quoteMoveCall(tx, quoteCall, messageLibCall);
910
+ this.context.oappHelper.extractQuoteResultMoveCall(tx, quoteCall);
687
911
  const result = await moveView(this.client, tx);
688
912
  const messageFee = MessagingFeeBcs.parse(result[0].value);
689
913
  return [BigInt(messageFee.native_fee), BigInt(messageFee.zro_fee)];
@@ -698,17 +922,20 @@ var Counter = class {
698
922
  arguments: [
699
923
  tx.object(this.objects.counter),
700
924
  tx.object(this.objects.endpoint_v2),
925
+ tx.object(this.objects.oapp_helper),
701
926
  tx.pure.u32(dstEid),
702
927
  tx.pure.u8(msgType),
703
928
  tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(options)),
929
+ tx.pure.u64(sendValue),
704
930
  nativeToken,
705
931
  zroToken,
706
- tx.pure.u64(sendValue),
707
932
  tx.pure.address(sender.toSuiAddress())
708
933
  ]
709
934
  });
710
- const executedCall = this.context.simpleMessageLib.sendMoveCall(tx, incrementCall);
711
- this.context.endpoint.confirmSendMoveCall(tx, executedCall);
935
+ const messagingChannel = await this.context.endpoint.getMessagingChannel(this.objects.counter_cap);
936
+ const mesageLibCall = this.context.endpoint.sendMoveCall(tx, messagingChannel, incrementCall);
937
+ this.context.simpleMessageLib.sendMoveCall(tx, messagingChannel, incrementCall, mesageLibCall);
938
+ this.context.oappHelper.refundSendMoveCall(tx, incrementCall);
712
939
  return validateTransaction(this.client, sender, tx);
713
940
  }
714
941
  };
@@ -1069,6 +1296,53 @@ var Zro = class {
1069
1296
  });
1070
1297
  }
1071
1298
  };
1299
+
1300
+ // src/modules/oapp-helper.ts
1301
+ var OappHelper = class {
1302
+ constructor(packageId, client, objects, context) {
1303
+ this.objects = objects;
1304
+ this.context = context;
1305
+ this.packageId = packageId;
1306
+ this.client = client;
1307
+ }
1308
+ refundSendMoveCall(tx, call) {
1309
+ return tx.moveCall({
1310
+ target: `${this.packageId}::oapp_helper::refund_send`,
1311
+ typeArguments: [],
1312
+ arguments: [tx.object(this.objects.oapp_helper), call]
1313
+ });
1314
+ }
1315
+ extractQuoteResultMoveCall(tx, call) {
1316
+ return tx.moveCall({
1317
+ target: `${this.packageId}::oapp_helper::extract_quote_result`,
1318
+ typeArguments: [],
1319
+ arguments: [call]
1320
+ });
1321
+ }
1322
+ };
1323
+
1324
+ // src/modules/call.ts
1325
+ var Call = class {
1326
+ constructor(packageId, client) {
1327
+ this.packageId = packageId;
1328
+ this.client = client;
1329
+ }
1330
+ createCapMoveCall(tx) {
1331
+ return tx.moveCall({
1332
+ target: `${this.packageId}::call::new_cap`,
1333
+ typeArguments: [],
1334
+ arguments: []
1335
+ });
1336
+ }
1337
+ };
1338
+
1339
+ // src/types.ts
1340
+ var MessageLibType = /* @__PURE__ */ ((MessageLibType2) => {
1341
+ MessageLibType2[MessageLibType2["Send"] = 0] = "Send";
1342
+ MessageLibType2[MessageLibType2["Receive"] = 1] = "Receive";
1343
+ MessageLibType2[MessageLibType2["SendAndReceive"] = 2] = "SendAndReceive";
1344
+ return MessageLibType2;
1345
+ })(MessageLibType || {});
1072
1346
  function assertSuiProvider(provider) {
1073
1347
  if (!(provider instanceof lzCorekitSui.SuiProvider)) {
1074
1348
  throw new Error("Invalid provider");
@@ -1098,7 +1372,9 @@ var SDK = class {
1098
1372
  endpoint_v2: readAddressFromDeployment(network, "endpoint_v2"),
1099
1373
  counter_v2: readAddressFromDeployment(network, "counter"),
1100
1374
  simple_message_lib: readAddressFromDeployment(network, "simple_message_lib"),
1101
- zro: readAddressFromDeployment(network, "zro")
1375
+ zro: readAddressFromDeployment(network, "zro"),
1376
+ oapp_helper: readAddressFromDeployment(network, "oapp_helper"),
1377
+ call: readAddressFromDeployment(network, "call")
1102
1378
  };
1103
1379
  this.packages = {
1104
1380
  ...defaultPackages,
@@ -1107,6 +1383,7 @@ var SDK = class {
1107
1383
  const defaultObjects = {
1108
1384
  endpoint_v2: readAddressFromDeployment(network, "object-EndpointV2"),
1109
1385
  simple_message_lib: readAddressFromDeployment(network, "object-SimpleMessageLib"),
1386
+ simple_message_lib_cap: readAddressFromDeployment(network, "object-SimpleMessageLibCap"),
1110
1387
  uln_302: readAddressFromDeployment(network, "object-ULN302"),
1111
1388
  blocked_message_lib: readAddressFromDeployment(network, "object-BlockedMessageLib"),
1112
1389
  discovery: readAddressFromDeployment(network, "object-Discovery"),
@@ -1114,7 +1391,8 @@ var SDK = class {
1114
1391
  counter_admin_cap: readAddressFromDeployment(network, "object-CounterAdminCap"),
1115
1392
  counter_cap: readAddressFromDeployment(network, "object-CounterCap"),
1116
1393
  endpoint_admin_cap: readAddressFromDeployment(network, "object-EndpointV2AdminCap"),
1117
- oapp_core: readAddressFromDeployment(network, "object-OAppCore")
1394
+ oapp_core: readAddressFromDeployment(network, "object-OAppCore"),
1395
+ oapp_helper: readAddressFromDeployment(network, "object-OAppHelper")
1118
1396
  };
1119
1397
  this.objects = {
1120
1398
  ...defaultObjects,
@@ -1131,11 +1409,15 @@ var SDK = class {
1131
1409
  );
1132
1410
  this.utils = new Utils(this.packages.utils, this.client, context);
1133
1411
  this.zro = new Zro(this.packages.zro, this.client, context);
1412
+ this.oappHelper = new OappHelper(this.packages.oapp_helper, this.client, this.objects, context);
1413
+ this.call = new Call(this.packages.call, this.client);
1134
1414
  context.endpoint = this.endpoint;
1135
1415
  context.counter = this.counter;
1136
1416
  context.simpleMessageLib = this.simpleMessageLib;
1137
1417
  context.utils = this.utils;
1138
1418
  context.zro = this.zro;
1419
+ context.oappHelper = this.oappHelper;
1420
+ context.call = this.call;
1139
1421
  }
1140
1422
  /**
1141
1423
  * Gets the Sui client.
@@ -1209,20 +1491,32 @@ var SDK = class {
1209
1491
  getUtils() {
1210
1492
  return this.utils;
1211
1493
  }
1494
+ /**
1495
+ * Gets the oapp helper module.
1496
+ *
1497
+ * @returns {OappHelper} The oapp helper module.
1498
+ */
1499
+ getOappHelper() {
1500
+ return this.oappHelper;
1501
+ }
1212
1502
  };
1213
1503
 
1504
+ exports.Call = Call;
1214
1505
  exports.Counter = Counter;
1215
1506
  exports.CounterErrorCode = CounterErrorCode;
1216
1507
  exports.Endpoint = Endpoint;
1217
1508
  exports.EndpointErrorCode = EndpointErrorCode;
1218
1509
  exports.MessageLibManagerErrorCode = MessageLibManagerErrorCode;
1510
+ exports.MessageLibType = MessageLibType;
1219
1511
  exports.MessagingFeeBcs = MessagingFeeBcs;
1220
1512
  exports.MoveAbortError = MoveAbortError;
1513
+ exports.OappHelper = OappHelper;
1221
1514
  exports.SDK = SDK;
1222
1515
  exports.SimpleMessageLib = SimpleMessageLib;
1223
1516
  exports.UnclassifiedError = UnclassifiedError;
1224
1517
  exports.Utils = Utils;
1225
1518
  exports.Zro = Zro;
1519
+ exports.convertStringToUint8Array = convertStringToUint8Array;
1226
1520
  exports.getSDKFromProvider = getSDKFromProvider;
1227
1521
  exports.handleError = handleError;
1228
1522
  exports.moveView = moveView;