Skip to content

Commit f775156

Browse files
author
ilitteri
committed
Add scripts for AlignedToken
1 parent 59ae563 commit f775156

8 files changed

+331
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.19;
3+
4+
import "../../src/AlignedTokenV1.sol";
5+
import "../../src/AlignedTokenV2Example.sol";
6+
import "forge-std/Script.sol";
7+
import {Utils} from "../Utils.sol";
8+
9+
contract AlignedTokenCreate2 is Script {
10+
function run(uint256 _version, bytes32 _salt, address _deployer) public {
11+
address _create2Address;
12+
if (_version == 1) {
13+
_create2Address = vm.computeCreate2Address(
14+
_salt,
15+
keccak256(type(AlignedTokenV1).creationCode),
16+
_deployer
17+
);
18+
} else if (_version == 2) {
19+
_create2Address = vm.computeCreate2Address(
20+
_salt,
21+
keccak256(type(AlignedTokenV2Example).creationCode),
22+
_deployer
23+
);
24+
} else {
25+
revert("Unsupported version");
26+
}
27+
console.logAddress(_create2Address);
28+
vm.writeFile(
29+
string.concat(
30+
vm.projectRoot(),
31+
"/script-out/aligned_token_v",
32+
vm.toString(_version),
33+
"_create2_address.hex"
34+
),
35+
vm.toString(_create2Address)
36+
);
37+
}
38+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.19;
3+
4+
import "forge-std/Script.sol";
5+
import {Utils} from "../Utils.sol";
6+
7+
contract AlignedTokenInitData is Script {
8+
function run(
9+
address _implementation,
10+
uint256 _version,
11+
address _safe,
12+
address _beneficiary1,
13+
address _beneficiary2,
14+
address _beneficiary3,
15+
uint256 _mintAmount
16+
) public {
17+
bytes memory data = Utils.alignedTokenInitData(
18+
_implementation,
19+
_version,
20+
_safe,
21+
_beneficiary1,
22+
_beneficiary2,
23+
_beneficiary3,
24+
_mintAmount
25+
);
26+
console.logBytes(data);
27+
vm.writeFile(
28+
string.concat(
29+
vm.projectRoot(),
30+
"/script-out/aligned_token_init_data.hex"
31+
),
32+
vm.toString(data)
33+
);
34+
}
35+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.19;
3+
4+
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
5+
import "forge-std/Script.sol";
6+
import {Utils} from "../Utils.sol";
7+
8+
contract AlignedTokenProxyCreate2 is Script {
9+
function run(
10+
bytes32 _salt,
11+
address _deployer,
12+
address _implementation,
13+
uint256 _version,
14+
address _safe,
15+
address _beneficiary1,
16+
address _beneficiary2,
17+
address _beneficiary3,
18+
uint256 _mintAmount
19+
) public {
20+
address _create2Address = vm.computeCreate2Address(
21+
_salt,
22+
keccak256(
23+
Utils.alignedTokenProxyDeploymentData(
24+
_implementation,
25+
_version,
26+
_safe,
27+
_beneficiary1,
28+
_beneficiary2,
29+
_beneficiary3,
30+
_mintAmount
31+
)
32+
),
33+
_deployer
34+
);
35+
console.logAddress(_create2Address);
36+
vm.writeFile(
37+
string.concat(
38+
vm.projectRoot(),
39+
"/script-out/aligned_token_proxy_create2_address.hex"
40+
),
41+
vm.toString(_create2Address)
42+
);
43+
}
44+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.19;
3+
4+
import "forge-std/Script.sol";
5+
import {Utils} from "../Utils.sol";
6+
7+
contract AlignedTokenProxyDeploymentData is Script {
8+
function run(
9+
address _implementation,
10+
uint256 _version,
11+
address _safe,
12+
address _beneficiary1,
13+
address _beneficiary2,
14+
address _beneficiary3,
15+
uint256 _mintAmount
16+
) public {
17+
bytes memory data = Utils.alignedTokenProxyDeploymentData(
18+
_implementation,
19+
_version,
20+
_safe,
21+
_beneficiary1,
22+
_beneficiary2,
23+
_beneficiary3,
24+
_mintAmount
25+
);
26+
console.logBytes(data);
27+
vm.writeFile(
28+
string.concat(
29+
vm.projectRoot(),
30+
"/script-out/aligned_token_proxy_deployment_data.hex"
31+
),
32+
vm.toString(data)
33+
);
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.19;
3+
4+
import "forge-std/Script.sol";
5+
import {Utils} from "../Utils.sol";
6+
7+
contract AlignedTokenUpgradeData is Script {
8+
function run(
9+
address _newImplementation,
10+
uint256 _version,
11+
address _safe,
12+
address _beneficiary1,
13+
address _beneficiary2,
14+
address _beneficiary3,
15+
uint256 _mintAmount
16+
) public {
17+
bytes memory _upgradeData = Utils.alignedTokenUpgradeData(
18+
_newImplementation,
19+
_version,
20+
_safe,
21+
_beneficiary1,
22+
_beneficiary2,
23+
_beneficiary3,
24+
_mintAmount
25+
);
26+
console.logBytes(_upgradeData);
27+
vm.writeFile(
28+
string.concat(
29+
vm.projectRoot(),
30+
"/script-out/aligned_token_upgrade_data.hex"
31+
),
32+
vm.toString(_upgradeData)
33+
);
34+
}
35+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.19;
3+
4+
import "../../src/AlignedTokenV1.sol";
5+
import "../../src/AlignedTokenV2Example.sol";
6+
import "forge-std/Script.sol";
7+
import {Utils} from "../Utils.sol";
8+
9+
contract DeployTokenImplementation is Script {
10+
function run(uint256 _version) public {
11+
address _implementation_address = Utils
12+
.deployAlignedTokenImplementation(_version);
13+
14+
console.log(
15+
string.concat(
16+
"Token Implementation v",
17+
vm.toString(_version),
18+
"Address:"
19+
),
20+
_implementation_address
21+
);
22+
23+
vm.serializeAddress(
24+
"implementation",
25+
"address",
26+
_implementation_address
27+
);
28+
29+
string memory out;
30+
if (_version == 1) {
31+
out = vm.serializeBytes(
32+
"implementation",
33+
"deploymentData",
34+
type(AlignedTokenV1).creationCode
35+
);
36+
} else if (_version == 2) {
37+
out = vm.serializeBytes(
38+
"implementation",
39+
"deploymentData",
40+
type(AlignedTokenV2Example).creationCode
41+
);
42+
} else {
43+
revert("Unsupported version");
44+
}
45+
46+
string memory path = string.concat(
47+
vm.projectRoot(),
48+
"/script-out/aligned_token_implementation_v",
49+
vm.toString(_version),
50+
".json"
51+
);
52+
53+
vm.writeJson(out, path);
54+
}
55+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.19;
3+
4+
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
5+
import "forge-std/Script.sol";
6+
import {Utils} from "../Utils.sol";
7+
8+
contract DeployAlignedTokenProxy is Script {
9+
function run(
10+
address _implementation,
11+
uint256 _version,
12+
address _safe,
13+
address _beneficiary1,
14+
address _beneficiary2,
15+
address _beneficiary3,
16+
uint256 _mintAmount
17+
) public {
18+
bytes memory _deploymentData = Utils.alignedTokenInitData(
19+
_implementation,
20+
_version,
21+
_safe,
22+
_beneficiary1,
23+
_beneficiary2,
24+
_beneficiary3,
25+
_mintAmount
26+
);
27+
vm.broadcast();
28+
ERC1967Proxy _proxy = new ERC1967Proxy(
29+
_implementation,
30+
_deploymentData
31+
);
32+
33+
console.log("Aligned Token Proxy Address:", address(_proxy));
34+
35+
vm.serializeAddress("proxy", "address", address(_proxy));
36+
string memory _out = vm.serializeBytes(
37+
"proxy",
38+
"deploymentData",
39+
Utils.alignedTokenProxyDeploymentData(
40+
_implementation,
41+
_version,
42+
_safe,
43+
_beneficiary1,
44+
_beneficiary2,
45+
_beneficiary3,
46+
_mintAmount
47+
)
48+
);
49+
string memory _path = string.concat(
50+
vm.projectRoot(),
51+
"/script-out/aligned_token_proxy.json"
52+
);
53+
vm.writeJson(_out, _path);
54+
}
55+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.19;
3+
4+
import "../src/AlignedTokenV1.sol";
5+
import "../src/AlignedTokenV2Example.sol";
6+
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
7+
import "forge-std/Script.sol";
8+
import {Utils} from "./Utils.sol";
9+
10+
contract UpgradeAlignedTokenImplementation is Script {
11+
function run(
12+
address _proxy,
13+
address _newImplementation,
14+
uint256 _version,
15+
address _safe,
16+
address _beneficiary1,
17+
address _beneficiary2,
18+
address _beneficiary3,
19+
uint256 _mintAmount
20+
) public {
21+
bytes memory _upgradeData = Utils.alignedTokenUpgradeData(
22+
_newImplementation,
23+
_version,
24+
_safe,
25+
_beneficiary1,
26+
_beneficiary2,
27+
_beneficiary3,
28+
_mintAmount
29+
);
30+
31+
vm.broadcast();
32+
_proxy.call(_upgradeData);
33+
}
34+
}

0 commit comments

Comments
 (0)