Skip to content

Commit 25f3f4b

Browse files
author
ilitteri
committed
Update Utils
1 parent 8a4df7a commit 25f3f4b

File tree

1 file changed

+111
-170
lines changed

1 file changed

+111
-170
lines changed

claim_contracts/script/Utils.sol

Lines changed: 111 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ pragma solidity ^0.8.13;
33

44
import {Vm} from "forge-std/Vm.sol";
55
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
6+
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
7+
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
68
import "../src/AlignedTokenV1.sol";
7-
import "../src/AlignedTokenV2Example.sol";
89
import "../src/ClaimableAirdropV1.sol";
9-
import "../src/ClaimableAirdropV2Example.sol";
1010

1111
library Utils {
1212
// Cheatcodes address, 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D.
@@ -25,8 +25,7 @@ library Utils {
2525
function deployWithCreate2(
2626
bytes memory bytecode,
2727
bytes32 salt,
28-
address create2Factory,
29-
uint256 signerPrivateKey
28+
address create2Factory
3029
) internal returns (address) {
3130
if (bytecode.length == 0) {
3231
revert("Bytecode is not set");
@@ -40,7 +39,7 @@ library Utils {
4039
revert("Contract already deployed");
4140
}
4241

43-
vm.broadcast(signerPrivateKey);
42+
vm.broadcast();
4443
(bool success, bytes memory data) = create2Factory.call(
4544
abi.encodePacked(salt, bytecode)
4645
);
@@ -75,239 +74,181 @@ library Utils {
7574
}
7675
}
7776

78-
function deployAlignedTokenImplementation(
79-
uint256 _version
80-
) internal returns (address) {
81-
address _implementation_address;
82-
if (_version == 1) {
83-
vm.broadcast();
84-
AlignedTokenV1 _implementation = new AlignedTokenV1();
85-
_implementation_address = address(_implementation);
86-
} else if (_version == 2) {
87-
vm.broadcast();
88-
AlignedTokenV2Example _implementation = new AlignedTokenV2Example();
89-
_implementation_address = address(_implementation);
90-
} else {
91-
revert("Unsupported version");
92-
}
93-
return _implementation_address;
77+
// AlignedToken utils
78+
79+
function deployAlignedTokenImplementation() internal returns (address) {
80+
vm.broadcast();
81+
AlignedTokenV1 _implementation = new AlignedTokenV1();
82+
return address(_implementation);
9483
}
9584

9685
function alignedTokenProxyDeploymentData(
86+
address _proxyAdmin,
9787
address _implementation,
98-
uint256 _version,
99-
address _safe,
10088
address _beneficiary1,
10189
address _beneficiary2,
10290
address _beneficiary3,
10391
uint256 _mintAmount
10492
) internal pure returns (bytes memory) {
10593
return
10694
abi.encodePacked(
107-
type(ERC1967Proxy).creationCode,
108-
alignedTokenInitData(
95+
type(TransparentUpgradeableProxy).creationCode,
96+
abi.encode(
10997
_implementation,
110-
_version,
111-
_safe,
112-
_beneficiary1,
113-
_beneficiary2,
114-
_beneficiary3,
115-
_mintAmount
98+
_proxyAdmin,
99+
alignedTokenInitData(
100+
_implementation,
101+
_beneficiary1,
102+
_beneficiary2,
103+
_beneficiary3,
104+
_mintAmount
105+
)
116106
)
117107
);
118108
}
119109

120110
function alignedTokenInitData(
121111
address _implementation,
122-
uint256 _version,
123-
address _safe,
124112
address _beneficiary1,
125113
address _beneficiary2,
126114
address _beneficiary3,
127115
uint256 _mintAmount
128116
) internal pure returns (bytes memory) {
129-
if (_version == 1) {
130-
return
131-
abi.encodeCall(
132-
AlignedTokenV1(_implementation).initialize,
133-
(
134-
_safe,
135-
_beneficiary1,
136-
_mintAmount,
137-
_beneficiary2,
138-
_mintAmount,
139-
_beneficiary3,
140-
_mintAmount
141-
)
142-
);
143-
} else if (_version == 2) {
144-
return
145-
abi.encodeCall(
146-
AlignedTokenV2Example(_implementation).initialize,
147-
(
148-
_safe,
149-
_beneficiary1,
150-
_mintAmount,
151-
_beneficiary2,
152-
_mintAmount,
153-
_beneficiary3,
154-
_mintAmount
155-
)
156-
);
157-
} else {
158-
revert("Unsupported version");
159-
}
117+
return
118+
abi.encodeCall(
119+
AlignedTokenV1(_implementation).initialize,
120+
(
121+
_beneficiary1,
122+
_mintAmount,
123+
_beneficiary2,
124+
_mintAmount,
125+
_beneficiary3,
126+
_mintAmount
127+
)
128+
);
160129
}
161130

162131
function alignedTokenUpgradeData(
132+
address _proxyAdmin,
133+
address _proxy,
163134
address _newImplementation,
164-
uint256 _version,
165-
address _safe,
166135
address _beneficiary1,
167136
address _beneficiary2,
168137
address _beneficiary3,
169138
uint256 _mintAmount
170139
) internal pure returns (bytes memory) {
171-
bytes memory _initData = Utils.alignedTokenInitData(
172-
_newImplementation,
173-
_version,
174-
_safe,
175-
_beneficiary1,
176-
_beneficiary2,
177-
_beneficiary3,
178-
_mintAmount
179-
);
180-
bytes memory _upgradeData;
181-
if (_version == 1) {
182-
_upgradeData = abi.encodeCall(
183-
AlignedTokenV1(_newImplementation).upgradeToAndCall,
184-
(_newImplementation, _initData)
185-
);
186-
} else if (_version == 2) {
187-
_upgradeData = abi.encodeCall(
188-
AlignedTokenV2Example(_newImplementation).upgradeToAndCall,
189-
(_newImplementation, _initData)
140+
return
141+
abi.encodeCall(
142+
ProxyAdmin(_proxyAdmin).upgradeAndCall,
143+
(
144+
ITransparentUpgradeableProxy(_proxy),
145+
_newImplementation,
146+
Utils.alignedTokenInitData(
147+
_newImplementation,
148+
_beneficiary1,
149+
_beneficiary2,
150+
_beneficiary3,
151+
_mintAmount
152+
)
153+
)
190154
);
191-
} else {
192-
revert("Unsupported version");
193-
}
194-
return _upgradeData;
195155
}
196156

197-
function deployClaimableAirdropImplementation(
198-
uint256 _version
199-
) internal returns (address) {
200-
address _implementation_address;
201-
if (_version == 1) {
202-
vm.broadcast();
203-
ClaimableAirdropV1 _implementation = new ClaimableAirdropV1();
204-
_implementation_address = address(_implementation);
205-
} else if (_version == 2) {
206-
vm.broadcast();
207-
ClaimableAirdropV2Example _implementation = new ClaimableAirdropV2Example();
208-
_implementation_address = address(_implementation);
209-
} else {
210-
revert("Unsupported version");
211-
}
212-
return _implementation_address;
157+
// ClaimableAirdrop utils
158+
159+
function deployClaimableAirdropImplementation() internal returns (address) {
160+
vm.broadcast();
161+
ClaimableAirdropV1 _implementation = new ClaimableAirdropV1();
162+
return address(_implementation);
213163
}
214164

215165
function claimableAirdropProxyDeploymentData(
166+
address _proxyAdmin,
216167
address _implementation,
217-
uint256 _version,
218-
address _safe,
168+
address _owner,
219169
address _tokenContractAddress,
220170
address _tokenOwnerAddress,
221171
uint256 _limitTimestampToClaim,
222172
bytes32 _claimMerkleRoot
223173
) internal pure returns (bytes memory) {
224174
return
225175
abi.encodePacked(
226-
type(ERC1967Proxy).creationCode,
227-
claimableAirdropInitData(
176+
type(TransparentUpgradeableProxy).creationCode,
177+
abi.encode(
228178
_implementation,
229-
_version,
230-
_safe,
231-
_tokenContractAddress,
232-
_tokenOwnerAddress,
233-
_limitTimestampToClaim,
234-
_claimMerkleRoot
179+
_proxyAdmin,
180+
claimableAirdropInitData(
181+
_implementation,
182+
_owner,
183+
_tokenContractAddress,
184+
_tokenOwnerAddress,
185+
_limitTimestampToClaim,
186+
_claimMerkleRoot
187+
)
235188
)
236189
);
237190
}
238191

239192
function claimableAirdropInitData(
240193
address _implementation,
241-
uint256 _version,
242-
address _safe,
194+
address _owner,
243195
address _tokenContractAddress,
244196
address _tokenOwnerAddress,
245197
uint256 _limitTimestampToClaim,
246198
bytes32 _claimMerkleRoot
247199
) internal pure returns (bytes memory) {
248-
if (_version == 1) {
249-
return
250-
abi.encodeCall(
251-
ClaimableAirdropV1(_implementation).initialize,
252-
(
253-
_safe,
254-
_tokenContractAddress,
255-
_tokenOwnerAddress,
256-
_limitTimestampToClaim,
257-
_claimMerkleRoot
258-
)
259-
);
260-
} else if (_version == 2) {
261-
return
262-
abi.encodeCall(
263-
ClaimableAirdropV2Example(_implementation).initialize,
264-
(
265-
_safe,
266-
_tokenContractAddress,
267-
_tokenOwnerAddress,
268-
_limitTimestampToClaim,
269-
_claimMerkleRoot
270-
)
271-
);
272-
} else {
273-
revert("Unsupported version");
274-
}
200+
return
201+
abi.encodeCall(
202+
ClaimableAirdropV1(_implementation).initialize,
203+
(
204+
_owner,
205+
_tokenContractAddress,
206+
_tokenOwnerAddress,
207+
_limitTimestampToClaim,
208+
_claimMerkleRoot
209+
)
210+
);
275211
}
276212

277213
function claimableAirdropUpgradeData(
214+
address _proxy,
215+
address _owner,
278216
address _newImplementation,
279-
uint256 _version,
280-
address _safe,
281217
address _tokenContractAddress,
282218
address _tokenOwnerAddress,
283219
uint256 _limitTimestampToClaim,
284220
bytes32 _claimMerkleRoot
285221
) internal pure returns (bytes memory) {
286-
bytes memory _initData = Utils.claimableAirdropInitData(
287-
_newImplementation,
288-
_version,
289-
_safe,
290-
_tokenContractAddress,
291-
_tokenOwnerAddress,
292-
_limitTimestampToClaim,
293-
_claimMerkleRoot
294-
);
295-
bytes memory _upgradeData;
296-
if (_version == 1) {
297-
_upgradeData = abi.encodeCall(
298-
ClaimableAirdropV1(_newImplementation).upgradeToAndCall,
299-
(_newImplementation, _initData)
300-
);
301-
} else if (_version == 2) {
302-
_upgradeData = abi.encodeCall(
303-
ClaimableAirdropV2Example(_newImplementation).upgradeToAndCall,
304-
(_newImplementation, _initData)
222+
return
223+
abi.encodeCall(
224+
ProxyAdmin(_newImplementation).upgradeAndCall,
225+
(
226+
ITransparentUpgradeableProxy(_proxy),
227+
_newImplementation,
228+
Utils.claimableAirdropInitData(
229+
_owner,
230+
_newImplementation,
231+
_tokenContractAddress,
232+
_tokenOwnerAddress,
233+
_limitTimestampToClaim,
234+
_claimMerkleRoot
235+
)
236+
)
305237
);
306-
} else {
307-
revert("Unsupported version");
308-
}
309-
return _upgradeData;
310238
}
311239

312-
240+
// ProxyAdmin utils
241+
242+
function deployProxyAdmin(address _safe) internal returns (address) {
243+
vm.broadcast();
244+
ProxyAdmin _proxyAdmin = new ProxyAdmin(_safe);
245+
return address(_proxyAdmin);
246+
}
247+
248+
function proxyAdminDeploymentData(
249+
address _safe
250+
) internal pure returns (bytes memory) {
251+
return
252+
abi.encodePacked(type(ProxyAdmin).creationCode, abi.encode(_safe));
253+
}
313254
}

0 commit comments

Comments
 (0)