-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement task to deploy ValidatorRegistry contract
- Loading branch information
Showing
5 changed files
with
239 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Binaries | ||
BIN_HARDHAT := ./node_modules/.bin/hardhat | ||
BIN_ECHIDNA := echidna | ||
BIN_MYTH := myth | ||
|
||
# Configs | ||
CONFIG_ECHIDNA := echidna.config.yaml | ||
CONFIG_SOLC := solc.json | ||
|
||
# Networks | ||
NETWORK_HARDHAT := hardhat | ||
NETWORK_LOCALHOST := localhost | ||
NETWORK_HOLESKY := holesky | ||
NETWORK_ETHEREUM := ethereum | ||
|
||
# Hardhat contract addresses | ||
HARDHAT_MATICX := 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 | ||
HARDHAT_VALIDATOR_REGISTRY := 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 | ||
HARDHAT_STAKE_MANAGER := 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 | ||
HARDHAT_MATIC_TOKEN := 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 | ||
HARDHAT_MATICX := 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 | ||
HARDHAT_MANAGER := 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 | ||
|
||
# Localhost contract addresses | ||
LOCALHOST_MATICX := | ||
LOCALHOST_VALIDATOR_REGISTRY := | ||
LOCALHOST_STAKE_MANAGER := | ||
LOCALHOST_MATIC_TOKEN := | ||
LOCALHOST_MATICX := | ||
LOCALHOST_MANAGER := | ||
|
||
# Holesky contract addresses | ||
HOLESKY_MATICX := | ||
HOLESKY_VALIDATOR_REGISTRY := | ||
HOLESKY_STAKE_MANAGER := | ||
HOLESKY_MATIC_TOKEN := | ||
HOLESKY_MATICX := | ||
HOLESKY_MANAGER := | ||
|
||
# Ethereum contract addresses | ||
ETHEREUM_MATICX := | ||
ETHEREUM_VALIDATOR_REGISTRY := | ||
ETHEREUM_STAKE_MANAGER := | ||
ETHEREUM_MATIC_TOKEN := | ||
ETHEREUM_MATICX := | ||
ETHEREUM_MANAGER := | ||
|
||
all: hardhat | ||
|
||
hardhat: deploy-validatorregistry-hardhat | ||
|
||
localhost: deploy-validatorregistry-localhost | ||
|
||
# Deploy the MaticX contract | ||
deploy-validatorregistry-hardhat: | ||
$(BIN_HARDHAT) deploy:validator-registry --network $(NETWORK_HARDHAT) --stake-manager $(HARDHAT_STAKE_MANAGER) --matic-token $(HARDHAT_MATIC_TOKEN) --matic-x $(HARDHAT_MATICX) --manager $(HARDHAT_MANAGER) | ||
deploy-validatorregistry-localhost: | ||
$(BIN_HARDHAT) deploy:validator-registry --network $(NETWORK_LOCALHOST) | ||
deploy-validatorregistry-holesky: | ||
$(BIN_HARDHAT) deploy:validator-registry --network $(NETWORK_HOLESKY) | ||
deploy-validatorregistry-ethereum: | ||
$(BIN_HARDHAT) deploy:validator-registry --network $(NETWORK_ETHEREUM) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { TASK_CLEAN, TASK_COMPILE } from "hardhat/builtin-tasks/task-names"; | ||
import { task, types } from "hardhat/config"; | ||
import { getSigner } from "../utils/account"; | ||
import { isLocalNetwork, Network } from "../utils/network"; | ||
|
||
interface TaskParams { | ||
stakeManager: string; | ||
maticToken: string; | ||
maticX: string; | ||
manager: string; | ||
} | ||
|
||
task("deploy:validator-registry") | ||
.setDescription("Deploy the ValidatorRegistry contract") | ||
.addParam<string>( | ||
"stakeManager", | ||
"Address of the StakeManager contract", | ||
undefined, | ||
types.string | ||
) | ||
.addParam<string>( | ||
"maticToken", | ||
"Address of the MaticToken contract", | ||
undefined, | ||
types.string | ||
) | ||
.addParam<string>( | ||
"maticX", | ||
"Address of the MaticX contract", | ||
undefined, | ||
types.string | ||
) | ||
.addParam<string>( | ||
"manager", | ||
"Address of the Manager contract", | ||
undefined, | ||
types.string | ||
) | ||
.setAction( | ||
async ( | ||
{ | ||
stakeManager: stakeManagerAddress, | ||
maticToken: maticTokenAddress, | ||
maticX: maticXAddress, | ||
manager: managerAddress, | ||
}: TaskParams, | ||
{ ethers, network, run, upgrades } | ||
) => { | ||
if (!ethers.utils.isAddress(stakeManagerAddress)) { | ||
throw new Error("Invalid StakeManager address"); | ||
} | ||
if (!ethers.utils.isAddress(maticTokenAddress)) { | ||
throw new Error("Invalid MaticToken address"); | ||
} | ||
if (!ethers.utils.isAddress(maticXAddress)) { | ||
throw new Error("Invalid MaticX address"); | ||
} | ||
if (!ethers.utils.isAddress(managerAddress)) { | ||
throw new Error("Invalid Manager address"); | ||
} | ||
|
||
const networkName = network.name as Network; | ||
console.log(`Network name: ${networkName}`); | ||
if (!isLocalNetwork(networkName)) { | ||
await run(TASK_CLEAN); | ||
} | ||
await run(TASK_COMPILE); | ||
|
||
const deployer = await getSigner( | ||
ethers, | ||
network.provider, | ||
network.config.from | ||
); | ||
const ValidatorRegistry = await ethers.getContractFactory( | ||
"ValidatorRegistry", | ||
deployer | ||
); | ||
|
||
const validatorRegistry = await upgrades.deployProxy( | ||
ValidatorRegistry, | ||
[ | ||
stakeManagerAddress, | ||
maticTokenAddress, | ||
maticXAddress, | ||
managerAddress, | ||
], | ||
{ kind: "transparent" } | ||
); | ||
await validatorRegistry.deployed(); | ||
|
||
console.log( | ||
`ValidatorRegistry Proxy deployed at ${validatorRegistry.address}` | ||
); | ||
|
||
const implementationAddress = | ||
await upgrades.erc1967.getImplementationAddress( | ||
validatorRegistry.address | ||
); | ||
console.log( | ||
`ValidatorRegistry Implementation deployed at ${implementationAddress}` | ||
); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
export enum Provider { | ||
Alchemy = "alchemy", | ||
Infura = "infura", | ||
} | ||
|
||
export enum Network { | ||
Hardhat = "hardhat", | ||
Localhost = "localhost", | ||
Holesky = "holesky", | ||
Ethereum = "ethereum", | ||
EthereumAlt = "mainnet", | ||
} | ||
|
||
export function getProviderUrl( | ||
network: Network, | ||
provider: Provider, | ||
apiKey: string | ||
): string { | ||
if (network === Network.Localhost) { | ||
return "http://127.0.0.1:8545"; | ||
} | ||
|
||
const urls: Record<string, Record<Provider, string | undefined>> = { | ||
[Network.Holesky]: { | ||
[Provider.Alchemy]: "https://eth-holesky.g.alchemy.com", | ||
[Provider.Infura]: "https://holesky.infura.io", | ||
}, | ||
[Network.Ethereum]: { | ||
[Provider.Alchemy]: "https://eth-mainnet.g.alchemy.com", | ||
[Provider.Infura]: "https://mainnet.infura.io", | ||
}, | ||
[Network.EthereumAlt]: { | ||
[Provider.Alchemy]: "https://eth-mainnet.g.alchemy.com", | ||
[Provider.Infura]: "https://mainnet.infura.io", | ||
}, | ||
}; | ||
|
||
const apiVersions: Record<Provider, number> = { | ||
[Provider.Alchemy]: 2, | ||
[Provider.Infura]: 3, | ||
}; | ||
|
||
return ( | ||
provider && | ||
`${urls[network][provider]}/v${apiVersions[provider]}/${apiKey}` | ||
); | ||
} | ||
|
||
export function isLocalNetwork(network: Network): boolean { | ||
return [Network.Hardhat, Network.Localhost].includes(network); | ||
} | ||
|
||
export function isTestNetwork(network: Network): boolean { | ||
return [Network.Holesky].includes(network); | ||
} | ||
|
||
export function isMainNetwork(network: Network): boolean { | ||
return [Network.Ethereum, Network.EthereumAlt].includes(network); | ||
} |