Skip to content

Commit

Permalink
Move out tasks from hardhat configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
evercoinx committed Oct 4, 2024
1 parent afa11fe commit f0c5846
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 130 deletions.
136 changes: 6 additions & 130 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import * as dotenv from "dotenv";
import {
HardhatNetworkMiningConfig,
HardhatRuntimeEnvironment,
} from "hardhat/types";
import { HardhatUserConfig, task } from "hardhat/config";
import "@typechain/hardhat";
import "@nomiclabs/hardhat-waffle";
import { HardhatNetworkMiningConfig } from "hardhat/types";
import { HardhatUserConfig } from "hardhat/config";
import "@nomiclabs/hardhat-ethers";
import "@nomiclabs/hardhat-solhint";
import "@openzeppelin/hardhat-upgrades";
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-solhint";
import "@nomiclabs/hardhat-waffle";
import "@openzeppelin/hardhat-defender";
import "@openzeppelin/hardhat-upgrades";
import "@typechain/hardhat";
import "hardhat-contract-sizer";
import "hardhat-gas-reporter";
import "solidity-coverage";
import { deployDirect, deployProxy, verify } from "./scripts/tasks";
import "./tasks/deploy-validator-registry";
import { extractEnvironmentVariables } from "./utils/environment";

Expand All @@ -27,126 +23,6 @@ dotenv.config({

const envVars = extractEnvironmentVariables();

task("verifyMaticX", "MaticX contracts verification").setAction(
async (args, hre: HardhatRuntimeEnvironment) => {
await verify(hre);
}
);

task("deployFxStateChildTunnel", "Deploy FxStateChildTunnel").setAction(
async (args, hre: HardhatRuntimeEnvironment) => {
if (!isChildNetwork(hre.network.name)) {
return;
}
await deployDirect(hre, "FxStateChildTunnel", envVars.FX_CHILD);
}
);

task("deployFxStateRootTunnel", "Deploy FxStateRootTunnel")
.addPositionalParam("maticX")
.setAction(async ({ maticX }, hre: HardhatRuntimeEnvironment) => {
if (!isRootNetwork(hre.network.name)) {
return;
}
await deployDirect(
hre,
"FxStateRootTunnel",
envVars.CHECKPOINT_MANAGER,
envVars.FX_ROOT,
maticX
);
});

task("deployRateProvider", "Deploy RateProvider")
.addPositionalParam("fxStateChildTunnel")
.setAction(
async ({ fxStateChildTunnel }, hre: HardhatRuntimeEnvironment) => {
if (!isChildNetwork(hre.network.name)) {
return;
}
await deployDirect(hre, "RateProvider", fxStateChildTunnel);
}
);

task("deployMaticXImpl", "Deploy MaticX Implementation only").setAction(
async (args, hre: HardhatRuntimeEnvironment) => {
if (!isRootNetwork(hre.network.name)) {
return;
}
await deployDirect(hre, "MaticX");
}
);

task(
"deployValidatorRegistryImpl",
"Deploy ValidatorRegistry Implementation only"
).setAction(async (args, hre: HardhatRuntimeEnvironment) => {
if (!isRootNetwork(hre.network.name)) return;
await deployDirect(hre, "ValidatorRegistry");
});

task("deployChildPoolProxy", "Deploy ChildPool Proxy only")
.addPositionalParam("fxStateChildTunnel")
.addPositionalParam("maticX")
.addPositionalParam("manager")
.addPositionalParam("instantPoolOwner")
.addPositionalParam("treasury")
.addPositionalParam("instantWithdrawalFeeBps")
.setAction(
async (
{
fxStateChildTunnel,
maticX,
manager,
instantPoolOwner,
treasury,
instantWithdrawalFeeBps,
},
hre: HardhatRuntimeEnvironment
) => {
if (!isChildNetwork(hre.network.name)) return;
await deployProxy(
hre,
"ChildPool",
fxStateChildTunnel,
maticX,
manager,
instantPoolOwner,
treasury,
instantWithdrawalFeeBps
);
}
);

task("deployChildPoolImpl", "Deploy ChildPool Implementation only").setAction(
async (args, hre: HardhatRuntimeEnvironment) => {
if (!isChildNetwork(hre.network.name)) {
return;
}
await deployDirect(hre, "ChildPool");
}
);

function isChildNetwork(selected: string) {
const expected = "matic";
return _isCorrectNetwork(expected, selected);
}

function isRootNetwork(selected: string) {
const expected = "mainnet";
return _isCorrectNetwork(expected, selected);
}

function _isCorrectNetwork(expected: string, selected: string) {
if (selected === expected) {
return true;
}

console.log(
`Wrong network configuration! Expected: ${expected} Selected: ${selected}`
);
}

const mining: HardhatNetworkMiningConfig = {
auto: true,
interval: 1_000,
Expand Down
124 changes: 124 additions & 0 deletions scripts/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import * as GOERLI_DEPLOYMENT_DETAILS from "../testnet-deployment-info.json";
import { extractEnvironmentVariables } from "../utils/environment";

const envVars = extractEnvironmentVariables();

const verifyContract = async (
hre: HardhatRuntimeEnvironment,
Expand Down Expand Up @@ -58,3 +62,123 @@ export async function deployProxy(

console.log(`Proxy ${contractName} deployed to:`, contract.address);
}

task("verifyMaticX", "MaticX contracts verification").setAction(
async (args, hre: HardhatRuntimeEnvironment) => {
await verify(hre);
}
);

task("deployFxStateChildTunnel", "Deploy FxStateChildTunnel").setAction(
async (args, hre: HardhatRuntimeEnvironment) => {
if (!isChildNetwork(hre.network.name)) {
return;
}
await deployDirect(hre, "FxStateChildTunnel", envVars.FX_CHILD);
}
);

task("deployFxStateRootTunnel", "Deploy FxStateRootTunnel")
.addPositionalParam("maticX")
.setAction(async ({ maticX }, hre: HardhatRuntimeEnvironment) => {
if (!isRootNetwork(hre.network.name)) {
return;
}
await deployDirect(
hre,
"FxStateRootTunnel",
envVars.CHECKPOINT_MANAGER,
envVars.FX_ROOT,
maticX
);
});

task("deployRateProvider", "Deploy RateProvider")
.addPositionalParam("fxStateChildTunnel")
.setAction(
async ({ fxStateChildTunnel }, hre: HardhatRuntimeEnvironment) => {
if (!isChildNetwork(hre.network.name)) {
return;
}
await deployDirect(hre, "RateProvider", fxStateChildTunnel);
}
);

task("deployMaticXImpl", "Deploy MaticX Implementation only").setAction(
async (args, hre: HardhatRuntimeEnvironment) => {
if (!isRootNetwork(hre.network.name)) {
return;
}
await deployDirect(hre, "MaticX");
}
);

task(
"deployValidatorRegistryImpl",
"Deploy ValidatorRegistry Implementation only"
).setAction(async (args, hre: HardhatRuntimeEnvironment) => {
if (!isRootNetwork(hre.network.name)) return;
await deployDirect(hre, "ValidatorRegistry");
});

task("deployChildPoolProxy", "Deploy ChildPool Proxy only")
.addPositionalParam("fxStateChildTunnel")
.addPositionalParam("maticX")
.addPositionalParam("manager")
.addPositionalParam("instantPoolOwner")
.addPositionalParam("treasury")
.addPositionalParam("instantWithdrawalFeeBps")
.setAction(
async (
{
fxStateChildTunnel,
maticX,
manager,
instantPoolOwner,
treasury,
instantWithdrawalFeeBps,
},
hre: HardhatRuntimeEnvironment
) => {
if (!isChildNetwork(hre.network.name)) return;
await deployProxy(
hre,
"ChildPool",
fxStateChildTunnel,
maticX,
manager,
instantPoolOwner,
treasury,
instantWithdrawalFeeBps
);
}
);

task("deployChildPoolImpl", "Deploy ChildPool Implementation only").setAction(
async (args, hre: HardhatRuntimeEnvironment) => {
if (!isChildNetwork(hre.network.name)) {
return;
}
await deployDirect(hre, "ChildPool");
}
);

function isChildNetwork(selected: string) {
const expected = "matic";
return _isCorrectNetwork(expected, selected);
}

function isRootNetwork(selected: string) {
const expected = "mainnet";
return _isCorrectNetwork(expected, selected);
}

function _isCorrectNetwork(expected: string, selected: string) {
if (selected === expected) {
return true;
}

console.log(
`Wrong network configuration! Expected: ${expected} Selected: ${selected}`
);
}

0 comments on commit f0c5846

Please sign in to comment.