@layerzerolabs/lz-aptos-sdk-v1 2.3.31 → 2.3.32

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/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as aptos2 from 'aptos';
2
- import { HexString, BCS } from 'aptos';
2
+ import { ApiError, HexString, BCS } from 'aptos';
3
3
  import invariant2 from 'tiny-invariant';
4
4
  import { Environment, Stage } from '@layerzerolabs/lz-definitions';
5
5
  import crypto from 'crypto';
@@ -20,6 +20,7 @@ var constants_exports = {};
20
20
  __export(constants_exports, {
21
21
  BRIDGE_ADDRESS: () => BRIDGE_ADDRESS,
22
22
  BRIDGE_PRECRIME_ADDRESS: () => BRIDGE_PRECRIME_ADDRESS,
23
+ COUNTER_ADDRESS: () => COUNTER_ADDRESS,
23
24
  EXECUTOR_ADDRESS: () => EXECUTOR_ADDRESS,
24
25
  EXECUTOR_EXT_ADDRESS: () => EXECUTOR_EXT_ADDRESS,
25
26
  FAUCET_URL: () => FAUCET_URL,
@@ -50,67 +51,82 @@ var LAYERZERO_ADDRESS = {
50
51
  [Stage.MAINNET]: "0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90",
51
52
  // MAINNET
52
53
  [Stage.TESTNET]: "0x1759cc0d3161f1eb79f65847d4feb9d1f74fb79014698a23b16b28b9cd4c37e3",
53
- [Stage.SANDBOX]: "0x88cb10d5573e2aa38ed9a92763535ed6828c193567906a56c0f3b9158b1decb7"
54
+ [Stage.SANDBOX]: "0xf2e1e034475dc0439487dd09dfc3950c462f731599e53a6b015dd85502352e68"
55
+ //TODO(Ethan) double check
54
56
  };
55
57
  var LAYERZERO_APPS_ADDRESS = {
56
58
  [Stage.MAINNET]: "0x43d8cad89263e6936921a0adb8d5d49f0e236c229460f01b14dca073114df2b9",
57
59
  [Stage.TESTNET]: "0x2f972c173927006c83277b6e6ae38f83482eba560f343d022f145979020d3621",
58
- [Stage.SANDBOX]: "0x3afbb2e0e598c6a6b1d694ae3ab6517a6d9941c99f8bb06257e1109b571bb823"
60
+ [Stage.SANDBOX]: "0x9b2bac312330430f5e7287a18065e24b55a5e3834459a92be0784177441959bf"
61
+ //TODO(Ethan) double check
59
62
  };
60
63
  var ORACLE_ADDRESS = {
61
64
  [Stage.MAINNET]: "0xc2846ea05319c339b3b52186ceae40b43d4e9cf6c7350336c3eb0b351d9394eb",
62
65
  // MAINNET
63
66
  [Stage.TESTNET]: "0x8ab85d94bf34808386b3ce0f9516db74d2b6d2f1166aa48f75ca641f3adb6c63",
64
- [Stage.SANDBOX]: "0x22be7b12e214d4f9f96dc3638fb8d9e3f760e483102c4b48b04a2a656de5a24a"
67
+ [Stage.SANDBOX]: "0x86052d5722c3222a88de346aad92a02ace56839487165c6b1bad844e85297d5e"
68
+ //TODO(Ethan) double check
65
69
  };
66
70
  var ORACLE_SIGNER_ADDRESS = {
67
71
  [Stage.MAINNET]: "0x12e12de0af996d9611b0b78928cd9f4cbf50d94d972043cdd829baa77a78929b",
68
72
  // MAINNET
69
73
  [Stage.TESTNET]: "0x47a30bcdb5b5bdbf6af883c7325827f3e40b3f52c3538e9e677e68cf0c0db060",
70
- [Stage.SANDBOX]: "0xbccf3169d417448997cb4928e2b8e33e97067871b8564b20c5c2ef6c3a7bf377"
74
+ [Stage.SANDBOX]: "0x81f5957aa36d8d1515ba5eb95df187fed85185610e7b14fbb0f281b12397f807"
75
+ //TODO(Ethan) double check
71
76
  };
72
77
  var RELAYER_SIGNER_ADDRESS = {
73
78
  [Stage.MAINNET]: "0x1d8727df513fa2a8785d0834e40b34223daff1affc079574082baadb74b66ee4",
74
79
  // MAINNET
75
80
  [Stage.TESTNET]: "0xc192864c4215741051321d44f89c3b7a54840a0b1b7ef5bec6149a07f9df4641",
76
- [Stage.SANDBOX]: "0xc180500ddac3fef70cb1e9fc0d75793850e2cef84d518ea0a3b3adfb93751ea7"
81
+ [Stage.SANDBOX]: "0x34fb23a3db82f39629506b507fdf886202c7935f74ddc8ecef9dac0bb849b07f"
82
+ //TODO(Ethan) double check
77
83
  };
78
84
  var EXECUTOR_ADDRESS = {
79
85
  [Stage.MAINNET]: "0x1d8727df513fa2a8785d0834e40b34223daff1affc079574082baadb74b66ee4",
80
86
  // MAINNET
81
87
  [Stage.TESTNET]: "0xc192864c4215741051321d44f89c3b7a54840a0b1b7ef5bec6149a07f9df4641",
82
- [Stage.SANDBOX]: "0xc180500ddac3fef70cb1e9fc0d75793850e2cef84d518ea0a3b3adfb93751ea7"
88
+ [Stage.SANDBOX]: "0xbfef909638ef90885158fdab9f56e216fd811fe25b32ead0bc2a272d66522bb0"
89
+ //TODO(Ethan) double check
83
90
  };
84
91
  var EXECUTOR_EXT_ADDRESS = {
85
92
  [Stage.MAINNET]: "0xd122ac52d43736e0f524a334fc37b6750884559da7ddf1aee0b11b6ae62643d7",
86
93
  // MAINNET
87
94
  [Stage.TESTNET]: "0x39942f4bd78e899f162644b5ec5998a19cb6de1ff8b7321070cb75cf96e5cf6c",
88
- [Stage.SANDBOX]: "0xeed8a91797cdfcbe0d33f92b57b76830f1ff6b4613db00f0c33035e31f77c936"
95
+ [Stage.SANDBOX]: "0xd8f318cab62a1142e1cd60f3f090331becc9a462a1a85180de8a99e2a27eadc0"
96
+ //TODO(Ethan) double check
89
97
  };
90
98
  var LAYERZERO_APPS_PUBKEY = {
91
99
  [Stage.MAINNET]: "0xf57e5a95ae0e2b5f999ac14abd0ff73daf64e6e7e2a1fad024f2e44422e88d76",
92
100
  // MAINNET
93
101
  [Stage.TESTNET]: "0xa6d39a1f522da0298a387032952393b1dd2f88ea75423de05c26792930c60ac0",
94
- [Stage.SANDBOX]: "0x3378e95c0f5f245208d3b330815eccdf704df522ccdebceabb4310354dd22e06"
102
+ [Stage.SANDBOX]: "0x116a5d69ece688512eaf0c0849ca587c6386c36a474d21504a4b6f6ae3a3a487"
95
103
  };
96
104
  var BRIDGE_ADDRESS = {
97
105
  [Stage.MAINNET]: "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa",
98
106
  // MAINNET
99
107
  [Stage.TESTNET]: "0xec84c05cc40950c86d8a8bed19552f1e8ebb783196bb021c916161d22dc179f7",
100
- [Stage.SANDBOX]: "0x96a9b4d53a6cb4f4fe2c43a82ab71b52624396f0792b64b5f23a1085690d8edb"
108
+ [Stage.SANDBOX]: "0xf52132c1ce7922eb0ac4f5342e8d7d0f817a5af9fb8da23793b058ad8ad38e19"
109
+ //TODO(Ethan) double check
101
110
  };
102
111
  var BRIDGE_PRECRIME_ADDRESS = {
103
112
  [Stage.MAINNET]: "0x16c7d29eea08ac77dfc4e4665bb56da0ded4e7b82c4c25d535b3d5a5fd6071ad",
104
113
  [Stage.TESTNET]: "0x3ed30825c327d8ee51e079c48b12981053fe2bfe07f74a6572726abf4d5c9afc",
105
- [Stage.SANDBOX]: ""
114
+ [Stage.SANDBOX]: "0x93b4711e61b1339868ab29f109b2204b452d6997bb5b58cf9d2160addfb71724"
106
115
  // TODO TESTNET_SANDBOX
107
116
  };
108
117
  var OFT_PRECRIME_ADDRESS = {
109
118
  [Stage.MAINNET]: "0x273f3e39593a6723adcecd5aa112158c07239043f79609a0380473157c841e19",
110
119
  [Stage.TESTNET]: "0x9fea38276544542be16c4592d1b10cf08d4d9dee33b51eca8a88f17921d985d2",
111
- [Stage.SANDBOX]: ""
120
+ [Stage.SANDBOX]: "0xa721bd722a3eff335044536af6e048afcfaae03043da920639f773154f20afd6"
112
121
  // TODO TESTNET_SANDBOX
113
122
  };
123
+ var COUNTER_ADDRESS = {
124
+ [Stage.MAINNET]: "",
125
+ // MAINNET
126
+ [Stage.TESTNET]: "0x52cfc2b434a0de1b5cb3982c556081d51585152c5d5f190ad0eb88f9bf1f07ce",
127
+ // [Stage.SANDBOX]: '0x9584ff2b8ec928fc82889c979a0d443ebccde12a0c65840bd302f6254e14c004',
128
+ [Stage.SANDBOX]: "0x2b249feeed4e30deb84f92c0960baf68652757ce2d7d672d566fdb9a34f8720e"
129
+ };
114
130
 
115
131
  // src/utils.ts
116
132
  var utils_exports = {};
@@ -671,6 +687,21 @@ var Endpoint = class {
671
687
  };
672
688
  return this.sdk.sendAndConfirmTransaction(signer, transaction);
673
689
  }
690
+ async getLocalChainId() {
691
+ try {
692
+ const resource = await this.sdk.client.getAccountResource(
693
+ this.sdk.accounts.layerzero,
694
+ `${this.module}::ChainConfig`
695
+ );
696
+ const { local_chain_id } = resource.data;
697
+ return local_chain_id;
698
+ } catch (err) {
699
+ if (err instanceof ApiError && err.errorCode === "resource_not_found") {
700
+ return void 0;
701
+ }
702
+ throw err;
703
+ }
704
+ }
674
705
  async getUATypeInfo(uaAddress) {
675
706
  const resource = await this.sdk.client.getAccountResource(
676
707
  this.sdk.accounts.layerzero,
@@ -745,6 +776,27 @@ var Endpoint = class {
745
776
  const transaction = this.registerExecutorPayload(executorType);
746
777
  return this.sdk.sendAndConfirmTransaction(signer, transaction);
747
778
  }
779
+ async getExecutorCap(version = "1") {
780
+ try {
781
+ const resource = await this.sdk.client.getAccountResource(
782
+ this.sdk.accounts.layerzero,
783
+ `${this.module}::Capabilities`
784
+ );
785
+ const { executor_caps } = resource.data;
786
+ const handle = executor_caps.handle;
787
+ const executorCap = await this.sdk.client.getTableItem(handle, {
788
+ key_type: "u64",
789
+ value_type: `${this.sdk.accounts.executor_auth}::executor_cap::ExecutorCapability`,
790
+ key: version
791
+ });
792
+ return executorCap.version;
793
+ } catch (err) {
794
+ if (err instanceof ApiError && (err.errorCode === "resource_not_found" || err.errorCode === "table_item_not_found")) {
795
+ return void 0;
796
+ }
797
+ throw err;
798
+ }
799
+ }
748
800
  };
749
801
 
750
802
  // src/format/bytecode.ts
@@ -2262,18 +2314,70 @@ var PacketEvent = class {
2262
2314
  constructor(sdk) {
2263
2315
  this.sdk = sdk;
2264
2316
  this.module = `${sdk.accounts.layerzero}::packet_event`;
2317
+ this.OutboundEventType = `${this.module}::OutboundEvent`;
2318
+ this.InboundEventType = `${this.module}::InboundEvent`;
2265
2319
  }
2266
2320
  module;
2321
+ OutboundEventType;
2322
+ InboundEventType;
2323
+ /**
2324
+ * returns an array of VersionedEvent objects for inbound events
2325
+ * @param start - the start index of the events, starting from 0
2326
+ * @param limit - the maximum number of events to return
2327
+ * @returns an array of VersionedEvent objects
2328
+ * @example
2329
+ * [
2330
+ * {
2331
+ * "version": "2527457",
2332
+ * "guid": {
2333
+ * "creation_number": "7",
2334
+ * "account_address": "0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90"
2335
+ * },
2336
+ * "sequence_number": "0",
2337
+ * "type": "0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90::packet_event::InboundEvent",
2338
+ * "data": {
2339
+ * "packet": {
2340
+ * "dst_address": "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa",
2341
+ * "dst_chain_id": "108",
2342
+ * "nonce": "1",
2343
+ * "payload": "0x00000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4857203756ea4273c43f583acd5b7a72aa168098da3fb9ffe4f6505515aae8fc9b0000000002faf080",
2344
+ * "src_address": "0x50002cdfe7ccb0c41f519c6eb0653158d11cd907",
2345
+ * "src_chain_id": "101"
2346
+ * }
2347
+ * }
2348
+ * },
2349
+ * {
2350
+ * "version": "2617627",
2351
+ * "guid": {
2352
+ * "creation_number": "7",
2353
+ * "account_address": "0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90"
2354
+ * },
2355
+ * "sequence_number": "1",
2356
+ * "type": "0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90::packet_event::InboundEvent",
2357
+ * "data": {
2358
+ * "packet": {
2359
+ * "dst_address": "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa",
2360
+ * "dst_chain_id": "108",
2361
+ * "nonce": "2",
2362
+ * "payload": "0x00000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7495f9f30a60c7cda8a60937b4281d00d8730596409820bbf59b2674624c76d9b00000000000f4240",
2363
+ * "src_address": "0x50002cdfe7ccb0c41f519c6eb0653158d11cd907",
2364
+ * "src_chain_id": "101"
2365
+ * }
2366
+ * }
2367
+ * }
2368
+ * ]
2369
+ */
2267
2370
  async getInboundEvents(start, limit) {
2268
2371
  if (this.sdk.accounts.layerzero === void 0) {
2269
2372
  throw new Error("sdk accounts layerzero is undefined when invoke getInboundEvents");
2270
2373
  }
2271
- return this.sdk.client.getEventsByEventHandle(
2374
+ const events = await this.sdk.client.getEventsByEventHandle(
2272
2375
  this.sdk.accounts.layerzero,
2273
2376
  `${this.module}::EventStore`,
2274
2377
  "inbound_events",
2275
2378
  { start, limit }
2276
2379
  );
2380
+ return events.map((event) => event);
2277
2381
  }
2278
2382
  async getInboundEventCount() {
2279
2383
  if (this.sdk.accounts.layerzero === void 0) {
@@ -2286,11 +2390,44 @@ var PacketEvent = class {
2286
2390
  const { inbound_events } = resource.data;
2287
2391
  return new BN(inbound_events.counter).toNumber();
2288
2392
  }
2393
+ /**
2394
+ * returns an array of VersionedEvent objects for outbound events
2395
+ * @param start - the start index of the events, starting from 0
2396
+ * @param limit - the maximum number of events to return
2397
+ * @returns an array of VersionedEvent objects
2398
+ * @example
2399
+ * [
2400
+ * {
2401
+ * version: '3290647',
2402
+ * guid: {
2403
+ * creation_number: '8',
2404
+ * account_address: '0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90'
2405
+ * },
2406
+ * sequence_number: '0',
2407
+ * type: '0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90::packet_event::OutboundEvent',
2408
+ * data: {
2409
+ * encoded_packet: '0x0000000000000001006cf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa006f86bb63148d17d445ed5398ef26aa05bf76dd5b59010000000000000000000000007f5c764cbc14f9669b88837ca1490cca17c316070000000000000000000000003a983ffaa79e2d12ef94b50f68346a4b9c653a9a00000000001e848000'
2410
+ * }
2411
+ * },
2412
+ * {
2413
+ * version: '3308828',
2414
+ * guid: {
2415
+ * creation_number: '8',
2416
+ * account_address: '0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90'
2417
+ * },
2418
+ * sequence_number: '1',
2419
+ * type: '0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90::packet_event::OutboundEvent',
2420
+ * data: {
2421
+ * encoded_packet: '0x0000000000000001006cf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa006aa5972eee0c9b5bbb89a5b16d1d65f94c9ef25166010000000000000000000000009702230a8ea53601f5cd2dc00fdbc13d4df4a8c700000000000000000000000015028e41c7ed391674505f6ea1213045571564e4000000000000006400'
2422
+ * }
2423
+ * }
2424
+ * ]
2425
+ */
2289
2426
  async getOutboundEvents(start, limit) {
2290
2427
  if (this.sdk.accounts.layerzero === void 0) {
2291
2428
  throw new Error("sdk accounts layerzero is undefined when invoke getOutboundEvents");
2292
2429
  }
2293
- return this.sdk.client.getEventsByEventHandle(
2430
+ const events = await this.sdk.client.getEventsByEventHandle(
2294
2431
  this.sdk.accounts.layerzero,
2295
2432
  `${this.module}::EventStore`,
2296
2433
  "outbound_events",
@@ -2299,6 +2436,7 @@ var PacketEvent = class {
2299
2436
  limit
2300
2437
  }
2301
2438
  );
2439
+ return events.map((event) => event);
2302
2440
  }
2303
2441
  async getOutboundEventCount() {
2304
2442
  if (this.sdk.accounts.layerzero === void 0) {
@@ -2499,6 +2637,20 @@ var UlnReceive = class {
2499
2637
  };
2500
2638
  return this.sdk.sendAndConfirmTransaction(signer, transaction);
2501
2639
  }
2640
+ async isInitialize() {
2641
+ try {
2642
+ await this.sdk.client.getAccountResource(
2643
+ this.sdk.accounts.layerzero,
2644
+ `${this.module}::CapStore`
2645
+ );
2646
+ return true;
2647
+ } catch (err) {
2648
+ if (err instanceof ApiError && err.errorCode === "resource_not_found") {
2649
+ return false;
2650
+ }
2651
+ throw err;
2652
+ }
2653
+ }
2502
2654
  async getOracleProposePayload(hash, confirmations) {
2503
2655
  const transaction = {
2504
2656
  function: `${this.module}::oracle_propose`,
@@ -3699,13 +3851,45 @@ var MultisigOracleTss = class {
3699
3851
  return this.sdk.sendAndConfirmTransaction(signer, transaction);
3700
3852
  }
3701
3853
  // Admin Functions
3854
+ getInitConfigPayload(validators, threshold, admins) {
3855
+ return {
3856
+ function: `${this.module}::mso_init_config`,
3857
+ type_arguments: [],
3858
+ arguments: [validators, threshold, admins]
3859
+ };
3860
+ }
3861
+ async initConfig(signer, validators, threshold, admins) {
3862
+ const transaction = this.getInitConfigPayload(validators, threshold, admins);
3863
+ return this.sdk.sendAndConfirmTransaction(signer, transaction);
3864
+ }
3702
3865
  getSetFeePayload(remoteChainId, baseFee) {
3703
- const result = {
3866
+ return {
3704
3867
  function: `${this.module}::mso_set_fee`,
3705
3868
  type_arguments: [],
3706
3869
  arguments: [remoteChainId, baseFee]
3707
3870
  };
3708
- return result;
3871
+ }
3872
+ getUpgradePayload() {
3873
+ return {
3874
+ function: `${this.module}::upgrade`,
3875
+ type_arguments: [],
3876
+ arguments: []
3877
+ };
3878
+ }
3879
+ async upgrade(signer) {
3880
+ const transaction = this.getUpgradePayload();
3881
+ return this.sdk.sendAndConfirmTransaction(signer, transaction);
3882
+ }
3883
+ getSetUseMsoPayload(useMso) {
3884
+ return {
3885
+ function: `${this.module}::mso_set_use_mso`,
3886
+ type_arguments: [],
3887
+ arguments: [useMso]
3888
+ };
3889
+ }
3890
+ async setUseMso(signer, useMso) {
3891
+ const transaction = this.getSetUseMsoPayload(useMso);
3892
+ return this.sdk.sendAndConfirmTransaction(signer, transaction);
3709
3893
  }
3710
3894
  async setFee(signer, remoteChainId, baseFee) {
3711
3895
  const transaction = this.getSetFeePayload(remoteChainId, baseFee);
@@ -4366,7 +4550,8 @@ var SDK = class {
4366
4550
  executor_ext: EXECUTOR_EXT_ADDRESS[this.stage],
4367
4551
  executor_v2: LAYERZERO_ADDRESS[this.stage],
4368
4552
  layerzero_apps: LAYERZERO_APPS_ADDRESS[this.stage],
4369
- layerzero_apps_pubkey: LAYERZERO_APPS_PUBKEY[this.stage]
4553
+ layerzero_apps_pubkey: LAYERZERO_APPS_PUBKEY[this.stage],
4554
+ counter: COUNTER_ADDRESS[this.stage]
4370
4555
  };
4371
4556
  this.client = options.provider;
4372
4557
  this.LayerzeroModule = new Layerzero(this);