@apibara/evm 2.1.0-beta.18 → 2.1.0-beta.19

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apibara/evm",
3
- "version": "2.1.0-beta.18",
3
+ "version": "2.1.0-beta.19",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -35,7 +35,7 @@
35
35
  "vitest": "^1.6.0"
36
36
  },
37
37
  "dependencies": {
38
- "@apibara/protocol": "2.1.0-beta.18",
38
+ "@apibara/protocol": "2.1.0-beta.19",
39
39
  "@effect/schema": "^0.67.15",
40
40
  "effect": "^3.2.6",
41
41
  "long": "^5.2.1",
package/src/block.ts CHANGED
@@ -2,6 +2,7 @@ import { Bytes, BytesFromUint8Array } from "@apibara/protocol";
2
2
  import { Schema } from "@effect/schema";
3
3
 
4
4
  import { Address, B256, U128, U256 } from "./common";
5
+ import { tag } from "./helpers";
5
6
  import * as proto from "./proto";
6
7
 
7
8
  export const Bloom = Schema.transform(
@@ -155,12 +156,185 @@ export const Log = Schema.Struct({
155
156
 
156
157
  export type Log = typeof Log.Type;
157
158
 
159
+ export const CallType = Schema.transform(
160
+ Schema.Enums(proto.data.CallType),
161
+ Schema.Literal(
162
+ "unknown",
163
+ "call",
164
+ "delegateCall",
165
+ "callCode",
166
+ "delegateCall",
167
+ "staticCall",
168
+ "authCall",
169
+ ),
170
+ {
171
+ decode(value) {
172
+ const enumMap = {
173
+ [proto.data.CallType.CALL]: "call",
174
+ [proto.data.CallType.CALL_CODE]: "callCode",
175
+ [proto.data.CallType.DELEGATE_CALL]: "delegateCall",
176
+ [proto.data.CallType.STATIC_CALL]: "staticCall",
177
+ [proto.data.CallType.AUTH_CALL]: "authCall",
178
+ [proto.data.CallType.UNSPECIFIED]: "unknown",
179
+ [proto.data.CallType.UNRECOGNIZED]: "unknown",
180
+ } as const;
181
+
182
+ return enumMap[value] ?? "unknown";
183
+ },
184
+ encode(value) {
185
+ throw new Error("encode: not implemented");
186
+ },
187
+ },
188
+ );
189
+
190
+ export type CallType = typeof CallType.Type;
191
+
192
+ export const CreationMethod = Schema.transform(
193
+ Schema.Enums(proto.data.CreationMethod),
194
+ Schema.Literal("unknown", "create", "create2", "eofCreate"),
195
+ {
196
+ decode(value) {
197
+ const enumMap = {
198
+ [proto.data.CreationMethod.CREATE]: "create",
199
+ [proto.data.CreationMethod.CREATE2]: "create2",
200
+ [proto.data.CreationMethod.EOF_CREATE]: "eofCreate",
201
+ [proto.data.CallType.UNSPECIFIED]: "unknown",
202
+ [proto.data.CallType.UNRECOGNIZED]: "unknown",
203
+ } as const;
204
+
205
+ return enumMap[value] ?? "unknown";
206
+ },
207
+ encode(value) {
208
+ throw new Error("encode: not implemented");
209
+ },
210
+ },
211
+ );
212
+
213
+ export type CreationMethod = typeof CreationMethod.Type;
214
+
215
+ export const CallAction = Schema.Struct({
216
+ _tag: tag("call"),
217
+ call: Schema.Struct({
218
+ fromAddress: Address,
219
+ type: CallType,
220
+ gas: Schema.BigIntFromSelf,
221
+ input: BytesFromUint8Array,
222
+ toAddress: Address,
223
+ value: U256,
224
+ }),
225
+ });
226
+
227
+ export type CallAction = typeof CallAction.Type;
228
+
229
+ export const CreateAction = Schema.Struct({
230
+ _tag: tag("create"),
231
+ create: Schema.Struct({
232
+ fromAddress: Address,
233
+ gas: Schema.BigIntFromSelf,
234
+ init: BytesFromUint8Array,
235
+ value: U256,
236
+ creationMethod: CreationMethod,
237
+ }),
238
+ });
239
+
240
+ export type CreateAction = typeof CreateAction.Type;
241
+
242
+ export const SelfDestructAction = Schema.Struct({
243
+ _tag: tag("selfDestruct"),
244
+ selfDestruct: Schema.Struct({
245
+ address: Address,
246
+ balance: U256,
247
+ refundAddress: Address,
248
+ }),
249
+ });
250
+
251
+ export type SelfDestructAction = typeof SelfDestructAction.Type;
252
+
253
+ export const RewardType = Schema.transform(
254
+ Schema.Enums(proto.data.RewardType),
255
+ Schema.Literal("unknown", "block", "uncle"),
256
+ {
257
+ decode(value) {
258
+ const enumMap = {
259
+ [proto.data.RewardType.BLOCK]: "block",
260
+ [proto.data.RewardType.UNCLE]: "uncle",
261
+ [proto.data.RewardType.UNSPECIFIED]: "unknown",
262
+ [proto.data.RewardType.UNRECOGNIZED]: "unknown",
263
+ } as const;
264
+
265
+ return enumMap[value] ?? "unknown";
266
+ },
267
+ encode(value) {
268
+ throw new Error("encode: not implemented");
269
+ },
270
+ },
271
+ );
272
+
273
+ export type RewardType = typeof RewardType.Type;
274
+
275
+ export const RewardAction = Schema.Struct({
276
+ _tag: tag("reward"),
277
+ reward: Schema.Struct({
278
+ author: Address,
279
+ type: RewardType,
280
+ value: U256,
281
+ }),
282
+ });
283
+
284
+ export type RewardAction = typeof RewardAction.Type;
285
+
286
+ export const CallOutput = Schema.Struct({
287
+ _tag: tag("callOutput"),
288
+ callOutput: Schema.Struct({
289
+ gasUsed: Schema.BigIntFromSelf,
290
+ output: BytesFromUint8Array,
291
+ }),
292
+ });
293
+
294
+ export type CallOutput = typeof CallOutput.Type;
295
+
296
+ export const CreateOutput = Schema.Struct({
297
+ _tag: tag("createOutput"),
298
+ createOutput: Schema.Struct({
299
+ address: Address,
300
+ code: BytesFromUint8Array,
301
+ gasUsed: Schema.BigIntFromSelf,
302
+ }),
303
+ });
304
+
305
+ export type CreateOutput = typeof CreateOutput.Type;
306
+
307
+ export const Trace = Schema.Struct({
308
+ action: Schema.Union(
309
+ CallAction,
310
+ CreateAction,
311
+ SelfDestructAction,
312
+ RewardAction,
313
+ ),
314
+ error: Schema.optional(Schema.String),
315
+ output: Schema.optional(Schema.Union(CallOutput, CreateOutput)),
316
+ subtraces: Schema.Number,
317
+ traceAddress: Schema.Array(Schema.Number),
318
+ });
319
+
320
+ export type Trace = typeof Trace.Type;
321
+
322
+ export const TransactionTrace = Schema.Struct({
323
+ filterIds: Schema.Array(Schema.Number),
324
+ transactionIndex: Schema.Number,
325
+ transactionHash: B256,
326
+ traces: Schema.Array(Trace),
327
+ });
328
+
329
+ export type TransactionTrace = typeof TransactionTrace.Type;
330
+
158
331
  export const Block = Schema.Struct({
159
332
  header: BlockHeader,
160
333
  withdrawals: Schema.Array(Withdrawal),
161
334
  transactions: Schema.Array(Transaction),
162
335
  receipts: Schema.Array(TransactionReceipt),
163
336
  logs: Schema.Array(Log),
337
+ traces: Schema.Array(TransactionTrace),
164
338
  });
165
339
 
166
340
  export type Block = typeof Block.Type;
package/src/filter.ts CHANGED
@@ -113,6 +113,7 @@ export const LogFilter = Schema.Struct({
113
113
  transactionStatus: Schema.optional(TransactionStatusFilter),
114
114
  includeTransaction: Schema.optional(Schema.Boolean),
115
115
  includeReceipt: Schema.optional(Schema.Boolean),
116
+ includeTransactionTrace: Schema.optional(Schema.Boolean),
116
117
  });
117
118
 
118
119
  export type LogFilter = typeof LogFilter.Type;
@@ -125,6 +126,7 @@ export const TransactionFilter = Schema.Struct({
125
126
  transactionStatus: Schema.optional(TransactionStatusFilter),
126
127
  includeReceipt: Schema.optional(Schema.Boolean),
127
128
  includeLogs: Schema.optional(Schema.Boolean),
129
+ includeTransactionTrace: Schema.optional(Schema.Boolean),
128
130
  });
129
131
 
130
132
  export type TransactionFilter = typeof TransactionFilter.Type;
package/src/helpers.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { Schema } from "@effect/schema";
2
+
3
+ export function tag<T extends string>(tag: T) {
4
+ return Schema.Literal(tag).pipe(
5
+ Schema.propertySignature,
6
+ Schema.fromKey("$case"),
7
+ );
8
+ }