diff --git a/src/actions/getConfirmPeriodBlocks.ts b/src/actions/getConfirmPeriodBlocks.ts index 7beead55..120db86a 100644 --- a/src/actions/getConfirmPeriodBlocks.ts +++ b/src/actions/getConfirmPeriodBlocks.ts @@ -1,9 +1,9 @@ import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem'; import { rollupAdminLogic } from '../contracts'; -import { ActionParameters } from '../types/Actions'; +import { WithContractAddress } from '../types/Actions'; import { getRollupAddress } from '../getRollupAddress'; -export type GetConfirmPeriodBlocksParameters = ActionParameters< +export type GetConfirmPeriodBlocksParameters = WithContractAddress< {}, 'rollupAdminLogic', Curried diff --git a/src/actions/getExtraChallengeTimeBlocks.ts b/src/actions/getExtraChallengeTimeBlocks.ts index 9db0be24..0bce1c4f 100644 --- a/src/actions/getExtraChallengeTimeBlocks.ts +++ b/src/actions/getExtraChallengeTimeBlocks.ts @@ -1,10 +1,10 @@ import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem'; import { rollupAdminLogic } from '../contracts'; -import { ActionParameters } from '../types/Actions'; +import { WithContractAddress } from '../types/Actions'; import { getRollupAddress } from '../getRollupAddress'; export type GetExtraChallengeTimeBlocksParameters = - ActionParameters<{}, 'rollupAdminLogic', Curried>; + WithContractAddress<{}, 'rollupAdminLogic', Curried>; export type GetExtraChallengeTimeBlocksReturnType = ReadContractReturnType< typeof rollupAdminLogic.abi, diff --git a/src/actions/getMinimumAssertionPeriod.ts b/src/actions/getMinimumAssertionPeriod.ts index d96f9882..0ff81960 100644 --- a/src/actions/getMinimumAssertionPeriod.ts +++ b/src/actions/getMinimumAssertionPeriod.ts @@ -1,13 +1,10 @@ import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem'; import { rollupAdminLogic } from '../contracts'; -import { ActionParameters } from '../types/Actions'; +import { WithContractAddress } from '../types/Actions'; import { getRollupAddress } from '../getRollupAddress'; -export type GetMinimumAssertionPeriodParameters = ActionParameters< - {}, - 'rollupAdminLogic', - Curried ->; +export type GetMinimumAssertionPeriodParameters = + WithContractAddress<{}, 'rollupAdminLogic', Curried>; export type GetMinimumAssertionPeriodReturnType = ReadContractReturnType< typeof rollupAdminLogic.abi, diff --git a/src/actions/getWasmModuleRoot.ts b/src/actions/getWasmModuleRoot.ts index af6331b0..8798b32d 100644 --- a/src/actions/getWasmModuleRoot.ts +++ b/src/actions/getWasmModuleRoot.ts @@ -1,9 +1,9 @@ import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem'; import { rollupAdminLogic } from '../contracts'; -import { ActionParameters } from '../types/Actions'; +import { WithContractAddress } from '../types/Actions'; import { getRollupAddress } from '../getRollupAddress'; -export type GetWasmModuleRootParameters = ActionParameters< +export type GetWasmModuleRootParameters = WithContractAddress< {}, 'rollupAdminLogic', Curried diff --git a/src/types/Actions.ts b/src/types/Actions.ts index 0327ffba..057bdb58 100644 --- a/src/types/Actions.ts +++ b/src/types/Actions.ts @@ -20,3 +20,35 @@ export type ActionParameters; + +/** + * Some actions require a different contract than sequencerInbox. + * We either accept sequencerInbox to fetch the contract address + * or an override + */ +export type WithContractAddress< + Args, + ContractName extends string, + Curried extends boolean, +> = Curried extends true + ? /** + * If sequencerInbox was passed to the decorator. We accept the contract address, + * an sequencerInbox override, or no parameters + */ + | (Args & { + sequencerInbox?: Address; + }) + | (Args & { + [key in ContractName]?: Address; + }) + | void + : /** + * If sequencerInbox wasn't passed to the decorator. We need one of the address to be passed + * We either accept the contract address or an sequencerInbox override + */ + | (Args & { + sequencerInbox: Address; + }) + | (Args & { + [key in ContractName]: Address; + });