# sushiswap/v2-core architecture

> Architecture diagram of the GitHub repository sushiswap/v2-core, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sushiswap/v2-core
- Repository: https://github.com/sushiswap/v2-core

## Overview

##### Main Components

a. Core Protocol Components:
- UniswapV2Factory (Smart Contract)
- UniswapV2Router02 (Smart Contract)
- Liquidity Pools (Generated by Factory)
- WETH Contract Interface
- SushiRoll (Migration Contract)

b. Cross-Chain Infrastructure:
- Multiple Blockchain Networks Support (40+ networks identified in deployments)
- Chain-Specific Deployments

**[Web3 Wallets] ←→ [Frontend Interface]***

**[UniswapV2Router02]**
- Handles all swap operations
- Manages liquidity addition/removal
- Path finding for trades

**[UniswapV2Factory] ←→ [Liquidity Pools]**
- (Pair Contracts)

**[ERC20 Tokens] [WETH] [Native Currencies]**

##### Connection Types

**Supported Networks:**
- Ethereum
- Arbitrum
- Avalanche
- BSC
- Polygon
**[etc.]**

##### Implementation Details

Technical annotations:
- Solidity version
- Deployment configurations
- Chain IDs
- Gas optimization notes

##### Architectural Notes

- Permissionless nature of pair creation
- Constant product formula (x * y = k)
- Flash swap capabilities
- Fee structure

##### Security boundaries and trust assumptions

- Contract inheritance patterns
- Upgrade paths (if any)
- Integration points
- Security considerations
- Gas optimization points

Remember to include version information and deployment-specific configurations for each network, as the project supports multiple chains with potentially different parameters.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph User["User Interaction Layer"]
        Wallet["Web3 Wallets"]
        Frontend["Frontend Interface"]
    end

    subgraph Router["Router Layer"]
        Router02["UniswapV2Router02"]:::router
    end

    subgraph Core["Core Protocol Layer"]
        Factory["UniswapV2Factory"]:::factory
        LiqPools["Liquidity Pools"]:::pools
        SushiRoll["SushiRoll Migration"]:::migration
    end

    subgraph Token["Token Layer"]
        ERC20["ERC20 Tokens"]
        WETH["WETH Contract"]:::weth
        Native["Native Currencies"]
    end

    subgraph Networks["Supported Networks"]
        direction TB
        Ethereum["Ethereum"]:::network
        Arbitrum["Arbitrum"]:::network
        Avalanche["Avalanche"]:::network
        BSC["BSC"]:::network
        Polygon["Polygon"]:::network
        Optimism["Optimism"]:::network
        Base["Base"]:::network
        Others["Other Networks"]:::network
    end

    subgraph Components["Component Types"]
        Contracts["Smart Contracts"]:::contract
        Pools["Liquidity Pools"]:::pools
        Interfaces["Interfaces"]:::interface
        Migration["Migration Tools"]:::migration
    end

    Wallet <--> Frontend
    Frontend <--> Router02
    Router02 <--> Factory
    Factory <--> LiqPools
    Router02 <--> LiqPools
    LiqPools <--> ERC20
    LiqPools <--> WETH
    LiqPools <--> Native
    SushiRoll <--> Router02

    %% Click events for component mapping
    click Factory "https://github.com/sushiswap/v2-core/blob/master/deploy/UniswapV2Factory.ts"
    click Router02 "https://github.com/sushiswap/v2-core/blob/master/deploy/UniswapV2Router02.ts"
    click SushiRoll "https://github.com/sushiswap/v2-core/blob/master/deploy/SushiRoll.ts"
    click WETH "https://github.com/sushiswap/v2-core/blob/master/deploy/WETH9.ts"
    click Arbitrum "https://github.com/sushiswap/v2-core/tree/master/deployments/arbitrum"
    click Avalanche "https://github.com/sushiswap/v2-core/tree/master/deployments/avalanche"
    click BSC "https://github.com/sushiswap/v2-core/tree/master/deployments/bsc"
    click Polygon "https://github.com/sushiswap/v2-core/tree/master/deployments/matic"
    click Optimism "https://github.com/sushiswap/v2-core/tree/master/deployments/optimism"
    click Base "https://github.com/sushiswap/v2-core/tree/master/deployments/base"

    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef router fill:#ff9900,stroke:#333,stroke-width:2px
    classDef factory fill:#3498db,stroke:#333,stroke-width:2px
    classDef pools fill:#2ecc71,stroke:#333,stroke-width:2px
    classDef network fill:#e74c3c,stroke:#333,stroke-width:2px
    classDef weth fill:#9b59b6,stroke:#333,stroke-width:2px
    classDef migration fill:#f1c40f,stroke:#333,stroke-width:2px
    classDef contract fill:#3498db,stroke:#333,stroke-width:2px
    classDef interface fill:#95a5a6,stroke:#333,stroke-width:2px
```
