Invarians
On-Chain Integration · Chainlink

Bring certified infrastructure state
into smart contracts and AI agents

Invarians certifies the structural execution context of blockchain infrastructure, L1 regime, L2 rollup signals, bridge liveness. This page describes how to bring that certified state on-chain via Chainlink Functions, and how it maps to the Chainlink Runtime Environment (CRE) agent model.

Chainlink Functions CRE CCIP, Q3 2026 ETH · POL · ARB · BASE · OP
The gap Invarians fills, post-EIP-4844
Since Dencun (March 2024, EIP-4844), L1 basefee is structurally decoupled from L2 activity. A complete Arbitrum sequencer outage produces zero L1 fee signature. Fee monitors and price feeds are structurally blind to L2 incidents.

Invarians measures structural regime directly from finalized block data, rhythm, saturation, continuity, and certifies a regime vector independent of fee markets. This is the dimension missing from on-chain execution logic.
What price feeds provide
Market state

Asset prices, liquidity depth, gas fees, slippage estimates. Observable, reactive, dominated by MEV and arbitrage noise at short timescales.

What Invarians provides
Infrastructure state

Structural regime of the chain substrate, 4 base codes (S1D1 · S1D2 · S2D1 · S2D2) extended with signed direction codes (S1D2+/-/±, S2±D2±) on chains with calibrated lower bounds since 2026-04-29. Three structural observables on Ethereum (rhythm, continuity, beacon participation), three on each L2 (rhythm, continuity, sequencer publish latency). Plus a per-metric Drift Signal exposing how far the chain has drifted from its 30-day baseline. Observable independently of market activity. Certified, signed, reproducible.

Empirical validation, Arbitrum, June 20 2024: L1 normal (S1D1) throughout. L2 basefee ×1649 normal. Bridge posting gap 37 minutes. Fee monitors: no ARB-specific signal at any point. Invarians detected L2 stress +6h before impact and bridge degradation in real time.
Chainlink Functions, certified state for smart contracts

Chainlink Functions executes off-chain JavaScript on a decentralized oracle network and returns the result to your smart contract. The pattern below is designed to bring the Invarians execution context on-chain with a single Functions request.

StepActorAction
1 Smart contract Calls sendRequest() on the Chainlink Functions Router
2 Functions DON Executes the JavaScript source, calls Invarians API with encrypted API key (stored as Functions secret)
3 Invarians API Returns the signed panel: panel.l1[], panel.l2[], panel.bridges[], oracle_status, signed_execution_context
4 Functions DON Encodes the response and delivers it to fulfillRequest() on the contract
5 Smart contract Stores the decoded panel.l1[].regime and panel.bridges[].state in its own storage slots, gates execution via modifier, S1D1 · S1D2 · S2D1 · S2D2 · BS1 · BS2
// Invarians × Chainlink Functions, source.js
// Deploy via Chainlink Functions Toolkit, store API key as encrypted secret

const l1Chain = args[0] || "ethereum"    // L1 to read regime from
const l2Chain = args[1] || "arbitrum"    // L2 endpoint of the CCTP route
const apiKey  = secrets.INVARIANS_API_KEY

const response = await Functions.makeHttpRequest({
  url:     `https://api.invarians.com/v2/panel`,
  headers: { "Authorization": `Bearer ${apiKey}` },
  timeout: 5000
})

if (response.error) throw new Error(`API error: ${response.error}`)

const panel = response.data

// Guard: reject DEGRADED oracle
if (panel.oracle_status !== "OK") throw new Error(`Oracle ${panel.oracle_status}, not relaying`)

// Lookup L1 regime + CCTP route state
const l1Entry = panel.panel.l1.find(e => e.chain === l1Chain)
const bridge  = panel.panel.bridges.find(b => b.id === `${l2Chain}-${l1Chain}/cctp`)

if (!l1Entry || l1Entry.status !== "OK") throw new Error(`L1 ${l1Entry?.status ?? "missing"}`)
if (!bridge  || bridge.status  !== "OK") throw new Error(`Bridge ${bridge?.status ?? "missing"}`)

// Encode: panel.l1[].regime + panel.bridges[].state as packed string
// regime:       "S1D1" | "S1D2" | "S2D1" | "S2D2"
// bridge state: "BS1"  | "BS2"
return Functions.encodeString(l1Entry.regime + "|" + bridge.state)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "@chainlink/contracts/src/v0.8/functions/FunctionsClient.sol";
import "@chainlink/contracts/src/v0.8/functions/ConfirmedOwner.sol";

