foundry-create2-deployer
foundry-create2-deployer copied to clipboard
(WIP) Foundry scripting template for deploying contracts to deterministic addresses on any network
foundry-create2-deployer
Currently a work in progress - Currently stuck until Foundry implements multiple forks per test, as the script cannot read code deployed in the same transaction (I think)
src/Create2DeployScriptBase.s.sol serves as a basis for Foundry scripts meant to deploy contracts to a deterministic address on any network using CREATE2_DEPLOYER.safeCreate2(salt, code), which has the following interface:
interface ImmutableCreate2Factory {
function safeCreate2(bytes32 salt , bytes memory contractCreationCode) external;
}
Where salt is a bytes32 with the msg.sender's address encoded as the first 160 bits, and contractCreationCode is the code to be deployed.
Usage
The setUp() method of Create2DeployerBase.s.sol performs the following checks and steps:
- Check that the
KEYLESS_CREATE2_FACTORYis deployed to the network- If not, check that
KEYLESS_CREATE2_DEPLOYERhas sufficient funds to deploy theKEYLESS_CREATE2_FACTORY- If not, send funds (0.01 of the native token) to the
KEYLESS_CREATE2_DEPLOYER
- If not, send funds (0.01 of the native token) to the
- Submit a pre-signed transaction from
KEYLESS_CREATE2_DEPLOYERto deploy theKEYLESS_CREATE2_FACTORY
- If not, check that
- Check that the
INEFFICIENT_IMMUTABLE_CREATE2_FACTORYis deployed to the network- If not, submit a transaction to
KEYLESS_CREATE2to deploy theINEFFICIENT_IMMUTABLE_CREATE2_FACTORY
- If not, submit a transaction to
- Check that the
EFFICIENT_IMMUTABLE_CREATE2_FACTORYis deployed to the network- If not, submit a transaction to
INEFFICIENT_IMMUTABLE_CREATE2_FACTORYto deploy theEFFICIENT_IMMUTABLE_CREATE2_FACTORY
- If not, submit a transaction to
When overriding the base script, calls to super.setUp() will ensure that the CREATE2_DEPLOYER is available on the network before the body of the script's run() function is executed.