Skip to content
Verified contractPartialUNLICENSED

ChainlinkEthUsdOracle

Address0x899e6f258e4fa77dfa3f94fbacbbae37a87dfd9a
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.26

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
Via IR
yes
License
UNLICENSED
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,329,889
Creation transaction
0xcdee3bd703…e5ca9ed54a

src/pass/ChainlinkEthUsdOracle.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

import {IEthUsdOracle} from "./IEthUsdOracle.sol";

/// @notice The Chainlink aggregator reads the adapter needs.
interface AggregatorV3Interface {
    function decimals() external view returns (uint8);
    function description() external view returns (string memory);
    function latestRoundData() external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}

/// @title ChainlinkEthUsdOracle — ETH/USD from a Chainlink price feed, as 6-decimal dollars
/// @notice Reads `latestRoundData` and refuses an answer that is not positive or older than `maxAge` seconds, so a
///         stalled feed turns ETH payments off instead of pricing them wrong. `PassPayment` additionally bounds the
///         result to an owner-set sane range. Ethereum: the ETH/USD feed 0x5f4eC3Df…8419 (1 h heartbeat, 0.5% deviation);
///         Sepolia: 0x694AA176…5306 (same heartbeat, tracks mainnet).
/// @dev Immutable: a different feed or age limit is a new adapter plus `PassPayment.setEthOracle`.
contract ChainlinkEthUsdOracle is IEthUsdOracle {
    AggregatorV3Interface public immutable feed;
    uint256 public immutable maxAge;
    uint8 public immutable feedDecimals;

    error BadFeed();
    error StalePrice(uint256 updatedAt, uint256 maxAge);
    error BadAnswer(int256 answer);

    constructor(address feed_, uint256 maxAge_) {
        if (feed_ == address(0) || maxAge_ == 0) revert BadFeed();
        feed = AggregatorV3Interface(feed_);
        maxAge = maxAge_;
        feedDecimals = AggregatorV3Interface(feed_).decimals();
        if (feedDecimals > 30) revert BadFeed();
    }

    /// @inheritdoc IEthUsdOracle
    function ethUsd6() external view returns (uint256) {
        (, int256 answer,, uint256 updatedAt,) = feed.latestRoundData();
        if (answer <= 0) revert BadAnswer(answer);
        if (updatedAt == 0 || updatedAt > block.timestamp || block.timestamp - updatedAt > maxAge) revert StalePrice(updatedAt, maxAge);
        uint256 a = uint256(answer);
        return feedDecimals >= 6 ? a / 10 ** (feedDecimals - 6) : a * 10 ** (6 - feedDecimals);
    }
}

/// @notice Stand-in Chainlink feed for dev chains and tests: a settable answer and update time.
contract MockAggregator is AggregatorV3Interface {
    uint8 public immutable decimals;
    int256 public answer;
    uint256 public updatedAt;
    uint80 public round;
    address public immutable setter;
    constructor(uint8 d, int256 a) { decimals = d; setter = msg.sender; set(a); }
    function description() external pure returns (string memory) { return "ETH / USD (mock)"; }
    function set(int256 a) public { require(msg.sender == setter); answer = a; updatedAt = block.timestamp; round++; }
    function setUpdatedAt(uint256 t) external { require(msg.sender == setter); updatedAt = t; }
    function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80) { return (round, answer, updatedAt, updatedAt, round); }
}

src/pass/IEthUsdOracle.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

