Skip to main content

Critical Raw Minerals & Urban Mining Oracle (minerals-oracle-x402)

Glama.ai Cloud Run Base Network FastAPI Agent Protocol MCP

High-performance deterministic micro-oracle service designed for autonomous trading, supply chain, and RWA (Real World Asset) agents on Base Network. Serves real-time spot pricing, COMEX/LME cross-exchange arbitrage spreads, and urban-mining scrap benchmark yield valuations for critical raw physical commodities.


โšก Key Features

  1. Normalized Critical Commodities Price Feeds:

    • Silver (Ag): LBMA & COMEX spot in USD/troy_oz, USD/g, USD/kg.
    • Platinum (Pt): LPPM & NYMEX spot in USD/troy_oz, USD/g.
    • Copper (Cu): LME Grade A Cathode & COMEX in USD/mt, USD/lb, USD/kg.
    • Lithium (Li): Battery Grade 99.5% $\text{Li}_2\text{CO}_3$ / $\text{LiOH}$ in USD/mt, USD/kg.
    • Rare Earths (NdDy): Permanent magnet grade Neodymium-Dysprosium ($\text{PrNd}/\text{DyFe}$) composite in USD/kg.
  2. Locational Arbitrage & Basis Spreads:

    • COMEX vs. LME Copper arbitrage calculation factoring in trans-oceanic freight & import tariffs.
    • COMEX vs. LBMA Loco London Silver spread.
    • SMM Domestic China vs. Fastmarkets CIF Rotterdam Lithium premium/discount.
    • NYMEX vs. LPPM Platinum spread.
  3. Urban Mining & Circular Economy Valuation Engine:

    • EV_BATTERY_BLACK_MASS: Hydrometallurgical recovery of $\text{Li}$, $\text{Ni}$, $\text{Co}$, and $\text{Mn}$ with payable recovery yields and treatment charges (TC/RC).
    • AUTO_CATALYST_CERAMIC: Spent catalytic converter PGM recovery ($\text{Pt}$, $\text{Pd}$, $\text{Rh}$) from ceramic monolith assays.
    • E_WASTE_HIGH_GRADE_PCB: Precious and base metal extraction ($\text{Au}$, $\text{Ag}$, $\text{Cu}$) from shredded PCB feedstock.
    • WIND_EV_PERMANENT_MAGNETS: NdFeB scrap recycling for separated rare earth oxides ($\text{Nd}$, $\text{Dy}$, $\text{Pr}$).
  4. Web3 Monetization via x402 on Base:

    • Enforces micro-payments (0.005 USDC per query) via HTTP 402 challenge-response on Base (Chain ID 8453).
    • Native Base USDC token: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913.
    • Supports EIP-712/EIP-191 cryptographic signatures and facilitator verification.
  5. Multi-Agent Standards Native:

    • Google AP2 (/.well-known/ap2): Agent Protocol v2 manifest.
    • Model Context Protocol (MCP): Tool schema definitions (mcp_tool_spec.json) and /mcp/invoke dispatcher.
    • OpenAPI / Swagger (/docs): Standard machine-readable and interactive API documentation.

๐Ÿ“ Repository Structure

minerals-oracle-x402/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ main.py              # FastAPI application, routing & MCP endpoints
โ”‚   โ”œโ”€โ”€ feed_engine.py       # Deterministic commodity pricing, spread & scrap engine
โ”‚   โ”œโ”€โ”€ x402_verifier.py     # HTTP 402 challenge & EIP-712 payment verifier
โ”‚   โ””โ”€โ”€ schemas.py           # Pydantic data contracts & schemas
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ test_client.py       # Autonomous agent payment test suite
โ”œโ”€โ”€ .well-known/
โ”‚   โ””โ”€โ”€ ap2.json             # Google Agent Protocol AP2 manifest
โ”œโ”€โ”€ mcp_tool_spec.json       # FastMCP tool definition for LLM agents
โ”œโ”€โ”€ Dockerfile               # Ultra-lightweight multi-stage container
โ”œโ”€โ”€ requirements.txt         # Python dependencies
โ””โ”€โ”€ README.md                # Documentation & quickstart

