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.
- package/LICENSE +21 -0
- package/README.md +120 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +197 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/default.d.ts.map +1 -0
- package/dist/config/default.js +5 -0
- package/dist/config/default.js.map +1 -0
- package/dist/config/get-config.d.ts.map +1 -0
- package/dist/config/get-config.js +9 -0
- package/dist/config/get-config.js.map +1 -0
- package/dist/config/validation.d.ts.map +1 -0
- package/dist/config/validation.js +17 -0
- package/dist/config/validation.js.map +1 -0
- package/dist/generate-types.d.ts +5 -0
- package/dist/generate-types.d.ts.map +1 -0
- package/dist/generate-types.js +244 -0
- package/dist/generate-types.js.map +1 -0
- package/dist/helpers.d.ts +34 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/{esm/helpers.js → helpers.js} +106 -73
- package/dist/helpers.js.map +1 -0
- package/dist/hook-handlers/config.d.ts.map +1 -0
- package/dist/hook-handlers/config.js +68 -0
- package/dist/hook-handlers/config.js.map +1 -0
- package/dist/hook-handlers/solidity.d.ts.map +1 -0
- package/dist/hook-handlers/solidity.js +21 -0
- package/dist/hook-handlers/solidity.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/{esm/index.js → index.js} +20 -3
- package/dist/index.js.map +1 -0
- package/dist/postinstall.d.ts +3 -0
- package/dist/postinstall.d.ts.map +1 -0
- package/dist/postinstall.js +148 -0
- package/dist/postinstall.js.map +1 -0
- package/dist/{esm/tasks → tasks}/deploy.d.ts +1 -0
- package/dist/tasks/deploy.d.ts.map +1 -0
- package/dist/tasks/deploy.js +32 -0
- package/dist/tasks/deploy.js.map +1 -0
- package/dist/{esm/type-extensions.d.ts → type-extensions.d.ts} +2 -2
- package/dist/type-extensions.d.ts.map +1 -0
- package/dist/type-extensions.js.map +1 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/files.d.ts +9 -0
- package/dist/utils/files.d.ts.map +1 -0
- package/dist/utils/files.js +25 -0
- package/dist/utils/files.js.map +1 -0
- package/dist/v1-detection.d.ts +12 -0
- package/dist/v1-detection.d.ts.map +1 -0
- package/dist/v1-detection.js +118 -0
- package/dist/v1-detection.js.map +1 -0
- package/dist/v1-entry.cjs +92 -0
- package/package.json +58 -26
- package/src/cli.ts +246 -0
- package/src/config/default.ts +6 -0
- package/src/config/get-config.ts +12 -0
- package/src/config/validation.ts +25 -0
- package/src/generate-types.ts +281 -0
- package/src/helpers.ts +311 -0
- package/src/hook-handlers/config.ts +80 -0
- package/src/hook-handlers/solidity.ts +33 -0
- package/src/index.ts +53 -0
- package/src/postinstall.ts +166 -0
- package/src/tasks/deploy.ts +43 -0
- package/src/type-extensions.ts +12 -0
- package/src/types.ts +9 -0
- package/src/utils/files.ts +37 -0
- package/src/v1-entry.cjs +92 -0
- package/templates/basic/README.md +44 -0
- package/templates/basic/contracts/Counter.sol +19 -0
- package/templates/basic/contracts/Counter.t.sol +29 -0
- package/templates/basic/deploy/01_deploy_counter.ts +13 -0
- package/templates/basic/hardhat.config.ts +50 -0
- package/templates/basic/package.json +31 -0
- package/templates/basic/pnpm-lock.yaml +1643 -0
- package/templates/basic/rocketh/config.ts +65 -0
- package/templates/basic/rocketh/deploy.ts +20 -0
- package/templates/basic/rocketh/environment.ts +22 -0
- package/templates/basic/test/Counter.ts +61 -0
- package/templates/basic/tsconfig.json +13 -0
- package/dist/esm/config/default.d.ts.map +0 -1
- package/dist/esm/config/default.js +0 -8
- package/dist/esm/config/default.js.map +0 -1
- package/dist/esm/config/get-config.d.ts.map +0 -1
- package/dist/esm/config/get-config.js +0 -8
- package/dist/esm/config/get-config.js.map +0 -1
- package/dist/esm/config/validation.d.ts.map +0 -1
- package/dist/esm/config/validation.js +0 -16
- package/dist/esm/config/validation.js.map +0 -1
- package/dist/esm/generate-types.d.ts +0 -6
- package/dist/esm/generate-types.d.ts.map +0 -1
- package/dist/esm/generate-types.js +0 -198
- package/dist/esm/generate-types.js.map +0 -1
- package/dist/esm/helpers.d.ts +0 -18
- package/dist/esm/helpers.d.ts.map +0 -1
- package/dist/esm/helpers.js.map +0 -1
- package/dist/esm/hook-handlers/config.d.ts.map +0 -1
- package/dist/esm/hook-handlers/config.js +0 -16
- package/dist/esm/hook-handlers/config.js.map +0 -1
- package/dist/esm/hook-handlers/solidity.d.ts.map +0 -1
- package/dist/esm/hook-handlers/solidity.js +0 -15
- package/dist/esm/hook-handlers/solidity.js.map +0 -1
- package/dist/esm/index.d.ts +0 -5
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/tasks/deploy.d.ts.map +0 -1
- package/dist/esm/tasks/deploy.js +0 -21
- package/dist/esm/tasks/deploy.js.map +0 -1
- package/dist/esm/type-extensions.d.ts.map +0 -1
- package/dist/esm/type-extensions.js.map +0 -1
- package/dist/esm/types.d.ts +0 -15
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/types.js.map +0 -1
- /package/dist/{esm/config → config}/default.d.ts +0 -0
- /package/dist/{esm/config → config}/get-config.d.ts +0 -0
- /package/dist/{esm/config → config}/validation.d.ts +0 -0
- /package/dist/{esm/hook-handlers → hook-handlers}/config.d.ts +0 -0
- /package/dist/{esm/hook-handlers → hook-handlers}/solidity.d.ts +0 -0
- /package/dist/{esm/type-extensions.js → type-extensions.js} +0 -0
- /package/dist/{esm/types.js → types.js} +0 -0
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import {configVariable} from 'hardhat/config';
|
|
2
|
+
import {
|
|
3
|
+
EdrNetworkHDAccountsUserConfig,
|
|
4
|
+
EdrNetworkUserConfig,
|
|
5
|
+
HttpNetworkUserConfig,
|
|
6
|
+
NetworkUserConfig,
|
|
7
|
+
SensitiveString,
|
|
8
|
+
} from 'hardhat/types/config';
|
|
9
|
+
import {HardhatRuntimeEnvironment} from 'hardhat/types/hre';
|
|
10
|
+
import {NetworkConnection} from 'hardhat/types/network';
|
|
11
|
+
import type {Environment, UnresolvedUnknownNamedAccounts, UnresolvedNetworkSpecificData} from 'rocketh/types';
|
|
12
|
+
import {enhanceEnvIfNeeded, chainByCanonicalName} from 'rocketh';
|
|
13
|
+
import {loadEnvironmentFromFiles} from '@rocketh/node';
|
|
14
|
+
|
|
15
|
+
export function setupHardhatDeploy<
|
|
16
|
+
Extensions extends Record<string, (env: Environment<any, any, any>) => any> = {},
|
|
17
|
+
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
18
|
+
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
19
|
+
>(extensions: Extensions) {
|
|
20
|
+
async function loadEnvironmentFromHardhatWithExtensions(
|
|
21
|
+
required: {hre: HardhatRuntimeEnvironment; connection?: NetworkConnection},
|
|
22
|
+
// options?: {
|
|
23
|
+
// useChainIdOfForkedNetwork?: boolean;
|
|
24
|
+
// }
|
|
25
|
+
) {
|
|
26
|
+
const env = await loadEnvironmentFromHardhat<NamedAccounts, Data>(required);
|
|
27
|
+
return enhanceEnvIfNeeded(env, extensions);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
loadEnvironmentFromHardhat: loadEnvironmentFromHardhatWithExtensions,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function generateForkConfig(
|
|
36
|
+
params: {hre: HardhatRuntimeEnvironment; connection?: NetworkConnection},
|
|
37
|
+
// options?: {
|
|
38
|
+
// useChainIdOfForkedNetwork?: boolean;
|
|
39
|
+
// }
|
|
40
|
+
): Promise<{provider: any; environment: string | {fork: string}; connection: NetworkConnection; isFork: boolean}> {
|
|
41
|
+
const fork = process.env.HARDHAT_FORK as string | undefined;
|
|
42
|
+
|
|
43
|
+
const connection =
|
|
44
|
+
params.connection || fork
|
|
45
|
+
? await params.hre.network.connect({network: 'fork'})
|
|
46
|
+
: await params.hre.network.connect();
|
|
47
|
+
|
|
48
|
+
let provider: any = connection.provider;
|
|
49
|
+
let environment: string | {fork: string} = connection.networkName;
|
|
50
|
+
let forkChainId: number | undefined;
|
|
51
|
+
|
|
52
|
+
if (fork) {
|
|
53
|
+
// if (options?.useChainIdOfForkedNetwork) {
|
|
54
|
+
// const forkNetworkConfig = params.hre.config.networks[fork];
|
|
55
|
+
|
|
56
|
+
// if (forkNetworkConfig.type === 'edr-simulated') {
|
|
57
|
+
// forkChainId = forkNetworkConfig.chainId;
|
|
58
|
+
// } else if (forkNetworkConfig.chainId) {
|
|
59
|
+
// forkChainId = forkNetworkConfig.chainId;
|
|
60
|
+
// } else {
|
|
61
|
+
// if ('url' in forkNetworkConfig) {
|
|
62
|
+
// const url = await forkNetworkConfig.url.getUrl();
|
|
63
|
+
// const response = await fetch(url, {
|
|
64
|
+
// method: 'POST',
|
|
65
|
+
// headers: {
|
|
66
|
+
// 'Content-Type': 'application/json',
|
|
67
|
+
// },
|
|
68
|
+
// body: JSON.stringify({
|
|
69
|
+
// jsonrpc: '2.0',
|
|
70
|
+
// id: 1,
|
|
71
|
+
// method: 'eth_chainId',
|
|
72
|
+
// params: [],
|
|
73
|
+
// }),
|
|
74
|
+
// });
|
|
75
|
+
// const json = (await response.json()) as {result: string};
|
|
76
|
+
// forkChainId = Number(json.result);
|
|
77
|
+
// } else {
|
|
78
|
+
// throw new Error(`cannot fetch chainId`);
|
|
79
|
+
// }
|
|
80
|
+
// }
|
|
81
|
+
// }
|
|
82
|
+
|
|
83
|
+
environment = {
|
|
84
|
+
fork,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (forkChainId) {
|
|
89
|
+
const originalProvider = provider;
|
|
90
|
+
const chainId = forkChainId;
|
|
91
|
+
async function request(args: {method: string; params?: string[]}): Promise<any> {
|
|
92
|
+
if (args.method === 'eth_chainId') {
|
|
93
|
+
return `0x${chainId.toString(16)}`;
|
|
94
|
+
}
|
|
95
|
+
return originalProvider.request(args);
|
|
96
|
+
}
|
|
97
|
+
provider = new Proxy(originalProvider, {
|
|
98
|
+
get: function (target, property, receiver) {
|
|
99
|
+
switch (property) {
|
|
100
|
+
case 'request':
|
|
101
|
+
return request;
|
|
102
|
+
default:
|
|
103
|
+
return originalProvider[property];
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return {provider, environment, connection, isFork: !!fork};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function loadEnvironmentFromHardhat<
|
|
113
|
+
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
114
|
+
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
115
|
+
>(
|
|
116
|
+
params: {hre: HardhatRuntimeEnvironment; connection?: NetworkConnection},
|
|
117
|
+
// TODO ?
|
|
118
|
+
// options?: {
|
|
119
|
+
// useChainIdOfForkedNetwork?: boolean;
|
|
120
|
+
// }
|
|
121
|
+
): Promise<Environment<NamedAccounts, Data>> {
|
|
122
|
+
const {connection, environment, provider, isFork} = await generateForkConfig(params);
|
|
123
|
+
// console.log(`loading environments...`);
|
|
124
|
+
return loadEnvironmentFromFiles<NamedAccounts, Data>({
|
|
125
|
+
provider,
|
|
126
|
+
environment,
|
|
127
|
+
extra: {
|
|
128
|
+
connection,
|
|
129
|
+
},
|
|
130
|
+
saveDeployments: isFork ? false : undefined,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function getVariable(prefix: string, name: string): string | SensitiveString | undefined {
|
|
135
|
+
// We transform dash into underscore as dash are not supported everywhere in env var names
|
|
136
|
+
const variableName = (prefix + name).replaceAll('-', '_');
|
|
137
|
+
let uri = process.env[variableName];
|
|
138
|
+
if (uri === 'SECRET') {
|
|
139
|
+
return configVariable(`SECRET_${variableName}`);
|
|
140
|
+
} else if (uri?.startsWith('SECRET:')) {
|
|
141
|
+
const splitted = uri.split(':');
|
|
142
|
+
if (splitted.length !== 2) {
|
|
143
|
+
throw new Error(`invalid secret uri ${uri}`);
|
|
144
|
+
}
|
|
145
|
+
return configVariable(`SECRET_${prefix + splitted[1]}`);
|
|
146
|
+
}
|
|
147
|
+
return uri;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function getRPC(networkName: string): string | SensitiveString | undefined {
|
|
151
|
+
let uri = getVariable('ETH_NODE_URI_', networkName);
|
|
152
|
+
|
|
153
|
+
if (uri && uri !== '') {
|
|
154
|
+
return uri;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
uri = process.env.ETH_NODE_URI;
|
|
158
|
+
if (uri) {
|
|
159
|
+
uri = uri.replace('{{networkName}}', networkName);
|
|
160
|
+
}
|
|
161
|
+
if (!uri || uri === '') {
|
|
162
|
+
if (networkName === 'localhost') {
|
|
163
|
+
return 'http://localhost:8545';
|
|
164
|
+
}
|
|
165
|
+
return uri;
|
|
166
|
+
// throw new Error(`no uri specified or for network ${networkName}`);
|
|
167
|
+
}
|
|
168
|
+
if (uri.indexOf('{{') >= 0) {
|
|
169
|
+
throw new Error(`invalid uri or network not supported by node provider : ${uri}`);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return uri;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function getMnemonic(networkName?: string, doNotDefault?: boolean): string | SensitiveString | undefined {
|
|
176
|
+
if (networkName) {
|
|
177
|
+
const mnemonic = getVariable('MNEMONIC_', networkName);
|
|
178
|
+
|
|
179
|
+
if (mnemonic && mnemonic !== '') {
|
|
180
|
+
return mnemonic;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const mnemonic = process.env.MNEMONIC;
|
|
185
|
+
if (!mnemonic || mnemonic === '') {
|
|
186
|
+
if (doNotDefault) {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
return 'test test test test test test test test test test test junk';
|
|
190
|
+
}
|
|
191
|
+
return mnemonic;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function getAccounts(
|
|
195
|
+
networkName?: string,
|
|
196
|
+
doNotDefault?: boolean,
|
|
197
|
+
): {mnemonic: string | SensitiveString} | undefined {
|
|
198
|
+
const mnemonic = getMnemonic(networkName, doNotDefault);
|
|
199
|
+
if (!mnemonic) {
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
return {mnemonic};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function addNetworksFromEnv(networks?: Record<string, NetworkUserConfig>): Record<string, NetworkUserConfig> {
|
|
206
|
+
const newNetworks: Record<string, NetworkUserConfig> = networks ? {...networks} : {};
|
|
207
|
+
const allEnv = Object.keys(process.env);
|
|
208
|
+
for (const envKey of allEnv) {
|
|
209
|
+
if (envKey.startsWith(`ETH_NODE_URI_`) && envKey.length > `ETH_NODE_URI_`.length) {
|
|
210
|
+
const networkName = envKey.slice(`ETH_NODE_URI_`.length);
|
|
211
|
+
const url = getRPC(networkName);
|
|
212
|
+
if (!newNetworks[networkName]) {
|
|
213
|
+
if (url) {
|
|
214
|
+
newNetworks[networkName] = {
|
|
215
|
+
type: 'http',
|
|
216
|
+
url,
|
|
217
|
+
accounts: getAccounts(networkName),
|
|
218
|
+
};
|
|
219
|
+
} else {
|
|
220
|
+
console.error(`no url for network ${networkName}`);
|
|
221
|
+
}
|
|
222
|
+
} else {
|
|
223
|
+
console.error(`duplicated network ${networkName}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return newNetworks;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const listOfNetworkNamesWithTestAccountAllowed = ['hardhat', 'localhost', 'memory', 'test'];
|
|
231
|
+
export function addNetworksFromKnownList(
|
|
232
|
+
networks?: Record<string, NetworkUserConfig>,
|
|
233
|
+
): Record<string, NetworkUserConfig> {
|
|
234
|
+
const newNetworks: Record<string, NetworkUserConfig> = networks ? {...networks} : {};
|
|
235
|
+
const canonicalNames = Object.keys(chainByCanonicalName);
|
|
236
|
+
|
|
237
|
+
for (const canonicalName of canonicalNames) {
|
|
238
|
+
const chain = chainByCanonicalName[canonicalName];
|
|
239
|
+
const url = getRPC(canonicalName) || chain.rpcUrls.default.http[0];
|
|
240
|
+
if (!newNetworks[canonicalName]) {
|
|
241
|
+
if (url) {
|
|
242
|
+
newNetworks[canonicalName] = {
|
|
243
|
+
type: 'http',
|
|
244
|
+
url,
|
|
245
|
+
accounts: getAccounts(canonicalName, !listOfNetworkNamesWithTestAccountAllowed.includes(canonicalName)),
|
|
246
|
+
chainType: chain.chainType === 'op-stack' ? 'op' : undefined,
|
|
247
|
+
chainId: chain.id,
|
|
248
|
+
};
|
|
249
|
+
} else {
|
|
250
|
+
console.error(`no url for chain ${canonicalName}`);
|
|
251
|
+
}
|
|
252
|
+
} else {
|
|
253
|
+
// console.error(`duplicated chain ${canonicalName}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return newNetworks;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export function addForkConfiguration(networks: Record<string, NetworkUserConfig>): Record<string, NetworkUserConfig> {
|
|
260
|
+
const currentNetworkName = process.env.HARDHAT_FORK;
|
|
261
|
+
let forkURL: SensitiveString | string | undefined;
|
|
262
|
+
let hardhatAccounts: EdrNetworkHDAccountsUserConfig | undefined;
|
|
263
|
+
if (
|
|
264
|
+
currentNetworkName &&
|
|
265
|
+
currentNetworkName !== 'hardhat' &&
|
|
266
|
+
currentNetworkName !== 'edr' &&
|
|
267
|
+
currentNetworkName !== 'edr-simulated' &&
|
|
268
|
+
currentNetworkName !== 'memory'
|
|
269
|
+
) {
|
|
270
|
+
const currentNetwork = networks[currentNetworkName] as HttpNetworkUserConfig;
|
|
271
|
+
if (currentNetwork) {
|
|
272
|
+
if (currentNetwork.type === 'http') {
|
|
273
|
+
forkURL = currentNetwork.url;
|
|
274
|
+
if (
|
|
275
|
+
currentNetwork.accounts &&
|
|
276
|
+
typeof currentNetwork.accounts === 'object' &&
|
|
277
|
+
'mnemonic' in currentNetwork.accounts
|
|
278
|
+
) {
|
|
279
|
+
hardhatAccounts = currentNetwork.accounts;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// else if (currentNetwork.accounts && Array.isArray(currentNetwork.accounts)) {
|
|
283
|
+
// hardhatAccounts = currentNetwork.accounts.map((v) => ({
|
|
284
|
+
// balance: '10000000000000000000000',
|
|
285
|
+
// privateKey: v,
|
|
286
|
+
// }));
|
|
287
|
+
// }
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const existingForkConfiguration: EdrNetworkUserConfig =
|
|
293
|
+
networks.fork && networks.fork.type === 'edr-simulated' ? networks.fork : {type: 'edr-simulated', chainType: 'l1'};
|
|
294
|
+
|
|
295
|
+
const newNetworks: Record<string, NetworkUserConfig> = {
|
|
296
|
+
...networks,
|
|
297
|
+
fork: {
|
|
298
|
+
...existingForkConfiguration,
|
|
299
|
+
...{
|
|
300
|
+
accounts: hardhatAccounts || existingForkConfiguration?.accounts,
|
|
301
|
+
forking: forkURL
|
|
302
|
+
? {
|
|
303
|
+
url: forkURL,
|
|
304
|
+
blockNumber: process.env.HARDHAT_FORK_NUMBER ? parseInt(process.env.HARDHAT_FORK_NUMBER) : undefined,
|
|
305
|
+
}
|
|
306
|
+
: undefined,
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
return newNetworks;
|
|
311
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type {ConfigHooks} from 'hardhat/types/hooks';
|
|
2
|
+
|
|
3
|
+
import {getConfig} from '../config/get-config.js';
|
|
4
|
+
import {validateTypechainUserConfig} from '../config/validation.js';
|
|
5
|
+
import {SolidityBuildProfileConfig, SolidityConfig} from 'hardhat/types/config';
|
|
6
|
+
|
|
7
|
+
function addIfNotPresent(array: string[], value: string) {
|
|
8
|
+
if (array.indexOf(value) === -1) {
|
|
9
|
+
array.push(value);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function setupExtraSolcSettings(settings: {
|
|
13
|
+
metadata: {useLiteralContent: boolean};
|
|
14
|
+
outputSelection: {'*': {'': string[]; '*': string[]}};
|
|
15
|
+
}): void {
|
|
16
|
+
settings.metadata = settings.metadata || {};
|
|
17
|
+
settings.metadata.useLiteralContent = true;
|
|
18
|
+
|
|
19
|
+
if (settings.outputSelection === undefined) {
|
|
20
|
+
settings.outputSelection = {
|
|
21
|
+
'*': {
|
|
22
|
+
'*': [],
|
|
23
|
+
'': [],
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (settings.outputSelection['*'] === undefined) {
|
|
28
|
+
settings.outputSelection['*'] = {
|
|
29
|
+
'*': [],
|
|
30
|
+
'': [],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (settings.outputSelection['*']['*'] === undefined) {
|
|
34
|
+
settings.outputSelection['*']['*'] = [];
|
|
35
|
+
}
|
|
36
|
+
if (settings.outputSelection['*'][''] === undefined) {
|
|
37
|
+
settings.outputSelection['*'][''] = [];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
addIfNotPresent(settings.outputSelection['*']['*'], 'abi');
|
|
41
|
+
// addIfNotPresent(settings.outputSelection['*']['*'], 'evm.bytecode');
|
|
42
|
+
// addIfNotPresent(settings.outputSelection['*']['*'], 'evm.deployedBytecode');
|
|
43
|
+
addIfNotPresent(settings.outputSelection['*']['*'], 'metadata');
|
|
44
|
+
addIfNotPresent(settings.outputSelection['*']['*'], 'devdoc');
|
|
45
|
+
addIfNotPresent(settings.outputSelection['*']['*'], 'userdoc');
|
|
46
|
+
addIfNotPresent(settings.outputSelection['*']['*'], 'storageLayout');
|
|
47
|
+
// addIfNotPresent(settings.outputSelection['*']['*'], 'evm.methodIdentifiers');
|
|
48
|
+
addIfNotPresent(settings.outputSelection['*']['*'], 'evm.gasEstimates');
|
|
49
|
+
// addIfNotPresent(settings.outputSelection["*"][""], "ir");
|
|
50
|
+
// addIfNotPresent(settings.outputSelection["*"][""], "irOptimized");
|
|
51
|
+
// addIfNotPresent(settings.outputSelection["*"][""], "ast");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default async (): Promise<Partial<ConfigHooks>> => {
|
|
55
|
+
const handlers: Partial<ConfigHooks> = {
|
|
56
|
+
validateUserConfig: validateTypechainUserConfig,
|
|
57
|
+
resolveUserConfig: async (userConfig, resolveConfigurationVariable, next) => {
|
|
58
|
+
const resolvedConfig = await next(userConfig, resolveConfigurationVariable);
|
|
59
|
+
|
|
60
|
+
const solidity: SolidityConfig = structuredClone(resolvedConfig.solidity);
|
|
61
|
+
const profiles: Record<string, SolidityBuildProfileConfig> = solidity.profiles;
|
|
62
|
+
for (const profileName of Object.keys(profiles)) {
|
|
63
|
+
const profile: SolidityBuildProfileConfig = profiles[profileName];
|
|
64
|
+
const compilers = profile.compilers;
|
|
65
|
+
for (const compiler of compilers) {
|
|
66
|
+
const settings = compiler.settings;
|
|
67
|
+
setupExtraSolcSettings(settings);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
...resolvedConfig,
|
|
73
|
+
solidity,
|
|
74
|
+
generateTypedArtifacts: getConfig(userConfig.generateTypedArtifacts),
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return handlers;
|
|
80
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type {HookContext, SolidityHooks} from 'hardhat/types/hooks';
|
|
2
|
+
|
|
3
|
+
import {generateTypes} from '../generate-types.js';
|
|
4
|
+
|
|
5
|
+
export default async (): Promise<Partial<SolidityHooks>> => {
|
|
6
|
+
const handlers: Partial<SolidityHooks> = {
|
|
7
|
+
async onCleanUpArtifacts(
|
|
8
|
+
context: HookContext,
|
|
9
|
+
artifactPaths: string[],
|
|
10
|
+
next: (nextContext: HookContext, artifactPaths: string[]) => Promise<void>
|
|
11
|
+
) {
|
|
12
|
+
let artifactPathsToProcess = [context.config.paths.artifacts];
|
|
13
|
+
// if (context.config.generateTypedArtifacts.externalArtifacts) {
|
|
14
|
+
// artifactPathsToProcess = artifactPathsToProcess.concat(
|
|
15
|
+
// context.config.generateTypedArtifacts.externalArtifacts
|
|
16
|
+
// );
|
|
17
|
+
// }
|
|
18
|
+
|
|
19
|
+
if (artifactPaths.length > 0) {
|
|
20
|
+
await generateTypes(
|
|
21
|
+
{
|
|
22
|
+
artifacts: artifactPathsToProcess,
|
|
23
|
+
},
|
|
24
|
+
context.config.generateTypedArtifacts
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return next(context, artifactPaths);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return handlers;
|
|
33
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {setupLogger} from 'named-logs-console';
|
|
2
|
+
import type {HardhatPlugin} from 'hardhat/types/plugins';
|
|
3
|
+
import {task} from 'hardhat/config';
|
|
4
|
+
|
|
5
|
+
import './type-extensions.js';
|
|
6
|
+
import {ArgumentType} from 'hardhat/types/arguments';
|
|
7
|
+
import type {Environment} from 'rocketh/types';
|
|
8
|
+
import type {NetworkConnection} from 'hardhat/types/network';
|
|
9
|
+
|
|
10
|
+
// const deployTask = import.meta.resolve('./tasks/deploy.js').replace('.ts', '.js');
|
|
11
|
+
// console.log({deployTask});
|
|
12
|
+
|
|
13
|
+
setupLogger(['rocketh', '@rocketh/node'], {
|
|
14
|
+
enabled: true,
|
|
15
|
+
level: 3,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const hardhatPlugin: HardhatPlugin = {
|
|
19
|
+
id: 'hardhat-deploy',
|
|
20
|
+
hookHandlers: {
|
|
21
|
+
config: () => import('./hook-handlers/config.js'),
|
|
22
|
+
solidity: () => import('./hook-handlers/solidity.js'),
|
|
23
|
+
},
|
|
24
|
+
tasks: [
|
|
25
|
+
task('deploy', 'Deploy contracts')
|
|
26
|
+
// .addFlag('skipGasReport', 'if set, skip gas report')
|
|
27
|
+
.addFlag({name: 'skipPrompts', description: 'if set, skip any prompts'})
|
|
28
|
+
.addOption({
|
|
29
|
+
name: 'saveDeployments',
|
|
30
|
+
description: 'if set, save deployments',
|
|
31
|
+
defaultValue: '',
|
|
32
|
+
type: ArgumentType.STRING,
|
|
33
|
+
})
|
|
34
|
+
.addOption({
|
|
35
|
+
name: 'tags',
|
|
36
|
+
description: 'specify which tags to deploy',
|
|
37
|
+
defaultValue: '',
|
|
38
|
+
type: ArgumentType.STRING,
|
|
39
|
+
})
|
|
40
|
+
.setAction(() => import('./tasks/deploy.js'))
|
|
41
|
+
.build(),
|
|
42
|
+
],
|
|
43
|
+
npmPackage: 'hardhat-deploy',
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export default hardhatPlugin;
|
|
47
|
+
|
|
48
|
+
export function getHardhatConnection(env: Environment): NetworkConnection<'generic'> {
|
|
49
|
+
if (!env.extra?.connection) {
|
|
50
|
+
throw new Error('Hardhat deploy connection not found in the environment');
|
|
51
|
+
}
|
|
52
|
+
return env.extra.connection as NetworkConnection<'generic'>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Attempt to detect if user is in a v1 environment
|
|
4
|
+
// This script should be lightweight and fail gracefully
|
|
5
|
+
|
|
6
|
+
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
7
|
+
import { join, dirname } from 'path';
|
|
8
|
+
import { execSync } from 'child_process';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const MIGRATION_URL = 'https://rocketh.dev/hardhat-deploy/documentation/how-to/migration-from-v1.html';
|
|
12
|
+
const V1_INSTALL_CMD = 'npm install hardhat-deploy@1';
|
|
13
|
+
const MARKER_FILE = '.hardhat-deploy-v2-notice';
|
|
14
|
+
|
|
15
|
+
// Find the project root by navigating up from node_modules
|
|
16
|
+
function findProjectRoot(currentPath: string): string {
|
|
17
|
+
let path = currentPath;
|
|
18
|
+
|
|
19
|
+
while (path !== '/' && path !== '') {
|
|
20
|
+
// Check if we're inside node_modules
|
|
21
|
+
if (path.includes('node_modules')) {
|
|
22
|
+
path = dirname(path);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Check if this directory has a package.json (likely project root)
|
|
27
|
+
if (existsSync(join(path, 'package.json'))) {
|
|
28
|
+
return path;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
path = dirname(path);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Fallback to current directory
|
|
35
|
+
return currentPath;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function checkEnvironment() {
|
|
39
|
+
// Postinstall runs in the package directory, need to find the actual project root
|
|
40
|
+
const projectRoot = findProjectRoot(process.cwd());
|
|
41
|
+
let v1Detected = false;
|
|
42
|
+
let reasons: string[] = [];
|
|
43
|
+
|
|
44
|
+
// Check for hardhat version via command line
|
|
45
|
+
try {
|
|
46
|
+
const output = execSync('hardhat --version', { encoding: 'utf-8', stdio: 'pipe', cwd: projectRoot });
|
|
47
|
+
// Output format is like "hardhat, version 2.x.x" or "hardhat, version 3.x.x"
|
|
48
|
+
const match = output.match(/hardhat, version (\d+\.\d+\.\d+)/);
|
|
49
|
+
if (match) {
|
|
50
|
+
const hardhatVersion = match[1];
|
|
51
|
+
if (hardhatVersion.startsWith('2.')) {
|
|
52
|
+
v1Detected = true;
|
|
53
|
+
reasons.push(`hardhat ${hardhatVersion} detected (v2 requires hardhat 3.x)`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
} catch (e) {
|
|
57
|
+
// Hardhat not installed yet - that's fine
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Check for v1-style config patterns
|
|
61
|
+
try {
|
|
62
|
+
const configFiles = ['hardhat.config.js', 'hardhat.config.ts'];
|
|
63
|
+
|
|
64
|
+
for (const configFile of configFiles) {
|
|
65
|
+
const configPath = join(projectRoot, configFile);
|
|
66
|
+
if (existsSync(configPath)) {
|
|
67
|
+
const content = readFileSync(configPath, 'utf-8');
|
|
68
|
+
|
|
69
|
+
if (content.includes('namedAccounts')) {
|
|
70
|
+
v1Detected = true;
|
|
71
|
+
reasons.push(`'namedAccounts' found in ${configFile}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (content.includes("require('hardhat-deploy')") || content.includes('require("hardhat-deploy")')) {
|
|
75
|
+
v1Detected = true;
|
|
76
|
+
reasons.push(`require('hardhat-deploy') found in ${configFile}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (content.includes('module.exports')) {
|
|
80
|
+
v1Detected = true;
|
|
81
|
+
reasons.push(`CommonJS 'module.exports' found in ${configFile}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} catch (e) {
|
|
86
|
+
// Config check failed - continue silently
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (v1Detected) {
|
|
90
|
+
printV1Warning(reasons);
|
|
91
|
+
createMarkerFile(projectRoot, reasons);
|
|
92
|
+
} else {
|
|
93
|
+
printWelcome();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function createMarkerFile(projectRoot: string, reasons: string[]) {
|
|
98
|
+
const markerPath = join(projectRoot, MARKER_FILE);
|
|
99
|
+
const content = `HARDHAT-DEPLOY V2 - V1 PATTERNS DETECTED
|
|
100
|
+
|
|
101
|
+
This file was created because hardhat-deploy v2 detected v1 patterns in your project.
|
|
102
|
+
You can delete this file after reading.
|
|
103
|
+
|
|
104
|
+
Detected issues:
|
|
105
|
+
${reasons.map((r) => ` - ${r}`).join('\n')}
|
|
106
|
+
|
|
107
|
+
To resolve this, either:
|
|
108
|
+
|
|
109
|
+
1. Install hardhat-deploy v1 instead:
|
|
110
|
+
npm uninstall hardhat-deploy
|
|
111
|
+
${V1_INSTALL_CMD}
|
|
112
|
+
|
|
113
|
+
2. Migrate your project to v2:
|
|
114
|
+
${MIGRATION_URL}
|
|
115
|
+
|
|
116
|
+
For more information, see the migration guide.
|
|
117
|
+
`;
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
writeFileSync(markerPath, content, 'utf-8');
|
|
121
|
+
} catch (e) {
|
|
122
|
+
// Failed to write marker file - continue anyway
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function printV1Warning(reasons: string[]) {
|
|
127
|
+
const reasonsList = reasons.map((r) => ` • ${r}`).join('\n');
|
|
128
|
+
|
|
129
|
+
console.log(`
|
|
130
|
+
╔══════════════════════════════════════════════════════════════════════════════╗
|
|
131
|
+
║ ║
|
|
132
|
+
║ ⚠️ HARDHAT-DEPLOY V2 - V1 PATTERNS DETECTED ║
|
|
133
|
+
║ ║
|
|
134
|
+
╚══════════════════════════════════════════════════════════════════════════════╝
|
|
135
|
+
|
|
136
|
+
Your project appears to be using hardhat-deploy v1 patterns:
|
|
137
|
+
|
|
138
|
+
${reasonsList}
|
|
139
|
+
|
|
140
|
+
hardhat-deploy v2 has MAJOR breaking changes and requires hardhat 3.x.
|
|
141
|
+
|
|
142
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
143
|
+
|
|
144
|
+
OPTION 1: Install v1 instead (recommended for existing v1 projects)
|
|
145
|
+
|
|
146
|
+
npm uninstall hardhat-deploy
|
|
147
|
+
${V1_INSTALL_CMD}
|
|
148
|
+
|
|
149
|
+
OPTION 2: Migrate to v2
|
|
150
|
+
|
|
151
|
+
See: ${MIGRATION_URL}
|
|
152
|
+
|
|
153
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
154
|
+
|
|
155
|
+
A marker file '${MARKER_FILE}' has been created in your project root.
|
|
156
|
+
`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function printWelcome() {
|
|
160
|
+
console.log(`
|
|
161
|
+
✓ hardhat-deploy v2 installed successfully!
|
|
162
|
+
Documentation: https://rocketh.dev/hardhat-deploy/
|
|
163
|
+
`);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
checkEnvironment().catch(() => {});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {NewTaskActionFunction} from 'hardhat/types/tasks';
|
|
2
|
+
import {loadAndExecuteDeploymentsFromFiles} from '@rocketh/node';
|
|
3
|
+
import {generateForkConfig} from '../helpers.js';
|
|
4
|
+
import {setupLogger} from 'named-logs-console';
|
|
5
|
+
|
|
6
|
+
interface RunActionArguments {
|
|
7
|
+
saveDeployments: string;
|
|
8
|
+
skipPrompts: boolean;
|
|
9
|
+
tags?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const runScriptWithHardhat: NewTaskActionFunction<RunActionArguments> = async (args, hre) => {
|
|
13
|
+
let saveDeployments = true;
|
|
14
|
+
let skipPrompts = args.skipPrompts ? true : false;
|
|
15
|
+
|
|
16
|
+
const {connection, environment, isFork, provider} = await generateForkConfig({hre});
|
|
17
|
+
|
|
18
|
+
const isMemoryNetwork = connection.networkConfig.type == 'edr-simulated';
|
|
19
|
+
if (isMemoryNetwork) {
|
|
20
|
+
skipPrompts = true;
|
|
21
|
+
saveDeployments = false;
|
|
22
|
+
}
|
|
23
|
+
if (args.saveDeployments != '') {
|
|
24
|
+
saveDeployments = args.saveDeployments == 'true' ? true : false;
|
|
25
|
+
}
|
|
26
|
+
const tags = args.tags && args.tags != '' ? args.tags : undefined;
|
|
27
|
+
|
|
28
|
+
setupLogger(['rocketh', '@rocketh/node'], {
|
|
29
|
+
enabled: true,
|
|
30
|
+
level: 3,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
await loadAndExecuteDeploymentsFromFiles({
|
|
34
|
+
provider,
|
|
35
|
+
environment: environment,
|
|
36
|
+
saveDeployments: isFork ? false : saveDeployments,
|
|
37
|
+
askBeforeProceeding: skipPrompts ? false : true,
|
|
38
|
+
tags: tags?.split(','),
|
|
39
|
+
// reportGasUse: args.skipGasReport ? false : true,
|
|
40
|
+
extra: {connection},
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
export default runScriptWithHardhat;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import 'hardhat/types/config';
|
|
2
|
+
import {ArtifactGenerationConfig, ArtifactGenerationUserConfig} from './types.js';
|
|
3
|
+
|
|
4
|
+
declare module 'hardhat/types/config' {
|
|
5
|
+
export interface HardhatUserConfig {
|
|
6
|
+
generateTypedArtifacts?: ArtifactGenerationUserConfig;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface HardhatConfig {
|
|
10
|
+
readonly generateTypedArtifacts: ArtifactGenerationConfig;
|
|
11
|
+
}
|
|
12
|
+
}
|