Skip to content

Commit

Permalink
fix: use generics for rollup deployment config (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc authored May 30, 2024
1 parent 8b4bc71 commit 27c24d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/createRollupPrepareDeploymentParamsConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PublicClient } from 'viem';
import { Chain, Client, Transport } from 'viem';

import { ChainConfig } from './types/ChainConfig';
import { validateParentChain } from './types/ParentChain';
Expand Down Expand Up @@ -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<TTransport, TChain>,
{ chainConfig, ...params }: CreateRollupPrepareDeploymentParamsConfigParams,
): CreateRollupPrepareDeploymentParamsConfigResult {
const parentChainId = validateParentChain(client);
Expand Down
12 changes: 6 additions & 6 deletions src/types/ParentChain.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<TTransport, TChain>): ParentChainId {
const chainId = typeof chainIdOrClient === 'number' ? chainIdOrClient : chainIdOrClient.chain?.id;

if (!isValidParentChainId(chainId)) {
throw new Error(`Parent chain not supported: ${chainId}`);
Expand Down

0 comments on commit 27c24d6

Please sign in to comment.