๐Ÿš€ Quick Start

1. Local Setup

# Clone and enter directory
cd minerals-oracle-x402

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Run development server
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload

Interactive documentation will be available at http://localhost:8000/docs.

2. Running via Docker

# Build lightweight container
docker build -t minerals-oracle-x402 .

# Run container
docker run -p 8000:8000 minerals-oracle-x402

๐Ÿ’ณ x402 Payment Flow Specification

sequenceDiagram
    autonumber
    actor Agent as Autonomous AI Agent
    participant Oracle as minerals-oracle-x402
    participant Base as Base Network (USDC)

    Agent->>Oracle: GET /api/v1/oracle/prices
    Oracle-->>Agent: HTTP 402 Payment Required<br/>(Nonce, Price: 0.005 USDC, Base Chain ID: 8453)
    Note over Agent: Agent signs payment challenge<br/>using private key (EIP-712/EIP-191)
    Agent->>Oracle: GET /api/v1/oracle/prices<br/>Header: Authorization: x402 <base64_payload>
    Oracle->>Oracle: Verify signature / Facilitator settle
    Oracle-->>Agent: HTTP 200 OK<br/>Certified Oracle Feeds & Attestation Hashes

Payment Authorization Header Format

Authorization: x402 eyJub25jZSI6ICIxYTIz...IiwgInNpZ25hdHVyZSI6ICIweDk5...In0=

Where the decoded JSON payload contains:

{
  "nonce": "7f8b92c4a90184b2ef019a823b102938",
  "signature": "0x...",
  "signer": "0xYourAgentWalletAddress"
}

๐Ÿค– MCP (Model Context Protocol) Integration

To use with Claude Desktop, Cursor, Gemini or Antigravity agents, load mcp_tool_spec.json.

Available tools:

  1. get_mineral_prices: Retrieve all current spot prices and unit conversions.
  2. get_arbitrage_spreads: Fetch COMEX/LME/SMM basis spreads and margins.
  3. calculate_urban_mining_value: Calculate batch recovery yields for EV Black Mass, Auto Catalysts, E-Waste, or Permanent Magnets.

Example Python Agent MCP tool call:

import httpx

resp = httpx.post(
    "http://localhost:8000/mcp/invoke",
    json={
        "name": "calculate_urban_mining_value",
        "arguments": {
            "scrap_category": "EV_BATTERY_BLACK_MASS",
            "quantity_metric_tons": 5.0,
            "custom_assay_overrides": {"Li": 4.1, "Co": 6.5}
        }
    },
    headers={"X-Dev-Bypass": "true"}  # Or with valid x402 signature
)
print(resp.json())

๐Ÿงช Running Tests

Execute the automated test suite verifying 402 challenge flow, EIP-712 cryptographic verification, scrap calculations, and AP2 endpoints:

pytest -v tests/test_client.py

๐Ÿ“œ License

MIT License. Built for Autonomous Agent Commerce and Critical Mineral Resilience.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

minerals_oracle_x402-1.0.0.tar.gz (32.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

minerals_oracle_x402-1.0.0-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

File details

Details for the file minerals_oracle_x402-1.0.0.tar.gz.

File metadata

  • Download URL: minerals_oracle_x402-1.0.0.tar.gz
  • Upload date:
  • Size: 32.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for minerals_oracle_x402-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c7888ca9bdc130cc2232738efa0074c8113ab413eb61586828242521f40a8c69
MD5 d2bd78cf950c682c21e556d422fcaa3e
BLAKE2b-256 54bb809ab2f3ae136e0b542063a68be21d0705eda000ef3f5648c3ec2af6e9a5

See more details on using hashes here.

File details

Details for the file minerals_oracle_x402-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for minerals_oracle_x402-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 33c8921c8ce30fd16ccbb9d4065ffdcd67adb7f1096e70fc24e2437d03dc9d79
MD5 70b50c455feb718c60ed6988bb37e7f0
BLAKE2b-256 05a594207696976a5095938d50c8e52a843fe5e709cb3c9d27cad4cd17f2fbfd

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page