-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.d.ts
587 lines (585 loc) · 18.4 KB
/
index.d.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
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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
/* tslint:disable */
/* eslint-disable */
/* auto-generated by NAPI-RS */
export interface StreamConfig {
columnMapping?: ColumnMapping
eventSignature?: string
hexOutput?: HexOutput
batchSize?: number
maxBatchSize?: number
minBatchSize?: number
concurrency?: number
maxNumBlocks?: number
maxNumTransactions?: number
maxNumLogs?: number
maxNumTraces?: number
responseBytesCeiling?: number
responseBytesFloor?: number
reverse?: boolean
}
export enum HexOutput {
NoEncode = 'NoEncode',
Prefixed = 'Prefixed',
NonPrefixed = 'NonPrefixed'
}
export enum DataType {
Float64 = 'Float64',
Float32 = 'Float32',
UInt64 = 'UInt64',
UInt32 = 'UInt32',
Int64 = 'Int64',
Int32 = 'Int32'
}
export interface ColumnMapping {
block?: Record<string, DataType>
transaction?: Record<string, DataType>
log?: Record<string, DataType>
trace?: Record<string, DataType>
decodedLog?: Record<string, DataType>
}
export interface ClientConfig {
url?: string
bearerToken?: string
httpReqTimeoutMillis?: number
maxNumRetries?: number
retryBackoffMs?: number
retryBaseMs?: number
retryCeilingMs?: number
enableChecksumAddresses?: boolean
}
/**
* Returns a query for all Blocks and Transactions within the block range (from_block, to_block]
* If to_block is None then query runs to the head of the chain.
*/
export declare function presetQueryBlocksAndTransactions(fromBlock: number, toBlock?: number | undefined | null): Query
/**
* Returns a query object for all Blocks and hashes of the Transactions within the block range
* (from_block, to_block]. Also returns the block_hash and block_number fields on each Transaction
* so it can be mapped to a block. If to_block is None then query runs to the head of the chain.
*/
export declare function presetQueryBlocksAndTransactionHashes(fromBlock: number, toBlock?: number | undefined | null): Query
/**
* Returns a query object for all Logs within the block range from the given address.
* If to_block is None then query runs to the head of the chain.
*/
export declare function presetQueryLogs(contractAddress: string, fromBlock: number, toBlock?: number | undefined | null): Query
/**
* Returns a query for all Logs within the block range from the given address with a
* matching topic0 event signature. Topic0 is the keccak256 hash of the event signature.
* If to_block is None then query runs to the head of the chain.
*/
export declare function presetQueryLogsOfEvent(contractAddress: string, topic0: string, fromBlock: number, toBlock?: number | undefined | null): Query
export interface LogSelection {
/**
* Address of the contract, any logs that has any of these addresses will be returned.
* Empty means match all.
*/
address?: Array<string>
/**
* Topics to match, each member of the top level array is another array, if the nth topic matches any
* topic specified in topics[n] the log will be returned. Empty means match all.
*/
topics?: Array<Array<string>>
}
export interface TransactionSelection {
/**
* Address the transaction should originate from. If transaction.from matches any of these, the transaction
* will be returned. Keep in mind that this has an and relationship with to filter, so each transaction should
* match both of them. Empty means match all.
*/
from?: Array<string>
/**
* Address the transaction should go to. If transaction.to matches any of these, the transaction will
* be returned. Keep in mind that this has an and relationship with from filter, so each transaction should
* match both of them. Empty means match all.
*/
to?: Array<string>
/** If first 4 bytes of transaction input matches any of these, transaction will be returned. Empty means match all. */
sighash?: Array<string>
/** If tx.status matches this it will be returned. */
status?: number
/** If transaction.type matches any of these values, the transaction will be returned */
kind?: Array<number>
contractAddress?: Array<string>
}
export interface FieldSelection {
block?: Array<BlockField>
transaction?: Array<TransactionField>
log?: Array<LogField>
trace?: Array<TraceField>
}
export enum BlockField {
Number = 'Number',
Hash = 'Hash',
ParentHash = 'ParentHash',
Nonce = 'Nonce',
Sha3Uncles = 'Sha3Uncles',
LogsBloom = 'LogsBloom',
TransactionsRoot = 'TransactionsRoot',
StateRoot = 'StateRoot',
ReceiptsRoot = 'ReceiptsRoot',
Miner = 'Miner',
Difficulty = 'Difficulty',
TotalDifficulty = 'TotalDifficulty',
ExtraData = 'ExtraData',
Size = 'Size',
GasLimit = 'GasLimit',
GasUsed = 'GasUsed',
Timestamp = 'Timestamp',
Uncles = 'Uncles',
BaseFeePerGas = 'BaseFeePerGas',
BlobGasUsed = 'BlobGasUsed',
ExcessBlobGas = 'ExcessBlobGas',
ParentBeaconBlockRoot = 'ParentBeaconBlockRoot',
WithdrawalsRoot = 'WithdrawalsRoot',
Withdrawals = 'Withdrawals',
L1BlockNumber = 'L1BlockNumber',
SendCount = 'SendCount',
SendRoot = 'SendRoot',
MixHash = 'MixHash'
}
export enum TransactionField {
BlockHash = 'BlockHash',
BlockNumber = 'BlockNumber',
From = 'From',
Gas = 'Gas',
GasPrice = 'GasPrice',
Hash = 'Hash',
Input = 'Input',
Nonce = 'Nonce',
To = 'To',
TransactionIndex = 'TransactionIndex',
Value = 'Value',
V = 'V',
R = 'R',
S = 'S',
YParity = 'YParity',
MaxPriorityFeePerGas = 'MaxPriorityFeePerGas',
MaxFeePerGas = 'MaxFeePerGas',
ChainId = 'ChainId',
AccessList = 'AccessList',
MaxFeePerBlobGas = 'MaxFeePerBlobGas',
BlobVersionedHashes = 'BlobVersionedHashes',
CumulativeGasUsed = 'CumulativeGasUsed',
EffectiveGasPrice = 'EffectiveGasPrice',
GasUsed = 'GasUsed',
ContractAddress = 'ContractAddress',
LogsBloom = 'LogsBloom',
Kind = 'Kind',
Root = 'Root',
Status = 'Status',
L1Fee = 'L1Fee',
L1GasPrice = 'L1GasPrice',
L1GasUsed = 'L1GasUsed',
L1FeeScalar = 'L1FeeScalar',
GasUsedForL1 = 'GasUsedForL1'
}
export enum LogField {
Removed = 'Removed',
LogIndex = 'LogIndex',
TransactionIndex = 'TransactionIndex',
TransactionHash = 'TransactionHash',
BlockHash = 'BlockHash',
BlockNumber = 'BlockNumber',
Address = 'Address',
Data = 'Data',
Topic0 = 'Topic0',
Topic1 = 'Topic1',
Topic2 = 'Topic2',
Topic3 = 'Topic3'
}
export enum TraceField {
From = 'From',
To = 'To',
CallType = 'CallType',
Gas = 'Gas',
Input = 'Input',
Init = 'Init',
Value = 'Value',
Author = 'Author',
RewardType = 'RewardType',
BlockHash = 'BlockHash',
BlockNumber = 'BlockNumber',
Address = 'Address',
Code = 'Code',
GasUsed = 'GasUsed',
Output = 'Output',
Subtraces = 'Subtraces',
TraceAddress = 'TraceAddress',
TransactionHash = 'TransactionHash',
TransactionPosition = 'TransactionPosition',
Kind = 'Kind',
Error = 'Error'
}
export interface TraceSelection {
from?: Array<string>
to?: Array<string>
address?: Array<string>
callType?: Array<string>
rewardType?: Array<string>
kind?: Array<string>
sighash?: Array<string>
}
export interface BlockSelection {
/**
* Hash of a block, any blocks that have one of these hashes will be returned.
* Empty means match all.
*/
hash?: Array<string>
/**
* Miner address of a block, any blocks that have one of these miners will be returned.
* Empty means match all.
*/
miner?: Array<string>
}
export enum JoinMode {
Default = 0,
JoinAll = 1,
JoinNothing = 2
}
export interface Query {
/** The block to start the query from */
fromBlock: number
/**
* The block to end the query at. If not specified, the query will go until the
* end of data. Exclusive, the returned range will be [from_block..to_block).
*
* The query will return before it reaches this target block if it hits the time limit
* configured on the server. The user should continue their query by putting the
* next_block field in the response into from_block field of their next query. This implements
* pagination.
*/
toBlock?: number
/**
* List of log selections, these have an or relationship between them, so the query will return logs
* that match any of these selections.
*/
logs?: Array<LogSelection>
/**
* List of transaction selections, the query will return transactions that match any of these selections and
* it will return transactions that are related to the returned logs.
*/
transactions?: Array<TransactionSelection>
/**
* List of trace selections, the query will return traces that match any of these selections and
* it will re turn traces that are related to the returned logs.
*/
traces?: Array<TraceSelection>
/** List of block selections, the query will return blocks that match any of these selections */
blocks?: Array<BlockSelection>
/**
* Weather to include all blocks regardless of if they are related to a returned transaction or log. Normally
* the server will return only the blocks that are related to the transaction or logs in the response. But if this
* is set to true, the server will return data for all blocks in the requested range [from_block, to_block).
*/
includeAllBlocks?: boolean
/**
* Field selection. The user can select which fields they are interested in, requesting less fields will improve
* query execution time and reduce the payload size so the user should always use a minimal number of fields.
*/
fieldSelection: FieldSelection
/**
* Maximum number of blocks that should be returned, the server might return more blocks than this number but
* it won't overshoot by too much.
*/
maxNumBlocks?: number
/**
* Maximum number of transactions that should be returned, the server might return more transactions than this number but
* it won't overshoot by too much.
*/
maxNumTransactions?: number
/**
* Maximum number of logs that should be returned, the server might return more logs than this number but
* it won't overshoot by too much.
*/
maxNumLogs?: number
/**
* Maximum number of traces that should be returned, the server might return more traces than this number but
* it won't overshoot by too much.
*/
maxNumTraces?: number
/**
* Selects join mode for the query,
* Default: join in this order logs -> transactions -> traces -> blocks
* JoinAll: join everything to everything. For example if logSelection matches log0, we get the
* associated transaction of log0 and then we get associated logs of that transaction as well. Applites similarly
* to blocks, traces.
* JoinNothing: join nothing.
*/
joinMode?: JoinMode
}
/** Data relating to a single event (log) */
export interface Event {
/** Transaction that triggered this event */
transaction?: Transaction
/** Block that this event happened in */
block?: Block
/** Evm log data */
log: Log
}
/**
* Evm log object
*
* See ethereum rpc spec for the meaning of fields
*/
export interface Log {
removed?: boolean
logIndex?: number
transactionIndex?: number
transactionHash?: string
blockHash?: string
blockNumber?: number
address?: string
data?: string
topics: Array<string | undefined | null>
}
/**
* Evm transaction object
*
* See ethereum rpc spec for the meaning of fields
*/
export interface Transaction {
blockHash?: string
blockNumber?: number
from?: string
gas?: bigint
gasPrice?: bigint
hash?: string
input?: string
nonce?: bigint
to?: string
transactionIndex?: number
value?: bigint
v?: string
r?: string
s?: string
yParity?: string
maxPriorityFeePerGas?: bigint
maxFeePerGas?: bigint
chainId?: number
accessList?: Array<AccessList>
maxFeePerBlobGas?: bigint
blobVersionedHashes?: Array<string>
cumulativeGasUsed?: bigint
effectiveGasPrice?: bigint
gasUsed?: bigint
contractAddress?: string
logsBloom?: string
kind?: number
root?: string
status?: number
l1Fee?: bigint
l1GasPrice?: bigint
l1GasUsed?: bigint
l1FeeScalar?: number
gasUsedForL1?: bigint
}
/**
* Evm withdrawal object
*
* See ethereum rpc spec for the meaning of fields
*/
export interface Withdrawal {
index?: string
validatorIndex?: string
address?: string
amount?: string
}
/**
* Evm access list object
*
* See ethereum rpc spec for the meaning of fields
*/
export interface AccessList {
address?: string
storageKeys?: Array<string>
}
/**
* Evm block header object
*
* See ethereum rpc spec for the meaning of fields
*/
export interface Block {
number?: number
hash?: string
parentHash?: string
nonce?: bigint
sha3Uncles?: string
logsBloom?: string
transactionsRoot?: string
stateRoot?: string
receiptsRoot?: string
miner?: string
difficulty?: bigint
totalDifficulty?: bigint
extraData?: string
size?: bigint
gasLimit?: bigint
gasUsed?: bigint
timestamp?: number
uncles?: Array<string>
baseFeePerGas?: bigint
blobGasUsed?: bigint
excessBlobGas?: bigint
parentBeaconBlockRoot?: string
withdrawalsRoot?: string
withdrawals?: Array<Withdrawal>
l1BlockNumber?: number
sendCount?: string
sendRoot?: string
mixHash?: string
}
/**
* Evm trace object
*
* See ethereum rpc spec for the meaning of fields
*/
export interface Trace {
from?: string
to?: string
callType?: string
gas?: bigint
input?: string
init?: string
value?: bigint
author?: string
rewardType?: string
blockHash?: string
blockNumber?: number
address?: string
code?: string
gasUsed?: bigint
output?: string
subtraces?: number
traceAddress?: Array<number>
transactionHash?: string
transactionPosition?: number
kind?: string
error?: string
}
/** Decoded EVM log */
export interface DecodedEvent {
indexed: Array<DecodedSolValue>
body: Array<DecodedSolValue>
}
export interface DecodedSolValue {
val: boolean | bigint | string | Array<DecodedSolValue>
}
export interface RollbackGuard {
/** Block number of the last scanned block */
blockNumber: number
/** Block timestamp of the last scanned block */
timestamp: number
/** Block hash of the last scanned block */
hash: string
/**
* Block number of the first scanned block in memory.
*
* This might not be the first scanned block. It only includes blocks that are in memory (possible to be rolled back).
*/
firstBlockNumber: number
/**
* Parent hash of the first scanned block in memory.
*
* This might not be the first scanned block. It only includes blocks that are in memory (possible to be rolled back).
*/
firstParentHash: string
}
export interface QueryResponseData {
blocks: Array<Block>
transactions: Array<Transaction>
logs: Array<Log>
traces: Array<Trace>
}
export interface QueryResponse {
/** Current height of the source hypersync instance */
archiveHeight?: number
/**
* Next block to query for, the responses are paginated so,
* the caller should continue the query from this block if they
* didn't get responses up to the to_block they specified in the Query.
*/
nextBlock: number
/** Total time it took the hypersync instance to execute the query. */
totalExecutionTime: number
/** Response data */
data: QueryResponseData
/** Rollback guard, supposed to be used to detect rollbacks */
rollbackGuard?: RollbackGuard
}
export interface EventResponse {
/** Current height of the source hypersync instance */
archiveHeight?: number
/**
* Next block to query for, the responses are paginated so,
* the caller should continue the query from this block if they
* didn't get responses up to the to_block they specified in the Query.
*/
nextBlock: number
/** Total time it took the hypersync instance to execute the query. */
totalExecutionTime: number
/** Response data */
data: Array<Event>
/** Rollback guard, supposed to be used to detect rollbacks */
rollbackGuard?: RollbackGuard
}
export interface Events {
/** Current height of the source hypersync instance */
archiveHeight?: number
/**
* Next block to query for, the responses are paginated so,
* the caller should continue the query from this block if they
* didn't get responses up to the to_block they specified in the Query.
*/
nextBlock: number
/** Total time it took the hypersync instance to execute the query. */
totalExecutionTime: number
/** Response data */
events: Array<Event>
/** Rollback guard, supposed to be used to detect rollbacks */
rollbackGuard?: RollbackGuard
}
export declare class Decoder {
static fromSignatures(signatures: Array<string>): Decoder
static fromSignaturesWithChecksum(signatures: Array<string>, checksum: boolean): Decoder
enableChecksummedAddresses(): void
disableChecksummedAddresses(): void
decodeLogs(logs: Array<Log>): Promise<Array<DecodedEvent | undefined | null>>
decodeLogsSync(logs: Array<Log>): Array<DecodedEvent | undefined | null>
decodeEvents(events: Array<Event>): Promise<Array<DecodedEvent | undefined | null>>
decodeEventsSync(events: Array<Event>): Array<DecodedEvent | undefined | null>
}
export declare class CallDecoder {
static fromSignatures(signatures: Array<string>): CallDecoder
static fromSignaturesWithChecksum(signatures: Array<string>, checksum: boolean): CallDecoder
decodeInputs(inputs: Array<string>): Promise<Array<Array<DecodedSolValue> | undefined | null>>
decodeTransactionsInput(txs: Array<Transaction>): Promise<Array<Array<DecodedSolValue> | undefined | null>>
decodeTracesInput(traces: Array<Trace>): Promise<Array<Array<DecodedSolValue> | undefined | null>>
decodeInputsSync(inputs: Array<string>): Array<Array<DecodedSolValue> | undefined | null>
decodeTransactionsInputSync(txs: Array<Transaction>): Array<Array<DecodedSolValue> | undefined | null>
decodeTracesInputSync(traces: Array<Trace>): Array<Array<DecodedSolValue> | undefined | null>
decodeImpl(input: string): Array<DecodedSolValue> | null
}
export declare class HypersyncClient {
/** Create a new client with given config */
static new(cfg?: ClientConfig | undefined | null): HypersyncClient
/** Get the height of the source hypersync instance */
getHeight(): Promise<number>
/** Get the chain_id of the source hypersync instance */
getChainId(): Promise<number>
collect(query: Query, config: StreamConfig): Promise<QueryResponse>
collectEvents(query: Query, config: StreamConfig): Promise<EventResponse>
collectParquet(path: string, query: Query, config: StreamConfig): Promise<void>
get(query: Query): Promise<QueryResponse>
getEvents(query: Query): Promise<EventResponse>
stream(query: Query, config: StreamConfig): Promise<QueryResponseStream>
streamEvents(query: Query, config: StreamConfig): Promise<EventStream>
}
export declare class QueryResponseStream {
close(): Promise<void>
recv(): Promise<QueryResponse | null>
}
export declare class EventStream {
close(): Promise<void>
recv(): Promise<EventResponse | null>
}