How sablier-labs/lockup works
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)