Skip to content

Commit a54e4a1

Browse files
epoon-circlegrantmike
authored andcommitted
Update Create2Factory deployAndMultiCall (circlefin#45)
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
1 parent 13cad5d commit a54e4a1

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/v2/Create2Factory.sol

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
pragma solidity 0.7.6;
17+
pragma abicoder v2;
1718

1819
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
1920
import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
@@ -48,16 +49,19 @@ contract Create2Factory is Ownable {
4849
* @param data The data to call the implementation with
4950
* @return addr The deployed address
5051
*/
51-
function deployAndCall(
52+
function deployAndMultiCall(
5253
uint256 amount,
5354
bytes32 salt,
5455
bytes calldata bytecode,
55-
bytes calldata data
56+
bytes[] calldata data
5657
) external payable onlyOwner returns (address addr) {
5758
// Deploy deterministically
5859
addr = Create2.deploy(amount, salt, bytecode);
5960

60-
Address.functionCall(addr, data);
61+
uint256 dataLength = data.length;
62+
for (uint256 i = 0; i < dataLength; ++i) {
63+
Address.functionCall(addr, data[i]);
64+
}
6165
}
6266

6367
/**

test/v2/Create2Factory.t.sol

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,24 @@ contract Create2FactoryTest is Test {
6565
assertEq(MockInitializableImplementation(proxyAddr).num(), num);
6666
}
6767

68-
function testDeployAndCall(
68+
function testDeployAndMultiCall(
6969
address addr,
7070
uint256 num,
7171
uint256 amount,
7272
bytes32 salt
7373
) public {
74-
// Construct initializer
75-
bytes memory initializer = abi.encodeWithSelector(
74+
// Construct initializers
75+
bytes memory initializer1 = abi.encodeWithSelector(
7676
MockInitializableImplementation.initialize.selector,
7777
addr,
7878
num
7979
);
80+
bytes memory initializer2 = abi.encodeWithSelector(
81+
MockInitializableImplementation.initializeV2.selector
82+
);
83+
bytes[] memory data = new bytes[](2);
84+
data[0] = initializer1;
85+
data[1] = initializer2;
8086
// Construct bytecode
8187
bytes memory bytecode = abi.encodePacked(
8288
type(UpgradeableProxy).creationCode,
@@ -88,11 +94,16 @@ contract Create2FactoryTest is Test {
8894
keccak256(bytecode)
8995
);
9096
vm.deal(address(this), amount);
91-
address proxyAddr = create2Factory.deployAndCall{value: amount}(
97+
98+
// Expect calls
99+
vm.expectCall(expectedAddr, initializer1);
100+
vm.expectCall(expectedAddr, initializer2);
101+
102+
address proxyAddr = create2Factory.deployAndMultiCall{value: amount}(
92103
amount,
93104
salt,
94105
bytecode,
95-
initializer
106+
data
96107
);
97108

98109
// Verify deterministic

0 commit comments

Comments
 (0)