DiaAdapterOracleCapped

Description:

ERC20 token contract with Factory, Oracle capabilities. Standard implementation for fungible tokens on Ethereum.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Interface for the optional metadata functions from the ERC-20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}
"
    },
    "@openzeppelin/contracts/token/ERC20/IERC20.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}
"
    },
    "contracts/interfaces/IAggregatorV3.sol": {
      "content": "// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.8.28;

/**
 * @title IAggregatorV3
 *     @notice Copied directly from chainlink website as standard interface for oracles
 */
interface IAggregatorV3 {
    function decimals() external view returns (uint8);

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

    function version() external view returns (uint256);

    function latestAnswer() external view returns (int256);

    // getRoundData and latestRoundData should both raise "No data present"
    // if they do not have data to report, instead of returning unset values
    // which could be misinterpreted as actual reported values.
    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);
}
"
    },
    "contracts/interfaces/IOracleV2.sol": {
      "content": "// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.8.28;

import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

interface IOracleV2 {
    /// @notice Get the asset of the oracle
    /// @return asset The address of the asset
    function asset() external view returns (IERC20Metadata);

    /// @notice Get the price of an asset for a given amount
    /// @dev If the asset is an LP token, the RZR and USD amounts are the amounts of RZR and USD in the LP
    /// @param amount The amount of the asset to get the price of
    /// @return rzrAssets The amount of RZR assets
    /// @return usdAssets The amount of USD assets
    /// @return lastUpdatedAt The timestamp of the last update
    function getPriceForAmount(uint256 amount)
        external
        view
        returns (uint256 rzrAssets, uint256 usdAssets, uint256 lastUpdatedAt);
}
"
    },
    "contracts/oracles/pricefeeds/v2/DiaAdapterOracleCapped.sol": {
      "content": "// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.8.28;

import "../../../interfaces/IOracleV2.sol";
import "../../../interfaces/IAggregatorV3.sol";

interface IDiaOracle {
    function getValue(string memory _key) external view returns (uint128 value, uint128 timestamp);
}

contract DiaAdapterOracleCapped is IOracleV2, IAggregatorV3 {
    IDiaOracle public immutable DIAL_ORACLE;
    IERC20Metadata public immutable asset;
    uint128 public immutable lowerBound;
    uint128 public immutable upperBound;
    string public key;

    constructor(IDiaOracle _diaOracle, string memory _key, address _asset, uint128 _lowerBound, uint128 _upperBound) {
        DIAL_ORACLE = _diaOracle;
        key = _key;
        asset = IERC20Metadata(_asset);
        lowerBound = _lowerBound;
        upperBound = _upperBound;
    }

    function description() external pure returns (string memory) {
        return "IAggregatorV3 implementation for a Dia price feed";
    }

    /// @inheritdoc IAggregatorV3
    function version() external pure returns (uint256) {
        return 1;
    }

    /// @inheritdoc IOracleV2
    function getPriceForAmount(uint256)
        external
        view
        override
        returns (uint256 rzrAssets, uint256 usdAssets, uint256 lastUpdatedAt)
    {
        (uint128 value, uint128 timestamp) = DIAL_ORACLE.getValue(key);
        rzrAssets = 0;
        usdAssets = value * 1e10;
        lastUpdatedAt = timestamp;
    }

    /// @inheritdoc IAggregatorV3
    function latestAnswer() external view returns (int256) {
        (uint128 value,) = getPriceAfterBounds();
        // forge-lint: disable-next-line(unsafe-typecast)
        return int256(int128(value));
    }

    /// @inheritdoc IAggregatorV3
    function decimals() external pure returns (uint8) {
        return 8;
    }

    /// @inheritdoc IAggregatorV3
    function latestRoundData()
        public
        view
        override
        returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
    {
        (uint128 value, uint128 timestamp) = getPriceAfterBounds();
        // forge-lint: disable-next-line(unsafe-typecast)
        return (0, int256(int128(value)), 0, timestamp, 0);
    }

    /// @inheritdoc IAggregatorV3
    function getRoundData(uint80)
        external
        view
        override
        returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
    {
        return latestRoundData();
    }

    function getPriceAfterBounds() public view returns (uint128 value, uint128 timestamp) {
        (value, timestamp) = DIAL_ORACLE.getValue(key);
        if (value < lowerBound) value = lowerBound;
        if (value > upperBound) value = upperBound;
    }
}
"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 2000
    },
    "evmVersion": "paris",
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "metadata": {
      "useLiteralContent": true
    }
  }
}}

Tags:
ERC20, Token, Factory, Oracle|addr:0xce849e6defeb0759aa5d7c9db013a0de6ef7d373|verified:true|block:23552960|tx:0x8a0e8b36cd42613323082467b082ae3f8f69444f219e74ef6e3a586f91a5b249|first_check:1760266483

Submitted on: 2025-10-12 12:54:46

Comments

Log in to comment.

No comments yet.