@layerzerolabs/lz-definitions 3.0.14 → 3.0.16

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,17 @@
1
1
  # @layerzerolabs/lz-definitions
2
2
 
3
+ ## 3.0.16
4
+
5
+ ### Patch Changes
6
+
7
+ - 87a4bc9: islander mainnet
8
+
9
+ ## 3.0.15
10
+
11
+ ### Patch Changes
12
+
13
+ - 67856bd: endpoints
14
+
3
15
  ## 3.0.14
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -0,0 +1,376 @@
1
+ # @layerzerolabs/lz-definitions
2
+
3
+ The LayerZero Definitions package provides a comprehensive set of type definitions and utilities for interacting with various blockchains. It includes enums, types, and interfaces that facilitate the development and integration of applications with the LayerZero protocol.
4
+
5
+ ## Features
6
+
7
+ - **Enums**: Provides a set of enums representing various blockchain-related constants.
8
+ - **Types**: Defines various types used across the LayerZero protocol.
9
+ - **Interfaces**: Provides interfaces for different blockchain specifications and configurations.
10
+ - **Utilities**: Includes utility functions for converting and handling blockchain-related data.
11
+
12
+ ## Installation
13
+
14
+ To install the LayerZero Definitions package, you can use npm or yarn:
15
+
16
+ ```sh
17
+ npm install @layerzerolabs/lz-definitions
18
+ ```
19
+
20
+ or
21
+
22
+ ```sh
23
+ yarn add @layerzerolabs/lz-definitions
24
+ ```
25
+
26
+ ## Utilities
27
+
28
+ ### networkToEndpointId
29
+
30
+ ```typescript
31
+ import {
32
+ networkToEndpointId,
33
+ EndpointVersion,
34
+ EndpointId,
35
+ } from "@layerzerolabs/lz-definitions";
36
+
37
+ // Converts a network name and version to an endpoint ID.
38
+ const endpointId: EndpointId = networkToEndpointId(
39
+ "ethereum-mainnet",
40
+ EndpointVersion.V1,
41
+ );
42
+ console.log(endpointId);
43
+ ```
44
+
45
+ ### networkToEnv
46
+
47
+ ```typescript
48
+ import {
49
+ networkToEnv,
50
+ EndpointVersion,
51
+ Environment,
52
+ } from "@layerzerolabs/lz-definitions";
53
+
54
+ // Converts a network name and version to an environment.
55
+ const environment: Environment = networkToEnv(
56
+ "ethereum-mainnet",
57
+ EndpointVersion.V1,
58
+ );
59
+ console.log(environment);
60
+ ```
61
+
62
+ ### networkToStage
63
+
64
+ ```typescript
65
+ import { networkToStage, Stage } from "@layerzerolabs/lz-definitions";
66
+
67
+ // Converts a network name to a stage.
68
+ const stage: Stage = networkToStage("ethereum-mainnet");
69
+ console.log(stage);
70
+ ```
71
+
72
+ ### endpointIdToNetwork
73
+
74
+ ```typescript
75
+ import {
76
+ endpointIdToNetwork,
77
+ Environment,
78
+ Network,
79
+ SandboxV2EndpointId,
80
+ } from "@layerzerolabs/lz-definitions";
81
+
82
+ // Converts an endpoint ID to a network name.
83
+ const network: Network = endpointIdToNetwork(
84
+ SandboxV2EndpointId.APTOS_V2_SANDBOX,
85
+ Environment.MAINNET,
86
+ );
87
+ console.log(network);
88
+ ```
89
+
90
+ ### endpointIdToVersion
91
+
92
+ ```typescript
93
+ import {
94
+ endpointIdToVersion,
95
+ EndpointVersion,
96
+ SandboxV2EndpointId,
97
+ } from "@layerzerolabs/lz-definitions";
98
+
99
+ // Converts an endpoint ID to an endpoint version.
100
+ const version: EndpointVersion = endpointIdToVersion(
101
+ SandboxV2EndpointId.APTOS_V2_SANDBOX,
102
+ );
103
+ console.log(version);
104
+ ```
105
+
106
+ ### endpointIdToChainKey
107
+
108
+ ```typescript
109
+ import {
110
+ endpointIdToChainKey,
111
+ ChainKey,
112
+ SandboxV2EndpointId,
113
+ } from "@layerzerolabs/lz-definitions";
114
+
115
+ // Converts an endpoint ID to a chain key.
116
+ const chainKey: ChainKey = endpointIdToChainKey(
117
+ SandboxV2EndpointId.APTOS_V2_SANDBOX,
118
+ );
119
+ console.log(chainKey);
120
+ ```
121
+
122
+ ### chainAndStageToEndpointId
123
+
124
+ ```typescript
125
+ import {
126
+ chainAndStageToEndpointId,
127
+ Chain,
128
+ Stage,
129
+ EndpointVersion,
130
+ EndpointId,
131
+ } from "@layerzerolabs/lz-definitions";
132
+
133
+ // Converts a chain and stage to an endpoint ID.
134
+ const endpointId: EndpointId = chainAndStageToEndpointId(
135
+ Chain.ETHEREUM,
136
+ Stage.MAINNET,
137
+ EndpointVersion.V1,
138
+ );
139
+ console.log(endpointId);
140
+ ```
141
+
142
+ ### chainAndStageToNetwork
143
+
144
+ ```typescript
145
+ import {
146
+ chainAndStageToNetwork,
147
+ Chain,
148
+ Stage,
149
+ Network,
150
+ } from "@layerzerolabs/lz-definitions";
151
+
152
+ // Converts a chain and stage to a network name.
153
+ const network: Network = chainAndStageToNetwork(Chain.ETHEREUM, Stage.MAINNET);
154
+ console.log(network);
155
+ ```
156
+
157
+ ### endpointSpecToNetwork
158
+
159
+ ```typescript
160
+ import {
161
+ endpointSpecToNetwork,
162
+ EndpointSpec,
163
+ Network,
164
+ } from "@layerzerolabs/lz-definitions";
165
+
166
+ const spec: EndpointSpec = {
167
+ chain: Chain.ETHEREUM,
168
+ stage: Stage.MAINNET,
169
+ version: EndpointVersion.V1,
170
+ env: Environment.MAINNET,
171
+ };
172
+
173
+ // Converts an endpoint specification to a network name.
174
+ const network: Network = endpointSpecToNetwork(spec);
175
+ console.log(network);
176
+ ```
177
+
178
+ ### endpointSpecToEnv
179
+
180
+ ```typescript
181
+ import {
182
+ endpointSpecToEnv,
183
+ EndpointSpec,
184
+ Environment,
185
+ } from "@layerzerolabs/lz-definitions";
186
+
187
+ const spec: EndpointSpec = {
188
+ chain: Chain.ETHEREUM,
189
+ stage: Stage.MAINNET,
190
+ version: EndpointVersion.V1,
191
+ env: Environment.MAINNET,
192
+ };
193
+
194
+ // Converts an endpoint specification to an environment.
195
+ const environment: Environment = endpointSpecToEnv(spec);
196
+ console.log(environment);
197
+ ```
198
+
199
+ ### endpointSpecToEndpointId
200
+
201
+ ```typescript
202
+ import {
203
+ endpointSpecToEndpointId,
204
+ EndpointSpec,
205
+ EndpointId,
206
+ } from "@layerzerolabs/lz-definitions";
207
+
208
+ const spec: EndpointSpec = {
209
+ chain: Chain.ETHEREUM,
210
+ stage: Stage.MAINNET,
211
+ version: EndpointVersion.V1,
212
+ env: Environment.MAINNET,
213
+ };
214
+
215
+ // Converts an endpoint specification to an endpoint ID.
216
+ const endpointId: EndpointId = endpointSpecToEndpointId(spec);
217
+ console.log(endpointId);
218
+ ```
219
+
220
+ ### endpointIdToEndpointSpec
221
+
222
+ ```typescript
223
+ import {
224
+ endpointIdToEndpointSpec,
225
+ EndpointId,
226
+ EndpointSpec,
227
+ Environment,
228
+ SandboxV2EndpointId,
229
+ } from "@layerzerolabs/lz-definitions";
230
+
231
+ // Converts an endpoint ID and environment to an endpoint specification.
232
+ const spec: EndpointSpec = endpointIdToEndpointSpec(
233
+ SandboxV2EndpointId.APTOS_V2_SANDBOX,
234
+ Environment.MAINNET,
235
+ );
236
+ console.log(spec);
237
+ ```
238
+
239
+ ### networkToChain
240
+
241
+ ```typescript
242
+ import { networkToChain, Chain } from "@layerzerolabs/lz-definitions";
243
+
244
+ // Converts a network name to a chain.
245
+ const chain: Chain = networkToChain("ethereum-mainnet");
246
+ console.log(chain);
247
+ ```
248
+
249
+ ### networkToChainType
250
+
251
+ ```typescript
252
+ import { networkToChainType, ChainType } from "@layerzerolabs/lz-definitions";
253
+
254
+ // Converts a network name to a chain type.
255
+ const chainType: ChainType = networkToChainType("ethereum-mainnet");
256
+ console.log(chainType);
257
+ ```
258
+
259
+ ### chainToChainType
260
+
261
+ ```typescript
262
+ import {
263
+ chainToChainType,
264
+ Chain,
265
+ ChainType,
266
+ } from "@layerzerolabs/lz-definitions";
267
+
268
+ // Returns the chain type for a given chain.
269
+ const chainType: ChainType = chainToChainType(Chain.ETHEREUM);
270
+ console.log(chainType);
271
+ ```
272
+
273
+ ### endpointIdToChain
274
+
275
+ ```typescript
276
+ import {
277
+ endpointIdToChain,
278
+ Chain,
279
+ SandboxV2EndpointId,
280
+ } from "@layerzerolabs/lz-definitions";
281
+
282
+ // Converts an endpoint ID to a chain.
283
+ const chain: Chain = endpointIdToChain(SandboxV2EndpointId.APTOS_V2_SANDBOX);
284
+ console.log(chain);
285
+ ```
286
+
287
+ ### endpointIdToStage
288
+
289
+ ```typescript
290
+ import {
291
+ endpointIdToStage,
292
+ Stage,
293
+ SandboxV2EndpointId,
294
+ } from "@layerzerolabs/lz-definitions";
295
+
296
+ // Converts an endpoint ID to a stage.
297
+ const stage: Stage = endpointIdToStage(SandboxV2EndpointId.APTOS_V2_SANDBOX);
298
+ console.log(stage);
299
+ ```
300
+
301
+ ### endpointIdToChainType
302
+
303
+ ```typescript
304
+ import {
305
+ endpointIdToChainType,
306
+ ChainType,
307
+ SandboxV2EndpointId,
308
+ } from "@layerzerolabs/lz-definitions";
309
+
310
+ // Converts an endpoint ID to a chain type.
311
+ const chainType: ChainType = endpointIdToChainType(
312
+ SandboxV2EndpointId.APTOS_V2_SANDBOX,
313
+ );
314
+ console.log(chainType);
315
+ ```
316
+
317
+ ### getNetworksForStage
318
+
319
+ ```typescript
320
+ import { getNetworksForStage, Stage } from "@layerzerolabs/lz-definitions";
321
+
322
+ // Gets the networks for a given stage.
323
+ const networks: string[] = getNetworksForStage(Stage.MAINNET);
324
+ console.log(networks);
325
+ ```
326
+
327
+ ### getChainIdForNetwork
328
+
329
+ ```typescript
330
+ import { getChainIdForNetwork } from "@layerzerolabs/lz-definitions";
331
+
332
+ // Gets the chain ID for a given network.
333
+ const chainId: string = getChainIdForNetwork("ethereum", "mainnet", "1.0.0");
334
+ console.log(chainId);
335
+ ```
336
+
337
+ ### getNetworkForChainId
338
+
339
+ ```typescript
340
+ import {
341
+ getNetworkForChainId,
342
+ Chain,
343
+ Stage,
344
+ SandboxV2EndpointId,
345
+ } from "@layerzerolabs/lz-definitions";
346
+
347
+ // Gets the network for a given chain ID.
348
+ const networkInfo = getNetworkForChainId(SandboxV2EndpointId.APTOS_V2_SANDBOX);
349
+ console.log(networkInfo.chainName, networkInfo.env, networkInfo.ulnVersion);
350
+ ```
351
+
352
+ ### isNetworkEndpointIdSupported
353
+
354
+ ```typescript
355
+ import {
356
+ isNetworkEndpointIdSupported,
357
+ EndpointVersion,
358
+ } from "@layerzerolabs/lz-definitions";
359
+
360
+ // Checks if a network endpoint ID is supported.
361
+ const isSupported: boolean = isNetworkEndpointIdSupported(
362
+ "ethereum-mainnet",
363
+ EndpointVersion.V1,
364
+ );
365
+ console.log(isSupported);
366
+ ```
367
+
368
+ ### isEvmChain
369
+
370
+ ```typescript
371
+ import { isEvmChain, Chain } from "@layerzerolabs/lz-definitions";
372
+
373
+ // Determines if a chain is EVM based.
374
+ const isEvm: boolean = isEvmChain(Chain.ETHEREUM);
375
+ console.log(isEvm);
376
+ ```
package/dist/index.cjs CHANGED
@@ -187,6 +187,7 @@ var EvmChain = /* @__PURE__ */ ((EvmChain2) => {
187
187
  EvmChain2["MOKSHA"] = "moksha";
188
188
  EvmChain2["EDU"] = "edu";
189
189
  EvmChain2["CITREA"] = "citrea";
190
+ EvmChain2["ISLANDER"] = "islander";
190
191
  return EvmChain2;
191
192
  })(EvmChain || {});
