Skip to content

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.

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

The Mezo Earn repository contains:

  • Node.js (check .nvmrc for exact version)
  • pnpm package manager
  • Git
  • Foundry (for smart contract development)
  1. Clone the repository:
Terminal window
git clone https://github.com/mezo-org/tigris.git
cd tigris
  1. Install dependencies:
Terminal window
pnpm install
  1. Set up pre-commit hooks:
Terminal window
# Install pre-commit tool
brew install pre-commit
# Install hooks in the repository
pre-commit install
Terminal window
# Test all files
pre-commit run --all-files
# Test specific files
pre-commit run --files <path-to-file>

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
  1. Write Contracts: Create or modify Solidity files in solidity/
  2. Test Contracts: Write comprehensive tests for your contracts
  3. Deploy: Use deployment scripts to deploy to testnet/mainnet
  4. Verify: Verify contracts on block explorers
Terminal window
# Compile smart contracts
pnpm compile
# or with Foundry directly
cd solidity
forge build
Terminal window
# Run all tests
pnpm test
# Run specific test file
pnpm test <test-file>
# Run with gas reporting
pnpm test:gas

The dapp/ directory contains the frontend application for interacting with Mezo Earn contracts.

  • 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
Terminal window
# Navigate to dapp directory
cd dapp
# Start development server
pnpm dev
# Build for production
pnpm build
# Preview production build
pnpm preview
  1. Get Contract Addresses: Deployed contract addresses for Mezo testnet/mainnet
  2. ABI Integration: Import contract ABIs for interaction
  3. Web3 Provider: Connect to Mezo network via RPC
import { ethers } from 'ethers';
// Connect to Mezo network
const provider = new ethers.JsonRpcProvider('https://rpc.mezo.org');
// Load contract ABI and address
const contract = new ethers.Contract(
'CONTRACT_ADDRESS',
CONTRACT_ABI,
provider
);
// Interact with contract
const result = await contract.someFunction();
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
);
}
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
);
}
  1. Configure testnet parameters in .env
  2. Deploy contracts using deployment scripts:
Terminal window
pnpm deploy:testnet
  1. Verify contracts on testnet explorer
  2. Update frontend configuration
  1. Complete thorough testing on testnet
  2. Security audit (if required)
  3. Deploy to mainnet
  4. Verify contracts
  5. Update production configuration
  • Set up event monitoring for critical functions
  • Monitor gas usage and optimization opportunities
  • Track contract interactions and user activity
  • Regular security audits
  • Access control management
  • Emergency pause mechanisms
  • Upgrade procedures

For development support: