# across-protocol/relayer architecture

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

- Interactive diagram: https://gitdiagram.com/across-protocol/relayer
- Repository: https://github.com/across-protocol/relayer

## Overview

##### Project Type and Purpose
- This project implements a secure, instant asset-transfer bridge across various EVM networks. It’s a cross-chain relayer system that executes UMIP-157 for interacting with audited smart contracts.
- The relayer works in tandem with other “bots” (dataworker, finalizer) and uses caching (via Redis) to efficiently query blockchain RPCs. The design supports different bridge adapters and integrates with external services (e.g., blockchain networks, Redis, and possibly other protocol services).

##### Key Components from the File Structure
a. Core Agents / Services:
- Relayer – Located under src/relayer: This appears to be the primary service managing cross-chain token transfers, event monitoring, and possibly routing transactions.
- Dataworker – Under src/dataworker: Responsible for gathering and pre-processing blockchain data (e.g., event queries, pool rebalances) and caching.
- Finalizer – Under src/finalizer: Likely handles the final steps needed to conclude transfers or reconcile states after the relayer has picked up events.
- Monitor – Under src/monitor: Provides health checks or performance monitoring to ensure the relayer’s proper functioning.

b. Bridge/Adapter Infrastructure:
- Adapters – Located in src/adapter (and subdirectories such as bridges and l2Bridges): These modules abstract interactions with different blockchain bridges and protocols (e.g., Arbitrum, OpStack, Polygon, ZK Sync, etc.).
- Clients – Found in src/clients: They wrap interactions with external APIs, smart contracts, and provide helper methods for cross-chain communication.

c. Common Utilities and Libraries:
- Common – Under src/common captures ABIs and shared constants, configuration, and addresses for interacting with smart contracts.
- Utils – In src/utils: A rich collection of helper modules (e.g., ContractUtils, TokenUtils, NetworkUtils) that support core operations across the system.

d. Deployment & Testing:
- Deployment scripts (deploy, deployments) ensure that changes are propagated to live networks.
- Tests and tasks directories show that the project includes comprehensive integration and unit tests for each major component.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Each agent (relayer, dataworker, finalizer, monitor) has its own module and utility subset, decoupling responsibilities.
- Adapter/Bridge Pattern: The adapters for various blockchain protocols allow for extendibility and abstract communication methods.
- Modular Design: The system’s encapsulation (clients, common/ABI, utils) enhances the interoperability of components and fosters better maintainability.
- Caching: Use of Redis (and presence of the Redis utility files) emphasizes read performance and reduces on-chain call overhead.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Components
    extBC["Blockchain Networks (EVM)"]:::external
    redis["Redis Server"]:::external

    %% Core Agents
    subgraph "Core Agents"
        relayer["Relayer Agent"]:::coreAgent
        dataworker["Dataworker Agent"]:::coreAgent
        finalizer["Finalizer Agent"]:::coreAgent
        monitor["Monitor Agent"]:::coreAgent
    end

    %% Adapter / Client Layer
    subgraph "Adapter / Client Layer"
        adapter["Bridge/Adapter Infrastructure"]:::adapterLayer
        clients["Clients"]:::adapterLayer
    end

    %% Utilities
    subgraph "Utilities"
        common["Common Utilities"]:::util
        utils["Helper Utils"]:::util
    end

    %% Data Flow and Relationships
    extBC -->|"SmartContractEvent"| relayer
    extBC -->|"BlockchainData"| dataworker
    dataworker -->|"CacheUpdate"| redis
    relayer -->|"InvokeAdapter"| adapter
    adapter -->|"BridgeTransfer"| extBC
    relayer -->|"TransferStatus"| finalizer
    relayer -->|"MonitoringInfo"| monitor
    clients -->|"APICalls"| extBC
    clients -->|"AdapterCoordination"| adapter
    common -->|"SharedConfig"| relayer
    common -->|"SharedConfig"| adapter
    common -->|"SharedConfig"| clients
    utils -->|"UtilityFunctions"| relayer
    utils -->|"UtilityFunctions"| dataworker
    utils -->|"UtilityFunctions"| finalizer

    %% Click Events
    click relayer "https://github.com/across-protocol/relayer/blob/master/src/relayer/Relayer.ts"
    click dataworker "https://github.com/across-protocol/relayer/blob/master/src/dataworker/Dataworker.ts"
    click finalizer "https://github.com/across-protocol/relayer/blob/master/src/finalizer/index.ts"
    click monitor "https://github.com/across-protocol/relayer/blob/master/src/monitor/Monitor.ts"
    click adapter "https://github.com/across-protocol/relayer/tree/master/src/adapter"
    click clients "https://github.com/across-protocol/relayer/tree/master/src/clients"
    click common "https://github.com/across-protocol/relayer/tree/master/src/common"
    click utils "https://github.com/across-protocol/relayer/tree/master/src/utils"
    click redis "https://github.com/across-protocol/relayer/blob/master/src/caching/RedisCache.ts"

    %% Styling
    classDef coreAgent fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef adapterLayer fill:#F9E79F,stroke:#9A7D0A,stroke-width:2px;
    classDef external fill:#FADBD8,stroke:#922B21,stroke-width:2px;
    classDef util fill:#D5F5E3,stroke:#196F3D,stroke-width:2px;
```
