From cbaa56d7817cec4d1d77655e25585e417dcb532a Mon Sep 17 00:00:00 2001 From: Niran Babalola Date: Sat, 16 Dec 2023 21:10:41 +0000 Subject: [PATCH 1/3] Add documentation for gas estimation actions --- site/.vitepress/config.mts | 12 ++++++++++++ site/docs/actions/public/L2/estimateFees.md | 17 +++++++++++++++++ site/docs/actions/public/L2/estimateL1Fee.md | 15 +++++++++++++++ .../docs/actions/public/L2/estimateL1GasUsed.md | 13 +++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 site/docs/actions/public/L2/estimateFees.md create mode 100644 site/docs/actions/public/L2/estimateL1Fee.md create mode 100644 site/docs/actions/public/L2/estimateL1GasUsed.md diff --git a/site/.vitepress/config.mts b/site/.vitepress/config.mts index f21341c4..a51af2d7 100644 --- a/site/.vitepress/config.mts +++ b/site/.vitepress/config.mts @@ -79,6 +79,18 @@ export default defineConfig({ { text: 'L2', items: [ + { + text: 'estimateFees', + link: '/docs/actions/public/L2/estimateFees', + }, + { + text: 'estimateL1Fee', + link: '/docs/actions/public/L2/estimateL1Fee', + }, + { + text: 'estimateL1GasUsed', + link: '/docs/actions/public/L2/estimateL1GasUsed', + }, { text: 'getProveWithdrawalTransactionArgs', link: '/docs/actions/public/L2/getProveWithdrawalTransactionArgs', diff --git a/site/docs/actions/public/L2/estimateFees.md b/site/docs/actions/public/L2/estimateFees.md new file mode 100644 index 00000000..d68e8110 --- /dev/null +++ b/site/docs/actions/public/L2/estimateFees.md @@ -0,0 +1,17 @@ +# estimateFees + +Estimates gas for an L2 transaction including the L1 fee. + +```ts +const feeValue = await estimateFees(publicClient, { + abi, + functionName: balanceOf, + args: [address], +}) +``` + +On non-OP chains, fees are usually by `GasUsed * GasPrice`, so the fee depends on the amount of computation required to execute the transaction. On OP chains this is `GasUsed * GasPrice + L1Fee`. + +The L1 portion of the fee depends primarily on the _length_ of the transaction data and the current gas price on L1. The [Gas Price Oracle](https://docs.optimism.io/builders/tools/oracles#gas-oracle) is called to provide the L1 gas price and calculate the total L1 fee. + +See also: [Transaction Fees on OP Mainnet](https://docs.optimism.io/stack/transactions/transaction-fees) diff --git a/site/docs/actions/public/L2/estimateL1Fee.md b/site/docs/actions/public/L2/estimateL1Fee.md new file mode 100644 index 00000000..c849e462 --- /dev/null +++ b/site/docs/actions/public/L2/estimateL1Fee.md @@ -0,0 +1,15 @@ +# estimateL1Fee + +Computes the L1 portion of the fee based on the size of the RLP-encoded input transaction, the current L1 base fee, and the various dynamic parameters. + +```ts +const L1FeeValue = await estimateL1Fee(publicClient, { + abi, + functionName: balanceOf, + args: [address], +}) +``` + +The L1 portion of the fee depends primarily on the _length_ of the transaction data and the current gas price on L1. The [Gas Price Oracle](https://docs.optimism.io/builders/tools/oracles#gas-oracle) is called to provide the L1 gas price and calculate the total L1 fee. + +See also: [Transaction Fees on OP Mainnet](https://docs.optimism.io/stack/transactions/transaction-fees) diff --git a/site/docs/actions/public/L2/estimateL1GasUsed.md b/site/docs/actions/public/L2/estimateL1GasUsed.md new file mode 100644 index 00000000..192ac3fd --- /dev/null +++ b/site/docs/actions/public/L2/estimateL1GasUsed.md @@ -0,0 +1,13 @@ +# estimateL1GasUsed + +Returns the L1 gas used for the specified transaction. + +```ts +const L1GasUsedValue = await estimateL1GasUsed(data, { + abi, + functionName: balanceOf, + args: [address], +}) +``` + +The [Gas Price Oracle](https://docs.optimism.io/builders/tools/oracles#gas-oracle) is called to calculate the gas that will be necessary to publish the given transaction to L1. From f7caee48542cc8f3a5ab378215a868e43c78214d Mon Sep 17 00:00:00 2001 From: Niran Babalola Date: Sun, 17 Dec 2023 05:52:54 +0000 Subject: [PATCH 2/3] Add documentation for parameters and return types for the gas estimation actions --- site/docs/actions/public/L2/estimateFees.md | 60 ++++++++++++++++++- site/docs/actions/public/L2/estimateL1Fee.md | 46 ++++++++++++++ .../actions/public/L2/estimateL1GasUsed.md | 46 ++++++++++++++ 3 files changed, 151 insertions(+), 1 deletion(-) diff --git a/site/docs/actions/public/L2/estimateFees.md b/site/docs/actions/public/L2/estimateFees.md index d68e8110..14fefa30 100644 --- a/site/docs/actions/public/L2/estimateFees.md +++ b/site/docs/actions/public/L2/estimateFees.md @@ -14,4 +14,62 @@ On non-OP chains, fees are usually by `GasUsed * GasPrice`, so the fee depends o The L1 portion of the fee depends primarily on the _length_ of the transaction data and the current gas price on L1. The [Gas Price Oracle](https://docs.optimism.io/builders/tools/oracles#gas-oracle) is called to provide the L1 gas price and calculate the total L1 fee. -See also: [Transaction Fees on OP Mainnet](https://docs.optimism.io/stack/transactions/transaction-fees) +See also: + +- [Transaction Fees on OP Mainnet](https://docs.optimism.io/stack/transactions/transaction-fees) +- [`estimateGas` from `viem`](https://viem.sh/docs/actions/public/estimateGas.html) + +## Return Value + +`bigint` + +The fee in units of wei. + +## Parameters + +### client + +- **Type:** `PublicClient` + +A client for the desired OP Stack chain. + +### options + +- **abi:** `Abi` + +The ABI for the contract containing the function being estimated. + +- **functionName:** `string` + +The name of the function being estimated. + +- **args:** `any[]` + +The arguments to the function being estimated. + +- **account:** `Account | Address` + +The Account to estimate gas from. + +- **to (optional):** `Address` + +Transaction recipient. + +- **value (optional):** `bigint` + +Value (in wei) sent with this transaction. + +- **blockNumber (optional)**: `number` + +The block number to perform the gas estimate against. + +- **blockTag (optional):** `'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'` + +**Default:** `'latest'` + +The block tag to perform the gas estimate against. + +## JSON-RPC Methods + +[`eth_estimateGas`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_estimategas) + diff --git a/site/docs/actions/public/L2/estimateL1Fee.md b/site/docs/actions/public/L2/estimateL1Fee.md index c849e462..2405a625 100644 --- a/site/docs/actions/public/L2/estimateL1Fee.md +++ b/site/docs/actions/public/L2/estimateL1Fee.md @@ -13,3 +13,49 @@ const L1FeeValue = await estimateL1Fee(publicClient, { The L1 portion of the fee depends primarily on the _length_ of the transaction data and the current gas price on L1. The [Gas Price Oracle](https://docs.optimism.io/builders/tools/oracles#gas-oracle) is called to provide the L1 gas price and calculate the total L1 fee. See also: [Transaction Fees on OP Mainnet](https://docs.optimism.io/stack/transactions/transaction-fees) + +## Return Value + +`bigint` + +The fee in units of wei. + +## Parameters + +### client + +- **Type:** `PublicClient` + +A client for the desired OP Stack chain. + +### options + +- **abi:** `Abi` + +The ABI for the contract containing the function being estimated. + +- **functionName:** `string` + +The name of the function being estimated. + +- **args:** `any[]` + +The arguments to the function being estimated. + +- **to (optional):** `Address` + +Transaction recipient. + +- **value (optional):** `bigint` + +Value (in wei) sent with this transaction. + +- **blockNumber (optional)**: `number` + +The block number to perform the gas estimate against. + +- **blockTag (optional):** `'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'` + +**Default:** `'latest'` + +The block tag to perform the gas estimate against. diff --git a/site/docs/actions/public/L2/estimateL1GasUsed.md b/site/docs/actions/public/L2/estimateL1GasUsed.md index 192ac3fd..160521f0 100644 --- a/site/docs/actions/public/L2/estimateL1GasUsed.md +++ b/site/docs/actions/public/L2/estimateL1GasUsed.md @@ -11,3 +11,49 @@ const L1GasUsedValue = await estimateL1GasUsed(data, { ``` The [Gas Price Oracle](https://docs.optimism.io/builders/tools/oracles#gas-oracle) is called to calculate the gas that will be necessary to publish the given transaction to L1. + +## Return Value + +`bigint` + +The estimated gas used. + +## Parameters + +### client + +- **Type:** `PublicClient` + +A client for the desired OP Stack chain. + +### options + +- **abi:** `Abi` + +The ABI for the contract containing the function being estimated. + +- **functionName:** `string` + +The name of the function being estimated. + +- **args:** `any[]` + +The arguments to the function being estimated. + +- **to (optional):** `Address` + +Transaction recipient. + +- **value (optional):** `bigint` + +Value (in wei) sent with this transaction. + +- **blockNumber (optional)**: `number` + +The block number to perform the gas estimate against. + +- **blockTag (optional):** `'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'` + +**Default:** `'latest'` + +The block tag to perform the gas estimate against. From 8cac7c869f6fbbf16eccfb7d4da5d17969695e10 Mon Sep 17 00:00:00 2001 From: Niran Babalola Date: Sun, 17 Dec 2023 05:54:00 +0000 Subject: [PATCH 3/3] Post-commit linting --- site/docs/actions/public/L2/estimateFees.md | 1 - 1 file changed, 1 deletion(-) diff --git a/site/docs/actions/public/L2/estimateFees.md b/site/docs/actions/public/L2/estimateFees.md index 14fefa30..beb5376c 100644 --- a/site/docs/actions/public/L2/estimateFees.md +++ b/site/docs/actions/public/L2/estimateFees.md @@ -72,4 +72,3 @@ The block tag to perform the gas estimate against. ## JSON-RPC Methods [`eth_estimateGas`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_estimategas) -