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,576 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import type { WorkflowConfig } from "./config";
|
|
4
|
+
import { writeJsonFile } from "./config";
|
|
5
|
+
import { stageContractInfoCandidate } from "./contractInfoCandidates";
|
|
6
|
+
import {
|
|
7
|
+
cloneContractInfo,
|
|
8
|
+
ContractInfo,
|
|
9
|
+
contractInfoKey,
|
|
10
|
+
deploymentInstanceId,
|
|
11
|
+
loadContractInfo,
|
|
12
|
+
} from "./deployments";
|
|
13
|
+
|
|
14
|
+
export type DeploymentExecutionStatus =
|
|
15
|
+
| "prepared"
|
|
16
|
+
| "applied"
|
|
17
|
+
| "waiting_code_check"
|
|
18
|
+
| "waiting_external"
|
|
19
|
+
| "partial";
|
|
20
|
+
|
|
21
|
+
export type DeploymentChangeStatus =
|
|
22
|
+
| "prepared"
|
|
23
|
+
| "applied"
|
|
24
|
+
| "waiting_code_check"
|
|
25
|
+
| "waiting_external"
|
|
26
|
+
| "failed";
|
|
27
|
+
|
|
28
|
+
export interface GateToolEvidence {
|
|
29
|
+
outputPath: string;
|
|
30
|
+
data: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface PendingDeploymentReuseEvidence {
|
|
34
|
+
status: "verified";
|
|
35
|
+
sourceExecutionId: string;
|
|
36
|
+
sourceCandidatePath: string;
|
|
37
|
+
archivedCandidatePath?: string;
|
|
38
|
+
sourceDeploymentRecordPath: string;
|
|
39
|
+
sourceExecutionPlanPath: string;
|
|
40
|
+
sourceOperatorExecutionPath?: string;
|
|
41
|
+
sourceExecutionResultPath: string;
|
|
42
|
+
sourceVerificationPath: string;
|
|
43
|
+
releaseFingerprint: {
|
|
44
|
+
manifestHash: string;
|
|
45
|
+
artifactHash: string;
|
|
46
|
+
parametersHash: string;
|
|
47
|
+
configHash: string;
|
|
48
|
+
};
|
|
49
|
+
artifactDigest: string;
|
|
50
|
+
proxyAddress: string;
|
|
51
|
+
implementationAddress: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface DeploymentChange {
|
|
55
|
+
stepId: string;
|
|
56
|
+
kind: "deploy" | "upgrade";
|
|
57
|
+
instanceId: string;
|
|
58
|
+
actualContract: string;
|
|
59
|
+
contractInfoKey: string;
|
|
60
|
+
status?: DeploymentChangeStatus;
|
|
61
|
+
contractInfoChanged?: boolean;
|
|
62
|
+
strategy?: string;
|
|
63
|
+
proxyKind?: string;
|
|
64
|
+
address?: string;
|
|
65
|
+
proxyAddress?: string;
|
|
66
|
+
implementationAddress?: string;
|
|
67
|
+
preparedImplementationAddress?: string;
|
|
68
|
+
placeholderImplementationAddress?: string;
|
|
69
|
+
implementationTxHash?: string;
|
|
70
|
+
implementationSalt?: string;
|
|
71
|
+
constructorArgs?: unknown[];
|
|
72
|
+
factory?: string;
|
|
73
|
+
multicall?: string;
|
|
74
|
+
salt?: string;
|
|
75
|
+
expectedAddress?: string;
|
|
76
|
+
predictedAddress?: string;
|
|
77
|
+
leadingZeroBytes?: number;
|
|
78
|
+
txHash?: string;
|
|
79
|
+
proxyTransactionId?: string;
|
|
80
|
+
reused?: boolean;
|
|
81
|
+
alreadyDeployed?: boolean;
|
|
82
|
+
redeployReason?: string;
|
|
83
|
+
previousAddress?: string;
|
|
84
|
+
candidateAddress?: string;
|
|
85
|
+
candidatePath?: string;
|
|
86
|
+
backupPath?: string;
|
|
87
|
+
gateTool?: GateToolEvidence;
|
|
88
|
+
gateToolSync?: GateToolEvidence;
|
|
89
|
+
pendingReuse?: PendingDeploymentReuseEvidence;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface DeploymentExecutionRecord {
|
|
93
|
+
taskId: string;
|
|
94
|
+
executionId: string;
|
|
95
|
+
network: string;
|
|
96
|
+
status: DeploymentExecutionStatus;
|
|
97
|
+
startedAt: string;
|
|
98
|
+
updatedAt: string;
|
|
99
|
+
candidatePath?: string;
|
|
100
|
+
backupPath?: string;
|
|
101
|
+
candidateStatus?: "pending" | "promoted";
|
|
102
|
+
contractInfo: {
|
|
103
|
+
before: ContractInfo;
|
|
104
|
+
planned: ContractInfo;
|
|
105
|
+
after?: ContractInfo;
|
|
106
|
+
};
|
|
107
|
+
changes: Array<DeploymentChange & {
|
|
108
|
+
status: DeploymentChangeStatus;
|
|
109
|
+
contractInfoChanged: boolean;
|
|
110
|
+
}>;
|
|
111
|
+
external?: Record<string, unknown>;
|
|
112
|
+
failure?: {
|
|
113
|
+
name?: string;
|
|
114
|
+
message: string;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export const deploymentRecordPath = (
|
|
119
|
+
taskDir: string,
|
|
120
|
+
network: string,
|
|
121
|
+
executionId: string,
|
|
122
|
+
): string => path.join(taskDir, "results", `${network}.${executionId}.deployment.json`);
|
|
123
|
+
|
|
124
|
+
export const loadDeploymentExecutionRecord = (input: {
|
|
125
|
+
taskDir: string;
|
|
126
|
+
taskId: string;
|
|
127
|
+
network: string;
|
|
128
|
+
executionId: string;
|
|
129
|
+
}): DeploymentExecutionRecord => {
|
|
130
|
+
const filePath = deploymentRecordPath(input.taskDir, input.network, input.executionId);
|
|
131
|
+
let record: DeploymentExecutionRecord;
|
|
132
|
+
try {
|
|
133
|
+
record = JSON.parse(fs.readFileSync(filePath, "utf8")) as DeploymentExecutionRecord;
|
|
134
|
+
} catch (error) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
`Cannot load deployment record: ${error instanceof Error ? error.message : String(error)}`,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
if (
|
|
140
|
+
record.taskId !== input.taskId
|
|
141
|
+
|| record.network !== input.network
|
|
142
|
+
|| record.executionId !== input.executionId
|
|
143
|
+
|| !Array.isArray(record.changes)
|
|
144
|
+
) {
|
|
145
|
+
throw new Error("Deployment record identity does not match requested execution");
|
|
146
|
+
}
|
|
147
|
+
return record;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export const markDeploymentRecordReconciled = (input: {
|
|
151
|
+
taskDir: string;
|
|
152
|
+
taskId: string;
|
|
153
|
+
network: string;
|
|
154
|
+
executionId: string;
|
|
155
|
+
reportPath: string;
|
|
156
|
+
reportHash: string;
|
|
157
|
+
gateToolSyncByStep?: Record<string, GateToolEvidence>;
|
|
158
|
+
}): DeploymentExecutionRecord => {
|
|
159
|
+
const filePath = deploymentRecordPath(input.taskDir, input.network, input.executionId);
|
|
160
|
+
const record = loadDeploymentExecutionRecord(input);
|
|
161
|
+
if (record.status !== "waiting_external" && record.status !== "waiting_code_check") {
|
|
162
|
+
throw new Error(`Deployment record cannot be reconciled from status ${record.status}`);
|
|
163
|
+
}
|
|
164
|
+
if (record.status === "waiting_code_check") {
|
|
165
|
+
const reconciliation = record.external?.reconciliation as Record<string, unknown> | undefined;
|
|
166
|
+
if (
|
|
167
|
+
reconciliation?.reportPath === input.reportPath
|
|
168
|
+
&& reconciliation?.reportHash === input.reportHash
|
|
169
|
+
) {
|
|
170
|
+
return record;
|
|
171
|
+
}
|
|
172
|
+
throw new Error("Deployment record was already reconciled with different evidence");
|
|
173
|
+
}
|
|
174
|
+
const next: DeploymentExecutionRecord = {
|
|
175
|
+
...record,
|
|
176
|
+
status: "waiting_code_check",
|
|
177
|
+
updatedAt: new Date().toISOString(),
|
|
178
|
+
changes: record.changes.map((change) => (
|
|
179
|
+
change.status === "waiting_external" || change.status === "prepared"
|
|
180
|
+
? {
|
|
181
|
+
...change,
|
|
182
|
+
status: "waiting_code_check",
|
|
183
|
+
...(input.gateToolSyncByStep?.[change.stepId]
|
|
184
|
+
? { gateToolSync: input.gateToolSyncByStep[change.stepId] }
|
|
185
|
+
: {}),
|
|
186
|
+
}
|
|
187
|
+
: input.gateToolSyncByStep?.[change.stepId]
|
|
188
|
+
? { ...change, gateToolSync: input.gateToolSyncByStep[change.stepId] }
|
|
189
|
+
: change
|
|
190
|
+
)),
|
|
191
|
+
external: {
|
|
192
|
+
...(record.external || {}),
|
|
193
|
+
reconciliation: {
|
|
194
|
+
status: "reconciled",
|
|
195
|
+
reportPath: input.reportPath,
|
|
196
|
+
reportHash: input.reportHash,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
writeJsonFile(filePath, next);
|
|
201
|
+
return next;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export interface DeploymentRecorderOptions {
|
|
205
|
+
root: string;
|
|
206
|
+
taskDir: string;
|
|
207
|
+
config: WorkflowConfig;
|
|
208
|
+
taskId: string;
|
|
209
|
+
executionId: string;
|
|
210
|
+
network: string;
|
|
211
|
+
awaitRegistryCommit?: boolean;
|
|
212
|
+
resume?: boolean;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const errorDetails = (error: unknown): { name?: string; message: string } => {
|
|
216
|
+
if (error instanceof Error) {
|
|
217
|
+
return { name: error.name, message: error.message };
|
|
218
|
+
}
|
|
219
|
+
return { message: String(error) };
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export class DeploymentRecorder {
|
|
223
|
+
readonly filePath: string;
|
|
224
|
+
|
|
225
|
+
private readonly root: string;
|
|
226
|
+
private readonly config: WorkflowConfig;
|
|
227
|
+
private readonly record: DeploymentExecutionRecord;
|
|
228
|
+
private readonly awaitRegistryCommit: boolean;
|
|
229
|
+
|
|
230
|
+
constructor(options: DeploymentRecorderOptions) {
|
|
231
|
+
this.root = options.root;
|
|
232
|
+
this.config = options.config;
|
|
233
|
+
this.awaitRegistryCommit = options.awaitRegistryCommit === true;
|
|
234
|
+
this.filePath = deploymentRecordPath(
|
|
235
|
+
options.taskDir,
|
|
236
|
+
options.network,
|
|
237
|
+
options.executionId,
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
if (options.resume === true) {
|
|
241
|
+
this.record = this.loadResumableRecord(options);
|
|
242
|
+
} else {
|
|
243
|
+
const startedAt = new Date().toISOString();
|
|
244
|
+
const before = cloneContractInfo(loadContractInfo(options.root, options.config));
|
|
245
|
+
this.record = {
|
|
246
|
+
taskId: options.taskId,
|
|
247
|
+
executionId: options.executionId,
|
|
248
|
+
network: options.network,
|
|
249
|
+
status: "prepared",
|
|
250
|
+
startedAt,
|
|
251
|
+
updatedAt: startedAt,
|
|
252
|
+
contractInfo: {
|
|
253
|
+
before,
|
|
254
|
+
planned: cloneContractInfo(before),
|
|
255
|
+
},
|
|
256
|
+
changes: [],
|
|
257
|
+
};
|
|
258
|
+
this.persistInitial();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
prepare(change: DeploymentChange): void {
|
|
263
|
+
deploymentInstanceId(change.instanceId);
|
|
264
|
+
this.upsertChange(change, "prepared", false);
|
|
265
|
+
this.record.status = "prepared";
|
|
266
|
+
delete this.record.failure;
|
|
267
|
+
this.persist();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
bindProxyTransaction(stepId: string, transactionId: string): void {
|
|
271
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9_-]{0,199}$/.test(transactionId)) {
|
|
272
|
+
throw new Error("Deployment proxy transactionId is invalid");
|
|
273
|
+
}
|
|
274
|
+
const change = this.record.changes.find((entry) => entry.stepId === stepId);
|
|
275
|
+
if (!change || change.proxyKind !== "uups") {
|
|
276
|
+
throw new Error(`Cannot bind a proxy transaction for deployment change ${stepId}`);
|
|
277
|
+
}
|
|
278
|
+
if (
|
|
279
|
+
change.proxyTransactionId
|
|
280
|
+
&& change.proxyTransactionId !== transactionId
|
|
281
|
+
) {
|
|
282
|
+
throw new Error(`Deployment change ${stepId} is already bound to another proxy transaction`);
|
|
283
|
+
}
|
|
284
|
+
change.proxyTransactionId = transactionId;
|
|
285
|
+
this.persist();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
stageAddressCandidate(change: DeploymentChange, address: string): void {
|
|
289
|
+
const canonicalKey = contractInfoKey(change.instanceId, change.actualContract);
|
|
290
|
+
if (change.contractInfoKey !== canonicalKey) {
|
|
291
|
+
throw new Error(
|
|
292
|
+
`Deployment record key ${change.contractInfoKey} does not match canonical key ${canonicalKey}`,
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
const staged = stageContractInfoCandidate(
|
|
296
|
+
{
|
|
297
|
+
root: this.root,
|
|
298
|
+
taskDir: path.dirname(path.dirname(this.filePath)),
|
|
299
|
+
config: this.config,
|
|
300
|
+
deploymentId: this.record.taskId,
|
|
301
|
+
executionId: this.record.executionId,
|
|
302
|
+
network: this.record.network,
|
|
303
|
+
supersedeCandidatePath: change.pendingReuse?.sourceCandidatePath,
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
instanceId: change.instanceId,
|
|
307
|
+
contractName: change.actualContract,
|
|
308
|
+
address,
|
|
309
|
+
},
|
|
310
|
+
);
|
|
311
|
+
this.record.candidatePath = staged.candidatePath;
|
|
312
|
+
this.record.backupPath = staged.backupPath;
|
|
313
|
+
this.record.candidateStatus = "pending";
|
|
314
|
+
this.record.contractInfo.planned = cloneContractInfo(staged.candidate.contractInfo);
|
|
315
|
+
this.record.contractInfo.after = cloneContractInfo(
|
|
316
|
+
loadContractInfo(this.root, this.config),
|
|
317
|
+
);
|
|
318
|
+
this.upsertChange(
|
|
319
|
+
{
|
|
320
|
+
...change,
|
|
321
|
+
address,
|
|
322
|
+
previousAddress: staged.replacement.previousAddress,
|
|
323
|
+
candidateAddress: staged.replacement.candidateAddress,
|
|
324
|
+
candidatePath: staged.candidatePath,
|
|
325
|
+
backupPath: staged.backupPath,
|
|
326
|
+
...(change.pendingReuse
|
|
327
|
+
? {
|
|
328
|
+
pendingReuse: {
|
|
329
|
+
...change.pendingReuse,
|
|
330
|
+
...(staged.archivedCandidatePath
|
|
331
|
+
? { archivedCandidatePath: staged.archivedCandidatePath }
|
|
332
|
+
: {}),
|
|
333
|
+
},
|
|
334
|
+
}
|
|
335
|
+
: {}),
|
|
336
|
+
},
|
|
337
|
+
"prepared",
|
|
338
|
+
true,
|
|
339
|
+
);
|
|
340
|
+
this.record.status = "prepared";
|
|
341
|
+
this.persist();
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
applyAddress(change: DeploymentChange, address: string): void {
|
|
345
|
+
const canonicalKey = contractInfoKey(change.instanceId, change.actualContract);
|
|
346
|
+
if (change.contractInfoKey !== canonicalKey) {
|
|
347
|
+
throw new Error(
|
|
348
|
+
`Deployment record key ${change.contractInfoKey} does not match canonical key ${canonicalKey}`,
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
const preparedChange = {
|
|
352
|
+
...change,
|
|
353
|
+
address,
|
|
354
|
+
candidateAddress: address,
|
|
355
|
+
contractInfoKey: canonicalKey,
|
|
356
|
+
};
|
|
357
|
+
this.upsertChange(preparedChange, "prepared", true);
|
|
358
|
+
this.record.status = "prepared";
|
|
359
|
+
this.persist();
|
|
360
|
+
|
|
361
|
+
try {
|
|
362
|
+
const staged = stageContractInfoCandidate(
|
|
363
|
+
{
|
|
364
|
+
root: this.root,
|
|
365
|
+
taskDir: path.dirname(path.dirname(this.filePath)),
|
|
366
|
+
config: this.config,
|
|
367
|
+
deploymentId: this.record.taskId,
|
|
368
|
+
executionId: this.record.executionId,
|
|
369
|
+
network: this.record.network,
|
|
370
|
+
supersedeCandidatePath: change.pendingReuse?.sourceCandidatePath,
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
instanceId: change.instanceId,
|
|
374
|
+
contractName: change.actualContract,
|
|
375
|
+
address,
|
|
376
|
+
},
|
|
377
|
+
);
|
|
378
|
+
const pendingChange = {
|
|
379
|
+
...preparedChange,
|
|
380
|
+
contractInfoKey: staged.replacement.candidateKey,
|
|
381
|
+
previousAddress: staged.replacement.previousAddress,
|
|
382
|
+
candidateAddress: staged.replacement.candidateAddress,
|
|
383
|
+
candidatePath: staged.candidatePath,
|
|
384
|
+
backupPath: staged.backupPath,
|
|
385
|
+
...(change.pendingReuse
|
|
386
|
+
? {
|
|
387
|
+
pendingReuse: {
|
|
388
|
+
...change.pendingReuse,
|
|
389
|
+
...(staged.archivedCandidatePath
|
|
390
|
+
? { archivedCandidatePath: staged.archivedCandidatePath }
|
|
391
|
+
: {}),
|
|
392
|
+
},
|
|
393
|
+
}
|
|
394
|
+
: {}),
|
|
395
|
+
};
|
|
396
|
+
this.record.candidatePath = staged.candidatePath;
|
|
397
|
+
this.record.backupPath = staged.backupPath;
|
|
398
|
+
this.record.candidateStatus = "pending";
|
|
399
|
+
this.record.contractInfo.planned = cloneContractInfo(staged.candidate.contractInfo);
|
|
400
|
+
this.record.contractInfo.after = cloneContractInfo(
|
|
401
|
+
loadContractInfo(this.root, this.config),
|
|
402
|
+
);
|
|
403
|
+
this.upsertChange(pendingChange, "waiting_code_check", true);
|
|
404
|
+
this.record.status = "waiting_code_check";
|
|
405
|
+
delete this.record.failure;
|
|
406
|
+
this.persist();
|
|
407
|
+
} catch (error) {
|
|
408
|
+
this.upsertChange(preparedChange, "failed", true);
|
|
409
|
+
this.record.status = "partial";
|
|
410
|
+
this.record.failure = errorDetails(error);
|
|
411
|
+
this.record.contractInfo.after = cloneContractInfo(
|
|
412
|
+
loadContractInfo(this.root, this.config),
|
|
413
|
+
);
|
|
414
|
+
this.persist();
|
|
415
|
+
throw error;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
apply(change: DeploymentChange): void {
|
|
420
|
+
const current = cloneContractInfo(loadContractInfo(this.root, this.config));
|
|
421
|
+
this.record.contractInfo.planned = current;
|
|
422
|
+
this.record.contractInfo.after = cloneContractInfo(current);
|
|
423
|
+
this.upsertChange(change, "applied", false);
|
|
424
|
+
this.updateAppliedStatus();
|
|
425
|
+
this.persist();
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
markWaitingExternal(external: Record<string, unknown>): void {
|
|
429
|
+
this.record.status = "waiting_external";
|
|
430
|
+
this.record.external = external;
|
|
431
|
+
this.record.contractInfo.after = cloneContractInfo(
|
|
432
|
+
loadContractInfo(this.root, this.config),
|
|
433
|
+
);
|
|
434
|
+
this.record.changes = this.record.changes.map((change) => (
|
|
435
|
+
change.status === "prepared"
|
|
436
|
+
? { ...change, status: "waiting_external" }
|
|
437
|
+
: change
|
|
438
|
+
));
|
|
439
|
+
this.persist();
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
markPartial(error: unknown): void {
|
|
443
|
+
this.record.status = "partial";
|
|
444
|
+
this.record.failure = errorDetails(error);
|
|
445
|
+
this.record.contractInfo.after = cloneContractInfo(
|
|
446
|
+
loadContractInfo(this.root, this.config),
|
|
447
|
+
);
|
|
448
|
+
this.record.changes = this.record.changes.map((change) => (
|
|
449
|
+
change.status === "prepared" || change.status === "waiting_external"
|
|
450
|
+
? { ...change, status: "failed" }
|
|
451
|
+
: change
|
|
452
|
+
));
|
|
453
|
+
this.persist();
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
complete(): DeploymentExecutionStatus {
|
|
457
|
+
this.record.contractInfo.after = cloneContractInfo(
|
|
458
|
+
loadContractInfo(this.root, this.config),
|
|
459
|
+
);
|
|
460
|
+
if (
|
|
461
|
+
this.awaitRegistryCommit
|
|
462
|
+
&& this.record.changes.every((change) => change.status !== "failed")
|
|
463
|
+
) {
|
|
464
|
+
this.record.status = "waiting_code_check";
|
|
465
|
+
} else if (this.record.changes.some((change) => change.status === "waiting_code_check")) {
|
|
466
|
+
this.record.status = "waiting_code_check";
|
|
467
|
+
} else {
|
|
468
|
+
this.record.status = this.record.changes.every((change) => change.status === "applied")
|
|
469
|
+
? "applied"
|
|
470
|
+
: "partial";
|
|
471
|
+
}
|
|
472
|
+
this.persist();
|
|
473
|
+
return this.record.status;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
private upsertChange(
|
|
477
|
+
change: DeploymentChange,
|
|
478
|
+
status: DeploymentChangeStatus,
|
|
479
|
+
contractInfoChanged: boolean,
|
|
480
|
+
): void {
|
|
481
|
+
const index = this.record.changes.findIndex((item) => item.stepId === change.stepId);
|
|
482
|
+
const existing = index >= 0 ? this.record.changes[index] : undefined;
|
|
483
|
+
let pendingReuse = change.pendingReuse ?? existing?.pendingReuse;
|
|
484
|
+
if (existing?.pendingReuse && change.pendingReuse) {
|
|
485
|
+
pendingReuse = { ...existing.pendingReuse, ...change.pendingReuse };
|
|
486
|
+
}
|
|
487
|
+
const next: DeploymentChange & {
|
|
488
|
+
status: DeploymentChangeStatus;
|
|
489
|
+
contractInfoChanged: boolean;
|
|
490
|
+
} = {
|
|
491
|
+
...existing,
|
|
492
|
+
...change,
|
|
493
|
+
status,
|
|
494
|
+
contractInfoChanged: existing?.contractInfoChanged || contractInfoChanged,
|
|
495
|
+
...(pendingReuse ? { pendingReuse } : {}),
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
if (index >= 0) {
|
|
499
|
+
this.record.changes[index] = next;
|
|
500
|
+
} else {
|
|
501
|
+
this.record.changes.push(next);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
private updateAppliedStatus(): void {
|
|
506
|
+
if (this.record.changes.some((change) => change.status === "waiting_code_check")) {
|
|
507
|
+
this.record.status = "waiting_code_check";
|
|
508
|
+
} else {
|
|
509
|
+
this.record.status = this.record.changes.every((change) => change.status === "applied")
|
|
510
|
+
? "applied"
|
|
511
|
+
: "prepared";
|
|
512
|
+
}
|
|
513
|
+
delete this.record.failure;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
private persist(): void {
|
|
517
|
+
this.record.updatedAt = new Date().toISOString();
|
|
518
|
+
writeJsonFile(this.filePath, this.record);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
private persistInitial(): void {
|
|
522
|
+
this.record.updatedAt = new Date().toISOString();
|
|
523
|
+
fs.mkdirSync(path.dirname(this.filePath), { recursive: true });
|
|
524
|
+
|
|
525
|
+
let file: number;
|
|
526
|
+
try {
|
|
527
|
+
file = fs.openSync(this.filePath, "wx");
|
|
528
|
+
} catch (error) {
|
|
529
|
+
if (
|
|
530
|
+
error &&
|
|
531
|
+
typeof error === "object" &&
|
|
532
|
+
"code" in error &&
|
|
533
|
+
String((error as { code?: unknown }).code) === "EEXIST"
|
|
534
|
+
) {
|
|
535
|
+
throw new Error(`Deployment record already exists: ${this.filePath}`);
|
|
536
|
+
}
|
|
537
|
+
throw error;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
try {
|
|
541
|
+
fs.writeFileSync(file, `${JSON.stringify(this.record, null, 2)}\n`);
|
|
542
|
+
fs.fsyncSync(file);
|
|
543
|
+
} catch (error) {
|
|
544
|
+
fs.closeSync(file);
|
|
545
|
+
fs.unlinkSync(this.filePath);
|
|
546
|
+
throw error;
|
|
547
|
+
}
|
|
548
|
+
fs.closeSync(file);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
private loadResumableRecord(options: DeploymentRecorderOptions): DeploymentExecutionRecord {
|
|
552
|
+
let parsed: unknown;
|
|
553
|
+
try {
|
|
554
|
+
parsed = JSON.parse(fs.readFileSync(this.filePath, "utf8"));
|
|
555
|
+
} catch (error) {
|
|
556
|
+
throw new Error(
|
|
557
|
+
`Cannot resume deployment record: ${error instanceof Error ? error.message : String(error)}`,
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
561
|
+
throw new Error("Cannot resume an invalid deployment record");
|
|
562
|
+
}
|
|
563
|
+
const record = parsed as DeploymentExecutionRecord;
|
|
564
|
+
if (
|
|
565
|
+
record.taskId !== options.taskId
|
|
566
|
+
|| record.executionId !== options.executionId
|
|
567
|
+
|| record.network !== options.network
|
|
568
|
+
|| (record.status !== "waiting_external" && record.status !== "partial")
|
|
569
|
+
|| !record.contractInfo
|
|
570
|
+
|| !Array.isArray(record.changes)
|
|
571
|
+
) {
|
|
572
|
+
throw new Error("Deployment record is not resumable for this execution");
|
|
573
|
+
}
|
|
574
|
+
return record;
|
|
575
|
+
}
|
|
576
|
+
}
|