@subsquid/portal-client 0.0.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.
@@ -0,0 +1,367 @@
1
+ import type {Select, Selector, Trues, Hex, ConditionalOmit, Simplify, PortalBlock, PortalQuery} from './common'
2
+
3
+ type AddPrefix<Prefix extends string, S> = S extends string ? `${Prefix}${Capitalize<S>}` : never
4
+
5
+ type RemovePrefix<Prefix extends string, T> = T extends `${Prefix}${infer S}` ? Uncapitalize<S> : never
6
+
7
+ type RemoveKeysPrefix<Prefix extends string, T> = {
8
+ [K in keyof T as RemovePrefix<Prefix, K>]: T[K]
9
+ }
10
+
11
+ export type BlockHeaderFields = {
12
+ number: number
13
+ hash: Hex
14
+ parentHash: Hex
15
+ timestamp: number
16
+ transactionsRoot: Hex
17
+ receiptsRoot: Hex
18
+ stateRoot: Hex
19
+ logsBloom: Hex
20
+ sha3Uncles: Hex
21
+ extraData: Hex
22
+ miner: Hex
23
+ nonce: Hex
24
+ mixHash: Hex
25
+ size: bigint
26
+ gasLimit: bigint
27
+ gasUsed: bigint
28
+ difficulty: bigint
29
+ totalDifficulty: bigint
30
+ baseFeePerGas: bigint
31
+ blobGasUsed: bigint
32
+ excessBlobGas: bigint
33
+ l1BlockNumber?: number
34
+ }
35
+
36
+ export type TransactionFields = {
37
+ transactionIndex: number
38
+ hash: Hex
39
+ nonce: number
40
+ from: Hex
41
+ to?: Hex
42
+ input: Hex
43
+ value: bigint
44
+ gas: bigint
45
+ gasPrice: bigint
46
+ maxFeePerGas?: bigint
47
+ maxPriorityFeePerGas?: bigint
48
+ v: bigint
49
+ r: Hex
50
+ s: Hex
51
+ yParity?: number
52
+ chainId?: number
53
+ sighash?: Hex
54
+ contractAddress?: Hex
55
+ gasUsed: bigint
56
+ cumulativeGasUsed: bigint
57
+ effectiveGasPrice: bigint
58
+ type: number
59
+ status: number
60
+ blobVersionedHashes: Hex[]
61
+
62
+ l1Fee?: bigint
63
+ l1FeeScalar?: number
64
+ l1GasPrice?: bigint
65
+ l1GasUsed?: bigint
66
+ l1BlobBaseFee?: bigint
67
+ l1BlobBaseFeeScalar?: number
68
+ l1BaseFeeScalar?: number
69
+ }
70
+
71
+ export type LogFields = {
72
+ logIndex: number
73
+ transactionIndex: number
74
+ transactionHash: Hex
75
+ address: Hex
76
+ data: Hex
77
+ topics: Hex[]
78
+ }
79
+
80
+ export type TraceBaseFields = {
81
+ type: string
82
+ transactionIndex: number
83
+ traceAddress: number[]
84
+ subtraces: number
85
+ error: string | null
86
+ revertReason?: string
87
+ }
88
+
89
+ export type TraceCreateFields = TraceBaseFields & {
90
+ type: 'create'
91
+ }
92
+
93
+ export type TraceCreateActionFields = {
94
+ from: Hex
95
+ value: bigint
96
+ gas: bigint
97
+ init: Hex
98
+ }
99
+
100
+ export type TraceCreateResultFields = {
101
+ gasUsed: bigint
102
+ code: Hex
103
+ address: Hex
104
+ }
105
+
106
+ export type TraceCallFields = TraceBaseFields & {
107
+ type: 'call'
108
+ }
109
+
110
+ export type TraceCallActionFields = {
111
+ callType: string
112
+ from: Hex
113
+ to: Hex
114
+ value?: bigint
115
+ gas: bigint
116
+ input: Hex
117
+ sighash: Hex
118
+ }
119
+
120
+ export type TraceCallResultFields = {
121
+ gasUsed: bigint
122
+ output: Hex
123
+ }
124
+
125
+ export type TraceSuicideFields = TraceBaseFields & {
126
+ type: 'suicide'
127
+ }
128
+
129
+ export type TraceSuicideActionFields = {
130
+ address: Hex
131
+ refundAddress: Hex
132
+ balance: bigint
133
+ }
134
+
135
+ export type TraceRewardFields = TraceBaseFields & {
136
+ type: 'reward'
137
+ }
138
+
139
+ export type TraceRewardActionFields = {
140
+ author: Hex
141
+ value: bigint
142
+ type: string
143
+ }
144
+
145
+ export type StateDiffBaseFields = {
146
+ transactionIndex: number
147
+ address: Hex
148
+ key: 'balance' | 'code' | 'nonce' | Hex
149
+ kind: string
150
+ prev?: unknown
151
+ next?: unknown
152
+ }
153
+
154
+ export type StateDiffAddFields = StateDiffBaseFields & {
155
+ kind: '+'
156
+ prev?: null
157
+ next: Hex
158
+ }
159
+
160
+ export type StateDiffNoChangeFields = StateDiffBaseFields & {
161
+ kind: '='
162
+ prev?: null
163
+ next?: null
164
+ }
165
+
166
+ export type StateDiffChangeFields = StateDiffBaseFields & {
167
+ kind: '*'
168
+ prev: Hex
169
+ next: Hex
170
+ }
171
+
172
+ export type StateDiffDeleteFields = StateDiffBaseFields & {
173
+ kind: '-'
174
+ prev: Hex
175
+ next?: null
176
+ }
177
+
178
+ export type BlockHeaderFieldSelection = Simplify<Selector<keyof BlockHeaderFields> & {number: true; hash: true}>
179
+ export type BlockHeader<T extends BlockHeaderFieldSelection = Trues<BlockHeaderFieldSelection>> = Select<
180
+ BlockHeaderFields,
181
+ T
182
+ >
183
+
184
+ export type TransactionFieldSelection = Selector<keyof TransactionFields>
185
+ export type Transaction<T extends TransactionFieldSelection = Trues<TransactionFieldSelection>> = Select<
186
+ TransactionFields,
187
+ T
188
+ >
189
+
190
+ export type LogFieldSelection = Selector<keyof LogFields>
191
+ export type Log<T extends LogFieldSelection = Trues<LogFieldSelection>> = Select<LogFields, T>
192
+
193
+ export type TraceCreateFieldSelection = Selector<
194
+ | keyof TraceBaseFields
195
+ | AddPrefix<'create', keyof TraceCreateActionFields>
196
+ | AddPrefix<'createResult', keyof TraceCreateResultFields>
197
+ >
198
+
199
+ export type TraceCallFieldSelection = Selector<
200
+ | keyof TraceBaseFields
201
+ | AddPrefix<'call', keyof TraceCallActionFields>
202
+ | AddPrefix<'callResult', keyof TraceCallResultFields>
203
+ >
204
+
205
+ export type TraceSuicideFieldSelection = Selector<
206
+ keyof TraceBaseFields | AddPrefix<'suicide', keyof TraceSuicideActionFields>
207
+ >
208
+
209
+ export type TraceRewardFieldSelection = Selector<
210
+ keyof TraceBaseFields | AddPrefix<'reward', keyof TraceRewardActionFields>
211
+ >
212
+
213
+ export type TraceFieldSelection = Simplify<
214
+ TraceCreateFieldSelection & TraceCallFieldSelection & TraceSuicideFieldSelection & TraceRewardFieldSelection
215
+ >
216
+
217
+ export type TraceCreateAction<F extends TraceFieldSelection = Trues<TraceFieldSelection>> = Select<
218
+ TraceCreateActionFields,
219
+ RemoveKeysPrefix<'create', F>
220
+ >
221
+
222
+ export type TraceCreateResult<F extends TraceCreateFieldSelection = Trues<TraceCreateFieldSelection>> = Select<
223
+ TraceCreateResultFields,
224
+ RemoveKeysPrefix<'createResult', F>
225
+ >
226
+
227
+ export type TraceCallAction<F extends TraceCallFieldSelection = Trues<TraceCallFieldSelection>> = Select<
228
+ TraceCallActionFields,
229
+ RemoveKeysPrefix<'call', F>
230
+ >
231
+
232
+ export type TraceCallResult<F extends TraceCallFieldSelection = Trues<TraceCallFieldSelection>> = Select<
233
+ TraceCallResultFields,
234
+ RemoveKeysPrefix<'callResult', F>
235
+ >
236
+
237
+ export type TraceSuicideAction<F extends TraceSuicideFieldSelection = Trues<TraceSuicideFieldSelection>> = Select<
238
+ TraceSuicideActionFields,
239
+ RemoveKeysPrefix<'suicide', F>
240
+ >
241
+
242
+ export type TraceRewardAction<F extends TraceRewardFieldSelection = Trues<TraceRewardFieldSelection>> = Select<
243
+ TraceRewardActionFields,
244
+ RemoveKeysPrefix<'reward', F>
245
+ >
246
+
247
+ export type TraceCreate<F extends TraceCreateFieldSelection = Trues<TraceCreateFieldSelection>> = Simplify<
248
+ Select<TraceCreateFields, F> &
249
+ ConditionalOmit<{action: TraceCreateAction<F>; result?: TraceCreateResult<F>}, {[k: string]: never} | undefined>
250
+ >
251
+
252
+ export type TraceCall<F extends TraceCallFieldSelection = Trues<TraceCallFieldSelection>> = Simplify<
253
+ Select<TraceCallFields, F> &
254
+ ConditionalOmit<{action: TraceCallAction<F>; result?: TraceCallResult<F>}, {[k: string]: never} | undefined>
255
+ >
256
+
257
+ export type TraceSuicide<F extends TraceSuicideFieldSelection = Trues<TraceSuicideFieldSelection>> = Simplify<
258
+ Select<TraceSuicideFields, F> & ConditionalOmit<{action: TraceSuicideAction<F>}, {[k: string]: never} | undefined>
259
+ >
260
+
261
+ export type TraceReward<F extends TraceRewardFieldSelection = Trues<TraceRewardFieldSelection>> = Simplify<
262
+ Select<TraceRewardFields, F> & ConditionalOmit<{action: TraceRewardAction<F>}, {[k: string]: never} | undefined>
263
+ >
264
+
265
+ export type Trace<F extends TraceFieldSelection = Trues<TraceFieldSelection>> = F extends any
266
+ ? TraceCreate<F> | TraceCall<F> | TraceSuicide<F> | TraceReward<F>
267
+ : never
268
+
269
+ export type StateDiffFieldSelection = Selector<keyof StateDiffBaseFields>
270
+
271
+ export type StateDiffNoChange<F extends StateDiffFieldSelection = Trues<StateDiffFieldSelection>> = Select<
272
+ StateDiffNoChangeFields,
273
+ F
274
+ >
275
+
276
+ export type StateDiffAdd<F extends StateDiffFieldSelection = Trues<StateDiffFieldSelection>> = Select<
277
+ StateDiffAddFields,
278
+ F
279
+ >
280
+
281
+ export type StateDiffChange<F extends StateDiffFieldSelection = Trues<StateDiffFieldSelection>> = Select<
282
+ StateDiffChangeFields,
283
+ F
284
+ >
285
+
286
+ export type StateDiffDelete<F extends StateDiffFieldSelection = Trues<StateDiffFieldSelection>> = Select<
287
+ StateDiffDeleteFields,
288
+ F
289
+ >
290
+
291
+ export type StateDiff<F extends StateDiffFieldSelection = Trues<StateDiffFieldSelection>> = F extends any
292
+ ? StateDiffNoChange<F> | StateDiffAdd<F> | StateDiffChange<F> | StateDiffDelete<F>
293
+ : never
294
+
295
+ export type FieldSelection = {
296
+ block?: BlockHeaderFieldSelection
297
+ transaction?: TransactionFieldSelection
298
+ log?: LogFieldSelection
299
+ trace?: TraceFieldSelection
300
+ stateDiff?: StateDiffFieldSelection
301
+ }
302
+
303
+ export type LogRequest = {
304
+ address?: Hex[]
305
+ topic0?: Hex[]
306
+ topic1?: Hex[]
307
+ topic2?: Hex[]
308
+ topic3?: Hex[]
309
+ transaction?: boolean
310
+ transactionTraces?: boolean
311
+ transactionLogs?: boolean
312
+ transactionStateDiffs?: boolean
313
+ }
314
+
315
+ export type TransactionRequest = {
316
+ to?: Hex[]
317
+ from?: Hex[]
318
+ sighash?: Hex[]
319
+ type?: number[]
320
+ logs?: boolean
321
+ traces?: boolean
322
+ stateDiffs?: boolean
323
+ }
324
+
325
+ export type TraceRequest = {
326
+ type?: string[]
327
+ createFrom?: Hex[]
328
+ callTo?: Hex[]
329
+ callFrom?: Hex[]
330
+ callSighash?: Hex[]
331
+ suicideRefundAddress?: Hex[]
332
+ rewardAuthor?: Hex[]
333
+ transaction?: boolean
334
+ transactionLogs?: boolean
335
+ subtraces?: boolean
336
+ parents?: boolean
337
+ }
338
+
339
+ export type StateDiffRequest = {
340
+ address?: Hex[]
341
+ key?: Hex[]
342
+ kind?: string[]
343
+ transaction?: boolean
344
+ }
345
+
346
+ export type DataRequest = {
347
+ logs?: LogRequest[]
348
+ transactions?: TransactionRequest[]
349
+ traces?: TraceRequest[]
350
+ stateDiffs?: StateDiffRequest[]
351
+ includeAllBlocks?: boolean
352
+ }
353
+
354
+ export type Query = Simplify<
355
+ PortalQuery & {
356
+ type: 'evm'
357
+ fields: FieldSelection
358
+ } & DataRequest
359
+ >
360
+
361
+ export type Block<F extends FieldSelection> = Simplify<{
362
+ header: BlockHeader<F['block'] & {}>
363
+ logs?: Log<F['log'] & {}>[]
364
+ transactions?: Transaction<F['transaction'] & {}>[]
365
+ traces?: Trace<F['trace'] & {}>[]
366
+ stateDiffs?: StateDiff<F['stateDiff'] & {}>[]
367
+ }>
@@ -0,0 +1,4 @@
1
+ export type * as evm from './evm'
2
+ export type * as solana from './solana'
3
+ export type * as substrate from './substrate'
4
+ export type {PortalBlock, PortalQuery} from './common'
@@ -0,0 +1,276 @@
1
+ import type {Select, Selector, Trues, Base58, Base64, Simplify, PortalBlock, PortalQuery} from './common'
2
+
3
+ export type BlockHeaderFields = {
4
+ hash: Base58
5
+ number: number
6
+ height: number
7
+ parentSlot: number
8
+ parentHash: Base58
9
+ timestamp: number
10
+ }
11
+
12
+ export type TransactionFields = {
13
+ /**
14
+ * Transaction position in block
15
+ */
16
+ transactionIndex: number
17
+ version: 'legacy' | number
18
+ // transaction message
19
+ accountKeys: Base58[]
20
+ addressTableLookups: AddressTableLookup[]
21
+ numReadonlySignedAccounts: number
22
+ numReadonlyUnsignedAccounts: number
23
+ numRequiredSignatures: number
24
+ recentBlockhash: Base58
25
+ signatures: Base58[]
26
+ // meta fields
27
+ err: null | object
28
+ computeUnitsConsumed: bigint
29
+ fee: bigint
30
+ loadedAddresses: {
31
+ readonly: Base58[]
32
+ writable: Base58[]
33
+ }
34
+ hasDroppedLogMessages: boolean
35
+ }
36
+
37
+ export type AddressTableLookup = {
38
+ accountKey: Base58
39
+ readonlyIndexes: number[]
40
+ writableIndexes: number[]
41
+ }
42
+
43
+ export type InstructionFields = {
44
+ transactionIndex: number
45
+ instructionAddress: number[]
46
+ programId: Base58
47
+ accounts: Base58[]
48
+ data: Base58
49
+ // execution result extracted from logs
50
+ computeUnitsConsumed?: bigint
51
+ error?: string
52
+ /**
53
+ * `true` when transaction completed successfully, `false` otherwise
54
+ */
55
+ isCommitted: boolean
56
+ hasDroppedLogMessages: boolean
57
+ }
58
+
59
+ export type LogMessageFields = {
60
+ transactionIndex: number
61
+ logIndex: number
62
+ instructionAddress: number[]
63
+ programId: Base58
64
+ kind: 'log' | 'data' | 'other'
65
+ message: Base64
66
+ }
67
+
68
+ export type BalanceFields = {
69
+ transactionIndex: number
70
+ account: Base58
71
+ pre: bigint
72
+ post: bigint
73
+ }
74
+
75
+ export type PreTokenBalanceFields = {
76
+ transactionIndex: number
77
+ account: Base58
78
+
79
+ preProgramId?: Base58
80
+ preMint: Base58
81
+ preDecimals: number
82
+ preOwner?: Base58
83
+ preAmount: bigint
84
+
85
+ postProgramId?: undefined
86
+ postMint?: undefined
87
+ postDecimals?: undefined
88
+ postOwner?: undefined
89
+ postAmount?: undefined
90
+ }
91
+
92
+ export type PostTokenBalanceFields = {
93
+ transactionIndex: number
94
+ account: Base58
95
+
96
+ preProgramId?: undefined
97
+ preMint?: undefined
98
+ preDecimals?: undefined
99
+ preOwner?: undefined
100
+ preAmount?: undefined
101
+
102
+ postProgramId?: Base58
103
+ postMint: Base58
104
+ postDecimals: number
105
+ postOwner?: Base58
106
+ postAmount: bigint
107
+ }
108
+
109
+ export type PrePostTokenBalanceFields = {
110
+ transactionIndex: number
111
+ account: Base58
112
+ preProgramId?: Base58
113
+ preMint: Base58
114
+ preDecimals: number
115
+ preOwner?: Base58
116
+ preAmount: bigint
117
+ postProgramId?: Base58
118
+ postMint: Base58
119
+ postDecimals: number
120
+ postOwner?: Base58
121
+ postAmount: bigint
122
+ }
123
+
124
+ export type TokenBalanceFields = PreTokenBalanceFields | PostTokenBalanceFields | PrePostTokenBalanceFields
125
+
126
+ export type RewardFields = {
127
+ pubkey: Base58
128
+ lamports: bigint
129
+ postBalance: bigint
130
+ rewardType?: string
131
+ commission?: number
132
+ }
133
+
134
+ export type BlockHeaderFieldSelection = Simplify<Selector<keyof BlockHeaderFields> & {number: true; hash: true}>
135
+ export type BlockHeader<F extends BlockHeaderFieldSelection = Trues<BlockHeaderFieldSelection>> = Select<
136
+ BlockHeaderFields,
137
+ F
138
+ >
139
+
140
+ export type TransactionFieldSelection = Selector<keyof TransactionFields>
141
+ export type Transaction<F extends TransactionFieldSelection = Trues<TransactionFieldSelection>> = Select<
142
+ TransactionFields,
143
+ F
144
+ >
145
+
146
+ export type InstructionFieldSelection = Selector<keyof InstructionFields>
147
+ export type Instruction<F extends InstructionFieldSelection = Trues<InstructionFieldSelection>> = Select<
148
+ InstructionFields,
149
+ F
150
+ >
151
+
152
+ export type LogMessageFieldSelection = Selector<keyof LogMessageFields>
153
+ export type LogMessage<F extends LogMessageFieldSelection = Trues<LogMessageFieldSelection>> = Select<
154
+ LogMessageFields,
155
+ F
156
+ >
157
+
158
+ export type BalanceFieldSelection = Selector<keyof BalanceFields>
159
+ export type Balance<F extends BalanceFieldSelection = Trues<BalanceFieldSelection>> = Select<BalanceFields, F>
160
+
161
+ export type TokenBalanceFieldSelection = Selector<keyof TokenBalanceFields>
162
+ export type TokenBalance<F extends TokenBalanceFieldSelection = Trues<TokenBalanceFieldSelection>> = Select<
163
+ {[K in keyof TokenBalanceFields]: TokenBalanceFields[K]},
164
+ F
165
+ >
166
+
167
+ export type RewardFieldSelection = Selector<keyof RewardFields>
168
+ export type Reward<F extends RewardFieldSelection = Trues<RewardFieldSelection>> = Select<RewardFields, F>
169
+
170
+ export type FieldSelection = {
171
+ block?: BlockHeaderFieldSelection
172
+ transaction?: TransactionFieldSelection
173
+ instruction?: InstructionFieldSelection
174
+ log?: LogMessageFieldSelection
175
+ balance?: BalanceFieldSelection
176
+ tokenBalance?: TokenBalanceFieldSelection
177
+ reward?: RewardFieldSelection
178
+ }
179
+
180
+ export type DataRequest = {
181
+ includeAllBlocks?: boolean
182
+ transactions?: TransactionRequest[]
183
+ instructions?: InstructionRequest[]
184
+ logs?: LogRequest[]
185
+ balances?: BalanceRequest[]
186
+ tokenBalances?: TokenBalanceRequest[]
187
+ rewards?: RewardRequest[]
188
+ }
189
+
190
+ export type TransactionRequest = {
191
+ feePayer?: Base58[]
192
+
193
+ instructions?: boolean
194
+ logs?: boolean
195
+ }
196
+
197
+ /**
198
+ * Hex encoded prefix of instruction data
199
+ */
200
+ export type Discriminator = string & {}
201
+
202
+ export type InstructionRequest = {
203
+ programId?: Base58[]
204
+ d1?: Discriminator[]
205
+ d2?: Discriminator[]
206
+ d3?: Discriminator[]
207
+ d4?: Discriminator[]
208
+ d8?: Discriminator[]
209
+ a0?: Base58[]
210
+ a1?: Base58[]
211
+ a2?: Base58[]
212
+ a3?: Base58[]
213
+ a4?: Base58[]
214
+ a5?: Base58[]
215
+ a6?: Base58[]
216
+ a7?: Base58[]
217
+ a8?: Base58[]
218
+ a9?: Base58[]
219
+ isCommitted?: boolean
220
+
221
+ transaction?: boolean
222
+ transactionBalances?: boolean
223
+ transactionTokenBalances?: boolean
224
+ transactionInstructions?: boolean
225
+ logs?: boolean
226
+ innerInstructions?: boolean
227
+ }
228
+
229
+ export type LogRequest = {
230
+ programId?: Base58[]
231
+ kind?: LogMessageFields['kind'][]
232
+
233
+ transaction?: boolean
234
+ instruction?: boolean
235
+ }
236
+
237
+ export type BalanceRequest = {
238
+ account?: Base58[]
239
+
240
+ transaction?: boolean
241
+ transactionInstructions?: boolean
242
+ }
243
+
244
+ export type TokenBalanceRequest = {
245
+ account?: Base58[]
246
+ preProgramId?: Base58[]
247
+ postProgramId?: Base58[]
248
+ preMint?: Base58[]
249
+ postMint?: Base58[]
250
+ preOwner?: Base58[]
251
+ postOwner?: Base58[]
252
+
253
+ transaction?: boolean
254
+ transactionInstructions?: boolean
255
+ }
256
+
257
+ export type RewardRequest = {
258
+ pubkey?: Base58[]
259
+ }
260
+
261
+ export type Query = Simplify<
262
+ PortalQuery & {
263
+ type: 'solana'
264
+ fields: FieldSelection
265
+ } & DataRequest
266
+ >
267
+
268
+ export type Block<F extends FieldSelection> = Simplify<{
269
+ header: BlockHeader<F['block'] & {}>
270
+ transactions?: Transaction<F['transaction'] & {}>[]
271
+ instructions?: Instruction<F['instruction'] & {}>[]
272
+ logs?: LogMessage<F['log'] & {}>[]
273
+ balances?: Balance<F['balance'] & {}>[]
274
+ tokenBalances?: TokenBalance<F['tokenBalance'] & {}>[]
275
+ rewards?: Reward<F['reward'] & {}>[]
276
+ }>