-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.d.mts
executable file
·436 lines (385 loc) · 10.7 KB
/
index.d.mts
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
import {
WebSocketProvider,
Wallet,
Contract,
Interface,
Fragment,
JsonFragment,
TransactionReceipt,
TransactionResponse,
TransactionDescription,
BigNumberish,
BytesLike,
BaseContract,
ContractInterface,
ContractEventName,
EventEmitterable,
Log,
Result,
EventFragment,
} from "ethers";
import { EventEmitter } from "node:events";
import { ChildProcess } from "node:child_process";
import { SigningKey } from "ethers";
type DevWallet = Omit<Wallet, "connect">;
type DeployedBaseContract = Omit<
BaseContract,
"target" | "connect" | "attach"
> & {
target: string;
connect(...args: Parameters<Contract["connect"]>): Contract;
attach(...args: Parameters<Contract["attach"]>): Contract;
waitForDeployment(): Promise<Contract>;
} & {
readonly __receipt: TransactionReceipt;
readonly __info: {
readonly contract: string;
readonly origin: string;
readonly bytecode: Uint8Array;
readonly libs: { [cid: string]: string };
readonly from: DevWallet;
};
};
type DeployedContract = DeployedBaseContract &
Omit<ContractInterface, keyof DeployedBaseContract> &
EventEmitterable<ContractEventName>;
type EventLike = string | EventFragment;
type InterfaceLike =
| Interface
| Contract
| (Fragment | JsonFragment | string)[];
type ExternalLink = {
file: string;
contract: string;
offsets: number[];
};
type PathLike = string | URL;
type WalletLike = string | DevWallet;
type CompiledArtifact = {
readonly type: string;
readonly contract: string;
readonly origin: string;
readonly abi: Interface;
readonly bytecode: string;
readonly links: ExternalLink[];
};
type CompiledFromSourceArtifact = CompiledArtifact & {
readonly cid: string;
readonly root: string;
readonly compiler: string;
};
type FileArtifact = CompiledFromSourceArtifact & {
readonly file: string;
};
type CodeArtifact = CompiledFromSourceArtifact & {
readonly sol: string;
};
type Artifact = CompiledArtifact | FileArtifact | CodeArtifact;
type CompileOptions = {
optimize?: boolean | number;
solcVersion?: string;
evmVersion?: string;
viaIR?: boolean;
autoHeader?: boolean;
contract?: string;
};
export function compile(
sol: string | string[],
options?: { foundry?: Foundry } & CompileOptions
): Promise<CodeArtifact>;
type ArtifactLike =
| { import: string; contract?: string }
| { bytecode: string; abi?: InterfaceLike; contract?: string }
| ({ sol: string } & CompileOptions)
| { file: string; contract?: string };
type ToConsoleLog = boolean | PathLike | ((line: string) => any);
type WalletOptions = {
ether?: BigNumberish;
};
type BuildInfo = {
date: Date;
};
type ConfirmOptions = {
silent?: boolean;
confirms?: number;
};
type Backend = "ethereum" | "optimism";
type FoundryBaseOptions = {
root?: PathLike; // default: ancestor w/foundry.toml
profile?: string; // default: "default"
forge?: string; // default: "forge" via PATH
};
type BuildEvent = {
started: Date;
root: string;
cmd: string[];
force: boolean;
profile: string;
mode: "project" | "shadow" | "compile";
};
type FoundryEventMap = {
building: [event: BuildEvent];
built: [event: BuildEvent & { sources: string[] }];
shutdown: [];
tx: [
tx: TransactionResponse,
receipt: TransactionReceipt,
desc?: TransactionDescription
];
console: [line: string];
deploy: [contract: DeployedContract];
};
export class FoundryBase extends EventEmitter {
// <FoundryEventMap> {
static profile(): string;
static root(cwd?: PathLike): Promise<string>;
static load(options?: FoundryBaseOptions): Promise<FoundryBase>;
build(force?: boolean): Promise<BuildInfo>;
compile(
sol: string | string[],
options?: CompileOptions
): Promise<CodeArtifact>;
find(options: { file: string; contract?: string }): Promise<string>;
readonly root: string;
readonly profile: string;
readonly config: {
src: string;
test: string;
out: string;
libs: string[];
remappings: string[];
};
readonly forge: string;
readonly built?: BuildInfo;
version(): Promise<string>;
on<E extends keyof FoundryEventMap>(
name: E,
fn: (...args: FoundryEventMap[E]) => any
): this;
once<E extends keyof FoundryEventMap>(
name: E,
fn: (...args: FoundryEventMap[E]) => any
): this;
}
type SolidityStandardJSONInput = {
language: string;
sources: { [cid: string]: { content: string } };
optimizer: {
enabled: boolean;
runs?: number;
};
settings: {
remappings: string[];
metadata: Record<string, any>;
evmVersion: string;
viaIR: boolean;
libraries: { [cid: string]: { [contract: string]: string } };
};
};
export type Deployable = {
gas: bigint;
gasPrice: bigint;
maxFeePerGas: bigint;
maxPriorityFeePerGas: bigint;
wei: bigint;
eth: string;
root: string;
cid: string;
linked: (ExternalLink & { cid: string; address: string })[];
compiler: string;
decodedArgs: any[];
encodedArgs: string;
deployArgs(injectPrivateKey?: boolean): string[];
deploy(options?: {
confirms?: number;
}): Promise<{ contract: Contract; receipt: TransactionReceipt }>;
json(): Promise<Readonly<SolidityStandardJSONInput>>;
verifyEtherscan(address?: string): Promise<void>;
};
type FoundryDeployerOptions = FoundryBaseOptions & {
infoLog?: ToConsoleLog; // default: true
};
export class FoundryDeployer extends FoundryBase {
static etherscanChains(): Promise<Map<bigint, string>>;
static mainnet(
privateKey?: BytesLike | SigningKey,
options?: FoundryDeployerOptions
): Promise<FoundryDeployer>;
static sepolia(
privateKey?: BytesLike | SigningKey,
options?: FoundryDeployerOptions
): Promise<FoundryDeployer>;
static load(
options: {
wallet: Wallet;
} & FoundryDeployerOptions
): Promise<FoundryDeployer>;
readonly rpc: string;
readonly chain: bigint;
readonly wallet: Wallet;
set etherscanApiKey(apiKey: string | undefined);
get etherscanApiKey(): string;
prepare(
options:
| string
| ({
args?: any[];
libs?: { [cid: string]: string };
confirms?: number;
} & ArtifactLike)
): Promise<Readonly<Deployable>>;
verifyEtherscan(options: {
json: SolidityStandardJSONInput;
address: string; // 0x...
cid?: string; // "src/File.sol:Contract"
apiKey?: string; // foundry.toml => ETHERSCAN_API_KEY
encodedArg?: string | Uint8Array;
compiler?: string; // can be semver
pollMs?: number; // default: 5sec
retry?: number; // default: 3
}): Promise<void>;
}
export class Foundry extends FoundryBase {
static of(x: DevWallet | DeployedContract): Foundry;
static launch(
options?: {
port?: number;
chain?: number;
anvil?: string;
gasLimit?: number;
blockSec?: number;
accounts?: string[];
autoClose?: boolean; // default: true
infoLog?: ToConsoleLog; // default: true = console.log()
procLog?: ToConsoleLog; // default: off
fork?: PathLike;
infiniteCallGas?: boolean; // default: false
genesisTimestamp?: number; // default: now
backend?: Backend; // default: 'ethereum'
hardfork?: string; // default: latest
} & FoundryBaseOptions
): Promise<Foundry>;
readonly anvil: string;
readonly proc: ChildProcess;
readonly provider: WebSocketProvider;
readonly wallets: Record<string, DevWallet>;
readonly accounts: Map<string, DeployedContract | DevWallet>;
readonly endpoint: string;
readonly chain: number;
readonly port: number;
readonly automine: boolean;
readonly backend: Backend;
readonly hardfork: string;
readonly started: Date;
readonly fork: string | undefined;
// note: these are silent fail on forks
nextBlock(options?: { blocks?: number; sec?: number }): Promise<void>;
setStorageValue(
address: string | DeployedContract,
slot: BigNumberish,
value: BigNumberish | Uint8Array
): Promise<void>;
setStorageBytes(
address: string | DeployedContract,
slot: BigNumberish,
value: BytesLike
): Promise<void>;
// require a wallet
requireWallet(...wallets: (WalletLike | undefined)[]): DevWallet;
randomWallet(
options?: { prefix?: string } & WalletOptions
): Promise<DevWallet>;
ensureWallet(
wallet: WalletLike,
options?: WalletOptions
): Promise<DevWallet>;
resolveArtifact(artifact: ArtifactLike): Promise<Artifact>;
// compile and deploy a contract, returns Contract with ABI
deploy(
options:
| string
| ({
from?: WalletLike;
args?: any[];
libs?: { [cid: string]: string | DeployedContract };
abis?: InterfaceLike[];
parseAllErrors?: boolean;
} & ConfirmOptions &
ArtifactLike)
): Promise<DeployedContract>;
// send a transaction promise and get a pretty print console log
confirm(
call: TransactionResponse | Promise<TransactionResponse>,
options?: ConfirmOptions & Record<string, any>
): Promise<TransactionReceipt>;
addABI(abi: Interface): void;
parseAllErrors(iface: Interface): Interface;
findEvent(event: EventLike): { abi: Interface; frag: EventFragment };
getEventResults(
logs: Log[] | TransactionReceipt | DeployedContract,
event: EventLike
): Result[];
// kill anvil (this is a bound function)
shutdown: () => Promise<void>;
}
export function mergeABI(...abis: InterfaceLike[]): Interface;
export class Node extends Map {
static root(tag?: string): Node;
static create(name: string | Node): Node;
readonly label: string;
readonly parent: Node;
readonly namehash: string;
readonly labelhash: string;
get dns(): Uint8Array;
get name(): string;
get isETH2LD(): boolean;
get depth(): number;
get nodeCount(): number;
get root(): Node;
path(includeRoot?: boolean): Node[];
find(name: string): Node | undefined;
create(name: string): Node;
child(label: string): Node;
unique(prefix?: string): Node;
scan(fn: (node: Node, level: number) => void, level?: number): void;
flat(): Node[];
print(): void;
}
type RecordQuery = {
type: "addr" | "text" | "contenthash" | "pubkey" | "name";
arg?: any;
};
type RecordResult = { rec: RecordQuery; res?: any; err?: Error };
type TORPrefix = "on" | "off" | undefined;
type RecordOptions = { multi?: boolean; ccip?: boolean; tor?: TORPrefix };
export class Resolver {
static readonly ABI: Interface;
static get(ens: Contract, node: Node): Promise<Resolver | undefined>;
constructor(node: Node, contract: Contract);
readonly node: Node;
readonly contract: Contract;
readonly base: Node;
readonly drop: number;
wild: boolean;
tor: boolean;
get address(): string;
text(key: string, options?: RecordOptions): Promise<string>;
addr(type?: number, options?: RecordOptions): Promise<string>;
contenthash(options?: RecordOptions): Promise<string>;
record(rec: RecordQuery, options?: RecordOptions): Promise<any>;
records(
rec: RecordQuery[],
options?: RecordOptions
): Promise<[records: RecordResult[], multicalled?: boolean]>;
profile(
rec?: RecordQuery[],
options?: RecordOptions
): Promise<{ [key: string]: any }>;
}
export function error_with(
message: string,
options: Object,
cause?: any
): Error;
export function to_address(x: any): string;
export function is_address(x: any): boolean;