contract InvariansGatedExecutor is FunctionsClient, ConfirmedOwner {

  // Last certified state from Invarians
  string public  lastL1Regime;        // "S1D1" | "S1D2" | "S2D1" | "S2D2"
  string public  lastBridgeState;     // "BS1" | "BS2"
  uint256 public lastUpdated;         // block.timestamp of last fulfilled request
  bytes32 public lastRequestId;

  event StateUpdated(string l1Regime, string bridgeState, uint256 timestamp);

  constructor(address router) FunctionsClient(router) ConfirmedOwner(msg.sender) {}

  // Modifier: gate execution on nominal L1 state
  modifier whenExecutable() {
    bytes32 s = keccak256(bytes(lastL1Regime));
    require(
      s == keccak256(bytes("S1D1")) || s == keccak256(bytes("S1D2")),
      "Invarians: panel.l1.regime not nominal"
    );
    require(block.timestamp - lastUpdated < 7200, "Invarians: state too old");
    _;
  }

  // Request a fresh state update from Invarians via Functions
  function requestStateUpdate(
    bytes32  donId,
    string memory source,      // source.js above, stored off-chain
    bytes memory  encryptedSecrets,
    string[] memory args,     // args[0] = chain name
    uint64   subscriptionId,
    uint32   gasLimit
  ) external onlyOwner returns (bytes32 requestId) {
    FunctionsRequest.Request memory req;
    req.initializeRequestForInlineJavaScript(source);
    req.addSecretsReference(encryptedSecrets);
    req.setArgs(args);
    lastRequestId = _sendRequest(req.encodeCBOR(), subscriptionId, gasLimit, donId);
    return lastRequestId;
  }

  // Callback from Chainlink Functions DON
  function fulfillRequest(bytes32 requestId, bytes memory response, bytes memory) internal override {
    if (requestId != lastRequestId) return;
    // Parse JSON response, use a JSON utility or decode off-chain then re-encode as ABI
    // Minimal pattern: store raw string, decode in UI layer
    string memory decoded = string(response);
    lastUpdated = block.timestamp;
    emit StateUpdated(lastL1Regime, lastBridgeState, lastUpdated);
  }

  // Example: gated execution function
  function executeWhenSafe() external whenExecutable {
    // Your execution logic here, only runs when panel.l1[].regime is S1D1 or S1D2
  }
}
STALE handling in the contract: the require(block.timestamp - lastUpdated < 7200) guard ensures the contract rejects execution if the last Invarians update is more than 2 hours old, independent of the on-chain data. Tune this value to your execution latency requirements. The structural regime of L1 chains changes on ~3h timescales by design.
Chainlink Runtime Environment, infrastructure sensing for AI agents

CRE is Chainlink's orchestration layer for AI agents, agents that monitor conditions, make decisions, and execute on-chain actions without human intervention. Invarians provides the infrastructure sensing layer these agents are missing: what is the execution substrate doing right now?

Current AI agents use: price · liquidity · gas estimates · slippage · mempool.

None of these detect a sequencer degradation with no L1 fee signature (S2D1 condition). None detect a bridge posting gap invisible to fee markets (BS2 condition). An agent executing during these events is operating blind, not because it lacks data, but because it is looking at the wrong layer.
# Invarians × CRE, agent sensing pattern (Python pseudocode)
# The agent queries Invarians before committing to any execution decision

import requests

INVARIANS_URL = "https://api.invarians.com"

def fetch_panel_state(api_key: str, l1_chain: str = "ethereum", l2_chain: str = "arbitrum"):
    headers = {"Authorization": f"Bearer {api_key}"}

    # Fetch full panel (L1 + L2 + bridges)
    panel = requests.get(f"{INVARIANS_URL}/panel", headers=headers).json()

    if panel.get("oracle_status") != "OK":
        return {"action": "defer", "reason": "oracle_degraded"}

    l1_entry = next((e for e in panel["panel"]["l1"] if e["chain"] == l1_chain), {})
    l2_entry = next((e for e in panel["panel"]["l2"] if e["chain"] == l2_chain), {})
    bridge   = next((b for b in panel["panel"]["bridges"]
                    if b["id"] == f"{l2_chain}-{l1_chain}/cctp"), {})

    sec = panel["signed_execution_context"]

    return {
        "l1":             l1_entry,             # { chain, regime, status, window }
        "l2":             l2_entry,             # { chain, regime, status, window }
        "bridge":         bridge,               # { id, state, calibrated, status, window }
        "signature":      sec["signature"],     # HMAC-SHA256, verifiable via /verify
        "payload_hash":   sec["payload_hash"],  # Canonical digest of the panel
        "audit_context":  panel                # Full signed panel, stored with each decision
    }

# Agent decision loop, agent applies its own policy on raw states
def agent_execution_loop():
    ctx = fetch_panel_state(api_key="inv_...")

    if ctx["l1"].get("regime", "").startswith("S1") and ctx["bridge"].get("state") == "BS1":
        execute_transaction()
        log_audit(ctx)                     # Certified context stored with each decision

    else:
        defer_execution(ctx)               # Structural stress or bridge degraded, do not execute
        log_audit(ctx)
CapabilityWithout InvariansWith Invarians
L2 sequencer health Invisible post-EIP-4844, no L1 fee signature S2D1 detected up to +6h before market impact
Bridge liveness Not measured, assumed operational BS1/BS2 state · batch posting gap detection
Execution context Price + gas only panel.l1[].regime: S1D1 · S1D2 · S2D1 · S2D2 · panel.bridges[].state: BS1 · BS2
Audit trail Transaction hash only Certified signed_execution_context at each decision point
CCIP, bridge state integration (Q3 2026)
The Invarians bridge collectors (deployed March 2026) measure variable-latency bridge cadence: Circle CCTP attestation latency via the Circle API and Chainlink CCIP sequence advance + RMN status per lane. These signals capture cross-chain operational stress invisible to fee monitors.

Integration pattern: Before initiating a cross-chain settlement, a CRE agent reads the matching entry from panel.bridges[]. If bridge.state === "BS2" (latency observable above the P97 threshold), the agent defers the settlement, the receiving chain may not finalize messages reliably during the degradation window. CCIP lanes are exposed in the panel as raw observability entries with classification deferred until sustained throughput emerges; CCTP routes carry preliminary BS1 / BS2 classification on Circle attestation API health.
The bridge layer of the panel actively classifies variable-latency bridges (CCIP, CCTP) where Invarians can provide a measurable value lever to AI agents. Both CCTP (10 routes) and CCIP (10 lanes) are captured per message (capability_level: per_message_attested): CCTP exposes the Circle ECDSA signature per message (crypto.anchor: circle_ecdsa); CCIP matches source send and destination execute by bytes32 messageId (crypto.anchor: null today). Unified BS1 / BS2 nomenclature on panel.bridges[].state; type field distinguishes the protocol.

Interested in integrating Invarians into your Chainlink Functions consumer,
CRE agent pipeline, or CCIP execution logic?

Discuss integration →