hardhat 2.17.4 → 2.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/README.md +1 -1
  2. package/builtin-tasks/compile.js +17 -1
  3. package/builtin-tasks/compile.js.map +1 -1
  4. package/builtin-tasks/help.js +36 -5
  5. package/builtin-tasks/help.js.map +1 -1
  6. package/internal/cli/ArgumentsParser.d.ts +7 -2
  7. package/internal/cli/ArgumentsParser.d.ts.map +1 -1
  8. package/internal/cli/ArgumentsParser.js +72 -11
  9. package/internal/cli/ArgumentsParser.js.map +1 -1
  10. package/internal/cli/HelpPrinter.d.ts +7 -3
  11. package/internal/cli/HelpPrinter.d.ts.map +1 -1
  12. package/internal/cli/HelpPrinter.js +53 -22
  13. package/internal/cli/HelpPrinter.js.map +1 -1
  14. package/internal/cli/cli.js +29 -15
  15. package/internal/cli/cli.js.map +1 -1
  16. package/internal/cli/project-creation.d.ts.map +1 -1
  17. package/internal/cli/project-creation.js +61 -7
  18. package/internal/cli/project-creation.js.map +1 -1
  19. package/internal/core/config/config-env.d.ts +2 -1
  20. package/internal/core/config/config-env.d.ts.map +1 -1
  21. package/internal/core/config/config-env.js +7 -1
  22. package/internal/core/config/config-env.js.map +1 -1
  23. package/internal/core/errors-list.d.ts +28 -0
  24. package/internal/core/errors-list.d.ts.map +1 -1
  25. package/internal/core/errors-list.js +36 -2
  26. package/internal/core/errors-list.js.map +1 -1
  27. package/internal/core/runtime-environment.d.ts +5 -3
  28. package/internal/core/runtime-environment.d.ts.map +1 -1
  29. package/internal/core/runtime-environment.js +30 -7
  30. package/internal/core/runtime-environment.js.map +1 -1
  31. package/internal/core/tasks/dsl.d.ts +10 -1
  32. package/internal/core/tasks/dsl.d.ts.map +1 -1
  33. package/internal/core/tasks/dsl.js +64 -4
  34. package/internal/core/tasks/dsl.js.map +1 -1
  35. package/internal/core/tasks/task-definitions.d.ts +31 -4
  36. package/internal/core/tasks/task-definitions.d.ts.map +1 -1
  37. package/internal/core/tasks/task-definitions.js +51 -5
  38. package/internal/core/tasks/task-definitions.js.map +1 -1
  39. package/internal/core/tasks/util.d.ts +6 -0
  40. package/internal/core/tasks/util.d.ts.map +1 -0
  41. package/internal/core/tasks/util.js +19 -0
  42. package/internal/core/tasks/util.js.map +1 -0
  43. package/internal/lib/hardhat-lib.d.ts.map +1 -1
  44. package/internal/lib/hardhat-lib.js +1 -1
  45. package/internal/lib/hardhat-lib.js.map +1 -1
  46. package/internal/sentry/anonymizer.d.ts.map +1 -1
  47. package/internal/sentry/anonymizer.js +3 -1
  48. package/internal/sentry/anonymizer.js.map +1 -1
  49. package/internal/solidity/compiler/solc-info.d.ts +2 -0
  50. package/internal/solidity/compiler/solc-info.d.ts.map +1 -0
  51. package/internal/solidity/compiler/solc-info.js +69 -0
  52. package/internal/solidity/compiler/solc-info.js.map +1 -0
  53. package/package.json +1 -1
  54. package/register.js +1 -1
  55. package/register.js.map +1 -1
  56. package/sample-projects/typescript-viem/LICENSE.md +11 -0
  57. package/sample-projects/typescript-viem/README.md +13 -0
  58. package/sample-projects/typescript-viem/contracts/Lock.sol +34 -0
  59. package/sample-projects/typescript-viem/hardhat.config.ts +8 -0
  60. package/sample-projects/typescript-viem/scripts/deploy.ts +26 -0
  61. package/sample-projects/typescript-viem/test/Lock.ts +132 -0
  62. package/sample-projects/typescript-viem/tsconfig.json +11 -0
  63. package/src/builtin-tasks/compile.ts +34 -10
  64. package/src/builtin-tasks/help.ts +47 -5
  65. package/src/internal/cli/ArgumentsParser.ts +79 -13
  66. package/src/internal/cli/HelpPrinter.ts +89 -24
  67. package/src/internal/cli/cli.ts +43 -25
  68. package/src/internal/cli/project-creation.ts +91 -24
  69. package/src/internal/core/config/config-env.ts +11 -0
  70. package/src/internal/core/errors-list.ts +38 -2
  71. package/src/internal/core/runtime-environment.ts +32 -7
  72. package/src/internal/core/tasks/dsl.ts +99 -4
  73. package/src/internal/core/tasks/task-definitions.ts +97 -3
  74. package/src/internal/core/tasks/util.ts +18 -0
  75. package/src/internal/lib/hardhat-lib.ts +1 -0
  76. package/src/internal/sentry/anonymizer.ts +3 -1
  77. package/src/internal/solidity/compiler/solc-info.ts +67 -0
  78. package/src/register.ts +1 -0
  79. package/src/types/builtin-tasks/compile.ts +5 -0
  80. package/src/types/runtime.ts +35 -1
  81. package/types/builtin-tasks/compile.d.ts +4 -0
  82. package/types/builtin-tasks/compile.d.ts.map +1 -1
  83. package/types/builtin-tasks/compile.js.map +1 -1
  84. package/types/runtime.d.ts +24 -1
  85. package/types/runtime.d.ts.map +1 -1
