# ignite-market/smart-contracts architecture

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

- Interactive diagram: https://gitdiagram.com/ignite-market/smart-contracts
- Repository: https://github.com/ignite-market/smart-contracts

## Overview

##### Project type and purpose
- This is a suite of Ethereum smart contracts (no frontend) targeting prediction markets under the Ignite umbrella.
- Core deliverables:
- Conditional Tokens contract (manages positions, collateralization)
- FPMM Factory + FPMM market contract (creates and runs automated market‐maker pools)
- Ignite Oracle (connects to an external verification service—currently a dummy)
- Tooling: Hardhat as the build/test/deploy framework, Mocha/Chai for tests, ethers.js under the hood.

##### File structure
- Top‐level artifacts:
- hardhat.config.js, package.json, secrets.json (credentials)
- /contracts – Solidity code, broken into ConditionalTokens, FPMM, and Oracle modules
- /scripts – JS scripts that invoke Hardhat tasks to deploy each contract
- /test – Mocha test suites covering unit and full‐lifecycle scenarios
- Patterns & roles:
- Factory pattern (FPMMFactory)
- Separation of on‐chain modules (contracts/) and off‐chain orchestration (scripts/, tests/)
- Config files for multiple networks (hardhat.config.js)

##### Key README insights
- Indicates network “coston2” for deployment
- Deployment order and interdependencies:
1. Deploy ConditionalTokens
2. Deploy FPMMFactory (links to ConditionalTokens)
3. Deploy Oracle (needs addresses for ConditionalTokens and a verification service)
- Testing suites mirror these contracts and include helper utilities.

a. Main components to represent
- Developer/CI environment
- Hardhat framework (local node & tasks)
- Deployment & test scripts
- Ethereum network (coston2)
- On‐chain contracts:
- ConditionalTokens
- FPMMFactory → FPMM markets
- IgniteOracle → (External) Verification Service
- External verification service (DummyVerification or real API)
b. Relationships & interactions
- Scripts invoke Hardhat → network RPC → deploy or call contracts
- FPMMFactory uses ConditionalTokens library via linked address
- Oracle reads data from external service, writes results on‐chain
- Tests simulate all actor roles by calling scripts/Hardhat directly
c. Architectural patterns & design principles
- Factory pattern for market creation (FPMMFactory → new FPMM instances)
- Modular smart‐contract separation (token logic vs. market logic vs. oracle logic)
- Off‐chain orchestration (scripts/tests) decoupled from on‐chain code
d. Relevant technologies
- Solidity contracts under /contracts
- Hardhat tasks and config (hardhat.config.js)
- Deployment scripts (deploy-*.js under /scripts)
- Test suite (Mocha/Chai, utils in /test/helpers)
- Ethers.js for contract interaction

## Diagram (Mermaid)

