Skip to content

Commit

Permalink
Implement task to deploy implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
evercoinx committed Nov 20, 2024
1 parent 34e4b79 commit 33495c7
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 16 deletions.
54 changes: 39 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions contracts/mocks/ChildPoolMock.sol
Original file line number Diff line number Diff line change
@@ -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_);
}
}
15 changes: 15 additions & 0 deletions contracts/mocks/MaticXMock.sol
Original file line number Diff line number Diff line change
@@ -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_);
}
}
15 changes: 15 additions & 0 deletions contracts/mocks/ValidatorRegistryMock.sol
Original file line number Diff line number Diff line change
@@ -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_);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
49 changes: 49 additions & 0 deletions tasks/deploy-implementation.ts
Original file line number Diff line number Diff line change
@@ -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<string>("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}`
);
}
);
1 change: 1 addition & 0 deletions tasks/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down

0 comments on commit 33495c7

Please sign in to comment.