This document provides comprehensive guidance for local Mercury (Compound Comet v3) development on BlockDAG, including environment setup, testing, deployment, and understanding the deployment process.
- Prerequisites
- Initial Setup
- Running a Local Blockchain
- Running Tests
- Deploying Markets Locally
- Understanding the Deployment Process
- Deployment Scripts Reference
- Debugging and Development Tools
- Deployment Caching System
- Node.js and Yarn installed
- Foundry (For Anvil) or Hardhat installed
- Git access to the repository
- Basic understanding of Ethereum/blockchain development
- Familiarity with command-line tools
# Clone the repository
git clone <repository-url>
cd comet
# Install dependencies
yarn install
# Build the project
yarn build
# Verify setup
yarn hardhat compile# Copy environment template
cp .env.example .env
# Edit .env and configure required variables
# ETH_PK=your_private_key_here
# LOCAL_CHAIN_ID=31337 # for Anvil, or 1337 for HardhatRequired Environment Variables:
The project requires the following API keys (can use placeholders if not needed):
ETHERSCAN_KEY,SNOWTRACE_KEY,INFURA_KEY,ANKR_KEYPOLYGONSCAN_KEY,ARBISCAN_KEY,LINEASCAN_KEY,OPTIMISMSCAN_KEYMANTLESCAN_KEY,SCROLLSCAN_KEY,UNICHAIN_QUICKNODE_KEY
Required:
ETH_PK- Your private key for deployment operationsLOCAL_CHAIN_ID-31337for Anvil or1337for Hardhat
For detailed environment configuration, see Environment Configuration.
Anvil provides a local Ethereum node with persistent state, ideal for testing deployments:
# Start Anvil in a separate terminal
anvilAnvil will:
- Create test accounts with pre-funded ETH
- Provide instant block mining
- Maintain state between deployments
- Listen on
http://127.0.0.1:8545by default
Hardhat automatically uses its built-in network when running tests:
# Tests run on Hardhat's network automatically
yarn hardhat testKey Differences:
- Hardhat Network: Ephemeral, used for automated testing, no explicit network specification needed
- Anvil: Persistent, used for local deployments, requires
--network localflag
Mercury includes 40+ test files covering all protocol functionality including supply, withdraw, liquidation, governance, and custom BlockDAG features (CustomGovernor, Proposal Manager, E2E deployment verification).
Quick Start:
# Run all tests
yarn hardhat test
# Run specific test pattern
yarn hardhat test --grep "governance"For comprehensive testing documentation including E2E tests, custom tests, and configuration, see Testing Guide.
The automated deployment script handles the complete flow including infrastructure, market deployment, governance proposals, and verification:
# Start Anvil first (in separate terminal)
anvil
# Deploy DAI market (automated with confirmations)
./scripts/deployer/deploy-markets/index.sh -n local -d dai
# Deploy with auto-confirmation (non-interactive)
./scripts/deployer/deploy-markets/index.sh -n local -d dai -c -y# Deploy single market
./scripts/deployer/deploy-markets/index.sh -n local -d dai
# Deploy multiple markets at once
./scripts/deployer/deploy-markets/index.sh -n local -d dai,usdc,weth
# Deploy with clean cache (removes existing artifacts)
./scripts/deployer/deploy-markets/index.sh -n local -d dai -c
# Deploy all available markets
./scripts/deployer/deploy-markets/index.sh -n local -d allFor more information on how to add new networks or markets, check the respective documentation:
The automated script performs these steps:
- Builds the project - Compiles contracts
- Clears proposal stack - Resets governance queue to avoid conflicts
- Deploys infrastructure - Governor, Timelock, COMP token and other shared contracts
- Prompts for configuration - Asks you to update
configuration.json - Deploys market(s) - Deploys Comet implementations
- Proposes Market upgrades - Upgrades markets to new implementations
- Funds rewards - Transfers COMP to CometRewards
- Runs Deployment verification - Tests deployment validity
The BlockDAG deployment system consists of several layers:
Deployment Scripts (bash wrappers)
↓
TypeScript Scripts (logic layer)
↓
Hardhat Tasks (deployment primitives)
↓
DeploymentManager (contract management)
↓
Blockchain (Anvil/Network)
- Hardhat loads task definitions from
tasks/deployment_manager/task.ts - Command line arguments are parsed:
network,deployment,bdagflag - Environment and network configuration is established
- Creates DeploymentManager instance with network and deployment parameters
- Establishes deployment cache for contract reuse
- Sets up contract discovery and relationship mapping
- Loads appropriate
deployments/{network}/{deployment}/deploy.tsscript - Imports and executes the deployment function
- Handles governance contract cloning (COMP token, Governor implementation)
Phase 1: Infrastructure Deployment
- Governance Contracts: Deploy CustomGovernor, CustomTimelock, COMP token
- Shared Protocol Contracts: Deploy CometProxyAdmin, Configurator, CometFactory, CometRewards
Phase 2: Market Deployment
- Token Deployment: Deploy market tokens (DAI, USDC, etc.) if needed
- Price Feed Setup: Configure asset price feeds
- Comet Implementation: Deploy Comet implementation contract
- Governance Proposal: Create proposal to add implementation to configuration
Phase 3: Market Activation
- Governance Approval: Approve the proposal (multisig voting)
- Queue Proposal: Queue proposal for execution
- Execute Proposal: Execute after timelock delay
- Upgrade Proposal: Create and execute upgrade to new implementation
Phase 4: Rewards & Verification
- Fund Rewards: Transfer COMP tokens to CometRewards
- Verify Deployment: Run automated verification tests
Note: When executing the deploy-markets script, for multiple markets, the script will use the Proposal Service to create batched proposals for the market implementations and upgrades. This means that the script will create a single proposal for all the market implementations and upgrades, and then execute it.
- Contract verification (when applicable)
- Cache storage for future deployments
- Logging of deployment statistics and gas usage
Infrastructure (_infrastructure folder):
- Deployed once per network
- Contains shared contracts: Governor, Timelock, COMP, CometFactory, CometRewards
- Configuration in
deployments/{network}/_infrastructure/configuration.json
Market (e.g., dai, usdc folders):
- Deployed per market
- Contains market-specific: Comet implementation, market configuration
- Configuration in
deployments/{network}/{market}/configuration.json
Before deploying markets, configure two key files:
1. Infrastructure Configuration (deployments/{network}/_infrastructure/configuration.json):
- Governor admins and multisig threshold
- Timelock delay and grace period settings
2. Market Configuration (deployments/{network}/{market}/configuration.json):
- Protocol settings (name, symbol, base token)
- Interest rate models (
ratessection) - Reward tracking (
trackingsection) - Collateral assets with price feeds and risk parameters
For complete configuration examples and detailed parameter explanations, see:
- Market Configuration - Configuring market parameters
- Governance System - Infrastructure configuration
Located in scripts/deployer/deploy-markets/:
Main Script:
index.sh- Bash wrapper for user-friendly interfaceindex.ts- TypeScript implementation with full deployment logic
Usage:
./scripts/deployer/deploy-markets/index.sh [options]
Options:
-n, --network <network> Network to deploy to (default: local)
-d, --deployment <market> Market(s) to deploy
-c, --clean Clean deployment cache before deploying
-h, --help Show help messageLocated in scripts/governor/:
Proposal Creation (propose/):
market-phase-1/- Deploy new market implementationmarket-phase-2/- Propose upgrade to new implementationcomet-reward-funding/- Propose CometRewards fundinggovernance-update/- Propose governance parameter changes
Proposal Management:
accept-proposal/- Approve proposals (multisig voting)queue-proposal/- Queue approved proposalsexecute-proposal/- Execute queued proposals
Testing & Verification:
test-governor-setup/- Verify governance configurationtest-market-setup/- Verify market deployment
Governance Proposal Workflow:
Mercury's governance follows a structured workflow with clear states:
Proposal States:
- Pending: Proposal created, waiting for approvals
- Approved: Multisig threshold reached, queued in Timelock
- Queued: In timelock delay period
- Executable: Delay passed, ready for execution
- Executed: Successfully executed on-chain
Example: Deploy New Market
# Phase 1: Deploy market implementation
./scripts/governor/propose/market-phase-1/index.sh -n local -d wbtc
# Output: Proposal ID: 1
# Phase 2: Approve, queue, and execute implementation
./scripts/governor/accept-proposal/index.sh -n local -p 1
./scripts/governor/queue-proposal/index.sh -n local -p 1
./scripts/governor/execute-proposal/index.sh -n local -p 1 -t comet-impl-in-configuration
# Phase 3: Propose upgrade to new implementation
./scripts/governor/propose/market-phase-2/index.sh -n local -d wbtc -i <IMPLEMENTATION_ADDRESS>
# Output: Proposal ID: 2
# Phase 4: Approve, queue, and execute upgrade
./scripts/governor/accept-proposal/index.sh -n local -p 2
./scripts/governor/queue-proposal/index.sh -n local -p 2
./scripts/governor/execute-proposal/index.sh -n local -p 2 -t comet-upgrade
# Verify market setup
./scripts/governor/test-market-setup/index.sh -n local -d wbtcExecution Types:
comet-impl-in-configuration- For market implementation deployments (Phase 1)comet-upgrade- For market upgrades (Phase 2)governance-update- For governance configuration changescomet-reward-funding- For CometRewards funding proposals
If you need fine-grained control, you can use Hardhat tasks directly:
Infrastructure Deployment:
yarn hardhat deploy_infrastructure --network local --bdagMarket Deployment:
yarn hardhat deploy --network local --deployment dai --bdagGovernance Commands:
# Check proposal status
yarn hardhat governor:status --network local --proposal-id 1
# Approve proposal
yarn hardhat governor:approve --network local --proposal-id 1
# Queue proposal
yarn hardhat governor:queue --network local --proposal-id 1
# Execute proposal
yarn hardhat governor:execute --network local --proposal-id 1 --execution-type comet-impl-in-configurationInteractive Console:
yarn hardhat console --network localDeployment Verification:
./scripts/governor/test-market-setup/index.sh -n local -d dai
./scripts/governor/test-governor-setup/index.sh -n localSpider Tool (contract discovery and relationship mapping):
yarn hardhat spider --network local --deployment daiDebugging:
# Gas reporting
REPORT_GAS=true yarn hardhat test
# Debug logging
DEBUG=* yarn hardhat deploy --network local --deployment dai --bdagMercury uses deployment caching to avoid re-deploying existing contracts, improving development efficiency and ensuring consistency.
Quick Cache Management:
# Deploy with clean cache (recommended for fresh start)
./scripts/deployer/deploy-markets/index.sh -n local -d dai -c
# Manually clear specific market cache
rm -rf deployments/local/dai/.contracts/Cache Location: deployments/{network}/{deployment}/.contracts/
For detailed caching behavior, benefits, and BlockDAG-specific considerations, see Deployment Caching.
# Kill any existing Anvil instances
pkill anvil
# Start fresh Anvil instance
anvil# Use -c flag when you want a complete fresh start
./scripts/deployer/deploy-markets/index.sh -n local -d dai -c# Always verify your deployment
./scripts/governor/test-market-setup/index.sh -n local -d daiAlways test your configurations locally before deploying to real networks:
# Test locally first
./scripts/deployer/deploy-markets/index.sh -n local -d usdc
# Then deploy to real network
./scripts/deployer/deploy-markets/index.sh -n bdag-primordial -d usdcAlways update your configuration.json files with correct:
- Price feed addresses
- Asset configurations
- Supply caps
- Collateral factors
Common Quick Fixes:
# Clear deployment cache
./scripts/deployer/deploy-markets/index.sh -n local -d dai -c
# Clear proposal stack
yarn hardhat governor:clear-stack --network local
# Check Anvil is running
curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://127.0.0.1:8545For comprehensive troubleshooting including deployment failures, governance issues, and network problems, see Troubleshooting Guide.
- Environment Configuration - API keys and environment setup
- Market Configuration - Configuring market parameters
- Governance System - Understanding BDAG governance
- Testing Guide - Comprehensive testing documentation
- Deployment Caching - Deep dive into caching system
- Troubleshooting - Solutions to common issues