From e9a404e107ee7f92ffd244129ba089c731addf28 Mon Sep 17 00:00:00 2001 From: elizabeth Date: Thu, 12 Dec 2024 14:46:42 -0500 Subject: [PATCH] add oracle permissions to contract --- src/AstriaOracle.sol | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/AstriaOracle.sol b/src/AstriaOracle.sol index 61ba728..cda0b7c 100644 --- a/src/AstriaOracle.sol +++ b/src/AstriaOracle.sol @@ -4,6 +4,9 @@ pragma solidity ^0.8.21; // Core oracle contract for Astria's native oracle. // This contract stores the price data for every currency pair supported by the oracle. contract AstriaOracle { + // the `astriaOracleSenderAddress` built into the astria-geth node + address public immutable ORACLE; + // mapping of block number to mapping of hash of the currency pair string to its price data mapping(uint256 => mapping(bytes32 => PriceData)) public priceData; @@ -13,16 +16,21 @@ contract AstriaOracle { // block number of the latest price data update uint256 public latestBlockNumber; + modifier onlyOracle() { + require(msg.sender == ORACLE, "AstriaOracle: only oracle can update"); + _; + } + struct PriceData { uint128 price; uint256 timestamp; } - function setDecimals(bytes32 _currencyPair, uint8 _decimals) public { + function setDecimals(bytes32 _currencyPair, uint8 _decimals) external onlyOracle { decimals[_currencyPair] = _decimals; } - function updatePriceData(bytes32[] memory _currencyPairs, uint128[] memory _prices) public { + function updatePriceData(bytes32[] memory _currencyPairs, uint128[] memory _prices) external onlyOracle { require(_currencyPairs.length == _prices.length, "currency pair and price length mismatch"); latestBlockNumber = block.number; for (uint256 i = 0; i < _currencyPairs.length; i++) {