hardhat-external-artifacts 0.0.1

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.
@@ -0,0 +1,113 @@
1
+ import { readJsonFile, getAllFilesMatching, } from '@nomicfoundation/hardhat-utils/fs';
2
+ import path from 'node:path';
3
+ import fs from 'node:fs/promises';
4
+ export class ArtifactLoader {
5
+ #config;
6
+ #projectRoot;
7
+ constructor(config, projectRoot) {
8
+ this.#config = config;
9
+ this.#projectRoot = projectRoot;
10
+ }
11
+ async loadAll() {
12
+ const artifacts = [];
13
+ // Load from paths
14
+ if (this.#config.paths) {
15
+ for (const pathOrGlob of this.#config.paths) {
16
+ const absolutePath = path.resolve(this.#projectRoot, pathOrGlob);
17
+ artifacts.push(...(await this.#loadFromPath(absolutePath)));
18
+ }
19
+ }
20
+ // Load from resolver function
21
+ if (this.#config.resolver) {
22
+ const resolvedArtifacts = await this.#config.resolver();
23
+ artifacts.push(...resolvedArtifacts);
24
+ }
25
+ return artifacts;
26
+ }
27
+ async #loadFromPath(absolutePath) {
28
+ let stat;
29
+ try {
30
+ stat = await fs.stat(absolutePath);
31
+ }
32
+ catch {
33
+ // Path doesn't exist, return empty array
34
+ if (this.#config.warnOnInvalidArtifacts !== false) {
35
+ console.warn(`[hardhat-external-artifacts] Path not found: ${absolutePath}`);
36
+ }
37
+ return [];
38
+ }
39
+ if (stat.isFile()) {
40
+ try {
41
+ return [await this.#loadArtifactFile(absolutePath)];
42
+ }
43
+ catch (error) {
44
+ if (this.#config.warnOnInvalidArtifacts !== false) {
45
+ console.warn(`[hardhat-external-artifacts] Failed to load artifact: ${absolutePath}`, error);
46
+ }
47
+ return [];
48
+ }
49
+ }
50
+ if (stat.isDirectory()) {
51
+ // Support both .json and .ts artifact files
52
+ const files = await getAllFilesMatching(absolutePath, (p) => p.endsWith('.json'));
53
+ const loadedArtifacts = [];
54
+ for (const file of files) {
55
+ try {
56
+ loadedArtifacts.push(await this.#loadArtifactFile(file));
57
+ }
58
+ catch (error) {
59
+ if (this.#config.warnOnInvalidArtifacts !== false) {
60
+ console.warn(`[hardhat-external-artifacts] Failed to load artifact: ${file}`, error);
61
+ }
62
+ }
63
+ }
64
+ return loadedArtifacts;
65
+ }
66
+ return [];
67
+ }
68
+ async #loadArtifactFile(filePath) {
69
+ const content = await readJsonFile(filePath);
70
+ return this.#normalizeArtifact(content, filePath);
71
+ }
72
+ #normalizeArtifact(raw, source) {
73
+ // Validate required fields - only ABI is truly required
74
+ if (!raw.abi || !Array.isArray(raw.abi)) {
75
+ throw new Error(`Artifact from ${source} is missing required field 'abi' or it's not an array`);
76
+ }
77
+ // Infer contractName from filename if not provided
78
+ // e.g., "/path/to/EIP173Proxy.json" -> "EIP173Proxy"
79
+ let contractName = raw.contractName;
80
+ if (!contractName || typeof contractName !== 'string') {
81
+ const filename = path.basename(source, '.json');
82
+ contractName = filename;
83
+ }
84
+ // Infer sourceName from filename if not provided
85
+ // e.g., "EIP173Proxy" -> "external/EIP173Proxy.sol"
86
+ let sourceName = raw.sourceName;
87
+ if (!sourceName || typeof sourceName !== 'string') {
88
+ sourceName = `external/${contractName}.sol`;
89
+ }
90
+ // Base artifact fields - required
91
+ const artifact = {
92
+ contractName,
93
+ sourceName,
94
+ abi: raw.abi,
95
+ bytecode: raw.bytecode ?? '0x',
96
+ deployedBytecode: raw.deployedBytecode ?? '0x',
97
+ linkReferences: raw.linkReferences ?? {},
98
+ deployedLinkReferences: raw.deployedLinkReferences ?? {},
99
+ };
100
+ // Check if this is a "rich" artifact with embedded solcInput
101
+ if (raw.solcInput) {
102
+ // Rich artifact - has full compilation data
103
+ artifact.solcInput = raw.solcInput;
104
+ artifact.metadata = raw.metadata;
105
+ artifact.evm = raw.evm;
106
+ artifact.devdoc = raw.devdoc;
107
+ artifact.userdoc = raw.userdoc;
108
+ artifact.storageLayout = raw.storageLayout;
109
+ }
110
+ return artifact;
111
+ }
112
+ }
113
+ //# sourceMappingURL=loader.js.map
@@ -0,0 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BAAsB,IAAI,EAAE;SACxD,CAAC;QAEF,6DAA6D;QAC7D,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;YACnB,4CAA4C;YAC3C,QAAyB,CAAC,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC;YACpD,QAAyB,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;YAClD,QAAyB,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;YACxC,QAAyB,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;YAC9C,QAAyB,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;YAChD,QAAyB,CAAC,aAAa,GAAG,GAAG,CAAC,aAAa,CAAC;QAC9D,CAAC;QAED,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * A minimal artifact format that can be provided externally.
3
+ * Supports both Hardhat v2 and v3 formats.
4
+ */
5
+ export interface ExternalArtifact {
6
+ /** Contract name */
7
+ contractName: string;
8
+ /** Source file path/identifier */
9
+ sourceName: string;
10
+ /** Contract ABI */
11
+ abi: readonly any[];
12
+ /** Deployment bytecode (0x-prefixed) */
13
+ bytecode: string;
14
+ /** Deployed/runtime bytecode (0x-prefixed) */
15
+ deployedBytecode: string;
16
+ /** Library link references for deployment bytecode */
17
+ linkReferences?: LinkReferences;
18
+ /** Library link references for deployed bytecode */
19
+ deployedLinkReferences?: LinkReferences;
20
+ }
21
+ /**
22
+ * A rich artifact that includes embedded solcInput and full compilation data.
23
+ * This is the format from hardhat-deploy or other tools that preserve
24
+ * the full compilation output.
25
+ */
26
+ export interface RichArtifact extends ExternalArtifact {
27
+ /** The full solc compiler input JSON (stringified) */
28
+ solcInput?: string;
29
+ /** Contract metadata JSON (contains solc version, settings, etc.) */
30
+ metadata?: string;
31
+ /** Full EVM output including generated sources, source maps, etc. */
32
+ evm?: {
33
+ bytecode: {
34
+ object: string;
35
+ opcodes: string;
36
+ sourceMap: string;
37
+ linkReferences: LinkReferences;
38
+ generatedSources?: any[];
39
+ functionDebugData?: Record<string, any>;
40
+ };
41
+ deployedBytecode: {
42
+ object: string;
43
+ opcodes: string;
44
+ sourceMap: string;
45
+ linkReferences: LinkReferences;
46
+ immutableReferences?: Record<string, Array<{
47
+ start: number;
48
+ length: number;
49
+ }>>;
50
+ generatedSources?: any[];
51
+ functionDebugData?: Record<string, any>;
52
+ };
53
+ methodIdentifiers?: Record<string, string>;
54
+ gasEstimates?: any;
55
+ };
56
+ /** Developer documentation */
57
+ devdoc?: any;
58
+ /** User documentation */
59
+ userdoc?: any;
60
+ /** Storage layout */
61
+ storageLayout?: any;
62
+ }
63
+ export interface LinkReferences {
64
+ [sourceName: string]: {
65
+ [libraryName: string]: Array<{
66
+ start: number;
67
+ length: number;
68
+ }>;
69
+ };
70
+ }
71
+ /**
72
+ * Type guard to check if an artifact is a rich artifact
73
+ */
74
+ export declare function isRichArtifact(artifact: ExternalArtifact): artifact is RichArtifact;
75
+ /**
76
+ * Function type for dynamically resolving artifacts
77
+ */
78
+ export type ArtifactResolver = () => Promise<ExternalArtifact[]> | ExternalArtifact[];
79
+ /**
80
+ * Configuration for external artifacts
81
+ */
82
+ export interface ExternalArtifactsConfig {
83
+ /**
84
+ * Paths to artifact files or directories
85
+ * - File path: loads single artifact JSON
86
+ * - Directory path: loads all .json files recursively
87
+ */
88
+ paths?: string[];
89
+ /**
90
+ * Function that resolves and returns artifacts dynamically
91
+ * Useful for loading from APIs, databases, or complex logic
92
+ */
93
+ resolver?: ArtifactResolver;
94
+ /**
95
+ * Solc version to use when creating synthetic compilations
96
+ * @default "0.8.20"
97
+ */
98
+ solcVersion?: string;
99
+ /**
100
+ * Whether to log warnings for malformed artifacts
101
+ * @default true
102
+ */
103
+ warnOnInvalidArtifacts?: boolean;
104
+ /**
105
+ * Enable debug logging to diagnose issues
106
+ * @default false
107
+ */
108
+ debug?: boolean;
109
+ }
110
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 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,CAAC,EAAE,GAAG,EAAE,CAAC;YACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;SACxC,CAAC;QACF,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC3C,YAAY,CAAC,EAAE,GAAG,CAAC;KACnB,CAAC;IAEF,8BAA8B;IAC9B,MAAM,CAAC,EAAE,GAAG,CAAC;IAEb,yBAAyB;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;IAEd,qBAAqB;IACrB,aAAa,CAAC,EAAE,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC9B,CAAC,UAAU,EAAE,MAAM,GAAG;QACrB,CAAC,WAAW,EAAE,MAAM,GAAG,KAAK,CAAC;YAAC,KAAK,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAC,CAAC,CAAC;KAC9D,CAAC;CACF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC7B,QAAQ,EAAE,gBAAgB,GACxB,QAAQ,IAAI,YAAY,CAE1B;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAC5B,OAAO,CAAC,gBAAgB,EAAE,CAAC,GAC3B,gBAAgB,EAAE,CAAC;AAEtB;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACvC;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IAEjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAE5B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Type guard to check if an artifact is a rich artifact
3
+ */
4
+ export function isRichArtifact(artifact) {
5
+ return 'solcInput' in artifact && artifact.solcInput !== undefined;
6
+ }
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/artifacts/types.ts"],"names":[],"mappings":"AAiFA;;GAEG;AACH,MAAM,UAAU,cAAc,CAC7B,QAA0B;IAE1B,OAAO,WAAW,IAAI,QAAQ,IAAI,QAAQ,CAAC,SAAS,KAAK,SAAS,CAAC;AACpE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { ConfigHooks } from 'hardhat/types/hooks';
2
+ declare const _default: () => Promise<Partial<ConfigHooks>>;
3
+ export default _default;
4
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/hooks/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAC;8BAG5B,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AAAtD,wBAuCE"}
@@ -0,0 +1,23 @@
1
+ export default async () => {
2
+ const handlers = {
3
+ resolveUserConfig: async (userConfig, resolveConfigurationVariable, next) => {
4
+ const resolvedConfig = await next(userConfig, resolveConfigurationVariable);
5
+ // Get user's external artifacts config
6
+ const externalArtifactsUserConfig = userConfig.externalArtifacts;
7
+ // Apply defaults
8
+ const externalArtifacts = {
9
+ paths: externalArtifactsUserConfig?.paths ?? [],
10
+ resolver: externalArtifactsUserConfig?.resolver,
11
+ solcVersion: externalArtifactsUserConfig?.solcVersion ?? '0.8.20',
12
+ warnOnInvalidArtifacts: externalArtifactsUserConfig?.warnOnInvalidArtifacts ?? true,
13
+ debug: externalArtifactsUserConfig?.debug ?? false,
14
+ };
15
+ return {
16
+ ...resolvedConfig,
17
+ externalArtifacts,
18
+ };
19
+ },
20
+ };
21
+ return handlers;
22
+ };
23
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/hooks/config.ts"],"names":[],"mappings":"AAGA,eAAe,KAAK,IAAmC,EAAE;IACxD,MAAM,QAAQ,GAAyB;QACtC,iBAAiB,EAAE,KAAK,EACvB,UAAU,EACV,4BAA4B,EAC5B,IAAI,EACH,EAAE;YACH,MAAM,cAAc,GAAG,MAAM,IAAI,CAChC,UAAU,EACV,4BAA4B,CAC5B,CAAC;YAEF,uCAAuC;YACvC,MAAM,2BAA2B,GAAG,UAAU,CAAC,iBAEnC,CAAC;YAEb,iBAAiB;YACjB,MAAM,iBAAiB,GAInB;gBACH,KAAK,EAAE,2BAA2B,EAAE,KAAK,IAAI,EAAE;gBAC/C,QAAQ,EAAE,2BAA2B,EAAE,QAAQ;gBAC/C,WAAW,EAAE,2BAA2B,EAAE,WAAW,IAAI,QAAQ;gBACjE,sBAAsB,EACrB,2BAA2B,EAAE,sBAAsB,IAAI,IAAI;gBAC5D,KAAK,EAAE,2BAA2B,EAAE,KAAK,IAAI,KAAK;aAClD,CAAC;YAEF,OAAO;gBACN,GAAG,cAAc;gBACjB,iBAAiB;aACjB,CAAC;QACH,CAAC;KACD,CAAC;IAEF,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { NetworkHooks } from 'hardhat/types/hooks';
2
+ declare const _default: () => Promise<Partial<NetworkHooks>>;
3
+ export default _default;
4
+ //# sourceMappingURL=network.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/hooks/network.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAc,MAAM,qBAAqB,CAAC;8BAS1C,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AAAvD,wBAsHE"}
@@ -0,0 +1,87 @@
1
+ import { ArtifactLoader } from '../artifacts/loader.js';
2
+ import { artifactsToCompilations, } from '../artifacts/converter.js';
3
+ import { isRichArtifact } from '../artifacts/types.js';
4
+ export default async () => {
5
+ const handlers = {
6
+ newConnection: async (context, next) => {
7
+ // Call the default behavior first to create the connection
8
+ const connection = await next(context);
9
+ // Only inject artifacts for EDR networks (hardhat network)
10
+ if (connection.networkConfig.type !== 'edr-simulated') {
11
+ return connection;
12
+ }
13
+ const config = context.config.externalArtifacts;
14
+ // Check if config exists and there's anything to load
15
+ if (!config || (!config.paths?.length && !config.resolver)) {
16
+ return connection;
17
+ }
18
+ const debug = config.debug ?? false;
19
+ const log = debug ? console.log.bind(console) : () => { };
20
+ try {
21
+ // Load external artifacts
22
+ const loader = new ArtifactLoader(config, context.config.paths.root);
23
+ const artifacts = await loader.loadAll();
24
+ if (artifacts.length === 0) {
25
+ log('[hardhat-external-artifacts] No artifacts found');
26
+ return connection;
27
+ }
28
+ log(`[hardhat-external-artifacts] Loaded ${artifacts.length} artifact(s):`);
29
+ for (const artifact of artifacts) {
30
+ const isRich = isRichArtifact(artifact);
31
+ const deployedBytecodeLength = artifact.deployedBytecode?.length || 0;
32
+ log(` - ${artifact.sourceName}:${artifact.contractName} (${isRich ? 'rich' : 'simple'}, deployedBytecode: ${deployedBytecodeLength} chars)`);
33
+ }
34
+ // Convert to compilation format(s)
35
+ // Rich artifacts with solcInput get their own compilations
36
+ // Simple artifacts get grouped into a synthetic compilation
37
+ const compilations = artifactsToCompilations(artifacts, config.solcVersion);
38
+ log(`[hardhat-external-artifacts] Created ${compilations.length} compilation(s)`);
39
+ // Add to the EDR provider - use type assertion since addCompilationResult is an internal method
40
+ const provider = connection.provider;
41
+ if (typeof provider.addCompilationResult === 'function') {
42
+ for (const compilation of compilations) {
43
+ logCompilation(compilation, log);
44
+ // Ensure clean JSON serialization for the native EDR binding
45
+ // by round-tripping through JSON stringify/parse
46
+ const cleanInput = JSON.parse(JSON.stringify(compilation.compilerInput));
47
+ const cleanOutput = JSON.parse(JSON.stringify(compilation.compilerOutput));
48
+ log(`[hardhat-external-artifacts] Calling addCompilationResult with solcVersion: ${compilation.solcVersion}`);
49
+ await provider.addCompilationResult(compilation.solcVersion, cleanInput, cleanOutput);
50
+ log(`[hardhat-external-artifacts] Successfully added compilation to EDR provider`);
51
+ }
52
+ console.log(`[hardhat-external-artifacts] Loaded ${artifacts.length} external artifact(s) in ${compilations.length} compilation(s)`);
53
+ }
54
+ else {
55
+ console.warn(`[hardhat-external-artifacts] Warning: provider.addCompilationResult is not available. ` +
56
+ `This might indicate an incompatible Hardhat version.`);
57
+ }
58
+ }
59
+ catch (error) {
60
+ if (config.warnOnInvalidArtifacts !== false) {
61
+ console.warn(`[hardhat-external-artifacts] Warning: Failed to load external artifacts:`, error);
62
+ }
63
+ }
64
+ return connection;
65
+ },
66
+ };
67
+ return handlers;
68
+ };
69
+ function logCompilation(compilation, log) {
70
+ log(`[hardhat-external-artifacts] Compilation details:`);
71
+ log(` solcVersion: ${compilation.solcVersion}`);
72
+ log(` sources in compilerInput: ${Object.keys(compilation.compilerInput.sources).join(', ')}`);
73
+ log(` sources in compilerOutput: ${Object.keys(compilation.compilerOutput.sources).join(', ')}`);
74
+ for (const [sourceName, contracts] of Object.entries(compilation.compilerOutput.contracts || {})) {
75
+ for (const [contractName, contract] of Object.entries(contracts)) {
76
+ const deployedBytecodeLength = contract.evm?.deployedBytecode?.object?.length || 0;
77
+ const methodCount = Object.keys(contract.evm?.methodIdentifiers || {}).length;
78
+ log(` ${sourceName}:${contractName} - deployedBytecode: ${deployedBytecodeLength} chars (${Math.floor(deployedBytecodeLength / 2)} bytes), methods: ${methodCount}`);
79
+ // Log first 100 chars of bytecode for verification
80
+ if (deployedBytecodeLength > 0) {
81
+ const preview = contract.evm.deployedBytecode.object.substring(0, 100);
82
+ log(` bytecode preview: ${preview}...`);
83
+ }
84
+ }
85
+ }
86
+ }
87
+ //# sourceMappingURL=network.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/hooks/network.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,cAAc,EAAC,MAAM,wBAAwB,CAAC;AACtD,OAAO,EACN,uBAAuB,GAEvB,MA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MAAM,IAAI,CAAC,CAAC;YACrD,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAC9B,QAAQ,CAAC,GAAG,EAAE,iBAAiB,IAAI,EAAE,CACrC,CAAC,MAAM,CAAC;YACT,GAAG,CACF,KAAK,UAAU,IAAI,YAAY,wBAAwB,sBAAsB,WAAW,IAAI,CAAC,KAAK,CAAC,sBAAsB,GAAG,CAAC,CAAC,qBAAqB,WAAW,EAAE,CAChK,CAAC;YACF,mDAAmD;YACnD,IAAI,sBAAsB,GAAG,CAAC,EAAE,CAAC;gBAChC,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;gBACvE,GAAG,CAAC,yBAAyB,OAAO,KAAK,CAAC,CAAC;YAC5C,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { HardhatPlugin } from 'hardhat/types/plugins';
2
+ import './type-extensions.js';
3
+ declare const hardhatExternalArtifactsPlugin: HardhatPlugin;
4
+ export default hardhatExternalArtifactsPlugin;
5
+ export * from './artifacts/types.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AAGzD,OAAO,sBAAsB,CAAC;AAE9B,QAAA,MAAM,8BAA8B,EAAE,aAMrC,CAAC;AAEF,eAAe,8BAA8B,CAAC;AAC9C,cAAc,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ // Import type extensions
2
+ import './type-extensions.js';
3
+ const hardhatExternalArtifactsPlugin = {
4
+ id: 'hardhat-external-artifacts',
5
+ hookHandlers: {
6
+ config: () => import('./hooks/config.js'),
7
+ network: () => import('./hooks/network.js'),
8
+ },
9
+ };
10
+ export default hardhatExternalArtifactsPlugin;
11
+ export * from './artifacts/types.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,yBAAyB;AACzB,OAAO,sBAAsB,CAAC;AAE9B,MAAM,8BAA8B,GAAkB;IACrD,EAAE,EAAE,4BAA4B;IAChC,YAAY,EAAE;QACb,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC;QACzC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC;KAC3C;CACD,CAAC;AAEF,eAAe,8BAA8B,CAAC;AAC9C,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import "hardhat/types/config";
2
+ import type { ExternalArtifactsConfig } from "./artifacts/types.js";
3
+ /**
4
+ * Resolved external artifacts configuration with defaults applied.
5
+ */
6
+ export type ResolvedExternalArtifactsConfig = Required<Omit<ExternalArtifactsConfig, "resolver">> & {
7
+ resolver?: ExternalArtifactsConfig["resolver"];
8
+ };
9
+ declare module "hardhat/types/config" {
10
+ interface HardhatUserConfig {
11
+ externalArtifacts?: ExternalArtifactsConfig;
12
+ }
13
+ interface HardhatConfig {
14
+ externalArtifacts?: ResolvedExternalArtifactsConfig;
15
+ }
16
+ }
17
+ //# sourceMappingURL=type-extensions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-extensions.d.ts","sourceRoot":"","sources":["../src/type-extensions.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAEpE;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAAE,UAAU,CAAC,CAAC,GAAG;IAClG,QAAQ,CAAC,EAAE,uBAAuB,CAAC,UAAU,CAAC,CAAC;CAChD,CAAC;AAEF,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAU,iBAAiB;QACzB,iBAAiB,CAAC,EAAE,uBAAuB,CAAC;KAC7C;IAED,UAAU,aAAa;QACrB,iBAAiB,CAAC,EAAE,+BAA+B,CAAC;KACrD;CACF"}
@@ -0,0 +1,2 @@
1
+ import "hardhat/types/config";
2
+ //# sourceMappingURL=type-extensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-extensions.js","sourceRoot":"","sources":["../src/type-extensions.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "hardhat-external-artifacts",
3
+ "version": "0.0.1",
4
+ "description": "Hardhat plugin that allow hardhat to know about them",
5
+ "keywords": [
6
+ "hardhat",
7
+ "ethereum",
8
+ "solidity"
9
+ ],
10
+ "author": "Ronan Sandford",
11
+ "license": "MIT",
12
+ "homepage": "https://github.com/wighawag/hardhat-external-artifacts#readme",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/wighawag/hardhat-external-artifacts.git"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/wighawag/hardhat-external-artifacts/issues"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "type": "module",
24
+ "main": "dist/index.js",
25
+ "module": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "import": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ }
33
+ }
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "src"
38
+ ],
39
+ "engines": {
40
+ "node": ">=22.0.0"
41
+ },
42
+ "devDependencies": {
43
+ "@changesets/cli": "^2.29.8",
44
+ "@rocketh/node": "^0.19.3",
45
+ "@types/node": "^25.2.3",
46
+ "as-soon": "^0.1.5",
47
+ "hardhat": "3.1.8",
48
+ "prettier": "^3.8.1",
49
+ "rimraf": "^6.1.3",
50
+ "set-defaults": "^0.0.5",
51
+ "typescript": "^5.9.3"
52
+ },
53
+ "peerDependencies": {
54
+ "hardhat": "^3.1.8"
55
+ },
56
+ "dependencies": {
57
+ "@nomicfoundation/hardhat-utils": "^4.0.0",
58
+ "named-logs": "^0.4.1",
59
+ "viem": "^2.0.0"
60
+ },
61
+ "scripts": {
62
+ "build": "tsc --project tsconfig.json",
63
+ "dev": "as-soon -w src pnpm build"
64
+ }
65
+ }