Skip to content

Commit

Permalink
Update Create2Factory deployAndMultiCall (circlefin#45)
Browse files Browse the repository at this point in the history
Update `deployAndCall` to `deployAndMultiCall` to allow for atomic
bundling of all proxy deployment steps in a singular transaction.
 - Arrayified `data` param.
 - Updated tests.

V2 deployment process doc:
https://docs.google.com/document/d/1ayFWGNVmaO6jlLwgZsa0Yk-490CTBdiFASuY4jJzkE0/edit?pli=1&tab=t.0#heading=h.r8mn3sdqq2kb
  • Loading branch information
epoon-circle authored Nov 6, 2024
1 parent 47dcbca commit e5e3b5a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/v2/Create2Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
pragma solidity 0.7.6;
pragma abicoder v2;

import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
Expand Down Expand Up @@ -48,16 +49,19 @@ contract Create2Factory is Ownable {
* @param data The data to call the implementation with
* @return addr The deployed address
*/
function deployAndCall(
function deployAndMultiCall(
uint256 amount,
bytes32 salt,
bytes calldata bytecode,
bytes calldata data
bytes[] calldata data
) external payable onlyOwner returns (address addr) {
// Deploy deterministically
addr = Create2.deploy(amount, salt, bytecode);

Address.functionCall(addr, data);
uint256 dataLength = data.length;
for (uint256 i = 0; i < dataLength; ++i) {
Address.functionCall(addr, data[i]);
}
}

/**
Expand Down
21 changes: 16 additions & 5 deletions test/v2/Create2Factory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,24 @@ contract Create2FactoryTest is Test {
assertEq(MockInitializableImplementation(proxyAddr).num(), num);
}

function testDeployAndCall(
function testDeployAndMultiCall(
address addr,
uint256 num,
uint256 amount,
bytes32 salt
) public {
// Construct initializer
bytes memory initializer = abi.encodeWithSelector(
// Construct initializers
bytes memory initializer1 = abi.encodeWithSelector(
MockInitializableImplementation.initialize.selector,
addr,
num
);
bytes memory initializer2 = abi.encodeWithSelector(
MockInitializableImplementation.initializeV2.selector
);
bytes[] memory data = new bytes[](2);
data[0] = initializer1;
data[1] = initializer2;
// Construct bytecode
bytes memory bytecode = abi.encodePacked(
type(UpgradeableProxy).creationCode,
Expand All @@ -88,11 +94,16 @@ contract Create2FactoryTest is Test {
keccak256(bytecode)
);
vm.deal(address(this), amount);
address proxyAddr = create2Factory.deployAndCall{value: amount}(

// Expect calls
vm.expectCall(expectedAddr, initializer1);
vm.expectCall(expectedAddr, initializer2);

address proxyAddr = create2Factory.deployAndMultiCall{value: amount}(
amount,
salt,
bytecode,
initializer
data
);

// Verify deterministic
Expand Down

0 comments on commit e5e3b5a

Please sign in to comment.