Skip to content

Commit 2697d7a

Browse files
authoredSep 28, 2024··
Merge pull request #5772 from NomicFoundation/move-chaintype-type
Move Chaintype type
2 parents ce77ee9 + 7c3054d commit 2697d7a

File tree

8 files changed

+55
-48
lines changed

8 files changed

+55
-48
lines changed
 

‎v-next/example-project/viem-scketch-plugin.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { HardhatPlugin } from "@ignored/hardhat-vnext/types/plugins";
2-
import { ChainType } from "@ignored/hardhat-vnext/types/config";
32
import { HookContext } from "@ignored/hardhat-vnext/types/hooks";
43

5-
import type { NetworkConnection } from "@ignored/hardhat-vnext/types/network";
4+
import type {
5+
ChainType,
6+
NetworkConnection,
7+
} from "@ignored/hardhat-vnext/types/network";
68

79
import "@ignored/hardhat-vnext/types/network";
810

‎v-next/hardhat-network-helpers/src/internal/hook-handlers/network.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import type { ChainType } from "@ignored/hardhat-vnext/types/config";
21
import type {
32
HookContext,
43
NetworkHooks,
54
} from "@ignored/hardhat-vnext/types/hooks";
6-
import type { NetworkConnection } from "@ignored/hardhat-vnext/types/network";
5+
import type {
6+
ChainType,
7+
NetworkConnection,
8+
} from "@ignored/hardhat-vnext/types/network";
79

810
import { NetworkHelpers } from "../network-helpers/network-helpers.js";
911

‎v-next/hardhat-network-helpers/src/type-extensions.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import "@ignored/hardhat-vnext/types/network";
22

33
import type { NetworkHelpers } from "./internal/network-helpers/network-helpers.js";
4-
import type { ChainType } from "@ignored/hardhat-vnext/types/config";
54

65
declare module "@ignored/hardhat-vnext/types/network" {
76
// 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

‎v-next/hardhat/src/internal/builtin-plugins/network-manager/network-connection.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { ChainType, NetworkConfig } from "../../../types/config.js";
2-
import type { NetworkConnection } from "../../../types/network.js";
1+
import type { NetworkConfig } from "../../../types/config.js";
2+
import type { ChainType, NetworkConnection } from "../../../types/network.js";
33
import type { EthereumProvider } from "../../../types/providers.js";
44

55
export type CloseConnectionFunction<ChainTypeT extends ChainType | string> = (

‎v-next/hardhat/src/internal/builtin-plugins/network-manager/network-manager.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import type { NetworkConfig } from "../../../types/config.js";
2+
import type { HookManager } from "../../../types/hooks.js";
13
import type {
24
ChainType,
35
DefaultChainType,
4-
NetworkConfig,
5-
} from "../../../types/config.js";
6-
import type { HookManager } from "../../../types/hooks.js";
7-
import type { NetworkConnection } from "../../../types/network.js";
6+
NetworkConnection,
7+
} from "../../../types/network.js";
88
import type { EthereumProvider } from "../../../types/providers.js";
99

1010
import { HardhatError } from "@ignored/hardhat-vnext-errors";

‎v-next/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/config.ts

+2-34
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,7 @@
1+
import type { ChainType, DefaultChainType } from "../../../../types/network.js";
2+
13
import "../../../../types/config.js";
24
declare module "../../../../types/config.js" {
3-
/**
4-
* Represents the possible chain types for the network. The options are:
5-
* - `"unknown"`: Represents the most generic type of network.
6-
* - `"l1"`: Represents Layer 1 networks like Ethereum.
7-
* - `"optimism"`: Represents Layer 2 networks like Optimism.
8-
*/
9-
export type ChainType = "unknown" | "l1" | "optimism";
10-
11-
/**
12-
* Determines the default chain type to use when no chain type is specified.
13-
* The default chain type is `"unknown"` by default. You can customize the
14-
* default chain type by adding a `defaultChainType` property to the
15-
* `ChainTypeConfig` interface with a valid `ChainType` value.
16-
* For example:
17-
* ```ts
18-
* declare module "@ignored/hardhat-vnext/types/config" {
19-
* export interface ChainTypeConfig {
20-
* defaultChainType: "l1";
21-
* }
22-
* }
23-
* ```
24-
*/
25-
export type DefaultChainType = ChainTypeConfig extends {
26-
defaultChainType: infer T;
27-
}
28-
? T extends ChainType
29-
? T
30-
: "unknown"
31-
: "unknown";
32-
33-
/* eslint-disable-next-line @typescript-eslint/no-empty-interface -- Empty
34-
interface to allow the user to change the default chain type. */
35-
export interface ChainTypeConfig {}
36-
375
export interface HardhatUserConfig {
386
defaultChainType?: DefaultChainType;
397
defaultNetwork?: string;

‎v-next/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/hooks.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import type { ChainType } from "../../../../types/config.js";
2-
import type { NetworkConnection } from "../../../../types/network.js";
1+
import type {
2+
ChainType,
3+
NetworkConnection,
4+
} from "../../../../types/network.js";
35
import type {
46
JsonRpcRequest,
57
JsonRpcResponse,

‎v-next/hardhat/src/types/network.ts

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
1-
import type { ChainType, DefaultChainType, NetworkConfig } from "./config.js";
1+
import type { NetworkConfig } from "./config.js";
22
import type { EthereumProvider } from "./providers.js";
33

4+
/**
5+
* Represents the possible chain types for the network. The options are:
6+
* - `"unknown"`: Represents the most generic type of network.
7+
* - `"l1"`: Represents Layer 1 networks like Ethereum.
8+
* - `"optimism"`: Represents Layer 2 networks like Optimism.
9+
*/
10+
export type ChainType = "unknown" | "l1" | "optimism";
11+
12+
/**
13+
* Determines the default chain type to use when no chain type is specified.
14+
* The default chain type is `"unknown"` by default. You can customize the
15+
* default chain type by adding a `defaultChainType` property to the
16+
* `ChainTypeConfig` interface with a valid `ChainType` value.
17+
* For example:
18+
* ```ts
19+
* declare module "@ignored/hardhat-vnext/types/config" {
20+
* export interface ChainTypeConfig {
21+
* defaultChainType: "l1";
22+
* }
23+
* }
24+
* ```
25+
*/
26+
export type DefaultChainType = ChainTypeConfig extends {
27+
defaultChainType: infer T;
28+
}
29+
? T extends ChainType
30+
? T
31+
: "unknown"
32+
: "unknown";
33+
34+
/* eslint-disable-next-line @typescript-eslint/no-empty-interface -- Empty
35+
interface to allow the user to change the default chain type. */
36+
export interface ChainTypeConfig {}
37+
438
export interface NetworkManager {
539
connect<ChainTypeT extends ChainType = DefaultChainType>(
640
networkName?: string,

0 commit comments

Comments
 (0)
Please sign in to comment.