# DirvenBank — Operator Runbook
## Exit Bot + Bridge + EscapeVault 24/7

**Versie:** 1.0 | **Datum:** July 10, 2026
**Classificatie:** OPERATOR — INTERNAL

---

## 1. SYSTEM OVERVIEW

```
EURC (stuck) → StuckLockContract → ESC_CREDIT
  → EscapeVaultV3 → dUSDC (minted)
    → DirvenUSDCBridge → Robinhood Wallet → flap.sh → USD
```

### Live Contracts (Base Chain 8453)

| Component | Address | Functie |
|-----------|---------|---------|
| EscapeCreditToken (ESC) | `0xA8a36bA95fe81b5f9746fBC02c888cE2Ed5E5eB2` | Credit token, 18 decimals |
| StuckLockContract | `0xf614E29e14907c94f00D4d6fc75Da1Ff54F2BC10` | EURC locker |
| EscapeVaultV3 | `0x27eFa4a0213828EBe1EB27698a4C145F537CBa0a` | ESC → dUSDC mint |
| dUSDC | `0x605D24837f95A1EA9258CC613B323552A92427c7` | Synthetic USDC, 6 decimals |
| DirvenUSDCBridge (dUSDC) | `0x4e2E5b3d4a4aAce20F866CB883E3d2CF661303b4` | Bridge → Robinhood |
| Robinhood Wallet | `0x510758429DB29f65CfAA2CeB33CaB533AaAEff99` | Destination (Chain 4663) |
| Treasury | `0x35CafF16D0834E67922ff2Da078bA9e3D6cE86eA` | Operator wallet |

### Externe Dependencies
| Service | Contact | Doel |
|---------|---------|------|
| Base RPC | https://base-rpc.publicnode.com | Chain communicatie |
| flap.sh relay | `0xF1aP0000000000000000000000000000ReLay` | On-chain relay contract |
| flap.sh API | https://flap.sh/relay | HTTP relay endpoint |
| Robinhood Wallet | `0x510758429DB29f65CfAA2CeB33CaB533AaAEff99` | Destination (Chain 4663) |

---

## 2. EXIT BOT RUNBOOK

### Locatie
**Script:** `scripts/usdc_exit_bot.py` (op Hetzner: `/var/www/dirvenbank.com/usdc_exit_bot.py`)

### Werking
```
24/7 Loop:
  1. Controleer EscapeVaultV3 op nieuwe deposits (totalDeposits)
  2. Check dUSDC balance op operator wallet
  3. Als balance > 0: log USDC beschikbaar voor exit
  4. Wacht op bridge() call van operator naar Robinhood
```

### Starten
```bash
cd /var/www/dirvenbank.com
python3 usdc_exit_bot.py
```

### Automatische Start (cron)
```crontab
# Elke minuut checken
* * * * * cd /var/www/dirvenbank.com && python3 usdc_exit_bot.py >> /var/log/usdc_exit.log 2>&1

# Elke 24 uur bridge batch
0 */24 * * * cd /var/www/dirvenbank.com && python3 -c "
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('https://base-rpc.publicnode.com'))
data = '0x5b0a2da0' + '0x' + '0'*63 + '1'  # bridge(uint256,bytes32)
# Let op: gebruik correcte selector
"
```

### Monitor
```bash
# Logs bekijken
tail -f /var/log/usdc_exit.log

# Status check
curl -s https://base-rpc.publicnode.com -X POST -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","method":"eth_call","params":[{"to":"0x4e2E5b3d4a4aAce20F866CB883E3d2CF661303b4","data":"0xefc81a8c"},"latest"],"id":1}'
```

---

## 3. BRIDGE OPERATIONS

### Check Bridge Status
```bash
# Total deposited
cast call --rpc-url https://base-rpc.publicnode.com \
  0x4e2E5b3d4a4aAce20F866CB883E3d2CF661303b4 "totalDeposited()(uint256)"

# Total withdrawn
cast call --rpc-url https://base-rpc.publicnode.com \
  0x4e2E5b3d4a4aAce20F866CB883E3d2CF661303b4 "totalWithdrawn()(uint256)"

# Operator address
cast call --rpc-url https://base-rpc.publicnode.com \
  0x4e2E5b3d4a4aAce20F866CB883E3d2CF661303b4 "operator()(address)"
```

