1 | import { EventEmitter } from "events";
|
2 | import { DeepPartial, DeepReadonly, Omit } from "ts-essentials";
|
3 |
|
4 | import {
|
5 | EvmMessageTrace,
|
6 | MessageTrace,
|
7 | } from "./internal/buidler-evm/stack-traces/message-trace";
|
8 | import * as types from "./internal/core/params/argumentTypes";
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export interface CommonNetworkConfig {
|
15 | chainId?: number;
|
16 | from?: string;
|
17 | gas?: "auto" | number;
|
18 | gasPrice?: "auto" | number;
|
19 | gasMultiplier?: number;
|
20 | }
|
21 |
|
22 | export interface BuidlerNetworkAccount {
|
23 | privateKey: string;
|
24 | balance: string;
|
25 | }
|
26 |
|
27 | export interface BuidlerNetworkConfig extends CommonNetworkConfig {
|
28 | accounts?: BuidlerNetworkAccount[];
|
29 | blockGasLimit?: number;
|
30 | hardfork?: string;
|
31 | throwOnTransactionFailures?: boolean;
|
32 | throwOnCallFailures?: boolean;
|
33 | loggingEnabled?: boolean;
|
34 | allowUnlimitedContractSize?: boolean;
|
35 | initialDate?: string;
|
36 | }
|
37 |
|
38 | export interface HDAccountsConfig {
|
39 | mnemonic: string;
|
40 | initialIndex?: number;
|
41 | count?: number;
|
42 | path?: string;
|
43 | }
|
44 |
|
45 | export interface OtherAccountsConfig {
|
46 | type: string;
|
47 | }
|
48 |
|
49 | export type NetworkConfigAccounts =
|
50 | | "remote"
|
51 | | string[]
|
52 | | HDAccountsConfig
|
53 | | OtherAccountsConfig;
|
54 |
|
55 | export interface HttpNetworkConfig extends CommonNetworkConfig {
|
56 | url?: string;
|
57 | timeout?: number;
|
58 | httpHeaders?: { [name: string]: string };
|
59 | accounts?: NetworkConfigAccounts;
|
60 | }
|
61 |
|
62 | export type NetworkConfig = BuidlerNetworkConfig | HttpNetworkConfig;
|
63 |
|
64 | export interface Networks {
|
65 | [networkName: string]: NetworkConfig;
|
66 | }
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | export interface ProjectPaths {
|
78 | root: string;
|
79 | configFile: string;
|
80 | cache: string;
|
81 | artifacts: string;
|
82 | sources: string;
|
83 | tests: string;
|
84 | }
|
85 |
|
86 | type EVMVersion = string;
|
87 |
|
88 | export interface SolcConfig {
|
89 | version: string;
|
90 | optimizer: SolcOptimizerConfig;
|
91 | evmVersion?: EVMVersion;
|
92 | }
|
93 |
|
94 | export interface SolcOptimizerConfig {
|
95 | enabled: boolean;
|
96 | runs: number;
|
97 | }
|
98 |
|
99 | export interface AnalyticsConfig {
|
100 | enabled: boolean;
|
101 | }
|
102 |
|
103 | export interface BuidlerConfig {
|
104 | defaultNetwork?: string;
|
105 | networks?: Networks;
|
106 | paths?: Omit<Partial<ProjectPaths>, "configFile">;
|
107 | solc?: DeepPartial<SolcConfig>;
|
108 | mocha?: Mocha.MochaOptions;
|
109 | analytics?: Partial<AnalyticsConfig>;
|
110 | }
|
111 |
|
112 | export interface ResolvedBuidlerConfig extends BuidlerConfig {
|
113 | defaultNetwork: string;
|
114 | paths: ProjectPaths;
|
115 | networks: Networks;
|
116 | solc: SolcConfig;
|
117 | analytics: AnalyticsConfig;
|
118 | }
|
119 |
|
120 |
|
121 |
|
122 | export interface SolcInput {
|
123 | settings: {
|
124 | metadata: { useLiteralContent: boolean };
|
125 | optimizer: SolcOptimizerConfig;
|
126 | outputSelection: { "*": { "": string[]; "*": string[] } };
|
127 | evmVersion?: string;
|
128 | };
|
129 | sources: { [p: string]: { content: string } };
|
130 | language: string;
|
131 | }
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | export type EnvironmentExtender = (env: BuidlerRuntimeEnvironment) => void;
|
138 |
|
139 | export type ConfigExtender = (
|
140 | config: ResolvedBuidlerConfig,
|
141 | userConfig: DeepReadonly<BuidlerConfig>
|
142 | ) => void;
|
143 |
|
144 |
|
145 |
|
146 | export type ExperimentalBuidlerEVMMessageTraceHook = (
|
147 | bre: BuidlerRuntimeEnvironment,
|
148 | trace: MessageTrace,
|
149 | isMessageTraceFromACall: boolean
|
150 | ) => Promise<void>;
|
151 |
|
152 |
|
153 |
|
154 | export type BoundExperimentalBuidlerEVMMessageTraceHook = (
|
155 | trace: MessageTrace,
|
156 | isMessageTraceFromACall: boolean
|
157 | ) => Promise<void>;
|
158 |
|
159 | export interface TasksMap {
|
160 | [name: string]: TaskDefinition;
|
161 | }
|
162 |
|
163 | export interface ConfigurableTaskDefinition {
|
164 | setDescription(description: string): this;
|
165 |
|
166 | setAction(action: ActionType<TaskArguments>): this;
|
167 |
|
168 | addParam<T>(
|
169 | name: string,
|
170 | description?: string,
|
171 | defaultValue?: T,
|
172 | type?: types.ArgumentType<T>,
|
173 | isOptional?: boolean
|
174 | ): this;
|
175 |
|
176 | addOptionalParam<T>(
|
177 | name: string,
|
178 | description?: string,
|
179 | defaultValue?: T,
|
180 | type?: types.ArgumentType<T>
|
181 | ): this;
|
182 |
|
183 | addPositionalParam<T>(
|
184 | name: string,
|
185 | description?: string,
|
186 | defaultValue?: T,
|
187 | type?: types.ArgumentType<T>,
|
188 | isOptional?: boolean
|
189 | ): this;
|
190 |
|
191 | addOptionalPositionalParam<T>(
|
192 | name: string,
|
193 | description?: string,
|
194 | defaultValue?: T,
|
195 | type?: types.ArgumentType<T>
|
196 | ): this;
|
197 |
|
198 | addVariadicPositionalParam<T>(
|
199 | name: string,
|
200 | description?: string,
|
201 | defaultValue?: T[],
|
202 | type?: types.ArgumentType<T>,
|
203 | isOptional?: boolean
|
204 | ): this;
|
205 |
|
206 | addOptionalVariadicPositionalParam<T>(
|
207 | name: string,
|
208 | description?: string,
|
209 | defaultValue?: T[],
|
210 | type?: types.ArgumentType<T>
|
211 | ): this;
|
212 |
|
213 | addFlag(name: string, description?: string): this;
|
214 | }
|
215 |
|
216 | export interface ParamDefinition<T> {
|
217 | name: string;
|
218 | defaultValue?: T;
|
219 | type: types.ArgumentType<T>;
|
220 | description?: string;
|
221 | isOptional: boolean;
|
222 | isFlag: boolean;
|
223 | isVariadic: boolean;
|
224 | }
|
225 |
|
226 | export interface OptionalParamDefinition<T> extends ParamDefinition<T> {
|
227 | defaultValue: T;
|
228 | isOptional: true;
|
229 | }
|
230 |
|
231 | export interface ParamDefinitionsMap {
|
232 | [paramName: string]: ParamDefinition<any>;
|
233 | }
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 | export interface BuidlerArguments {
|
245 | network?: string;
|
246 | showStackTraces: boolean;
|
247 | version: boolean;
|
248 | help: boolean;
|
249 | emoji: boolean;
|
250 | config?: string;
|
251 | verbose: boolean;
|
252 | maxMemory?: number;
|
253 | }
|
254 |
|
255 | export type BuidlerParamDefinitions = {
|
256 | [param in keyof Required<BuidlerArguments>]: OptionalParamDefinition<
|
257 | BuidlerArguments[param]
|
258 | >;
|
259 | };
|
260 |
|
261 | export interface TaskDefinition extends ConfigurableTaskDefinition {
|
262 | readonly name: string;
|
263 | readonly description?: string;
|
264 | readonly action: ActionType<TaskArguments>;
|
265 | readonly isInternal: boolean;
|
266 |
|
267 |
|
268 |
|
269 | readonly paramDefinitions: ParamDefinitionsMap;
|
270 |
|
271 | readonly positionalParamDefinitions: Array<ParamDefinition<any>>;
|
272 | }
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 | export type TaskArguments = any;
|
289 |
|
290 | export type RunTaskFunction = (
|
291 | name: string,
|
292 | taskArguments?: TaskArguments
|
293 | ) => Promise<any>;
|
294 |
|
295 | export interface RunSuperFunction<ArgT extends TaskArguments> {
|
296 | (taskArguments?: ArgT): Promise<any>;
|
297 | isDefined: boolean;
|
298 | }
|
299 |
|
300 | export type ActionType<ArgsT extends TaskArguments> = (
|
301 | taskArgs: ArgsT,
|
302 | env: BuidlerRuntimeEnvironment,
|
303 | runSuper: RunSuperFunction<ArgsT>
|
304 | ) => Promise<any>;
|
305 |
|
306 | export interface EthereumProvider extends EventEmitter {
|
307 | send(method: string, params?: any[]): Promise<any>;
|
308 | }
|
309 |
|
310 |
|
311 | export type IEthereumProvider = EthereumProvider;
|
312 |
|
313 | export interface Network {
|
314 | name: string;
|
315 | config: NetworkConfig;
|
316 | provider: EthereumProvider;
|
317 | }
|
318 |
|
319 | export interface BuidlerRuntimeEnvironment {
|
320 | readonly config: ResolvedBuidlerConfig;
|
321 | readonly buidlerArguments: BuidlerArguments;
|
322 | readonly tasks: TasksMap;
|
323 | readonly run: RunTaskFunction;
|
324 | readonly network: Network;
|
325 | readonly ethereum: EthereumProvider;
|
326 | }
|
327 |
|
328 | export interface Artifact {
|
329 | contractName: string;
|
330 | abi: any;
|
331 | bytecode: string;
|
332 | deployedBytecode: string;
|
333 | linkReferences: LinkReferences;
|
334 | deployedLinkReferences: LinkReferences;
|
335 | }
|
336 |
|
337 | export interface LinkReferences {
|
338 | [libraryFileName: string]: {
|
339 | [libraryName: string]: Array<{ length: number; start: number }>;
|
340 | };
|
341 | }
|