gate-evm-tools 1.0.25 → 1.0.27

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.
Files changed (352) hide show
  1. package/README.md +33 -11
  2. package/bin/workflow.cjs +19 -0
  3. package/dist/commands/check.d.ts.map +1 -1
  4. package/dist/commands/check.js +21 -57
  5. package/dist/commands/check.js.map +1 -1
  6. package/dist/commands/checkBatch.d.ts +4 -0
  7. package/dist/commands/checkBatch.d.ts.map +1 -0
  8. package/dist/commands/checkBatch.js +57 -0
  9. package/dist/commands/checkBatch.js.map +1 -0
  10. package/dist/commands/checkOptions.d.ts +3 -0
  11. package/dist/commands/checkOptions.d.ts.map +1 -1
  12. package/dist/commands/checkOptions.js +10 -1
  13. package/dist/commands/checkOptions.js.map +1 -1
  14. package/dist/commands/prepare.d.ts +1 -2
  15. package/dist/commands/prepare.d.ts.map +1 -1
  16. package/dist/commands/prepare.js +2 -17
  17. package/dist/commands/prepare.js.map +1 -1
  18. package/dist/commands/sync.d.ts.map +1 -1
  19. package/dist/commands/sync.js +2 -17
  20. package/dist/commands/sync.js.map +1 -1
  21. package/dist/commands/validate.d.ts.map +1 -1
  22. package/dist/commands/validate.js +2 -17
  23. package/dist/commands/validate.js.map +1 -1
  24. package/dist/core/BytecodeChecker.d.ts.map +1 -1
  25. package/dist/core/BytecodeChecker.js +16 -1
  26. package/dist/core/BytecodeChecker.js.map +1 -1
  27. package/dist/core/legacyProxyArtifact.d.ts +6 -0
  28. package/dist/core/legacyProxyArtifact.d.ts.map +1 -0
  29. package/dist/core/legacyProxyArtifact.js +36 -0
  30. package/dist/core/legacyProxyArtifact.js.map +1 -0
  31. package/dist/index.js +3 -3
  32. package/dist/index.js.map +1 -1
  33. package/dist/types.d.ts +2 -2
  34. package/dist/types.d.ts.map +1 -1
  35. package/dist/utils/hardhat.d.ts +4 -0
  36. package/dist/utils/hardhat.d.ts.map +1 -0
  37. package/dist/utils/hardhat.js +9 -0
  38. package/dist/utils/hardhat.js.map +1 -0
  39. package/dist-runtime/config/hardhatAdapters.d.ts +5 -0
  40. package/dist-runtime/config/hardhatAdapters.js +53 -0
  41. package/dist-runtime/config/hardhatAdapters.js.map +1 -0
  42. package/dist-runtime/config/networks.d.ts +8 -0
  43. package/dist-runtime/config/networks.js +269 -0
  44. package/dist-runtime/config/networks.js.map +1 -0
  45. package/dist-runtime/config/openzeppelin.d.ts +28 -0
  46. package/dist-runtime/config/openzeppelin.js +144 -0
  47. package/dist-runtime/config/openzeppelin.js.map +1 -0
  48. package/dist-runtime/config/rpc.d.ts +7 -0
  49. package/dist-runtime/config/rpc.js +19 -0
  50. package/dist-runtime/config/rpc.js.map +1 -0
  51. package/dist-runtime/config/zksyncSolcPath.d.ts +1 -0
  52. package/dist-runtime/config/zksyncSolcPath.js +61 -0
  53. package/dist-runtime/config/zksyncSolcPath.js.map +1 -0
  54. package/dist-runtime/migrate.d.ts +13 -0
  55. package/dist-runtime/migrate.js +208 -0
  56. package/dist-runtime/migrate.js.map +1 -0
  57. package/dist-runtime/package.json +1 -0
  58. package/dist-runtime/projectHardhat.d.ts +4 -0
  59. package/dist-runtime/projectHardhat.js +16 -0
  60. package/dist-runtime/projectHardhat.js.map +1 -0
  61. package/dist-runtime/runtime-identity.json +4 -0
  62. package/dist-runtime/template-migration.json +293 -0
  63. package/dist-runtime/workflow/checkCode.d.ts +1 -0
  64. package/dist-runtime/workflow/checkCode.js +16 -0
  65. package/dist-runtime/workflow/checkCode.js.map +1 -0
  66. package/dist-runtime/workflow/checkCodeFinalize.d.ts +1 -0
  67. package/dist-runtime/workflow/checkCodeFinalize.js +11 -0
  68. package/dist-runtime/workflow/checkCodeFinalize.js.map +1 -0
  69. package/dist-runtime/workflow/checkCodePlan.d.ts +1 -0
  70. package/dist-runtime/workflow/checkCodePlan.js +11 -0
  71. package/dist-runtime/workflow/checkCodePlan.js.map +1 -0
  72. package/dist-runtime/workflow/cli.d.ts +1 -0
  73. package/dist-runtime/workflow/cli.js +302 -0
  74. package/dist-runtime/workflow/cli.js.map +1 -0
  75. package/dist-runtime/workflow/commitContractInfo.d.ts +1 -0
  76. package/dist-runtime/workflow/commitContractInfo.js +64 -0
  77. package/dist-runtime/workflow/commitContractInfo.js.map +1 -0
  78. package/dist-runtime/workflow/create2Hashes.d.ts +1 -0
  79. package/dist-runtime/workflow/create2Hashes.js +76 -0
  80. package/dist-runtime/workflow/create2Hashes.js.map +1 -0
  81. package/dist-runtime/workflow/forkSourceProxy.d.ts +1 -0
  82. package/dist-runtime/workflow/forkSourceProxy.js +151 -0
  83. package/dist-runtime/workflow/forkSourceProxy.js.map +1 -0
  84. package/dist-runtime/workflow/importState.d.ts +1 -0
  85. package/dist-runtime/workflow/importState.js +193 -0
  86. package/dist-runtime/workflow/importState.js.map +1 -0
  87. package/dist-runtime/workflow/lib/authority.d.ts +28 -0
  88. package/dist-runtime/workflow/lib/authority.js +122 -0
  89. package/dist-runtime/workflow/lib/authority.js.map +1 -0
  90. package/dist-runtime/workflow/lib/calldata.d.ts +2 -0
  91. package/dist-runtime/workflow/lib/calldata.js +8 -0
  92. package/dist-runtime/workflow/lib/calldata.js.map +1 -0
  93. package/dist-runtime/workflow/lib/calls.d.ts +23 -0
  94. package/dist-runtime/workflow/lib/calls.js +316 -0
  95. package/dist-runtime/workflow/lib/calls.js.map +1 -0
  96. package/dist-runtime/workflow/lib/checkCode/args.d.ts +2 -0
  97. package/dist-runtime/workflow/lib/checkCode/args.js +68 -0
  98. package/dist-runtime/workflow/lib/checkCode/args.js.map +1 -0
  99. package/dist-runtime/workflow/lib/checkCode/command.d.ts +5 -0
  100. package/dist-runtime/workflow/lib/checkCode/command.js +35 -0
  101. package/dist-runtime/workflow/lib/checkCode/command.js.map +1 -0
  102. package/dist-runtime/workflow/lib/checkCode/dependencies.d.ts +6 -0
  103. package/dist-runtime/workflow/lib/checkCode/dependencies.js +125 -0
  104. package/dist-runtime/workflow/lib/checkCode/dependencies.js.map +1 -0
  105. package/dist-runtime/workflow/lib/checkCode/finalize.d.ts +17 -0
  106. package/dist-runtime/workflow/lib/checkCode/finalize.js +174 -0
  107. package/dist-runtime/workflow/lib/checkCode/finalize.js.map +1 -0
  108. package/dist-runtime/workflow/lib/checkCode/index.d.ts +3 -0
  109. package/dist-runtime/workflow/lib/checkCode/index.js +20 -0
  110. package/dist-runtime/workflow/lib/checkCode/index.js.map +1 -0
  111. package/dist-runtime/workflow/lib/checkCode/plan.d.ts +22 -0
  112. package/dist-runtime/workflow/lib/checkCode/plan.js +145 -0
  113. package/dist-runtime/workflow/lib/checkCode/plan.js.map +1 -0
  114. package/dist-runtime/workflow/lib/checkCodeReport.d.ts +25 -0
  115. package/dist-runtime/workflow/lib/checkCodeReport.js +102 -0
  116. package/dist-runtime/workflow/lib/checkCodeReport.js.map +1 -0
  117. package/dist-runtime/workflow/lib/checkCodeRunner.d.ts +87 -0
  118. package/dist-runtime/workflow/lib/checkCodeRunner.js +964 -0
  119. package/dist-runtime/workflow/lib/checkCodeRunner.js.map +1 -0
  120. package/dist-runtime/workflow/lib/cliTool.d.ts +10 -0
  121. package/dist-runtime/workflow/lib/cliTool.js +25 -0
  122. package/dist-runtime/workflow/lib/cliTool.js.map +1 -0
  123. package/dist-runtime/workflow/lib/config.d.ts +33 -0
  124. package/dist-runtime/workflow/lib/config.js +100 -0
  125. package/dist-runtime/workflow/lib/config.js.map +1 -0
  126. package/dist-runtime/workflow/lib/contractInfoCandidates.d.ts +82 -0
  127. package/dist-runtime/workflow/lib/contractInfoCandidates.js +441 -0
  128. package/dist-runtime/workflow/lib/contractInfoCandidates.js.map +1 -0
  129. package/dist-runtime/workflow/lib/create2.d.ts +49 -0
  130. package/dist-runtime/workflow/lib/create2.js +194 -0
  131. package/dist-runtime/workflow/lib/create2.js.map +1 -0
  132. package/dist-runtime/workflow/lib/create2Hashes.d.ts +22 -0
  133. package/dist-runtime/workflow/lib/create2Hashes.js +57 -0
  134. package/dist-runtime/workflow/lib/create2Hashes.js.map +1 -0
  135. package/dist-runtime/workflow/lib/deploymentInfo.d.ts +40 -0
  136. package/dist-runtime/workflow/lib/deploymentInfo.js +240 -0
  137. package/dist-runtime/workflow/lib/deploymentInfo.js.map +1 -0
  138. package/dist-runtime/workflow/lib/deploymentRecords.d.ts +137 -0
  139. package/dist-runtime/workflow/lib/deploymentRecords.js +374 -0
  140. package/dist-runtime/workflow/lib/deploymentRecords.js.map +1 -0
  141. package/dist-runtime/workflow/lib/deployments.d.ts +21 -0
  142. package/dist-runtime/workflow/lib/deployments.js +240 -0
  143. package/dist-runtime/workflow/lib/deployments.js.map +1 -0
  144. package/dist-runtime/workflow/lib/erc1967.d.ts +5 -0
  145. package/dist-runtime/workflow/lib/erc1967.js +29 -0
  146. package/dist-runtime/workflow/lib/erc1967.js.map +1 -0
  147. package/dist-runtime/workflow/lib/errors.d.ts +6 -0
  148. package/dist-runtime/workflow/lib/errors.js +77 -0
  149. package/dist-runtime/workflow/lib/errors.js.map +1 -0
  150. package/dist-runtime/workflow/lib/executionId.d.ts +7 -0
  151. package/dist-runtime/workflow/lib/executionId.js +26 -0
  152. package/dist-runtime/workflow/lib/executionId.js.map +1 -0
  153. package/dist-runtime/workflow/lib/executionPlan.d.ts +85 -0
  154. package/dist-runtime/workflow/lib/executionPlan.js +450 -0
  155. package/dist-runtime/workflow/lib/executionPlan.js.map +1 -0
  156. package/dist-runtime/workflow/lib/executionProgress.d.ts +5 -0
  157. package/dist-runtime/workflow/lib/executionProgress.js +100 -0
  158. package/dist-runtime/workflow/lib/executionProgress.js.map +1 -0
  159. package/dist-runtime/workflow/lib/external.d.ts +62 -0
  160. package/dist-runtime/workflow/lib/external.js +282 -0
  161. package/dist-runtime/workflow/lib/external.js.map +1 -0
  162. package/dist-runtime/workflow/lib/externalExecutionScanner.d.ts +64 -0
  163. package/dist-runtime/workflow/lib/externalExecutionScanner.js +638 -0
  164. package/dist-runtime/workflow/lib/externalExecutionScanner.js.map +1 -0
  165. package/dist-runtime/workflow/lib/forkSnapshot.d.ts +34 -0
  166. package/dist-runtime/workflow/lib/forkSnapshot.js +167 -0
  167. package/dist-runtime/workflow/lib/forkSnapshot.js.map +1 -0
  168. package/dist-runtime/workflow/lib/gateTool.d.ts +16 -0
  169. package/dist-runtime/workflow/lib/gateTool.js +177 -0
  170. package/dist-runtime/workflow/lib/gateTool.js.map +1 -0
  171. package/dist-runtime/workflow/lib/gateToolSync.d.ts +22 -0
  172. package/dist-runtime/workflow/lib/gateToolSync.js +253 -0
  173. package/dist-runtime/workflow/lib/gateToolSync.js.map +1 -0
  174. package/dist-runtime/workflow/lib/lock.d.ts +52 -0
  175. package/dist-runtime/workflow/lib/lock.js +269 -0
  176. package/dist-runtime/workflow/lib/lock.js.map +1 -0
  177. package/dist-runtime/workflow/lib/migrationState.d.ts +103 -0
  178. package/dist-runtime/workflow/lib/migrationState.js +920 -0
  179. package/dist-runtime/workflow/lib/migrationState.js.map +1 -0
  180. package/dist-runtime/workflow/lib/operatorExecution.d.ts +28 -0
  181. package/dist-runtime/workflow/lib/operatorExecution.js +134 -0
  182. package/dist-runtime/workflow/lib/operatorExecution.js.map +1 -0
  183. package/dist-runtime/workflow/lib/parameters.d.ts +58 -0
  184. package/dist-runtime/workflow/lib/parameters.js +322 -0
  185. package/dist-runtime/workflow/lib/parameters.js.map +1 -0
  186. package/dist-runtime/workflow/lib/pendingDeploymentReuse.d.ts +29 -0
  187. package/dist-runtime/workflow/lib/pendingDeploymentReuse.js +277 -0
  188. package/dist-runtime/workflow/lib/pendingDeploymentReuse.js.map +1 -0
  189. package/dist-runtime/workflow/lib/proxy.d.ts +18 -0
  190. package/dist-runtime/workflow/lib/proxy.js +19 -0
  191. package/dist-runtime/workflow/lib/proxy.js.map +1 -0
  192. package/dist-runtime/workflow/lib/registryCommit.d.ts +33 -0
  193. package/dist-runtime/workflow/lib/registryCommit.js +319 -0
  194. package/dist-runtime/workflow/lib/registryCommit.js.map +1 -0
  195. package/dist-runtime/workflow/lib/release.d.ts +57 -0
  196. package/dist-runtime/workflow/lib/release.js +256 -0
  197. package/dist-runtime/workflow/lib/release.js.map +1 -0
  198. package/dist-runtime/workflow/lib/releaseFinalize.d.ts +14 -0
  199. package/dist-runtime/workflow/lib/releaseFinalize.js +571 -0
  200. package/dist-runtime/workflow/lib/releaseFinalize.js.map +1 -0
  201. package/dist-runtime/workflow/lib/releaseParameters.d.ts +43 -0
  202. package/dist-runtime/workflow/lib/releaseParameters.js +184 -0
  203. package/dist-runtime/workflow/lib/releaseParameters.js.map +1 -0
  204. package/dist-runtime/workflow/lib/reporter.d.ts +39 -0
  205. package/dist-runtime/workflow/lib/reporter.js +452 -0
  206. package/dist-runtime/workflow/lib/reporter.js.map +1 -0
  207. package/dist-runtime/workflow/lib/resultPaths.d.ts +17 -0
  208. package/dist-runtime/workflow/lib/resultPaths.js +29 -0
  209. package/dist-runtime/workflow/lib/resultPaths.js.map +1 -0
  210. package/dist-runtime/workflow/lib/runtimeVersion.d.ts +10 -0
  211. package/dist-runtime/workflow/lib/runtimeVersion.js +46 -0
  212. package/dist-runtime/workflow/lib/runtimeVersion.js.map +1 -0
  213. package/dist-runtime/workflow/lib/signer.d.ts +10 -0
  214. package/dist-runtime/workflow/lib/signer.js +105 -0
  215. package/dist-runtime/workflow/lib/signer.js.map +1 -0
  216. package/dist-runtime/workflow/lib/signerIdentity.d.ts +1 -0
  217. package/dist-runtime/workflow/lib/signerIdentity.js +23 -0
  218. package/dist-runtime/workflow/lib/signerIdentity.js.map +1 -0
  219. package/dist-runtime/workflow/lib/simulation.d.ts +35 -0
  220. package/dist-runtime/workflow/lib/simulation.js +282 -0
  221. package/dist-runtime/workflow/lib/simulation.js.map +1 -0
  222. package/dist-runtime/workflow/lib/simulationCallers.d.ts +44 -0
  223. package/dist-runtime/workflow/lib/simulationCallers.js +260 -0
  224. package/dist-runtime/workflow/lib/simulationCallers.js.map +1 -0
  225. package/dist-runtime/workflow/lib/sourceRpcPolicy.d.ts +1 -0
  226. package/dist-runtime/workflow/lib/sourceRpcPolicy.js +43 -0
  227. package/dist-runtime/workflow/lib/sourceRpcPolicy.js.map +1 -0
  228. package/dist-runtime/workflow/lib/state.d.ts +6 -0
  229. package/dist-runtime/workflow/lib/state.js +25 -0
  230. package/dist-runtime/workflow/lib/state.js.map +1 -0
  231. package/dist-runtime/workflow/lib/staticValidation.d.ts +22 -0
  232. package/dist-runtime/workflow/lib/staticValidation.js +124 -0
  233. package/dist-runtime/workflow/lib/staticValidation.js.map +1 -0
  234. package/dist-runtime/workflow/lib/zksyncForkCapability.d.ts +27 -0
  235. package/dist-runtime/workflow/lib/zksyncForkCapability.js +52 -0
  236. package/dist-runtime/workflow/lib/zksyncForkCapability.js.map +1 -0
  237. package/dist-runtime/workflow/lib/zksyncForkRunner.d.ts +57 -0
  238. package/dist-runtime/workflow/lib/zksyncForkRunner.js +344 -0
  239. package/dist-runtime/workflow/lib/zksyncForkRunner.js.map +1 -0
  240. package/dist-runtime/workflow/reconcileExternal.d.ts +1 -0
  241. package/dist-runtime/workflow/reconcileExternal.js +87 -0
  242. package/dist-runtime/workflow/reconcileExternal.js.map +1 -0
  243. package/dist-runtime/workflow/reconcileExternalRun.d.ts +1 -0
  244. package/dist-runtime/workflow/reconcileExternalRun.js +77 -0
  245. package/dist-runtime/workflow/reconcileExternalRun.js.map +1 -0
  246. package/dist-runtime/workflow/releaseFinalize.d.ts +1 -0
  247. package/dist-runtime/workflow/releaseFinalize.js +11 -0
  248. package/dist-runtime/workflow/releaseFinalize.js.map +1 -0
  249. package/dist-runtime/workflow/run.d.ts +40 -0
  250. package/dist-runtime/workflow/run.js +858 -0
  251. package/dist-runtime/workflow/run.js.map +1 -0
  252. package/dist-runtime/workflow/staticValidate.d.ts +1 -0
  253. package/dist-runtime/workflow/staticValidate.js +26 -0
  254. package/dist-runtime/workflow/staticValidate.js.map +1 -0
  255. package/dist-runtime/workflow/steps/call.d.ts +3 -0
  256. package/dist-runtime/workflow/steps/call.js +9 -0
  257. package/dist-runtime/workflow/steps/call.js.map +1 -0
  258. package/dist-runtime/workflow/steps/check.d.ts +3 -0
  259. package/dist-runtime/workflow/steps/check.js +9 -0
  260. package/dist-runtime/workflow/steps/check.js.map +1 -0
  261. package/dist-runtime/workflow/steps/custom.d.ts +3 -0
  262. package/dist-runtime/workflow/steps/custom.js +33 -0
  263. package/dist-runtime/workflow/steps/custom.js.map +1 -0
  264. package/dist-runtime/workflow/steps/deploy.d.ts +3 -0
  265. package/dist-runtime/workflow/steps/deploy.js +595 -0
  266. package/dist-runtime/workflow/steps/deploy.js.map +1 -0
  267. package/dist-runtime/workflow/steps/upgrade.d.ts +3 -0
  268. package/dist-runtime/workflow/steps/upgrade.js +465 -0
  269. package/dist-runtime/workflow/steps/upgrade.js.map +1 -0
  270. package/dist-runtime/workflow/steps/view.d.ts +3 -0
  271. package/dist-runtime/workflow/steps/view.js +9 -0
  272. package/dist-runtime/workflow/steps/view.js.map +1 -0
  273. package/package.json +26 -5
  274. package/runtime/config/hardhatAdapters.ts +50 -0
  275. package/runtime/config/networks.ts +296 -0
  276. package/runtime/config/openzeppelin.ts +173 -0
  277. package/runtime/config/rpc.ts +27 -0
  278. package/runtime/config/zksyncSolcPath.ts +59 -0
  279. package/runtime/hardhat-types.d.ts +2 -0
  280. package/runtime/migrate.ts +154 -0
  281. package/runtime/projectHardhat.ts +10 -0
  282. package/runtime/template-migration.json +293 -0
  283. package/runtime/workflow/checkCode.ts +13 -0
  284. package/runtime/workflow/checkCodeFinalize.ts +8 -0
  285. package/runtime/workflow/checkCodePlan.ts +8 -0
  286. package/runtime/workflow/cli.ts +356 -0
  287. package/runtime/workflow/commitContractInfo.ts +63 -0
  288. package/runtime/workflow/create2Hashes.ts +79 -0
  289. package/runtime/workflow/forkSourceProxy.ts +193 -0
  290. package/runtime/workflow/importState.ts +190 -0
  291. package/runtime/workflow/lib/authority.ts +170 -0
  292. package/runtime/workflow/lib/calldata.ts +9 -0
  293. package/runtime/workflow/lib/calls.ts +407 -0
  294. package/runtime/workflow/lib/checkCode/args.ts +76 -0
  295. package/runtime/workflow/lib/checkCode/command.ts +36 -0
  296. package/runtime/workflow/lib/checkCode/dependencies.ts +112 -0
  297. package/runtime/workflow/lib/checkCode/finalize.ts +198 -0
  298. package/runtime/workflow/lib/checkCode/index.ts +18 -0
  299. package/runtime/workflow/lib/checkCode/plan.ts +163 -0
  300. package/runtime/workflow/lib/checkCodeReport.ts +133 -0
  301. package/runtime/workflow/lib/checkCodeRunner.ts +1225 -0
  302. package/runtime/workflow/lib/cliTool.ts +31 -0
  303. package/runtime/workflow/lib/config.ts +130 -0
  304. package/runtime/workflow/lib/contractInfoCandidates.ts +690 -0
  305. package/runtime/workflow/lib/create2.ts +278 -0
  306. package/runtime/workflow/lib/create2Hashes.ts +83 -0
  307. package/runtime/workflow/lib/deploymentInfo.ts +286 -0
  308. package/runtime/workflow/lib/deploymentRecords.ts +576 -0
  309. package/runtime/workflow/lib/deployments.ts +276 -0
  310. package/runtime/workflow/lib/erc1967.ts +57 -0
  311. package/runtime/workflow/lib/errors.ts +95 -0
  312. package/runtime/workflow/lib/executionId.ts +35 -0
  313. package/runtime/workflow/lib/executionPlan.ts +550 -0
  314. package/runtime/workflow/lib/executionProgress.ts +127 -0
  315. package/runtime/workflow/lib/external.ts +372 -0
  316. package/runtime/workflow/lib/externalExecutionScanner.ts +892 -0
  317. package/runtime/workflow/lib/forkSnapshot.ts +231 -0
  318. package/runtime/workflow/lib/gateTool.ts +261 -0
  319. package/runtime/workflow/lib/gateToolSync.ts +398 -0
  320. package/runtime/workflow/lib/lock.ts +388 -0
  321. package/runtime/workflow/lib/migrationState.ts +1246 -0
  322. package/runtime/workflow/lib/operatorExecution.ts +174 -0
  323. package/runtime/workflow/lib/parameters.ts +437 -0
  324. package/runtime/workflow/lib/pendingDeploymentReuse.ts +428 -0
  325. package/runtime/workflow/lib/proxy.ts +45 -0
  326. package/runtime/workflow/lib/registryCommit.ts +455 -0
  327. package/runtime/workflow/lib/release.ts +329 -0
  328. package/runtime/workflow/lib/releaseFinalize.ts +711 -0
  329. package/runtime/workflow/lib/releaseParameters.ts +248 -0
  330. package/runtime/workflow/lib/reporter.ts +502 -0
  331. package/runtime/workflow/lib/resultPaths.ts +49 -0
  332. package/runtime/workflow/lib/runtimeVersion.ts +28 -0
  333. package/runtime/workflow/lib/signer.ts +124 -0
  334. package/runtime/workflow/lib/signerIdentity.ts +22 -0
  335. package/runtime/workflow/lib/simulation.ts +415 -0
  336. package/runtime/workflow/lib/simulationCallers.ts +335 -0
  337. package/runtime/workflow/lib/sourceRpcPolicy.ts +41 -0
  338. package/runtime/workflow/lib/state.ts +25 -0
  339. package/runtime/workflow/lib/staticValidation.ts +142 -0
  340. package/runtime/workflow/lib/zksyncForkCapability.ts +80 -0
  341. package/runtime/workflow/lib/zksyncForkRunner.ts +505 -0
  342. package/runtime/workflow/reconcileExternal.ts +86 -0
  343. package/runtime/workflow/reconcileExternalRun.ts +88 -0
  344. package/runtime/workflow/releaseFinalize.ts +8 -0
  345. package/runtime/workflow/run.ts +1072 -0
  346. package/runtime/workflow/staticValidate.ts +23 -0
  347. package/runtime/workflow/steps/call.ts +10 -0
  348. package/runtime/workflow/steps/check.ts +10 -0
  349. package/runtime/workflow/steps/custom.ts +43 -0
  350. package/runtime/workflow/steps/deploy.ts +771 -0
  351. package/runtime/workflow/steps/upgrade.ts +598 -0
  352. package/runtime/workflow/steps/view.ts +10 -0
