Mezo Earn Development Guide
Mezo Earn is the smart contract system powering the Mezo gauge system and decentralized exchange (DEX). This guide will help you understand how to build and interact with Mezo Earn contracts.
📄 Download the Mezo Earn Whitepaper (PDF) — For a comprehensive overview of the economic incentive framework, dual-token model, and tokenomics.
Overview
Section titled “Overview”Mezo Earn provides:
- Decentralized Exchange (DEX): Automated market maker for token swaps
- Gauge System: Voting and reward distribution mechanism
- Solidly-inspired Architecture: Efficient ve-tokenomics and liquidity management
Repository Structure
Section titled “Repository Structure”The Mezo Earn repository contains:
- solidity/: Smart contracts written in Solidity
- dapp/: Frontend application for interacting with contracts
- infrastructure/: Cloudflare-based infrastructure components
- .github/workflows/: CI/CD automation
Development Setup
Section titled “Development Setup”Prerequisites
Section titled “Prerequisites”- Node.js (check
.nvmrcfor exact version) - pnpm package manager
- Git
- Foundry (for smart contract development)
Installation
Section titled “Installation”- Clone the repository:
git clone https://github.com/mezo-org/tigris.gitcd tigris- Install dependencies:
pnpm install- Set up pre-commit hooks:
# Install pre-commit toolbrew install pre-commit
# Install hooks in the repositorypre-commit installTesting Pre-commit Hooks
Section titled “Testing Pre-commit Hooks”# Test all filespre-commit run --all-files
# Test specific filespre-commit run --files <path-to-file>Smart Contract Development
Section titled “Smart Contract Development”Contract Architecture
Section titled “Contract Architecture”Mezo Earn contracts are organized in the solidity/ directory. Key components include:
- Core DEX Contracts: Automated market maker functionality
- Gauge Contracts: Voting and reward distribution
- Token Contracts: ERC20 implementations
- Utility Contracts: Helper functions and libraries
Development Workflow
Section titled “Development Workflow”- Write Contracts: Create or modify Solidity files in
solidity/ - Test Contracts: Write comprehensive tests for your contracts
- Deploy: Use deployment scripts to deploy to testnet/mainnet
- Verify: Verify contracts on block explorers
Compiling Contracts
Section titled “Compiling Contracts”# Compile smart contractspnpm compile
# or with Foundry directlycd solidityforge buildTesting
Section titled “Testing”# Run all testspnpm test
# Run specific test filepnpm test <test-file>
# Run with gas reportingpnpm test:gasFrontend Development
Section titled “Frontend Development”The dapp/ directory contains the frontend application for interacting with Mezo Earn contracts.
Key Features
Section titled “Key Features”- Swap Interface: Token swapping functionality
- Liquidity Management: Add/remove liquidity from pools
- Gauge Voting: Participate in gauge voting and rewards
- Portfolio Management: Track positions and rewards
Development Commands
Section titled “Development Commands”# Navigate to dapp directorycd dapp
# Start development serverpnpm dev
# Build for productionpnpm build
# Preview production buildpnpm previewIntegration Guide
Section titled “Integration Guide”Connecting to Mezo Earn Contracts
Section titled “Connecting to Mezo Earn Contracts”- Get Contract Addresses: Deployed contract addresses for Mezo testnet/mainnet
- ABI Integration: Import contract ABIs for interaction
- Web3 Provider: Connect to Mezo network via RPC
Example Integration
Section titled “Example Integration”import { ethers } from 'ethers';
// Connect to Mezo networkconst provider = new ethers.JsonRpcProvider('https://rpc.mezo.org');
// Load contract ABI and addressconst contract = new ethers.Contract( 'CONTRACT_ADDRESS', CONTRACT_ABI, provider);
// Interact with contractconst result = await contract.someFunction();Swapping Tokens
Section titled “Swapping Tokens”async function swapTokens( routerContract: Contract, wallet: Wallet, amountIn: bigint, tokenIn: string, tokenOut: string, to: string) { // Approve token spending const tokenContract = new ethers.Contract(tokenIn, ERC20_ABI, wallet); await tokenContract.approve(routerContract.address, amountIn);
// Execute swap const deadline = Math.floor(Date.now() / 1000) + 60 * 20; // 20 minutes const minAmountOut = 0; // Calculate proper slippage in production
await routerContract.connect(wallet).swapExactTokensForTokens( amountIn, minAmountOut, [tokenIn, tokenOut], to, deadline );}Adding Liquidity
Section titled “Adding Liquidity”async function addLiquidity( routerContract: Contract, wallet: Wallet, tokenA: string, tokenB: string, amountA: bigint, amountB: bigint) { // Approve both tokens const tokenAContract = new ethers.Contract(tokenA, ERC20_ABI, wallet); const tokenBContract = new ethers.Contract(tokenB, ERC20_ABI, wallet);
await tokenAContract.approve(routerContract.address, amountA); await tokenBContract.approve(routerContract.address, amountB);
// Add liquidity const deadline = Math.floor(Date.now() / 1000) + 60 * 20;
await routerContract.connect(wallet).addLiquidity( tokenA, tokenB, amountA, amountB, 0, // minAmountA - calculate proper slippage 0, // minAmountB - calculate proper slippage wallet.address, deadline );}Deployment
Section titled “Deployment”Testnet Deployment
Section titled “Testnet Deployment”- Configure testnet parameters in
.env - Deploy contracts using deployment scripts:
pnpm deploy:testnet- Verify contracts on testnet explorer
- Update frontend configuration
Mainnet Deployment
Section titled “Mainnet Deployment”- Complete thorough testing on testnet
- Security audit (if required)
- Deploy to mainnet
- Verify contracts
- Update production configuration
Monitoring and Maintenance
Section titled “Monitoring and Maintenance”Contract Monitoring
Section titled “Contract Monitoring”- Set up event monitoring for critical functions
- Monitor gas usage and optimization opportunities
- Track contract interactions and user activity
Security Considerations
Section titled “Security Considerations”- Regular security audits
- Access control management
- Emergency pause mechanisms
- Upgrade procedures
Additional Resources
Section titled “Additional Resources”- Mezo Earn Repository - Main repository
- Solidly Documentation - Solidly protocol documentation
- Mezo Network Documentation - Network configuration
- Contract Verification Guide - Contract verification
Support
Section titled “Support”For development support:
- Join the Mezo Discord
- Check the GitHub Issues
- Review the FAQ