Skip to content

Commit 6576e28

Browse files
authored
feat: multicall deploy contract for v3
1 parent 39abeaa commit 6576e28

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity 0.8.17;
3+
4+
import "./interfaces/IFactory.sol";
5+
import "@openzeppelin/contracts/access/AccessControl.sol";
6+
7+
/**
8+
* @notice Interface for V3 wallet execute function
9+
*/
10+
interface IV3Wallet {
11+
function execute(bytes calldata _payload, bytes calldata _signature) external;
12+
}
13+
14+
/**
15+
* @title MultiCallDeployV3
16+
* @notice Contract for deploying and executing transactions on V3 wallets
17+
* @dev V3 version that accepts bytes payload instead of Transaction[]
18+
*/
19+
contract MultiCallDeployV3 is AccessControl {
20+
bytes32 public constant EXECUTOR_ROLE = keccak256("EXECUTOR_ROLE");
21+
22+
/**
23+
* @notice Constructor
24+
* @param _admin address with admin role
25+
* @param _executor address with executor role
26+
*/
27+
constructor(address _admin, address _executor) {
28+
_grantRole(DEFAULT_ADMIN_ROLE, _admin);
29+
_grantRole(EXECUTOR_ROLE, _executor);
30+
}
31+
32+
/**
33+
* @notice Deploy wallet, upgrade it to Stage 2, then execute user transaction *
34+
* @param cfa counter factual address of the wallet
35+
* @param _mainModule Address of the main module to be used by the wallet
36+
* @param _salt Salt used to generate the address (should be final imageHash)
37+
* @param factory address of the factory contract
38+
* @param _bootstrapPayload V3 encoded payload containing updateImageHash transaction (always required)
39+
* @param _bootstrapSignature Immutable-only signature for bootstrap (always required)
40+
* @param _userPayload V3 encoded payload containing user's transaction
41+
* @param _userSignature EOA + Immutable signature for user transaction
42+
*/
43+
function deployBootstrapAndExecute(
44+
address cfa,
45+
address _mainModule,
46+
bytes32 _salt,
47+
address factory,
48+
bytes calldata _bootstrapPayload,
49+
bytes calldata _bootstrapSignature // TODO not used after wallet is deployed, to improve
50+
bytes calldata _userPayload,
51+
bytes calldata _userSignature
52+
) external onlyRole(EXECUTOR_ROLE) {
53+
// Get code size at CFA
54+
uint32 size;
55+
assembly {
56+
size := extcodesize(cfa)
57+
}
58+
59+
if (size == 0) {
60+
// 1. Deploy wallet
61+
address wallet = IFactory(factory).deploy(_mainModule, _salt);
62+
require(cfa == wallet, "MultiCallDeployV3: deployed address does not match CFA");
63+
64+
// 2. Bootstrap transaction (updateImageHash) - signed by Immutable-only
65+
IV3Wallet(wallet).execute(_bootstrapPayload, _bootstrapSignature);
66+
67+
// 3. Actual transaction - signed by EOA + Immutable
68+
IV3Wallet(wallet).execute(_userPayload, _userSignature);
69+
} else {
70+
IV3Wallet(cfa).execute(_userPayload, _userSignature);
71+
}
72+
}
73+
}
74+

0 commit comments

Comments
 (0)