@layerzerolabs/evm-sdks-build 2.1.2

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.cjs ADDED
@@ -0,0 +1,111 @@
1
+ 'use strict';
2
+
3
+ var promises = require('fs/promises');
4
+ var module$1 = require('module');
5
+ var path2 = require('path');
6
+ var glob = require('glob');
7
+ var ethers = require('ethers');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var path2__default = /*#__PURE__*/_interopDefault(path2);
12
+
13
+ // src/populate.ts
14
+ async function populate(copyTargets, callerRootFile) {
15
+ const callerRootDir = path2__default.default.dirname(callerRootFile);
16
+ for (const [srcPackage, srcFiles] of Object.entries(copyTargets)) {
17
+ const srcDir = path2__default.default.dirname(module$1.createRequire(callerRootFile).resolve(`${srcPackage}/package.json`));
18
+ for (const [filePath, patterns] of Object.entries(srcFiles)) {
19
+ const files = await glob.glob(patterns.map((p) => path2__default.default.join(srcDir, filePath, p)));
20
+ let count = 0;
21
+ for (const file of files) {
22
+ const relativePath = path2__default.default.relative(srcDir, file);
23
+ const destPath = path2__default.default.join(callerRootDir, relativePath);
24
+ await promises.mkdir(path2__default.default.dirname(destPath), { recursive: true });
25
+ await promises.copyFile(file, destPath);
26
+ count++;
27
+ }
28
+ console.log(`Copied ${count} ${filePath} from ${srcPackage}`);
29
+ }
30
+ }
31
+ }
32
+
33
+ // src/semaphore.ts
34
+ var Semaphore = class {
35
+ constructor(max) {
36
+ this.max = max;
37
+ this.counter = 0;
38
+ this.queue = [];
39
+ }
40
+ /**
41
+ * Acquires a lock on the semaphore. If the semaphore is at its maximum,
42
+ * the function will wait until it can acquire the lock.
43
+ * @returns A promise that resolves when the lock has been acquired.
44
+ */
45
+ async acquire() {
46
+ if (this.counter >= this.max) {
47
+ await new Promise((resolve) => this.queue.push(resolve));
48
+ }
49
+ this.counter++;
50
+ }
51
+ /**
52
+ * Releases a lock on the semaphore.
53
+ */
54
+ release() {
55
+ if (this.counter == 0)
56
+ return;
57
+ this.counter--;
58
+ const resolve = this.queue.shift() ?? (() => null);
59
+ resolve();
60
+ }
61
+ };
62
+
63
+ // src/errors.ts
64
+ var { ErrorFragment, FormatTypes, Interface } = ethers.utils;
65
+ async function readJSONFile(filePath) {
66
+ const data = await promises.readFile(filePath, { encoding: "utf8" });
67
+ return JSON.parse(data);
68
+ }
69
+ async function parallelProcess(filePath, semaphore, errors) {
70
+ await semaphore.acquire();
71
+ try {
72
+ const { abi } = await readJSONFile(filePath);
73
+ if (!abi || !Array.isArray(abi))
74
+ return;
75
+ abi.filter(({ type }) => type === "error").forEach((obj) => {
76
+ const frag = ErrorFragment.from(obj);
77
+ errors.full.add(frag.format(FormatTypes.full));
78
+ errors.selector[Interface.getSighash(frag)] = frag.format(FormatTypes.sighash);
79
+ });
80
+ } finally {
81
+ semaphore.release();
82
+ }
83
+ }
84
+ async function populateErrors(callerRootFile, destPath = "src/errors", maxConcurrent = 50) {
85
+ const callerRootDir = path2__default.default.dirname(callerRootFile);
86
+ const callerArtifactsPath = path2__default.default.join(callerRootDir, "artifacts");
87
+ const files = await promises.readdir(callerArtifactsPath, { recursive: true });
88
+ const jsonFiles = files.filter((file) => path2__default.default.extname(file).toLowerCase() === ".json");
89
+ const semaphore = new Semaphore(maxConcurrent);
90
+ const errors = { full: /* @__PURE__ */ new Set(), selector: {} };
91
+ const filePromises = jsonFiles.map(
92
+ (file) => parallelProcess(path2__default.default.join(callerArtifactsPath, file), semaphore, errors)
93
+ );
94
+ await Promise.all(filePromises);
95
+ const { full, selector } = errors;
96
+ let sorter = new Intl.Collator("en", { caseFirst: "upper", numeric: true });
97
+ const sortedErrors = [...full].sort(sorter.compare);
98
+ sorter = new Intl.Collator("en", { caseFirst: "upper", numeric: false });
99
+ const sortedSelectors = Object.fromEntries(Object.entries(selector).sort(([a], [b]) => sorter.compare(a, b)));
100
+ const errorDir = path2__default.default.join(callerRootDir, destPath);
101
+ await promises.mkdir(errorDir, { recursive: true });
102
+ await promises.writeFile(path2__default.default.join(errorDir, "errors.json"), JSON.stringify(sortedErrors, null, 2));
103
+ console.log(`Generated abi for ${sortedErrors.length} errors`);
104
+ await promises.writeFile(path2__default.default.join(errorDir, "errorSelectors.json"), JSON.stringify(sortedSelectors, null, 2));
105
+ }
106
+
107
+ exports.Semaphore = Semaphore;
108
+ exports.populate = populate;
109
+ exports.populateErrors = populateErrors;
110
+ //# sourceMappingURL=out.js.map
111
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/populate.ts","../src/errors.ts","../src/semaphore.ts"],"names":["mkdir","path"],"mappings":";AAAA,SAAS,UAAU,aAAa;AAChC,SAAS,qBAAqB;AAC9B,OAAO,UAAU;AAEjB,SAAS,YAAY;AAMrB,eAAsB,SAAS,aAA0B,gBAAwB;AAC7E,QAAM,gBAAgB,KAAK,QAAQ,cAAc;AACjD,aAAW,CAAC,YAAY,QAAQ,KAAK,OAAO,QAAQ,WAAW,GAAG;AAC9D,UAAM,SAAS,KAAK,QAAQ,cAAc,cAAc,EAAE,QAAQ,GAAG,UAAU,eAAe,CAAC;AAC/F,eAAW,CAAC,UAAU,QAAQ,KAAK,OAAO,QAAQ,QAAQ,GAAG;AACzD,YAAM,QAAQ,MAAM,KAAK,SAAS,IAAI,CAAC,MAAM,KAAK,KAAK,QAAQ,UAAU,CAAC,CAAC,CAAC;AAC5E,UAAI,QAAQ;AACZ,iBAAW,QAAQ,OAAO;AACtB,cAAM,eAAe,KAAK,SAAS,QAAQ,IAAI;AAC/C,cAAM,WAAW,KAAK,KAAK,eAAe,YAAY;AACtD,cAAM,MAAM,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;AACvD,cAAM,SAAS,MAAM,QAAQ;AAC7B;AAAA,MACJ;AACA,cAAQ,IAAI,UAAU,KAAK,IAAI,QAAQ,SAAS,UAAU,EAAE;AAAA,IAChE;AAAA,EACJ;AACJ;;;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AC,CAAC;AACxG","sourcesContent":["import { copyFile, mkdir } from 'fs/promises'\nimport { createRequire } from 'module'\nimport path from 'path'\n\nimport { glob } from 'glob'\n\ntype AllowedFiles = 'artifacts' | 'deployments'\nexport type SrcFiles = { [key in AllowedFiles]?: readonly string[] }\nexport type CopyTargets = Record<string, SrcFiles>\n\nexport async function populate(copyTargets: CopyTargets, callerRootFile: string) {\n const callerRootDir = path.dirname(callerRootFile)\n for (const [srcPackage, srcFiles] of Object.entries(copyTargets)) {\n const srcDir = path.dirname(createRequire(callerRootFile).resolve(`${srcPackage}/package.json`))\n for (const [filePath, patterns] of Object.entries(srcFiles)) {\n const files = await glob(patterns.map((p) => path.join(srcDir, filePath, p)))\n let count = 0\n for (const file of files) {\n const relativePath = path.relative(srcDir, file)\n const destPath = path.join(callerRootDir, relativePath)\n await mkdir(path.dirname(destPath), { recursive: true })\n await copyFile(file, destPath)\n count++\n }\n console.log(`Copied ${count} ${filePath} from ${srcPackage}`)\n }\n }\n}\n","import { mkdir, readFile, readdir, writeFile } from 'fs/promises'\nimport path from 'path'\n\nimport { utils } from 'ethers'\n\nimport { Semaphore } from './semaphore'\n\nconst { ErrorFragment, FormatTypes, Interface } = utils\n\n/**\n * Asynchronously reads a JSON file from a given file path.\n * @param filePath - The path to the JSON file.\n * @returns A promise that resolves to the parsed JSON data.\n */\nasync function readJSONFile(filePath: string) {\n const data = await readFile(filePath, { encoding: 'utf8' })\n return JSON.parse(data)\n}\n\n/**\n * Processes ABI errors in parallel, controlled by a semaphore, and populates error collections.\n * @param filePath - The file path to read.\n * @param semaphore - Semaphore instance for concurrency control.\n * @param errors - Object to collect full errors and error selectors.\n */\nasync function parallelProcess(\n filePath: string,\n semaphore: Semaphore,\n errors: { full: Set<string>; selector: Record<string, string> }\n) {\n await semaphore.acquire()\n try {\n const { abi } = await readJSONFile(filePath)\n if (!abi || !Array.isArray(abi)) return\n abi.filter(({ type }) => type === 'error').forEach((obj) => {\n const frag = ErrorFragment.from(obj)\n errors.full.add(frag.format(FormatTypes.full))\n errors.selector[Interface.getSighash(frag)] = frag.format(FormatTypes.sighash)\n })\n } finally {\n semaphore.release()\n }\n}\n\n/**\n * Populates error information from ABI files in parallel.\n * @param callerRootFile - The root file path to start the search for ABI files.\n * @param destPath - The path relative to root to copy the files in.\n * @param maxConcurrent - Maximum number of concurrent file processing operations.\n */\nexport async function populateErrors(callerRootFile: string, destPath = 'src/errors', maxConcurrent = 50) {\n // Determining the directory paths from the caller's root file\n const callerRootDir = path.dirname(callerRootFile)\n const callerArtifactsPath = path.join(callerRootDir, 'artifacts')\n\n // Reading and filtering artifacts to process only JSON files\n const files = await readdir(callerArtifactsPath, { recursive: true })\n const jsonFiles = files.filter((file) => path.extname(file).toLowerCase() === '.json')\n\n const semaphore = new Semaphore(maxConcurrent)\n const errors = { full: new Set<string>(), selector: {} }\n\n // Parallel processing of files using the semaphore for concurrency control\n const filePromises = jsonFiles.map((file) =>\n parallelProcess(path.join(callerArtifactsPath, file), semaphore, errors)\n )\n await Promise.all(filePromises)\n\n // Sorting and organizing errors for output\n const { full, selector } = errors\n let sorter = new Intl.Collator('en', { caseFirst: 'upper', numeric: true })\n const sortedErrors = [...full].sort(sorter.compare)\n sorter = new Intl.Collator('en', { caseFirst: 'upper', numeric: false })\n const sortedSelectors = Object.fromEntries(Object.entries(selector).sort(([a], [b]) => sorter.compare(a, b)))\n const errorDir = path.join(callerRootDir, destPath)\n // Writing errors to files in the error directory\n await mkdir(errorDir, { recursive: true })\n await writeFile(path.join(errorDir, 'errors.json'), JSON.stringify(sortedErrors, null, 2))\n console.log(`Generated abi for ${sortedErrors.length} errors`)\n await writeFile(path.join(errorDir, 'errorSelectors.json'), JSON.stringify(sortedSelectors, null, 2))\n}\n","/**\n * Semaphore class for controlling access to a resource by multiple processes.\n * It maintains a counter and a queue for managing access.\n */\nexport class Semaphore {\n private counter = 0\n private queue: (() => void)[] = []\n constructor(private max: number) {}\n\n /**\n * Acquires a lock on the semaphore. If the semaphore is at its maximum,\n * the function will wait until it can acquire the lock.\n * @returns A promise that resolves when the lock has been acquired.\n */\n public async acquire(): Promise<void> {\n if (this.counter >= this.max) {\n await new Promise<void>((resolve) => this.queue.push(resolve))\n }\n this.counter++\n }\n\n /**\n * Releases a lock on the semaphore.\n */\n public release(): void {\n if (this.counter == 0) return\n this.counter--\n const resolve = this.queue.shift() ?? (() => null)\n resolve()\n }\n}\n"]}
@@ -0,0 +1,37 @@
1
+ type AllowedFiles = 'artifacts' | 'deployments';
2
+ type SrcFiles = {
3
+ [key in AllowedFiles]?: readonly string[];
4
+ };
5
+ type CopyTargets = Record<string, SrcFiles>;
6
+ declare function populate(copyTargets: CopyTargets, callerRootFile: string): Promise<void>;
7
+
8
+ /**
9
+ * Populates error information from ABI files in parallel.
10
+ * @param callerRootFile - The root file path to start the search for ABI files.
11
+ * @param destPath - The path relative to root to copy the files in.
12
+ * @param maxConcurrent - Maximum number of concurrent file processing operations.
13
+ */
14
+ declare function populateErrors(callerRootFile: string, destPath?: string, maxConcurrent?: number): Promise<void>;
15
+
16
+ /**
17
+ * Semaphore class for controlling access to a resource by multiple processes.
18
+ * It maintains a counter and a queue for managing access.
19
+ */
20
+ declare class Semaphore {
21
+ private max;
22
+ private counter;
23
+ private queue;
24
+ constructor(max: number);
25
+ /**
26
+ * Acquires a lock on the semaphore. If the semaphore is at its maximum,
27
+ * the function will wait until it can acquire the lock.
28
+ * @returns A promise that resolves when the lock has been acquired.
29
+ */
30
+ acquire(): Promise<void>;
31
+ /**
32
+ * Releases a lock on the semaphore.
33
+ */
34
+ release(): void;
35
+ }
36
+
37
+ export { type CopyTargets, Semaphore, type SrcFiles, populate, populateErrors };
@@ -0,0 +1,37 @@
1
+ type AllowedFiles = 'artifacts' | 'deployments';
2
+ type SrcFiles = {
3
+ [key in AllowedFiles]?: readonly string[];
4
+ };
5
+ type CopyTargets = Record<string, SrcFiles>;
6
+ declare function populate(copyTargets: CopyTargets, callerRootFile: string): Promise<void>;
7
+
8
+ /**
9
+ * Populates error information from ABI files in parallel.
10
+ * @param callerRootFile - The root file path to start the search for ABI files.
11
+ * @param destPath - The path relative to root to copy the files in.
12
+ * @param maxConcurrent - Maximum number of concurrent file processing operations.
13
+ */
14
+ declare function populateErrors(callerRootFile: string, destPath?: string, maxConcurrent?: number): Promise<void>;
15
+
16
+ /**
17
+ * Semaphore class for controlling access to a resource by multiple processes.
18
+ * It maintains a counter and a queue for managing access.
19
+ */
20
+ declare class Semaphore {
21
+ private max;
22
+ private counter;
23
+ private queue;
24
+ constructor(max: number);
25
+ /**
26
+ * Acquires a lock on the semaphore. If the semaphore is at its maximum,
27
+ * the function will wait until it can acquire the lock.
28
+ * @returns A promise that resolves when the lock has been acquired.
29
+ */
30
+ acquire(): Promise<void>;
31
+ /**
32
+ * Releases a lock on the semaphore.
33
+ */
34
+ release(): void;
35
+ }
36
+
37
+ export { type CopyTargets, Semaphore, type SrcFiles, populate, populateErrors };
package/dist/index.mjs ADDED
@@ -0,0 +1,103 @@
1
+ import { mkdir, copyFile, readdir, writeFile, readFile } from 'fs/promises';
2
+ import { createRequire } from 'module';
3
+ import path2 from 'path';
4
+ import { glob } from 'glob';
5
+ import { utils } from 'ethers';
6
+
7
+ // src/populate.ts
8
+ async function populate(copyTargets, callerRootFile) {
9
+ const callerRootDir = path2.dirname(callerRootFile);
10
+ for (const [srcPackage, srcFiles] of Object.entries(copyTargets)) {
11
+ const srcDir = path2.dirname(createRequire(callerRootFile).resolve(`${srcPackage}/package.json`));
12
+ for (const [filePath, patterns] of Object.entries(srcFiles)) {
13
+ const files = await glob(patterns.map((p) => path2.join(srcDir, filePath, p)));
14
+ let count = 0;
15
+ for (const file of files) {
16
+ const relativePath = path2.relative(srcDir, file);
17
+ const destPath = path2.join(callerRootDir, relativePath);
18
+ await mkdir(path2.dirname(destPath), { recursive: true });
19
+ await copyFile(file, destPath);
20
+ count++;
21
+ }
22
+ console.log(`Copied ${count} ${filePath} from ${srcPackage}`);
23
+ }
24
+ }
25
+ }
26
+
27
+ // src/semaphore.ts
28
+ var Semaphore = class {
29
+ constructor(max) {
30
+ this.max = max;
31
+ this.counter = 0;
32
+ this.queue = [];
33
+ }
34
+ /**
35
+ * Acquires a lock on the semaphore. If the semaphore is at its maximum,
36
+ * the function will wait until it can acquire the lock.
37
+ * @returns A promise that resolves when the lock has been acquired.
38
+ */
39
+ async acquire() {
40
+ if (this.counter >= this.max) {
41
+ await new Promise((resolve) => this.queue.push(resolve));
42
+ }
43
+ this.counter++;
44
+ }
45
+ /**
46
+ * Releases a lock on the semaphore.
47
+ */
48
+ release() {
49
+ if (this.counter == 0)
50
+ return;
51
+ this.counter--;
52
+ const resolve = this.queue.shift() ?? (() => null);
53
+ resolve();
54
+ }
55
+ };
56
+
57
+ // src/errors.ts
58
+ var { ErrorFragment, FormatTypes, Interface } = utils;
59
+ async function readJSONFile(filePath) {
60
+ const data = await readFile(filePath, { encoding: "utf8" });
61
+ return JSON.parse(data);
62
+ }
63
+ async function parallelProcess(filePath, semaphore, errors) {
64
+ await semaphore.acquire();
65
+ try {
66
+ const { abi } = await readJSONFile(filePath);
67
+ if (!abi || !Array.isArray(abi))
68
+ return;
69
+ abi.filter(({ type }) => type === "error").forEach((obj) => {
70
+ const frag = ErrorFragment.from(obj);
71
+ errors.full.add(frag.format(FormatTypes.full));
72
+ errors.selector[Interface.getSighash(frag)] = frag.format(FormatTypes.sighash);
73
+ });
74
+ } finally {
75
+ semaphore.release();
76
+ }
77
+ }
78
+ async function populateErrors(callerRootFile, destPath = "src/errors", maxConcurrent = 50) {
79
+ const callerRootDir = path2.dirname(callerRootFile);
80
+ const callerArtifactsPath = path2.join(callerRootDir, "artifacts");
81
+ const files = await readdir(callerArtifactsPath, { recursive: true });
82
+ const jsonFiles = files.filter((file) => path2.extname(file).toLowerCase() === ".json");
83
+ const semaphore = new Semaphore(maxConcurrent);
84
+ const errors = { full: /* @__PURE__ */ new Set(), selector: {} };
85
+ const filePromises = jsonFiles.map(
86
+ (file) => parallelProcess(path2.join(callerArtifactsPath, file), semaphore, errors)
87
+ );
88
+ await Promise.all(filePromises);
89
+ const { full, selector } = errors;
90
+ let sorter = new Intl.Collator("en", { caseFirst: "upper", numeric: true });
91
+ const sortedErrors = [...full].sort(sorter.compare);
92
+ sorter = new Intl.Collator("en", { caseFirst: "upper", numeric: false });
93
+ const sortedSelectors = Object.fromEntries(Object.entries(selector).sort(([a], [b]) => sorter.compare(a, b)));
94
+ const errorDir = path2.join(callerRootDir, destPath);
95
+ await mkdir(errorDir, { recursive: true });
96
+ await writeFile(path2.join(errorDir, "errors.json"), JSON.stringify(sortedErrors, null, 2));
97
+ console.log(`Generated abi for ${sortedErrors.length} errors`);
98
+ await writeFile(path2.join(errorDir, "errorSelectors.json"), JSON.stringify(sortedSelectors, null, 2));
99
+ }
100
+
101
+ export { Semaphore, populate, populateErrors };
102
+ //# sourceMappingURL=out.js.map
103
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/populate.ts","../src/errors.ts","../src/semaphore.ts"],"names":["mkdir","path"],"mappings":";AAAA,SAAS,UAAU,aAAa;AAChC,SAAS,qBAAqB;AAC9B,OAAO,UAAU;AAEjB,SAAS,YAAY;AAMrB,eAAsB,SAAS,aAA0B,gBAAwB;AAC7E,QAAM,gBAAgB,KAAK,QAAQ,cAAc;AACjD,aAAW,CAAC,YAAY,QAAQ,KAAK,OAAO,QAAQ,WAAW,GAAG;AAC9D,UAAM,SAAS,KAAK,QAAQ,cAAc,cAAc,EAAE,QAAQ,GAAG,UAAU,eAAe,CAAC;AAC/F,eAAW,CAAC,UAAU,QAAQ,KAAK,OAAO,QAAQ,QAAQ,GAAG;AACzD,YAAM,QAAQ,MAAM,KAAK,SAAS,IAAI,CAAC,MAAM,KAAK,KAAK,QAAQ,UAAU,CAAC,CAAC,CAAC;AAC5E,UAAI,QAAQ;AACZ,iBAAW,QAAQ,OAAO;AACtB,cAAM,eAAe,KAAK,SAAS,QAAQ,IAAI;AAC/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D,OAAM,UAAU,EAAE,WAAW,KAAK,CAAC;AACzC,QAAM,UAAUC,MAAK,KAAK,UAAU,aAAa,GAAG,KAAK,UAAU,cAAc,MAAM,CAAC,CAAC;AACzF,UAAQ,IAAI,qBAAqB,aAAa,MAAM,SAAS;AAC7D,QAAM,UAAUA,MAAK,KAAK,UAAU,qBAAqB,GAAG,KAAK,UAAU,iBAAiB,MAAM,CAAC,CAAC;AACxG","sourcesContent":["import { copyFile, mkdir } from 'fs/promises'\nimport { createRequire } from 'module'\nimport path from 'path'\n\nimport { glob } from 'glob'\n\ntype AllowedFiles = 'artifacts' | 'deployments'\nexport type SrcFiles = { [key in AllowedFiles]?: readonly string[] }\nexport type CopyTargets = Record<string, SrcFiles>\n\nexport async function populate(copyTargets: CopyTargets, callerRootFile: string) {\n const callerRootDir = path.dirname(callerRootFile)\n for (const [srcPackage, srcFiles] of Object.entries(copyTargets)) {\n const srcDir = path.dirname(createRequire(callerRootFile).resolve(`${srcPackage}/package.json`))\n for (const [filePath, patterns] of Object.entries(srcFiles)) {\n const files = await glob(patterns.map((p) => path.join(srcDir, filePath, p)))\n let count = 0\n for (const file of files) {\n const relativePath = path.relative(srcDir, file)\n const destPath = path.join(callerRootDir, relativePath)\n await mkdir(path.dirname(destPath), { recursive: true })\n await copyFile(file, destPath)\n count++\n }\n console.log(`Copied ${count} ${filePath} from ${srcPackage}`)\n }\n }\n}\n","import { mkdir, readFile, readdir, writeFile } from 'fs/promises'\nimport path from 'path'\n\nimport { utils } from 'ethers'\n\nimport { Semaphore } from './semaphore'\n\nconst { ErrorFragment, FormatTypes, Interface } = utils\n\n/**\n * Asynchronously reads a JSON file from a given file path.\n * @param filePath - The path to the JSON file.\n * @returns A promise that resolves to the parsed JSON data.\n */\nasync function readJSONFile(filePath: string) {\n const data = await readFile(filePath, { encoding: 'utf8' })\n return JSON.parse(data)\n}\n\n/**\n * Processes ABI errors in parallel, controlled by a semaphore, and populates error collections.\n * @param filePath - The file path to read.\n * @param semaphore - Semaphore instance for concurrency control.\n * @param errors - Object to collect full errors and error selectors.\n */\nasync function parallelProcess(\n filePath: string,\n semaphore: Semaphore,\n errors: { full: Set<string>; selector: Record<string, string> }\n) {\n await semaphore.acquire()\n try {\n const { abi } = await readJSONFile(filePath)\n if (!abi || !Array.isArray(abi)) return\n abi.filter(({ type }) => type === 'error').forEach((obj) => {\n const frag = ErrorFragment.from(obj)\n errors.full.add(frag.format(FormatTypes.full))\n errors.selector[Interface.getSighash(frag)] = frag.format(FormatTypes.sighash)\n })\n } finally {\n semaphore.release()\n }\n}\n\n/**\n * Populates error information from ABI files in parallel.\n * @param callerRootFile - The root file path to start the search for ABI files.\n * @param destPath - The path relative to root to copy the files in.\n * @param maxConcurrent - Maximum number of concurrent file processing operations.\n */\nexport async function populateErrors(callerRootFile: string, destPath = 'src/errors', maxConcurrent = 50) {\n // Determining the directory paths from the caller's root file\n const callerRootDir = path.dirname(callerRootFile)\n const callerArtifactsPath = path.join(callerRootDir, 'artifacts')\n\n // Reading and filtering artifacts to process only JSON files\n const files = await readdir(callerArtifactsPath, { recursive: true })\n const jsonFiles = files.filter((file) => path.extname(file).toLowerCase() === '.json')\n\n const semaphore = new Semaphore(maxConcurrent)\n const errors = { full: new Set<string>(), selector: {} }\n\n // Parallel processing of files using the semaphore for concurrency control\n const filePromises = jsonFiles.map((file) =>\n parallelProcess(path.join(callerArtifactsPath, file), semaphore, errors)\n )\n await Promise.all(filePromises)\n\n // Sorting and organizing errors for output\n const { full, selector } = errors\n let sorter = new Intl.Collator('en', { caseFirst: 'upper', numeric: true })\n const sortedErrors = [...full].sort(sorter.compare)\n sorter = new Intl.Collator('en', { caseFirst: 'upper', numeric: false })\n const sortedSelectors = Object.fromEntries(Object.entries(selector).sort(([a], [b]) => sorter.compare(a, b)))\n const errorDir = path.join(callerRootDir, destPath)\n // Writing errors to files in the error directory\n await mkdir(errorDir, { recursive: true })\n await writeFile(path.join(errorDir, 'errors.json'), JSON.stringify(sortedErrors, null, 2))\n console.log(`Generated abi for ${sortedErrors.length} errors`)\n await writeFile(path.join(errorDir, 'errorSelectors.json'), JSON.stringify(sortedSelectors, null, 2))\n}\n","/**\n * Semaphore class for controlling access to a resource by multiple processes.\n * It maintains a counter and a queue for managing access.\n */\nexport class Semaphore {\n private counter = 0\n private queue: (() => void)[] = []\n constructor(private max: number) {}\n\n /**\n * Acquires a lock on the semaphore. If the semaphore is at its maximum,\n * the function will wait until it can acquire the lock.\n * @returns A promise that resolves when the lock has been acquired.\n */\n public async acquire(): Promise<void> {\n if (this.counter >= this.max) {\n await new Promise<void>((resolve) => this.queue.push(resolve))\n }\n this.counter++\n }\n\n /**\n * Releases a lock on the semaphore.\n */\n public release(): void {\n if (this.counter == 0) return\n this.counter--\n const resolve = this.queue.shift() ?? (() => null)\n resolve()\n }\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@layerzerolabs/evm-sdks-build",
3
+ "version": "2.1.2",
4
+ "license": "BUSL-1.1",
5
+ "exports": {
6
+ "types": "./dist/index.d.ts",
7
+ "import": "./dist/index.mjs",
8
+ "require": "./dist/index.cjs",
9
+ "default": "./dist/index.cjs"
10
+ },
11
+ "main": "./dist/index.cjs",
12
+ "types": "./dist/index.d.ts",
13
+ "files": [
14
+ "dist/**/*"
15
+ ],
16
+ "scripts": {
17
+ "build": "$npm_execpath clean-prebuild && $npm_execpath tsup",
18
+ "clean": "$npm_execpath clean-prebuild && rimraf .turbo",
19
+ "clean-prebuild": "rimraf dist"
20
+ },
21
+ "dependencies": {
22
+ "ethers": "^5.7.2",
23
+ "glob": "^10.3.10"
24
+ },
25
+ "devDependencies": {
26
+ "@layerzerolabs/tsup-config-next": "^2.1.2",
27
+ "@layerzerolabs/typescript-config-next": "^2.1.2",
28
+ "@types/glob": "^8.1.0",
29
+ "@types/node": "^20.10.5",
30
+ "rimraf": "^5.0.5",
31
+ "tsup": "^8.0.1",
32
+ "typescript": "~5.2.2"
33
+ },
34
+ "engines": {
35
+ "node": ">=18.19.0"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ }
40
+ }