Skip to content

Commit

Permalink
fix: comments
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 c2580bf commit 56b4279
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
16 changes: 9 additions & 7 deletions src/oracles/CoinbaseOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ 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 {
uint8 public immutable decimals = 6;
address public reporter = 0xfCEAdAFab14d46e20144F48824d0C09B1a03F2BC;
uint8 public immutable DECIMALS = 6;
bytes32 public immutable KIND_HASH = keccak256(abi.encodePacked("prices"));

struct RoundData {
int256 answer;
Expand All @@ -25,11 +27,11 @@ contract CoinbaseOracle is IAggregatorV3SourceCoinbase {
event PricePushed(string indexed ticker, uint80 indexed roundId, int256 price, uint256 timestamp);

/**
* @notice Returns the address of the reporter.
* @return The address of the reporter.
* @notice Returns the number of decimals used by the oracle.
* @return The number of decimals used by the oracle.
*/
function reporter() public view virtual returns (address) {
return 0xfCEAdAFab14d46e20144F48824d0C09B1a03F2BC;
function decimals() external pure returns (uint8) {
return DECIMALS;
}

/**
Expand Down Expand Up @@ -85,13 +87,13 @@ contract CoinbaseOracle is IAggregatorV3SourceCoinbase {
uint256 price // 6 decimals
) = abi.decode(priceData, (string, uint256, string, uint256));

require(keccak256(abi.encodePacked(kind)) == keccak256(abi.encodePacked("prices")), "Invalid kind.");
require(keccak256(abi.encodePacked(kind)) == KIND_HASH, "Invalid kind.");

PriceData storage priceDataStruct = prices[ticker];
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: 1 addition & 7 deletions test/mocks/MockCoinbaseOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ pragma solidity 0.8.17;
import {CoinbaseOracle} from "../../src/oracles/CoinbaseOracle.sol";

contract MockCoinbaseOracle is CoinbaseOracle {
address public customReporter;

constructor(address _customReporter) {
customReporter = _customReporter;
}

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

0 comments on commit 56b4279

Please sign in to comment.