SimpleAggregator

Description:

Smart contract deployed on Ethereum with Oracle features.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

// Sources flattened with hardhat v2.26.3 https://hardhat.org

// SPDX-License-Identifier: MIT

// File contracts/SimpleAggregator.sol

// Original license: SPDX_License_Identifier: MIT
pragma solidity ^0.8.0;

/// Minimal Chainlink-compatible aggregator for testing + custom feeds
/// Implements latestRoundData() and decimals() so RiseToken can call it.
contract SimpleAggregator {
    uint80 public roundId;
    int256 public answer;
    uint256 public startedAt;
    uint256 public updatedAt;
    uint80 public answeredInRound;
    uint8 public overrideDecimals;

    address public owner;

    event AnswerUpdated(int256 indexed current, uint256 indexed updatedAt);
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /// @notice Constructor accepts decimals and an initial answer (in the decimals' units)
    /// @param _decimals decimals used by this aggregator (e.g. 18 or 8)
    /// @param _initialAnswer initial value already scaled to `_decimals` (e.g. "75 * 10^18")
    constructor(uint8 _decimals, int256 _initialAnswer) {
        owner = msg.sender;
        overrideDecimals = _decimals;
        roundId = 1;
        startedAt = block.timestamp;
        updatedAt = block.timestamp;
        answeredInRound = 1;
        answer = _initialAnswer; // may be zero if you pass 0
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "Only owner");
        _;
    }

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

    function latestRoundData()
        external
        view
        returns (
            uint80 _roundId,
            int256 _answer,
            uint256 _startedAt,
            uint256 _updatedAt,
            uint80 _answeredInRound
        )
    {
        return (roundId, answer, startedAt, updatedAt, answeredInRound);
    }

    /// @notice owner can update the answer (value should already be scaled appropriately)
    function updateAnswer(int256 _answer) external onlyOwner {
        answer = _answer;
        roundId += 1;
        startedAt = block.timestamp;
        updatedAt = block.timestamp;
        answeredInRound = roundId;
        emit AnswerUpdated(_answer, block.timestamp);
    }
        
    function transferOwnership(address newOwner) external onlyOwner {
        require(newOwner != address(0), "zero addr");
        emit OwnershipTransferred(owner, newOwner);
        owner = newOwner;
    }
}

Tags:
Oracle|addr:0x0fb5acf955ac75c29cc6c64394152a97ecb6e33f|verified:true|block:23591720|tx:0x7b1ec8decbaa1358ba220e77e9055cc7031df1535309202cdee296e1d92e78d3|first_check:1760635879

Submitted on: 2025-10-16 19:31:19

Comments

Log in to comment.

No comments yet.