@odatano/core 2.0.0-rc.3 → 2.0.0-rc.30

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 (162) hide show
  1. package/@cds-models/CardanoAgentService/index.d.ts +251 -0
  2. package/@cds-models/CardanoAgentService/index.js +36 -0
  3. package/@cds-models/CardanoBackendService/index.d.ts +357 -0
  4. package/@cds-models/CardanoBackendService/index.js +40 -0
  5. package/@cds-models/CardanoIndexerService/index.d.ts +194 -2
  6. package/@cds-models/CardanoIndexerService/index.js +25 -0
  7. package/@cds-models/CardanoODataService/index.d.ts +294 -7
  8. package/@cds-models/CardanoODataService/index.js +33 -0
  9. package/@cds-models/CardanoSignService/index.d.ts +28 -3
  10. package/@cds-models/CardanoSignService/index.js +3 -0
  11. package/@cds-models/CardanoTransactionService/index.d.ts +52 -19
  12. package/@cds-models/CardanoTransactionService/index.js +4 -0
  13. package/@cds-models/index.d.ts +18 -0
  14. package/@cds-models/index.js +3 -0
  15. package/@cds-models/odatano/cardano/index.d.ts +408 -7
  16. package/@cds-models/odatano/cardano/index.js +42 -0
  17. package/README.md +64 -5
  18. package/db/schema.cds +677 -13
  19. package/db/types.cds +27 -0
  20. package/package.json +182 -173
  21. package/scripts/migrate-slot-leader.mjs +104 -0
  22. package/scripts/migrate-txseq.mjs +147 -0
  23. package/src/index.d.ts +11 -10
  24. package/src/index.js +28 -14
  25. package/src/plugin.js +39 -52
  26. package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
  27. package/srv/blockchain/backends/blockfrost-backend.js +49 -160
  28. package/srv/blockchain/backends/cardano-backend.d.ts +104 -158
  29. package/srv/blockchain/backends/cardano-backend.js +19 -5
  30. package/srv/blockchain/backends/koios-backend.d.ts +126 -60
  31. package/srv/blockchain/backends/koios-backend.js +356 -217
  32. package/srv/blockchain/backends/odatano-backend.d.ts +64 -0
  33. package/srv/blockchain/backends/odatano-backend.js +170 -0
  34. package/srv/blockchain/backends/ogmios-backend.d.ts +162 -94
  35. package/srv/blockchain/backends/ogmios-backend.js +548 -197
  36. package/srv/blockchain/backends/ogmios-frame-guard.d.ts +32 -0
  37. package/srv/blockchain/backends/ogmios-frame-guard.js +142 -0
  38. package/srv/blockchain/cardano-client.d.ts +78 -205
  39. package/srv/blockchain/cardano-client.js +186 -242
  40. package/srv/blockchain/cardano-indexer.d.ts +302 -242
  41. package/srv/blockchain/cardano-indexer.js +1191 -362
  42. package/srv/blockchain/cardano-tx-builder.d.ts +43 -81
  43. package/srv/blockchain/cardano-tx-builder.js +177 -132
  44. package/srv/blockchain/crawler/certificate-backfill.d.ts +67 -0
  45. package/srv/blockchain/crawler/certificate-backfill.js +169 -0
  46. package/srv/blockchain/crawler/crawler.d.ts +139 -54
  47. package/srv/blockchain/crawler/crawler.js +478 -96
  48. package/srv/blockchain/crawler/hooks.d.ts +3 -14
  49. package/srv/blockchain/crawler/index.d.ts +5 -0
  50. package/srv/blockchain/crawler/index.js +35 -7
  51. package/srv/blockchain/crawler/sync-state.d.ts +46 -28
  52. package/srv/blockchain/crawler/sync-state.js +128 -43
  53. package/srv/blockchain/crawler/transaction-backfill.d.ts +52 -0
  54. package/srv/blockchain/crawler/transaction-backfill.js +283 -0
  55. package/srv/blockchain/crawler/utxo-set-import.d.ts +78 -0
  56. package/srv/blockchain/crawler/utxo-set-import.js +363 -0
  57. package/srv/blockchain/ledger-state.d.ts +101 -0
  58. package/srv/blockchain/ledger-state.js +432 -0
  59. package/srv/blockchain/pending-spends.d.ts +28 -0
  60. package/srv/blockchain/pending-spends.js +89 -0
  61. package/srv/blockchain/signing/cose-verifier.d.ts +5 -12
  62. package/srv/blockchain/signing/cose-verifier.js +6 -12
  63. package/srv/blockchain/signing/external-signer.d.ts +16 -113
  64. package/srv/blockchain/signing/external-signer.js +19 -122
  65. package/srv/blockchain/signing/hsm-signer.d.ts +13 -45
  66. package/srv/blockchain/signing/hsm-signer.js +23 -63
  67. package/srv/blockchain/signing/signature-verifier.d.ts +8 -44
  68. package/srv/blockchain/signing/signature-verifier.js +13 -54
  69. package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
  70. package/srv/blockchain/signing/submission-finalizer.js +16 -49
  71. package/srv/blockchain/stored-chain.d.ts +33 -0
  72. package/srv/blockchain/stored-chain.js +234 -0
  73. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +108 -160
  74. package/srv/blockchain/transaction-building/buildooor-tx.js +620 -285
  75. package/srv/blockchain/transaction-building/caller-datums.d.ts +17 -0
  76. package/srv/blockchain/transaction-building/caller-datums.js +50 -0
  77. package/srv/blockchain/transaction-building/cardano-tx.d.ts +10 -35
  78. package/srv/blockchain/transaction-rows.d.ts +12 -0
  79. package/srv/blockchain/transaction-rows.js +43 -0
  80. package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
  81. package/srv/blockchain/wallet-worker/build-request.js +48 -24
  82. package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +25 -17
  83. package/srv/blockchain/wallet-worker/confirmation-tracker.js +87 -41
  84. package/srv/blockchain/wallet-worker/index.js +2 -8
  85. package/srv/blockchain/wallet-worker/job-store.d.ts +36 -103
  86. package/srv/blockchain/wallet-worker/job-store.js +0 -0
  87. package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +4 -20
  88. package/srv/blockchain/wallet-worker/lease-heartbeat.js +4 -20
  89. package/srv/blockchain/wallet-worker/signers.d.ts +6 -19
  90. package/srv/blockchain/wallet-worker/signers.js +3 -8
  91. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +15 -71
  92. package/srv/blockchain/wallet-worker/wallet-worker.js +40 -91
  93. package/srv/cardano-agent-service.cds +146 -0
  94. package/srv/cardano-agent-service.d.ts +2 -0
  95. package/srv/cardano-agent-service.js +12 -0
  96. package/srv/cardano-backend-service.cds +52 -0
  97. package/srv/cardano-backend-service.d.ts +2 -0
  98. package/srv/cardano-backend-service.js +244 -0
  99. package/srv/cardano-indexer-service.cds +201 -73
  100. package/srv/cardano-indexer-service.js +280 -11
  101. package/srv/cardano-service.cds +56 -1
  102. package/srv/cardano-service.js +52 -113
  103. package/srv/cardano-sign-service.cds +200 -180
  104. package/srv/cardano-sign-service.js +55 -173
  105. package/srv/cardano-tx-service.cds +439 -364
  106. package/srv/cardano-tx-service.js +305 -209
  107. package/srv/cardano-ui.cds +16 -16
  108. package/srv/cardano-worker-service.js +7 -15
  109. package/srv/cbor/parse.js +13 -1
  110. package/srv/server.d.ts +28 -86
  111. package/srv/server.js +127 -135
  112. package/srv/utils/agent-grants-config.d.ts +37 -0
  113. package/srv/utils/agent-grants-config.js +138 -0
  114. package/srv/utils/agent-grants.d.ts +262 -0
  115. package/srv/utils/agent-grants.js +922 -0
  116. package/srv/utils/agent-token-auth.d.ts +16 -0
  117. package/srv/utils/agent-token-auth.js +78 -0
  118. package/srv/utils/backend-request-handler.d.ts +2 -16
  119. package/srv/utils/backend-request-handler.js +3 -18
  120. package/srv/utils/collections.d.ts +4 -8
  121. package/srv/utils/collections.js +4 -8
  122. package/srv/utils/const.d.ts +30 -67
  123. package/srv/utils/const.js +32 -72
  124. package/srv/utils/crypto.d.ts +3 -12
  125. package/srv/utils/crypto.js +5 -18
  126. package/srv/utils/db-indexes.d.ts +25 -0
  127. package/srv/utils/db-indexes.js +94 -0
  128. package/srv/utils/db-sanitize.d.ts +27 -0
  129. package/srv/utils/db-sanitize.js +85 -0
  130. package/srv/utils/epoch-slots.d.ts +13 -0
  131. package/srv/utils/epoch-slots.js +25 -0
  132. package/srv/utils/error-codes.d.ts +20 -73
  133. package/srv/utils/error-codes.js +19 -70
  134. package/srv/utils/errors.d.ts +50 -177
  135. package/srv/utils/errors.js +94 -218
  136. package/srv/utils/liveness.d.ts +16 -0
  137. package/srv/utils/liveness.js +40 -0
  138. package/srv/utils/mappers.d.ts +128 -214
  139. package/srv/utils/mappers.js +354 -299
  140. package/srv/utils/network-context.js +2 -11
  141. package/srv/utils/pg-inline-json.d.ts +8 -0
  142. package/srv/utils/pg-inline-json.js +62 -0
  143. package/srv/utils/pg-order-nulls.d.ts +14 -0
  144. package/srv/utils/pg-order-nulls.js +56 -0
  145. package/srv/utils/plutus-placeholders.d.ts +23 -16
  146. package/srv/utils/plutus-placeholders.js +63 -27
  147. package/srv/utils/rate-limiter.d.ts +46 -0
  148. package/srv/utils/rate-limiter.js +116 -0
  149. package/srv/utils/service-events.d.ts +2 -22
  150. package/srv/utils/service-events.js +3 -23
  151. package/srv/utils/signing-helper.d.ts +3 -18
  152. package/srv/utils/signing-helper.js +10 -32
  153. package/srv/utils/tx-build-helper.d.ts +26 -92
  154. package/srv/utils/tx-build-helper.js +68 -123
  155. package/srv/utils/tx-request-parsers.d.ts +107 -21
  156. package/srv/utils/tx-request-parsers.js +433 -34
  157. package/srv/utils/tx-utils.d.ts +4 -23
  158. package/srv/utils/tx-utils.js +12 -41
  159. package/srv/utils/types.d.ts +238 -169
  160. package/srv/utils/types.js +2 -6
  161. package/srv/utils/validators.d.ts +24 -90
  162. package/srv/utils/validators.js +50 -147
@@ -1,183 +1,83 @@
1
1
  import { Transaction, Address, UTxO, NetworkInformation, BlockData, EpochData, MetadataLabelTx, PoolData, DrepData, AccountData, AssetInfo, AssetHistoryEntry, LedgerProtocolParameters, ScriptEvaluationResult } from '../../utils/types';
2
- /**
3
- * CardanoBackend - Interface Definition for multiple backends (Blockfrost, Koios, Ogmios, etc.)
4
- *
5
- * Defines the standard methods that any Cardano backend must implement to be used interchangeably.
6
- */
2
+ /** Common interface every Cardano backend (Blockfrost, Koios, Ogmios, ...) implements. */
7
3
  export interface CardanoBackend {
8
- /**
9
- * Backend name
10
- */
4
+ /** Backend name */
11
5
  name: string;
12
6
  /**
13
- * Methods this backend declares as NOT supported. The orchestrator skips the
14
- * backend for these without counting a circuit-breaker failure — previously
15
- * Ogmios either fabricated placeholder data for them (which preferLive routing
16
- * then preferred over correct historical data) or its thrown errors poisoned
17
- * the breaker.
7
+ * Methods this backend declares as NOT supported; the orchestrator skips it for
8
+ * these without counting a circuit-breaker failure.
18
9
  */
19
10
  readonly unsupportedMethods?: ReadonlySet<string>;
20
- /**
21
- * Initialize the backend
22
- */
11
+ /** Initialize the backend */
23
12
  init(): Promise<boolean>;
24
- /**
25
- * Get Transaction Data
26
- * @param txHash transaction hash (hex)
27
- * @returns {Promise<Transaction>} transaction data
28
- */
13
+ /** Transaction by hash (hex). */
29
14
  getTransaction(txHash: string): Promise<Transaction>;
30
- /**
31
- * Get Address Data
32
- * @param address bech32 address
33
- * @returns {Promise<Address>} address data
34
- */
15
+ /** Address data by bech32 address. */
35
16
  getAddress(address: string): Promise<Address>;
36
- /**
37
- * Get Address UTxOs
38
- * @param address bech32 address
39
- * @returns {Promise<UTxO[]>} list of UTxOs
40
- */
17
+ /** UTxOs of a bech32 address. */
41
18
  getAddressUtxos(address: string): Promise<UTxO[]>;
42
- /**
43
- * Get Address Transactions (lightweight - only tx hashes and basic info)
44
- * @param address bech32 address
45
- * @returns {Promise<Transaction[]>} list of transactions involving this address
46
- */
19
+ /** Transactions involving a bech32 address (lightweight — hashes and basic info). */
47
20
  getAddressTransactions(address: string, limit: number): Promise<Transaction[]>;
48
- /**
49
- * Get Network Information
50
- * @returns {Promise<NetworkInformation>} network information
51
- */
21
+ /** Network information (supply, stake). */
52
22
  getNetworkInformation(): Promise<NetworkInformation>;
53
- /**
54
- * Get Transaction Metadata
55
- * @param txHash transaction hash (hex)
56
- * @returns {Promise<MetadataLabelTx[]>} transaction metadata list
57
- */
23
+ /** Metadata labels of a transaction (hash hex). */
58
24
  getTransactionMetadata(txHash: string): Promise<MetadataLabelTx[]>;
59
- /**
60
- * Get Block Data
61
- * @param blockHash block hash (hex)
62
- * @returns {Promise<BlockData>} block data
63
- */
25
+ /** Block by hash (hex). */
64
26
  getBlock(blockHash: string): Promise<BlockData>;
65
- /**
66
- * Get Epoch Data
67
- * @param epochNumber epoch number
68
- * @returns {Promise<EpochData>} epoch data
69
- */
27
+ /** Epoch by number. */
70
28
  getEpoch(epochNumber: number): Promise<EpochData>;
71
- /**
72
- * Get Latest Epoch Data
73
- * @returns {Promise<EpochData>} latest epoch data
74
- */
29
+ /** Latest epoch. */
75
30
  getLatestEpoch(): Promise<EpochData>;
76
- /**
77
- * Get Latest Block Data
78
- * @returns {Promise<BlockData>} latest block data
79
- */
31
+ /** Latest block. */
80
32
  getLatestBlock(): Promise<BlockData>;
81
- /**
82
- * Get the latest chain tip slot.
83
- * Throws ProviderUnavailableError when the backend's latest block has no slot.
84
- * @returns {Promise<number>} current chain slot
85
- */
33
+ /** Latest chain tip slot; throws ProviderUnavailableError when the latest block has no slot. */
86
34
  getCurrentSlot(): Promise<number>;
87
35
  /**
88
- * Check whether a UTxO is still unspent. Returns `false` for txs that don't
89
- * exist on chain and for out-of-range output indices.
36
+ * Whether a UTxO is still unspent. `false` for txs that don't exist on chain and
37
+ * for out-of-range output indices.
90
38
  * @param txHash 64-char lowercase hex
91
- * @param outputIndex non-negative integer
92
- * @returns {Promise<boolean>} true iff the UTxO exists and is unspent
93
39
  */
94
40
  isUtxoUnspent(txHash: string, outputIndex: number): Promise<boolean>;
95
- /**
96
- * Get Pool Data
97
- * @param poolId pool id
98
- * @returns {Promise<PoolData>} pool data
99
- */
41
+ /** Stake pool by id. */
100
42
  getPool(poolId: string): Promise<PoolData>;
101
- /**
102
- * Get Drep Data
103
- * @param drepId drep id
104
- * @returns {Promise<DrepData>} drep data
105
- */
43
+ /** DRep by id. */
106
44
  getDrep(drepId: string): Promise<DrepData>;
107
- /**
108
- * Get Account Data
109
- * @param accountId account id
110
- * @returns {Promise<AccountData>} account data
111
- */
45
+ /** Account by stake address. */
112
46
  getAccount(accountId: string): Promise<AccountData>;
113
- /**
114
- * Get Asset Info (supply, mint history, CIP-25 + CIP-26 metadata)
115
- * @param unit policyId + assetNameHex (concatenated hex)
116
- * @returns {Promise<AssetInfo>} canonical asset info
117
- */
47
+ /** Asset info (supply, mint history, CIP-25 + CIP-26 metadata); unit = policyId + assetNameHex. */
118
48
  getAssetInfo(unit: string): Promise<AssetInfo>;
119
49
  /**
120
- * Get latest mint/burn events for an asset (most recent first).
121
- * Optional — Ogmios doesn't expose this. Blockfrost lacks block timestamps;
122
- * Koios includes block_time per entry.
123
- * @param unit policyId + assetNameHex (concatenated hex)
124
- * @param limit max number of events (default 100)
125
- * @returns {Promise<AssetHistoryEntry[]>} list of mint/burn events
50
+ * Latest mint/burn events for an asset (most recent first; limit default 100).
51
+ * Optional — Ogmios doesn't expose this. Blockfrost lacks block timestamps; Koios has block_time per entry.
126
52
  */
127
53
  getAssetHistory?(unit: string, limit?: number): Promise<AssetHistoryEntry[]>;
128
- /**
129
- * Get Protocol Parameters
130
- * @returns {Promise<LedgerProtocolParameters>} protocol parameters
131
- */
54
+ /** Current protocol parameters. */
132
55
  getProtocolParameters(): Promise<LedgerProtocolParameters>;
133
- /**
134
- * Submit a signed transaction to the network
135
- * @param signedTxCbor signed transaction in CBOR hex format
136
- * @returns {Promise<string>} transaction hash
137
- */
56
+ /** Submit a signed transaction (CBOR hex); returns the tx hash. */
138
57
  submitTransaction(signedTxCbor: string): Promise<string>;
139
58
  /**
140
- * Get transaction hashes for an address (lightweight — no full tx details).
141
- * Used by the indexer to separate hash listing from detail fetching.
142
- * Optional: falls back to getAddressTransactions() + map to hashes if not implemented.
143
- * @param address bech32 address
144
- * @param limit maximum number of transaction hashes to return
145
- * @returns {Promise<string[]>} list of transaction hashes (most recent first)
59
+ * Most recent tx hashes of an address (no details).
60
+ * Optional — falls back to getAddressTransactions() mapped to hashes.
146
61
  */
147
62
  getAddressTransactionHashes?(address: string, limit: number): Promise<string[]>;
148
63
  /**
149
- * Batch fetch multiple transactions by hash.
150
- * Koios implements natively via POST /tx_info; Blockfrost uses concurrency-limited parallel calls.
151
- * Optional: falls back to individual getTransaction() calls if not implemented.
152
- * @param txHashes array of transaction hashes (hex)
153
- * @returns {Promise<Map<string, Transaction>>} map of txHash -> Transaction
64
+ * Transactions by hash, as a map txHash -> Transaction.
65
+ * Optional — falls back to individual getTransaction() calls.
154
66
  */
155
67
  getTransactionsBatch?(txHashes: string[]): Promise<Map<string, Transaction>>;
156
68
  /**
157
- * Get UTxOs across all bech32 addresses sharing a 28-byte payment credential
158
- * (key hash or script hash). Returns UTxOs with their owning bech32 address.
159
- * Optional — only Koios implements this natively (`POST /credential_utxos`).
69
+ * UTxOs across all bech32 addresses sharing a 28-byte payment credential (key or script
70
+ * hash), each with its owning address. Optional — only Koios has this natively.
160
71
  * @param credHash 28-byte payment credential as 56-char lowercase hex
161
- * @returns {Promise<UTxO[]>} list of UTxOs across all bech32 forms
162
72
  */
163
73
  getCredentialUtxos?(credHash: string): Promise<UTxO[]>;
164
74
  }
