Windmill EVM Contracts contains the core smart contracts of Windmill Exchange — a decentralized on-chain order matching engine with configurable dynamic pricing curves and autonomous keeper matching.
Orders (buy and sell) are submitted on-chain and continuously matched by keeper bots. Matching rewards are earned by keepers based on configurable price curves, and all settlements happen atomically on-chain.
- On-chain order matching: buy and sell orders stored on-chain in
OrderStorageandPairStorageand matched atomically. - Dynamic pricing curves: configurable
PriceCurveandMathUtilslibraries drive matching rewards. - Safe token handling:
TokenTransferlibrary with reentrancy-aware ERC20 transfers. - Auction-based incentive model: keepers earn on each executed match.
- Foundry toolchain: build, fuzz, gas-snapshot, and Slither workflows out of the box.
src/
├── core/
│ └── WindmillExchange.sol # Core exchange + matching logic
├── interfaces/
│ ├── IWindmillExchange.sol # Public exchange interface
│ └── IERC20.sol # Minimal ERC20 interface
├── libraries/
│ ├── MathUtils.sol # Safe math helpers
│ ├── PriceCurve.sol # Configurable dynamic pricing curves
│ └── TokenTransfer.sol # Reentrancy-aware token transfers
└── storage/
├── OrderStorage.sol # Order book storage
└── PairStorage.sol # Trading pair storage
script/
└── DeployWindmill.s.sol # Deployment script (Foundry)
test/
└── WindmillExchange.t.sol # Core test suite
flowchart LR
U[User / Trader] -->|placeOrder| X(WindmillExchange)
K[Keeper Bot] -->|match/matchExecution| X
X -->|store| OS[(OrderStorage)]
X -->|price curve| PC[[PriceCurve]]
X -->|transfer| TT[[TokenTransfer]]
X -->|settle + pay keeper| U
K -.->|scan events| X
| Layer | Technology |
|---|---|
| Language | Solidity ^0.8.23 |
| Framework | Foundry (forge, cast, anvil) |
| Libraries | OpenZeppelin + forge-std (via lib/) |
| Static analysis | Slither (CI) |
.
├── .github/workflows/ # CI, security, gas, fuzz, release pipelines
├── lib/ # Foundry dependencies (git submodules)
├── public/ # Logos and static assets
├── script/ # Forge deployment scripts
├── src/ # Solidity source contracts
├── test/ # Forge test suite
├── foundry.toml # Foundry config (RPCs, verifiers)
├── foundry.lock # Locked dependency versions
├── Deployments.md # Deployment records
└── README.md
| Tool | Version | Install |
|---|---|---|
git |
any | git-scm.com |
foundryup |
latest | See getfoundry.sh |
forge / cast / anvil |
latest | run foundryup after install |
Verify installation:
forge --version
anvil --version
cast --version# 1. Clone with submodules
git clone --recurse-submodules https://github.com/StabilityNexus/Windmill-EVM-Contracts
cd Windmill-EVM-Contracts
# 2. If you forgot --recurse-submodules
git submodule update --init --recursive
# 3. Install/update Foundry dependencies
forge installforge build# Run all tests
forge test
# Verbose output (logs and traces)
forge test -vvv
# Run a specific test
forge test --match-test testMatchOrders -vvvforge coverage
forge coverage --report lcov
genhtml lcov.info --output-directory coverage/forge snapshot # generate snapshot
forge snapshot --diff # compare against last snapshotforge fmt # format Solidity files
forge fmt --check # check without writing (used in CI)Make sure your
.envis configured before deploying. See.env.exampleand Deployments.md.
# Fork-test / local deployment with Anvil
anvil # in one terminal
# Deploy (set RPC url for your target network)
forge script script/DeployWindmill.s.sol \
--rpc-url <RPC_URL> \
--broadcast \
--verify \
-vvvvRPC aliases (ethereum, sepolia, base, polygon, etc.) are pre-configured in foundry.toml.
| Network | Chain ID |
|---|---|
| Ethereum (Mainnet) | 1 |
| Ethereum Classic (Mainnet) | 61 |
| Polygon PoS (Mainnet) | 137 |
| BNB Smart Chain (Mainnet) | 56 |
| Base (Mainnet) | 8453 |
| Avalanche C-Chain (Mainnet) | 43114 |
| Sepolia (Testnet) | 11155111 |
| Mordor (ETC Testnet) | 63 |
| Workflow | Trigger | What it does |
|---|---|---|
ci.yml |
Push / PR | Format check → Build → Unit tests → Coverage report |
security-slither.yml |
Push / PR | Slither static analysis for vulnerabilities |
gas-snapshot.yml |
Push / PR | Gas baseline and regression checks |
nightly-fuzz.yml |
Nightly (cron) | Deep fuzz & invariant testing |
release.yml |
Tag push | Builds and publishes release artifacts |
- Static analysis is run on every PR via Slither (
.github/workflows/security-slither.yml). - CodeRabbit AI review is enabled via
.coderabbit.yaml. - Deep fuzz runs nightly to catch edge cases.
Found a vulnerability? Please do not open a public issue. Contact the Stability Nexus team privately via Discord or Telegram.
⭐ Don't forget to star this repository if you find it useful! ⭐
Thank you for considering contributing to this project! Please read our Contribution Guidelines first — they cover the mandatory Discord workflow and our AI-use disclosure policy.
See COPYRIGHT.md and DCO.md for intellectual property and sign-off details.
© Stability Nexus