# Complete Execution Guide - All Next Actions

**Date**: 2025-12-24  
**Status**: Ready for Complete Execution

---

## Overview

This guide provides complete instructions for executing all next actions: deployment, integration, and testing.

---

## Prerequisites

### 1. Environment Setup

```bash
cd /home/intlc/projects/proxmox/smom-dbis-138

# Set required environment variables
export PRIVATE_KEY=<your_deployer_private_key>
export RPC_URL=http://192.168.11.250:8545

# Optional: Set admin addresses (defaults to deployer)
export COMPLIANCE_ADMIN=<admin_address>
export TOKEN_REGISTRY_OWNER=<owner_address>
export FEE_COLLECTOR_OWNER=<owner_address>
```

### 2. Verify Prerequisites

```bash
# Check RPC connection
cast block-number --rpc-url $RPC_URL

# Check deployer balance
cast balance $(cast wallet address $PRIVATE_KEY) --rpc-url $RPC_URL

# Verify contracts compile
forge build --via-ir contracts/compliance/*.sol contracts/tokens/*.sol contracts/utils/*.sol
```

---

## Option 1: Automated Complete Deployment and Integration (Recommended)

### Single Command Execution

```bash
cd /home/intlc/projects/proxmox/smom-dbis-138

# Set PRIVATE_KEY
export PRIVATE_KEY=<your_private_key>

# Run complete deployment and integration
./scripts/deploy-and-integrate-all.sh
```

**This script will**:
1. ✅ Verify prerequisites (RPC, balance)
2. ✅ Deploy all 5 contracts
3. ✅ Register contracts in ComplianceRegistry
4. ✅ Register tokens in TokenRegistry
5. ✅ Verify all deployments
6. ✅ Save all addresses to .env

---

## Option 2: Step-by-Step Manual Execution

### Step 1: Deploy ComplianceRegistry

```bash
forge script script/DeployComplianceRegistry.s.sol:DeployComplianceRegistry \
  --rpc-url $RPC_URL \
  --broadcast \
  --legacy \
  --gas-price 20000000000 \
  --via-ir \
  -vv

# Save address from output
export COMPLIANCE_REGISTRY_ADDRESS=<deployed_address>
echo "COMPLIANCE_REGISTRY_ADDRESS=$COMPLIANCE_REGISTRY_ADDRESS" >> .env
```

### Step 2: Deploy CompliantUSDT

```bash
forge script script/DeployCompliantUSDT.s.sol:DeployCompliantUSDT \
  --rpc-url $RPC_URL \
  --broadcast \
  --legacy \
  --gas-price 20000000000 \
  --via-ir \
  -vv

# Save address from output
export COMPLIANT_USDT_ADDRESS=<deployed_address>
echo "COMPLIANT_USDT_ADDRESS=$COMPLIANT_USDT_ADDRESS" >> .env
```

### Step 3: Deploy CompliantUSDC

```bash
forge script script/DeployCompliantUSDC.s.sol:DeployCompliantUSDC \
  --rpc-url $RPC_URL \
  --broadcast \
  --legacy \
  --gas-price 20000000000 \
  --via-ir \
  -vv

# Save address from output
export COMPLIANT_USDC_ADDRESS=<deployed_address>
echo "COMPLIANT_USDC_ADDRESS=$COMPLIANT_USDC_ADDRESS" >> .env
```

### Step 4: Deploy TokenRegistry

```bash
forge script script/DeployTokenRegistry.s.sol:DeployTokenRegistry \
  --rpc-url $RPC_URL \
  --broadcast \
  --legacy \
  --gas-price 20000000000 \
  -vv

# Save address from output
export TOKEN_REGISTRY_ADDRESS=<deployed_address>
echo "TOKEN_REGISTRY_ADDRESS=$TOKEN_REGISTRY_ADDRESS" >> .env
```

### Step 5: Deploy FeeCollector

```bash
forge script script/DeployFeeCollector.s.sol:DeployFeeCollector \
  --rpc-url $RPC_URL \
  --broadcast \
  --legacy \
  --gas-price 20000000000 \
  -vv

# Save address from output
export FEE_COLLECTOR_ADDRESS=<deployed_address>
echo "FEE_COLLECTOR_ADDRESS=$FEE_COLLECTOR_ADDRESS" >> .env
```

### Step 6: Register Contracts in ComplianceRegistry

```bash
# Register CompliantUSDT
cast send $COMPLIANCE_REGISTRY_ADDRESS \
  "registerContract(address)" \
  $COMPLIANT_USDT_ADDRESS \
  --rpc-url $RPC_URL \
  --private-key $PRIVATE_KEY \
  --legacy \
  --gas-price 20000000000

# Register CompliantUSDC
cast send $COMPLIANCE_REGISTRY_ADDRESS \
  "registerContract(address)" \
  $COMPLIANT_USDC_ADDRESS \
  --rpc-url $RPC_URL \
  --private-key $PRIVATE_KEY \
  --legacy \
  --gas-price 20000000000
```

### Step 7: Register Tokens in TokenRegistry

