Skip to content

Commit 6bbb0dd

Browse files
committed
Feat: Add v1 SequencerInbox getters
Closes FS-535
1 parent 4fedd67 commit 6bbb0dd

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-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 { sequencerInbox } from '../contracts';
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<false>,
21+
): Promise<GetMaxTimeVariationReturnType> {
22+
const [delayBlocks, futureBlocks, delaySeconds, futureSeconds] = await client.readContract({
23+
abi: sequencerInbox.abi,
24+
functionName: 'maxTimeVariation',
25+
address: args.sequencerInbox,
26+
});
27+
return {
28+
delayBlocks,
29+
futureBlocks,
30+
delaySeconds,
31+
futureSeconds,
32+
};
33+
}

src/actions/isBatchPoster.ts

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

src/actions/isValidKeysetHash.ts

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

src/types/Actions.ts

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

0 commit comments

Comments
 (0)