Skip to main content

AContractsRegistry

Overview​

License: MIT​

abstract contract AContractsRegistry is Initializable

The ContractsRegistry module

For more information please refer to EIP-6224.

The purpose of this module is to provide an organized registry of the project's smart contracts together with the upgradeability and dependency injection mechanisms.

The ContractsRegistry should be used as the highest level smart contract that is aware of any other contract present in the system. The contracts that demand other system's contracts would then inherit special ADependant contract and override setDependencies() function to enable ContractsRegistry to inject dependencies into them.

The ContractsRegistry will help with the following use cases:

1) Making the system upgradeable 2) Making the system contracts-interchangeable 3) Simplifying the contracts management and deployment

The ContractsRegistry acts as a AdminableProxy deployer. One can add proxy-compatible implementations to the registry and deploy proxies to them. Then these proxies can be upgraded easily using the provided interface. The ContractsRegistry itself can be deployed behind a proxy as well.

The dependency injection system may come in handy when one wants to substitute a contract A with a contract B (for example contract A got exploited) without a necessity of redeploying the whole system. One would just add a new B contract to a ContractsRegistry and re-inject all the required dependencies. Dependency injection mechanism is also meant to be compatible with factories.

Users may also fetch all the contracts present in the system as they are now located in a single place.

Structs info​

AContractsRegistryStorage​

struct AContractsRegistryStorage {
AdminableProxyUpgrader proxyUpgrader;
mapping(string => address) contracts;
mapping(address => bool) isProxy;
}

Events info​

ContractAdded​

event ContractAdded(string name, address contractAddress)

ProxyContractAdded​

event ProxyContractAdded(string name, address contractAddress, address implementation)

ProxyContractUpgraded​

event ProxyContractUpgraded(string name, address newImplementation)

ContractRemoved​

event ContractRemoved(string name)

Errors info​

NoMappingExists​

error NoMappingExists(string contractName)

NotAProxy​

error NotAProxy(string contractName, address contractProxy)

ZeroAddressProvided​

error ZeroAddressProvided(string contractName)

Functions info​

getContract (0x35817773)​

function getContract(string memory name_) public view returns (address)

The function that returns an associated contract with the name

Parameters:

NameTypeDescription
name_stringthe name of the contract

Return values:

NameTypeDescription
[0]addressthe address of the contract

hasContract (0x8c223601)​

function hasContract(string memory name_) public view returns (bool)

The function that checks if a contract with a given name has been added

Parameters:

NameTypeDescription
name_stringthe name of the contract

Return values:

NameTypeDescription
[0]booltrue if the contract is present in the registry

getProxyUpgrader (0xd10611fc)​

function getProxyUpgrader() public view returns (address)

The function that returns the admin of the added proxy contracts

Return values:

NameTypeDescription
[0]addressthe proxy admin address

getImplementation (0x6b683896)​

function getImplementation(string memory name_) public view returns (address)

The function that returns an implementation of the given proxy contract

Parameters:

NameTypeDescription
name_stringthe name of the contract

Return values:

NameTypeDescription
[0]addressthe implementation address