Skip to content

Commit

Permalink
Add upgradeExecutor flag
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx committed Jul 15, 2024
1 parent 03117ca commit ba1f66c
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 90 deletions.
56 changes: 26 additions & 30 deletions src/actions/setIsbatchPoster.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,45 @@
import {
Address,
Chain,
PrepareTransactionRequestParameters,
PrepareTransactionRequestReturnType,
PublicClient,
Transport,
encodeFunctionData,
} from 'viem';
import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { sequencerInbox } from '../contracts';
import { ActionParameters, WithAccount } from '../types/Actions';
import {
ActionParameters,
PrepareTransactionRequestReturnTypeWithChainId,
WithAccount,
WithUpgradeExecutor,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { withUpgradeExecutor } from '../withUpgradeExecutor';

Check failure on line 10 in src/actions/setIsbatchPoster.ts

View workflow job for this annotation

GitHub Actions / Test (Unit)

Cannot find module '../withUpgradeExecutor' or its corresponding type declarations.
import { validateParentChainPublicClient } from '../types/ParentChain';

type Args = {
batchPoster: Address;
};

export type SetIsBatchPosterParameters<Curried extends boolean = false> = Prettify<
WithAccount<ActionParameters<Args, 'sequencerInbox', Curried>>
WithUpgradeExecutor<WithAccount<ActionParameters<Args, 'sequencerInbox', Curried>>>
>;

export type SetIsBatchPosterReturnType = PrepareTransactionRequestReturnType;

function sequencerInboxFunctionData({
batchPoster,
enable,
}: SetIsBatchPosterParameters & { enable: boolean }) {
return encodeFunctionData({
abi: sequencerInbox.abi,
functionName: 'setIsBatchPoster',
args: [batchPoster, enable],
});
}
export type SetIsBatchPosterReturnType = PrepareTransactionRequestReturnTypeWithChainId;

async function setIsBatchPoster<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: SetIsBatchPosterParameters & { enable: boolean },
params: SetIsBatchPosterParameters & { enable: boolean },
): Promise<SetIsBatchPosterReturnType> {
const data = sequencerInboxFunctionData(args);
return client.prepareTransactionRequest({
to: args.sequencerInbox,
value: BigInt(0),
const validatedPublicClient = validateParentChainPublicClient(client);
const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params;

const request = await client.prepareTransactionRequest({
chain: client.chain,
data,
account: args.account,
account,
...withUpgradeExecutor({
to: sequencerInboxAddress,
upgradeExecutor,
args: [args.batchPoster, args.enable],
abi: sequencerInbox.abi,
functionName: 'setIsBatchPoster',
}),
} satisfies PrepareTransactionRequestParameters);

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

export async function enableBatchPoster<TChain extends Chain | undefined>(
Expand Down
66 changes: 33 additions & 33 deletions src/actions/setKeyset.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
import {
Chain,
Hex,
PrepareTransactionRequestParameters,
PrepareTransactionRequestReturnType,
PublicClient,
Transport,
encodeFunctionData,
} from 'viem';
import { Chain, Hex, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { sequencerInbox } from '../contracts';
import { ActionParameters, WithAccount } from '../types/Actions';
import {
ActionParameters,
PrepareTransactionRequestReturnTypeWithChainId,
WithAccount,
WithUpgradeExecutor,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { validateParentChainPublicClient } from '../types/ParentChain';
import { withUpgradeExecutor } from '../withUpgradeExecutor';

Check failure on line 11 in src/actions/setKeyset.ts

View workflow job for this annotation

GitHub Actions / Test (Unit)

Cannot find module '../withUpgradeExecutor' or its corresponding type declarations.

export type SetKeysetParameters<Curried extends boolean = false> = Prettify<
WithAccount<
ActionParameters<
{
keyset: Hex;
},
'sequencerInbox',
Curried
WithUpgradeExecutor<
WithAccount<
ActionParameters<
{
keyset: Hex;
},
'sequencerInbox',
Curried
>
>
>
>;

export type SetKeysetReturnType = PrepareTransactionRequestReturnType;

function sequencerInboxFunctionData({ keyset }: SetKeysetParameters) {
return encodeFunctionData({
abi: sequencerInbox.abi,
functionName: 'setValidKeyset',
args: [keyset],
});
}
export type SetKeysetReturnType = PrepareTransactionRequestReturnTypeWithChainId;

export async function setKeyset<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: SetKeysetParameters,
params: SetKeysetParameters,
): Promise<SetKeysetReturnType> {
const data = sequencerInboxFunctionData(args);
const validatedPublicClient = validateParentChainPublicClient(client);
const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params;

return client.prepareTransactionRequest({
to: args.sequencerInbox,
value: BigInt(0),
const request = await client.prepareTransactionRequest({
chain: client.chain,
data,
account: args.account,
account,
...withUpgradeExecutor({
to: sequencerInboxAddress,
upgradeExecutor,
args: [args.keyset],
abi: sequencerInbox.abi,
functionName: 'setValidKeyset',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: validatedPublicClient.chain.id };
}
51 changes: 25 additions & 26 deletions src/actions/setMaxTimeVariation.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
Chain,
PrepareTransactionRequestParameters,
PrepareTransactionRequestReturnType,
PublicClient,
Transport,
encodeFunctionData,
} from 'viem';
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { sequencerInbox } from '../contracts';
import { ActionParameters, WithAccount } from '../types/Actions';
import {
ActionParameters,
PrepareTransactionRequestReturnTypeWithChainId,
WithAccount,
WithUpgradeExecutor,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { withUpgradeExecutor } from '../withUpgradeExecutor';

Check failure on line 10 in src/actions/setMaxTimeVariation.ts

View workflow job for this annotation

GitHub Actions / Test (Unit)

Cannot find module '../withUpgradeExecutor' or its corresponding type declarations.
import { validateParentChainPublicClient } from '../types/ParentChain';

type Args = {
delayBlocks: bigint;
Expand All @@ -17,30 +17,29 @@ type Args = {
futureSeconds: bigint;
};
export type SetMaxTimeVariationParameters<Curried extends boolean = false> = Prettify<
WithAccount<ActionParameters<Args, 'sequencerInbox', Curried>>
WithUpgradeExecutor<WithAccount<ActionParameters<Args, 'sequencerInbox', Curried>>>
>;

export type SetMaxTimeVariationReturnType = PrepareTransactionRequestReturnType;

function sequencerInboxFunctionData(args: SetMaxTimeVariationParameters) {
return encodeFunctionData({
abi: sequencerInbox.abi,
functionName: 'setMaxTimeVariation',
args: [args],
});
}
export type SetMaxTimeVariationReturnType = PrepareTransactionRequestReturnTypeWithChainId;

export async function setMaxTimeVariation<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: SetMaxTimeVariationParameters,
params: SetMaxTimeVariationParameters,
): Promise<SetMaxTimeVariationReturnType> {
const data = sequencerInboxFunctionData(args);
const validatedPublicClient = validateParentChainPublicClient(client);
const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params;

return client.prepareTransactionRequest({
to: args.sequencerInbox,
value: BigInt(0),
const request = await client.prepareTransactionRequest({
chain: client.chain,
data,
account: args.account,
account,
...withUpgradeExecutor({
to: sequencerInboxAddress,
upgradeExecutor,
args: [args],
abi: sequencerInbox.abi,
functionName: 'setMaxTimeVariation',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: validatedPublicClient.chain.id };
}
10 changes: 9 additions & 1 deletion src/types/Actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address } from 'viem';
import { Address, PrepareTransactionRequestReturnType } from 'viem';
import { Prettify } from './utils';

/**
Expand All @@ -24,3 +24,11 @@ export type ActionParameters<Args, ContractName extends string, Curried extends
export type WithAccount<Args> = Args & {
account: Address;
};

export type WithUpgradeExecutor<Args> = Args & {
upgradeExecutor: Address | false;
};

export type PrepareTransactionRequestReturnTypeWithChainId = PrepareTransactionRequestReturnType & {
chainId: number;
};

0 comments on commit ba1f66c

Please sign in to comment.