-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhardhat.config.ts
More file actions
84 lines (79 loc) · 3.07 KB
/
hardhat.config.ts
File metadata and controls
84 lines (79 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Hardhat 3 config. Compiler aligned with foundry.toml.
* For public deployment: copy env.deployment.example to .env.deployment and set DEPLOY_*.
*
* Optional — Hardhat deployment (e.g. deploy:hardhat, deploy:hardhat:foundation):
* npm install --save-dev @nomicfoundation/hardhat-toolbox-viem
* Install the toolbox only when you need live deployment; the core library stays clean without it.
*/
import "dotenv/config";
import { config as loadDeploymentEnv } from "dotenv";
import path from "path";
import { fileURLToPath } from "url";
import { createRequire } from "module";
import { defineConfig, type HardhatUserConfig } from "hardhat/config";
const require = createRequire(import.meta.url);
let hardhatToolboxViem: NonNullable<HardhatUserConfig["plugins"]>[number] | null = null;
let hardhatEthers: NonNullable<HardhatUserConfig["plugins"]>[number] | null = null;
try {
const m = require("@nomicfoundation/hardhat-toolbox-viem");
hardhatToolboxViem = (m?.default !== undefined ? m.default : m) as NonNullable<HardhatUserConfig["plugins"]>[number];
} catch {
// Toolbox not installed; install with: npm install --save-dev @nomicfoundation/hardhat-toolbox-viem
}
try {
const m = require("@nomicfoundation/hardhat-ethers");
hardhatEthers = (m?.default !== undefined ? m.default : m) as NonNullable<HardhatUserConfig["plugins"]>[number];
} catch {
// For blox deploy with library linking: npm install --save-dev @nomicfoundation/hardhat-ethers ethers
}
const __dirname = path.dirname(fileURLToPath(import.meta.url));
loadDeploymentEnv({ path: path.join(__dirname, ".env.deployment") });
const DEPLOY_RPC = process.env.DEPLOY_RPC_URL;
const DEPLOY_PK = process.env.DEPLOY_PRIVATE_KEY;
const rawChainId = process.env.DEPLOY_CHAIN_ID;
const chainId = (rawChainId != null && String(rawChainId).trim() !== "")
? parseInt(String(rawChainId).trim(), 10)
: 11155111;
if (Number.isNaN(chainId) || chainId <= 0) {
throw new Error(`Invalid DEPLOY_CHAIN_ID: "${rawChainId}". Must be a positive integer.`);
}
const deployNetworkName = process.env.DEPLOY_NETWORK_NAME?.trim();
// Compiler settings aligned with foundry.toml: solc 0.8.34, optimizer 200, via_ir, evm osaka
const SOLIDITY_VERSION = "0.8.34";
const OPTIMIZER_RUNS = 200;
const EVM_VERSION = "osaka";
export default defineConfig({
plugins: [hardhatToolboxViem, hardhatEthers].filter(Boolean) as HardhatUserConfig["plugins"],
paths: {
sources: "./contracts",
tests: "./test",
cache: "./cache",
artifacts: "./artifacts",
},
solidity: {
version: SOLIDITY_VERSION,
settings: {
optimizer: { enabled: true, runs: OPTIMIZER_RUNS },
viaIR: true,
evmVersion: EVM_VERSION,
},
},
networks: {
hardhat: {
type: "edr-simulated",
chainType: "l1",
},
...(DEPLOY_RPC && DEPLOY_PK && deployNetworkName
? {
[deployNetworkName]: {
type: "http" as const,
chainType: "l1" as const,
url: DEPLOY_RPC,
chainId,
accounts: [DEPLOY_PK.startsWith("0x") ? DEPLOY_PK : `0x${DEPLOY_PK}`],
},
}
: {}),
},
});