From 5ac3c6fec4e4655f751324a6bc9b2e1b92cf42f2 Mon Sep 17 00:00:00 2001 From: Franco NG Date: Tue, 11 Jun 2024 16:14:07 +0200 Subject: [PATCH] Add deployment script --- .../L2/paused/L2GovernorPaused.s.sol | 53 ++++++++++++++++++ .../L2/paused/L2VotingPowerPaused.s.sol | 56 +++++++++++++++++++ script/contracts/Utils.sol | 4 ++ 3 files changed, 113 insertions(+) create mode 100644 script/contracts/L2/paused/L2GovernorPaused.s.sol create mode 100644 script/contracts/L2/paused/L2VotingPowerPaused.s.sol diff --git a/script/contracts/L2/paused/L2GovernorPaused.s.sol b/script/contracts/L2/paused/L2GovernorPaused.s.sol new file mode 100644 index 00000000..66b5719d --- /dev/null +++ b/script/contracts/L2/paused/L2GovernorPaused.s.sol @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity 0.8.23; + +import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; +import { Upgrades } from "openzeppelin-foundry-upgrades/Upgrades.sol"; +import { Options } from "openzeppelin-foundry-upgrades/Options.sol"; +import { Script, console2 } from "forge-std/Script.sol"; +import { L2GovernorPaused } from "src/L2/paused/L2GovernorPaused.sol"; +import "script/contracts/Utils.sol"; + +/// @title L2GovernorPausedScript - L2GovernorPaused contract deployment script +/// @notice This contract is used to deploy L2GovernorPaused contract and write its address to JSON file. +contract L2GovernorPausedScript is Script { + /// @notice Utils contract which provides functions to read and write JSON files containing L1 and L2 addresses. + Utils utils; + + function setUp() public { + utils = new Utils(); + } + + /// @notice This function deploys L2GovernorPaused contract and writes its address to JSON file. + function run() public { + // Deployer's private key. This key is used to deploy the contract. + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + + // Validate L2GovernorPaused contract if it is implemented correctly so that it may be used as new + // implementation for the proxy contract. + Options memory opts; + opts.referenceContract = "L2Governor.sol"; + opts.unsafeAllow = "constructor,external-library-linking"; + Upgrades.validateUpgrade("L2GovernorPaused.sol", opts); + + console2.log("Deploying L2GovernorPaused contract..."); + + // deploy L2GovernorPaused contract + vm.startBroadcast(deployerPrivateKey); + L2GovernorPaused l2GovernorPaused = new L2GovernorPaused(); + vm.stopBroadcast(); + + assert(address(l2GovernorPaused) != address(0)); + + // ERC1967Utils: keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1. + assert(l2GovernorPaused.proxiableUUID() == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)); + + console2.log("L2GovernorPaused contract successfully deployed!"); + console2.log("L2GovernorPaused (Implementation) address: %s", address(l2GovernorPaused)); + + // write L2GovernorPaused address to l2addresses.json + Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(); + l2AddressesConfig.L2GovernorPaused = address(l2GovernorPaused); + utils.writeL2AddressesFile(l2AddressesConfig); + } +} diff --git a/script/contracts/L2/paused/L2VotingPowerPaused.s.sol b/script/contracts/L2/paused/L2VotingPowerPaused.s.sol new file mode 100644 index 00000000..7a1da787 --- /dev/null +++ b/script/contracts/L2/paused/L2VotingPowerPaused.s.sol @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity 0.8.23; + +import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; +import { Upgrades } from "openzeppelin-foundry-upgrades/Upgrades.sol"; +import { Options } from "openzeppelin-foundry-upgrades/Options.sol"; +import { Script, console2 } from "forge-std/Script.sol"; +import { L2VotingPowerPaused } from "src/L2/paused/L2VotingPowerPaused.sol"; +import "script/contracts/Utils.sol"; + +/// @title L2VotingPowerPausedScript - L2VotingPowerPaused contract deployment script +/// @notice This contract is used to deploy L2VotingPowerPaused contract and write its address to JSON file. +contract L2VotingPowerPausedScript is Script { + /// @notice Utils contract which provides functions to read and write JSON files containing L1 and L2 addresses. + Utils utils; + + function setUp() public { + utils = new Utils(); + } + + /// @notice This function deploys L2VotingPowerPaused contract and writes its address to JSON file. + function run() public { + // Deployer's private key. This key is used to deploy the contract. + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + + // Validate L2VotingPowerPaused contract if it is implemented correctly so that it may be used as new + // implementation for the proxy contract. + Options memory opts; + opts.referenceContract = "L2VotingPower.sol"; + opts.unsafeAllow = "constructor,external-library-linking"; + Upgrades.validateUpgrade("L2VotingPowerPaused.sol", opts); + + console2.log("Deploying L2VotingPowerPaused contract..."); + + // deploy L2VotingPowerPaused contract + vm.startBroadcast(deployerPrivateKey); + L2VotingPowerPaused l2VotingPowerPausedImplementation = new L2VotingPowerPaused(); + vm.stopBroadcast(); + + assert(address(l2VotingPowerPausedImplementation) != address(0)); + + // ERC1967Utils: keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1. + assert( + l2VotingPowerPausedImplementation.proxiableUUID() + == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1) + ); + + console2.log("L2VotingPowerPaused contract successfully deployed!"); + console2.log("L2VotingPowerPaused (Implementation) address: %s", address(l2VotingPowerPausedImplementation)); + + // write L2VotingPowerPaused address to l2addresses.json + Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(); + l2AddressesConfig.L2VotingPowerPaused = address(l2VotingPowerPausedImplementation); + utils.writeL2AddressesFile(l2AddressesConfig); + } +} diff --git a/script/contracts/Utils.sol b/script/contracts/Utils.sol index 3402ebf8..693a44f4 100644 --- a/script/contracts/Utils.sol +++ b/script/contracts/Utils.sol @@ -29,6 +29,8 @@ contract Utils is Script { address L2Governor; /// @notice The Current implementation of L2 Governor Contract. address L2GovernorImplementation; + /// @notice The Current implementation of L2GovernorPaused Contract. + address L2GovernorPaused; /// @notice L2 Lisk token address. address L2LiskToken; /// @notice L2 Locking Position contract (in Proxy), which users interact with. @@ -51,6 +53,8 @@ contract Utils is Script { address L2VotingPower; /// @notice The Current implementation of L2 Voting Power Contract. address L2VotingPowerImplementation; + /// @notice The Current implementation of L2VotingPowerPaused Contract. + address L2VotingPowerPaused; } /// @notice This struct is used to read MerkleRoot from JSON file.