From 4fce4ab7cf3a7c722f8524dd4098fa132998ace1 Mon Sep 17 00:00:00 2001 From: Matt <98158711+BedrockSquirrel@users.noreply.github.com> Date: Wed, 6 Nov 2024 12:58:19 +0000 Subject: [PATCH] Deploy scripts: load message bus address dynamically (#2127) --- .../testing/003_simple_withdrawal.ts | 18 +++++++++--------- .../testnet/layer2/001_whitelist_tokens.ts | 10 +++++++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/contracts/deployment_scripts/testing/003_simple_withdrawal.ts b/contracts/deployment_scripts/testing/003_simple_withdrawal.ts index b8f4f24469..2b447a07a1 100644 --- a/contracts/deployment_scripts/testing/003_simple_withdrawal.ts +++ b/contracts/deployment_scripts/testing/003_simple_withdrawal.ts @@ -57,8 +57,15 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { return; const l2Network = hre; const {deployer} = await hre.getNamedAccounts(); - - var mbusBase = await hre.ethers.getContractAt("MessageBus", "0x526c84529b2b8c11f57d93d3f5537aca3aecef9b"); + + const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + console.log(`Network config = ${JSON.stringify(networkConfig, null, 2)}`); + + const mgmtContractAddress = networkConfig.ManagementContractAddress; + const messageBusAddress = networkConfig.MessageBusAddress; + const l2MessageBusAddress = networkConfig.L2MessageBusAddress; + + var mbusBase = await hre.ethers.getContractAt("MessageBus", l2MessageBusAddress); const mbus = mbusBase.connect(await hre.ethers.provider.getSigner(deployer)); const tx = await mbus.getFunction("sendValueToL2").send(deployer, 1000, { value: 1000}); const receipt = await tx.wait() @@ -96,13 +103,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { return } - - const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); - console.log(`Network config = ${JSON.stringify(networkConfig, null, 2)}`); - - const mgmtContractAddress = networkConfig.ManagementContractAddress; - const messageBusAddress = networkConfig.MessageBusAddress; - const l1Accounts = await hre.companionNetworks.layer1.getNamedAccounts() const fundTx = await hre.companionNetworks.layer1.deployments.rawTx({ from: l1Accounts.deployer, diff --git a/contracts/deployment_scripts/testnet/layer2/001_whitelist_tokens.ts b/contracts/deployment_scripts/testnet/layer2/001_whitelist_tokens.ts index 2b3064758c..c831f99bb3 100644 --- a/contracts/deployment_scripts/testnet/layer2/001_whitelist_tokens.ts +++ b/contracts/deployment_scripts/testnet/layer2/001_whitelist_tokens.ts @@ -27,6 +27,14 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { console.log(` Using deployers for bridge interaction L1 address=${l1Accounts.deployer} L2 Address=${l2Accounts.deployer}`); + // Request the message bus address from the config endpoint + const networkConfig: any = await hre.network.provider.request({ method: 'net_config' }); + if (!networkConfig || !networkConfig.L2MessageBusAddress) { + throw new Error("Failed to retrieve L2MessageBusAddress from network config"); + } + const l2messageBusAddress = networkConfig.L2MessageBusAddress; + console.log(`Loaded message bus address = ${l2messageBusAddress}`); + // Tell the bridge to whitelist the address of HOC token. This generates a cross chain message. let hocResult = await l1Network.deployments.execute("ObscuroBridge", { from: l1Accounts.deployer, @@ -95,7 +103,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { // Poll message submission await new Promise(async (resolve, fail)=> { setTimeout(fail, 30_000) - const messageBusContract = (await hre.ethers.getContractAt('MessageBus', '0x526c84529b2b8c11f57d93d3f5537aca3aecef9b')); + const messageBusContract = (await hre.ethers.getContractAt('MessageBus', l2messageBusAddress)); const gasLimit = await messageBusContract.getFunction('verifyMessageFinalized').estimateGas(messages[1], { maxFeePerGas: 1000000001, })