# sablier-labs/lockup architecture

> Architecture diagram of the GitHub repository sablier-labs/lockup, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sablier-labs/lockup
- Repository: https://github.com/sablier-labs/lockup

## Overview

##### Project Type and Purpose
- Sablier Lockup is an open-source Solidity library/protocol for on-chain token vesting and airdrops. It exposes a singleton “SablierLockup” smart contract that manages multiple distribution models (linear streams, batch lockup, dynamic, tranched, NFT descriptor).
- It ships as an NPM/Foundry package and is extensively tested and benchmarked.

##### File Structure Analysis
- src/
- abstracts/      — base contracts defining common state and hooks
- interfaces/     — public interfaces (ISablierLockup, model interfaces, etc.)
- libraries/      — internal math/utility contracts
- types/          — custom Solidity types
- script/           — Foundry deployment and maintenance scripts
- shell/            — helpers to generate SVGs, prepare artifacts, update counts
- tests/            — unit, integration, fuzz, invariant, mocks, branching-tree technique (.tree)
- benchmark/        — performance tests and results
- CI config         — GitHub Actions workflows, slither.config.json
- package.json, foundry.toml, remappings.txt — build & dependency management

##### README Insights
- Singleton-style architecture: one contract (SablierLockup) hosts all streams/models.
- External deps: OpenZeppelin ERC-20, PRB-Math.
- Testing uses Foundry + Bulloak’s branching tree.

a. Main Components
- On-chain Components:
- SablierLockup (singleton contract)
- AbstractBase (common storage & logic)
- Concrete Models:
– BatchLockup
– LockupBase
– LockupDynamic
– LockupLinear
– LockupTranched
- NFTDescriptor Module
- External Protocols: ERC-20 tokens, PRB-Math, OpenZeppelin contracts
- Off-chain Components:
- Foundry toolchain (forge, remappings)
- NPM package (@sablier/lockup)
- CI/CD pipelines (GitHub Actions, Slither, Multibuild)
- Benchmark runner & results
- Scripts & Shell utilities

b. Relationships & Data Flows
- User/App → imports ISablierLockup → calls SablierLockup.deposit/withdraw
- SablierLockup dispatches to appropriate model module (via internal routing)
- Model modules reference AbstractBase for storage, Libraries for math, Interfaces for token hooks
- SablierLockup and modules invoke ERC-20 transfer functions
- Off-chain: Foundry compiles/deploys contracts, tests call contract methods, CI triggers benchmarks and security checks

c. Architectural Patterns & Principles
- Singleton Contract Pattern (one on-chain entrypoint)
- Modular Extension (plug-in concrete models inheriting from abstracts)
- Separation of Concerns (interfaces vs. implementations vs. libraries vs. scripts)
- Branching Tree Testing (Bulloak) for exhaustive behavior coverage

d. Key Technologies & Frameworks
- Solidity (contracts)
- Foundry (forge, foundry.toml)
- OpenZeppelin & PRB-Math (external libs)
- GitHub Actions (CI workflows)
- Slither (static analysis)
- Bulloak (branching tree technique)
- Bun/Node.js (package manager)

## Diagram (Mermaid)

