# Deployment Instructions

Step-by-step instructions for deploying the trustless bridge system.

## 🚀 Quick Start

### Option 1: Interactive Deployment (Recommended)

```bash
cd /home/intlc/projects/proxmox/smom-dbis-138
./scripts/deployment/start-deployment.sh
```

This will:
- Verify all prerequisites
- Check environment configuration
- Guide you through each deployment phase
- Prompt for confirmation before each step

### Option 2: Manual Phase-by-Phase

Run each phase individually:

```bash
# Phase 1: Verify environment
./scripts/deployment/phase1-env-setup.sh

# Phase 2: Deploy core contracts
./scripts/deployment/phase2-deploy-core.sh

# Phase 3: Deploy enhanced router
./scripts/deployment/phase3-deploy-router.sh

# Phase 4: Deploy integration contracts
./scripts/deployment/phase4-deploy-integration.sh

# Phase 5: Initialize system
./scripts/deployment/phase5-initialize.sh

# Phase 6: Provide liquidity
./scripts/deployment/phase6-provide-liquidity.sh

# Phase 7: Configure access control
./scripts/deployment/phase7-configure.sh

# Phase 8: Deploy backend services
./scripts/deployment/phase8-deploy-services.sh

# Phase 9: Deploy frontend
./scripts/deployment/phase9-deploy-frontend.sh

# Phase 10: Verify deployment
./scripts/deployment/phase10-verify.sh
```

## ⚠️ Important Pre-Deployment Checklist

Before starting deployment:

- [ ] **Foundry Installed**: `forge --version` should work
- [ ] **Environment Variables**: All required variables set in `.env`
- [ ] **ETH Balance**: Deployer has 5-10 ETH for gas fees
- [ ] **RPC Access**: RPC endpoints are accessible
- [ ] **Etherscan API**: API key is valid
- [ ] **RESERVE_SYSTEM**: Address set (if deploying integration contracts)
- [ ] **Backup**: `.env` file is backed up

## 📋 Phase 2: Deploy Core Contracts

This is the first actual deployment phase. It will:

1. **Deploy on ChainID 138:**
   - Lockbox contract

2. **Deploy on Ethereum Mainnet:**
   - BondManager
   - ChallengeManager
   - LiquidityPoolETH
   - InboxETH
   - SwapRouter (basic)
   - BridgeSwapCoordinator

### What to Expect

1. Script will compile contracts
2. Deploy contracts sequentially
3. Verify contracts on Etherscan (if `--verify` flag used)
4. Output contract addresses
5. **IMPORTANT**: Save all addresses to `.env` file

### After Phase 2

You must:
1. Copy all deployed contract addresses
2. Add them to `.env` file:
   ```bash
   BOND_MANAGER=0x...
   CHALLENGE_MANAGER=0x...
   LIQUIDITY_POOL=0x...
   INBOX_ETH=0x...
   SWAP_ROUTER=0x...
   BRIDGE_SWAP_COORDINATOR=0x...
   LOCKBOX_138=0x...
   ```

## 🔍 Monitoring Deployment

### During Deployment

Watch for:
- Compilation errors
- Deployment transaction hashes
- Contract addresses
- Verification status

### After Each Phase

1. **Verify contracts deployed:**
   ```bash
   cast code <CONTRACT_ADDRESS> --rpc-url $ETHEREUM_MAINNET_RPC
   ```

2. **Check on Etherscan:**
   - Visit: https://etherscan.io/address/<CONTRACT_ADDRESS>
   - Verify contract code is verified

3. **Update .env:**
   - Add all new contract addresses
   - Verify with: `./scripts/deployment/check-env-requirements.sh`

## 🛠️ Troubleshooting

### Deployment Fails

1. **Check gas prices:**
   ```bash
   cast gas-price --rpc-url $ETHEREUM_MAINNET_RPC
   ```

2. **Check balance:**
   ```bash
   cast balance <DEPLOYER_ADDRESS> --rpc-url $ETHEREUM_MAINNET_RPC
   ```

3. **Check RPC connectivity:**
   ```bash
   cast block-number --rpc-url $ETHEREUM_MAINNET_RPC
   ```

### Contract Verification Fails

1. Check Etherscan API key is valid
2. Verify constructor arguments match
3. Try manual verification:
   ```bash
   forge verify-contract <ADDRESS> <CONTRACT> \
     --chain-id 1 \
     --etherscan-api-key $ETHERSCAN_API_KEY
   ```

### RPC Connection Issues

1. Check RPC endpoint URL
2. Verify network connectivity
3. Check for IP whitelisting requirements (Infura)
4. Try alternative RPC endpoint

## 📊 Deployment Progress Tracking

Use this to track your progress:

```bash
# Check current status
./scripts/deployment/check-env-requirements.sh

# Review current deployment docs
cat docs/bridge/trustless/README.md
```

## 🎯 Next Steps After Deployment

Once all phases complete:

1. **Verify everything:**
   ```bash
   ./scripts/deployment/phase10-verify.sh
   ```

2. **Test end-to-end:**
   - Deposit on ChainID 138
   - Submit claim on Ethereum
   - Verify swap execution

3. **Set up monitoring:**
   - Configure dashboards
   - Set up alerts
   - Monitor bridge activity

4. **Begin operations:**
   - Start accepting deposits
   - Monitor liquidity
   - Manage reserves

## 📞 Support

If you encounter issues:

1. Check logs and error messages
2. Review documentation:
   - `DEPLOYMENT_GUIDE.md`
   - `OPERATIONS_GUIDE.md`
   - `TROUBLESHOOTING.md`
3. Verify environment: `check-env-requirements.sh`
4. Check RPC connectivity: `verify-all-rpcs.sh`

---

**Ready to deploy?** Run: `./scripts/deployment/start-deployment.sh`
