diff --git a/src/actions/getMaxTimeVariation.ts b/src/actions/getMaxTimeVariation.ts new file mode 100644 index 00000000..b0bfe82c --- /dev/null +++ b/src/actions/getMaxTimeVariation.ts @@ -0,0 +1,33 @@ +import { Chain, PublicClient, Transport } from 'viem'; +import { sequencerInboxABI } from '../contracts/SequencerInbox'; +import { ActionParameters } from '../types/Actions'; + +export type GetMaxTimeVariationParameters = ActionParameters< + {}, + 'sequencerInbox', + Curried +>; + +export type GetMaxTimeVariationReturnType = { + delayBlocks: bigint; + futureBlocks: bigint; + delaySeconds: bigint; + futureSeconds: bigint; +}; + +export async function getMaxTimeVariation( + client: PublicClient, + args: GetMaxTimeVariationParameters, +): Promise { + const [delayBlocks, futureBlocks, delaySeconds, futureSeconds] = await client.readContract({ + abi: sequencerInboxABI, + functionName: 'maxTimeVariation', + address: args.sequencerInbox, + }); + return { + delayBlocks, + futureBlocks, + delaySeconds, + futureSeconds, + }; +} diff --git a/src/actions/index.ts b/src/actions/index.ts new file mode 100644 index 00000000..63164981 --- /dev/null +++ b/src/actions/index.ts @@ -0,0 +1,3 @@ +export * from './getMaxTimeVariation'; +export * from './isBatchPoster'; +export * from './isValidKeysetHash'; diff --git a/src/actions/isBatchPoster.ts b/src/actions/isBatchPoster.ts new file mode 100644 index 00000000..f71b773f --- /dev/null +++ b/src/actions/isBatchPoster.ts @@ -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 = ActionParameters< + Args, + 'sequencerInbox', + Curried +>; + +export type IsBatchPosterReturnType = ReadContractReturnType< + typeof sequencerInboxABI, + 'isBatchPoster' +>; + +export async function isBatchPoster( + client: PublicClient, + args: IsBatchPosterParameters, +): Promise { + return client.readContract({ + abi: sequencerInboxABI, + functionName: 'isBatchPoster', + address: args.sequencerInbox, + args: [args.batchPoster], + }); +} diff --git a/src/actions/isValidKeysetHash.ts b/src/actions/isValidKeysetHash.ts new file mode 100644 index 00000000..1a5e7007 --- /dev/null +++ b/src/actions/isValidKeysetHash.ts @@ -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 = ActionParameters< + Args, + 'sequencerInbox', + Curried +>; + +export type IsValidKeysetHashReturnType = ReadContractReturnType< + typeof sequencerInboxABI, + 'isValidKeysetHash' +>; + +export async function isValidKeysetHash( + client: PublicClient, + args: IsValidKeysetHashParameters, +): Promise { + return client.readContract({ + abi: sequencerInboxABI, + functionName: 'isValidKeysetHash', + address: args.sequencerInbox, + args: [args.keysetHash], + }); +} diff --git a/src/index.ts b/src/index.ts index 3f143780..db767cbe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -137,6 +137,7 @@ import { getConsensusReleaseByWasmModuleRoot, GetConsensusReleaseByWasmModuleRoot, } from './wasmModuleRoot'; +export * from './actions'; export { arbOwnerPublicActions, diff --git a/src/types/Actions.ts b/src/types/Actions.ts new file mode 100644 index 00000000..0327ffba --- /dev/null +++ b/src/types/Actions.ts @@ -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 = Prettify< + Curried extends false + ? Args & { [key in ContractName]: Address } + : Args extends Record + ? + | { + [key in ContractName]: Address; + } + | void + : Args & { + [key in ContractName]?: Address; + } +>;