rocketh 0.4.41 → 0.5.1
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/.prettierignore +3 -0
- package/.prettierrc +7 -0
- package/CHANGELOG.md +7 -0
- package/README.md +1 -21
- package/dist/chunk-KWY4QLNL.js +648 -0
- package/dist/chunk-KWY4QLNL.js.map +1 -0
- package/dist/cli.cjs +697 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +66 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +684 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +186 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -20
- package/src/cli.ts +37 -0
- package/src/environment/deployments.ts +79 -0
- package/src/environment/index.ts +392 -0
- package/src/environment/types.ts +158 -0
- package/src/executor/index.ts +302 -0
- package/src/executor/types.ts +42 -0
- package/src/index.ts +5 -0
- package/src/internal/types.ts +6 -0
- package/src/utils/fs.ts +70 -0
- package/src/utils/json.ts +26 -0
- package/tsconfig.json +15 -0
- package/tsup.config.ts +5 -0
- package/.gitattributes +0 -1
- package/bitski_subprovider.js +0 -148
- package/geth_test_server.js +0 -194
- package/index.js +0 -424
- package/provider.js +0 -58
- package/providerengine.js +0 -128
- package/run.js +0 -1575
- package/run_ganache.js +0 -27
- package/utils.js +0 -188
- package/walletprovider.js +0 -232
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,684 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
execute: () => execute,
|
|
34
|
+
executeDeployScripts: () => executeDeployScripts,
|
|
35
|
+
extendEnvironment: () => extendEnvironment,
|
|
36
|
+
handleSignerProtocol: () => handleSignerProtocol,
|
|
37
|
+
loadAndExecuteDeployments: () => loadAndExecuteDeployments,
|
|
38
|
+
loadDeployments: () => loadDeployments,
|
|
39
|
+
readAndResolveConfig: () => readAndResolveConfig,
|
|
40
|
+
readConfig: () => readConfig,
|
|
41
|
+
resolveConfig: () => resolveConfig
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(src_exports);
|
|
44
|
+
|
|
45
|
+
// src/utils/fs.ts
|
|
46
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
47
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
48
|
+
function traverseMultipleDirectory(dirs) {
|
|
49
|
+
const filepaths = [];
|
|
50
|
+
for (const dir of dirs) {
|
|
51
|
+
let filesStats = traverse(dir);
|
|
52
|
+
filesStats = filesStats.filter((v) => !v.directory);
|
|
53
|
+
for (const filestat of filesStats) {
|
|
54
|
+
filepaths.push(import_node_path.default.join(dir, filestat.relativePath));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return filepaths;
|
|
58
|
+
}
|
|
59
|
+
var traverse = function(dir, result = [], topDir, filter) {
|
|
60
|
+
import_node_fs.default.readdirSync(dir).forEach((name) => {
|
|
61
|
+
const fPath = import_node_path.default.resolve(dir, name);
|
|
62
|
+
const stats = import_node_fs.default.statSync(fPath);
|
|
63
|
+
if (!filter && !name.startsWith(".") || filter && filter(name, stats)) {
|
|
64
|
+
const fileStats = {
|
|
65
|
+
name,
|
|
66
|
+
path: fPath,
|
|
67
|
+
relativePath: import_node_path.default.relative(topDir || dir, fPath),
|
|
68
|
+
mtimeMs: stats.mtimeMs,
|
|
69
|
+
directory: stats.isDirectory()
|
|
70
|
+
};
|
|
71
|
+
if (fileStats.directory) {
|
|
72
|
+
result.push(fileStats);
|
|
73
|
+
return traverse(fPath, result, topDir || dir, filter);
|
|
74
|
+
}
|
|
75
|
+
result.push(fileStats);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return result;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/executor/index.ts
|
|
82
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
83
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
84
|
+
|
|
85
|
+
// src/environment/index.ts
|
|
86
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
87
|
+
var import_viem = require("viem");
|
|
88
|
+
var import_eip_1193_json_provider = require("eip-1193-json-provider");
|
|
89
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
90
|
+
|
|
91
|
+
// src/utils/json.ts
|
|
92
|
+
function bnReplacer(k, v) {
|
|
93
|
+
if (typeof v === "bigint") {
|
|
94
|
+
return v.toString() + "n";
|
|
95
|
+
}
|
|
96
|
+
return v;
|
|
97
|
+
}
|
|
98
|
+
function bnReviver(k, v) {
|
|
99
|
+
if (typeof v === "string" && (v.startsWith("-") ? !isNaN(parseInt(v.charAt(1))) : !isNaN(parseInt(v.charAt(0)))) && v.charAt(v.length - 1) === "n") {
|
|
100
|
+
return BigInt(v.slice(0, -1));
|
|
101
|
+
}
|
|
102
|
+
return v;
|
|
103
|
+
}
|
|
104
|
+
function JSONToString(json, space) {
|
|
105
|
+
return JSON.stringify(json, bnReplacer, space);
|
|
106
|
+
}
|
|
107
|
+
function stringToJSON(str) {
|
|
108
|
+
return JSON.parse(str, bnReviver);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/environment/deployments.ts
|
|
112
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
113
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
114
|
+
function loadDeployments(deploymentsPath, subPath, onlyABIAndAddress, expectedChainId) {
|
|
115
|
+
const deploymentsFound = {};
|
|
116
|
+
const deployPath = import_node_path2.default.join(deploymentsPath, subPath);
|
|
117
|
+
let filesStats;
|
|
118
|
+
try {
|
|
119
|
+
filesStats = traverse(deployPath, void 0, void 0, (name) => !name.startsWith(".") && name !== "solcInputs");
|
|
120
|
+
} catch (e) {
|
|
121
|
+
return { deployments: {} };
|
|
122
|
+
}
|
|
123
|
+
let chainId;
|
|
124
|
+
if (filesStats.length > 0) {
|
|
125
|
+
const chainIdFilepath = import_node_path2.default.join(deployPath, ".chainId");
|
|
126
|
+
if (import_node_fs2.default.existsSync(chainIdFilepath)) {
|
|
127
|
+
chainId = import_node_fs2.default.readFileSync(chainIdFilepath).toString().trim();
|
|
128
|
+
} else {
|
|
129
|
+
throw new Error(`A .chainId' file is expected to be present in the deployment folder for network ${subPath}`);
|
|
130
|
+
}
|
|
131
|
+
if (expectedChainId) {
|
|
132
|
+
if (expectedChainId !== chainId) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
`Loading deployment in folder '${deployPath}' (with chainId: ${chainId}) for a different chainId (${expectedChainId})`
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
return { deployments: {} };
|
|
140
|
+
}
|
|
141
|
+
let fileNames = filesStats.map((a) => a.relativePath);
|
|
142
|
+
fileNames = fileNames.sort((a, b) => {
|
|
143
|
+
if (a < b) {
|
|
144
|
+
return -1;
|
|
145
|
+
}
|
|
146
|
+
if (a > b) {
|
|
147
|
+
return 1;
|
|
148
|
+
}
|
|
149
|
+
return 0;
|
|
150
|
+
});
|
|
151
|
+
for (const fileName of fileNames) {
|
|
152
|
+
if (fileName.substring(fileName.length - 5) === ".json") {
|
|
153
|
+
const deploymentFileName = import_node_path2.default.join(deployPath, fileName);
|
|
154
|
+
let deployment = JSON.parse(import_node_fs2.default.readFileSync(deploymentFileName).toString());
|
|
155
|
+
if (onlyABIAndAddress) {
|
|
156
|
+
deployment = {
|
|
157
|
+
address: deployment.address,
|
|
158
|
+
abi: deployment.abi,
|
|
159
|
+
linkedData: deployment.linkedData
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const name = fileName.slice(0, fileName.length - 5);
|
|
163
|
+
deploymentsFound[name] = deployment;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return { deployments: deploymentsFound, chainId };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// src/environment/index.ts
|
|
170
|
+
globalThis.extensions = [];
|
|
171
|
+
function extendEnvironment(extension) {
|
|
172
|
+
globalThis.extensions.push(extension);
|
|
173
|
+
}
|
|
174
|
+
globalThis.signerProtocols = {};
|
|
175
|
+
function handleSignerProtocol(protocol, getSigner) {
|
|
176
|
+
globalThis.signerProtocols[protocol] = {
|
|
177
|
+
getSigner
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
async function createEnvironment(config, providedContext) {
|
|
181
|
+
const provider = "provider" in config ? config.provider : new import_eip_1193_json_provider.JSONRPCHTTPProvider(config.nodeUrl);
|
|
182
|
+
const transport = (0, import_viem.custom)(provider);
|
|
183
|
+
const viemClient = (0, import_viem.createPublicClient)({ transport });
|
|
184
|
+
const chainId = (await viemClient.getChainId()).toString();
|
|
185
|
+
let networkName;
|
|
186
|
+
let saveDeployments;
|
|
187
|
+
let tags = {};
|
|
188
|
+
if ("nodeUrl" in config) {
|
|
189
|
+
networkName = config.networkName;
|
|
190
|
+
saveDeployments = true;
|
|
191
|
+
} else {
|
|
192
|
+
if (config.networkName) {
|
|
193
|
+
networkName = config.networkName;
|
|
194
|
+
} else {
|
|
195
|
+
networkName = "memory";
|
|
196
|
+
}
|
|
197
|
+
if (networkName === "memory" || networkName === "hardhat") {
|
|
198
|
+
tags["memory"] = true;
|
|
199
|
+
saveDeployments = false;
|
|
200
|
+
} else {
|
|
201
|
+
saveDeployments = true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const resolvedAccounts = {};
|
|
205
|
+
const accountCache = {};
|
|
206
|
+
async function getAccount(name, accounts, accountDef) {
|
|
207
|
+
if (accountCache[name]) {
|
|
208
|
+
return accountCache[name];
|
|
209
|
+
}
|
|
210
|
+
let account;
|
|
211
|
+
if (typeof accountDef === "number") {
|
|
212
|
+
const accounts2 = await provider.request({ method: "eth_accounts" });
|
|
213
|
+
const accountPerIndex = accounts2[accountDef];
|
|
214
|
+
if (accountPerIndex) {
|
|
215
|
+
accountCache[name] = account = {
|
|
216
|
+
type: "remote",
|
|
217
|
+
address: accountPerIndex,
|
|
218
|
+
signer: provider
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
} else if (typeof accountDef === "string") {
|
|
222
|
+
if (accountDef.startsWith("0x")) {
|
|
223
|
+
if (accountDef.length === 66) {
|
|
224
|
+
const privateKeyProtocol = globalThis.signerProtocols["privateKey"];
|
|
225
|
+
if (privateKeyProtocol) {
|
|
226
|
+
const namedSigner = await privateKeyProtocol.getSigner(`privateKey:${accountDef}`);
|
|
227
|
+
const [address] = await namedSigner.signer.request({ method: "eth_accounts" });
|
|
228
|
+
accountCache[name] = account = {
|
|
229
|
+
...namedSigner,
|
|
230
|
+
address
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
} else {
|
|
234
|
+
accountCache[name] = account = {
|
|
235
|
+
type: "remote",
|
|
236
|
+
address: accountDef,
|
|
237
|
+
signer: provider
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
if (accountDef.indexOf(":") > 0) {
|
|
242
|
+
const [protocolID, extra] = accountDef.split(":");
|
|
243
|
+
const protocol = globalThis.signerProtocols[protocolID];
|
|
244
|
+
if (!protocol) {
|
|
245
|
+
throw new Error(`protocol: ${protocol} is not supported`);
|
|
246
|
+
}
|
|
247
|
+
const namedSigner = await protocol.getSigner(accountDef);
|
|
248
|
+
const [address] = await namedSigner.signer.request({ method: "eth_accounts" });
|
|
249
|
+
accountCache[name] = account = {
|
|
250
|
+
...namedSigner,
|
|
251
|
+
address
|
|
252
|
+
};
|
|
253
|
+
} else {
|
|
254
|
+
const accountFetched = await getAccount(name, accounts, accounts[accountDef]);
|
|
255
|
+
if (accountFetched) {
|
|
256
|
+
accountCache[name] = account = accountFetched;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
const accountForNetwork = accountDef[networkName] || accountDef[chainId] || accountDef["default"];
|
|
262
|
+
if (accountForNetwork) {
|
|
263
|
+
const accountFetched = await getAccount(name, accounts, accountForNetwork);
|
|
264
|
+
if (accountFetched) {
|
|
265
|
+
accountCache[name] = account = accountFetched;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return account;
|
|
270
|
+
}
|
|
271
|
+
if (providedContext.accounts) {
|
|
272
|
+
const accountNames = Object.keys(providedContext.accounts);
|
|
273
|
+
for (const accountName of accountNames) {
|
|
274
|
+
let account = await getAccount(accountName, providedContext.accounts, providedContext.accounts[accountName]);
|
|
275
|
+
resolvedAccounts[accountName] = account;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const context = {
|
|
279
|
+
accounts: resolvedAccounts,
|
|
280
|
+
artifacts: providedContext.artifacts,
|
|
281
|
+
network: {
|
|
282
|
+
name: networkName,
|
|
283
|
+
saveDeployments,
|
|
284
|
+
tags
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
const { deployments } = loadDeployments(config.deployments, context.network.name, false, chainId);
|
|
288
|
+
const namedAccounts = {};
|
|
289
|
+
const namedSigners = {};
|
|
290
|
+
const addressSigners = {};
|
|
291
|
+
for (const entry of Object.entries(resolvedAccounts)) {
|
|
292
|
+
const name = entry[0];
|
|
293
|
+
const { address, ...namedSigner } = entry[1];
|
|
294
|
+
namedAccounts[name] = address;
|
|
295
|
+
addressSigners[address] = namedSigner;
|
|
296
|
+
namedSigners[name] = namedSigner;
|
|
297
|
+
}
|
|
298
|
+
const perliminaryEnvironment = {
|
|
299
|
+
config,
|
|
300
|
+
deployments,
|
|
301
|
+
accounts: namedAccounts,
|
|
302
|
+
signers: namedSigners,
|
|
303
|
+
addressSigners,
|
|
304
|
+
artifacts: context.artifacts,
|
|
305
|
+
network: {
|
|
306
|
+
chainId,
|
|
307
|
+
name: context.network.name,
|
|
308
|
+
tags: context.network.tags,
|
|
309
|
+
provider
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
function ensureDeploymentFolder() {
|
|
313
|
+
const folderPath = import_node_path3.default.join(config.deployments, context.network.name);
|
|
314
|
+
import_node_fs3.default.mkdirSync(folderPath, { recursive: true });
|
|
315
|
+
const chainIdFilepath = import_node_path3.default.join(folderPath, ".chainId");
|
|
316
|
+
if (!import_node_fs3.default.existsSync(chainIdFilepath)) {
|
|
317
|
+
import_node_fs3.default.writeFileSync(chainIdFilepath, chainId);
|
|
318
|
+
}
|
|
319
|
+
return folderPath;
|
|
320
|
+
}
|
|
321
|
+
function get(name) {
|
|
322
|
+
return deployments[name];
|
|
323
|
+
}
|
|
324
|
+
async function save(name, deployment) {
|
|
325
|
+
deployments[name] = deployment;
|
|
326
|
+
if (context.network.saveDeployments) {
|
|
327
|
+
const folderPath = ensureDeploymentFolder();
|
|
328
|
+
import_node_fs3.default.writeFileSync(`${folderPath}/${name}.json`, JSONToString(deployment, 2));
|
|
329
|
+
}
|
|
330
|
+
return deployment;
|
|
331
|
+
}
|
|
332
|
+
async function recoverTransactionsIfAny() {
|
|
333
|
+
const filepath = import_node_path3.default.join(config.deployments, context.network.name, ".pending_transactions.json");
|
|
334
|
+
let existingPendingDeployments;
|
|
335
|
+
try {
|
|
336
|
+
existingPendingDeployments = stringToJSON(import_node_fs3.default.readFileSync(filepath, "utf-8"));
|
|
337
|
+
} catch {
|
|
338
|
+
existingPendingDeployments = [];
|
|
339
|
+
}
|
|
340
|
+
if (existingPendingDeployments.length > 0) {
|
|
341
|
+
while (existingPendingDeployments.length > 0) {
|
|
342
|
+
const pendingTransaction = existingPendingDeployments.shift();
|
|
343
|
+
if (pendingTransaction) {
|
|
344
|
+
console.log(
|
|
345
|
+
`recovering ${pendingTransaction.name} with transaction ${pendingTransaction.transaction.txHash}`
|
|
346
|
+
);
|
|
347
|
+
await waitForTransactionAndSave(pendingTransaction.name, pendingTransaction.transaction);
|
|
348
|
+
console.log(`transaction ${pendingTransaction.transaction.txHash} complete`);
|
|
349
|
+
import_node_fs3.default.writeFileSync(filepath, JSONToString(existingPendingDeployments, 2));
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
import_node_fs3.default.rmSync(filepath);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
async function saveTransaction(name, transaction) {
|
|
356
|
+
if (context.network.saveDeployments) {
|
|
357
|
+
const folderPath = ensureDeploymentFolder();
|
|
358
|
+
const filepath = import_node_path3.default.join(folderPath, ".pending_transactions.json");
|
|
359
|
+
let existingPendingDeployments;
|
|
360
|
+
try {
|
|
361
|
+
existingPendingDeployments = stringToJSON(import_node_fs3.default.readFileSync(filepath, "utf-8"));
|
|
362
|
+
} catch {
|
|
363
|
+
existingPendingDeployments = [];
|
|
364
|
+
}
|
|
365
|
+
existingPendingDeployments.push({ name, transaction });
|
|
366
|
+
import_node_fs3.default.writeFileSync(filepath, JSONToString(existingPendingDeployments, 2));
|
|
367
|
+
}
|
|
368
|
+
return deployments;
|
|
369
|
+
}
|
|
370
|
+
async function deleteTransaction(hash) {
|
|
371
|
+
if (context.network.saveDeployments) {
|
|
372
|
+
const filepath = import_node_path3.default.join(config.deployments, context.network.name, ".pending_transactions.json");
|
|
373
|
+
let existingPendingDeployments;
|
|
374
|
+
try {
|
|
375
|
+
existingPendingDeployments = stringToJSON(import_node_fs3.default.readFileSync(filepath, "utf-8"));
|
|
376
|
+
} catch {
|
|
377
|
+
existingPendingDeployments = [];
|
|
378
|
+
}
|
|
379
|
+
existingPendingDeployments = existingPendingDeployments.filter((v) => v.transaction.txHash !== hash);
|
|
380
|
+
if (existingPendingDeployments.length === 0) {
|
|
381
|
+
import_node_fs3.default.rmSync(filepath);
|
|
382
|
+
} else {
|
|
383
|
+
import_node_fs3.default.writeFileSync(filepath, JSONToString(existingPendingDeployments, 2));
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
async function exportDeploymentsAsTypes() {
|
|
388
|
+
const folderPath = "./generated";
|
|
389
|
+
import_node_fs3.default.mkdirSync(folderPath, { recursive: true });
|
|
390
|
+
import_node_fs3.default.writeFileSync(`${folderPath}/deployments.ts`, `export default ${JSONToString(deployments, 2)} as const;`);
|
|
391
|
+
}
|
|
392
|
+
async function waitForTransactionAndSave(name, pendingDeployment) {
|
|
393
|
+
const receipt = await viemClient.waitForTransactionReceipt({
|
|
394
|
+
hash: pendingDeployment.txHash
|
|
395
|
+
});
|
|
396
|
+
if (!receipt.contractAddress) {
|
|
397
|
+
throw new Error(`failed to deploy contract ${name}`);
|
|
398
|
+
}
|
|
399
|
+
const { abi, ...artifactObjectWithoutABI } = pendingDeployment.partialDeployment;
|
|
400
|
+
if (!artifactObjectWithoutABI.nonce) {
|
|
401
|
+
const transaction = await provider.request({
|
|
402
|
+
method: "eth_getTransactionByHash",
|
|
403
|
+
params: [pendingDeployment.txHash]
|
|
404
|
+
});
|
|
405
|
+
if (transaction) {
|
|
406
|
+
artifactObjectWithoutABI.nonce = transaction.nonce;
|
|
407
|
+
artifactObjectWithoutABI.txOrigin = transaction.from;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
for (const key of Object.keys(artifactObjectWithoutABI)) {
|
|
411
|
+
if (key.startsWith("_")) {
|
|
412
|
+
delete artifactObjectWithoutABI[key];
|
|
413
|
+
}
|
|
414
|
+
if (key === "evm") {
|
|
415
|
+
const { gasEstimates } = artifactObjectWithoutABI.evm;
|
|
416
|
+
artifactObjectWithoutABI.evm = {
|
|
417
|
+
gasEstimates
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
const deployment = {
|
|
422
|
+
address: receipt.contractAddress,
|
|
423
|
+
txHash: pendingDeployment.txHash,
|
|
424
|
+
abi,
|
|
425
|
+
...artifactObjectWithoutABI
|
|
426
|
+
};
|
|
427
|
+
return save(name, deployment);
|
|
428
|
+
}
|
|
429
|
+
async function saveWhilePending(name, pendingDeployment) {
|
|
430
|
+
await saveTransaction(name, pendingDeployment);
|
|
431
|
+
const transaction = await provider.request({
|
|
432
|
+
method: "eth_getTransactionByHash",
|
|
433
|
+
params: [pendingDeployment.txHash]
|
|
434
|
+
});
|
|
435
|
+
const deployment = waitForTransactionAndSave(
|
|
436
|
+
name,
|
|
437
|
+
transaction ? {
|
|
438
|
+
...pendingDeployment,
|
|
439
|
+
nonce: transaction.nonce,
|
|
440
|
+
txOrigin: transaction.from
|
|
441
|
+
} : pendingDeployment
|
|
442
|
+
);
|
|
443
|
+
await deleteTransaction(pendingDeployment.txHash);
|
|
444
|
+
return deployment;
|
|
445
|
+
}
|
|
446
|
+
let env = {
|
|
447
|
+
...perliminaryEnvironment,
|
|
448
|
+
save,
|
|
449
|
+
saveWhilePending,
|
|
450
|
+
get
|
|
451
|
+
};
|
|
452
|
+
for (const extension of globalThis.extensions) {
|
|
453
|
+
env = extension(env);
|
|
454
|
+
}
|
|
455
|
+
return {
|
|
456
|
+
external: env,
|
|
457
|
+
internal: {
|
|
458
|
+
exportDeploymentsAsTypes,
|
|
459
|
+
recoverTransactionsIfAny
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// src/executor/index.ts
|
|
465
|
+
require("esbuild-register/dist/node").register();
|
|
466
|
+
function execute(context, callback, options) {
|
|
467
|
+
const scriptModule = (env) => callback(env);
|
|
468
|
+
scriptModule.providedContext = context;
|
|
469
|
+
scriptModule.tags = options.tags;
|
|
470
|
+
scriptModule.dependencies = options.dependencies;
|
|
471
|
+
return scriptModule;
|
|
472
|
+
}
|
|
473
|
+
function readConfig(options, extra) {
|
|
474
|
+
let configFile;
|
|
475
|
+
try {
|
|
476
|
+
const configString = import_node_fs4.default.readFileSync("./rocketh.json", "utf-8");
|
|
477
|
+
configFile = JSON.parse(configString);
|
|
478
|
+
} catch {
|
|
479
|
+
}
|
|
480
|
+
let nodeUrl;
|
|
481
|
+
const fromEnv = process.env["ETH_NODE_URI_" + options.network];
|
|
482
|
+
if (typeof fromEnv === "string") {
|
|
483
|
+
nodeUrl = fromEnv;
|
|
484
|
+
} else {
|
|
485
|
+
if (configFile) {
|
|
486
|
+
const network = configFile.networks && configFile.networks[options.network];
|
|
487
|
+
if (network) {
|
|
488
|
+
nodeUrl = network.rpcUrl;
|
|
489
|
+
} else {
|
|
490
|
+
if (extra?.ignoreMissingRPC) {
|
|
491
|
+
nodeUrl = "";
|
|
492
|
+
} else {
|
|
493
|
+
console.error(`network "${options.network}" is not configured. Please add it to the rocketh.json file`);
|
|
494
|
+
process.exit(1);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
} else {
|
|
498
|
+
if (extra?.ignoreMissingRPC) {
|
|
499
|
+
nodeUrl = "";
|
|
500
|
+
} else {
|
|
501
|
+
console.error(`network "${options.network}" is not configured. Please add it to the rocketh.json file`);
|
|
502
|
+
process.exit(1);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return {
|
|
507
|
+
nodeUrl,
|
|
508
|
+
networkName: options.network,
|
|
509
|
+
deployments: options.deployments,
|
|
510
|
+
scripts: options.scripts,
|
|
511
|
+
tags: typeof options.tags === "undefined" ? void 0 : options.tags.split(",")
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
function readAndResolveConfig(options, extra) {
|
|
515
|
+
return resolveConfig(readConfig(options, extra));
|
|
516
|
+
}
|
|
517
|
+
function resolveConfig(config) {
|
|
518
|
+
const resolvedConfig = {
|
|
519
|
+
...config,
|
|
520
|
+
networkName: config.networkName || "memory",
|
|
521
|
+
deployments: config.deployments || "deployments",
|
|
522
|
+
scripts: config.scripts || "deploy",
|
|
523
|
+
tags: config.tags || []
|
|
524
|
+
};
|
|
525
|
+
return resolvedConfig;
|
|
526
|
+
}
|
|
527
|
+
async function loadAndExecuteDeployments(config) {
|
|
528
|
+
const resolvedConfig = resolveConfig(config);
|
|
529
|
+
return executeDeployScripts(resolvedConfig);
|
|
530
|
+
}
|
|
531
|
+
async function executeDeployScripts(config) {
|
|
532
|
+
let filepaths;
|
|
533
|
+
filepaths = traverseMultipleDirectory([config.scripts]);
|
|
534
|
+
filepaths = filepaths.filter((v) => !import_node_path4.default.basename(v).startsWith("_")).sort((a, b) => {
|
|
535
|
+
if (a < b) {
|
|
536
|
+
return -1;
|
|
537
|
+
}
|
|
538
|
+
if (a > b) {
|
|
539
|
+
return 1;
|
|
540
|
+
}
|
|
541
|
+
return 0;
|
|
542
|
+
});
|
|
543
|
+
let providedContext;
|
|
544
|
+
const scriptModuleByFilePath = {};
|
|
545
|
+
const scriptPathBags = {};
|
|
546
|
+
const scriptFilePaths = [];
|
|
547
|
+
for (const filepath of filepaths) {
|
|
548
|
+
const scriptFilePath = import_node_path4.default.resolve(filepath);
|
|
549
|
+
let scriptModule;
|
|
550
|
+
try {
|
|
551
|
+
if (require.cache) {
|
|
552
|
+
delete require.cache[scriptFilePath];
|
|
553
|
+
}
|
|
554
|
+
scriptModule = require(scriptFilePath);
|
|
555
|
+
if (scriptModule.default) {
|
|
556
|
+
scriptModule = scriptModule.default;
|
|
557
|
+
if (scriptModule.default) {
|
|
558
|
+
console.warn(`double default...`);
|
|
559
|
+
scriptModule = scriptModule.default;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
scriptModuleByFilePath[scriptFilePath] = scriptModule;
|
|
563
|
+
if (providedContext && providedContext !== scriptModule.providedContext) {
|
|
564
|
+
throw new Error(`context between 2 scripts is different, please share the same across them`);
|
|
565
|
+
}
|
|
566
|
+
providedContext = scriptModule.providedContext;
|
|
567
|
+
} catch (e) {
|
|
568
|
+
console.error(`could not import ${filepath}`);
|
|
569
|
+
throw e;
|
|
570
|
+
}
|
|
571
|
+
let scriptTags = scriptModule.tags;
|
|
572
|
+
if (scriptTags !== void 0) {
|
|
573
|
+
if (typeof scriptTags === "string") {
|
|
574
|
+
scriptTags = [scriptTags];
|
|
575
|
+
}
|
|
576
|
+
for (const tag of scriptTags) {
|
|
577
|
+
if (tag.indexOf(",") >= 0) {
|
|
578
|
+
throw new Error("Tag cannot contains commas");
|
|
579
|
+
}
|
|
580
|
+
const bag = scriptPathBags[tag] || [];
|
|
581
|
+
scriptPathBags[tag] = bag;
|
|
582
|
+
bag.push(scriptFilePath);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
if (config.tags !== void 0 && config.tags.length > 0) {
|
|
586
|
+
let found = false;
|
|
587
|
+
if (scriptTags !== void 0) {
|
|
588
|
+
for (const tagToFind of config.tags) {
|
|
589
|
+
for (const tag of scriptTags) {
|
|
590
|
+
if (tag === tagToFind) {
|
|
591
|
+
scriptFilePaths.push(scriptFilePath);
|
|
592
|
+
found = true;
|
|
593
|
+
break;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
if (found) {
|
|
597
|
+
break;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
} else {
|
|
602
|
+
scriptFilePaths.push(scriptFilePath);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
if (!providedContext) {
|
|
606
|
+
throw new Error(`no context loaded`);
|
|
607
|
+
}
|
|
608
|
+
const { internal, external } = await createEnvironment(config, providedContext);
|
|
609
|
+
await internal.recoverTransactionsIfAny();
|
|
610
|
+
const scriptsRegisteredToRun = {};
|
|
611
|
+
const scriptsToRun = [];
|
|
612
|
+
const scriptsToRunAtTheEnd = [];
|
|
613
|
+
function recurseDependencies(scriptFilePath) {
|
|
614
|
+
if (scriptsRegisteredToRun[scriptFilePath]) {
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
const scriptModule = scriptModuleByFilePath[scriptFilePath];
|
|
618
|
+
if (scriptModule.dependencies) {
|
|
619
|
+
for (const dependency of scriptModule.dependencies) {
|
|
620
|
+
const scriptFilePathsToAdd = scriptPathBags[dependency];
|
|
621
|
+
if (scriptFilePathsToAdd) {
|
|
622
|
+
for (const scriptFilenameToAdd of scriptFilePathsToAdd) {
|
|
623
|
+
recurseDependencies(scriptFilenameToAdd);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
if (!scriptsRegisteredToRun[scriptFilePath]) {
|
|
629
|
+
if (scriptModule.runAtTheEnd) {
|
|
630
|
+
scriptsToRunAtTheEnd.push({
|
|
631
|
+
filePath: scriptFilePath,
|
|
632
|
+
func: scriptModule
|
|
633
|
+
});
|
|
634
|
+
} else {
|
|
635
|
+
scriptsToRun.push({
|
|
636
|
+
filePath: scriptFilePath,
|
|
637
|
+
func: scriptModule
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
scriptsRegisteredToRun[scriptFilePath] = true;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
for (const scriptFilePath of scriptFilePaths) {
|
|
644
|
+
recurseDependencies(scriptFilePath);
|
|
645
|
+
}
|
|
646
|
+
for (const deployScript of scriptsToRun.concat(scriptsToRunAtTheEnd)) {
|
|
647
|
+
const filename = import_node_path4.default.basename(deployScript.filePath);
|
|
648
|
+
let skip = false;
|
|
649
|
+
if (deployScript.func.skip) {
|
|
650
|
+
try {
|
|
651
|
+
skip = await deployScript.func.skip(external);
|
|
652
|
+
} catch (e) {
|
|
653
|
+
console.error(`skip failed for ${deployScript.filePath}`);
|
|
654
|
+
throw e;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
if (!skip) {
|
|
658
|
+
let result;
|
|
659
|
+
try {
|
|
660
|
+
result = await deployScript.func(external);
|
|
661
|
+
} catch (e) {
|
|
662
|
+
console.error(`execution failed for ${deployScript.filePath}`);
|
|
663
|
+
throw e;
|
|
664
|
+
}
|
|
665
|
+
if (result && typeof result === "boolean") {
|
|
666
|
+
const deploymentFolderPath = config.deployments;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
return external.deployments;
|
|
671
|
+
}
|
|
672
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
673
|
+
0 && (module.exports = {
|
|
674
|
+
execute,
|
|
675
|
+
executeDeployScripts,
|
|
676
|
+
extendEnvironment,
|
|
677
|
+
handleSignerProtocol,
|
|
678
|
+
loadAndExecuteDeployments,
|
|
679
|
+
loadDeployments,
|
|
680
|
+
readAndResolveConfig,
|
|
681
|
+
readConfig,
|
|
682
|
+
resolveConfig
|
|
683
|
+
});
|
|
684
|
+
//# sourceMappingURL=index.cjs.map
|