From 3a1a87d25909e7f24b604afeb9f154e47934087a Mon Sep 17 00:00:00 2001 From: Christophe Date: Thu, 27 Jun 2024 19:08:07 +0000 Subject: [PATCH 01/14] Feat: Add v1 SequencerInbox setters Closes FS-535 --- src/actions/invalidateKeysetHash.ts | 49 +++++++++++++++++++++ src/actions/setIsbatchPoster.ts | 67 +++++++++++++++++++++++++++++ src/actions/setKeyset.ts | 49 +++++++++++++++++++++ src/actions/setMaxTimeVariation.ts | 46 ++++++++++++++++++++ 4 files changed, 211 insertions(+) create mode 100644 src/actions/invalidateKeysetHash.ts create mode 100644 src/actions/setIsbatchPoster.ts create mode 100644 src/actions/setKeyset.ts create mode 100644 src/actions/setMaxTimeVariation.ts 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); +} From 6faa3d60eb46081fc3a86581750a833da6d932d7 Mon Sep 17 00:00:00 2001 From: Christophe Date: Wed, 10 Jul 2024 22:32:50 +0000 Subject: [PATCH 02/14] Add WithAccount type --- src/types/Actions.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/types/Actions.ts b/src/types/Actions.ts index 0327ffba..e61648f0 100644 --- a/src/types/Actions.ts +++ b/src/types/Actions.ts @@ -20,3 +20,7 @@ export type ActionParameters; + +export type WithAccount = Args & { + account: Address; +}; From c352ffcbcfcaa63ef41ae1915bb00291f7c899e2 Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 15 Jul 2024 11:29:21 +0000 Subject: [PATCH 03/14] Add upgradeExecutor flag --- src/actions/setIsbatchPoster.ts | 56 ++++++++++++------------- src/actions/setKeyset.ts | 66 +++++++++++++++--------------- src/actions/setMaxTimeVariation.ts | 51 +++++++++++------------ src/types/Actions.ts | 10 ++++- 4 files changed, 93 insertions(+), 90 deletions(-) diff --git a/src/actions/setIsbatchPoster.ts b/src/actions/setIsbatchPoster.ts index eef471d3..040bb72b 100644 --- a/src/actions/setIsbatchPoster.ts +++ b/src/actions/setIsbatchPoster.ts @@ -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'; +import { validateParentChainPublicClient } from '../types/ParentChain'; type Args = { batchPoster: Address; }; export type SetIsBatchPosterParameters = Prettify< - WithAccount> + WithUpgradeExecutor>> >; -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( client: PublicClient, - args: SetIsBatchPosterParameters & { enable: boolean }, + params: SetIsBatchPosterParameters & { enable: boolean }, ): Promise { - 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( diff --git a/src/actions/setKeyset.ts b/src/actions/setKeyset.ts index d71c1212..0a9b5eb7 100644 --- a/src/actions/setKeyset.ts +++ b/src/actions/setKeyset.ts @@ -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'; export type SetKeysetParameters = 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( client: PublicClient, - args: SetKeysetParameters, + params: SetKeysetParameters, ): Promise { - 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 }; } diff --git a/src/actions/setMaxTimeVariation.ts b/src/actions/setMaxTimeVariation.ts index 7f763d84..9e0b2386 100644 --- a/src/actions/setMaxTimeVariation.ts +++ b/src/actions/setMaxTimeVariation.ts @@ -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'; +import { validateParentChainPublicClient } from '../types/ParentChain'; type Args = { delayBlocks: bigint; @@ -17,30 +17,29 @@ type Args = { futureSeconds: bigint; }; export type SetMaxTimeVariationParameters = Prettify< - WithAccount> + WithUpgradeExecutor>> >; -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( client: PublicClient, - args: SetMaxTimeVariationParameters, + params: SetMaxTimeVariationParameters, ): Promise { - 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 }; } diff --git a/src/types/Actions.ts b/src/types/Actions.ts index e61648f0..ba515953 100644 --- a/src/types/Actions.ts +++ b/src/types/Actions.ts @@ -1,4 +1,4 @@ -import { Address } from 'viem'; +import { Address, PrepareTransactionRequestReturnType } from 'viem'; import { Prettify } from './utils'; /** @@ -24,3 +24,11 @@ export type ActionParameters = Args & { account: Address; }; + +export type WithUpgradeExecutor = Args & { + upgradeExecutor: Address | false; +}; + +export type PrepareTransactionRequestReturnTypeWithChainId = PrepareTransactionRequestReturnType & { + chainId: number; +}; From e27405ddc635f23d22a71bf55f3a4c9e86aab6ea Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 15 Jul 2024 11:30:14 +0000 Subject: [PATCH 04/14] Add withUpgradeExecutor file --- src/withUpgradeExecutor.ts | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/withUpgradeExecutor.ts diff --git a/src/withUpgradeExecutor.ts b/src/withUpgradeExecutor.ts new file mode 100644 index 00000000..901ea589 --- /dev/null +++ b/src/withUpgradeExecutor.ts @@ -0,0 +1,56 @@ +import { + Address, + encodeFunctionData as viemEncodeFunctionData, + EncodeFunctionDataParameters as ViemEncodeFunctionDataParameters, +} from 'viem'; +import { GetFunctionName } from './types/utils'; +import { arbOwner, sequencerInbox } from './contracts'; +import { upgradeExecutorEncodeFunctionData } from './upgradeExecutorEncodeFunctionData'; + +type ABIs = typeof sequencerInbox.abi | typeof arbOwner.abi; +type FunctionName = GetFunctionName; + +type EncodeFunctionDataParameters< + TAbi extends ABIs, + TFunctionName extends FunctionName, +> = ViemEncodeFunctionDataParameters; + +function encodeFunctionData>({ + abi, + functionName, + args, +}: EncodeFunctionDataParameters) { + return viemEncodeFunctionData({ + abi, + functionName, + args, + } as unknown as ViemEncodeFunctionDataParameters); +} + +export function withUpgradeExecutor>( + params: EncodeFunctionDataParameters & { + to: Address; + upgradeExecutor: false | Address; + }, +) { + const { upgradeExecutor } = params; + if (!upgradeExecutor) { + return { + to: params.to, + data: encodeFunctionData(params), + value: BigInt(0), + }; + } + + return { + to: upgradeExecutor, + data: upgradeExecutorEncodeFunctionData({ + functionName: 'executeCall', + args: [ + params.to, // target + encodeFunctionData(params), // targetCallData + ], + }), + value: BigInt(0), + }; +} From 4ca765eebf0540a5ae9dcde68f0b5a4d2760afdb Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 19 Aug 2024 11:06:26 +0000 Subject: [PATCH 05/14] Update export --- src/actions/index.ts | 4 ++++ src/actions/invalidateKeysetHash.ts | 4 ++-- src/actions/setIsbatchPoster.ts | 4 ++-- src/actions/setKeyset.ts | 4 ++-- src/actions/setMaxTimeVariation.ts | 4 ++-- src/withUpgradeExecutor.ts | 5 +++-- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/actions/index.ts b/src/actions/index.ts index 63164981..6dbef323 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -1,3 +1,7 @@ export * from './getMaxTimeVariation'; export * from './isBatchPoster'; export * from './isValidKeysetHash'; +export * from './invalidateKeysetHash'; +export * from './setIsbatchPoster'; +export * from './setKeyset'; +export * from './setMaxTimeVariation'; diff --git a/src/actions/invalidateKeysetHash.ts b/src/actions/invalidateKeysetHash.ts index 1d0bd681..06e1a10d 100644 --- a/src/actions/invalidateKeysetHash.ts +++ b/src/actions/invalidateKeysetHash.ts @@ -7,7 +7,7 @@ import { Transport, encodeFunctionData, } from 'viem'; -import { sequencerInbox } from '../contracts'; +import { sequencerInboxABI } from '../contracts/SequencerInbox'; import { ActionParameters, WithAccount } from '../types/Actions'; import { Prettify } from '../types/utils'; @@ -27,7 +27,7 @@ export type InvalidateKeysetHashReturnType = PrepareTransactionRequestReturnType function sequencerInboxFunctionData({ keysetHash }: InvalidateKeysetHashParameters) { return encodeFunctionData({ - abi: sequencerInbox.abi, + abi: sequencerInboxABI, functionName: 'invalidateKeysetHash', args: [keysetHash], }); diff --git a/src/actions/setIsbatchPoster.ts b/src/actions/setIsbatchPoster.ts index 040bb72b..fe610a12 100644 --- a/src/actions/setIsbatchPoster.ts +++ b/src/actions/setIsbatchPoster.ts @@ -1,5 +1,5 @@ import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; -import { sequencerInbox } from '../contracts'; +import { sequencerInboxABI } from '../contracts/SequencerInbox'; import { ActionParameters, PrepareTransactionRequestReturnTypeWithChainId, @@ -34,7 +34,7 @@ async function setIsBatchPoster( to: sequencerInboxAddress, upgradeExecutor, args: [args.batchPoster, args.enable], - abi: sequencerInbox.abi, + abi: sequencerInboxABI, functionName: 'setIsBatchPoster', }), } satisfies PrepareTransactionRequestParameters); diff --git a/src/actions/setKeyset.ts b/src/actions/setKeyset.ts index 0a9b5eb7..cd70c791 100644 --- a/src/actions/setKeyset.ts +++ b/src/actions/setKeyset.ts @@ -1,5 +1,5 @@ import { Chain, Hex, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; -import { sequencerInbox } from '../contracts'; +import { sequencerInboxABI } from '../contracts/SequencerInbox'; import { ActionParameters, PrepareTransactionRequestReturnTypeWithChainId, @@ -40,7 +40,7 @@ export async function setKeyset( to: sequencerInboxAddress, upgradeExecutor, args: [args.keyset], - abi: sequencerInbox.abi, + abi: sequencerInboxABI, functionName: 'setValidKeyset', }), } satisfies PrepareTransactionRequestParameters); diff --git a/src/actions/setMaxTimeVariation.ts b/src/actions/setMaxTimeVariation.ts index 9e0b2386..178aecd3 100644 --- a/src/actions/setMaxTimeVariation.ts +++ b/src/actions/setMaxTimeVariation.ts @@ -1,5 +1,5 @@ import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; -import { sequencerInbox } from '../contracts'; +import { sequencerInboxABI } from '../contracts/SequencerInbox'; import { ActionParameters, PrepareTransactionRequestReturnTypeWithChainId, @@ -36,7 +36,7 @@ export async function setMaxTimeVariation( to: sequencerInboxAddress, upgradeExecutor, args: [args], - abi: sequencerInbox.abi, + abi: sequencerInboxABI, functionName: 'setMaxTimeVariation', }), } satisfies PrepareTransactionRequestParameters); diff --git a/src/withUpgradeExecutor.ts b/src/withUpgradeExecutor.ts index 901ea589..27a611f4 100644 --- a/src/withUpgradeExecutor.ts +++ b/src/withUpgradeExecutor.ts @@ -4,10 +4,11 @@ import { EncodeFunctionDataParameters as ViemEncodeFunctionDataParameters, } from 'viem'; import { GetFunctionName } from './types/utils'; -import { arbOwner, sequencerInbox } from './contracts'; +import { sequencerInboxABI } from './contracts/SequencerInbox'; +import { arbOwnerABI } from './contracts/ArbOwner'; import { upgradeExecutorEncodeFunctionData } from './upgradeExecutorEncodeFunctionData'; -type ABIs = typeof sequencerInbox.abi | typeof arbOwner.abi; +type ABIs = typeof sequencerInboxABI | typeof arbOwnerABI; type FunctionName = GetFunctionName; type EncodeFunctionDataParameters< From 8bb0b9ba2ad9195af9be004631a10f82ea5351ee Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 19 Aug 2024 14:27:30 +0000 Subject: [PATCH 06/14] Prefix setters with prepare --- src/actions/index.ts | 8 +++--- ...Hash.ts => prepareInvalidateKeysetHash.ts} | 12 ++++----- ...chPoster.ts => prepareSetIsbatchPoster.ts} | 26 +++++++++---------- .../{setKeyset.ts => prepareSetKeyset.ts} | 10 +++---- ...ation.ts => prepareSetMaxTimeVariation.ts} | 10 +++---- 5 files changed, 33 insertions(+), 33 deletions(-) rename src/actions/{invalidateKeysetHash.ts => prepareInvalidateKeysetHash.ts} (66%) rename src/actions/{setIsbatchPoster.ts => prepareSetIsbatchPoster.ts} (63%) rename src/actions/{setKeyset.ts => prepareSetKeyset.ts} (79%) rename src/actions/{setMaxTimeVariation.ts => prepareSetMaxTimeVariation.ts} (77%) diff --git a/src/actions/index.ts b/src/actions/index.ts index 6dbef323..8bbec6cb 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -1,7 +1,7 @@ export * from './getMaxTimeVariation'; export * from './isBatchPoster'; export * from './isValidKeysetHash'; -export * from './invalidateKeysetHash'; -export * from './setIsbatchPoster'; -export * from './setKeyset'; -export * from './setMaxTimeVariation'; +export * from './prepareInvalidateKeysetHash'; +export * from './prepareSetIsbatchPoster'; +export * from './prepareSetKeyset'; +export * from './prepareSetMaxTimeVariation'; diff --git a/src/actions/invalidateKeysetHash.ts b/src/actions/prepareInvalidateKeysetHash.ts similarity index 66% rename from src/actions/invalidateKeysetHash.ts rename to src/actions/prepareInvalidateKeysetHash.ts index 06e1a10d..f38279eb 100644 --- a/src/actions/invalidateKeysetHash.ts +++ b/src/actions/prepareInvalidateKeysetHash.ts @@ -11,7 +11,7 @@ import { sequencerInboxABI } from '../contracts/SequencerInbox'; import { ActionParameters, WithAccount } from '../types/Actions'; import { Prettify } from '../types/utils'; -export type InvalidateKeysetHashParameters = Prettify< +export type PrepareInvalidateKeysetHashParameters = Prettify< WithAccount< ActionParameters< { @@ -23,9 +23,9 @@ export type InvalidateKeysetHashParameters = Pr > >; -export type InvalidateKeysetHashReturnType = PrepareTransactionRequestReturnType; +export type PrepareInvalidateKeysetHashReturnType = PrepareTransactionRequestReturnType; -function sequencerInboxFunctionData({ keysetHash }: InvalidateKeysetHashParameters) { +function sequencerInboxFunctionData({ keysetHash }: PrepareInvalidateKeysetHashParameters) { return encodeFunctionData({ abi: sequencerInboxABI, functionName: 'invalidateKeysetHash', @@ -33,10 +33,10 @@ function sequencerInboxFunctionData({ keysetHash }: InvalidateKeysetHashParamete }); } -export async function invalidateKeysetHash( +export async function prepareInvalidateKeysetHash( client: PublicClient, - args: InvalidateKeysetHashParameters, -): Promise { + args: PrepareInvalidateKeysetHashParameters, +): Promise { const data = sequencerInboxFunctionData(args); return client.prepareTransactionRequest({ diff --git a/src/actions/setIsbatchPoster.ts b/src/actions/prepareSetIsbatchPoster.ts similarity index 63% rename from src/actions/setIsbatchPoster.ts rename to src/actions/prepareSetIsbatchPoster.ts index fe610a12..835b21e0 100644 --- a/src/actions/setIsbatchPoster.ts +++ b/src/actions/prepareSetIsbatchPoster.ts @@ -14,16 +14,16 @@ type Args = { batchPoster: Address; }; -export type SetIsBatchPosterParameters = Prettify< +export type PrepareSetIsBatchPosterParameters = Prettify< WithUpgradeExecutor>> >; -export type SetIsBatchPosterReturnType = PrepareTransactionRequestReturnTypeWithChainId; +export type PrepareSetIsBatchPosterReturnType = PrepareTransactionRequestReturnTypeWithChainId; -async function setIsBatchPoster( +async function prepareSetIsBatchPoster( client: PublicClient, - params: SetIsBatchPosterParameters & { enable: boolean }, -): Promise { + params: PrepareSetIsBatchPosterParameters & { enable: boolean }, +): Promise { const validatedPublicClient = validateParentChainPublicClient(client); const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params; @@ -42,21 +42,21 @@ async function setIsBatchPoster( return { ...request, chainId: validatedPublicClient.chain.id }; } -export async function enableBatchPoster( +export async function prepareEnableBatchPoster( client: PublicClient, - args: SetIsBatchPosterParameters, -): Promise { - return setIsBatchPoster(client, { + args: PrepareSetIsBatchPosterParameters, +): Promise { + return prepareSetIsBatchPoster(client, { ...args, enable: true, }); } -export async function disableBatchPoster( +export async function prepareDisableBatchPoster( client: PublicClient, - args: SetIsBatchPosterParameters, -): Promise { - return setIsBatchPoster(client, { + args: PrepareSetIsBatchPosterParameters, +): Promise { + return prepareSetIsBatchPoster(client, { ...args, enable: false, }); diff --git a/src/actions/setKeyset.ts b/src/actions/prepareSetKeyset.ts similarity index 79% rename from src/actions/setKeyset.ts rename to src/actions/prepareSetKeyset.ts index cd70c791..c22fd5c6 100644 --- a/src/actions/setKeyset.ts +++ b/src/actions/prepareSetKeyset.ts @@ -10,7 +10,7 @@ import { Prettify } from '../types/utils'; import { validateParentChainPublicClient } from '../types/ParentChain'; import { withUpgradeExecutor } from '../withUpgradeExecutor'; -export type SetKeysetParameters = Prettify< +export type PrepareSetKeysetParameters = Prettify< WithUpgradeExecutor< WithAccount< ActionParameters< @@ -24,12 +24,12 @@ export type SetKeysetParameters = Prettify< > >; -export type SetKeysetReturnType = PrepareTransactionRequestReturnTypeWithChainId; +export type PrepareSetKeysetReturnType = PrepareTransactionRequestReturnTypeWithChainId; -export async function setKeyset( +export async function prepareSetKeyset( client: PublicClient, - params: SetKeysetParameters, -): Promise { + params: PrepareSetKeysetParameters, +): Promise { const validatedPublicClient = validateParentChainPublicClient(client); const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params; diff --git a/src/actions/setMaxTimeVariation.ts b/src/actions/prepareSetMaxTimeVariation.ts similarity index 77% rename from src/actions/setMaxTimeVariation.ts rename to src/actions/prepareSetMaxTimeVariation.ts index 178aecd3..983fd552 100644 --- a/src/actions/setMaxTimeVariation.ts +++ b/src/actions/prepareSetMaxTimeVariation.ts @@ -16,16 +16,16 @@ type Args = { delaySeconds: bigint; futureSeconds: bigint; }; -export type SetMaxTimeVariationParameters = Prettify< +export type PrepareSetMaxTimeVariationParameters = Prettify< WithUpgradeExecutor>> >; -export type SetMaxTimeVariationReturnType = PrepareTransactionRequestReturnTypeWithChainId; +export type PrepareSetMaxTimeVariationReturnType = PrepareTransactionRequestReturnTypeWithChainId; -export async function setMaxTimeVariation( +export async function prepareSetMaxTimeVariation( client: PublicClient, - params: SetMaxTimeVariationParameters, -): Promise { + params: PrepareSetMaxTimeVariationParameters, +): Promise { const validatedPublicClient = validateParentChainPublicClient(client); const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params; From eaa16aabfefece438517dcf76b393d6dd362261e Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 19 Aug 2024 14:32:46 +0000 Subject: [PATCH 07/14] Replace prepare with build --- ...etHash.ts => buildInvalidateKeysetHash.ts} | 12 ++++----- ...atchPoster.ts => buildSetIsbatchPoster.ts} | 26 +++++++++---------- ...{prepareSetKeyset.ts => buildSetKeyset.ts} | 10 +++---- ...riation.ts => buildSetMaxTimeVariation.ts} | 10 +++---- src/actions/index.ts | 8 +++--- 5 files changed, 33 insertions(+), 33 deletions(-) rename src/actions/{prepareInvalidateKeysetHash.ts => buildInvalidateKeysetHash.ts} (66%) rename src/actions/{prepareSetIsbatchPoster.ts => buildSetIsbatchPoster.ts} (63%) rename src/actions/{prepareSetKeyset.ts => buildSetKeyset.ts} (79%) rename src/actions/{prepareSetMaxTimeVariation.ts => buildSetMaxTimeVariation.ts} (77%) diff --git a/src/actions/prepareInvalidateKeysetHash.ts b/src/actions/buildInvalidateKeysetHash.ts similarity index 66% rename from src/actions/prepareInvalidateKeysetHash.ts rename to src/actions/buildInvalidateKeysetHash.ts index f38279eb..c13344ab 100644 --- a/src/actions/prepareInvalidateKeysetHash.ts +++ b/src/actions/buildInvalidateKeysetHash.ts @@ -11,7 +11,7 @@ import { sequencerInboxABI } from '../contracts/SequencerInbox'; import { ActionParameters, WithAccount } from '../types/Actions'; import { Prettify } from '../types/utils'; -export type PrepareInvalidateKeysetHashParameters = Prettify< +export type BuildInvalidateKeysetHashParameters = Prettify< WithAccount< ActionParameters< { @@ -23,9 +23,9 @@ export type PrepareInvalidateKeysetHashParameters >; -export type PrepareInvalidateKeysetHashReturnType = PrepareTransactionRequestReturnType; +export type BuildInvalidateKeysetHashReturnType = PrepareTransactionRequestReturnType; -function sequencerInboxFunctionData({ keysetHash }: PrepareInvalidateKeysetHashParameters) { +function sequencerInboxFunctionData({ keysetHash }: BuildInvalidateKeysetHashParameters) { return encodeFunctionData({ abi: sequencerInboxABI, functionName: 'invalidateKeysetHash', @@ -33,10 +33,10 @@ function sequencerInboxFunctionData({ keysetHash }: PrepareInvalidateKeysetHashP }); } -export async function prepareInvalidateKeysetHash( +export async function buildInvalidateKeysetHash( client: PublicClient, - args: PrepareInvalidateKeysetHashParameters, -): Promise { + args: BuildInvalidateKeysetHashParameters, +): Promise { const data = sequencerInboxFunctionData(args); return client.prepareTransactionRequest({ diff --git a/src/actions/prepareSetIsbatchPoster.ts b/src/actions/buildSetIsbatchPoster.ts similarity index 63% rename from src/actions/prepareSetIsbatchPoster.ts rename to src/actions/buildSetIsbatchPoster.ts index 835b21e0..2566c28f 100644 --- a/src/actions/prepareSetIsbatchPoster.ts +++ b/src/actions/buildSetIsbatchPoster.ts @@ -14,16 +14,16 @@ type Args = { batchPoster: Address; }; -export type PrepareSetIsBatchPosterParameters = Prettify< +export type BuildSetIsBatchPosterParameters = Prettify< WithUpgradeExecutor>> >; -export type PrepareSetIsBatchPosterReturnType = PrepareTransactionRequestReturnTypeWithChainId; +export type BuildSetIsBatchPosterReturnType = PrepareTransactionRequestReturnTypeWithChainId; -async function prepareSetIsBatchPoster( +async function buildSetIsBatchPoster( client: PublicClient, - params: PrepareSetIsBatchPosterParameters & { enable: boolean }, -): Promise { + params: BuildSetIsBatchPosterParameters & { enable: boolean }, +): Promise { const validatedPublicClient = validateParentChainPublicClient(client); const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params; @@ -42,21 +42,21 @@ async function prepareSetIsBatchPoster( return { ...request, chainId: validatedPublicClient.chain.id }; } -export async function prepareEnableBatchPoster( +export async function buildEnableBatchPoster( client: PublicClient, - args: PrepareSetIsBatchPosterParameters, -): Promise { - return prepareSetIsBatchPoster(client, { + args: BuildSetIsBatchPosterParameters, +): Promise { + return buildSetIsBatchPoster(client, { ...args, enable: true, }); } -export async function prepareDisableBatchPoster( +export async function buildDisableBatchPoster( client: PublicClient, - args: PrepareSetIsBatchPosterParameters, -): Promise { - return prepareSetIsBatchPoster(client, { + args: BuildSetIsBatchPosterParameters, +): Promise { + return buildSetIsBatchPoster(client, { ...args, enable: false, }); diff --git a/src/actions/prepareSetKeyset.ts b/src/actions/buildSetKeyset.ts similarity index 79% rename from src/actions/prepareSetKeyset.ts rename to src/actions/buildSetKeyset.ts index c22fd5c6..a2fc1780 100644 --- a/src/actions/prepareSetKeyset.ts +++ b/src/actions/buildSetKeyset.ts @@ -10,7 +10,7 @@ import { Prettify } from '../types/utils'; import { validateParentChainPublicClient } from '../types/ParentChain'; import { withUpgradeExecutor } from '../withUpgradeExecutor'; -export type PrepareSetKeysetParameters = Prettify< +export type BuildSetKeysetParameters = Prettify< WithUpgradeExecutor< WithAccount< ActionParameters< @@ -24,12 +24,12 @@ export type PrepareSetKeysetParameters = Pretti > >; -export type PrepareSetKeysetReturnType = PrepareTransactionRequestReturnTypeWithChainId; +export type BuildSetKeysetReturnType = PrepareTransactionRequestReturnTypeWithChainId; -export async function prepareSetKeyset( +export async function buildSetKeyset( client: PublicClient, - params: PrepareSetKeysetParameters, -): Promise { + params: BuildSetKeysetParameters, +): Promise { const validatedPublicClient = validateParentChainPublicClient(client); const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params; diff --git a/src/actions/prepareSetMaxTimeVariation.ts b/src/actions/buildSetMaxTimeVariation.ts similarity index 77% rename from src/actions/prepareSetMaxTimeVariation.ts rename to src/actions/buildSetMaxTimeVariation.ts index 983fd552..b3068904 100644 --- a/src/actions/prepareSetMaxTimeVariation.ts +++ b/src/actions/buildSetMaxTimeVariation.ts @@ -16,16 +16,16 @@ type Args = { delaySeconds: bigint; futureSeconds: bigint; }; -export type PrepareSetMaxTimeVariationParameters = Prettify< +export type BuildSetMaxTimeVariationParameters = Prettify< WithUpgradeExecutor>> >; -export type PrepareSetMaxTimeVariationReturnType = PrepareTransactionRequestReturnTypeWithChainId; +export type BuildSetMaxTimeVariationReturnType = PrepareTransactionRequestReturnTypeWithChainId; -export async function prepareSetMaxTimeVariation( +export async function buildSetMaxTimeVariation( client: PublicClient, - params: PrepareSetMaxTimeVariationParameters, -): Promise { + params: BuildSetMaxTimeVariationParameters, +): Promise { const validatedPublicClient = validateParentChainPublicClient(client); const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params; diff --git a/src/actions/index.ts b/src/actions/index.ts index 8bbec6cb..04ae5f63 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -1,7 +1,7 @@ export * from './getMaxTimeVariation'; export * from './isBatchPoster'; export * from './isValidKeysetHash'; -export * from './prepareInvalidateKeysetHash'; -export * from './prepareSetIsbatchPoster'; -export * from './prepareSetKeyset'; -export * from './prepareSetMaxTimeVariation'; +export * from './buildInvalidateKeysetHash'; +export * from './buildSetIsbatchPoster'; +export * from './buildSetKeyset'; +export * from './buildSetMaxTimeVariation'; From 745f2c589c60ddcedd39a174bc4ec831ff2de095 Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 19 Aug 2024 14:35:10 +0000 Subject: [PATCH 08/14] Add chainId to returned value in invalidateKeysetHash --- src/actions/buildInvalidateKeysetHash.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/actions/buildInvalidateKeysetHash.ts b/src/actions/buildInvalidateKeysetHash.ts index c13344ab..f8edc82f 100644 --- a/src/actions/buildInvalidateKeysetHash.ts +++ b/src/actions/buildInvalidateKeysetHash.ts @@ -2,14 +2,18 @@ import { Chain, Hex, PrepareTransactionRequestParameters, - PrepareTransactionRequestReturnType, PublicClient, Transport, encodeFunctionData, } from 'viem'; import { sequencerInboxABI } from '../contracts/SequencerInbox'; -import { ActionParameters, WithAccount } from '../types/Actions'; +import { + ActionParameters, + PrepareTransactionRequestReturnTypeWithChainId, + WithAccount, +} from '../types/Actions'; import { Prettify } from '../types/utils'; +import { validateParentChainPublicClient } from '../types/ParentChain'; export type BuildInvalidateKeysetHashParameters = Prettify< WithAccount< @@ -23,7 +27,7 @@ export type BuildInvalidateKeysetHashParameters > >; -export type BuildInvalidateKeysetHashReturnType = PrepareTransactionRequestReturnType; +export type BuildInvalidateKeysetHashReturnType = PrepareTransactionRequestReturnTypeWithChainId; function sequencerInboxFunctionData({ keysetHash }: BuildInvalidateKeysetHashParameters) { return encodeFunctionData({ @@ -37,13 +41,16 @@ export async function buildInvalidateKeysetHash, args: BuildInvalidateKeysetHashParameters, ): Promise { + const validatedPublicClient = validateParentChainPublicClient(client); const data = sequencerInboxFunctionData(args); - return client.prepareTransactionRequest({ + const request = await client.prepareTransactionRequest({ to: args.sequencerInbox, value: BigInt(0), chain: client.chain, data, account: args.account, } satisfies PrepareTransactionRequestParameters); + + return { ...request, chainId: validatedPublicClient.chain.id }; } From 7c6e52cd655402ef22192cc72fc801aa9c16c60d Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 19 Aug 2024 14:39:22 +0000 Subject: [PATCH 09/14] Cleanup buildInvalidateKeysetHash --- src/actions/buildInvalidateKeysetHash.ts | 51 ++++++++++-------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/src/actions/buildInvalidateKeysetHash.ts b/src/actions/buildInvalidateKeysetHash.ts index f8edc82f..9dcc7ddb 100644 --- a/src/actions/buildInvalidateKeysetHash.ts +++ b/src/actions/buildInvalidateKeysetHash.ts @@ -1,55 +1,48 @@ -import { - Chain, - Hex, - PrepareTransactionRequestParameters, - PublicClient, - Transport, - encodeFunctionData, -} from 'viem'; +import { Chain, Hex, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; import { sequencerInboxABI } from '../contracts/SequencerInbox'; import { ActionParameters, PrepareTransactionRequestReturnTypeWithChainId, WithAccount, + WithUpgradeExecutor, } from '../types/Actions'; import { Prettify } from '../types/utils'; import { validateParentChainPublicClient } from '../types/ParentChain'; +import { withUpgradeExecutor } from '../withUpgradeExecutor'; export type BuildInvalidateKeysetHashParameters = Prettify< - WithAccount< - ActionParameters< - { - keysetHash: Hex; - }, - 'sequencerInbox', - Curried + WithUpgradeExecutor< + WithAccount< + ActionParameters< + { + keysetHash: Hex; + }, + 'sequencerInbox', + Curried + > > > >; export type BuildInvalidateKeysetHashReturnType = PrepareTransactionRequestReturnTypeWithChainId; -function sequencerInboxFunctionData({ keysetHash }: BuildInvalidateKeysetHashParameters) { - return encodeFunctionData({ - abi: sequencerInboxABI, - functionName: 'invalidateKeysetHash', - args: [keysetHash], - }); -} - export async function buildInvalidateKeysetHash( client: PublicClient, - args: BuildInvalidateKeysetHashParameters, + params: BuildInvalidateKeysetHashParameters, ): Promise { const validatedPublicClient = validateParentChainPublicClient(client); - const data = sequencerInboxFunctionData(args); + const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params; const request = await client.prepareTransactionRequest({ - to: args.sequencerInbox, - value: BigInt(0), chain: client.chain, - data, - account: args.account, + account, + ...withUpgradeExecutor({ + to: sequencerInboxAddress, + upgradeExecutor, + args: [args.keysetHash], + abi: sequencerInboxABI, + functionName: 'setValidKeyset', + }), } satisfies PrepareTransactionRequestParameters); return { ...request, chainId: validatedPublicClient.chain.id }; From a4292936f7d62956af3e1a85d07f5be33d8fc0e9 Mon Sep 17 00:00:00 2001 From: Christophe Date: Tue, 27 Aug 2024 13:48:53 +0000 Subject: [PATCH 10/14] Review comments --- src/actions/buildInvalidateKeysetHash.ts | 4 +- src/actions/buildSetIsbatchPoster.ts | 4 +- src/actions/buildSetKeyset.ts | 4 +- src/actions/buildSetMaxTimeVariation.ts | 4 +- src/withUpgradeExecutor.ts | 57 ------------------------ 5 files changed, 8 insertions(+), 65 deletions(-) delete mode 100644 src/withUpgradeExecutor.ts diff --git a/src/actions/buildInvalidateKeysetHash.ts b/src/actions/buildInvalidateKeysetHash.ts index 9dcc7ddb..30b55039 100644 --- a/src/actions/buildInvalidateKeysetHash.ts +++ b/src/actions/buildInvalidateKeysetHash.ts @@ -8,7 +8,7 @@ import { } from '../types/Actions'; import { Prettify } from '../types/utils'; import { validateParentChainPublicClient } from '../types/ParentChain'; -import { withUpgradeExecutor } from '../withUpgradeExecutor'; +import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; export type BuildInvalidateKeysetHashParameters = Prettify< WithUpgradeExecutor< @@ -36,7 +36,7 @@ export async function buildInvalidateKeysetHash( const request = await client.prepareTransactionRequest({ chain: client.chain, account, - ...withUpgradeExecutor({ + ...prepareUpgradeExecutorCallParameters({ to: sequencerInboxAddress, upgradeExecutor, args: [args.batchPoster, args.enable], diff --git a/src/actions/buildSetKeyset.ts b/src/actions/buildSetKeyset.ts index a2fc1780..fd46512e 100644 --- a/src/actions/buildSetKeyset.ts +++ b/src/actions/buildSetKeyset.ts @@ -8,7 +8,7 @@ import { } from '../types/Actions'; import { Prettify } from '../types/utils'; import { validateParentChainPublicClient } from '../types/ParentChain'; -import { withUpgradeExecutor } from '../withUpgradeExecutor'; +import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; export type BuildSetKeysetParameters = Prettify< WithUpgradeExecutor< @@ -36,7 +36,7 @@ export async function buildSetKeyset( const request = await client.prepareTransactionRequest({ chain: client.chain, account, - ...withUpgradeExecutor({ + ...prepareUpgradeExecutorCallParameters({ to: sequencerInboxAddress, upgradeExecutor, args: [args.keyset], diff --git a/src/actions/buildSetMaxTimeVariation.ts b/src/actions/buildSetMaxTimeVariation.ts index b3068904..aef110fa 100644 --- a/src/actions/buildSetMaxTimeVariation.ts +++ b/src/actions/buildSetMaxTimeVariation.ts @@ -7,7 +7,7 @@ import { WithUpgradeExecutor, } from '../types/Actions'; import { Prettify } from '../types/utils'; -import { withUpgradeExecutor } from '../withUpgradeExecutor'; +import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; import { validateParentChainPublicClient } from '../types/ParentChain'; type Args = { @@ -32,7 +32,7 @@ export async function buildSetMaxTimeVariation const request = await client.prepareTransactionRequest({ chain: client.chain, account, - ...withUpgradeExecutor({ + ...prepareUpgradeExecutorCallParameters({ to: sequencerInboxAddress, upgradeExecutor, args: [args], diff --git a/src/withUpgradeExecutor.ts b/src/withUpgradeExecutor.ts deleted file mode 100644 index 27a611f4..00000000 --- a/src/withUpgradeExecutor.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { - Address, - encodeFunctionData as viemEncodeFunctionData, - EncodeFunctionDataParameters as ViemEncodeFunctionDataParameters, -} from 'viem'; -import { GetFunctionName } from './types/utils'; -import { sequencerInboxABI } from './contracts/SequencerInbox'; -import { arbOwnerABI } from './contracts/ArbOwner'; -import { upgradeExecutorEncodeFunctionData } from './upgradeExecutorEncodeFunctionData'; - -type ABIs = typeof sequencerInboxABI | typeof arbOwnerABI; -type FunctionName = GetFunctionName; - -type EncodeFunctionDataParameters< - TAbi extends ABIs, - TFunctionName extends FunctionName, -> = ViemEncodeFunctionDataParameters; - -function encodeFunctionData>({ - abi, - functionName, - args, -}: EncodeFunctionDataParameters) { - return viemEncodeFunctionData({ - abi, - functionName, - args, - } as unknown as ViemEncodeFunctionDataParameters); -} - -export function withUpgradeExecutor>( - params: EncodeFunctionDataParameters & { - to: Address; - upgradeExecutor: false | Address; - }, -) { - const { upgradeExecutor } = params; - if (!upgradeExecutor) { - return { - to: params.to, - data: encodeFunctionData(params), - value: BigInt(0), - }; - } - - return { - to: upgradeExecutor, - data: upgradeExecutorEncodeFunctionData({ - functionName: 'executeCall', - args: [ - params.to, // target - encodeFunctionData(params), // targetCallData - ], - }), - value: BigInt(0), - }; -} From f4a37ea5388bb271492d9790f10b75c1803b20be Mon Sep 17 00:00:00 2001 From: Christophe Date: Tue, 27 Aug 2024 13:51:45 +0000 Subject: [PATCH 11/14] Add prepareUpgradeExecutorCallParameters --- src/prepareUpgradeExecutorCallParameters.ts | 76 +++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/prepareUpgradeExecutorCallParameters.ts diff --git a/src/prepareUpgradeExecutorCallParameters.ts b/src/prepareUpgradeExecutorCallParameters.ts new file mode 100644 index 00000000..dcde21c0 --- /dev/null +++ b/src/prepareUpgradeExecutorCallParameters.ts @@ -0,0 +1,76 @@ +import { + Address, + encodeFunctionData as viemEncodeFunctionData, + EncodeFunctionDataParameters as ViemEncodeFunctionDataParameters, +} from 'viem'; +import { GetFunctionName } from './types/utils'; +import { sequencerInboxABI } from './contracts/SequencerInbox'; +import { arbOwnerABI } from './contracts/ArbOwner'; +import { + upgradeExecutorEncodeFunctionData, + UpgradeExecutorFunctionName, +} from './upgradeExecutorEncodeFunctionData'; + +type ABIs = typeof sequencerInboxABI | typeof arbOwnerABI; +type FunctionName = GetFunctionName; + +type EncodeFunctionDataParameters< + TAbi extends ABIs, + TFunctionName extends FunctionName, +> = ViemEncodeFunctionDataParameters; + +function encodeFunctionData>({ + abi, + functionName, + args, +}: EncodeFunctionDataParameters) { + return viemEncodeFunctionData({ + abi, + functionName, + args, + } as unknown as ViemEncodeFunctionDataParameters); +} + +export function prepareUpgradeExecutorCallParameters< + TAbi extends ABIs, + TFunctionName extends FunctionName, +>( + params: EncodeFunctionDataParameters & + ( + | { + to: Address; + upgradeExecutor: false; + value?: bigint; + } + | { + to: Address; + upgradeExecutor: Address; + value?: bigint; + upgradeExecutorFunctionName?: Extract< + UpgradeExecutorFunctionName, + 'execute' | 'executeCall' + >; + } + ), +) { + const { upgradeExecutor, value = BigInt(0) } = params; + if (!upgradeExecutor) { + return { + to: params.to, + data: encodeFunctionData(params), + value, + }; + } + + return { + to: upgradeExecutor, + data: upgradeExecutorEncodeFunctionData({ + functionName: params.upgradeExecutorFunctionName ?? 'executeCall', + args: [ + params.to, // target + encodeFunctionData(params), // targetCallData + ], + }), + value, + }; +} From 0e746977d23efff01bf4dc769a8419f6e6d2ac45 Mon Sep 17 00:00:00 2001 From: Christophe Date: Tue, 27 Aug 2024 14:36:59 +0000 Subject: [PATCH 12/14] Rename buildSetIsbatchPoster to buildSetIsBatchPoster --- .../{buildSetIsbatchPoster.ts => buildSetIsBatchPoster.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/actions/{buildSetIsbatchPoster.ts => buildSetIsBatchPoster.ts} (100%) diff --git a/src/actions/buildSetIsbatchPoster.ts b/src/actions/buildSetIsBatchPoster.ts similarity index 100% rename from src/actions/buildSetIsbatchPoster.ts rename to src/actions/buildSetIsBatchPoster.ts From e6dc732d59388337978eae32ea0c83aef87fd215 Mon Sep 17 00:00:00 2001 From: Christophe Date: Tue, 27 Aug 2024 14:45:57 +0000 Subject: [PATCH 13/14] Correct export --- src/actions/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/index.ts b/src/actions/index.ts index 04ae5f63..95750e82 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -2,6 +2,6 @@ export * from './getMaxTimeVariation'; export * from './isBatchPoster'; export * from './isValidKeysetHash'; export * from './buildInvalidateKeysetHash'; -export * from './buildSetIsbatchPoster'; +export * from './buildSetIsBatchPoster'; export * from './buildSetKeyset'; export * from './buildSetMaxTimeVariation'; From ba1bcb17d04ac01c31812ae8914a31ef85b1af56 Mon Sep 17 00:00:00 2001 From: Christophe Date: Tue, 27 Aug 2024 14:54:37 +0000 Subject: [PATCH 14/14] Rename buildSetKeyset to buildSetValidKeyset --- .../{buildSetKeyset.ts => buildSetValidKeyset.ts} | 10 +++++----- src/actions/index.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) rename src/actions/{buildSetKeyset.ts => buildSetValidKeyset.ts} (79%) diff --git a/src/actions/buildSetKeyset.ts b/src/actions/buildSetValidKeyset.ts similarity index 79% rename from src/actions/buildSetKeyset.ts rename to src/actions/buildSetValidKeyset.ts index fd46512e..c690a41c 100644 --- a/src/actions/buildSetKeyset.ts +++ b/src/actions/buildSetValidKeyset.ts @@ -10,7 +10,7 @@ import { Prettify } from '../types/utils'; import { validateParentChainPublicClient } from '../types/ParentChain'; import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; -export type BuildSetKeysetParameters = Prettify< +export type BuildSetValidKeysetParameters = Prettify< WithUpgradeExecutor< WithAccount< ActionParameters< @@ -24,12 +24,12 @@ export type BuildSetKeysetParameters = Prettify > >; -export type BuildSetKeysetReturnType = PrepareTransactionRequestReturnTypeWithChainId; +export type BuildSetValidKeysetReturnType = PrepareTransactionRequestReturnTypeWithChainId; -export async function buildSetKeyset( +export async function buildSetValidKeyset( client: PublicClient, - params: BuildSetKeysetParameters, -): Promise { + params: BuildSetValidKeysetParameters, +): Promise { const validatedPublicClient = validateParentChainPublicClient(client); const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params; diff --git a/src/actions/index.ts b/src/actions/index.ts index 95750e82..28c51440 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -3,5 +3,5 @@ export * from './isBatchPoster'; export * from './isValidKeysetHash'; export * from './buildInvalidateKeysetHash'; export * from './buildSetIsBatchPoster'; -export * from './buildSetKeyset'; +export * from './buildSetValidKeyset'; export * from './buildSetMaxTimeVariation';