The "Brain" of ShieldYield. This repository contains the Chainlink Runtime Environment (CRE) workflows that monitor DeFi protocols, calculate risk scores, and execute emergency protection actions.
- Chainlink SDK:
@chainlink/cre-sdk - Runtime: Bun / TypeScript
- Network: Arbitrum Sepolia (Staging) / CCIP Integration
The engine runs three primary workflows defined in main.ts:
- Trigger: Cron (Every 5 minutes).
- Function:
- Scans all active protocol adapters (Aave, Compound, etc.).
- Fetches TVL data, utilization rates, and external AI threat scores.
- Aggregates signals into a 0-100 Risk Score.
- If the score deviates significantly, it performs an on-chain broadcast to the
RiskRegistry.
- Trigger: On-Chain Event (
RiskScoreUpdated). - Function:
- Listens for updates in the
RiskRegistry. - If risk levels change (e.g., from SAFE to WATCH), it calculates new optimal weights.
- Calls
ShieldVault.rebalance()to shift funds between protocols for optimal yield-to-risk ratio.
- Listens for updates in the
- Trigger: On-Chain Event (
RiskScoreUpdated). - Function:
- Handles high-risk scenarios (WARNING/CRITICAL).
- WARNING: Triggers
partialWithdraw(50%) from the affected protocol to the vault's internal cash reserve. - CRITICAL: Triggers
emergencyWithdraw(100%) and moves funds to the Safe Haven. - EXTREME: Initiates
bridgeToSafeChainvia CCIP to evacuate funds to another blockchain.
Located in shieldyield-workflow/simulation/, these scripts allow for end-to-end testing without waiting for real-world exploits:
sim-daemon.ts🧊: Starts the local simulation environment including a mock variance server.sim-inject.ts💉: The primary CLI tool to inject risk scenarios.bun simulation/sim-inject.ts warning --trigger: Simulate a protocol warning.bun simulation/sim-inject.ts critical --trigger: Simulate a critical exploit.
sim-finalize-base.ts✅: Oracle instruction to finalize cross-chain claims on the destination chain (Base).sim-fetcher.ts📡: Mocks the ingestion of external DeFi metrics (TVL, APY).
The CRE simulation environment is designed to be fully integrated with the ShieldYield Dashboard:
- Mock Variance Server (Port 3099): The
sim-daemonstarts a server that hosts the current injected scenario state. - Frontend Proxy: The Next.js API routes (e.g.,
/api/ai-sentinel) act as a proxy that polls the CRE's Mock Server. - Synchronization: This ensures that when you run
sim-inject.ts, the frontend immediately reflects the exact same AI threat scores and reasoning being "seen" by the CRE workflows.
bun installbun run sim:daemonbun run sim:broadcast:staging🤖 Automated Intelligence. Decentralized Security.