A complete MVP Copper Reference Oracle for Base Sepolia (chainId 84532).
This repo contains:
- Hardhat contracts: an on-chain store for two values (both 8 decimals):
copperUsdPerKg(USD/kg)copperBtcPerKg(BTC/kg)
- CRE-style workflow runner (TypeScript): runs hourly to fetch copper + BTC/USD, compute both values, apply guardrails, and submit on-chain.
- Lightweight read-only dApp (Vite + React): displays the latest values and refreshes every 30 seconds.
copperUsdPerKg— copper spot price normalized to USD per kilogram, scaled by1e8.copperBtcPerKg— computed ascopperUsdPerKg / btcUsd, scaled by1e8.
- Workflow outlier filter (10%): rejects updates when
|new - old| / old > 10%(first update allowed when old is 0). - On-chain minimum update interval (1 hour):
minUpdateInterval = 3600seconds enforced in Solidity.
- Fetch copper spot price from MetalpriceAPI:
XCUin USD/oz. - Convert USD/oz → USD/kg using
1 oz = 0.028349523125 kg. - Read BTC/USD from a Chainlink AggregatorV3 feed.
- Normalize BTC/USD to 8 decimals and compute
copperBtcPerKg. - Apply 10% outlier check vs the last on-chain
copperUsdPerKg. - Submit both values +
sourceHash = keccak256(utf8(JSON.stringify(raw_api_payload)))to the on-chain contract.
Important: Chainlink feed addresses are network-specific and must be verified for Base Sepolia. The example address in
.env.exampleis a common placeholder and may not be correct for Base Sepolia.
cd contracts
cp .env.example .env
npm i
npm run compile
npm run deploy:base-sepoliacd ../workflow
cp .env.example .env
npm i
# One shot
npm run run-once
# Hourly runner
npm run run-hourlycd ../dapp
cp .env.example .env
npm i
npm run devcontracts/– Solidity contract + deploy script (Hardhat)workflow/– CRE-style runner (TypeScript) withrun-onceandrun-hourlydapp/– Vite + React read-only UI
This repository includes additional documentation explaining the oracle reference pattern, trust boundaries, failure modes, and CRE compatibility:
- REFERENCE_PATTERN.md
- docs/TRUST_BOUNDARIES.md
- docs/FAILURE_MODES.md
- docs/CRE_MAPPING.md