CRE Workflow

File: cre/vault-sentinel-workflow.yaml Trigger: Cron — every 60 seconds Purpose: Compute Systemic Risk Index and write it on-chain


Overview

The CRE (Compute Runtime Environment) workflow is the autonomous engine of GuardAI. It runs every minute, aggregates risk signals from multiple sources, computes a weighted score, and writes it to VaultSentinel.setRiskScore() on-chain.

If the score reaches 70 or above, the smart contract automatically triggers an emergency withdrawal — no human action needed.


Workflow Steps

Step 1: fetch_eth_price    → Chainlink Data Feed (ETH/USD)
Step 2: fetch_lido_tvl     → DeFiLlama HTTP API
Step 3: fetch_aave_tvl     → DeFiLlama HTTP API
Step 4: fetch_maker_tvl    → DeFiLlama HTTP API
Step 5: compute_systemic_risk → JavaScript (weighted score)
Step 6: write_risk_score   → eth-transaction (setRiskScore)
Step 7: log_result         → JavaScript (console debug)

Uses the official Chainlink ETH/USD aggregator on Ethereum mainnet. Returns: { answer, decimals, updatedAt } — price is answer / 10^decimals.


Steps 2–4 — Protocol TVL from DeFiLlama

Each response exposes currentChainTvls.Ethereum — the current TVL locked on Ethereum mainnet.


Step 5 — Compute Systemic Risk Index

The core of GuardAI's risk model. Runs in a JavaScript compute step:

Risk Factors & Weights

Factor
Weight
Baseline
Score Formula

ETH Price Drop

30%

$3,500

min(100, priceDrop% × 2.5)

Lido TVL Drain

25%

$10B

min(100, drain% × 2)

Aave TVL Drain

25%

$8B

min(100, drain% × 2)

MakerDAO TVL Drain

20%

$6B

min(100, drain% × 2)

Final Score

RiskScore=(priceScore×0.30)+(lidoScore×0.25)+(aaveScore×0.25)+(makerScore×0.20)\text{RiskScore} = (\text{priceScore} \times 0.30) + (\text{lidoScore} \times 0.25) + (\text{aaveScore} \times 0.25) + (\text{makerScore} \times 0.20)

Score is always an integer from 0 to 100.

Example Output


Step 6 — Write Score On-Chain

Calls VaultSentinel.setRiskScore() with the computed score. The contract handles the rest — including emergency withdrawal if threshold is breached.


Environment Variables

Variable
Description

env.TENDERLY_RPC_URL

RPC endpoint for the target network

env.VAULT_SENTINEL_ADDRESS

Deployed VaultSentinel contract address

secrets.CRE_WALLET_PRIVATE_KEY

Private key of the authorized CRE wallet

⚠️ The CRE wallet address must match authorizedCaller set in the contract. Update with setAuthorizedCaller() if changed.


Console Log Output (Step 7)

When running, the workflow logs a detailed breakdown:


Simulating the Workflow Locally

Since CRE workflows require a live CRE node, use the Hardhat script to simulate setRiskScore() directly:

See Scripts Reference for full details.

Last updated