Skip to content

Commit

Permalink
Cleanup, rename setters to buildX
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx committed Sep 18, 2024
1 parent 6fe99d3 commit a61fb2a
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 453 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { rollupAdminLogic } from '../contracts';
import { rollupABI } from '../contracts/Rollup';
import {
WithAccount,
ActionParameters,
Expand All @@ -9,32 +9,32 @@ import {
import { Prettify } from '../types/utils';
import { getRollupAddress } from '../getRollupAddress';
import { validateParentChainPublicClient } from '../types/ParentChain';
import { withUpgradeExecutor } from '../withUpgradeExecutor';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';

export type SetConfirmPeriodBlocksParameters<Curried extends boolean = false> = Prettify<
export type BuildSetConfirmPeriodBlocksParameters<Curried extends boolean = false> = Prettify<
WithUpgradeExecutor<
WithAccount<ActionParameters<{ newPeriod: bigint }, 'rollupAdminLogic', Curried>>
>
>;

export type SetConfirmPeriodBlocksReturnType = PrepareTransactionRequestReturnTypeWithChainId;
export type BuildSetConfirmPeriodBlocksReturnType = PrepareTransactionRequestReturnTypeWithChainId;

export async function setConfirmPeriodBlocks<TChain extends Chain | undefined>(
export async function buildSetConfirmPeriodBlocks<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
params: SetConfirmPeriodBlocksParameters,
): Promise<SetConfirmPeriodBlocksReturnType> {
{ params, account, upgradeExecutor, ...args }: BuildSetConfirmPeriodBlocksParameters,
): Promise<BuildSetConfirmPeriodBlocksReturnType> {
const validatedPublicClient = validateParentChainPublicClient(client);
const rollupAdminLogicAddresss = await getRollupAddress(client, params);
const { account, upgradeExecutor, newPeriod } = params;
const rollupAdminLogicAddress =
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic;

const request = await client.prepareTransactionRequest({
chain: client.chain,
chain: client.chain as Chain | undefined,
account,
...withUpgradeExecutor({
to: rollupAdminLogicAddresss,
...prepareUpgradeExecutorCallParameters({
to: rollupAdminLogicAddress,
upgradeExecutor,
args: [newPeriod],
abi: rollupAdminLogic.abi,
args: [params.newPeriod],
abi: rollupABI,
functionName: 'setConfirmPeriodBlocks',
}),
} satisfies PrepareTransactionRequestParameters);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { rollupAdminLogic } from '../contracts';
import { rollupABI } from '../contracts/Rollup';
import {
WithAccount,
ActionParameters,
Expand All @@ -9,32 +9,33 @@ import {
import { Prettify } from '../types/utils';
import { getRollupAddress } from '../getRollupAddress';
import { validateParentChainPublicClient } from '../types/ParentChain';
import { withUpgradeExecutor } from '../withUpgradeExecutor';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';

export type SetExtraChallengeTimeBlocksParameters<Curried extends boolean = false> = Prettify<
export type BuildSetExtraChallengeTimeBlocksParameters<Curried extends boolean = false> = Prettify<
WithUpgradeExecutor<
WithAccount<ActionParameters<{ newExtraTimeBlocks: bigint }, 'rollupAdminLogic', Curried>>
>
>;

export type SetExtraChallengeTimeBlocksReturnType = PrepareTransactionRequestReturnTypeWithChainId;
export type BuildSetExtraChallengeTimeBlocksReturnType =
PrepareTransactionRequestReturnTypeWithChainId;

export async function setExtraChallengeTimeBlocks<TChain extends Chain | undefined>(
export async function buildSetExtraChallengeTimeBlocks<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
params: SetExtraChallengeTimeBlocksParameters,
): Promise<SetExtraChallengeTimeBlocksReturnType> {
{ params, account, upgradeExecutor, ...args }: BuildSetExtraChallengeTimeBlocksParameters,
): Promise<BuildSetExtraChallengeTimeBlocksReturnType> {
const validatedPublicClient = validateParentChainPublicClient(client);
const rollupAdminLogicAddresss = await getRollupAddress(client, params);
const { account, upgradeExecutor, newExtraTimeBlocks } = params;
const rollupAdminLogicAddress =
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic;

const request = await client.prepareTransactionRequest({
chain: client.chain,
chain: client.chain as Chain | undefined,
account,
...withUpgradeExecutor({
to: rollupAdminLogicAddresss,
...prepareUpgradeExecutorCallParameters({
to: rollupAdminLogicAddress,
upgradeExecutor,
args: [newExtraTimeBlocks],
abi: rollupAdminLogic.abi,
args: [params.newExtraTimeBlocks],
abi: rollupABI,
functionName: 'setExtraChallengeTimeBlocks',
}),
} satisfies PrepareTransactionRequestParameters);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { rollupAdminLogic } from '../contracts';
import { rollupABI } from '../contracts/Rollup';
import {
WithAccount,
ActionParameters,
Expand All @@ -9,32 +9,33 @@ import {
import { Prettify } from '../types/utils';
import { getRollupAddress } from '../getRollupAddress';
import { validateParentChainPublicClient } from '../types/ParentChain';
import { withUpgradeExecutor } from '../withUpgradeExecutor';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';

export type SetMinimumAssertionPeriodParameters<Curried extends boolean = false> = Prettify<
export type BuildSetMinimumAssertionPeriodParameters<Curried extends boolean = false> = Prettify<
WithUpgradeExecutor<
WithAccount<ActionParameters<{ newPeriod: bigint }, 'rollupAdminLogic', Curried>>
>
>;

export type SetMinimumAssertionPeriodReturnType = PrepareTransactionRequestReturnTypeWithChainId;
export type BuildSetMinimumAssertionPeriodReturnType =
PrepareTransactionRequestReturnTypeWithChainId;

export async function setMinimumAssertionPeriod<TChain extends Chain | undefined>(
export async function setMinimumAssertionPeriod<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
params: SetMinimumAssertionPeriodParameters,
): Promise<SetMinimumAssertionPeriodReturnType> {
{ params, account, upgradeExecutor, ...args }: BuildSetMinimumAssertionPeriodParameters,
): Promise<BuildSetMinimumAssertionPeriodReturnType> {
const validatedPublicClient = validateParentChainPublicClient(client);
const rollupAdminLogicAddresss = await getRollupAddress(client, params);
const { account, upgradeExecutor, newPeriod } = params;
const rollupAdminLogicAddress =
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic;

const request = await client.prepareTransactionRequest({
chain: client.chain,
chain: client.chain as Chain | undefined,
account,
...withUpgradeExecutor({
to: rollupAdminLogicAddresss,
...prepareUpgradeExecutorCallParameters({
to: rollupAdminLogicAddress,
upgradeExecutor,
args: [newPeriod],
abi: rollupAdminLogic.abi,
args: [params.newPeriod],
abi: rollupABI,
functionName: 'setMinimumAssertionPeriod',
}),
} satisfies PrepareTransactionRequestParameters);
Expand Down
27 changes: 14 additions & 13 deletions src/actions/setValidator.ts → src/actions/buildSetValidator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { rollupAdminLogic } from '../contracts';
import { rollupABI } from '../contracts/Rollup';
import {
WithAccount,
ActionParameters,
Expand All @@ -9,9 +9,9 @@ import {
import { Prettify } from '../types/utils';
import { getRollupAddress } from '../getRollupAddress';
import { validateParentChainPublicClient } from '../types/ParentChain';
import { withUpgradeExecutor } from '../withUpgradeExecutor';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';

export type SetIsValidatorParameters<Curried extends boolean = false> = Prettify<
export type BuildSetIsValidatorParameters<Curried extends boolean = false> = Prettify<
WithUpgradeExecutor<
WithAccount<
ActionParameters<
Expand All @@ -26,27 +26,28 @@ export type SetIsValidatorParameters<Curried extends boolean = false> = Prettify
>
>;

export type SetIsValidatorReturnType = PrepareTransactionRequestReturnTypeWithChainId;
export type BuildSetIsValidatorReturnType = PrepareTransactionRequestReturnTypeWithChainId;

export async function setValidators<TChain extends Chain | undefined>(
export async function buildSetValidators<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
params: SetIsValidatorParameters,
): Promise<SetIsValidatorReturnType> {
{ account, upgradeExecutor, params, ...args }: BuildSetIsValidatorParameters,
): Promise<BuildSetIsValidatorReturnType> {
const validatedPublicClient = validateParentChainPublicClient(client);
const rollupAdminLogicAddresss = await getRollupAddress(client, params);
const { account, upgradeExecutor, add: addressesToAdd, remove: addressesToRemove } = params;
const rollupAdminLogicAddress =
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic;
const { add: addressesToAdd, remove: addressesToRemove } = params;

const addState: boolean[] = new Array(addressesToAdd.length).fill(true);
const removeState: boolean[] = new Array(addressesToRemove.length).fill(false);

const request = await client.prepareTransactionRequest({
chain: client.chain,
chain: client.chain as Chain | undefined,
account,
...withUpgradeExecutor({
to: rollupAdminLogicAddresss,
...prepareUpgradeExecutorCallParameters({
to: rollupAdminLogicAddress,
upgradeExecutor,
args: [addressesToAdd.concat(addressesToRemove), addState.concat(removeState)],
abi: rollupAdminLogic.abi,
abi: rollupABI,
functionName: 'setValidator',
}),
} satisfies PrepareTransactionRequestParameters);
Expand Down
70 changes: 70 additions & 0 deletions src/actions/buildSetValidatorWhitelistDisabled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { rollupABI } from '../contracts/Rollup';
import {
WithAccount,
ActionParameters,
WithUpgradeExecutor,
PrepareTransactionRequestReturnTypeWithChainId,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { getRollupAddress } from '../getRollupAddress';
import { validateParentChainPublicClient } from '../types/ParentChain';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';

export type BuildSetValidatorWhitelistDisabledParameters<Curried extends boolean = false> =
Prettify<WithUpgradeExecutor<WithAccount<ActionParameters<{}, 'rollupAdminLogic', Curried>>>>;

export type BuildSetValidatorWhitelistDisabledReturnType =
PrepareTransactionRequestReturnTypeWithChainId;

export async function buildSetValidatorWhitelistDisabled<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
{
account,
upgradeExecutor,
params,
...args
}: BuildSetValidatorWhitelistDisabledParameters & { params: { enable: boolean } },
): Promise<BuildSetValidatorWhitelistDisabledReturnType> {
const validatedPublicClient = validateParentChainPublicClient(client);
const rollupAdminLogicAddress =
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic;

const request = await client.prepareTransactionRequest({
chain: client.chain as Chain | undefined,
account,
...prepareUpgradeExecutorCallParameters({
to: rollupAdminLogicAddress,
upgradeExecutor,
args: [params.enable],
abi: rollupABI,
functionName: 'setValidatorWhitelistDisabled',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: validatedPublicClient.chain.id };
}

export async function buildEnableValidatorWhitelist<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
args: BuildSetValidatorWhitelistDisabledParameters,
): Promise<BuildSetValidatorWhitelistDisabledReturnType> {
return buildSetValidatorWhitelistDisabled(client, {
...args,
params: {
enable: true,
},
});
}

export async function buildDisableValidatorWhitelist<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
args: BuildSetValidatorWhitelistDisabledParameters,
): Promise<BuildSetValidatorWhitelistDisabledReturnType> {
return buildSetValidatorWhitelistDisabled(client, {
...args,
params: {
enable: false,
},
});
}
51 changes: 51 additions & 0 deletions src/actions/buildSetWasmModuleRoot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Chain, Hex, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { rollupABI } from '../contracts/Rollup';
import {
WithAccount,
ActionParameters,
WithUpgradeExecutor,
PrepareTransactionRequestReturnTypeWithChainId,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { getRollupAddress } from '../getRollupAddress';
import { validateParentChainPublicClient } from '../types/ParentChain';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';

export type BuildSetWasmModuleRootParameters<Curried extends boolean = false> = Prettify<
WithUpgradeExecutor<
WithAccount<
ActionParameters<
{
newWasmModuleRoot: Hex;
},
'rollupAdminLogic',
Curried
>
>
>
>;

export type BuildSetWasmModuleRootReturnType = PrepareTransactionRequestReturnTypeWithChainId;

export async function buildSetWasmModuleRoot<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
{ account, upgradeExecutor, params, ...args }: BuildSetWasmModuleRootParameters,
): Promise<BuildSetWasmModuleRootReturnType> {
const validatedPublicClient = validateParentChainPublicClient(client);
const rollupAdminLogicAddress =
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic;

const request = await client.prepareTransactionRequest({
chain: client.chain as Chain | undefined,
account,
...prepareUpgradeExecutorCallParameters({
to: rollupAdminLogicAddress,
upgradeExecutor,
args: [params.newWasmModuleRoot],
abi: rollupABI,
functionName: 'setWasmModuleRoot',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: validatedPublicClient.chain.id };
}
49 changes: 0 additions & 49 deletions src/actions/invalidateKeysetHash.ts

This file was deleted.

Loading

0 comments on commit a61fb2a

Please sign in to comment.