From 33495c762b13a525e3ad0ba9ccf4e274db658b47 Mon Sep 17 00:00:00 2001 From: Sergey <2901744+evercoinx@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:10:57 +0100 Subject: [PATCH] Implement task to deploy implementation --- Makefile | 54 ++++++++++++++++------- contracts/mocks/ChildPoolMock.sol | 15 +++++++ contracts/mocks/MaticXMock.sol | 15 +++++++ contracts/mocks/ValidatorRegistryMock.sol | 15 +++++++ package.json | 2 +- tasks/deploy-implementation.ts | 49 ++++++++++++++++++++ tasks/index.ts | 1 + 7 files changed, 135 insertions(+), 16 deletions(-) create mode 100644 contracts/mocks/ChildPoolMock.sol create mode 100644 contracts/mocks/MaticXMock.sol create mode 100644 contracts/mocks/ValidatorRegistryMock.sol create mode 100644 tasks/deploy-implementation.ts diff --git a/Makefile b/Makefile index 63a505bc..5c79c40b 100644 --- a/Makefile +++ b/Makefile @@ -32,20 +32,20 @@ HARDHAT_TREASURY := 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 HARDHAT_INSTANT_POOL_OWNER := 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 # Localhost contract addresses -LOCALHOST_VALIDATOR_REGISTRY := -LOCALHOST_MATIC_X := -LOCALHOST_CHILD_POOL := -LOCALHOST_STAKE_MANAGER := -LOCALHOST_CHECKPOINT_MANAGER := -LOCALHOST_FX_ROOT := -LOCALHOST_FX_CHILD := -LOCALHOST_FX_STATE_ROOT_TUNNEL := -LOCALHOST_FX_STATE_CHILD_TUNNEL := -LOCALHOST_MATIC_TOKEN := -LOCALHOST_POL_TOKEN := -LOCALHOST_MANAGER := -LOCALHOST_TREASURY := -LOCALHOST_INSTANT_POOL_OWNER := +LOCALHOST_VALIDATOR_REGISTRY := 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 +LOCALHOST_MATIC_X := 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 +LOCALHOST_CHILD_POOL := 0xa513E6E4b8f2a923D98304ec87F64353C4D5C853 +LOCALHOST_STAKE_MANAGER := 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 +LOCALHOST_CHECKPOINT_MANAGER := 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 +LOCALHOST_FX_ROOT := 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 +LOCALHOST_FX_CHILD := 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 +LOCALHOST_FX_STATE_ROOT_TUNNEL := 0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9 +LOCALHOST_FX_STATE_CHILD_TUNNEL := 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 +LOCALHOST_MATIC_TOKEN := 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 +LOCALHOST_POL_TOKEN := 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 +LOCALHOST_MANAGER := 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 +LOCALHOST_TREASURY := 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 +LOCALHOST_INSTANT_POOL_OWNER := 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 # Sepolia contract addresses SEPOLIA_VALIDATOR_REGISTRY := 0xE98fc808E8aE8025a1D17d6F4Fbc3Df226788438 @@ -98,7 +98,7 @@ all: hardhat hardhat: deploy-validatorregistry-hardhat deploy-childpool-hardhat deploy-fxstateroottunnel-hardhat deploy-fxstatechildtunnel-hardhat -localhost: deploy-validatorregistry-localhost deploy-childpool-localhost deploy-fxstateroottunnel-localhost deploy-fxstatechildtunnel-localhost +localhost: deploy-validatorregistry-localhost deploy-maticx-localhost deploy-fxstateroottunnel-localhost deploy-fxstatechildtunnel-localhost deploy-childpool-localhost # Deploy the ValidatorRegistry contract deploy-validatorregistry-hardhat: @@ -124,6 +124,30 @@ deploy-maticx-ethereum: deploy-maticx-polygon: $(BIN_HARDHAT) deploy:u-child-erc20 --network $(NETWORK_POLYGON) --name "Liquid Staking Matic (PoS)" --symbol "MaticX" --child-chain-manager $(POLYGON_MANAGER) +# Deploy an implementation of the MaticX contract +deployimplementation-maticx-localhost: + $(BIN_HARDHAT) deploy-implementation --network $(NETWORK_LOCALHOST) --name MaticX +deployimplementation-maticx-sepolia: + $(BIN_HARDHAT) deploy-implementation --network $(NETWORK_SEPOLIA) --name MaticX +deployimplementation-maticx-ethereum: + $(BIN_HARDHAT) deploy-implementation --network $(NETWORK_ETHEREUM) --name MaticX + +# Deploy an implementation of the ValidatorRegistry contract +deployimplementation-validatorregistry-localhost: + $(BIN_HARDHAT) deploy-implementation --network $(NETWORK_LOCALHOST) --name ValidatorRegistry +deployimplementation-validatorregistry-sepolia: + $(BIN_HARDHAT) deploy-implementation --network $(NETWORK_SEPOLIA) --name ValidatorRegistry +deployimplementation-validatorregistry-ethereum: + $(BIN_HARDHAT) deploy-implementation --network $(NETWORK_ETHEREUM) --name ValidatorRegistry + +# Deploy an implementation of the ChildPool contract +deployimplementation-childpool-localhost: + $(BIN_HARDHAT) deploy-implementation --network $(NETWORK_LOCALHOST) --name ChildPool +deployimplementation-childpool-amoy: + $(BIN_HARDHAT) deploy-implementation --network $(NETWORK_AMOY) --name ChildPool +deployimplementation-childpool-polygon: + $(BIN_HARDHAT) deploy-implementation --network $(NETWORK_POLYGON) --name ChildPool + # Deploy the ChildPool contract deploy-childpool-hardhat: $(BIN_HARDHAT) deploy:child-pool --network $(NETWORK_HARDHAT) --fx-state-child-tunnel $(HARDHAT_FX_STATE_CHILD_TUNNEL) --matic-x $(HARDHAT_MATIC_X) --manager $(HARDHAT_MANAGER) --instant-pool-owner $(HARDHAT_INSTANT_POOL_OWNER) --treasury $(HARDHAT_TREASURY) diff --git a/contracts/mocks/ChildPoolMock.sol b/contracts/mocks/ChildPoolMock.sol new file mode 100644 index 00000000..23f78321 --- /dev/null +++ b/contracts/mocks/ChildPoolMock.sol @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity 0.8.7; + +import { ChildPool } from "../ChildPool.sol"; + +contract ChildPoolMock is ChildPool { + uint256 public value; + + event ValueSet(uint256 value); + + function setValue(uint256 value_) external { + value = value_; + emit ValueSet(value_); + } +} diff --git a/contracts/mocks/MaticXMock.sol b/contracts/mocks/MaticXMock.sol new file mode 100644 index 00000000..a8d87bb9 --- /dev/null +++ b/contracts/mocks/MaticXMock.sol @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity 0.8.7; + +import { MaticX } from "../MaticX.sol"; + +contract MaticXMock is MaticX { + uint256 public value; + + event ValueSet(uint256 value); + + function setValue(uint256 value_) external { + value = value_; + emit ValueSet(value_); + } +} diff --git a/contracts/mocks/ValidatorRegistryMock.sol b/contracts/mocks/ValidatorRegistryMock.sol new file mode 100644 index 00000000..7c7e3a68 --- /dev/null +++ b/contracts/mocks/ValidatorRegistryMock.sol @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity 0.8.7; + +import { ValidatorRegistry } from "../ValidatorRegistry.sol"; + +contract ValidatorRegistryMock is ValidatorRegistry { + uint256 public value; + + event ValueSet(uint256 value); + + function setValue(uint256 value_) external { + value = value_; + emit ValueSet(value_); + } +} diff --git a/package.json b/package.json index e15e51b2..8e0eab79 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "gas": "REPORT_GAS=true npm run test", "size": "hardhat size-contracts", "clean": "hardhat clean && rm -rf coverage cache crytic-{corpus,export} mochaOutput.json testMatrix.json", - "node": "hardat node", + "node": "hardhat node", "analyze": "slitherin .", "analyze:ci": "slitherin . --skip-clean --ignore-compile" }, diff --git a/tasks/deploy-implementation.ts b/tasks/deploy-implementation.ts new file mode 100644 index 00000000..30a590c5 --- /dev/null +++ b/tasks/deploy-implementation.ts @@ -0,0 +1,49 @@ +import { task, types } from "hardhat/config"; +import { TASK_CLEAN, TASK_COMPILE } from "hardhat/builtin-tasks/task-names"; +import { getSigner } from "../utils/account"; +import { isLocalNetwork, Network } from "../utils/network"; + +interface TaskParams { + name: string; +} + +task("deploy-implementation") + .setDescription("Deploy a contract implementation") + .addParam("name", "Contract name", undefined, types.string) + .setAction( + async ( + { name: contractName }: TaskParams, + { ethers, upgrades, network, run } + ) => { + const networkName = network.name as Network; + console.log(`Network name: ${networkName}`); + if (!isLocalNetwork(networkName)) { + await run(TASK_CLEAN); + } + await run(TASK_COMPILE); + + const signer = await getSigner( + ethers, + network.provider, + network.config.from + ); + const adjustedContractName = isLocalNetwork(networkName) + ? `${contractName}Mock` + : contractName; + const ContractFactory = await ethers.getContractFactory( + adjustedContractName, + signer + ); + + const implementationAddress = await upgrades.deployImplementation( + ContractFactory, + { + kind: "transparent", + verifySourceCode: true, + } + ); + console.log( + `${contractName} Implementation deployed at ${implementationAddress}` + ); + } + ); diff --git a/tasks/index.ts b/tasks/index.ts index e508232d..56c18b86 100644 --- a/tasks/index.ts +++ b/tasks/index.ts @@ -1,6 +1,7 @@ import "./deploy-child-pool"; import "./deploy-fx-state-child-tunnel"; import "./deploy-fx-state-root-tunnel"; +import "./deploy-implementation"; import "./deploy-matic-x"; import "./deploy-u-child-erc20"; import "./deploy-validator-registry";