# sarvagnakadiya/earnkit-contracts architecture

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

- Interactive diagram: https://gitdiagram.com/sarvagnakadiya/earnkit-contracts
- Repository: https://github.com/sarvagnakadiya/earnkit-contracts

## Overview

##### Project Type and Purpose
- This is a blockchain smart contract project that relies on Foundry. The primary purpose is to manage campaign contracts, deploy tokens with integrated campaigns, and handle protocol rewards, among others.
- The README clearly details multiple deployment scenarios (campaign deployment, earnkit & LpLocker, and campaign-linked token deployment) along with specific instructions for interacting with the deployed contracts on different networks like Sepolia and Mainnet.

##### File Structure and Key Components
- Smart Contracts and Source Code (src):
- The src directory includes modules like Interfaces, coinvise (with a submodule for protocol-rewards), and libraries.
- This is where the core business logic for the different contracts (campaign, earnkit, token management, rewards, etc.) is defined.
- ABI Files (abi):
- Contains JSON artifacts for various contracts (Campaigns, Earnkit, EarnkitToken, LpLocker, ProtocolRewards, RewardsSplitter) that reflect the compiled interface of each smart contract.
- Deployment Scripts (script):
- Contains shell scripts (deploy-campaign.sh, deploy-token-with-campaign.sh, deploy.sh) that handle the orchestration of contract deployments.
- Testing (test):
- Houses mocks and test files, which can detail interactions via Foundry tests to ensure contract functionality.
- Dependencies/External Libraries (lib):
- Includes third-party libraries like OpenZeppelin, Foundry’s forge-std, and v3-core. These are integral to secure and standard-compliant smart contract development.
- Foundry Setup (foundry.toml and other CLI instructions in the README):
- The build, test, formatting, and script execution commands in the README reiterate the reliance on Foundry’s toolset.

##### Main Components
a. Smart Contracts (Core Components):
- Campaign Contract
- Earnkit Contract & EarnkitToken
- ProtocolRewards Contract
- LpLocker Contract
- RewardsSplitter (if applicable)
b. Deployment and Scripting Layer:
- Deployment Scripts (deploy-campaign.sh, deploy.sh, deploy-token-with-campaign.sh)
- Environment Configuration (.env file and its role in setting addresses like CAMPAIGN_CONTRACT_ADDRESS)
c. Testing and Development Tools:
- Foundry Tools (Forge, Cast, Anvil, Chisel) as supporting components
d. External Dependencies:
- Libraries such as OpenZeppelin Contracts, forge-std, and v3-core (used for secure contract patterns and standards)

##### Relationships and Interactions
- The deployment scripts interact directly with the smart contract code in the src directory by orchestrating the deployment process.
- The ABI directory is the output of the compile process and is used for interacting with already-deployed contract instances.
- Testing utilizes both the smart contract source code and mocks from the test directory to simulate and verify expected behaviors.
- Environment variables (from .env) enable configuration of deployment parameters (for example, setting the campaign contract address).
- Foundry’s ecosystem underpins the entire workflow from development and testing (Forge, Anvil) to deployment and verification.

