From a8583096c37629660fac73648275a0d03c11c7ca Mon Sep 17 00:00:00 2001 From: Luis Schaab Date: Mon, 23 Sep 2024 10:55:38 -0300 Subject: [PATCH] Move ChainType types to Network --- v-next/example-project/viem-scketch-plugin.ts | 6 ++-- .../src/internal/hook-handlers/network.ts | 6 ++-- .../src/type-extensions.ts | 1 - .../network-manager/network-connection.ts | 4 +-- .../network-manager/network-manager.ts | 8 ++--- .../network-manager/type-extensions/config.ts | 36 ++----------------- .../network-manager/type-extensions/hooks.ts | 6 ++-- v-next/hardhat/src/types/network.ts | 36 ++++++++++++++++++- 8 files changed, 55 insertions(+), 48 deletions(-) diff --git a/v-next/example-project/viem-scketch-plugin.ts b/v-next/example-project/viem-scketch-plugin.ts index 09977bfd57..74fe15b0a9 100644 --- a/v-next/example-project/viem-scketch-plugin.ts +++ b/v-next/example-project/viem-scketch-plugin.ts @@ -1,8 +1,10 @@ import { HardhatPlugin } from "@ignored/hardhat-vnext/types/plugins"; -import { ChainType } from "@ignored/hardhat-vnext/types/config"; import { HookContext } from "@ignored/hardhat-vnext/types/hooks"; -import type { NetworkConnection } from "@ignored/hardhat-vnext/types/network"; +import type { + ChainType, + NetworkConnection, +} from "@ignored/hardhat-vnext/types/network"; import "@ignored/hardhat-vnext/types/network"; diff --git a/v-next/hardhat-network-helpers/src/internal/hook-handlers/network.ts b/v-next/hardhat-network-helpers/src/internal/hook-handlers/network.ts index 556a8928c7..24c074d717 100644 --- a/v-next/hardhat-network-helpers/src/internal/hook-handlers/network.ts +++ b/v-next/hardhat-network-helpers/src/internal/hook-handlers/network.ts @@ -1,9 +1,11 @@ -import type { ChainType } from "@ignored/hardhat-vnext/types/config"; import type { HookContext, NetworkHooks, } from "@ignored/hardhat-vnext/types/hooks"; -import type { NetworkConnection } from "@ignored/hardhat-vnext/types/network"; +import type { + ChainType, + NetworkConnection, +} from "@ignored/hardhat-vnext/types/network"; import { NetworkHelpers } from "../network-helpers/network-helpers.js"; diff --git a/v-next/hardhat-network-helpers/src/type-extensions.ts b/v-next/hardhat-network-helpers/src/type-extensions.ts index 3e7610cf9f..29de902480 100644 --- a/v-next/hardhat-network-helpers/src/type-extensions.ts +++ b/v-next/hardhat-network-helpers/src/type-extensions.ts @@ -1,7 +1,6 @@ import "@ignored/hardhat-vnext/types/network"; import type { NetworkHelpers } from "./internal/network-helpers/network-helpers.js"; -import type { ChainType } from "@ignored/hardhat-vnext/types/config"; declare module "@ignored/hardhat-vnext/types/network" { // eslint-disable-next-line @typescript-eslint/no-unused-vars -- the ChainTypeT must be declared in the interface but in this scenario it's not used diff --git a/v-next/hardhat/src/internal/builtin-plugins/network-manager/network-connection.ts b/v-next/hardhat/src/internal/builtin-plugins/network-manager/network-connection.ts index 0ad12d34f3..2bd92a87f5 100644 --- a/v-next/hardhat/src/internal/builtin-plugins/network-manager/network-connection.ts +++ b/v-next/hardhat/src/internal/builtin-plugins/network-manager/network-connection.ts @@ -1,5 +1,5 @@ -import type { ChainType, NetworkConfig } from "../../../types/config.js"; -import type { NetworkConnection } from "../../../types/network.js"; +import type { NetworkConfig } from "../../../types/config.js"; +import type { ChainType, NetworkConnection } from "../../../types/network.js"; import type { EthereumProvider } from "../../../types/providers.js"; export type CloseConnectionFunction = ( diff --git a/v-next/hardhat/src/internal/builtin-plugins/network-manager/network-manager.ts b/v-next/hardhat/src/internal/builtin-plugins/network-manager/network-manager.ts index be0ad8facb..c4c29b675b 100644 --- a/v-next/hardhat/src/internal/builtin-plugins/network-manager/network-manager.ts +++ b/v-next/hardhat/src/internal/builtin-plugins/network-manager/network-manager.ts @@ -1,10 +1,10 @@ +import type { NetworkConfig } from "../../../types/config.js"; +import type { HookManager } from "../../../types/hooks.js"; import type { ChainType, DefaultChainType, - NetworkConfig, -} from "../../../types/config.js"; -import type { HookManager } from "../../../types/hooks.js"; -import type { NetworkConnection } from "../../../types/network.js"; + NetworkConnection, +} from "../../../types/network.js"; import type { EthereumProvider } from "../../../types/providers.js"; import { HardhatError } from "@ignored/hardhat-vnext-errors"; diff --git a/v-next/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/config.ts b/v-next/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/config.ts index 7998eb9878..629043d33e 100644 --- a/v-next/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/config.ts +++ b/v-next/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/config.ts @@ -1,39 +1,7 @@ +import type { ChainType, DefaultChainType } from "../../../../types/network.js"; + import "../../../../types/config.js"; declare module "../../../../types/config.js" { - /** - * Represents the possible chain types for the network. The options are: - * - `"unknown"`: Represents the most generic type of network. - * - `"l1"`: Represents Layer 1 networks like Ethereum. - * - `"optimism"`: Represents Layer 2 networks like Optimism. - */ - export type ChainType = "unknown" | "l1" | "optimism"; - - /** - * Determines the default chain type to use when no chain type is specified. - * The default chain type is `"unknown"` by default. You can customize the - * default chain type by adding a `defaultChainType` property to the - * `ChainTypeConfig` interface with a valid `ChainType` value. - * For example: - * ```ts - * declare module "@ignored/hardhat-vnext/types/config" { - * export interface ChainTypeConfig { - * defaultChainType: "l1"; - * } - * } - * ``` - */ - export type DefaultChainType = ChainTypeConfig extends { - defaultChainType: infer T; - } - ? T extends ChainType - ? T - : "unknown" - : "unknown"; - - /* eslint-disable-next-line @typescript-eslint/no-empty-interface -- Empty - interface to allow the user to change the default chain type. */ - export interface ChainTypeConfig {} - export interface HardhatUserConfig { defaultChainType?: DefaultChainType; defaultNetwork?: string; diff --git a/v-next/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/hooks.ts b/v-next/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/hooks.ts index 7224ddf366..1821b79cf6 100644 --- a/v-next/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/hooks.ts +++ b/v-next/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/hooks.ts @@ -1,5 +1,7 @@ -import type { ChainType } from "../../../../types/config.js"; -import type { NetworkConnection } from "../../../../types/network.js"; +import type { + ChainType, + NetworkConnection, +} from "../../../../types/network.js"; import type { JsonRpcRequest, JsonRpcResponse, diff --git a/v-next/hardhat/src/types/network.ts b/v-next/hardhat/src/types/network.ts index e86a104b54..548ea5255b 100644 --- a/v-next/hardhat/src/types/network.ts +++ b/v-next/hardhat/src/types/network.ts @@ -1,6 +1,40 @@ -import type { ChainType, DefaultChainType, NetworkConfig } from "./config.js"; +import type { NetworkConfig } from "./config.js"; import type { EthereumProvider } from "./providers.js"; +/** + * Represents the possible chain types for the network. The options are: + * - `"unknown"`: Represents the most generic type of network. + * - `"l1"`: Represents Layer 1 networks like Ethereum. + * - `"optimism"`: Represents Layer 2 networks like Optimism. + */ +export type ChainType = "unknown" | "l1" | "optimism"; + +/** + * Determines the default chain type to use when no chain type is specified. + * The default chain type is `"unknown"` by default. You can customize the + * default chain type by adding a `defaultChainType` property to the + * `ChainTypeConfig` interface with a valid `ChainType` value. + * For example: + * ```ts + * declare module "@ignored/hardhat-vnext/types/config" { + * export interface ChainTypeConfig { + * defaultChainType: "l1"; + * } + * } + * ``` + */ +export type DefaultChainType = ChainTypeConfig extends { + defaultChainType: infer T; +} + ? T extends ChainType + ? T + : "unknown" + : "unknown"; + +/* eslint-disable-next-line @typescript-eslint/no-empty-interface -- Empty +interface to allow the user to change the default chain type. */ +export interface ChainTypeConfig {} + export interface NetworkManager { connect( networkName?: string,