Add Hardhat · viem download and align download menus - #829
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughAdds Hardhat 3 + viem ZIP generation for standard and upgradeable contracts, validates generated projects, exposes a Solidity UI download option, and standardizes download menu rendering through a shared Svelte component. ChangesHardhat viem project generation
Download UI
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant SolidityApp
participant zipHardhatViem
participant Hardhat3ViemZipGenerator
User->>SolidityApp: Select Hardhat project · viem
SolidityApp->>zipHardhatViem: Generate contract ZIP
zipHardhatViem->>Hardhat3ViemZipGenerator: Build project files
Hardhat3ViemZipGenerator-->>zipHardhatViem: Return ZIP archive
zipHardhatViem-->>SolidityApp: Return project.zip
SolidityApp-->>User: Download project.zip
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Caution Review the following alerts detected in dependencies. According to your organization's Security Policy, you must resolve all "Block" alerts before proceeding. It is recommended to resolve "Warn" alerts too. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/core/solidity/src/zip-hardhat-viem.test.ts`:
- Around line 214-225: Update the deployment-validation conditions in the test
around makeDeployCommand(c) and the subsequent “deployed to” assertion to check
c.constructorArgs.length === 0 instead of c.constructorArgs === undefined, so
zero-argument contracts represented by [] execute and validate deployment.
In `@packages/core/solidity/src/zip-hardhat-viem.ts`:
- Around line 199-213: Clone the imported JSON templates in getPackageJson and
getPackageLock before assigning c.license, then mutate and return the clone so
cached module objects remain unchanged across concurrent ZIP generations.
- Line 50: Run the configured formatter on the affected code in
zip-hardhat-viem.ts, including the line containing
spaceBetween(this.declareVariables(...)) and the additional reported range, and
commit the resulting Prettier-compliant formatting without changing behavior.
- Around line 207-210: Add the generated package-lock.json files for both
hardhat-viem environments referenced by getPackageLock: the standard package and
the upgradeable package. Generate them through the existing update-env flow and
include them in the template set so TypeScript compilation and runtime ZIP
generation can resolve both dynamic imports.
- Around line 163-165: Update the deployProxy generation in the relevant
proxy-kind generator to preserve the selected upgradeable mode, passing `{ kind:
"uups" }` when the selected mode is UUPS while retaining the existing
`unsafeAllow` option. Ensure non-UUPS deployments continue using the current
behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d703a4df-faa5-4bba-9260-751d65e10d72
⛔ Files ignored due to path filters (6)
packages/core/solidity/src/environments/hardhat-viem/package-lock.jsonis excluded by!**/package-lock.jsonpackages/core/solidity/src/environments/hardhat-viem/upgradeable/package-lock.jsonis excluded by!**/package-lock.jsonpackages/core/solidity/src/environments/hardhat/package-lock.jsonis excluded by!**/package-lock.jsonpackages/core/solidity/src/environments/hardhat/upgradeable/package-lock.jsonis excluded by!**/package-lock.jsonpackages/core/solidity/src/zip-hardhat-viem.test.ts.snapis excluded by!**/*.snappackages/core/solidity/src/zip-hardhat.test.ts.snapis excluded by!**/*.snap
📒 Files selected for processing (23)
.changeset/hardhat-viem-download.mdpackages/core/solidity/package.jsonpackages/core/solidity/src/environments/hardhat-viem/package.jsonpackages/core/solidity/src/environments/hardhat-viem/upgradeable/package.jsonpackages/core/solidity/src/environments/hardhat/upgradeable/package.jsonpackages/core/solidity/src/zip-hardhat-viem.test.tspackages/core/solidity/src/zip-hardhat-viem.test.ts.mdpackages/core/solidity/src/zip-hardhat-viem.tspackages/core/solidity/src/zip-hardhat.test.ts.mdpackages/core/solidity/zip-env-hardhat-viem.jspackages/core/solidity/zip-env-hardhat-viem.tspackages/ui/src/cairo/App.sveltepackages/ui/src/cairo_alpha/App.sveltepackages/ui/src/common/DownloadOption.sveltepackages/ui/src/common/post-config.tspackages/ui/src/common/styles/shared.csspackages/ui/src/confidential/App.sveltepackages/ui/src/polkadot/App.sveltepackages/ui/src/solidity/App.sveltepackages/ui/src/solidity/overrides.tspackages/ui/src/stellar/App.sveltepackages/ui/src/stylus/App.sveltepackages/ui/src/uniswap-hooks/App.svelte
💤 Files with no reviewable changes (1)
- packages/ui/src/common/styles/shared.css
| let command = `cd "${tempFolder}" && npm ci && npm test`; | ||
| if (c.constructorArgs === undefined) { | ||
| // only test deploying the contract if there are no constructor args needed | ||
| command += ` && ${makeDeployCommand(c)}`; | ||
| } | ||
|
|
||
| const exec = util.promisify(child.exec); | ||
| const result = await exec(command); | ||
|
|
||
| t.regex(result.stdout, /1 test passed/); | ||
| if (c.constructorArgs === undefined) { | ||
| t.regex(result.stdout, /deployed to/); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Execute deployment validation for zero-argument contracts.
constructorArgs is an array, including [] for MyContract, so === undefined is always false. The generated deploy scripts and Ignition modules are never run. Check c.constructorArgs.length === 0 instead.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/core/solidity/src/zip-hardhat-viem.test.ts` around lines 214 - 225,
Update the deployment-validation conditions in the test around
makeDeployCommand(c) and the subsequent “deployed to” assertion to check
c.constructorArgs.length === 0 instead of c.constructorArgs === undefined, so
zero-argument contracts represented by [] execute and validate deployment.
| const argNames = c.constructorArgs.map(a => a.name); | ||
| return [ | ||
| `test("${c.name}", async t => {`, | ||
| spaceBetween(this.declareVariables(c.constructorArgs), this.getDeployLines(c, argNames), this.getAssertions(c, opts)), |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Run the formatter before merging.
These ranges fail the configured Prettier ESLint rule.
Also applies to: 158-160
🧰 Tools
🪛 ESLint
[error] 50-50: Replace this.declareVariables(c.constructorArgs),·this.getDeployLines(c,·argNames),·this.getAssertions(c,·opts) with ⏎········this.declareVariables(c.constructorArgs),⏎········this.getDeployLines(c,·argNames),⏎········this.getAssertions(c,·opts),⏎······
(prettier/prettier)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/core/solidity/src/zip-hardhat-viem.ts` at line 50, Run the
configured formatter on the affected code in zip-hardhat-viem.ts, including the
line containing spaceBetween(this.declareVariables(...)) and the additional
reported range, and commit the resulting Prettier-compliant formatting without
changing behavior.
Source: Linters/SAST tools
| return unsafeAllowConstructor | ||
| ? `upgradesApi.deployProxy("${c.name}", [${argsList}], { unsafeAllow: ['constructor'] })` | ||
| : `upgradesApi.deployProxy("${c.name}", [${argsList}])`; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
ast-grep outline packages/core/solidity/src/zip-hardhat-viem.ts --view expanded
rg -n "deployProxy|upgradeable|kind: \"uups\"|kind:'uups'|kind: 'uups'" packages/core/solidity/src packages/core -g '*.ts' -g '*.js' -g '*.mjs' -g '*.cjs'
sed -n '130,200p' packages/core/solidity/src/zip-hardhat-viem.tsRepository: OpenZeppelin/contracts-wizard
Length of output: 50386
🏁 Script executed:
sed -n '1,240p' packages/core/solidity/src/zip-hardhat-viem.ts
printf '\n--- TESTS ---\n'
sed -n '1,220p' packages/core/solidity/src/zip-hardhat-viem.test.ts
printf '\n--- SET UPGRADEABLE ---\n'
sed -n '1,120p' packages/core/solidity/src/set-upgradeable.tsRepository: OpenZeppelin/contracts-wizard
Length of output: 16029
Preserve the selected proxy kind. UUPS examples currently emit deployProxy() without kind, so they fall back to the plugin’s default transparent proxy mode. Thread the selected upgradeable mode through the generator and pass { kind: "uups" } for UUPS deployments.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/core/solidity/src/zip-hardhat-viem.ts` around lines 163 - 165,
Update the deployProxy generation in the relevant proxy-kind generator to
preserve the selected upgradeable mode, passing `{ kind: "uups" }` when the
selected mode is UUPS while retaining the existing `unsafeAllow` option. Ensure
non-UUPS deployments continue using the current behavior.
| protected async getPackageJson(c: Contract): Promise<unknown> { | ||
| const { default: packageJson } = c.upgradeable | ||
| ? await import('./environments/hardhat-viem/upgradeable/package.json') | ||
| : await import('./environments/hardhat-viem/package.json'); | ||
| packageJson.license = c.license; | ||
| return packageJson; | ||
| } | ||
|
|
||
| protected async getPackageLock(c: Contract): Promise<unknown> { | ||
| const { default: packageLock } = c.upgradeable | ||
| ? await import('./environments/hardhat-viem/upgradeable/package-lock.json') | ||
| : await import('./environments/hardhat-viem/package-lock.json'); | ||
| packageLock.packages[''].license = c.license; | ||
| return packageLock; | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Clone imported JSON templates before setting the license.
ESM caches these JSON imports. Mutating them lets concurrent ZIP generations overwrite one another’s license before serialization, producing archives with the wrong license. Deep-clone each template, then mutate the clone.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/core/solidity/src/zip-hardhat-viem.ts` around lines 199 - 213, Clone
the imported JSON templates in getPackageJson and getPackageLock before
assigning c.license, then mutate and return the clone so cached module objects
remain unchanged across concurrent ZIP generations.
| protected async getPackageLock(c: Contract): Promise<unknown> { | ||
| const { default: packageLock } = c.upgradeable | ||
| ? await import('./environments/hardhat-viem/upgradeable/package-lock.json') | ||
| : await import('./environments/hardhat-viem/package-lock.json'); |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Commit the generated viem package-lock files.
This generator imports hardhat-viem/package-lock.json and hardhat-viem/upgradeable/package-lock.json, but neither file is included in this new template set. tsc/runtime ZIP generation cannot resolve these imports until the lockfiles produced by update-env are added.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/core/solidity/src/zip-hardhat-viem.ts` around lines 207 - 210, Add
the generated package-lock.json files for both hardhat-viem environments
referenced by getPackageLock: the standard package and the upgradeable package.
Generate them through the existing update-env flow and include them in the
template set so TypeScript compilation and runtime ZIP generation can resolve
both dynamic imports.
|
@SocketSecurity ignore-all |
Summary
Hardhat project · viemdownload next toHardhat project · ethers.js, for upgradeable and non-upgradeable contracts (viem uses@nomicfoundation/hardhat-viem/ Ignition viem, or@openzeppelin/hardhat-upgrades/viemwhen upgradeable).download-hardhat; adddownload-hardhat-viem. Polkadot omits the viem option.@openzeppelin/hardhat-upgrades@^4.1.0.DownloadOptioncomponent and flatter labels (e.g.Hardhat project · ethers.js/· viem,Foundry project, Stellar… package), dropping redundant “Simple to receive updates” copy while preserving load-bearing dependency notes. Other ecosystems get the same row layout and similar simplifications where appropriate.Solidity Download menu example
Test plan
zip-hardhat-viemintegration tests: unzip generated projects,npm ci+npm test(10/10), including upgradeabledeployProxyvia@openzeppelin/hardhat-upgrades/viemzip-hardhat(ethers) integration tests still pass after upgrades^4.1.0bump (10/10)omitZipHardhatViem