192
193
 
@@ -337,6 +338,7 @@ var MainnetEndpointId = /* @__PURE__ */ ((MainnetEndpointId2) => {
337
338
  MainnetEndpointId2[MainnetEndpointId2["SUPERPOSITION_MAINNET"] = 327] = "SUPERPOSITION_MAINNET";
338
339
  MainnetEndpointId2[MainnetEndpointId2["EDU_MAINNET"] = 328] = "EDU_MAINNET";
339
340
  MainnetEndpointId2[MainnetEndpointId2["HEMI_MAINNET"] = 329] = "HEMI_MAINNET";
341
+ MainnetEndpointId2[MainnetEndpointId2["ISLANDER_MAINNET"] = 330] = "ISLANDER_MAINNET";
340
342
  return MainnetEndpointId2;
341
343
  })(MainnetEndpointId || {});
342
344
  var TestnetEndpointId = /* @__PURE__ */ ((TestnetEndpointId2) => {
@@ -624,6 +626,7 @@ var MainnetV2EndpointId = /* @__PURE__ */ ((MainnetV2EndpointId2) => {
624
626
  MainnetV2EndpointId2[MainnetV2EndpointId2["EDU_V2_MAINNET"] = 30328] = "EDU_V2_MAINNET";
625
627
  MainnetV2EndpointId2[MainnetV2EndpointId2["TON_V2_MAINNET"] = 30343] = "TON_V2_MAINNET";
626
628
  MainnetV2EndpointId2[MainnetV2EndpointId2["HEMI_V2_MAINNET"] = 30329] = "HEMI_V2_MAINNET";
629
+ MainnetV2EndpointId2[MainnetV2EndpointId2["ISLANDER_V2_MAINNET"] = 30330] = "ISLANDER_V2_MAINNET";
627
630
  return MainnetV2EndpointId2;
628
631
  })(MainnetV2EndpointId || {});
629
632
  var TestnetV2EndpointId = /* @__PURE__ */ ((TestnetV2EndpointId2) => {
@@ -1139,6 +1142,7 @@ var ChainKey = /* @__PURE__ */ ((ChainKey3) => {
1139
1142
  ChainKey3["HEMI_TESTNET"] = "hemi-testnet";
1140
1143
  ChainKey3["HEMI"] = "hemi";
1141
1144
  ChainKey3["CITREA_TESTNET"] = "citrea-testnet";
1145
+ ChainKey3["ISLANDER"] = "islander";
1142
1146
  return ChainKey3;
1143
1147
  })(ChainKey || {});
1144
1148
 
@@ -1257,6 +1261,7 @@ var CHAIN_KEY = {
1257
1261
  [EndpointId.SUPERPOSITION_MAINNET]: "superposition" /* SUPERPOSITION */,
1258
1262
  [EndpointId.EDU_MAINNET]: "edu" /* EDU */,
1259
1263
  [EndpointId.HEMI_MAINNET]: "hemi" /* HEMI */,
1264
+ [EndpointId.ISLANDER_MAINNET]: "islander" /* ISLANDER */,
1260
1265
  // v2 mainnet
1261
1266
  [EndpointId.ETHEREUM_V2_MAINNET]: "ethereum" /* ETHEREUM */,
1262
1267
  [EndpointId.BSC_V2_MAINNET]: "bsc" /* BSC */,
@@ -1366,6 +1371,7 @@ var CHAIN_KEY = {
1366
1371
  [EndpointId.SUPERPOSITION_V2_MAINNET]: "superposition" /* SUPERPOSITION */,
1367
1372
  [EndpointId.EDU_V2_MAINNET]: "edu" /* EDU */,
1368
1373
  [EndpointId.HEMI_V2_MAINNET]: "hemi" /* HEMI */,
1374
+ [EndpointId.ISLANDER_V2_MAINNET]: "islander" /* ISLANDER */,
1369
1375
  [EndpointId.TON_V2_MAINNET]: "ton" /* TON */,
1370
1376
  // testnet
1371
1377
  [EndpointId.ETHEREUM_TESTNET]: "sepolia" /* SEPOLIA */,
@@ -1823,6 +1829,7 @@ var ENVIRONMENT = {
1823
1829
  [EndpointId.SUPERPOSITION_MAINNET]: "mainnet" /* MAINNET */,
1824
1830
  [EndpointId.EDU_MAINNET]: "mainnet" /* MAINNET */,
1825
1831
  [EndpointId.HEMI_MAINNET]: "mainnet" /* MAINNET */,
1832
+ [EndpointId.ISLANDER_MAINNET]: "mainnet" /* MAINNET */,
1826
1833
  // v2 mainnet
1827
1834
  [EndpointId.ETHEREUM_V2_MAINNET]: "mainnet" /* MAINNET */,
1828
1835
  [EndpointId.BSC_V2_MAINNET]: "mainnet" /* MAINNET */,
@@ -1932,6 +1939,7 @@ var ENVIRONMENT = {
1932
1939
  [EndpointId.SUPERPOSITION_V2_MAINNET]: "mainnet" /* MAINNET */,
1933
1940
  [EndpointId.EDU_V2_MAINNET]: "mainnet" /* MAINNET */,
1934
1941
  [EndpointId.HEMI_V2_MAINNET]: "mainnet" /* MAINNET */,
1942
+ [EndpointId.ISLANDER_V2_MAINNET]: "mainnet" /* MAINNET */,
1935
1943
  [EndpointId.TON_V2_MAINNET]: "mainnet" /* MAINNET */,
1936
1944
  // testnet
1937
1945
  [EndpointId.ETHEREUM_TESTNET]: "testnet" /* TESTNET */,
@@ -2392,7 +2400,7 @@ function networkToChain(network) {
2392
2400
  }
2393
2401
  function networkToChainType(network) {
2394
2402
  const chain = networkToChain(network);
2395
- return getChainType(chain);
2403
+ return chainToChainType(chain);
2396
2404
  }
2397
2405
  function chainToChainType(chain) {
2398
2406
  switch (chain) {
@@ -2439,7 +2447,7 @@ function endpointIdToStage(endpointId) {
2439
2447
  }
2440
2448
  function endpointIdToChainType(endpointId) {
2441
2449
  const chain = endpointIdToChain(endpointId);
2442
- return getChainType(chain);
2450
+ return chainToChainType(chain);
2443
2451
  }
2444
2452
  function getNetworksForStage(stage) {
2445
2453
  const networks = [];
@@ -2517,16 +2525,16 @@ function isTronChain(chain) {
2517
2525
  return chain === Chain.TRON || chain === Chain.TRONDEV;
2518
2526
  }
2519
2527
  function isEvmChain(chain) {
2520
- return getChainType(chain) === "evm" /* EVM */;
2528
+ return chainToChainType(chain) === "evm" /* EVM */;
2521
2529
  }
2522
2530
  function isAptosChain(chain) {
2523
- return getChainType(chain) === "aptos" /* APTOS */;
2531
+ return chainToChainType(chain) === "aptos" /* APTOS */;
2524
2532
  }
2525
2533
  function isSolanaChain(chain) {
2526
- return getChainType(chain) === "solana" /* SOLANA */;
2534
+ return chainToChainType(chain) === "solana" /* SOLANA */;
2527
2535
  }
2528
2536
  function isInitiaChain(chain) {
2529
- return getChainType(chain) === "initia" /* INITIA */;
2537
+ return chainToChainType(chain) === "initia" /* INITIA */;
2530
2538
  }
2531
2539
  function isChain(value) {
2532
2540
  return Object.values(Chain).includes(value);
@@ -2557,9 +2565,23 @@ var chainSpecConfig = {
2557
2565
  }
2558
2566
  };
2559
2567
  var ChainSpecs = class {
2568
+ /**
2569
+ * Gets the address size in bytes for a given chain.
2570
+ *
2571
+ * @param {Chain} chain - The chain.
2572
+ * @returns {number} The address size in bytes.
2573
+ */
2560
2574
  static getAddressSizeInBytes(chain) {
2561
2575
  return this.getChainSpec(getChainType(chain), chain).addressSizeInBytes;
2562
2576
  }
2577
+ /**
2578
+ * Gets the chain specification for a given chain type and chain.
2579
+ *
2580
+ * @param {ChainType} chainType - The type of the chain.
2581
+ * @param {Chain | 'default'} chain - The chain or 'default'.
2582
+ * @returns {ChainSpec} The chain specification.
2583
+ * @throws {Error} If the configuration for the chain type is not found.
2584
+ */
2563
2585
  static getChainSpec(chainType, chain) {
2564
2586
  if (chainSpecConfig[chainType] === void 0) {
2565
2587
  throw new Error(`config for ${chainType} not found in staticConfig`);