# CCIP Integration Deployment Guide

## Complete Deployment Checklist

### Phase 1: Prerequisites

- [ ] Install Node.js 18+ and npm
- [ ] Install Hardhat: `npm install`
- [ ] Install watcher dependencies: `cd watcher && npm install`
- [ ] Set up PostgreSQL database
- [ ] Configure `.env` file with all required variables
- [ ] Fund deployer wallet with ETH (Mainnet) and native token (Chain-138)
- [ ] Obtain CCIP router addresses from Chainlink CCIP Directory

### Phase 2: Deploy CCIPLogger (Ethereum Mainnet)

1. **Verify Configuration**
   ```bash
   # Check .env has required variables
   grep -E "PRIVATE_KEY|ETHEREUM_MAINNET_RPC|CCIP_ETH_ROUTER|CHAIN138_SELECTOR" .env
   ```

2. **Deploy Contract**
   ```bash
   npm run deploy:logger:mainnet
   ```

3. **Verify on Etherscan**
   ```bash
   npx hardhat verify --network mainnet <CCIP_LOGGER_ADDRESS> <ROUTER> <SIGNER> <SELECTOR>
   ```

4. **Update .env**
   - Contract address will be automatically added
   - Verify `CCIP_LOGGER_ETH_ADDRESS` is set

### Phase 3: Deploy CCIPTxReporter (Chain-138)

1. **Verify Configuration**
   ```bash
   # Ensure CCIPLogger address is set
   grep CCIP_LOGGER_ETH_ADDRESS .env
   ```

2. **Deploy Contract**
   ```bash
   export CHAIN138_CCIP_REPORTER=0x...
   ```

3. **Update .env**
   - Persist `CHAIN138_CCIP_REPORTER`
   - Restore `archive/solidity/contracts/ccip-integration/CCIPTxReporter.sol` only if a fresh redeploy is required

4. **Fund Contract**
   ```bash
   # Send ETH to CCIPTxReporter for CCIP fees
   cast send <CCIP_REPORTER_ADDRESS> --value 1ether --private-key $PRIVATE_KEY --rpc-url $CHAIN138_RPC_URL
   ```

### Phase 4: Set Up Watcher/Relayer

1. **Initialize Database**
   ```bash
   # Database will be auto-initialized on first run
   ```

2. **Configure Watcher**
   ```bash
   # Update watcher/.env with:
   # - Database connection
   # - RPC endpoints
   # - Contract addresses
   # - Private keys (use secure key management)
   ```

3. **Build and Start**
   ```bash
   cd watcher
   npm run build
   npm start
   ```

   Or with Docker:
   ```bash
   cd watcher/docker
   docker-compose up -d
   ```

### Phase 5: Verification and Testing

1. **Test Single Transaction**
   ```bash
   # On Chain-138, send a test transaction
   # Watch logs for relay confirmation
   ```

2. **Monitor Events**
   ```bash
   # On Ethereum Mainnet, watch for RemoteTxLogged events
   cast logs --from-block latest "RemoteTxLogged(uint64,bytes32,address,address,uint256,bytes)" --rpc-url $ETHEREUM_MAINNET_RPC
   ```

3. **Check Metrics**
   - Prometheus: http://localhost:9090
   - Database: Query `outbox` table
   - Logs: Check watcher logs

## Environment Variables Reference

See `docs/ccip-integration/README.md` for complete environment variable reference.

## Troubleshooting

See main README for troubleshooting guide.
