Factory
Inherits: IFactory, Migratable, OZInitializable
This contract is used to deploy implementations and proxies deterministically, using create2, and is to
only be deployed once on each chain. Implementations deployed use their own bytecode hash as their salt, so
a unique bytecode (including constructor arguments) will have only one possible address. Proxies deployed use
the sender's address combined with a salt of the sender's choosing as a final salt, and the constructor
arguments are always the same (i.e. the "initializable implementation"), so an address has only 2 degrees
of freedom. This is helpful for ensuring the address of a future/planned contract is constant, while the
implementation is not yet finalized or deployed.
State Variables
parameterRegistry
The address of the parameter registry.
address public immutable parameterRegistry;
_FACTORY_STORAGE_LOCATION
bytes32 internal constant _FACTORY_STORAGE_LOCATION = 0x651b031aaeb8a5a65735ac2bad4001a08e08ce7e1a4736b27ec7d04baeb8f600;
Functions
_getFactoryStorage
function _getFactoryStorage() internal pure returns (FactoryStorage storage $);
whenNotPaused
modifier whenNotPaused();
constructor
Constructor that deploys the initializable implementation.
The parameter registry must not be the zero address.
constructor(address parameterRegistry_);
Parameters
| Name | Type | Description |
|---|---|---|
parameterRegistry_ | address | The address of the parameter registry. |
initialize
Initializes the contract.
function initialize() external initializer;
deployImplementation
Deploys an implementation contract.
function deployImplementation(bytes calldata bytecode_) external whenNotPaused returns (address implementation_);
Parameters
| Name | Type | Description |
|---|---|---|
bytecode_ | bytes | The bytecode of the implementation to deploy (including appended constructor data). |
Returns
| Name | Type | Description |
|---|---|---|
implementation_ | address | The address of the deployed implementation. |
deployProxy
Deploys a proxy contract.
function deployProxy(address implementation_, bytes32 salt_, bytes calldata initializeCallData_)
external
whenNotPaused
returns (address proxy_);
Parameters
| Name | Type | Description |
|---|---|---|
implementation_ | address | The address of the implementation the proxy should proxy. |
salt_ | bytes32 | A salt defined by the sender. |
initializeCallData_ | bytes | The call data used to initialize the proxy. |
Returns
| Name | Type | Description |
|---|---|---|
proxy_ | address | The address of the deployed proxy. |
migrate
Initiates a migration of the proxy, in a way defined by the implementation.
Normally, the implementation has a way of determining the migrator that needs to be delegatecalled.
function migrate() external;
pausedParameterKey
The parameter registry key used to fetch the paused status.
function pausedParameterKey() public pure returns (string memory key_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() public pure returns (string memory key_);
paused
The pause status.
function paused() external view returns (bool paused_);
initializableImplementation
The address of the first temporary implementation that proxies will proxy.
*This contract is the first proxied implementation of any proxy, and allows the factory to then set the proxy's actual implementation, and initialize it with respect to that actual implementation. This ensures that:
- The address of a proxy is only defined by the nonce, and not by the implementation it will proxy.
- No contracts are deployed that are not used.
- The proxy can be easily initialized with respect to the actual implementation, atomically.*
function initializableImplementation() external view returns (address initializableImplementation_);
computeImplementationAddress
Computes the address of an implementation contract that would be deployed from a given bytecode.
The address is determined only by the bytecode, and so the same bytecode results in the same address.
function computeImplementationAddress(bytes calldata bytecode_) external view returns (address implementation_);
Parameters
| Name | Type | Description |
|---|---|---|
bytecode_ | bytes | The bytecode of the implementation to deploy (including appended constructor data). |
Returns
| Name | Type | Description |
|---|---|---|
implementation_ | address | The address of the implementation that would be deployed. |
computeProxyAddress
Computes the address of a proxy contract that would be deployed from given a caller and salt.
The actual salt used to deploy the proxy via create2 is keccak256(abi.encodePacked(caller_, salt_)).
function computeProxyAddress(address caller_, bytes32 salt_) external view returns (address proxy_);
Parameters
| Name | Type | Description |
|---|---|---|
caller_ | address | The address of the caller that would request the proxy deployment. |
salt_ | bytes32 | The salt defined by the caller. |
Returns
| Name | Type | Description |
|---|---|---|
proxy_ | address | The address of the proxy that would be deployed. |
_create2
Creates a contract via create2 and reverts if the deployment fails.
function _create2(bytes memory bytecode_, bytes32 salt_) internal returns (address deployed_);
_isZero
function _isZero(address input_) internal pure returns (bool isZero_);
_revertIfPaused
function _revertIfPaused() internal view;
Structs
FactoryStorage
The UUPS storage for the factory.
Note: storage-location: erc7201:xmtp.storage.Factory
struct FactoryStorage {
bool paused;
address initializableImplementation;
}
Properties
| Name | Type | Description |
|---|---|---|
paused | bool | The pause status. |
initializableImplementation | address |