hardhat-deploy 2.0.0-next.7 → 2.0.0-next.70

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.
Files changed (124) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +120 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +197 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/config/default.d.ts.map +1 -0
  8. package/dist/config/default.js +5 -0
  9. package/dist/config/default.js.map +1 -0
  10. package/dist/config/get-config.d.ts.map +1 -0
  11. package/dist/config/get-config.js +9 -0
  12. package/dist/config/get-config.js.map +1 -0
  13. package/dist/config/validation.d.ts.map +1 -0
  14. package/dist/config/validation.js +17 -0
  15. package/dist/config/validation.js.map +1 -0
  16. package/dist/generate-types.d.ts +5 -0
  17. package/dist/generate-types.d.ts.map +1 -0
  18. package/dist/generate-types.js +244 -0
  19. package/dist/generate-types.js.map +1 -0
  20. package/dist/helpers.d.ts +34 -0
  21. package/dist/helpers.d.ts.map +1 -0
  22. package/dist/{esm/helpers.js → helpers.js} +106 -73
  23. package/dist/helpers.js.map +1 -0
  24. package/dist/hook-handlers/config.d.ts.map +1 -0
  25. package/dist/hook-handlers/config.js +68 -0
  26. package/dist/hook-handlers/config.js.map +1 -0
  27. package/dist/hook-handlers/solidity.d.ts.map +1 -0
  28. package/dist/hook-handlers/solidity.js +21 -0
  29. package/dist/hook-handlers/solidity.js.map +1 -0
  30. package/dist/index.d.ts +8 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/{esm/index.js → index.js} +20 -3
  33. package/dist/index.js.map +1 -0
  34. package/dist/postinstall.d.ts +3 -0
  35. package/dist/postinstall.d.ts.map +1 -0
  36. package/dist/postinstall.js +148 -0
  37. package/dist/postinstall.js.map +1 -0
  38. package/dist/{esm/tasks → tasks}/deploy.d.ts +1 -0
  39. package/dist/tasks/deploy.d.ts.map +1 -0
  40. package/dist/tasks/deploy.js +32 -0
  41. package/dist/tasks/deploy.js.map +1 -0
  42. package/dist/{esm/type-extensions.d.ts → type-extensions.d.ts} +2 -2
  43. package/dist/type-extensions.d.ts.map +1 -0
  44. package/dist/type-extensions.js.map +1 -0
  45. package/dist/types.d.ts +13 -0
  46. package/dist/types.d.ts.map +1 -0
  47. package/dist/types.js.map +1 -0
  48. package/dist/utils/files.d.ts +9 -0
  49. package/dist/utils/files.d.ts.map +1 -0
  50. package/dist/utils/files.js +25 -0
  51. package/dist/utils/files.js.map +1 -0
  52. package/dist/v1-detection.d.ts +12 -0
  53. package/dist/v1-detection.d.ts.map +1 -0
  54. package/dist/v1-detection.js +118 -0
  55. package/dist/v1-detection.js.map +1 -0
  56. package/dist/v1-entry.cjs +92 -0
  57. package/package.json +58 -26
  58. package/src/cli.ts +246 -0
  59. package/src/config/default.ts +6 -0
  60. package/src/config/get-config.ts +12 -0
  61. package/src/config/validation.ts +25 -0
  62. package/src/generate-types.ts +281 -0
  63. package/src/helpers.ts +311 -0
  64. package/src/hook-handlers/config.ts +80 -0
  65. package/src/hook-handlers/solidity.ts +33 -0
  66. package/src/index.ts +53 -0
  67. package/src/postinstall.ts +166 -0
  68. package/src/tasks/deploy.ts +43 -0
  69. package/src/type-extensions.ts +12 -0
  70. package/src/types.ts +9 -0
  71. package/src/utils/files.ts +37 -0
  72. package/src/v1-entry.cjs +92 -0
  73. package/templates/basic/README.md +44 -0
  74. package/templates/basic/contracts/Counter.sol +19 -0
  75. package/templates/basic/contracts/Counter.t.sol +29 -0
  76. package/templates/basic/deploy/01_deploy_counter.ts +13 -0
  77. package/templates/basic/hardhat.config.ts +50 -0
  78. package/templates/basic/package.json +31 -0
  79. package/templates/basic/pnpm-lock.yaml +1643 -0
  80. package/templates/basic/rocketh/config.ts +65 -0
  81. package/templates/basic/rocketh/deploy.ts +20 -0
  82. package/templates/basic/rocketh/environment.ts +22 -0
  83. package/templates/basic/test/Counter.ts +61 -0
  84. package/templates/basic/tsconfig.json +13 -0
  85. package/dist/esm/config/default.d.ts.map +0 -1
  86. package/dist/esm/config/default.js +0 -8
  87. package/dist/esm/config/default.js.map +0 -1
  88. package/dist/esm/config/get-config.d.ts.map +0 -1
  89. package/dist/esm/config/get-config.js +0 -8
  90. package/dist/esm/config/get-config.js.map +0 -1
  91. package/dist/esm/config/validation.d.ts.map +0 -1
  92. package/dist/esm/config/validation.js +0 -16
  93. package/dist/esm/config/validation.js.map +0 -1
  94. package/dist/esm/generate-types.d.ts +0 -6
  95. package/dist/esm/generate-types.d.ts.map +0 -1
  96. package/dist/esm/generate-types.js +0 -198
  97. package/dist/esm/generate-types.js.map +0 -1
  98. package/dist/esm/helpers.d.ts +0 -18
  99. package/dist/esm/helpers.d.ts.map +0 -1
  100. package/dist/esm/helpers.js.map +0 -1
  101. package/dist/esm/hook-handlers/config.d.ts.map +0 -1
  102. package/dist/esm/hook-handlers/config.js +0 -16
  103. package/dist/esm/hook-handlers/config.js.map +0 -1
  104. package/dist/esm/hook-handlers/solidity.d.ts.map +0 -1
  105. package/dist/esm/hook-handlers/solidity.js +0 -15
  106. package/dist/esm/hook-handlers/solidity.js.map +0 -1
  107. package/dist/esm/index.d.ts +0 -5
  108. package/dist/esm/index.d.ts.map +0 -1
  109. package/dist/esm/index.js.map +0 -1
  110. package/dist/esm/tasks/deploy.d.ts.map +0 -1
  111. package/dist/esm/tasks/deploy.js +0 -21
  112. package/dist/esm/tasks/deploy.js.map +0 -1
  113. package/dist/esm/type-extensions.d.ts.map +0 -1
  114. package/dist/esm/type-extensions.js.map +0 -1
  115. package/dist/esm/types.d.ts +0 -15
  116. package/dist/esm/types.d.ts.map +0 -1
  117. package/dist/esm/types.js.map +0 -1
  118. /package/dist/{esm/config → config}/default.d.ts +0 -0
  119. /package/dist/{esm/config → config}/get-config.d.ts +0 -0
  120. /package/dist/{esm/config → config}/validation.d.ts +0 -0
  121. /package/dist/{esm/hook-handlers → hook-handlers}/config.d.ts +0 -0
  122. /package/dist/{esm/hook-handlers → hook-handlers}/solidity.d.ts +0 -0
  123. /package/dist/{esm/type-extensions.js → type-extensions.js} +0 -0
  124. /package/dist/{esm/types.js → types.js} +0 -0
