1
- import type { ViemPublicClient , ViemWalletClient } from '@aztec/ethereum' ;
1
+ import type { ExtendedViemWalletClient , ViemContract } from '@aztec/ethereum' ;
2
2
import { extractEvent } from '@aztec/ethereum/utils' ;
3
3
import { sha256ToField } from '@aztec/foundation/crypto' ;
4
4
import { EthAddress } from '@aztec/foundation/eth-address' ;
@@ -14,7 +14,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
14
14
import { computeSecretHash } from '@aztec/stdlib/hash' ;
15
15
import type { PXE } from '@aztec/stdlib/interfaces/client' ;
16
16
17
- import { type GetContractReturnType , type Hex , getContract , toFunctionSelector } from 'viem' ;
17
+ import { type Hex , getContract , toFunctionSelector } from 'viem' ;
18
18
19
19
import type { Wallet } from '../index.js' ;
20
20
@@ -57,28 +57,27 @@ export async function generateClaimSecret(logger?: Logger): Promise<[Fr, Fr]> {
57
57
58
58
/** Helper for managing an ERC20 on L1. */
59
59
export 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 ;
62
62
63
63
public constructor (
64
64
/** Address of the ERC20 contract. */
65
65
public readonly tokenAddress : EthAddress ,
66
66
/** Address of the handler/faucet contract. */
67
67
public readonly handlerAddress : EthAddress | undefined ,
68
- private publicClient : ViemPublicClient ,
69
- private walletClient : ViemWalletClient ,
68
+ private readonly extendedClient : ExtendedViemWalletClient ,
70
69
private logger : Logger ,
71
70
) {
72
71
this . contract = getContract ( {
73
72
address : this . tokenAddress . toString ( ) ,
74
73
abi : TestERC20Abi ,
75
- client : this . walletClient ,
74
+ client : this . extendedClient ,
76
75
} ) ;
77
76
if ( this . handlerAddress ) {
78
77
this . handler = getContract ( {
79
78
address : this . handlerAddress . toString ( ) ,
80
79
abi : FeeAssetHandlerAbi ,
81
- client : this . walletClient ,
80
+ client : this . extendedClient ,
82
81
} ) ;
83
82
}
84
83
}
@@ -124,7 +123,7 @@ export class L1TokenManager {
124
123
*/
125
124
public async approve ( amount : bigint , address : Hex , addressName = '' ) {
126
125
this . logger . info ( `Approving ${ amount } tokens for ${ stringifyEthAddress ( address , addressName ) } ` ) ;
127
- await this . publicClient . waitForTransactionReceipt ( {
126
+ await this . extendedClient . waitForTransactionReceipt ( {
128
127
hash : await this . contract . write . approve ( [ address , amount ] ) ,
129
128
} ) ;
130
129
}
@@ -133,21 +132,20 @@ export class L1TokenManager {
133
132
/** Helper for interacting with the FeeJuicePortal on L1. */
134
133
export class L1FeeJuicePortalManager {
135
134
private readonly tokenManager : L1TokenManager ;
136
- private readonly contract : GetContractReturnType < typeof FeeJuicePortalAbi , ViemWalletClient > ;
135
+ private readonly contract : ViemContract < typeof FeeJuicePortalAbi > ;
137
136
138
137
constructor (
139
138
portalAddress : EthAddress ,
140
139
tokenAddress : EthAddress ,
141
140
handlerAddress : EthAddress ,
142
- private readonly publicClient : ViemPublicClient ,
143
- private readonly walletClient : ViemWalletClient ,
141
+ private readonly extendedClient : ExtendedViemWalletClient ,
144
142
private readonly logger : Logger ,
145
143
) {
146
- this . tokenManager = new L1TokenManager ( tokenAddress , handlerAddress , publicClient , walletClient , logger ) ;
144
+ this . tokenManager = new L1TokenManager ( tokenAddress , handlerAddress , extendedClient , logger ) ;
147
145
this . contract = getContract ( {
148
146
address : portalAddress . toString ( ) ,
149
147
abi : FeeJuicePortalAbi ,
150
- client : this . walletClient ,
148
+ client : extendedClient ,
151
149
} ) ;
152
150
}
153
151
@@ -170,7 +168,7 @@ export class L1FeeJuicePortalManager {
170
168
if ( amountToBridge !== mintableAmount ) {
171
169
throw new Error ( `Minting amount must be ${ mintableAmount } ` ) ;
172
170
}
173
- await this . tokenManager . mint ( this . walletClient . account . address ) ;
171
+ await this . tokenManager . mint ( this . extendedClient . account . address ) ;
174
172
}
175
173
176
174
await this . tokenManager . approve ( amountToBridge , this . contract . address , 'FeeJuice Portal' ) ;
@@ -180,7 +178,7 @@ export class L1FeeJuicePortalManager {
180
178
181
179
await this . contract . simulate . depositToAztecPublic ( args ) ;
182
180
183
- const txReceipt = await this . publicClient . waitForTransactionReceipt ( {
181
+ const txReceipt = await this . extendedClient . waitForTransactionReceipt ( {
184
182
hash : await this . contract . write . depositToAztecPublic ( args ) ,
185
183
} ) ;
186
184
@@ -210,14 +208,12 @@ export class L1FeeJuicePortalManager {
210
208
/**
211
209
* Creates a new instance
212
210
* @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.
215
212
* @param logger - Logger.
216
213
*/
217
214
public static async new (
218
215
walletOrPxe : Wallet | PXE ,
219
- publicClient : ViemPublicClient ,
220
- walletClient : ViemWalletClient ,
216
+ extendedClient : ExtendedViemWalletClient ,
221
217
logger : Logger ,
222
218
) : Promise < L1FeeJuicePortalManager > {
223
219
const {
@@ -235,31 +231,29 @@ export class L1FeeJuicePortalManager {
235
231
feeJuicePortalAddress ,
236
232
feeJuiceAddress ,
237
233
feeAssetHandlerAddress ,
238
- publicClient ,
239
- walletClient ,
234
+ extendedClient ,
240
235
logger ,
241
236
) ;
242
237
}
243
238
}
244
239
245
240
/** Helper for interacting with a test TokenPortal on L1 for sending tokens to L2. */
246
241
export class L1ToL2TokenPortalManager {
247
- protected readonly portal : GetContractReturnType < typeof TokenPortalAbi , ViemWalletClient > ;
242
+ protected readonly portal : ViemContract < typeof TokenPortalAbi > ;
248
243
protected readonly tokenManager : L1TokenManager ;
249
244
250
245
constructor (
251
246
portalAddress : EthAddress ,
252
247
tokenAddress : EthAddress ,
253
248
handlerAddress : EthAddress | undefined ,
254
- protected publicClient : ViemPublicClient ,
255
- protected walletClient : ViemWalletClient ,
249
+ protected extendedClient : ExtendedViemWalletClient ,
256
250
protected logger : Logger ,
257
251
) {
258
- this . tokenManager = new L1TokenManager ( tokenAddress , handlerAddress , publicClient , walletClient , logger ) ;
252
+ this . tokenManager = new L1TokenManager ( tokenAddress , handlerAddress , extendedClient , logger ) ;
259
253
this . portal = getContract ( {
260
254
address : portalAddress . toString ( ) ,
261
255
abi : TokenPortalAbi ,
262
- client : this . walletClient ,
256
+ client : extendedClient ,
263
257
} ) ;
264
258
}
265
259
@@ -284,8 +278,8 @@ export class L1ToL2TokenPortalManager {
284
278
claimSecretHash . toString ( ) ,
285
279
] ) ;
286
280
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 ) ,
289
283
} ) ;
290
284
291
285
const log = extractEvent (
@@ -327,8 +321,8 @@ export class L1ToL2TokenPortalManager {
327
321
this . logger . info ( 'Sending L1 tokens to L2 to be claimed privately' ) ;
328
322
const { request } = await this . portal . simulate . depositToAztecPrivate ( [ amount , claimSecretHash . toString ( ) ] ) ;
329
323
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 ) ,
332
326
} ) ;
333
327
334
328
const log = extractEvent (
@@ -360,7 +354,7 @@ export class L1ToL2TokenPortalManager {
360
354
if ( amount !== mintableAmount ) {
361
355
throw new Error ( `Minting amount must be ${ mintableAmount } for testing` ) ;
362
356
}
363
- await this . tokenManager . mint ( this . walletClient . account . address ) ;
357
+ await this . tokenManager . mint ( this . extendedClient . account . address ) ;
364
358
}
365
359
await this . tokenManager . approve ( amount , this . portal . address , 'TokenPortal' ) ;
366
360
return generateClaimSecret ( ) ;
@@ -369,22 +363,21 @@ export class L1ToL2TokenPortalManager {
369
363
370
364
/** Helper for interacting with a test TokenPortal on L1 for both withdrawing from and bridging to L2. */
371
365
export class L1TokenPortalManager extends L1ToL2TokenPortalManager {
372
- private readonly outbox : GetContractReturnType < typeof OutboxAbi , ViemWalletClient > ;
366
+ private readonly outbox : ViemContract < typeof OutboxAbi > ;
373
367
374
368
constructor (
375
369
portalAddress : EthAddress ,
376
370
tokenAddress : EthAddress ,
377
371
handlerAddress : EthAddress | undefined ,
378
372
outboxAddress : EthAddress ,
379
- publicClient : ViemPublicClient ,
380
- walletClient : ViemWalletClient ,
373
+ extendedClient : ExtendedViemWalletClient ,
381
374
logger : Logger ,
382
375
) {
383
- super ( portalAddress , tokenAddress , handlerAddress , publicClient , walletClient , logger ) ;
376
+ super ( portalAddress , tokenAddress , handlerAddress , extendedClient , logger ) ;
384
377
this . outbox = getContract ( {
385
378
address : outboxAddress . toString ( ) ,
386
379
abi : OutboxAbi ,
387
- client : walletClient ,
380
+ client : extendedClient ,
388
381
} ) ;
389
382
}
390
383
@@ -422,7 +415,9 @@ export class L1TokenPortalManager extends L1ToL2TokenPortalManager {
422
415
siblingPath . toBufferArray ( ) . map ( ( buf : Buffer ) : Hex => `0x${ buf . toString ( 'hex' ) } ` ) ,
423
416
] ) ;
424
417
425
- await this . publicClient . waitForTransactionReceipt ( { hash : await this . walletClient . writeContract ( withdrawRequest ) } ) ;
418
+ await this . extendedClient . waitForTransactionReceipt ( {
419
+ hash : await this . extendedClient . writeContract ( withdrawRequest ) ,
420
+ } ) ;
426
421
427
422
const isConsumedAfter = await this . outbox . read . hasMessageBeenConsumedAtBlockAndIndex ( [ blockNumber , messageIndex ] ) ;
428
423
if ( ! isConsumedAfter ) {
@@ -455,7 +450,7 @@ export class L1TokenPortalManager extends L1ToL2TokenPortalManager {
455
450
l2Bridge . toBuffer ( ) ,
456
451
new Fr ( version ) . toBuffer ( ) , // aztec version
457
452
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
459
454
content . toBuffer ( ) ,
460
455
] ) ;
461
456
0 commit comments