Skip to content

Commit 11555c7

Browse files
committed
Feat: Add v1 ArbGasInfo getters
1 parent 7804ca2 commit 11555c7

File tree

5 files changed

+103
-0
lines changed

5 files changed

+103
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Chain, PublicClient, Transport } from 'viem';
2+
import { arbGasInfoABI, arbGasInfoAddress } from '../contracts/ArbGasInfo';
3+
4+
export type GetGasAccountingParamsParameters = void;
5+
6+
export type GetGasAccountingParamsReturnType = {
7+
speedLimitPerSecond: bigint;
8+
gasPoolMax: bigint;
9+
maxTxGasLimit: bigint;
10+
};
11+
12+
export async function getGasAccountingParams<TChain extends Chain>(
13+
client: PublicClient<Transport, TChain>,
14+
): Promise<GetGasAccountingParamsReturnType> {
15+
// `gasPoolMax` is always zero, as the exponential pricing model has no such notion.
16+
// see https://github.com/OffchainLabs/nitro-contracts/blob/main/src/precompiles/ArbGasInfo.sol
17+
const [speedLimitPerSecond, gasPoolMax, maxTxGasLimit] = await client.readContract({
18+
abi: arbGasInfoABI,
19+
functionName: 'getGasAccountingParams',
20+
address: arbGasInfoAddress,
21+
});
22+
return {
23+
speedLimitPerSecond,
24+
gasPoolMax,
25+
maxTxGasLimit,
26+
};
27+
}

src/actions/getMinimumGasPrice.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem';
2+
import { arbGasInfoABI, arbGasInfoAddress } from '../contracts/ArbGasInfo';
3+
4+
export type GetMinimumGasPriceParameters = void;
5+
6+
export type GetMinimumGasPriceReturnType = ReadContractReturnType<
7+
typeof arbGasInfoABI,
8+
'getMinimumGasPrice'
9+
>;
10+
11+
export async function getMinimumGasPrice<TChain extends Chain>(
12+
client: PublicClient<Transport, TChain>,
13+
): Promise<GetMinimumGasPriceReturnType> {
14+
return client.readContract({
15+
abi: arbGasInfoABI,
16+
functionName: 'getMinimumGasPrice',
17+
address: arbGasInfoAddress,
18+
});
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem';
2+
import { arbGasInfoABI, arbGasInfoAddress } from '../contracts/ArbGasInfo';
3+
4+
export type GetParentBaseFeeEstimateParameters = void;
5+
6+
export type GetParentBaseFeeEstimateReturnType = ReadContractReturnType<
7+
typeof arbGasInfoABI,
8+
'getL1BaseFeeEstimate'
9+
>;
10+
11+
export async function getParentBaseFeeEstimate<TChain extends Chain>(
12+
client: PublicClient<Transport, TChain>,
13+
): Promise<GetParentBaseFeeEstimateReturnType> {
14+
return client.readContract({
15+
abi: arbGasInfoABI,
16+
functionName: 'getL1BaseFeeEstimate',
17+
address: arbGasInfoAddress,
18+
});
19+
}

src/actions/getParentRewardRate.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem';
2+
import { arbGasInfoABI, arbGasInfoAddress } from '../contracts/ArbGasInfo';
3+
4+
export type GetParentRewardRateParameters = void;
5+
6+
export type GetParentRewardRateReturnType = ReadContractReturnType<
7+
typeof arbGasInfoABI,
8+
'getL1RewardRate'
9+
>;
10+
11+
export async function getParentRewardRate<TChain extends Chain>(
12+
client: PublicClient<Transport, TChain>,
13+
): Promise<GetParentRewardRateReturnType> {
14+
return client.readContract({
15+
abi: arbGasInfoABI,
16+
functionName: 'getL1RewardRate',
17+
address: arbGasInfoAddress,
18+
});
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem';
2+
import { arbGasInfoABI, arbGasInfoAddress } from '../contracts/ArbGasInfo';
3+
4+
export type GetParentRewardRecipientParameters = void;
5+
6+
export type GetParentRewardRecipientReturnType = ReadContractReturnType<
7+
typeof arbGasInfoABI,
8+
'getL1RewardRecipient'
9+
>;
10+
11+
export async function getParentRewardRecipient<TChain extends Chain>(
12+
client: PublicClient<Transport, TChain>,
13+
): Promise<GetParentRewardRecipientReturnType> {
14+
return client.readContract({
15+
abi: arbGasInfoABI,
16+
functionName: 'getL1RewardRecipient',
17+
address: arbGasInfoAddress,
18+
});
19+
}

0 commit comments

Comments
 (0)