```bash
# Register CompliantUSDT
cast send $TOKEN_REGISTRY_ADDRESS \
  "registerToken(address,string,string,uint8,bool,address)" \
  $COMPLIANT_USDT_ADDRESS \
  "Tether USD (Compliant)" \
  "cUSDT" \
  6 \
  false \
  0x0000000000000000000000000000000000000000 \
  --rpc-url $RPC_URL \
  --private-key $PRIVATE_KEY \
  --legacy \
  --gas-price 20000000000

# Register CompliantUSDC
cast send $TOKEN_REGISTRY_ADDRESS \
  "registerToken(address,string,string,uint8,bool,address)" \
  $COMPLIANT_USDC_ADDRESS \
  "USD Coin (Compliant)" \
  "cUSDC" \
  6 \
  false \
  0x0000000000000000000000000000000000000000 \
  --rpc-url $RPC_URL \
  --private-key $PRIVATE_KEY \
  --legacy \
  --gas-price 20000000000
```

---

## Step 8: Verify Deployments

```bash
# Run verification script
./scripts/verify-deployments.sh

# Or verify manually
cast code $COMPLIANCE_REGISTRY_ADDRESS --rpc-url $RPC_URL
cast code $COMPLIANT_USDT_ADDRESS --rpc-url $RPC_URL
cast code $COMPLIANT_USDC_ADDRESS --rpc-url $RPC_URL
cast code $TOKEN_REGISTRY_ADDRESS --rpc-url $RPC_URL
cast code $FEE_COLLECTOR_ADDRESS --rpc-url $RPC_URL
```

---

## Step 9: End-to-End Testing

```bash
# Run test script
./scripts/test-contracts.sh

# Or test manually
# Test token transfer
cast send $COMPLIANT_USDT_ADDRESS \
  "transfer(address,uint256)" \
  <recipient> 1000000 \
  --rpc-url $RPC_URL \
  --private-key $PRIVATE_KEY \
  --legacy

# Test registry queries
cast call $TOKEN_REGISTRY_ADDRESS \
  "getTokenInfo(address)" \
  $COMPLIANT_USDT_ADDRESS \
  --rpc-url $RPC_URL

# Test compliance status
cast call $COMPLIANCE_REGISTRY_ADDRESS \
  "isContractRegistered(address)" \
  $COMPLIANT_USDT_ADDRESS \
  --rpc-url $RPC_URL
```

---

## Step 10: Update Service Configurations

### Update Service .env Files

Add the new contract addresses to service configuration files:

```bash
# Oracle Publisher service
echo "COMPLIANCE_REGISTRY_ADDRESS=$COMPLIANCE_REGISTRY_ADDRESS" >> <service_path>/.env
echo "COMPLIANT_USDT_ADDRESS=$COMPLIANT_USDT_ADDRESS" >> <service_path>/.env
echo "COMPLIANT_USDC_ADDRESS=$COMPLIANT_USDC_ADDRESS" >> <service_path>/.env
echo "TOKEN_REGISTRY_ADDRESS=$TOKEN_REGISTRY_ADDRESS" >> <service_path>/.env
echo "FEE_COLLECTOR_ADDRESS=$FEE_COLLECTOR_ADDRESS" >> <service_path>/.env

# Repeat for other services as needed
```

---

## Step 11: Configure FeeCollector (Optional)

```bash
# Add fee recipient for ETH (example: 100% to one recipient)
cast send $FEE_COLLECTOR_ADDRESS \
  "addFeeRecipient(address,address,uint256)" \
  0x0000000000000000000000000000000000000000 \
  <recipient_address> \
  10000 \
  --rpc-url $RPC_URL \
  --private-key $PRIVATE_KEY \
  --legacy \
  --gas-price 20000000000

# Or split between multiple recipients
cast send $FEE_COLLECTOR_ADDRESS \
  "addFeeRecipient(address,address,uint256)" \
  0x0000000000000000000000000000000000000000 \
  <recipient1> 5000 \
  --rpc-url $RPC_URL --private-key $PRIVATE_KEY --legacy

cast send $FEE_COLLECTOR_ADDRESS \
  "addFeeRecipient(address,address,uint256)" \
  0x0000000000000000000000000000000000000000 \
  <recipient2> 5000 \
  --rpc-url $RPC_URL --private-key $PRIVATE_KEY --legacy
```

---

## Verification Checklist

After completion, verify:

- [ ] All contracts deployed successfully
- [ ] All contracts have code on-chain (>100 bytes)
- [ ] CompliantUSDT registered in ComplianceRegistry
- [ ] CompliantUSDC registered in ComplianceRegistry
- [ ] CompliantUSDT registered in TokenRegistry
- [ ] CompliantUSDC registered in TokenRegistry
- [ ] All addresses saved to .env
- [ ] Service .env files updated
- [ ] FeeCollector configured (if needed)
- [ ] End-to-end tests passing

---

## Troubleshooting

### Common Issues

1. **"PRIVATE_KEY not found"**
   - Solution: `export PRIVATE_KEY=<your_key>`

2. **"Insufficient funds"**
   - Solution: Fund deployer address with ETH

3. **"Contract already deployed"**
   - Solution: Check if address already has code, use different nonce if needed

4. **"Registration failed"**
   - Solution: Verify contract addresses are correct, check access control

---

## Quick Reference

### All-in-One Command

```bash
export PRIVATE_KEY=<your_key> && \
export RPC_URL=http://192.168.11.250:8545 && \
cd /home/intlc/projects/proxmox/smom-dbis-138 && \
./scripts/deploy-and-integrate-all.sh
```

### Verification Command

```bash
cd /home/intlc/projects/proxmox/smom-dbis-138 && \
./scripts/verify-deployments.sh
```

### Testing Command

```bash
cd /home/intlc/projects/proxmox/smom-dbis-138 && \
./scripts/test-contracts.sh
```

---

**Last Updated**: 2025-12-24  
**Status**: ✅ Ready for Execution

