Skip to content

Commit 81c4ba3

Browse files
committed
add operator fee to decorator
1 parent b8d7a91 commit 81c4ba3

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/op-stack/decorators/publicL2.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ import {
5252
type EstimateL1GasReturnType,
5353
estimateL1Gas,
5454
} from '../actions/estimateL1Gas.js'
55+
import {
56+
type EstimateOperatorFeeParameters,
57+
type EstimateOperatorFeeReturnType,
58+
estimateOperatorFee,
59+
} from '../actions/estimateOperatorFee.js'
5560
import {
5661
type EstimateTotalFeeParameters,
5762
type EstimateTotalFeeReturnType,
@@ -418,6 +423,34 @@ export type PublicActionsL2<
418423
estimateL1Gas: <chainOverride extends Chain | undefined = undefined>(
419424
parameters: EstimateL1GasParameters<chain, account, chainOverride>,
420425
) => Promise<EstimateL1GasReturnType>
426+
/**
427+
* Estimates the operator fee required to execute an L2 transaction.
428+
*
429+
* Returns 0 for pre-Isthmus chains or when operator fee functions don't exist.
430+
*
431+
* @param client - Client to use
432+
* @param parameters - {@link EstimateOperatorFeeParameters}
433+
* @returns The operator fee (in wei). {@link EstimateOperatorFeeReturnType}
434+
*
435+
* @example
436+
* import { createPublicClient, http, parseEther } from 'viem'
437+
* import { optimism } from 'viem/chains'
438+
* import { publicActionsL2 } from 'viem/op-stack'
439+
*
440+
* const client = createPublicClient({
441+
* chain: optimism,
442+
* transport: http(),
443+
* }).extend(publicActionsL2())
444+
*
445+
* const operatorFee = await client.estimateOperatorFee({
446+
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
447+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
448+
* value: parseEther('1'),
449+
* })
450+
*/
451+
estimateOperatorFee: <chainOverride extends Chain | undefined = undefined>(
452+
parameters: EstimateOperatorFeeParameters<chain, account, chainOverride>,
453+
) => Promise<EstimateOperatorFeeReturnType>
421454
/**
422455
* Estimates the L1 data fee + L2 fee to execute an L2 transaction.
423456
*
@@ -509,6 +542,7 @@ export function publicActionsL2() {
509542
estimateL1Fee: (args) => estimateL1Fee(client, args),
510543
getL1BaseFee: (args) => getL1BaseFee(client, args),
511544
estimateL1Gas: (args) => estimateL1Gas(client, args),
545+
estimateOperatorFee: (args) => estimateOperatorFee(client, args),
512546
estimateTotalFee: (args) => estimateTotalFee(client, args),
513547
estimateTotalGas: (args) => estimateTotalGas(client, args),
514548
}

0 commit comments

Comments
 (0)