MockOffchainAggregator v0.2.1 API Reference
MockOffchainAggregator
MockOffchainAggregator
simulates a Chainlink Data Feed aggregator for testing purposes. This contract maintains price feed data and allows manual updates of answers and round data.
Variables
decimals
uint8 public decimals
The number of decimal places in the answer values.
getAnswer
mapping(uint256 => int256) public getAnswer
Maps round IDs to their corresponding price answers.
getTimestamp
mapping(uint256 => uint256) public getTimestamp
Maps round IDs to their update timestamps.
latestAnswer
int256 public latestAnswer
The most recent price answer.
latestRound
uint256 public latestRound
The most recent round ID.
latestTimestamp
uint256 public latestTimestamp
The timestamp of the most recent update.
maxAnswer
int192 public maxAnswer
The highest answer the system can report. Not exposed from the Proxy contract.
minAnswer
int192 public minAnswer
The lowest answer the system can report. Not exposed from the Proxy contract.
Functions
constructor
constructor(uint8 _decimals, int256 _initialAnswer)
Initializes the aggregator with decimal precision and an initial answer.
Parameters:
Parameter | Type | Description |
---|---|---|
_decimals | uint8 | The number of decimal places in answers |
_initialAnswer | int256 | The initial price answer |
getRoundData
function getRoundData(uint80 _roundId) external view returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
)
Retrieves the complete round data for a specific round ID.
Parameters:
Parameter | Type | Description |
---|---|---|
_roundId | uint80 | The round ID to query |
Returns:
Parameter | Type | Description |
---|---|---|
roundId | uint80 | The round ID from the aggregator for this round |
answer | int256 | The price answer for this round |
startedAt | uint256 | Timestamp when the round started |
updatedAt | uint256 | Timestamp when the round was updated |
answeredInRound | uint80 | The round ID in which the answer was computed |
latestRoundData
function latestRoundData() external view returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
)
Retrieves the latest round data from the aggregator.
Returns:
Parameter | Type | Description |
---|---|---|
roundId | uint80 | The round ID from the aggregator for this round |
answer | int256 | The latest price answer |
startedAt | uint256 | Timestamp when the round started |
updatedAt | uint256 | Timestamp when the round was updated |
answeredInRound | uint80 | The round ID in which the answer was computed |
updateAnswer
function updateAnswer(int256 _answer) public
Updates the latest answer and associated round data.
Parameters:
Parameter | Type | Description |
---|---|---|
_answer | int256 | The new price answer |
updateMinAndMaxAnswers
function updateMinAndMaxAnswers(int192 _minAnswer, int192 _maxAnswer) external
Updates the minimum and maximum allowed answer values.
Parameters:
Parameter | Type | Description |
---|---|---|
_minAnswer | int192 | The new minimum allowed answer |
_maxAnswer | int192 | The new maximum allowed answer |
updateRoundData
function updateRoundData(
uint80 _roundId,
int256 _answer,
uint256 _timestamp,
uint256 _startedAt
) public
Updates all data for a specific round.
Parameters:
Parameter | Type | Description |
---|---|---|
_roundId | uint80 | The round ID to update |
_answer | int256 | The new price answer |
_timestamp | uint256 | The new update timestamp |
_startedAt | uint256 | The new round start timestamp |