# dawsbot/drain architecture

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

- Interactive diagram: https://gitdiagram.com/dawsbot/drain
- Repository: https://github.com/dawsbot/drain

## Overview

Drain is a non-custodial EVM wallet migration and rescue app. The main flow connects a source wallet, discovers balances for the active chain, lets the user select assets and a destination, then submits ERC-20 and native-token transfers. README documents additional batch-send, ENS, pricing, and compromised-wallet guidance capabilities. Source excerpts show the main UI and transfer logic; route wiring is partly supported by the SOURCE INDEX, so unsampled implementation details are not expanded.

Main entry points: [`components/contract/SendTokens.tsx`](https://github.com/dawsbot/drain/blob/main/components/contract/SendTokens.tsx) (Send form), [`pages/index.tsx`](https://github.com/dawsbot/drain/blob/main/pages/index.tsx) (Home flow), [`components/contract/GetTokens.tsx`](https://github.com/dawsbot/drain/blob/main/components/contract/GetTokens.tsx) (Token review), [`pages/api/chain-info/[chainId]/[evmAddress].ts`](https://github.com/dawsbot/drain/blob/main/pages/api/chain-info/%5BchainId%5D/%5BevmAddress%5D.ts) (Chain balance API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App experience"]
  node_home["Home flow<br/>[index.tsx]"]
  node_rescue["Rescue guide"]
  node_gettokens["Token review<br/>[GetTokens.tsx]"]
end

subgraph group_discovery["Token discovery"]
  node_fetchclient["Token fetch client<br/>[fetch-tokens.ts]"]
  node_chainapi["Chain balance API<br/>[&#91;evmAddress&#93;.ts]"]
  node_moralis["Moralis client<br/>[moralis-client.ts]"]
  node_tokenlists["Token address lists<br/>[token-lists.ts]"]
end

subgraph group_state["Shared state"]
  node_globaltokens[("Token state")]
  node_checkedtokens[("Selection state")]
  node_destination[("Destination state")]
end

subgraph group_transfer["Transfer execution"]
  node_sendtokens["Send form<br/>[SendTokens.tsx]"]
  node_ensapi["ENS lookup API<br/>[&#91;name&#93;.ts]"]
end

node_user(("Wallet owner"))
node_moralisservice{{"Moralis API"}}
node_ensservice{{"ENS resolution"}}
node_wallet{{"Connected wallet"}}
node_chain{{"EVM network"}}

node_user -->|"opens"| node_home
node_home -->|"renders"| node_gettokens
node_home -->|"renders"| node_sendtokens
node_home -->|"links"| node_rescue
node_gettokens -->|"requests balances"| node_fetchclient
node_fetchclient -->|"fetches route"| node_chainapi
node_chainapi -->|"uses client"| node_moralis
node_chainapi -->|"uses lists"| node_tokenlists
node_moralis -->|"fetches balances"| node_moralisservice
node_gettokens -->|"updates"| node_globaltokens
node_gettokens -->|"updates selection"| node_checkedtokens
node_sendtokens -->|"reads balances"| node_globaltokens
node_sendtokens -->|"reads selection"| node_checkedtokens
node_sendtokens -->|"reads and updates"| node_destination
node_sendtokens -->|"requests resolution"| node_ensapi
node_ensapi -.->|"resolves name"| node_ensservice
node_sendtokens -->|"submits transfers"| node_wallet
node_sendtokens -->|"simulates and checks gas"| node_chain
node_user -->|"connects"| node_wallet

click node_home "https://github.com/dawsbot/drain/blob/main/pages/index.tsx"
click node_rescue "https://github.com/dawsbot/drain/blob/main/pages/compromised-wallet-rescue.tsx"
click node_gettokens "https://github.com/dawsbot/drain/blob/main/components/contract/GetTokens.tsx"
click node_sendtokens "https://github.com/dawsbot/drain/blob/main/components/contract/SendTokens.tsx"
click node_fetchclient "https://github.com/dawsbot/drain/blob/main/src/fetch-tokens.ts"
click node_chainapi "https://github.com/dawsbot/drain/blob/main/pages/api/chain-info/%5BchainId%5D/%5BevmAddress%5D.ts"
click node_moralis "https://github.com/dawsbot/drain/blob/main/src/moralis-client.ts"
click node_tokenlists "https://github.com/dawsbot/drain/blob/main/src/token-lists.ts"
click node_globaltokens "https://github.com/dawsbot/drain/blob/main/src/atoms/global-tokens-atom.ts"
click node_checkedtokens "https://github.com/dawsbot/drain/blob/main/src/atoms/checked-tokens-atom.ts"
click node_destination "https://github.com/dawsbot/drain/blob/main/src/atoms/destination-address-atom.ts"
click node_ensapi "https://github.com/dawsbot/drain/blob/main/pages/api/ens/%5Bname%5D.ts"

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_home,node_rescue,node_gettokens toneBlue
class node_fetchclient,node_chainapi,node_moralis,node_tokenlists toneAmber
class node_globaltokens,node_checkedtokens,node_destination,node_moralisservice toneMint
class node_sendtokens,node_ensapi toneRose
class node_user,node_ensservice,node_wallet,node_chain toneIndigo
```

## Components

### App experience

- [Home flow](https://github.com/dawsbot/drain/blob/main/pages/index.tsx): `pages/index.tsx`
- [Rescue guide](https://github.com/dawsbot/drain/blob/main/pages/compromised-wallet-rescue.tsx): `pages/compromised-wallet-rescue.tsx`
- [Token review](https://github.com/dawsbot/drain/blob/main/components/contract/GetTokens.tsx): `components/contract/GetTokens.tsx`

### Token discovery

- [Token fetch client](https://github.com/dawsbot/drain/blob/main/src/fetch-tokens.ts): `src/fetch-tokens.ts`
- [Chain balance API](https://github.com/dawsbot/drain/blob/main/pages/api/chain-info/%5BchainId%5D/%5BevmAddress%5D.ts): `pages/api/chain-info/[chainId]/[evmAddress].ts`
- [Moralis client](https://github.com/dawsbot/drain/blob/main/src/moralis-client.ts): `src/moralis-client.ts`
- [Token address lists](https://github.com/dawsbot/drain/blob/main/src/token-lists.ts): `src/token-lists.ts`

### Shared state

- [Token state](https://github.com/dawsbot/drain/blob/main/src/atoms/global-tokens-atom.ts): `src/atoms/global-tokens-atom.ts`
- [Selection state](https://github.com/dawsbot/drain/blob/main/src/atoms/checked-tokens-atom.ts): `src/atoms/checked-tokens-atom.ts`
- [Destination state](https://github.com/dawsbot/drain/blob/main/src/atoms/destination-address-atom.ts): `src/atoms/destination-address-atom.ts`

### Transfer execution

- [Send form](https://github.com/dawsbot/drain/blob/main/components/contract/SendTokens.tsx): `components/contract/SendTokens.tsx`
- [ENS lookup API](https://github.com/dawsbot/drain/blob/main/pages/api/ens/%5Bname%5D.ts): `pages/api/ens/[name].ts`

### Other components

- **Wallet owner**
- **Moralis API**
- **ENS resolution**
- **Connected wallet**
- **EVM network**

## Connections

- Wallet owner → Home flow: opens (evidence: `README.md`)
- Home flow → Token review: renders (evidence: `pages/index.tsx`)
- Home flow → Send form: renders (evidence: `pages/index.tsx`)
- Home flow → Rescue guide: links (evidence: `pages/index.tsx`)
- Token review → Token fetch client: requests balances (evidence: `components/contract/GetTokens.tsx`)
- Token fetch client → Chain balance API: fetches route (evidence: `src/fetch-tokens.ts`)
- Chain balance API → Moralis client: uses client (evidence: `pages/api/chain-info/[chainId]/[evmAddress].ts`)
- Chain balance API → Token address lists: uses lists (evidence: `pages/api/chain-info/[chainId]/[evmAddress].ts`)
- Moralis client → Moralis API: fetches balances (evidence: `src/moralis-client.ts`)
- Token review → Token state: updates (evidence: `components/contract/GetTokens.tsx`)
- Token review → Selection state: updates selection (evidence: `components/contract/GetTokens.tsx`)
- Send form → Token state: reads balances (evidence: `components/contract/SendTokens.tsx`)
- Send form → Selection state: reads selection (evidence: `components/contract/SendTokens.tsx`)
- Send form → Destination state: reads and updates (evidence: `components/contract/SendTokens.tsx`)
- Send form → ENS lookup API: requests resolution (evidence: `components/contract/SendTokens.tsx`)
- ENS lookup API → ENS resolution: resolves name
- Send form → Connected wallet: submits transfers (evidence: `components/contract/SendTokens.tsx`)
- Send form → EVM network: simulates and checks gas (evidence: `components/contract/SendTokens.tsx`)
- Wallet owner → Connected wallet: connects (evidence: `README.md`)
