- Organized 252 files across project - Root directory: 187 → 2 files (98.9% reduction) - Moved configuration guides to docs/04-configuration/ - Moved troubleshooting guides to docs/09-troubleshooting/ - Moved quick start guides to docs/01-getting-started/ - Moved reports to reports/ directory - Archived temporary files - Generated comprehensive reports and documentation - Created maintenance scripts and guides All files organized according to established standards.
6.4 KiB
6.4 KiB
Update All Oracle Prices - Guide
Date: $(date)
ChainID: 138
Purpose: Update all oracle contracts with current token prices from CoinGecko
📋 Overview
This script updates all oracle contracts listed in the token list with current market prices fetched from CoinGecko API.
Current Token List
| Token | Symbol | Address | Oracle Address | CoinGecko ID |
|---|---|---|---|---|
| ETH/USD Price Feed | ETH-USD | 0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6 |
0x3304b747e565a97ec8ac220b0b6a1f6ffdb837e6 |
ethereum |
| Wrapped Ether | WETH | 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 |
0x3304b747e565a97ec8ac220b0b6a1f6ffdb837e6 |
ethereum |
| Wrapped Ether v10 | WETH10 | 0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9F |
0x3304b747e565a97ec8ac220b0b6a1f6ffdb837e6 |
ethereum |
| Chainlink Token | LINK | 0x514910771AF9Ca656af840dff83E8264EcF986CA |
(no oracle) | chainlink |
Note:
- WETH and WETH10 use the ETH/USD oracle (1:1 price with ETH)
- LINK token does not have an oracle contract yet - would need separate LINK/USD oracle
🚀 Usage
Prerequisites
- Private Key: Set
DEPLOYER_PRIVATE_KEYenvironment variable OR pass as argument - Foundry/cast: Must have
castcommand available - Python3: Required for price calculations
- jq: Required for JSON parsing
- bc: Required for floating point comparisons
Basic Usage
# Using environment variable for private key
export DEPLOYER_PRIVATE_KEY="0x..."
./scripts/update-all-oracle-prices.sh
# Using command line arguments
./scripts/update-all-oracle-prices.sh https://rpc-http-pub.d-bis.org 0x...
Arguments
- RPC URL (optional): Defaults to
https://rpc-http-pub.d-bis.org - Private Key (optional): Defaults to
$DEPLOYER_PRIVATE_KEYenvironment variable
📊 How It Works
- Read Token List: Parses
token-lists/lists/dbis-138.tokenlist.json - Map Tokens to CoinGecko: Maps token symbols to CoinGecko API IDs
- Fetch Prices: Gets current USD prices from CoinGecko API
- Check Oracle Contracts: Queries current oracle prices
- Update if Needed: Only updates if price difference > 0.5% (to save gas)
- Verify Update: Confirms transaction was successful
Price Sources
- ETH, WETH, WETH10: CoinGecko
ethereumprice - LINK: CoinGecko
chainlinkprice (if oracle exists)
🔧 Configuration
Token Mappings
Edit the script to add more tokens:
# Add to TOKEN_MAP
declare -A TOKEN_MAP=(
["NEWTOKEN"]="coingecko-id"
)
# Add to ORACLE_ADDRESSES
declare -A ORACLE_ADDRESSES=(
["NEWTOKEN"]="0x..."
)
Oracle Update Methods
The script tries these methods in order:
updateAnswer(int256)transmit(int256)setLatestAnswer(int256)
✅ Verification
After running the script, verify prices:
# Check ETH/USD oracle
cast call 0x3304b747e565a97ec8ac220b0b6a1f6ffdb837e6 \
"latestRoundData()" \
--rpc-url https://rpc-http-pub.d-bis.org
# Parse result (answer field is in 8 decimals)
# Format: (roundId, answer, startedAt, updatedAt, answeredInRound)
# Divide answer by 1e8 to get USD price
Expected Output
=========================================
Update All Oracle Prices
=========================================
[INFO] RPC URL: https://rpc-http-pub.d-bis.org
[INFO] Token List: /home/intlc/projects/proxmox/token-lists/lists/dbis-138.tokenlist.json
[✓] RPC is accessible
[INFO] Tokens to update: ethereum chainlink
[INFO] Fetching prices from CoinGecko...
[✓] Prices fetched successfully
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Updating Oracle Contracts
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[INFO] ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[INFO] Updating: ETH/USD Price Feed (ETH-USD)
[DETAIL] Oracle Address: 0x3304b747e565a97ec8ac220b0b6a1f6ffdb837e6
[DETAIL] Current Price: $2943.34 USD
[DETAIL] Price in 8 decimals: 294334000000
[INFO] Sending transaction to update oracle...
[✓] Transaction sent using updateAnswer: 0x...
[✓] Oracle updated: $2943.34 USD
=========================================
Summary
=========================================
[✓] Successfully updated: 1 oracle(s)
⚠️ Limitations
-
Single Oracle Contract: Currently only ETH/USD oracle exists
- WETH and WETH10 use the same oracle (correct, as they track ETH 1:1)
- LINK needs a separate oracle contract for LINK/USD
-
Gas Costs: Each update requires a transaction, so costs gas
- Script skips updates if price change < 0.5% to save gas
-
CoinGecko Rate Limits: Free API has rate limits
- Script fetches all prices in one API call to minimize requests
🔄 Automatic Updates
For automatic price updates, use the Oracle Publisher Service (VMID 3500):
- Configure Oracle Publisher: Set up service on VMID 3500
- Set Update Interval: Configure to update every 60 seconds
- Price Sources: Configure multiple sources (CoinGecko, Binance, etc.)
- Start Service: Service will automatically update prices
See: docs/METAMASK_USD_PRICE_FIX.md for Oracle Publisher setup
📝 Adding New Tokens
To add a new token oracle:
- Deploy Oracle Contract: Deploy Chainlink-compatible aggregator
- Add to Token List: Add token to
token-lists/lists/dbis-138.tokenlist.json - Update Script: Add mappings to
TOKEN_MAPandORACLE_ADDRESSES - Test: Run script and verify oracle updates
🐛 Troubleshooting
Error: "Private key required"
- Set
DEPLOYER_PRIVATE_KEYenvironment variable OR pass as argument
Error: "RPC is not accessible"
- Check RPC URL is correct and accessible
- Try:
curl -X POST https://rpc-http-pub.d-bis.org -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
Error: "Failed to fetch prices from CoinGecko"
- Check internet connection
- CoinGecko API may be rate-limited (wait and retry)
- Verify CoinGecko IDs are correct
Error: "Failed to update oracle"
- Check oracle contract address is correct
- Verify contract has
updateAnswer,transmit, orsetLatestAnswerfunction - Ensure private key has sufficient balance for gas
- Check transaction was successful on block explorer
Last Updated: $(date)