# onflow/defiactions architecture

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

- Interactive diagram: https://gitdiagram.com/onflow/defiactions
- Repository: https://github.com/onflow/defiactions

## Overview

##### Project type and purpose
- DeFiActions is an open-source, composable DeFi primitives framework built in Cadence for the Flow blockchain.
- It defines standard interfaces (Source, Sink, Swapper, PriceOracle, Flasher) and supplies plug-in “connector” implementations to adapt protocols (FungibleToken vaults, IncrementFi DEX, Band oracle, Flow-EVM, etc.).
- Goal: let developers assemble multi-step on-chain financial workflows (“money LEGOs”) without writing low-level protocol glue.

##### File structure
- Top‐level:
- cadence/ — all Cadence smart contracts, scripts, transactions, and tests
– contracts/interfaces/ — core DeFiActions interface definitions
– contracts/connectors/ — protocol‐specific connector implementations
– scripts/ & transactions/ — client entry points for on‐chain calls
– tests/ — mock contracts, unit tests, and transaction tests
- solidity/ — auxiliary EVM connector adapters and supporting libraries (Forge, OpenZeppelin, flow-sol-utils)
- config & CI: flow.json, Makefile, foundry.toml, GitHub workflows
- Patterns:
- Interface→Implementation layering
- Modular connectors grouped by protocol
- Transaction and script folders mirror connector categories for example usage
- Test harness uses Flow emulator accounts, mock oracles, and CI pipelines

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Cadence Contracts Layer
    subgraph "Cadence Contracts"
        subgraph "Interfaces"
            CoreInterfaces["DeFiActions Core Interfaces"]:::interface
        end
        subgraph "Connectors"
            FTStack["FungibleTokenStack Connector"]:::connector
            SwapStack["SwapStack Connector"]:::connector
            subgraph "IncrementFi Connectors"
                IncCore["IncrementFi Connectors Core"]:::connector
                IncPool["IncrementFi Pool Liquidity Connector"]:::connector
                IncStaking["IncrementFi Staking Connector"]:::connector
            end
            subgraph "Band Oracle Connectors"
                BandOracles["Band Oracle Connectors"]:::connector
            end
            subgraph "EVM Connectors"
                EVMConn["EVM Connectors"]:::connector
            end
        end
    end

    %% On-chain Entry Points
    subgraph "Cadence Entry Points"
        subgraph "Scripts"
            Scripts["Cadence Scripts\n(on-chain queries)"]:::script
        end
        subgraph "Transactions"
            TXs["Cadence Transactions\n(state-changing)"]:::transaction
        end
    end

    %% Off-chain Tooling
    subgraph "Off-chain Tooling"
        CLI["Flow CLI / Emulator"]:::tool
        Foundry["Solidity / Foundry Toolchain"]:::tool
    end

    %% External Services
    subgraph "External Services"
        FlowBC["Flow Blockchain\n(emulator, testnet, mainnet)"]:::external
        BandProt["Band Protocol Oracle"]:::external
        EVMDEX["EVM DEX (Flow EVM)"]:::external
    end

    %% CI/CD
    subgraph "CI/CD"
        CI["GitHub Actions Workflows"]:::ci
    end

    %% Relationships
    Scripts -->|"invoke connectors"| FTStack
    Scripts -->|"invoke connectors"| SwapStack
    Scripts -->|"invoke connectors"| IncCore
    Scripts -->|"invoke connectors"| BandOracles
    Scripts -->|"invoke connectors"| EVMConn

    TXs -->|"invoke connectors"| FTStack
    TXs -->|"invoke connectors"| SwapStack
    TXs -->|"invoke connectors"| IncPool
    TXs -->|"invoke connectors"| IncStaking
    TXs -->|"invoke connectors"| BandOracles
    TXs -->|"invoke connectors"| EVMConn

    FTStack -->|"implements"| CoreInterfaces
    SwapStack -->|"implements"| CoreInterfaces
    IncCore -->|"implements"| CoreInterfaces
    IncPool -->|"implements"| CoreInterfaces
    IncStaking -->|"implements"| CoreInterfaces
    BandOracles -->|"implements"| CoreInterfaces
    EVMConn -->|"implements"| CoreInterfaces

    %% Connectors to External
    FTStack -->|"interacts via vaults"| FlowBC
    SwapStack -->|"interacts via DEX"| FlowBC
    IncCore -->|"interacts via pools"| FlowBC
    BandOracles -->|"fetches data from"| BandProt
    EVMConn -->|"routes to"| EVMDEX

    %% Off-chain tooling interactions
    CLI -->|"deploy & test contracts"| FlowBC
    Foundry -->|"build & test EVM adapters"| EVMDEX
    CI -->|"runs via"| CLI
    CI -->|"runs via"| Foundry

    %% Attach tests (Flow emulator)
    CI -->|"runs emulator tests"| FlowBC

    %% Click Events
    click CoreInterfaces "https://github.com/onflow/defiactions/blob/main/cadence/contracts/interfaces/DeFiActions.cdc"
    click FTStack "https://github.com/onflow/defiactions/blob/main/cadence/contracts/connectors/FungibleTokenStack.cdc"
    click SwapStack "https://github.com/onflow/defiactions/blob/main/cadence/contracts/connectors/SwapStack.cdc"
    click IncCore "https://github.com/onflow/defiactions/blob/main/cadence/contracts/connectors/increment-fi/IncrementFiConnectors.cdc"
    click IncPool "https://github.com/onflow/defiactions/blob/main/cadence/contracts/connectors/increment-fi/IncrementFiPoolLiquidityConnectors.cdc"
    click IncStaking "https://github.com/onflow/defiactions/blob/main/cadence/contracts/connectors/increment-fi/IncrementFiStakingConnectors.cdc"
    click BandOracles "https://github.com/onflow/defiactions/blob/main/cadence/contracts/connectors/band-oracle/BandOracleConnectors.cdc"
    click EVMConn "https://github.com/onflow/defiactions/blob/main/cadence/contracts/connectors/evm/DeFiActionsEVMConnectors.cdc"
    click Scripts "https://github.com/onflow/defiactions/tree/main/cadence/scripts/"
    click AutoBalScripts "https://github.com/onflow/defiactions/tree/main/cadence/scripts/auto-balance-adapter/"
    click EVMScripts "https://github.com/onflow/defiactions/tree/main/cadence/scripts/evm/"
    click IncFiScripts "https://github.com/onflow/defiactions/tree/main/cadence/scripts/increment-fi-adapters/"
    click TokenScripts "https://github.com/onflow/defiactions/tree/main/cadence/scripts/tokens/"
    click TXs "https://github.com/onflow/defiactions/tree/main/cadence/transactions/"
    click AutoBalTX "https://github.com/onflow/defiactions/tree/main/cadence/transactions/auto-balance-adapter/"
    click BandTX "https://github.com/onflow/defiactions/tree/main/cadence/transactions/band-oracle-connector/"
    click EVMTX "https://github.com/onflow/defiactions/tree/main/cadence/transactions/evm/"
    click FTXX "https://github.com/onflow/defiactions/tree/main/cadence/transactions/fungible-token-stack/"
    click IncFiTX "https://github.com/onflow/defiactions/tree/main/cadence/transactions/increment-fi/"
    click CLI "https://github.com/onflow/defiactions/blob/main/flow.json"
    click Foundry "https://github.com/onflow/defiactions/blob/main/foundry.toml"
    click Foundry "https://github.com/onflow/defiactions/tree/main/solidity/"
    click CI "https://github.com/onflow/defiactions/blob/main/ .github/workflows/cadence_tests.yml"
    click CI "https://github.com/onflow/defiactions/blob/main/ .github/workflows/test.yml"

    %% Styles
    classDef interface fill:#D0E8FF,stroke:#0969DA,color:#0366D6,stroke-width:2px
    classDef connector fill:#E6FFEC,stroke:#28A745,color:#22863A,stroke-width:2px
    classDef script fill:#FFF5B1,stroke:#C47F00,color:#735C0F,stroke-width:2px
    classDef transaction fill:#FFEBE9,stroke:#D73A49,color:#86181D,stroke-width:2px
    classDef tool fill:#FFF5C4,stroke:#DBAB09,color:#735C0F,stroke-width:2px,stroke-dasharray: 5 5
    classDef external fill:#F0F6FC,stroke:#1B1F23,color:#57606A,stroke-width:2px,stroke-dasharray: 2 2
    classDef ci fill:#F5F0FF,stroke:#6F42C1,color:#5A32A3,stroke-width:2px,stroke-dasharray: 5 5
```
