Skip to content

Commit

Permalink
feat: add oracle account setters
Browse files Browse the repository at this point in the history
  • Loading branch information
shaspitz committed Jul 17, 2024
1 parent 7498a91 commit 298717d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
20 changes: 19 additions & 1 deletion contracts/contracts/BlockTracker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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_);
}

Expand Down Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion contracts/contracts/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ contract Oracle is OwnableUpgradeable, UUPSUpgradeable {
) external initializer {
preConfContract = IPreConfCommitmentStore(preConfContract_);
blockTrackerContract = IBlockTracker(blockTrackerContract_);
oracleAccount = oracleAccount_;
_setOracleAccount(oracleAccount_);
__Ownable_init(owner_);
}

Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 298717d

Please sign in to comment.