/// @notice ETH priced in 6-decimal dollars. `PassPayment` only depends on this.
interface IEthUsdOracle {
    /// @return usd6 dollars (6 decimals) per 1 ETH
    function ethUsd6() external view returns (uint256 usd6);
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@uniswap/v4-core/=lib/v4-periphery/lib/v4-core/",
    "@uniswap/v4-periphery/=lib/v4-periphery/",
    "uniswap-hooks/=lib/uniswap-hooks/",
    "permit2/=lib/v4-periphery/lib/permit2/",
    "forge-std/=lib/forge-std/src/",
    "solmate/=lib/v4-periphery/lib/v4-core/lib/solmate/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/lib/forge-std/:ds-test/=lib/uniswap-hooks/lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/lib/forge-std/lib/ds-test/src/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/lib/forge-std/:ds-test/=lib/uniswap-hooks/lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/lib/forge-std/lib/ds-test/src/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    "lib/uniswap-hooks/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/uniswap-hooks/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    "lib/uniswap-hooks/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/uniswap-hooks/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/permit2/lib/forge-std/:ds-test/=lib/uniswap-hooks/lib/v4-periphery/lib/permit2/lib/forge-std/lib/ds-test/src/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/permit2/lib/forge-std/:ds-test/=lib/uniswap-hooks/lib/v4-periphery/lib/permit2/lib/forge-std/lib/ds-test/src/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/permit2/lib/solmate/:ds-test/=lib/uniswap-hooks/lib/v4-periphery/lib/permit2/lib/solmate/lib/ds-test/src/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/permit2/lib/solmate/:ds-test/=lib/uniswap-hooks/lib/v4-periphery/lib/permit2/lib/solmate/lib/ds-test/src/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/lib/solmate/:ds-test/=lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/lib/solmate/lib/ds-test/src/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/lib/solmate/:ds-test/=lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/lib/solmate/lib/ds-test/src/",
    "lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/lib/forge-std/:ds-test/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/lib/forge-std/lib/ds-test/src/",
    "lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/lib/forge-std/:ds-test/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/lib/forge-std/lib/ds-test/src/",
    "lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    "lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    "lib/uniswap-hooks/lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=lib/uniswap-hooks/lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/uniswap-hooks/lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=lib/uniswap-hooks/lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/uniswap-hooks/lib/v4-core/lib/solmate/:ds-test/=lib/uniswap-hooks/lib/v4-core/lib/solmate/lib/ds-test/src/",
    "lib/uniswap-hooks/lib/v4-core/lib/solmate/:ds-test/=lib/uniswap-hooks/lib/v4-core/lib/solmate/lib/ds-test/src/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/permit2/:forge-gas-snapshot/=lib/uniswap-hooks/lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/permit2/:forge-gas-snapshot/=lib/uniswap-hooks/lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/permit2/:openzeppelin-contracts/=lib/uniswap-hooks/lib/v4-periphery/lib/permit2/lib/openzeppelin-contracts/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/permit2/:openzeppelin-contracts/=lib/uniswap-hooks/lib/v4-periphery/lib/permit2/lib/openzeppelin-contracts/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/:openzeppelin-contracts/=lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/",
    "lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/:openzeppelin-contracts/=lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/",
    "lib/v4-periphery/lib/permit2/lib/forge-std/:ds-test/=lib/v4-periphery/lib/permit2/lib/forge-std/lib/ds-test/src/",
    "lib/v4-periphery/lib/permit2/lib/forge-std/:ds-test/=lib/v4-periphery/lib/permit2/lib/forge-std/lib/ds-test/src/",
    "lib/v4-periphery/lib/permit2/lib/solmate/:ds-test/=lib/v4-periphery/lib/permit2/lib/solmate/lib/ds-test/src/",
    "lib/v4-periphery/lib/permit2/lib/solmate/:ds-test/=lib/v4-periphery/lib/permit2/lib/solmate/lib/ds-test/src/",
    "lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/v4-periphery/lib/v4-core/lib/solmate/:ds-test/=lib/v4-periphery/lib/v4-core/lib/solmate/lib/ds-test/src/",
    "lib/v4-periphery/lib/v4-core/lib/solmate/:ds-test/=lib/v4-periphery/lib/v4-core/lib/solmate/lib/ds-test/src/",
    "lib/uniswap-hooks/lib/openzeppelin-contracts/:erc4626-tests/=lib/uniswap-hooks/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/uniswap-hooks/lib/openzeppelin-contracts/:erc4626-tests/=lib/uniswap-hooks/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/uniswap-hooks/lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/uniswap-hooks/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "lib/uniswap-hooks/lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/uniswap-hooks/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "lib/uniswap-hooks/lib/v4-core/:openzeppelin-contracts/=lib/uniswap-hooks/lib/v4-core/lib/openzeppelin-contracts/",
    "lib/uniswap-hooks/lib/v4-core/:openzeppelin-contracts/=lib/uniswap-hooks/lib/v4-core/lib/openzeppelin-contracts/",
    "lib/uniswap-hooks/lib/v4-periphery/:v4-core/=lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/src/",
    "lib/uniswap-hooks/lib/v4-periphery/:v4-core/=lib/uniswap-hooks/lib/v4-periphery/lib/v4-core/src/",
    "lib/v4-periphery/lib/permit2/:forge-gas-snapshot/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
    "lib/v4-periphery/lib/permit2/:forge-gas-snapshot/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
    "lib/v4-periphery/lib/permit2/:openzeppelin-contracts/=lib/v4-periphery/lib/permit2/lib/openzeppelin-contracts/",
    "lib/v4-periphery/lib/permit2/:openzeppelin-contracts/=lib/v4-periphery/lib/permit2/lib/openzeppelin-contracts/",
    "lib/v4-periphery/lib/v4-core/:openzeppelin-contracts/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/",
    "lib/v4-periphery/lib/v4-core/:openzeppelin-contracts/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/",
    "lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "lib/uniswap-hooks/:openzeppelin-contracts/=lib/uniswap-hooks/lib/openzeppelin-contracts/",
    "lib/uniswap-hooks/:openzeppelin-contracts/=lib/uniswap-hooks/lib/openzeppelin-contracts/",
    "lib/uniswap-hooks/:v4-core/=lib/uniswap-hooks/lib/v4-core/src/",
    "lib/uniswap-hooks/:v4-core/=lib/uniswap-hooks/lib/v4-core/src/",
    "lib/uniswap-hooks/:v4-periphery/=lib/uniswap-hooks/lib/v4-periphery/",
    "lib/uniswap-hooks/:v4-periphery/=lib/uniswap-hooks/lib/v4-periphery/",
    "lib/v4-periphery/:v4-core/=lib/v4-periphery/lib/v4-core/src/",
    "lib/v4-periphery/:v4-core/=lib/v4-periphery/lib/v4-core/src/",
    "@ensdomains/=lib/uniswap-hooks/lib/v4-core/node_modules/@ensdomains/",
    "@openzeppelin/=lib/uniswap-hooks/lib/v4-core/lib/openzeppelin-contracts/",
    "ds-test/=lib/uniswap-hooks/lib/v4-core/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-gas-snapshot/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "hardhat/=lib/uniswap-hooks/lib/v4-core/node_modules/hardhat/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "v4-core/=lib/uniswap-hooks/lib/v4-core/src/",
    "v4-periphery/=lib/v4-periphery/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.