# sherlock-audit/2025-05-layeredge architecture

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

- Interactive diagram: https://gitdiagram.com/sherlock-audit/2025-05-layeredge
- Repository: https://github.com/sherlock-audit/2025-05-layeredge

## Overview

##### Project type and purpose
- This is a Solidity-based, EVM-compatible staking protocol (LayerEdgeStaking) intended for deployment on Ethereum and the LayerEdge L1 Cosmos chain.
- It provides a tiered staking system (20%/30%/50%) with a Fenwick Tree for efficient user ranking, supports ERC-20 token (EDGEN) and wrapped native token (WETH9), and is UUPS upgradeable via OpenZeppelin.

##### File structure
- Top‐level “edgen-staking” folder contains:
- src/ – Solidity contracts
– stake/LayerEdgeStaking.sol (core logic)
– library/FenwickTree.sol (ranking DS)
– WETH9.sol (wrapped native)
– interfaces/ and library/ folders
- lib/ – vendored dependencies (OpenZeppelin, Solady, forge-std)
- script/ – deployment/test scripts (Foundry)
- test/ – unit tests organized by contract area
- foundry.toml, remappings.txt, Makefile – build & config
- No frontend; purely smart-contract and off-chain tooling (tests/scripts).

##### Key insights from the README
- UUPSUpgradeable pattern (EIP-1822/1967).
- ERC-20 & WETH9 interfaces.
- Fenwick Tree for O(log n) tier boundary management.
- On‐chain invariants (tier distribution, FCFS ordering, interest correctness, reentrancy protection).
- Dual‐chain deployment: Ethereum & LayerEdge L1.

##### Detailed capture of all essential elements
- Proxy forwarding to the implementation, which loads the FenwickTree library.
- UUPS upgrade path: implementation ← upgradeTo() ← ProxyAdmin.
- Off-chain scripts/tests at the bottom, pointing to deployment and unit test targets in contracts.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Users
    Users["EOA Users"]:::external

    %% Blockchain Networks
    subgraph "On-Chain (Ethereum)" 
        direction TB
        Proxy["LayerEdgeStaking Proxy"]:::onchain
        Impl["LayerEdgeStaking Implementation"]:::onchain
        Fenw["FenwickTree Library"]:::library
        EDGEN["ERC-20 Token (EDGEN)"]:::external
        WETH9["Wrapped Native Token (WETH9)"]:::external
        Interfaces["ERC-20 Interfaces"]:::library
        ProxyAdmin["Proxy Admin"]:::onchain
    end

    subgraph "On-Chain (LayerEdge L1)" 
        direction TB
        Proxy2["LayerEdgeStaking Proxy"]:::onchain
        Impl2["LayerEdgeStaking Implementation"]:::onchain
        Fenw2["FenwickTree Library"]:::library
        EDGEN2["ERC-20 Token (EDGEN)"]:::external
        WETH92["Wrapped Native Token (WETH9)"]:::external
        ProxyAdmin2["Proxy Admin"]:::onchain
    end

    %% Off-Chain Tooling
    subgraph "Off-Chain Tooling" 
        direction TB
        Scripts["Deployment & Interaction Scripts"]:::offchain
        Tests["Unit Tests"]:::offchain
        OZ["OpenZeppelin UUPS Modules"]:::library
        Solady["Solady Utilities"]:::library
        ForgeStd["forge-std Utilities"]:::library
        Config["Project Configuration"]:::library
    end

    %% Interactions
    Users -->|"stake()/unstake()/claimInterest()"| Proxy
    Proxy -->|"delegate calls"| Impl
    Impl -->|"update()/query"| Fenw
    Impl -->|"transferFrom/transfer"| EDGEN
    Impl -->|"deposit()/withdraw()/transfer"| WETH9
    ProxyAdmin -->|"upgradeTo()"| Impl

    %% Dual-chain arrows
    Proxy --> Proxy2
    Impl --> Impl2
    Fenw --> Fenw2
    EDGEN --> EDGEN2
    WETH9 --> WETH92
    ProxyAdmin --> ProxyAdmin2

    %% Off-chain to on-chain
    Scripts -->|"deploy proxy & implementation"| Proxy
    Scripts --> ProxyAdmin
    Tests -->|"unit tests via forge"| Impl

    %% Click Events
    click Impl "https://github.com/sherlock-audit/2025-05-layeredge/blob/main/edgen-staking/src/stake/LayerEdgeStaking.sol"
    click Fenw "https://github.com/sherlock-audit/2025-05-layeredge/blob/main/edgen-staking/src/library/FenwickTree.sol"
    click WETH9 "https://github.com/sherlock-audit/2025-05-layeredge/blob/main/edgen-staking/src/WETH9.sol"
    click Interfaces "https://github.com/sherlock-audit/2025-05-layeredge/tree/main/edgen-staking/src/interfaces"
    click OZ "https://github.com/sherlock-audit/2025-05-layeredge/tree/main/edgen-staking/lib/openzeppelin-contracts-upgradeable"
    click Solady "https://github.com/sherlock-audit/2025-05-layeredge/tree/main/edgen-staking/lib/solady"
    click ForgeStd "https://github.com/sherlock-audit/2025-05-layeredge/tree/main/edgen-staking/lib/forge-std"
    click Scripts "https://github.com/sherlock-audit/2025-05-layeredge/tree/main/edgen-staking/script"
    click Tests "https://github.com/sherlock-audit/2025-05-layeredge/tree/main/edgen-staking/test"
    click Config "https://github.com/sherlock-audit/2025-05-layeredge/blob/main/edgen-staking/foundry.toml"

    %% Styles
    classDef onchain fill:#D0E6FF,stroke:#0366D6,stroke-width:2px
    classDef library fill:#F0F0F0,stroke:#999,stroke-dasharray: 5 5
    classDef external fill:#FFE6E6,stroke:#D10000,stroke-width:2px
    classDef offchain fill:#E6FFE6,stroke:#00A000,stroke-width:2px
```
