# Oracle Publisher Service - Configuration Complete

**Date**: $(date)  
**VMID**: 3500

---

## ✅ Configuration Status

### Completed Steps

1. **✅ Fixed .env Configuration File**
   - Location: `/opt/oracle-publisher/.env`
   - Status: Clean, properly formatted
   - Contains all required settings except PRIVATE_KEY

2. **✅ Created Systemd Service**
   - Location: `/etc/systemd/system/oracle-publisher.service`
   - Status: Installed and enabled
   - User: `oracle` (needs to be verified/created if missing)

3. **✅ Configured Oracle Addresses**
   - Aggregator: `0x99b3511a2d315a497c8112c1fdd8d508d4b1e506`
   - Proxy: `0x3304b747e565a97ec8ac220b0b6a1f6ffdb837e6`

4. **✅ Configured Data Sources**
   - CoinGecko API (primary)
   - Binance API (fallback)

5. **✅ Configured Update Settings**
   - Update Interval: 60 seconds
   - Deviation Threshold: 0.5%

---

## ⚠️ Remaining Steps

### 1. Copy Oracle Publisher Python Script

The `oracle_publisher.py` script needs to be copied to the container:

```bash
# From your local machine
cd /home/intlc/projects/proxmox
scp smom-dbis-138/services/oracle-publisher/oracle_publisher.py \
    root@192.168.11.10:/tmp/oracle_publisher.py

# Then copy to container
ssh root@192.168.11.10 "pct exec 3500 -- cp /tmp/oracle_publisher.py /opt/oracle-publisher/oracle_publisher.py && chmod 755 /opt/oracle-publisher/oracle_publisher.py"
```

### 2. Set Private Key

**IMPORTANT**: The private key must belong to an account authorized as a transmitter on the oracle contract.

```bash
ssh root@192.168.11.10
pct exec 3500 -- bash
cd /opt/oracle-publisher
nano .env
# Add or uncomment: PRIVATE_KEY=0x...
# Save and exit (Ctrl+X, Y, Enter)
chmod 600 .env
```

### 3. Verify User Permissions

If the `oracle` user doesn't exist, create it:

```bash
ssh root@192.168.11.10
pct exec 3500 -- useradd -r -s /bin/bash -d /opt/oracle-publisher oracle
pct exec 3500 -- chown -R oracle:oracle /opt/oracle-publisher
```

### 4. Start the Service

```bash
ssh root@192.168.11.10
pct exec 3500 -- systemctl start oracle-publisher
pct exec 3500 -- systemctl status oracle-publisher
```

---

## 📋 Current Configuration Values

```bash
# Oracle Contracts
AGGREGATOR_ADDRESS=0x99b3511a2d315a497c8112c1fdd8d508d4b1e506
ORACLE_ADDRESS=0x3304b747e565a97ec8ac220b0b6a1f6ffdb837e6

# Network
RPC_URL=http://192.168.11.250:8545
WS_URL=ws://192.168.11.250:8546
CHAIN_ID=138

# Update Settings
UPDATE_INTERVAL=60
HEARTBEAT_INTERVAL=60
DEVIATION_THRESHOLD=0.5

# 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

# Metrics
METRICS_PORT=8000
METRICS_ENABLED=true
```

---

## 🔍 Verification Commands

### Check Service Status

```bash
ssh root@192.168.11.10 "pct exec 3500 -- systemctl status oracle-publisher"
```

### View Logs

```bash
ssh root@192.168.11.10 "pct exec 3500 -- journalctl -u oracle-publisher -f"
```

### Verify Oracle Price Updates

```bash
# Query oracle for latest price
cast call 0x3304b747e565a97ec8ac220b0b6a1f6ffdb837e6 \
  "latestRoundData()" \
  --rpc-url https://rpc-http-pub.d-bis.org

# Check if price is updating (should change every ~60 seconds)
```

### Check Metrics

```bash
ssh root@192.168.11.10 "pct exec 3500 -- curl -s http://localhost:8000/metrics | grep oracle"
```

---

## 🐛 Troubleshooting

### Service Fails to Start

1. **Check logs**:
   ```bash
   pct exec 3500 -- journalctl -u oracle-publisher -n 50
   ```

2. **Verify Python script exists**:
   ```bash
   pct exec 3500 -- ls -la /opt/oracle-publisher/oracle_publisher.py
   ```

3. **Test Python script manually**:
   ```bash
   pct exec 3500 -- cd /opt/oracle-publisher && source venv/bin/activate && python oracle_publisher.py
   ```

### Authorization Errors

If you see "Aggregator: only transmitter":
- Verify PRIVATE_KEY account is authorized as transmitter on oracle contract
- Check account has sufficient ETH balance for gas

### Price Not Updating

- Check service is running: `systemctl status oracle-publisher`
- Check logs for errors: `journalctl -u oracle-publisher -f`
- Verify data sources are accessible
- Check deviation threshold (only updates if price changes > 0.5%)

---

## 📚 Related Documentation

- `docs/ORACLE_UPDATE_AUTHORIZATION.md` - Authorization requirements
- `docs/METAMASK_USD_PRICE_FIX.md` - MetaMask integration
- `docs/UPDATE_ALL_ORACLE_PRICES.md` - Manual update guide

---

**Last Updated**: $(date)