package/src/types.ts ADDED
@@ -0,0 +1,9 @@
1
+ export type ArtifactGenerationUserConfig = {
2
+ // externalArtifacts?: string[];
3
+ destinations?: {mode?: 'javascript' | 'typescript'; folder?: string}[];
4
+ };
5
+
6
+ export type ArtifactGenerationConfig = {
7
+ // externalArtifacts: string[];
8
+ destinations: {mode: 'javascript' | 'typescript'; folder: string}[];
9
+ };
@@ -0,0 +1,37 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ export type FileTraversed = {
5
+ name: string;
6
+ path: string;
7
+ relativePath: string;
8
+ mtimeMs: number;
9
+ directory: boolean;
10
+ };
11
+
12
+ export function traverse(
13
+ dir: string,
14
+ result: any[] = [],
15
+ topDir?: string,
16
+ filter?: (name: string, stats: any) => boolean // TODO any is Stats
17
+ ): Array<FileTraversed> {
18
+ fs.readdirSync(dir).forEach((name) => {
19
+ const fPath = path.resolve(dir, name);
20
+ const stats = fs.statSync(fPath);
21
+ if ((!filter && !name.startsWith('.')) || (filter && filter(name, stats))) {
22
+ const fileStats = {
23
+ name,
24
+ path: fPath,
25
+ relativePath: path.relative(topDir || dir, fPath),
26
+ mtimeMs: stats.mtimeMs,
27
+ directory: stats.isDirectory(),
28
+ };
29
+ if (fileStats.directory) {
30
+ result.push(fileStats);
31
+ return traverse(fPath, result, topDir || dir, filter);
32
+ }
33
+ result.push(fileStats);
34
+ }
35
+ });
36
+ return result;
37
+ }
@@ -0,0 +1,92 @@
1
+ // This file serves as a CommonJS entry point for hardhat v2
2
+ // It detects v1 users and shows them a migration message
3
+
4
+ const MIGRATION_URL = 'https://rocketh.dev/hardhat-deploy/documentation/how-to/migration-from-v1.html';
5
+ const V1_INSTALL_CMD = 'npm install hardhat-deploy@1';
6
+
7
+ function getHardhatVersion() {
8
+ try {
9
+ const {execSync} = require('child_process');
10
+ // Run hardhat --version to get the version
11
+ const output = execSync('hardhat --version', {encoding: 'utf-8', stdio: 'pipe'});
12
+ return output.trim();
13
+ } catch (e) {
14
+ console.error(e);
15
+ return 'unknown';
16
+ }
17
+ }
18
+
19
+ function detectV1Patterns() {
20
+ const fs = require('fs');
21
+ const path = require('path');
22
+ const reasons = [];
23
+
24
+ // Check hardhat.config for v1 patterns
25
+ const configFiles = ['hardhat.config.js', 'hardhat.config.cjs', 'hardhat.config.ts'];
26
+
27
+ for (const configFile of configFiles) {
28
+ const configPath = path.join(process.cwd(), configFile);
29
+ if (fs.existsSync(configPath)) {
30
+ try {
31
+ const content = fs.readFileSync(configPath, 'utf-8');
32
+
33
+ if (content.includes('namedAccounts')) {
34
+ reasons.push(`Found 'namedAccounts' in ${configFile} - this is a v1 pattern`);
35
+ }
36
+
37
+ if (content.includes("require('hardhat-deploy')") || content.includes('require("hardhat-deploy")')) {
38
+ reasons.push(
39
+ `Found require('hardhat-deploy') in ${configFile} - v2 uses ESM: import HardhatDeploy from 'hardhat-deploy'`,
40
+ );
41
+ }
42
+
43
+ if (content.includes('module.exports')) {
44
+ reasons.push(`Found 'module.exports' in ${configFile} - v2 uses ESM: export default defineConfig({...})`);
45
+ }
46
+ } catch (e) {
47
+ // Failed to read config - continue
48
+ }
49
+ }
50
+ }
51
+
52
+ return reasons;
53
+ }
54
+
55
+ function throwV1Error() {
56
+ const hardhatVersion = getHardhatVersion();
57
+ const reasons = detectV1Patterns();
58
+
59
+ let reasonsList = '';
60
+ if (reasons.length > 0) {
61
+ reasonsList = '\nYour project uses hardhat-deploy v1 patterns:\n\n' + reasons.map((r) => ` • ${r}`).join('\n');
62
+ }
63
+
64
+ throw new Error(`
65
+ ╔══════════════════════════════════════════════════════════════════════════════╗
66
+ ║ HARDHAT-DEPLOY V2 - INCOMPATIBLE WITH HARDHAT V2 ║
67
+ ╚══════════════════════════════════════════════════════════════════════════════╝
68
+
69
+ hardhat-deploy v2 requires hardhat 3.x, but you are using hardhat ${hardhatVersion}.${reasonsList}
70
+
71
+ hardhat-deploy v2 has MAJOR breaking changes and uses ESM modules.
72
+
73
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
74
+
75
+ OPTION 1: Install hardhat-deploy v1 (recommended for hardhat v2 projects)
76
+
77
+ npm uninstall hardhat-deploy
78
+ ${V1_INSTALL_CMD}
79
+
80
+ OPTION 2: Upgrade to hardhat 3.x and hardhat-deploy v2
81
+
82
+ Migration guide: ${MIGRATION_URL}
83
+
84
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
85
+ `);
86
+ }
87
+
88
+ // Throw error immediately when loaded by hardhat v2
89
+ throwV1Error();
90
+
91
+ // Export a dummy function to satisfy hardhat's plugin loading
92
+ module.exports = function () {};
@@ -0,0 +1,44 @@
1
+ # Sample Hardhat 3 Project (`node:test`)
2
+
3
+ This project showcases a Hardhat 3 project using the [hardhat-deploy](https://github.com/wighawag/hardhat-deploy) plugin (along with the [rocketh](https://github.com/wighawag/rocketh) deployment system) and the native Node.js test runner (`node:test`) .
4
+
5
+ To learn more about hardhat-deploy and rocketh, please visit the [documentation](https://rocketh.dev).
6
+
7
+ ## Project Overview
8
+
9
+ This example project includes:
10
+
11
+ - A simple Hardhat configuration file.
12
+ - Foundry-compatible Solidity unit tests.
13
+ - Built-in mechanism to load deployments in test via hardhat-deploy and rocketh.
14
+
15
+ ## Usage
16
+
17
+ ### Running Tests
18
+
19
+ To run all the tests in the project, execute the following command:
20
+
21
+ ```bash
22
+ pnpm hardhat test
23
+ ```
24
+
25
+ You can also selectively run the Solidity or `node:test` tests:
26
+
27
+ ```bash
28
+ pnpm hardhat test solidity
29
+ pnpm hardhat test nodejs
30
+ ```
31
+
32
+ ### Deploying Contracts
33
+
34
+ To deploy the contracts to an in-memory network, run:
35
+
36
+ ```bash
37
+ pnpm hardhat deploy
38
+ ```
39
+
40
+ To deploy the contracts to a specific network, use the `--network` option:
41
+
42
+ ```bash
43
+ pnpm hardhat deploy --network <network-name>
44
+ ```
@@ -0,0 +1,19 @@
1
+ // SPDX-License-Identifier: UNLICENSED
2
+ pragma solidity ^0.8.28;
3
+
4
+ contract Counter {
5
+ uint public x;
6
+
7
+ event Increment(uint by);
8
+
9
+ function inc() public {
10
+ x++;
11
+ emit Increment(1);
12
+ }
13
+
14
+ function incBy(uint by) public {
15
+ require(by > 0, "incBy: increment should be positive");
16
+ x += by;
17
+ emit Increment(by);
18
+ }
19
+ }
@@ -0,0 +1,29 @@
1
+ // SPDX-License-Identifier: UNLICENSED
2
+ pragma solidity ^0.8.28;
3
+
4
+ import {Counter} from "./Counter.sol";
5
+ import {Test} from "forge-std/Test.sol";
6
+
7
+ contract CounterTest is Test {
8
+ Counter counter;
9
+
10
+ function setUp() public {
11
+ counter = new Counter();
12
+ }
13
+
14
+ function test_InitialValue() public view {
15
+ require(counter.x() == 0, "Initial value should be 0");
16
+ }
17
+
18
+ function testFuzz_Inc(uint8 x) public {
19
+ for (uint8 i = 0; i < x; i++) {
20
+ counter.inc();
21
+ }
22
+ require(counter.x() == x, "Value after calling inc x times should be x");
23
+ }
24
+
25
+ function test_IncByZero() public {
26
+ vm.expectRevert();
27
+ counter.incBy(0);
28
+ }
29
+ }
@@ -0,0 +1,13 @@
1
+ import { deployScript, artifacts } from "../rocketh/deploy.js";
2
+
3
+ export default deployScript(
4
+ async ({ deploy, namedAccounts }) => {
5
+ const { deployer } = namedAccounts;
6
+
7
+ await deploy("Counter", {
8
+ account: deployer,
9
+ artifact: artifacts.Counter,
10
+ });
11
+ },
12
+ { tags: ["Counter", "Counter_deploy"] },
13
+ );
@@ -0,0 +1,50 @@
1
+ import { configVariable, defineConfig } from "hardhat/config";
2
+ import hardhatNodeTestRunnerPlugin from "@nomicfoundation/hardhat-node-test-runner";
3
+ import hardhatKeyStorePlugin from "@nomicfoundation/hardhat-keystore";
4
+ import hardhatNetworkHelpersPlugin from "@nomicfoundation/hardhat-network-helpers";
5
+ import hardhatViemPlugin from "@nomicfoundation/hardhat-viem";
6
+ import hardhatViemAssertionsPlugin from "@nomicfoundation/hardhat-viem-assertions";
7
+ import HardhatDeploy from "hardhat-deploy";
8
+
9
+ export default defineConfig({
10
+ plugins: [
11
+ hardhatNodeTestRunnerPlugin,
12
+ hardhatKeyStorePlugin,
13
+ hardhatNetworkHelpersPlugin,
14
+ HardhatDeploy,
15
+ hardhatViemPlugin,
16
+ hardhatViemAssertionsPlugin
17
+ ],
18
+ solidity: {
19
+ profiles: {
20
+ default: {
21
+ version: "0.8.28",
22
+ },
23
+ production: {
24
+ version: "0.8.28",
25
+ settings: {
26
+ optimizer: {
27
+ enabled: true,
28
+ runs: 200,
29
+ },
30
+ },
31
+ },
32
+ },
33
+ },
34
+ networks: {
35
+ hardhatMainnet: {
36
+ type: "edr-simulated",
37
+ chainType: "l1",
38
+ },
39
+ hardhatOp: {
40
+ type: "edr-simulated",
41
+ chainType: "op",
42
+ },
43
+ sepolia: {
44
+ type: "http",
45
+ chainType: "l1",
46
+ url: configVariable("SEPOLIA_RPC_URL"),
47
+ accounts: [configVariable("SEPOLIA_PRIVATE_KEY")],
48
+ },
49
+ },
50
+ });
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "template-hardhat-node-test-runner",
3
+ "version": "0.0.0",
4
+ "description": "A TypeScript Hardhat project using Node Test Runner",
5
+ "type": "module",
6
+ "devDependencies": {
7
+ "@nomicfoundation/hardhat-keystore": "^3.0.3",
8
+ "@nomicfoundation/hardhat-network-helpers": "^3.0.3",
9
+ "@nomicfoundation/hardhat-node-test-runner": "^3.0.8",
10
+ "@nomicfoundation/hardhat-viem": "^3.0.2",
11
+ "@nomicfoundation/hardhat-viem-assertions": "^3.0.5",
12
+ "@rocketh/deploy": "^0.17.9",
13
+ "@rocketh/doc": "^0.17.18",
14
+ "@rocketh/export": "^0.17.18",
15
+ "@rocketh/node": "^0.17.18",
16
+ "@rocketh/proxy": "^0.17.13",
17
+ "@rocketh/read-execute": "^0.17.9",
18
+ "@rocketh/verifier": "^0.17.18",
19
+ "@rocketh/viem": "^0.17.6",
20
+ "@types/node": "^25.0.10",
21
+ "forge-std": "foundry-rs/forge-std#v1.9.4",
22
+ "hardhat": "^3.1.5",
23
+ "hardhat-deploy": "workspace:*",
24
+ "rocketh": "^0.17.14",
25
+ "typescript": "~5.9.3",
26
+ "viem": "^2.43.0"
27
+ },
28
+ "scripts": {
29
+ "test": "hardhat test"
30
+ }
31
+ }