Skip to content

Commit 178c522

Browse files
author
ilitteri
committed
Add utils
1 parent 10b9dfc commit 178c522

File tree

1 file changed

+241
-0
lines changed

1 file changed

+241
-0
lines changed

claim_contracts/script/Utils.sol

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
pragma solidity ^0.8.13;
33

44
import {Vm} from "forge-std/Vm.sol";
5+
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
6+
import "../src/AlignedTokenV1.sol";
7+
import "../src/AlignedTokenV2Example.sol";
8+
import "../src/ClaimableAirdropV1.sol";
9+
import "../src/ClaimableAirdropV2Example.sol";
510

611
library Utils {
712
// Cheatcodes address, 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D.
@@ -69,4 +74,240 @@ library Utils {
6974
addr := mload(add(addressOffset, 20))
7075
}
7176
}
77+
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;
94+
}
95+
96+
function alignedTokenProxyDeploymentData(
97+
address _implementation,
98+
uint256 _version,
99+
address _safe,
100+
address _beneficiary1,
101+
address _beneficiary2,
102+
address _beneficiary3,
103+
uint256 _mintAmount
104+
) internal pure returns (bytes memory) {
105+
return
106+
abi.encodePacked(
107+
type(ERC1967Proxy).creationCode,
108+
alignedTokenInitData(
109+
_implementation,
110+
_version,
111+
_safe,
112+
_beneficiary1,
113+
_beneficiary2,
114+
_beneficiary3,
115+
_mintAmount
116+
)
117+
);
118+
}
119+
120+
function alignedTokenInitData(
121+
address _implementation,
122+
uint256 _version,
123+
address _safe,
124+
address _beneficiary1,
125+
address _beneficiary2,
126+
address _beneficiary3,
127+
uint256 _mintAmount
128+
) 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+
}
160+
}
161+
162+
function alignedTokenUpgradeData(
163+
address _newImplementation,
164+
uint256 _version,
165+
address _safe,
166+
address _beneficiary1,
167+
address _beneficiary2,
168+
address _beneficiary3,
169+
uint256 _mintAmount
170+
) 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)
190+
);
191+
} else {
192+
revert("Unsupported version");
193+
}
194+
return _upgradeData;
195+
}
196+
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;
213+
}
214+
215+
function claimableAirdropProxyDeploymentData(
216+
address _implementation,
217+
uint256 _version,
218+
address _safe,
219+
address _tokenContractAddress,
220+
address _tokenOwnerAddress,
221+
uint256 _limitTimestampToClaim,
222+
bytes32 _claimMerkleRoot
223+
) internal pure returns (bytes memory) {
224+
return
225+
abi.encodePacked(
226+
type(ERC1967Proxy).creationCode,
227+
claimableAirdropInitData(
228+
_implementation,
229+
_version,
230+
_safe,
231+
_tokenContractAddress,
232+
_tokenOwnerAddress,
233+
_limitTimestampToClaim,
234+
_claimMerkleRoot
235+
)
236+
);
237+
}
238+
239+
function claimableAirdropInitData(
240+
address _implementation,
241+
uint256 _version,
242+
address _safe,
243+
address _tokenContractAddress,
244+
address _tokenOwnerAddress,
245+
uint256 _limitTimestampToClaim,
246+
bytes32 _claimMerkleRoot
247+
) 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+
}
275+
}
276+
277+
function claimableAirdropUpgradeData(
278+
address _newImplementation,
279+
uint256 _version,
280+
address _safe,
281+
address _tokenContractAddress,
282+
address _tokenOwnerAddress,
283+
uint256 _limitTimestampToClaim,
284+
bytes32 _claimMerkleRoot
285+
) 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)
305+
);
306+
} else {
307+
revert("Unsupported version");
308+
}
309+
return _upgradeData;
310+
}
311+
312+
72313
}

0 commit comments

Comments
 (0)