univo 0.4.1 → 0.4.2

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/dist/cli.mjs CHANGED
@@ -5,7 +5,7 @@ import { config } from 'dotenv';
5
5
  import { WebSocket } from 'partysocket';
6
6
  import { defineCommand, runMain } from 'citty';
7
7
  import { http } from './transport.mjs';
8
- import { c as createLogger, v as version, f as name } from './shared/univo.DD1x3F1G.mjs';
8
+ import { c as createLogger, v as version, f as name } from './shared/univo.CUNaTwXY.mjs';
9
9
 
10
10
  const log = createLogger({ quiet: false });
11
11
  const dev = defineCommand({
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as Action, B as Block, E as Event, F as Filter, H as Head, e as Indexer, f as PrivateMetadata, P as PublicMetadata, g as Result, c as defineAction, a as defineEvent, d as defineIndexer } from './shared/univo.BcZ0twA5.mjs';
1
+ export { A as Action, B as Block, E as Event, F as Filter, H as Head, e as Indexer, f as PrivateMetadata, P as PublicMetadata, g as Result, c as defineAction, a as defineEvent, d as defineIndexer } from './shared/univo.Ckj3I8tQ.mjs';
2
2
  import 'viem';
3
3
  import './metadata.mjs';
4
4
  import './metadata/adapters.mjs';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as Action, B as Block, E as Event, F as Filter, H as Head, e as Indexer, f as PrivateMetadata, P as PublicMetadata, g as Result, c as defineAction, a as defineEvent, d as defineIndexer } from './shared/univo.CNIJRI7c.js';
1
+ export { A as Action, B as Block, E as Event, F as Filter, H as Head, e as Indexer, f as PrivateMetadata, P as PublicMetadata, g as Result, c as defineAction, a as defineEvent, d as defineIndexer } from './shared/univo.7S1OTdpc.js';
2
2
  import 'viem';
3
3
  import './metadata.js';
4
4
  import './metadata/adapters.js';
package/dist/index.mjs CHANGED
@@ -1,50 +1,111 @@
1
- import { hexToNumber, numberToHex, hexToBytes, keccak256, toRlp, hexToBigInt, formatTransaction, serializeTransaction, numberToBytes, isHex, concatBytes } from 'viem';
1
+ import { hexToNumber, numberToHex, hexToBytes, keccak256, toRlp, hexToBigInt, numberToBytes, isHex, concatBytes, concatHex, formatTransaction, serializeTransaction } from 'viem';
2
2
  import { local } from './transport.mjs';
3
- import { c as createLogger, r as retry, v as version, n as normalizeHex, d as decompress, i as isHexEqual, a as compress, b as iife, e as decoder } from './shared/univo.DD1x3F1G.mjs';
3
+ import { c as createLogger, r as retry, v as version, n as normalizeHex, d as decompress, i as isHexEqual, a as compress, b as iife, e as decoder } from './shared/univo.CUNaTwXY.mjs';
4
4
  import { AdapterError } from './metadata/adapters.mjs';
5
5
  import { c as createException, a as catchException } from './shared/univo.C0flyVee.mjs';
6
6
  import 'ws';
7
7
  import 'partysocket';
8
8
 
9
9
  function matchFilter(block, filter) {
10
- if (!chainValid(block, filter)) return false;
11
- if (!toBlockValid(block, filter)) return false;
12
- if (!fromBlockValid(block, filter)) return false;
13
- if (!includesLogEvent(block, filter)) return false;
14
- if (!includesLogAddress(block, filter)) return false;
15
- return true;
16
- }
17
- const chainValid = (block, filter) => {
18
- if (hexToNumber(block.eth_chainId) === filter.chain) return true;
19
- return false;
20
- };
21
- const fromBlockValid = (block, filter) => {
22
- if (hexToNumber(block.eth_getBlockByNumber.number) >= filter.fromBlock) return true;
23
- return false;
24
- };
25
- const toBlockValid = (block, filter) => {
26
- if (filter.toBlock === void 0) return true;
27
- if (hexToNumber(block.eth_getBlockByNumber.number) <= filter.toBlock) return true;
28
- return false;
29
- };
30
- const includesLogAddress = (block, filter) => {
31
- if (filter.address === void 0) return true;
32
- for (const receipt of block.eth_getBlockReceipts) {
33
- for (const log of receipt.logs) {
34
- if (isHexEqual(log.address, filter.address)) return true;
10
+ if (hexToNumber(block.eth_chainId) !== filter.chain) {
11
+ return false;
12
+ }
13
+ if (hexToNumber(block.eth_getBlockByNumber.number) < filter.fromBlock) {
14
+ return false;
15
+ }
16
+ if (typeof filter.toBlock === "number" && hexToNumber(block.eth_getBlockByNumber.number) > filter.toBlock) {
17
+ return false;
18
+ }
19
+ if (filter.address && filter.event && filter.function) {
20
+ const txs = [];
21
+ for (const tx of block.eth_getBlockByNumber.transactions) {
22
+ if (tx.to !== null && isHexEqual(tx.to, filter.address)) {
23
+ if (isHexEqual(tx.input.slice(0, 10), filter.function)) {
24
+ txs.push(tx.transactionIndex);
25
+ }
26
+ }
27
+ }
28
+ for (const receipt of block.eth_getBlockReceipts) {
29
+ for (const log of receipt.logs) {
30
+ if (log.topics[0] !== void 0 && isHexEqual(log.topics[0], filter.event)) {
31
+ if (isHexEqual(log.address, filter.address)) {
32
+ if (txs.some((tx) => isHexEqual(tx, log.transactionIndex))) {
33
+ return true;
34
+ }
35
+ }
36
+ }
37
+ }
35
38
  }
39
+ return false;
36
40
  }
37
- return false;
38
- };
39
- const includesLogEvent = (block, filter) => {
40
- if (filter.event === void 0) return true;
41
- for (const receipt of block.eth_getBlockReceipts) {
42
- for (const log of receipt.logs) {
43
- if (log.topics[0] === filter.event) return true;
41
+ if (filter.address && filter.event && filter.function === void 0) {
42
+ for (const receipt of block.eth_getBlockReceipts) {
43
+ for (const log of receipt.logs) {
44
+ if (log.topics[0] !== void 0 && isHexEqual(log.topics[0], filter.event)) {
45
+ if (isHexEqual(log.address, filter.address)) {
46
+ return true;
47
+ }
48
+ }
49
+ }
50
+ }
51
+ return false;
52
+ }
53
+ if (filter.address && filter.event === void 0 && filter.function) {
54
+ for (const tx of block.eth_getBlockByNumber.transactions) {
55
+ if (tx.to !== null && isHexEqual(tx.to, filter.address)) {
56
+ if (isHexEqual(tx.input.slice(0, 10), filter.function)) {
57
+ return true;
58
+ }
59
+ }
44
60
  }
61
+ return false;
45
62
  }
46
- return false;
47
- };
63
+ if (filter.address === void 0 && filter.event && filter.function) {
64
+ const txs = [];
65
+ for (const tx of block.eth_getBlockByNumber.transactions) {
66
+ if (tx.to !== null && isHexEqual(tx.input.slice(0, 10), filter.function)) {
67
+ txs.push(tx.transactionIndex);
68
+ }
69
+ }
70
+ for (const receipt of block.eth_getBlockReceipts) {
71
+ for (const log of receipt.logs) {
72
+ if (log.topics[0] !== void 0 && isHexEqual(log.topics[0], filter.event)) {
73
+ if (txs.some((tx) => isHexEqual(tx, log.transactionIndex))) {
74
+ return true;
75
+ }
76
+ }
77
+ }
78
+ }
79
+ return false;
80
+ }
81
+ if (filter.address === void 0 && filter.event && filter.function === void 0) {
82
+ for (const receipt of block.eth_getBlockReceipts) {
83
+ for (const log of receipt.logs) {
84
+ if (log.topics[0] !== void 0 && isHexEqual(log.topics[0], filter.event)) {
85
+ return true;
86
+ }
87
+ }
88
+ }
89
+ return false;
90
+ }
91
+ if (filter.address === void 0 && filter.event === void 0 && filter.function) {
92
+ for (const tx of block.eth_getBlockByNumber.transactions) {
93
+ if (tx.to !== null && isHexEqual(tx.input.slice(0, 10), filter.function)) {
94
+ return true;
95
+ }
96
+ }
97
+ return false;
98
+ }
99
+ if (filter.address && filter.event === void 0 && filter.function === void 0) {
100
+ for (const tx of block.eth_getBlockByNumber.transactions) {
101
+ if (isHexEqual(tx.from, filter.address) || tx.to !== null && isHexEqual(tx.to, filter.address)) {
102
+ return true;
103
+ }
104
+ }
105
+ return false;
106
+ }
107
+ return true;
108
+ }
48
109
  function defineEvent(event) {
49
110
  return event;
50
111
  }
@@ -298,6 +359,45 @@ function defineIndexer(opts) {
298
359
  const type = hexToBigInt(receipt.type);
299
360
  return type === 0n ? encoded : concatBytes([Uint8Array.of(Number(type)), encoded]);
300
361
  }
362
+ function serializeTransaction$1(tx) {
363
+ if (tx.type === "0x4") {
364
+ return concatHex([
365
+ "0x04",
366
+ toRlp([
367
+ quantityToBytes(tx.chainId),
368
+ quantityToBytes(tx.nonce),
369
+ quantityToBytes(tx.maxPriorityFeePerGas),
370
+ quantityToBytes(tx.maxFeePerGas),
371
+ quantityToBytes(tx.gas),
372
+ hexToBytes(tx.to),
373
+ quantityToBytes(tx.value),
374
+ hexToBytes(tx.input),
375
+ tx.accessList.map(({ address, storageKeys }) => [hexToBytes(address), storageKeys.map((key) => hexToBytes(key))]),
376
+ (tx.authorizationList ?? []).map((authorization) => [
377
+ quantityToBytes(authorization.chainId),
378
+ hexToBytes(authorization.address),
379
+ quantityToBytes(authorization.nonce),
380
+ quantityToBytes(authorization.yParity),
381
+ quantityToBytes(authorization.r),
382
+ quantityToBytes(authorization.s)
383
+ ]),
384
+ quantityToBytes(tx.yParity ?? tx.v),
385
+ quantityToBytes(tx.r),
386
+ quantityToBytes(tx.s)
387
+ ])
388
+ ]);
389
+ }
390
+ const { input, ...formatted } = formatTransaction(tx);
391
+ if (formatted.type === "legacy" && (formatted.v === 27n || formatted.v === 28n)) {
392
+ formatted.chainId = void 0;
393
+ }
394
+ const signature = formatted.type === "legacy" ? { r: formatted.r, s: formatted.s, v: formatted.v } : { r: formatted.r, s: formatted.s, yParity: formatted.yParity };
395
+ return serializeTransaction(
396
+ { ...formatted, data: input },
397
+ //
398
+ signature
399
+ );
400
+ }
301
401
  const SUPPORTED_TRANSACTION_TYPES = /* @__PURE__ */ new Set([0n, 1n, 2n, 3n, 4n]);
302
402
  function verifyTransactionsRoot(block) {
303
403
  const unsupportedTxs = block.eth_getBlockByNumber.transactions.filter((tx) => {
@@ -310,16 +410,7 @@ function defineIndexer(opts) {
310
410
  return log.warn("Unable to verify block `transactionsRoot` because of unsupported tx type");
311
411
  }
312
412
  const transactions = block.eth_getBlockByNumber.transactions.map((tx) => {
313
- const { input, ...formatted } = formatTransaction(tx);
314
- if (formatted.type === "legacy" && (formatted.v === 27n || formatted.v === 28n)) {
315
- formatted.chainId = void 0;
316
- }
317
- const signature = formatted.type === "legacy" ? { r: formatted.r, s: formatted.s, v: formatted.v } : { r: formatted.r, s: formatted.s, yParity: formatted.yParity };
318
- const serialized = serializeTransaction(
319
- { ...formatted, data: input },
320
- //
321
- signature
322
- );
413
+ const serialized = serializeTransaction$1(tx);
323
414
  if (!isHexEqual(tx.hash, keccak256(serialized))) {
324
415
  throw new Error(`Transaction ${tx.hash} failed serialization check`);
325
416
  }
@@ -930,6 +1021,7 @@ function defineIndexer(opts) {
930
1021
  event: filter.event,
931
1022
  address: filter.address,
932
1023
  to_block: filter.toBlock,
1024
+ function: filter.function,
933
1025
  from_block: filter.fromBlock
934
1026
  };
935
1027
  });
package/dist/proxy.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { T as Transport, I as IndexerRpc } from './shared/univo.BcZ0twA5.mjs';
1
+ import { T as Transport, I as IndexerRpc } from './shared/univo.Ckj3I8tQ.mjs';
2
2
  import 'viem';
3
3
  import './metadata.mjs';
4
4
  import './metadata/adapters.mjs';
package/dist/proxy.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { T as Transport, I as IndexerRpc } from './shared/univo.CNIJRI7c.js';
1
+ import { T as Transport, I as IndexerRpc } from './shared/univo.7S1OTdpc.js';
2
2
  import 'viem';
3
3
  import './metadata.js';
4
4
  import './metadata/adapters.js';
package/dist/proxy.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { g as getException } from './shared/univo.C0flyVee.mjs';
2
- import { c as createLogger, d as decompress, e as decoder } from './shared/univo.DD1x3F1G.mjs';
2
+ import { c as createLogger, d as decompress, e as decoder } from './shared/univo.CUNaTwXY.mjs';
3
3
 
4
4
  function http(opts) {
5
5
  const log = createLogger({ quiet: opts.quiet, prefix: "[proxy]" });
@@ -1,4 +1,4 @@
1
- import { T as Transport, R as Rpc, I as IndexerRpc } from './shared/univo.BcZ0twA5.mjs';
1
+ import { T as Transport, R as Rpc, I as IndexerRpc } from './shared/univo.Ckj3I8tQ.mjs';
2
2
  import 'viem';
3
3
  import './metadata.mjs';
4
4
  import './metadata/adapters.mjs';
@@ -1,4 +1,4 @@
1
- import { T as Transport, R as Rpc, I as IndexerRpc } from './shared/univo.CNIJRI7c.js';
1
+ import { T as Transport, R as Rpc, I as IndexerRpc } from './shared/univo.7S1OTdpc.js';
2
2
  import 'viem';
3
3
  import './metadata.js';
4
4
  import './metadata/adapters.js';
package/dist/realtime.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { hexToNumber } from 'viem';
2
- import { c as createLogger, b as iife, m as mutex, l as lifecycle, q as queue, r as retry, i as isHexEqual } from './shared/univo.DD1x3F1G.mjs';
2
+ import { c as createLogger, b as iife, m as mutex, l as lifecycle, q as queue, r as retry, i as isHexEqual } from './shared/univo.CUNaTwXY.mjs';
3
3
 
4
4
  function defineBlockchain(opts) {
5
5
  const log = createLogger({ quiet: opts.quiet });
package/dist/rpc.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { I as IndexerRpc, R as Rpc } from './shared/univo.BcZ0twA5.mjs';
1
+ export { I as IndexerRpc, R as Rpc } from './shared/univo.Ckj3I8tQ.mjs';
2
2
  import 'viem';
3
3
  import './metadata.mjs';
4
4
  import './metadata/adapters.mjs';
package/dist/rpc.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { I as IndexerRpc, R as Rpc } from './shared/univo.CNIJRI7c.js';
1
+ export { I as IndexerRpc, R as Rpc } from './shared/univo.7S1OTdpc.js';
2
2
  import 'viem';
3
3
  import './metadata.js';
4
4
  import './metadata/adapters.js';
@@ -119,21 +119,7 @@ type Flatten<T> = {
119
119
  };
120
120
 
121
121
  /**
122
- * The minimum RPC data required to process a block.
123
- *
124
- * Extend this interface in your application to expose additional RPC methods to every event:
125
- *
126
- * ```ts
127
- * import "univo";
128
- *
129
- * declare module "univo" {
130
- * interface Block {
131
- * eth_getBalance: `0x${string}`;
132
- * }
133
- * }
134
- * ```
135
- *
136
- * Your `getBlock` function must also return any required fields added by the augmentation.
122
+ * Block
137
123
  */
138
124
  interface Block {
139
125
  eth_chainId: `0x${string}`;
@@ -154,6 +140,8 @@ type Filter = {
154
140
  event?: `0x${string}`;
155
141
  /** Index blocks that involve this address */
156
142
  address?: `0x${string}`;
143
+ /** Index blocks where this function signature was invoked */
144
+ function?: `0x${string}`;
157
145
  };
158
146
  /**
159
147
  * Events -----------------------------------------------------------------------------------------------------------------------------------
@@ -1,5 +1,5 @@
1
1
  const name = "univo";
2
- const version = "0.4.1";
2
+ const version = "0.4.2";
3
3
 
4
4
  function createLogger(opts) {
5
5
  const noop = (..._) => {
@@ -119,21 +119,7 @@ type Flatten<T> = {
119
119
  };
120
120
 
121
121
  /**
122
- * The minimum RPC data required to process a block.
123
- *
124
- * Extend this interface in your application to expose additional RPC methods to every event:
125
- *
126
- * ```ts
127
- * import "univo";
128
- *
129
- * declare module "univo" {
130
- * interface Block {
131
- * eth_getBalance: `0x${string}`;
132
- * }
133
- * }
134
- * ```
135
- *
136
- * Your `getBlock` function must also return any required fields added by the augmentation.
122
+ * Block
137
123
  */
138
124
  interface Block {
139
125
  eth_chainId: `0x${string}`;
@@ -154,6 +140,8 @@ type Filter = {
154
140
  event?: `0x${string}`;
155
141
  /** Index blocks that involve this address */
156
142
  address?: `0x${string}`;
143
+ /** Index blocks where this function signature was invoked */
144
+ function?: `0x${string}`;
157
145
  };
158
146
  /**
159
147
  * Events -----------------------------------------------------------------------------------------------------------------------------------
@@ -1,4 +1,4 @@
1
- export { T as Transport, b as browser, h as http, l as local, w as wss } from './shared/univo.BcZ0twA5.mjs';
1
+ export { T as Transport, b as browser, h as http, l as local, w as wss } from './shared/univo.Ckj3I8tQ.mjs';
2
2
  import 'viem';
3
3
  import './metadata.mjs';
4
4
  import './metadata/adapters.mjs';
@@ -1,4 +1,4 @@
1
- export { T as Transport, b as browser, h as http, l as local, w as wss } from './shared/univo.CNIJRI7c.js';
1
+ export { T as Transport, b as browser, h as http, l as local, w as wss } from './shared/univo.7S1OTdpc.js';
2
2
  import 'viem';
3
3
  import './metadata.js';
4
4
  import './metadata/adapters.js';
@@ -1,6 +1,6 @@
1
1
  import ws from 'ws';
2
2
  import { WebSocket } from 'partysocket';
3
- import { a as compress, c as createLogger, m as mutex } from './shared/univo.DD1x3F1G.mjs';
3
+ import { a as compress, c as createLogger, m as mutex } from './shared/univo.CUNaTwXY.mjs';
4
4
 
5
5
  const DEFAULT_TIMEOUT_MS = 60 * 1e3;
6
6
  function local(rpc) {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "univo",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "0.4.1",
5
+ "version": "0.4.2",
6
6
  "sideEffects": false,
7
7
  "module": "./dist/index.mjs",
8
8
  "types": "./dist/index.d.ts",