rocketh 0.15.15 → 0.16.0

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 (37) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/cli.js +1 -1
  3. package/dist/cli.js.map +1 -1
  4. package/dist/environment/deployment-store.d.ts +3 -0
  5. package/dist/environment/deployment-store.d.ts.map +1 -0
  6. package/dist/environment/deployment-store.js +49 -0
  7. package/dist/environment/deployment-store.js.map +1 -0
  8. package/dist/environment/utils/artifacts.d.ts +4 -4
  9. package/dist/executor/index.d.ts +15 -6
  10. package/dist/executor/index.d.ts.map +1 -1
  11. package/dist/executor/index.js +39 -316
  12. package/dist/executor/index.js.map +1 -1
  13. package/dist/index.d.ts +9 -7
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +8 -7
  16. package/dist/index.js.map +1 -1
  17. package/dist/internal/logging.d.ts +1 -1
  18. package/dist/internal/logging.d.ts.map +1 -1
  19. package/package.json +9 -12
  20. package/src/cli.ts +2 -1
  21. package/src/environment/deployment-store.ts +72 -0
  22. package/src/executor/index.ts +89 -398
  23. package/src/index.ts +10 -11
  24. package/src/environment/deployments.ts +0 -135
  25. package/src/environment/index.ts +0 -696
  26. package/src/environment/providers/BaseProvider.ts +0 -13
  27. package/src/environment/providers/TransactionHashTracker.ts +0 -22
  28. package/src/environment/utils/artifacts.ts +0 -176
  29. package/src/environment/utils/chains.ts +0 -192
  30. package/src/executor/setup.test.ts +0 -151
  31. package/src/internal/logging.ts +0 -80
  32. package/src/internal/types.ts +0 -5
  33. package/src/types.ts +0 -601
  34. package/src/utils/eth.ts +0 -96
  35. package/src/utils/extensions.test.ts +0 -53
  36. package/src/utils/extensions.ts +0 -72
  37. package/src/utils/json.ts +0 -33
