Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xb239bd2216D1c8476f601e0d9b5FfAD556C59Cc4
Balance 0 ETH
Nonce 1
Code Size 5384 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

5384 bytes
0x608060405234801561001057600080fd5b50600436106101585760003560e01c80638205bf6a116100c3578063b633620c1161007c578063b633620c14610300578063bd3be27c14610313578063d547741f1461031c578063f4a290671461032f578063feaf968c14610342578063ffa1ad741461034a57600080fd5b80638205bf6a1461027b5780638a991dd11461028357806391d148541461028b5780639a6fc8f51461029e578063a217fddf146102e5578063b5ab58dc146102ed57600080fd5b806347e633801161011557806347e633801461020a57806350d25bcd1461023157806354fd4d5014610239578063668a0f02146102405780637284e4161461024857806376670d7a1461025d57600080fd5b806301ffc9a71461015d578063248a9ca3146101855780632f2ff15d146101b6578063309676e9146101cb578063313ce567146101de57806336568abe146101f7575b600080fd5b61017061016b366004610f9c565b610352565b60405190151581526020015b60405180910390f35b6101a8610193366004610fc6565b60009081526065602052604090206001015490565b60405190815260200161017c565b6101c96101c4366004610ffb565b610389565b005b6101c96101d9366004611027565b6103b4565b60975460ff165b60405160ff909116815260200161017c565b6101c9610205366004610ffb565b610735565b6101a87f73e573f9566d61418a34d5de3ff49360f9c51fec37f7486551670290f6285dab81565b6101a86107b3565b60016101a8565b6101a8610800565b61025061083b565b60405161017c919061109f565b61026661012c81565b60405163ffffffff909116815260200161017c565b6101a86108cd565b6101e5600a81565b610170610299366004610ffb565b610924565b6102b16102ac3660046110d2565b61094f565b604080516001600160501b03968716815260208101959095528401929092526060830152909116608082015260a00161017c565b6101a8600081565b6101a86102fb366004610fc6565b6109c3565b6101a861030e366004610fc6565b610a07565b610266610e1081565b6101c961032a366004610ffb565b610a55565b6101c961033d366004611111565b610a7b565b6102b1610b90565b6101e5600181565b60006001600160e01b03198216637965db0b60e01b148061038357506301ffc9a760e01b6001600160e01b03198316145b92915050565b6000828152606560205260409020600101546103a58133610c0f565b6103af8383610c73565b505050565b7f73e573f9566d61418a34d5de3ff49360f9c51fec37f7486551670290f6285dab6103df8133610c0f565b609a546001600160501b0316600090815260996020526040902054601781900b9063ffffffff600160c01b90910481169042908516106104705760405162461bcd60e51b815260206004820152602160248201527f54696d657374616d702063616e6e6f7420626520696e207468652066757475726044820152606560f81b60648201526084015b60405180910390fd5b61012c61048363ffffffff861642611212565b11156104c85760405162461bcd60e51b8152602060048201526014602482015273151a5b595cdd185b5c081a5cc81d1bdbc81bdb1960621b6044820152606401610467565b808463ffffffff161161052d5760405162461bcd60e51b815260206004820152602760248201527f54696d657374616d70206973206f6c646572207468616e20746865206c6173746044820152662075706461746560c81b6064820152608401610467565b610e106105408263ffffffff8716611212565b1161059b5760405162461bcd60e51b815260206004820152602560248201527f54696d657374616d702063616e6e6f74206265207570646174656420746f6f2060448201526437b33a32b760d91b6064820152608401610467565b600082131561061757600060646105b3600a85611229565b6105bd91906112ae565b90506105cd601782900b846112ea565b8660170b13156105ec576105e5601782900b846112ea565b9550610615565b6105fa601782900b8461132b565b8660170b121561061557610612601782900b8461132b565b95505b505b609a54600090610631906001600160501b0316600161136a565b609a805469ffffffffffffffffffff19166001600160501b03831690811790915560408051808201825260178a900b80825263ffffffff8a811660208085018281526000888152609983528790209551865491516001600160c01b039091166001600160e01b031990921691909117600160c01b91909416029290921790935592519182529394509192917f0559884fd3a460db3073b7fc896cc77986f16e378210ded43186175bf646fc5f910160405180910390a360405163ffffffff8616815233906001600160501b038316907f0109fc6f55cf40689f02fbaad7af7fe7bbac8a3d2186600afc7d3e10cac602719060200160405180910390a3505050505050565b6001600160a01b03811633146107a55760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610467565b6107af8282610cf9565b5050565b609a546000906001600160501b03166107de5760405162461bcd60e51b815260040161046790611395565b50609a546001600160501b031660009081526099602052604090205460170b90565b609a546000906001600160501b031661082b5760405162461bcd60e51b815260040161046790611395565b50609a546001600160501b031690565b60606098805461084a906113be565b80601f0160208091040260200160405190810160405280929190818152602001828054610876906113be565b80156108c35780601f10610898576101008083540402835291602001916108c3565b820191906000526020600020905b8154815290600101906020018083116108a657829003601f168201915b5050505050905090565b609a546000906001600160501b03166108f85760405162461bcd60e51b815260040161046790611395565b50609a546001600160501b0316600090815260996020526040902054600160c01b900463ffffffff1690565b60009182526065602090815260408084206001600160a01b0393909316845291905290205460ff1690565b609a5460009081908190819081906001600160501b0390811690871611156109895760405162461bcd60e51b815260040161046790611395565b505050506001600160501b0382166000908152609960205260409020549192601783900b92600160c01b900463ffffffff16915081908490565b609a546000906001600160501b03168211156109f15760405162461bcd60e51b815260040161046790611395565b5060009081526099602052604090205460170b90565b609a546000906001600160501b0316821115610a355760405162461bcd60e51b815260040161046790611395565b50600090815260996020526040902054600160c01b900463ffffffff1690565b600082815260656020526040902060010154610a718133610c0f565b6103af8383610cf9565b600054610100900460ff16610a965760005460ff1615610a9a565b303b155b610afd5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610467565b600054610100900460ff16158015610b1f576000805461ffff19166101011790555b6097805460ff191660ff87161790558351610b41906098906020870190610f03565b50610b4d600084610c73565b610b777f73e573f9566d61418a34d5de3ff49360f9c51fec37f7486551670290f6285dab83610c73565b8015610b89576000805461ff00191690555b5050505050565b609a5460009081908190819081906001600160501b0316610bc35760405162461bcd60e51b815260040161046790611395565b5050609a546001600160501b03166000818152609960205260409020549094601782900b9450600160c01b90910463ffffffff1692508291508490565b6001600160a01b03163b151590565b610c198282610924565b6107af57610c31816001600160a01b03166014610d60565b610c3c836020610d60565b604051602001610c4d9291906113f9565b60408051601f198184030181529082905262461bcd60e51b82526104679160040161109f565b610c7d8282610924565b6107af5760008281526065602090815260408083206001600160a01b03851684529091529020805460ff19166001179055610cb53390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b610d038282610924565b156107af5760008281526065602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60606000610d6f83600261146e565b610d7a90600261148d565b67ffffffffffffffff811115610d9257610d926110fb565b6040519080825280601f01601f191660200182016040528015610dbc576020820181803683370190505b509050600360fc1b81600081518110610dd757610dd76114a5565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110610e0657610e066114a5565b60200101906001600160f81b031916908160001a9053506000610e2a84600261146e565b610e3590600161148d565b90505b6001811115610ead576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110610e6957610e696114a5565b1a60f81b828281518110610e7f57610e7f6114a5565b60200101906001600160f81b031916908160001a90535060049490941c93610ea6816114bb565b9050610e38565b508315610efc5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610467565b9392505050565b828054610f0f906113be565b90600052602060002090601f016020900481019282610f315760008555610f77565b82601f10610f4a57805160ff1916838001178555610f77565b82800160010185558215610f77579182015b82811115610f77578251825591602001919060010190610f5c565b50610f83929150610f87565b5090565b5b80821115610f835760008155600101610f88565b600060208284031215610fae57600080fd5b81356001600160e01b031981168114610efc57600080fd5b600060208284031215610fd857600080fd5b5035919050565b80356001600160a01b0381168114610ff657600080fd5b919050565b6000806040838503121561100e57600080fd5b8235915061101e60208401610fdf565b90509250929050565b6000806040838503121561103a57600080fd5b82358060170b811461104b57600080fd5b9150602083013563ffffffff8116811461106457600080fd5b809150509250929050565b60005b8381101561108a578181015183820152602001611072565b83811115611099576000848401525b50505050565b60208152600082518060208401526110be81604085016020870161106f565b601f01601f19169190910160400192915050565b6000602082840312156110e457600080fd5b81356001600160501b0381168114610efc57600080fd5b634e487b7160e01b600052604160045260246000fd5b6000806000806080858703121561112757600080fd5b843560ff8116811461113857600080fd5b9350602085013567ffffffffffffffff8082111561115557600080fd5b818701915087601f83011261116957600080fd5b81358181111561117b5761117b6110fb565b604051601f8201601f19908116603f011681019083821181831017156111a3576111a36110fb565b816040528281528a60208487010111156111bc57600080fd5b8260208601602083013760006020848301015280975050505050506111e360408601610fdf565b91506111f160608601610fdf565b905092959194509250565b634e487b7160e01b600052601160045260246000fd5b600082821015611224576112246111fc565b500390565b60006001600160ff1b038184138284138082168684048611161561124f5761124f6111fc565b600160ff1b600087128281168783058912161561126e5761126e6111fc565b6000871292508782058712848416161561128a5761128a6111fc565b878505871281841616156112a0576112a06111fc565b505050929093029392505050565b6000826112cb57634e487b7160e01b600052601260045260246000fd5b600160ff1b8214600019841416156112e5576112e56111fc565b500590565b600080821280156001600160ff1b038490038513161561130c5761130c6111fc565b600160ff1b8390038412811615611325576113256111fc565b50500190565b60008083128015600160ff1b850184121615611349576113496111fc565b6001600160ff1b0384018313811615611364576113646111fc565b50500390565b60006001600160501b0380831681851680830382111561138c5761138c6111fc565b01949350505050565b6020808252600f908201526e139bc819185d18481c1c995cd95b9d608a1b604082015260600190565b600181811c908216806113d257607f821691505b602082108114156113f357634e487b7160e01b600052602260045260246000fd5b50919050565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161143181601785016020880161106f565b7001034b99036b4b9b9b4b733903937b6329607d1b601791840191820152835161146281602884016020880161106f565b01602801949350505050565b6000816000190483118215151615611488576114886111fc565b500290565b600082198211156114a0576114a06111fc565b500190565b634e487b7160e01b600052603260045260246000fd5b6000816114ca576114ca6111fc565b50600019019056fea264697066735822122097ec7a5e085f219cbb2920290b7e3a8ba7b459b91549b1695d05deca48cf939164736f6c63430008090033