@@ -613,8 +613,26 @@ Please double check your task definitions.`,
613
613
  What makes these types special is that they can be represented as strings, so you can write them down in the terminal.`,
614
614
  shouldBeReported: false,
615
615
  },
616
- DEPRECATED_TRANSFORM_IMPORT_TASK: {
616
+ TASK_SCOPE_CLASH: {
617
617
  number: 213,
618
+ message:
619
+ "A clash was found while creating scope '%scopeName%', since a task with that name already exists.",
620
+ title: "Attempted to create a scope with a name already used by a task",
621
+ description: `You can't create a scope if a task with that name already exists.
622
+ Please double check your task definitions.`,
623
+ shouldBeReported: false,
624
+ },
625
+ SCOPE_TASK_CLASH: {
626
+ number: 214,
627
+ message:
628
+ "A clash was found while creating task '%taskName%', since a scope with that name already exists.",
629
+ title: "Attempted to create a task with a name already used by a scope",
630
+ description: `You can't create a task if a scope with that name already exists.
631
+ Please double check your task definitions.`,
632
+ shouldBeReported: false,
633
+ },
634
+ DEPRECATED_TRANSFORM_IMPORT_TASK: {
635
+ number: 215,
618
636
  title: "Use of deprecated remapping task",
619
637
  message:
620
638
  "Task TASK_COMPILE_TRANSFORM_IMPORT_NAME is deprecated. Please update your @nomicfoundation/hardhat-foundry plugin version.",
@@ -654,7 +672,7 @@ Please double check your arguments.`,
654
672
  },
655
673
  UNRECOGNIZED_TASK: {
656
674
  number: 303,
657
- message: "Unrecognized task %task%",
675
+ message: "Unrecognized task '%task%'",
658
676
  title: "Unrecognized task",
659
677
  description: `Tried to run a nonexistent task.
660
678
 
@@ -756,6 +774,24 @@ This is not supported. Please run the help task to see the available options.`,
756
774
  This flag can only be used in typescript projects.`,
757
775
  shouldBeReported: false,
758
776
  },
777
+ UNRECOGNIZED_SCOPE: {
778
+ number: 314,
779
+ message: "Unrecognized scope '%scope%'",
780
+ title: "Unrecognized scope",
781
+ description: `Tried to run a task from a nonexistent scope.
782
+
783
+ Please double check the scope of the task you are trying to run.`,
784
+ shouldBeReported: false,
785
+ },
786
+ UNRECOGNIZED_SCOPED_TASK: {
787
+ number: 315,
788
+ message: "Unrecognized task '%task%' under scope '%scope%'",
789
+ title: "Unrecognized scoped task",
790
+ description: `Tried to run a nonexistent scoped task.
791
+
792
+ Please double check the name of the task you are trying to run.`,
793
+ shouldBeReported: false,
794
+ },
759
795
  },
