Skip to content

Commit

Permalink
refactor(script): use create2 for deployments, prompt user for version
Browse files Browse the repository at this point in the history
  • Loading branch information
jparklev committed Apr 25, 2024
1 parent aed4f4a commit ebc9c85
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 29 deletions.
34 changes: 10 additions & 24 deletions contracts/script/PointTokenVault.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,11 @@ contract PointTokenVaultScripts is BatchScript {
function run() public returns (address) {
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY");

string memory version = vm.prompt("Enter PointTokenVault version:");

vm.startBroadcast(deployerPrivateKey);

PointTokenVault pointTokenVaultImplementation = new PointTokenVault();

PointTokenVault pointTokenVault = PointTokenVault(
address(
new ERC1967Proxy(
address(pointTokenVaultImplementation), abi.encodeCall(PointTokenVault.initialize, (msg.sender))
)
)
);
PointTokenVault pointTokenVault = run(version);

// Set roles
pointTokenVault.grantRole(pointTokenVault.MERKLE_UPDATER_ROLE(), SEOPLIA_MERKLE_BOT_SAFE);
Expand All @@ -56,23 +50,15 @@ contract PointTokenVaultScripts is BatchScript {
return address(pointTokenVault);
}

function deployPointTokenVault(address admin, string memory version) public returns (PointTokenVault) {
PointTokenVault pointTokenVaultImplementation = PointTokenVault(
CREATE3.deploy(
keccak256(bytes(string.concat("PointTokenVault", "-v", version))), type(PointTokenVault).creationCode, 0
)
);
function run(string memory version) public returns (PointTokenVault) {
PointTokenVault pointTokenVaultImplementation = new PointTokenVault{salt: keccak256(abi.encode(version))}();

PointTokenVault pointTokenVault = PointTokenVault(
CREATE3.deploy(
keccak256(bytes(string.concat("PointTokenVaultProxy", "-v", version))),
abi.encodePacked(
type(ERC1967Proxy).creationCode,
abi.encode(
address(pointTokenVaultImplementation), abi.encodeCall(PointTokenVault.initialize, (admin))
)
),
0
address(
new ERC1967Proxy{salt: keccak256(abi.encode(version))}(
address(pointTokenVaultImplementation),
abi.encodeCall(PointTokenVault.initialize, (msg.sender)) // msg.sender is admin
)
)
);

Expand Down
2 changes: 1 addition & 1 deletion contracts/test/PointTokenVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ contract PointTokenVaultTest is Test {
PointTokenVaultScripts scripts = new PointTokenVaultScripts();

// Deploy the PointTokenVault
pointTokenVault = scripts.deployPointTokenVault(address(this), "0.0.1");
pointTokenVault = scripts.run("0.0.1");

pointTokenVault.grantRole(pointTokenVault.DEFAULT_ADMIN_ROLE(), admin);
pointTokenVault.grantRole(pointTokenVault.MERKLE_UPDATER_ROLE(), merkleUpdater);
Expand Down
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ test = 'contracts/test'
out = "contracts/out"
libs = ["lib"]
ffi = true
evm_version = "cancun"

[rpc_endpoints]
sepolia = "${SEPOLIA_RPC_URL}"
Expand Down
2 changes: 1 addition & 1 deletion lib/openzeppelin-contracts
2 changes: 1 addition & 1 deletion lib/openzeppelin-contracts-upgradeable

0 comments on commit ebc9c85

Please sign in to comment.