envio 3.0.2-svm-alpha.0 → 3.0.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.
Files changed (43) hide show
  1. package/evm.schema.json +8 -8
  2. package/fuel.schema.json +12 -12
  3. package/index.d.ts +1 -155
  4. package/package.json +7 -6
  5. package/src/ChainFetcher.res +1 -25
  6. package/src/ChainFetcher.res.mjs +1 -19
  7. package/src/Config.res +94 -156
  8. package/src/Config.res.mjs +97 -60
  9. package/src/Core.res +0 -32
  10. package/src/Env.res.mjs +2 -1
  11. package/src/Envio.res +0 -94
  12. package/src/EventConfigBuilder.res +25 -63
  13. package/src/EventConfigBuilder.res.mjs +8 -37
  14. package/src/HandlerLoader.res +1 -12
  15. package/src/HandlerLoader.res.mjs +1 -6
  16. package/src/Internal.res +0 -38
  17. package/src/Main.res +3 -53
  18. package/src/Main.res.mjs +2 -34
  19. package/src/Persistence.res +17 -2
  20. package/src/Persistence.res.mjs +14 -2
  21. package/src/SimulateItems.res +10 -23
  22. package/src/SimulateItems.res.mjs +6 -21
  23. package/src/bindings/ClickHouse.res +6 -2
  24. package/src/bindings/ClickHouse.res.mjs +3 -2
  25. package/src/sources/EventRouter.res +0 -65
  26. package/src/sources/EventRouter.res.mjs +0 -43
  27. package/src/sources/HyperSyncClient.res +157 -30
  28. package/src/sources/HyperSyncClient.res.mjs +6 -20
  29. package/src/sources/HyperSyncSource.res +8 -5
  30. package/src/sources/HyperSyncSource.res.mjs +8 -1
  31. package/src/sources/RpcSource.res.mjs +1 -1
  32. package/src/sources/Svm.res +2 -2
  33. package/src/sources/Svm.res.mjs +2 -3
  34. package/src/tui/Tui.res +2 -9
  35. package/src/tui/Tui.res.mjs +4 -19
  36. package/src/tui/components/TuiData.res +0 -3
  37. package/svm.schema.json +4 -345
  38. package/src/SvmTypes.res +0 -9
  39. package/src/SvmTypes.res.mjs +0 -14
  40. package/src/sources/HyperSyncSolanaClient.res +0 -227
  41. package/src/sources/HyperSyncSolanaClient.res.mjs +0 -25
  42. package/src/sources/HyperSyncSolanaSource.res +0 -515
  43. package/src/sources/HyperSyncSolanaSource.res.mjs +0 -441
package/evm.schema.json CHANGED
@@ -4,10 +4,6 @@
4
4
  "description": "Schema for a YAML config for an envio indexer",
5
5
  "type": "object",
6
6
  "properties": {
7
- "name": {
8
- "description": "Name of the project",
9
- "type": "string"
10
- },
11
7
  "description": {
12
8
  "description": "Description of the project",
13
9
  "type": [
@@ -15,6 +11,10 @@
15
11
  "null"
16
12
  ]
17
13
  },
14
+ "name": {
15
+ "description": "Name of the project",
16
+ "type": "string"
17
+ },
18
18
  "schema": {
19
19
  "description": "Custom path to schema.graphql file",
20
20
  "type": [
@@ -67,7 +67,7 @@
67
67
  "null"
68
68
  ],
69
69
  "items": {
70
- "$ref": "#/$defs/GlobalContract"
70
+ "$ref": "#/$defs/GlobalContract_for_ContractConfig"
71
71
  }
72
72
  },
73
73
  "chains": {
@@ -189,7 +189,7 @@
189
189
  "evm"
190
190
  ]
191
191
  },
192
- "GlobalContract": {
192
+ "GlobalContract_for_ContractConfig": {
193
193
  "type": "object",
194
194
  "properties": {
195
195
  "name": {
@@ -418,7 +418,7 @@
418
418
  "null"
419
419
  ],
420
420
  "items": {
421
- "$ref": "#/$defs/ChainContract"
421
+ "$ref": "#/$defs/ChainContract_for_ContractConfig"
422
422
  }
423
423
  }
424
424
  },
@@ -578,7 +578,7 @@
578
578
  "url"
579
579
  ]
580
580
  },
