rocketh 0.5.12 → 0.5.14
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/CHANGELOG.md +12 -0
- package/dist/{chunk-PJUHRI2O.js → chunk-33O2ISAE.js} +21 -18
- package/dist/chunk-33O2ISAE.js.map +1 -0
- package/dist/{chunk-4YSEV6V7.js → chunk-MYGNNFLV.js} +21 -18
- package/dist/chunk-MYGNNFLV.js.map +1 -0
- package/dist/{chunk-FNGUBXU4.js → chunk-NG7ZGEAR.js} +15 -12
- package/dist/chunk-NG7ZGEAR.js.map +1 -0
- package/dist/chunk-VO2YJH6E.js +822 -0
- package/dist/chunk-VO2YJH6E.js.map +1 -0
- package/dist/{chunk-TSZHO6IV.js → chunk-VX3ZYUUU.js} +3 -4
- package/dist/chunk-VX3ZYUUU.js.map +1 -0
- package/dist/cli.cjs +10 -7
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +9 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/environment/index.ts +16 -7
- package/dist/chunk-472IGS3D.js +0 -775
- package/dist/chunk-472IGS3D.js.map +0 -1
- package/dist/chunk-4QVFNMWY.js +0 -814
- package/dist/chunk-4QVFNMWY.js.map +0 -1
- package/dist/chunk-4YSEV6V7.js.map +0 -1
- package/dist/chunk-6MXUXCI5.js +0 -814
- package/dist/chunk-6MXUXCI5.js.map +0 -1
- package/dist/chunk-6OHBWJ6R.js +0 -802
- package/dist/chunk-6OHBWJ6R.js.map +0 -1
- package/dist/chunk-6SYA5IBX.js +0 -775
- package/dist/chunk-6SYA5IBX.js.map +0 -1
- package/dist/chunk-A2DF6IYU.js +0 -775
- package/dist/chunk-A2DF6IYU.js.map +0 -1
- package/dist/chunk-BDP52TGA.js +0 -775
- package/dist/chunk-BDP52TGA.js.map +0 -1
- package/dist/chunk-CWIC3RNX.js +0 -779
- package/dist/chunk-CWIC3RNX.js.map +0 -1
- package/dist/chunk-CY65LIMI.js +0 -812
- package/dist/chunk-CY65LIMI.js.map +0 -1
- package/dist/chunk-DVS3FHRT.js +0 -775
- package/dist/chunk-DVS3FHRT.js.map +0 -1
- package/dist/chunk-E3HMPYAE.js +0 -802
- package/dist/chunk-E3HMPYAE.js.map +0 -1
- package/dist/chunk-EEKPYOVG.js +0 -814
- package/dist/chunk-EEKPYOVG.js.map +0 -1
- package/dist/chunk-EZAHXMFN.js +0 -779
- package/dist/chunk-EZAHXMFN.js.map +0 -1
- package/dist/chunk-FIYG7LWT.js +0 -802
- package/dist/chunk-FIYG7LWT.js.map +0 -1
- package/dist/chunk-FNGUBXU4.js.map +0 -1
- package/dist/chunk-HYG6AZHD.js +0 -775
- package/dist/chunk-HYG6AZHD.js.map +0 -1
- package/dist/chunk-K53RF3NI.js +0 -775
- package/dist/chunk-K53RF3NI.js.map +0 -1
- package/dist/chunk-LQNPDN2C.js +0 -802
- package/dist/chunk-LQNPDN2C.js.map +0 -1
- package/dist/chunk-N3LXBIZU.js +0 -813
- package/dist/chunk-N3LXBIZU.js.map +0 -1
- package/dist/chunk-NYXECIHF.js +0 -779
- package/dist/chunk-NYXECIHF.js.map +0 -1
- package/dist/chunk-PJUHRI2O.js.map +0 -1
- package/dist/chunk-QBPUQWOC.js +0 -802
- package/dist/chunk-QBPUQWOC.js.map +0 -1
- package/dist/chunk-SBMZCD52.js +0 -813
- package/dist/chunk-SBMZCD52.js.map +0 -1
- package/dist/chunk-T632AEY2.js +0 -775
- package/dist/chunk-T632AEY2.js.map +0 -1
- package/dist/chunk-TDQGC7ST.js +0 -775
- package/dist/chunk-TDQGC7ST.js.map +0 -1
- package/dist/chunk-TNMQT3PW.js +0 -802
- package/dist/chunk-TNMQT3PW.js.map +0 -1
- package/dist/chunk-TRN42LR4.js +0 -779
- package/dist/chunk-TRN42LR4.js.map +0 -1
- package/dist/chunk-TSZHO6IV.js.map +0 -1
- package/dist/chunk-YZAKY2DK.js +0 -813
- package/dist/chunk-YZAKY2DK.js.map +0 -1
package/dist/chunk-CWIC3RNX.js
DELETED
|
@@ -1,779 +0,0 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined")
|
|
5
|
-
return require.apply(this, arguments);
|
|
6
|
-
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
// src/utils/fs.ts
|
|
10
|
-
import fs from "fs";
|
|
11
|
-
import path from "path";
|
|
12
|
-
function traverseMultipleDirectory(dirs) {
|
|
13
|
-
const filepaths = [];
|
|
14
|
-
for (const dir of dirs) {
|
|
15
|
-
let filesStats = traverse(dir);
|
|
16
|
-
filesStats = filesStats.filter((v) => !v.directory);
|
|
17
|
-
for (const filestat of filesStats) {
|
|
18
|
-
filepaths.push(path.join(dir, filestat.relativePath));
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return filepaths;
|
|
22
|
-
}
|
|
23
|
-
var traverse = function(dir, result = [], topDir, filter) {
|
|
24
|
-
fs.readdirSync(dir).forEach((name) => {
|
|
25
|
-
const fPath = path.resolve(dir, name);
|
|
26
|
-
const stats = fs.statSync(fPath);
|
|
27
|
-
if (!filter && !name.startsWith(".") || filter && filter(name, stats)) {
|
|
28
|
-
const fileStats = {
|
|
29
|
-
name,
|
|
30
|
-
path: fPath,
|
|
31
|
-
relativePath: path.relative(topDir || dir, fPath),
|
|
32
|
-
mtimeMs: stats.mtimeMs,
|
|
33
|
-
directory: stats.isDirectory()
|
|
34
|
-
};
|
|
35
|
-
if (fileStats.directory) {
|
|
36
|
-
result.push(fileStats);
|
|
37
|
-
return traverse(fPath, result, topDir || dir, filter);
|
|
38
|
-
}
|
|
39
|
-
result.push(fileStats);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
return result;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// src/executor/index.ts
|
|
46
|
-
import path4 from "path";
|
|
47
|
-
import fs4 from "fs";
|
|
48
|
-
|
|
49
|
-
// src/environment/index.ts
|
|
50
|
-
import fs3 from "fs";
|
|
51
|
-
import { createPublicClient, custom } from "viem";
|
|
52
|
-
import { JSONRPCHTTPProvider } from "eip-1193-json-provider";
|
|
53
|
-
import path3 from "path";
|
|
54
|
-
|
|
55
|
-
// src/utils/json.ts
|
|
56
|
-
function bnReplacer(k, v) {
|
|
57
|
-
if (typeof v === "bigint") {
|
|
58
|
-
return v.toString() + "n";
|
|
59
|
-
}
|
|
60
|
-
return v;
|
|
61
|
-
}
|
|
62
|
-
function bnReviver(k, v) {
|
|
63
|
-
if (typeof v === "string" && (v.startsWith("-") ? !isNaN(parseInt(v.charAt(1))) : !isNaN(parseInt(v.charAt(0)))) && v.charAt(v.length - 1) === "n") {
|
|
64
|
-
return BigInt(v.slice(0, -1));
|
|
65
|
-
}
|
|
66
|
-
return v;
|
|
67
|
-
}
|
|
68
|
-
function JSONToString(json, space) {
|
|
69
|
-
return JSON.stringify(json, bnReplacer, space);
|
|
70
|
-
}
|
|
71
|
-
function stringToJSON(str) {
|
|
72
|
-
return JSON.parse(str, bnReviver);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// src/environment/deployments.ts
|
|
76
|
-
import path2 from "path";
|
|
77
|
-
import fs2 from "fs";
|
|
78
|
-
function loadDeployments(deploymentsPath, subPath, onlyABIAndAddress, expectedChainId) {
|
|
79
|
-
const deploymentsFound = {};
|
|
80
|
-
const deployPath = path2.join(deploymentsPath, subPath);
|
|
81
|
-
let filesStats;
|
|
82
|
-
try {
|
|
83
|
-
filesStats = traverse(deployPath, void 0, void 0, (name) => !name.startsWith(".") && name !== "solcInputs");
|
|
84
|
-
} catch (e) {
|
|
85
|
-
return { deployments: {} };
|
|
86
|
-
}
|
|
87
|
-
let chainId;
|
|
88
|
-
if (filesStats.length > 0) {
|
|
89
|
-
const chainIdFilepath = path2.join(deployPath, ".chainId");
|
|
90
|
-
if (fs2.existsSync(chainIdFilepath)) {
|
|
91
|
-
chainId = fs2.readFileSync(chainIdFilepath).toString().trim();
|
|
92
|
-
} else {
|
|
93
|
-
throw new Error(`A .chainId' file is expected to be present in the deployment folder for network ${subPath}`);
|
|
94
|
-
}
|
|
95
|
-
if (expectedChainId) {
|
|
96
|
-
if (expectedChainId !== chainId) {
|
|
97
|
-
throw new Error(
|
|
98
|
-
`Loading deployment in folder '${deployPath}' (with chainId: ${chainId}) for a different chainId (${expectedChainId})`
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
return { deployments: {} };
|
|
104
|
-
}
|
|
105
|
-
let fileNames = filesStats.map((a) => a.relativePath);
|
|
106
|
-
fileNames = fileNames.sort((a, b) => {
|
|
107
|
-
if (a < b) {
|
|
108
|
-
return -1;
|
|
109
|
-
}
|
|
110
|
-
if (a > b) {
|
|
111
|
-
return 1;
|
|
112
|
-
}
|
|
113
|
-
return 0;
|
|
114
|
-
});
|
|
115
|
-
for (const fileName of fileNames) {
|
|
116
|
-
if (fileName.substring(fileName.length - 5) === ".json") {
|
|
117
|
-
const deploymentFileName = path2.join(deployPath, fileName);
|
|
118
|
-
let deployment = JSON.parse(fs2.readFileSync(deploymentFileName).toString());
|
|
119
|
-
if (onlyABIAndAddress) {
|
|
120
|
-
deployment = {
|
|
121
|
-
address: deployment.address,
|
|
122
|
-
abi: deployment.abi,
|
|
123
|
-
linkedData: deployment.linkedData
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
const name = fileName.slice(0, fileName.length - 5);
|
|
127
|
-
deploymentsFound[name] = deployment;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return { deployments: deploymentsFound, chainId };
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// src/internal/logging.ts
|
|
134
|
-
import { logs } from "named-logs";
|
|
135
|
-
import { hookup, logs as Logging } from "named-logs-console";
|
|
136
|
-
hookup();
|
|
137
|
-
function setLogLevel(level) {
|
|
138
|
-
Logging.level = level;
|
|
139
|
-
if (Logging.level > 0) {
|
|
140
|
-
Logging.enable();
|
|
141
|
-
} else {
|
|
142
|
-
Logging.disable();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
var logger = logs("rocketh");
|
|
146
|
-
var voidSpinner = {
|
|
147
|
-
start(msg) {
|
|
148
|
-
if (msg) {
|
|
149
|
-
console.log(msg);
|
|
150
|
-
}
|
|
151
|
-
return this;
|
|
152
|
-
},
|
|
153
|
-
stop() {
|
|
154
|
-
return this;
|
|
155
|
-
},
|
|
156
|
-
succeed(msg) {
|
|
157
|
-
if (msg) {
|
|
158
|
-
console.log(msg);
|
|
159
|
-
}
|
|
160
|
-
return this;
|
|
161
|
-
},
|
|
162
|
-
fail(msg) {
|
|
163
|
-
if (msg) {
|
|
164
|
-
console.error(msg);
|
|
165
|
-
}
|
|
166
|
-
return this;
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
var lastSpin = voidSpinner;
|
|
170
|
-
function spin(message) {
|
|
171
|
-
if (Logging.level > 0) {
|
|
172
|
-
lastSpin = lastSpin.start(message);
|
|
173
|
-
return lastSpin;
|
|
174
|
-
} else {
|
|
175
|
-
return voidSpinner;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// src/environment/index.ts
|
|
180
|
-
globalThis.extensions = [];
|
|
181
|
-
function extendEnvironment(extension) {
|
|
182
|
-
globalThis.extensions.push(extension);
|
|
183
|
-
}
|
|
184
|
-
globalThis.signerProtocols = {};
|
|
185
|
-
function handleSignerProtocol(protocol, getSigner) {
|
|
186
|
-
globalThis.signerProtocols[protocol] = {
|
|
187
|
-
getSigner
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
function displayTransaction(transaction) {
|
|
191
|
-
if (transaction.type === "0x2") {
|
|
192
|
-
return `(maxFeePerGas: ${BigInt(transaction.maxFeePerGas).toString()}, maxPriorityFeePerGas: ${BigInt(
|
|
193
|
-
transaction.maxPriorityFeePerGas
|
|
194
|
-
).toString()})`;
|
|
195
|
-
} else {
|
|
196
|
-
return `(gasPrice: ${BigInt(transaction.gasPrice).toString()})`;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
async function createEnvironment(config, providedContext) {
|
|
200
|
-
const provider = "provider" in config ? config.provider : new JSONRPCHTTPProvider(config.nodeUrl);
|
|
201
|
-
const transport = custom(provider);
|
|
202
|
-
const viemClient = createPublicClient({ transport });
|
|
203
|
-
const chainId = (await viemClient.getChainId()).toString();
|
|
204
|
-
let networkName;
|
|
205
|
-
let saveDeployments;
|
|
206
|
-
let tags = {};
|
|
207
|
-
if ("nodeUrl" in config) {
|
|
208
|
-
networkName = config.networkName;
|
|
209
|
-
saveDeployments = true;
|
|
210
|
-
} else {
|
|
211
|
-
if (config.networkName) {
|
|
212
|
-
networkName = config.networkName;
|
|
213
|
-
} else {
|
|
214
|
-
networkName = "memory";
|
|
215
|
-
}
|
|
216
|
-
if (networkName === "memory" || networkName === "hardhat") {
|
|
217
|
-
tags["memory"] = true;
|
|
218
|
-
saveDeployments = false;
|
|
219
|
-
} else {
|
|
220
|
-
saveDeployments = true;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
const resolvedAccounts = {};
|
|
224
|
-
const accountCache = {};
|
|
225
|
-
async function getAccount(name, accounts, accountDef) {
|
|
226
|
-
if (accountCache[name]) {
|
|
227
|
-
return accountCache[name];
|
|
228
|
-
}
|
|
229
|
-
let account;
|
|
230
|
-
if (typeof accountDef === "number") {
|
|
231
|
-
const accounts2 = await provider.request({ method: "eth_accounts" });
|
|
232
|
-
const accountPerIndex = accounts2[accountDef];
|
|
233
|
-
if (accountPerIndex) {
|
|
234
|
-
accountCache[name] = account = {
|
|
235
|
-
type: "remote",
|
|
236
|
-
address: accountPerIndex,
|
|
237
|
-
signer: provider
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
} else if (typeof accountDef === "string") {
|
|
241
|
-
if (accountDef.startsWith("0x")) {
|
|
242
|
-
if (accountDef.length === 66) {
|
|
243
|
-
const privateKeyProtocol = globalThis.signerProtocols["privateKey"];
|
|
244
|
-
if (privateKeyProtocol) {
|
|
245
|
-
const namedSigner = await privateKeyProtocol.getSigner(`privateKey:${accountDef}`);
|
|
246
|
-
const [address] = await namedSigner.signer.request({ method: "eth_accounts" });
|
|
247
|
-
accountCache[name] = account = {
|
|
248
|
-
...namedSigner,
|
|
249
|
-
address
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
} else {
|
|
253
|
-
accountCache[name] = account = {
|
|
254
|
-
type: "remote",
|
|
255
|
-
address: accountDef,
|
|
256
|
-
signer: provider
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
} else {
|
|
260
|
-
if (accountDef.indexOf(":") > 0) {
|
|
261
|
-
const [protocolID, extra] = accountDef.split(":");
|
|
262
|
-
const protocol = globalThis.signerProtocols[protocolID];
|
|
263
|
-
if (!protocol) {
|
|
264
|
-
throw new Error(`protocol: ${protocol} is not supported`);
|
|
265
|
-
}
|
|
266
|
-
const namedSigner = await protocol.getSigner(accountDef);
|
|
267
|
-
const [address] = await namedSigner.signer.request({ method: "eth_accounts" });
|
|
268
|
-
accountCache[name] = account = {
|
|
269
|
-
...namedSigner,
|
|
270
|
-
address
|
|
271
|
-
};
|
|
272
|
-
} else {
|
|
273
|
-
const accountFetched = await getAccount(name, accounts, accounts[accountDef]);
|
|
274
|
-
if (accountFetched) {
|
|
275
|
-
accountCache[name] = account = accountFetched;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
} else {
|
|
280
|
-
const accountForNetwork = accountDef[networkName] || accountDef[chainId] || accountDef["default"];
|
|
281
|
-
if (typeof accountForNetwork !== void 0) {
|
|
282
|
-
const accountFetched = await getAccount(name, accounts, accountForNetwork);
|
|
283
|
-
if (accountFetched) {
|
|
284
|
-
accountCache[name] = account = accountFetched;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return account;
|
|
289
|
-
}
|
|
290
|
-
if (providedContext.accounts) {
|
|
291
|
-
const accountNames = Object.keys(providedContext.accounts);
|
|
292
|
-
for (const accountName of accountNames) {
|
|
293
|
-
let account = await getAccount(accountName, providedContext.accounts, providedContext.accounts[accountName]);
|
|
294
|
-
resolvedAccounts[accountName] = account;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
const context = {
|
|
298
|
-
accounts: resolvedAccounts,
|
|
299
|
-
artifacts: providedContext.artifacts,
|
|
300
|
-
network: {
|
|
301
|
-
name: networkName,
|
|
302
|
-
saveDeployments,
|
|
303
|
-
tags
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
const { deployments } = loadDeployments(config.deployments, context.network.name, false, chainId);
|
|
307
|
-
const namedAccounts = {};
|
|
308
|
-
const namedSigners = {};
|
|
309
|
-
const addressSigners = {};
|
|
310
|
-
for (const entry of Object.entries(resolvedAccounts)) {
|
|
311
|
-
const name = entry[0];
|
|
312
|
-
const { address, ...namedSigner } = entry[1];
|
|
313
|
-
namedAccounts[name] = address;
|
|
314
|
-
addressSigners[address] = namedSigner;
|
|
315
|
-
namedSigners[name] = namedSigner;
|
|
316
|
-
}
|
|
317
|
-
const perliminaryEnvironment = {
|
|
318
|
-
config,
|
|
319
|
-
deployments,
|
|
320
|
-
accounts: namedAccounts,
|
|
321
|
-
signers: namedSigners,
|
|
322
|
-
addressSigners,
|
|
323
|
-
artifacts: context.artifacts,
|
|
324
|
-
network: {
|
|
325
|
-
chainId,
|
|
326
|
-
name: context.network.name,
|
|
327
|
-
tags: context.network.tags,
|
|
328
|
-
provider
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
function ensureDeploymentFolder() {
|
|
332
|
-
const folderPath = path3.join(config.deployments, context.network.name);
|
|
333
|
-
fs3.mkdirSync(folderPath, { recursive: true });
|
|
334
|
-
const chainIdFilepath = path3.join(folderPath, ".chainId");
|
|
335
|
-
if (!fs3.existsSync(chainIdFilepath)) {
|
|
336
|
-
fs3.writeFileSync(chainIdFilepath, chainId);
|
|
337
|
-
}
|
|
338
|
-
return folderPath;
|
|
339
|
-
}
|
|
340
|
-
function get(name) {
|
|
341
|
-
return deployments[name];
|
|
342
|
-
}
|
|
343
|
-
async function save(name, deployment) {
|
|
344
|
-
deployments[name] = deployment;
|
|
345
|
-
if (context.network.saveDeployments) {
|
|
346
|
-
const folderPath = ensureDeploymentFolder();
|
|
347
|
-
fs3.writeFileSync(`${folderPath}/${name}.json`, JSONToString(deployment, 2));
|
|
348
|
-
}
|
|
349
|
-
return deployment;
|
|
350
|
-
}
|
|
351
|
-
async function recoverTransactionsIfAny() {
|
|
352
|
-
const folderPath = ensureDeploymentFolder();
|
|
353
|
-
const filepath = path3.join(folderPath, ".pending_transactions.json");
|
|
354
|
-
let existingPendingTansactions;
|
|
355
|
-
try {
|
|
356
|
-
existingPendingTansactions = stringToJSON(fs3.readFileSync(filepath, "utf-8"));
|
|
357
|
-
} catch {
|
|
358
|
-
existingPendingTansactions = [];
|
|
359
|
-
}
|
|
360
|
-
if (existingPendingTansactions.length > 0) {
|
|
361
|
-
while (existingPendingTansactions.length > 0) {
|
|
362
|
-
const pendingTransaction = existingPendingTansactions.shift();
|
|
363
|
-
if (pendingTransaction) {
|
|
364
|
-
if (pendingTransaction.type === "deployment") {
|
|
365
|
-
const spinner = spin(`recovering ${pendingTransaction.name} with transaction ${pendingTransaction.txHash}`);
|
|
366
|
-
try {
|
|
367
|
-
await waitForTransactionAndSave(pendingTransaction.name, pendingTransaction);
|
|
368
|
-
fs3.writeFileSync(filepath, JSONToString(existingPendingTansactions, 2));
|
|
369
|
-
spinner.succeed();
|
|
370
|
-
} catch (e) {
|
|
371
|
-
spinner.fail();
|
|
372
|
-
throw e;
|
|
373
|
-
}
|
|
374
|
-
} else {
|
|
375
|
-
const spinner = spin(`recovering execution's transaction ${pendingTransaction.txHash}`);
|
|
376
|
-
try {
|
|
377
|
-
await waitForTransaction(pendingTransaction.txHash);
|
|
378
|
-
fs3.writeFileSync(filepath, JSONToString(existingPendingTansactions, 2));
|
|
379
|
-
spinner.succeed();
|
|
380
|
-
} catch (e) {
|
|
381
|
-
spinner.fail();
|
|
382
|
-
throw e;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
fs3.rmSync(filepath);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
async function saveDeploymentTransaction(pendingDeployment) {
|
|
391
|
-
if (context.network.saveDeployments) {
|
|
392
|
-
const folderPath = ensureDeploymentFolder();
|
|
393
|
-
const filepath = path3.join(folderPath, ".pending_transactions.json");
|
|
394
|
-
let existingPendingDeployments;
|
|
395
|
-
try {
|
|
396
|
-
existingPendingDeployments = stringToJSON(fs3.readFileSync(filepath, "utf-8"));
|
|
397
|
-
} catch {
|
|
398
|
-
existingPendingDeployments = [];
|
|
399
|
-
}
|
|
400
|
-
existingPendingDeployments.push(pendingDeployment);
|
|
401
|
-
fs3.writeFileSync(filepath, JSONToString(existingPendingDeployments, 2));
|
|
402
|
-
}
|
|
403
|
-
return deployments;
|
|
404
|
-
}
|
|
405
|
-
async function deleteTransaction(hash) {
|
|
406
|
-
if (context.network.saveDeployments) {
|
|
407
|
-
const folderPath = ensureDeploymentFolder();
|
|
408
|
-
const filepath = path3.join(folderPath, ".pending_transactions.json");
|
|
409
|
-
let existingPendingDeployments;
|
|
410
|
-
try {
|
|
411
|
-
existingPendingDeployments = stringToJSON(fs3.readFileSync(filepath, "utf-8"));
|
|
412
|
-
} catch {
|
|
413
|
-
existingPendingDeployments = [];
|
|
414
|
-
}
|
|
415
|
-
existingPendingDeployments = existingPendingDeployments.filter((v) => v.transaction.txHash !== hash);
|
|
416
|
-
if (existingPendingDeployments.length === 0) {
|
|
417
|
-
fs3.rmSync(filepath);
|
|
418
|
-
} else {
|
|
419
|
-
fs3.writeFileSync(filepath, JSONToString(existingPendingDeployments, 2));
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
async function exportDeploymentsAsTypes() {
|
|
424
|
-
const folderPath = "./generated";
|
|
425
|
-
fs3.mkdirSync(folderPath, { recursive: true });
|
|
426
|
-
fs3.writeFileSync(`${folderPath}/deployments.ts`, `export default ${JSONToString(deployments, 2)} as const;`);
|
|
427
|
-
}
|
|
428
|
-
async function waitForTransaction(hash, message) {
|
|
429
|
-
const spinner = spin(message || "");
|
|
430
|
-
let receipt;
|
|
431
|
-
try {
|
|
432
|
-
receipt = await viemClient.waitForTransactionReceipt({
|
|
433
|
-
hash
|
|
434
|
-
});
|
|
435
|
-
} catch (e) {
|
|
436
|
-
spinner.fail();
|
|
437
|
-
throw e;
|
|
438
|
-
}
|
|
439
|
-
if (!receipt) {
|
|
440
|
-
throw new Error(`receipt for ${hash} not found`);
|
|
441
|
-
} else {
|
|
442
|
-
spinner.succeed();
|
|
443
|
-
}
|
|
444
|
-
return receipt;
|
|
445
|
-
}
|
|
446
|
-
async function waitForTransactionAndSave(name, pendingDeployment, transaction) {
|
|
447
|
-
const message = ` - Deploying ${name} with tx:
|
|
448
|
-
${pendingDeployment.txHash}${transaction ? `
|
|
449
|
-
${displayTransaction(transaction)}` : ""}`;
|
|
450
|
-
const receipt = await waitForTransaction(pendingDeployment.txHash, message);
|
|
451
|
-
if (!receipt.contractAddress) {
|
|
452
|
-
throw new Error(`failed to deploy contract ${name}`);
|
|
453
|
-
}
|
|
454
|
-
const { abi, ...artifactObjectWithoutABI } = pendingDeployment.partialDeployment;
|
|
455
|
-
if (!artifactObjectWithoutABI.nonce) {
|
|
456
|
-
const spinner = spin();
|
|
457
|
-
let transaction2 = null;
|
|
458
|
-
try {
|
|
459
|
-
transaction2 = await provider.request({
|
|
460
|
-
method: "eth_getTransactionByHash",
|
|
461
|
-
params: [pendingDeployment.txHash]
|
|
462
|
-
});
|
|
463
|
-
} catch (e) {
|
|
464
|
-
spinner.fail();
|
|
465
|
-
throw e;
|
|
466
|
-
}
|
|
467
|
-
if (!transaction2) {
|
|
468
|
-
spinner.fail(`tx ${pendingDeployment.txHash} not found`);
|
|
469
|
-
} else {
|
|
470
|
-
spinner.stop();
|
|
471
|
-
}
|
|
472
|
-
if (transaction2) {
|
|
473
|
-
artifactObjectWithoutABI.nonce = transaction2.nonce;
|
|
474
|
-
artifactObjectWithoutABI.txOrigin = transaction2.from;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
for (const key of Object.keys(artifactObjectWithoutABI)) {
|
|
478
|
-
if (key.startsWith("_")) {
|
|
479
|
-
delete artifactObjectWithoutABI[key];
|
|
480
|
-
}
|
|
481
|
-
if (key === "evm") {
|
|
482
|
-
const { gasEstimates } = artifactObjectWithoutABI.evm;
|
|
483
|
-
artifactObjectWithoutABI.evm = {
|
|
484
|
-
gasEstimates
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
const deployment = {
|
|
489
|
-
address: receipt.contractAddress,
|
|
490
|
-
txHash: pendingDeployment.txHash,
|
|
491
|
-
abi,
|
|
492
|
-
...artifactObjectWithoutABI
|
|
493
|
-
};
|
|
494
|
-
return save(name, deployment);
|
|
495
|
-
}
|
|
496
|
-
async function saveWhilePending(name, pendingDeployment) {
|
|
497
|
-
await saveDeploymentTransaction(name, pendingDeployment);
|
|
498
|
-
let transaction = null;
|
|
499
|
-
const spinner = spin();
|
|
500
|
-
try {
|
|
501
|
-
transaction = await provider.request({
|
|
502
|
-
method: "eth_getTransactionByHash",
|
|
503
|
-
params: [pendingDeployment.txHash]
|
|
504
|
-
});
|
|
505
|
-
} catch (e) {
|
|
506
|
-
spinner.fail();
|
|
507
|
-
throw e;
|
|
508
|
-
}
|
|
509
|
-
if (!transaction) {
|
|
510
|
-
spinner.fail(`tx ${pendingDeployment.txHash} not found`);
|
|
511
|
-
} else {
|
|
512
|
-
spinner.stop();
|
|
513
|
-
}
|
|
514
|
-
const deployment = await waitForTransactionAndSave(
|
|
515
|
-
name,
|
|
516
|
-
transaction ? {
|
|
517
|
-
...pendingDeployment,
|
|
518
|
-
nonce: transaction.nonce,
|
|
519
|
-
txOrigin: transaction.from
|
|
520
|
-
} : pendingDeployment,
|
|
521
|
-
transaction
|
|
522
|
-
);
|
|
523
|
-
await deleteTransaction(pendingDeployment.txHash);
|
|
524
|
-
return deployment;
|
|
525
|
-
}
|
|
526
|
-
let env = {
|
|
527
|
-
...perliminaryEnvironment,
|
|
528
|
-
save,
|
|
529
|
-
saveWhilePending,
|
|
530
|
-
get
|
|
531
|
-
};
|
|
532
|
-
for (const extension of globalThis.extensions) {
|
|
533
|
-
env = extension(env);
|
|
534
|
-
}
|
|
535
|
-
return {
|
|
536
|
-
external: env,
|
|
537
|
-
internal: {
|
|
538
|
-
exportDeploymentsAsTypes,
|
|
539
|
-
recoverTransactionsIfAny
|
|
540
|
-
}
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
// src/executor/index.ts
|
|
545
|
-
__require("esbuild-register/dist/node").register();
|
|
546
|
-
function execute(context, callback, options) {
|
|
547
|
-
const scriptModule = (env) => callback(env);
|
|
548
|
-
scriptModule.providedContext = context;
|
|
549
|
-
scriptModule.tags = options.tags;
|
|
550
|
-
scriptModule.dependencies = options.dependencies;
|
|
551
|
-
return scriptModule;
|
|
552
|
-
}
|
|
553
|
-
function readConfig(options, extra) {
|
|
554
|
-
let configFile;
|
|
555
|
-
try {
|
|
556
|
-
const configString = fs4.readFileSync("./rocketh.json", "utf-8");
|
|
557
|
-
configFile = JSON.parse(configString);
|
|
558
|
-
} catch {
|
|
559
|
-
}
|
|
560
|
-
let nodeUrl;
|
|
561
|
-
const fromEnv = process.env["ETH_NODE_URI_" + options.network];
|
|
562
|
-
if (typeof fromEnv === "string") {
|
|
563
|
-
nodeUrl = fromEnv;
|
|
564
|
-
} else {
|
|
565
|
-
if (configFile) {
|
|
566
|
-
const network = configFile.networks && configFile.networks[options.network];
|
|
567
|
-
if (network) {
|
|
568
|
-
nodeUrl = network.rpcUrl;
|
|
569
|
-
} else {
|
|
570
|
-
if (extra?.ignoreMissingRPC) {
|
|
571
|
-
nodeUrl = "";
|
|
572
|
-
} else {
|
|
573
|
-
if (options.network === "localhost") {
|
|
574
|
-
nodeUrl = "http://127.0.0.1:8545";
|
|
575
|
-
} else {
|
|
576
|
-
logger.error(`network "${options.network}" is not configured. Please add it to the rocketh.json file`);
|
|
577
|
-
process.exit(1);
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
} else {
|
|
582
|
-
if (extra?.ignoreMissingRPC) {
|
|
583
|
-
nodeUrl = "";
|
|
584
|
-
} else {
|
|
585
|
-
if (options.network === "localhost") {
|
|
586
|
-
nodeUrl = "http://127.0.0.1:8545";
|
|
587
|
-
} else {
|
|
588
|
-
logger.error(`network "${options.network}" is not configured. Please add it to the rocketh.json file`);
|
|
589
|
-
process.exit(1);
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
return {
|
|
595
|
-
nodeUrl,
|
|
596
|
-
networkName: options.network,
|
|
597
|
-
deployments: options.deployments,
|
|
598
|
-
scripts: options.scripts,
|
|
599
|
-
tags: typeof options.tags === "undefined" ? void 0 : options.tags.split(",")
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
|
-
function readAndResolveConfig(options, extra) {
|
|
603
|
-
return resolveConfig(readConfig(options, extra));
|
|
604
|
-
}
|
|
605
|
-
function resolveConfig(config) {
|
|
606
|
-
const resolvedConfig = {
|
|
607
|
-
...config,
|
|
608
|
-
networkName: config.networkName || "memory",
|
|
609
|
-
deployments: config.deployments || "deployments",
|
|
610
|
-
scripts: config.scripts || "deploy",
|
|
611
|
-
tags: config.tags || []
|
|
612
|
-
};
|
|
613
|
-
return resolvedConfig;
|
|
614
|
-
}
|
|
615
|
-
async function loadAndExecuteDeployments(config) {
|
|
616
|
-
const resolvedConfig = resolveConfig(config);
|
|
617
|
-
return executeDeployScripts(resolvedConfig);
|
|
618
|
-
}
|
|
619
|
-
async function executeDeployScripts(config) {
|
|
620
|
-
setLogLevel(typeof config.logLevel === "undefined" ? 0 : config.logLevel);
|
|
621
|
-
let filepaths;
|
|
622
|
-
filepaths = traverseMultipleDirectory([config.scripts]);
|
|
623
|
-
filepaths = filepaths.filter((v) => !path4.basename(v).startsWith("_")).sort((a, b) => {
|
|
624
|
-
if (a < b) {
|
|
625
|
-
return -1;
|
|
626
|
-
}
|
|
627
|
-
if (a > b) {
|
|
628
|
-
return 1;
|
|
629
|
-
}
|
|
630
|
-
return 0;
|
|
631
|
-
});
|
|
632
|
-
let providedContext;
|
|
633
|
-
const scriptModuleByFilePath = {};
|
|
634
|
-
const scriptPathBags = {};
|
|
635
|
-
const scriptFilePaths = [];
|
|
636
|
-
for (const filepath of filepaths) {
|
|
637
|
-
const scriptFilePath = path4.resolve(filepath);
|
|
638
|
-
let scriptModule;
|
|
639
|
-
try {
|
|
640
|
-
if (__require.cache) {
|
|
641
|
-
delete __require.cache[scriptFilePath];
|
|
642
|
-
}
|
|
643
|
-
scriptModule = __require(scriptFilePath);
|
|
644
|
-
if (scriptModule.default) {
|
|
645
|
-
scriptModule = scriptModule.default;
|
|
646
|
-
if (scriptModule.default) {
|
|
647
|
-
logger.warn(`double default...`);
|
|
648
|
-
scriptModule = scriptModule.default;
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
scriptModuleByFilePath[scriptFilePath] = scriptModule;
|
|
652
|
-
if (providedContext && providedContext !== scriptModule.providedContext) {
|
|
653
|
-
throw new Error(`context between 2 scripts is different, please share the same across them`);
|
|
654
|
-
}
|
|
655
|
-
providedContext = scriptModule.providedContext;
|
|
656
|
-
} catch (e) {
|
|
657
|
-
logger.error(`could not import ${filepath}`);
|
|
658
|
-
throw e;
|
|
659
|
-
}
|
|
660
|
-
let scriptTags = scriptModule.tags;
|
|
661
|
-
if (scriptTags !== void 0) {
|
|
662
|
-
if (typeof scriptTags === "string") {
|
|
663
|
-
scriptTags = [scriptTags];
|
|
664
|
-
}
|
|
665
|
-
for (const tag of scriptTags) {
|
|
666
|
-
if (tag.indexOf(",") >= 0) {
|
|
667
|
-
throw new Error("Tag cannot contains commas");
|
|
668
|
-
}
|
|
669
|
-
const bag = scriptPathBags[tag] || [];
|
|
670
|
-
scriptPathBags[tag] = bag;
|
|
671
|
-
bag.push(scriptFilePath);
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
if (config.tags !== void 0 && config.tags.length > 0) {
|
|
675
|
-
let found = false;
|
|
676
|
-
if (scriptTags !== void 0) {
|
|
677
|
-
for (const tagToFind of config.tags) {
|
|
678
|
-
for (const tag of scriptTags) {
|
|
679
|
-
if (tag === tagToFind) {
|
|
680
|
-
scriptFilePaths.push(scriptFilePath);
|
|
681
|
-
found = true;
|
|
682
|
-
break;
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
if (found) {
|
|
686
|
-
break;
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
} else {
|
|
691
|
-
scriptFilePaths.push(scriptFilePath);
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
if (!providedContext) {
|
|
695
|
-
throw new Error(`no context loaded`);
|
|
696
|
-
}
|
|
697
|
-
const { internal, external } = await createEnvironment(config, providedContext);
|
|
698
|
-
await internal.recoverTransactionsIfAny();
|
|
699
|
-
const scriptsRegisteredToRun = {};
|
|
700
|
-
const scriptsToRun = [];
|
|
701
|
-
const scriptsToRunAtTheEnd = [];
|
|
702
|
-
function recurseDependencies(scriptFilePath) {
|
|
703
|
-
if (scriptsRegisteredToRun[scriptFilePath]) {
|
|
704
|
-
return;
|
|
705
|
-
}
|
|
706
|
-
const scriptModule = scriptModuleByFilePath[scriptFilePath];
|
|
707
|
-
if (scriptModule.dependencies) {
|
|
708
|
-
for (const dependency of scriptModule.dependencies) {
|
|
709
|
-
const scriptFilePathsToAdd = scriptPathBags[dependency];
|
|
710
|
-
if (scriptFilePathsToAdd) {
|
|
711
|
-
for (const scriptFilenameToAdd of scriptFilePathsToAdd) {
|
|
712
|
-
recurseDependencies(scriptFilenameToAdd);
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
if (!scriptsRegisteredToRun[scriptFilePath]) {
|
|
718
|
-
if (scriptModule.runAtTheEnd) {
|
|
719
|
-
scriptsToRunAtTheEnd.push({
|
|
720
|
-
filePath: scriptFilePath,
|
|
721
|
-
func: scriptModule
|
|
722
|
-
});
|
|
723
|
-
} else {
|
|
724
|
-
scriptsToRun.push({
|
|
725
|
-
filePath: scriptFilePath,
|
|
726
|
-
func: scriptModule
|
|
727
|
-
});
|
|
728
|
-
}
|
|
729
|
-
scriptsRegisteredToRun[scriptFilePath] = true;
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
for (const scriptFilePath of scriptFilePaths) {
|
|
733
|
-
recurseDependencies(scriptFilePath);
|
|
734
|
-
}
|
|
735
|
-
for (const deployScript of scriptsToRun.concat(scriptsToRunAtTheEnd)) {
|
|
736
|
-
const filename = path4.basename(deployScript.filePath);
|
|
737
|
-
const relativeFilepath = path4.relative(".", deployScript.filePath);
|
|
738
|
-
let skip = false;
|
|
739
|
-
const spinner = spin(`- Executing ${filename}`);
|
|
740
|
-
if (deployScript.func.skip) {
|
|
741
|
-
const spinner2 = spin(` - skip?()`);
|
|
742
|
-
try {
|
|
743
|
-
skip = await deployScript.func.skip(external);
|
|
744
|
-
spinner2.succeed(skip ? `skipping ${filename}` : void 0);
|
|
745
|
-
} catch (e) {
|
|
746
|
-
spinner2.fail();
|
|
747
|
-
throw e;
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
if (!skip) {
|
|
751
|
-
let result;
|
|
752
|
-
try {
|
|
753
|
-
result = await deployScript.func(external);
|
|
754
|
-
spinner.succeed(`
|
|
755
|
-
`);
|
|
756
|
-
} catch (e) {
|
|
757
|
-
spinner.fail();
|
|
758
|
-
throw e;
|
|
759
|
-
}
|
|
760
|
-
if (result && typeof result === "boolean") {
|
|
761
|
-
const deploymentFolderPath = config.deployments;
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
return external.deployments;
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
export {
|
|
769
|
-
loadDeployments,
|
|
770
|
-
extendEnvironment,
|
|
771
|
-
handleSignerProtocol,
|
|
772
|
-
execute,
|
|
773
|
-
readConfig,
|
|
774
|
-
readAndResolveConfig,
|
|
775
|
-
resolveConfig,
|
|
776
|
-
loadAndExecuteDeployments,
|
|
777
|
-
executeDeployScripts
|
|
778
|
-
};
|
|
779
|
-
//# sourceMappingURL=chunk-CWIC3RNX.js.map
|