Skip to content

Commit

Permalink
Merge pull request #5772 from NomicFoundation/move-chaintype-type
Browse files Browse the repository at this point in the history
Move Chaintype type
  • Loading branch information
schaable authored Sep 28, 2024
2 parents ce77ee9 + 7c3054d commit 2697d7a
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 48 deletions.
6 changes: 4 additions & 2 deletions v-next/example-project/viem-scketch-plugin.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
1 change: 0 additions & 1 deletion v-next/hardhat-network-helpers/src/type-extensions.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ChainTypeT extends ChainType | string> = (
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
36 changes: 35 additions & 1 deletion v-next/hardhat/src/types/network.ts
Original file line number Diff line number Diff line change
@@ -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<ChainTypeT extends ChainType = DefaultChainType>(
networkName?: string,
Expand Down

0 comments on commit 2697d7a

Please sign in to comment.