Skip to content

Commit

Permalink
Extend task to validate parent deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
evercoinx committed Nov 24, 2024
1 parent 9857b89 commit a36e29b
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ CONTRACT_PATH_VALIDATOR_REGISTRY := contracts/ValidatorRegistry.sol
CONTRACT_PATH_MATIC_X := contracts/MaticX.sol
CONTRACT_PATH_CHILD_POOL := contracts/ChildPool.sol

# Contract data
VALIDATOR_REGISTRY_VERSION := 2
MATIC_X_VERSION := 2
MATIC_X_FEE_PERCENT := 1100

all: hardhat

hardhat: deploy-validatorregistry-hardhat deploy-childpool-hardhat deploy-fxstateroottunnel-hardhat deploy-fxstatechildtunnel-hardhat
Expand Down Expand Up @@ -321,16 +326,22 @@ initializev2-maticx-ethereum-prod:
initializev2-maticx-ethereum-staging:
$(BIN_HARDHAT) initialize-v2:matic-x --network $(NETWORK_ETHEREUM) --contract $(ETHEREUM_STAGING_MATIC_X) --pol $(ETHEREUM_STAGING_POL)

# Validate environment deployment
validatedeployment-testnet: validateparentdeployment-sepolia validatechilddeployment-amoy

# Validate the parent deployment
validateparentdeployment-sepolia:
$(BIN_HARDHAT) validate-parent-deployment --network $(NETWORK_SEPOLIA) --validator-registry $(SEPOLIA_VALIDATOR_REGISTRY) --matic-x $(SEPOLIA_MATIC_X) --fx-state-root-tunnel $(SEPOLIA_FX_STATE_ROOT_TUNNEL) --fx-state-child-tunnel $(AMOY_FX_STATE_CHILD_TUNNEL) --stake-manager $(SEPOLIA_STAKE_MANAGER) --checkpoint-manager $(SEPOLIA_CHECKPOINT_MANAGER) --fx-root $(SEPOLIA_FX_ROOT) --matic $(SEPOLIA_MATIC) --pol $(SEPOLIA_POL) --manager $(SEPOLIA_MANAGER) --treasury $(SEPOLIA_TREASURY) --deployer $(SEPOLIA_DEPLOYER)
$(BIN_HARDHAT) validate-parent-deployment --network $(NETWORK_SEPOLIA) --validator-registry $(SEPOLIA_VALIDATOR_REGISTRY) --matic-x $(SEPOLIA_MATIC_X) --fx-state-root-tunnel $(SEPOLIA_FX_STATE_ROOT_TUNNEL) --fx-state-child-tunnel $(AMOY_FX_STATE_CHILD_TUNNEL) --stake-manager $(SEPOLIA_STAKE_MANAGER) --checkpoint-manager $(SEPOLIA_CHECKPOINT_MANAGER) --fx-root $(SEPOLIA_FX_ROOT) --matic $(SEPOLIA_MATIC) --pol $(SEPOLIA_POL) --manager $(SEPOLIA_MANAGER) --treasury $(SEPOLIA_TREASURY) --deployer $(SEPOLIA_DEPLOYER) --matic-x-version $(MATIC_X_VERSION) --validator-registry-version $(VALIDATOR_REGISTRY_VERSION) --fee-percent $(MATIC_X_FEE_PERCENT)
validateparentdeployment-ethereum-staging:
$(BIN_HARDHAT) validate-parent-deployment --network $(NETWORK_ETHEREUM) --validator-registry $(ETHEREUM_STAGING_VALIDATOR_REGISTRY) --matic-x $(ETHEREUM_STAGING_MATIC_X) --fx-state-root-tunnel $(ETHEREUM_STAGING_FX_STATE_ROOT_TUNNEL) --fx-state-child-tunnel $(POLYGON_STAGING_FX_STATE_CHILD_TUNNEL) --stake-manager $(ETHEREUM_STAGING_STAKE_MANAGER) --checkpoint-manager $(ETHEREUM_STAGING_CHECKPOINT_MANAGER) --fx-root $(ETHEREUM_STAGING_FX_ROOT) --matic $(ETHEREUM_STAGING_MATIC) --pol $(ETHEREUM_STAGING_POL) --manager $(ETHEREUM_STAGING_MANAGER) --treasury $(ETHEREUM_STAGING_TREASURY) --deployer $(ETHEREUM_STAGING_DEPLOYER) --matic-x-version $(MATIC_X_VERSION) --validator-registry-version $(VALIDATOR_REGISTRY_VERSION) --fee-percent $(MATIC_X_FEE_PERCENT)

# Validate the child deployment
validatechilddeployment-amoy:
$(BIN_HARDHAT) validate-child-deployment --network $(NETWORK_AMOY) --child-pool $(AMOY_CHILD_POOL) --matic-x $(AMOY_MATIC_X) --fx-state-child-tunnel $(AMOY_FX_STATE_CHILD_TUNNEL) --fx-state-root-tunnel $(SEPOLIA_FX_STATE_ROOT_TUNNEL) --fx-child $(AMOY_FX_CHILD) --manager $(AMOY_MANAGER) --treasury $(AMOY_TREASURY) --instant-pool-owner $(AMOY_INSTANT_POOL_OWNER) --deployer $(AMOY_DEPLOYER)
validatechilddeployment-polygon-staging:
$(BIN_HARDHAT) validate-child-deployment --network $(NETWORK_ETHEREUM) --child-pool $(POLYGON_STAGING_CHILD_POOL) --matic-x $(POLYGON_STAGING_MATIC_X) --fx-state-child-tunnel $(POLYGON_STAGING_FX_STATE_CHILD_TUNNEL) --fx-state-root-tunnel $(ETHEREUM_STAGING_FX_STATE_ROOT_TUNNEL) --fx-child $(POLYGON_STAGING_FX_CHILD) --manager $(POLYGON_STAGING_MANAGER) --treasury $(POLYGON_STAGING_TREASURY) --instant-pool-owner $(POLYGON_STAGING_INSTANT_POOL_OWNER) --deployer $(POLYGON_STAGING_DEPLOYER)

