Overview
The CoW Protocol Contracts project uses a hybrid build system that compiles both Solidity smart contracts and TypeScript bindings. The build process is managed through npm scripts and uses Hardhat as the development environment.This repository is migrating to Foundry. For Hardhat-based development, refer to the v1 branch.
Prerequisites
Before building the project, ensure you have:- Node.js (v16 or higher recommended)
- Yarn package manager
- Git
Installation
Build Commands
The project provides several build commands for different purposes:Build Script Details
yarn build
Executes the complete build process:
- Compiles Solidity contracts with Hardhat
- Generates TypeScript bindings
- Compiles TypeScript in three configurations (ESM, CommonJS, and default)
yarn build:sol
Compiles all Solidity smart contracts using Hardhat with the --force flag to ensure a clean build:
- Optimizer: Enabled
- Optimizer runs: 1,000,000
- EVM version: Cancun
- IR compilation: Disabled
yarn build:ts
Compiles TypeScript files in multiple module formats:
- Default TypeScript output
- ESM (ECMAScript Modules) build in
lib/esm/ - CommonJS build in
lib/commonjs/
Compiler Configuration
The project uses Foundry’s configuration system with settings optimized for gas efficiency:Output Structure
After a successful build, you’ll find:- Compiled contracts:
out/directory (Foundry) or contract artifacts - TypeScript ESM:
lib/esm/directory - TypeScript CommonJS:
lib/commonjs/directory - Type definitions:
.d.tsfiles alongside compiled JavaScript
Linting
The project includes comprehensive linting for both Solidity and TypeScript:Formatting
Code formatting is available for both Solidity and TypeScript:Troubleshooting
Build Failures
If you encounter build errors:-
Clean the build artifacts:
-
Reinstall dependencies:
-
Force rebuild:
Compiler Version Issues
Ensure your Solidity compiler version matches the project requirements. The project uses Hardhat’s built-in compiler management.Next Steps
- Run tests to verify your build
- Benchmark performance of the contracts
- Review the deployment documentation for deploying contracts
