Skip to content

deficollective/morpho-oracles-analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Morpho Oracles Analysis

This repository holds scripts to analyse the oracles used within Morpho markets across multiple blockchains.

Features

  • 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

Directory Structure

data/
├── mainnet/           # Ethereum mainnet data files
└── base/             # Base chain data files

results/
├── mainnet/          # Mainnet analysis results
└── base/            # Base chain analysis results

Installation

  1. Set up a Python virtual environment:
python -m venv morpho_env
source morpho_env/bin/activate  # On Windows: morpho_env\Scripts\activate
  1. Install dependencies:
pip install web3 eth-abi requests

Usage

Quick Start

To 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)

Individual Steps

You can also run each step individually:

  1. Retrieve Markets and Oracles:
python oracles.py --chain mainnet --oracles
  1. Query Oracle Aggregators:
python oracles.py --chain mainnet --aggr
  1. 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
  1. 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-morpho

Advanced Options

Chain 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

Data Sources

TVL Data Sources

  1. 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
  2. TheGraph API

    • Comprehensive market coverage
    • Requires API key from https://thegraph.com/studio/
    • Default for mainnet
    • May have data staleness on some chains

Oracle Data Sources

  • 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

Output Files

Data Files (data/{chain}/)

  • markets.json - Market data and oracle addresses from blockchain events
  • aggregator.json - Oracle aggregator feed mappings
  • chainlink.json - Chainlink oracle addresses
  • tvl.json - Default TVL data
  • tvl-morpho.json - TVL data from Morpho API
  • tvl-thegraph.json - TVL data from TheGraph API
  • tvl-all.json - All markets TVL data (Base only)

Results Files (results/{chain}/)

  • analysis.json - Default analysis results
  • analysis-morpho.json - Analysis using Morpho API data
  • analysis-thegraph.json - Analysis using TheGraph API data
  • analysis-whitelisted.json - Whitelisted markets analysis (Base)
  • analysis-all.json - All markets analysis (Base)

Configuration

Required: API Keys Setup

Before running the analysis, you must configure your API keys:

  1. Infura API Key (Required for blockchain access):
    • Get your free API key at https://infura.io/
    • In oracles.py, replace YOUR_INFURA_API_KEY with 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",
        # ...
    }
}
  1. TheGraph API Key (Optional, for mainnet TVL data):

Error Messages

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

Results

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%)

About

Analysis of Morpho oracle feeds, and in particular Chainlink feeds, used across markets

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages