Skip to content
CA$COMVEX · TBA
Kit · step 1

Write a cutoff policy

A policy is one feed and one maximum age. Your contract accepts the feed's latest answer while its round is at most that many seconds old and refuses it from the next second on.
Feed address
0x78F3556b67E17Df817D51Ef5a990cDaF09E8d3A9
Latest round age now
reading…
Documented heartbeat / deviation
1 d 0 h / 0.5%
Measured over the last … rounds
median — · longest —

Generated files

Written in your browser from the feed and the limit above. The repository compiles one output of this generator (ETH / USD, 60 s) and runs its test in forge, on a stand-in feed and on a Robinhood Chain fork.

src/EthUsdMax60Cutoff.sol
// SPDX-License-Identifier: MIT
// Cutoff policy for Robinhood Chain (chain id 4663), written by the COMVEX policy page.
// Feed ETH / USD at 0x78F3556b67E17Df817D51Ef5a990cDaF09E8d3A9 (8 decimals). Documented heartbeat 86400 s.
// Rule: a price whose round is older than 60 seconds is refused (age == 60 is still accepted).
pragma solidity ^0.8.20;

interface IEthUsdMax60Feed {
    function latestRoundData() external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}

/// @notice ETH / USD, maximum age 60 seconds. Call freshPrice() wherever your contract reads this feed.
library EthUsdMax60Cutoff {
    address internal constant FEED = 0x78F3556b67E17Df817D51Ef5a990cDaF09E8d3A9;
    uint256 internal constant MAX_AGE = 60;
    uint8 internal constant DECIMALS = 8;

    error StalePrice(uint256 age, uint256 maxAge);
    error FutureRound(uint256 updatedAt, uint256 blockTime);
    error EmptyRound();
    error NonPositiveAnswer(int256 answer);

    /// @notice The latest answer and its round time, or a revert that names the reason.
    function freshPrice() internal view returns (int256 answer, uint256 updatedAt) {
        (, answer,, updatedAt,) = IEthUsdMax60Feed(FEED).latestRoundData();
        if (updatedAt == 0) revert EmptyRound();
        if (updatedAt > block.timestamp) revert FutureRound(updatedAt, block.timestamp);
        uint256 age = block.timestamp - updatedAt;
        if (age > MAX_AGE) revert StalePrice(age, MAX_AGE);
        if (answer <= 0) revert NonPositiveAnswer(answer);
    }
}

/// @notice Callable form of the rule. Deploy it, or compile it and paste its runtime bytecode into a COMVEX boundary run
///         (it has no constructor and no storage, so the runtime code alone behaves exactly like a deployment).
contract EthUsdMax60CutoffGuard {
    function readFresh() external view returns (int256 answer, uint256 updatedAt) {
        return EthUsdMax60Cutoff.freshPrice();
    }
}

Register the policy on chain

Optional. A registered policy gets a number that boundary reports point to. Anyone can register the same feed and limit again; the registry keeps every entry with its author.

registerPolicydry run · no wallet needed
to
ComvexCutoffRegistry (not deployed yet)
function
registerPolicy(address feed, uint32 maxAge, string label)
feed
0x78F3556b67E17Df817D51Ef5a990cDaF09E8d3A9 (ETH / USD)
maxAge
60
label
"EthUsdMax60"
value
0 ETH (gas only, paid in ETH on Robinhood Chain)
call data · 164 bytes
0xa87bdd0600000000000000000000000078f3556b67e17df817d51ef5a990cdaf09e8d3a9000000000000000000000000000000000000000000000000000000000000003c0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000b4574685573644d61783630000000000000000000000000000000000000000000
Signing opens once ComvexCutoffRegistry has an address on Robinhood Chain. The call data above is final.