@@ -0,0 +1,356 @@
1
+ import { createRequire } from "module";
2
+ import { spawn, spawnSync, type ChildProcess } from "child_process";
3
+ import { existsSync, mkdtempSync, readFileSync, rmSync } from "fs";
4
+ import { tmpdir } from "os";
5
+ import path from "path";
6
+ import { openZeppelinProcessEnvironment } from "../config/openzeppelin";
7
+ import { resolveCliTool } from "./lib/cliTool";
8
+ import { validateExecutionId } from "./lib/executionId";
9
+ import {
10
+ buildForkSnapshot,
11
+ isCapturedZkSyncChainSnapshot,
12
+ parseCapturedChainSnapshot,
13
+ type CapturedChainSnapshotV1,
14
+ } from "./lib/forkSnapshot";
15
+ import {
16
+ resolveZkSyncForkRunner,
17
+ startZkSyncForkRunner,
18
+ type RunningZkSyncFork,
19
+ } from "./lib/zksyncForkRunner";
20
+
21
+ type ArgValue = string | boolean;
22
+
23
+ const WORKFLOW_ARG_KEYS = new Set([
24
+ "mode",
25
+ "target",
26
+ "step",
27
+ "from",
28
+ "executionId",
29
+ "useLock",
30
+ "sourceSuperTaskId",
31
+ "mergeCommit",
32
+ "parameterOverrides",
33
+ "existingDeploymentPolicies",
34
+ "simulationSigner",
35
+ "operator",
36
+ "releaseKind",
37
+ ]);
38
+
39
+ const parseArgs = (argv: string[]): Record<string, ArgValue> => {
40
+ const args: Record<string, ArgValue> = {};
41
+ for (let index = 0; index < argv.length; index += 1) {
42
+ const item = argv[index];
43
+ if (!item.startsWith("--")) continue;
44
+
45
+ const equalIndex = item.indexOf("=");
46
+ if (equalIndex > 2) {
47
+ args[item.slice(2, equalIndex)] = item.slice(equalIndex + 1);
48
+ continue;
49
+ }
50
+
51
+ const key = item.slice(2);
52
+ const next = argv[index + 1];
53
+ if (!next || next.startsWith("--")) {
54
+ args[key] = true;
55
+ } else {
56
+ args[key] = next;
57
+ index += 1;
58
+ }
59
+ }
60
+ return args;
61
+ };
62
+
63
+ const stringArg = (
64
+ args: Record<string, ArgValue>,
65
+ key: string,
66
+ ): string | undefined => {
67
+ const value = args[key];
68
+ return typeof value === "string" && value.length > 0 ? value : undefined;
69
+ };
70
+
71
+ interface SourceProxyHandshake {
72
+ proxyUrl: string;
73
+ snapshot: CapturedChainSnapshotV1;
74
+ zksync: boolean;
75
+ }
76
+
77
+ const delay = (milliseconds: number): Promise<void> => new Promise(
78
+ (resolve) => setTimeout(resolve, milliseconds),
79
+ );
80
+
81
+ const loopbackProxyUrl = (value: unknown): string => {
82
+ if (typeof value !== "string") throw new Error("Source-chain proxy handshake URL is missing");
83
+ let parsed: URL;
84
+ try {
85
+ parsed = new URL(value);
86
+ } catch {
87
+ throw new Error("Source-chain proxy handshake URL is invalid");
88
+ }
89
+ if (
90
+ parsed.protocol !== "http:"
91
+ || parsed.hostname !== "127.0.0.1"
92
+ || !parsed.port
93
+ || parsed.pathname === "/"
94
+ || parsed.username
95
+ || parsed.password
96
+ || parsed.search
97
+ || parsed.hash
98
+ ) {
99
+ throw new Error("Source-chain proxy handshake URL must be tokenized and loopback-only");
100
+ }
101
+ return parsed.toString();
102
+ };
103
+
104
+ const parseSourceProxyHandshake = (
105
+ value: unknown,
106
+ target: string,
107
+ ): SourceProxyHandshake => {
108
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
109
+ throw new Error("Source-chain proxy handshake must be an object");
110
+ }
111
+ const record = value as Record<string, unknown>;
112
+ const keys = Object.keys(record).sort();
113
+ if (JSON.stringify(keys) !== JSON.stringify(["proxyUrl", "snapshot", "version", "zksync"])) {
114
+ throw new Error("Source-chain proxy handshake fields are invalid");
115
+ }
116
+ if (record.version !== 1 || typeof record.zksync !== "boolean") {
117
+ throw new Error("Source-chain proxy handshake metadata is invalid");
118
+ }
119
+ return {
120
+ proxyUrl: loopbackProxyUrl(record.proxyUrl),
121
+ snapshot: parseCapturedChainSnapshot(record.snapshot, target, record.zksync),
122
+ zksync: record.zksync,
123
+ };
124
+ };
125
+
126
+ const waitForSourceProxy = async (
127
+ child: ChildProcess,
128
+ handshakePath: string,
129
+ target: string,
130
+ ): Promise<SourceProxyHandshake> => {
131
+ let launchError: Error | undefined;
132
+ child.once("error", (error) => {
133
+ launchError = error;
134
+ });
135
+ const deadline = Date.now() + 30_000;
136
+ while (Date.now() < deadline) {
137
+ if (launchError) throw new Error(`Source-chain proxy failed to start: ${launchError.message}`);
138
+ if (existsSync(handshakePath)) {
139
+ let parsed: unknown;
140
+ try {
141
+ parsed = JSON.parse(readFileSync(handshakePath, "utf8"));
142
+ } catch {
143
+ throw new Error("Source-chain proxy handshake is not valid JSON");
144
+ }
145
+ return parseSourceProxyHandshake(parsed, target);
146
+ }
147
+ if (child.exitCode !== null) {
148
+ throw new Error(`Source-chain proxy exited before readiness with code ${child.exitCode}`);
149
+ }
150
+ await delay(50);
151
+ }
152
+ throw new Error("Source-chain proxy readiness timed out");
153
+ };
154
+
155
+ const stopChild = async (
156
+ child: ChildProcess | undefined,
157
+ signal: NodeJS.Signals,
158
+ ): Promise<void> => {
159
+ if (!child || child.exitCode !== null) return;
160
+ child.kill(signal);
161
+ const exited = new Promise<void>((resolve) => child.once("exit", () => resolve()));
162
+ await Promise.race([exited, delay(2_000)]);
163
+ if (child.exitCode === null) {
164
+ child.kill("SIGKILL");
165
+ await Promise.race([exited, delay(2_000)]);
166
+ }
167
+ };
168
+
169
+ const runChild = async (
170
+ command: string,
171
+ commandArgs: string[],
172
+ env: NodeJS.ProcessEnv,
173
+ ): Promise<number> => {
174
+ const child = spawn(command, commandArgs, { env, stdio: "inherit" });
175
+ let forwardedSignal: NodeJS.Signals | undefined;
176
+ const forward = (signal: NodeJS.Signals) => {
177
+ forwardedSignal = signal;
178
+ child.kill(signal);
179
+ };
180
+ const interrupt = () => forward("SIGINT");
181
+ const terminate = () => forward("SIGTERM");
182
+ process.once("SIGINT", interrupt);
183
+ process.once("SIGTERM", terminate);
184
+ try {
185
+ return await new Promise<number>((resolve) => {
186
+ child.once("error", (error) => {
187
+ console.error(error);
188
+ resolve(1);
189
+ });
190
+ child.once("exit", (code) => resolve(forwardedSignal ? 1 : code ?? 1));
191
+ });
192
+ } finally {
193
+ process.removeListener("SIGINT", interrupt);
194
+ process.removeListener("SIGTERM", terminate);
195
+ }
196
+ };
197
+
198
+ const hardhatVersion = (): string => {
199
+ const value = (createRequire(path.join(process.cwd(), "package.json"))("hardhat/package.json") as { version?: unknown }).version;
200
+ if (typeof value !== "string" || !value) {
201
+ throw new Error("Cannot resolve the installed Hardhat version");
202
+ }
203
+ return value;
204
+ };
205
+
206
+ const main = async (): Promise<number> => {
207
+ const args = parseArgs(process.argv.slice(2));
208
+
209
+ if (args.checkcode === true) {
210
+ const forwardedArgs = process.argv.slice(2).filter((item) => item !== "--checkcode");
211
+ const tsNode = resolveCliTool({ root: process.cwd(), binary: "ts-node" });
212
+ const result = spawnSync(
213
+ tsNode.command,
214
+ [...tsNode.argsPrefix, path.join(__dirname, "checkCode.js"), ...forwardedArgs],
215
+ { env: process.env, stdio: "inherit" },
216
+ );
217
+ if (result.error) console.error(result.error);
218
+ return result.error ? 1 : result.status ?? 1;
219
+ }
220
+
221
+ if (Object.hasOwn(args, "executionId")) {
222
+ validateExecutionId(args.executionId);
223
+ }
224
+
225
+ const requestedNetwork = stringArg(args, "network") || "hardhat";
226
+ const mode = stringArg(args, "mode") || "execute";
227
+ const target = stringArg(args, "target") || requestedNetwork;
228
+ const task = stringArg(args, "task") || process.env.WORKFLOW_TASK;
229
+
230
+ const workflowArgs = Object.fromEntries(
231
+ Object.entries(args).filter(([key]) => WORKFLOW_ARG_KEYS.has(key)),
232
+ ) as Record<string, ArgValue>;
233
+ const remoteSimulation = mode === "simulate"
234
+ && target !== "hardhat"
235
+ && target !== "localhost";
236
+ if (remoteSimulation && requestedNetwork !== "hardhat") {
237
+ throw new Error("Remote simulation must be invoked with --network hardhat");
238
+ }
239
+
240
+ const hardhat = resolveCliTool({ root: process.cwd(), binary: "hardhat" });
241
+ let sourceProcess: ChildProcess | undefined;
242
+ let zkSyncFork: RunningZkSyncFork | undefined;
243
+ let temporaryDirectory: string | undefined;
244
+ try {
245
+ let runtimeNetwork = requestedNetwork;
246
+ const runtimeWorkflowArgs = { ...workflowArgs };
247
+ let forkEnvironment: NodeJS.ProcessEnv = {};
248
+ if (remoteSimulation) {
249
+ temporaryDirectory = mkdtempSync(path.join(tmpdir(), "gate-current-chain-fork-"));
250
+ const handshakePath = path.join(temporaryDirectory, "source-proxy.json");
251
+ const sourceEnvironment = { ...process.env };
252
+ delete sourceEnvironment.GATE_SIMULATION_FORK_SNAPSHOT_JSON;
253
+ delete sourceEnvironment.GATE_SIMULATION_SOURCE_RPC_URL;
254
+ delete sourceEnvironment.HARDHAT_FORK_CHAIN_ID;
255
+ sourceEnvironment.GATE_FORK_PROXY_HANDSHAKE = handshakePath;
256
+ sourceEnvironment.GATE_FORK_SOURCE_READ_ONLY = "1";
257
+ // Explicit empty values prevent dotenv from reintroducing project
258
+ // credentials into the real-network source process.
259
+ sourceEnvironment.WALLET_CREDENTIAL = "";
260
+ sourceEnvironment.PRIVATE_KEY = "";
261
+ sourceProcess = spawn(
262
+ hardhat.command,
263
+ [
264
+ ...hardhat.argsPrefix,
265
+ "run",
266
+ path.join(__dirname, "forkSourceProxy.js"),
267
+ "--network",
268
+ target,
269
+ "--no-compile",
270
+ ],
271
+ { env: sourceEnvironment, stdio: "inherit" },
272
+ );
273
+ const source = await waitForSourceProxy(sourceProcess, handshakePath, target);
274
+ if (source.zksync) {
275
+ if (!isCapturedZkSyncChainSnapshot(source.snapshot)) {
276
+ throw new Error("zkSync source snapshot is missing protocol metadata");
277
+ }
278
+ const runner = resolveZkSyncForkRunner(source.snapshot.protocolVersion);
279
+ if (!runner) {
280
+ throw new Error(
281
+ `Unsupported zkSync protocol ${source.snapshot.protocolVersion}: `
282
+ + "install a workflow dependency with an approved EraVM fork runner and retry",
283
+ );
284
+ }
285
+ const snapshot = buildForkSnapshot(source.snapshot, runner);
286
+ if (snapshot.runner.kind !== "anvil-zksync") {
287
+ throw new Error("zkSync source snapshot selected an invalid fork runner");
288
+ }
289
+ zkSyncFork = await startZkSyncForkRunner({
290
+ sourceProxyUrl: source.proxyUrl,
291
+ snapshot,
292
+ });
293
+ runtimeNetwork = "zkFork";
294
+ forkEnvironment = {
295
+ GATE_SIMULATION_FORK_SNAPSHOT_JSON: JSON.stringify(snapshot),
296
+ GATE_SIMULATION_SOURCE_RPC_URL: source.proxyUrl,
297
+ GATE_ZKSYNC_FORK_RPC_URL: zkSyncFork.rpcUrl,
298
+ HARDHAT_FORK_CHAIN_ID: String(snapshot.chainId),
299
+ };
300
+ } else {
301
+ const snapshot = buildForkSnapshot(source.snapshot, {
302
+ kind: "hardhat",
303
+ version: hardhatVersion(),
304
+ });
305
+ runtimeNetwork = "hardhat";
306
+ forkEnvironment = {
307
+ GATE_SIMULATION_FORK_SNAPSHOT_JSON: JSON.stringify(snapshot),
308
+ GATE_SIMULATION_SOURCE_RPC_URL: source.proxyUrl,
309
+ HARDHAT_FORK_CHAIN_ID: String(snapshot.chainId),
310
+ };
311
+ }
312
+ }
313
+
314
+ const manifestBaseEnv = { ...process.env, ...forkEnvironment };
315
+ const manifestEnv = openZeppelinProcessEnvironment({
316
+ root: process.cwd(),
317
+ network: runtimeNetwork,
318
+ mode,
319
+ target: target,
320
+ env: manifestBaseEnv,
321
+ });
322
+ const env = {
323
+ ...manifestEnv,
324
+ ...forkEnvironment,
325
+ WORKFLOW_ARGS_JSON: JSON.stringify(runtimeWorkflowArgs),
326
+ ...(task ? { WORKFLOW_TASK: task } : {}),
327
+ };
328
+
329
+ const hardhatArgs = [
330
+ ...hardhat.argsPrefix,
331
+ "run",
332
+ path.join(__dirname, "run.js"),
333
+ "--network",
334
+ runtimeNetwork,
335
+ ];
336
+ if (args["no-compile"] === true) {
337
+ hardhatArgs.push("--no-compile");
338
+ }
339
+ return await runChild(hardhat.command, hardhatArgs, env);
340
+ } finally {
341
+ await zkSyncFork?.stop();
342
+ await stopChild(sourceProcess, "SIGTERM");
343
+ if (temporaryDirectory) {
344
+ rmSync(temporaryDirectory, { recursive: true, force: true });
345
+ }
346
+ }
347
+ };
348
+
349
+ main()
350
+ .then((status) => {
351
+ process.exitCode = status;
352
+ })
353
+ .catch((error) => {
354
+ console.error(error instanceof Error ? error.message : String(error));
355
+ process.exitCode = 1;
356
+ });
@@ -0,0 +1,63 @@
1
+ import path from "path";
2
+ import {
3
+ commitVerifiedContractInfo,
4
+ RegistryCommitSelection,
5
+ } from "./lib/registryCommit";
6
+
7
+ const parseArgs = (argv: string[]): Record<string, string[]> => {
8
+ const args: Record<string, string[]> = {};
9
+ for (let index = 0; index < argv.length; index += 1) {
10
+ const item = argv[index];
11
+ if (!item.startsWith("--")) continue;
12
+ const key = item.slice(2);
13
+ const value = argv[index + 1];
14
+ if (!value || value.startsWith("--")) throw new Error(`--${key} requires a value`);
15
+ (args[key] ||= []).push(value);
16
+ index += 1;
17
+ }
18
+ return args;
19
+ };
20
+
21
+ const single = (args: Record<string, string[]>, key: string, required = false): string | undefined => {
22
+ const values = args[key] || [];
23
+ if (values.length > 1) throw new Error(`--${key} may be provided only once`);
24
+ const value = values[0]?.trim();
25
+ if (required && !value) throw new Error(`--${key} is required`);
26
+ return value;
27
+ };
28
+
29
+ const selection = (value: string): RegistryCommitSelection => {
30
+ const index = value.indexOf("=");
31
+ if (index <= 0 || index === value.length - 1) {
32
+ throw new Error("--selection must use <network>=<executionId>");
33
+ }
34
+ return { network: value.slice(0, index), executionId: value.slice(index + 1) };
35
+ };
36
+
37
+ const main = (): void => {
38
+ if (process.env.GATEFLOW_NODE_KEY?.trim() === "DevelopmentDeployExecute") {
39
+ throw new Error(
40
+ "GateFlow node DevelopmentDeployExecute cannot run workflow:commit-contract-info",
41
+ );
42
+ }
43
+ const args = parseArgs(process.argv.slice(2));
44
+ const report = commitVerifiedContractInfo({
45
+ root: path.resolve(single(args, "root") || process.cwd()),
46
+ taskId: single(args, "task", true) as string,
47
+ commitId: single(args, "commitId", true) as string,
48
+ selections: (args.selection || []).map(selection),
49
+ });
50
+ console.log(JSON.stringify({
51
+ status: report.status,
52
+ commitId: report.commitId,
53
+ selections: report.selections,
54
+ afterHash: report.afterHash,
55
+ }));
56
+ };
57
+
58
+ try {
59
+ main();
60
+ } catch (error) {
61
+ console.error(error instanceof Error ? error.message : String(error));
62
+ process.exitCode = 1;
63
+ }
@@ -0,0 +1,79 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import type { InterfaceAbi } from "ethers";
4
+ import {
5
+ canonicalCreate2Hashes,
6
+ normalizeCreate2Scheme,
7
+ } from "./lib/create2Hashes";
8
+
9
+ type ArgValue = string | boolean;
10
+
11
+ const parseArgs = (argv: string[]): Record<string, ArgValue> => {
12
+ const result: Record<string, ArgValue> = {};
13
+ for (let index = 0; index < argv.length; index += 1) {
14
+ const item = argv[index];
15
+ if (!item.startsWith("--")) continue;
16
+ const key = item.slice(2);
17
+ const next = argv[index + 1];
18
+ if (!next || next.startsWith("--")) {
19
+ result[key] = true;
20
+ } else {
21
+ result[key] = next;
22
+ index += 1;
23
+ }
24
+ }
25
+ return result;
26
+ };
27
+
28
+ const requiredString = (args: Record<string, ArgValue>, key: string): string => {
29
+ const value = args[key];
30
+ if (typeof value !== "string" || !value.trim()) {
31
+ throw new Error(`workflow:create2-hashes requires --${key} <value>`);
32
+ }
33
+ return value.trim();
34
+ };
35
+
36
+ const confinedArtifactPath = (root: string, value: string): string => {
37
+ const candidate = path.resolve(root, value);
38
+ const realRoot = fs.realpathSync(root);
39
+ const realArtifact = fs.realpathSync(candidate);
40
+ if (!realArtifact.startsWith(`${realRoot}${path.sep}`)) {
41
+ throw new Error("--artifact must resolve inside the project workspace");
42
+ }
43
+ return realArtifact;
44
+ };
45
+
46
+ const main = (): void => {
47
+ const args = parseArgs(process.argv.slice(2));
48
+ const root = process.cwd();
49
+ const artifactPath = confinedArtifactPath(root, requiredString(args, "artifact"));
50
+ const artifact = JSON.parse(fs.readFileSync(artifactPath, "utf8")) as Record<string, unknown>;
51
+ if (!Array.isArray(artifact.abi)) throw new Error("CREATE2 artifact.abi must be an array");
52
+ if (typeof artifact.bytecode !== "string" || !artifact.bytecode.startsWith("0x")) {
53
+ throw new Error("CREATE2 artifact.bytecode must be a hex string");
54
+ }
55
+
56
+ const rawArgs = typeof args["args-json"] === "string" ? args["args-json"] : "[]";
57
+ const constructorArgs = JSON.parse(rawArgs) as unknown;
58
+ if (!Array.isArray(constructorArgs)) throw new Error("--args-json must contain a JSON array");
59
+ const scheme = normalizeCreate2Scheme(
60
+ typeof args.scheme === "string" ? args.scheme : undefined,
61
+ );
62
+ const result = canonicalCreate2Hashes({
63
+ scheme,
64
+ artifact: {
65
+ _format: typeof artifact._format === "string" ? artifact._format : undefined,
66
+ abi: artifact.abi as InterfaceAbi,
67
+ bytecode: artifact.bytecode,
68
+ },
69
+ args: constructorArgs,
70
+ });
71
+ process.stdout.write(`${JSON.stringify(result)}\n`);
72
+ };
73
+
74
+ try {
75
+ main();
76
+ } catch (error) {
77
+ console.error(error instanceof Error ? error.message : String(error));
78
+ process.exitCode = 1;
79
+ }
@@ -0,0 +1,193 @@
1
+ import { randomUUID } from "crypto";
2
+ import http from "http";
3
+ import { ethers, network } from "../projectHardhat";
4
+ import { writeJsonFile } from "./lib/config";
5
+ import {
6
+ parseCapturedChainSnapshot,
7
+ parseZkSyncBlockDetails,
8
+ } from "./lib/forkSnapshot";
9
+ import { isAllowedSourceRpcMethod } from "./lib/sourceRpcPolicy";
10
+ import {
11
+ ANVIL_ZKSYNC_SOURCE_PATH_SUFFIX,
12
+ rewriteZkSyncForkRunnerRpcResult,
13
+ } from "./lib/zksyncForkRunner";
14
+
15
+ const MAX_REQUEST_BYTES = 10 * 1024 * 1024;
16
+
17
+ interface JsonRpcRequest {
18
+ jsonrpc: "2.0";
19
+ id?: string | number | null;
20
+ method: string;
21
+ params?: unknown[];
22
+ }
23
+
24
+ const jsonResponse = (
25
+ response: http.ServerResponse,
26
+ statusCode: number,
27
+ body: unknown,
28
+ ): void => {
29
+ const contents = JSON.stringify(body);
30
+ response.writeHead(statusCode, {
31
+ "content-type": "application/json",
32
+ "content-length": Buffer.byteLength(contents),
33
+ });
34
+ response.end(contents);
35
+ };
36
+
37
+ const rpcError = (
38
+ id: JsonRpcRequest["id"],
39
+ code: number,
40
+ message: string,
41
+ ) => ({ jsonrpc: "2.0", id: id ?? null, error: { code, message } });
42
+
43
+ const forwardRequest = async (
44
+ value: unknown,
45
+ runnerSourceProtocolVersion?: number,
46
+ ): Promise<unknown> => {
47
+ if (
48
+ value === null
49
+ || typeof value !== "object"
50
+ || Array.isArray(value)
51
+ ) {
52
+ return rpcError(null, -32600, "Invalid JSON-RPC request");
53
+ }
54
+ const request = value as Partial<JsonRpcRequest>;
55
+ if (
56
+ request.jsonrpc !== "2.0"
57
+ || typeof request.method !== "string"
58
+ || !request.method
59
+ || (request.params !== undefined && !Array.isArray(request.params))
60
+ ) {
61
+ return rpcError(request.id, -32600, "Invalid JSON-RPC request");
62
+ }
63
+ if (!isAllowedSourceRpcMethod(request.method)) {
64
+ return rpcError(request.id, -32601, "Source RPC method is not allowed");
65
+ }
66
+ try {
67
+ const result = await network.provider.request({
68
+ method: request.method,
69
+ params: request.params || [],
70
+ });
71
+ return {
72
+ jsonrpc: "2.0",
73
+ id: request.id ?? null,
74
+ result: runnerSourceProtocolVersion === undefined
75
+ ? result
76
+ : rewriteZkSyncForkRunnerRpcResult(
77
+ request.method,
78
+ result,
79
+ runnerSourceProtocolVersion,
80
+ ),
81
+ };
82
+ } catch {
83
+ return rpcError(request.id, -32000, "Source RPC request failed");
84
+ }
85
+ };
86
+
87
+ const readRequestBody = (request: http.IncomingMessage): Promise<string> => new Promise(
88
+ (resolve, reject) => {
89
+ const chunks: Buffer[] = [];
90
+ let size = 0;
91
+ request.on("data", (chunk: Buffer) => {
92
+ size += chunk.length;
93
+ if (size > MAX_REQUEST_BYTES) {
94
+ reject(new Error("JSON-RPC request is too large"));
95
+ request.destroy();
96
+ return;
97
+ }
98
+ chunks.push(chunk);
99
+ });
100
+ request.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
101
+ request.on("error", reject);
102
+ },
103
+ );
104
+
105
+ const main = async (): Promise<void> => {
106
+ const handshakePath = process.env.GATE_FORK_PROXY_HANDSHAKE?.trim();
107
+ if (!handshakePath) throw new Error("GATE_FORK_PROXY_HANDSHAKE is required");
108
+
109
+ const [sourceNetwork, latest, providerNetwork] = await Promise.all([
110
+ Promise.resolve(network.name),
111
+ ethers.provider.getBlock("latest"),
112
+ ethers.provider.getNetwork(),
113
+ ]);
114
+ if (!latest || !latest.hash) {
115
+ throw new Error("Target network latest block is missing its block hash");
116
+ }
117
+ const zksync = (network.config as { zksync?: boolean }).zksync === true;
118
+ const zkSyncBlockDetails = zksync
119
+ ? parseZkSyncBlockDetails(
120
+ await network.provider.request({
121
+ method: "zks_getBlockDetails",
122
+ params: [latest.number],
123
+ }),
124
+ latest.number,
125
+ )
126
+ : undefined;
127
+ const snapshot = parseCapturedChainSnapshot({
128
+ version: 1,
129
+ sourceNetwork,
130
+ chainId: Number(providerNetwork.chainId),
131
+ blockNumber: latest.number,
132
+ blockHash: latest.hash,
133
+ ...(zkSyncBlockDetails ? {
134
+ protocolVersion: zkSyncBlockDetails.protocolVersion,
135
+ l1BatchNumber: zkSyncBlockDetails.l1BatchNumber,
136
+ } : {}),
137
+ }, sourceNetwork, zksync);
138
+ const token = randomUUID();
139
+ const endpointPath = `/${token}`;
140
+ const runnerEndpointPath = `${endpointPath}${ANVIL_ZKSYNC_SOURCE_PATH_SUFFIX}`;
141
+ const server = http.createServer(async (request, response) => {
142
+ const runnerRequest = zksync && request.url === runnerEndpointPath;
143
+ if (
144
+ request.method !== "POST"
145
+ || (request.url !== endpointPath && !runnerRequest)
146
+ ) {
147
+ jsonResponse(response, 404, rpcError(null, -32600, "Unknown JSON-RPC endpoint"));
148
+ return;
149
+ }
150
+ try {
151
+ const parsed: unknown = JSON.parse(await readRequestBody(request));
152
+ const runnerSourceProtocolVersion = runnerRequest
153
+ ? zkSyncBlockDetails?.protocolVersion
154
+ : undefined;
155
+ const result = Array.isArray(parsed)
156
+ ? await Promise.all(parsed.map(
157
+ (entry) => forwardRequest(entry, runnerSourceProtocolVersion),
158
+ ))
159
+ : await forwardRequest(parsed, runnerSourceProtocolVersion);
160
+ jsonResponse(response, 200, result);
161
+ } catch {
162
+ jsonResponse(response, 400, rpcError(null, -32700, "Invalid JSON-RPC payload"));
163
+ }
164
+ });
165
+
166
+ await new Promise<void>((resolve, reject) => {
167
+ server.once("error", reject);
168
+ server.listen(0, "127.0.0.1", () => resolve());
169
+ });
170
+ const address = server.address();
171
+ if (!address || typeof address === "string") {
172
+ server.close();
173
+ throw new Error("Source-chain proxy did not bind a TCP port");
174
+ }
175
+ writeJsonFile(handshakePath, {
176
+ version: 1,
177
+ proxyUrl: `http://127.0.0.1:${address.port}${endpointPath}`,
178
+ snapshot,
179
+ zksync,
180
+ });
181
+
182
+ await new Promise<void>((resolve, reject) => {
183
+ const shutdown = () => server.close((error) => (error ? reject(error) : resolve()));
184
+ process.once("SIGINT", shutdown);
185
+ process.once("SIGTERM", shutdown);
186
+ server.once("error", reject);
187
+ });
188
+ };
189
+
190
+ main().catch((error) => {
191
+ console.error(error instanceof Error ? error.message : String(error));
192
+ process.exitCode = 1;
193
+ });