# Complete Connections, Contracts, and Containers List

**Date**: $(date)  
**Purpose**: Comprehensive list of all connections, smart contracts, and LXC containers

---

## 📋 Table of Contents

1. [Smart Contract Connections](#smart-contract-connections)
2. [Smart Contracts Required](#smart-contracts-required)
3. [LXC Containers to Deploy](#lxc-containers-to-deploy)
4. [MetaMask ETH Price Feed Setup](#metamask-eth-price-feed-setup)

---

## 🔗 Smart Contract Connections

### RPC Endpoint Connections

All services that interact with smart contracts need to connect to Besu RPC endpoints:

#### Primary RPC Endpoints
- **HTTP RPC**: `http://192.168.11.250:8545` (or load-balanced endpoint)
- **WebSocket RPC**: `ws://192.168.11.250:8546`
- **Chain ID**: 138

#### RPC Node IPs (Current Deployment)
| VMID | Hostname | IP Address | RPC Port | WS Port |
|------|----------|------------|----------|---------|
| 2500 | besu-rpc-1 | 192.168.11.250 | 8545 | 8546 |
| 2501 | besu-rpc-2 | 192.168.11.251 | 8545 | 8546 |
| 2502 | besu-rpc-3 | 192.168.11.252 | 8545 | 8546 |

**Note**: Services should use load-balanced endpoint or connect to multiple RPC nodes for redundancy.

---

## 📦 Smart Contracts Required

### Priority 1: Core Infrastructure Contracts

#### 1. Oracle Contract ⏳
- **Status**: Not Deployed
- **Required By**: Oracle Publisher Service (VMID 3500)
- **Script**: `DeployOracle.s.sol`
- **Purpose**: Receive price feed updates, store aggregated price data
- **Configuration**: `/opt/oracle-publisher/.env`
  ```bash
  ORACLE_CONTRACT_ADDRESS=<deploy-first>
  ```

#### 2. CCIP Router Contract ⏳
- **Status**: Not Deployed
- **Required By**: CCIP Monitor Service (VMID 3501)
- **Script**: `DeployCCIPRouter.s.sol`
- **Purpose**: Main CCIP router for cross-chain message routing
- **Configuration**: `/opt/ccip-monitor/.env`
  ```bash
  CCIP_ROUTER_ADDRESS=<deploy-first>
  ```

#### 3. CCIP Sender Contract ⏳
- **Status**: Not Deployed
- **Required By**: CCIP Monitor Service (VMID 3501)
- **Script**: `DeployCCIPSender.s.sol`
- **Purpose**: Sender contract for initiating CCIP messages
- **Configuration**: `/opt/ccip-monitor/.env`
  ```bash
  CCIP_SENDER_ADDRESS=<deploy-first>
  ```

#### 4. LINK Token Contract ⏳
- **Status**: Not Deployed
- **Required By**: CCIP Monitor Service (VMID 3501)
- **Purpose**: LINK token for CCIP fee payments
- **Configuration**: `/opt/ccip-monitor/.env`
  ```bash
  LINK_TOKEN_ADDRESS=<deploy-or-use-native-eth>
  ```

### Priority 2: Automation & Price Feeds

#### 5. Price Feed Keeper Contract ⏳
- **Status**: Not Deployed
- **Required By**: Price Feed Keeper Service (VMID 3502)
- **Script**: `reserve/DeployKeeper.s.sol` (Chain 138 specific)
- **Purpose**: Automation contract for triggering price feed updates
- **Configuration**: `/opt/keeper/.env`
  ```bash
  PRICE_FEED_KEEPER_ADDRESS=<deploy-after-oracle>
  KEEPER_CONTRACT_ADDRESS=<same-as-above>
  ```

#### 6. Oracle Price Feed Contract ⏳
- **Status**: Not Deployed
- **Required By**: Keeper Service, MetaMask Price Display
- **Script**: Part of Reserve System deployment
- **Purpose**: Provides ETH/USD and other price feeds for MetaMask and dApps
- **Configuration**: `/opt/keeper/.env`
  ```bash
  ORACLE_PRICE_FEED=<deploy-with-oracle>
  ```

### Priority 3: Tokenization

#### 7. Financial Tokenization Contract ⏳
- **Status**: Not Deployed
- **Required By**: Financial Tokenization Service (VMID 3503)
- **Script**: `reserve/DeployReserveSystem.s.sol`
- **Purpose**: Tokenization of financial instruments, ERC-20/ERC-721 management
- **Configuration**: `/opt/financial-tokenization/.env`
  ```bash
  TOKENIZATION_CONTRACT_ADDRESS=<deploy-after-reserve>
  ```

#### 8. Reserve System Contract ⏳
- **Status**: Not Deployed
- **Required By**: Financial Tokenization Service (VMID 3503)
- **Script**: `reserve/DeployReserveSystem.s.sol` (Chain 138 specific)
- **Purpose**: Reserve system for financial tokenization
- **Configuration**: `/opt/financial-tokenization/.env`

### Auto-Deployed Contracts

#### 9. Firefly Core Contracts ⏳
- **Status**: Auto-deployed by Firefly on first startup
- **Required By**: Hyperledger Firefly (VMID 6200)
- **Purpose**: Firefly core functionality, tokenization APIs
- **Configuration**: Auto-configured in `/opt/firefly/docker-compose.yml`

---

## 🖥️ LXC Containers to Deploy

### Priority 1: Smart Contract Services (High Priority)

| VMID | Hostname | IP Address | Service | Status | Priority |
|------|----------|------------|---------|--------|----------|
| 3500 | oracle-publisher-1 | 192.168.11.68 | Oracle Publisher | ⏳ Pending | P1 - High |
| 3501 | ccip-monitor-1 | 192.168.11.69 | CCIP Monitor | ⏳ Pending | P1 - High |
| 3502 | keeper-1 | 192.168.11.70 | Price Feed Keeper | ⏳ Pending | P1 - High |
| 3503 | financial-tokenization-1 | 192.168.11.71 | Financial Tokenization | ⏳ Pending | P2 - Medium |

**Total**: 4 containers

---

### Priority 2: Hyperledger Services (Ready for Deployment)

| VMID | Hostname | IP Address | Service | Status | Priority |
|------|----------|------------|---------|--------|----------|
| 5200 | cacti-1 | 192.168.11.64 | Hyperledger Cacti | ✅ Ready | P1 - High |
| 6000 | fabric-1 | 192.168.11.65 | Hyperledger Fabric | ✅ Ready | P2 - Medium |
| 6200 | firefly-1 | 192.168.11.66 | Hyperledger Firefly | ✅ Ready | P1 - High |
| 6400 | indy-1 | 192.168.11.67 | Hyperledger Indy | ✅ Ready | P2 - Medium |

**Total**: 4 containers

**Note**: These are ready but need RPC endpoint configuration after deployment.

---

### Priority 3: Monitoring Stack (High Priority)

| VMID | Hostname | IP Address | Service | Status | Priority |
|------|----------|------------|---------|--------|----------|
| 3504 | monitoring-stack-1 | 192.168.11.80 | Prometheus | ⏳ Pending | P1 - High |
| 3505 | monitoring-stack-2 | 192.168.11.81 | Grafana | ⏳ Pending | P1 - High |
| 3506 | monitoring-stack-3 | 192.168.11.82 | Loki | ⏳ Pending | P2 - Medium |
| 3507 | monitoring-stack-4 | 192.168.11.83 | Alertmanager | ⏳ Pending | P2 - Medium |
| 3508 | monitoring-stack-5 | 192.168.11.84 | Additional monitoring | ⏳ Pending | P2 - Medium |

**Total**: 5 containers

---

### Priority 4: Explorer (Medium Priority)

| VMID | Hostname | IP Address | Service | Status | Priority |
|------|----------|------------|---------|--------|----------|
| 5000 | blockscout-1 | 192.168.11.140 | Blockscout Explorer | ⏳ Pending | P2 - Medium |

**Total**: 1 container

---

## 📊 Summary

### Total Containers to Deploy

**By Priority**:
- **P1 (High)**: 7 containers
  - Oracle Publisher (3500)
  - CCIP Monitor (3501)
  - Keeper (3502)
  - Cacti (5200)
  - Firefly (6200)
  - Prometheus (3504)
  - Grafana (3505)

- **P2 (Medium)**: 7 containers
  - Financial Tokenization (3503)
  - Fabric (6000)
  - Indy (6400)
  - Loki (3506)
  - Alertmanager (3507)
  - Monitoring Stack 5 (3508)
  - Blockscout (5000)

**Grand Total**: **14 containers** ready for deployment

### Total Smart Contracts Required

**By Priority**:
- **P1 (High)**: 4 contracts
  - Oracle Contract
  - CCIP Router
  - CCIP Sender
  - LINK Token

- **P2 (Medium)**: 2 contracts
  - Price Feed Keeper
  - Oracle Price Feed

- **P3 (Low)**: 2 contracts
  - Financial Tokenization
  - Reserve System

**Grand Total**: **8 contracts** need to be deployed

---

## 🦊 MetaMask ETH Price Feed Setup

### Overview

For MetaMask to display ETH pricing in USD, you need:

1. **Price Feed Oracle Contract** - Provides ETH/USD price data
2. **Oracle Publisher Service** - Updates price feed from external sources
3. **Token List Configuration** (Optional) - For MetaMask to recognize tokens

### Components Required

#### 1. Oracle Price Feed Contract ✅

**Purpose**: Stores and provides ETH/USD price data that MetaMask can query

**Contract Type**: Chainlink-compatible Aggregator contract

**Features Needed**:
- `latestRoundData()` function - Returns latest price, timestamp, round ID
- `decimals()` function - Returns price feed decimals (typically 8)
- `description()` function - Returns price feed description (e.g., "ETH / USD")

**Deployment**:
```bash
# Deploy Oracle Price Feed (part of Oracle deployment)
cd /home/intlc/projects/smom-dbis-138
forge script script/DeployOracle.s.sol:DeployOracle \
  --rpc-url http://192.168.11.250:8545 \
  --private-key $PRIVATE_KEY \
  --broadcast --verify -vvvv
```

**Contract Address**: Will be generated after deployment

---

#### 2. Oracle Publisher Service ✅

**Purpose**: Fetches ETH/USD price from external APIs and updates the on-chain oracle

**VMID**: 3500  
**IP**: 192.168.11.68  
**Status**: ⏳ Pending Deployment

**Data Sources** (configure in service):
- CoinGecko API: `https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd`
- CoinMarketCap API: `https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=ETH`
- Binance API: `https://api.binance.com/api/v3/ticker/price?symbol=ETHUSDT`
- Multiple sources for aggregation and median calculation

**Configuration**: `/opt/oracle-publisher/.env`
```bash
RPC_URL_138=http://192.168.11.250:8545
WS_URL_138=ws://192.168.11.250:8546
ORACLE_CONTRACT_ADDRESS=<deployed-oracle-address>
PRIVATE_KEY=<oracle-publisher-private-key>
UPDATE_INTERVAL=60  # Update every 60 seconds
METRICS_PORT=8000

# Data Sources
DATA_SOURCE_1_URL=https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd
DATA_SOURCE_1_PARSER=coingecko
DATA_SOURCE_2_URL=https://api.binance.com/api/v3/ticker/price?symbol=ETHUSDT
DATA_SOURCE_2_PARSER=binance
```

**How It Works**:
1. Service fetches ETH/USD price from multiple APIs
2. Calculates median price (for accuracy)
3. Checks deviation threshold (to avoid unnecessary updates)
4. Submits transaction to update oracle contract
5. Oracle contract stores latest price, timestamp, round ID

---

#### 3. MetaMask Integration

**Option A: Direct Oracle Contract Query** (Recommended)

MetaMask can query the oracle contract directly using the Aggregator interface:

```javascript
// MetaMask/dApp code to get ETH price
const oracleAddress = "0x..."; // Deployed oracle contract address
const oracleABI = [
  "function latestRoundData() external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)",
  "function decimals() external view returns (uint8)",
  "function description() external view returns (string memory)"
];

const provider = new ethers.providers.Web3Provider(window.ethereum);
const oracle = new ethers.Contract(oracleAddress, oracleABI, provider);

// Get latest price
const roundData = await oracle.latestRoundData();
const price = roundData.answer; // Price in USD (with decimals)
const decimals = await oracle.decimals();
const priceInUSD = price / (10 ** decimals);
```

**Option B: Token List Configuration** (For Token Display)

Create a token list JSON file for MetaMask:

```json
{
  "name": "SMOM-DBIS-138 Token List",
  "version": {
    "major": 1,
    "minor": 0,
    "patch": 0
  },
  "tokens": [
    {
      "chainId": 138,
      "address": "0x...", // Native ETH or WETH address
      "symbol": "ETH",
      "name": "Ether",
      "decimals": 18,
      "logoURI": "https://example.com/eth-logo.png"
    }
  ]
}
```

**Deploy Token List**:
- Host on a public URL (e.g., GitHub Pages, IPFS)
- Add to MetaMask via Settings → Security & Privacy → Token Lists
- Or use in dApp: `tokenListUrl: "https://your-domain.com/token-list.json"`

---

### Deployment Steps for MetaMask Price Feed

#### Step 1: Deploy Oracle Contract

```bash
cd /home/intlc/projects/smom-dbis-138
forge script script/DeployOracle.s.sol:DeployOracle \
  --rpc-url http://192.168.11.250:8545 \
  --private-key $PRIVATE_KEY \
  --broadcast --verify -vvvv
```

**Extract Contract Address**:
```bash
# From broadcast file
jq -r '.transactions[0].contractAddress' \
  broadcast/DeployOracle.s.sol/138/run-latest.json
```

#### Step 2: Deploy Oracle Publisher Service

```bash
cd /opt/smom-dbis-138-proxmox
./scripts/deployment/deploy-services.sh
```

**Configure Service**:
```bash
pct exec 3500 -- bash -c "cat > /opt/oracle-publisher/.env <<EOF
RPC_URL_138=http://192.168.11.250:8545
WS_URL_138=ws://192.168.11.250:8546
ORACLE_CONTRACT_ADDRESS=<deployed-oracle-address>
PRIVATE_KEY=<oracle-publisher-private-key>
UPDATE_INTERVAL=60
METRICS_PORT=8000
DATA_SOURCE_1_URL=https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd
DATA_SOURCE_1_PARSER=coingecko
DATA_SOURCE_2_URL=https://api.binance.com/api/v3/ticker/price?symbol=ETHUSDT
DATA_SOURCE_2_PARSER=binance
EOF"
```

#### Step 3: Start Oracle Publisher Service

```bash
pct exec 3500 -- systemctl start oracle-publisher
pct exec 3500 -- systemctl enable oracle-publisher
```

#### Step 4: Verify Price Feed Updates

```bash
# Check service logs
pct exec 3500 -- journalctl -u oracle-publisher -f

# Query oracle contract directly
cast call <oracle-address> "latestRoundData()" --rpc-url http://192.168.11.250:8545
```

#### Step 5: Integrate with MetaMask/dApp

```javascript
// Example: Get ETH price in dApp
const oracleAddress = "0x..."; // Your deployed oracle address
const oracleABI = [
  "function latestRoundData() external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)",
  "function decimals() external view returns (uint8)"
];

// In your dApp
const provider = new ethers.providers.Web3Provider(window.ethereum);
const oracle = new ethers.Contract(oracleAddress, oracleABI, provider);

async function getETHPrice() {
  const roundData = await oracle.latestRoundData();
  const decimals = await oracle.decimals();
  const priceInUSD = Number(roundData.answer) / (10 ** Number(decimals));
  return priceInUSD;
}

// Display in UI
const ethPrice = await getETHPrice();
console.log(`ETH Price: $${ethPrice.toFixed(2)}`);
```

---

### Additional Components for Full MetaMask Integration

#### 1. Network Configuration

MetaMask needs network configuration for Chain 138:

```javascript
const networkConfig = {
  chainId: '0x8a', // 138 in hex
  chainName: 'SMOM-DBIS-138',
  nativeCurrency: {
    name: 'Ether',
    symbol: 'ETH',
    decimals: 18
  },
  rpcUrls: ['https://rpc-core.d-bis.org'], // Your public RPC endpoint
  blockExplorerUrls: ['https://explorer.d-bis.org'] // When Blockscout is deployed
};
```

**Add to MetaMask**:
```javascript
await window.ethereum.request({
  method: 'wallet_addEthereumChain',
  params: [networkConfig]
});
```

#### 2. Token List (Optional)

For MetaMask to display custom tokens with prices:

1. **Create Token List JSON** (see example above)
2. **Host on Public URL** (GitHub Pages, IPFS, or your domain)
3. **Add to MetaMask**:
   - Settings → Security & Privacy → Token Lists
   - Add custom token list URL

#### 3. Price Feed Aggregator (Advanced)

For multiple price feeds (ETH/USD, BTC/USD, etc.):

- Deploy multiple oracle contracts (one per price pair)
- Configure Oracle Publisher to update all feeds
- Create aggregator contract that combines multiple feeds

---

## 📚 Related Documentation

- [Smart Contract Connections & Next LXCs](./SMART_CONTRACT_CONNECTIONS_AND_NEXT_LXCS.md)
- [Contract Deployment Guide](./CONTRACT_DEPLOYMENT_GUIDE.md)
- [Deployed Smart Contracts Inventory](./DEPLOYED_SMART_CONTRACTS_INVENTORY.md)
- [Source Project Contract Deployment Info](./SOURCE_PROJECT_CONTRACT_DEPLOYMENT_INFO.md)
- [Remaining LXCs to Deploy](./archive/REMAINING_LXCS_TO_DEPLOY.md)

---

## ✅ Next Steps

1. **Deploy Smart Contracts** (Priority 1)
   - Oracle Contract
   - CCIP Router
   - CCIP Sender
   - LINK Token

2. **Deploy Oracle Publisher Service** (VMID 3500)
   - Configure with deployed oracle address
   - Set up data sources
   - Start service

3. **Deploy Additional Services** (Priority 2)
   - CCIP Monitor (3501)
   - Keeper (3502)
   - Financial Tokenization (3503)

4. **Deploy Hyperledger Services** (Priority 2)
   - Firefly (6200)
   - Cacti (5200)
   - Fabric (6000)
   - Indy (6400)

5. **Deploy Monitoring Stack** (Priority 2)
   - Prometheus (3504)
   - Grafana (3505)
   - Loki (3506)
   - Alertmanager (3507)

6. **Deploy Explorer** (Priority 2)
   - Blockscout (5000)

7. **Configure MetaMask Integration**
   - Deploy oracle contract
   - Configure Oracle Publisher service
   - Create token list (optional)
   - Test price feed in dApp

---

**Last Updated**: $(date)  
**Status**: Ready for deployment

