@valve-tech/chain-source 0.5.0 → 0.7.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.
- package/CHANGELOG.md +93 -0
- package/README.md +76 -18
- package/dist/capabilities.d.ts +42 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +98 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/index.d.ts +27 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -1
- package/dist/index.js.map +1 -1
- package/dist/mempool.d.ts +37 -0
- package/dist/mempool.d.ts.map +1 -0
- package/dist/mempool.js +54 -0
- package/dist/mempool.js.map +1 -0
- package/dist/source.d.ts +128 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +198 -0
- package/dist/source.js.map +1 -0
- package/dist/subscriptions.d.ts +42 -0
- package/dist/subscriptions.d.ts.map +1 -0
- package/dist/subscriptions.js +66 -0
- package/dist/subscriptions.js.map +1 -0
- package/dist/transport.d.ts +84 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +106 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +161 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +22 -0
- package/dist/types.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAYH,uEAAuE;AACvE,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAA;AAE9C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,MAAoB,EACpB,MAAc,EACd,MAAiB,EACjB,OAAgC,EACb,EAAE;IACrB,IAAI,CAAC;QACH,+DAA+D;QAC/D,8DAA8D;QAC9D,yDAAyD;Q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BAAgB,EAChB,CAAC,KAAK,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,WAAW,CAAC,EACvD,OAAO,CACR,CAAA;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,MAAoB,EACpB,OAAgC,EACD,EAAE,CACjC,WAAW,CAAgB,MAAM,EAAE,gBAAgB,EAAE,EAAE,EAAE,OAAO,CAAC,CAAA;AAEnE;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,MAAoB,EACpB,IAAY,EACZ,OAAgC,EACI,EAAE,CACtC,WAAW,CACT,MAAM,EACN,2BAA2B,EAC3B,CAAC,IAAI,CAAC,EACN,OAAO,CACR,CAAA;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EACnC,MAAoB,EACpB,IAAY,EACZ,OAAgC,EACT,EAAE,CACzB,WAAW,CAAQ,MAAM,EAAE,0BAA0B,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical wire-shape types for `@valve-tech/chain-source`. Pure data
|
|
3
|
+
* shapes — no deps, no runtime behavior.
|
|
4
|
+
*
|
|
5
|
+
* **Wire format note.** Numeric fields that come from the EVM (block
|
|
6
|
+
* numbers, gas, fees, timestamps) are kept as `bigint` once decoded.
|
|
7
|
+
* The boundary types (`BlockResult`, `TxPoolContent`, `FeeHistoryResult`)
|
|
8
|
+
* keep them as hex strings because that is what `eth_getBlockByNumber`
|
|
9
|
+
* et al. return — the source decodes at the point of use, then returns
|
|
10
|
+
* `bigint`-typed objects to consumers (oracle, tracker). `JSON.stringify`
|
|
11
|
+
* on a state with `bigint` will throw; persistence layers hex-encode
|
|
12
|
+
* at their wire boundary, see `docs/tx-tracker-spec.md` §2.5.
|
|
13
|
+
*
|
|
14
|
+
* The shapes here are **functionally identical** to the equivalent
|
|
15
|
+
* types currently in `@valve-tech/gas-oracle/src/transport.ts` and
|
|
16
|
+
* `mempool.ts`. That is intentional — a future PR migrates gas-oracle
|
|
17
|
+
* to import from this package and removes its local copies. Keeping
|
|
18
|
+
* them structurally identical now means the migration is a simple
|
|
19
|
+
* import swap, not a type-shape change.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Minimal tx shape extracted from `eth_getBlockByNumber(latest, true)`
|
|
23
|
+
* or `txpool_content`. Hash, sender (`from`), and `nonce` support
|
|
24
|
+
* mempool lookups (`findInMempool`-style helpers downstream); fee
|
|
25
|
+
* fields drive any downstream tip math; other tx fields
|
|
26
|
+
* (to/value/data/etc.) are not required by the source.
|
|
27
|
+
*
|
|
28
|
+
* The three identity fields (`hash`, `from`, `nonce`) are nominally
|
|
29
|
+
* optional because tests may construct fixtures with only the bits
|
|
30
|
+
* they exercise. In practice every modern EVM client populates all
|
|
31
|
+
* three on both `eth_getBlockByNumber(_, true)` and `txpool_content`.
|
|
32
|
+
*/
|
|
33
|
+
export interface RawTx {
|
|
34
|
+
maxPriorityFeePerGas?: string;
|
|
35
|
+
maxFeePerGas?: string;
|
|
36
|
+
gasPrice?: string;
|
|
37
|
+
gas?: string;
|
|
38
|
+
type?: string;
|
|
39
|
+
hash?: string;
|
|
40
|
+
from?: string;
|
|
41
|
+
nonce?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Result shape returned by `eth_feeHistory`. Hex-encoded numbers; the
|
|
45
|
+
* source decodes at the point of use.
|
|
46
|
+
*/
|
|
47
|
+
export interface FeeHistoryResult {
|
|
48
|
+
baseFeePerGas: string[];
|
|
49
|
+
reward?: string[][];
|
|
50
|
+
gasUsedRatio: number[];
|
|
51
|
+
oldestBlock: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Result shape returned by `eth_getBlockByNumber` with
|
|
55
|
+
* `fullTransactions=true`. Hex-encoded numbers; consumers
|
|
56
|
+
* (oracle, tracker) decode the fields they need.
|
|
57
|
+
*/
|
|
58
|
+
export interface BlockResult {
|
|
59
|
+
number: string;
|
|
60
|
+
hash?: string;
|
|
61
|
+
parentHash?: string;
|
|
62
|
+
timestamp: string;
|
|
63
|
+
baseFeePerGas: string;
|
|
64
|
+
gasLimit: string;
|
|
65
|
+
gasUsed: string;
|
|
66
|
+
transactions: RawTx[];
|
|
67
|
+
excessBlobGas?: string;
|
|
68
|
+
blobGasUsed?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Result shape returned by `txpool_content`. Two-level map: sender
|
|
72
|
+
* address → nonce → RawTx, split into `pending` (next-in-line) and
|
|
73
|
+
* `queued` (gap txs that can't mine yet).
|
|
74
|
+
*
|
|
75
|
+
* Upstream clients are inconsistent about address case (geth/reth use
|
|
76
|
+
* EIP-55 checksum; some clients lowercase) and nonce encoding (hex vs
|
|
77
|
+
* decimal). Pass through `normalizeMempool` once at ingest to get a
|
|
78
|
+
* canonical `NormalizedMempool` (lowercase addresses, decimal nonces);
|
|
79
|
+
* lookup helpers expect that form.
|
|
80
|
+
*/
|
|
81
|
+
export interface TxPoolContent {
|
|
82
|
+
pending: Record<string, Record<string, RawTx>>;
|
|
83
|
+
queued: Record<string, Record<string, RawTx>>;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* `TxPoolContent` after a single normalization pass — every sender
|
|
87
|
+
* address key is lowercase ASCII, every nonce key is a decimal string.
|
|
88
|
+
* Structural alias of `TxPoolContent`; the type name signals the
|
|
89
|
+
* invariant to downstream lookup helpers.
|
|
90
|
+
*/
|
|
91
|
+
export type NormalizedMempool = TxPoolContent;
|
|
92
|
+
/**
|
|
93
|
+
* Single full-block fetch shape. viem's `getTransactionReceipt` returns
|
|
94
|
+
* a richer object than this minimal type captures; consumers cast as
|
|
95
|
+
* needed. Source-level shape is loose because `txpool_content` /
|
|
96
|
+
* receipts vary slightly across clients and we don't want a strict
|
|
97
|
+
* shape rejecting a working response.
|
|
98
|
+
*/
|
|
99
|
+
export interface TransactionReceipt {
|
|
100
|
+
transactionHash: string;
|
|
101
|
+
blockHash: string;
|
|
102
|
+
blockNumber: string;
|
|
103
|
+
status?: string;
|
|
104
|
+
[key: string]: unknown;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Producer-side toggles: which RPCs the source's poll loop fans out
|
|
108
|
+
* each cycle. Fields default to `true`. `eth_getBlockByNumber` is
|
|
109
|
+
* intentionally not toggleable — without a block neither downstream
|
|
110
|
+
* consumer can do anything.
|
|
111
|
+
*
|
|
112
|
+
* - `feeHistory: false` — drops `eth_feeHistory`. Downstream consumers
|
|
113
|
+
* relying on multi-block trend detection lose
|
|
114
|
+
* fidelity (single-element fallback is
|
|
115
|
+
* conservative).
|
|
116
|
+
* - `mempool: false` — drops `txpool_content`. Mempool subscribers
|
|
117
|
+
* never receive snapshots; `getMempoolSnapshot`
|
|
118
|
+
* returns `null`. Useful when the upstream
|
|
119
|
+
* provider gates the method.
|
|
120
|
+
*/
|
|
121
|
+
export interface PollOptions {
|
|
122
|
+
feeHistory?: boolean;
|
|
123
|
+
mempool?: boolean;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* How the source observed a particular fact. Discriminates the
|
|
127
|
+
* authority of any downstream-built event. The same chain-state can
|
|
128
|
+
* legitimately be observed via four paths; consumers that need hard
|
|
129
|
+
* guarantees filter to `'subscription'`.
|
|
130
|
+
*
|
|
131
|
+
* `'block-poll'` and `'mempool-snapshot'` indicate the source's
|
|
132
|
+
* own poll cycle pulled the data via `eth_getBlockByNumber` /
|
|
133
|
+
* `txpool_content` respectively. `'receipt-poll'` is reserved for
|
|
134
|
+
* downstream consumers (tx-tracker) that fall back to per-hash
|
|
135
|
+
* receipt polling when a higher-authority path is missing.
|
|
136
|
+
*/
|
|
137
|
+
export type EventSource = 'subscription' | 'block-poll' | 'mempool-snapshot' | 'receipt-poll';
|
|
138
|
+
/**
|
|
139
|
+
* Per-method capability snapshot. Probed once on `source.start()` and
|
|
140
|
+
* re-probed on transport reconnect when the underlying transport
|
|
141
|
+
* supports reconnection signals.
|
|
142
|
+
*
|
|
143
|
+
* Intentionally per-method, not per-transport — real-world providers
|
|
144
|
+
* gate `txpool_content` while allowing `eth_subscribe('newHeads')`,
|
|
145
|
+
* and chains expose `txpool_content` while never offering
|
|
146
|
+
* `newPendingTransactions`. A single "ws-or-http" knob would elide
|
|
147
|
+
* cases the toolkit needs to cover.
|
|
148
|
+
*/
|
|
149
|
+
export interface Capabilities {
|
|
150
|
+
/** `eth_subscribe('newHeads')` push-based new-block events. */
|
|
151
|
+
newHeads: 'subscription' | 'poll-only' | 'unavailable';
|
|
152
|
+
/** `eth_subscribe('newPendingTransactions')` push-based mempool ingress. */
|
|
153
|
+
newPendingTransactions: 'subscription' | 'poll-only' | 'unavailable';
|
|
154
|
+
/** `txpool_content` support — many public RPCs gate this method. */
|
|
155
|
+
txpoolContent: 'available' | 'gated';
|
|
156
|
+
/** `eth_getTransactionReceipt` fallback path for inclusion watch. */
|
|
157
|
+
receiptByHash: 'available' | 'unavailable';
|
|
158
|
+
/** Whether transport reconnection re-probes (WS reconnect, etc.). */
|
|
159
|
+
reprobeOnReconnect: boolean;
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,KAAK;IACpB,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MA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,CAAC,EAAE,OAAO,CAAA;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,GACnB,cAAc,GACd,YAAY,GACZ,kBAAkB,GAClB,cAAc,CAAA;AAElB;;;;;;;;;;GAUG;AACH,MAAM,WAAW,YAAY;IAC3B,+DAA+D;IAC/D,QAAQ,EAAE,cAAc,GAAG,WAAW,GAAG,aAAa,CAAA;IACtD,4EAA4E;IAC5E,sBAAsB,EAAE,cAAc,GAAG,WAAW,GAAG,aAAa,CAAA;IACpE,oEAAoE;IACpE,aAAa,EAAE,WAAW,GAAG,OAAO,CAAA;IACpC,qEAAqE;IACrE,aAAa,EAAE,WAAW,GAAG,aAAa,CAAA;IAC1C,qEAAqE;IACrE,kBAAkB,EAAE,OAAO,CAAA;CAC5B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical wire-shape types for `@valve-tech/chain-source`. Pure data
|
|
3
|
+
* shapes — no deps, no runtime behavior.
|
|
4
|
+
*
|
|
5
|
+
* **Wire format note.** Numeric fields that come from the EVM (block
|
|
6
|
+
* numbers, gas, fees, timestamps) are kept as `bigint` once decoded.
|
|
7
|
+
* The boundary types (`BlockResult`, `TxPoolContent`, `FeeHistoryResult`)
|
|
8
|
+
* keep them as hex strings because that is what `eth_getBlockByNumber`
|
|
9
|
+
* et al. return — the source decodes at the point of use, then returns
|
|
10
|
+
* `bigint`-typed objects to consumers (oracle, tracker). `JSON.stringify`
|
|
11
|
+
* on a state with `bigint` will throw; persistence layers hex-encode
|
|
12
|
+
* at their wire boundary, see `docs/tx-tracker-spec.md` §2.5.
|
|
13
|
+
*
|
|
14
|
+
* The shapes here are **functionally identical** to the equivalent
|
|
15
|
+
* types currently in `@valve-tech/gas-oracle/src/transport.ts` and
|
|
16
|
+
* `mempool.ts`. That is intentional — a future PR migrates gas-oracle
|
|
17
|
+
* to import from this package and removes its local copies. Keeping
|
|
18
|
+
* them structurally identical now means the migration is a simple
|
|
19
|
+
* import swap, not a type-shape change.
|
|
20
|
+
*/
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@valve-tech/chain-source",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Canonical EVM chain-observation primitive: a unified push-or-poll source for new blocks, mempool snapshots, on-demand receipt + tx lookups, and capability disclosure (HTTP / WS / per-method gating). Used as the shared foundation by @valve-tech/gas-oracle and @valve-tech/tx-tracker; consumable directly by anyone building their own derived view on chain state. viem-native. Part of the valve-tech/evm-toolkit synchronized release line — implementation lands in subsequent 0.3.x releases per docs/tx-tracker-spec.md.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/valve-tech/evm-toolkit/tree/main/packages/chain-source#readme",
|