[Chore] Add setMessageServiceOnTokenBridge task (#347)

* add setMessageServiceOnTokenBridge task

* remove duplicate and correct conditional

* fix missing ! in check
This commit is contained in:
The Dark Jester
2024-11-28 16:48:24 +00:00
committed by GitHub
parent 8226d2c9b2
commit 7476afd033
2 changed files with 52 additions and 0 deletions

View File

@@ -12,6 +12,8 @@ import "./scripts/operational/renounceContractRolesTask";
import "./scripts/operational/setRateLimitTask";
import "./scripts/operational/setVerifierAddressTask";
import "./scripts/operational/transferOwnershipAndSetRemoteTokenBridgeTask";
import "./scripts/operational/setMessageServiceOnTokenBridgeTask";
import "solidity-docgen";
dotenv.config();

View File

@@ -0,0 +1,50 @@
// import { ethers, network, upgrades } from "hardhat";
import { task } from "hardhat/config";
import { TokenBridge } from "../../typechain-types";
import { getTaskCliOrEnvValue } from "../../common/helpers/environmentHelper";
import { getDeployedContractOnNetwork } from "../../common/helpers/readAddress";
/*
*******************************************************************************************
1. Deploy the TokenBridge + MessageService contracts on both networks and get the addresses
2. Run this script on both addresses with the correct variables set.
*******************************************************************************************
SEPOLIA_PRIVATE_KEY=<key> \
INFURA_API_KEY=<key> \
npx hardhat setMessageServiceOnTokenBridge \
--message-service-address <address> \
--token-bridge-address <address> \
--network sepolia
*******************************************************************************************
*/
task("setMessageServiceOnTokenBridge", "Sets The Message Service On A TokenBridge")
.addOptionalParam("messageServiceAddress")
.addOptionalParam("tokenBridgeAddress")
.setAction(async (taskArgs, hre) => {
const ethers = hre.ethers;
const messageServiceAddress = getTaskCliOrEnvValue(taskArgs, "messageServiceAddress", "MESSAGE_SERVICE_ADDRESS");
if (!messageServiceAddress) {
throw "messageServiceAddress is undefined";
}
let tokenBridgeAddress = getTaskCliOrEnvValue(taskArgs, "tokenBridgeAddress", "TOKEN_BRIDGE_ADDRESS");
if (!tokenBridgeAddress) {
tokenBridgeAddress = await getDeployedContractOnNetwork(hre.network.name, "TokenBridge");
if (!tokenBridgeAddress) {
throw "tokenBridgeAddress is undefined";
}
}
const chainId = (await ethers.provider.getNetwork()).chainId;
console.log(`Current network's chainId is ${chainId}`);
const TokenBridge = await ethers.getContractFactory("TokenBridge");
const tokenBridge = TokenBridge.attach(tokenBridgeAddress) as TokenBridge;
const tx = await tokenBridge.setMessageService(messageServiceAddress!);
await tx.wait();
console.log(`MessageService set for the TokenBridge on: ${hre.network.name}`);
});