```mermaid
graph TD
    %% Off-Chain Tools
    subgraph "Off-Chain Tools"
        Hardhat["Hardhat Framework"]:::offchain
        config["hardhat.config.js"]:::offchain
        pkg["package.json"]:::offchain
        secrets["secrets.sample.json"]:::offchain
    end

    %% Scripts & Tests
    subgraph "Scripts & Tests"
        deployCT["deploy-conditional-tokens.js"]:::offchain
        deployFactory["deploy-fpmm-factory.js"]:::offchain
        deployMarket["deploy-fpmm.js"]:::offchain
        deployOracle["deploy-oracle.js"]:::offchain
        deployDummy["deploy-dummy-verification.js"]:::offchain
        convertABI["convert-abi.js"]:::offchain
        testCT["ConditionalTokens.js"]:::offchain
        testFPAmounts["FPMM-amounts.js"]:::offchain
        testFPFull["FPMM-full-lifecycle.js"]:::offchain
        testFP["FPMM.js"]:::offchain
        testOracle["IgniteOracle.js"]:::offchain
        helpersID["id-helpers.js"]:::offchain
        helpersUtils["utils.js"]:::offchain
    end

    %% Network
    Ethereum["Ethereum Network (coston2)"]:::network

    %% On-Chain Contracts
    subgraph "On-Chain Contracts"
        CT["ConditionalTokens.sol"]:::onchain
        FPMMFactory["FPMMFactory & Factory Pattern"]:::onchain
        FPMM["FPMMMarket.sol"]:::onchain
        Oracle["IgniteOracle.sol"]:::onchain
        Interfaces["Oracle Interfaces"]:::onchain
    end

    %% External Service
    ExtVerification["External Verification Service"]:::external

    %% Relationships
    deployCT -->|"invoke deploy"| Hardhat
    deployFactory -->|"invoke deploy"| Hardhat
    deployMarket -->|"invoke deploy"| Hardhat
    deployOracle -->|"invoke deploy"| Hardhat
    deployDummy -->|"invoke deploy"| Hardhat
    convertABI -->|"utility"| Hardhat

    testCT -->|"run tests"| Hardhat
    testFPAmounts -->|"run tests"| Hardhat
    testFPFull -->|"run tests"| Hardhat
    testFP -->|"run tests"| Hardhat
    testOracle -->|"run tests"| Hardhat
    helpersID -->|"used by tests"| testCT
    helpersUtils -->|"used by tests"| testFPFull

    Hardhat -->|"RPC calls"| Ethereum

    Ethereum -->|"deploy"| CT
    Ethereum -->|"deploy"| FPMMFactory
    Ethereum -->|"deploy"| FPMM
    Ethereum -->|"deploy"| Oracle
    Ethereum -->|"deploy"| ExtVerification

    FPMMFactory -->|"factory uses"| CT
    FPMMFactory -->|"creates"| FPMM
    Oracle -->|"reads/writes"| Ethereum
    Oracle -->|"fetches data"| ExtVerification
    Interfaces -->|"ABI definitions for Oracle"| Oracle

    %% Click Events
    click CT "https://github.com/ignite-market/smart-contracts/tree/main/contracts/ConditionalTokens"
    click FPMMFactory "https://github.com/ignite-market/smart-contracts/tree/main/contracts/FPMM"
    click FPMM "https://github.com/ignite-market/smart-contracts/tree/main/contracts/FPMM"
    click Oracle "https://github.com/ignite-market/smart-contracts/tree/main/contracts/Oracle"
    click Interfaces "https://github.com/ignite-market/smart-contracts/tree/main/contracts/Oracle/interfaces"
    click config "https://github.com/ignite-market/smart-contracts/blob/main/hardhat.config.js"
    click pkg "https://github.com/ignite-market/smart-contracts/blob/main/package.json"
    click secrets "https://github.com/ignite-market/smart-contracts/blob/main/secrets.sample.json"
    click deployCT "https://github.com/ignite-market/smart-contracts/blob/main/scripts/deploy-conditional-tokens.js"
    click deployFactory "https://github.com/ignite-market/smart-contracts/blob/main/scripts/deploy-fpmm-factory.js"
    click deployMarket "https://github.com/ignite-market/smart-contracts/blob/main/scripts/deploy-fpmm.js"
    click deployOracle "https://github.com/ignite-market/smart-contracts/blob/main/scripts/deploy-oracle.js"
    click deployDummy "https://github.com/ignite-market/smart-contracts/blob/main/scripts/deploy-dummy-verification.js"
    click convertABI "https://github.com/ignite-market/smart-contracts/blob/main/scripts/convert-abi.js"
    click testCT "https://github.com/ignite-market/smart-contracts/blob/main/test/ConditionalTokens.js"
    click testFPAmounts "https://github.com/ignite-market/smart-contracts/blob/main/test/FPMM-amounts.js"
    click testFPFull "https://github.com/ignite-market/smart-contracts/blob/main/test/FPMM-full-lifecycle.js"
    click testFP "https://github.com/ignite-market/smart-contracts/blob/main/test/FPMM.js"
    click testOracle "https://github.com/ignite-market/smart-contracts/blob/main/test/IgniteOracle.js"
    click helpersID "https://github.com/ignite-market/smart-contracts/blob/main/test/helpers/id-helpers.js"
    click helpersUtils "https://github.com/ignite-market/smart-contracts/blob/main/test/helpers/utils.js"

    %% Styles
    classDef onchain fill:#cce5ff,stroke:#005cbf,color:#005cbf;
    classDef offchain fill:#d4edda,stroke:#155724,color:#155724;
    classDef network fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
    classDef external fill:#fff3cd,stroke:#856404,color:#856404;
```
