Skip to content

Commit

Permalink
refactor: token bridge contract takes token in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Sep 27, 2023
1 parent 4bb0351 commit 7882204
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
17 changes: 5 additions & 12 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7882204

Please sign in to comment.