This repository holds scripts to analyse the oracles used within Morpho markets across multiple blockchains.
- Chains: Analyze Morpho markets on Ethereum mainnet and Base
- Data Sources: Compare TVL data from Morpho API and TheGraph subgraphs
- Automatic Oracle Detection: Scrape latest Chainlink oracle addresses from data.chain.link
- Comprehensive Analysis: Track oracle usage, TVL distribution, and market coverage
data/
├── mainnet/ # Ethereum mainnet data files
└── base/ # Base chain data files
results/
├── mainnet/ # Mainnet analysis results
└── base/ # Base chain analysis results
- Set up a Python virtual environment:
python -m venv morpho_env
source morpho_env/bin/activate # On Windows: morpho_env\Scripts\activate- Install dependencies:
pip install web3 eth-abi requestsTo run the complete analysis pipeline for a specific chain. If the api key is not specified the program will use cached tvl data.
# Analyze Ethereum mainnet with TheGraph API (automatically uses TheGraph as TVL source)
python oracles.py --chain mainnet (--thegraph-api-key YOUR_API_KEY)
# Analyze Base chain (uses Morpho API by default)
python oracles.py --chain base
# Analyze Base chain with TheGraph API (automatically uses TheGraph as TVL source)
python oracles.py --chain base (--thegraph-api-key YOUR_API_KEY)You can also run each step individually:
- Retrieve Markets and Oracles:
python oracles.py --chain mainnet --oracles- Query Oracle Aggregators:
python oracles.py --chain mainnet --aggr- Fetch TVL Data:
# Default source (TheGraph for mainnet, Morpho API for Base)
python oracles.py --chain mainnet --tvl --thegraph-api-key YOUR_API_KEY
python oracles.py --chain base --tvl
# Force specific data source
python oracles.py --chain base --tvl --use-thegraph --thegraph-api-key YOUR_API_KEY
python oracles.py --chain mainnet --tvl --use-morpho- Run Analysis:
# Standard analysis
python oracles.py --chain base --analysis
# Analysis with specific data source (auto-fetches fresh data)
python oracles.py --chain base --analysis --use-thegraph --thegraph-api-key YOUR_API_KEY
python oracles.py --chain mainnet --analysis --use-morphoChain Selection:
--chain mainnet- Analyze Ethereum mainnet--chain base- Analyze Base chain
Data Source Options:
--use-thegraph- Force use TheGraph API for TVL data--use-morpho- Force use Morpho API for TVL data--thegraph-api-key KEY- Provide TheGraph API key (automatically uses TheGraph as TVL source)
Market Filtering (Base chain only):
--whitelisted- Analyze only whitelisted markets (default)--all-markets- Analyze all markets including non-whitelisted
Utility Commands:
--update-chainlink- Update Chainlink oracle addresses from website--help- Show all available options
-
Morpho API (
https://blue-api.morpho.org/graphql)- Real-time, accurate TVL data
- Supports both whitelisted and all markets
- Default for Base chain
- Available for both chains
-
TheGraph API
- Comprehensive market coverage
- Requires API key from https://thegraph.com/studio/
- Default for mainnet
- May have data staleness on some chains
- Chainlink Addresses: Automatically scraped from data.chain.link with fallback to local cache
- Market Events: Retrieved directly from blockchain via RPC
- Oracle Aggregators: Queried from oracle contracts on-chain
markets.json- Market data and oracle addresses from blockchain eventsaggregator.json- Oracle aggregator feed mappingschainlink.json- Chainlink oracle addressestvl.json- Default TVL datatvl-morpho.json- TVL data from Morpho APItvl-thegraph.json- TVL data from TheGraph APItvl-all.json- All markets TVL data (Base only)
analysis.json- Default analysis resultsanalysis-morpho.json- Analysis using Morpho API dataanalysis-thegraph.json- Analysis using TheGraph API dataanalysis-whitelisted.json- Whitelisted markets analysis (Base)analysis-all.json- All markets analysis (Base)
Before running the analysis, you must configure your API keys:
- Infura API Key (Required for blockchain access):
- Get your free API key at https://infura.io/
- In
oracles.py, replaceYOUR_INFURA_API_KEYwith your actual Infura project ID:
CHAIN_CONFIG = {
"mainnet": {
"rpc_url": "https://mainnet.infura.io/v3/YOUR_ACTUAL_INFURA_KEY",
# ...
},
"base": {
"rpc_url": "https://base-mainnet.infura.io/v3/YOUR_ACTUAL_INFURA_KEY",
# ...
}
}- TheGraph API Key (Optional, for mainnet TVL data):
- Get your API key at https://thegraph.com/studio/
- Pass via command line:
--thegraph-api-key YOUR_ACTUAL_KEY
If you forget to configure API keys, you'll see helpful error messages:
❌ Infura API key not configured!- Replace the placeholder in CHAIN_CONFIG⚠️ No valid TheGraph API key provided- Pass --thegraph-api-key parameter
The analysis provides:
- Total TVL across all markets
- TVL and percentage using Chainlink oracles
- Market count and oracle distribution
- Unused markets (in TVL data but not in blockchain events)
- Data source tracking for transparency Example output:
Total TVL: $981,114,661.56 USD
TVL using Chainlink: $909,809,993.20 USD (92.73%)
Total Markets: 1,006
Markets using Chainlink: 159 (15.81%)