envio 3.7.0 → 3.8.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.
Files changed (43) hide show
  1. package/index.d.ts +331 -142
  2. package/package.json +6 -6
  3. package/src/ChainState.res +9 -1
  4. package/src/ChainState.res.mjs +6 -1
  5. package/src/Config.res +19 -10
  6. package/src/Config.res.mjs +17 -7
  7. package/src/Envio.res +54 -76
  8. package/src/EventConfigBuilder.res +159 -30
  9. package/src/EventConfigBuilder.res.mjs +120 -24
  10. package/src/HandlerRegister.res +20 -11
  11. package/src/HandlerRegister.res.mjs +22 -5
  12. package/src/Hasura.res +30 -22
  13. package/src/Hasura.res.mjs +11 -5
  14. package/src/InMemoryStore.res +1 -6
  15. package/src/InMemoryStore.res.mjs +1 -3
  16. package/src/Internal.res +33 -13
  17. package/src/Internal.res.mjs +12 -16
  18. package/src/Main.res +2 -5
  19. package/src/MemoryStorage.res +40 -8
  20. package/src/MemoryStorage.res.mjs +38 -16
  21. package/src/Persistence.res +4 -2
  22. package/src/PgStorage.res +6 -1
  23. package/src/PgStorage.res.mjs +1 -1
  24. package/src/SimulateItems.res +261 -9
  25. package/src/SimulateItems.res.mjs +218 -47
  26. package/src/TestIndexer.res +26 -10
  27. package/src/TestIndexer.res.mjs +34 -12
  28. package/src/bindings/ClickHouse.res +33 -6
  29. package/src/bindings/ClickHouse.res.mjs +25 -4
  30. package/src/db/InternalTable.res +11 -0
  31. package/src/db/InternalTable.res.mjs +7 -0
  32. package/src/sources/EvmHyperSyncSource.res +3 -2
  33. package/src/sources/SimulateSource.res +8 -4
  34. package/src/sources/SimulateSource.res.mjs +7 -3
  35. package/src/sources/Svm.res +34 -7
  36. package/src/sources/Svm.res.mjs +32 -4
  37. package/src/sources/SvmHyperSyncClient.res +10 -12
  38. package/src/sources/SvmHyperSyncClient.res.mjs +3 -2
  39. package/src/sources/SvmHyperSyncSource.res +91 -34
  40. package/src/sources/SvmHyperSyncSource.res.mjs +77 -37
  41. package/src/sources/TransactionStore.res +38 -0
  42. package/src/sources/TransactionStore.res.mjs +5 -0
  43. package/svm.schema.json +27 -78
@@ -8,46 +8,83 @@ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js
8
8
  import * as SvmHyperSyncClient from "./SvmHyperSyncClient.res.mjs";
9
9
  import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
10
10
 
11
- function parseDecoded(d) {
12
- let args;
11
+ function parseArgs(d) {
13
12
  try {
14
- args = JSON.parse(d.argsJson);
13
+ return JSON.parse(d.argsJson);
15
14
  } catch (exn) {
16
- args = {};
15
+ return {};
17
16
  }
18
- let accounts;
19
- try {
20
- accounts = JSON.parse(d.accountsJson);
21
- } catch (exn$1) {
22
- accounts = {};
17
+ }
18
+
19
+ function namedAccounts(idlNames, accountArguments) {
20
+ let out = {};
21
+ idlNames.forEach((name, i) => {
22
+ let address = accountArguments[i];
23
+ if (address !== undefined) {
24
+ out[name] = {
25
+ address: address,
26
+ accountName: name,
27
+ instructionAccountIndex: i
28
+ };
29
+ return;
30
+ }
31
+ });
32
+ return out;
33
+ }
34
+
35
+ function selectedLog(log, logFields) {
36
+ let out = {};
37
+ if (logFields.has("kind")) {
38
+ let kind = log.kind;
39
+ if (kind !== undefined) {
40
+ out["kind"] = kind;
41
+ }
23
42
  }
24
- return {
25
- name: d.name,
26
- args: args,
27
- accounts: accounts,
28
- extraAccounts: d.extraAccounts
29
- };
43
+ if (logFields.has("message")) {
44
+ let message = log.message;
45
+ if (message !== undefined) {
46
+ out["message"] = message;
47
+ }
48
+ }
49
+ return out;
30
50
  }
31
51
 
32
- function toSvmInstruction(item, programName, instructionName) {
33
- return {
34
- programName: programName,
35
- instructionName: instructionName,
36
- programId: item.programId,
37
- data: item.data,
38
- accounts: item.accounts,
39
- instructionAddress: item.instructionAddress,
40
- isInner: item.isInner,
41
- d1: item.d1,
42
- d2: item.d2,
43
- d4: item.d4,
44
- d8: item.d8,
45
- params: Stdlib_Option.map(item.decoded, parseDecoded),
46
- logs: Stdlib_Option.map(item.logs, logs => logs.map(log => ({
47
- kind: log.kind,
48
- message: log.message
49
- })))
50
- };
52
+ function setField(out, name, value) {
53
+ out[name] = value;
54
+ }
55
+
56
+ function toSvmInstruction(item, programName, instructionName, eventConfig, fieldSelection) {
57
+ let d = eventConfig.discriminator;
58
+ let discriminator = d !== undefined ? d : item.data;
59
+ let out = {};
60
+ setField(out, "programName", programName);
61
+ setField(out, "instructionName", instructionName);
62
+ setField(out, "discriminator", discriminator);
63
+ if (fieldSelection.instructionFields.has("programId")) {
64
+ setField(out, "programId", item.programId);
65
+ }
66
+ if (fieldSelection.instructionFields.has("data")) {
67
+ setField(out, "data", item.data);
68
+ }
69
+ if (fieldSelection.instructionFields.has("path")) {
70
+ setField(out, "path", item.path);
71
+ }
72
+ if (fieldSelection.instructionFields.has("isInner")) {
73
+ setField(out, "isInner", item.isInner);
74
+ }
75
+ if (fieldSelection.instructionFields.has("args")) {
76
+ setField(out, "args", Stdlib_Option.map(item.decoded, parseArgs));
77
+ }
78
+ if (fieldSelection.instructionFields.has("accounts")) {
79
+ setField(out, "accounts", namedAccounts(eventConfig.accounts, item.accounts));
80
+ }
81
+ if (fieldSelection.instructionFields.has("accountArguments")) {
82
+ setField(out, "accountArguments", item.accounts);
83
+ }
84
+ if (fieldSelection.logFields.size > 0) {
85
+ setField(out, "logs", Stdlib_Option.getOr(item.logs, []).map(log => selectedLog(log, fieldSelection.logFields)));
86
+ }
87
+ return out;
51
88
  }
52
89
 
53
90
  function make(param) {
@@ -97,14 +134,14 @@ function make(param) {
97
134
  let parsedQueueItems = resp.items.map(item => {
98
135
  let onEventRegistration = onEventRegistrations[item.onEventRegistrationIndex];
99
136
  let eventConfig = onEventRegistration.eventConfig;
100
- let payload = toSvmInstruction(item, eventConfig.contractName, eventConfig.name);
137
+ let payload = toSvmInstruction(item, eventConfig.contractName, eventConfig.name, eventConfig, onEventRegistration.fieldSelection);
101
138
  return {
102
139
  kind: 0,
103
140
  onEventRegistration: onEventRegistration,
104
141
  chainId: chainId,
105
142
  blockNumber: item.slot,
106
143
  logIndex: item.transactionIndex,
107
- orderPath: item.instructionAddress,
144
+ orderPath: item.path,
108
145
  transactionIndex: item.transactionIndex,
109
146
  payload: payload
110
147
  };
@@ -152,7 +189,10 @@ function make(param) {
152
189
  }
153
190
 
154
191
  export {
155
- parseDecoded,
192
+ parseArgs,
193
+ namedAccounts,
194
+ selectedLog,
195
+ setField,
156
196
  toSvmInstruction,
157
197
  make,
158
198
  }
@@ -31,6 +31,44 @@ let fieldCodes = FieldMask.fieldCodes
31
31
  // Drain another store (a fetch-response page) into this one.
32
32
  @send external merge: (t, t) => unit = "merge"
33
33
 
34
+ type svmTxInput = {
35
+ slot: int,
36
+ transactionIndex: int,
37
+ signature?: string,
38
+ allSignatures?: array<string>,
39
+ feePayer?: string,
40
+ success?: bool,
41
+ err?: string,
42
+ fee?: bigint,
43
+ computeUnitsConsumed?: bigint,
44
+ accountKeys?: array<string>,
45
+ recentBlockhash?: string,
46
+ version?: string,
47
+ }
48
+
49
+ type svmActivityInput = {
50
+ slot: int,
51
+ transactionIndex: int,
52
+ account: string,
53
+ accountIndex?: int,
54
+ isSigner?: bool,
55
+ isWritable?: bool,
56
+ preBalance?: bigint,
57
+ postBalance?: bigint,
58
+ mint?: string,
59
+ owner?: string,
60
+ decimals?: int,
61
+ preAmount?: bigint,
62
+ postAmount?: bigint,
63
+ }
64
+
65
+ @send
66
+ external fromJsSvm: (Core.transactionStoreCtor, array<svmTxInput>, array<svmActivityInput>) => t =
67
+ "fromJsSvm"
68
+
69
+ let fromSvmJs = (transactions: array<svmTxInput>, activities: array<svmActivityInput>): t =>
70
+ Core.getAddon().transactionStore->fromJsSvm(transactions, activities)
71
+
34
72
  // Bulk-materialise transactions off the JS thread, one row per
35
73
  // (blockNumbers[i], transactionIndices[i]) key, decoding only the fields set in
36
74
  // that row's own masks[i]. Result is aligned with the input.
@@ -15,6 +15,10 @@ function make(ecosystem, shouldChecksum) {
15
15
  }
16
16
  }
17
17
 
18
+ function fromSvmJs(transactions, activities) {
19
+ return Core.getAddon().TransactionStore.fromJsSvm(transactions, activities);
20
+ }
21
+
18
22
  let makeMaskFn = FieldMask.makeMaskFn;
19
23
 
20
24
  let orMask = FieldMask.orMask;
@@ -26,5 +30,6 @@ export {
26
30
  makeMaskFn,
27
31
  orMask,
28
32
  fieldCodes,
33
+ fromSvmJs,
29
34
  }
30
35
  /* Core Not a pure module */
package/svm.schema.json CHANGED
@@ -212,6 +212,10 @@
212
212
  "Chain": {
213
213
  "type": "object",
214
214
  "properties": {
215
+ "id": {
216
+ "description": "Identifies the Svm cluster: the label \"solana\" (7565164) or \"solana-devnet\" (7565165), or an explicit number of your choosing for other clusters (up to Number.MAX_SAFE_INTEGER). Svm has no native numeric chain id, so the label ids are assigned by Envio and match the ids used for HyperSync usage attribution.",
217
+ "$ref": "#/$defs/ChainId"
218
+ },
215
219
  "skip": {
216
220
  "description": "Excludes the chain from indexing and migrations. Code generation is unaffected. For testing, prefer using a test framework instead.",
217
221
  "type": [
@@ -264,9 +268,31 @@
264
268
  },
265
269
  "additionalProperties": false,
266
270
  "required": [
271
+ "id",
267
272
  "start_block"
268
273
  ]
269
274
  },
275
+ "ChainId": {
276
+ "description": "The chain id of an Svm chain: either a known cluster label or an\nexplicit number (for private chains, rollups, or custom clusters).",
277
+ "anyOf": [
278
+ {
279
+ "$ref": "#/$defs/ChainLabel"
280
+ },
281
+ {
282
+ "type": "integer",
283
+ "format": "uint64",
284
+ "minimum": 0,
285
+ "maximum": 9007199254740991
286
+ }
287
+ ]
288
+ },
289
+ "ChainLabel": {
290
+ "type": "string",
291
+ "enum": [
292
+ "solana",
293
+ "solana-devnet"
294
+ ]
295
+ },
270
296
  "Experimental": {
271
297
  "type": "object",
272
298
  "properties": {
@@ -373,19 +399,8 @@
373
399
  }
374
400
  ]
375
401
  },
376
- "field_selection": {
377
- "description": "Select which additional data to fetch for each matched instruction. Each key accepts `true` (include all fields) or a list of field names (per-field selection, not yet supported). When absent, only the instruction itself is included.",
378
- "anyOf": [
379
- {
380
- "$ref": "#/$defs/SvmFieldSelection"
381
- },
382
- {
383
- "type": "null"
384
- }
385
- ]
386
- },
387
402
  "accounts": {
388
- "description": "Optional positional account names. The Nth entry names account slot N on the dispatched instruction; surfaces as `event.instruction.decoded.accounts.<name>`. Accounts beyond the named list become `extra_accounts`.",
403
+ "description": "Optional positional account names. The Nth entry names account slot N on the dispatched instruction; surfaces as `instruction.accounts.<name>` when `fields.instruction` includes `accounts`.",
389
404
  "type": [
390
405
  "array",
391
406
  "null"
@@ -466,72 +481,6 @@
466
481
  "any_of"
467
482
  ]
468
483
  },
469
- "SvmFieldSelection": {
470
- "type": "object",
471
- "properties": {
472
- "transaction_fields": {
473
- "description": "Parent-transaction fields to include on each matched instruction, as a list of field names. Omit (or pass an empty list) to include no transaction.",
474
- "type": [
475
- "array",
476
- "null"
477
- ],
478
- "items": {
479
- "$ref": "#/$defs/SvmTransactionField"
480
- }
481
- },
482
- "block_fields": {
483
- "description": "Block fields to include on each matched instruction's `block`, as a list of field names. `slot`/`time`/`hash` are always included; this adds `height`/`parentSlot`/`parentHash`.",
484
- "type": [
485
- "array",
486
- "null"
487
- ],
488
- "items": {
489
- "$ref": "#/$defs/SvmBlockField"
490
- }
491
- },
492
- "log_fields": {
493
- "description": "Set to `true` to include program logs scoped to each matched instruction.",
494
- "type": [
495
- "boolean",
496
- "null"
497
- ]
498
- },
499
- "token_balance_fields": {
500
- "description": "Set to `true` to include SPL Token / Token-2022 balance snapshots for the parent transaction, exposed as `transaction.tokenBalances`. Independent of `transaction_fields`.",
501
- "type": [
502
- "boolean",
503
- "null"
504
- ]
505
- }
506
- },
507
- "additionalProperties": false
508
- },
509
- "SvmTransactionField": {
510
- "description": "Selectable parent-transaction field names (camelCase), matching the\npublic `svmTransaction` shape. `tokenBalances` is selected via the\nseparate `token_balance_fields` toggle, so it isn't listed here.",
511
- "type": "string",
512
- "enum": [
513
- "transactionIndex",
514
- "signature",
515
- "feePayer",
516
- "success",
517
- "err",
518
- "fee",
519
- "computeUnitsConsumed",
520
- "accountKeys",
521
- "recentBlockhash",
522
- "version",
523
- "allSignatures"
524
- ]
525
- },
526
- "SvmBlockField": {
527
- "description": "Selectable block field names (camelCase), matching the public\n`instruction.block` shape. `slot`/`time`/`hash` are always included,\nso everything here is opt-in on top of that trio.",
528
- "type": "string",
529
- "enum": [
530
- "height",
531
- "parentSlot",
532
- "parentHash"
533
- ]
534
- },
535
484
  "ArgDef": {
536
485
  "description": "One named argument of an instruction. Mirrors\n`hypersync_client_solana::decode::NamedField`.",
537
486
  "type": "object",