Integration Examples
Working code for the most common integration patterns. Copy, paste, deploy.
SolidityTypeScriptPythonMCP
Code Examples
RiskGatedLending.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {IBROOracle} from "./IBROOracle.sol";
contract RiskAwareLending {
IBROOracle immutable registry;
constructor(address _registry) {
registry = IBROOracle(_registry);
}
function getCollateralHaircut(
string calldata slug
) external view returns (uint256 haircutBps) {
(uint16 bri, uint8 forgeScale,, bool stale) = registry.getScore(slug);
if (stale) revert StaleOracle();
if (bri < 650) revert CollateralTooRisky(); // TEMPERED minimum
// Base haircut: lower BRI = more haircut
haircutBps = (1000 - bri) * 3; // 0-2100 bps
// Forge Scale penalty: RAW/CAST get extra haircut
if (forgeScale <= 2) haircutBps += 500;
// Per-dimension check: D12 Cascade Exposure
uint16 cascadeScore = registry.getDimension(slug, 11);
if (cascadeScore < 50) haircutBps += (50 - cascadeScore) * 20;
}
function getMarginRequirement(
string calldata slug
) external view returns (uint256 marginPct) {
// D3 (Oracle Integrity) matters most for perps pricing
uint16 oracleScore = registry.getDimension(slug, 2);
uint16 cascadeScore = registry.getDimension(slug, 11);
// Get composite
(uint16 bri,,,) = registry.getScore(slug);
// Re-weight: 40% oracle, 30% cascade, 30% composite
uint256 weighted = (uint256(oracleScore) * 40
+ uint256(cascadeScore) * 30
+ uint256(bri - 300) * 30 / 7) / 100;
// 100/100 = 5% margin, 50/100 = 10%, 0/100 = 20%
marginPct = 500 + (100 - weighted) * 15;
}
error StaleOracle();
error CollateralTooRisky();
}What Each Example Demonstrates
SOSolidity
Risk-aware lending: dynamic haircuts from BRI + cascade dimension, per-dimension margin from oracle integrity scores via the registry
TYTypeScript
viem reads via registry: composite scores, full 12-dimension structs, per-dimension queries, batch portfolio monitoring
PYPython
web3.py via registry: composite scores, 12-dimension breakdown, evidence hashes, batch portfolio reads
MCMCP
AI tool configuration for Claude Code, Cursor, and any MCP-compatible agent