This repository has been archived by the owner on Jan 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
hardhat.config.ts
182 lines (152 loc) · 5.74 KB
/
hardhat.config.ts
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import { HardhatUserConfig, task } from "hardhat/config";
import '@typechain/hardhat';
import "hardhat-storage-layout-changes";
import "@nomicfoundation/hardhat-foundry";
import "@nomiclabs/hardhat-ethers";
import "hardhat-deploy";
import "hardhat-contract-sizer";
import dotenv from "dotenv";
import fs from "fs";
import { HardhatRuntimeEnvironment } from "hardhat/types";
dotenv.config();
const lazyImport = async (module: any) => {
return await import(module);
};
async function saveDeployments(env: string, deploymentData: { [key in string]: string }, branch?: string) {
const deploymentsJsonPath = `${process.cwd()}/deployments.json`;
let deploymentsJson = { [env]: {} };
if (fs.existsSync(deploymentsJsonPath)) {
deploymentsJson = JSON.parse(fs.readFileSync(deploymentsJsonPath).toString());
}
if (branch) {
deploymentsJson[env] = { ...deploymentsJson[env], [branch]: deploymentData }
} else {
deploymentsJson[env] = { ...deploymentsJson[env], ...deploymentData }
}
fs.writeFileSync(deploymentsJsonPath, JSON.stringify(deploymentsJson));
}
async function getDeployments(env: string): Promise<{ [key in string]: string }> {
const deploymentsJsonPath = `${process.cwd()}/deployments.json`;
let deployments = {};
if (fs.existsSync(deploymentsJsonPath)) {
deployments = JSON.parse(fs.readFileSync(deploymentsJsonPath).toString())[env];
}
return deployments;
}
task('deploy-libraries', 'Build and deploys all libraries on the selected network', async (args, hre: HardhatRuntimeEnvironment) => {
const { deploy } = await lazyImport('./scripts/deploy-libraries');
const libsDeployment = await deploy();
console.log(libsDeployment);
await saveDeployments(hre.network.name, libsDeployment, 'libs');
});
task('deploy-gateway', 'Builds and deploys the Gateway contract on the selected network', async (args, hre: HardhatRuntimeEnvironment) => {
const network = hre.network.name;
const deployments = await getDeployments(network);
const { deploy } = await lazyImport('./scripts/deploy-gateway');
const gatewayDeployment = await deploy(deployments.libs);
console.log(gatewayDeployment);
await saveDeployments(network, gatewayDeployment);
});
task('deploy-subnet', 'Builds and deploys the SubnetActor contract on the selected network', async (args, hre: HardhatRuntimeEnvironment) => {
const network = hre.network.name;
const deployments = await getDeployments(network);
const { deploy } = await lazyImport('./scripts/deploy-subnet');
// remove unused lib
delete deployments.libs["StorableMsgHelper"];
const subnetDeployment = await deploy(deployments.Gateway, deployments.libs);
console.log(subnetDeployment);
await saveDeployments(network, subnetDeployment);
});
task('deploy-gw-diamond-and-facets', 'Builds and deploys Gateway Actor diamond and its facets', async (args, hre: HardhatRuntimeEnvironment) => {
const network = hre.network.name;
const deployments = await getDeployments(network);
const { deployDiamond } = await lazyImport('./scripts/deploy-gw-diamond');
const gatewayActorDiamond = await deployDiamond(deployments.libs);
console.log(gatewayActorDiamond);
await saveDeployments(network, gatewayActorDiamond);
});
task('deploy-sa-diamond-and-facets', 'Builds and deploys Subnet Actor diamond and its facets', async (args, hre: HardhatRuntimeEnvironment) => {
const network = hre.network.name;
const deployments = await getDeployments(network);
const { deployDiamond } = await lazyImport('./scripts/deploy-sa-diamond');
const subnetActorDiamond = await deployDiamond(deployments.GatewayActorDiamond, deployments.libs);
console.log(subnetActorDiamond);
await saveDeployments(network, subnetActorDiamond);
});
task('deploy', 'Builds and deploys all contracts on the selected network', async (args, hre: HardhatRuntimeEnvironment) => {
await hre.run('compile');
await hre.run('deploy-libraries');
await hre.run('deploy-gateway');
});
task('deploy-gw-diamond', 'Builds and deploys Gateway Actor diamond', async (args, hre: HardhatRuntimeEnvironment) => {
await hre.run('compile');
await hre.run('deploy-libraries');
await hre.run('deploy-gw-diamond-and-facets');
});
task('deploy-sa-diamond', 'Builds and deploys Subnet Actor diamond', async (args, hre: HardhatRuntimeEnvironment) => {
await hre.run('compile');
await hre.run('deploy-libraries');
await hre.run('deploy-sa-diamond-and-facets');
});
/** @type import('hardhat/config').HardhatUserConfig */
const config: HardhatUserConfig = {
defaultNetwork: "calibrationnet",
networks: {
mainnet: {
chainId: 314,
url: process.env.RPC_URL!,
accounts: [process.env.PRIVATE_KEY!],
timeout: 1000000,
},
calibrationnet: {
chainId: 314159,
url: process.env.RPC_URL!,
accounts: [process.env.PRIVATE_KEY!],
timeout: 1000000,
},
localnet: {
chainId: 31415926,
url: process.env.RPC_URL!,
accounts: [process.env.PRIVATE_KEY!],
},
// automatically fetch chainID for network
auto: {
chainId: parseInt(process.env.CHAIN_ID!, 16),
url: process.env.RPC_URL!,
accounts: [process.env.PRIVATE_KEY!],
// timeout to support also slow networks (like calibration/mainnet)
timeout: 1000000,
}
},
solidity: {
compilers: [
{
version: '0.8.19',
settings: {
viaIR: true,
optimizer: {
enabled: true,
runs: 200,
},
},
},
],
},
typechain: {
outDir: 'typechain',
target: 'ethers-v5',
},
paths: {
storageLayouts: ".storage-layouts",
},
storageLayoutChanges: {
contracts: [
'GatewayDiamond',
'SubnetActorDiamond',
'GatewayActorModifiers',
'SubnetActorModifiers',
],
fullPath: false,
},
};
export default config;