```mermaid
graph TD
  subgraph "On-chain Architecture"
    direction TB
    SC["SablierLockup"]:::contract
    AB["AbstractLockup"]:::abstract
    subgraph "Models"
      direction TB
      BL["BatchLockup"]:::contract
      LB["LockupBase"]:::contract
      LD["LockupDynamic"]:::contract
      LL["LockupLinear"]:::contract
      LT["LockupTranched"]:::contract
    end
    ND["NFTDescriptor"]:::contract
    subgraph "Interfaces"
      direction TB
      PI["Public Interfaces"]:::interface
    end
    subgraph "Libraries"
      direction TB
      LIB["Math & Utilities"]:::library
      CT["Custom Types"]:::type
    end
    subgraph "Externals"
      direction TB
      ERC["ERC-20 Tokens"]:::external
      PRB["PRB-Math"]:::external
      OZ["OpenZeppelin"]:::external
    end

    SC -->|"inherits"| AB
    AB -->|"extends"| LIB
    AB -->|"uses types"| CT
    SC -->|"routes to"| BL
    SC -->|"routes to"| LB
    SC -->|"routes to"| LD
    SC -->|"routes to"| LL
    SC -->|"routes to"| LT
    BL -->|"use storage"| AB
    LB -->|"use storage"| AB
    LD -->|"use storage"| AB
    LL -->|"use storage"| AB
    LT -->|"use storage"| AB
    BL -->|"import"| LIB
    LB -->|"import"| LIB
    LD -->|"import"| LIB
    LL -->|"import"| LIB
    LT -->|"import"| LIB
    BL -->|"implement"| PI
    LB -->|"implement"| PI
    LD -->|"implement"| PI
    LL -->|"implement"| PI
    LT -->|"implement"| PI
    SC -->|"descriptor"| ND
    SC -->|"ERC20 calls"| ERC
    SC -->|"ERC20 calls"| OZ
    SC -->|"math"| PRB
  end

  subgraph "Off-chain Ecosystem"
    direction TB
    DEV["Developer"]:::actor
    FD["Foundry Toolchain"]:::tool
    NPM["NPM Package"]:::tool
    SPR["Scripts"]:::script
    SHL["Shell Utils"]:::script
    CI["CI/CD Pipelines"]:::ci
    SL["Slither Config"]:::ci
    BM["Benchmark Runner"]:::benchmark
    RES["Benchmark Results"]:::benchmark
    TEST["Tests Suite"]:::test
  end

  DEV --> FD
  DEV -->|"publishes"| NPM
  FD -->|"runs"| SPR
  SPR -->|"calls"| SHL
  CI -->|"triggers"| FD
  CI -->|"runs"| SL
  CI -->|"runs"| BM
  FD -->|"executes"| TEST
  BM --> RES

  click SC "https://github.com/sablier-labs/lockup/blob/main/src/SablierLockup.sol"
  click AB "https://github.com/sablier-labs/lockup/blob/main/src/abstracts/AbstractLockup.sol"
  click BL "https://github.com/sablier-labs/lockup/blob/main/src/BatchLockup.sol"
  click LB "https://github.com/sablier-labs/lockup/blob/main/src/LockupBase.sol"
  click LD "https://github.com/sablier-labs/lockup/blob/main/src/LockupDynamic.sol"
  click LL "https://github.com/sablier-labs/lockup/blob/main/src/LockupLinear.sol"
  click LT "https://github.com/sablier-labs/lockup/blob/main/src/LockupTranched.sol"
  click ND "https://github.com/sablier-labs/lockup/blob/main/src/NFTDescriptor.sol"
  click PI "https://github.com/sablier-labs/lockup/tree/main/src/interfaces/"
  click LIB "https://github.com/sablier-labs/lockup/tree/main/src/libraries/"
  click CT "https://github.com/sablier-labs/lockup/tree/main/src/types/"
  click FD "https://github.com/sablier-labs/lockup/blob/main/foundry.toml"
  click NPM "https://github.com/sablier-labs/lockup/blob/main/package.json"
  click CI "https://github.com/sablier-labs/lockup/blob/main/.github/workflows/ci.yml"
  click SL "https://github.com/sablier-labs/lockup/blob/main/slither.config.json"
  click BM "https://github.com/sablier-labs/lockup/tree/main/benchmark/"
  click RES "https://github.com/sablier-labs/lockup/blob/main/benchmark/results/SablierLockup_*.md"
  click SPR "https://github.com/sablier-labs/lockup/tree/main/script/"
  click SHL "https://github.com/sablier-labs/lockup/blob/main/shell/generate-svg.sh"
  click TEST "https://github.com/sablier-labs/lockup/tree/main/tests/unit/"

  classDef contract fill:#ffd700,stroke:#333,stroke-width:1px
  classDef abstract fill:#e0e0e0,stroke:#333,stroke-dasharray: 5 5
  classDef interface fill:#add8e6,stroke:#333,stroke-width:1px
  classDef library fill:#90ee90,shape:circle
  classDef type fill:#ffdead,shape:circle
  classDef external fill:#d3d3d3,shape:cylinder
  classDef actor fill:#ffa07a,stroke:#333,stroke-width:1px
  classDef tool fill:#dda0dd,stroke:#333,stroke-width:1px
  classDef script fill:#fafad2,stroke:#333,stroke-width:1px
  classDef ci fill:#87cefa,stroke:#333,stroke-width:1px
  classDef benchmark fill:#98fb98,stroke:#333,stroke-width:1px
  classDef test fill:#ffb6c1,stroke:#333,stroke-width:1px
```
