-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathDeploy.s.sol
More file actions
205 lines (171 loc) · 8.48 KB
/
Copy pathDeploy.s.sol
File metadata and controls
205 lines (171 loc) · 8.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol";
import {Script, console} from "forge-std/Script.sol";
import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
import {AccountFactory} from "../src/account/AccountFactory.sol";
import {ReferenceModularAccount} from "../src/account/ReferenceModularAccount.sol";
import {SemiModularAccount} from "../src/account/SemiModularAccount.sol";
import {SingleSignerValidationModule} from "../src/modules/validation/SingleSignerValidationModule.sol";
contract DeployScript is Script {
IEntryPoint public entryPoint = IEntryPoint(payable(vm.envAddress("ENTRYPOINT")));
address public owner = vm.envAddress("OWNER");
address public accountImpl = vm.envOr("ACCOUNT_IMPL", address(0));
address public semiModularAccountImpl = vm.envOr("SMA_IMPL", address(0));
address public factory = vm.envOr("FACTORY", address(0));
address public singleSignerValidationModule = vm.envOr("SINGLE_SIGNER_VALIDATION_MODULE", address(0));
bytes32 public accountImplSalt = bytes32(vm.envOr("ACCOUNT_IMPL_SALT", uint256(0)));
bytes32 public semiModularAccountImplSalt = bytes32(vm.envOr("SMA_IMPL_SALT", uint256(0)));
bytes32 public factorySalt = bytes32(vm.envOr("FACTORY_SALT", uint256(0)));
bytes32 public singleSignerValidationModuleSalt =
bytes32(vm.envOr("SINGLE_SIGNER_VALIDATION_MODULE_SALT", uint256(0)));
uint256 public requiredStakeAmount = vm.envOr("STAKE_AMOUNT", uint256(0.1 ether));
uint256 public requiredUnstakeDelay = vm.envOr("UNSTAKE_DELAY", uint256(1 days));
function run() public {
console.log("******** Deploying ERC-6900 Reference Implementation ********");
console.log("Chain: ", block.chainid);
console.log("EP: ", address(entryPoint));
console.log("Factory owner: ", owner);
vm.startBroadcast();
_deployAccountImpl(accountImplSalt, accountImpl);
_deploySemiModularAccountImpl(semiModularAccountImplSalt, semiModularAccountImpl);
_deploySingleSignerValidation(singleSignerValidationModuleSalt, singleSignerValidationModule);
_deployAccountFactory(factorySalt, factory);
_addStakeForFactory(uint32(requiredUnstakeDelay), requiredStakeAmount);
vm.stopBroadcast();
}
function _deployAccountImpl(bytes32 salt, address expected) internal {
console.log(string.concat("Deploying AccountImpl with salt: ", vm.toString(salt)));
address addr = Create2.computeAddress(
salt,
keccak256(abi.encodePacked(type(ReferenceModularAccount).creationCode, abi.encode(entryPoint))),
CREATE2_FACTORY
);
if (addr != expected) {
console.log("Expected address mismatch");
console.log("Expected: ", expected);
console.log("Actual: ", addr);
revert();
}
if (addr.code.length == 0) {
console.log("No code found at expected address, deploying...");
ReferenceModularAccount deployed = new ReferenceModularAccount{salt: salt}(entryPoint);
if (address(deployed) != expected) {
console.log("Deployed address mismatch");
console.log("Expected: ", expected);
console.log("Deployed: ", address(deployed));
revert();
}
console.log("Deployed AccountImpl at: ", address(deployed));
} else {
console.log("Code found at expected address, skipping deployment");
}
}
function _deploySemiModularAccountImpl(bytes32 salt, address expected) internal {
console.log(string.concat("Deploying SemiModularAccountImpl with salt: ", vm.toString(salt)));
address addr = Create2.computeAddress(
salt,
keccak256(abi.encodePacked(type(SemiModularAccount).creationCode, abi.encode(entryPoint))),
CREATE2_FACTORY
);
if (addr != expected) {
console.log("Expected address mismatch");
console.log("Expected: ", expected);
console.log("Actual: ", addr);
revert();
}
if (addr.code.length == 0) {
console.log("No code found at expected address, deploying...");
SemiModularAccount deployed = new SemiModularAccount{salt: salt}(entryPoint);
if (address(deployed) != expected) {
console.log("Deployed address mismatch");
console.log("Expected: ", expected);
console.log("Deployed: ", address(deployed));
revert();
}
console.log("Deployed SemiModularAccount at: ", address(deployed));
} else {
console.log("Code found at expected address, skipping deployment");
}
}
function _deploySingleSignerValidation(bytes32 salt, address expected) internal {
console.log(string.concat("Deploying SingleSignerValidationModule with salt: ", vm.toString(salt)));
address addr = Create2.computeAddress(
salt, keccak256(abi.encodePacked(type(SingleSignerValidationModule).creationCode)), CREATE2_FACTORY
);
if (addr != expected) {
console.log("Expected address mismatch");
console.log("Expected: ", expected);
console.log("Actual: ", addr);
revert();
}
if (addr.code.length == 0) {
console.log("No code found at expected address, deploying...");
SingleSignerValidationModule deployed = new SingleSignerValidationModule{salt: salt}();
if (address(deployed) != expected) {
console.log("Deployed address mismatch");
console.log("Expected: ", expected);
console.log("Deployed: ", address(deployed));
revert();
}
console.log("Deployed SingleSignerValidationModule at: ", address(deployed));
} else {
console.log("Code found at expected address, skipping deployment");
}
}
function _deployAccountFactory(bytes32 salt, address expected) internal {
console.log(string.concat("Deploying AccountFactory with salt: ", vm.toString(salt)));
address addr = Create2.computeAddress(
salt,
keccak256(
abi.encodePacked(
type(AccountFactory).creationCode,
abi.encode(
entryPoint, accountImpl, semiModularAccountImpl, singleSignerValidationModule, owner
)
)
),
CREATE2_FACTORY
);
if (addr != expected) {
console.log("Expected address mismatch");
console.log("Expected: ", expected);
console.log("Actual: ", addr);
revert();
}
if (addr.code.length == 0) {
console.log("No code found at expected address, deploying...");
AccountFactory deployed = new AccountFactory{salt: salt}(
entryPoint,
ReferenceModularAccount(payable(accountImpl)),
SemiModularAccount(payable(semiModularAccountImpl)),
singleSignerValidationModule,
owner
);
if (address(deployed) != expected) {
console.log("Deployed address mismatch");
console.log("Expected: ", expected);
console.log("Deployed: ", address(deployed));
revert();
}
console.log("Deployed AccountFactory at: ", address(deployed));
} else {
console.log("Code found at expected address, skipping deployment");
}
}
function _addStakeForFactory(uint32 unstakeDelay, uint256 stakeAmount) internal {
console.log("Adding stake to factory");
uint256 currentStake = entryPoint.getDepositInfo(address(factory)).stake;
console.log("Current stake: ", currentStake);
uint256 stakeToAdd = stakeAmount - currentStake;
if (stakeToAdd > 0) {
console.log("Adding stake: ", stakeToAdd);
AccountFactory(factory).addStake{value: stakeToAdd}(unstakeDelay);
console.log("Staked factory: ", address(factory));
console.log("Total stake amount: ", entryPoint.getDepositInfo(address(factory)).stake);
console.log("Unstake delay: ", entryPoint.getDepositInfo(address(factory)).unstakeDelaySec);
} else {
console.log("No stake to add");
}
}
}