# Fix Bridge Errors Guide

**Date**: $(date)  
**Purpose**: Guide to fix all errors found in bridge dry run

---

## Errors Found in Dry Run

### ❌ Critical Error: Ethereum Mainnet Destination Not Configured

**Issue**: The WETH9 bridge contract does not have Ethereum Mainnet configured as a destination.

**Impact**: Bridge transactions to Ethereum Mainnet will fail.

**Solution**: Configure the destination using the fix script.

---

## Fix Script

### Script: `scripts/fix-bridge-errors.sh`

**Purpose**: Configures Ethereum Mainnet as a destination in the bridge contract.

**Usage**:
```bash
./scripts/fix-bridge-errors.sh [private_key] [weth9_mainnet_bridge_address]
```

**Example**:
```bash
./scripts/fix-bridge-errors.sh 0xYourPrivateKey 0xEthereumMainnetBridgeAddress
```

**What it does**:
1. Checks current bridge configuration
2. Configures WETH9 bridge for Ethereum Mainnet (if needed)
3. Verifies configuration was successful
4. Reports status

---

## Prerequisites

### Required Information

1. **Private Key**: With permissions to configure bridge (usually deployer/admin)
2. **Ethereum Mainnet Bridge Address**: The address of the CCIPWETH9Bridge contract on Ethereum Mainnet

### Finding Ethereum Mainnet Bridge Address

The Ethereum Mainnet bridge address should be:
- The deployed CCIPWETH9Bridge contract address on Ethereum Mainnet
- Should match the bridge contract pattern used on other chains
- Check deployment records or contract verification

**Note**: If you don't have the Ethereum Mainnet bridge address, you may need to:
1. Deploy the bridge contract on Ethereum Mainnet first
2. Or use an existing bridge address if one was already deployed

---

## Step-by-Step Fix

### Step 1: Check Current Configuration

```bash
# Check WETH9 bridge
cast call 0x89dd12025bfCD38A168455A44B400e913ED33BE2 \
  "destinations(uint64)" \
  5009297550715157269 \
  --rpc-url http://192.168.11.250:8545
```

If this returns `0x0000000000000000000000000000000000000000`, the destination is not configured.

### Step 2: Run Fix Script

```bash
./scripts/fix-bridge-errors.sh [private_key] [ethereum_mainnet_bridge_address]
```

### Step 3: Verify Fix

```bash
# Re-run dry run to verify
./scripts/dry-run-bridge-to-ethereum.sh 0.1 [address]
```

All checks should now pass.

---

## Alternative: Manual Configuration

If you prefer to configure manually:

```bash
# Get current nonce
NONCE=$(cast nonce [your_address] --rpc-url http://192.168.11.250:8545)

# Configure destination
cast send 0x89dd12025bfCD38A168455A44B400e913ED33BE2 \
  "addDestination(uint64,address)" \
  5009297550715157269 \
  [ethereum_mainnet_bridge_address] \
  --rpc-url http://192.168.11.250:8545 \
  --private-key [your_private_key] \
  --gas-price 5000000000 \
  --nonce $NONCE
```

---

## Verification

After running the fix script, verify the configuration:

```bash
# Check WETH9 bridge destination
cast call 0x89dd12025bfCD38A168455A44B400e913ED33BE2 \
  "destinations(uint64)" \
  5009297550715157269 \
  --rpc-url http://192.168.11.250:8545
```

Should return the Ethereum Mainnet bridge address (not zero address).

---

## Other Issues

### CCIP Fee Calculation Failed

**Issue**: Could not calculate CCIP fee in dry run.

**Possible Causes**:
1. Bridge contract may require LINK tokens for fees
2. Fee calculation function may have different signature
3. Network/RPC issues

**Solution**:
1. Check if LINK tokens are needed
2. Verify bridge contract fee mechanism
3. Check LINK balance if required

**Note**: This is a warning, not a critical error. The actual bridge transaction will show the required fee.

---

## After Fixing

Once the destination is configured:

1. **Re-run Dry Run**: Verify all checks pass
   ```bash
   ./scripts/dry-run-bridge-to-ethereum.sh 0.1 [address]
   ```

2. **Bridge Tokens**: Execute actual bridge
   ```bash
   ./scripts/wrap-and-bridge-to-ethereum.sh 0.1 [private_key]
   ```

---

## Summary

**Error**: Ethereum Mainnet destination not configured  
**Fix**: Run `./scripts/fix-bridge-errors.sh [private_key] [bridge_address]`  
**Verify**: Re-run dry run script  
**Status**: Ready to bridge after fix

---

**Last Updated**: $(date)

