Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/actions/getMaxTimeVariation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Chain, PublicClient, Transport } from 'viem';
import { sequencerInboxABI } from '../contracts/SequencerInbox';
import { ActionParameters } from '../types/Actions';

export type GetMaxTimeVariationParameters<Curried extends boolean = false> = ActionParameters<
{},
'sequencerInbox',
Curried
>;

export type GetMaxTimeVariationReturnType = {
delayBlocks: bigint;
futureBlocks: bigint;
delaySeconds: bigint;
futureSeconds: bigint;
};

export async function getMaxTimeVariation<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: GetMaxTimeVariationParameters,
): Promise<GetMaxTimeVariationReturnType> {
const [delayBlocks, futureBlocks, delaySeconds, futureSeconds] = await client.readContract({
abi: sequencerInboxABI,
functionName: 'maxTimeVariation',
address: args.sequencerInbox,
});
return {
delayBlocks,
futureBlocks,
delaySeconds,
futureSeconds,
};
}
3 changes: 3 additions & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './getMaxTimeVariation';
export * from './isBatchPoster';
export * from './isValidKeysetHash';
29 changes: 29 additions & 0 deletions src/actions/isBatchPoster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Address, Chain, PublicClient, ReadContractReturnType, Transport } from 'viem';
import { sequencerInboxABI } from '../contracts/SequencerInbox';
import { ActionParameters } from '../types/Actions';

type Args = {
batchPoster: Address;
};
export type IsBatchPosterParameters<Curried extends boolean = false> = ActionParameters<
Args,
'sequencerInbox',
Curried
>;

export type IsBatchPosterReturnType = ReadContractReturnType<
typeof sequencerInboxABI,
'isBatchPoster'
>;

export async function isBatchPoster<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: IsBatchPosterParameters,
): Promise<IsBatchPosterReturnType> {
return client.readContract({
abi: sequencerInboxABI,
functionName: 'isBatchPoster',
address: args.sequencerInbox,
args: [args.batchPoster],
});
}
30 changes: 30 additions & 0 deletions src/actions/isValidKeysetHash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Chain, Hex, PublicClient, ReadContractReturnType, Transport } from 'viem';
import { sequencerInboxABI } from '../contracts/SequencerInbox';
import { ActionParameters } from '../types/Actions';

type Args = {
keysetHash: Hex;
};

export type IsValidKeysetHashParameters<Curried extends boolean = false> = ActionParameters<
Args,
'sequencerInbox',
Curried
>;

export type IsValidKeysetHashReturnType = ReadContractReturnType<
typeof sequencerInboxABI,
'isValidKeysetHash'
>;

export async function isValidKeysetHash<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: IsValidKeysetHashParameters,
): Promise<IsValidKeysetHashReturnType> {
return client.readContract({
abi: sequencerInboxABI,
functionName: 'isValidKeysetHash',
address: args.sequencerInbox,
args: [args.keysetHash],
});
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ import {
getConsensusReleaseByWasmModuleRoot,
GetConsensusReleaseByWasmModuleRoot,
} from './wasmModuleRoot';
export * from './actions';

export {
arbOwnerPublicActions,
Expand Down
22 changes: 22 additions & 0 deletions src/types/Actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Address } from 'viem';
import { Prettify } from './utils';

/**
* Actions require contract address, but as part of decorators, the address might have been passed already to the decorator.
*
* If the address was passed to the decorator, it's now optional (we still allow overrides of the address per action).
* If the action doesn't have any other parameters beside the contract address, then parameters can either be { contract: address } or void
*/
export type ActionParameters<Args, ContractName extends string, Curried extends boolean> = Prettify<
Curried extends false
? Args & { [key in ContractName]: Address }
: Args extends Record<string, never>
?
| {
[key in ContractName]: Address;
}
| void
: Args & {
[key in ContractName]?: Address;
}
>;