TLUniversalDeployer

Git Source

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

NameTypeDescription
initOwneraddressThe 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

NameTypeDescription
contractTypestringThe contract type to deploy
initializationCodebytesThe 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

NameTypeDescription
contractTypestringThe contract type to deploy
initializationCodebytesThe initialization code to call after contract deployment
versionIndexuint256The 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

NameTypeDescription
contractTypestringThe contract type to save this under
versionContractVersionThe 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

NameTypeDescription
contractTypestringThe 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

NameTypeDescription
senderaddressThe sender of the contract deployment transaction
contractTypestringThe contract type to deploy
initializationCodebytesThe 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

NameTypeDescription
senderaddressThe sender of the contract deployment transaction
contractTypestringThe contract type to deploy
initializationCodebytesThe initialization code to call after contract deployment
versionIndexuint256The 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;
}