From 298717d021d431569d897d9a7e0bc82752764346 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Wed, 17 Jul 2024 12:01:50 -0700 Subject: [PATCH] feat: add oracle account setters --- contracts/contracts/BlockTracker.sol | 20 +++++++++++++++++++- contracts/contracts/Oracle.sol | 20 +++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/contracts/contracts/BlockTracker.sol b/contracts/contracts/BlockTracker.sol index 07a7a1c07..6d95c83fe 100644 --- a/contracts/contracts/BlockTracker.sol +++ b/contracts/contracts/BlockTracker.sol @@ -29,6 +29,9 @@ contract BlockTracker is OwnableUpgradeable, UUPSUpgradeable { /// @dev Event emitted when a new window is created. event NewWindow(uint256 indexed window); + /// @dev Event emitted when the oracle account is set. + event OracleAccountSet(address indexed oldOracleAccount, address indexed newOracleAccount); + uint256 public currentWindow; uint256 public blocksPerWindow; @@ -49,7 +52,7 @@ contract BlockTracker is OwnableUpgradeable, UUPSUpgradeable { function initialize(uint256 blocksPerWindow_, address oracleAccount_, address owner_) external initializer { currentWindow = 1; blocksPerWindow = blocksPerWindow_; - oracleAccount = oracleAccount_; + _setOracleAccount(oracleAccount_); __Ownable_init(owner_); } @@ -118,6 +121,21 @@ contract BlockTracker is OwnableUpgradeable, UUPSUpgradeable { emit NewL1Block(_blockNumber, _winner, currentWindow); } + /// @dev Allows the owner to set the oracle account. + function setOracleAccount(address newOracleAccount) external onlyOwner { + _setOracleAccount(newOracleAccount); + } + + /** + * @dev Internal function to set the oracle account. + * @param newOracleAccount The new address of the oracle account. + */ + function _setOracleAccount(address newOracleAccount) internal { + address oldOracleAccount = oracleAccount; + oracleAccount = newOracleAccount; + emit OracleAccountSet(oldOracleAccount, newOracleAccount); + } + /** * @dev Internal function to record a new block winner * @param blockNumber The number of the block diff --git a/contracts/contracts/Oracle.sol b/contracts/contracts/Oracle.sol index d8c5fbfbd..704175296 100644 --- a/contracts/contracts/Oracle.sol +++ b/contracts/contracts/Oracle.sol @@ -67,7 +67,7 @@ contract Oracle is OwnableUpgradeable, UUPSUpgradeable { ) external initializer { preConfContract = IPreConfCommitmentStore(preConfContract_); blockTrackerContract = IBlockTracker(blockTrackerContract_); - oracleAccount = oracleAccount_; + _setOracleAccount(oracleAccount_); __Ownable_init(owner_); } @@ -80,6 +80,9 @@ contract Oracle is OwnableUpgradeable, UUPSUpgradeable { /// @dev Event emitted when a commitment is processed. event CommitmentProcessed(bytes32 indexed commitmentIndex, bool isSlash); + /// @dev Event emitted when the oracle account is set. + event OracleAccountSet(address indexed oldOracleAccount, address indexed newOracleAccount); + // Function to receive and process the block data (this would be automated in a real-world scenario) /** * @dev Processes a builder's commitment for a specific block number. @@ -118,6 +121,21 @@ contract Oracle is OwnableUpgradeable, UUPSUpgradeable { } } + /// @dev Allows the owner to set the oracle account. + function setOracleAccount(address newOracleAccount) external onlyOwner { + _setOracleAccount(newOracleAccount); + } + + /** + * @dev Internal function to set the oracle account. + * @param newOracleAccount The new address of the oracle account. + */ + function _setOracleAccount(address newOracleAccount) internal { + address oldOracleAccount = oracleAccount; + oracleAccount = newOracleAccount; + emit OracleAccountSet(oldOracleAccount, newOracleAccount); + } + /** * @dev Internal function to process a commitment, either slashing or rewarding based on the commitment's state. * @param commitmentIndex The id of the commitment to be processed.