Skip to content

Commit

Permalink
feat: virtual function
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
  • Loading branch information
md0x committed Jun 18, 2024
1 parent 56b4279 commit b057756
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/oracles/CoinbaseOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {IAggregatorV3SourceCoinbase} from "../interfaces/coinbase/IAggregatorV3S
* @notice A smart contract that serves as an oracle for price data reported by a designated reporter.
*/
contract CoinbaseOracle is IAggregatorV3SourceCoinbase {
address public reporter = 0xfCEAdAFab14d46e20144F48824d0C09B1a03F2BC;
address public immutable REPORTER = 0xfCEAdAFab14d46e20144F48824d0C09B1a03F2BC;
uint8 public immutable DECIMALS = 6;
bytes32 public immutable KIND_HASH = keccak256(abi.encodePacked("prices"));

Expand All @@ -34,6 +34,14 @@ contract CoinbaseOracle is IAggregatorV3SourceCoinbase {
return DECIMALS;
}

/**
* @notice Returns the address of the reporter.
* @return The address of the reporter.
*/
function reporter() public view virtual returns (address) {
return REPORTER;
}

/**
* @notice Returns the latest round data for a given ticker.
* @param ticker The ticker symbol to retrieve the data for.
Expand Down Expand Up @@ -93,7 +101,7 @@ contract CoinbaseOracle is IAggregatorV3SourceCoinbase {
uint256 latestTimestamp = priceDataStruct.rounds[priceDataStruct.lastRoundId].timestamp;

require(timestamp > latestTimestamp, "Invalid timestamp.");
require(recoverSigner(priceData, signature) == reporter, "Invalid signature.");
require(recoverSigner(priceData, signature) == reporter(), "Invalid signature.");
require(price <= uint256(type(int256).max), "Price exceeds max value.");

priceDataStruct.lastRoundId++;
Expand Down
8 changes: 7 additions & 1 deletion test/mocks/MockCoinbaseOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ pragma solidity 0.8.17;
import {CoinbaseOracle} from "../../src/oracles/CoinbaseOracle.sol";

contract MockCoinbaseOracle is CoinbaseOracle {
address public customReporter;

constructor(address _customReporter) {
reporter = _customReporter;
customReporter = _customReporter;
}

function reporter() public view override returns (address) {
return customReporter;
}
}

0 comments on commit b057756

Please sign in to comment.