# metadev-xi/anychainswap architecture

> Architecture diagram of the GitHub repository metadev-xi/anychainswap, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/metadev-xi/anychainswap
- Repository: https://github.com/metadev-xi/anychainswap

## Overview

This repository implements a testnet token bridge across Ethereum, BSC, and several additional chains. A user approves tokens and submits a source-chain swap; the bridge emits an event, the long-running relayer observes it and submits a destination-chain transaction that mints tokens. Scripts also support direct multi-chain swaps and balance checks. The README documents burn/mint semantics; sampled relayer code shows event handling and destination dispatch. Other contract internals were not sampled, so the graph avoids asserting their detailed behavior.

Main entry points: [`contracts`](https://github.com/metadev-xi/anychainswap/tree/main/contracts) (Chain bridge contracts), [`scripts/bridge-api.js`](https://github.com/metadev-xi/anychainswap/blob/main/scripts/bridge-api.js) (Event relayer), [`scripts/approve.js`](https://github.com/metadev-xi/anychainswap/blob/main/scripts/approve.js) (Token approval), [`scripts/eth-bsc-transfer.js`](https://github.com/metadev-xi/anychainswap/blob/main/scripts/eth-bsc-transfer.js) (Swap submission)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_user_ops["User Operations"]
  node_approval["Token approval<br/>[approve.js]"]
  node_swap_cli["Swap submission"]
  node_multi_swap["Multi-chain swap<br/>[swap.js]"]
  node_balance_check["Balance lookup<br/>[balance.js]"]
end

subgraph group_bridge_contracts["Bridge Contracts"]
  node_chain_bridges["Chain bridge contracts"]
  node_bridge_base["Bridge base<br/>[BridgeBase.sol]"]
end

subgraph group_relayer["Relayer"]
  node_bridge_api["Event relayer<br/>[bridge-api.js]"]
  node_destination_dispatch["Destination dispatch<br/>[bridge-api.js]"]
end

subgraph group_token_assets["Token Assets"]
  node_chain_tokens["Chain token contracts"]
  node_token_base["Token base<br/>[TokenBase.sol]"]
end

node_user(("Bridge user"))
node_networks{{"Testnet chains"}}

node_user -->|"approves"| node_approval
node_approval -->|"sets allowance"| node_chain_tokens
node_user -->|"starts transfer"| node_swap_cli
node_swap_cli -->|"calls swap"| node_chain_bridges
node_user -->|"requests swap"| node_multi_swap
node_multi_swap -->|"calls swap"| node_chain_bridges
node_chain_bridges -->|"emits events"| node_bridge_api
node_bridge_api -->|"subscribes events"| node_chain_bridges
node_bridge_api -->|"dispatches event"| node_destination_dispatch
node_destination_dispatch -->|"submits destination tx"| node_chain_bridges
node_chain_bridges -->|"burns and mints"| node_chain_tokens
node_user -->|"checks balance"| node_balance_check
node_balance_check -->|"reads balance"| node_chain_tokens
node_networks -->|"hosts"| node_chain_bridges
node_networks -->|"hosts"| node_chain_tokens

click node_approval "https://github.com/metadev-xi/anychainswap/blob/main/scripts/approve.js"
click node_swap_cli "https://github.com/metadev-xi/anychainswap/blob/main/scripts/eth-bsc-transfer.js"
click node_multi_swap "https://github.com/metadev-xi/anychainswap/blob/main/scripts/swap.js"
click node_balance_check "https://github.com/metadev-xi/anychainswap/blob/main/scripts/balance.js"
click node_chain_bridges "https://github.com/metadev-xi/anychainswap/tree/main/contracts"
click node_bridge_base "https://github.com/metadev-xi/anychainswap/blob/main/contracts/BridgeBase.sol"
click node_bridge_api "https://github.com/metadev-xi/anychainswap/blob/main/scripts/bridge-api.js"
click node_destination_dispatch "https://github.com/metadev-xi/anychainswap/blob/main/scripts/bridge-api.js"
click node_chain_tokens "https://github.com/metadev-xi/anychainswap/tree/main/contracts"
click node_token_base "https://github.com/metadev-xi/anychainswap/blob/main/contracts/TokenBase.sol"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_approval,node_swap_cli,node_multi_swap,node_balance_check,node_user toneBlue
class node_chain_bridges,node_bridge_base toneAmber
class node_bridge_api,node_destination_dispatch toneMint
class node_chain_tokens,node_token_base toneRose
class node_networks toneIndigo
```

## Components

### User Operations

- [Token approval](https://github.com/metadev-xi/anychainswap/blob/main/scripts/approve.js): `scripts/approve.js`
- [Swap submission](https://github.com/metadev-xi/anychainswap/blob/main/scripts/eth-bsc-transfer.js): `scripts/eth-bsc-transfer.js`
- [Multi-chain swap](https://github.com/metadev-xi/anychainswap/blob/main/scripts/swap.js): `scripts/swap.js`
- [Balance lookup](https://github.com/metadev-xi/anychainswap/blob/main/scripts/balance.js): `scripts/balance.js`

### Bridge Contracts

- [Chain bridge contracts](https://github.com/metadev-xi/anychainswap/tree/main/contracts): `contracts`
- [Bridge base](https://github.com/metadev-xi/anychainswap/blob/main/contracts/BridgeBase.sol): `contracts/BridgeBase.sol`

### Relayer

- [Event relayer](https://github.com/metadev-xi/anychainswap/blob/main/scripts/bridge-api.js): `scripts/bridge-api.js`
- [Destination dispatch](https://github.com/metadev-xi/anychainswap/blob/main/scripts/bridge-api.js): `scripts/bridge-api.js`

### Token Assets

- [Chain token contracts](https://github.com/metadev-xi/anychainswap/tree/main/contracts): `contracts`
- [Token base](https://github.com/metadev-xi/anychainswap/blob/main/contracts/TokenBase.sol): `contracts/TokenBase.sol`

### Other components

- **Bridge user**
- **Testnet chains**

## Connections

- Bridge user → Token approval: approves (evidence: `README.md`)
- Token approval → Chain token contracts: sets allowance (evidence: `scripts/approve.js`)
- Bridge user → Swap submission: starts transfer (evidence: `README.md`)
- Swap submission → Chain bridge contracts: calls swap (evidence: `scripts/eth-bsc-transfer.js`)
- Bridge user → Multi-chain swap: requests swap (evidence: `README.md`)
- Multi-chain swap → Chain bridge contracts: calls swap (evidence: `scripts/swap.js`)
- Chain bridge contracts → Event relayer: emits events (evidence: `README.md`)
- Event relayer → Chain bridge contracts: subscribes events (evidence: `scripts/bridge-api.js`)
- Event relayer → Destination dispatch: dispatches event (evidence: `scripts/bridge-api.js`)
- Destination dispatch → Chain bridge contracts: submits destination tx (evidence: `scripts/bridge-api.js`)
- Chain bridge contracts → Chain token contracts: burns and mints (evidence: `README.md`)
- Bridge user → Balance lookup: checks balance (evidence: `README.md`)
- Balance lookup → Chain token contracts: reads balance (evidence: `scripts/balance.js`)
- Testnet chains → Chain bridge contracts: hosts (evidence: `README.md`)
- Testnet chains → Chain token contracts: hosts (evidence: `README.md`)