760
796
  RESOLVER: {
761
797
  FILE_NOT_FOUND: {
@@ -10,13 +10,14 @@ import {
10
10
  HardhatUserConfig,
11
11
  Network,
12
12
  ParamDefinition,
13
+ ProviderExtender,
13
14
  RunSuperFunction,
14
15
  RunTaskFunction,
15
16
  SubtaskArguments,
16
17
  TaskArguments,
17
18
  TaskDefinition,
18
19
  TasksMap,
19
- ProviderExtender,
20
+ ScopesMap,
20
21
  } from "../../types";
21
22
  import { Artifacts } from "../artifacts";
22
23
  import { MessageTrace } from "../hardhat-network/stack-traces/message-trace";
@@ -34,6 +35,7 @@ import {
34
35
  createTaskProfile,
35
36
  TaskProfile,
36
37
  } from "./task-profiling";
38
+ import { parseTaskIdentifier } from "./tasks/util";
37
39
 
38
40
  const log = debug("hardhat:core:hre");
39
41
 
@@ -65,6 +67,7 @@ export class Environment implements HardhatRuntimeEnvironment {
65
67
  * @param config The hardhat's config object.
66
68
  * @param hardhatArguments The parsed hardhat's arguments.
67
69
  * @param tasks A map of tasks.
70
+ * @param scopes A map of scopes.
68
71
  * @param environmentExtenders A list of environment extenders.
69
72
  * @param providerExtenders A list of provider extenders.
70
73
  */
@@ -72,6 +75,7 @@ export class Environment implements HardhatRuntimeEnvironment {
72
75
  public readonly config: HardhatConfig,
73
76
  public readonly hardhatArguments: HardhatArguments,
74
77
  public readonly tasks: TasksMap,
78
+ public readonly scopes: ScopesMap,
75
79
  environmentExtenders: EnvironmentExtender[] = [],
76
80
  experimentalHardhatNetworkMessageTraceHooks: ExperimentalHardhatNetworkMessageTraceHook[] = [],
77
81
  public readonly userConfig: HardhatUserConfig = {},
@@ -122,7 +126,7 @@ export class Environment implements HardhatRuntimeEnvironment {
122
126
  /**
123
127
  * Executes the task with the given name.
124
128
  *
125
- * @param name The task's name.
129
+ * @param taskIdentifier The task or scoped task to be executed.
126
130
  * @param taskArguments A map of task's arguments.
127
131
  * @param subtaskArguments A map of subtasks to their arguments.
128
132
  *
@@ -130,18 +134,39 @@ export class Environment implements HardhatRuntimeEnvironment {
130
134
  * @returns a promise with the task's execution result.
131
135
  */
132
136
  public readonly run: RunTaskFunction = async (
133
- name,
137
+ taskIdentifier,
134
138
  taskArguments = {},
135
139
  subtaskArguments = {},
136
140
  callerTaskProfile?: TaskProfile
137
141
  ) => {
138
- const taskDefinition = this.tasks[name];
142
+ const { scope, task } = parseTaskIdentifier(taskIdentifier);
143
+
144
+ let taskDefinition;
145
+ if (scope === undefined) {
146
+ taskDefinition = this.tasks[task];
147
+ log("Running task %s", task);
148
+ } else {
149
+ const scopeDefinition = this.scopes[scope];
150
+ if (scopeDefinition === undefined) {
151
+ throw new HardhatError(ERRORS.ARGUMENTS.UNRECOGNIZED_SCOPE, {
152
+ scope,
153
+ });
154
+ }
139
155
 
140
- log("Running task %s", name);
156
+ taskDefinition = scopeDefinition.tasks?.[task];
157
+ log("Running scoped task %s %s", scope, task);
158
+ }
141
159
 
142
160
  if (taskDefinition === undefined) {
161
+ if (scope !== undefined) {
162
+ throw new HardhatError(ERRORS.ARGUMENTS.UNRECOGNIZED_SCOPED_TASK, {
163
+ scope,
164
+ task,
165
+ });
166
+ }
167
+
143
168
  throw new HardhatError(ERRORS.ARGUMENTS.UNRECOGNIZED_TASK, {
144
- task: name,
169
+ task,
145
170
  });
146
171
  }
147
172
 
@@ -153,7 +178,7 @@ export class Environment implements HardhatRuntimeEnvironment {
153
178
 
154
179
  let taskProfile: TaskProfile | undefined;
155
180
  if (this.hardhatArguments.flamegraph === true) {
156
- taskProfile = createTaskProfile(name);
181
+ taskProfile = createTaskProfile(task);
157
182
 
158
183
  if (callerTaskProfile !== undefined) {
159
184
  callerTaskProfile.children.push(taskProfile);
@@ -1,14 +1,21 @@
1
1
  import {
2
2
  ActionType,
3
+ ScopeDefinition,
4
+ ScopesMap,
3
5
  TaskArguments,
4
6
  TaskDefinition,
7
+ TaskIdentifier,
5
8
  TasksMap,
6
9
  } from "../../../types";
10
+ import { HardhatError, assertHardhatInvariant } from "../errors";
11
+ import { ERRORS } from "../errors-list";
7
12
 
8
13
  import {
9
14
  OverriddenTaskDefinition,
15
+ SimpleScopeDefinition,
10
16
  SimpleTaskDefinition,
11
17
  } from "./task-definitions";
18
+ import { parseTaskIdentifier } from "./util";
12
19
 
13
20
  /**
14
21
  * This class defines the DSL used in Hardhat config files
@@ -18,6 +25,7 @@ export class TasksDSL {
18
25
  public readonly internalTask = this.subtask;
19
26
 
20
27
  private readonly _tasks: TasksMap = {};
28
+ private readonly _scopes: ScopesMap = {};
21
29
 
22
30
  /**
23
31
  * Creates a task, overriding any previous task with the same name.
@@ -56,6 +64,8 @@ export class TasksDSL {
56
64
  descriptionOrAction?: string | ActionType<TaskArgumentsT>,
57
65
  action?: ActionType<TaskArgumentsT>
58
66
  ): TaskDefinition {
67
+ // if this function is updated, update the corresponding callback
68
+ // passed to `new SimpleScopeDefinition`
59
69
  return this._addTask(name, descriptionOrAction, action, false);
60
70
  }
61
71
 
@@ -96,9 +106,56 @@ export class TasksDSL {
96
106
  descriptionOrAction?: string | ActionType<TaskArgumentsT>,
97
107
  action?: ActionType<TaskArgumentsT>
98
108
  ): TaskDefinition {
109
+ // if this function is updated, update the corresponding callback
110
+ // passed to `new SimpleScopeDefinition`
99
111
  return this._addTask(name, descriptionOrAction, action, true);
100
112
  }
101
113
 
114
+ public scope(name: string, description?: string): ScopeDefinition {
115
+ if (this._tasks[name] !== undefined) {
116
+ throw new HardhatError(ERRORS.TASK_DEFINITIONS.TASK_SCOPE_CLASH, {
117
+ scopeName: name,
118
+ });
119
+ }
120
+
121
+ const scopeDefinition = this._scopes[name];
122
+
123
+ if (scopeDefinition !== undefined) {
124
+ // if the scope already exists, the only thing we might
125
+ // do is to update its description
126
+ if (description !== undefined) {
127
+ scopeDefinition.setDescription(description);
128
+ }
129
+
130
+ return scopeDefinition;
131
+ }
132
+
133
+ const scope = new SimpleScopeDefinition(
134
+ name,
135
+ description,
136
+ (taskName, descriptionOrAction, action) =>
137
+ // if this function is updated, update the dsl.task function too
138
+ this._addTask(
139
+ { scope: name, task: taskName },
140
+ descriptionOrAction,
141
+ action,
142
+ false
143
+ ),
144
+ (subtaskName, descriptionOrAction, action) =>
145
+ // if this function is updated, update the dsl.subtask function too
146
+ this._addTask(
147
+ { scope: name, task: subtaskName },
148
+ descriptionOrAction,
149
+ action,
150
+ true
151
+ )
152
+ );
153
+
154
+ this._scopes[name] = scope;
155
+
156
+ return scope;
157
+ }
158
+
102
159
  /**
103
160
  * Retrieves the task definitions.
104
161
  *
@@ -108,13 +165,41 @@ export class TasksDSL {
108
165
  return this._tasks;
109
166
  }
110
167
 
168
+ /**
169
+ * Retrieves the scoped task definitions.
170
+ *
171
+ * @returns The scoped tasks container.
172
+ */
173
+ public getScopesDefinitions(): ScopesMap {
174
+ return this._scopes;
175
+ }
176
+
177
+ public getTaskDefinition(
178
+ scope: string | undefined,
179
+ name: string
180
+ ): TaskDefinition | undefined {
181
+ if (scope === undefined) {
182
+ return this._tasks[name];
183
+ } else {
184
+ return this._scopes[scope]?.tasks?.[name];
185
+ }
186
+ }
187
+
111
188
  private _addTask<TaskArgumentsT extends TaskArguments>(
112
- name: string,
189
+ taskIdentifier: TaskIdentifier,
113
190
  descriptionOrAction?: string | ActionType<TaskArgumentsT>,
114
191
  action?: ActionType<TaskArgumentsT>,
115
192
  isSubtask?: boolean
116
193
  ) {
117
- const parentTaskDefinition = this._tasks[name];
194
+ const { scope, task } = parseTaskIdentifier(taskIdentifier);
195
+
196
+ if (scope === undefined && this._scopes[task] !== undefined) {
197
+ throw new HardhatError(ERRORS.TASK_DEFINITIONS.SCOPE_TASK_CLASH, {
198
+ taskName: task,
199
+ });
200
+ }
201
+
202
+ const parentTaskDefinition = this.getTaskDefinition(scope, task);
118
203
 
119
204
  let taskDefinition: TaskDefinition;
120
205
 
@@ -124,7 +209,7 @@ export class TasksDSL {
124
209
  isSubtask
125
210
  );
126
211
  } else {
127
- taskDefinition = new SimpleTaskDefinition(name, isSubtask);
212
+ taskDefinition = new SimpleTaskDefinition(taskIdentifier, isSubtask);
128
213
  }
129
214
 
130
215
  if (descriptionOrAction instanceof Function) {
@@ -140,7 +225,17 @@ export class TasksDSL {
140
225
  taskDefinition.setAction(action);
141
226
  }
142
227
 
143
- this._tasks[name] = taskDefinition;
228
+ if (scope === undefined) {
229
+ this._tasks[task] = taskDefinition;
230
+ } else {
231
+ const scopeDefinition = this._scopes[scope];
232
+ assertHardhatInvariant(
233
+ scopeDefinition !== undefined,
234
+ "It shouldn't be possible to create a task in a scope that doesn't exist"
235
+ );
236
+ scopeDefinition.tasks[task] = taskDefinition;
237
+ }
238
+
144
239
  return taskDefinition;
145
240
  }
146
241
  }
@@ -4,13 +4,17 @@ import {
4
4
  CLIArgumentType,
5
5
  ParamDefinition,
6
6
  ParamDefinitionsMap,
7
+ ScopeDefinition,
7
8
  TaskArguments,
8
9
  TaskDefinition,
10
+ TaskIdentifier,
11
+ TasksMap,
9
12
  } from "../../../types";
10
13
  import { HardhatError } from "../errors";
11
14
  import { ErrorDescriptor, ERRORS } from "../errors-list";
12
15
  import * as types from "../params/argumentTypes";
13
16
  import { HARDHAT_PARAM_DEFINITIONS } from "../params/hardhat-params";
17
+ import { parseTaskIdentifier } from "./util";
14
18
 
15
19
  function isCLIArgumentType(
16
20
  type: ArgumentType<any>
@@ -26,6 +30,12 @@ function isCLIArgumentType(
26
30
  *
27
31
  */
28
32
  export class SimpleTaskDefinition implements TaskDefinition {
33
+ public get name() {
34
+ return this._task;
35
+ }
36
+ public get scope() {
37
+ return this._scope;
38
+ }
29
39
  public get description() {
30
40
  return this._description;
31
41
  }
@@ -36,6 +46,8 @@ export class SimpleTaskDefinition implements TaskDefinition {
36
46
  private _positionalParamNames: Set<string>;
37
47
  private _hasVariadicParam: boolean;
38
48
  private _hasOptionalPositionalParam: boolean;
49
+ private _scope?: string;
50
+ private _task: string;
39
51
  private _description?: string;
40
52
 
41
53
  /**
@@ -43,19 +55,22 @@ export class SimpleTaskDefinition implements TaskDefinition {
43
55
  *
44
56
  * This definition will have no params, and will throw a HH205 if executed.
45
57
  *
46
- * @param name The task's name.
58
+ * @param taskIdentifier The task's identifier.
47
59
  * @param isSubtask `true` if the task is a subtask, `false` otherwise.
48
60
  */
49
61
  constructor(
50
- public readonly name: string,
62
+ taskIdentifier: TaskIdentifier,
51
63
  public readonly isSubtask: boolean = false
52
64
  ) {
53
65
  this._positionalParamNames = new Set();
54
66
  this._hasVariadicParam = false;
55
67
  this._hasOptionalPositionalParam = false;
68
+ const { scope, task } = parseTaskIdentifier(taskIdentifier);
69
+ this._scope = scope;
70
+ this._task = task;
56
71
  this.action = () => {
57
72
  throw new HardhatError(ERRORS.TASK_DEFINITIONS.ACTION_NOT_SET, {
58
- taskName: name,
73
+ taskName: this._task,
59
74
  });
60
75
  };
61
76
  }
@@ -562,6 +577,10 @@ export class OverriddenTaskDefinition implements TaskDefinition {
562
577
  this.parentTaskDefinition = parentTaskDefinition;
563
578
  }
564
579
 
580
+ /**
581
+ * Sets the task's description.
582
+ * @param description The description.
583
+ */
565
584
  public setDescription(description: string) {
566
585
  this._description = description;
567
586
  return this;
@@ -579,6 +598,13 @@ export class OverriddenTaskDefinition implements TaskDefinition {
579
598
  return this;
580
599
  }
581
600
 
601
+ /**
602
+ * Retrieves the parent task's scope.
603
+ */
604
+ public get scope() {
605
+ return this.parentTaskDefinition.scope;
606
+ }
607
+
582
608
  /**
583
609
  * Retrieves the parent task's name.
584
610
  */
@@ -734,3 +760,71 @@ export class OverriddenTaskDefinition implements TaskDefinition {
734
760
  });
735
761
  }
736
762
  }
763
+
764
+ type AddTaskFunction = <TaskArgumentsT extends TaskArguments>(
765
+ name: string,
766
+ descriptionOrAction?: string | ActionType<TaskArgumentsT>,
767
+ action?: ActionType<TaskArgumentsT>
768
+ ) => TaskDefinition;
769
+
770
+ export class SimpleScopeDefinition implements ScopeDefinition {
771
+ public tasks: TasksMap = {};
772
+
773
+ constructor(
774
+ public readonly name: string,
775
+ private _description: string | undefined,
776
+ private _addTask: AddTaskFunction,
777
+ private _addSubtask: AddTaskFunction
778
+ ) {}
779
+
780
+ public get description() {
781
+ return this._description;
782
+ }
783
+
784
+ public setDescription(description: string): this {
785
+ this._description = description;
786
+ return this;
787
+ }
788
+
789
+ public task<TaskArgumentsT extends TaskArguments>(
790
+ name: string,
791
+ description?: string,
792
+ action?: ActionType<TaskArgumentsT>
793
+ ): TaskDefinition;
794
+ public task<TaskArgumentsT extends TaskArguments>(
795
+ name: string,
796
+ action: ActionType<TaskArgumentsT>
797
+ ): TaskDefinition;
798
+ public task<TaskArgumentsT extends TaskArguments>(
799
+ name: string,
800
+ descriptionOrAction?: string | ActionType<TaskArgumentsT>,
801
+ action?: ActionType<TaskArgumentsT>
802
+ ) {
803
+ const task = this._addTask(name, descriptionOrAction, action);
804
+
805
+ this.tasks[name] = task;
806
+
807
+ return task;
808
+ }
809
+
810
+ public subtask<TaskArgumentsT extends TaskArguments>(
811
+ name: string,
812
+ description?: string,
813
+ action?: ActionType<TaskArgumentsT>
814
+ ): TaskDefinition;
815
+ public subtask<TaskArgumentsT extends TaskArguments>(
816
+ name: string,
817
+ action: ActionType<TaskArgumentsT>
818
+ ): TaskDefinition;
819
+ public subtask<TaskArgumentsT extends TaskArguments>(
820
+ name: string,
821
+ descriptionOrAction?: string | ActionType<TaskArgumentsT>,
822
+ action?: ActionType<TaskArgumentsT>
823
+ ) {
824
+ const subtask = this._addSubtask(name, descriptionOrAction, action);
825
+
826
+ this.tasks[name] = subtask;
827
+
828
+ return subtask;
829
+ }
830
+ }
@@ -0,0 +1,18 @@
1
+ import { TaskIdentifier } from "../../../types";
2
+
3
+ export function parseTaskIdentifier(taskIdentifier: TaskIdentifier): {
4
+ scope: string | undefined;
5
+ task: string;
6
+ } {
7
+ if (typeof taskIdentifier === "string") {
8
+ return {
9
+ scope: undefined,
10
+ task: taskIdentifier,
11
+ };
12
+ } else {
13
+ return {
14
+ scope: taskIdentifier.scope,
15
+ task: taskIdentifier.task,
16
+ };
17
+ }
18
+ }
@@ -40,6 +40,7 @@ if (HardhatContext.isCreated()) {
40
40
  resolvedConfig,
41
41
  hardhatArguments,
42
42
  ctx.tasksDSL.getTaskDefinitions(),
43
+ ctx.tasksDSL.getScopesDefinitions(),
43
44
  ctx.environmentExtenders,
44
45
  ctx.experimentalHardhatNetworkMessageTraceHooks,
45
46
  userConfig,
@@ -171,9 +171,11 @@ export class Anonymizer {
171
171
 
172
172
  private _isHardhatFile(filename: string): boolean {
173
173
  const nomiclabsPath = path.join("node_modules", "@nomiclabs");
174
+ const nomicFoundationPath = path.join("node_modules", "@nomicfoundation");
174
175
  const truffleContractPath = path.join(nomiclabsPath, "truffle-contract");
175
176
  const isHardhatFile =
176
- filename.startsWith(nomiclabsPath) &&
177
+ (filename.startsWith(nomiclabsPath) ||
178
+ filename.startsWith(nomicFoundationPath)) &&
177
179
  !filename.startsWith(truffleContractPath);
178
180
 
179
181
  return isHardhatFile;
@@ -0,0 +1,67 @@
1
+ const defaultEvmTargets: { [key: string]: string } = {
2
+ "0.5.1": "byzantium",
3
+ "0.5.2": "byzantium",
4
+ "0.5.3": "byzantium",
5
+ "0.5.4": "byzantium",
6
+ "0.5.5": "petersburg",
7
+ "0.5.6": "petersburg",
8
+ "0.5.7": "petersburg",
9
+ "0.5.8": "petersburg",
10
+ "0.5.9": "petersburg",
11
+ "0.5.10": "petersburg",
12
+ "0.5.11": "petersburg",
13
+ "0.5.12": "petersburg",
14
+ "0.5.13": "petersburg",
15
+ "0.5.14": "istanbul",
16
+ "0.5.15": "istanbul",
17
+ "0.5.16": "istanbul",
18
+ "0.5.17": "istanbul",
19
+ "0.6.0": "istanbul",
20
+ "0.6.1": "istanbul",
21
+ "0.6.2": "istanbul",
22
+ "0.6.3": "istanbul",
23
+ "0.6.4": "istanbul",
24
+ "0.6.5": "istanbul",
25
+ "0.6.6": "istanbul",
26
+ "0.6.7": "istanbul",
27
+ "0.6.8": "istanbul",
28
+ "0.6.9": "istanbul",
29
+ "0.6.10": "istanbul",
30
+ "0.6.11": "istanbul",
31
+ "0.6.12": "istanbul",
32
+ "0.7.0": "istanbul",
33
+ "0.7.1": "istanbul",
34
+ "0.7.2": "istanbul",
35
+ "0.7.3": "istanbul",
36
+ "0.7.4": "istanbul",
37
+ "0.7.5": "istanbul",
38
+ "0.7.6": "istanbul",
39
+ "0.8.0": "istanbul",
40
+ "0.8.1": "istanbul",
41
+ "0.8.2": "istanbul",
42
+ "0.8.3": "istanbul",
43
+ "0.8.4": "istanbul",
44
+ "0.8.5": "berlin",
45
+ "0.8.6": "berlin",
46
+ "0.8.7": "london",
47
+ "0.8.8": "london",
48
+ "0.8.9": "london",
49
+ "0.8.10": "london",
50
+ "0.8.11": "london",
51
+ "0.8.12": "london",
52
+ "0.8.13": "london",
53
+ "0.8.14": "london",
54
+ "0.8.15": "london",
55
+ "0.8.16": "london",
56
+ "0.8.17": "london",
57
+ "0.8.18": "paris",
58
+ "0.8.19": "paris",
59
+ "0.8.20": "shanghai",
60
+ "0.8.21": "shanghai",
61
+ };
62
+
63
+ export function getEvmVersionFromSolcVersion(
64
+ solcVersion: string
65
+ ): string | undefined {
66
+ return defaultEvmTargets[solcVersion];
67
+ }
package/src/register.ts CHANGED
@@ -42,6 +42,7 @@ if (!HardhatContext.isCreated()) {
42
42
  resolvedConfig,
43
43
  hardhatArguments,
44
44
  ctx.tasksDSL.getTaskDefinitions(),
45
+ ctx.tasksDSL.getScopesDefinitions(),
45
46
  ctx.environmentExtenders,
46
47
  ctx.experimentalHardhatNetworkMessageTraceHooks,
47
48
  userConfig,
@@ -15,6 +15,11 @@ export interface ResolvedFile {
15
15
  getVersionedName(): string;
16
16
  }
17
17
 
18
+ export type ArtifactsEmittedPerFile = Array<{
19
+ file: ResolvedFile;
20
+ artifactsEmitted: string[];
21
+ }>;
22
+
18
23
  /**
19
24
  * Information about an npm library.
20
25
  */
@@ -93,6 +93,26 @@ export interface ConfigurableTaskDefinition {
93
93
  addFlag(name: string, description?: string): this;
94
94
  }
95
95
 
96
+ // type alias to get the overloaded function type
97
+ // for 'task` and 'subtask'
98
+ declare function addTask<TaskArgumentsT extends TaskArguments>(
99
+ name: string,
100
+ description?: string,
101
+ action?: ActionType<TaskArgumentsT>
102
+ ): ConfigurableTaskDefinition;
103
+ declare function addTask<TaskArgumentsT extends TaskArguments>(
104
+ name: string,
105
+ action: ActionType<TaskArgumentsT>
106
+ ): ConfigurableTaskDefinition;
107
+ type AddConfigurableTaskFunction = typeof addTask;
108
+
109
+ export interface ConfigurableScopeDefinition {
110
+ setDescription(description: string): this;
111
+
112
+ task: AddConfigurableTaskFunction;
113
+ subtask: AddConfigurableTaskFunction;
114
+ }
115
+
96
116
  export interface ParamDefinition<T> {
97
117
  name: string;
98
118
  defaultValue?: T;
@@ -118,6 +138,7 @@ export interface ParamDefinitionsMap {
118
138
  }
119
139
 
120
140
  export interface TaskDefinition extends ConfigurableTaskDefinition {
141
+ readonly scope?: string;
121
142
  readonly name: string;
122
143
  readonly description?: string;
123
144
  readonly action: ActionType<TaskArguments>;
@@ -130,6 +151,14 @@ export interface TaskDefinition extends ConfigurableTaskDefinition {
130
151
  readonly positionalParamDefinitions: Array<ParamDefinition<any>>;
131
152
  }
132
153
 
154
+ export interface ScopeDefinition extends ConfigurableScopeDefinition {
155
+ readonly name: string;
156
+ readonly description?: string;
157
+ readonly tasks: TasksMap;
158
+ }
159
+
160
+ export type TaskIdentifier = string | { scope?: string; task: string };
161
+
133
162
  /**
134
163
  * @type TaskArguments {object-like} - the input arguments for a task.
135
164
  *
@@ -188,8 +217,12 @@ export interface TasksMap {
188
217
  [name: string]: TaskDefinition;
189
218
  }
190
219
 
220
+ export interface ScopesMap {
221
+ [scopeName: string]: ScopeDefinition;
222
+ }
223
+
191
224
  export type RunTaskFunction = (
192
- name: string,
225
+ taskIdentifier: TaskIdentifier,
193
226
  taskArguments?: TaskArguments,
194
227
  subtaskArguments?: SubtaskArguments
195
228
  ) => Promise<any>;
@@ -199,6 +232,7 @@ export interface HardhatRuntimeEnvironment {
199
232
  readonly userConfig: HardhatUserConfig;
200
233
  readonly hardhatArguments: HardhatArguments;
201
234
  readonly tasks: TasksMap;
235
+ readonly scopes: ScopesMap;
202
236
  readonly run: RunTaskFunction;
203
237
  readonly network: Network;
204
238
  readonly artifacts: Artifacts;