Deployer

Git Source

Inherits: ChainAwareReader, Logger

State Variables

CREATE2_FACTORY_NAME

string internal constant CREATE2_FACTORY_NAME = "Create2Factory";

DEFAULT_CREATE2_FACTORY

Deployed on lots of chains, could be deployed on more chains using EOA

address private constant DEFAULT_CREATE2_FACTORY = 0xa6190aBC82427800935E0598892f7488a7F73A04;

envCreate2Factory

address private envCreate2Factory;

nextDeploymentSalt

Salt to be used for the next create2 deployment, will be erased after the deployment

bytes32 private nextDeploymentSalt;

permanentDeploymentSalt

Salt to be used for the next create2 deployment, will be kept after the deployment

bytes32 private permanentDeploymentSalt;

Functions

loadEnvCreate2Factory

function loadEnvCreate2Factory() internal;

getCreate2Factory

Returns the address of the create2 factory to be used for the create2 deployments.

*There are a few ways to set the factory address. Priority in descending order:

  1. Deployment artifact for the factory saved in deployments/chainName
  2. CREATE2_FACTORY env variable
  3. DEFAULT_CREATE2_FACTORY*
function getCreate2Factory() internal view virtual returns (address);

getDeploymentSalt

function getDeploymentSalt() internal view virtual returns (bytes32);

getInitCode

function getInitCode(
    string memory contractName,
    bytes memory constructorArgs
)
    internal
    view
    virtual
    returns (bytes memory);

cbDeploy

Creates a contract with the given name and constructor args. Bytecode generated by forge is used for the deployment. Note: could be used as callback for deployAndSave and deployAndSaveAs for contracts with a different compiler version.

function cbDeploy(string memory contractName, bytes memory constructorArgs) internal returns (address deployedAt);

deployCode

Creates a contract with the given init code.

Does not save the deployment JSON, and therefore the direct usage should be avoided. Use as a part of a deploy callback for deployAndSave and deployAndSaveAs instead.

function deployCode(bytes memory initCode) internal returns (address deployedAt);

cbDeployCreate2

Creates a contract with the given name and constructor args. Bytecode generated by forge is used for the deployment. Deployment is done in a deterministic way, using create2 and nextDeploymentSalt() Note: could be used as callback for deployAndSave and deployAndSaveAs

function cbDeployCreate2(
    string memory contractName,
    bytes memory constructorArgs
)
    internal
    returns (address deployedAt);

factoryDeployCreate2

Creates a contract with the given init code. Deployment is done in a deterministic way, using create2 and the given salt.

Does not save the deployment JSON, and therefore the direct usage should be avoided. Use deployCreate2 as the deploy callback for deployAndSave and deployAndSaveAs instead.

function factoryDeployCreate2(
    address factory,
    bytes memory initCode,
    bytes32 salt
)
    internal
    returns (address deployedAt);

setNextDeploymentSalt

Set a deployment salt that will be used for a single next create2 deployment.

function setNextDeploymentSalt(bytes32 salt) internal;

setPermanentDeploymentSalt

Set a deployment salt that will be used for all create2 deployments.

function setPermanentDeploymentSalt(bytes32 salt) internal;

predictAddress

Predicts the address of a contract that would be deployed with the given init code and salt, using the default create2 factory.

function predictAddress(bytes memory initCode, bytes32 salt) internal view returns (address deployedAt);

predictAddress

Predicts the address of a contract that would be deployed with the given init code and salt, using the given create2 factory.

function predictAddress(
    address factory,
    bytes memory initCode,
    bytes32 salt
)
    internal
    pure
    returns (address deployedAt);