Skip to content

Commit

Permalink
Feat: Add v1 ArbGasInfo getters
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx committed Sep 27, 2024
1 parent 7804ca2 commit 11555c7
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/actions/getGasAccountingParams.ts
Original file line number Diff line number Diff line change
@@ -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<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
): Promise<GetGasAccountingParamsReturnType> {
// `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,
};
}
19 changes: 19 additions & 0 deletions src/actions/getMinimumGasPrice.ts
Original file line number Diff line number Diff line change
@@ -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<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
): Promise<GetMinimumGasPriceReturnType> {
return client.readContract({
abi: arbGasInfoABI,
functionName: 'getMinimumGasPrice',
address: arbGasInfoAddress,
});
}
19 changes: 19 additions & 0 deletions src/actions/getParentBaseFeeEstimate.ts
Original file line number Diff line number Diff line change
@@ -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<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
): Promise<GetParentBaseFeeEstimateReturnType> {
return client.readContract({
abi: arbGasInfoABI,
functionName: 'getL1BaseFeeEstimate',
address: arbGasInfoAddress,
});
}
19 changes: 19 additions & 0 deletions src/actions/getParentRewardRate.ts
Original file line number Diff line number Diff line change
@@ -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<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
): Promise<GetParentRewardRateReturnType> {
return client.readContract({
abi: arbGasInfoABI,
functionName: 'getL1RewardRate',
address: arbGasInfoAddress,
});
}
19 changes: 19 additions & 0 deletions src/actions/getParentRewardRecipient.ts
Original file line number Diff line number Diff line change
@@ -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<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
): Promise<GetParentRewardRecipientReturnType> {
return client.readContract({
abi: arbGasInfoABI,
functionName: 'getL1RewardRecipient',
address: arbGasInfoAddress,
});
}

0 comments on commit 11555c7

Please sign in to comment.