WBETHPriceFeed

Description:

Smart contract deployed on Ethereum with Factory, Oracle features.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "contracts/oracle/priceFeeds/ethereum/WBETHPriceFeed.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import "../../interfaces/IResilientOracle.sol";
import "../../interfaces/IWBETH.sol";
import "../../libraries/FullMath.sol";

/**
 * @title WBETHPriceFeed
 * @dev This contract is used to get the price of wBETH/ETH from wBETH exchangeRate and ETH/USD from ChainLink
 */
contract WBETHPriceFeed {
  IResilientOracle public resilientOracle;
  address public constant WETH_TOKEN_ADDR = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
  address public constant WBETH_TOKEN_ADDR = 0xa2E3356610840701BDf5611a53974510Ae27E2e1;

  /**
   * @dev Constructor
   * @param _resilientOracle The address of the Resilient Oracle contract
   */
  constructor(address _resilientOracle) {
    require(_resilientOracle != address(0), "Zero address provided");
    resilientOracle = IResilientOracle(_resilientOracle);
  }

  function decimals() external pure returns (uint8) {
    return 8;
  }

  function description() external pure returns (string memory) {
    return "wBETH Price Feed";
  }

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

  function latestAnswer() external view returns (int256 answer) {
    // get price
    uint256 price = getPrice();
    // cast price to int256
    answer = int256(price);
  }

  function latestRoundData()
    external
    view
    returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
  {
    // get price
    uint256 _answer = getPrice();
    // mock timestamp to latest block timestamp
    uint256 timestamp = block.timestamp;
    // mock roundId to timestamp
    roundId = uint80(timestamp);
    return (roundId, int256(_answer), timestamp, timestamp, roundId);
  }

  /**
   * @dev Get the price of wBETH in 8 DPs
   *      wBETH/ETH from wBETH exchange Rate and ETH/USD from ChainLink
   *      multiply them and divide by 1e8
   * @return price The price of wBETH in 8 decimals
   */
  function getPrice() private view returns (uint256 price) {
    // wstETH/ETH in 18 DPs
    uint256 exchangeRate = IWBETH(WBETH_TOKEN_ADDR).exchangeRate();

    // ETH/USD in 8 DPs
    uint256 ethPrice = resilientOracle.peek(WETH_TOKEN_ADDR);

    return FullMath.mulDiv(exchangeRate, ethPrice, 1e18);
  }
}
"
    },
    "contracts/oracle/interfaces/IResilientOracle.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

interface IResilientOracle {
  function peek(address asset) external view returns (uint256);
}
"
    },
    "contracts/oracle/interfaces/IWBETH.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

interface IWBETH {
    function exchangeRate() external view returns (uint256);
}
"
    },
    "contracts/oracle/libraries/FullMath.sol": {
      "content": "// SPDX-License-Identifier: CC-BY-4.0
pragma solidity ^0.8.10;

// taken from https://medium.com/coinmonks/math-in-solidity-part-3-percents-and-proportions-4db014e080b1
// license is CC-BY-4.0
library FullMath {
  function fullMul(uint256 x, uint256 y) internal pure returns (uint256 l, uint256 h) {
  unchecked{
    uint256 mm = mulmod(x, y, type(uint256).max);
    l = x * y;
    h = mm - l;
    if (mm < l) h -= 1;
  }
  }

  function fullDiv(
    uint256 l,
    uint256 h,
    uint256 d
  ) private pure returns (uint256) {
  unchecked {
    uint256 pow2 = d & (~d + 1);
    d /= pow2;
    l /= pow2;
    l += h * ((~pow2 + 1) / pow2 + 1);
    uint256 r = 1;
    r *= 2 - d * r;
    r *= 2 - d * r;
    r *= 2 - d * r;
    r *= 2 - d * r;
    r *= 2 - d * r;
    r *= 2 - d * r;
    r *= 2 - d * r;
    r *= 2 - d * r;
    return l * r;
  }
  }

  function mulDiv(
    uint256 x,
    uint256 y,
    uint256 d
  ) internal pure returns (uint256) {
    (uint256 l, uint256 h) = fullMul(x, y);

    unchecked {
      uint256 mm = mulmod(x, y, d);
      if (mm > l) h -= 1;
      l -= mm;

      if (h == 0) return l / d;

      require(h < d, "FullMath: FULLDIV_OVERFLOW");
      return fullDiv(l, h, d);
    }
  }

  /// @notice ported from https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol
  function mulDivRoundingUp(
      uint256 a,
      uint256 b,
      uint256 denominator
  ) internal pure returns (uint256 result) {
      result = mulDiv(a, b, denominator);
      if (mulmod(a, b, denominator) > 0) {
          require(result < type(uint256).max);
          result++;
      }
  }
}
"
    }
  },
  "settings": {
    "remappings": [
      "@chainlink/=node_modules/@chainlink/",
      "@openzeppelin/=node_modules/@openzeppelin/",
      "@pythnetwork/=node_modules/@pythnetwork/",
      "eth-gas-reporter/=node_modules/eth-gas-reporter/",
      "forge-std/=lib/forge-std/src/",
      "hardhat/=node_modules/hardhat/"
    ],
    "optimizer": {
      "enabled": true,
      "runs": 100
    },
    "metadata": {
      "useLiteralContent": false,
      "bytecodeHash": "ipfs"
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "evmVersion": "london",
    "viaIR": false
  }
}}

Tags:
Factory, Oracle|addr:0x0709755a26b78ce8e1f4cab598ac7477858c4aa2|verified:true|block:23459025|tx:0x791d1908260d4a50ecc0a7998993e476f89bcf28bcd4fe4129418a3122b9c93b|first_check:1759050932

Submitted on: 2025-09-28 11:15:32

Comments

Log in to comment.

No comments yet.