From bd52fb5b3c17d99394ec14535ba7e54c66f74417 Mon Sep 17 00:00:00 2001 From: Matt Curtis Date: Wed, 6 Nov 2024 11:07:43 +0000 Subject: [PATCH] Deploy scripts: load message bus address dynamically --- .../testing/003_simple_withdrawal.ts | 17 ++++++++--------- .../testnet/layer2/001_whitelist_tokens.ts | 10 +++++++++- 2 files changed, 17 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..c265311c4f 100644 --- a/contracts/deployment_scripts/testing/003_simple_withdrawal.ts +++ b/contracts/deployment_scripts/testing/003_simple_withdrawal.ts @@ -57,8 +57,14 @@ 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; + + var mbusBase = await hre.ethers.getContractAt("MessageBus", messageBusAddress); 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 +102,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..3839e92782 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.MessageBusAddress) { + throw new Error("Failed to retrieve MessageBusAddress from network config"); + } + const messageBusAddress = networkConfig.MessageBusAddress; + console.log(`Loaded message bus address = ${messageBusAddress}`); + // 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', messageBusAddress)); const gasLimit = await messageBusContract.getFunction('verifyMessageFinalized').estimateGas(messages[1], { maxFeePerGas: 1000000001, })