BaseRegistry.sol
The protocol maintains a contract registry known as the BaseRegistry. In this registry, each contract is assigned a unique identification (ID), ensuring that the same ID cannot be associated with multiple contracts.
As BaseRegistry contract stores mapping of registered contracts. This registeration of contracts can only be done by owner address (this is check by onlyOwner
modifier).
When a contract is initially registered, a waiting period, referred to as a waitPeriod
, is also established. This waitPeriod
represents the amount of time (seconds) that must elapse before any changes can be made to the contract address. To initiate an update to the contract address, the process involves two steps: starting the contract change and subsequently waiting for the specified waitPeriod
duration before finalizing the update by approving the contract change. This approach is implemented to ensure that users have sufficient time to exit the system or that the contract owners have ample time to respond in the event of a potential contract upgrade. In case a contract update needs to be aborted, there is a provision to cancel the ongoing update process using the cancelContractChange
function.
To get a registered contract's address, you can use the getAddr(id)
function.
Contract Information
SPDX-License-Identifier: MIT
Solidity Version: 0.8.10
State Variables
mapping(bytes4 => Entry) public entries
: A mapping that associates a unique identifier (bytes4) with anEntry
struct. This struct contains information about the contract address, wait period for address changes, change start time, and flags indicating whether a contract change is in progress.mapping(bytes4 => address) public previousAddresses
: A mapping that associates a unique identifier with the previous address of a contract. This allows reverting to the previous contract address in case of issues.mapping(bytes4 => address) public pendingAddresses
: A mapping that associates a unique identifier with a pending contract address change.mapping(bytes4 => uint256) public pendingWaitTimes
: A mapping that associates a unique identifier with a pending wait period change.
Structs
Entry
The
Entry
struct stores information about a contract entry in the registry.address contractAddr
: The current address of the contract.uint256 waitPeriod
: The waiting period (in seconds) required before a contract address can be changed.uint256 changeStartTime
: The timestamp when a contract address change was initiated.bool inContractChange
: A flag indicating whether a contract address change is currently in progress.bool inWaitPeriodChange
: A flag indicating whether a wait period change is currently in progress.bool exists
: A flag indicating whether the contract entry exists.
Events
Public Functions
addNewContract(bytes4 _id, address _contractAddr, uint256 _waitPeriod)
Visibility: Public
Parameters:
_id
: The unique identifier (bytes4) for the new contract._contractAddr
: The address of the new contract._waitPeriod
: The wait period (in seconds) required before changing the contract address.
This function allows the contract owner to add a new contract entry to the registry. It specifies the contract's identifier, address, and the wait period before address changes can occur.
revertToPreviousAddress(bytes4 _id)
Visibility: Public
Parameters:
_id
: The unique identifier (bytes4) associated with a contract.
This function allows the contract owner to immediately revert to the previous address of a contract in case of issues with the new version.
startWaitPeriodChange(bytes4 _id, uint256 _newWaitPeriod)
Visibility: Public
Parameters:
_id
: The unique identifier (bytes4) associated with a contract._newWaitPeriod
: The new wait period (in seconds).
This function allows the contract owner to initiate a change in the wait period required before contract address changes.