Skip to content

Commit

Permalink
Implement task to generate initializeV2 calldata for MaticX contract
Browse files Browse the repository at this point in the history
  • Loading branch information
evercoinx committed Dec 6, 2024
1 parent d9d5640 commit e31704b
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ AMOY_DEPLOYER := 0x8C6B3eE457b193A49794df466957441b4AccD102
# Ethereum (Preprod) contract addresses
ETHEREUM_PREPROD_VALIDATOR_REGISTRY := 0xcEbaFD96Df8a1Cc63ee77770296F14B68089Ab04
ETHEREUM_PREPROD_MATIC_X := 0xD22dd194B8ec2abEeeFAC36a69cd8898FB6C43b3
ETHEREUM_PREPROD_MATIC_X_IMPLEMENTATION := 0x801e30fD56b43641CcB7724b31F2401004B2609c
ETHEREUM_PREPROD_FX_STATE_ROOT_TUNNEL := 0xcD7AdBBF3030AFFa7766606c5EA9E016141422Ca
ETHEREUM_PREPROD_TIMELOCK_CONTROLLER := 0x420d319efe3Dd573Ccf3219dDdf60C83902B9f10
ETHEREUM_PREPROD_STAKE_MANAGER := 0x5e3Ef299fDDf15eAa0432E6e66473ace8c13D908
Expand All @@ -90,6 +91,7 @@ ETHEREUM_PREPROD_DEPLOYER := 0x6FCBE6C2d6f6c890fD0cC5b0288E2D474D90BB1F
# Ethereum (Prod) contract addresses
ETHEREUM_PROD_VALIDATOR_REGISTRY := 0xf556442D5B77A4B0252630E15d8BbE2160870d77
ETHEREUM_PROD_MATIC_X := 0xf03A7Eb46d01d9EcAA104558C732Cf82f6B6B645
ETHEREUM_PROD_MATIC_X_IMPLEMENTATION := 0x801e30fD56b43641CcB7724b31F2401004B2609c
ETHEREUM_PROD_FX_STATE_ROOT_TUNNEL := 0x40FB804Cc07302b89EC16a9f8d040506f64dFe29
ETHEREUM_PROD_TIMELOCK_CONTROLLER := 0x20Ea6f63de406040E1e4B67aD98E84A0Eb3778Be
ETHEREUM_PROD_STAKE_MANAGER := 0x5e3Ef299fDDf15eAa0432E6e66473ace8c13D908
Expand Down Expand Up @@ -355,6 +357,12 @@ initializev2-maticx-ethereum-preprod:
initializev2-maticx-ethereum-prod:
$(BIN_HARDHAT) initialize-v2:matic-x --network $(NETWORK_ETHEREUM) --contract $(ETHEREUM_PROD_MATIC_X) --pol $(ETHEREUM_PROD_POL)

# Generate initializeV2 calldata for the MaticX contract
generateinitializev2calldata-maticx-ethereum-preprod:
$(BIN_HARDHAT) generate-initializev2-calldata-matic-x --network $(NETWORK_ETHEREUM) --matic-x-proxy $(ETHEREUM_PREPROD_MATIC_X) --matic-x-implementation $(ETHEREUM_PREPROD_MATIC_X_IMPLEMENTATION) --pol $(ETHEREUM_PREPROD_POL)
generateinitializev2calldata-maticx-ethereum-prod:
$(BIN_HARDHAT) generate-initializev2-calldata-matic-x --network $(NETWORK_ETHEREUM) --matic-x-proxy $(ETHEREUM_PROD_MATIC_X) --matic-x-implementation $(ETHEREUM_PROD_MATIC_X_IMPLEMENTATION) --pol $(ETHEREUM_PROD_POL)

# 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) --matic-x-version $(MATIC_X_VERSION) --validator-registry-version $(VALIDATOR_REGISTRY_VERSION) --fee-percent $(MATIC_X_FEE_PERCENT)
Expand Down
10 changes: 10 additions & 0 deletions contracts/ProxyAdmin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.7;

import { ProxyAdmin as OpenzeppelinProxyAdmin } from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";

/**
* @title ProxyAdmin
*/
// solhint-disable-next-line no-empty-blocks
contract ProxyAdmin is OpenzeppelinProxyAdmin {}
70 changes: 70 additions & 0 deletions tasks/generate-initializev2-calldata-matic-x.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { AbiCoder } from "ethers";
import { task, types } from "hardhat/config";

interface TaskParams {
maticXProxy: string;
maticXImplementation: string;
pol: string;
}

task("generate-initializev2-calldata-matic-x")
.setDescription("Generate initializeV2 calldata for the MaticX contract")
.addParam<string>(
"maticXProxy",
"Address of the MaticX proxy contract",
undefined,
types.string
)
.addParam<string>(
"maticXImplementation",
"Address of the MaticX implementation contract",
undefined,
types.string
)
.addParam<string>("pol", "POL contract address", undefined, types.string)
.setAction(
async (
{
maticXProxy: maticXProxyAddress,
maticXImplementation: maticXImplementationAddress,
pol: polAddress,
}: TaskParams,
{ ethers }
) => {
if (!ethers.isAddress(maticXProxyAddress)) {
throw new Error("Invalid MaticX proxy address");
}
if (!ethers.isAddress(maticXImplementationAddress)) {
throw new Error("Invalid MaticX implementation address");
}
if (!ethers.isAddress(polAddress)) {
throw new Error("Invalid POL address");
}

const proxyAdmin = await ethers.getContractFactory(
"contracts/ProxyAdmin.sol:ProxyAdmin"
);
const maticX = await ethers.getContractFactory("MaticX");

const initialzeV2Selector =
maticX.interface.getFunction("initializeV2")?.selector;
if (!initialzeV2Selector) {
throw new Error("InitializeV2 selector on MaticX not defined");
}

const abiCoder = new AbiCoder();
const encodedPOLAddress = abiCoder.encode(
["address"],
[polAddress]
);

const initializeV2Calldata =
proxyAdmin.interface.encodeFunctionData("upgradeAndCall", [
maticXProxyAddress,
maticXImplementationAddress,
`${initialzeV2Selector}${encodedPOLAddress.slice(2)}`,
]);

console.log("Initialize v2 calldata:\n%s", initializeV2Calldata);
}
);
1 change: 1 addition & 0 deletions tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "./deploy-matic-x";
import "./deploy-timelock-controller";
import "./deploy-u-child-erc20";
import "./deploy-validator-registry";
import "./generate-initializev2-calldata-matic-x";
import "./import-contract";
import "./initialize-v2-matic-x";
import "./initialize-v2-validator-registry";
Expand Down

0 comments on commit e31704b

Please sign in to comment.