Skip to content
Verified contractExactMIT

ChainlinkCompositeFeed

Address0xcfb2a2e0e3be32430bc3db946da48e9a3e04ff53
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.30

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.30+commit.73712a01
Language
solidity
Optimization
Yes, 100 runs
EVM version
prague
Via IR
yes
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,335,674
Creation transaction
0x141285a69b…924cbf7818

contracts/oracle/ChainlinkCompositeFeed.sol

// SPDX-License-Identifier: MIT
//
//   Constant Finance — fixed-term, order-book lending on Ethereum
//   App:  https://app.constant.finance/en
//   X:    https://x.com/constant_fi
//
pragma solidity ^0.8.29;

import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

/**
 * @title ChainlinkCompositeFeed
 * @notice Multiplies two Chainlink feeds, e.g. WBTC/BTC * BTC/USD = WBTC/USD. Answer has 8 decimals.
 *         `updatedAt` is the older of the two inputs so staleness checks stay conservative.
 */
contract ChainlinkCompositeFeed is AggregatorV3Interface {
    AggregatorV3Interface public immutable BASE; // e.g. WBTC / BTC
    AggregatorV3Interface public immutable QUOTE; // e.g. BTC / USD
    uint8 public constant override decimals = 8;
    string public override description;

    constructor(address base_, address quote_, string memory description_) {
        require(base_ != address(0) && quote_ != address(0), "feed: zero");
        BASE = AggregatorV3Interface(base_);
        QUOTE = AggregatorV3Interface(quote_);
        description = description_;
    }

    function version() external pure override returns (uint256) {
        return 1;
    }

    function getRoundData(uint80) external pure override returns (uint80, int256, uint256, uint256, uint80) {
        revert("feed: historical data unsupported");
    }

    function latestRoundData()
        external
        view
        override
        returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
    {
        (uint80 r0, int256 a0, uint256 s0, uint256 u0,) = BASE.latestRoundData();
        (, int256 a1, uint256 s1, uint256 u1,) = QUOTE.latestRoundData();
        require(a0 > 0 && a1 > 0, "feed: bad answer");
        uint256 scale = 10 ** (uint256(BASE.decimals()) + uint256(QUOTE.decimals()) - 8);
        answer = int256((uint256(a0) * uint256(a1)) / scale);
        roundId = r0;
        answeredInRound = r0;
        startedAt = s0 < s1 ? s0 : s1;
        updatedAt = u0 < u1 ? u0 : u1;
    }
}

lib/chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface AggregatorV3Interface {
  function decimals() external view returns (uint8);

  function description() external view returns (string memory);

  function version() external view returns (uint256);

  function getRoundData(
    uint80 _roundId
  ) external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);

  function latestRoundData()
    external
    view
    returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 100,
    "enabled": true
  },
  "evmVersion": "prague",
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin/contracts/",
    "@chainlink/contracts/=lib/chainlink/contracts/",
    "@uniswap/v3-core/=lib/v3-core/",
    "@uniswap/v3-periphery/=lib/v3-periphery/",
    "v3-core/=lib/v3-core/contracts/",
    "v3-periphery/=lib/v3-periphery/contracts/",
    "forge-std/=lib/forge-std/src/",
    "chainlink/=lib/chainlink/",
    "openzeppelin/=lib/openzeppelin/contracts/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.