-
Notifications
You must be signed in to change notification settings - Fork 298
/
types.ts
399 lines (363 loc) · 10.5 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/* eslint-disable @typescript-eslint/no-explicit-any */
import 'hardhat/types/runtime';
import 'hardhat/types/config';
import {
LinkReferences,
Artifact,
HardhatRuntimeEnvironment,
} from 'hardhat/types';
import type {BigNumber} from '@ethersproject/bignumber';
import {Signer} from '@ethersproject/abstract-signer';
export type ExtendedArtifact = {
abi: any[];
bytecode: string; // "0x"-prefixed hex string
deployedBytecode?: string; // "0x"-prefixed hex string
metadata?: string;
linkReferences?: LinkReferences;
deployedLinkReferences?: LinkReferences;
solcInput?: string;
solcInputHash?: string;
userdoc?: any;
devdoc?: any;
methodIdentifiers?: any;
storageLayout?: any;
evm?: any;
};
export interface DeployFunction {
(env: HardhatRuntimeEnvironment): Promise<void | boolean>;
skip?: (env: HardhatRuntimeEnvironment) => Promise<boolean>;
tags?: string[];
dependencies?: string[];
runAtTheEnd?: boolean;
id?: string;
}
export type Address = string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type ABI = any[]; // TODO abi
export type Log = {
blockNumber: number;
blockHash: string;
transactionHash: string;
transactionIndex: number;
logIndex: number;
removed: boolean;
address: string;
topics: string[];
data: string;
};
export type Receipt = {
from: Address;
transactionHash: string;
blockHash: string;
blockNumber: number;
transactionIndex: number;
cumulativeGasUsed: BigNumber | string | number;
gasUsed: BigNumber | string | number;
contractAddress?: string;
to?: Address;
logs?: Log[];
events?: any[];
logsBloom?: string;
byzantium?: boolean;
status?: number;
confirmations?: number;
};
export type FacetOptions = {
name?: string;
contract?: string | ArtifactData;
args?: any[];
linkedData?: any; // JSONable ?
libraries?: Libraries;
deterministic?: boolean | string;
};
export type DiamondFacets = Array<string> | Array<FacetOptions>;
export interface DiamondOptions extends TxOptions {
diamondContract?: string | ArtifactData; // TODO
diamondContractArgs?: any[];
owner?: Address;
// defaultLoopeFacet?: boolean; // TODO // always there
defaultOwnershipFacet?: boolean;
defaultCutFacet?: boolean;
facets: DiamondFacets;
log?: boolean;
libraries?: Libraries;
linkedData?: any; // JSONable ?
upgradeIndex?: number;
execute?: {
contract?:
| string
| {name: string; artifact: string | ArtifactData; args?: any[]};
methodName: string;
args: any[];
};
excludeSelectors?: {
[facetName: string]: string[];
};
deterministicSalt?: string;
facetsArgs?: any[];
}
type ProxyOptionsBase = {
owner?: Address;
upgradeIndex?: number;
proxyContract?: // default to EIP173Proxy
string | ArtifactData;
proxyArgs?: any[]; // default to ["{implementation}", "{admin}", "{data}"]
viaAdminContract?:
| string
| {
name: string;
artifact?: string | ArtifactData;
};
implementationName?: string;
checkABIConflict?: boolean;
checkProxyAdmin?: boolean;
upgradeFunction?: {
methodName: string;
upgradeArgs: any[];
};
};
export type ProxyOptions =
| (ProxyOptionsBase & {
methodName?: string;
})
| (ProxyOptionsBase & {
execute?:
| {
methodName: string;
args: any[];
}
| {
init: {
methodName: string;
args: any[];
};
onUpgrade?: {
methodName: string;
args: any[];
};
};
});
export type ArtifactData = {
abi: ABI;
bytecode: string;
deployedBytecode?: string;
metadata?: string;
methodIdentifiers?: any;
storageLayout?: any;
userdoc?: any;
devdoc?: any;
gasEstimates?: any;
};
export interface DeployOptionsBase extends TxOptions {
contract?: string | ArtifactData;
args?: any[];
skipIfAlreadyDeployed?: boolean;
linkedData?: any; // JSONable ?
libraries?: Libraries;
proxy?: boolean | string | ProxyOptions; // TODO support different type of proxies ?
}
export interface DeployOptions extends DeployOptionsBase {
deterministicDeployment?: boolean | string;
}
export interface Create2DeployOptions extends DeployOptionsBase {
salt?: string;
}
export interface CallOptions {
from?: string;
gasLimit?: string | number | BigNumber;
gasPrice?: string | BigNumber;
maxFeePerGas?: string | BigNumber;
maxPriorityFeePerGas?: string | BigNumber;
value?: string | BigNumber;
nonce?: string | number | BigNumber;
to?: string; // TODO make to and data part of a `SimpleCallOptions` interface
data?: string;
}
export interface TxOptions extends CallOptions {
from: string;
log?: boolean; // TODO string (for comment in log)
autoMine?: boolean;
estimatedGasLimit?: string | number | BigNumber;
estimateGasExtra?: string | number | BigNumber;
waitConfirmations?: number;
}
export interface Execute extends TxOptions {
name: string;
methodName: string;
args?: any[];
}
export interface SimpleTx extends TxOptions {
to: string;
}
export interface DeployedContract {
address: Address;
abi: ABI;
}
export interface DeployResult extends Deployment {
newlyDeployed: boolean;
}
export type FixtureFunc<T, O> = (
env: HardhatRuntimeEnvironment,
options?: O
) => Promise<T>;
export interface DeploymentsExtension {
deploy(name: string, options: DeployOptions): Promise<DeployResult>; // deploy a contract
diamond: {
// deploy diamond based contract (see section below)
deploy(name: string, options: DiamondOptions): Promise<DeployResult>;
};
deterministic( // return the determinsitic address as well as a function to deploy the contract, can pass the `salt` field in the option to use different salt
name: string,
options: Create2DeployOptions
): Promise<{
address: Address;
implementationAddress?: Address;
deploy(): Promise<DeployResult>;
}>;
fetchIfDifferent( // return true if new compiled code is different than deployed contract
name: string,
options: DeployOptions
): Promise<{differences: boolean; address?: string}>;
readDotFile(name: string): Promise<string>;
saveDotFile(name: string, content: string): Promise<void>;
deleteDotFile(name: string): Promise<void>;
save(name: string, deployment: DeploymentSubmission): Promise<void>; // low level save of deployment
delete(name: string): Promise<void>;
get(name: string): Promise<Deployment>; // fetch a deployment by name, throw if not existing
getOrNull(name: string): Promise<Deployment | null>; // fetch deployment by name, return null if not existing
getDeploymentsFromAddress(address: string): Promise<Deployment[]>;
all(): Promise<{[name: string]: Deployment}>; // return all deployments
getArtifact(name: string): Promise<Artifact>; // return a hardhat artifact (compiled contract without deployment)
getExtendedArtifact(name: string): Promise<ExtendedArtifact>; // return a extended artifact (with more info) (compiled contract without deployment)
run( // execute deployment scripts
tags?: string | string[],
options?: {
resetMemory?: boolean;
deletePreviousDeployments?: boolean;
writeDeploymentsToFiles?: boolean;
export?: string;
exportAll?: string;
}
): Promise<{[name: string]: Deployment}>;
fixture( // execute deployment as fixture for test // use evm_snapshot to revert back
tags?: string | string[],
options?: {fallbackToGlobal?: boolean; keepExistingDeployments?: boolean}
): Promise<{[name: string]: Deployment}>;
createFixture<T, O>( // execute a function as fixture using evm_snaphost to revert back each time
func: FixtureFunc<T, O>,
id?: string
): (options?: O) => Promise<T>;
log(...args: any[]): void; // log data only if log enabled (disabled in test fixture)
getNetworkName(): string;
getGasUsed(): number;
execute( // execute function call on contract
name: string,
options: TxOptions,
methodName: string,
...args: any[]
): Promise<Receipt>;
rawTx(tx: SimpleTx): Promise<Receipt>; // execute a simple transaction
catchUnknownSigner( // you can wrap other function with this function and it will catch failure due to missing signer with the details of the tx to be executed
action: Promise<any> | (() => Promise<any>),
options?: {log?: boolean}
): Promise<null | {
from: string;
to?: string;
value?: string;
data?: string;
}>;
read( // make a read-only call to a contract
name: string,
options: CallOptions,
methodName: string,
...args: any[]
): Promise<any>;
read(name: string, methodName: string, ...args: any[]): Promise<any>;
getSigner(address: string): Promise<Signer>;
// rawCall(to: Address, data: string): Promise<any>; // TODO ?
}
export interface ContractExport {
address: string;
abi: any[];
linkedData?: any;
}
export interface Export {
chainId: string;
name: string;
contracts: {[name: string]: ContractExport};
}
export type MultiExport = {
[chainId: string]: Export[];
};
export type Libraries = {[libraryName: string]: Address};
export enum FacetCutAction {
Add,
Replace,
Remove,
}
export type FacetCut = Facet & {
action: FacetCutAction;
};
export type Facet = {
facetAddress: string;
functionSelectors: string[];
};
export interface DeploymentSubmission {
abi: ABI;
address: Address; // used to override receipt.contractAddress (useful for proxies)
receipt?: Receipt;
transactionHash?: string;
history?: Deployment[];
implementation?: string;
args?: any[];
linkedData?: any;
solcInput?: string;
solcInputHash?: string;
metadata?: string;
bytecode?: string;
deployedBytecode?: string;
userdoc?: any;
devdoc?: any;
methodIdentifiers?: any;
facets?: Facet[];
execute?: {
methodName: string;
args: any[];
};
storageLayout?: any;
libraries?: Libraries;
gasEstimates?: any;
factoryDeps?: string[];
}
// export type LibraryReferences = {
// [filepath: string]: { [name: string]: { length: number; start: number }[] };
// };
export interface Deployment {
address: Address;
abi: ABI;
receipt?: Receipt;
transactionHash?: string;
history?: Deployment[];
numDeployments?: number;
implementation?: string;
args?: any[];
linkedData?: any;
solcInputHash?: string;
metadata?: string;
bytecode?: string;
deployedBytecode?: string;
libraries?: Libraries;
userdoc?: any;
devdoc?: any;
methodIdentifiers?: any;
facets?: Facet[];
storageLayout?: any;
gasEstimates?: any;
factoryDeps?: string[];
}
export interface DeterministicDeploymentInfo {
factory: string;
deployer: string;
funding: string;
signedTx: string;
}