AI-powered risk intelligence and signals for tokenized equities (xStocks) on X Layer.
XIRA continuously analyzes 15 high-visibility xStocks, generates explainable multi-factor risk scores with short rationales, and publishes compact on-chain attestations so agents, DeFi protocols, and users can act on them in real time.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Data Layer β
β yfinance (price/volume) β Sentiment signals β
β On-chain X Layer data β Market news proxies β
ββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AI Engine β
β Multi-factor scoring (momentum, sentiment, volume, β
β liquidity) + explanation generation + anomaly detection β
ββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Attestation Engine β
β Evidence hashing β On-chain publisher contract β
ββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β On-Chain Layer (X Layer) β
β XIRA.sol β stores latest attestation per asset β
β Verifiable by agents, protocols, composable in DeFi β
ββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Interface Layer β
β REST API (FastAPI) β Next.js Dashboard β
β Agent-friendly JSON β MCP-ready endpoints β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
xira/
βββ contracts/ # Solidity smart contracts (Foundry)
β βββ src/XIRA.sol # Core attestation contract
β βββ script/Deploy.s.sol # Deployment scripts
β βββ test/XIRA.t.sol # Tests
β βββ foundry.toml # Foundry config
βββ backend/ # FastAPI backend
β βββ app/
β β βββ main.py # API entry point
β β βββ models.py # Pydantic models
β β βββ routers/
β β β βββ assets.py # /api/assets/* endpoints
β β β βββ attestations.py # /api/attestations/* endpoints
β β βββ services/
β β βββ data_fetcher.py # Price + sentiment ingestion
β β βββ ai_engine.py # Multi-factor AI scoring
β β βββ publisher.py # On-chain publisher
β βββ requirements.txt
βββ frontend/ # Next.js dashboard
β βββ app/
β β βββ page.tsx # Dashboard (all assets)
β β βββ layout.tsx # Root layout
β β βββ asset/[symbol]/ # Asset detail page
β βββ components/
β β βββ ScoreCard.tsx # Risk score card
β β βββ FactorBreakdown.tsx # Charts + alerts
β βββ lib/
β βββ api.ts # API client
β βββ types.ts # TypeScript types
βββ README.md
- Node.js 18+
- Python 3.10+
- Foundry (
curl -L https://foundry.paradigm.xyz | bash) - An X Layer testnet RPC endpoint (or use the public one)
See DEPLOYMENT.md for complete deployment instructions.
Quick deploy:
cd contracts
export PRIVATE_KEY=your_testnet_key
forge script script/DeployAll.s.sol --rpc-url https://testrpc.xlayer.tech --broadcast --legacyOracle wallet: 0x0CE306F2863a98e847F454dF74E93Ff1461ED3c0
cd backend
# Create virtual environment
python3 -m venv venv
source venv/bin/activate # or `venv\Scripts\activate` on Windows
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .env
# Edit .env with your RPC URL, private key, and contract address
# The backend works in OFF-CHAIN MODE without a wallet β scores are still generated
# Run the server
python -m app.main
# API available at http://localhost:8000
# Docs at http://localhost:8000/docscd frontend
# Install dependencies
npm install
# Run dev server
npm run dev
# Dashboard at http://localhost:3000| Symbol | Underlying | Sector |
|---|---|---|
| NVDAx | NVDA | Technology |
| TSLAx | TSLA | Consumer Cyclical |
| AAPLx | AAPL | Technology |
| MSFTx | MSFT | Technology |
| GOOGLx | GOOGL | Communication |
| AMZNx | AMZN | Consumer Cyclical |
| METAx | META | Communication |
| SPYx | SPY | ETF (S&P 500) |
| QQQx | QQQ | ETF (Nasdaq-100) |
| AMDx | AMD | Technology |
| INTCx | INTC | Technology |
| NFLXx | NFLX | Communication |
| BAx | BA | Industrials |
| JPMx | JPM | Financial |
| XOMx | XOM | Energy |
struct Attestation {
uint8 score; // 0-100 risk score
uint8 confidence; // 0-100 confidence level
bytes32 evidenceHash; // SHA-256 of evidence payload
uint64 timestamp; // Unix timestamp
string modelVersion; // Model version string
bool anomaly; // Anomaly flag
string anomalyReason; // Anomaly explanation
}Functions:
updateAttestation(asset, score, confidence, evidenceHash, modelVersion, anomaly, anomalyReason)β Write latest attestation (authorized only)batchUpdateAttestations(...)β Write multiple attestations in one txgetLatestAttestation(asset)β Read full attestation structgetScore(asset)β Quick score readgetScoreBatch(assets[])β Batch score readregisterAsset(tokenAddr, symbol)β Register a new tracked asset
Returns risk scores for all 15 tracked assets plus a market summary.
Returns detail for a single asset: underlying, sector, token address, current risk score, 24h price change, and the score delta vs the previous attestation.
Market-level statistics: average score, distribution across risk levels, anomaly count, and best/worst scoring assets.
Returns all currently flagged anomaly alerts, sorted by risk score descending.
Returns detailed attestation for a single asset (runs AI analysis on demand, publishes on-chain).
Returns last N attestations for an asset.
Health check with model version and tracked asset count.
SQLite history database statistics (record count, oldest/newest records).
The /api/assets/all endpoint returns JSON consumable by AI agents and DeFi protocols:
{
"generated_at": 1723315200,
"model_version": "v1.0.0",
"summary": "Market outlook: Moderate risk. Average score 47/100 across 15 assets. 2 anomaly alerts active.",
"assets": [
{
"symbol": "NVDAx",
"risk_score": 42,
"risk_level": "MODERATE",
"confidence": 78,
"factors": [
{
"name": "momentum",
"label": "Momentum",
"score": 55,
"weight": 0.30,
"description": "Neutral momentum: +1.23% 24h change."
},
{
"name": "sentiment",
"label": "Sentiment",
"score": 48,
"weight": 0.25,
"description": "Mixed or neutral sentiment signals."
},
{
"name": "volume_anomaly",
"label": "Volume Anomaly",
"score": 38,
"weight": 0.25,
"description": "Below-average volume: 0.35x average."
},
{
"name": "liquidity_proxy",
"label": "Liquidity Proxy",
"score": 30,
"weight": 0.20,
"description": "Low dollar turnover. Moderate slippage risk."
}
],
"explanation": "NVDAx shows moderate risk (score 42/100). The underlying gained 1.2% in the last 24h. Key concern: liquidity proxy (30/100). Strength: momentum (55/100).",
"anomaly": false,
"anomaly_reason": "",
"evidence_hash": "a1b2c3d4e5f6...",
"timestamp": 1723315200,
"model_version": "v1.0.0"
}
]
}| Factor | Weight | Description |
|---|---|---|
| Momentum | 30% | Short/long MA ratio, 52-week position, 24h change |
| Sentiment | 25% | News/market sentiment signal |
| Volume Anomaly | 25% | Current volume vs 20-day average |
| Liquidity Proxy | 20% | Dollar turnover estimation |
Each factor scores 0-100. The weighted average produces the overall Risk Score. A score of 0 = very low risk, 100 = critical risk.
Risk Levels:
- 0β20: LOW (green)
- 21β40: MODERATE (yellow)
- 41β60: ELEVATED (orange)
- 61β80: HIGH (red)
- 81β100: CRITICAL (dark red)
| Variable | Default | Description |
|---|---|---|
XLAYER_RPC_URL |
https://testrpc.xlayer.tech |
X Layer testnet RPC |
XIRA_CONTRACT_ADDRESS |
0x00... |
Deployed contract |
PRIVATE_KEY |
(empty) | Deployer/updater key |
AI_MODE |
heuristic |
heuristic or openai |
OPENAI_API_KEY |
(empty) | For LLM explanations |
MODEL_VERSION |
v1.0.0 |
Model version tag |
PORT |
8000 |
API port |
The backend works without a wallet or contract address. Set PRIVATE_KEY= and XIRA_CONTRACT_ADDRESS=0x00... to run in off-chain mode. Scores, explanations, and history are still generated and served via the API. On-chain publishing is simply skipped.
- Start the backend:
python -m app.main - Start the frontend:
npm run dev - Open
http://localhost:3000β see the dashboard with all 15 assets - Click any asset card for detailed factor breakdown + history
- Hit
http://localhost:8000/api/assets/allfor the agent-friendly JSON - Read attestations on-chain via the XIRA contract
MIT