package/src/types.ts DELETED
@@ -1,601 +0,0 @@
1
- import type {Abi, AbiConstructor, AbiError, AbiEvent, AbiFallback, AbiFunction, AbiReceive, Narrow} from 'abitype';
2
- import {
3
- EIP1193Account,
4
- EIP1193DATA,
5
- EIP1193ProviderWithoutEvents,
6
- EIP1193QUANTITY,
7
- EIP1193SignerProvider,
8
- EIP1193TransactionReceipt,
9
- EIP1193WalletProvider,
10
- } from 'eip-1193';
11
- import type {Address, Chain, DeployContractParameters} from 'viem';
12
- import {TransactionHashTracker} from './environment/providers/TransactionHashTracker.js';
13
- import {ProgressIndicator} from './internal/logging.js';
14
-
15
- export type DeployScriptFunction<
16
- NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
17
- Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
18
- ArgumentsTypes = undefined,
19
- Deployments extends UnknownDeployments = UnknownDeployments,
20
- Extra extends Record<string, unknown> = Record<string, unknown>
21
- > = (env: Environment<NamedAccounts, Data, Deployments, Extra>, args?: ArgumentsTypes) => Promise<void | boolean>;
22
-
23
- export interface DeployScriptModule<
24
- NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
25
- Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
26
- ArgumentsTypes = undefined,
27
- Deployments extends UnknownDeployments = UnknownDeployments,
28
- Extra extends Record<string, unknown> = Record<string, unknown>
29
- > {
30
- (env: Environment<NamedAccounts, Data, Deployments, Extra>, args?: ArgumentsTypes): Promise<void | boolean>;
31
- tags?: string[];
32
- dependencies?: string[];
33
- runAtTheEnd?: boolean;
34
- id?: string;
35
- }
36
-
37
- export type ScriptCallback<
38
- NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
39
- Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
40
- Deployments extends UnknownDeployments = UnknownDeployments,
41
- Extra extends Record<string, unknown> = Record<string, unknown>
42
- > = (env: Environment<NamedAccounts, Data, Deployments, Extra>) => Promise<void>;
43
-
44
- /**
45
- * Utility type to extract the return value from a higher-order function
46
- * For functions of type (firstParam: T) => (...args: any[]) => V or (firstParam: T) => V
47
- */
48
- export type ExtractReturnFunction<T> = T extends (first: any) => infer Return ? Return : never;
49
-
50
- /**
51
- * Utility type to transform an object of higher-order functions by extracting their return types
52
- * This handles both regular functions and getter functions
53
- */
54
- export type CurriedFunctions<T> = {
55
- [K in keyof T]: ExtractReturnFunction<T[K]>;
56
- };
57
-
58
- /**
59
- * Type for the enhanced environment proxy that includes both the original environment
60
- * and the curried functions
61
- */
62
- export type EnhancedEnvironment<
63
- NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
64
- Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
65
- Deployments extends UnknownDeployments = UnknownDeployments,
66
- Extensions extends Record<
67
- string,
68
- (env: Environment<NamedAccounts, Data, Deployments>, ...args: any[]) => any
69
- > = Record<string, (env: Environment<NamedAccounts, Data, Deployments>, ...args: any[]) => any>,
70
- Extra extends Record<string, unknown> = Record<string, unknown>
71
- > = Environment<NamedAccounts, Data, Deployments, Extra> & CurriedFunctions<Extensions>;
72
-
73
- /**
74
- * Type for a deploy script function that receives an enhanced environment
75
- */
76
- export type EnhancedDeployScriptFunction<
77
- NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
78
- Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
79
- ArgumentsTypes = undefined,
80
- Deployments extends UnknownDeployments = UnknownDeployments,
81
- Functions extends Record<
82
- string,
83
- (env: Environment<NamedAccounts, Data, Deployments>, ...args: any[]) => any
84
- > = Record<string, (env: Environment<NamedAccounts, Data, Deployments>, ...args: any[]) => any>,
85
- Extra extends Record<string, unknown> = Record<string, unknown>
86
- > = (
87
- env: EnhancedEnvironment<NamedAccounts, Data, Deployments, Functions, Extra>,
88
- args?: ArgumentsTypes
89
- ) => Promise<void | boolean>;
90
-
91
- type ChainBlockExplorer = {
92
- name: string;
93
- url: string;
94
- apiUrl?: string | undefined;
95
- };
96
- type ChainContract = {
97
- address: Address;
98
- blockCreated?: number | undefined;
99
- };
100
-
101
- type ChainNativeCurrency = {
102
- name: string;
103
- /** 2-6 characters long */
104
- symbol: string;
105
- decimals: number;
106
- };
107
-
108
- type ChainRpcUrls = {
109
- http: readonly string[];
110
- webSocket?: readonly string[] | undefined;
111
- };
112
-
113
- /**
114
- * @description Combines members of an intersection into a readable type.
115
- *
116
- * @see {@link https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg}
117
- * @example
118
- * Prettify<{ a: string } & { b: string } & { c: number, d: bigint }>
119
- * => { a: string, b: string, c: number, d: bigint }
120
- */
121
- type Prettify<T> = {
122
- [K in keyof T]: T[K];
123
- } & {};
124
-
125
- export type ChainInfo = {
126
- /** ID in number form */
127
- id: number;
128
- /** Human-readable name */
129
- name: string;
130
- /** Collection of block explorers */
131
- blockExplorers?:
132
- | {
133
- [key: string]: ChainBlockExplorer;
134
- default: ChainBlockExplorer;
135
- }
136
- | undefined;
137
- /** Collection of contracts */
138
- contracts?:
139
- | Prettify<
140
- {
141
- [key: string]: ChainContract | {[sourceId: number]: ChainContract | undefined} | undefined;
142
- } & {
143
- ensRegistry?: ChainContract | undefined;
144
- ensUniversalResolver?: ChainContract | undefined;
145
- multicall3?: ChainContract | undefined;
146
- }
147
- >
148
- | undefined;
149
- /** Currency used by chain */
150
- nativeCurrency: ChainNativeCurrency;
151
- /** Collection of RPC endpoints */
152
- rpcUrls: {
153
- [key: string]: ChainRpcUrls;
154
- default: ChainRpcUrls;
155
- };
156
- /** Source Chain ID (ie. the L1 chain) */
157
- sourceId?: number | undefined;
158
- /** Flag for test networks */
159
- testnet?: boolean | undefined;
160
-
161
- chainType?: 'zksync' | 'op-stack' | 'celo' | 'default';
162
-
163
- genesisHash?: string;
164
-
165
- properties?: Record<string, JSONTypePlusBigInt>;
166
-
167
- // this will bring in the following when reconstructed from the data above
168
-
169
- // /** Custom chain data. */
170
- // custom?: any;
171
-
172
- // /**
173
- // * Modifies how chain data structures (ie. Blocks, Transactions, etc)
174
- // * are formatted & typed.
175
- // */
176
- // formatters?: any | undefined;
177
- // /** Modifies how data (ie. Transactions) is serialized. */
178
- // serializers?: any | undefined;
179
- // /** Modifies how fees are derived. */
180
- // fees?: any | undefined;
181
- };
182
-
183
- export type NamedAccountExecuteFunction<
184
- NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
185
- Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
186
- > = <ArgumentsType = undefined, Deployments extends UnknownDeployments = UnknownDeployments>(
187
- callback: DeployScriptFunction<NamedAccounts, Data, ArgumentsType, Deployments>,
188
- options: {tags?: string[]; dependencies?: string[]; id?: string}
189
- ) => DeployScriptModule<NamedAccounts, Data, ArgumentsType, Deployments>;
190
-
191
- export interface UntypedRequestArguments {
192
- readonly method: string;
193
- readonly params?: readonly unknown[] | object;
194
- }
195
- export type UntypedEIP1193Provider = {
196
- request(requestArguments: UntypedRequestArguments): Promise<unknown>;
197
- };
198
-
199
- export type ConfigOverrides = {
200
- deployments?: string;
201
- scripts?: string | string[];
202
- };
203
-
204
- export type Create2DeterministicDeploymentInfo = {
205
- factory: `0x${string}`;
206
- deployer: `0x${string}`;
207
- funding: string;
208
- signedTx: `0x${string}`;
209
- };
210
-
211
- export type Create3DeterministicDeploymentInfo = {
212
- salt?: `0x${string}`;
213
- factory: `0x${string}`;
214
- bytecode: `0x${string}`;
215
- proxyBytecode: `0x${string}`;
216
- };
217
-
218
- export type DeterministicDeploymentInfo =
219
- | Create2DeterministicDeploymentInfo
220
- | {
221
- create2?: Create2DeterministicDeploymentInfo;
222
- create3?: Create3DeterministicDeploymentInfo;
223
- };
224
-
225
- export type ChainUserConfig = {
226
- readonly rpcUrl?: string;
227
- readonly tags?: readonly string[];
228
- readonly deterministicDeployment?: DeterministicDeploymentInfo;
229
- readonly info?: ChainInfo;
230
- readonly pollingInterval?: number;
231
- readonly properties?: Record<string, JSONTypePlusBigInt>;
232
- };
233
-
234
- export type ChainConfig = {
235
- readonly rpcUrl: string;
236
- readonly tags: readonly string[];
237
- readonly deterministicDeployment: DeterministicDeploymentInfo;
238
- readonly info: ChainInfo;
239
- readonly pollingInterval: number;
240
- readonly properties: Record<string, JSONTypePlusBigInt>;
241
- };
242
-
243
- export type DeploymentEnvironmentConfig = {
244
- readonly chain?: string | number;
245
- readonly scripts?: string | readonly string[];
246
- readonly overrides?: Omit<ChainUserConfig, 'info'>;
247
- };
248
-
249
- export type Chains = {
250
- readonly [idOrName: number | string]: ChainUserConfig;
251
- };
252
-
253
- export type SignerProtocolFunction = (protocolString: string) => Promise<Signer>;
254
- export type SignerProtocol = {
255
- getSigner: SignerProtocolFunction;
256
- };
257
-
258
- export type UserConfig<
259
- NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
260
- Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
261
- > = {
262
- readonly environments?: {readonly [name: string]: DeploymentEnvironmentConfig};
263
- readonly chains?: Chains;
264
- readonly defaultChainProperties?: Record<string, JSONTypePlusBigInt>;
265
- readonly deployments?: string;
266
- readonly scripts?: string | readonly string[];
267
- readonly accounts?: NamedAccounts;
268
- readonly data?: Data;
269
- readonly signerProtocols?: Record<string, SignerProtocolFunction>;
270
- readonly defaultPollingInterval?: number;
271
- };
272
-
273
- export type ResolvedUserConfig<
274
- NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
275
- Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
276
- > = UserConfig & {
277
- readonly deployments: string;
278
- readonly scripts: readonly string[];
279
- readonly defaultPollingInterval: number;
280
- };
281
-
282
- export type ExecutionParams<Extra extends Record<string, unknown> = Record<string, unknown>> = {
283
- environment?: string | {fork: string};
284
- tags?: string[];
285
- saveDeployments?: boolean;
286
- askBeforeProceeding?: boolean;
287
- reportGasUse?: boolean;
288
- defaultPollingInterval?: number;
289
- extra?: Extra;
290
- logLevel?: number;
291
- provider?: EIP1193ProviderWithoutEvents;
292
- config?: ConfigOverrides;
293
- };
294
-
295
- export type {Abi, AbiConstructor, AbiError, AbiEvent, AbiFallback, AbiFunction, AbiReceive};
296
- export type Libraries = {readonly [libraryName: string]: EIP1193Account};
297
-
298
- export type GasEstimate = 'infinite' | `${number}`;
299
- export type CreationGasEstimate = {
300
- readonly codeDepositCost: GasEstimate;
301
- readonly executionCost: GasEstimate;
302
- readonly totalCost: GasEstimate;
303
- };
304
-
305
- export type GasEstimates = {
306
- readonly creation?: CreationGasEstimate;
307
- readonly external?: {
308
- readonly [signature: string]: GasEstimate;
309
- };
310
- readonly internal?: {
311
- readonly [signature: string]: GasEstimate;
312
- };
313
- };
314
-
315
- export type Storage = {
316
- readonly astId: number;
317
- readonly contract: string; // canonical name <path>:<name>
318
- readonly label: string; // variable name
319
- readonly offset: number;
320
- readonly slot: `${number}`; // slot bytes32
321
- readonly type: string; // "t_mapping(t_uint256,t_struct(Cell)12382_storage)"
322
- };
323
- export type TypeDef = {
324
- readonly encoding: 'inplace' | string; // TODO
325
- readonly label: 'address' | 'byte24' | string; // TODO
326
- readonly numberOfBytes: `${number}`;
327
- readonly key?: string; // ref to another typedef
328
- readonly value?: string;
329
- readonly members?: readonly Storage[];
330
- };
331
-
332
- export type DevEventDoc = {
333
- readonly details?: string;
334
- readonly params?: {readonly [name: string]: string};
335
- };
336
-
337
- export type DevErrorDoc = {
338
- readonly details?: string; // TODO check if it can exists
339
- readonly params?: {readonly [name: string]: string};
340
- };
341
-
342
- export type DevMethodDoc = {
343
- readonly details?: string; // TODO check if it can exists
344
- readonly params?: {readonly [name: string]: string};
345
- readonly returns?: {
346
- readonly [key: string | `_${number}`]: string; // description
347
- };
348
- };
349
-
350
- export type NoticeUserDoc = {
351
- readonly notice?: string;
352
- };
353
-
354
- export type DevDoc = {
355
- readonly events?: {
356
- [signature: string]: DevEventDoc;
357
- };
358
- readonly errors?: {
359
- [signature: string]: readonly DevErrorDoc[];
360
- };
361
- readonly methods: {
362
- [signature: string]: DevMethodDoc;
363
- };
364
- readonly kind?: 'dev';
365
- readonly version?: number;
366
- readonly title?: string;
367
- readonly author?: string;
368
- };
369
-
370
- export type UserDoc = {
371
- readonly events?: {
372
- readonly [signature: string]: NoticeUserDoc;
373
- };
374
- readonly errors?: {
375
- readonly [signature: string]: readonly NoticeUserDoc[];
376
- };
377
- readonly kind?: 'user';
378
- readonly methods: {
379
- readonly [signature: string]: NoticeUserDoc;
380
- };
381
- readonly version?: number;
382
- readonly notice?: string;
383
- };
384
-
385
- export type JSONTypePlusBigInt =
386
- | bigint
387
- | string
388
- | number
389
- | boolean
390
- | null
391
- | JSONTypePlusBigInt[]
392
- | {[key: string]: JSONTypePlusBigInt};
393
- export type LinkedData = Record<string, JSONTypePlusBigInt>;
394
-
395
- export type StorageLayout = {
396
- readonly storage: readonly Storage[];
397
- readonly types: {
398
- readonly [name: string]: TypeDef;
399
- } | null;
400
- };
401
-
402
- export type MinimalDeployment<TAbi extends Abi = Abi> = {
403
- readonly address: EIP1193Account;
404
- readonly abi: Narrow<TAbi>;
405
- };
406
-
407
- export type Deployment<TAbi extends Abi> = MinimalDeployment<TAbi> & {
408
- readonly bytecode: EIP1193DATA;
409
- readonly argsData: EIP1193DATA;
410
- readonly metadata: string;
411
-
412
- readonly transaction?: {
413
- readonly hash: EIP1193DATA;
414
- readonly origin?: EIP1193Account;
415
- readonly nonce?: EIP1193DATA;
416
- };
417
- readonly receipt?: {
418
- blockHash: EIP1193DATA;
419
- blockNumber: EIP1193QUANTITY;
420
- transactionIndex: EIP1193QUANTITY;
421
- };
422
- readonly numDeployments?: number;
423
- readonly libraries?: Libraries;
424
- readonly linkedData?: LinkedData;
425
- readonly deployedBytecode?: EIP1193DATA;
426
- readonly linkReferences?: any; // TODO
427
- readonly deployedLinkReferences?: any; // TODO
428
- readonly contractName?: string;
429
- readonly sourceName?: string; // relative path
430
- readonly devdoc?: DevDoc;
431
- readonly evm?: {
432
- readonly gasEstimates?: GasEstimates | null;
433
- } & any;
434
- readonly storageLayout?: StorageLayout;
435
- readonly userdoc?: UserDoc;
436
- } & Record<string, unknown>;
437
-
438
- export type Artifact<TAbi extends Abi = Abi> = {
439
- readonly abi: TAbi;
440
- readonly bytecode: EIP1193DATA;
441
- readonly metadata: string;
442
- readonly deployedBytecode?: EIP1193DATA;
443
- readonly linkReferences?: any; // TODO
444
- readonly deployedLinkReferences?: any; // TODO
445
- readonly contractName?: string;
446
- readonly sourceName?: string; // relative path
447
- readonly devdoc?: DevDoc;
448
- readonly evm?: {
449
- readonly gasEstimates?: GasEstimates | null;
450
- } & any;
451
- readonly storageLayout?: StorageLayout;
452
- readonly userdoc?: UserDoc;
453
- };
454
-
455
- export type AccountDefinition = EIP1193Account | string | number;
456
-
457
- export type AccountType =
458
- | AccountDefinition
459
- | {
460
- [networkOrChainId: string | number]: AccountDefinition;
461
- };
462
-
463
- export type ResolvedAccount = {
464
- address: EIP1193Account;
465
- } & Signer;
466
-
467
- export type UnknownDeployments = Record<string, Deployment<Abi>>;
468
- export type UnknownNamedAccounts = {
469
- [name: string]: EIP1193Account;
470
- };
471
-
472
- export type UnresolvedUnknownNamedAccounts = {
473
- [name: string]: AccountType;
474
- };
475
-
476
- export type ResolvedNamedAccounts<T extends UnresolvedUnknownNamedAccounts> = {
477
- [Property in keyof T]: EIP1193Account;
478
- };
479
-
480
- export type DataType<T> = {
481
- [networkOrChainId: string | number]: T;
482
- };
483
-
484
- export type UnknownData = {
485
- [name: string]: unknown;
486
- };
487
-
488
- export type UnresolvedNetworkSpecificData = {
489
- [name: string]: DataType<unknown>;
490
- };
491
-
492
- export type ResolvedNetworkSpecificData<T extends UnresolvedNetworkSpecificData> = {
493
- [Property in keyof T]: T[Property] extends DataType<infer U> ? U : never;
494
- };
495
-
496
- export type Signer =
497
- | {type: 'signerOnly'; signer: EIP1193SignerProvider}
498
- | {type: 'remote'; signer: EIP1193ProviderWithoutEvents}
499
- | {type: 'wallet'; signer: EIP1193WalletProvider};
500
-
501
- export type ResolvedNamedSigners<T extends UnknownNamedAccounts> = {
502
- [Property in keyof T]: Signer;
503
- };
504
-
505
- export type UnknownDeploymentsAcrossNetworks = Record<string, UnknownDeployments>;
506
-
507
- export type ResolvedExecutionParams<Extra extends Record<string, unknown> = Record<string, unknown>> = {
508
- readonly environment: {
509
- readonly name: string;
510
- readonly tags: readonly string[];
511
- readonly fork?: boolean;
512
- readonly deterministicDeployment: DeterministicDeploymentInfo;
513
- };
514
- readonly chain: ChainInfo;
515
- readonly tags: readonly string[];
516
- readonly saveDeployments: boolean;
517
- readonly askBeforeProceeding: boolean;
518
- readonly reportGasUse: boolean;
519
- readonly pollingInterval: number;
520
- readonly extra?: Extra;
521
- readonly logLevel: number;
522
- readonly provider: EIP1193ProviderWithoutEvents;
523
- readonly scripts: readonly string[];
524
- };
525
-
526
- export interface Environment<
527
- NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
528
- Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
529
- Deployments extends UnknownDeployments = UnknownDeployments,
530
- Extra extends Record<string, unknown> = Record<string, unknown>
531
- > {
532
- readonly name: string;
533
- readonly context: {
534
- readonly saveDeployments: boolean;
535
- };
536
- readonly tags: {readonly [tag: string]: boolean};
537
- readonly network: {
538
- readonly chain: Chain;
539
- readonly provider: TransactionHashTracker;
540
- readonly fork?: boolean;
541
- readonly deterministicDeployment: DeterministicDeploymentInfo;
542
- };
543
- readonly deployments: Deployments;
544
- readonly namedAccounts: ResolvedNamedAccounts<NamedAccounts>;
545
- readonly data: ResolvedNetworkSpecificData<Data>;
546
- readonly namedSigners: ResolvedNamedSigners<ResolvedNamedAccounts<NamedAccounts>>;
547
- readonly unnamedAccounts: EIP1193Account[];
548
- // unnamedSigners: {type: 'remote'; signer: EIP1193ProviderWithoutEvents}[];
549
- readonly addressSigners: {[name: `0x${string}`]: Signer};
550
- save<TAbi extends Abi = Abi>(
551
- name: string,
552
- deployment: Deployment<TAbi>,
553
- options?: {doNotCountAsNewDeployment?: boolean}
554
- ): Promise<Deployment<TAbi>>;
555
- savePendingDeployment<TAbi extends Abi = Abi>(pendingDeployment: PendingDeployment<TAbi>): Promise<Deployment<TAbi>>;
556
- savePendingExecution(pendingExecution: PendingExecution): Promise<EIP1193TransactionReceipt>;
557
- get<TAbi extends Abi>(name: string): Deployment<TAbi>;
558
- getOrNull<TAbi extends Abi>(name: string): Deployment<TAbi> | null;
559
- fromAddressToNamedABI<TAbi extends Abi>(address: Address): {mergedABI: TAbi; names: string[]};
560
- fromAddressToNamedABIOrNull<TAbi extends Abi>(address: Address): {mergedABI: TAbi; names: string[]} | null;
561
- showMessage(message: string): void;
562
- showProgress(message?: string): ProgressIndicator;
563
-
564
- hasMigrationBeenDone(id: string): boolean;
565
- readonly extra?: Extra;
566
- }
567
-
568
- export type DeploymentConstruction<TAbi extends Abi> = Omit<
569
- DeployContractParameters<TAbi>,
570
- 'bytecode' | 'account' | 'abi' | 'chain'
571
- > & {account: string | EIP1193Account; artifact: Artifact<TAbi>};
572
-
573
- export type PartialDeployment<TAbi extends Abi = Abi> = Artifact<TAbi> & {
574
- argsData: EIP1193DATA;
575
- libraries?: Libraries;
576
- linkedData?: LinkedData;
577
- };
578
-
579
- export type PendingDeployment<TAbi extends Abi = Abi> = {
580
- type: 'deployment';
581
- name?: string;
582
- transaction: {
583
- hash: `0x${string}`;
584
- nonce?: `0x${string}`;
585
- origin?: `0x${string}`;
586
- };
587
- partialDeployment: PartialDeployment<TAbi>;
588
- expectedAddress?: `0x${string}`; // TODO we could make that a event specification so we can get address from factory event
589
- };
590
-
591
- export type PendingExecution = {
592
- type: 'execution';
593
- description?: string;
594
- transaction: {
595
- hash: `0x${string}`;
596
- nonce?: `0x${string}`;
597
- origin?: `0x${string}`;
598
- };
599
- };
600
-
601
- export type PendingTransaction = PendingDeployment | PendingExecution;
package/src/utils/eth.ts DELETED
@@ -1,96 +0,0 @@
1
- import {EIP1193BlockTag, EIP1193ProviderWithoutEvents, EIP1193QUANTITY} from 'eip-1193';
2
-
3
- function avg(arr: bigint[]) {
4
- const sum = arr.reduce((a: bigint, v: bigint) => a + v);
5
- return sum / BigInt(arr.length);
6
- }
7
-
8
- export type EstimateGasPriceOptions = {
9
- blockCount: number;
10
- newestBlock: EIP1193BlockTag;
11
- rewardPercentiles: number[];
12
- };
13
-
14
- export type RoughEstimateGasPriceOptions = {
15
- blockCount: number;
16
- newestBlock: EIP1193BlockTag;
17
- rewardPercentiles: [number, number, number];
18
- };
19
-
20
- export type GasPrice = {maxFeePerGas: bigint; maxPriorityFeePerGas: bigint};
21
- export type EstimateGasPriceResult = GasPrice[];
22
- export type RoughEstimateGasPriceResult = {slow: GasPrice; average: GasPrice; fast: GasPrice};
23
-
24
- export async function getGasPriceEstimate(
25
- provider: EIP1193ProviderWithoutEvents,
26
- options?: Partial<EstimateGasPriceOptions>
27
- ): Promise<EstimateGasPriceResult> {
28
- const defaultOptions: EstimateGasPriceOptions = {
29
- blockCount: 20,
30
- newestBlock: 'pending',
31
- rewardPercentiles: [10, 50, 80],
32
- };
33
- const optionsResolved = options ? {...defaultOptions, ...options} : defaultOptions;
34
-
35
- const historicalBlocks = `0x${optionsResolved.blockCount.toString(16)}`;
36
-
37
- const rawFeeHistory = await provider.request({
38
- method: 'eth_feeHistory',
39
- params: [historicalBlocks as EIP1193QUANTITY, optionsResolved.newestBlock, optionsResolved.rewardPercentiles],
40
- });
41
-
42
- let blockNum = Number(rawFeeHistory.oldestBlock);
43
- const lastBlock = blockNum + rawFeeHistory.reward.length;
44
- let index = 0;
45
- const blocksHistory: {number: number; baseFeePerGas: bigint; gasUsedRatio: number; priorityFeePerGas: bigint[]}[] =
46
- [];
47
- while (blockNum < lastBlock) {
48
- blocksHistory.push({
49
- number: blockNum,
50
- baseFeePerGas: BigInt(rawFeeHistory.baseFeePerGas[index]),
51
- gasUsedRatio: Number(rawFeeHistory.gasUsedRatio[index]),
52
- priorityFeePerGas: rawFeeHistory.reward[index].map((x) => BigInt(x)),
53
- });
54
- blockNum += 1;
55
- index += 1;
56
- }
57
-
58
- const percentilePriorityFeeAverages: bigint[] = [];
59
- for (let i = 0; i < optionsResolved.rewardPercentiles.length; i++) {
60
- percentilePriorityFeeAverages.push(avg(blocksHistory.map((b) => b.priorityFeePerGas[i])));
61
- }
62
-
63
- const baseFeePerGas = BigInt(rawFeeHistory.baseFeePerGas[rawFeeHistory.baseFeePerGas.length - 1]);
64
-
65
- const result: EstimateGasPriceResult = [];
66
- for (let i = 0; i < optionsResolved.rewardPercentiles.length; i++) {
67
- result.push({
68
- maxFeePerGas: percentilePriorityFeeAverages[i] + baseFeePerGas,
69
- maxPriorityFeePerGas: percentilePriorityFeeAverages[i],
70
- });
71
- }
72
- return result;
73
- }
74
-
75
- export async function getRoughGasPriceEstimate(
76
- provider: EIP1193ProviderWithoutEvents,
77
- options?: Partial<RoughEstimateGasPriceOptions>
78
- ): Promise<RoughEstimateGasPriceResult> {
79
- const defaultOptions: EstimateGasPriceOptions = {
80
- blockCount: 20,
81
- newestBlock: 'pending',
82
- rewardPercentiles: [10, 50, 80],
83
- };
84
- const optionsResolved = options ? {...defaultOptions, ...options} : defaultOptions;
85
-
86
- if (optionsResolved.rewardPercentiles.length !== 3) {
87
- throw new Error(`rough gas estimate require 3 percentile, it defaults to [10,50,80]`);
88
- }
89
-
90
- const result = await getGasPriceEstimate(provider, optionsResolved);
91
- return {
92
- slow: result[0],
93
- average: result[1],
94
- fast: result[2],
95
- };
96
- }