gate-evm-tools 1.0.26 → 1.0.28
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/README.md +14 -0
- package/bin/workflow.cjs +19 -0
- package/dist/core/BytecodeChecker.d.ts.map +1 -1
- package/dist/core/BytecodeChecker.js +16 -1
- package/dist/core/BytecodeChecker.js.map +1 -1
- package/dist/core/legacyProxyArtifact.d.ts +6 -0
- package/dist/core/legacyProxyArtifact.d.ts.map +1 -0
- package/dist/core/legacyProxyArtifact.js +36 -0
- package/dist/core/legacyProxyArtifact.js.map +1 -0
- package/dist-runtime/config/hardhatAdapters.d.ts +7 -0
- package/dist-runtime/config/hardhatAdapters.js +61 -0
- package/dist-runtime/config/hardhatAdapters.js.map +1 -0
- package/dist-runtime/config/networks.d.ts +32 -0
- package/dist-runtime/config/networks.js +275 -0
- package/dist-runtime/config/networks.js.map +1 -0
- package/dist-runtime/config/openzeppelin.d.ts +28 -0
- package/dist-runtime/config/openzeppelin.js +144 -0
- package/dist-runtime/config/openzeppelin.js.map +1 -0
- package/dist-runtime/config/rpc.d.ts +7 -0
- package/dist-runtime/config/rpc.js +19 -0
- package/dist-runtime/config/rpc.js.map +1 -0
- package/dist-runtime/config/zksyncSolcPath.d.ts +1 -0
- package/dist-runtime/config/zksyncSolcPath.js +61 -0
- package/dist-runtime/config/zksyncSolcPath.js.map +1 -0
- package/dist-runtime/migrate.d.ts +13 -0
- package/dist-runtime/migrate.js +208 -0
- package/dist-runtime/migrate.js.map +1 -0
- package/dist-runtime/package.json +1 -0
- package/dist-runtime/projectHardhat.d.ts +4 -0
- package/dist-runtime/projectHardhat.js +16 -0
- package/dist-runtime/projectHardhat.js.map +1 -0
- package/dist-runtime/runtime-identity.json +4 -0
- package/dist-runtime/template-migration.json +293 -0
- package/dist-runtime/workflow/checkCode.d.ts +1 -0
- package/dist-runtime/workflow/checkCode.js +16 -0
- package/dist-runtime/workflow/checkCode.js.map +1 -0
- package/dist-runtime/workflow/checkCodeFinalize.d.ts +1 -0
- package/dist-runtime/workflow/checkCodeFinalize.js +11 -0
- package/dist-runtime/workflow/checkCodeFinalize.js.map +1 -0
- package/dist-runtime/workflow/checkCodePlan.d.ts +1 -0
- package/dist-runtime/workflow/checkCodePlan.js +11 -0
- package/dist-runtime/workflow/checkCodePlan.js.map +1 -0
- package/dist-runtime/workflow/cli.d.ts +1 -0
- package/dist-runtime/workflow/cli.js +302 -0
- package/dist-runtime/workflow/cli.js.map +1 -0
- package/dist-runtime/workflow/commitContractInfo.d.ts +1 -0
- package/dist-runtime/workflow/commitContractInfo.js +64 -0
- package/dist-runtime/workflow/commitContractInfo.js.map +1 -0
- package/dist-runtime/workflow/create2Hashes.d.ts +1 -0
- package/dist-runtime/workflow/create2Hashes.js +76 -0
- package/dist-runtime/workflow/create2Hashes.js.map +1 -0
- package/dist-runtime/workflow/forkSourceProxy.d.ts +1 -0
- package/dist-runtime/workflow/forkSourceProxy.js +151 -0
- package/dist-runtime/workflow/forkSourceProxy.js.map +1 -0
- package/dist-runtime/workflow/importState.d.ts +1 -0
- package/dist-runtime/workflow/importState.js +193 -0
- package/dist-runtime/workflow/importState.js.map +1 -0
- package/dist-runtime/workflow/lib/authority.d.ts +28 -0
- package/dist-runtime/workflow/lib/authority.js +122 -0
- package/dist-runtime/workflow/lib/authority.js.map +1 -0
- package/dist-runtime/workflow/lib/calldata.d.ts +2 -0
- package/dist-runtime/workflow/lib/calldata.js +8 -0
- package/dist-runtime/workflow/lib/calldata.js.map +1 -0
- package/dist-runtime/workflow/lib/calls.d.ts +23 -0
- package/dist-runtime/workflow/lib/calls.js +316 -0
- package/dist-runtime/workflow/lib/calls.js.map +1 -0
- package/dist-runtime/workflow/lib/checkCode/args.d.ts +2 -0
- package/dist-runtime/workflow/lib/checkCode/args.js +68 -0
- package/dist-runtime/workflow/lib/checkCode/args.js.map +1 -0
- package/dist-runtime/workflow/lib/checkCode/command.d.ts +5 -0
- package/dist-runtime/workflow/lib/checkCode/command.js +35 -0
- package/dist-runtime/workflow/lib/checkCode/command.js.map +1 -0
- package/dist-runtime/workflow/lib/checkCode/dependencies.d.ts +6 -0
- package/dist-runtime/workflow/lib/checkCode/dependencies.js +125 -0
- package/dist-runtime/workflow/lib/checkCode/dependencies.js.map +1 -0
- package/dist-runtime/workflow/lib/checkCode/finalize.d.ts +17 -0
- package/dist-runtime/workflow/lib/checkCode/finalize.js +174 -0
- package/dist-runtime/workflow/lib/checkCode/finalize.js.map +1 -0
- package/dist-runtime/workflow/lib/checkCode/index.d.ts +3 -0
- package/dist-runtime/workflow/lib/checkCode/index.js +20 -0
- package/dist-runtime/workflow/lib/checkCode/index.js.map +1 -0
- package/dist-runtime/workflow/lib/checkCode/plan.d.ts +22 -0
- package/dist-runtime/workflow/lib/checkCode/plan.js +145 -0
- package/dist-runtime/workflow/lib/checkCode/plan.js.map +1 -0
- package/dist-runtime/workflow/lib/checkCodeReport.d.ts +25 -0
- package/dist-runtime/workflow/lib/checkCodeReport.js +102 -0
- package/dist-runtime/workflow/lib/checkCodeReport.js.map +1 -0
- package/dist-runtime/workflow/lib/checkCodeRunner.d.ts +87 -0
- package/dist-runtime/workflow/lib/checkCodeRunner.js +964 -0
- package/dist-runtime/workflow/lib/checkCodeRunner.js.map +1 -0
- package/dist-runtime/workflow/lib/cliTool.d.ts +10 -0
- package/dist-runtime/workflow/lib/cliTool.js +25 -0
- package/dist-runtime/workflow/lib/cliTool.js.map +1 -0
- package/dist-runtime/workflow/lib/config.d.ts +33 -0
- package/dist-runtime/workflow/lib/config.js +100 -0
- package/dist-runtime/workflow/lib/config.js.map +1 -0
- package/dist-runtime/workflow/lib/contractInfoCandidates.d.ts +82 -0
- package/dist-runtime/workflow/lib/contractInfoCandidates.js +441 -0
- package/dist-runtime/workflow/lib/contractInfoCandidates.js.map +1 -0
- package/dist-runtime/workflow/lib/controlledMulticallAbi.d.ts +2 -0
- package/dist-runtime/workflow/lib/controlledMulticallAbi.js +10 -0
- package/dist-runtime/workflow/lib/controlledMulticallAbi.js.map +1 -0
- package/dist-runtime/workflow/lib/create2.d.ts +49 -0
- package/dist-runtime/workflow/lib/create2.js +194 -0
- package/dist-runtime/workflow/lib/create2.js.map +1 -0
- package/dist-runtime/workflow/lib/create2Hashes.d.ts +22 -0
- package/dist-runtime/workflow/lib/create2Hashes.js +57 -0
- package/dist-runtime/workflow/lib/create2Hashes.js.map +1 -0
- package/dist-runtime/workflow/lib/deploymentInfo.d.ts +40 -0
- package/dist-runtime/workflow/lib/deploymentInfo.js +240 -0
- package/dist-runtime/workflow/lib/deploymentInfo.js.map +1 -0
- package/dist-runtime/workflow/lib/deploymentRecords.d.ts +137 -0
- package/dist-runtime/workflow/lib/deploymentRecords.js +374 -0
- package/dist-runtime/workflow/lib/deploymentRecords.js.map +1 -0
- package/dist-runtime/workflow/lib/deployments.d.ts +21 -0
- package/dist-runtime/workflow/lib/deployments.js +240 -0
- package/dist-runtime/workflow/lib/deployments.js.map +1 -0
- package/dist-runtime/workflow/lib/erc1967.d.ts +5 -0
- package/dist-runtime/workflow/lib/erc1967.js +29 -0
- package/dist-runtime/workflow/lib/erc1967.js.map +1 -0
- package/dist-runtime/workflow/lib/errors.d.ts +6 -0
- package/dist-runtime/workflow/lib/errors.js +77 -0
- package/dist-runtime/workflow/lib/errors.js.map +1 -0
- package/dist-runtime/workflow/lib/executionId.d.ts +7 -0
- package/dist-runtime/workflow/lib/executionId.js +26 -0
- package/dist-runtime/workflow/lib/executionId.js.map +1 -0
- package/dist-runtime/workflow/lib/executionPlan.d.ts +85 -0
- package/dist-runtime/workflow/lib/executionPlan.js +450 -0
- package/dist-runtime/workflow/lib/executionPlan.js.map +1 -0
- package/dist-runtime/workflow/lib/executionProgress.d.ts +5 -0
- package/dist-runtime/workflow/lib/executionProgress.js +100 -0
- package/dist-runtime/workflow/lib/executionProgress.js.map +1 -0
- package/dist-runtime/workflow/lib/external.d.ts +62 -0
- package/dist-runtime/workflow/lib/external.js +282 -0
- package/dist-runtime/workflow/lib/external.js.map +1 -0
- package/dist-runtime/workflow/lib/externalExecutionScanner.d.ts +64 -0
- package/dist-runtime/workflow/lib/externalExecutionScanner.js +638 -0
- package/dist-runtime/workflow/lib/externalExecutionScanner.js.map +1 -0
- package/dist-runtime/workflow/lib/forkSnapshot.d.ts +34 -0
- package/dist-runtime/workflow/lib/forkSnapshot.js +167 -0
- package/dist-runtime/workflow/lib/forkSnapshot.js.map +1 -0
- package/dist-runtime/workflow/lib/gateTool.d.ts +16 -0
- package/dist-runtime/workflow/lib/gateTool.js +177 -0
- package/dist-runtime/workflow/lib/gateTool.js.map +1 -0
- package/dist-runtime/workflow/lib/gateToolSync.d.ts +22 -0
- package/dist-runtime/workflow/lib/gateToolSync.js +253 -0
- package/dist-runtime/workflow/lib/gateToolSync.js.map +1 -0
- package/dist-runtime/workflow/lib/lock.d.ts +52 -0
- package/dist-runtime/workflow/lib/lock.js +269 -0
- package/dist-runtime/workflow/lib/lock.js.map +1 -0
- package/dist-runtime/workflow/lib/migrationState.d.ts +103 -0
- package/dist-runtime/workflow/lib/migrationState.js +920 -0
- package/dist-runtime/workflow/lib/migrationState.js.map +1 -0
- package/dist-runtime/workflow/lib/operatorExecution.d.ts +28 -0
- package/dist-runtime/workflow/lib/operatorExecution.js +134 -0
- package/dist-runtime/workflow/lib/operatorExecution.js.map +1 -0
- package/dist-runtime/workflow/lib/parameters.d.ts +58 -0
- package/dist-runtime/workflow/lib/parameters.js +323 -0
- package/dist-runtime/workflow/lib/parameters.js.map +1 -0
- package/dist-runtime/workflow/lib/pendingDeploymentReuse.d.ts +29 -0
- package/dist-runtime/workflow/lib/pendingDeploymentReuse.js +277 -0
- package/dist-runtime/workflow/lib/pendingDeploymentReuse.js.map +1 -0
- package/dist-runtime/workflow/lib/proxy.d.ts +18 -0
- package/dist-runtime/workflow/lib/proxy.js +19 -0
- package/dist-runtime/workflow/lib/proxy.js.map +1 -0
- package/dist-runtime/workflow/lib/registryCommit.d.ts +33 -0
- package/dist-runtime/workflow/lib/registryCommit.js +319 -0
- package/dist-runtime/workflow/lib/registryCommit.js.map +1 -0
- package/dist-runtime/workflow/lib/release.d.ts +57 -0
- package/dist-runtime/workflow/lib/release.js +256 -0
- package/dist-runtime/workflow/lib/release.js.map +1 -0
- package/dist-runtime/workflow/lib/releaseFinalize.d.ts +14 -0
- package/dist-runtime/workflow/lib/releaseFinalize.js +571 -0
- package/dist-runtime/workflow/lib/releaseFinalize.js.map +1 -0
- package/dist-runtime/workflow/lib/releaseParameters.d.ts +43 -0
- package/dist-runtime/workflow/lib/releaseParameters.js +184 -0
- package/dist-runtime/workflow/lib/releaseParameters.js.map +1 -0
- package/dist-runtime/workflow/lib/reporter.d.ts +39 -0
- package/dist-runtime/workflow/lib/reporter.js +452 -0
- package/dist-runtime/workflow/lib/reporter.js.map +1 -0
- package/dist-runtime/workflow/lib/resultPaths.d.ts +17 -0
- package/dist-runtime/workflow/lib/resultPaths.js +29 -0
- package/dist-runtime/workflow/lib/resultPaths.js.map +1 -0
- package/dist-runtime/workflow/lib/runtimeVersion.d.ts +10 -0
- package/dist-runtime/workflow/lib/runtimeVersion.js +46 -0
- package/dist-runtime/workflow/lib/runtimeVersion.js.map +1 -0
- package/dist-runtime/workflow/lib/signer.d.ts +10 -0
- package/dist-runtime/workflow/lib/signer.js +105 -0
- package/dist-runtime/workflow/lib/signer.js.map +1 -0
- package/dist-runtime/workflow/lib/signerIdentity.d.ts +1 -0
- package/dist-runtime/workflow/lib/signerIdentity.js +23 -0
- package/dist-runtime/workflow/lib/signerIdentity.js.map +1 -0
- package/dist-runtime/workflow/lib/simulation.d.ts +35 -0
- package/dist-runtime/workflow/lib/simulation.js +282 -0
- package/dist-runtime/workflow/lib/simulation.js.map +1 -0
- package/dist-runtime/workflow/lib/simulationCallers.d.ts +44 -0
- package/dist-runtime/workflow/lib/simulationCallers.js +260 -0
- package/dist-runtime/workflow/lib/simulationCallers.js.map +1 -0
- package/dist-runtime/workflow/lib/sourceRpcPolicy.d.ts +1 -0
- package/dist-runtime/workflow/lib/sourceRpcPolicy.js +43 -0
- package/dist-runtime/workflow/lib/sourceRpcPolicy.js.map +1 -0
- package/dist-runtime/workflow/lib/state.d.ts +6 -0
- package/dist-runtime/workflow/lib/state.js +25 -0
- package/dist-runtime/workflow/lib/state.js.map +1 -0
- package/dist-runtime/workflow/lib/staticValidation.d.ts +22 -0
- package/dist-runtime/workflow/lib/staticValidation.js +124 -0
- package/dist-runtime/workflow/lib/staticValidation.js.map +1 -0
- package/dist-runtime/workflow/lib/zksyncForkCapability.d.ts +27 -0
- package/dist-runtime/workflow/lib/zksyncForkCapability.js +52 -0
- package/dist-runtime/workflow/lib/zksyncForkCapability.js.map +1 -0
- package/dist-runtime/workflow/lib/zksyncForkRunner.d.ts +57 -0
- package/dist-runtime/workflow/lib/zksyncForkRunner.js +344 -0
- package/dist-runtime/workflow/lib/zksyncForkRunner.js.map +1 -0
- package/dist-runtime/workflow/reconcileExternal.d.ts +1 -0
- package/dist-runtime/workflow/reconcileExternal.js +87 -0
- package/dist-runtime/workflow/reconcileExternal.js.map +1 -0
- package/dist-runtime/workflow/reconcileExternalRun.d.ts +1 -0
- package/dist-runtime/workflow/reconcileExternalRun.js +77 -0
- package/dist-runtime/workflow/reconcileExternalRun.js.map +1 -0
- package/dist-runtime/workflow/releaseFinalize.d.ts +1 -0
- package/dist-runtime/workflow/releaseFinalize.js +11 -0
- package/dist-runtime/workflow/releaseFinalize.js.map +1 -0
- package/dist-runtime/workflow/run.d.ts +40 -0
- package/dist-runtime/workflow/run.js +858 -0
- package/dist-runtime/workflow/run.js.map +1 -0
- package/dist-runtime/workflow/staticValidate.d.ts +1 -0
- package/dist-runtime/workflow/staticValidate.js +26 -0
- package/dist-runtime/workflow/staticValidate.js.map +1 -0
- package/dist-runtime/workflow/steps/call.d.ts +3 -0
- package/dist-runtime/workflow/steps/call.js +9 -0
- package/dist-runtime/workflow/steps/call.js.map +1 -0
- package/dist-runtime/workflow/steps/check.d.ts +3 -0
- package/dist-runtime/workflow/steps/check.js +9 -0
- package/dist-runtime/workflow/steps/check.js.map +1 -0
- package/dist-runtime/workflow/steps/custom.d.ts +3 -0
- package/dist-runtime/workflow/steps/custom.js +33 -0
- package/dist-runtime/workflow/steps/custom.js.map +1 -0
- package/dist-runtime/workflow/steps/deploy.d.ts +3 -0
- package/dist-runtime/workflow/steps/deploy.js +596 -0
- package/dist-runtime/workflow/steps/deploy.js.map +1 -0
- package/dist-runtime/workflow/steps/upgrade.d.ts +3 -0
- package/dist-runtime/workflow/steps/upgrade.js +466 -0
- package/dist-runtime/workflow/steps/upgrade.js.map +1 -0
- package/dist-runtime/workflow/steps/view.d.ts +3 -0
- package/dist-runtime/workflow/steps/view.js +9 -0
- package/dist-runtime/workflow/steps/view.js.map +1 -0
- package/docs/direct-package-acceptance.md +20 -0
- package/docs/external-infrastructure-acceptance.md +33 -0
- package/docs/network-runtime-acceptance.md +18 -0
- package/docs/plans/2026-09-09-workflow-extraction.md +16 -0
- package/docs/superpowers/plans/2026-07-22-manifest-bootstrap-transaction.md +50 -0
- package/docs/superpowers/plans/2026-07-22-manifest-review-remediation.md +49 -0
- package/docs/superpowers/plans/2026-08-17-custody-hardhat-signers.md +227 -0
- package/docs/superpowers/plans/2026-09-09-remove-template-infrastructure-contracts.md +11 -0
- package/docs/workflow-reference.md +1181 -0
- package/docs/workflow-runtime-acceptance.md +17 -0
- package/docs/workflow-runtime.md +56 -0
- package/package.json +26 -5
- package/runtime/config/hardhatAdapters.ts +58 -0
- package/runtime/config/networks.ts +305 -0
- package/runtime/config/openzeppelin.ts +173 -0
- package/runtime/config/rpc.ts +27 -0
- package/runtime/config/zksyncSolcPath.ts +59 -0
- package/runtime/hardhat-types.d.ts +2 -0
- package/runtime/migrate.ts +154 -0
- package/runtime/projectHardhat.ts +10 -0
- package/runtime/template-migration.json +293 -0
- package/runtime/workflow/checkCode.ts +13 -0
- package/runtime/workflow/checkCodeFinalize.ts +8 -0
- package/runtime/workflow/checkCodePlan.ts +8 -0
- package/runtime/workflow/cli.ts +356 -0
- package/runtime/workflow/commitContractInfo.ts +63 -0
- package/runtime/workflow/create2Hashes.ts +79 -0
- package/runtime/workflow/forkSourceProxy.ts +193 -0
- package/runtime/workflow/importState.ts +190 -0
- package/runtime/workflow/lib/authority.ts +170 -0
- package/runtime/workflow/lib/calldata.ts +9 -0
- package/runtime/workflow/lib/calls.ts +407 -0
- package/runtime/workflow/lib/checkCode/args.ts +76 -0
- package/runtime/workflow/lib/checkCode/command.ts +36 -0
- package/runtime/workflow/lib/checkCode/dependencies.ts +112 -0
- package/runtime/workflow/lib/checkCode/finalize.ts +198 -0
- package/runtime/workflow/lib/checkCode/index.ts +18 -0
- package/runtime/workflow/lib/checkCode/plan.ts +163 -0
- package/runtime/workflow/lib/checkCodeReport.ts +133 -0
- package/runtime/workflow/lib/checkCodeRunner.ts +1225 -0
- package/runtime/workflow/lib/cliTool.ts +31 -0
- package/runtime/workflow/lib/config.ts +130 -0
- package/runtime/workflow/lib/contractInfoCandidates.ts +690 -0
- package/runtime/workflow/lib/controlledMulticallAbi.ts +6 -0
- package/runtime/workflow/lib/create2.ts +278 -0
- package/runtime/workflow/lib/create2Hashes.ts +83 -0
- package/runtime/workflow/lib/deploymentInfo.ts +286 -0
- package/runtime/workflow/lib/deploymentRecords.ts +576 -0
- package/runtime/workflow/lib/deployments.ts +276 -0
- package/runtime/workflow/lib/erc1967.ts +57 -0
- package/runtime/workflow/lib/errors.ts +95 -0
- package/runtime/workflow/lib/executionId.ts +35 -0
- package/runtime/workflow/lib/executionPlan.ts +550 -0
- package/runtime/workflow/lib/executionProgress.ts +127 -0
- package/runtime/workflow/lib/external.ts +372 -0
- package/runtime/workflow/lib/externalExecutionScanner.ts +892 -0
- package/runtime/workflow/lib/forkSnapshot.ts +231 -0
- package/runtime/workflow/lib/gateTool.ts +261 -0
- package/runtime/workflow/lib/gateToolSync.ts +398 -0
- package/runtime/workflow/lib/lock.ts +388 -0
- package/runtime/workflow/lib/migrationState.ts +1246 -0
- package/runtime/workflow/lib/operatorExecution.ts +174 -0
- package/runtime/workflow/lib/parameters.ts +438 -0
- package/runtime/workflow/lib/pendingDeploymentReuse.ts +428 -0
- package/runtime/workflow/lib/proxy.ts +45 -0
- package/runtime/workflow/lib/registryCommit.ts +455 -0
- package/runtime/workflow/lib/release.ts +329 -0
- package/runtime/workflow/lib/releaseFinalize.ts +711 -0
- package/runtime/workflow/lib/releaseParameters.ts +248 -0
- package/runtime/workflow/lib/reporter.ts +502 -0
- package/runtime/workflow/lib/resultPaths.ts +49 -0
- package/runtime/workflow/lib/runtimeVersion.ts +28 -0
- package/runtime/workflow/lib/signer.ts +124 -0
- package/runtime/workflow/lib/signerIdentity.ts +22 -0
- package/runtime/workflow/lib/simulation.ts +415 -0
- package/runtime/workflow/lib/simulationCallers.ts +335 -0
- package/runtime/workflow/lib/sourceRpcPolicy.ts +41 -0
- package/runtime/workflow/lib/state.ts +25 -0
- package/runtime/workflow/lib/staticValidation.ts +142 -0
- package/runtime/workflow/lib/zksyncForkCapability.ts +80 -0
- package/runtime/workflow/lib/zksyncForkRunner.ts +505 -0
- package/runtime/workflow/reconcileExternal.ts +86 -0
- package/runtime/workflow/reconcileExternalRun.ts +88 -0
- package/runtime/workflow/releaseFinalize.ts +8 -0
- package/runtime/workflow/run.ts +1072 -0
- package/runtime/workflow/staticValidate.ts +23 -0
- package/runtime/workflow/steps/call.ts +10 -0
- package/runtime/workflow/steps/check.ts +10 -0
- package/runtime/workflow/steps/custom.ts +43 -0
- package/runtime/workflow/steps/deploy.ts +772 -0
- package/runtime/workflow/steps/upgrade.ts +599 -0
- package/runtime/workflow/steps/view.ts +10 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import YAML from "yaml";
|
|
4
|
+
import { parseForkSnapshotJson } from "../workflow/lib/forkSnapshot";
|
|
5
|
+
|
|
6
|
+
export type DeploymentEnvironment = "local" | "development" | "production";
|
|
7
|
+
|
|
8
|
+
export interface OpenZeppelinTargetConfig {
|
|
9
|
+
environment: DeploymentEnvironment;
|
|
10
|
+
openzeppelin?: { manifestDir?: unknown };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const TARGET_ENVIRONMENTS = new Set<DeploymentEnvironment>([
|
|
14
|
+
"local",
|
|
15
|
+
"development",
|
|
16
|
+
"production",
|
|
17
|
+
]);
|
|
18
|
+
const SAFE_MANIFEST_DIR = /^\.openzeppelin(?:\.[a-z0-9][a-z0-9-]*)?$/;
|
|
19
|
+
|
|
20
|
+
const assertConfinedManifestDirectory = (root: string, manifestDir: string): void => {
|
|
21
|
+
const rootPath = fs.realpathSync(root);
|
|
22
|
+
const candidatePath = path.resolve(root, manifestDir);
|
|
23
|
+
if (path.dirname(candidatePath) !== path.resolve(root)) {
|
|
24
|
+
throw new Error(`OpenZeppelin manifest directory escapes the project: ${manifestDir}`);
|
|
25
|
+
}
|
|
26
|
+
if (!fs.existsSync(candidatePath)) return;
|
|
27
|
+
|
|
28
|
+
const realCandidate = fs.realpathSync(candidatePath);
|
|
29
|
+
const relative = path.relative(rootPath, realCandidate);
|
|
30
|
+
if (relative === "" || relative.startsWith(`..${path.sep}`) || relative === ".." || path.isAbsolute(relative)) {
|
|
31
|
+
throw new Error(`OpenZeppelin manifest symlink resolves outside the project: ${manifestDir}`);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export function resolveOpenZeppelinManifestDir(
|
|
36
|
+
root: string,
|
|
37
|
+
network: string,
|
|
38
|
+
target: OpenZeppelinTargetConfig,
|
|
39
|
+
): string {
|
|
40
|
+
if (!TARGET_ENVIRONMENTS.has(target?.environment)) {
|
|
41
|
+
throw new Error(`Network ${network} must declare a valid deployment environment`);
|
|
42
|
+
}
|
|
43
|
+
const manifestDir = target.openzeppelin?.manifestDir;
|
|
44
|
+
if (typeof manifestDir !== "string" || !SAFE_MANIFEST_DIR.test(manifestDir)) {
|
|
45
|
+
throw new Error(`Network ${network} must declare one safe OpenZeppelin manifest directory segment`);
|
|
46
|
+
}
|
|
47
|
+
if (target.environment === "production" && manifestDir !== ".openzeppelin") {
|
|
48
|
+
throw new Error(`Production network ${network} must use exactly .openzeppelin`);
|
|
49
|
+
}
|
|
50
|
+
if (target.environment !== "production" && manifestDir === ".openzeppelin") {
|
|
51
|
+
throw new Error(`Non-production network ${network} must not use .openzeppelin`);
|
|
52
|
+
}
|
|
53
|
+
assertConfinedManifestDirectory(root, manifestDir);
|
|
54
|
+
return manifestDir;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function loadOpenZeppelinManifestDir(root: string, network: string): string {
|
|
58
|
+
const configPath = path.join(root, "config.yaml");
|
|
59
|
+
const config = YAML.parse(fs.readFileSync(configPath, "utf8"), { merge: true }) as unknown;
|
|
60
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
61
|
+
throw new Error("config.yaml must define network keys at the top level");
|
|
62
|
+
}
|
|
63
|
+
const target = (config as Record<string, unknown>)[network];
|
|
64
|
+
if (!target || typeof target !== "object" || Array.isArray(target) || network.startsWith("_")) {
|
|
65
|
+
throw new Error(`Missing config.yaml entry for network "${network}"`);
|
|
66
|
+
}
|
|
67
|
+
return resolveOpenZeppelinManifestDir(
|
|
68
|
+
root,
|
|
69
|
+
network,
|
|
70
|
+
target as OpenZeppelinTargetConfig,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function resolveEffectiveManifestTarget(input: {
|
|
75
|
+
network: string;
|
|
76
|
+
mode?: string;
|
|
77
|
+
target?: string;
|
|
78
|
+
env?: NodeJS.ProcessEnv;
|
|
79
|
+
}): string {
|
|
80
|
+
const network = input.network.trim();
|
|
81
|
+
const target = input.target?.trim();
|
|
82
|
+
const env = input.env ?? process.env;
|
|
83
|
+
if (!network) throw new Error("Hardhat network is required to resolve the OpenZeppelin manifest");
|
|
84
|
+
if (input.mode === "simulate" && network === "hardhat" && !target) {
|
|
85
|
+
throw new Error("Target is required for a Hardhat fork simulation");
|
|
86
|
+
}
|
|
87
|
+
if (network === "zkFork" && !target) {
|
|
88
|
+
throw new Error("Target is required for a zkSync fork simulation");
|
|
89
|
+
}
|
|
90
|
+
if (target && network !== "hardhat" && target !== network) {
|
|
91
|
+
if (network !== "zkFork") {
|
|
92
|
+
throw new Error(`Manifest target ${target} conflicts with Hardhat network ${network}`);
|
|
93
|
+
}
|
|
94
|
+
const snapshot = parseForkSnapshotJson(
|
|
95
|
+
env.GATE_SIMULATION_FORK_SNAPSHOT_JSON,
|
|
96
|
+
target,
|
|
97
|
+
);
|
|
98
|
+
if (snapshot.runner.kind !== "anvil-zksync") {
|
|
99
|
+
throw new Error("zkFork manifest target requires an anvil-zksync fork snapshot");
|
|
100
|
+
}
|
|
101
|
+
let rpcUrl: URL;
|
|
102
|
+
try {
|
|
103
|
+
rpcUrl = new URL(env.GATE_ZKSYNC_FORK_RPC_URL || "");
|
|
104
|
+
} catch {
|
|
105
|
+
throw new Error("zkFork manifest target requires a valid loopback RPC URL");
|
|
106
|
+
}
|
|
107
|
+
if (
|
|
108
|
+
rpcUrl.protocol !== "http:"
|
|
109
|
+
|| rpcUrl.hostname !== "127.0.0.1"
|
|
110
|
+
|| !rpcUrl.port
|
|
111
|
+
|| rpcUrl.username
|
|
112
|
+
|| rpcUrl.password
|
|
113
|
+
|| rpcUrl.search
|
|
114
|
+
|| rpcUrl.hash
|
|
115
|
+
) {
|
|
116
|
+
throw new Error("zkFork manifest target requires a loopback-only RPC URL");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return target || network;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function openZeppelinProcessEnvironment(input: {
|
|
123
|
+
root: string;
|
|
124
|
+
network: string;
|
|
125
|
+
mode?: string;
|
|
126
|
+
target?: string;
|
|
127
|
+
env?: NodeJS.ProcessEnv;
|
|
128
|
+
}): NodeJS.ProcessEnv {
|
|
129
|
+
const env = input.env ?? process.env;
|
|
130
|
+
const target = resolveEffectiveManifestTarget({ ...input, env });
|
|
131
|
+
const manifestDir = loadOpenZeppelinManifestDir(input.root, target);
|
|
132
|
+
if (env.GATE_WORKFLOW_TARGET && env.GATE_WORKFLOW_TARGET !== target) {
|
|
133
|
+
throw new Error(`GATE_WORKFLOW_TARGET conflict: expected ${target}, received ${env.GATE_WORKFLOW_TARGET}`);
|
|
134
|
+
}
|
|
135
|
+
if (env.MANIFEST_DEFAULT_DIR && env.MANIFEST_DEFAULT_DIR !== manifestDir) {
|
|
136
|
+
throw new Error(`MANIFEST_DEFAULT_DIR conflict: expected ${manifestDir}, received ${env.MANIFEST_DEFAULT_DIR}`);
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
...env,
|
|
140
|
+
GATE_WORKFLOW_TARGET: target,
|
|
141
|
+
MANIFEST_DEFAULT_DIR: manifestDir,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const argvValue = (argv: string[], name: string): string | undefined => {
|
|
146
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
147
|
+
const value = argv[index];
|
|
148
|
+
if (value === name) return argv[index + 1];
|
|
149
|
+
if (value.startsWith(`${name}=`)) return value.slice(name.length + 1);
|
|
150
|
+
}
|
|
151
|
+
return undefined;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export function configureOpenZeppelinManifestEnvironment(input: {
|
|
155
|
+
root: string;
|
|
156
|
+
target?: string;
|
|
157
|
+
argv?: string[];
|
|
158
|
+
env?: NodeJS.ProcessEnv;
|
|
159
|
+
}): string {
|
|
160
|
+
const env = input.env ?? process.env;
|
|
161
|
+
const network = argvValue(input.argv ?? process.argv, "--network")?.trim()
|
|
162
|
+
|| input.target?.trim()
|
|
163
|
+
|| "hardhat";
|
|
164
|
+
const next = openZeppelinProcessEnvironment({
|
|
165
|
+
root: input.root,
|
|
166
|
+
network,
|
|
167
|
+
target: input.target,
|
|
168
|
+
env,
|
|
169
|
+
});
|
|
170
|
+
env.GATE_WORKFLOW_TARGET = next.GATE_WORKFLOW_TARGET;
|
|
171
|
+
env.MANIFEST_DEFAULT_DIR = next.MANIFEST_DEFAULT_DIR;
|
|
172
|
+
return next.MANIFEST_DEFAULT_DIR!;
|
|
173
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface EvmRpcOptions {
|
|
2
|
+
route: string;
|
|
3
|
+
publicFallback: string;
|
|
4
|
+
useBaseRpc: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const trimSlashes = (value: string): string => value.replace(/^\/+|\/+$/g, "");
|
|
8
|
+
|
|
9
|
+
export const resolveEvmRpcUrl = (
|
|
10
|
+
options: EvmRpcOptions,
|
|
11
|
+
baseRpcUri: string | undefined = process.env.BASE_RPC_URI,
|
|
12
|
+
): string => {
|
|
13
|
+
const fallback = options.publicFallback.trim();
|
|
14
|
+
const base = baseRpcUri?.trim();
|
|
15
|
+
if (!options.useBaseRpc || !base) return fallback;
|
|
16
|
+
|
|
17
|
+
const normalizedBase = base.replace(/\/+$/g, "");
|
|
18
|
+
const normalizedRoute = trimSlashes(options.route.trim());
|
|
19
|
+
return normalizedRoute
|
|
20
|
+
? `${normalizedBase}/${normalizedRoute}/`
|
|
21
|
+
: `${normalizedBase}/`;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const resolveZkSyncRpcUrl = (
|
|
25
|
+
publicFallback: string,
|
|
26
|
+
explicitRpcUrl: string | undefined = process.env.ZKSYNC_RPC_URL,
|
|
27
|
+
): string => explicitRpcUrl?.trim() || publicFallback.trim();
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import os from "os";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
let adapterTail: Promise<void> = Promise.resolve();
|
|
6
|
+
|
|
7
|
+
const runSerialized = async <T>(run: () => Promise<T>): Promise<T> => {
|
|
8
|
+
const previous = adapterTail;
|
|
9
|
+
let release: () => void = () => undefined;
|
|
10
|
+
adapterTail = new Promise<void>((resolve) => {
|
|
11
|
+
release = resolve;
|
|
12
|
+
});
|
|
13
|
+
await previous;
|
|
14
|
+
try {
|
|
15
|
+
return await run();
|
|
16
|
+
} finally {
|
|
17
|
+
release();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const restorePath = (previousPath: string | undefined): void => {
|
|
22
|
+
if (previousPath === undefined) {
|
|
23
|
+
delete process.env.PATH;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
process.env.PATH = previousPath;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export async function withZkSyncSolcOnPath<T>(
|
|
30
|
+
solcPath: string,
|
|
31
|
+
run: () => Promise<T>,
|
|
32
|
+
): Promise<T> {
|
|
33
|
+
return runSerialized(async () => {
|
|
34
|
+
const resolvedSolcPath = fs.realpathSync(solcPath);
|
|
35
|
+
if (!fs.statSync(resolvedSolcPath).isFile()) {
|
|
36
|
+
throw new Error(`Hardhat solc path is not a file: ${solcPath}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const adapterDirectory = fs.mkdtempSync(path.join(os.tmpdir(), "gate-zksolc-path-"));
|
|
40
|
+
const executableName = process.platform === "win32" ? "solc.exe" : "solc";
|
|
41
|
+
const mappedSolcPath = path.join(adapterDirectory, executableName);
|
|
42
|
+
const previousPath = process.env.PATH;
|
|
43
|
+
try {
|
|
44
|
+
if (process.platform === "win32") {
|
|
45
|
+
fs.copyFileSync(resolvedSolcPath, mappedSolcPath);
|
|
46
|
+
fs.chmodSync(mappedSolcPath, 0o755);
|
|
47
|
+
} else {
|
|
48
|
+
fs.symlinkSync(resolvedSolcPath, mappedSolcPath);
|
|
49
|
+
}
|
|
50
|
+
process.env.PATH = previousPath
|
|
51
|
+
? `${adapterDirectory}${path.delimiter}${previousPath}`
|
|
52
|
+
: adapterDirectory;
|
|
53
|
+
return await run();
|
|
54
|
+
} finally {
|
|
55
|
+
restorePath(previousPath);
|
|
56
|
+
fs.rmSync(adapterDirectory, { recursive: true, force: true });
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { satisfies, validRange } from 'semver';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
|
|
7
|
+
interface Entry { sha256: string; replacement: string }
|
|
8
|
+
interface Change { path: string; status: 'current' | 'remove' | 'update' | 'conflict'; reason?: string }
|
|
9
|
+
const commands: Record<string, string> = {
|
|
10
|
+
cli: 'run', checkCode: 'checkcode', checkCodePlan: 'checkcode-plan',
|
|
11
|
+
checkCodeFinalize: 'checkcode-finalize', staticValidate: 'static-validate',
|
|
12
|
+
create2Hashes: 'create2-hashes', releaseFinalize: 'release-finalize',
|
|
13
|
+
importState: 'import-state', reconcileExternal: 'reconcile-external',
|
|
14
|
+
commitContractInfo: 'commit-contract-info',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** Plan first; preserve custom files/state. Only known sources/shims are removable. */
|
|
18
|
+
export function migrateTemplate(projectRoot: string, apply = false) {
|
|
19
|
+
const root = fs.realpathSync(projectRoot);
|
|
20
|
+
const baseline: { templateVersion: string; files: Record<string, Entry> } = JSON.parse(
|
|
21
|
+
fs.readFileSync(path.join(__dirname, 'template-migration.json'), 'utf8'),
|
|
22
|
+
);
|
|
23
|
+
const plan: Change[] = [];
|
|
24
|
+
const edits = new Map<string, string>();
|
|
25
|
+
const originals = new Map<string, string>();
|
|
26
|
+
const conflict = (relative: string, reason: string) => plan.push({ path: relative, status: 'conflict', reason });
|
|
27
|
+
const unsafe = (relative: string) => {
|
|
28
|
+
const file = path.resolve(root, relative);
|
|
29
|
+
if (!file.startsWith(root + path.sep)) return true;
|
|
30
|
+
return relative.split('/').some((_, i, parts) => {
|
|
31
|
+
try { return fs.lstatSync(path.join(root, ...parts.slice(0, i + 1))).isSymbolicLink(); }
|
|
32
|
+
catch (error) { if ((error as NodeJS.ErrnoException).code === 'ENOENT') return false; throw error; }
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
for (const [relative, entry] of Object.entries(baseline.files)) {
|
|
37
|
+
const file = path.join(root, relative);
|
|
38
|
+
if (unsafe(relative)) { conflict(relative, 'Symlinked or unconfined runtime path'); continue; }
|
|
39
|
+
if (!fs.existsSync(file)) { plan.push({ path: relative, status: 'current' }); continue; }
|
|
40
|
+
if (!fs.statSync(file).isFile()) { conflict(relative, 'Runtime path must be a regular file'); continue; }
|
|
41
|
+
const source = fs.readFileSync(file, 'utf8');
|
|
42
|
+
if (source !== entry.replacement && createHash('sha256').update(source).digest('hex') !== entry.sha256) {
|
|
43
|
+
conflict(relative, 'Customized runtime file requires manual merge'); continue;
|
|
44
|
+
}
|
|
45
|
+
originals.set(relative, source);
|
|
46
|
+
plan.push({ path: relative, status: 'remove' });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const packagePath = path.join(root, 'package.json');
|
|
50
|
+
if (unsafe('package.json') || !fs.existsSync(packagePath)) conflict('package.json', 'Project package.json must exist and be a regular local file');
|
|
51
|
+
else {
|
|
52
|
+
const source = fs.readFileSync(packagePath, 'utf8');
|
|
53
|
+
const pkg = JSON.parse(source);
|
|
54
|
+
try {
|
|
55
|
+
if (!(pkg.devDependencies?.['gate-evm-tools'] ?? pkg.dependencies?.['gate-evm-tools'])) throw new Error('gate-evm-tools is not declared');
|
|
56
|
+
const projectRequire = createRequire(packagePath);
|
|
57
|
+
const installedRoot = path.resolve(path.dirname(projectRequire.resolve('gate-evm-tools/runtime/cli')), '../..');
|
|
58
|
+
const installed = JSON.parse(fs.readFileSync(path.join(installedRoot, 'package.json'), 'utf8'));
|
|
59
|
+
const declared = pkg.devDependencies?.['gate-evm-tools'] ?? pkg.dependencies?.['gate-evm-tools'];
|
|
60
|
+
if (typeof declared !== 'string' || (!declared.startsWith('file:') && (!validRange(declared) || !satisfies(installed.version, declared)))) throw new Error('Install a version satisfying the declared dependency range first');
|
|
61
|
+
const lockPath = path.join(root, 'package-lock.json');
|
|
62
|
+
if (fs.existsSync(lockPath)) {
|
|
63
|
+
const lock = JSON.parse(fs.readFileSync(lockPath, 'utf8'));
|
|
64
|
+
const locked = lock.packages?.['node_modules/gate-evm-tools'] ?? lock.dependencies?.['gate-evm-tools'];
|
|
65
|
+
if (locked?.version !== installed.version) throw new Error('Lockfile version differs from installation');
|
|
66
|
+
}
|
|
67
|
+
for (const entry of Object.values(baseline.files)) {
|
|
68
|
+
const specifier = entry.replacement.match(/export \* from "([^"]+)"/)?.[1];
|
|
69
|
+
if (!specifier || !fs.statSync(projectRequire.resolve(specifier)).isFile()) throw new Error('Missing packaged runtime export');
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
conflict('package.json', 'Install the approved GateTool package and existing lockfile with all runtime exports before removing scripts');
|
|
73
|
+
}
|
|
74
|
+
let changed = false;
|
|
75
|
+
for (const [name, command] of Object.entries(pkg.scripts ?? {})) {
|
|
76
|
+
if (typeof command !== 'string') continue;
|
|
77
|
+
const match = command.match(/^ts-node scripts\/workflow\/([A-Za-z0-9]+)\.ts(?=\s|$)/);
|
|
78
|
+
if (match && commands[match[1]!]) {
|
|
79
|
+
pkg.scripts[name] = command.replace(match[0], `gate-workflow ${commands[match[1]!]}`);
|
|
80
|
+
changed = true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const next = changed ? JSON.stringify(pkg, null, source.match(/\n(\s+)"/)?.[1] ?? 2) + '\n' : source;
|
|
84
|
+
if (next.includes('scripts/workflow') || next.includes('scripts\\\\workflow')) conflict('package.json', 'Unrecognized workflow command/reference; update manually');
|
|
85
|
+
else if (changed) { originals.set('package.json', source); edits.set('package.json', next); plan.push({ path: 'package.json', status: 'update' }); }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const moduleTarget = (file: string, specifier: string): string | undefined => {
|
|
89
|
+
if (!specifier.startsWith('.')) return undefined;
|
|
90
|
+
const absolute = path.resolve(path.dirname(file), specifier).replace(/\.(?:ts|js)$/, '') + '.ts';
|
|
91
|
+
const relative = path.relative(root, absolute).split(path.sep).join('/');
|
|
92
|
+
return baseline.files[relative]?.replacement.match(/export \* from "([^"]+)"/)?.[1];
|
|
93
|
+
};
|
|
94
|
+
const ignored = new Set(['node_modules', '.git', '.gateflow', '.codex', 'dist', 'build', 'out', 'results', 'runtime-bindings', 'calldata', 'tx-requests']);
|
|
95
|
+
const visit = (directory: string) => {
|
|
96
|
+
for (const item of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
97
|
+
if (ignored.has(item.name) || /^(?:artifacts|cache|typechain|\.openzeppelin|\.gate-workflow-backup)/.test(item.name)) continue;
|
|
98
|
+
const file = path.join(directory, item.name);
|
|
99
|
+
const relative = path.relative(root, file).split(path.sep).join('/');
|
|
100
|
+
if (baseline.files[relative] || relative === 'package.json') continue;
|
|
101
|
+
if (item.isSymbolicLink()) { conflict(relative, 'Cannot inspect symlink for legacy runtime references'); continue; }
|
|
102
|
+
if (item.isDirectory()) { visit(file); continue; }
|
|
103
|
+
if (relative.startsWith('scripts/workflow/')) { conflict(relative, 'Unrecognized custom workflow file'); continue; }
|
|
104
|
+
if (!item.isFile() || !/\.(?:[cm]?[jt]sx?|json|ya?ml|sh|toml)$/.test(item.name) || item.name.endsWith('.lock.json') || /(?:package-lock|yarn.lock|pnpm-lock)/.test(item.name)) continue;
|
|
105
|
+
const source = fs.readFileSync(file, 'utf8');
|
|
106
|
+
let next = source;
|
|
107
|
+
if (/\.[cm]?[jt]sx?$/.test(item.name)) {
|
|
108
|
+
// Only static module specifiers are rewritten; filesystem paths/commands require review.
|
|
109
|
+
next = source.replace(/(\bfrom\s*|\b(?:require|import)\s*\(\s*|\bimport\s*)(["'])(\.[^"'\n]+)\2/g,
|
|
110
|
+
(all, prefix: string, quote: string, specifier: string) => {
|
|
111
|
+
const target = moduleTarget(file, specifier);
|
|
112
|
+
return target ? `${prefix}${quote}${target}${quote}` : all;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const unresolvedModule = [...next.matchAll(/["'](\.[^"'\n]+)["']/g)].some(match => moduleTarget(file, match[1]!) !== undefined);
|
|
116
|
+
if (unresolvedModule || /scripts[\\/]workflow|scripts[\\/]config[\\/](?:rpc|openzeppelin|zksyncSolcPath)/.test(next)) {
|
|
117
|
+
conflict(relative, 'Unresolved runtime path/reference; update manually before removal'); continue;
|
|
118
|
+
}
|
|
119
|
+
if (next !== source) { originals.set(relative, source); edits.set(relative, next); plan.push({ path: relative, status: 'update' }); }
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
visit(root);
|
|
123
|
+
const conflicts = plan.filter(item => item.status === 'conflict');
|
|
124
|
+
if (apply && conflicts.length) throw new Error('Runtime migration requires manual merge: ' + conflicts.map(item => `${item.path}: ${item.reason}`).join('; '));
|
|
125
|
+
let backup: string | undefined;
|
|
126
|
+
if (apply && originals.size > 0) {
|
|
127
|
+
// Recheck every input before creating the backup or applying changes.
|
|
128
|
+
for (const [relative, source] of originals) {
|
|
129
|
+
if (unsafe(relative) || fs.readFileSync(path.join(root, relative), 'utf8') !== source) throw new Error(`Migration input changed: ${relative}`);
|
|
130
|
+
}
|
|
131
|
+
backup = fs.mkdtempSync(path.join(root, '.gate-workflow-backup-'));
|
|
132
|
+
for (const [relative, source] of originals) {
|
|
133
|
+
const saved = path.join(backup, relative);
|
|
134
|
+
fs.mkdirSync(path.dirname(saved), { recursive: true });
|
|
135
|
+
fs.writeFileSync(saved, source);
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
// Rewrite consumers first, then remove the now-unreferenced known files.
|
|
139
|
+
for (const [relative, source] of edits) fs.writeFileSync(path.join(root, relative), source);
|
|
140
|
+
for (const item of plan.filter(item => item.status === 'remove')) fs.unlinkSync(path.join(root, item.path));
|
|
141
|
+
} catch (error) {
|
|
142
|
+
for (const [relative, source] of originals) fs.writeFileSync(path.join(root, relative), source);
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
const prune = (directory: string) => {
|
|
146
|
+
if (!fs.existsSync(directory) || fs.lstatSync(directory).isSymbolicLink()) return;
|
|
147
|
+
for (const item of fs.readdirSync(directory, { withFileTypes: true })) if (item.isDirectory()) prune(path.join(directory, item.name));
|
|
148
|
+
if (fs.readdirSync(directory).length === 0) fs.rmdirSync(directory);
|
|
149
|
+
};
|
|
150
|
+
prune(path.join(root, 'scripts/workflow'));
|
|
151
|
+
prune(path.join(root, 'scripts/config'));
|
|
152
|
+
}
|
|
153
|
+
return { applied: apply, baselineVersion: baseline.templateVersion, backup, plan };
|
|
154
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
// Runtime modules must use the selected project's HRE, not a package/global HRE.
|
|
4
|
+
const projectRequire = createRequire(path.join(process.cwd(), 'package.json'));
|
|
5
|
+
projectRequire('hardhat/register');
|
|
6
|
+
const hre: typeof import('hardhat') = projectRequire('hardhat');
|
|
7
|
+
export default hre;
|
|
8
|
+
export const { ethers, artifacts, network, config, upgrades } = hre;
|
|
9
|
+
|
|
10
|
+
export const run = hre.run.bind(hre);
|