From 78822047ea9253022226db96e713a5b583526cb5 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Wed, 27 Sep 2023 14:07:51 +0100 Subject: [PATCH] refactor: token bridge contract takes token in constructor --- yarn-project/end-to-end/src/fixtures/utils.ts | 17 +++++------------ .../contracts/token_bridge_contract/src/main.nr | 4 ++-- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index 8b84f18d8b97..178e0912f772 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -402,31 +402,24 @@ export async function deployAndInitializeStandardizedTokenAndBridgeContracts( // deploy l2 token const deployTx = TokenContract.deploy(wallet, wallet.getCompleteAddress()).send(); - // deploy l2 token bridge and attach to the portal - const bridgeTx = TokenBridgeContract.deploy(wallet).send({ - portalContract: tokenPortalAddress, - contractAddressSalt: Fr.random(), - }); - // now wait for the deploy txs to be mined. This way we send all tx in the same rollup. const deployReceipt = await deployTx.wait(); if (deployReceipt.status !== TxStatus.MINED) throw new Error(`Deploy token tx status is ${deployReceipt.status}`); const token = await TokenContract.at(deployReceipt.contractAddress!, wallet); + // deploy l2 token bridge and attach to the portal + const bridgeTx = TokenBridgeContract.deploy(wallet, token.address).send({ + portalContract: tokenPortalAddress, + contractAddressSalt: Fr.random(), + }); const bridgeReceipt = await bridgeTx.wait(); if (bridgeReceipt.status !== TxStatus.MINED) throw new Error(`Deploy bridge tx status is ${bridgeReceipt.status}`); const bridge = await TokenBridgeContract.at(bridgeReceipt.contractAddress!, wallet); await bridge.attach(tokenPortalAddress); const bridgeAddress = bridge.address.toString() as `0x${string}`; - // initialize bridge - const initializeBridgeTx = bridge.methods._initialize(token.address).send(); - if ((await token.methods.admin().view()) !== owner.toBigInt()) throw new Error(`Token admin is not ${owner}`); - const initializeBridgeReceipt = await initializeBridgeTx.wait(); - if (initializeBridgeReceipt.status !== TxStatus.MINED) - throw new Error(`Initialize token bridge tx status is ${initializeBridgeReceipt.status}`); if ((await bridge.methods.token().view()) !== token.address.toBigInt()) throw new Error(`Bridge token is not ${token.address}`); diff --git a/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr index 97cc1b92b611..006f39d4c8de 100644 --- a/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr @@ -39,9 +39,9 @@ contract TokenBridge { // Constructs the contract. #[aztec(private)] - fn constructor() { + fn constructor(token: AztecAddress) { let selector = compute_selector("_initialize((Field))"); - let _callStackItem = context.call_public_function(context.this_address(), selector, [context.msg_sender()]); + let _callStackItem = context.call_public_function(context.this_address(), selector, token.serialize()); } // docs:start:claim_public