From a5dc4126f1fe76d5ae59b3fc6a68f48830cd8f9f Mon Sep 17 00:00:00 2001 From: Christophe Date: Thu, 27 Jun 2024 21:12:15 +0000 Subject: [PATCH] Feat: Add v1 RollupAdminLogic setters Closes FS-621 --- src/actions/setConfirmPeriodBlocks.ts | 48 +++++++++++++++ src/actions/setExtraChallengeTimeBlocks.ts | 50 ++++++++++++++++ src/actions/setMinimumAssertionPeriod.ts | 48 +++++++++++++++ src/actions/setValidator.ts | 47 +++++++++++++++ src/actions/setValidatorWhitelistDisabled.ts | 61 ++++++++++++++++++++ src/actions/setWasmModuleRoot.ts | 49 ++++++++++++++++ 6 files changed, 303 insertions(+) create mode 100644 src/actions/setConfirmPeriodBlocks.ts create mode 100644 src/actions/setExtraChallengeTimeBlocks.ts create mode 100644 src/actions/setMinimumAssertionPeriod.ts create mode 100644 src/actions/setValidator.ts create mode 100644 src/actions/setValidatorWhitelistDisabled.ts create mode 100644 src/actions/setWasmModuleRoot.ts diff --git a/src/actions/setConfirmPeriodBlocks.ts b/src/actions/setConfirmPeriodBlocks.ts new file mode 100644 index 00000000..89a4be54 --- /dev/null +++ b/src/actions/setConfirmPeriodBlocks.ts @@ -0,0 +1,48 @@ +import { + Chain, + PrepareTransactionRequestParameters, + PrepareTransactionRequestReturnType, + PublicClient, + Transport, + encodeFunctionData, +} from 'viem'; +import { rollupAdminLogic } from '../contracts'; +import { ActionParameters, WithAccount } from '../types/Actions'; +import { Prettify } from '../types/utils'; + +export type SetConfirmPeriodBlocksParameters = Prettify< + WithAccount< + ActionParameters< + { + newPeriod: bigint; + }, + 'rollupAdminLogic', + Curried + > + > +>; + +export type SetConfirmPeriodBlocksReturnType = PrepareTransactionRequestReturnType; + +function rollupAdminLogicFunctionData({ newPeriod }: SetConfirmPeriodBlocksParameters) { + return encodeFunctionData({ + abi: rollupAdminLogic.abi, + functionName: 'setConfirmPeriodBlocks', + args: [newPeriod], + }); +} + +export async function setConfirmPeriodBlocks( + client: PublicClient, + args: SetConfirmPeriodBlocksParameters, +): Promise { + const data = rollupAdminLogicFunctionData(args); + + return client.prepareTransactionRequest({ + to: args.rollupAdminLogic, + value: BigInt(0), + chain: client.chain, + data, + account: args.account, + } satisfies PrepareTransactionRequestParameters); +} diff --git a/src/actions/setExtraChallengeTimeBlocks.ts b/src/actions/setExtraChallengeTimeBlocks.ts new file mode 100644 index 00000000..265b8d84 --- /dev/null +++ b/src/actions/setExtraChallengeTimeBlocks.ts @@ -0,0 +1,50 @@ +import { + Chain, + PrepareTransactionRequestParameters, + PrepareTransactionRequestReturnType, + PublicClient, + Transport, + encodeFunctionData, +} from 'viem'; +import { rollupAdminLogic } from '../contracts'; +import { ActionParameters, WithAccount } from '../types/Actions'; +import { Prettify } from '../types/utils'; + +export type SetExtraChallengeTimeBlocksParameters = Prettify< + WithAccount< + ActionParameters< + { + newExtraTimeBlocks: bigint; + }, + 'rollupAdminLogic', + Curried + > + > +>; + +export type SetExtraChallengeTimeBlocksReturnType = PrepareTransactionRequestReturnType; + +function rollupAdminLogicFunctionData({ + newExtraTimeBlocks, +}: SetExtraChallengeTimeBlocksParameters) { + return encodeFunctionData({ + abi: rollupAdminLogic.abi, + functionName: 'setExtraChallengeTimeBlocks', + args: [newExtraTimeBlocks], + }); +} + +export async function setExtraChallengeTimeBlocks( + client: PublicClient, + args: SetExtraChallengeTimeBlocksParameters, +): Promise { + const data = rollupAdminLogicFunctionData(args); + + return client.prepareTransactionRequest({ + to: args.rollupAdminLogic, + value: BigInt(0), + chain: client.chain, + data, + account: args.account, + } satisfies PrepareTransactionRequestParameters); +} diff --git a/src/actions/setMinimumAssertionPeriod.ts b/src/actions/setMinimumAssertionPeriod.ts new file mode 100644 index 00000000..1eed2739 --- /dev/null +++ b/src/actions/setMinimumAssertionPeriod.ts @@ -0,0 +1,48 @@ +import { + Chain, + PrepareTransactionRequestParameters, + PrepareTransactionRequestReturnType, + PublicClient, + Transport, + encodeFunctionData, +} from 'viem'; +import { rollupAdminLogic } from '../contracts'; +import { ActionParameters, WithAccount } from '../types/Actions'; +import { Prettify } from '../types/utils'; + +export type SetMinimumAssertionPeriodParameters = Prettify< + WithAccount< + ActionParameters< + { + newPeriod: bigint; + }, + 'rollupAdminLogic', + Curried + > + > +>; + +export type SetMinimumAssertionPeriodReturnType = PrepareTransactionRequestReturnType; + +function rollupAdminLogicFunctionData({ newPeriod }: SetMinimumAssertionPeriodParameters) { + return encodeFunctionData({ + abi: rollupAdminLogic.abi, + functionName: 'setMinimumAssertionPeriod', + args: [newPeriod], + }); +} + +export async function setMinimumAssertionPeriod( + client: PublicClient, + args: SetMinimumAssertionPeriodParameters, +): Promise { + const data = rollupAdminLogicFunctionData(args); + + return client.prepareTransactionRequest({ + to: args.rollupAdminLogic, + value: BigInt(0), + chain: client.chain, + data, + account: args.account, + } satisfies PrepareTransactionRequestParameters); +} diff --git a/src/actions/setValidator.ts b/src/actions/setValidator.ts new file mode 100644 index 00000000..f49a8ba0 --- /dev/null +++ b/src/actions/setValidator.ts @@ -0,0 +1,47 @@ +import { + Address, + Chain, + PrepareTransactionRequestParameters, + PrepareTransactionRequestReturnType, + PublicClient, + Transport, + encodeFunctionData, +} from 'viem'; +import { rollupAdminLogic } from '../contracts'; +import { ActionParameters, WithAccount } from '../types/Actions'; +import { Prettify } from '../types/utils'; + +type Args = { + add: Address[]; + remove: Address[]; +}; + +export type SetIsValidatorParameters = Prettify< + WithAccount> +>; + +export type SetIsValidatorReturnType = PrepareTransactionRequestReturnType; + +function rollupAdminLogicFunctionData({ add, remove }: SetIsValidatorParameters) { + const addState: boolean[] = new Array(add.length).fill(true); + const removeState: boolean[] = new Array(remove.length).fill(false); + return encodeFunctionData({ + abi: rollupAdminLogic.abi, + functionName: 'setValidator', + args: [add.concat(remove), addState.concat(removeState)], + }); +} + +export async function setValidators( + client: PublicClient, + args: SetIsValidatorParameters, +): Promise { + const data = rollupAdminLogicFunctionData(args); + return client.prepareTransactionRequest({ + to: args.rollupAdminLogic, + value: BigInt(0), + chain: client.chain, + data, + account: args.account, + } satisfies PrepareTransactionRequestParameters); +} diff --git a/src/actions/setValidatorWhitelistDisabled.ts b/src/actions/setValidatorWhitelistDisabled.ts new file mode 100644 index 00000000..38f36abd --- /dev/null +++ b/src/actions/setValidatorWhitelistDisabled.ts @@ -0,0 +1,61 @@ +import { + Chain, + PrepareTransactionRequestParameters, + PrepareTransactionRequestReturnType, + PublicClient, + Transport, + encodeFunctionData, +} from 'viem'; +import { rollupAdminLogic } from '../contracts'; +import { ActionParameters, WithAccount } from '../types/Actions'; +import { Prettify } from '../types/utils'; + +export type SetValidatorWhitelistDisabledParameters = Prettify< + WithAccount> +>; + +export type SetValidatorWhitelistDisabledReturnType = PrepareTransactionRequestReturnType; + +function rollupAdminLogicFunctionData({ + enable, +}: SetValidatorWhitelistDisabledParameters & { enable: boolean }) { + return encodeFunctionData({ + abi: rollupAdminLogic.abi, + functionName: 'setValidatorWhitelistDisabled', + args: [enable], + }); +} + +async function setValidatorWhitelistDisabled( + client: PublicClient, + args: SetValidatorWhitelistDisabledParameters & { enable: boolean }, +): Promise { + const data = rollupAdminLogicFunctionData(args); + return client.prepareTransactionRequest({ + to: args.rollupAdminLogic, + value: BigInt(0), + chain: client.chain, + data, + account: args.account, + } satisfies PrepareTransactionRequestParameters); +} + +export async function enableValidatorWhitelist( + client: PublicClient, + args: SetValidatorWhitelistDisabledParameters, +): Promise { + return setValidatorWhitelistDisabled(client, { + ...args, + enable: true, + }); +} + +export async function disableValidatorWhitelist( + client: PublicClient, + args: SetValidatorWhitelistDisabledParameters, +): Promise { + return setValidatorWhitelistDisabled(client, { + ...args, + enable: false, + }); +} diff --git a/src/actions/setWasmModuleRoot.ts b/src/actions/setWasmModuleRoot.ts new file mode 100644 index 00000000..7c856d7d --- /dev/null +++ b/src/actions/setWasmModuleRoot.ts @@ -0,0 +1,49 @@ +import { + Chain, + Hex, + PrepareTransactionRequestParameters, + PrepareTransactionRequestReturnType, + PublicClient, + Transport, + encodeFunctionData, +} from 'viem'; +import { rollupAdminLogic } from '../contracts'; +import { ActionParameters, WithAccount } from '../types/Actions'; +import { Prettify } from '../types/utils'; + +export type SetWasmModuleRootParameters = Prettify< + WithAccount< + ActionParameters< + { + newWasmModuleRoot: Hex; + }, + 'rollupAdminLogic', + Curried + > + > +>; + +export type SetWasmModuleRootReturnType = PrepareTransactionRequestReturnType; + +function rollupAdminLogicFunctionData({ newWasmModuleRoot }: SetWasmModuleRootParameters) { + return encodeFunctionData({ + abi: rollupAdminLogic.abi, + functionName: 'setWasmModuleRoot', + args: [newWasmModuleRoot], + }); +} + +export async function setWasmModuleRoot( + client: PublicClient, + args: SetWasmModuleRootParameters, +): Promise { + const data = rollupAdminLogicFunctionData(args); + + return client.prepareTransactionRequest({ + to: args.rollupAdminLogic, + value: BigInt(0), + chain: client.chain, + data, + account: args.account, + } satisfies PrepareTransactionRequestParameters); +}