@layerzerolabs/evm-sdks-core 3.0.15 → 3.0.17

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,18 @@
1
1
  # @layerzerolabs/evm-sdks-core
2
2
 
3
+ ## 3.0.17
4
+
5
+ ### Patch Changes
6
+
7
+ - 40f2269: islander mainnet
8
+ - 40f2269: testnets
9
+
10
+ ## 3.0.16
11
+
12
+ ### Patch Changes
13
+
14
+ - 87a4bc9: islander mainnet
15
+
3
16
  ## 3.0.15
4
17
 
5
18
  ### Patch Changes
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # @layerzerolabs/evm-sdks-core
2
+
3
+ The EVM SDKs Core package provides essential utilities and tools for interacting with EVM-compatible blockchains. It includes functions for contract error parsing.
4
+
5
+ ## Features
6
+
7
+ - **Error Parsing**: Parse contract errors and convert them into easy-to-read and structured data.
8
+
9
+ ## Installation
10
+
11
+ To install the EVM SDKs Core package, you can use npm or yarn:
12
+
13
+ ```sh
14
+ npm install @layerzerolabs/evm-sdks-core
15
+ ```
16
+
17
+ or
18
+
19
+ ```sh
20
+ yarn add @layerzerolabs/evm-sdks-core
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ### Error Parsing
26
+
27
+ ```typescript
28
+ import { LayerZeroErrorParser, Abi } from "@layerzerolabs/evm-sdks-core";
29
+ import { EndpointV2__factory } from "@layerzerolabs/lz-evm-sdk-v2";
30
+
31
+ const abi: Abi = Endpoint__factory.createInterface();
32
+ const parser = new LayerZeroErrorParser(abi);
33
+
34
+ const errorData = "..."; // Error data string
35
+ const parsedError = parser.parse(errorData);
36
+
37
+ if (parsedError) {
38
+ console.log(`Error: ${parsedError.message}`);
39
+ }
40
+ ```
package/dist/index.cjs CHANGED
@@ -4,6 +4,12 @@ var ethers = require('ethers');
4
4
 
5
5
  // src/error-parser.ts
6
6
  var LayerZeroContractError = class extends Error {
7
+ /**
8
+ * Creates an instance of LayerZeroContractError.
9
+ * @param message The error message.
10
+ * @param cause The cause of the error.
11
+ * @param args The arguments associated with the error. {@link FormattedErrorArg}
12
+ */
7
13
  constructor(message, cause, args) {
8
14
  super(message);
9
15
  this.name = "LayerZeroContractError";
@@ -29,15 +35,13 @@ var LayerZeroErrorParser = class {
29
35
  try {
30
36
  const interf = new ethers.utils.Interface(this.abi);
31
37
  const parsed = interf.parseError(data);
32
- if (!parsed)
33
- return null;
38
+ if (!parsed) return null;
34
39
  const { name: cause, args } = parsed;
35
40
  const formattedArgs = [];
36
41
  let message = `${cause}, `;
37
42
  parsed.errorFragment.inputs.forEach(({ name: argName, type }, i) => {
38
43
  formattedArgs.push({ param: argName, type, value: args[i]?.toString() ?? args[i] });
39
- if (argName)
40
- message += `${argName} `;
44
+ if (argName) message += `${argName} `;
41
45
  message += `${args[i]}, `;
42
46
  });
43
47
  return { message: message.slice(0, -2), name: "LayerZeroContractError", cause, args: formattedArgs };
@@ -64,8 +68,7 @@ var LayerZeroErrorParser = class {
64
68
  const error = this.parseContractError(data);
65
69
  if (error) {
66
70
  const lzErr = new LayerZeroContractError(error.message, error.cause, error.args);
67
- if (cleanUpStackTrace)
68
- Error.captureStackTrace(lzErr, cleanUpStackTrace);
71
+ if (cleanUpStackTrace) Error.captureStackTrace(lzErr, cleanUpStackTrace);
69
72
  throw lzErr;
70
73
  }
71
74
  }
@@ -73,5 +76,5 @@ var LayerZeroErrorParser = class {
73
76
 
74
77
  exports.LayerZeroContractError = LayerZeroContractError;
75
78
  exports.LayerZeroErrorParser = LayerZeroErrorParser;
76
- //# sourceMappingURL=out.js.map
79
+ //# sourceMappingURL=index.cjs.map
77
80
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/error-parser.ts"],"names":[],"mappings":";AAAA,SAAS,aAAa;AAef,IAAM,yBAAN,cAAqC,MAAuB;AAAA,EAG/D,YAAY,SAAiB,OAAe,MAA2B;AACnE,UAAM,OAAO;AAC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AiB;AACvE,YAAM;AAAA,IACV;AAAA,EACJ;AACJ","sourcesContent":["import { utils } from 'ethers'\n\nexport interface LayerZeroParsedError {\n message: string\n name: string\n cause: string\n args: FormattedErrorArg[]\n}\nexport type Abi = ConstructorParameters<typeof utils.Interface>[0]\nexport interface FormattedErrorArg {\n param: string | null\n type: string\n value: string\n}\n\nexport class LayerZeroContractError extends Error implements Error {\n public args: FormattedErrorArg[]\n public cause: string\n constructor(message: string, cause: string, args: FormattedErrorArg[]) {\n super(message)\n this.name = 'LayerZeroContractError'\n this.cause = cause\n this.args = args\n }\n}\n\n/**\n * Class responsible for parsing errors related to LayerZero operations.\n */\nexport class LayerZeroErrorParser {\n /**\n * Creates an instance of LayerZeroErrorParser.\n * @param abi The error abi of the contracts that are interacted with.\n */\n constructor(public abi: Abi) {}\n\n /**\n * Parses a contract error from a given data string.\n * @param data The error data string to parse.\n * @returns The parsed error information or null if parsing fails.\n * @private\n */\n private parseContractError(data: string): LayerZeroParsedError | null {\n try {\n const interf = new utils.Interface(this.abi)\n const parsed = interf.parseError(data)\n if (!parsed) return null\n const { name: cause, args } = parsed\n const formattedArgs: FormattedErrorArg[] = []\n let message = `${cause}, `\n parsed.errorFragment.inputs.forEach(({ name: argName, type }, i) => {\n formattedArgs.push({ param: argName, type, value: args[i]?.toString() ?? args[i] })\n if (argName) message += `${argName} `\n message += `${args[i]}, `\n })\n return { message: message.slice(0, -2), name: 'LayerZeroContractError', cause, args: formattedArgs }\n } catch (error) {\n return null\n }\n }\n\n /**\n * Parses an error from a given data string.\n * @param data The error data string to parse.\n * @returns The parsed error information or null if the error is unrecognized.\n */\n public parse(data: string): LayerZeroParsedError | null {\n const error = this.parseContractError(data)\n // add more error parsers here as needed, for now only contract errors are supported\n return error\n }\n\n /**\n * Checks for a contract error in the given data string, throwing a `LayerZeroContractError` if one is found.\n * @param data The error data string to check.\n * @param cleanUpStackTrace An optional function to clean up the stack. This function and all function above in the stack will be excluded from the trace.\n * @throws {LayerZeroContractError} Throws a LayerZeroContractError if an error is found corresponding to the data string.\n */\n public check(data: string, cleanUpStackTrace?: (...args: any) => any): void {\n const error = this.parseContractError(data)\n if (error) {\n const lzErr = new LayerZeroContractError(error.message, error.cause, error.args)\n if (cleanUpStackTrace) Error.captureStackTrace(lzErr, cleanUpStackTrace)\n throw lzErr\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/error-parser.ts"],"names":["utils"],"mappings":";;;;;AAmDa,IAAA,sBAAA,GAAN,cAAqC,KAAuB,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgB/D,WAAA,CAAY,OAAiB,EAAA,KAAA,EAAe,IAA2B,EAAA;AACnE,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAO,GAAA,wBAAA;AACZ,IAAA,IAAA,CAAK,KAAQ,GAAA,KAAA;AACb,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;AAAA;AAEpB;AAKO,IAAM,uBAAN,MAA2B;AAAA;AAAA;AAAA;AAAA;AAAA,EAK9B,YAAmB,GAAU,EAAA;AAAV,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAAA;AAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQtB,mBAAmB,IAA2C,EAAA;AAClE,IAAI,IAAA;AACA,MAAA,MAAM,MAAS,GAAA,IAAIA,YAAM,CAAA,SAAA,CAAU,KAAK,GAAG,CAAA;AAC3C,MAAM,MAAA,MAAA,GAAS,MAAO,CAAA,UAAA,CAAW,IAAI,CAAA;AACrC,MAAI,IAAA,CAAC,QAAe,OAAA,IAAA;AACpB,MAAA,MAAM,EAAE,IAAA,EAAM,KAAO,EAAA,IAAA,EAAS,GAAA,MAAA;AAC9B,MAAA,MAAM,gBAAqC,EAAC;AAC5C,MAAI,IAAA,OAAA,GAAU,GAAG,KAAK,CAAA,EAAA,CAAA;AACtB,MAAO,MAAA,CAAA,aAAA,CAAc,OAAO,OAAQ,CAAA,CAAC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'\n\n/**\n * Interface representing a parsed LayerZero error.\n */\nexport interface LayerZeroParsedError {\n /**\n * The error message.\n */\n message: string\n /**\n * The name of the error.\n */\n name: string\n /**\n * The cause of the error.\n */\n cause: string\n /**\n * The arguments associated with the error.\n * @see {@link FormattedErrorArg}\n */\n args: FormattedErrorArg[]\n}\n\n/**\n * Type representing the ABI of a contract.\n */\nexport type Abi = ConstructorParameters<typeof utils.Interface>[0]\n\n/**\n * Interface representing a formatted error argument.\n */\nexport interface FormattedErrorArg {\n /**\n * The parameter name.\n */\n param: string | null\n /**\n * The type of the parameter.\n */\n type: string\n /**\n * The value of the parameter.\n */\n value: string\n}\n\n/**\n * Class representing a LayerZero contract error.\n */\nexport class LayerZeroContractError extends Error implements Error {\n /**\n * The arguments associated with the error.\n * @see {@link FormattedErrorArg}\n */\n public args: FormattedErrorArg[]\n /**\n * The cause of the error.\n */\n public cause: string\n /**\n * Creates an instance of LayerZeroContractError.\n * @param message The error message.\n * @param cause The cause of the error.\n * @param args The arguments associated with the error. {@link FormattedErrorArg}\n */\n constructor(message: string, cause: string, args: FormattedErrorArg[]) {\n super(message)\n this.name = 'LayerZeroContractError'\n this.cause = cause\n this.args = args\n }\n}\n\n/**\n * Class responsible for parsing errors related to LayerZero operations.\n */\nexport class LayerZeroErrorParser {\n /**\n * Creates an instance of LayerZeroErrorParser.\n * @param abi The error abi of the contracts that are interacted with.\n */\n constructor(public abi: Abi) {}\n\n /**\n * Parses a contract error from a given data string.\n * @param data The error data string to parse.\n * @returns The parsed error information or null if parsing fails.\n * @private\n */\n private parseContractError(data: string): LayerZeroParsedError | null {\n try {\n const interf = new utils.Interface(this.abi)\n const parsed = interf.parseError(data)\n if (!parsed) return null\n const { name: cause, args } = parsed\n const formattedArgs: FormattedErrorArg[] = []\n let message = `${cause}, `\n parsed.errorFragment.inputs.forEach(({ name: argName, type }, i) => {\n formattedArgs.push({ param: argName, type, value: args[i]?.toString() ?? args[i] })\n if (argName) message += `${argName} `\n message += `${args[i]}, `\n })\n return { message: message.slice(0, -2), name: 'LayerZeroContractError', cause, args: formattedArgs }\n } catch (error) {\n return null\n }\n }\n\n /**\n * Parses an error from a given data string.\n * @param data The error data string to parse.\n * @returns The parsed error information or null if the error is unrecognized.\n */\n public parse(data: string): LayerZeroParsedError | null {\n const error = this.parseContractError(data)\n // add more error parsers here as needed, for now only contract errors are supported\n return error\n }\n\n /**\n * Checks for a contract error in the given data string, throwing a `LayerZeroContractError` if one is found.\n * @param data The error data string to check.\n * @param cleanUpStackTrace An optional function to clean up the stack. This function and all function above in the stack will be excluded from the trace.\n * @throws {LayerZeroContractError} Throws a LayerZeroContractError if an error is found corresponding to the data string.\n */\n public check(data: string, cleanUpStackTrace?: (...args: any) => any): void {\n const error = this.parseContractError(data)\n if (error) {\n const lzErr = new LayerZeroContractError(error.message, error.cause, error.args)\n if (cleanUpStackTrace) Error.captureStackTrace(lzErr, cleanUpStackTrace)\n throw lzErr\n }\n }\n}\n"]}
package/dist/index.d.mts CHANGED
@@ -1,20 +1,67 @@
1
1
  import { utils } from 'ethers';
2
2
 
3
+ /**
4
+ * Interface representing a parsed LayerZero error.
5
+ */
3
6
  interface LayerZeroParsedError {
7
+ /**
8
+ * The error message.
9
+ */
4
10
  message: string;
11
+ /**
12
+ * The name of the error.
13
+ */
5
14
  name: string;
15
+ /**
16
+ * The cause of the error.
17
+ */
6
18
  cause: string;
19
+ /**
20
+ * The arguments associated with the error.
21
+ * @see {@link FormattedErrorArg}
22
+ */
7
23
  args: FormattedErrorArg[];
8
24
  }
25
+ /**
26
+ * Type representing the ABI of a contract.
27
+ */
9
28
  type Abi = ConstructorParameters<typeof utils.Interface>[0];
29
+ /**
30
+ * Interface representing a formatted error argument.
31
+ */
10
32
  interface FormattedErrorArg {
33
+ /**
34
+ * The parameter name.
35
+ */
11
36
  param: string | null;
37
+ /**
38
+ * The type of the parameter.
39
+ */
12
40
  type: string;
41
+ /**
42
+ * The value of the parameter.
43
+ */
13
44
  value: string;
14
45
  }
46
+ /**
47
+ * Class representing a LayerZero contract error.
48
+ */
15
49
  declare class LayerZeroContractError extends Error implements Error {
50
+ /**
51
+ * The arguments associated with the error.
52
+ * @see {@link FormattedErrorArg}
53
+ */
16
54
  args: FormattedErrorArg[];
55
+ /**
56
+ * The cause of the error.
57
+ */
17
58
  cause: string;
59
+ /**
60
+ * Creates an instance of LayerZeroContractError.
61
+ * @param message The error message.
62
+ * @param cause The cause of the error.
63
+ * @param args The arguments associated with the error. {@link FormattedErrorArg}
64
+ */
18
65
  constructor(message: string, cause: string, args: FormattedErrorArg[]);
19
66
  }
20
67
  /**
package/dist/index.d.ts CHANGED
@@ -1,20 +1,67 @@
1
1
  import { utils } from 'ethers';
2
2
 
3
+ /**
4
+ * Interface representing a parsed LayerZero error.
5
+ */
3
6
  interface LayerZeroParsedError {
7
+ /**
8
+ * The error message.
9
+ */
4
10
  message: string;
11
+ /**
12
+ * The name of the error.
13
+ */
5
14
  name: string;
15
+ /**
16
+ * The cause of the error.
17
+ */
6
18
  cause: string;
19
+ /**
20
+ * The arguments associated with the error.
21
+ * @see {@link FormattedErrorArg}
22
+ */
7
23
  args: FormattedErrorArg[];
8
24
  }
25
+ /**
26
+ * Type representing the ABI of a contract.
27
+ */
9
28
  type Abi = ConstructorParameters<typeof utils.Interface>[0];
29
+ /**
30
+ * Interface representing a formatted error argument.
31
+ */
10
32
  interface FormattedErrorArg {
33
+ /**
34
+ * The parameter name.
35
+ */
11
36
  param: string | null;
37
+ /**
38
+ * The type of the parameter.
39
+ */
12
40
  type: string;
41
+ /**
42
+ * The value of the parameter.
43
+ */
13
44
  value: string;
14
45
  }
46
+ /**
47
+ * Class representing a LayerZero contract error.
48
+ */
15
49
  declare class LayerZeroContractError extends Error implements Error {
50
+ /**
51
+ * The arguments associated with the error.
52
+ * @see {@link FormattedErrorArg}
53
+ */
16
54
  args: FormattedErrorArg[];
55
+ /**
56
+ * The cause of the error.
57
+ */
17
58
  cause: string;
59
+ /**
60
+ * Creates an instance of LayerZeroContractError.
61
+ * @param message The error message.
62
+ * @param cause The cause of the error.
63
+ * @param args The arguments associated with the error. {@link FormattedErrorArg}
64
+ */
18
65
  constructor(message: string, cause: string, args: FormattedErrorArg[]);
19
66
  }
20
67
  /**
package/dist/index.mjs CHANGED
@@ -2,6 +2,12 @@ import { utils } from 'ethers';
2
2
 
3
3
  // src/error-parser.ts
4
4
  var LayerZeroContractError = class extends Error {
5
+ /**
6
+ * Creates an instance of LayerZeroContractError.
7
+ * @param message The error message.
8
+ * @param cause The cause of the error.
9
+ * @param args The arguments associated with the error. {@link FormattedErrorArg}
10
+ */
5
11
  constructor(message, cause, args) {
6
12
  super(message);
7
13
  this.name = "LayerZeroContractError";
@@ -27,15 +33,13 @@ var LayerZeroErrorParser = class {
27
33
  try {
28
34
  const interf = new utils.Interface(this.abi);
29
35
  const parsed = interf.parseError(data);
30
- if (!parsed)
31
- return null;
36
+ if (!parsed) return null;
32
37
  const { name: cause, args } = parsed;
33
38
  const formattedArgs = [];
34
39
  let message = `${cause}, `;
35
40
  parsed.errorFragment.inputs.forEach(({ name: argName, type }, i) => {
36
41
  formattedArgs.push({ param: argName, type, value: args[i]?.toString() ?? args[i] });
37
- if (argName)
38
- message += `${argName} `;
42
+ if (argName) message += `${argName} `;
39
43
  message += `${args[i]}, `;
40
44
  });
41
45
  return { message: message.slice(0, -2), name: "LayerZeroContractError", cause, args: formattedArgs };
@@ -62,13 +66,12 @@ var LayerZeroErrorParser = class {
62
66
  const error = this.parseContractError(data);
63
67
  if (error) {
64
68
  const lzErr = new LayerZeroContractError(error.message, error.cause, error.args);
65
- if (cleanUpStackTrace)
66
- Error.captureStackTrace(lzErr, cleanUpStackTrace);
69
+ if (cleanUpStackTrace) Error.captureStackTrace(lzErr, cleanUpStackTrace);
67
70
  throw lzErr;
68
71
  }
69
72
  }
70
73
  };
71
74
 
72
75
  export { LayerZeroContractError, LayerZeroErrorParser };
73
- //# sourceMappingURL=out.js.map
76
+ //# sourceMappingURL=index.mjs.map
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EAQO,MAAM,MAAc,mBAAiD;AACxE,UAAM,QAAQ,KAAK,mBAAmB,IAAI;AAC1C,QAAI,OAAO;AACP,YAAM,QAAQ,IAAI,uBAAuB,MAAM,SAAS,MAAM,OAAO,MAAM,IAAI;AAC/E,UAAI;AAAmB,cAAM,kBAAkB,OAAO,iBAAiB;AACvE,YAAM;AAAA,IACV;AAAA,EACJ;AACJ","sourcesContent":["import { utils } from 'ethers'\n\nexport interface LayerZeroParsedError {\n message: string\n name: string\n cause: string\n args: FormattedErrorArg[]\n}\nexport type Abi = ConstructorParameters<typeof utils.Interface>[0]\nexport interface FormattedErrorArg {\n param: string | null\n type: string\n value: string\n}\n\nexport class LayerZeroContractError extends Error implements Error {\n public args: FormattedErrorArg[]\n public cause: string\n constructor(message: string, cause: string, args: FormattedErrorArg[]) {\n super(message)\n this.name = 'LayerZeroContractError'\n this.cause = cause\n this.args = args\n }\n}\n\n/**\n * Class responsible for parsing errors related to LayerZero operations.\n */\nexport class LayerZeroErrorParser {\n /**\n * Creates an instance of LayerZeroErrorParser.\n * @param abi The error abi of the contracts that are interacted with.\n */\n constructor(public abi: Abi) {}\n\n /**\n * Parses a contract error from a given data string.\n * @param data The error data string to parse.\n * @returns The parsed error information or null if parsing fails.\n * @private\n */\n private parseContractError(data: string): LayerZeroParsedError | null {\n try {\n const interf = new utils.Interface(this.abi)\n const parsed = interf.parseError(data)\n if (!parsed) return null\n const { name: cause, args } = parsed\n const formattedArgs: FormattedErrorArg[] = []\n let message = `${cause}, `\n parsed.errorFragment.inputs.forEach(({ name: argName, type }, i) => {\n formattedArgs.push({ param: argName, type, value: args[i]?.toString() ?? args[i] })\n if (argName) message += `${argName} `\n message += `${args[i]}, `\n })\n return { message: message.slice(0, -2), name: 'LayerZeroContractError', cause, args: formattedArgs }\n } catch (error) {\n return null\n }\n }\n\n /**\n * Parses an error from a given data string.\n * @param data The error data string to parse.\n * @returns The parsed error information or null if the error is unrecognized.\n */\n public parse(data: string): LayerZeroParsedError | null {\n const error = this.parseContractError(data)\n // add more error parsers here as needed, for now only contract errors are supported\n return error\n }\n\n /**\n * Checks for a contract error in the given data string, throwing a `LayerZeroContractError` if one is found.\n * @param data The error data string to check.\n * @param cleanUpStackTrace An optional function to clean up the stack. This function and all function above in the stack will be excluded from the trace.\n * @throws {LayerZeroContractError} Throws a LayerZeroContractError if an error is found corresponding to the data string.\n */\n public check(data: string, cleanUpStackTrace?: (...args: any) => any): void {\n const error = this.parseContractError(data)\n if (error) {\n const lzErr = new LayerZeroContractError(error.message, error.cause, error.args)\n if (cleanUpStackTrace) Error.captureStackTrace(lzErr, cleanUpStackTrace)\n throw lzErr\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/error-parser.ts"],"names":[],"mappings":";;;AAmDa,IAAA,sBAAA,GAAN,cAAqC,KAAuB,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgB/D,WAAA,CAAY,OAAiB,EAAA,KAAA,EAAe,IAA2B,EAAA;AACnE,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAO,GAAA,wBAAA;AACZ,IAAA,IAAA,CAAK,KAAQ,GAAA,KAAA;AACb,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;AAAA;AAEpB;AAKO,IAAM,uBAAN,MAA2B;AAAA;AAAA;AAAA;AAAA;AAAA,EAK9B,YAAmB,GAAU,EAAA;AAAV,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAAA;AAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQtB,mBAAmB,IAA2C,EAAA;AAClE,IAAI,IAAA;AACA,MAAA,MAAM,MAAS,GAAA,IAAI,KAAM,CAAA,SAAA,CAAU,KAAK,GAAG,CAAA;AAC3C,MAAM,MAAA,MAAA,GAAS,MAAO,CAAA,UAAA,CAAW,IAAI,CAAA;AACrC,MAAI,IAAA,CAAC,QAAe,OAAA,IAAA;AACpB,MAAA,MAAM,EAAE,IAAA,EAAM,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,KAAA,EAAO,MAAM,IAAI,CAAA;AAC/E,MAAA,IAAI,iBAAmB,EAAA,KAAA,CAAM,iBAAkB,CAAA,KAAA,EAAO,iBAAiB,CAAA;AACvE,MAAM,MAAA,KAAA;AAAA;AACV;AAER","file":"index.mjs","sourcesContent":["import { utils } from 'ethers'\n\n/**\n * Interface representing a parsed LayerZero error.\n */\nexport interface LayerZeroParsedError {\n /**\n * The error message.\n */\n message: string\n /**\n * The name of the error.\n */\n name: string\n /**\n * The cause of the error.\n */\n cause: string\n /**\n * The arguments associated with the error.\n * @see {@link FormattedErrorArg}\n */\n args: FormattedErrorArg[]\n}\n\n/**\n * Type representing the ABI of a contract.\n */\nexport type Abi = ConstructorParameters<typeof utils.Interface>[0]\n\n/**\n * Interface representing a formatted error argument.\n */\nexport interface FormattedErrorArg {\n /**\n * The parameter name.\n */\n param: string | null\n /**\n * The type of the parameter.\n */\n type: string\n /**\n * The value of the parameter.\n */\n value: string\n}\n\n/**\n * Class representing a LayerZero contract error.\n */\nexport class LayerZeroContractError extends Error implements Error {\n /**\n * The arguments associated with the error.\n * @see {@link FormattedErrorArg}\n */\n public args: FormattedErrorArg[]\n /**\n * The cause of the error.\n */\n public cause: string\n /**\n * Creates an instance of LayerZeroContractError.\n * @param message The error message.\n * @param cause The cause of the error.\n * @param args The arguments associated with the error. {@link FormattedErrorArg}\n */\n constructor(message: string, cause: string, args: FormattedErrorArg[]) {\n super(message)\n this.name = 'LayerZeroContractError'\n this.cause = cause\n this.args = args\n }\n}\n\n/**\n * Class responsible for parsing errors related to LayerZero operations.\n */\nexport class LayerZeroErrorParser {\n /**\n * Creates an instance of LayerZeroErrorParser.\n * @param abi The error abi of the contracts that are interacted with.\n */\n constructor(public abi: Abi) {}\n\n /**\n * Parses a contract error from a given data string.\n * @param data The error data string to parse.\n * @returns The parsed error information or null if parsing fails.\n * @private\n */\n private parseContractError(data: string): LayerZeroParsedError | null {\n try {\n const interf = new utils.Interface(this.abi)\n const parsed = interf.parseError(data)\n if (!parsed) return null\n const { name: cause, args } = parsed\n const formattedArgs: FormattedErrorArg[] = []\n let message = `${cause}, `\n parsed.errorFragment.inputs.forEach(({ name: argName, type }, i) => {\n formattedArgs.push({ param: argName, type, value: args[i]?.toString() ?? args[i] })\n if (argName) message += `${argName} `\n message += `${args[i]}, `\n })\n return { message: message.slice(0, -2), name: 'LayerZeroContractError', cause, args: formattedArgs }\n } catch (error) {\n return null\n }\n }\n\n /**\n * Parses an error from a given data string.\n * @param data The error data string to parse.\n * @returns The parsed error information or null if the error is unrecognized.\n */\n public parse(data: string): LayerZeroParsedError | null {\n const error = this.parseContractError(data)\n // add more error parsers here as needed, for now only contract errors are supported\n return error\n }\n\n /**\n * Checks for a contract error in the given data string, throwing a `LayerZeroContractError` if one is found.\n * @param data The error data string to check.\n * @param cleanUpStackTrace An optional function to clean up the stack. This function and all function above in the stack will be excluded from the trace.\n * @throws {LayerZeroContractError} Throws a LayerZeroContractError if an error is found corresponding to the data string.\n */\n public check(data: string, cleanUpStackTrace?: (...args: any) => any): void {\n const error = this.parseContractError(data)\n if (error) {\n const lzErr = new LayerZeroContractError(error.message, error.cause, error.args)\n if (cleanUpStackTrace) Error.captureStackTrace(lzErr, cleanUpStackTrace)\n throw lzErr\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerzerolabs/evm-sdks-core",
3
- "version": "3.0.15",
3
+ "version": "3.0.17",
4
4
  "license": "BUSL-1.1",
5
5
  "exports": {
6
6
  "types": "./dist/index.d.ts",
@@ -23,14 +23,14 @@
23
23
  "ethers": "^5.7.2"
24
24
  },
25
25
  "devDependencies": {
26
- "@layerzerolabs/tsup-config-next": "^3.0.15",
27
- "@layerzerolabs/typescript-config-next": "^3.0.15",
26
+ "@layerzerolabs/tsup-config-next": "^3.0.17",
27
+ "@layerzerolabs/typescript-config-next": "^3.0.17",
28
28
  "@types/jest": "^29.5.10",
29
29
  "@types/node": "^20.10.5",
30
30
  "jest": "^29.7.0",
31
31
  "rimraf": "^5.0.5",
32
32
  "ts-jest": "^29.1.1",
33
- "tsup": "^8.0.1",
33
+ "tsup": "^8.3.5",
34
34
  "typescript": "~5.2.2"
35
35
  },
36
36
  "publishConfig": {