diff --git a/src/actions/buildInvalidateKeysetHash.ts b/src/actions/buildInvalidateKeysetHash.ts index 68b92548..fdc29550 100644 --- a/src/actions/buildInvalidateKeysetHash.ts +++ b/src/actions/buildInvalidateKeysetHash.ts @@ -28,10 +28,14 @@ export type BuildInvalidateKeysetHashReturnType = PrepareTransactionRequestRetur export async function buildInvalidateKeysetHash( client: PublicClient, - params: BuildInvalidateKeysetHashParameters, + { + account, + upgradeExecutor, + sequencerInbox: sequencerInboxAddress, + params, + }: BuildInvalidateKeysetHashParameters, ): Promise { const validatedPublicClient = validateParentChainPublicClient(client); - const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params; const request = await client.prepareTransactionRequest({ chain: client.chain, @@ -39,7 +43,7 @@ export async function buildInvalidateKeysetHash( client: PublicClient, - params: BuildSetIsBatchPosterParameters & { enable: boolean }, + { + account, + upgradeExecutor, + sequencerInbox: sequencerInboxAddress, + params, + }: BuildSetIsBatchPosterParameters & { params: { enable: boolean } }, ): Promise { const validatedPublicClient = validateParentChainPublicClient(client); - const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params; const request = await client.prepareTransactionRequest({ chain: client.chain, @@ -33,7 +37,7 @@ export async function buildSetIsBatchPoster( ...prepareUpgradeExecutorCallParameters({ to: sequencerInboxAddress, upgradeExecutor, - args: [args.batchPoster, args.enable], + args: [params.batchPoster, params.enable], abi: sequencerInboxABI, functionName: 'setIsBatchPoster', }), @@ -48,7 +52,10 @@ export async function buildEnableBatchPoster( ): Promise { return buildSetIsBatchPoster(client, { ...args, - enable: true, + params: { + ...args.params, + enable: true, + }, }); } @@ -58,6 +65,9 @@ export async function buildDisableBatchPoster( ): Promise { return buildSetIsBatchPoster(client, { ...args, - enable: false, + params: { + ...args.params, + enable: false, + }, }); } diff --git a/src/actions/buildSetMaxTimeVariation.ts b/src/actions/buildSetMaxTimeVariation.ts index aef110fa..3fad2176 100644 --- a/src/actions/buildSetMaxTimeVariation.ts +++ b/src/actions/buildSetMaxTimeVariation.ts @@ -24,10 +24,14 @@ export type BuildSetMaxTimeVariationReturnType = PrepareTransactionRequestReturn export async function buildSetMaxTimeVariation( client: PublicClient, - params: BuildSetMaxTimeVariationParameters, + { + account, + upgradeExecutor, + sequencerInbox: sequencerInboxAddress, + params, + }: BuildSetMaxTimeVariationParameters, ): Promise { const validatedPublicClient = validateParentChainPublicClient(client); - const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params; const request = await client.prepareTransactionRequest({ chain: client.chain, @@ -35,7 +39,7 @@ export async function buildSetMaxTimeVariation ...prepareUpgradeExecutorCallParameters({ to: sequencerInboxAddress, upgradeExecutor, - args: [args], + args: [params], abi: sequencerInboxABI, functionName: 'setMaxTimeVariation', }), diff --git a/src/actions/buildSetValidKeyset.ts b/src/actions/buildSetValidKeyset.ts index c690a41c..666b1fda 100644 --- a/src/actions/buildSetValidKeyset.ts +++ b/src/actions/buildSetValidKeyset.ts @@ -28,10 +28,14 @@ export type BuildSetValidKeysetReturnType = PrepareTransactionRequestReturnTypeW export async function buildSetValidKeyset( client: PublicClient, - params: BuildSetValidKeysetParameters, + { + account, + upgradeExecutor, + sequencerInbox: sequencerInboxAddress, + params, + }: BuildSetValidKeysetParameters, ): Promise { const validatedPublicClient = validateParentChainPublicClient(client); - const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params; const request = await client.prepareTransactionRequest({ chain: client.chain, @@ -39,7 +43,7 @@ export async function buildSetValidKeyset( ...prepareUpgradeExecutorCallParameters({ to: sequencerInboxAddress, upgradeExecutor, - args: [args.keyset], + args: [params.keyset], abi: sequencerInboxABI, functionName: 'setValidKeyset', }), diff --git a/src/actions/getMaxTimeVariation.ts b/src/actions/getMaxTimeVariation.ts index b0bfe82c..4924a757 100644 --- a/src/actions/getMaxTimeVariation.ts +++ b/src/actions/getMaxTimeVariation.ts @@ -17,12 +17,12 @@ export type GetMaxTimeVariationReturnType = { export async function getMaxTimeVariation( client: PublicClient, - args: GetMaxTimeVariationParameters, + { sequencerInbox }: GetMaxTimeVariationParameters, ): Promise { const [delayBlocks, futureBlocks, delaySeconds, futureSeconds] = await client.readContract({ abi: sequencerInboxABI, functionName: 'maxTimeVariation', - address: args.sequencerInbox, + address: sequencerInbox, }); return { delayBlocks, diff --git a/src/actions/isBatchPoster.ts b/src/actions/isBatchPoster.ts index f71b773f..39e24894 100644 --- a/src/actions/isBatchPoster.ts +++ b/src/actions/isBatchPoster.ts @@ -18,12 +18,12 @@ export type IsBatchPosterReturnType = ReadContractReturnType< export async function isBatchPoster( client: PublicClient, - args: IsBatchPosterParameters, + { sequencerInbox, params }: IsBatchPosterParameters, ): Promise { return client.readContract({ abi: sequencerInboxABI, functionName: 'isBatchPoster', - address: args.sequencerInbox, - args: [args.batchPoster], + address: sequencerInbox, + args: [params.batchPoster], }); } diff --git a/src/actions/isValidKeysetHash.ts b/src/actions/isValidKeysetHash.ts index 1a5e7007..3ef15828 100644 --- a/src/actions/isValidKeysetHash.ts +++ b/src/actions/isValidKeysetHash.ts @@ -19,12 +19,12 @@ export type IsValidKeysetHashReturnType = ReadContractReturnType< export async function isValidKeysetHash( client: PublicClient, - args: IsValidKeysetHashParameters, + { sequencerInbox, params }: IsValidKeysetHashParameters, ): Promise { return client.readContract({ abi: sequencerInboxABI, functionName: 'isValidKeysetHash', - address: args.sequencerInbox, - args: [args.keysetHash], + address: sequencerInbox, + args: [params.keysetHash], }); } diff --git a/src/actions/sequencerInbox.integration.test.ts b/src/actions/sequencerInbox.integration.test.ts index 1ebd1e3f..56ad1074 100644 --- a/src/actions/sequencerInbox.integration.test.ts +++ b/src/actions/sequencerInbox.integration.test.ts @@ -48,9 +48,8 @@ describe('max time variation management', () => { const transactionRequest = await buildSetMaxTimeVariation(client, { sequencerInbox: l3SequencerInbox, upgradeExecutor: l3UpgradeExecutor, - ...changes, - account: l3RollupOwner.address, + params: changes, }); const txHash = await client.sendRawTransaction({ serializedTransaction: await l3RollupOwner.signTransaction(transactionRequest), @@ -83,12 +82,16 @@ describe('batch poster management', () => { it('isBatchPoster successfully fetches whether or an address is a batch poster', async () => { const isNotBatchPosterAddress = await isBatchPoster(client, { sequencerInbox: l3SequencerInbox, - batchPoster: zeroAddress, + params: { + batchPoster: zeroAddress, + }, }); expect(isNotBatchPosterAddress).toBeFalsy(); const isBatchPosterAddress = await isBatchPoster(client, { sequencerInbox: l3SequencerInbox, - batchPoster: l3BatchPoster, + params: { + batchPoster: l3BatchPoster, + }, }); expect(isBatchPosterAddress).toBeTruthy(); }); @@ -97,15 +100,19 @@ describe('batch poster management', () => { const randomAddress = privateKeyToAccount(generatePrivateKey()).address; const isRandomAddressBatchPoster = await isBatchPoster(client, { sequencerInbox: l3SequencerInbox, - batchPoster: randomAddress, + params: { + batchPoster: randomAddress, + }, }); expect(isRandomAddressBatchPoster).toBeFalsy(); const enableTransactionRequest = await buildEnableBatchPoster(client, { sequencerInbox: l3SequencerInbox, upgradeExecutor: l3UpgradeExecutor, - batchPoster: randomAddress, account: l3RollupOwner.address, + params: { + batchPoster: randomAddress, + }, }); const enableTxHash = await client.sendRawTransaction({ serializedTransaction: await l3RollupOwner.signTransaction(enableTransactionRequest), @@ -113,15 +120,19 @@ describe('batch poster management', () => { await client.waitForTransactionReceipt({ hash: enableTxHash }); const isRandomAddressBatchPosterAfterEnabling = await isBatchPoster(client, { sequencerInbox: l3SequencerInbox, - batchPoster: randomAddress, + params: { + batchPoster: randomAddress, + }, }); expect(isRandomAddressBatchPosterAfterEnabling).toBeTruthy(); const disableTransactionRequest = await buildDisableBatchPoster(client, { sequencerInbox: l3SequencerInbox, upgradeExecutor: l3UpgradeExecutor, - batchPoster: randomAddress, account: l3RollupOwner.address, + params: { + batchPoster: randomAddress, + }, }); const disableTxHash = await client.sendRawTransaction({ serializedTransaction: await l3RollupOwner.signTransaction(disableTransactionRequest), @@ -129,7 +140,9 @@ describe('batch poster management', () => { await client.waitForTransactionReceipt({ hash: disableTxHash }); const isRandomAddressBatchPosterAfterDisabling = await isBatchPoster(client, { sequencerInbox: l3SequencerInbox, - batchPoster: randomAddress, + params: { + batchPoster: randomAddress, + }, }); expect(isRandomAddressBatchPosterAfterDisabling).toBeFalsy(); }); @@ -153,9 +166,11 @@ describe('keyset management', () => { const { sequencerInbox, upgradeExecutor } = createRollupInformation.coreContracts; const transactionRequest = await buildSetValidKeyset(client, { sequencerInbox: sequencerInbox, - keyset, account: l3TokenBridgeDeployer.address, upgradeExecutor, + params: { + keyset, + }, }); const transactionHash = await client.sendRawTransaction({ serializedTransaction: await l3TokenBridgeDeployer.signTransaction(transactionRequest), @@ -179,7 +194,9 @@ describe('keyset management', () => { it('isValidKeysetHash successfully fetches whether a hash is a valid keyset hash', async () => { const invalidKeysetHash = await isValidKeysetHash(client, { sequencerInbox: l3SequencerInbox, - keysetHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + params: { + keysetHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + }, }); expect(invalidKeysetHash).toBeFalsy(); @@ -187,7 +204,9 @@ describe('keyset management', () => { const result = await isValidKeysetHash(client, { sequencerInbox, - keysetHash: keysetHash!, + params: { + keysetHash: keysetHash!, + }, }); expect(result).toBeTruthy(); }); @@ -199,15 +218,19 @@ describe('keyset management', () => { const result = await isValidKeysetHash(client, { sequencerInbox, - keysetHash: keysetHash!, + params: { + keysetHash: keysetHash!, + }, }); expect(result).toBeTruthy(); const transactionRequest = await buildInvalidateKeysetHash(client, { - keysetHash: keysetHash!, sequencerInbox, account: l3TokenBridgeDeployer.address, upgradeExecutor, + params: { + keysetHash: keysetHash!, + }, }); const txHash = await client.sendRawTransaction({ serializedTransaction: await l3TokenBridgeDeployer.signTransaction(transactionRequest), @@ -216,7 +239,9 @@ describe('keyset management', () => { const resultAfterChange = await isValidKeysetHash(client, { sequencerInbox, - keysetHash: keysetHash!, + params: { + keysetHash: keysetHash!, + }, }); expect(resultAfterChange).toBeFalsy(); }); diff --git a/src/types/Actions.ts b/src/types/Actions.ts index ba515953..71093865 100644 --- a/src/types/Actions.ts +++ b/src/types/Actions.ts @@ -1,6 +1,8 @@ import { Address, PrepareTransactionRequestReturnType } from 'viem'; import { Prettify } from './utils'; +type isEmptyObject = Args extends Record ? true : false; + /** * Actions require contract address, but as part of decorators, the address might have been passed already to the decorator. * @@ -9,16 +11,12 @@ import { Prettify } from './utils'; */ export type ActionParameters = Prettify< Curried extends false - ? Args & { [key in ContractName]: Address } - : Args extends Record - ? - | { - [key in ContractName]: Address; - } - | void - : Args & { - [key in ContractName]?: Address; - } + ? isEmptyObject extends true + ? { [key in ContractName]: Address } // Contract wasn't curried. Args is an empty object. Only requires the contract name + : { params: Args } & { [key in ContractName]: Address } // Contract wasn't curried. Args is not empty. Requires both params and contract name + : isEmptyObject extends true + ? { [key in ContractName]: Address } | void // Contract was curried. Args is empty. Only requires the contract name. Allows no parameters + : { params: Args } & { [key in ContractName]?: Address } // Contract was curried. Args is not empty. Requires params, contract name is optional >; export type WithAccount = Args & {