Transient Labs Universal Deployer
A contract factory that can be used for multiple types of contracts to deploy ERC-1167 minimal proxy clones.
Running Tests
- Install foundry
- Run
make install
ormake update
- Run
forge test
(optionally can adjust the fuzz runs via the flag--fuzz-runs <number>
)
Disclaimer
This codebase is provided on an "as is" and "as available" basis.
We do not give any warranties and will not be liable for any loss incurred through any use of this codebase.
License
This code is copyright Transient Labs, Inc 2023 and is licensed under the MIT license.
TLUniversalDeployer
Inherits: Ownable
Author: transientlabs.xyz
Transient Labs universal deployer - a contract factory allowing for easy deployment of TL contracts
This contract uses deterministic contract deployments (CREATE2)
State Variables
VERSION
string public constant VERSION = "1.0.0";
_deployableContracts
mapping(bytes32 => DeployableContract) private _deployableContracts;
_deployableContractKeys
bytes32[] private _deployableContractKeys;
Functions
constructor
constructor(address initOwner) Ownable(initOwner);
Parameters
Name | Type | Description |
---|---|---|
initOwner | address | The initial owner of the contract |
deploy
Function to deploy the latest version of a deployable contract
function deploy(string calldata contractType, bytes calldata initializationCode) external;
Parameters
Name | Type | Description |
---|---|---|
contractType | string | The contract type to deploy |
initializationCode | bytes | The initialization code to call after contract deployment |
deploy
Function to deploy the latest version of a cloneable contract
function deploy(string calldata contractType, bytes calldata initializationCode, uint256 versionIndex) external;
Parameters
Name | Type | Description |
---|---|---|
contractType | string | The contract type to deploy |
initializationCode | bytes | The initialization code to call after contract deployment |
versionIndex | uint256 | The indeex of the ContractVersion to deploy |
addDeployableContract
Function to add a contract type and/or version
Restricted to only owner
function addDeployableContract(string calldata contractType, ContractVersion calldata version) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
contractType | string | The contract type to save this under |
version | ContractVersion | The version to push to the DeployableContract struct |
getDeployableContracts
Function to get contracts that can be deployed
function getDeployableContracts() external view returns (string[] memory);
getDeployableContract
Function to get a specific contract type
Does not revert for a contractType
that doesn't exist
function getDeployableContract(string calldata contractType) external view returns (DeployableContract memory);
Parameters
Name | Type | Description |
---|---|---|
contractType | string | The contract type to look up |
predictDeployedContractAddress
Function to predict the address at which a contract would be deployed
Predicts for the latest implementation
function predictDeployedContractAddress(address sender, string calldata contractType, bytes calldata initializationCode)
external
view
returns (address);
Parameters
Name | Type | Description |
---|---|---|
sender | address | The sender of the contract deployment transaction |
contractType | string | The contract type to deploy |
initializationCode | bytes | The initialization code to call after contract deployment |
predictDeployedContractAddress
Function to predict the address at which a contract would be deployed
Predicts for a specific implementation
function predictDeployedContractAddress(
address sender,
string calldata contractType,
bytes calldata initializationCode,
uint256 versionIndex
) external view returns (address);
Parameters
Name | Type | Description |
---|---|---|
sender | address | The sender of the contract deployment transaction |
contractType | string | The contract type to deploy |
initializationCode | bytes | The initialization code to call after contract deployment |
versionIndex | uint256 | The indeex of the ContractVersion to deploy |
_deploy
Private function to deploy contracts
function _deploy(DeployableContract memory dc, ContractVersion memory cv, bytes memory initializationCode) private;
Events
ContractDeployed
Event emitted whenever a contract is deployed
event ContractDeployed(
address indexed sender,
address indexed deployedContract,
address indexed implementation,
string cType,
string version
);
Errors
InvalidDeployableContract
Not a valid contract name
error InvalidDeployableContract();
InitializationFailed
Initialization failed
error InitializationFailed();
ContractAlreadyCreated
Contract already created
error ContractAlreadyCreated();
Structs
ContractVersion
Struct defining a contract version that is deployable
struct ContractVersion {
string id;
address implementation;
}
DeployableContract
Struct defining a contract that is deployable
struct DeployableContract {
bool created;
string cType;
ContractVersion[] versions;
}