# Validate environment deployment
validatedeployment-testnet: validateparentdeployment-sepolia validatechilddeployment-amoy

validatedeployment-staging: validateparentdeployment-ethereum-staging validatechilddeployment-polygon-staging

# Analyze contracts with mythril
analyze-mytrhil-validatorregistry:
Expand Down
72 changes: 72 additions & 0 deletions tasks/validate-parent-deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ interface TaskParams {
manager: string;
treasury: string;
deployer: string;
maticXVersion: string;
validatorRegistryVersion: string;
feePercent: string;
}

type VersionedContract = MaticX | ValidatorRegistry;

type AccessControlledContract = FxStateRootTunnel | MaticX | ValidatorRegistry;

task("validate-parent-deployment")
Expand Down Expand Up @@ -92,6 +97,24 @@ task("validate-parent-deployment")
undefined,
types.string
)
.addParam<string>(
"maticXVersion",
"Version of the MaticX contract",
undefined,
types.string
)
.addParam<string>(
"validatorRegistryVersion",
"Version of the ValidatorRegistry contract",
undefined,
types.string
)
.addParam<string>(
"feePercent",
"Fee percent on MaticX contract",
undefined,
types.string
)
.setAction(
async (
{
Expand All @@ -107,6 +130,9 @@ task("validate-parent-deployment")
manager: managerAddress,
treasury: treasuryAddress,
deployer: deployerAddress,
maticXVersion,
validatorRegistryVersion,
feePercent,
}: TaskParams,
{ ethers, network, run }
) => {
Expand Down Expand Up @@ -146,6 +172,9 @@ task("validate-parent-deployment")
if (!ethers.isAddress(deployerAddress)) {
throw new Error("Invalid Deployer address");
}
if (!feePercent) {
throw new Error("Zero fee percent");
}

const networkName = network.name as Network;
console.log(`Network name: ${networkName}`);
Expand All @@ -160,6 +189,7 @@ task("validate-parent-deployment")
maticAddress,
polAddress,
managerAddress,
validatorRegistryVersion,
});

await run("validate-parent-deployment:matic-x", {
Expand All @@ -171,6 +201,8 @@ task("validate-parent-deployment")
polAddress,
managerAddress,
treasuryAddress,
feePercent,
maticXVersion,
});

await run("validate-parent-deployment:fx-state-root-tunnel", {
Expand All @@ -192,6 +224,7 @@ subtask("validate-parent-deployment:validator-registry")
.addParam<string>("maticAddress")
.addParam<string>("polAddress")
.addParam<string>("managerAddress")
.addParam<string>("validatorRegistryVersion")
.setAction(
async (
{
Expand All @@ -201,6 +234,7 @@ subtask("validate-parent-deployment:validator-registry")
maticAddress,
polAddress,
managerAddress,
validatorRegistryVersion,
},
{ ethers }
) => {
Expand All @@ -210,6 +244,13 @@ subtask("validate-parent-deployment:validator-registry")
validatorRegistryAddress
);

await validateVersion(
validatorRegistry,
"ValidatorRegistry",
validatorRegistryAddress,
validatorRegistryVersion
);

await validateAccessControl(
validatorRegistry,
"ValidatorRegistry",
Expand Down Expand Up @@ -258,6 +299,8 @@ subtask("validate-parent-deployment:matic-x")
.addParam<string>("polAddress")
.addParam<string>("managerAddress")
.addParam<string>("treasuryAddress")
.addParam<string>("feePercent")
.addParam<string>("maticXVersion")
.setAction(
async (
{
Expand All @@ -269,12 +312,21 @@ subtask("validate-parent-deployment:matic-x")
polAddress,
managerAddress,
treasuryAddress,
feePercent,
maticXVersion,
},
{ ethers }
) => {
console.log("MaticX validation started");
const maticX = await ethers.getContractAt("MaticX", maticXAddress);

await validateVersion(
maticX,
"MaticX",
maticXAddress,
maticXVersion
);

await validateAccessControl(
maticX,
"MaticX",
Expand Down Expand Up @@ -324,6 +376,12 @@ subtask("validate-parent-deployment:matic-x")
);
}

const currentFeePecent = await maticX.feePercent();
if (currentFeePecent.toString() !== feePercent) {
throw new Error(
`Call setFeePercent(${feePercent}) on MaticX(${maticXAddress})`
);
}
console.log("MaticX validation finished\n");
}
);
Expand Down Expand Up @@ -414,3 +472,17 @@ async function validateAccessControl(
);
}
}

async function validateVersion(
contract: VersionedContract,
contractName: string,
contractAddress: string,
version: string
) {
const currentVersion = await contract.version();
if (currentVersion !== version) {
throw new Error(
`Call setVersion(${version}) on ${contractName}(${contractAddress})`
);
}
}

0 comments on commit a36e29b

Please sign in to comment.