1- import type { ViemPublicClient , ViemWalletClient } from '@aztec/ethereum' ;
1+ import type { ExtendedViemWalletClient , ViemContract } from '@aztec/ethereum' ;
22import { extractEvent } from '@aztec/ethereum/utils' ;
33import { sha256ToField } from '@aztec/foundation/crypto' ;
44import { EthAddress } from '@aztec/foundation/eth-address' ;
@@ -14,7 +14,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
1414import { computeSecretHash } from '@aztec/stdlib/hash' ;
1515import type { PXE } from '@aztec/stdlib/interfaces/client' ;
1616
17- import { type GetContractReturnType , type Hex , getContract , toFunctionSelector } from 'viem' ;
17+ import { type Hex , getContract , toFunctionSelector } from 'viem' ;
1818
1919import type { Wallet } from '../index.js' ;
2020
@@ -57,28 +57,27 @@ export async function generateClaimSecret(logger?: Logger): Promise<[Fr, Fr]> {
5757
5858/** Helper for managing an ERC20 on L1. */
5959export class L1TokenManager {
60- private contract : GetContractReturnType < typeof TestERC20Abi , ViemWalletClient > ;
61- private handler : GetContractReturnType < typeof FeeAssetHandlerAbi , ViemWalletClient > | undefined ;
60+ private contract : ViemContract < typeof TestERC20Abi > ;
61+ private handler : ViemContract < typeof FeeAssetHandlerAbi > | undefined ;
6262
6363 public constructor (
6464 /** Address of the ERC20 contract. */
6565 public readonly tokenAddress : EthAddress ,
6666 /** Address of the handler/faucet contract. */
6767 public readonly handlerAddress : EthAddress | undefined ,
68- private publicClient : ViemPublicClient ,
69- private walletClient : ViemWalletClient ,
68+ private readonly extendedClient : ExtendedViemWalletClient ,
7069 private logger : Logger ,
7170 ) {
7271 this . contract = getContract ( {
7372 address : this . tokenAddress . toString ( ) ,
7473 abi : TestERC20Abi ,
75- client : this . walletClient ,
74+ client : this . extendedClient ,
7675 } ) ;
7776 if ( this . handlerAddress ) {
7877 this . handler = getContract ( {
7978 address : this . handlerAddress . toString ( ) ,
8079 abi : FeeAssetHandlerAbi ,
81- client : this . walletClient ,
80+ client : this . extendedClient ,
8281 } ) ;
8382 }
8483 }
@@ -124,7 +123,7 @@ export class L1TokenManager {
124123 */
125124 public async approve ( amount : bigint , address : Hex , addressName = '' ) {
126125 this . logger . info ( `Approving ${ amount } tokens for ${ stringifyEthAddress ( address , addressName ) } ` ) ;
127- await this . publicClient . waitForTransactionReceipt ( {
126+ await this . extendedClient . waitForTransactionReceipt ( {
128127 hash : await this . contract . write . approve ( [ address , amount ] ) ,
129128 } ) ;
130129 }
@@ -133,21 +132,20 @@ export class L1TokenManager {
133132/** Helper for interacting with the FeeJuicePortal on L1. */
134133export class L1FeeJuicePortalManager {
135134 private readonly tokenManager : L1TokenManager ;
136- private readonly contract : GetContractReturnType < typeof FeeJuicePortalAbi , ViemWalletClient > ;
135+ private readonly contract : ViemContract < typeof FeeJuicePortalAbi > ;
137136
138137 constructor (
139138 portalAddress : EthAddress ,
140139 tokenAddress : EthAddress ,
141140 handlerAddress : EthAddress ,
142- private readonly publicClient : ViemPublicClient ,
143- private readonly walletClient : ViemWalletClient ,
141+ private readonly extendedClient : ExtendedViemWalletClient ,
144142 private readonly logger : Logger ,
145143 ) {
146- this . tokenManager = new L1TokenManager ( tokenAddress , handlerAddress , publicClient , walletClient , logger ) ;
144+ this . tokenManager = new L1TokenManager ( tokenAddress , handlerAddress , extendedClient , logger ) ;
147145 this . contract = getContract ( {
148146 address : portalAddress . toString ( ) ,
149147 abi : FeeJuicePortalAbi ,
150- client : this . walletClient ,
148+ client : extendedClient ,
151149 } ) ;
152150 }
153151
@@ -170,7 +168,7 @@ export class L1FeeJuicePortalManager {
170168 if ( amountToBridge !== mintableAmount ) {
171169 throw new Error ( `Minting amount must be ${ mintableAmount } ` ) ;
172170 }
173- await this . tokenManager . mint ( this . walletClient . account . address ) ;
171+ await this . tokenManager . mint ( this . extendedClient . account . address ) ;
174172 }
175173
176174 await this . tokenManager . approve ( amountToBridge , this . contract . address , 'FeeJuice Portal' ) ;
@@ -180,7 +178,7 @@ export class L1FeeJuicePortalManager {
180178
181179 await this . contract . simulate . depositToAztecPublic ( args ) ;
182180
183- const txReceipt = await this . publicClient . waitForTransactionReceipt ( {
181+ const txReceipt = await this . extendedClient . waitForTransactionReceipt ( {
184182 hash : await this . contract . write . depositToAztecPublic ( args ) ,
185183 } ) ;
186184
@@ -210,14 +208,12 @@ export class L1FeeJuicePortalManager {
210208 /**
211209 * Creates a new instance
212210 * @param walletOrPxe - Wallet or PXE client used for retrieving the L1 contract addresses.
213- * @param publicClient - L1 public client.
214- * @param walletClient - L1 wallet client.
211+ * @param extendedClient - Wallet client, extended with public actions.
215212 * @param logger - Logger.
216213 */
217214 public static async new (
218215 walletOrPxe : Wallet | PXE ,
219- publicClient : ViemPublicClient ,
220- walletClient : ViemWalletClient ,
216+ extendedClient : ExtendedViemWalletClient ,
221217 logger : Logger ,
222218 ) : Promise < L1FeeJuicePortalManager > {
223219 const {
@@ -235,31 +231,29 @@ export class L1FeeJuicePortalManager {
235231 feeJuicePortalAddress ,
236232 feeJuiceAddress ,
237233 feeAssetHandlerAddress ,
238- publicClient ,
239- walletClient ,
234+ extendedClient ,
240235 logger ,
241236 ) ;
242237 }
243238}
244239
245240/** Helper for interacting with a test TokenPortal on L1 for sending tokens to L2. */
246241export class L1ToL2TokenPortalManager {
247- protected readonly portal : GetContractReturnType < typeof TokenPortalAbi , ViemWalletClient > ;
242+ protected readonly portal : ViemContract < typeof TokenPortalAbi > ;
248243 protected readonly tokenManager : L1TokenManager ;
249244
250245 constructor (
251246 portalAddress : EthAddress ,
252247 tokenAddress : EthAddress ,
253248 handlerAddress : EthAddress | undefined ,
254- protected publicClient : ViemPublicClient ,
255- protected walletClient : ViemWalletClient ,
249+ protected extendedClient : ExtendedViemWalletClient ,
256250 protected logger : Logger ,
257251 ) {
258- this . tokenManager = new L1TokenManager ( tokenAddress , handlerAddress , publicClient , walletClient , logger ) ;
252+ this . tokenManager = new L1TokenManager ( tokenAddress , handlerAddress , extendedClient , logger ) ;
259253 this . portal = getContract ( {
260254 address : portalAddress . toString ( ) ,
261255 abi : TokenPortalAbi ,
262- client : this . walletClient ,
256+ client : extendedClient ,
263257 } ) ;
264258 }
265259
@@ -284,8 +278,8 @@ export class L1ToL2TokenPortalManager {
284278 claimSecretHash . toString ( ) ,
285279 ] ) ;
286280
287- const txReceipt = await this . publicClient . waitForTransactionReceipt ( {
288- hash : await this . walletClient . writeContract ( request ) ,
281+ const txReceipt = await this . extendedClient . waitForTransactionReceipt ( {
282+ hash : await this . extendedClient . writeContract ( request ) ,
289283 } ) ;
290284
291285 const log = extractEvent (
@@ -327,8 +321,8 @@ export class L1ToL2TokenPortalManager {
327321 this . logger . info ( 'Sending L1 tokens to L2 to be claimed privately' ) ;
328322 const { request } = await this . portal . simulate . depositToAztecPrivate ( [ amount , claimSecretHash . toString ( ) ] ) ;
329323
330- const txReceipt = await this . publicClient . waitForTransactionReceipt ( {
331- hash : await this . walletClient . writeContract ( request ) ,
324+ const txReceipt = await this . extendedClient . waitForTransactionReceipt ( {
325+ hash : await this . extendedClient . writeContract ( request ) ,
332326 } ) ;
333327
334328 const log = extractEvent (
@@ -360,7 +354,7 @@ export class L1ToL2TokenPortalManager {
360354 if ( amount !== mintableAmount ) {
361355 throw new Error ( `Minting amount must be ${ mintableAmount } for testing` ) ;
362356 }
363- await this . tokenManager . mint ( this . walletClient . account . address ) ;
357+ await this . tokenManager . mint ( this . extendedClient . account . address ) ;
364358 }
365359 await this . tokenManager . approve ( amount , this . portal . address , 'TokenPortal' ) ;
366360 return generateClaimSecret ( ) ;
@@ -369,22 +363,21 @@ export class L1ToL2TokenPortalManager {
369363
370364/** Helper for interacting with a test TokenPortal on L1 for both withdrawing from and bridging to L2. */
371365export class L1TokenPortalManager extends L1ToL2TokenPortalManager {
372- private readonly outbox : GetContractReturnType < typeof OutboxAbi , ViemWalletClient > ;
366+ private readonly outbox : ViemContract < typeof OutboxAbi > ;
373367
374368 constructor (
375369 portalAddress : EthAddress ,
376370 tokenAddress : EthAddress ,
377371 handlerAddress : EthAddress | undefined ,
378372 outboxAddress : EthAddress ,
379- publicClient : ViemPublicClient ,
380- walletClient : ViemWalletClient ,
373+ extendedClient : ExtendedViemWalletClient ,
381374 logger : Logger ,
382375 ) {
383- super ( portalAddress , tokenAddress , handlerAddress , publicClient , walletClient , logger ) ;
376+ super ( portalAddress , tokenAddress , handlerAddress , extendedClient , logger ) ;
384377 this . outbox = getContract ( {
385378 address : outboxAddress . toString ( ) ,
386379 abi : OutboxAbi ,
387- client : walletClient ,
380+ client : extendedClient ,
388381 } ) ;
389382 }
390383
@@ -422,7 +415,9 @@ export class L1TokenPortalManager extends L1ToL2TokenPortalManager {
422415 siblingPath . toBufferArray ( ) . map ( ( buf : Buffer ) : Hex => `0x${ buf . toString ( 'hex' ) } ` ) ,
423416 ] ) ;
424417
425- await this . publicClient . waitForTransactionReceipt ( { hash : await this . walletClient . writeContract ( withdrawRequest ) } ) ;
418+ await this . extendedClient . waitForTransactionReceipt ( {
419+ hash : await this . extendedClient . writeContract ( withdrawRequest ) ,
420+ } ) ;
426421
427422 const isConsumedAfter = await this . outbox . read . hasMessageBeenConsumedAtBlockAndIndex ( [ blockNumber , messageIndex ] ) ;
428423 if ( ! isConsumedAfter ) {
@@ -455,7 +450,7 @@ export class L1TokenPortalManager extends L1ToL2TokenPortalManager {
455450 l2Bridge . toBuffer ( ) ,
456451 new Fr ( version ) . toBuffer ( ) , // aztec version
457452 EthAddress . fromString ( this . portal . address ) . toBuffer32 ( ) ?? Buffer . alloc ( 32 , 0 ) ,
458- new Fr ( this . publicClient . chain . id ) . toBuffer ( ) , // chain id
453+ new Fr ( this . extendedClient . chain . id ) . toBuffer ( ) , // chain id
459454 content . toBuffer ( ) ,
460455 ] ) ;
461456
0 commit comments