@subsquid/portal-client 0.3.2 → 0.4.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 (131) hide show
  1. package/lib/client.d.ts +40 -18
  2. package/lib/client.d.ts.map +1 -1
  3. package/lib/client.js +166 -188
  4. package/lib/client.js.map +1 -1
  5. package/lib/query/common/data.d.ts +21 -0
  6. package/lib/query/common/data.d.ts.map +1 -0
  7. package/lib/query/common/data.js +3 -0
  8. package/lib/query/common/data.js.map +1 -0
  9. package/lib/query/common/query.d.ts +7 -0
  10. package/lib/query/common/query.d.ts.map +1 -0
  11. package/lib/query/common/query.js +3 -0
  12. package/lib/query/common/query.js.map +1 -0
  13. package/lib/query/evm/data.d.ts +159 -0
  14. package/lib/query/evm/data.d.ts.map +1 -0
  15. package/lib/query/evm/data.js +3 -0
  16. package/lib/query/evm/data.js.map +1 -0
  17. package/lib/query/evm/fields.d.ts +50 -0
  18. package/lib/query/evm/fields.d.ts.map +1 -0
  19. package/lib/query/evm/fields.js +3 -0
  20. package/lib/query/evm/fields.js.map +1 -0
  21. package/lib/query/evm/index.d.ts +4 -0
  22. package/lib/query/evm/index.d.ts.map +1 -0
  23. package/lib/query/evm/index.js +7 -0
  24. package/lib/query/evm/index.js.map +1 -0
  25. package/lib/query/evm/query.d.ts +54 -0
  26. package/lib/query/evm/query.d.ts.map +1 -0
  27. package/lib/query/evm/query.js +3 -0
  28. package/lib/query/evm/query.js.map +1 -0
  29. package/lib/query/evm/schema.d.ts +322 -0
  30. package/lib/query/evm/schema.d.ts.map +1 -0
  31. package/lib/query/evm/schema.js +224 -0
  32. package/lib/query/evm/schema.js.map +1 -0
  33. package/lib/query/index.d.ts +576 -8
  34. package/lib/query/index.d.ts.map +1 -1
  35. package/lib/query/index.js +15 -24
  36. package/lib/query/index.js.map +1 -1
  37. package/lib/query/solana/data.d.ts +115 -0
  38. package/lib/query/solana/data.d.ts.map +1 -0
  39. package/lib/query/solana/data.js +3 -0
  40. package/lib/query/solana/data.js.map +1 -0
  41. package/lib/query/solana/fields.d.ts +31 -0
  42. package/lib/query/solana/fields.d.ts.map +1 -0
  43. package/lib/query/solana/fields.js +3 -0
  44. package/lib/query/solana/fields.js.map +1 -0
  45. package/lib/query/solana/index.d.ts +4 -0
  46. package/lib/query/solana/index.d.ts.map +1 -0
  47. package/lib/query/solana/index.js +7 -0
  48. package/lib/query/solana/index.js.map +1 -0
  49. package/lib/query/solana/query.d.ts +74 -0
  50. package/lib/query/solana/query.d.ts.map +1 -0
  51. package/lib/query/solana/query.js +3 -0
  52. package/lib/query/solana/query.js.map +1 -0
  53. package/lib/query/solana/schema.d.ts +160 -0
  54. package/lib/query/solana/schema.d.ts.map +1 -0
  55. package/lib/query/solana/schema.js +130 -0
  56. package/lib/query/solana/schema.js.map +1 -0
  57. package/lib/query/substrate/data.d.ts +98 -0
  58. package/lib/query/substrate/data.d.ts.map +1 -0
  59. package/lib/query/substrate/data.js +3 -0
  60. package/lib/query/substrate/data.js.map +1 -0
  61. package/lib/query/substrate/fields.d.ts +22 -0
  62. package/lib/query/substrate/fields.d.ts.map +1 -0
  63. package/lib/query/substrate/fields.js +3 -0
  64. package/lib/query/substrate/fields.js.map +1 -0
  65. package/lib/query/substrate/index.d.ts +4 -0
  66. package/lib/query/substrate/index.d.ts.map +1 -0
  67. package/lib/query/substrate/index.js +7 -0
  68. package/lib/query/substrate/index.js.map +1 -0
  69. package/lib/query/substrate/query.d.ts +50 -0
  70. package/lib/query/substrate/query.d.ts.map +1 -0
  71. package/lib/query/substrate/query.js +3 -0
  72. package/lib/query/substrate/query.js.map +1 -0
  73. package/lib/query/substrate/schema.d.ts +102 -0
  74. package/lib/query/substrate/schema.d.ts.map +1 -0
  75. package/lib/query/substrate/schema.js +88 -0
  76. package/lib/query/substrate/schema.js.map +1 -0
  77. package/lib/query/type-util.d.ts +13 -0
  78. package/lib/query/type-util.d.ts.map +1 -0
  79. package/lib/query/type-util.js +3 -0
  80. package/lib/query/type-util.js.map +1 -0
  81. package/lib/query/util.d.ts +5 -0
  82. package/lib/query/util.d.ts.map +1 -0
  83. package/lib/query/util.js +23 -0
  84. package/lib/query/util.js.map +1 -0
  85. package/lib/util.d.ts +19 -0
  86. package/lib/util.d.ts.map +1 -0
  87. package/lib/util.js +57 -0
  88. package/lib/util.js.map +1 -0
  89. package/package.json +3 -3
  90. package/src/client.ts +231 -247
  91. package/src/query/common/data.ts +24 -0
  92. package/src/query/common/query.ts +6 -0
  93. package/src/query/evm/data.ts +182 -0
  94. package/src/query/evm/fields.ts +105 -0
  95. package/src/query/evm/index.ts +3 -0
  96. package/src/query/evm/query.ts +59 -0
  97. package/src/query/evm/schema.ts +277 -0
  98. package/src/query/index.ts +19 -36
  99. package/src/query/solana/data.ts +132 -0
  100. package/src/query/solana/fields.ts +42 -0
  101. package/src/query/solana/index.ts +3 -0
  102. package/src/query/solana/query.ts +89 -0
  103. package/src/query/solana/schema.ts +164 -0
  104. package/src/query/substrate/data.ts +101 -0
  105. package/src/query/substrate/fields.ts +30 -0
  106. package/src/query/substrate/index.ts +3 -0
  107. package/src/query/substrate/query.ts +60 -0
  108. package/src/query/substrate/schema.ts +114 -0
  109. package/src/query/type-util.ts +25 -0
  110. package/src/query/util.ts +23 -0
  111. package/src/util.ts +56 -0
  112. package/lib/query/common.d.ts +0 -56
  113. package/lib/query/common.d.ts.map +0 -1
  114. package/lib/query/common.js +0 -16
  115. package/lib/query/common.js.map +0 -1
  116. package/lib/query/evm.d.ts +0 -267
  117. package/lib/query/evm.d.ts.map +0 -1
  118. package/lib/query/evm.js +0 -245
  119. package/lib/query/evm.js.map +0 -1
  120. package/lib/query/solana.d.ts +0 -224
  121. package/lib/query/solana.d.ts.map +0 -1
  122. package/lib/query/solana.js +0 -121
  123. package/lib/query/solana.js.map +0 -1
  124. package/lib/query/substrate.d.ts +0 -173
  125. package/lib/query/substrate.d.ts.map +0 -1
  126. package/lib/query/substrate.js +0 -71
  127. package/lib/query/substrate.js.map +0 -1
  128. package/src/query/common.ts +0 -83
  129. package/src/query/evm.ts +0 -677
  130. package/src/query/solana.ts +0 -438
  131. package/src/query/substrate.ts +0 -288
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Hex binary string
3
+ */
4
+ export type Bytes = string & {}
5
+
6
+ /**
7
+ * 32 bytes as a hex string
8
+ */
9
+ export type Bytes32 = string & {}
10
+
11
+ /**
12
+ * 20 bytes as a hex string
13
+ */
14
+ export type Bytes20 = string & {}
15
+
16
+ /**
17
+ * 8 bytes as a hex string
18
+ */
19
+ export type Bytes8 = string & {}
20
+
21
+ /**
22
+ * Base58 encoded byte string
23
+ */
24
+ export type Base58Bytes = string & {}
@@ -0,0 +1,6 @@
1
+ export interface QueryBase {
2
+ fromBlock: number
3
+ toBlock?: number
4
+ parentBlockHash?: string
5
+ includeAllBlocks?: boolean
6
+ }
@@ -0,0 +1,182 @@
1
+ import type {Bytes, Bytes20, Bytes32, Bytes8} from '../common/data'
2
+
3
+ export interface BlockHeader {
4
+ number: number
5
+ hash: Bytes32
6
+ parentHash: Bytes32
7
+ nonce: Bytes8
8
+ sha3Uncles: Bytes32
9
+ logsBloom: Bytes
10
+ transactionsRoot: Bytes32
11
+ stateRoot: Bytes32
12
+ receiptsRoot: Bytes32
13
+ mixHash: Bytes
14
+ miner: Bytes20
15
+ difficulty: bigint
16
+ totalDifficulty: bigint
17
+ extraData: Bytes
18
+ size: bigint
19
+ gasLimit: bigint
20
+ gasUsed: bigint
21
+ timestamp: number
22
+ baseFeePerGas: bigint
23
+ l1BlockNumber: number
24
+ }
25
+
26
+ export interface Transaction {
27
+ transactionIndex: number
28
+ // Transaction part
29
+ hash: Bytes32
30
+ from: Bytes20
31
+ to?: Bytes20
32
+ gas: bigint
33
+ gasPrice: bigint
34
+ maxFeePerGas?: bigint
35
+ maxPriorityFeePerGas?: bigint
36
+ input: Bytes
37
+ sighash?: Bytes8
38
+ nonce: number
39
+ value: bigint
40
+ v: bigint
41
+ r: Bytes32
42
+ s: Bytes32
43
+ yParity?: number
44
+ chainId?: number
45
+ authorizationList?: EIP7702Authorization[]
46
+ // Receipt part
47
+ gasUsed: bigint
48
+ cumulativeGasUsed: bigint
49
+ effectiveGasPrice: bigint
50
+ contractAddress?: Bytes20
51
+ type: number
52
+ status: number
53
+ l1Fee?: bigint
54
+ l1FeeScalar?: number
55
+ l1GasPrice?: bigint
56
+ l1GasUsed?: bigint
57
+ l1BlobBaseFee?: bigint
58
+ l1BlobBaseFeeScalar?: number
59
+ l1BaseFeeScalar?: number
60
+ }
61
+
62
+ export interface EIP7702Authorization {
63
+ chainId: number
64
+ nonce: number
65
+ address: Bytes20
66
+ yParity: number
67
+ r: Bytes32
68
+ s: Bytes32
69
+ }
70
+
71
+ export interface Log {
72
+ logIndex: number
73
+ transactionIndex: number
74
+ transactionHash: Bytes32
75
+ address: Bytes20
76
+ topics: Bytes32[]
77
+ data: Bytes
78
+ }
79
+
80
+ export interface TraceBase {
81
+ transactionIndex: number
82
+ traceAddress: number[]
83
+ subtraces: number
84
+ error: string | null
85
+ revertReason?: string
86
+ }
87
+
88
+ export interface TraceCreate extends TraceBase {
89
+ type: 'create'
90
+ action: TraceCreateAction
91
+ result?: TraceCreateResult
92
+ }
93
+
94
+ export interface TraceCreateAction {
95
+ from: Bytes20
96
+ value: bigint
97
+ gas: bigint
98
+ init: Bytes
99
+ }
100
+
101
+ export interface TraceCreateResult {
102
+ gasUsed: bigint
103
+ code: Bytes
104
+ address: Bytes20
105
+ }
106
+
107
+ export interface TraceCall extends TraceBase {
108
+ type: 'call'
109
+ action: TraceCallAction
110
+ result?: TraceCallResult
111
+ }
112
+
113
+ export interface TraceCallAction {
114
+ callType: string
115
+ from: Bytes20
116
+ to: Bytes20
117
+ value?: bigint
118
+ gas: bigint
119
+ input: Bytes
120
+ sighash: Bytes8
121
+ }
122
+
123
+ export interface TraceCallResult {
124
+ gasUsed: bigint
125
+ output: Bytes
126
+ }
127
+
128
+ export interface TraceSuicide extends TraceBase {
129
+ type: 'suicide'
130
+ action: TraceSuicideAction
131
+ }
132
+
133
+ export interface TraceSuicideAction {
134
+ address: Bytes20
135
+ refundAddress: Bytes20
136
+ balance: bigint
137
+ }
138
+
139
+ export interface TraceReward extends TraceBase {
140
+ type: 'reward'
141
+ action: TraceRewardAction
142
+ }
143
+
144
+ export interface TraceRewardAction {
145
+ author: Bytes20
146
+ value: bigint
147
+ type: string
148
+ }
149
+
150
+ export type Trace = TraceCreate | TraceCall | TraceSuicide | TraceReward
151
+
152
+ export interface StateDiffBase {
153
+ transactionIndex: number
154
+ address: Bytes20
155
+ key: 'balance' | 'code' | 'nonce' | Bytes32
156
+ }
157
+
158
+ export interface StateDiffNoChange extends StateDiffBase {
159
+ kind: '='
160
+ prev?: null
161
+ next?: null
162
+ }
163
+
164
+ export interface StateDiffAdd extends StateDiffBase {
165
+ kind: '+'
166
+ prev?: null
167
+ next: Bytes32
168
+ }
169
+
170
+ export interface StateDiffChange extends StateDiffBase {
171
+ kind: '*'
172
+ prev: Bytes32
173
+ next: Bytes32
174
+ }
175
+
176
+ export interface StateDiffDelete extends StateDiffBase {
177
+ kind: '-'
178
+ prev: Bytes32
179
+ next?: null
180
+ }
181
+
182
+ export type StateDiff = StateDiffNoChange | StateDiffAdd | StateDiffChange | StateDiffDelete
@@ -0,0 +1,105 @@
1
+ import type {AddPrefix, GetFields, RemovePrefix, Select, Selector, Simplify} from '../type-util'
2
+ import type * as data from './data'
3
+
4
+ type BlockRequiredFields = 'number' | 'hash' | 'parentHash'
5
+
6
+ export interface FieldSelection {
7
+ block?: Selector<Exclude<keyof data.BlockHeader, BlockRequiredFields>>
8
+ transaction?: Selector<keyof data.Transaction>
9
+ log?: Selector<keyof data.Log>
10
+ trace?: Selector<
11
+ | keyof data.TraceBase
12
+ | AddPrefix<'create', keyof data.TraceCreateAction>
13
+ | AddPrefix<'createResult', keyof data.TraceCreateResult>
14
+ | AddPrefix<'call', keyof data.TraceCallAction>
15
+ | AddPrefix<'callResult', keyof data.TraceCallResult>
16
+ | AddPrefix<'suicide', keyof data.TraceSuicideAction>
17
+ | AddPrefix<'reward', keyof data.TraceRewardAction>
18
+ >
19
+ stateDiff?: Selector<Exclude<keyof data.StateDiff, 'kind'>>
20
+ }
21
+
22
+ export type BlockHeader<F extends FieldSelection> = Simplify<
23
+ Pick<data.BlockHeader, BlockRequiredFields> & Select<data.BlockHeader, GetFields<F['block']>>
24
+ >
25
+
26
+ export type Transaction<F extends FieldSelection> = Select<data.Transaction, GetFields<F['transaction']>>
27
+
28
+ export type Log<F extends FieldSelection> = Select<data.Log, GetFields<F['log']>>
29
+
30
+ export type TraceCreateAction<F extends FieldSelection> = Select<
31
+ data.TraceCreateAction,
32
+ RemovePrefix<'create', GetFields<F['trace']>>
33
+ >
34
+
35
+ export type TraceCreateResult<F extends FieldSelection> = Select<
36
+ data.TraceCreateResult,
37
+ RemovePrefix<'createResult', GetFields<F['trace']>>
38
+ >
39
+
40
+ export type TraceCallAction<F extends FieldSelection> = Select<
41
+ data.TraceCallAction,
42
+ RemovePrefix<'call', GetFields<F['trace']>>
43
+ >
44
+
45
+ export type TraceCallResult<F extends FieldSelection> = Select<
46
+ data.TraceCallResult,
47
+ RemovePrefix<'callResult', GetFields<F['trace']>>
48
+ >
49
+
50
+ export type TraceSuicideAction<F extends FieldSelection> = Select<
51
+ data.TraceSuicideAction,
52
+ RemovePrefix<'suicide', GetFields<F['trace']>>
53
+ >
54
+
55
+ export type TraceRewardAction<F extends FieldSelection> = Select<
56
+ data.TraceRewardAction,
57
+ RemovePrefix<'reward', GetFields<F['trace']>>
58
+ >
59
+
60
+ type TraceBase<F extends FieldSelection, Type> = {type: Type} & Select<data.TraceBase, GetFields<F['trace']>>
61
+
62
+ type RemoveEmptyObjects<T> = {
63
+ [K in keyof T as {} extends T[K] ? never : K]: T[K]
64
+ }
65
+
66
+ export type TraceCreate<F extends FieldSelection> = Simplify<
67
+ TraceBase<F, 'create'> &
68
+ RemoveEmptyObjects<{
69
+ action: TraceCreateAction<F>
70
+ result?: TraceCreateResult<F>
71
+ }>
72
+ >
73
+
74
+ export type TraceCall<F extends FieldSelection> = Simplify<
75
+ TraceBase<F, 'call'> &
76
+ RemoveEmptyObjects<{
77
+ action: TraceCallAction<F>
78
+ result?: TraceCallResult<F>
79
+ }>
80
+ >
81
+
82
+ export type TraceSuicide<F extends FieldSelection> = Simplify<
83
+ TraceBase<F, 'suicide'> &
84
+ RemoveEmptyObjects<{
85
+ action: TraceSuicideAction<F>
86
+ }>
87
+ >
88
+
89
+ export type TraceReward<F extends FieldSelection> = Simplify<
90
+ TraceBase<F, 'reward'> & RemoveEmptyObjects<{action: TraceRewardAction<F>}>
91
+ >
92
+
93
+ export type Trace<F extends FieldSelection> = TraceCreate<F> | TraceCall<F> | TraceSuicide<F> | TraceReward<F>
94
+
95
+ export type StateDiff<F extends FieldSelection> = Simplify<
96
+ Pick<data.StateDiff, 'kind'> & Select<data.StateDiff, GetFields<F['stateDiff']>>
97
+ >
98
+
99
+ export interface Block<F extends FieldSelection> {
100
+ header: BlockHeader<F>
101
+ transactions: Transaction<F>[]
102
+ logs: Log<F>[]
103
+ traces: Trace<F>[]
104
+ stateDiffs: StateDiff<F>[]
105
+ }
@@ -0,0 +1,3 @@
1
+ export type * from './fields'
2
+ export type * from './query'
3
+ export {getBlockSchema, patchQueryFields} from './schema'
@@ -0,0 +1,59 @@
1
+ import type {Bytes, Bytes20, Bytes32, Bytes8} from '../common/data'
2
+ import type {QueryBase} from '../common/query'
3
+ import type {StateDiff} from './data'
4
+ import type {FieldSelection} from './fields'
5
+
6
+ export interface Query<F extends FieldSelection = FieldSelection> extends QueryBase, ItemQuery {
7
+ type: 'evm'
8
+ fields?: F
9
+ }
10
+
11
+ export interface ItemQuery {
12
+ logs?: LogRequest[]
13
+ transactions?: TransactionRequest[]
14
+ traces?: TraceRequest[]
15
+ stateDiffs?: StateDiffRequest[]
16
+ }
17
+
18
+ export interface LogRequest {
19
+ address?: Bytes20[]
20
+ topic0?: Bytes32[]
21
+ topic1?: Bytes32[]
22
+ topic2?: Bytes32[]
23
+ topic3?: Bytes32[]
24
+ transaction?: boolean
25
+ transactionTraces?: boolean
26
+ transactionLogs?: boolean
27
+ transactionStateDiffs?: boolean
28
+ }
29
+
30
+ export interface TransactionRequest {
31
+ to?: Bytes20[]
32
+ from?: Bytes20[]
33
+ sighash?: Bytes8[]
34
+ type?: number[]
35
+ logs?: boolean
36
+ traces?: boolean
37
+ stateDiffs?: boolean
38
+ }
39
+
40
+ export interface TraceRequest {
41
+ type?: string[]
42
+ createFrom?: Bytes20[]
43
+ callTo?: Bytes20[]
44
+ callFrom?: Bytes20[]
45
+ callSighash?: Bytes[]
46
+ suicideRefundAddress?: Bytes[]
47
+ rewardAuthor?: Bytes20[]
48
+ transaction?: boolean
49
+ transactionLogs?: boolean
50
+ subtraces?: boolean
51
+ parents?: boolean
52
+ }
53
+
54
+ export interface StateDiffRequest {
55
+ address?: Bytes20[]
56
+ key?: Bytes[]
57
+ kind?: StateDiff['kind'][]
58
+ transaction?: boolean
59
+ }
@@ -0,0 +1,277 @@
1
+ import {
2
+ array,
3
+ BYTES,
4
+ NAT,
5
+ object,
6
+ option,
7
+ QTY,
8
+ STRING,
9
+ STRING_FLOAT,
10
+ taggedUnion,
11
+ withDefault,
12
+ } from '@subsquid/util-internal-validation'
13
+ import {isEmpty, project} from '../util'
14
+ import type {FieldSelection} from './fields'
15
+
16
+ export function patchQueryFields(fields: FieldSelection): FieldSelection {
17
+ fields = {...fields}
18
+
19
+ let {number, hash, parentHash, ...block} = (fields.block as any) ?? {}
20
+ fields.block = {
21
+ ...block,
22
+ number: true,
23
+ hash: true,
24
+ parentHash: true,
25
+ }
26
+
27
+ let {type, ...trace} = (fields.trace as any) ?? {}
28
+ fields.trace = {
29
+ ...trace,
30
+ type: true,
31
+ }
32
+
33
+ let {kind, ...stateDiff} = (fields.stateDiff as any) ?? {}
34
+ fields.stateDiff = {
35
+ ...stateDiff,
36
+ kind: true,
37
+ }
38
+
39
+ return fields
40
+ }
41
+
42
+ export function getBlockSchema(fields: FieldSelection) {
43
+ return object({
44
+ header: getBlockHeaderSchema(fields.block),
45
+ transactions: withDefault([], array(getTransactionSchema(fields.transaction))),
46
+ logs: withDefault([], array(getLogSchema(fields.log))),
47
+ traces: withDefault([], array(getTraceFrameSchema(fields.trace))),
48
+ stateDiffs: withDefault([], array(getStateDiffSchema(fields.stateDiff))),
49
+ })
50
+ }
51
+
52
+ function getBlockHeaderSchema(fields: FieldSelection['block']) {
53
+ return object({
54
+ number: NAT,
55
+ hash: BYTES,
56
+ parentHash: BYTES,
57
+ ...project(fields, {
58
+ nonce: BYTES,
59
+ sha3Uncles: BYTES,
60
+ logsBloom: BYTES,
61
+ transactionsRoot: BYTES,
62
+ stateRoot: BYTES,
63
+ receiptsRoot: BYTES,
64
+ mixHash: BYTES,
65
+ miner: BYTES,
66
+ extraData: BYTES,
67
+ size: NAT,
68
+ gasLimit: QTY,
69
+ gasUsed: QTY,
70
+ timestamp: NAT,
71
+ difficulty: QTY,
72
+ totalDifficulty: option(QTY),
73
+ baseFeePerGas: option(QTY),
74
+ l1BlockNumber: option(NAT),
75
+ }),
76
+ })
77
+ }
78
+
79
+ const Authorization = object({
80
+ chainId: NAT,
81
+ nonce: NAT,
82
+ address: BYTES,
83
+ yParity: NAT,
84
+ r: BYTES,
85
+ s: BYTES,
86
+ })
87
+
88
+ function getTransactionSchema(fields: FieldSelection['transaction']) {
89
+ return object(
90
+ project(fields, {
91
+ transactionIndex: NAT,
92
+ hash: BYTES,
93
+ from: BYTES,
94
+ to: option(BYTES),
95
+ gas: QTY,
96
+ gasPrice: option(QTY),
97
+ maxFeePerGas: option(QTY),
98
+ maxPriorityFeePerGas: option(QTY),
99
+ input: BYTES,
100
+ sighash: withDefault('0x', BYTES),
101
+ nonce: NAT,
102
+ value: QTY,
103
+ v: option(QTY),
104
+ r: option(BYTES),
105
+ s: option(BYTES),
106
+ yParity: option(NAT),
107
+ chainId: option(NAT),
108
+ authorizationList: option(array(Authorization)),
109
+ gasUsed: QTY,
110
+ cumulativeGasUsed: QTY,
111
+ effectiveGasPrice: QTY,
112
+ contractAddress: option(BYTES),
113
+ type: option(NAT),
114
+ status: option(NAT),
115
+ l1Fee: option(QTY),
116
+ l1FeeScalar: option(STRING_FLOAT),
117
+ l1GasPrice: option(QTY),
118
+ l1GasUsed: option(QTY),
119
+ l1BlobBaseFee: option(QTY),
120
+ l1BlobBaseFeeScalar: option(NAT),
121
+ l1BaseFeeScalar: option(NAT),
122
+ })
123
+ )
124
+ }
125
+
126
+ function getLogSchema(fields: FieldSelection['log']) {
127
+ return object(
128
+ project(fields, {
129
+ logIndex: NAT,
130
+ transactionIndex: NAT,
131
+ transactionHash: BYTES,
132
+ address: BYTES,
133
+ data: BYTES,
134
+ topics: array(BYTES),
135
+ })
136
+ )
137
+ }
138
+
139
+ function getTraceFrameSchema(fields: FieldSelection['trace']) {
140
+ let traceBase = project(fields, {
141
+ transactionIndex: NAT,
142
+ traceAddress: array(NAT),
143
+ subtraces: NAT,
144
+ error: option(STRING),
145
+ revertReason: option(STRING),
146
+ })
147
+
148
+ let traceCreateAction = project(
149
+ {
150
+ from: fields?.createFrom,
151
+ value: fields?.createValue,
152
+ gas: fields?.createGas,
153
+ init: fields?.createInit,
154
+ },
155
+ {
156
+ from: BYTES,
157
+ value: QTY,
158
+ gas: QTY,
159
+ init: withDefault('0x', BYTES),
160
+ }
161
+ )
162
+
163
+ let traceCreateResult = project(
164
+ {
165
+ gasUsed: fields?.createResultGasUsed,
166
+ code: fields?.createResultCode,
167
+ address: fields?.createResultAddress,
168
+ },
169
+ {
170
+ gasUsed: QTY,
171
+ code: withDefault('0x', BYTES),
172
+ address: withDefault('0x0000000000000000000000000000000000000000', BYTES),
173
+ }
174
+ )
175
+
176
+ let TraceCreate = object({
177
+ ...traceBase,
178
+ action: isEmpty(traceCreateAction) ? undefined : object(traceCreateAction),
179
+ result: isEmpty(traceCreateResult) ? undefined : option(object(traceCreateResult)),
180
+ })
181
+
182
+ let traceCallAction = project(
183
+ {
184
+ callType: fields?.callCallType,
185
+ from: fields?.callFrom,
186
+ to: fields?.callTo,
187
+ value: fields?.callValue,
188
+ gas: fields?.callGas,
189
+ input: fields?.callInput,
190
+ sighash: fields?.callSighash,
191
+ },
192
+ {
193
+ callType: STRING,
194
+ from: BYTES,
195
+ to: BYTES,
196
+ value: option(QTY),
197
+ gas: QTY,
198
+ input: BYTES,
199
+ sighash: withDefault('0x', BYTES),
200
+ }
201
+ )
202
+
203
+ let traceCallResult = project(
204
+ {
205
+ gasUsed: fields?.callResultGasUsed,
206
+ output: fields?.callResultOutput,
207
+ },
208
+ {
209
+ gasUsed: QTY,
210
+ output: withDefault('0x', BYTES),
211
+ }
212
+ )
213
+
214
+ let TraceCall = object({
215
+ ...traceBase,
216
+ action: isEmpty(traceCallAction) ? undefined : object(traceCallAction),
217
+ result: isEmpty(traceCallResult) ? undefined : option(object(traceCallResult)),
218
+ })
219
+
220
+ let traceSuicideAction = project(
221
+ {
222
+ address: fields?.suicideAddress,
223
+ refundAddress: fields?.suicideRefundAddress,
224
+ balance: fields?.suicideBalance,
225
+ },
226
+ {
227
+ address: BYTES,
228
+ refundAddress: BYTES,
229
+ balance: QTY,
230
+ }
231
+ )
232
+
233
+ let TraceSuicide = object({
234
+ ...traceBase,
235
+ action: isEmpty(traceSuicideAction) ? undefined : object(traceSuicideAction),
236
+ })
237
+
238
+ let traceRewardAction = project(
239
+ {
240
+ author: fields?.rewardAuthor,
241
+ value: fields?.rewardValue,
242
+ type: fields?.rewardType,
243
+ },
244
+ {
245
+ author: BYTES,
246
+ value: QTY,
247
+ type: STRING,
248
+ }
249
+ )
250
+
251
+ let TraceReward = object({
252
+ ...traceBase,
253
+ action: isEmpty(traceRewardAction) ? undefined : object(traceRewardAction),
254
+ })
255
+
256
+ return taggedUnion('type', {
257
+ create: TraceCreate,
258
+ call: TraceCall,
259
+ suicide: TraceSuicide,
260
+ reward: TraceReward,
261
+ })
262
+ }
263
+
264
+ function getStateDiffSchema(fields: FieldSelection['stateDiff']) {
265
+ let stateDiffBase = {
266
+ transactionIndex: NAT,
267
+ address: BYTES,
268
+ key: STRING,
269
+ }
270
+
271
+ return taggedUnion('kind', {
272
+ ['=']: object(project(fields, stateDiffBase)),
273
+ ['+']: object(project(fields, {...stateDiffBase, next: BYTES})),
274
+ ['*']: object(project(fields, {...stateDiffBase, prev: BYTES, next: BYTES})),
275
+ ['-']: object(project(fields, {...stateDiffBase, prev: BYTES})),
276
+ })
277
+ }