Skip to content

Commit

Permalink
have explicit init via currencyPairInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed Dec 12, 2024
1 parent a12a19d commit 74f6138
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion script/AstriaOracle.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ contract AstriaOracleScript is Script {
function run() public {
vm.startBroadcast();

astriaOracle = new AstriaOracle();
address oracleSenderAddress = vm.envAddress("EVM_ORACLE_SENDER_ADDRESS");
astriaOracle = new AstriaOracle(oracleSenderAddress);

vm.stopBroadcast();
}
Expand Down
22 changes: 16 additions & 6 deletions src/AstriaOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ contract AstriaOracle {
// the `astriaOracleSenderAddress` built into the astria-geth node
address public immutable ORACLE;

struct PriceData {
uint128 price;
uint256 timestamp;
}

// mapping of block number to mapping of hash of the currency pair string to its price data
mapping(uint256 => mapping(bytes32 => PriceData)) public priceData;

struct CurrencyPairInfo {
// require an explicit initialization boolean, as otherwise the default value of 0 would be ambiguous
bool initialized;
uint8 decimals;
}

// mapping of hash of the currency pair string to the number of decimals the price is represented in
mapping(bytes32 => uint8) public decimals;
mapping(bytes32 => CurrencyPairInfo) public currencyPairInfo;

// block number of the latest price data update
uint256 public latestBlockNumber;
Expand All @@ -21,13 +32,12 @@ contract AstriaOracle {
_;
}

struct PriceData {
uint128 price;
uint256 timestamp;
constructor(address _oracle) {
ORACLE = _oracle;
}

function setDecimals(bytes32 _currencyPair, uint8 _decimals) external onlyOracle {
decimals[_currencyPair] = _decimals;
function initializeCurrencyPair(bytes32 _currencyPair, uint8 _decimals) external onlyOracle {
currencyPairInfo[_currencyPair] = CurrencyPairInfo(true, _decimals);
}

function updatePriceData(bytes32[] memory _currencyPairs, uint128[] memory _prices) external onlyOracle {
Expand Down
3 changes: 2 additions & 1 deletion src/MockAggregator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ contract MockAggregator is AggregatorV2V3Interface {
/* v3 aggregator interface */

function decimals() external view returns (uint8) {
return oracle.decimals(currencyPairHash);
(, uint8 _decimals) = oracle.currencyPairInfo(currencyPairHash);
return _decimals;
}

function description() external pure returns (string memory) {
Expand Down

0 comments on commit 74f6138

Please sign in to comment.