UNPKG

8.44 kBPlain TextView Raw
1import { EventEmitter } from "events";
2import { DeepPartial, DeepReadonly, Omit } from "ts-essentials";
3
4import {
5 EvmMessageTrace,
6 MessageTrace,
7} from "./internal/buidler-evm/stack-traces/message-trace";
8import * as types from "./internal/core/params/argumentTypes";
9
10// Begin config types
11
12// IMPORTANT: This t.types MUST be kept in sync with the actual types.
13
14export interface CommonNetworkConfig {
15 chainId?: number;
16 from?: string;
17 gas?: "auto" | number;
18 gasPrice?: "auto" | number;
19 gasMultiplier?: number;
20}
21
22export interface BuidlerNetworkAccount {
23 privateKey: string;
24 balance: string;
25}
26
27export 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
38export interface HDAccountsConfig {
39 mnemonic: string;
40 initialIndex?: number;
41 count?: number;
42 path?: string;
43}
44
45export interface OtherAccountsConfig {
46 type: string;
47}
48
49export type NetworkConfigAccounts =
50 | "remote"
51 | string[]
52 | HDAccountsConfig
53 | OtherAccountsConfig;
54
55export interface HttpNetworkConfig extends CommonNetworkConfig {
56 url?: string;
57 timeout?: number;
58 httpHeaders?: { [name: string]: string };
59 accounts?: NetworkConfigAccounts;
60}
61
62export type NetworkConfig = BuidlerNetworkConfig | HttpNetworkConfig;
63
64export interface Networks {
65 [networkName: string]: NetworkConfig;
66}
67
68/**
69 * The project paths:
70 * * root: the project's root.
71 * * configFile: the buidler's config filepath.
72 * * cache: project's cache directory.
73 * * artifacts: artifact's directory.
74 * * sources: project's sources directory.
75 * * tests: project's tests directory.
76 */
77export interface ProjectPaths {
78 root: string;
79 configFile: string;
80 cache: string;
81 artifacts: string;
82 sources: string;
83 tests: string;
84}
85
86type EVMVersion = string;
87
88export interface SolcConfig {
89 version: string;
90 optimizer: SolcOptimizerConfig;
91 evmVersion?: EVMVersion;
92}
93
94export interface SolcOptimizerConfig {
95 enabled: boolean;
96 runs: number;
97}
98
99export interface AnalyticsConfig {
100 enabled: boolean;
101}
102
103export 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
112export interface ResolvedBuidlerConfig extends BuidlerConfig {
113 defaultNetwork: string;
114 paths: ProjectPaths;
115 networks: Networks;
116 solc: SolcConfig;
117 analytics: AnalyticsConfig;
118}
119
120// End config types
121
122export 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 * A function that receives a BuidlerRuntimeEnvironment and
135 * modify its properties or add new ones.
136 */
137export type EnvironmentExtender = (env: BuidlerRuntimeEnvironment) => void;
138
139export type ConfigExtender = (
140 config: ResolvedBuidlerConfig,
141 userConfig: DeepReadonly<BuidlerConfig>
142) => void;
143
144// NOTE: This is experimental and will be removed. Please contact our team
145// if you are planning to use it.
146export type ExperimentalBuidlerEVMMessageTraceHook = (
147 bre: BuidlerRuntimeEnvironment,
148 trace: MessageTrace,
149 isMessageTraceFromACall: boolean
150) => Promise<void>;
151
152// NOTE: This is experimental and will be removed. Please contact our team
153// if you are planning to use it.
154export type BoundExperimentalBuidlerEVMMessageTraceHook = (
155 trace: MessageTrace,
156 isMessageTraceFromACall: boolean
157) => Promise<void>;
158
159export interface TasksMap {
160 [name: string]: TaskDefinition;
161}
162
163export 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
216export 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
226export interface OptionalParamDefinition<T> extends ParamDefinition<T> {
227 defaultValue: T;
228 isOptional: true;
229}
230
231export interface ParamDefinitionsMap {
232 [paramName: string]: ParamDefinition<any>;
233}
234
235/**
236 * Buidler arguments:
237 * * network: the network to be used.
238 * * showStackTraces: flag to show stack traces.
239 * * version: flag to show buidler's version.
240 * * help: flag to show buidler's help message.
241 * * emoji:
242 * * config: used to specify buidler's config file.
243 */
244export 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
255export type BuidlerParamDefinitions = {
256 [param in keyof Required<BuidlerArguments>]: OptionalParamDefinition<
257 BuidlerArguments[param]
258 >;
259};
260
261export interface TaskDefinition extends ConfigurableTaskDefinition {
262 readonly name: string;
263 readonly description?: string;
264 readonly action: ActionType<TaskArguments>;
265 readonly isInternal: boolean;
266
267 // TODO: Rename this to something better. It doesn't include the positional
268 // params, and that's not clear.
269 readonly paramDefinitions: ParamDefinitionsMap;
270
271 readonly positionalParamDefinitions: Array<ParamDefinition<any>>;
272}
273
274/**
275 * @type TaskArguments {object-like} - the input arguments for a task.
276 *
277 * TaskArguments type is set to 'any' because it's interface is dynamic.
278 * It's impossible in TypeScript to statically specify a variadic
279 * number of fields and at the same time define specific types for\
280 * the argument values.
281 *
282 * For example, we could define:
283 * type TaskArguments = Record<string, any>;
284 *
285 * ...but then, we couldn't narrow the actual argument value's type in compile time,
286 * thus we have no other option than forcing it to be just 'any'.
287 */
288export type TaskArguments = any;
289
290export type RunTaskFunction = (
291 name: string,
292 taskArguments?: TaskArguments
293) => Promise<any>;
294
295export interface RunSuperFunction<ArgT extends TaskArguments> {
296 (taskArguments?: ArgT): Promise<any>;
297 isDefined: boolean;
298}
299
300export type ActionType<ArgsT extends TaskArguments> = (
301 taskArgs: ArgsT,
302 env: BuidlerRuntimeEnvironment,
303 runSuper: RunSuperFunction<ArgsT>
304) => Promise<any>;
305
306export interface EthereumProvider extends EventEmitter {
307 send(method: string, params?: any[]): Promise<any>;
308}
309
310// This alias is here for backwards compatibility
311export type IEthereumProvider = EthereumProvider;
312
313export interface Network {
314 name: string;
315 config: NetworkConfig;
316 provider: EthereumProvider;
317}
318
319export 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; // DEPRECATED: Use network.provider
326}
327
328export interface Artifact {
329 contractName: string;
330 abi: any;
331 bytecode: string; // "0x"-prefixed hex string
332 deployedBytecode: string; // "0x"-prefixed hex string
333 linkReferences: LinkReferences;
334 deployedLinkReferences: LinkReferences;
335}
336
337export interface LinkReferences {
338 [libraryFileName: string]: {
339 [libraryName: string]: Array<{ length: number; start: number }>;
340 };
341}