From 11555c7518be0a573f78ab851475ed27672d37ed Mon Sep 17 00:00:00 2001 From: Christophe Date: Fri, 28 Jun 2024 15:05:11 +0000 Subject: [PATCH] Feat: Add v1 ArbGasInfo getters --- src/actions/getGasAccountingParams.ts | 27 +++++++++++++++++++++++++ src/actions/getMinimumGasPrice.ts | 19 +++++++++++++++++ src/actions/getParentBaseFeeEstimate.ts | 19 +++++++++++++++++ src/actions/getParentRewardRate.ts | 19 +++++++++++++++++ src/actions/getParentRewardRecipient.ts | 19 +++++++++++++++++ 5 files changed, 103 insertions(+) create mode 100644 src/actions/getGasAccountingParams.ts create mode 100644 src/actions/getMinimumGasPrice.ts create mode 100644 src/actions/getParentBaseFeeEstimate.ts create mode 100644 src/actions/getParentRewardRate.ts create mode 100644 src/actions/getParentRewardRecipient.ts diff --git a/src/actions/getGasAccountingParams.ts b/src/actions/getGasAccountingParams.ts new file mode 100644 index 00000000..a6b97118 --- /dev/null +++ b/src/actions/getGasAccountingParams.ts @@ -0,0 +1,27 @@ +import { Chain, PublicClient, Transport } from 'viem'; +import { arbGasInfoABI, arbGasInfoAddress } from '../contracts/ArbGasInfo'; + +export type GetGasAccountingParamsParameters = void; + +export type GetGasAccountingParamsReturnType = { + speedLimitPerSecond: bigint; + gasPoolMax: bigint; + maxTxGasLimit: bigint; +}; + +export async function getGasAccountingParams( + client: PublicClient, +): Promise { + // `gasPoolMax` is always zero, as the exponential pricing model has no such notion. + // see https://github.com/OffchainLabs/nitro-contracts/blob/main/src/precompiles/ArbGasInfo.sol + const [speedLimitPerSecond, gasPoolMax, maxTxGasLimit] = await client.readContract({ + abi: arbGasInfoABI, + functionName: 'getGasAccountingParams', + address: arbGasInfoAddress, + }); + return { + speedLimitPerSecond, + gasPoolMax, + maxTxGasLimit, + }; +} diff --git a/src/actions/getMinimumGasPrice.ts b/src/actions/getMinimumGasPrice.ts new file mode 100644 index 00000000..99d11273 --- /dev/null +++ b/src/actions/getMinimumGasPrice.ts @@ -0,0 +1,19 @@ +import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem'; +import { arbGasInfoABI, arbGasInfoAddress } from '../contracts/ArbGasInfo'; + +export type GetMinimumGasPriceParameters = void; + +export type GetMinimumGasPriceReturnType = ReadContractReturnType< + typeof arbGasInfoABI, + 'getMinimumGasPrice' +>; + +export async function getMinimumGasPrice( + client: PublicClient, +): Promise { + return client.readContract({ + abi: arbGasInfoABI, + functionName: 'getMinimumGasPrice', + address: arbGasInfoAddress, + }); +} diff --git a/src/actions/getParentBaseFeeEstimate.ts b/src/actions/getParentBaseFeeEstimate.ts new file mode 100644 index 00000000..bb3774e4 --- /dev/null +++ b/src/actions/getParentBaseFeeEstimate.ts @@ -0,0 +1,19 @@ +import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem'; +import { arbGasInfoABI, arbGasInfoAddress } from '../contracts/ArbGasInfo'; + +export type GetParentBaseFeeEstimateParameters = void; + +export type GetParentBaseFeeEstimateReturnType = ReadContractReturnType< + typeof arbGasInfoABI, + 'getL1BaseFeeEstimate' +>; + +export async function getParentBaseFeeEstimate( + client: PublicClient, +): Promise { + return client.readContract({ + abi: arbGasInfoABI, + functionName: 'getL1BaseFeeEstimate', + address: arbGasInfoAddress, + }); +} diff --git a/src/actions/getParentRewardRate.ts b/src/actions/getParentRewardRate.ts new file mode 100644 index 00000000..39b697ce --- /dev/null +++ b/src/actions/getParentRewardRate.ts @@ -0,0 +1,19 @@ +import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem'; +import { arbGasInfoABI, arbGasInfoAddress } from '../contracts/ArbGasInfo'; + +export type GetParentRewardRateParameters = void; + +export type GetParentRewardRateReturnType = ReadContractReturnType< + typeof arbGasInfoABI, + 'getL1RewardRate' +>; + +export async function getParentRewardRate( + client: PublicClient, +): Promise { + return client.readContract({ + abi: arbGasInfoABI, + functionName: 'getL1RewardRate', + address: arbGasInfoAddress, + }); +} diff --git a/src/actions/getParentRewardRecipient.ts b/src/actions/getParentRewardRecipient.ts new file mode 100644 index 00000000..39c440be --- /dev/null +++ b/src/actions/getParentRewardRecipient.ts @@ -0,0 +1,19 @@ +import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem'; +import { arbGasInfoABI, arbGasInfoAddress } from '../contracts/ArbGasInfo'; + +export type GetParentRewardRecipientParameters = void; + +export type GetParentRewardRecipientReturnType = ReadContractReturnType< + typeof arbGasInfoABI, + 'getL1RewardRecipient' +>; + +export async function getParentRewardRecipient( + client: PublicClient, +): Promise { + return client.readContract({ + abi: arbGasInfoABI, + functionName: 'getL1RewardRecipient', + address: arbGasInfoAddress, + }); +}