### Bridge USDC naar Robinhood
```bash
# Alleen operator kan bridge() aanroepen
# bridge(uint256 amount, bytes32 targetChain)
# amount: hoeveelheid in 6 decimals (bv 100000000 = 100 dUSDC)
# targetChain: Robinhood Chain ID als bytes32

cast send --rpc-url https://base-rpc.publicnode.com \
  --private-key $OPERATOR_PK \
  0x4e2E5b3d4a4aAce20F866CB883E3d2CF661303b4 \
  "bridge(uint256,bytes32)" \
  100000000 \
  0x0000000000000000000000000000000000000000000000000000000000001237
```

### Set Operator
```bash
# Alleen huidige operator kan nieuwe operator aanwijzen
cast send --rpc-url https://base-rpc.publicnode.com \
  --private-key $OLD_OPERATOR_PK \
  0x4e2E5b3d4a4aAce20F866CB883E3d2CF661303b4 \
  "setOperator(address)" \
  0xNewOperatorAddress
```

---

## 4. ESCAPE VAULT OPERATIONS

### Check Vault Status
```bash
# Total deposits (ESC_CREDIT)
cast call --rpc-url https://base-rpc.publicnode.com \
  0x27eFa4a0213828EBe1EB27698a4C145F537CBa0a "totalDeposits()(uint256)"

# Total minted (dUSDC)
cast call --rpc-url https://base-rpc.publicnode.com \
  0x27eFa4a0213828EBe1EB27698a4C145F537CBa0a "totalMinted()(uint256)"

# User deposit
cast call --rpc-url https://base-rpc.publicnode.com \
  0x27eFa4a0213828EBe1EB27698a4C145F537CBa0a "deposits(address)(uint256)" \
  0xUserAddress
```

### Complete User Exit Flow
```bash
# 1. User approve ESC to vault
cast send --rpc-url https://base-rpc.publicnode.com \
  --private-key $USER_PK \
  0xA8a36bA95fe81b5f9746fBC02c888cE2Ed5E5eB2 \
  "approve(address,uint256)" \
  0x27eFa4a0213828EBe1EB27698a4C145F537CBa0a \
  100000000000000000000

# 2. Deposit ESC → receive dUSDC
cast send --rpc-url https://base-rpc.publicnode.com \
  --private-key $USER_PK \
  0x27eFa4a0213828EBe1EB27698a4C145F537CBa0a \
  "deposit(uint256)" \
  100000000000000000000

# 3. Check dUSDC received
cast call --rpc-url https://base-rpc.publicnode.com \
  0x605D24837f95A1EA9258CC613B323552A92427c7 \
  "balanceOf(address)(uint256)" \
  $USER

# 4. Approve bridge
cast send --rpc-url https://base-rpc.publicnode.com \
  --private-key $USER_PK \
  0x605D24837f95A1EA9258CC613B323552A92427c7 \
  "approve(address,uint256)" \
  0x4e2E5b3d4a4aAce20F866CB883E3d2CF661303b4 \
  100000000

# 5. Deposit into bridge
cast send --rpc-url https://base-rpc.publicnode.com \
  --private-key $USER_PK \
  0x4e2E5b3d4a4aAce20F866CB883E3d2CF661303b4 \
  "deposit(uint256,bytes32)" \
  100000000 \
  0x000000000000000000000000UserRobinhoodWallet
```

---

## 4B. DIRVENBANKCHAIN (Chain ID 2279) — LOCAL OPERATIONS

### Chain Info
| Parameter | Value |
|-----------|-------|
| Chain ID | 2279 |
| RPC | http://127.0.0.1:8545 |
| Consensus | Clique PoA, 5s block time |
| Validator | Treasury (single node) |
| Native | DEUR (1 EUR, 2.26B supply) |

### Contract Addresses
| Contract | Address |
|----------|---------|
| DEUR | `0x3D40969c0644eC85749D74fFa6db7F6CDc7Cf647` |
| PAXG | `0x942F66Fee4fFfc58dE4Efa77013432A1F2F3944B` |
| USDC | `0xF998b4006149FF45bd6880518B06b687a1892E91` |
| ChainAuth | `0xb1ce1feeC7156355ad0C9B86BD7890E08971AfAa` |
| Treasury | `0x35CafF16D0834E67922ff2Da078bA9e3D6cE86eA` |

