# vana-com/vana-dlp-smart-contracts architecture

> Architecture diagram of the GitHub repository vana-com/vana-dlp-smart-contracts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vana-com/vana-dlp-smart-contracts
- Repository: https://github.com/vana-com/vana-dlp-smart-contracts

## Overview

##### Main Components
- Data Liquidity Pool (DLP) Contract – the upgradeable pool that handles file uploads, reward calculations, and integration with external contracts.
- DAT (Data Access Token) Contract – an ERC20 token contract with additional governance features (ERC20Permit and ERC20Votes).
- Dependency Contracts – these include:
- Data Registry Contract, which catalogs files, manages file metadata, and controls access.
- TEE Pool Contract, which coordinates file validation via trusted execution environments.
- Root Network Contract, which handles the registration of DLPs, staking, and reward distribution via an epoch-based system.
- Deployment & Testing Scripts – shown by deploy directory (deploy.ts, dlp-deploy.ts, token-deploy.ts) and test directory which verifies these contracts.
- Utility Scripts – assisting with time manipulation and helper functionalities used by tests or deployment.

##### Relationships and Interactions
- The DLP Contract is central and integrates directly with the Data Registry and TEE Pool contracts, as well as registering itself with the Root Network for rewards.
- The DAT contract is the token associated with the DLP, managing minting, governance, and additional extension functionalities.
- The data flow, as described in the README, goes from a data contributor (e.g., “Bob”):
- Bob uploads his file to the Data Registry.
- The file is then associated with an attestation via the TEE Pool.
- Once a valid proof is established, Bob interacts with the DLP contract to get rewarded.
- There is also an administrative flow for registering, updating, and deregistering a DLP with the Root Network contract.
- The deployment scripts manage the deployment order and configuration settings as required (using environment variables).

##### Architectural Patterns and Design Principles
- Use of the Universal Upgradeable Proxy Standard (UUPS) for the DLP contract ensures upgradeability while preserving state.
- Modular separation: Each dependency (Data Registry, TEE Pool, Root Network) is handled in separate contracts and directories, enabling independent testing and updates.
- Standardization: The DAT token leverages widely adopted patterns from OpenZeppelin (ERC20, ERC20Votes) ensuring reliability and security.
- Clear boundaries exist between on-chain smart contract logic and off-chain interactions (e.g., deployment scripts, environment setups, and optional UI interactions).

##### Incorporate Technologies and Frameworks
- Hardhat – for deployment and testing.
- Typescript – evident from tsconfig.json and script files.
- OpenZeppelin libraries – for upgradeable contracts, ERC20, Pausable, etc.
- Gelato integration for gasless transactions (via trusted forwarder) and deployment support.

##### Elements
- From Data Contributor to Data Registry (file submission).
- From Data Registry to TEE Pool (attestation/proof validation).
- From TEE Pool back to Data Registry (storing attestations).
- Then linking Data Registry and DLP (to trigger reward logic).
- From DLP to Root Network (for registration and staking-based reward distribution).

##### Overall Approach
- Drill down to show sub-components within the DLP smart contract (initialization, file management, contributor details) to capture important methods (like initialize, pause, update functions, and reward requests).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Actor
    DC("Data Contributor"):::external

    %% Smart Contracts Subgraph
    subgraph "Smart Contracts"
        DLP("Data Liquidity Pool Contract"):::contract
        DAT("DAT Token Contract"):::contract
        DR("Data Registry Contract"):::contract
        TEE("TEE Pool Contract"):::contract
        RN("Root Network Contract"):::contract
    end

    %% Off-chain Scripts Subgraph
    subgraph "Off-chain Scripts"
        %% Deployment Scripts
        subgraph "Deployment Scripts"
            DS1("deploy/deploy.ts"):::script
            DS2("deploy/dlp-deploy.ts"):::script
            DS3("deploy/token-deploy.ts"):::script
        end
        %% Testing Scripts
        subgraph "Testing Scripts"
            TS1("test/dlp.ts"):::script
            TS2("test/token.ts"):::script
            TS3("test/dependencies"):::script
        end
        %% Utility Scripts
        subgraph "Utility Scripts"
            US1("utils/helpers.ts"):::script
            US2("utils/timeAndBlockManipulation.ts"):::script
        end
    end

    %% Interactions between Data Contributor and Smart Contracts
    DC -->|"uploads"| DR
    DR -->|"attestation_request"| TEE
    TEE -->|"stores_attestation"| DR
    DR -->|"triggers_reward"| DLP
    DC -->|"claims_reward"| DLP
    DLP -->|"registers_and_stakes"| RN
    DLP ---|"associates"| DAT

    %% Deployment Scripts deploying Smart Contracts
    DS1 -->|"deploys"| DLP
    DS1 -->|"deploys"| DAT
    DS1 -->|"deploys"| DR
    DS1 -->|"deploys"| TEE
    DS1 -->|"deploys"| RN

    DS2 -->|"deploys"| DLP
    DS3 -->|"deploys"| DAT

    %% Utility Scripts support Deployment and Testing
    US1 -->|"supports"| DS1
    US2 -->|"supports"| DS1
    US1 -->|"supports"| TS1
    US2 -->|"supports"| TS1

    %% Styling for components
    classDef contract fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef script fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef external fill:#FFB6C1,stroke:#000,stroke-width:2px;

    %% Click Events
    click DLP "https://github.com/vana-com/vana-dlp-smart-contracts/tree/main/contracts/dlp"
    click DAT "https://github.com/vana-com/vana-dlp-smart-contracts/tree/main/contracts/token"
    click DR "https://github.com/vana-com/vana-dlp-smart-contracts/tree/main/contracts/dependencies/dataRegistry"
    click TEE "https://github.com/vana-com/vana-dlp-smart-contracts/tree/main/contracts/dependencies/teePool"
    click RN "https://github.com/vana-com/vana-dlp-smart-contracts/tree/main/contracts/dependencies/root"
    click DS1 "https://github.com/vana-com/vana-dlp-smart-contracts/blob/main/deploy/deploy.ts"
    click DS2 "https://github.com/vana-com/vana-dlp-smart-contracts/blob/main/deploy/dlp-deploy.ts"
    click DS3 "https://github.com/vana-com/vana-dlp-smart-contracts/blob/main/deploy/token-deploy.ts"
    click TS1 "https://github.com/vana-com/vana-dlp-smart-contracts/blob/main/test/dlp.ts"
    click TS2 "https://github.com/vana-com/vana-dlp-smart-contracts/blob/main/test/token.ts"
    click TS3 "https://github.com/vana-com/vana-dlp-smart-contracts/tree/main/test/dependencies"
    click US1 "https://github.com/vana-com/vana-dlp-smart-contracts/blob/main/utils/helpers.ts"
    click US2 "https://github.com/vana-com/vana-dlp-smart-contracts/blob/main/utils/timeAndBlockManipulation.ts"
```
