UNPKG

6.65 kBTypeScriptView Raw
1import { Artifacts } from "./artifacts";
2import { HardhatConfig, HardhatUserConfig, NetworkConfig } from "./config";
3import { EIP1193Provider, EthereumProvider } from "./provider";
4/**
5 * This class is used to dynamically validate task's argument types.
6 */
7export interface ArgumentType<T> {
8 /**
9 * The type's name.
10 */
11 name: string;
12 /**
13 * Check if argument value is of type <T>.
14 *
15 * @param argName {string} argument's name - used for context in case of error.
16 * @param argumentValue - value to be validated
17 *
18 * @throws HH301 if value is not of type <t>
19 */
20 validate(argName: string, argumentValue: any): void;
21}
22/**
23 * This is a special case of ArgumentType.
24 *
25 * These types must have a human-friendly string representation, so that they
26 * can be used as command line arguments.
27 */
28export interface CLIArgumentType<T> extends ArgumentType<T> {
29 /**
30 * Parses strValue into T. This function MUST throw HH301 if it
31 * can parse the given value.
32 *
33 * @param argName argument's name - used for context in case of error.
34 * @param strValue argument's string value to be parsed.
35 */
36 parse(argName: string, strValue: string): T;
37}
38export interface ConfigurableTaskDefinition {
39 setDescription(description: string): this;
40 setAction(action: ActionType<TaskArguments>): this;
41 addParam<T>(name: string, description?: string, defaultValue?: T, type?: ArgumentType<T>, isOptional?: boolean): this;
42 addOptionalParam<T>(name: string, description?: string, defaultValue?: T, type?: ArgumentType<T>): this;
43 addPositionalParam<T>(name: string, description?: string, defaultValue?: T, type?: ArgumentType<T>, isOptional?: boolean): this;
44 addOptionalPositionalParam<T>(name: string, description?: string, defaultValue?: T, type?: ArgumentType<T>): this;
45 addVariadicPositionalParam<T>(name: string, description?: string, defaultValue?: T[], type?: ArgumentType<T>, isOptional?: boolean): this;
46 addOptionalVariadicPositionalParam<T>(name: string, description?: string, defaultValue?: T[], type?: ArgumentType<T>): this;
47 addFlag(name: string, description?: string): this;
48}
49declare function addTask<TaskArgumentsT extends TaskArguments>(name: string, description?: string, action?: ActionType<TaskArgumentsT>): ConfigurableTaskDefinition;
50declare function addTask<TaskArgumentsT extends TaskArguments>(name: string, action: ActionType<TaskArgumentsT>): ConfigurableTaskDefinition;
51type AddConfigurableTaskFunction = typeof addTask;
52export interface ConfigurableScopeDefinition {
53 setDescription(description: string): this;
54 task: AddConfigurableTaskFunction;
55 subtask: AddConfigurableTaskFunction;
56}
57export interface ParamDefinition<T> {
58 name: string;
59 defaultValue?: T;
60 type: ArgumentType<T>;
61 description?: string;
62 isOptional: boolean;
63 isFlag: boolean;
64 isVariadic: boolean;
65}
66export interface OptionalParamDefinition<T> extends ParamDefinition<T> {
67 defaultValue: T;
68 isOptional: true;
69}
70export interface CLIOptionalParamDefinition<T> extends OptionalParamDefinition<T> {
71 type: CLIArgumentType<T>;
72}
73export interface ParamDefinitionsMap {
74 [paramName: string]: ParamDefinition<any>;
75}
76export interface TaskDefinition extends ConfigurableTaskDefinition {
77 readonly scope?: string;
78 readonly name: string;
79 readonly description?: string;
80 readonly action: ActionType<TaskArguments>;
81 readonly isSubtask: boolean;
82 readonly paramDefinitions: ParamDefinitionsMap;
83 readonly positionalParamDefinitions: Array<ParamDefinition<any>>;
84}
85export interface ScopeDefinition extends ConfigurableScopeDefinition {
86 readonly name: string;
87 readonly description?: string;
88 readonly tasks: TasksMap;
89}
90export type TaskIdentifier = string | {
91 scope?: string;
92 task: string;
93};
94/**
95 * @type TaskArguments {object-like} - the input arguments for a task.
96 *
97 * TaskArguments type is set to 'any' because it's interface is dynamic.
98 * It's impossible in TypeScript to statically specify a variadic
99 * number of fields and at the same time define specific types for\
100 * the argument values.
101 *
102 * For example, we could define:
103 * type TaskArguments = Record<string, any>;
104 *
105 * ...but then, we couldn't narrow the actual argument value's type in compile time,
106 * thus we have no other option than forcing it to be just 'any'.
107 */
108export type TaskArguments = any;
109export interface SubtaskArguments {
110 [subtaskName: string]: TaskArguments;
111}
112export interface RunSuperFunction<TaskArgumentsT extends TaskArguments> {
113 (taskArguments?: TaskArgumentsT, subtaskArguments?: SubtaskArguments): Promise<any>;
114 isDefined: boolean;
115}
116export type ActionType<TaskArgumentsT extends TaskArguments> = (taskArgs: TaskArgumentsT, env: HardhatRuntimeEnvironment, runSuper: RunSuperFunction<TaskArgumentsT>) => Promise<any>;
117export interface HardhatArguments {
118 network?: string;
119 showStackTraces: boolean;
120 version: boolean;
121 help: boolean;
122 emoji: boolean;
123 config?: string;
124 verbose: boolean;
125 maxMemory?: number;
126 tsconfig?: string;
127 flamegraph?: boolean;
128 typecheck?: boolean;
129}
130export type HardhatParamDefinitions = {
131 [param in keyof Required<HardhatArguments>]: CLIOptionalParamDefinition<HardhatArguments[param]>;
132};
133export interface TasksMap {
134 [name: string]: TaskDefinition;
135}
136export interface ScopesMap {
137 [scopeName: string]: ScopeDefinition;
138}
139export type RunTaskFunction = (taskIdentifier: TaskIdentifier, taskArguments?: TaskArguments, subtaskArguments?: SubtaskArguments) => Promise<any>;
140export interface HardhatRuntimeEnvironment {
141 readonly config: HardhatConfig;
142 readonly userConfig: HardhatUserConfig;
143 readonly hardhatArguments: HardhatArguments;
144 readonly tasks: TasksMap;
145 readonly scopes: ScopesMap;
146 readonly run: RunTaskFunction;
147 readonly network: Network;
148 readonly artifacts: Artifacts;
149 readonly version: string;
150}
151export interface Network {
152 name: string;
153 config: NetworkConfig;
154 provider: EthereumProvider;
155}
156/**
157 * A function that receives a HardhatRuntimeEnvironment and
158 * modify its properties or add new ones.
159 */
160export type EnvironmentExtender = (env: HardhatRuntimeEnvironment) => void;
161/**
162 * A function that receives a provider, crafts and returns a new one.
163 * Adding and modifying the current provider is preferred over ignoring it and returning a new instance.
164 */
165export type ProviderExtender = (provider: EIP1193Provider, config: HardhatConfig, network: string) => EIP1193Provider | Promise<EIP1193Provider>;
166export {};
167//# sourceMappingURL=runtime.d.ts.map
\No newline at end of file