Skip to content
Verified contractExactMIT

AXBHDPoROracle

Address0x4ddfcb6998dbc32f46b0cb9fb67917c42f63d7ab
Balance

0 ETH

 

Transactions

34

 

Compiler

solc 0.8.24

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.24+commit.e11b9ed9
Language
solidity
Optimization
Yes, 200 runs
EVM version
paris
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,180,349
Creation transaction
0x9fbfecb871…4e7e842983

contracts/oracle/AXBHDPoROracle.sol

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

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

contract AXBHDPoROracle is PoROracleBase {
    constructor(uint8 decimals_, int256 initialAnswer_, string memory description_, address owner_)
        PoROracleBase(decimals_, initialAnswer_, description_, owner_)
    {}
}

contracts/oracle/PoROracleBase.sol

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

interface IAggregatorV3 {
    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, int256, uint256, uint256, uint80);

    function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80);
}

abstract contract PoROracleBase is IAggregatorV3 {
    struct RoundData {
        int256 answer;
        uint256 startedAt;
        uint256 updatedAt;
        uint80 answeredInRound;
    }

    uint256 public constant override version = 1;

    address public owner;
    uint8 private immutable feedDecimals;
    string private feedDescription;
    uint80 private latestRoundId;

    mapping(uint80 roundId => RoundData data) private rounds;

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

    error NotOwner();
    error NoDataPresent();
    error InvalidOwner();

    constructor(uint8 decimals_, int256 initialAnswer_, string memory description_, address owner_) {
        if (owner_ == address(0)) revert InvalidOwner();

        owner = owner_;
        feedDecimals = decimals_;
        feedDescription = description_;

        emit OwnershipTransferred(address(0), owner_);
        _setRoundData(1, initialAnswer_);
    }

    modifier onlyOwner() {
        if (msg.sender != owner) revert NotOwner();
        _;
    }

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

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

    function getRoundData(uint80 roundId) external view override returns (uint80, int256, uint256, uint256, uint80) {
        RoundData memory data = rounds[roundId];
        if (data.updatedAt == 0) revert NoDataPresent();

        return (roundId, data.answer, data.startedAt, data.updatedAt, data.answeredInRound);
    }

    function latestRoundData() external view override returns (uint80, int256, uint256, uint256, uint80) {
        RoundData memory data = rounds[latestRoundId];
        if (data.updatedAt == 0) revert NoDataPresent();

        return (latestRoundId, data.answer, data.startedAt, data.updatedAt, data.answeredInRound);
    }

    function updateAnswer(int256 answer) external onlyOwner returns (uint80 roundId) {
        roundId = latestRoundId + 1;
        _setRoundData(roundId, answer);
    }

    function updateRoundData(uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt) external onlyOwner {
        if (updatedAt == 0) revert NoDataPresent();

        rounds[roundId] =
            RoundData({answer: answer, startedAt: startedAt, updatedAt: updatedAt, answeredInRound: roundId});

        if (roundId > latestRoundId) {
            latestRoundId = roundId;
        }

        emit NewRound(roundId, msg.sender, startedAt);
        emit AnswerUpdated(answer, roundId, updatedAt);
    }

    function transferOwnership(address newOwner) external onlyOwner {
        if (newOwner == address(0)) revert InvalidOwner();

        address previousOwner = owner;
        owner = newOwner;

        emit OwnershipTransferred(previousOwner, newOwner);
    }

    function _setRoundData(uint80 roundId, int256 answer) private {
        uint256 timestamp = block.timestamp;

        rounds[roundId] =
            RoundData({answer: answer, startedAt: timestamp, updatedAt: timestamp, answeredInRound: roundId});
        latestRoundId = roundId;

        emit NewRound(roundId, msg.sender, timestamp);
        emit AnswerUpdated(answer, roundId, timestamp);
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "paris"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.