Skip to content

Oracle clamping price difference with market #1220

@mrq1911

Description

@mrq1911

EVM: Add Clamped / Aggregate Oracle (Primary feed clamped by Hydration Market EMA oracle)

Context

We want a small Solidity “aggregate oracle” contract that outputs the primary oracle price, but clamps it within a configurable max deviation from our Market EMA oracle (available via the Chainlink adapter precompile).

Problem

Current setup can allow:

  • Primary oracle reports price far from Hydration market (EMA).

We need a bounded output price so that external feeds can’t exceed a safe band around our market.

Proposed solution

Create a Solidity contract that:

  • reads from two Chainlink-style feeds (AggregatorV3Interface)
    • Oracle1 (primary): DIA/Chainlink adapter feed
    • Oracle2 (secondary): Hydration Market EMA oracle feed (chainlink_adapter precompile address for the pair)
  • clamps primary by a max deviation around secondary:

If maxDiff = 10% and:

  • primary = 1.50
  • secondary = 1.00
    Bounds: [0.90, 1.10] → output = 1.10

Math (bps):

  • lower = S * (10_000 - d) / 10_000
  • upper = S * (10_000 + d) / 10_000
  • out = clamp(P, lower, upper)

Deployment model:

  • one clamped oracle per reserve (different constructor args per reserve)
  • both feeds can be constants passed in constructor (no admin setters required)

Scope

  • New Solidity contract: ClampedOracle (Chainlink AggregatorV3Interface compatible)
  • Foundry tests (unit + fuzz)
  • Docs: short README / comments explaining clamp and how to compute EMA feed address

References

Notes from discussion

  • Both parent oracles can be constant; deploy per reserve with constructor args.
  • Clamp % can also be set via constructor.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions