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 an Entry 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

  1. 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

event AddNewContract(address,bytes4,address,uint256);
event RevertToPreviousAddress(address,bytes4,address,address);
event StartContractChange(address,bytes4,address,address);
event ApproveContractChange(address,bytes4,address,address);
event CancelContractChange(address,bytes4,address,address);
event StartWaitPeriodChange(address,bytes4,uint256);
event ApproveWaitPeriodChange(address,bytes4,uint256,uint256);
event CancelWaitPeriodChange(address,bytes4,uint256,uint256);

Public Functions

  1. getAddr(bytes4 _id)

    • Visibility: Public

    • Parameters:

      • _id: The unique identifier (bytes4) associated with a contract.

    • Returns: The current address of the contract.

    This function allows users to retrieve the current address associated with a contract identifier.

  2. isRegistered(bytes4 _id)

    • Visibility: Public

    • Parameters:

      • _id: The unique identifier (bytes4) associated with a contract.

    • Returns: A boolean indicating whether the contract identifier is registered.

    This function allows users to check if a contract identifier is registered in the registry.

  3. 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.

  4. 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.

  5. startContractChange(bytes4 _id, address _newContractAddr)

    • Visibility: Public

    • Parameters:

      • _id: The unique identifier (bytes4) associated with a contract.

      • _newContractAddr: The new contract address.

    This function allows the contract owner to initiate a contract address change.

  6. approveContractChange(bytes4 _id)

    • Visibility: Public

    • Parameters:

      • _id: The unique identifier (bytes4) associated with a contract.

    This function allows the contract owner to approve and execute a pending contract address change, provided the required wait period has passed.

  7. cancelContractChange(bytes4 _id)

    • Visibility: Public

    • Parameters:

      • _id: The unique identifier (bytes4) associated with a contract.

    This function allows the contract owner to cancel a pending contract address change.

  8. 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.

  9. approveWaitPeriodChange(bytes4 _id)

    • Visibility: Public

    • Parameters:

      • _id: The unique identifier (bytes4) associated with a contract.

    This function allows the contract owner to approve and execute a pending wait period change, provided the required wait period has passed.

  10. cancelWaitPeriodChange(bytes4 _id)

    • Visibility: Public

    • Parameters:

      • _id: The unique identifier (bytes4) associated with a contract.

    This function allows the contract owner to cancel a pending wait period change.