How velodrome-finance/contracts works
Project Type and Core Purpose
• This is a blockchain protocol project that implements an automated market maker (AMM) based on a Uniswap V2-like approach, with extended features including tokenomics (voting escrow, minter, rewards distribution) and governance.
• The README clearly delineates three major areas:
• AMM contracts (e.g., Pool.sol, Router.sol, PoolFees.sol)
• Tokenomy contracts (e.g., Velo.sol, VotingEscrow.sol, Minter.sol, RewardsDistributor.sol)
• Governance and protocol mechanics (e.g., Voter.sol, Gauge.sol and a suite of rewards contracts)
File Structure
• Directories:
• contracts: Contains all the Solidity source files, neatly organized into subdirectories such as art, factories, gauges, governance, interfaces, libraries, and rewards. This modular structure implies a strong separation of concerns between different functionalities.
• script: Contains deployment scripts (with both Hardhat and other scripts) and constants files that are used for deployment and network-specific configuration (for example, Optimism and CI outputs).
• test: Holds testing code (including end-to-end and invariant tests) that uses Foundry.
• lib: Contains external dependencies/libraries like forge-std, ds-test, OpenZeppelin’s contracts, etc.
• Configuration Files:
• foundry.toml, hardhat.config.ts, and package.json inform us of the testing, deployment, and build environments, respectively.
Main Components
a. AMM Layer:
• Pool, Router, and PoolFees: Represent the core swapping functionality, liquidity management, and fee handling.
• VelodromeLibrary: Provides helper functions necessary for pricing and impact calculations.
• FactoryRegistry: Manages the allowed factories for creating additional components such as pools and rewards.
b. Token Management and Tokenomy:
• Velo (ERC20 token contract)
• VotingEscrow: Implements vote-escrow logic with NFT-like properties.
• Minter: Handles token emissions and distribution.
• RewardsDistributor: Manages the distribution of rebases and rewards.
• VeArtProxy: Provides upgradability for the vote-escrow art.
c. Governance & Protocol Mechanics:
• Voter: Central to routing voting, gauge creation, and controlling emissions.
• Gauge and associated reward contracts (Reward, VotingReward, FeesVotingReward, BribeVotingReward, ManagedReward, LockedManagedReward, FreeManagedReward): Outline how liquidity providers interact with pools to earn rewards.
• Governance contracts like VeloGovernor and EpochGovernor manage protocol-wide decisions.
d. Deployment & Interaction Infrastructure:
• Deployment scripts (script/hardhat) show the orchestration of contract deployment.
• Testing infrastructure using Foundry is an essential part of the project’s CI/CD lifecycle.
• External services and configuration (e.g., .env and funding.json) that tie into network specifics like Optimism.
Relationships and Data Flow
• From the FactoryRegistry to AMM and governance components, indicating how factories spawn new pools, gauges, or rewards.
• Between the Pool and Router—indicating the flow of liquidity and swap transactions.
• From the Voter contract to the Gauge and Reward contracts, showing how voting signals control reward distributions.
• From the Minter to both Voter and RewardsDistributor to delineate token emission flows.
Architectural Patterns and Technology Stack
• The separation into distinct directories follows a modular and layered architecture, making use of well-known patterns for DeFi protocols.
• Leverage standard design patterns used in smart contract development, such as Factory patterns (for pools, gauges, and rewards), and the separation of concerns as seen in the governance and token modules.
• Usage of standardized libraries like OpenZeppelin, forge-std, and ds-test as part of the toolchain.
• Testing and deployment are handled through Foundry and Hardhat respectively; indicate these environments as auxiliary components in the overall system design.