diff --git a/yarn-project/aztec.js/src/utils/portal_manager.ts b/yarn-project/aztec.js/src/utils/portal_manager.ts index c2434ac61d3..660a63687d2 100644 --- a/yarn-project/aztec.js/src/utils/portal_manager.ts +++ b/yarn-project/aztec.js/src/utils/portal_manager.ts @@ -7,7 +7,7 @@ import { type SiblingPath, computeSecretHash, } from '@aztec/aztec.js'; -import { L1TxUtils, extractEvent } from '@aztec/ethereum'; +import { extractEvent } from '@aztec/ethereum'; import { sha256ToField } from '@aztec/foundation/crypto'; import { FeeJuicePortalAbi, OutboxAbi, TestERC20Abi, TokenPortalAbi } from '@aztec/l1-artifacts'; @@ -19,7 +19,6 @@ import { type HttpTransport, type PublicClient, type WalletClient, - encodeFunctionData, getContract, toFunctionSelector, } from 'viem'; @@ -60,7 +59,6 @@ export function generateClaimSecret(logger?: Logger): [Fr, Fr] { /** Helper for managing an ERC20 on L1. */ export class L1TokenManager { private contract: GetContractReturnType>; - private l1TxUtils: L1TxUtils; public constructor( /** Address of the ERC20 contract. */ @@ -74,7 +72,6 @@ export class L1TokenManager { abi: TestERC20Abi, client: this.walletClient, }); - this.l1TxUtils = new L1TxUtils(publicClient, walletClient, logger); } /** @@ -93,13 +90,8 @@ export class L1TokenManager { */ public async mint(amount: bigint, address: Hex, addressName?: string) { this.logger.info(`Minting ${amount} tokens for ${stringifyEthAddress(address, addressName)}`); - await this.l1TxUtils.sendAndMonitorTransaction({ - to: this.contract.address, - data: encodeFunctionData({ - abi: this.contract.abi, - functionName: 'mint', - args: [address, amount], - }), + await this.publicClient.waitForTransactionReceipt({ + hash: await this.contract.write.mint([address, amount]), }); } @@ -111,13 +103,8 @@ export class L1TokenManager { */ public async approve(amount: bigint, address: Hex, addressName = '') { this.logger.info(`Approving ${amount} tokens for ${stringifyEthAddress(address, addressName)}`); - await this.l1TxUtils.sendAndMonitorTransaction({ - to: this.contract.address, - data: encodeFunctionData({ - abi: this.contract.abi, - functionName: 'approve', - args: [address, amount], - }), + await this.publicClient.waitForTransactionReceipt({ + hash: await this.contract.write.approve([address, amount]), }); } } @@ -129,7 +116,6 @@ export class L1FeeJuicePortalManager { typeof FeeJuicePortalAbi, WalletClient >; - private readonly l1TxUtils: L1TxUtils; constructor( portalAddress: EthAddress, @@ -144,7 +130,6 @@ export class L1FeeJuicePortalManager { abi: FeeJuicePortalAbi, client: this.walletClient, }); - this.l1TxUtils = new L1TxUtils(publicClient, walletClient, logger); } /** Returns the associated token manager for the L1 ERC20. */ @@ -169,13 +154,10 @@ export class L1FeeJuicePortalManager { this.logger.info('Sending L1 Fee Juice to L2 to be claimed publicly'); const args = [to.toString(), amount, claimSecretHash.toString()] as const; - const txReceipt = await this.l1TxUtils.sendAndMonitorTransaction({ - to: this.contract.address, - data: encodeFunctionData({ - abi: this.contract.abi, - functionName: 'depositToAztecPublic', - args, - }), + await this.contract.simulate.depositToAztecPublic(args); + + const txReceipt = await this.publicClient.waitForTransactionReceipt({ + hash: await this.contract.write.depositToAztecPublic(args), }); const log = extractEvent( @@ -228,7 +210,6 @@ export class L1FeeJuicePortalManager { export class L1ToL2TokenPortalManager { protected readonly portal: GetContractReturnType>; protected readonly tokenManager: L1TokenManager; - protected readonly l1TxUtils: L1TxUtils; constructor( portalAddress: EthAddress, @@ -243,7 +224,6 @@ export class L1ToL2TokenPortalManager { abi: TokenPortalAbi, client: this.walletClient, }); - this.l1TxUtils = new L1TxUtils(publicClient, walletClient, logger); } /** Returns the token manager for the underlying L1 token. */ @@ -261,15 +241,14 @@ export class L1ToL2TokenPortalManager { const [claimSecret, claimSecretHash] = await this.bridgeSetup(amount, mint); this.logger.info('Sending L1 tokens to L2 to be claimed publicly'); - const args = [to.toString(), amount, claimSecretHash.toString()] as const; + const { request } = await this.portal.simulate.depositToAztecPublic([ + to.toString(), + amount, + claimSecretHash.toString(), + ]); - const txReceipt = await this.l1TxUtils.sendAndMonitorTransaction({ - to: this.portal.address, - data: encodeFunctionData({ - abi: this.portal.abi, - functionName: 'depositToAztecPublic', - args, - }), + const txReceipt = await this.publicClient.waitForTransactionReceipt({ + hash: await this.walletClient.writeContract(request), }); const log = extractEvent( @@ -307,13 +286,10 @@ export class L1ToL2TokenPortalManager { const [claimSecret, claimSecretHash] = await this.bridgeSetup(amount, mint); this.logger.info('Sending L1 tokens to L2 to be claimed privately'); - const txReceipt = await this.l1TxUtils.sendAndMonitorTransaction({ - to: this.portal.address, - data: encodeFunctionData({ - abi: this.portal.abi, - functionName: 'depositToAztecPrivate', - args: [amount, claimSecretHash.toString()], - }), + const { request } = await this.portal.simulate.depositToAztecPrivate([amount, claimSecretHash.toString()]); + + const txReceipt = await this.publicClient.waitForTransactionReceipt({ + hash: await this.walletClient.writeContract(request), }); const log = extractEvent( @@ -392,23 +368,17 @@ export class L1TokenPortalManager extends L1ToL2TokenPortalManager { throw new Error(`L1 to L2 message at block ${blockNumber} index ${messageIndex} has already been consumed`); } - const withdrawArgs = [ + // Call function on L1 contract to consume the message + const { request: withdrawRequest } = await this.portal.simulate.withdraw([ recipient.toString(), amount, false, BigInt(blockNumber), messageIndex, siblingPath.toBufferArray().map((buf: Buffer): Hex => `0x${buf.toString('hex')}`), - ] as const; - // Call function on L1 contract to consume the message - await this.l1TxUtils.sendAndMonitorTransaction({ - to: this.portal.address, - data: encodeFunctionData({ - abi: this.portal.abi, - functionName: 'withdraw', - args: withdrawArgs, - }), - }); + ]); + + await this.publicClient.waitForTransactionReceipt({ hash: await this.walletClient.writeContract(withdrawRequest) }); const isConsumedAfter = await this.outbox.read.hasMessageBeenConsumedAtBlockAndIndex([blockNumber, messageIndex]); if (!isConsumedAfter) { diff --git a/yarn-project/cli/src/cmds/infrastructure/sequencers.ts b/yarn-project/cli/src/cmds/infrastructure/sequencers.ts index 74432781dab..cf5dbe7bdc1 100644 --- a/yarn-project/cli/src/cmds/infrastructure/sequencers.ts +++ b/yarn-project/cli/src/cmds/infrastructure/sequencers.ts @@ -1,9 +1,9 @@ import { createCompatibleClient } from '@aztec/aztec.js'; -import { L1TxUtils, createEthereumChain, getL1ContractsConfigEnvVars } from '@aztec/ethereum'; +import { createEthereumChain, getL1ContractsConfigEnvVars } from '@aztec/ethereum'; import { type LogFn, type Logger } from '@aztec/foundation/log'; import { RollupAbi, TestERC20Abi } from '@aztec/l1-artifacts'; -import { createPublicClient, createWalletClient, encodeFunctionData, getContract, http } from 'viem'; +import { createPublicClient, createWalletClient, getContract, http } from 'viem'; import { mnemonicToAccount } from 'viem/accounts'; export async function sequencers(opts: { @@ -48,8 +48,6 @@ export async function sequencers(opts: { const who = (maybeWho as `0x{string}`) ?? walletClient?.account.address.toString(); - const l1TxUtils = walletClient ? new L1TxUtils(publicClient, walletClient, debugLogger) : undefined; - if (command === 'list') { const sequencers = await rollup.read.getAttesters(); if (sequencers.length === 0) { @@ -61,8 +59,8 @@ export async function sequencers(opts: { } } } else if (command === 'add') { - if (!who || !writeableRollup || !walletClient || !l1TxUtils) { - throw new Error(`Missing sequencer address or wallet configuration`); + if (!who || !writeableRollup || !walletClient) { + throw new Error(`Missing sequencer address`); } log(`Adding ${who} as sequencer`); @@ -74,55 +72,25 @@ export async function sequencers(opts: { }); const config = getL1ContractsConfigEnvVars(); - const mintRequest = { - to: stakingAsset.address, - data: encodeFunctionData({ - abi: stakingAsset.abi, - functionName: 'mint', - args: [walletClient.account.address, config.minimumStake], - }), - }; - const approveRequest = { - to: stakingAsset.address, - data: encodeFunctionData({ - abi: stakingAsset.abi, - functionName: 'approve', - args: [rollup.address, config.minimumStake], - }), - }; - - await Promise.all([ - l1TxUtils.sendAndMonitorTransaction(mintRequest), - l1TxUtils.sendAndMonitorTransaction(approveRequest), - ]); - // send and monitor deposit transaction - const depositReceipt = await l1TxUtils.sendAndMonitorTransaction({ - to: writeableRollup.address, - data: encodeFunctionData({ - abi: writeableRollup.abi, - functionName: 'deposit', - args: [who, who, who, config.minimumStake], - }), - }); + await Promise.all( + [ + await stakingAsset.write.mint([walletClient.account.address, config.minimumStake], {} as any), + await stakingAsset.write.approve([rollup.address, config.minimumStake], {} as any), + ].map(txHash => publicClient.waitForTransactionReceipt({ hash: txHash })), + ); - log(`Added in tx ${depositReceipt.transactionHash}`); + const hash = await writeableRollup.write.deposit([who, who, who, config.minimumStake]); + await publicClient.waitForTransactionReceipt({ hash }); + log(`Added in tx ${hash}`); } else if (command === 'remove') { - if (!who || !writeableRollup || !l1TxUtils) { - throw new Error(`Missing sequencer address or wallet configuration`); + if (!who || !writeableRollup) { + throw new Error(`Missing sequencer address`); } log(`Removing ${who} as sequencer`); - - const receipt = await l1TxUtils.sendAndMonitorTransaction({ - to: writeableRollup.address, - data: encodeFunctionData({ - abi: writeableRollup.abi, - functionName: 'initiateWithdraw', - args: [who, who], - }), - }); - - log(`Removed in tx ${receipt.transactionHash}`); + const hash = await writeableRollup.write.initiateWithdraw([who, who]); + await publicClient.waitForTransactionReceipt({ hash }); + log(`Removed in tx ${hash}`); } else if (command === 'who-next') { const next = await rollup.read.getCurrentProposer(); log(`Sequencer expected to build is ${next}`);