### Start Chain
```bash
& "C:\bank\bin\geth.exe" --datadir "C:\bank\chain\data" --networkid 2279 --http --http.addr 127.0.0.1 --http.port 8545 --http.api "eth,net,web3,txpool,debug" --mine --miner.etherbase "0x35CafF16D0834E67922ff2Da078bA9e3D6cE86eA" --unlock "0x35CafF16D0834E67922ff2Da078bA9e3D6cE86eA" --password "C:\bank\chain\password.txt" --allow-insecure-unlock
```

### Check DEUR Balance
```bash
python -c "from web3 import Web3; w3=Web3(Web3.HTTPProvider('http://127.0.0.1:8545')); print(f'DEUR: {int(w3.eth.call({\"to\":\"0x3D40969c0644eC85749D74fFa6db7F6CDc7Cf647\",\"data\":\"0x70a08231\"+\"0\"*24+\"35caff16d0834e67922ff2da078ba9e3d6ce86ea\"}).hex(),16)/10**18:.2f}')"
```

### ChainAuth — Cross-Chain Auth
- ChainAuth verifies cross-chain messages via validator signatures
- 4 of N validator threshold (expandable set)
- Other chains can query ChainAuth to verify our chain's messages
- Treasury can add/remove validators
- Trusted chains can be registered for cross-chain communication

Open `C:\bank\wallet.html` in browser for live dashboard.

---

## 5. EMERGENCY PROCEDURES

### 5.1 Nonce Too Low
```bash
# Reset nonce door huidige nonce te checken
cast nonce --rpc-url https://base-rpc.publicnode.com $OPERATOR

# Gebruik correcte nonce in volgende tx
cast send --rpc-url https://base-rpc.publicnode.com \
  --private-key $PK --nonce $NONCE \
  $TO $DATA
```

### 5.2 Gas Te Laag
```bash
# Check current gas price
cast gas-price --rpc-url https://base-rpc.publicnode.com

# Gebruik priority fee indien nodig
cast send --rpc-url https://base-rpc.publicnode.com \
  --private-key $PK \
  --priority-gas-price 100000000 \
  $TO $DATA
```

### 5.3 Contract Stuck
```bash
# Check contract code bestaat
cast code --rpc-url https://base-rpc.publicnode.com $CONTRACT_ADDRESS

# Als 0x terugkomt: contract niet deployed of selfdestructed
# Alsnog: deploy opnieuw via scripts
```

### 5.4 RPC Failure
```bash
# Switch RPC
# primary:   https://base-rpc.publicnode.com
# fallback:  https://mainnet.base.org
# backup:    https://base.llamarpc.com

cast call --rpc-url https://mainnet.base.org \
  $CONTRACT $DATA
```

---

## 6. KEY CONTACTS & ADDRESSES

| Rol | Naam | Contact |
|-----|------|---------|
| Founder | Marinus Dirven | marinus@dirvenbank.com |
| Treasury PK | `0x61657434...d6d81` | In .env op Hetzner |
| Robinhood Seed | `resource marine...medal` | In robinhood_wallet.py |
| Plaid | Ashika Sagar | asagar@plaid.com |
| Plaid Risk | Jalon Jones | jjones@plaid.com |
| Stibbe Legal | Omar El Gachi | omar.elgachi@stibbe.com |

---

## 7. QUICK REFERENCE

```bash
# ===== ELKE DAG CHECKEN =====

# 1. Vault total deposits
cast call --rpc-url https://base-rpc.publicnode.com \
  0x27eFa4a0213828EBe1EB27698a4C145F537CBa0a \
  "totalDeposits()(uint256)"

# 2. Bridge total
cast call --rpc-url https://base-rpc.publicnode.com \
  0x4e2E5b3d4a4aAce20F866CB883E3d2CF661303b4 \
  "totalDeposited()(uint256)"

# 3. dUSDC in operator wallet
cast call --rpc-url https://base-rpc.publicnode.com \
  0x605D24837f95A1EA9258CC613B323552A92427c7 \
  "balanceOf(address)(uint256)" \
  0x35CafF16D0834E67922ff2Da078bA9e3D6cE86eA

# 4. ETH balance for gas
cast balance --rpc-url https://base-rpc.publicnode.com \
  0x35CafF16D0834E67922ff2Da078bA9e3D6cE86eA
```
