> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/mezo-org/documentation/llms.txt
> Use this file to discover all available pages before exploring further.

# Mezo Earn Development Guide

> Comprehensive guide for building on Mezo Earn, the Mezo gauge system and DEX inspired by Solidly

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.

<Note>
  **[Download the Mezo Earn Whitepaper (PDF)](/Mezo_Earn_Whitepaper.pdf)** — For a comprehensive overview of the economic incentive framework, dual-token model, and tokenomics.
</Note>

## 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](https://github.com/mezo-org/tigris.git) contains:

* **[solidity/](https://github.com/mezo-org/tigris/tree/main/solidity)**: Smart contracts written in Solidity
* **[dapp/](https://github.com/mezo-org/tigris/tree/main/dapp)**: Frontend application for interacting with contracts
* **[infrastructure/](https://github.com/mezo-org/tigris/tree/main/infrastructure)**: Cloudflare-based infrastructure components
* **[.github/workflows/](https://github.com/mezo-org/tigris/tree/main/.github/workflows)**: CI/CD automation

## Development Setup

### Prerequisites

* Node.js (check [`.nvmrc`](https://github.com/mezo-org/tigris/blob/main/.nvmrc) for exact version)
* pnpm package manager
* Git
* Foundry (for smart contract development)

### Installation

<Steps>
  <Step title="Clone the repository">
    ```bash theme={null}
    git clone https://github.com/mezo-org/tigris.git
    cd tigris
    ```
  </Step>

  <Step title="Install dependencies">
    ```bash theme={null}
    pnpm install
    ```
  </Step>

  <Step title="Set up pre-commit hooks">
    ```bash theme={null}
    # Install pre-commit tool
    brew install pre-commit

    # Install hooks in the repository
    pre-commit install
    ```
  </Step>
</Steps>

### Testing Pre-commit Hooks

<CodeGroup>
  ```bash Test all files theme={null}
  pre-commit run --all-files
  ```

  ```bash Test specific files theme={null}
  pre-commit run --files <path-to-file>
  ```
</CodeGroup>

## Smart Contract Development

### Contract Architecture

Mezo Earn contracts are organized in the [`solidity/`](https://github.com/mezo-org/tigris/tree/main/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

<Steps>
  <Step title="Write Contracts">
    Create or modify Solidity files in `solidity/`
  </Step>

  <Step title="Test Contracts">
    Write comprehensive tests for your contracts
  </Step>

  <Step title="Deploy">
    Use deployment scripts to deploy to testnet/mainnet
  </Step>

  <Step title="Verify">
    Verify contracts on block explorers
  </Step>
</Steps>

### Compiling Contracts

<CodeGroup>
  ```bash Using pnpm theme={null}
  pnpm compile
  ```

  ```bash Using Foundry directly theme={null}
  cd solidity
  forge build
  ```
</CodeGroup>

### Testing

<CodeGroup>
  ```bash Run all tests theme={null}
  pnpm test
  ```

  ```bash Run specific test file theme={null}
  pnpm test <test-file>
  ```

  ```bash Run with gas reporting theme={null}
  pnpm test:gas
  ```
</CodeGroup>

## Frontend Development

The [`dapp/`](https://github.com/mezo-org/tigris/tree/main/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

<CodeGroup>
  ```bash Start development server theme={null}
  cd dapp
  pnpm dev
  ```

  ```bash Build for production theme={null}
  pnpm build
  ```

  ```bash Preview production build theme={null}
  pnpm preview
  ```
</CodeGroup>

## Integration Guide

### Connecting to Mezo Earn Contracts

<Steps>
  <Step title="Get Contract Addresses">
    Deployed contract addresses for Mezo testnet/mainnet
  </Step>

  <Step title="ABI Integration">
    Import contract ABIs for interaction
  </Step>

  <Step title="Web3 Provider">
    Connect to Mezo network via RPC
  </Step>
</Steps>

### Example Integration

```typescript theme={null}
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

```typescript theme={null}
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

```typescript theme={null}
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

<Steps>
  <Step title="Configure testnet parameters">
    Set up testnet parameters in `.env`
  </Step>

  <Step title="Deploy contracts">
    ```bash theme={null}
    pnpm deploy:testnet
    ```
  </Step>

  <Step title="Verify contracts">
    Verify contracts on testnet explorer
  </Step>

  <Step title="Update configuration">
    Update frontend configuration
  </Step>
</Steps>

### Mainnet Deployment

<Steps>
  <Step title="Complete testing">
    Complete thorough testing on testnet
  </Step>

  <Step title="Security audit">
    Conduct security audit (if required)
  </Step>

  <Step title="Deploy to mainnet">
    Deploy contracts to mainnet
  </Step>

  <Step title="Verify contracts">
    Verify contracts on mainnet explorer
  </Step>

  <Step title="Update production config">
    Update production configuration
  </Step>
</Steps>

## 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

* **[Mezo Earn Repository](https://github.com/mezo-org/tigris.git)** - Main repository
* **[Solidly Documentation](https://docs.solidly.com/)** - Solidly protocol documentation
* **[Mezo Network Documentation](/developers/getting-started/environment)** - Network configuration
* **[Contract Verification Guide](/resources/contracts)** - Contract verification

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

## Support

For development support:

* Join the [Mezo Discord](https://discord.com/invite/mezo)
* Check the [GitHub Issues](https://github.com/mezo-org/tigris/issues)
* Review the [FAQ](/resources/faqs)