##### Architectural Patterns or Design Principles
- Modularization: The separation of contracts into individual responsibilities with distinct modules (campaign, earnkit, protocol rewards) is clearly visible.
- Separation of Concerns: The division between development (src, test), deployment (script), and external dependencies (lib) enhances maintainability.
- CI/CD Integration: The presence of the .github/workflows directory indicates automated testing (e.g., test.yml) and possible continuous integration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Smart Contracts Layer
    subgraph "Smart Contracts Layer"
        A("Campaign Contract"):::contract
        B("Earnkit & EarnkitToken"):::contract
        C("ProtocolRewards Contract"):::contract
        D("LpLocker Contract"):::contract
        E("RewardsSplitter Contract"):::contract
        F("Smart Contract Source Code"):::source
    end

    %% Deployment & Configuration Layer
    subgraph "Deployment & Configuration"
        G("Deployment Scripts"):::deploy
        H(".env Configuration"):::config
        I("Foundry Project Config"):::config
        J("ABI Artifacts"):::abi
        K("CI/CD Setup"):::ci
    end

    %% Testing & Development Tools Layer
    subgraph "Testing & Development Tools"
        L("Foundry Tools (Forge,Cast,Anvil,Chisel)"):::tools
        M("Testing Framework & Mocks"):::test
    end

    %% External Dependencies Layer
    subgraph "External Dependencies"
        N("External Libraries (OpenZeppelin,forge-std,v3-core)"):::external
    end

    %% Relationships and Data Flow
    %% Deployment Scripts deploy smart contracts
    G -->|"deploys"| A
    G -->|"deploys"| B
    G -->|"deploys"| C
    G -->|"deploys"| D
    G -->|"deploys"| E

    %% Smart Contract Source underpins the contracts
    F -->|"defines"| A
    F -->|"defines"| B
    F -->|"defines"| C
    F -->|"defines"| D
    F -->|"defines"| E

    %% ABI Artifacts are generated from Smart Contracts
    A -->|"compiled_to"| J
    B -->|"compiled_to"| J
    C -->|"compiled_to"| J
    D -->|"compiled_to"| J
    E -->|"compiled_to"| J

    %% Environment configuration feeds deployment
    H -->|"configures"| G

    %% Foundry Tools are used in deployment and testing
    L -->|"tests/deploys"| G
    L -->|"tests"| A
    L -->|"tests"| B
    L -->|"tests"| C
    L -->|"tests"| D
    L -->|"tests"| E

    %% Testing Framework uses Smart Contracts source and mocks
    M -->|"verifies"| F

    %% External Libraries are integrated with Smart Contract Source
    N -->|"imports"| F

    %% CI/CD automates Testing and Deployment
    K -->|"triggers"| M
    K -->|"triggers"| G

    %% Foundry Project Configuration supports all stages
    I -->|"configures"| F

    %% Click Events
    click F "https://github.com/sarvagnakadiya/earnkit-contracts/tree/main/src"
    click A "https://github.com/sarvagnakadiya/earnkit-contracts/blob/main/abi/Campaigns.json"
    click A "https://github.com/sarvagnakadiya/earnkit-contracts/tree/main/src"
    click B "https://github.com/sarvagnakadiya/earnkit-contracts/blob/main/abi/Earnkit.json"
    click B "https://github.com/sarvagnakadiya/earnkit-contracts/blob/main/abi/EarnkitToken.json"
    click C "https://github.com/sarvagnakadiya/earnkit-contracts/blob/main/abi/ProtocolRewards.json"
    click C "https://github.com/sarvagnakadiya/earnkit-contracts/tree/main/src/coinvise/protocol-rewards"
    click D "https://github.com/sarvagnakadiya/earnkit-contracts/blob/main/abi/LpLocker.json"
    click E "https://github.com/sarvagnakadiya/earnkit-contracts/blob/main/abi/RewardsSplitter.json"
    click G "https://github.com/sarvagnakadiya/earnkit-contracts/tree/main/script"
    click J "https://github.com/sarvagnakadiya/earnkit-contracts/tree/main/abi"
    click M "https://github.com/sarvagnakadiya/earnkit-contracts/tree/main/test"
    click N "https://github.com/sarvagnakadiya/earnkit-contracts/tree/main/lib"
    click H "https://github.com/sarvagnakadiya/earnkit-contracts/blob/main/.env.eg"
    click K "https://github.com/sarvagnakadiya/earnkit-contracts/tree/main/.github/workflows"
    click I "https://github.com/sarvagnakadiya/earnkit-contracts/blob/main/foundry.toml"

    %% Styles
    classDef contract fill:#e6ffe6,stroke:#00aa00,stroke-width:2px;
    classDef source fill:#e6f7ff,stroke:#0077cc,stroke-width:2px;
    classDef deploy fill:#fff0e6,stroke:#cc7a00,stroke-width:2px;
    classDef config fill:#fff5cc,stroke:#e6b800,stroke-width:2px;
    classDef abi fill:#e6f0ff,stroke:#3366cc,stroke-width:2px;
    classDef test fill:#fce6f9,stroke:#cc33aa,stroke-width:2px;
    classDef tools fill:#e6fcf9,stroke:#33ccaa,stroke-width:2px;
    classDef external fill:#ffe6e6,stroke:#aa0000,stroke-width:2px;
    classDef ci fill:#f9e6ff,stroke:#9933ff,stroke-width:2px;
```
