Skip to content

Commit ced5193

Browse files
authored
feat: add SequencerInbox getters (#114)
1 parent 36fd6fe commit ced5193

File tree

6 files changed

+118
-0
lines changed

6 files changed

+118
-0
lines changed

src/actions/getMaxTimeVariation.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Chain, PublicClient, Transport } from 'viem';
2+
import { sequencerInboxABI } from '../contracts/SequencerInbox';
3+
import { ActionParameters } from '../types/Actions';
4+
5+
export type GetMaxTimeVariationParameters<Curried extends boolean = false> = ActionParameters<
6+
{},
7+
'sequencerInbox',
8+
Curried
9+
>;
10+
11+
export type GetMaxTimeVariationReturnType = {
12+
delayBlocks: bigint;
13+
futureBlocks: bigint;
14+
delaySeconds: bigint;
15+
futureSeconds: bigint;
16+
};
17+
18+
export async function getMaxTimeVariation<TChain extends Chain | undefined>(
19+
client: PublicClient<Transport, TChain>,
20+
args: GetMaxTimeVariationParameters,
21+
): Promise<GetMaxTimeVariationReturnType> {
22+
const [delayBlocks, futureBlocks, delaySeconds, futureSeconds] = await client.readContract({
23+
abi: sequencerInboxABI,
24+
functionName: 'maxTimeVariation',
25+
address: args.sequencerInbox,
26+
});
27+
return {
28+
delayBlocks,
29+
futureBlocks,
30+
delaySeconds,
31+
futureSeconds,
32+
};
33+
}

src/actions/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './getMaxTimeVariation';
2+
export * from './isBatchPoster';
3+
export * from './isValidKeysetHash';

src/actions/isBatchPoster.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Address, Chain, PublicClient, ReadContractReturnType, Transport } from 'viem';
2+
import { sequencerInboxABI } from '../contracts/SequencerInbox';
3+
import { ActionParameters } from '../types/Actions';
4+
5+
type Args = {
6+
batchPoster: Address;
7+
};
8+
export type IsBatchPosterParameters<Curried extends boolean = false> = ActionParameters<
9+
Args,
10+
'sequencerInbox',
11+
Curried
12+
>;
13+
14+
export type IsBatchPosterReturnType = ReadContractReturnType<
15+
typeof sequencerInboxABI,
16+
'isBatchPoster'
17+
>;
18+
19+
export async function isBatchPoster<TChain extends Chain | undefined>(
20+
client: PublicClient<Transport, TChain>,
21+
args: IsBatchPosterParameters,
22+
): Promise<IsBatchPosterReturnType> {
23+
return client.readContract({
24+
abi: sequencerInboxABI,
25+
functionName: 'isBatchPoster',
26+
address: args.sequencerInbox,
27+
args: [args.batchPoster],
28+
});
29+
}

src/actions/isValidKeysetHash.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Chain, Hex, PublicClient, ReadContractReturnType, Transport } from 'viem';
2+
import { sequencerInboxABI } from '../contracts/SequencerInbox';
3+
import { ActionParameters } from '../types/Actions';
4+
5+
type Args = {
6+
keysetHash: Hex;
7+
};
8+
9+
export type IsValidKeysetHashParameters<Curried extends boolean = false> = ActionParameters<
10+
Args,
11+
'sequencerInbox',
12+
Curried
13+
>;
14+
15+
export type IsValidKeysetHashReturnType = ReadContractReturnType<
16+
typeof sequencerInboxABI,
17+
'isValidKeysetHash'
18+
>;
19+
20+
export async function isValidKeysetHash<TChain extends Chain | undefined>(
21+
client: PublicClient<Transport, TChain>,
22+
args: IsValidKeysetHashParameters,
23+
): Promise<IsValidKeysetHashReturnType> {
24+
return client.readContract({
25+
abi: sequencerInboxABI,
26+
functionName: 'isValidKeysetHash',
27+
address: args.sequencerInbox,
28+
args: [args.keysetHash],
29+
});
30+
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ import {
137137
getConsensusReleaseByWasmModuleRoot,
138138
GetConsensusReleaseByWasmModuleRoot,
139139
} from './wasmModuleRoot';
140+
export * from './actions';
140141

141142
export {
142143
arbOwnerPublicActions,

src/types/Actions.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Address } from 'viem';
2+
import { Prettify } from './utils';
3+
4+
/**
5+
* Actions require contract address, but as part of decorators, the address might have been passed already to the decorator.
6+
*
7+
* If the address was passed to the decorator, it's now optional (we still allow overrides of the address per action).
8+
* If the action doesn't have any other parameters beside the contract address, then parameters can either be { contract: address } or void
9+
*/
10+
export type ActionParameters<Args, ContractName extends string, Curried extends boolean> = Prettify<
11+
Curried extends false
12+
? Args & { [key in ContractName]: Address }
13+
: Args extends Record<string, never>
14+
?
15+
| {
16+
[key in ContractName]: Address;
17+
}
18+
| void
19+
: Args & {
20+
[key in ContractName]?: Address;
21+
}
22+
>;

0 commit comments

Comments
 (0)