# stabilitydao/stability-contracts architecture

> Architecture diagram of the GitHub repository stabilitydao/stability-contracts, 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/stabilitydao/stability-contracts
- Repository: https://github.com/stabilitydao/stability-contracts

## Overview

##### Project type and purpose
- This is a modular Solidity smart-contract suite for “asset management, liquidity mining, and yield farming.”
- It comprises core vault contracts, strategy modules, adapters/integrations to external DeFi protocols, periphery helpers, and tokenomics.

##### File structure
- Top-level folders:
– src/core: core vault logic, proxy patterns
– src/adapters: protocol-agnostic adapters for integrations
– src/integrations: protocol-specific connectors (Aave, Uniswap v3, Curve, etc.)
– src/strategies: strategy blueprints developers deploy into vaults
– src/periphery: external entry points (e.g., router, multicall)
– src/tokenomics: token issuance and vesting contracts
- scripts/: deployment/upgrade scripts (core, periphery, strategy, vaults, tokenomics)
- lib/: pinned external Solidity libraries (OpenZeppelin, Solady, forge-std)
- tests/: contract test suites mapped to each module
- config files: foundry.toml (build & test runner), slither.config.json (static analysis)

##### Leverage README and Guides
- The README references developer- and admin-guides (guides/Core.md, Strategy.md, ADM.md).
- Guides detail architecture patterns (e.g., upgradable proxy, strategy lifecycle, adapter pattern).

##### Main components & their relationships
a. On-chain framework (all within the EVM boundary):
1. Core Vault System
– VaultFactory / ProxyAdmin
– VaultBase (ERC-4626 style shares)
– Governance roles (ADM)
2. Strategy Layer
– BaseStrategy interface
– Concrete strategy contracts that Vaults delegate to
3. Adapter Layer
– Generic Adapter interfaces
– Mapping of Adapter ➞ Integration modules
4. Integration Layer
– Protocol connectors (AaveAdapter, UniswapV3Pool, CurvePool, etc.)
– Oracles & price feeds (Chainlink, DIA)
5. Periphery
– Router / multicall helpers / emergency withdraw
6. Tokenomics
– Platform token contract
– Emission schedule / vesting
b. Off-chain components:
– Deployment scripts (script/deploy-*)
– CI/CD pipelines (GitHub workflows lint, test, slither)
– Audits & coverage reports

