diff --git a/src/actions/invalidateKeysetHash.ts b/src/actions/invalidateKeysetHash.ts new file mode 100644 index 00000000..1d0bd681 --- /dev/null +++ b/src/actions/invalidateKeysetHash.ts @@ -0,0 +1,49 @@ +import { + Chain, + Hex, + PrepareTransactionRequestParameters, + PrepareTransactionRequestReturnType, + PublicClient, + Transport, + encodeFunctionData, +} from 'viem'; +import { sequencerInbox } from '../contracts'; +import { ActionParameters, WithAccount } from '../types/Actions'; +import { Prettify } from '../types/utils'; + +export type InvalidateKeysetHashParameters = Prettify< + WithAccount< + ActionParameters< + { + keysetHash: Hex; + }, + 'sequencerInbox', + Curried + > + > +>; + +export type InvalidateKeysetHashReturnType = PrepareTransactionRequestReturnType; + +function sequencerInboxFunctionData({ keysetHash }: InvalidateKeysetHashParameters) { + return encodeFunctionData({ + abi: sequencerInbox.abi, + functionName: 'invalidateKeysetHash', + args: [keysetHash], + }); +} + +export async function invalidateKeysetHash( + client: PublicClient, + args: InvalidateKeysetHashParameters, +): Promise { + const data = sequencerInboxFunctionData(args); + + return client.prepareTransactionRequest({ + to: args.sequencerInbox, + value: BigInt(0), + chain: client.chain, + data, + account: args.account, + } satisfies PrepareTransactionRequestParameters); +} diff --git a/src/actions/setIsbatchPoster.ts b/src/actions/setIsbatchPoster.ts new file mode 100644 index 00000000..eef471d3 --- /dev/null +++ b/src/actions/setIsbatchPoster.ts @@ -0,0 +1,67 @@ +import { + Address, + Chain, + PrepareTransactionRequestParameters, + PrepareTransactionRequestReturnType, + PublicClient, + Transport, + encodeFunctionData, +} from 'viem'; +import { sequencerInbox } from '../contracts'; +import { ActionParameters, WithAccount } from '../types/Actions'; +import { Prettify } from '../types/utils'; + +type Args = { + batchPoster: Address; +}; + +export type SetIsBatchPosterParameters = Prettify< + WithAccount> +>; + +export type SetIsBatchPosterReturnType = PrepareTransactionRequestReturnType; + +function sequencerInboxFunctionData({ + batchPoster, + enable, +}: SetIsBatchPosterParameters & { enable: boolean }) { + return encodeFunctionData({ + abi: sequencerInbox.abi, + functionName: 'setIsBatchPoster', + args: [batchPoster, enable], + }); +} + +async function setIsBatchPoster( + client: PublicClient, + args: SetIsBatchPosterParameters & { enable: boolean }, +): Promise { + const data = sequencerInboxFunctionData(args); + return client.prepareTransactionRequest({ + to: args.sequencerInbox, + value: BigInt(0), + chain: client.chain, + data, + account: args.account, + } satisfies PrepareTransactionRequestParameters); +} + +export async function enableBatchPoster( + client: PublicClient, + args: SetIsBatchPosterParameters, +): Promise { + return setIsBatchPoster(client, { + ...args, + enable: true, + }); +} + +export async function disableBatchPoster( + client: PublicClient, + args: SetIsBatchPosterParameters, +): Promise { + return setIsBatchPoster(client, { + ...args, + enable: false, + }); +} diff --git a/src/actions/setKeyset.ts b/src/actions/setKeyset.ts new file mode 100644 index 00000000..d71c1212 --- /dev/null +++ b/src/actions/setKeyset.ts @@ -0,0 +1,49 @@ +import { + Chain, + Hex, + PrepareTransactionRequestParameters, + PrepareTransactionRequestReturnType, + PublicClient, + Transport, + encodeFunctionData, +} from 'viem'; +import { sequencerInbox } from '../contracts'; +import { ActionParameters, WithAccount } from '../types/Actions'; +import { Prettify } from '../types/utils'; + +export type SetKeysetParameters = Prettify< + WithAccount< + ActionParameters< + { + keyset: Hex; + }, + 'sequencerInbox', + Curried + > + > +>; + +export type SetKeysetReturnType = PrepareTransactionRequestReturnType; + +function sequencerInboxFunctionData({ keyset }: SetKeysetParameters) { + return encodeFunctionData({ + abi: sequencerInbox.abi, + functionName: 'setValidKeyset', + args: [keyset], + }); +} + +export async function setKeyset( + client: PublicClient, + args: SetKeysetParameters, +): Promise { + const data = sequencerInboxFunctionData(args); + + return client.prepareTransactionRequest({ + to: args.sequencerInbox, + value: BigInt(0), + chain: client.chain, + data, + account: args.account, + } satisfies PrepareTransactionRequestParameters); +} diff --git a/src/actions/setMaxTimeVariation.ts b/src/actions/setMaxTimeVariation.ts new file mode 100644 index 00000000..7f763d84 --- /dev/null +++ b/src/actions/setMaxTimeVariation.ts @@ -0,0 +1,46 @@ +import { + Chain, + PrepareTransactionRequestParameters, + PrepareTransactionRequestReturnType, + PublicClient, + Transport, + encodeFunctionData, +} from 'viem'; +import { sequencerInbox } from '../contracts'; +import { ActionParameters, WithAccount } from '../types/Actions'; +import { Prettify } from '../types/utils'; + +type Args = { + delayBlocks: bigint; + futureBlocks: bigint; + delaySeconds: bigint; + futureSeconds: bigint; +}; +export type SetMaxTimeVariationParameters = Prettify< + WithAccount> +>; + +export type SetMaxTimeVariationReturnType = PrepareTransactionRequestReturnType; + +function sequencerInboxFunctionData(args: SetMaxTimeVariationParameters) { + return encodeFunctionData({ + abi: sequencerInbox.abi, + functionName: 'setMaxTimeVariation', + args: [args], + }); +} + +export async function setMaxTimeVariation( + client: PublicClient, + args: SetMaxTimeVariationParameters, +): Promise { + const data = sequencerInboxFunctionData(args); + + return client.prepareTransactionRequest({ + to: args.sequencerInbox, + value: BigInt(0), + chain: client.chain, + data, + account: args.account, + } satisfies PrepareTransactionRequestParameters); +}