# Bridge Configuration Guide

## Overview

After deploying CCIP WETH bridges on both Ethereum Mainnet and ChainID 138, you need to configure them to enable cross-chain transfers.

## Prerequisites

1. **Bridges deployed on both chains:**
   - Mainnet: CCIPWETH9Bridge and CCIPWETH10Bridge
   - ChainID 138: CCIPWETH9Bridge and CCIPWETH10Bridge

2. **Chain selectors:**
   - Ethereum Mainnet: `5009297550715157269`
   - ChainID 138: (to be determined from CCIP Router)

3. **Admin access** to bridge contracts

## Configuration Steps

### Step 1: Get Chain Selectors

```bash
# Get ChainID 138 selector from CCIP Router
cast call $CCIP_ROUTER "getChainSelector()" --rpc-url $RPC_URL

# Ethereum Mainnet selector is known: 5009297550715157269
```

### Step 2: Configure Mainnet Bridges

On Ethereum Mainnet, configure bridges to send to ChainID 138:

```bash
# Add ChainID 138 as destination for WETH9 bridge
cast send $MAINNET_WETH9_BRIDGE \
  "addDestination(uint64,address)" \
  $CHAIN138_SELECTOR \
  $CHAIN138_WETH9_BRIDGE \
  --rpc-url $MAINNET_RPC \
  --private-key $MAINNET_PRIVATE_KEY

# Add ChainID 138 as destination for WETH10 bridge
cast send $MAINNET_WETH10_BRIDGE \
  "addDestination(uint64,address)" \
  $CHAIN138_SELECTOR \
  $CHAIN138_WETH10_BRIDGE \
  --rpc-url $MAINNET_RPC \
  --private-key $MAINNET_PRIVATE_KEY
```

### Step 3: Configure ChainID 138 Bridges

On ChainID 138, configure bridges to send to Mainnet:

```bash
# Add Mainnet as destination for WETH9 bridge
cast send $CHAIN138_WETH9_BRIDGE \
  "addDestination(uint64,address)" \
  $MAINNET_SELECTOR \
  $MAINNET_WETH9_BRIDGE \
  --rpc-url $RPC_URL \
  --private-key $PRIVATE_KEY

# Add Mainnet as destination for WETH10 bridge
cast send $CHAIN138_WETH10_BRIDGE \
  "addDestination(uint64,address)" \
  $MAINNET_SELECTOR \
  $MAINNET_WETH10_BRIDGE \
  --rpc-url $RPC_URL \
  --private-key $PRIVATE_KEY
```

### Step 4: Verify Configuration

```bash
# Check destinations on Mainnet bridge
cast call $MAINNET_WETH9_BRIDGE \
  "destinations(uint64)" \
  $CHAIN138_SELECTOR \
  --rpc-url $MAINNET_RPC

# Check destinations on ChainID 138 bridge
cast call $CHAIN138_WETH9_BRIDGE \
  "destinations(uint64)" \
  $MAINNET_SELECTOR \
  --rpc-url $RPC_URL
```

## Gas Costs

Each `addDestination` call costs approximately:
- **Gas**: ~50,000 gas
- **Cost at 30 gwei**: ~0.0015 ETH (~$3.75)
- **Total for 4 calls**: ~0.006 ETH (~$15)

## Testing Cross-Chain Transfers

After configuration, test a cross-chain transfer:

```bash
# On Mainnet: Send WETH9 to ChainID 138
cast send $MAINNET_WETH9_BRIDGE \
  "sendCrossChain(uint64,address,uint256)" \
  $CHAIN138_SELECTOR \
  $RECIPIENT_ADDRESS \
  $AMOUNT \
  --rpc-url $MAINNET_RPC \
  --private-key $MAINNET_PRIVATE_KEY
```

## Troubleshooting

### Error: "destination not enabled"
- Ensure `addDestination` was called successfully
- Verify chain selector is correct
- Check bridge addresses are correct

### Error: "insufficient fee"
- Ensure LINK token balance is sufficient
- Check fee calculation: `calculateFee(chainSelector, amount)`

### Error: "transfer failed"
- Ensure WETH balance is sufficient
- Check WETH approval for bridge contract
