Refactor contracts crate out of the main folder for faster compilation 🚀#4217
Refactor contracts crate out of the main folder for faster compilation 🚀#4217jmg-duarte merged 11 commits intomainfrom
Conversation
# Description Based on @MartinquaXD's comment on Slack, I figured that there would be places where we can import the specific alloy crate, unlocking earlier and more parallel compilation. These changes alone seem to save ~5s on a clean build in my laptop; going down from ~1m to 55s. There's more gains to take from this, but for that we need to separate shared further and then split those dependencies. #4217 would also help a bunch. # Changes * app-data * replace alloy with alloy-primitives * since alloy uses tiny-keccak, replace the tiny-keccak with alloy's keccak * chain * manually implement thiserror (less 1 dep) * replace alloy with alloy-primitives * model * replace alloy with alloy-primives, alloy-signer, alloy-signer-local, alloy-sol-types * number * replace alloy with alloy-primitives * order-validation * replace alloy with alloy-primitives and alloy-contract * remove thiserror wrapper (less 1 dep) * serde-ext * replace alloy with alloy-primitives * testlib * replace alloy with alloy-primitives * winner-selection * replace alloy with alloy-primitives ## How to test Compiler + existing tests
cb3108b to
612834d
Compare
# Description Based on @MartinquaXD's comment on Slack, I figured that there would be places where we can import the specific alloy crate, unlocking earlier and more parallel compilation. These changes alone seem to save ~5s on a clean build in my laptop; going down from ~1m to 55s. There's more gains to take from this, but for that we need to separate shared further and then split those dependencies. #4217 would also help a bunch. # Changes * app-data * replace alloy with alloy-primitives * since alloy uses tiny-keccak, replace the tiny-keccak with alloy's keccak * chain * manually implement thiserror (less 1 dep) * replace alloy with alloy-primitives * model * replace alloy with alloy-primives, alloy-signer, alloy-signer-local, alloy-sol-types * number * replace alloy with alloy-primitives * order-validation * replace alloy with alloy-primitives and alloy-contract * remove thiserror wrapper (less 1 dep) * serde-ext * replace alloy with alloy-primitives * testlib * replace alloy with alloy-primitives * winner-selection * replace alloy with alloy-primitives ## How to test Compiler + existing tests
|
This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed. |
|
This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed. |
443c53c to
9512825
Compare
9512825 to
06f2557
Compare
f61837a to
76644af
Compare
Move `crates/contracts` to a top-level `contracts/` directory as a standalone binary that generates Alloy contract bindings from ABI artifacts. Replace the build.rs-based compile-time code generation with pre-generated per-contract crates under `contracts/generated/`. - Add `contracts-facade` crate that re-exports all generated bindings - Update all workspace crates to import from the new generated crates - Add missing contract artifacts (Balancer factory variants, DEX router variants like Honeyswap, Pancake, SushiSwap, Swapr) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
76644af to
960ff38
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces a new contracts sub-project to generate Rust bindings for various Solidity smart contracts within the CoW Protocol ecosystem. This involves adding a contracts-generate tool, new Cargo.toml and Cargo.lock files for the sub-project, and numerous JSON ABI files. The generated bindings are organized into individual crates and re-exported through a facade crate. The root Cargo.toml and Cargo.lock are updated to reflect this new structure, and a setup command is added to the Justfile to automate the vending and generation process. A review comment noted that several BalancerV2ComposableStablePoolFactory ABI files (V3, V4, V5, V6) are identical, suggesting consolidation into a single file to reduce maintenance overhead and prevent inconsistencies.
|
This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed. |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new contracts directory to manage and generate Rust bindings for various smart contracts using Alloy. It includes a contracts-generate tool, updates the workspace configuration to exclude the new directory, and adds generated code for multiple contracts. A high-severity issue was identified regarding incorrect deployment block numbers for Gnosis and Sepolia chains in the generated code for BalancerV2NoProtocolFeeLiquidityBootstrappingPoolFactory.
...ated/contracts-generated/balancerv2noprotocolfeeliquiditybootstrappingpoolfactory/src/lib.rs
Show resolved
Hide resolved
32460eb to
b8c33f1
Compare
MartinquaXD
left a comment
There was a problem hiding this comment.
Nice improvement!
Given that the main motivation stated in the PR description is compile time improvements could you please add some measurements?
I did a quick test on my machine and compile time dropped from 94s to 67s.

Description
Replace the
crates/contractsbuild.rs-based compile-time code generation with a standalone code-generation tool that produces pre-generated per-contract crates. This eliminates the slow build.rs step from the main workspace build and makes contract bindings explicit, version-controllable, and independently compilable.Changes
crates/contractsto top-levelcontracts/directory as a standalone binarycontracts/generated/contracts-facadecrate that re-exports all generated bindings for easy consumptionHow to test
cargo check --workspace --all-targets— workspace compiles against the new generated bindingscargo nextest run— unit tests passcd contracts && cargo run -- --help— codegen tool runs independentlycontracts/generated/output matches checked-in code by re-running the codegenCharts
Problematic time blocker:

CPU Graph (notice the 60s):

No more time blocker (doesn't fully fit vertically in my screen):

New CPU Graph (notice the 45s and much better (higher) CPU usage):
