Skip to main content
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

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

The Mezo Earn repository contains:

Development Setup

Prerequisites

  • Node.js (check .nvmrc for exact version)
  • pnpm package manager
  • Git
  • Foundry (for smart contract development)

Installation

1

Clone the repository

git clone https://github.com/mezo-org/tigris.git
cd tigris
2

Install dependencies

pnpm install
3

Set up pre-commit hooks

# Install pre-commit tool
brew install pre-commit

# Install hooks in the repository
pre-commit install

Testing Pre-commit Hooks

pre-commit run --all-files

Smart Contract Development

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

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

Compiling Contracts

pnpm compile

Testing

pnpm test

Frontend Development

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

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

cd dapp
pnpm dev

Integration Guide

Connecting to Mezo Earn Contracts

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

Example Integration

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();

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

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

Testnet Deployment

1

Configure testnet parameters

Set up testnet parameters in .env
2

Deploy contracts

pnpm deploy:testnet
3

Verify contracts

Verify contracts on testnet explorer
4

Update configuration

Update frontend configuration

Mainnet Deployment

1

Complete testing

Complete thorough testing on testnet
2

Security audit

Conduct security audit (if required)
3

Deploy to mainnet

Deploy contracts to mainnet
4

Verify contracts

Verify contracts on mainnet explorer
5

Update production config

Update production configuration

Monitoring and Maintenance

Contract Monitoring

  • Set up event monitoring for critical functions
  • Monitor gas usage and optimization opportunities
  • Track contract interactions and user activity

Security Considerations

  • Regular security audits
  • Access control management
  • Emergency pause mechanisms
  • Upgrade procedures

Additional Resources

For detailed architecture, tokenomics, and protocol mechanics, refer to the Mezo Earn repository README and documentation.

Support

For development support:

Build docs developers (and LLMs) love