Skip to content

Commit

Permalink
Feat: Add v1 RollupAdminLogic setters
Browse files Browse the repository at this point in the history
Closes FS-621
  • Loading branch information
chrstph-dvx committed Jun 27, 2024
1 parent 4561376 commit 6d8c079
Show file tree
Hide file tree
Showing 6 changed files with 303 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/actions/setConfirmPeriodBlocks.ts
Original file line number Diff line number Diff line change
@@ -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<Curried extends boolean = false> = 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<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: SetConfirmPeriodBlocksParameters,
): Promise<SetConfirmPeriodBlocksReturnType> {
const data = rollupAdminLogicFunctionData(args);

return client.prepareTransactionRequest({
to: args.rollupAdminLogic,
value: BigInt(0),
chain: client.chain,
data,
account: args.account,
} satisfies PrepareTransactionRequestParameters);
}
50 changes: 50 additions & 0 deletions src/actions/setExtraChallengeTimeBlocks.ts
Original file line number Diff line number Diff line change
@@ -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<Curried extends boolean = false> = 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<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: SetExtraChallengeTimeBlocksParameters,
): Promise<SetExtraChallengeTimeBlocksReturnType> {
const data = rollupAdminLogicFunctionData(args);

return client.prepareTransactionRequest({
to: args.rollupAdminLogic,
value: BigInt(0),
chain: client.chain,
data,
account: args.account,
} satisfies PrepareTransactionRequestParameters);
}
48 changes: 48 additions & 0 deletions src/actions/setMinimumAssertionPeriod.ts
Original file line number Diff line number Diff line change
@@ -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<Curried extends boolean = false> = 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<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: SetMinimumAssertionPeriodParameters,
): Promise<SetMinimumAssertionPeriodReturnType> {
const data = rollupAdminLogicFunctionData(args);

return client.prepareTransactionRequest({
to: args.rollupAdminLogic,
value: BigInt(0),
chain: client.chain,
data,
account: args.account,
} satisfies PrepareTransactionRequestParameters);
}
47 changes: 47 additions & 0 deletions src/actions/setValidator.ts
Original file line number Diff line number Diff line change
@@ -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<Curried extends boolean = false> = Prettify<
WithAccount<ActionParameters<Args, 'rollupAdminLogic', Curried>>
>;

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<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: SetIsValidatorParameters,
): Promise<SetIsValidatorReturnType> {
const data = rollupAdminLogicFunctionData(args);
return client.prepareTransactionRequest({
to: args.rollupAdminLogic,
value: BigInt(0),
chain: client.chain,
data,
account: args.account,
} satisfies PrepareTransactionRequestParameters);
}
61 changes: 61 additions & 0 deletions src/actions/setValidatorWhitelistDisabled.ts
Original file line number Diff line number Diff line change
@@ -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<Curried extends boolean = false> = Prettify<
WithAccount<ActionParameters<{}, 'rollupAdminLogic', Curried>>
>;

export type SetValidatorWhitelistDisabledReturnType = PrepareTransactionRequestReturnType;

function rollupAdminLogicFunctionData({
enable,
}: SetValidatorWhitelistDisabledParameters & { enable: boolean }) {
return encodeFunctionData({
abi: rollupAdminLogic.abi,
functionName: 'setValidatorWhitelistDisabled',
args: [enable],
});
}

async function setValidatorWhitelistDisabled<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: SetValidatorWhitelistDisabledParameters & { enable: boolean },
): Promise<SetValidatorWhitelistDisabledReturnType> {
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<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: SetValidatorWhitelistDisabledParameters,
): Promise<SetValidatorWhitelistDisabledReturnType> {
return setValidatorWhitelistDisabled(client, {
...args,
enable: true,
});
}

export async function disableValidatorWhitelist<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: SetValidatorWhitelistDisabledParameters,
): Promise<SetValidatorWhitelistDisabledReturnType> {
return setValidatorWhitelistDisabled(client, {
...args,
enable: false,
});
}
49 changes: 49 additions & 0 deletions src/actions/setWasmModuleRoot.ts
Original file line number Diff line number Diff line change
@@ -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<Curried extends boolean = false> = 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<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: SetWasmModuleRootParameters,
): Promise<SetWasmModuleRootReturnType> {
const data = rollupAdminLogicFunctionData(args);

return client.prepareTransactionRequest({
to: args.rollupAdminLogic,
value: BigInt(0),
chain: client.chain,
data,
account: args.account,
} satisfies PrepareTransactionRequestParameters);
}

0 comments on commit 6d8c079

Please sign in to comment.