From 373600e4e6eb338aed30606352bfde55e3f9915d Mon Sep 17 00:00:00 2001 From: blockgroot <170620375+blockgroot@users.noreply.github.com> Date: Thu, 20 Jun 2024 11:01:43 +0530 Subject: [PATCH] refactor: remove unused contract (#241) --- contracts/L2/ETHx.sol | 74 ------------------------- scripts/safe-scripts/helpers/upgrade.ts | 11 +++- scripts/safe-scripts/upgrade.ts | 4 +- scripts/safe-scripts/upgradeAll.ts | 4 +- scripts/safe-scripts/upgradeAllBatch.ts | 48 ++++++++++++++++ 5 files changed, 62 insertions(+), 79 deletions(-) delete mode 100644 contracts/L2/ETHx.sol create mode 100644 scripts/safe-scripts/upgradeAllBatch.ts diff --git a/contracts/L2/ETHx.sol b/contracts/L2/ETHx.sol deleted file mode 100644 index 3323badb..00000000 --- a/contracts/L2/ETHx.sol +++ /dev/null @@ -1,74 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-or-later -pragma solidity 0.8.16; - -import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; -import { ERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol"; -import { AccessControlUpgradeable } from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; -import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; - -/** - * @title ETHx token Contract for L2s - * @author Stader Labs - * @notice The ERC20 contract for the ETHx token - */ -contract ETHx is Initializable, ERC20Upgradeable, PausableUpgradeable, AccessControlUpgradeable { - error ZeroAddress(); - - bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); - bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE"); - bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); - - /// @custom:oz-upgrades-unsafe-allow constructor - constructor() { - _disableInitializers(); - } - - function initialize(address _admin) external initializer onlyNonZeroAddress(_admin) { - __ERC20_init("ETHx", "ETHx"); - __Pausable_init(); - __AccessControl_init(); - - _grantRole(DEFAULT_ADMIN_ROLE, _admin); - } - - /** - * @notice Mints ethX when called by an authorized caller - * @param to the account to mint to - * @param amount the amount of ethX to mint - */ - function mint(address to, uint256 amount) external onlyRole(MINTER_ROLE) whenNotPaused { - _mint(to, amount); - } - - /** - * @notice Burns ethX when called by an authorized caller - * @param account the account to burn from - * @param amount the amount of ethX to burn - */ - function burnFrom(address account, uint256 amount) external onlyRole(BURNER_ROLE) whenNotPaused { - _burn(account, amount); - } - - /** - * @dev Triggers stopped state. - * Contract must not be paused. - */ - function pause() external onlyRole(PAUSER_ROLE) { - _pause(); - } - - /** - * @dev Returns to normal state. - * Contract must be paused - */ - function unpause() external onlyRole(DEFAULT_ADMIN_ROLE) { - _unpause(); - } - - modifier onlyNonZeroAddress(address _addr) { - if (_addr == address(0)) { - revert ZeroAddress(); - } - _; - } -} diff --git a/scripts/safe-scripts/helpers/upgrade.ts b/scripts/safe-scripts/helpers/upgrade.ts index 3e1eb239..d622c965 100644 --- a/scripts/safe-scripts/helpers/upgrade.ts +++ b/scripts/safe-scripts/helpers/upgrade.ts @@ -1,6 +1,4 @@ import hre from "hardhat"; -import proposeTransaction from "./proposeTransaction"; - async function main(contractAddress: string, contractName: string) { const { ethers, upgrades } = hre; const network = await ethers.provider.getNetwork(); @@ -27,12 +25,19 @@ async function main(contractAddress: string, contractName: string) { contractAddress, newImplementationAddress, ]); - await proposeTransaction(await proxyAdminContract.getAddress(), "0", encodedFunctionCall); console.log( `Upgrade transaction proposed for ${contractName} at ${contractAddress} to new implementation at ${newImplementationAddress}`, ); console.log(`When finished run to verify:`); console.log(`npx hardhat verify ${newImplementationAddress} --network ${network.name}`); + console.log("\n"); + + + const to = await proxyAdminContract.getAddress(); + const value ="0" + const data = encodedFunctionCall; + + return{to, value, data}; } export default main; diff --git a/scripts/safe-scripts/upgrade.ts b/scripts/safe-scripts/upgrade.ts index 87eefb82..689247c0 100644 --- a/scripts/safe-scripts/upgrade.ts +++ b/scripts/safe-scripts/upgrade.ts @@ -1,5 +1,6 @@ import hre from "hardhat"; import upgrade from "./helpers/upgrade"; +import proposeTransaction from "./helpers/proposeTransaction"; import addressJson from "./address.json"; @@ -21,7 +22,8 @@ async function main() { if (contract === undefined) { throw new Error(`Contract ${contractName} not found`); } - await upgrade(contract?.address, contractName); + const {to, value, data} = await upgrade(contract?.address, contractName); + await proposeTransaction(to, data, value); } catch (error) { console.error("An error occurred:", error); } diff --git a/scripts/safe-scripts/upgradeAll.ts b/scripts/safe-scripts/upgradeAll.ts index a3f76e70..ede3d2b6 100644 --- a/scripts/safe-scripts/upgradeAll.ts +++ b/scripts/safe-scripts/upgradeAll.ts @@ -1,6 +1,7 @@ const { ethers, upgrades } = require("hardhat"); import upgradeHelper from "./helpers/upgrade"; import networkAddresses from "./address.json"; +import proposeTransaction from "./helpers/proposeTransaction"; import { artifacts } from "hardhat"; async function main(networks: { [networkName: string]: { contracts: { name: string; address: string }[] } }) { @@ -26,7 +27,8 @@ async function main(networks: { [networkName: string]: { contracts: { name: stri if (deployedBytecode !== compiledBytecode) { console.warn(` Contract "${name}" is out of date!`); console.log(` Upgrading to latest version...`); - await upgradeHelper(address, name); + const {to, value, data} = await upgradeHelper(address, name); + await proposeTransaction(to, data, value); } else { console.log(` "${name}" is already up to date on network "${networkName}".`); } diff --git a/scripts/safe-scripts/upgradeAllBatch.ts b/scripts/safe-scripts/upgradeAllBatch.ts new file mode 100644 index 00000000..17087349 --- /dev/null +++ b/scripts/safe-scripts/upgradeAllBatch.ts @@ -0,0 +1,48 @@ +const { ethers, upgrades } = require("hardhat"); +import upgradeHelper from "./helpers/upgrade"; +import networkAddresses from "./address.json"; +import proposeTransactions from "./helpers/proposeTransactions"; +import { MetaTransactionData } from "@safe-global/safe-core-sdk-types"; + + +async function main(networks: { [networkName: string]: { contracts: { name: string; address: string }[] } }) { + const networkName = await hre.network.name; + const networkContracts = networks[networkName].contracts; + let targets = []; + let values = []; + let params = []; + + console.log(`Checking contracts on network "${networkName}":`, "\n"); + + for (let { name, address } of networkContracts) { + const { to, value, data } = await upgradeHelper(address, name); + targets.push(to) + values.push(value) + params.push(data) + } + const multisigData = await buildMultisigTx(targets,values, params); + await proposeTransactions(multisigData); +} + + + +async function buildMultisigTx(targets:string[], values:string[], params: string[]): Promise { + const safeTransactionData: MetaTransactionData[] = []; + for (let i = 0; i < targets.length; ++i) { + const safeTxData: MetaTransactionData = { + to: targets[i], + data: params[i], + value: values[i], + operation: 0, + }; + safeTransactionData.push(safeTxData); + } + return safeTransactionData; +} + +main(networkAddresses) + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + });