@apibara/evm 2.0.0 → 2.0.1-beta.1

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,9 +1,14 @@
1
1
  {
2
2
  "name": "@apibara/evm",
3
- "version": "2.0.0",
3
+ "version": "2.0.1-beta.1",
4
4
  "type": "module",
5
- "source": "./src/index.ts",
5
+ "files": [
6
+ "dist",
7
+ "src",
8
+ "README.md"
9
+ ],
6
10
  "main": "./dist/index.mjs",
11
+ "types": "./dist/index.d.ts",
7
12
  "exports": {
8
13
  ".": {
9
14
  "types": "./dist/index.d.ts",
@@ -12,12 +17,15 @@
12
17
  "default": "./dist/index.mjs"
13
18
  }
14
19
  },
15
- "publishConfig": {
16
- "files": [
17
- "dist",
18
- "src",
19
- "README.md"
20
- ]
20
+ "scripts": {
21
+ "build": "pnpm build:proto && unbuild",
22
+ "build:proto": "buf generate proto",
23
+ "typecheck": "tsc --noEmit",
24
+ "test": "vitest",
25
+ "test:ci": "vitest run",
26
+ "lint": "biome check .",
27
+ "lint:fix": "pnpm lint --write",
28
+ "format": "biome format . --write"
21
29
  },
22
30
  "devDependencies": {
23
31
  "@bufbuild/buf": "^1.32.1",
@@ -27,23 +35,12 @@
27
35
  "vitest": "^1.6.0"
28
36
  },
29
37
  "dependencies": {
38
+ "@apibara/protocol": "2.0.0-beta.9",
30
39
  "@effect/schema": "^0.67.15",
31
40
  "effect": "^3.2.6",
32
41
  "long": "^5.2.1",
33
42
  "nice-grpc-common": "^2.0.2",
34
43
  "protobufjs": "^7.1.2",
35
- "viem": "^2.12.4",
36
- "@apibara/protocol": "2.0.0-beta.1"
37
- },
38
- "scripts": {
39
- "build": "pnpm build:proto && unbuild",
40
- "build:proto": "buf generate proto",
41
- "typecheck": "tsc --noEmit",
42
- "test": "vitest",
43
- "test:ci": "vitest run",
44
- "lint": "biome check .",
45
- "lint:fix": "pnpm lint --write",
46
- "format": "biome format . --write"
47
- },
48
- "types": "./dist/index.d.ts"
49
- }
44
+ "viem": "^2.12.4"
45
+ }
46
+ }
package/src/block.ts CHANGED
@@ -4,7 +4,7 @@ import { Schema } from "@effect/schema";
4
4
  import { Address, B256, U128, U256 } from "./common";
5
5
  import * as proto from "./proto";
6
6
 
7
- export const HexData = Schema.transform(
7
+ export const Bloom = Schema.transform(
8
8
  Schema.Struct({
9
9
  value: BytesFromUint8Array,
10
10
  }),
@@ -15,64 +15,67 @@ export const HexData = Schema.transform(
15
15
  throw new Error("Not implemented");
16
16
  },
17
17
  decode({ value }) {
18
- // return value;
19
- throw new Error("Not implemented");
18
+ return value;
20
19
  },
21
20
  },
22
21
  );
23
22
 
