Proposal: fail-closed cross-oracle preflight in RiskEngine.validateTrade()
Problem
Clodds already has the right enforcement points for this: a unified RiskEngine.validateTrade(), multi-venue execution, circuit breakers, and a decision ledger with hash verification/onchain anchoring.
One risk axis is still external to the current controls: whether the price evidence entering a trade is trustworthy at decision time. Position limits, VaR, slippage, and routing can all pass while a reference price is stale, materially divergent, or backed by a nominal quorum of sources operated by the same underlying party.
This is most relevant to oracle-dependent spot, perp, swap, lending, and copy-trading routes. Prediction-market orders could remain out of scope unless they use an external crypto reference price.
Proposal
Add an optional, provider-neutral OraclePreflightProvider to the central pre-trade path. When enabled for an applicable route, it would run after market/asset resolution and before any order is signed or submitted.
Suggested policy:
PASS: continue.CAUTION: continue with warnings and/or an optional size multiplier chosen by Clodds.DANGERorBLOCK: reject before execution.- Missing, unverifiable, or expired evidence: reject when
required: true(fail closed). - Persist the evidence UID, schema version, digest, verdict, and expiry in the existing ledger entry; bind the resulting order/transaction identifier after execution.
A minimal provider-neutral interface could look like:
interface OraclePreflightProvider {
check(input: {
assetIn: string;
assetOut: string;
chainId?: number;
venue: string;
side: 'buy' | 'sell';
size: number;
quotedPrice?: number;
}): Promise<{
verdict: 'PASS' | 'CAUTION' | 'DANGER' | 'BLOCK';
uid: string;
schemaVersion: string;
issuedAt: number;
expiresAt: number;
digest: string;
warnings: string[];
rawReceipt: unknown;
}>;
}
This keeps the Clodds core vendor-neutral; Insight would be one adapter rather than a hard-coded dependency.
Why Insight fits this hook
Insight is a cross-oracle safety layer for AI agents and trading bots. It currently provides:
- Cross-oracle coverage through 10 provider integrations across 40+ networks.
- Machine-readable
PASS / CAUTION / DANGER / BLOCKpre-trade verdicts. - EIP-712 signed
OracleSafetyCheckreceipts with a default 600-second validity window. - An opt-in v3 signed schema whose quorum and independence thresholds are carried in the signed bytes: at least 3 participating providers and at least 2 distinct non-derived operator groups.
- A zero-network local verifier:
verify-insight-receipt. Signature verification does not require an Insight API key. - Execution receipts that bind the pre-trade receipt UID to the submitted transaction hash.
The intended security boundary is narrow: the receipt proves what Insight observed and signed, and allows the consumer to enforce a deterministic policy. It does not claim that a valid signature makes the underlying market risk-free.
Smallest useful prototype
I would be happy to contribute a focused PR containing:
- The provider interface and config flag (disabled by default).
- An Insight adapter with timeouts and local receipt verification.
- A call from the centralized pre-trade path for one EVM spot/swap route.
- Ledger metadata for the evidence UID/digest/verdict.
- Tests proving that DANGER/BLOCK, expiry, invalid signatures, timeout, and unavailable service cannot reach the submitter when fail-closed mode is enabled.
For an end-to-end trial, we can start with one asset pair in paper/demo mode, then run a deliberately stale/divergent fixture to demonstrate a blocked order and a verifiable ledger record.
Would this fit the direction of the risk engine? If so, I can first open a small design PR around the interface and tests, without changing default behavior.
Disclosure: I am YuTao Peng, founder of Insight.
Thanks for the detailed proposal. This is an external provider integration and product-design request rather than a defect in the current implementation. PR #119 / issue #116 added a process-wide fail-closed pre-trade gate for the currently supported futures and swap routes, which is the appropriate extension point for future evidence providers. We are not adding an Insight-specific adapter, receipt schema, or ledger coupling to core without a separate maintainer-owned threat model and roadmap decision. Closing as not planned; a future provider-neutral design can be proposed again if that becomes a roadmap priority.
Thanks for the clear explanation, and for pointing me to the new process-wide pre-trade gate. I understand the distinction and the decision not to add provider-specific coupling without a maintainer-owned threat model and roadmap priority.\n\nI appreciate you taking the time to review the proposal. I will leave this closed and will not pursue an Insight-specific integration here. If provider-neutral external evidence becomes relevant to the roadmap in the future, I would be happy to revisit it from that direction. Thanks again.