univo 0.2.18 → 0.2.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/dist/cli.mjs +2 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +214 -98
- package/dist/realtime.d.mts +0 -1
- package/dist/realtime.d.ts +0 -1
- package/dist/realtime.mjs +9 -7
- package/dist/rpc.d.mts +249 -3
- package/dist/rpc.d.ts +249 -3
- package/dist/shared/{univo.GuW0GiSl.mjs → univo.D1x0MkrS.mjs} +61 -36
- package/dist/shared/{univo.TYA11b8i.mjs → univo.bwpFiVa7.mjs} +9 -4
- package/dist/transport.d.mts +4 -1
- package/dist/transport.d.ts +4 -1
- package/dist/transport.mjs +2 -2
- package/package.json +1 -1
- package/dist/shared/univo.BNqa7KED.d.mts +0 -219
- package/dist/shared/univo.BNqa7KED.d.ts +0 -219
package/dist/rpc.d.mts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Storage } from '@storagesdk/core';
|
|
2
|
+
|
|
3
|
+
type CamelToSnake<T extends string, P extends string = ""> = string extends T ? string : T extends `${infer C0}${infer R}` ? CamelToSnake<R, `${P}${C0 extends Lowercase<C0> ? "" : "_"}${Lowercase<C0>}`> : P;
|
|
4
|
+
type Flatten<T> = {
|
|
5
|
+
[K in keyof T as CamelToSnake<Extract<K, string>>]: T[K];
|
|
6
|
+
};
|
|
3
7
|
|
|
4
8
|
type Rpc = {
|
|
5
9
|
/**
|
|
@@ -98,4 +102,246 @@ type IndexerRpc = {
|
|
|
98
102
|
subscribe: Record<string, never>;
|
|
99
103
|
};
|
|
100
104
|
|
|
101
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Block -----------------------------------------------------------------------------------------------------------------------------------
|
|
107
|
+
*/
|
|
108
|
+
type Block = {
|
|
109
|
+
eth_chainId: `0x${string}`;
|
|
110
|
+
eth_getBlockByNumber: {
|
|
111
|
+
hash: `0x${string}`;
|
|
112
|
+
number: `0x${string}`;
|
|
113
|
+
parentHash: `0x${string}`;
|
|
114
|
+
};
|
|
115
|
+
eth_getBlockReceipts: Array<{
|
|
116
|
+
blockHash: `0x${string}`;
|
|
117
|
+
logs: Array<{
|
|
118
|
+
address: `0x${string}`;
|
|
119
|
+
topics: `0x${string}`[];
|
|
120
|
+
}>;
|
|
121
|
+
}>;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Filters -----------------------------------------------------------------------------------------------------------------------------------
|
|
125
|
+
*/
|
|
126
|
+
type Filter = {
|
|
127
|
+
/** Index blocks with this chain id */
|
|
128
|
+
chain: number;
|
|
129
|
+
/** Index blocks from this start block (inclusive) */
|
|
130
|
+
fromBlock: number;
|
|
131
|
+
/** Index blocks until this stop block (inclusive) */
|
|
132
|
+
toBlock?: number;
|
|
133
|
+
/** Index blocks where this event topic was emitted */
|
|
134
|
+
event?: `0x${string}`;
|
|
135
|
+
/** Index blocks that involve this address */
|
|
136
|
+
address?: `0x${string}`;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Events -----------------------------------------------------------------------------------------------------------------------------------
|
|
140
|
+
*/
|
|
141
|
+
type Event<TBlock, TEvent> = {
|
|
142
|
+
/**
|
|
143
|
+
* A human-readable identifier for the event.
|
|
144
|
+
*/
|
|
145
|
+
id: string;
|
|
146
|
+
/**
|
|
147
|
+
* Filters let you define what specific blocks you want this event to index.
|
|
148
|
+
*
|
|
149
|
+
* Blockchains are massive datasets and most of the time we are only ever interested in small portions of it.
|
|
150
|
+
* Sometimes that can be specific events like ERC20 transfers and other times it could be all events emitted
|
|
151
|
+
* by a specific contract. Filters provide a simple way for an event to define exactly which blocks we want
|
|
152
|
+
* to index.
|
|
153
|
+
*
|
|
154
|
+
* Filters reduce costs and improve backfill performance by ensuring we only index the blocks we need and
|
|
155
|
+
* ignore the blocks that don't have the data we are interested in.
|
|
156
|
+
*
|
|
157
|
+
* By default your event will not index any blocks, you must opt-in to indexing by providing atleast one filter.
|
|
158
|
+
*
|
|
159
|
+
* Each property in the filter operates like an AND statement. For example, if you specifiy an `address` and
|
|
160
|
+
* an `event` it implies that you only want to index blocks where the specific `address` emitted the specific
|
|
161
|
+
* `event` topic provided.
|
|
162
|
+
*
|
|
163
|
+
* However, when multiple filters are defined for a given event those filters operate like an OR statement. For
|
|
164
|
+
* example, if we define a second filter looking for a different `address` and `event` our event will now index
|
|
165
|
+
* any block that matches either the first filter or the second filter.
|
|
166
|
+
*
|
|
167
|
+
* Note that filters are a rudimentary method to dramatically reduce the number of blocks your application needs
|
|
168
|
+
* to index. Any advanced filtering should be performed in the event `handler` itself.
|
|
169
|
+
*/
|
|
170
|
+
filters: Filter[];
|
|
171
|
+
/**
|
|
172
|
+
* Synchronously transforms a raw block into a list of events.
|
|
173
|
+
*
|
|
174
|
+
* When a block matches any of filters defined by your event it will be passed to this function to be synchronously
|
|
175
|
+
* transformed into a list of structured events.
|
|
176
|
+
*
|
|
177
|
+
* The shape of the input `block` is determined by the return value of `getBlock` function provided to your `indexer`.
|
|
178
|
+
*
|
|
179
|
+
* The returned output value should be an array containg any valid JavaScript values. Each event that you return from
|
|
180
|
+
* your handler should not depend on any information outside of the input block data. It should directly map a given
|
|
181
|
+
* input (the raw block) to a given output (structured events). This ensures that handler remains idempotent and that
|
|
182
|
+
* repeated calls with the same input block produce the same output events.
|
|
183
|
+
*/
|
|
184
|
+
handler: (block: TBlock) => TEvent[];
|
|
185
|
+
/**
|
|
186
|
+
* Storage adapter to persist events in your off-chain storage.
|
|
187
|
+
*/
|
|
188
|
+
storage: {
|
|
189
|
+
/**
|
|
190
|
+
* Upserts a batch of events into your storage system.
|
|
191
|
+
*
|
|
192
|
+
* After a block is transformed into a list of structured events by your `handler` function, that batch
|
|
193
|
+
* is passed to this `upsert` function so they can be upserted into your storage system.
|
|
194
|
+
*
|
|
195
|
+
* This function must be idempotent. Functionally, this means that if the same batch of events is upserted
|
|
196
|
+
* multiple times it only produces a single set of events in your storage system.
|
|
197
|
+
*/
|
|
198
|
+
upsert: (events: TEvent[]) => Promise<void>;
|
|
199
|
+
/**
|
|
200
|
+
* Deletes a batch of events from your storage system.
|
|
201
|
+
*
|
|
202
|
+
* When your indexer encounters a chain reorganisation, this `delete` function will be invoked with the
|
|
203
|
+
* same batch of events created by that reorganised block. This ensures that any events that were previously
|
|
204
|
+
* upserted into your storage system that are no longer part of the canonical chain are safely removed.
|
|
205
|
+
*/
|
|
206
|
+
delete: (events: TEvent[]) => Promise<void>;
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Actions -----------------------------------------------------------------------------------------------------------------------------------
|
|
211
|
+
*/
|
|
212
|
+
type Action<TBlock, TEvent> = {
|
|
213
|
+
/**
|
|
214
|
+
* A human-readable identifier for the action.
|
|
215
|
+
*/
|
|
216
|
+
id: string;
|
|
217
|
+
/**
|
|
218
|
+
* The on-chain event that should invoke this action.
|
|
219
|
+
*/
|
|
220
|
+
event: Event<TBlock, TEvent>;
|
|
221
|
+
/**
|
|
222
|
+
* The action you want to execute when the event occurs on-chain.
|
|
223
|
+
*
|
|
224
|
+
* Actions are processed during realtime indexing only and are never invoked during historical
|
|
225
|
+
* backfills. Common actions include payment notifications for confirming payments or customer
|
|
226
|
+
* deposits, transaction monitoring for KYC/AML compliance tracking, DeFi protocol monitoring,
|
|
227
|
+
* or wallet activity notifications or alerts.
|
|
228
|
+
*
|
|
229
|
+
* Actions may be invoked multiple times. It is important that your application code is
|
|
230
|
+
* resilient to this by making use of an idempotency key - usually the id of the event passed
|
|
231
|
+
* to your handler.
|
|
232
|
+
*
|
|
233
|
+
* In production, actions should perform lightweight processing only. Do not use them for
|
|
234
|
+
* long-running tasks. Actions are extremely powerful when combined with a durable execution
|
|
235
|
+
* framework like Temporal, Inngest, Trigger.dev, Cloudflare Workflows, or Restate.dev to
|
|
236
|
+
* perform more advanced workflows that allow you to chain together multiple steps and
|
|
237
|
+
* automatically handle retries.
|
|
238
|
+
*/
|
|
239
|
+
handler: {
|
|
240
|
+
/**
|
|
241
|
+
* Executes your action when the event first occurs on-chain.
|
|
242
|
+
*
|
|
243
|
+
* Latest handlers operate with best-effort delivery. If your handler throws an error it will be
|
|
244
|
+
* retried 2 and then ignored. If you need to guarantee that your latest handler is invoked
|
|
245
|
+
* successfully you should run the same action code again from a finalized handler.
|
|
246
|
+
*/
|
|
247
|
+
latest?: (event: TEvent) => Promise<void> | void;
|
|
248
|
+
/**
|
|
249
|
+
* Executes your action when the event finalizes on-chain.
|
|
250
|
+
*
|
|
251
|
+
* Finalized handlers operate with at-least-once delivery. We guarantee that the indexer
|
|
252
|
+
* will not finalize a given block until it receives a successful response from your action.
|
|
253
|
+
*/
|
|
254
|
+
finalized?: (event: TEvent) => Promise<void> | void;
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Indexer -----------------------------------------------------------------------------------------------------------------------------------
|
|
259
|
+
*/
|
|
260
|
+
type Head = {
|
|
261
|
+
hash: `0x${string}`;
|
|
262
|
+
chain: `0x${string}`;
|
|
263
|
+
number: `0x${string}`;
|
|
264
|
+
parent_hash: `0x${string}`;
|
|
265
|
+
};
|
|
266
|
+
type Metadata = {
|
|
267
|
+
version: string;
|
|
268
|
+
language: string;
|
|
269
|
+
};
|
|
270
|
+
type Result = {
|
|
271
|
+
status: string;
|
|
272
|
+
event_id: string;
|
|
273
|
+
hash: `0x${string}`;
|
|
274
|
+
chain: `0x${string}`;
|
|
275
|
+
number: `0x${string}`;
|
|
276
|
+
parent_hash: `0x${string}`;
|
|
277
|
+
created_at: number;
|
|
278
|
+
};
|
|
279
|
+
type IndexerOptions<TBlock> = {
|
|
280
|
+
/**
|
|
281
|
+
* Silences all logs including errors.
|
|
282
|
+
*
|
|
283
|
+
* Logs are emitted based on the environment LOG_LEVEL. Set `quiet: true` to surpress all logs.
|
|
284
|
+
* Available log options are `DEBUG`, `INFO`, `WARN`, and `ERROR`.
|
|
285
|
+
*/
|
|
286
|
+
quiet?: boolean;
|
|
287
|
+
/**
|
|
288
|
+
* Request signing key
|
|
289
|
+
*
|
|
290
|
+
* Facilitates secure communication with a trusted source like the univo dashboard.
|
|
291
|
+
*/
|
|
292
|
+
signingKey: string;
|
|
293
|
+
/**
|
|
294
|
+
* Storage interface for durably persisting indexer metadata.
|
|
295
|
+
*
|
|
296
|
+
* This uses the unified key-value storage API from unstorage. Install the `unstorage` dependency
|
|
297
|
+
* and provide the return value of your `createStorage()` call. Check out the documentation for
|
|
298
|
+
* a full list of [supported storage drivers](https://unstorage.unjs.io/drivers).
|
|
299
|
+
*
|
|
300
|
+
* Functionally, storing metadata is fundamental to ensure the correct operation of your indexer. It
|
|
301
|
+
* ensures that you indexer recovers from downtime and ensures that all blocks are processed correctly during
|
|
302
|
+
* chain reorganisations.
|
|
303
|
+
*/
|
|
304
|
+
metadataStorage: Storage;
|
|
305
|
+
/**
|
|
306
|
+
* Loads raw block data in realtime from a trusted set of RPC sources.
|
|
307
|
+
*
|
|
308
|
+
* Note that historical backfills do not use this function to load block data.
|
|
309
|
+
*
|
|
310
|
+
* The response from this function determines the input data to your `handler` functions in each event.
|
|
311
|
+
* Generally, the shape is a list of RPC methods with their corresponding value from an RPC node. This
|
|
312
|
+
* generic format allows you support the full range of RPC data available to you from your node. This
|
|
313
|
+
* flexibility is important in cases where some methods are supported on specific chains only.
|
|
314
|
+
*
|
|
315
|
+
* Note that there is a minimum set of RPC methods expected on the response notably `eth_chainId`,
|
|
316
|
+
* `eth_getBlockByNumber` and `eth_getBlockReceipts`. These are expected so that we can safely match
|
|
317
|
+
* each block processed against your event filters.
|
|
318
|
+
*
|
|
319
|
+
* Note that we provide only the block number to look up block data. During a chain reorganisation, this
|
|
320
|
+
* makes it possible for different RPC calls to return data for different block hashes. We manually verify
|
|
321
|
+
* that all methods return the expected block hash. However, for any custom methods you add you must manually
|
|
322
|
+
* verify the block hash is consistent with the other known methods.
|
|
323
|
+
*/
|
|
324
|
+
getBlock: (block: {
|
|
325
|
+
chain: `0x${string}`;
|
|
326
|
+
number: string;
|
|
327
|
+
}) => Promise<TBlock | null>;
|
|
328
|
+
};
|
|
329
|
+
type Indexer<TBlock> = {
|
|
330
|
+
/**
|
|
331
|
+
* A web standard HTTP request handler. This is the entrypoint to your indexer and allows it to be deployed
|
|
332
|
+
* to your framework of choice so that it can receive requests and process responses.
|
|
333
|
+
*/
|
|
334
|
+
fetch: (req: Request) => Promise<Response>;
|
|
335
|
+
/**
|
|
336
|
+
* Define on-chain events you want to record in your off-chain storage system.
|
|
337
|
+
*/
|
|
338
|
+
event: <TEvent>(event: Event<TBlock, TEvent>) => Event<TBlock, TEvent>;
|
|
339
|
+
/**
|
|
340
|
+
* Perform fire-and-forget effects in response to on-chain events.
|
|
341
|
+
*/
|
|
342
|
+
action: <TEvent>(action: Action<TBlock, TEvent>) => Action<TBlock, TEvent>;
|
|
343
|
+
};
|
|
344
|
+
declare function indexer<TBlock extends Block>(opts: IndexerOptions<TBlock>): Indexer<TBlock> & IndexerRpc;
|
|
345
|
+
|
|
346
|
+
export { indexer as i };
|
|
347
|
+
export type { Block as B, Event as E, Filter as F, Head as H, Indexer as I, IndexerRpc, Metadata as M, NodeRpc, Result as R, Rpc };
|
package/dist/rpc.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Storage } from '@storagesdk/core';
|
|
2
|
+
|
|
3
|
+
type CamelToSnake<T extends string, P extends string = ""> = string extends T ? string : T extends `${infer C0}${infer R}` ? CamelToSnake<R, `${P}${C0 extends Lowercase<C0> ? "" : "_"}${Lowercase<C0>}`> : P;
|
|
4
|
+
type Flatten<T> = {
|
|
5
|
+
[K in keyof T as CamelToSnake<Extract<K, string>>]: T[K];
|
|
6
|
+
};
|
|
3
7
|
|
|
4
8
|
type Rpc = {
|
|
5
9
|
/**
|
|
@@ -98,4 +102,246 @@ type IndexerRpc = {
|
|
|
98
102
|
subscribe: Record<string, never>;
|
|
99
103
|
};
|
|
100
104
|
|
|
101
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Block -----------------------------------------------------------------------------------------------------------------------------------
|
|
107
|
+
*/
|
|
108
|
+
type Block = {
|
|
109
|
+
eth_chainId: `0x${string}`;
|
|
110
|
+
eth_getBlockByNumber: {
|
|
111
|
+
hash: `0x${string}`;
|
|
112
|
+
number: `0x${string}`;
|
|
113
|
+
parentHash: `0x${string}`;
|
|
114
|
+
};
|
|
115
|
+
eth_getBlockReceipts: Array<{
|
|
116
|
+
blockHash: `0x${string}`;
|
|
117
|
+
logs: Array<{
|
|
118
|
+
address: `0x${string}`;
|
|
119
|
+
topics: `0x${string}`[];
|
|
120
|
+
}>;
|
|
121
|
+
}>;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Filters -----------------------------------------------------------------------------------------------------------------------------------
|
|
125
|
+
*/
|
|
126
|
+
type Filter = {
|
|
127
|
+
/** Index blocks with this chain id */
|
|
128
|
+
chain: number;
|
|
129
|
+
/** Index blocks from this start block (inclusive) */
|
|
130
|
+
fromBlock: number;
|
|
131
|
+
/** Index blocks until this stop block (inclusive) */
|
|
132
|
+
toBlock?: number;
|
|
133
|
+
/** Index blocks where this event topic was emitted */
|
|
134
|
+
event?: `0x${string}`;
|
|
135
|
+
/** Index blocks that involve this address */
|
|
136
|
+
address?: `0x${string}`;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Events -----------------------------------------------------------------------------------------------------------------------------------
|
|
140
|
+
*/
|
|
141
|
+
type Event<TBlock, TEvent> = {
|
|
142
|
+
/**
|
|
143
|
+
* A human-readable identifier for the event.
|
|
144
|
+
*/
|
|
145
|
+
id: string;
|
|
146
|
+
/**
|
|
147
|
+
* Filters let you define what specific blocks you want this event to index.
|
|
148
|
+
*
|
|
149
|
+
* Blockchains are massive datasets and most of the time we are only ever interested in small portions of it.
|
|
150
|
+
* Sometimes that can be specific events like ERC20 transfers and other times it could be all events emitted
|
|
151
|
+
* by a specific contract. Filters provide a simple way for an event to define exactly which blocks we want
|
|
152
|
+
* to index.
|
|
153
|
+
*
|
|
154
|
+
* Filters reduce costs and improve backfill performance by ensuring we only index the blocks we need and
|
|
155
|
+
* ignore the blocks that don't have the data we are interested in.
|
|
156
|
+
*
|
|
157
|
+
* By default your event will not index any blocks, you must opt-in to indexing by providing atleast one filter.
|
|
158
|
+
*
|
|
159
|
+
* Each property in the filter operates like an AND statement. For example, if you specifiy an `address` and
|
|
160
|
+
* an `event` it implies that you only want to index blocks where the specific `address` emitted the specific
|
|
161
|
+
* `event` topic provided.
|
|
162
|
+
*
|
|
163
|
+
* However, when multiple filters are defined for a given event those filters operate like an OR statement. For
|
|
164
|
+
* example, if we define a second filter looking for a different `address` and `event` our event will now index
|
|
165
|
+
* any block that matches either the first filter or the second filter.
|
|
166
|
+
*
|
|
167
|
+
* Note that filters are a rudimentary method to dramatically reduce the number of blocks your application needs
|
|
168
|
+
* to index. Any advanced filtering should be performed in the event `handler` itself.
|
|
169
|
+
*/
|
|
170
|
+
filters: Filter[];
|
|
171
|
+
/**
|
|
172
|
+
* Synchronously transforms a raw block into a list of events.
|
|
173
|
+
*
|
|
174
|
+
* When a block matches any of filters defined by your event it will be passed to this function to be synchronously
|
|
175
|
+
* transformed into a list of structured events.
|
|
176
|
+
*
|
|
177
|
+
* The shape of the input `block` is determined by the return value of `getBlock` function provided to your `indexer`.
|
|
178
|
+
*
|
|
179
|
+
* The returned output value should be an array containg any valid JavaScript values. Each event that you return from
|
|
180
|
+
* your handler should not depend on any information outside of the input block data. It should directly map a given
|
|
181
|
+
* input (the raw block) to a given output (structured events). This ensures that handler remains idempotent and that
|
|
182
|
+
* repeated calls with the same input block produce the same output events.
|
|
183
|
+
*/
|
|
184
|
+
handler: (block: TBlock) => TEvent[];
|
|
185
|
+
/**
|
|
186
|
+
* Storage adapter to persist events in your off-chain storage.
|
|
187
|
+
*/
|
|
188
|
+
storage: {
|
|
189
|
+
/**
|
|
190
|
+
* Upserts a batch of events into your storage system.
|
|
191
|
+
*
|
|
192
|
+
* After a block is transformed into a list of structured events by your `handler` function, that batch
|
|
193
|
+
* is passed to this `upsert` function so they can be upserted into your storage system.
|
|
194
|
+
*
|
|
195
|
+
* This function must be idempotent. Functionally, this means that if the same batch of events is upserted
|
|
196
|
+
* multiple times it only produces a single set of events in your storage system.
|
|
197
|
+
*/
|
|
198
|
+
upsert: (events: TEvent[]) => Promise<void>;
|
|
199
|
+
/**
|
|
200
|
+
* Deletes a batch of events from your storage system.
|
|
201
|
+
*
|
|
202
|
+
* When your indexer encounters a chain reorganisation, this `delete` function will be invoked with the
|
|
203
|
+
* same batch of events created by that reorganised block. This ensures that any events that were previously
|
|
204
|
+
* upserted into your storage system that are no longer part of the canonical chain are safely removed.
|
|
205
|
+
*/
|
|
206
|
+
delete: (events: TEvent[]) => Promise<void>;
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Actions -----------------------------------------------------------------------------------------------------------------------------------
|
|
211
|
+
*/
|
|
212
|
+
type Action<TBlock, TEvent> = {
|
|
213
|
+
/**
|
|
214
|
+
* A human-readable identifier for the action.
|
|
215
|
+
*/
|
|
216
|
+
id: string;
|
|
217
|
+
/**
|
|
218
|
+
* The on-chain event that should invoke this action.
|
|
219
|
+
*/
|
|
220
|
+
event: Event<TBlock, TEvent>;
|
|
221
|
+
/**
|
|
222
|
+
* The action you want to execute when the event occurs on-chain.
|
|
223
|
+
*
|
|
224
|
+
* Actions are processed during realtime indexing only and are never invoked during historical
|
|
225
|
+
* backfills. Common actions include payment notifications for confirming payments or customer
|
|
226
|
+
* deposits, transaction monitoring for KYC/AML compliance tracking, DeFi protocol monitoring,
|
|
227
|
+
* or wallet activity notifications or alerts.
|
|
228
|
+
*
|
|
229
|
+
* Actions may be invoked multiple times. It is important that your application code is
|
|
230
|
+
* resilient to this by making use of an idempotency key - usually the id of the event passed
|
|
231
|
+
* to your handler.
|
|
232
|
+
*
|
|
233
|
+
* In production, actions should perform lightweight processing only. Do not use them for
|
|
234
|
+
* long-running tasks. Actions are extremely powerful when combined with a durable execution
|
|
235
|
+
* framework like Temporal, Inngest, Trigger.dev, Cloudflare Workflows, or Restate.dev to
|
|
236
|
+
* perform more advanced workflows that allow you to chain together multiple steps and
|
|
237
|
+
* automatically handle retries.
|
|
238
|
+
*/
|
|
239
|
+
handler: {
|
|
240
|
+
/**
|
|
241
|
+
* Executes your action when the event first occurs on-chain.
|
|
242
|
+
*
|
|
243
|
+
* Latest handlers operate with best-effort delivery. If your handler throws an error it will be
|
|
244
|
+
* retried 2 and then ignored. If you need to guarantee that your latest handler is invoked
|
|
245
|
+
* successfully you should run the same action code again from a finalized handler.
|
|
246
|
+
*/
|
|
247
|
+
latest?: (event: TEvent) => Promise<void> | void;
|
|
248
|
+
/**
|
|
249
|
+
* Executes your action when the event finalizes on-chain.
|
|
250
|
+
*
|
|
251
|
+
* Finalized handlers operate with at-least-once delivery. We guarantee that the indexer
|
|
252
|
+
* will not finalize a given block until it receives a successful response from your action.
|
|
253
|
+
*/
|
|
254
|
+
finalized?: (event: TEvent) => Promise<void> | void;
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Indexer -----------------------------------------------------------------------------------------------------------------------------------
|
|
259
|
+
*/
|
|
260
|
+
type Head = {
|
|
261
|
+
hash: `0x${string}`;
|
|
262
|
+
chain: `0x${string}`;
|
|
263
|
+
number: `0x${string}`;
|
|
264
|
+
parent_hash: `0x${string}`;
|
|
265
|
+
};
|
|
266
|
+
type Metadata = {
|
|
267
|
+
version: string;
|
|
268
|
+
language: string;
|
|
269
|
+
};
|
|
270
|
+
type Result = {
|
|
271
|
+
status: string;
|
|
272
|
+
event_id: string;
|
|
273
|
+
hash: `0x${string}`;
|
|
274
|
+
chain: `0x${string}`;
|
|
275
|
+
number: `0x${string}`;
|
|
276
|
+
parent_hash: `0x${string}`;
|
|
277
|
+
created_at: number;
|
|
278
|
+
};
|
|
279
|
+
type IndexerOptions<TBlock> = {
|
|
280
|
+
/**
|
|
281
|
+
* Silences all logs including errors.
|
|
282
|
+
*
|
|
283
|
+
* Logs are emitted based on the environment LOG_LEVEL. Set `quiet: true` to surpress all logs.
|
|
284
|
+
* Available log options are `DEBUG`, `INFO`, `WARN`, and `ERROR`.
|
|
285
|
+
*/
|
|
286
|
+
quiet?: boolean;
|
|
287
|
+
/**
|
|
288
|
+
* Request signing key
|
|
289
|
+
*
|
|
290
|
+
* Facilitates secure communication with a trusted source like the univo dashboard.
|
|
291
|
+
*/
|
|
292
|
+
signingKey: string;
|
|
293
|
+
/**
|
|
294
|
+
* Storage interface for durably persisting indexer metadata.
|
|
295
|
+
*
|
|
296
|
+
* This uses the unified key-value storage API from unstorage. Install the `unstorage` dependency
|
|
297
|
+
* and provide the return value of your `createStorage()` call. Check out the documentation for
|
|
298
|
+
* a full list of [supported storage drivers](https://unstorage.unjs.io/drivers).
|
|
299
|
+
*
|
|
300
|
+
* Functionally, storing metadata is fundamental to ensure the correct operation of your indexer. It
|
|
301
|
+
* ensures that you indexer recovers from downtime and ensures that all blocks are processed correctly during
|
|
302
|
+
* chain reorganisations.
|
|
303
|
+
*/
|
|
304
|
+
metadataStorage: Storage;
|
|
305
|
+
/**
|
|
306
|
+
* Loads raw block data in realtime from a trusted set of RPC sources.
|
|
307
|
+
*
|
|
308
|
+
* Note that historical backfills do not use this function to load block data.
|
|
309
|
+
*
|
|
310
|
+
* The response from this function determines the input data to your `handler` functions in each event.
|
|
311
|
+
* Generally, the shape is a list of RPC methods with their corresponding value from an RPC node. This
|
|
312
|
+
* generic format allows you support the full range of RPC data available to you from your node. This
|
|
313
|
+
* flexibility is important in cases where some methods are supported on specific chains only.
|
|
314
|
+
*
|
|
315
|
+
* Note that there is a minimum set of RPC methods expected on the response notably `eth_chainId`,
|
|
316
|
+
* `eth_getBlockByNumber` and `eth_getBlockReceipts`. These are expected so that we can safely match
|
|
317
|
+
* each block processed against your event filters.
|
|
318
|
+
*
|
|
319
|
+
* Note that we provide only the block number to look up block data. During a chain reorganisation, this
|
|
320
|
+
* makes it possible for different RPC calls to return data for different block hashes. We manually verify
|
|
321
|
+
* that all methods return the expected block hash. However, for any custom methods you add you must manually
|
|
322
|
+
* verify the block hash is consistent with the other known methods.
|
|
323
|
+
*/
|
|
324
|
+
getBlock: (block: {
|
|
325
|
+
chain: `0x${string}`;
|
|
326
|
+
number: string;
|
|
327
|
+
}) => Promise<TBlock | null>;
|
|
328
|
+
};
|
|
329
|
+
type Indexer<TBlock> = {
|
|
330
|
+
/**
|
|
331
|
+
* A web standard HTTP request handler. This is the entrypoint to your indexer and allows it to be deployed
|
|
332
|
+
* to your framework of choice so that it can receive requests and process responses.
|
|
333
|
+
*/
|
|
334
|
+
fetch: (req: Request) => Promise<Response>;
|
|
335
|
+
/**
|
|
336
|
+
* Define on-chain events you want to record in your off-chain storage system.
|
|
337
|
+
*/
|
|
338
|
+
event: <TEvent>(event: Event<TBlock, TEvent>) => Event<TBlock, TEvent>;
|
|
339
|
+
/**
|
|
340
|
+
* Perform fire-and-forget effects in response to on-chain events.
|
|
341
|
+
*/
|
|
342
|
+
action: <TEvent>(action: Action<TBlock, TEvent>) => Action<TBlock, TEvent>;
|
|
343
|
+
};
|
|
344
|
+
declare function indexer<TBlock extends Block>(opts: IndexerOptions<TBlock>): Indexer<TBlock> & IndexerRpc;
|
|
345
|
+
|
|
346
|
+
export { indexer as i };
|
|
347
|
+
export type { Block as B, Event as E, Filter as F, Head as H, Indexer as I, IndexerRpc, Metadata as M, NodeRpc, Result as R, Rpc };
|