Chainlink CRE lets you build and deploy autonomous workflows on a DON. Invarians adds one thing CRE doesn't have natively: a live read of the infrastructure state your workflow is about to execute on.
The sensing pattern
The integration is a single HTTP call inserted between your trigger and your execution logic. Your workflow asks Invarians for the current regime: then decides based on that.
runInNodeMode with mode aggregation ensures all DON nodes reach BFT consensus
on the regime value before your callback uses it.
Complete TypeScript workflow
Drop this pattern into any existing CRE workflow. The sensing call adds one HTTP request per trigger fire: negligible overhead, complete infrastructure observability.
import {
CronCapability, HTTPClient, handler,
consensusStringModeAggregation, Runner,
type NodeRuntime, type Runtime
} from "@chainlink/cre-sdk"
// ── Config (from config.staging.json) ──────────────────────────────
type Config = {
schedule: string
inVariansApiKey: string // your inv_* API key
targetChain: string // "arbitrum" | "ethereum" | "base" ...
}
// ── Invarians response type ─────────────────────────────────────────
type InVariansContext = {
oracle_status: "FRESH" | "STALE" | "OFFLINE"
regime: "S1D1" | "S1D2" | "S2D1" | "S2D2"
l2_regime: string
bridge_state: "BS1" | "BS2"
}
// ── Step 1: Fetch Invarians context (runs on every DON node) ────────
const fetchInVariansContext = (
nodeRuntime: NodeRuntime<Config>
): InVariansContext => {
const http = new HTTPClient()
const chain = nodeRuntime.config.targetChain
const resp = http.sendRequest(nodeRuntime, {
url: `https://sdpilypwumxsyyipceew.supabase.co/functions/v1/attestation/${chain}`,
method: "GET" as const,
headers: {
"x-api-key": nodeRuntime.config.inVariansApiKey,
}
}).result()
const data = JSON.parse(
new TextDecoder().decode(resp.body)
)
return {
oracle_status: data.oracle_status,
regime: data.regime,
l2_regime: data.proof_of_execution_context?.l2_regime ?? "N/A",
bridge_state: data.proof_of_execution_context?.bridge_state ?? "BS1",
}
}
// ── Step 2: Main callback ────────────────────────────────────────────
const onTrigger = (runtime: Runtime<Config>): string => {
// Query Invarians: BFT consensus across DON nodes on regime string
const ctx = runtime.runInNodeMode(
fetchInVariansContext,
consensusStringModeAggregation() // mode = most common value across nodes
)().result()
runtime.log(`Invarians: ${ctx.oracle_status}: L1:${ctx.regime} L2:${ctx.l2_regime} Bridge:${ctx.bridge_state}`)
// ── Gate 1: Oracle freshness ─────────────────────────────────────
if (ctx.oracle_status !== "FRESH") {
runtime.log("Oracle STALE: deferring execution")
return "deferred:oracle_stale"
}
// ── Gate 2: L1 structural stress ─────────────────────────────────
if (ctx.regime === "S2D1" || ctx.regime === "S2D2") {
runtime.log(`Structural stress detected (${ctx.regime}): deferring`)
return `deferred:structural_stress:${ctx.regime}`
}
// ── Gate 3: Bridge state (cross-chain workflows) ──────────────────
if (ctx.bridge_state === "BS2") {
runtime.log("Bridge degraded: deferring cross-chain execution")
return "deferred:bridge_degraded"
}
// ── Infrastructure nominal: proceed ──────────────────────────────
runtime.log(`Nominal (${ctx.regime}): executing`)
// ... your business logic here (onchain write, CCIP, computation)
return `executed:${ctx.regime}`
}
// ── Workflow entry point ─────────────────────────────────────────────
const initWorkflow = (config: Config) => {
const cron = new CronCapability()
return [handler(cron.trigger({ schedule: config.schedule }), onTrigger)]
}
export async function main() {
const runner = await Runner.newRunner<Config>()
await runner.run(initWorkflow)
}
{
"schedule": "*/30 * * * * *",
"inVariansApiKey": "inv_your_key_here",
"targetChain": "arbitrum"
}
The three gates
Each gate handles a distinct failure mode. None of these are visible to fee monitors or accessible without a dedicated sensing layer.
Before / after
Setup
inv_.
main.ts.
Add your Invarians API key and target chain to config.staging.json.
Invarians API is live. L1 + L2 + Bridge across 7 networks. Signed attestations. Free tier for development.