##### Architectural patterns and design principles
- Upgradable proxies (src/core/proxy)
- ERC-4626 vault pattern (deposit/withdraw, shares)
- Adapter pattern: decouple core logic from protocol specifics
- Strategy plug-in: vaults target arbitrary strategies at runtime
- Separation of concerns: core ≠ periphery ≠ integrations

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% EVM Boundary
    subgraph "EVM / Ethereum"
        direction TB

        %% Core Vault System
        subgraph "Core Vault System"
            direction TB
            VaultFactory["VaultFactory / ProxyAdmin"]:::core
            VaultBase["VaultBase (ERC-4626)"]:::core
            Governance["Governance Roles"]:::core
            CoreLibs["Core Libraries"]:::core
        end

        %% Strategy Layer
        subgraph "Strategy Layer"
            direction TB
            BaseStrategy["BaseStrategy Interface"]:::strategy
            StrategyLibs["Strategy Helper Libs"]:::strategy
            ConcreteStrategies["Concrete Strategies"]:::strategy
        end

        %% Adapter & Integration Layer
        subgraph "Adapter & Integration"
            direction TB
            GenericAdapter["Generic Adapter Interface"]:::adapterIntegration
            BalancerLib["Balancer Adapter Libs"]:::adapterIntegration
            BalancerV3Lib["Balancer V3 Adapter Libs"]:::adapterIntegration
            subgraph "Integrations"
                direction TB
                AaveInt["Aave Connector"]:::adapterIntegration
                UniswapV3Int["Uniswap V3 Connector"]:::adapterIntegration
                CurveInt["Curve Connector"]:::adapterIntegration
                ChainlinkInt["Chainlink Oracles"]:::adapterIntegration
                OtherInt["Other Protocol Connectors"]:::adapterIntegration
            end
        end

        %% Periphery
        subgraph "Periphery Utilities"
            direction TB
            Router["Router"]:::periphery
            Multicall["Multicall Helper"]:::periphery
            Emergency["Emergency Withdraw"]:::periphery
        end

        %% Tokenomics
        subgraph "Tokenomics"
            direction TB
            PlatformToken["Platform Token"]:::tokenomics
            EmissionVesting["Emission & Vesting"]:::tokenomics
        end

        %% On-chain Storage (Proxy Storage)
        ProxyStorage[(Proxy Storage)]:::core
    end

    %% External DeFi Protocols
    subgraph "External DeFi Protocols" 
        direction TB
        Aave["Aave"]:::external
        UniswapV3["Uniswap V3"]:::external
        Curve["Curve"]:::external
        Chainlink["Chainlink"]:::external
    end

    %% Off-chain Components
    subgraph "Off-chain & CI/CD"
        direction TB
        DeployCore["deploy-core script"]:::offchain
        DeployStrategy["deploy-strategy script"]:::offchain
        DeployAdapter["deploy-adapter script"]:::offchain
        DeployPeriphery["deploy-periphery script"]:::offchain
        DeployTokenomics["deploy-tokenomics script"]:::offchain
        DeployVault["deploy-vault script"]:::offchain
        UpgradeCore["upgrade-core script"]:::offchain
        LintCI[".github/workflows/lint.yml"]:::offchain
        SlitherCI[".github/workflows/slither.yml"]:::offchain
        TestCI[".github/workflows/test.yml"]:::offchain
        AuditReport["audits/initial-audit-stability-platform-v24.01.1-alpha.md"]:::offchain
        AuditScope["audits/scopes.md"]:::offchain
        ConfigFiles["foundry.toml / slither.config.json"]:::offchain
        Guides["guides/*.md, README.md"]:::offchain
    end

    %% Relationships
    Router -->|"deposit() / withdraw()"| VaultBase
    VaultBase -->|"delegateTo()"| BaseStrategy
    BaseStrategy -->|"execute()"| GenericAdapter
    GenericAdapter -->|"callAdapter()"| AaveInt
    GenericAdapter -->|"callAdapter()"| UniswapV3Int
    GenericAdapter -->|"callAdapter()"| CurveInt
    GenericAdapter -->|"callAdapter()"| ChainlinkInt
    AaveInt -->|"lend()/borrow()"| Aave
    UniswapV3Int -->|"swap()"| UniswapV3
    CurveInt -->|"addLiquidity()"| Curve
    ChainlinkInt -->|"getPrice()"| Chainlink
    VaultBase -->|"distributeRewards()"| PlatformToken
    PlatformToken -->|"mint()"| EmissionVesting
    ChainlinkInt -->|"priceFeed()"| VaultBase
    UpgradeCore --> VaultFactory
    VaultFactory --> ProxyStorage
    Governance --> VaultFactory

    %% Click Events
    click VaultFactory "https://github.com/stabilitydao/stability-contracts/tree/main/src/core/proxy"
    click VaultBase "https://github.com/stabilitydao/stability-contracts/tree/main/src/core/vaults"
    click Governance "https://github.com/stabilitydao/stability-contracts/tree/main/src/core/base"
    click CoreLibs "https://github.com/stabilitydao/stability-contracts/tree/main/src/core/libs"
    click BaseStrategy "https://github.com/stabilitydao/stability-contracts/tree/main/src/strategies/base"
    click StrategyLibs "https://github.com/stabilitydao/stability-contracts/tree/main/src/strategies/libs"
    click ConcreteStrategies "https://github.com/stabilitydao/stability-contracts/tree/main/src/strategies"
    click GenericAdapter "https://github.com/stabilitydao/stability-contracts/tree/main/src/adapters"
    click BalancerLib "https://github.com/stabilitydao/stability-contracts/tree/main/src/adapters/libs/balancer"
    click BalancerV3Lib "https://github.com/stabilitydao/stability-contracts/tree/main/src/adapters/libs/balancerv3"
    click AaveInt "https://github.com/stabilitydao/stability-contracts/tree/main/src/integrations/aave"
    click UniswapV3Int "https://github.com/stabilitydao/stability-contracts/tree/main/src/integrations/uniswapv3"
    click CurveInt "https://github.com/stabilitydao/stability-contracts/tree/main/src/integrations/curve"
    click ChainlinkInt "https://github.com/stabilitydao/stability-contracts/tree/main/src/integrations/chainlink"
    click Router "https://github.com/stabilitydao/stability-contracts/tree/main/src/periphery"
    click Multicall "https://github.com/stabilitydao/stability-contracts/tree/main/src/periphery"
    click Emergency "https://github.com/stabilitydao/stability-contracts/tree/main/src/periphery"
    click PlatformToken "https://github.com/stabilitydao/stability-contracts/tree/main/src/tokenomics"
    click EmissionVesting "https://github.com/stabilitydao/stability-contracts/tree/main/src/tokenomics"
    click DeployCore "https://github.com/stabilitydao/stability-contracts/tree/main/script/deploy-core"
    click DeployStrategy "https://github.com/stabilitydao/stability-contracts/tree/main/script/deploy-strategy"
    click DeployAdapter "https://github.com/stabilitydao/stability-contracts/tree/main/script/deploy-adapter"
    click DeployPeriphery "https://github.com/stabilitydao/stability-contracts/tree/main/script/deploy-periphery"
    click DeployTokenomics "https://github.com/stabilitydao/stability-contracts/tree/main/script/deploy-tokenomics"
    click DeployVault "https://github.com/stabilitydao/stability-contracts/tree/main/script/deploy-vault"
    click UpgradeCore "https://github.com/stabilitydao/stability-contracts/tree/main/script/upgrade-core"
    click LintCI "https://github.com/stabilitydao/stability-contracts/blob/main/.github/workflows/lint.yml"
    click SlitherCI "https://github.com/stabilitydao/stability-contracts/blob/main/.github/workflows/slither.yml"
    click TestCI "https://github.com/stabilitydao/stability-contracts/blob/main/.github/workflows/test.yml"
    click AuditReport "https://github.com/stabilitydao/stability-contracts/blob/main/audits/initial-audit-stability-platform-v24.01.1-alpha.md"
    click AuditScope "https://github.com/stabilitydao/stability-contracts/blob/main/audits/scopes.md"
    click ConfigFiles "https://github.com/stabilitydao/stability-contracts/blob/main/foundry.toml"
    click Guides "https://github.com/stabilitydao/stability-contracts/blob/main/guides/Core.md"

    %% Styles
    classDef core fill:#a0c4ff,stroke:#0366d6;
    classDef strategy fill:#b2f2bb,stroke:#2f8f2f;
    classDef adapterIntegration fill:#ffd8a8,stroke:#ff8f1c;
    classDef periphery fill:#dee2e6,stroke:#6c757d;
    classDef tokenomics fill:#fff3bf,stroke:#d4a017;
    classDef external fill:#caf0f8,stroke:#0077b6,stroke-dasharray: 5 5;
    classDef offchain fill:#fcbf49,stroke:#d97904;
```