581
- "ChainContract": {
581
+ "ChainContract_for_ContractConfig": {
582
582
  "type": "object",
583
583
  "properties": {
584
584
  "name": {
package/fuel.schema.json CHANGED
@@ -4,10 +4,6 @@
4
4
  "description": "Schema for a YAML config for an envio indexer",
5
5
  "type": "object",
6
6
  "properties": {
7
- "name": {
8
- "description": "Name of the project",
9
- "type": "string"
10
- },
11
7
  "description": {
12
8
  "description": "Description of the project",
13
9
  "type": [
@@ -15,6 +11,10 @@
15
11
  "null"
16
12
  ]
17
13
  },
14
+ "name": {
15
+ "description": "Name of the project",
16
+ "type": "string"
17
+ },
18
18
  "schema": {
19
19
  "description": "Custom path to schema.graphql file",
20
20
  "type": [
@@ -60,7 +60,7 @@
60
60
  "null"
61
61
  ],
62
62
  "items": {
63
- "$ref": "#/$defs/GlobalContract"
63
+ "$ref": "#/$defs/GlobalContract_for_ContractConfig"
64
64
  }
65
65
  },
66
66
  "chains": {
@@ -147,7 +147,7 @@
147
147
  "fuel"
148
148
  ]
149
149
  },
150
- "GlobalContract": {
150
+ "GlobalContract_for_ContractConfig": {
151
151
  "type": "object",
152
152
  "properties": {
153
153
  "name": {
@@ -183,10 +183,6 @@
183
183
  "EventConfig": {
184
184
  "type": "object",
185
185
  "properties": {
186
- "name": {
187
- "description": "Name of the event in the HyperIndex generated code",
188
- "type": "string"
189
- },
190
186
  "type": {
191
187
  "description": "Explicitly set the event type you want to index. It's derived from the event name and fallbacks to LogData.",
192
188
  "anyOf": [
@@ -198,6 +194,10 @@
198
194
  }
199
195
  ]
200
196
  },
197
+ "name": {
198
+ "description": "Name of the event in the HyperIndex generated code",
199
+ "type": "string"
200
+ },
201
201
  "logId": {
202
202
  "description": "An identifier of a logged type from ABI. Used for indexing LogData receipts. The option can be omitted when the event name matches the logged struct/enum name.",
203
203
  "type": [
@@ -281,7 +281,7 @@
281
281
  "null"
282
282
  ],
283
283
  "items": {
284
- "$ref": "#/$defs/ChainContract"
284
+ "$ref": "#/$defs/ChainContract_for_ContractConfig"
285
285
  }
286
286
  }
287
287
  },
@@ -304,7 +304,7 @@
304
304
  "url"
305
305
  ]
306
306
  },
307
- "ChainContract": {
307
+ "ChainContract_for_ContractConfig": {
308
308
  "type": "object",
309
309
  "properties": {
310
310
  "name": {
package/index.d.ts CHANGED
@@ -961,125 +961,6 @@ export type SvmOnSlotOptions<Config extends IndexerConfigTypes = GlobalConfig> =
961
961
  readonly where?: (args: SvmOnSlotWhereArgs<Config>) => SvmOnSlotWhereResult;
962
962
  };
963
963
 
964
- // ============== SVM onInstruction types ==============
965
-
966
- /** Borsh-decoded view of an instruction. Present whenever a `ProgramSchema`
967
- * was attached to the program (bundled, Anchor IDL, or hand-written
968
- * `accounts`/`args` in YAML). Absent when no schema applies or the
969
- * discriminator didn't match any registered instruction. */
970
- export type SvmDecodedInstruction = {
971
- /** Schema-declared instruction name. */
972
- readonly name: string;
973
- /** Borsh-decoded args object. POC types this as `unknown`; narrow with a
974
- * locally-declared type until the typed-args codegen lands. */
975
- readonly args: unknown;
976
- /** Named accounts in schema order. Keys are exactly the schema-declared
977
- * names; values are base58 pubkeys. */
978
- readonly accounts: Readonly<Record<string, string>>;
979
- /** Accounts beyond the schema's named list (Anchor `remaining_accounts`,
980
- * IDL drift). Empty when counts match the schema. */
981
- readonly extraAccounts: readonly string[];
982
- };
983
-
984
- /** A single Solana instruction matched by the indexer.
985
- *
986
- * `data` and discriminator prefixes are `0x`-prefixed hex strings; accounts
987
- * are base58 strings. When a Borsh schema is configured (bundled, Anchor
988
- * IDL, or hand-written YAML), `decoded` carries the named-accounts +
989
- * decoded-args view. */
990
- export type SvmInstruction = {
991
- readonly programId: string;
992
- readonly data: string;
993
- readonly accounts: readonly string[];
994
- readonly instructionAddress: readonly number[];
995
- readonly isInner: boolean;
996
- readonly d1?: string;
997
- readonly d2?: string;
998
- readonly d4?: string;
999
- readonly d8?: string;
1000
- readonly decoded?: SvmDecodedInstruction;
1001
- };
1002
-
1003
- /** Parent transaction surfaced when an instruction's
1004
- * `include_transaction` flag is `true`. */
1005
- export type SvmTransaction = {
1006
- readonly signatures: readonly string[];
1007
- readonly feePayer?: string;
1008
- readonly success?: boolean;
1009
- readonly err?: string;
1010
- /** Lamports. */
1011
- readonly fee?: bigint;
1012
- readonly computeUnitsConsumed?: bigint;
1013
- readonly accountKeys: readonly string[];
1014
- readonly recentBlockhash?: string;
1015
- readonly version?: string;
1016
- };
1017
-
1018
- export type SvmLog = {
1019
- readonly kind: string;
1020
- readonly message: string;
1021
- };
1022
-
1023
- /** A single Solana instruction event delivered to a handler. Parameterised
1024
- * over `Decoded` so the per-(program, instruction) overload of
1025
- * `onInstruction` can narrow `event.instruction.decoded` to the
1026
- * codegen-generated `{ args, accounts }` shape. */
1027
- export type SvmInstructionEvent<
1028
- Decoded extends SvmDecodedInstruction = SvmDecodedInstruction,
1029
- > = {
1030
- readonly contractName: string;
1031
- readonly eventName: string;
1032
- readonly instruction: Omit<SvmInstruction, "decoded"> & {
1033
- readonly decoded?: Decoded;
1034
- };
1035
- /** Present when the instruction's `include_transaction` is `true`. */
1036
- readonly transaction?: SvmTransaction;
1037
- /** Present when the instruction's `include_logs` is `true`; only logs
1038
- * scoped to this exact instruction (matching `instruction_address`). */
1039
- readonly logs?: readonly SvmLog[];
1040
- readonly slot: number;
1041
- readonly blockTime?: number;
1042
- };
1043
-
1044
- /** Arguments passed to handlers registered via `indexer.onInstruction`. */
1045
- export type SvmOnInstructionHandlerArgs<
1046
- Config extends IndexerConfigTypes = GlobalConfig,
1047
- Event extends SvmInstructionEvent = SvmInstructionEvent,
1048
- > = {
1049
- readonly event: Event;
1050
- readonly context: SvmOnSlotContext<Config>;
1051
- };
1052
-
1053
- /** Shape extracted from `Global.config.svm.programs[P][I]`. The codegen
1054
- * emits `{ args: ...; accounts: ... }` per (program, instruction); this
1055
- * helper turns that into a `SvmDecodedInstruction`-compatible record. */
1056
- type SvmDecodedFromProgramTable<TInstr> = TInstr extends {
1057
- args: infer A;
1058
- accounts: infer Acc extends Readonly<Record<string, string>>;
1059
- }
1060
- ? {
1061
- readonly name: string;
1062
- readonly args: A;
1063
- readonly accounts: Acc;
1064
- readonly extraAccounts: readonly string[];
1065
- }
1066
- : SvmDecodedInstruction;
1067
-
1068
- /** Options for an SVM `indexer.onInstruction` registration. */
1069
- export type SvmOnInstructionOptions<P extends string = string, I extends string = string> = {
1070
- /** Program name as declared under `chains[].programs[].name` in
1071
- * `config.yaml`. */
1072
- readonly program: P;
1073
- /** Instruction name as declared under
1074
- * `chains[].programs[].instructions[].name` in `config.yaml`. */
1075
- readonly instruction: I;
1076
- };
1077
-
1078
- /** Handler function for an SVM `indexer.onInstruction` registration. */
1079
- export type SvmOnInstructionHandler<
1080
- Config extends IndexerConfigTypes = GlobalConfig,
1081
- > = (args: SvmOnInstructionHandlerArgs<Config>) => Promise<void>;
1082
-
1083
964
  // ============== Indexer Types ==============
1084
965
 
1085
966
  // Helper: Check if an ecosystem is configured. Single-ecosystem indexers only
@@ -1257,7 +1138,7 @@ type FuelEcosystem<Config extends IndexerConfigTypes = GlobalConfig> =
1257
1138
  : never
1258
1139
  : never;
1259
1140
 
1260
- // SVM ecosystem type — chains plus instruction + slot handler methods.
1141
+ // SVM ecosystem type — chains plus onSlot handler method. SVM has no onEvent yet.
1261
1142
  type SvmEcosystem<Config extends IndexerConfigTypes = GlobalConfig> =
1262
1143
  "svm" extends keyof Config
1263
1144
  ? Config["svm"] extends { chains: infer Chains }
@@ -1281,41 +1162,7 @@ type SvmEcosystem<Config extends IndexerConfigTypes = GlobalConfig> =
1281
1162
  options: SvmOnSlotOptions<Config>,
1282
1163
  handler: SvmOnSlotHandler<Config>,
1283
1164
  ) => void;
1284
- } & (Config["svm"] extends {
1285
- programs: infer Programs extends Record<string, Record<string, any>>;
1286
1165
  }
1287
- ? {
1288
- /**
1289
- * Register an instruction handler. Dispatch matches on
1290
- * `(programId, discriminator)` from the YAML config.
1291
- * `event.instruction.decoded.args` and
1292
- * `event.instruction.decoded.accounts` are typed from the
1293
- * program's Borsh schema (Anchor IDL, bundled, or
1294
- * hand-written `accounts`/`args` in YAML). `decoded` stays
1295
- * optional at runtime because schema-matching can fail on
1296
- * IDL drift or unknown discriminators.
1297
- */
1298
- readonly onInstruction: <
1299
- P extends keyof Programs & string,
1300
- I extends keyof Programs[P] & string,
1301
- >(
1302
- options: SvmOnInstructionOptions<P, I>,
1303
- handler: (
1304
- args: SvmOnInstructionHandlerArgs<
1305
- Config,
1306
- SvmInstructionEvent<SvmDecodedFromProgramTable<Programs[P][I]>>
1307
- >,
1308
- ) => Promise<void>,
1309
- ) => void;
1310
- }
1311
- : {
1312
- /** Untyped fallback for indexers with no `programs` in
1313
- * config. `decoded` stays the generic shape. */
1314
- readonly onInstruction: (
1315
- options: SvmOnInstructionOptions,
1316
- handler: SvmOnInstructionHandler<Config>,
1317
- ) => void;
1318
- })
1319
1166
  : never
1320
1167
  : never
1321
1168
  : never;
@@ -1331,7 +1178,6 @@ type CodegenRequiredHint =
1331
1178
  "Run 'envio codegen' to generate handler types from config.yaml. Without codegen, the indexer has no contracts, chains, or events to register handlers for.";
1332
1179
  type CodegenRequiredFallback = {
1333
1180
  readonly onEvent: (...hint: CodegenRequiredHint[]) => void;
1334
- readonly onInstruction: (...hint: CodegenRequiredHint[]) => void;
1335
1181
  readonly onBlock: (...hint: CodegenRequiredHint[]) => void;
1336
1182
  readonly onSlot: (...hint: CodegenRequiredHint[]) => void;
1337
1183
  readonly contractRegister: (...hint: CodegenRequiredHint[]) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "envio",
3
- "version": "3.0.2-svm-alpha.0",
3
+ "version": "3.0.2",
4
4
  "type": "module",
5
5
  "description": "A latency and sync speed optimized, developer friendly blockchain data indexer.",
6
6
  "bin": "./bin.mjs",
@@ -43,6 +43,7 @@
43
43
  "@clickhouse/client": "1.17.0",
44
44
  "@elastic/ecs-pino-format": "1.4.0",
45
45
  "@envio-dev/hyperfuel-client": "1.2.2",
46
+ "@envio-dev/hypersync-client": "1.3.0",
46
47
  "@fuel-ts/crypto": "0.96.1",
47
48
  "@fuel-ts/errors": "0.96.1",
48
49
  "@fuel-ts/hasher": "0.96.1",
@@ -70,10 +71,10 @@
70
71
  "tsx": "4.21.0"
71
72
  },
72
73
  "optionalDependencies": {
73
- "envio-linux-x64": "3.0.2-svm-alpha.0",
74
- "envio-linux-x64-musl": "3.0.2-svm-alpha.0",
75
- "envio-linux-arm64": "3.0.2-svm-alpha.0",
76
- "envio-darwin-x64": "3.0.2-svm-alpha.0",
77
- "envio-darwin-arm64": "3.0.2-svm-alpha.0"
74
+ "envio-linux-x64": "3.0.2",
75
+ "envio-linux-x64-musl": "3.0.2",
76
+ "envio-linux-arm64": "3.0.2",
77
+ "envio-darwin-x64": "3.0.2",
78
+ "envio-darwin-arm64": "3.0.2"
78
79
  }
79
80
  }
@@ -233,31 +233,7 @@ let make = (
233
233
  ~lowercaseAddresses,
234
234
  )
235
235
  | Config.FuelSourceConfig({hypersync}) => [HyperFuelSource.make({chain, endpointUrl: hypersync})]
236
- | Config.SvmSourceConfig({hypersync, rpc}) =>
237
- switch hypersync {
238
- | None => [Svm.makeRPCSource(~chain, ~rpc)]
239
- | Some(hypersyncUrl) =>
240
- // HyperSync drives instruction sync; RPC remains the height oracle
241
- // (Svm.makeRPCSource's `getFinalizedSlot` route) and the fallback.
242
- let svmEventConfigs =
243
- chainConfig.contracts
244
- ->Array.flatMap(contract => contract.events)
245
- ->(
246
- Utils.magic: array<Internal.eventConfig> => array<Internal.svmInstructionEventConfig>
247
- )
248
- let apiToken = Env.envioApiToken
249
- [
250
- HyperSyncSolanaSource.make({
251
- chain,
252
- endpointUrl: hypersyncUrl,
253
- apiToken,
254
- eventConfigs: svmEventConfigs,
255
- clientMaxRetries: Env.hyperSyncClientMaxRetries,
256
- clientTimeoutMillis: Env.hyperSyncClientTimeoutMillis,
257
- }),
258
- Svm.makeRPCSource(~chain, ~rpc, ~sourceFor=Fallback),
259
- ]
260
- }
236
+ | Config.SvmSourceConfig({rpc}) => [Svm.makeRPCSource(~chain, ~rpc)]
261
237
  // For tests: use ready-to-use sources directly
262
238
  | Config.CustomSources(sources) => sources
263
239
  }
@@ -21,7 +21,6 @@ import * as Stdlib_Promise from "@rescript/runtime/lib/es6/Stdlib_Promise.js";
21
21
  import * as HyperFuelSource from "./sources/HyperFuelSource.res.mjs";
22
22
  import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
23
23
  import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
24
- import * as HyperSyncSolanaSource from "./sources/HyperSyncSolanaSource.res.mjs";
25
24
  import * as SafeCheckpointTracking from "./SafeCheckpointTracking.res.mjs";
26
25
 
27
26
  function configAddresses(chainConfig) {
@@ -134,24 +133,7 @@ function make(chainConfig, indexingAddresses, startBlock, endBlock, firstEventBl
134
133
  })];
135
134
  break;
136
135
  case "SvmSourceConfig" :
137
- let rpc = sources.rpc;
138
- let hypersync = sources.hypersync;
139
- if (hypersync !== undefined) {
140
- let svmEventConfigs = chainConfig.contracts.flatMap(contract => contract.events);
141
- sources$1 = [
142
- HyperSyncSolanaSource.make({
143
- chain: chain,
144
- endpointUrl: hypersync,
145
- apiToken: Env.envioApiToken,
146
- eventConfigs: svmEventConfigs,
147
- clientMaxRetries: Env.hyperSyncClientMaxRetries,
148
- clientTimeoutMillis: Env.hyperSyncClientTimeoutMillis
149
- }),
150
- Svm.makeRPCSource(chain, rpc, "Fallback")
151
- ];
152
- } else {
153
- sources$1 = [Svm.makeRPCSource(chain, rpc, undefined)];
154
- }
136
+ sources$1 = [Svm.makeRPCSource(chain, sources.rpc)];
155
137
  break;
156
138
  case "CustomSources" :
157
139
  sources$1 = sources._0;