Verified Source Code Full Match

Compiler: v0.8.9+commit.e5eed63a EVM: london Optimization: Yes (200 runs)
BackedOracle.sol 201 lines
/**
 * SPDX-License-Identifier: MIT
 *
 * Copyright (c) 2021-2023 Backed Finance AG
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
pragma solidity 0.8.9;

import "./BackedOracleInterface.sol";

import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";

contract BackedOracle is AccessControlUpgradeable, AggregatorV2V3Interface {
    uint8 public constant VERSION = 1;
    uint8 public constant MAX_PERCENT_DIFFERENCE = 10;
    uint32 public constant MAX_TIMESTAMP_AGE = 5 minutes;
    uint32 public constant MIN_UPDATE_INTERVAL = 1 hours;

    bytes32 public constant UPDATER_ROLE = keccak256("UPDATER_ROLE");

    struct RoundData {
        int192 answer;
        uint32 timestamp;
    }

    uint8 private _decimals;
    string private _description;

    mapping(uint256 => RoundData) private _roundData;
    uint80 private _latestRoundNumber;

    constructor() {
        initialize(0, "Backed Oracle Implementation", address(0), address(0));
    }

    function initialize(
        uint8 __decimals,
        string memory __description,

        address __admin,
        address __updater
    ) public initializer {
        _decimals = __decimals;
        _description = __description;

        _grantRole(DEFAULT_ADMIN_ROLE, __admin);
        _grantRole(UPDATER_ROLE, __updater);
    }

    function version() external view override returns (uint256) {
        return VERSION;
    }

    function decimals() external view override returns (uint8) {
        return _decimals;
    }

    function description() external view override returns (string memory) {
        return _description;
    }

    function latestAnswer() external view override returns (int256) {
        require(_latestRoundNumber != 0, "No data present");

        return _roundData[_latestRoundNumber].answer;
    }

    function latestTimestamp() external view override returns (uint256) {
        require(_latestRoundNumber != 0, "No data present");

        return _roundData[_latestRoundNumber].timestamp;
    }

    function latestRound() external view override returns (uint256) {
        require(_latestRoundNumber != 0, "No data present");

        return _latestRoundNumber;
    }

    function latestRoundData()
        external
        view
        override
        returns (uint80, int256, uint256, uint256, uint80)
    {
        require(_latestRoundNumber != 0, "No data present");

        return (
            uint80(_latestRoundNumber),
            _roundData[_latestRoundNumber].answer,
            _roundData[_latestRoundNumber].timestamp,
            _roundData[_latestRoundNumber].timestamp,
            uint80(_latestRoundNumber)
        );
    }

    function getAnswer(
        uint256 roundId
    ) external view override returns (int256) {
        require(roundId <= _latestRoundNumber, "No data present");

        return _roundData[roundId].answer;
    }

    function getTimestamp(
        uint256 roundId
    ) external view override returns (uint256) {
        require(roundId <= _latestRoundNumber, "No data present");

        return _roundData[roundId].timestamp;
    }

    function getRoundData(
        uint80 roundId
    )
        external
        view
        override
        returns (uint80, int256, uint256, uint256, uint80)
    {
        require(roundId <= _latestRoundNumber, "No data present");

        return (
            roundId,
            _roundData[roundId].answer,
            _roundData[roundId].timestamp,
            _roundData[roundId].timestamp,
            roundId
        );
    }

    function updateAnswer(
        int192 newAnswer,
        uint32 newTimestamp
    ) external onlyRole(UPDATER_ROLE) {
        int256 latestAnswer = _roundData[_latestRoundNumber].answer;
        uint256 latestTimestamp = _roundData[_latestRoundNumber].timestamp;

        // Timestamp is actual timestamp
        require(
            newTimestamp < block.timestamp,
            "Timestamp cannot be in the future"
        );

        // Check that the timestamp is not too old
        require(
            block.timestamp - newTimestamp <= MAX_TIMESTAMP_AGE,
            "Timestamp is too old"
        );

        // The timestamp is more than the last timestamp
        require(
            newTimestamp > latestTimestamp,
            "Timestamp is older than the last update"
        );

        // The last update happened more than MIN_UPDATE_INTERVAL ago
        require(
            newTimestamp - latestTimestamp > MIN_UPDATE_INTERVAL,
            "Timestamp cannot be updated too often"
        );

        // Limit the value to at most MAX_PERCENT_DIFFERENCE% different from the last value
        if (latestAnswer > 0) {
            int192 allowedDeviation = int192(
                (latestAnswer * int8(MAX_PERCENT_DIFFERENCE)) / 100
            );

            if (newAnswer > latestAnswer + allowedDeviation) {
                newAnswer = int192(latestAnswer + allowedDeviation);
            } else if (newAnswer < latestAnswer - allowedDeviation) {
                newAnswer = int192(latestAnswer - allowedDeviation);
            }
        }

        uint80 newRound = _latestRoundNumber + 1;

        _latestRoundNumber = newRound;
        _roundData[newRound] = RoundData(newAnswer, newTimestamp);

        emit AnswerUpdated(newAnswer, newRound, newTimestamp);
        emit NewRound(newRound, msg.sender, newTimestamp);
    }
}
BackedOracleInterface.sol 77 lines
/**
 * SPDX-License-Identifier: MIT
 *
 * Copyright (c) 2021-2023 Backed Finance AG
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
pragma solidity 0.8.9;


interface AggregatorInterface {
  function latestAnswer() external view returns (int256);

  function latestTimestamp() external view returns (uint256);

  function latestRound() external view returns (uint256);

  function getAnswer(uint256 roundId) external view returns (int256);

  function getTimestamp(uint256 roundId) external view returns (uint256);

  event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 updatedAt);
  event NewRound(uint256 indexed roundId, address indexed startedBy, uint256 startedAt);
}


interface AggregatorV3Interface {
  function version() external view returns (uint256);
  function decimals() external view returns (uint8);
  function description() external view returns (string memory);

  // 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
  );

}

interface AggregatorV2V3Interface is AggregatorInterface, AggregatorV3Interface
{
}
AddressUpgradeable.sol 195 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
ContextUpgradeable.sol 37 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}
StringsUpgradeable.sol 67 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library StringsUpgradeable {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }
}
Initializable.sol 80 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.0;

import "../../utils/AddressUpgradeable.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the
 * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() initializer {}
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        // If the contract is initializing we ignore whether _initialized is set in order to support multiple
        // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the
        // contract may have been reentered.
        require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} modifier, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    function _isConstructor() private view returns (bool) {
        return !AddressUpgradeable.isContract(address(this));
    }
}
AccessControlUpgradeable.sol 236 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "./IAccessControlUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../utils/StringsUpgradeable.sol";
import "../utils/introspection/ERC165Upgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {
    function __AccessControl_init() internal onlyInitializing {
    }

    function __AccessControl_init_unchained() internal onlyInitializing {
    }
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role, _msgSender());
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        StringsUpgradeable.toHexString(uint160(account), 20),
                        " is missing role ",
                        StringsUpgradeable.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}
IAccessControlUpgradeable.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControlUpgradeable {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}
ERC165Upgradeable.sol 42 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable {
    function __ERC165_init() internal onlyInitializing {
    }

    function __ERC165_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165Upgradeable).interfaceId;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}
IERC165Upgradeable.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165Upgradeable {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

Read Contract

DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
MAX_PERCENT_DIFFERENCE 0x8a991dd1 → uint8
MAX_TIMESTAMP_AGE 0x76670d7a → uint32
MIN_UPDATE_INTERVAL 0xbd3be27c → uint32
UPDATER_ROLE 0x47e63380 → bytes32
VERSION 0xffa1ad74 → uint8
decimals 0x313ce567 → uint8
description 0x7284e416 → string
getAnswer 0xb5ab58dc → int256
getRoleAdmin 0x248a9ca3 → bytes32
getRoundData 0x9a6fc8f5 → uint80, int256, uint256, uint256, uint80
getTimestamp 0xb633620c → uint256
hasRole 0x91d14854 → bool
latestAnswer 0x50d25bcd → int256
latestRound 0x668a0f02 → uint256
latestRoundData 0xfeaf968c → uint80, int256, uint256, uint256, uint80
latestTimestamp 0x8205bf6a → uint256
supportsInterface 0x01ffc9a7 → bool
version 0x54fd4d50 → uint256

Write Contract 5 functions

These functions modify contract state and require a wallet transaction to execute.

grantRole 0x2f2ff15d
bytes32 role
address account
initialize 0xf4a29067
uint8 __decimals
string __description
address __admin
address __updater
renounceRole 0x36568abe
bytes32 role
address account
revokeRole 0xd547741f
bytes32 role
address account
updateAnswer 0x309676e9
int192 newAnswer
uint32 newTimestamp

Recent Transactions

No transactions found for this address