From 27c24d61cdc7e62a81af29bd04f39d5a3549ecb3 Mon Sep 17 00:00:00 2001 From: spsjvc Date: Thu, 30 May 2024 16:10:11 +0200 Subject: [PATCH] fix: use generics for rollup deployment config (#106) --- src/createRollupPrepareDeploymentParamsConfig.ts | 9 ++++++--- src/types/ParentChain.ts | 12 ++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/createRollupPrepareDeploymentParamsConfig.ts b/src/createRollupPrepareDeploymentParamsConfig.ts index e8556ae6..8f7cbd52 100644 --- a/src/createRollupPrepareDeploymentParamsConfig.ts +++ b/src/createRollupPrepareDeploymentParamsConfig.ts @@ -1,4 +1,4 @@ -import { PublicClient } from 'viem'; +import { Chain, Client, Transport } from 'viem'; import { ChainConfig } from './types/ChainConfig'; import { validateParentChain } from './types/ParentChain'; @@ -63,8 +63,11 @@ export type CreateRollupPrepareDeploymentParamsConfigParams = Prettify< * }), * }); */ -export function createRollupPrepareDeploymentParamsConfig( - client: PublicClient, +export function createRollupPrepareDeploymentParamsConfig< + TTransport extends Transport = Transport, + TChain extends Chain | undefined = Chain | undefined, +>( + client: Client, { chainConfig, ...params }: CreateRollupPrepareDeploymentParamsConfigParams, ): CreateRollupPrepareDeploymentParamsConfigResult { const parentChainId = validateParentChain(client); diff --git a/src/types/ParentChain.ts b/src/types/ParentChain.ts index 7165a6f8..deebae74 100644 --- a/src/types/ParentChain.ts +++ b/src/types/ParentChain.ts @@ -1,4 +1,4 @@ -import { Chain, PublicClient, Transport } from 'viem'; +import { Chain, Client, PublicClient, Transport } from 'viem'; import { chains, nitroTestnodeL3 } from '../chains'; import { Prettify } from './utils'; @@ -21,11 +21,11 @@ function isValidParentChainId(parentChainId: number | undefined): parentChainId return ids.includes(Number(parentChainId)); } -export function validateParentChain(chainIdOrPublicClient: number | PublicClient): ParentChainId { - const chainId = - typeof chainIdOrPublicClient === 'number' - ? chainIdOrPublicClient - : chainIdOrPublicClient.chain?.id; +export function validateParentChain< + TTransport extends Transport = Transport, + TChain extends Chain | undefined = Chain | undefined, +>(chainIdOrClient: number | Client): ParentChainId { + const chainId = typeof chainIdOrClient === 'number' ? chainIdOrClient : chainIdOrClient.chain?.id; if (!isValidParentChainId(chainId)) { throw new Error(`Parent chain not supported: ${chainId}`);