165
- /**
166
- * Extended backend interface for backends that support transaction evaluation (e.g., Ogmios)
167
- */
75
+ /** Backend that can evaluate script execution units (Ogmios). */
168
76
  export interface EvaluatingBackend extends CardanoBackend {
169
- /**
170
- * Evaluate transaction script execution units
171
- * @param unsignedTxCbor unsigned transaction in CBOR hex format
172
- * @returns evaluation results with validator and budget
173
- */
77
+ /** Evaluate the script execution units of an unsigned transaction (CBOR hex). */
174
78
  evaluateTransaction(unsignedTxCbor: string): Promise<ScriptEvaluationResult[]>;
175
79
  }
176
- /**
177
- * Type guard to check if a backend supports transaction evaluation
178
- * @param backend - The backend to check
179
- * @returns true if the backend supports evaluateTransaction
180
- */
80
+ /** Type guard: does this backend support transaction evaluation? */
181
81
  export declare function isEvaluatingBackend(backend: CardanoBackend): backend is EvaluatingBackend;
182
82
  /** A chain position the crawler can start from, stream to, or roll back to. */
183
83
  export interface ChainPoint {
@@ -189,16 +89,14 @@ export interface ChainPoint {
189
89
  export interface ChainSyncCallbacks {
190
90
  /**
191
91
  * A new block (with its full transaction list) extends the chain.
192
- * @param tip the node's current chain tip, when the protocol supplies it — lets the
193
- * consumer track sync progress / detect being caught up
92
+ * @param tip the node's current chain tip when the protocol supplies it (sync progress)
194
93
  */
195
94
  rollForward(block: BlockData, txs: Transaction[], tip?: ChainPoint): Promise<void>;
196
95
  /** The chain rolled back to `point` (or to genesis). All blocks after it are abandoned. */
197
96
  rollBackward(point: ChainPoint | 'origin'): Promise<void>;
198
97
  /**
199
- * A message-handler error stalled the stream (mapping failure, callback throw). The
200
- * stream stops requesting further blocks; the consumer should record the error and
201
- * close/restart. Optional — without it such errors are only logged.
98
+ * A message-handler error stalled the stream; no further blocks are requested and the
99
+ * consumer should record the error and close/restart. Optional — otherwise only logged.
202
100
  */
203
101
  onError?(err: unknown): Promise<void>;
204
102
  }
@@ -208,39 +106,49 @@ export interface ChainSyncHandle {
208
106
  close(): Promise<void>;
209
107
  }
210
108
  /**
211
- * Backend that can stream the chain forward from a point, emitting ordered
212
- * rollForward + native rollBackward (reorg) events. Implemented by Ogmios via the
213
- * chain-synchronization protocol — the crawler's primary, reorg-aware source.
109
+ * Backend that streams the chain forward from a point, emitting ordered rollForward and
110
+ * native rollBackward (reorg) events — Ogmios chain-synchronization, the crawler's primary source.
214
111
  */
215
112
  export interface ChainSyncBackend extends CardanoBackend {
216
113
  /**
217
- * Open a chain-sync stream starting just after the first of `from` that is still
218
- * on the node's chain (or from genesis).
219
- * @param from candidate intersection points, NEWEST FIRST, or 'origin' for a
220
- * fresh sync. Passing ancestors as well as the last-indexed point is what makes
221
- * a reorg that happened while we were disconnected resolvable: the node
222
- * intersects at the last common block and reports it via rollBackward, instead
223
- * of failing the whole stream with "No intersection found".
224
- * @param callbacks rollForward / rollBackward handlers
225
- * @returns a handle to close the stream
114
+ * Open a chain-sync stream starting just after the first of `from` still on the node's chain.
115
+ * @param from intersection candidates NEWEST FIRST (or 'origin'); include ancestors of the
116
+ * last-indexed point so a reorg during a disconnect resolves via rollBackward instead of "No intersection found"
226
117
  */
227
118
  openChainSync(from: ChainPoint[] | 'origin', callbacks: ChainSyncCallbacks): Promise<ChainSyncHandle>;
228
119
  }
229
120
  /** Type guard: does this backend support streamed chain-sync? */
230
121
  export declare function isChainSyncBackend(backend: CardanoBackend): backend is ChainSyncBackend;
231
122
  /**
232
- * Backend that can walk the chain forward by pagination (no live node). The
233
- * crawler's fallback source when no Ogmios chain-sync is available. Reorgs are
234
- * detected by the crawler via parent-hash mismatch (not delivered natively).
123
+ * Backend that reads UTxOs straight from the node's ledger (Ogmios `queryLedgerState/utxo`):
124
+ * the whole set as of a chain point inside the volatile window, or selected outputs at the tip.
125
+ */
126
+ export interface LedgerStateBackend extends CardanoBackend {
127
+ queryUtxoSetAt(point: ChainPoint): Promise<UTxO[]>;
128
+ /** Outputs among `refs` that are unspent at the tip; spent or unknown references are absent. */
129
+ getUnspentOutputs(refs: Array<{
130
+ txHash: string;
131
+ outputIndex: number;
132
+ }>): Promise<UTxO[]>;
133
+ }
134
+ export declare function isLedgerStateBackend(backend: CardanoBackend): backend is LedgerStateBackend;
135
+ /**
136
+ * Backend that walks the chain forward by pagination (no live node) — the crawler's fallback
137
+ * source. Reorgs are not delivered natively; the crawler detects them via parent-hash mismatch.
235
138
  */
236
139
  export interface PaginatingBackend extends CardanoBackend {
140
+ /**
141
+ * Optional: what the crawl wants per block beyond inputs/outputs. A backend that pays per
142
+ * payload (Koios `_certs`/`_withdrawals`) only asks when told to.
143
+ */
144
+ configureCrawl?(options: {
145
+ certificates: boolean;
146
+ }): void;
237
147
  /** Fetch a block by its height. */
238
148
  getBlockByHeight(height: number): Promise<BlockData>;
239
149
  /**
240
150
  * Fetch up to `count` blocks immediately following `afterHash`, in chain order.
241
- * @param afterHeight optional height of `afterHash` when the caller already knows it
242
- * (the crawler's cursor does) — lets height-listing backends
243
- * (Koios) skip a hash→height resolution round-trip
151
+ * @param afterHeight height of `afterHash` when known — lets height-listing backends skip a hash→height round-trip
244
152
  */
245
153
  getNextBlocks(afterHash: string, count: number, afterHeight?: number): Promise<BlockData[]>;
246
154
  /** Fetch the full transaction list of a block, in block order. */
@@ -248,4 +156,42 @@ export interface PaginatingBackend extends CardanoBackend {
248
156
  }
249
157
  /** Type guard: can this backend be walked forward by pagination? */
250
158
  export declare function isPaginatingBackend(backend: CardanoBackend): backend is PaginatingBackend;
159
+ /**
160
+ * Backend that enumerates the full stake-pool and DRep set and resolves them in batches
161
+ * (crawler epoch snapshots). Koios only: `/pool_list` + `POST /pool_info` make a mainnet
162
+ * snapshot a handful of requests; Blockfrost has no batch info endpoint (thousands of calls).
163
+ */
164
+ export interface EnumeratingBackend extends CardanoBackend {
165
+ /** All known stake-pool ids (bech32). */
166
+ getPoolIds(): Promise<string[]>;
167
+ /** Resolve a batch of pool ids. Ids the backend does not know are omitted, not faked. */
168
+ getPools(poolIds: string[]): Promise<PoolData[]>;
169
+ /** All known DRep ids (bech32). */
170
+ getDrepIds(): Promise<string[]>;
171
+ /** Resolve a batch of DRep ids. Ids the backend does not know are omitted. */
172
+ getDreps(drepIds: string[]): Promise<DrepData[]>;
173
+ }
174
+ /** Network-wide ledger state read at one block for an epoch snapshot; unreported figures are null. */
175
+ export interface EpochLedgerState {
176
+ /** Epoch the ledger was in at the acquired block. */
177
+ epoch: number;
178
+ pools: PoolData[];
179
+ /** Registered DReps only; the two predefined DReps are summed into the stake fields below. */
180
+ dreps: DrepData[];
181
+ treasury: string | null;
182
+ reserves: string | null;
183
+ drepAbstainStake: string | null;
184
+ drepNoConfidenceStake: string | null;
185
+ }
186
+ /**
187
+ * Backend that reads the whole pool/DRep set from the node's ledger at a given block (Ogmios).
188
+ * The block must still be inside the node's volatile window (k blocks), else acquisition fails.
189
+ */
190
+ export interface EpochStateBackend extends CardanoBackend {
191
+ epochStateAt(point: ChainPoint): Promise<EpochLedgerState>;
192
+ }
193
+ /** Type guard: can this backend read epoch state at a block? */
194
+ export declare function isEpochStateBackend(backend: CardanoBackend): backend is EpochStateBackend;
195
+ /** Type guard: can this backend enumerate pools and DReps? */
196
+ export declare function isEnumeratingBackend(backend: CardanoBackend): backend is EnumeratingBackend;
251
197
  //# sourceMappingURL=cardano-backend.d.ts.map
@@ -2,12 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isEvaluatingBackend = isEvaluatingBackend;
4
4
  exports.isChainSyncBackend = isChainSyncBackend;
5
+ exports.isLedgerStateBackend = isLedgerStateBackend;
5
6
  exports.isPaginatingBackend = isPaginatingBackend;
6
- /**
7
- * Type guard to check if a backend supports transaction evaluation
8
- * @param backend - The backend to check
9
- * @returns true if the backend supports evaluateTransaction
10
- */
7
+ exports.isEpochStateBackend = isEpochStateBackend;
8
+ exports.isEnumeratingBackend = isEnumeratingBackend;
9
+ /** Type guard: does this backend support transaction evaluation? */
11
10
  function isEvaluatingBackend(backend) {
12
11
  return typeof backend.evaluateTransaction === 'function';
13
12
  }
@@ -15,6 +14,9 @@ function isEvaluatingBackend(backend) {
15
14
  function isChainSyncBackend(backend) {
16
15
  return typeof backend.openChainSync === 'function';
17
16
  }
17
+ function isLedgerStateBackend(backend) {
18
+ return typeof backend.queryUtxoSetAt === 'function';
19
+ }
18
20
  /** Type guard: can this backend be walked forward by pagination? */
19
21
  function isPaginatingBackend(backend) {
20
22
  const b = backend;
@@ -22,4 +24,16 @@ function isPaginatingBackend(backend) {
22
24
  && typeof b.getNextBlocks === 'function'
23
25
  && typeof b.getBlockTransactions === 'function';
24
26
  }
27
+ /** Type guard: can this backend read epoch state at a block? */
28
+ function isEpochStateBackend(backend) {
29
+ return typeof backend.epochStateAt === 'function';
30
+ }
31
+ /** Type guard: can this backend enumerate pools and DReps? */
32
+ function isEnumeratingBackend(backend) {
33
+ const b = backend;
34
+ return typeof b.getPoolIds === 'function'
35
+ && typeof b.getPools === 'function'
36
+ && typeof b.getDrepIds === 'function'
37
+ && typeof b.getDreps === 'function';
38
+ }
25
39
  //# sourceMappingURL=cardano-backend.js.map
@@ -1,37 +1,87 @@
1
- import { CardanoBackend, PaginatingBackend } from './cardano-backend';
2
- import { Transaction, BlockData, Address, UTxO, NetworkInformation, EpochData, MetadataLabelTx, PoolData, DrepData, AccountData, AssetInfo, AssetHistoryEntry, LedgerProtocolParameters } from '../../utils/types';
1
+ import { CardanoBackend, PaginatingBackend, EnumeratingBackend } from './cardano-backend';
2
+ import { Transaction, BlockData, Address, UTxO, NetworkInformation, EpochData, MetadataLabelTx, PoolData, DrepData, AccountData, AssetInfo, AssetHistoryEntry, LedgerProtocolParameters, TxCertificate } from '../../utils/types';
3
3
  import { Network } from '../cardano-client';
4
- /**
5
- * KoiosBackend Implementation for CardanoBackend Interface
6
- * Implements the CardanoBackend interface using Koios API with Axios
7
- */
8
- export declare class KoiosBackend implements CardanoBackend, PaginatingBackend {
9
- readonly name = "koios";
10
- private api;
11
- private network;
4
+ /** Shape of a Koios tx-in/tx-out row from /tx_info */
5
+ interface KoiosTxIO {
6
+ address?: string;
7
+ payment_addr?: {
8
+ bech32?: string;
9
+ };
10
+ tx_hash: string;
11
+ tx_index: number;
12
+ value: string;
13
+ datum_hash?: string | null;
14
+ inline_datum?: unknown;
15
+ reference_script?: unknown;
16
+ asset_list?: Array<{
17
+ policy_id: string;
18
+ asset_name: string;
19
+ quantity: string;
20
+ }>;
21
+ }
22
+ /** Shape of a Koios /tx_info response row */
23
+ interface KoiosTxInfo {
24
+ tx_hash: string;
25
+ block_hash: string;
26
+ block_height: number | string;
27
+ tx_timestamp?: number;
28
+ block_time?: number;
29
+ absolute_slot?: number;
30
+ slot_no?: number;
31
+ tx_block_index?: number;
32
+ fee?: string;
33
+ deposit?: string;
34
+ tx_size: number;
35
+ metadata?: Record<string, unknown> | null;
36
+ inputs: KoiosTxIO[];
37
+ outputs: KoiosTxIO[];
38
+ /** False when the script phase failed (collateral consumed, regular ins/outs not applied). Absent on older Koios. */
39
+ valid_contract?: boolean | null;
40
+ collateral_inputs?: KoiosTxIO[] | null;
41
+ /** Live Koios returns ONE object here (the spec says array); both shapes are accepted. */
42
+ collateral_output?: KoiosTxIO | KoiosTxIO[] | null;
43
+ reference_inputs?: KoiosTxIO[] | null;
12
44
  /**
13
- * Constructor
45
+ * Net mint/burn (`_assets: true`), quantity signed — negative is a burn. Absent on older
46
+ * Koios; the indexer then derives the delta from inputs/outputs.
14
47
  */
15
- constructor(network: Network, timeoutMs: number, apiKey?: string);
48
+ assets_minted?: Array<{
49
+ policy_id?: string;
50
+ asset_name?: string | null;
51
+ quantity?: string | number;
52
+ }> | null;
53
+ /** `_withdrawals: true` only (crawler batch path); null/absent otherwise. */
54
+ withdrawals?: Array<{
55
+ amount?: string | number;
56
+ stake_addr?: string;
57
+ }> | null;
16
58
  /**
17
- * Initialize the backend
59
+ * `_certs: true` only (crawler batch path). `type` is Koios' own vocabulary
60
+ * (stake_registration, pool_delegation, …); `info` carries per-type fields.
18
61
  */
62
+ certificates?: Array<{
63
+ index?: number | null;
64
+ type?: string;
65
+ info?: Record<string, unknown> | null;
66
+ }> | null;
67
+ }
68
+ /** CardanoBackend implementation on the Koios REST API (Axios). */
69
+ export declare class KoiosBackend implements CardanoBackend, PaginatingBackend, EnumeratingBackend {
70
+ readonly name = "koios";
71
+ private api;
72
+ private network;
73
+ constructor(network: Network, timeoutMs: number, apiKey?: string);
74
+ /** Probe /tip to verify connectivity. */
19
75
  init(): Promise<boolean>;
20
76
  /**
21
- * Retry a Koios API call up to 3 times with exponential backoff if the
22
- * result is an empty array. Koios sometimes returns [] transiently for
23
- * valid queries — a single retry is not always sufficient for historical
24
- * epoch lookups, so we retry with increasing delays (500 → 1000 → 2000 ms).
77
+ * Retry (500 → 1000 → 2000 ms) when Koios transiently returns [] for a valid query.
78
+ * Only non-emptiness is checked here; rows keep the caller's element type.
25
79
  */
26
80
  private fetchWithRetryOnEmpty;
27
81
  /**
28
- * Koios runs several load-balanced grest instances and they are occasionally
29
- * version-skewed: some return HTTP 400 with Postgres error 42804 ("structure
30
- * of query does not match function result type", e.g. `out_sum_lovelace`
31
- * word128 vs numeric on /epoch_info) while healthy instances serve the
32
- * IDENTICAL request fine. The same request therefore flips 200/400 between
33
- * calls. Retrying a few times lands on a healthy instance. Scoped strictly to
34
- * the 42804 type-skew error so genuine 400s (bad params) still fail fast.
82
+ * Retry on Postgres 42804 ("structure of query does not match function result type"):
83
+ * version-skewed Koios instances behind the load balancer return it for a request that
84
+ * healthy instances serve fine. Other 400s still fail fast.
35
85
  */
36
86
  private getWithRetryOn42804;
37
87
  /**
@@ -71,11 +121,8 @@ export declare class KoiosBackend implements CardanoBackend, PaginatingBackend {
71
121
  */
72
122
  getAddressUtxos(address: string): Promise<UTxO[]>;
73
123
  /**
74
- * Get UTxOs by payment credential. Returns UTxOs across all bech32 addresses
75
- * sharing the given 28-byte payment credential (key hash or script hash).
76
- * Native Koios endpoint — single round-trip with inline-datum hydration.
124
+ * UTxOs across all bech32 addresses sharing a payment credential (native Koios endpoint).
77
125
  * @param credHash 28-byte payment credential as 56-char lowercase hex
78
- * @returns {Promise<UTxO[]>} list of UTxOs across all bech32 forms
79
126
  */
80
127
  getCredentialUtxos(credHash: string): Promise<UTxO[]>;
81
128
  /**
@@ -95,23 +142,17 @@ export declare class KoiosBackend implements CardanoBackend, PaginatingBackend {
95
142
  * @returns {Promise<PoolData>} pool data
96
143
  */
97
144
  getPool(poolId: string): Promise<PoolData>;
145
+ /** Map one Koios /pool_info row to the canonical PoolData. */
146
+ private _mapKoiosPool;
98
147
  /**
99
- * Get Asset Info (supply, mint history, CIP-25 + CIP-26 metadata).
100
- * Koios's `asset_info` returns total_supply, mint/burn counts split,
101
- * minting tx + creation_time, and both on-chain and registry metadata.
148
+ * Asset info from Koios `asset_info`: supply, mint/burn counts, minting tx, CIP-25 + CIP-26 metadata.
102
149
  * @param unit policyId + assetNameHex (concatenated hex)
103
- * @returns {Promise<AssetInfo>} canonical asset info
104
150
  */
105
151
  getAssetInfo(unit: string): Promise<AssetInfo>;
106
152
  /**
107
- * Get latest mint/burn events for an asset.
108
- * Koios's `asset_history` returns minting_txs[{ tx_hash, block_time, quantity }]
109
- * with `quantity` SIGNED (negative = burn). Action is derived from sign;
110
- * the canonical `quantity` field stores absolute value.
111
- * @param unit policyId + assetNameHex (concatenated hex)
112
- * @param limit max number of events (default 100). Note: Koios returns ALL events;
113
- * limit is applied client-side after sort-by-block_time desc.
114
- * @returns {Promise<AssetHistoryEntry[]>} list of mint/burn events (most recent first)
153
+ * Latest mint/burn events. Koios `asset_history` returns ALL events with `quantity` SIGNED
154
+ * (negative = burn): action derives from the sign, `quantity` stores the absolute value,
155
+ * `limit` is applied client-side after sorting by block_time desc.
115
156
  */
116
157
  getAssetHistory(unit: string, limit?: number): Promise<AssetHistoryEntry[]>;
117
158
  /**
@@ -120,6 +161,8 @@ export declare class KoiosBackend implements CardanoBackend, PaginatingBackend {
120
161
  * @returns {Promise<DrepData>} drep data
121
162
  */
122
163
  getDrep(drepId: string): Promise<DrepData>;
164
+ /** Map one Koios /drep_info row to the canonical DrepData. */
165
+ private _mapKoiosDrep;
123
166
  /**
124
167
  * Get Account Data for specified stake address
125
168
  * @param accountId account id
@@ -166,17 +209,14 @@ export declare class KoiosBackend implements CardanoBackend, PaginatingBackend {
166
209
  * @returns {Promise<string[]>} most recent tx hashes
167
210
  */
168
211
  getAddressTransactionHashes(address: string, limit: number): Promise<string[]>;
169
- /**
170
- * Batch fetch multiple transactions by hash using Koios POST /tx_info.
171
- * Sends all hashes in one request (chunked at 100 per Koios limit).
172
- * @param txHashes array of transaction hashes
173
- * @returns {Promise<Map<string, Transaction>>} map of hash -> Transaction
174
- */
212
+ /** crawler.certificates: ask /tx_info for certificates + withdrawals on the crawl's batch call. */
213
+ private crawlCertificates;
214
+ configureCrawl(options: {
215
+ certificates: boolean;
216
+ }): void;
217
+ /** Batch fetch transactions via POST /tx_info, chunked at 100 hashes (Koios limit). */
175
218
  getTransactionsBatch(txHashes: string[]): Promise<Map<string, Transaction>>;
176
- /**
177
- * Map a Koios /block_info response object to our BlockData (same shape getBlock
178
- * maps inline; kept private to avoid touching getBlock).
179
- */
219
+ /** Map a Koios /block_info row to BlockData. */
180
220
  private mapKoiosBlockInfo;
181
221
  /**
182
222
  * Get a block by its height via the PostgREST-filtered /blocks list, then resolve
@@ -184,22 +224,48 @@ export declare class KoiosBackend implements CardanoBackend, PaginatingBackend {
184
224
  */
185
225
  getBlockByHeight(height: number): Promise<BlockData>;
186
226
  /**
187
- * Get up to `count` blocks following `afterHash`, in ascending chain order.
188
- * Koios has no "next after hash" endpoint, so we list blocks above the anchor height
189
- * (PostgREST gt + order + limit), then batch /block_info. When the caller already
190
- * knows the anchor height (the crawler's cursor), the hash→height resolution
191
- * round-trip is skipped entirely.
227
+ * Up to `count` blocks after `afterHash`, ascending. Koios has no "next after hash" endpoint:
228
+ * list blocks above the anchor height (PostgREST gt + order + limit), then batch /block_info.
229
+ * A known `afterHeight` skips the hash→height round-trip.
192
230
  */
193
231
  getNextBlocks(afterHash: string, count: number, afterHeight?: number): Promise<BlockData[]>;
232
+ /** Rows per page when listing ids (PostgREST caps a response at 1000 rows). */
233
+ private static readonly LIST_PAGE_SIZE;
234
+ /** Ids resolved per /pool_info / /drep_info request. */
235
+ private static readonly INFO_BATCH_SIZE;
236
+ /** Page cap — 500 pages is 500 000 ids, far beyond any real pool or DRep set. */
237
+ private static readonly LIST_MAX_PAGES;
194
238
  /**
195
- * Get the full transaction list of a block in block order via /block_txs → /tx_info
196
- * batch. Handles both the current flattened shape ({tx_hash} per row) and the older
197
- * {tx_hashes:[...]} shape defensively.
239
+ * Page through a PostgREST list endpoint and collect one id column. Stops on the first
240
+ * short page, so a complete set costs exactly ceil(n / 1000) + 1 requests.
198
241
  */
199
- getBlockTransactions(blockHash: string): Promise<Transaction[]>;
242
+ private listAllIds;
243
+ /**
244
+ * All stake-pool ids known to Koios (bech32), including retired ones — a snapshot that
245
+ * silently dropped retiring pools would misreport the epoch's pool set.
246
+ */
247
+ getPoolIds(): Promise<string[]>;
248
+ /**
249
+ * Resolve pool ids in batches. Ids Koios does not return are omitted rather than
250
+ * substituted with empty rows — a missing pool is better than an invented one.
251
+ */
252
+ getPools(poolIds: string[]): Promise<PoolData[]>;
253
+ /** All DRep ids known to Koios (bech32). */
254
+ getDrepIds(): Promise<string[]>;
255
+ /** Resolve DRep ids in batches; unknown ids are omitted (see getPools). */
256
+ getDreps(drepIds: string[]): Promise<DrepData[]>;
200
257
  /**
201
- * Map a Koios /tx_info response object to the normalized Transaction type.
258
+ * Full transaction list of a block in block order via /block_txs → /tx_info batch.
259
+ * Accepts both the flattened ({tx_hash} per row) and the {tx_hashes:[...]} shape.
202
260
  */
261
+ getBlockTransactions(blockHash: string): Promise<Transaction[]>;
262
+ /** Map a Koios /tx_info row to the normalized Transaction (ledger view, see ledgerView). */
203
263
  private _mapKoiosTx;
204
264
  }
265
+ /**
266
+ * Normalize Koios `/tx_info` certificates (`_certs: true`). Field names inside `info` differ
267
+ * per type (`retiring_epoch` is spelled `retiring epoch` in current Koios), so every alias is read.
268
+ */
269
+ export declare function mapKoiosCertificates(certs: NonNullable<KoiosTxInfo['certificates']>): TxCertificate[];
270
+ export {};
205
271
  //# sourceMappingURL=koios-backend.d.ts.map