24
- export const Bloom = Schema.transform(
25
- Schema.Struct({
26
- value: BytesFromUint8Array,
27
- }),
28
- Bytes,
23
+ export const TransactionStatus = Schema.transform(
24
+ Schema.Enums(proto.data.TransactionStatus),
25
+ Schema.Literal("unknown", "succeeded", "reverted"),
29
26
  {
30
- strict: false,
31
- encode(value) {
32
- throw new Error("Not implemented");
27
+ decode(value) {
28
+ const enumMap = {
29
+ [proto.data.TransactionStatus.SUCCEEDED]: "succeeded",
30
+ [proto.data.TransactionStatus.REVERTED]: "reverted",
31
+ [proto.data.TransactionStatus.UNSPECIFIED]: "unknown",
32
+ [proto.data.TransactionStatus.UNRECOGNIZED]: "unknown",
33
+ } as const;
34
+
35
+ return enumMap[value] ?? "unknown";
33
36
  },
34
- decode({ value }) {
35
- throw new Error("Not implemented");
36
- // return value;
37
+ encode(value) {
38
+ throw new Error("encode: not implemented");
37
39
  },
38
40
  },
39
41
  );
40
42
 
43
+ export type TransactionStatus = typeof TransactionStatus.Type;
44
+
41
45
  export const BlockHeader = Schema.Struct({
42
- number: Schema.BigIntFromSelf,
43
- hash: Schema.optional(B256),
44
- parentHash: Schema.optional(B256),
45
- uncleHash: Schema.optional(B256),
46
+ blockNumber: Schema.BigIntFromSelf,
47
+ blockHash: Schema.optional(B256),
48
+ parentBlockHash: Schema.optional(B256),
49
+ unclesHash: Schema.optional(B256),
46
50
  miner: Schema.optional(Address),
47
51
  stateRoot: Schema.optional(B256),
48
- transactionRoot: Schema.optional(B256),
49
- receiptRoot: Schema.optional(B256),
52
+ transactionsRoot: Schema.optional(B256),
53
+ receiptsRoot: Schema.optional(B256),
50
54
  logsBloom: Schema.optional(Bloom),
51
55
  difficulty: Schema.optional(U256),
52
- gasLimit: Schema.optional(U256),
53
- gasUsed: Schema.optional(U256),
56
+ gasLimit: Schema.optional(U128),
57
+ gasUsed: Schema.optional(U128),
54
58
  timestamp: Schema.optional(Schema.DateFromSelf),
55
- // extraData: Schema.optional(HexData),
59
+ extraData: BytesFromUint8Array,
56
60
  mixHash: Schema.optional(B256),
57
- nonce: Schema.BigIntFromSelf,
58
- baseFeePerGas: Schema.optional(U256),
61
+ nonce: Schema.optional(Schema.BigIntFromSelf),
62
+ baseFeePerGas: Schema.optional(U128),
59
63
  withdrawalsRoot: Schema.optional(B256),
60
64
  totalDifficulty: Schema.optional(U256),
61
- uncles: Schema.Array(B256),
62
- size: Schema.optional(U256),
63
- blobGasUsed: Schema.BigIntFromSelf,
64
- excessBlobGas: Schema.BigIntFromSelf,
65
+ blobGasUsed: Schema.optional(U128),
66
+ excessBlobGas: Schema.optional(U128),
65
67
  parentBeaconBlockRoot: Schema.optional(B256),
66
68
  });
67
69
 
68
70
  export type BlockHeader = typeof BlockHeader.Type;
69
71
 
70
72
  export const Withdrawal = Schema.Struct({
73
+ filterIds: Schema.optional(Schema.Array(Schema.Number)),
74
+ withdrawalIndex: Schema.Number,
71
75
  index: Schema.BigIntFromSelf,
72
- validatorIndex: Schema.BigIntFromSelf,
73
- withdrawalIndex: Schema.BigIntFromSelf,
76
+ validatorIndex: Schema.Number,
74
77
  address: Schema.optional(Address),
75
- amount: Schema.optional(U256),
78
+ amount: Schema.optional(Schema.BigIntFromSelf),
76
79
  });
77
80
 
78
81
  export const AccessListItem = Schema.Struct({
@@ -88,50 +91,53 @@ export const Signature = Schema.Struct({
88
91
  });
89
92
 
90
93
  export const Transaction = Schema.Struct({
91
- hash: Schema.optional(B256),
92
- nonce: Schema.BigIntFromSelf,
93
- transactionIndex: Schema.BigIntFromSelf,
94
+ filterIds: Schema.optional(Schema.Array(Schema.Number)),
95
+ transactionIndex: Schema.Number,
96
+ transactionHash: Schema.optional(B256),
97
+ nonce: Schema.optional(Schema.BigIntFromSelf),
94
98
  from: Schema.optional(Address),
95
99
  to: Schema.optional(Address),
96
100
  value: Schema.optional(U256),
97
101
  gasPrice: Schema.optional(U128),
98
- gas: Schema.optional(U256),
102
+ gas: Schema.optional(U128),
99
103
  maxFeePerGas: Schema.optional(U128),
100
104
  maxPriorityFeePerGas: Schema.optional(U128),
101
- // TODO
102
- // input: Schema.optional(HexData),
105
+ input: BytesFromUint8Array,
103
106
  signature: Schema.optional(Signature),
104
- chainId: Schema.BigIntFromSelf,
107
+ chainId: Schema.optional(Schema.BigIntFromSelf),
105
108
  accessList: Schema.Array(AccessListItem),
106
- transactionType: Schema.BigIntFromSelf,
109
+ transactionType: Schema.optional(Schema.BigIntFromSelf),
107
110
  maxFeePerBlobGas: Schema.optional(U128),
108
111
  blobVersionedHashes: Schema.Array(B256),
112
+ transactionStatus: Schema.optional(TransactionStatus),
109
113
  });
110
114
 
111
115
  export const TransactionReceipt = Schema.Struct({
116
+ filterIds: Schema.optional(Schema.Array(Schema.Number)),
117
+ transactionIndex: Schema.optional(Schema.Number),
112
118
  transactionHash: Schema.optional(B256),
113
- transactionIndex: Schema.BigIntFromSelf,
114
- cumulativeGasUsed: Schema.optional(U256),
115
- gasUsed: Schema.optional(U256),
119
+ cumulativeGasUsed: Schema.optional(U128),
120
+ gasUsed: Schema.optional(U128),
116
121
  effectiveGasPrice: Schema.optional(U128),
117
122
  from: Schema.optional(Address),
118
123
  to: Schema.optional(Address),
119
124
  contractAddress: Schema.optional(Address),
120
125
  logsBloom: Schema.optional(Bloom),
121
- statusCode: Schema.BigIntFromSelf,
122
- transactionType: Schema.BigIntFromSelf,
126
+ transactionType: Schema.optional(Schema.BigIntFromSelf),
123
127
  blobGasUsed: Schema.optional(U128),
124
128
  blobGasPrice: Schema.optional(U128),
129
+ transactionStatus: Schema.optional(TransactionStatus),
125
130
  });
126
131
 
127
132
  export const Log = Schema.Struct({
133
+ filterIds: Schema.optional(Schema.Array(Schema.Number)),
128
134
  address: Schema.optional(Address),
129
135
  topics: Schema.Array(B256),
130
- // TODO
131
- // data: Bytes,
132
- logIndex: Schema.BigIntFromSelf,
133
- transactionIndex: Schema.BigIntFromSelf,
136
+ data: BytesFromUint8Array,
137
+ logIndex: Schema.Number,
138
+ transactionIndex: Schema.Number,
134
139
  transactionHash: Schema.optional(B256),
140
+ transactionStatus: Schema.optional(TransactionStatus),
135
141
  });
136
142
 
137
143
  export type Log = typeof Log.Type;
package/src/common.ts CHANGED
@@ -35,7 +35,7 @@ export type Address = typeof Address.Type;
35
35
  const _B256 = Schema.TemplateLiteral(Schema.Literal("0x"), Schema.String);
36
36
 
37
37
  /** Wire representation of `B256`. */
38
- const B256Proto = Schema.Struct({
38
+ export const B256Proto = Schema.Struct({
39
39
  x0: Schema.BigIntFromSelf,
40
40
  x1: Schema.BigIntFromSelf,
41
41
  x2: Schema.BigIntFromSelf,
@@ -87,23 +87,19 @@ describe("LogFilter", () => {
87
87
 
88
88
  describe("mergeFilter", () => {
89
89
  it("returns header.always if any has it", () => {
90
- const fa = mergeFilter({}, { header: { always: true } });
90
+ const fa = mergeFilter({}, { header: "always" });
91
91
  expect(fa).toMatchInlineSnapshot(`
92
92
  {
93
- "header": {
94
- "always": true,
95
- },
93
+ "header": "always",
96
94
  "logs": [],
97
95
  "transactions": [],
98
96
  "withdrawals": [],
99
97
  }
100
98
  `);
101
- const fb = mergeFilter({ header: { always: true } }, {});
99
+ const fb = mergeFilter({ header: "always" }, {});
102
100
  expect(fb).toMatchInlineSnapshot(`
103
101
  {
104
- "header": {
105
- "always": true,
106
- },
102
+ "header": "always",
107
103
  "logs": [],
108
104
  "transactions": [],
109
105
  "withdrawals": [],
@@ -169,8 +165,8 @@ describe("mergeFilter", () => {
169
165
 
170
166
  it("concatenates withdrawals", () => {
171
167
  const f = mergeFilter(
172
- { withdrawals: [{ validatorIndex: 1n }] },
173
- { withdrawals: [{ validatorIndex: 100n }] },
168
+ { withdrawals: [{ validatorIndex: 1 }] },
169
+ { withdrawals: [{ validatorIndex: 100 }] },
174
170
  );
175
171
  expect(f).toMatchInlineSnapshot(`
176
172
  {
@@ -179,10 +175,10 @@ describe("mergeFilter", () => {
179
175
  "transactions": [],
180
176
  "withdrawals": [
181
177
  {
182
- "validatorIndex": 1n,
178
+ "validatorIndex": 1,
183
179
  },
184
180
  {
185
- "validatorIndex": 100n,
181
+ "validatorIndex": 100,
186
182
  },
187
183
  ],
188
184
  }
package/src/filter.ts CHANGED
@@ -1,51 +1,114 @@
1
1
  import { Schema } from "@effect/schema";
2
2
 
3
- import { Address, B256, b256FromProto, b256ToProto } from "./common";
3
+ import { Address, B256, B256Proto } from "./common";
4
4
 
5
5
  import * as proto from "./proto";
6
6
 
7
7
  const OptionalArray = <TSchema extends Schema.Schema.Any>(schema: TSchema) =>
8
8
  Schema.optional(Schema.Array(schema));
9
9
 
10
- export const HeaderFilter = Schema.Struct({
11
- always: Schema.optional(Schema.Boolean),
12
- });
10
+ /** Header options.
11
+ *
12
+ * - `always`: receive all block headers.
13
+ * - `on_data`: receive headers only if any other filter matches.
14
+ * - `on_data_or_on_new_block`: receive headers only if any other filter matches and for "live" blocks.
15
+ */
16
+ export const HeaderFilter = Schema.transform(
17
+ Schema.Enums(proto.filter.HeaderFilter),
18
+ Schema.Literal("always", "on_data", "on_data_or_on_new_block", "unknown"),
19
+ {
20
+ decode(value) {
21
+ const enumMap = {
22
+ [proto.filter.HeaderFilter.ALWAYS]: "always",
23
+ [proto.filter.HeaderFilter.ON_DATA]: "on_data",
24
+ [proto.filter.HeaderFilter.ON_DATA_OR_ON_NEW_BLOCK]:
25
+ "on_data_or_on_new_block",
26
+ [proto.filter.HeaderFilter.UNSPECIFIED]: "unknown",
27
+ [proto.filter.HeaderFilter.UNRECOGNIZED]: "unknown",
28
+ } as const;
29
+ return enumMap[value] ?? "unknown";
30
+ },
31
+ encode(value) {
32
+ switch (value) {
33
+ case "always":
34
+ return proto.filter.HeaderFilter.ALWAYS;
35
+ case "on_data":
36
+ return proto.filter.HeaderFilter.ON_DATA;
37
+ case "on_data_or_on_new_block":
38
+ return proto.filter.HeaderFilter.ON_DATA_OR_ON_NEW_BLOCK;
39
+ default:
40
+ return proto.filter.HeaderFilter.UNSPECIFIED;
41
+ }
42
+ },
43
+ },
44
+ );
13
45
 
14
46
  export type HeaderFilter = typeof HeaderFilter.Type;
15
47
 
16
48
  export const WithdrawalFilter = Schema.Struct({
17
- validatorIndex: Schema.optional(Schema.BigIntFromSelf),
49
+ id: Schema.optional(Schema.Number),
50
+ validatorIndex: Schema.optional(Schema.Number),
18
51
  address: Schema.optional(Address),
19
52
  });
20
53
 
21
54
  export type WithdrawalFilter = typeof WithdrawalFilter.Type;
22
55
 
23
- // TODO: using the decoder inside decode/encode feels wrong.
56
+ export const TransactionStatusFilter = Schema.transform(
57
+ Schema.Enums(proto.filter.TransactionStatusFilter),
58
+ Schema.Literal("succeeded", "reverted", "all", "unknown"),
59
+ {
60
+ decode(value) {
61
+ const enumMap = {
62
+ [proto.filter.TransactionStatusFilter.SUCCEEDED]: "succeeded",
63
+ [proto.filter.TransactionStatusFilter.REVERTED]: "reverted",
64
+ [proto.filter.TransactionStatusFilter.ALL]: "all",
65
+ [proto.filter.TransactionStatusFilter.UNSPECIFIED]: "unknown",
66
+ [proto.filter.TransactionStatusFilter.UNRECOGNIZED]: "unknown",
67
+ } as const;
68
+ return enumMap[value] ?? "unknown";
69
+ },
70
+ encode(value) {
71
+ switch (value) {
72
+ case "succeeded":
73
+ return proto.filter.TransactionStatusFilter.SUCCEEDED;
74
+ case "reverted":
75
+ return proto.filter.TransactionStatusFilter.REVERTED;
76
+ case "all":
77
+ return proto.filter.TransactionStatusFilter.ALL;
78
+ default:
79
+ return proto.filter.TransactionStatusFilter.UNSPECIFIED;
80
+ }
81
+ },
82
+ },
83
+ );
84
+
85
+ export type TransactionStatusFilter = typeof TransactionStatusFilter.Type;
86
+
24
87
  export const Topic = Schema.transform(
25
- Schema.Struct({ value: Schema.UndefinedOr(B256) }),
88
+ Schema.Struct({ value: Schema.UndefinedOr(B256Proto) }),
26
89
  Schema.NullOr(B256),
27
90
  {
28
- strict: false,
29
91
  decode({ value }) {
30
92
  if (value === undefined) {
31
93
  return null;
32
94
  }
33
- return b256ToProto(value);
95
+ return value;
34
96
  },
35
97
  encode(value) {
36
98
  if (value === null) {
37
99
  return { value: undefined };
38
100
  }
39
- return { value: b256FromProto(value) };
101
+ return { value };
40
102
  },
41
103
  },
42
104
  );
43
105
 
44
106
  export const LogFilter = Schema.Struct({
107
+ id: Schema.optional(Schema.Number),
45
108
  address: Schema.optional(Address),
46
109
  topics: OptionalArray(Topic),
47
-
48
110
  strict: Schema.optional(Schema.Boolean),
111
+ transactionStatus: Schema.optional(TransactionStatusFilter),
49
112
  includeTransaction: Schema.optional(Schema.Boolean),
50
113
  includeReceipt: Schema.optional(Schema.Boolean),
51
114
  });
@@ -53,9 +116,11 @@ export const LogFilter = Schema.Struct({
53
116
  export type LogFilter = typeof LogFilter.Type;
54
117
 
55
118
  export const TransactionFilter = Schema.Struct({
119
+ id: Schema.optional(Schema.Number),
56
120
  from: Schema.optional(Address),
57
121
  to: Schema.optional(Address),
58
-
122
+ create: Schema.optional(Schema.Boolean),
123
+ transactionStatus: Schema.optional(TransactionStatusFilter),
59
124
  includeReceipt: Schema.optional(Schema.Boolean),
60
125
  includeLogs: Schema.optional(Schema.Boolean),
61
126
  });
@@ -65,8 +130,8 @@ export type TransactionFilter = typeof TransactionFilter.Type;
65
130
  export const Filter = Schema.Struct({
66
131
  header: Schema.optional(HeaderFilter),
67
132
  withdrawals: OptionalArray(WithdrawalFilter),
68
- logs: OptionalArray(LogFilter),
69
133
  transactions: OptionalArray(TransactionFilter),
134
+ logs: OptionalArray(LogFilter),
70
135
  });
71
136
 
72
137
  export type Filter = typeof Filter.Type;
@@ -111,7 +176,14 @@ function mergeHeaderFilter(
111
176
  if (b === undefined) {
112
177
  return a;
113
178
  }
114
- return {
115
- always: a.always || b.always,
116
- };
179
+
180
+ if (a === "always" || b === "always") {
181
+ return "always";
182
+ }
183
+
184
+ if (a === "on_data_or_on_new_block" || b === "on_data_or_on_new_block") {
185
+ return "on_data_or_on_new_block";
186
+ }
187
+
188
+ return "on_data";
117
189
  }
@@ -6,7 +6,7 @@
6
6
 
7
7
  /* eslint-disable */
8
8
  import Long from "long";
9
- import _m0 from "protobufjs/minimal";
9
+ import _m0 from "protobufjs/minimal.js";
10
10
 
11
11
  export const protobufPackage = "evm.v2";
12
12