diff --git a/src/v2/Create2Factory.sol b/src/v2/Create2Factory.sol index 3b9fdb8..0e5941a 100644 --- a/src/v2/Create2Factory.sol +++ b/src/v2/Create2Factory.sol @@ -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"; @@ -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]); + } } /** diff --git a/test/v2/Create2Factory.t.sol b/test/v2/Create2Factory.t.sol index 0f98707..51f5c30 100644 --- a/test/v2/Create2Factory.t.sol +++ b/test/v2/Create2Factory.t.sol @@ -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, @@ -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