@odatano/core 2.0.0-rc.21 → 2.0.0-rc.24

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 (45) hide show
  1. package/@cds-models/CardanoBackendService/index.d.ts +357 -0
  2. package/@cds-models/CardanoBackendService/index.js +40 -0
  3. package/@cds-models/CardanoIndexerService/index.d.ts +18 -0
  4. package/@cds-models/CardanoIndexerService/index.js +3 -0
  5. package/@cds-models/CardanoODataService/index.d.ts +37 -0
  6. package/@cds-models/CardanoODataService/index.js +3 -0
  7. package/@cds-models/odatano/cardano/index.d.ts +37 -0
  8. package/@cds-models/odatano/cardano/index.js +3 -0
  9. package/db/schema.cds +2226 -2133
  10. package/package.json +182 -181
  11. package/srv/blockchain/backends/cardano-backend.d.ts +23 -0
  12. package/srv/blockchain/backends/cardano-backend.js +5 -0
  13. package/srv/blockchain/backends/odatano-backend.d.ts +59 -0
  14. package/srv/blockchain/backends/odatano-backend.js +154 -0
  15. package/srv/blockchain/backends/ogmios-backend.d.ts +92 -9
  16. package/srv/blockchain/backends/ogmios-backend.js +164 -32
  17. package/srv/blockchain/cardano-client.d.ts +19 -5
  18. package/srv/blockchain/cardano-client.js +53 -12
  19. package/srv/blockchain/cardano-indexer.d.ts +100 -4
  20. package/srv/blockchain/cardano-indexer.js +466 -23
  21. package/srv/blockchain/cardano-tx-builder.js +2 -2
  22. package/srv/blockchain/crawler/crawler.d.ts +20 -5
  23. package/srv/blockchain/crawler/crawler.js +78 -15
  24. package/srv/blockchain/crawler/utxo-set-import.js +3 -0
  25. package/srv/blockchain/ledger-state.d.ts +6 -0
  26. package/srv/blockchain/ledger-state.js +29 -0
  27. package/srv/blockchain/stored-chain.d.ts +30 -0
  28. package/srv/blockchain/stored-chain.js +208 -0
  29. package/srv/cardano-backend-service.cds +52 -0
  30. package/srv/cardano-backend-service.d.ts +2 -0
  31. package/srv/cardano-backend-service.js +217 -0
  32. package/srv/cardano-indexer-service.cds +176 -164
  33. package/srv/cardano-indexer-service.js +30 -0
  34. package/srv/cardano-service.cds +6 -1
  35. package/srv/cardano-service.js +5 -2
  36. package/srv/server.js +19 -2
  37. package/srv/utils/agent-grants.js +7 -0
  38. package/srv/utils/const.d.ts +4 -0
  39. package/srv/utils/const.js +4 -3
  40. package/srv/utils/db-indexes.js +1 -0
  41. package/srv/utils/errors.d.ts +8 -0
  42. package/srv/utils/errors.js +14 -1
  43. package/srv/utils/mappers.d.ts +19 -2
  44. package/srv/utils/mappers.js +25 -7
  45. package/srv/utils/types.d.ts +8 -1
@@ -241,8 +241,8 @@ module.exports = (srv) => {
241
241
  return Array.from(seen.values());
242
242
  });
243
243
  });
244
- // GetUTxOsByCredential — Koios-only, always-fresh credential-keyed UTxO query
245
- // (dApp state reads need current data). ProviderUnavailableError without Koios.
244
+ // GetUTxOsByCredential — always-fresh credential-keyed UTxO query (dApp state reads need current
245
+ // data). Crawled UTxO set + node first, else Koios; ProviderUnavailableError without either.
246
246
  srv.on('GetUTxOsByCredential', async (req) => {
247
247
  const { credential } = req.data;
248
248
  if (!credential)
@@ -315,6 +315,9 @@ module.exports = (srv) => {
315
315
  (0, errors_1.rejectInvalid)(req, 'GetLatestTransactionsByAddress', 'Invalid bech32 address format', 'address');
316
316
  const txLimit = Math.min(Math.max(limit || 10, 1), 100);
317
317
  return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
318
+ // The crawled UTxO set is current; the cached rows may miss the newest transactions.
319
+ if (await indexer().ledgerCoverageActive(db))
320
+ return indexer().indexAddressTransactions(db, address, txLimit);
318
321
  const existing = await db.run(SELECT.from(AddressTransactions)
319
322
  .where({ address_address: address })
320
323
  .orderBy('blockTime desc')
package/srv/server.js CHANGED
@@ -36,7 +36,7 @@ const agent_grants_config_1 = require("./utils/agent-grants-config");
36
36
  const process_1 = require("process");
37
37
  const logger = cds_1.default.log('ODATANO');
38
38
  const VALID_NETWORKS = ['mainnet', 'preview', 'preprod'];
39
- const VALID_BACKENDS = ['blockfrost', 'koios', 'ogmios'];
39
+ const VALID_BACKENDS = ['blockfrost', 'koios', 'ogmios', 'odatano'];
40
40
  const CRAWLER_LIMITS = {
41
41
  batchSize: { min: 1, max: 100 },
42
42
  confirmationDepth: { min: 0, max: 2160 },
@@ -192,6 +192,8 @@ async function createTestContext(backends, _txBuilderName = 'buildooor', protoco
192
192
  blockfrostCustomBackend: process_1.env.BLOCKFROST_CUSTOM_BACKEND || undefined,
193
193
  koiosApiKey: process_1.env.KOIOS_API_KEY || '',
194
194
  ogmiosUrl: process_1.env.OGMIOS_URL || '',
195
+ odatanoUrl: process_1.env.ODATANO_URL || undefined,
196
+ odatanoApiKey: process_1.env.ODATANO_API_KEY || undefined,
195
197
  transactionBuilders: ['buildooor'],
196
198
  primaryTimeoutMs: Number(process_1.env.PRIMARY_TIMEOUT_MS) || 30000, // || intentional: NaN (missing env var) falls back to default
197
199
  fallbackTimeoutMs: Number(process_1.env.FALLBACK_TIMEOUT_MS) || 60000,
@@ -270,6 +272,17 @@ function loadConfigFromEnv() {
270
272
  }
271
273
  const koiosApiKey = cdsConfig.koiosApiKey || process_1.env.KOIOS_API_KEY || '';
272
274
  const ogmiosUrl = cdsConfig.ogmiosUrl || process_1.env.OGMIOS_URL || '';
275
+ const odatanoUrl = cdsConfig.odatanoUrl || process_1.env.ODATANO_URL || '';
276
+ const odatanoApiKey = cdsConfig.odatanoApiKey || process_1.env.ODATANO_API_KEY || '';
277
+ if (odatanoUrl && !/^https?:\/\//i.test(odatanoUrl)) {
278
+ throw new errors_1.ConfigError(`Invalid ODATANO_URL "${odatanoUrl}". Must be an http(s) URL (e.g. https://api.preprod.odatano.dev).`);
279
+ }
280
+ if (backends.includes('odatano') && !odatanoUrl && network === 'mainnet') {
281
+ throw new errors_1.ConfigError('ODATANO_URL is required for the odatano backend on mainnet.');
282
+ }
283
+ if (backends.includes('odatano') && !odatanoApiKey) {
284
+ logger.warn('ODATANO_API_KEY is not set but odatano is listed in BACKENDS; the public API refuses calls without a key');
285
+ }
273
286
  if (backends.includes('blockfrost') && !blockfrostApiKey && !blockfrostCustomBackend) {
274
287
  logger.warn('Neither BLOCKFROST_API_KEY nor BLOCKFROST_CUSTOM_BACKEND is set but blockfrost is listed in BACKENDS');
275
288
  }
@@ -286,6 +299,8 @@ function loadConfigFromEnv() {
286
299
  blockfrostCustomBackend: blockfrostCustomBackend || undefined,
287
300
  koiosApiKey,
288
301
  ogmiosUrl,
302
+ odatanoUrl: odatanoUrl || undefined,
303
+ odatanoApiKey: odatanoApiKey || undefined,
289
304
  transactionBuilders: txBuilders,
290
305
  primaryTimeoutMs: Number(primaryTimeout) || 30000, // || intentional: NaN (missing config) falls back to default
291
306
  fallbackTimeoutMs: Number(fallbackTimeout) || 60000,
@@ -376,9 +391,11 @@ function loadCrawlerConfigFromEnv() {
376
391
  const certificates = crawlerBoolean(c.certificates ?? process_1.env.CRAWLER_CERTIFICATES, 'CRAWLER_CERTIFICATES', false);
377
392
  // UTxO set: opt-in, inert until a snapshot has been imported (importUtxoSet).
378
393
  const utxoSet = crawlerBoolean(c.utxoSet ?? process_1.env.CRAWLER_UTXO_SET, 'CRAWLER_UTXO_SET', false);
394
+ // Crawled chain answers misses with 404 instead of a provider call.
395
+ const authoritative = crawlerBoolean(c.authoritative ?? process_1.env.CRAWLER_AUTHORITATIVE, 'CRAWLER_AUTHORITATIVE', false);
379
396
  return {
380
397
  enabled, startSlot, startBlockHash, startHeight, source, batchSize, confirmationDepth, pollIntervalMs,
381
- assetHistory, assetCatalogue, assetEnrichRate, epochSnapshots, certificates, utxoSet,
398
+ assetHistory, assetCatalogue, assetEnrichRate, epochSnapshots, certificates, utxoSet, authoritative,
382
399
  };
383
400
  }
384
401
  /** Start the crawler if enabled and the app context is ready. Never throws; idempotent. */
@@ -66,6 +66,7 @@ exports.AGENT_SERVICE_NAMES = [
66
66
  'CardanoWorkerService',
67
67
  'CardanoIndexerService',
68
68
  'CardanoAgentService',
69
+ 'CardanoBackendService',
69
70
  ];
70
71
  /**
71
72
  * Actions an operator may put on a grant's allow list; each call costs one budget unit. Anything else
@@ -112,6 +113,12 @@ exports.AGENT_ALWAYS_ALLOWED_EVENTS = new Set([
112
113
  'GetJobStatus', 'GetWorkerStatus', 'getStatus', 'getLiveness',
113
114
  // CardanoAgentService: the token's own grant (GetGrantUsage is narrowed to it in enforceAgentGrant)
114
115
  'GetGrantStatus', 'GetGrantUsage',
116
+ // CardanoBackendService: reads and evaluation for another ODATANO instance (submit is allow-listed)
117
+ 'GetTransaction', 'GetTransactionsBatch', 'GetTransactionMetadata', 'GetBlock', 'GetBlockByHeight',
118
+ 'GetNextBlocks', 'GetBlockTransactions', 'GetCurrentSlot', 'GetEpoch', 'GetAddress', 'GetAddressUtxos',
119
+ 'GetAddressTransactions', 'GetAddressTransactionHashes', 'GetCredentialUtxos', 'IsUtxoUnspent',
120
+ 'GetUnspentOutputs', 'GetAccount', 'GetPool', 'GetPoolIds', 'GetPools', 'GetDrep', 'GetDrepIds', 'GetDreps',
121
+ 'GetProtocolParameters', 'EvaluateTransaction',
115
122
  ]);
116
123
  /** Mirrors WalletJobKind in db/types.cds; kept literal so this module stays free of cds-models. */
117
124
  exports.AGENT_JOB_KINDS = ['simpleAda', 'metadata', 'multiAsset', 'mint', 'plutusSpend', 'submitSigned'];
@@ -9,22 +9,26 @@ export declare const CARDANO_DEFAULTS: {
9
9
  * Per-network epoch geometry anchored at the Shelley transition:
10
10
  * `epochStartSlot(epoch) = shelleyStartSlot + (epoch - shelleyStartEpoch) * slotsPerEpoch`.
11
11
  * Preview epochs are 1 day; mainnet/preprod are offset by their Byron era.
12
+ * `securityParam` (k): blocks the node keeps volatile, i.e. how far back ledger state can be acquired.
12
13
  */
13
14
  export declare const EPOCH_CONFIG_BY_NETWORK: {
14
15
  readonly mainnet: {
15
16
  readonly shelleyStartEpoch: 208;
16
17
  readonly shelleyStartSlot: 4492800;
17
18
  readonly slotsPerEpoch: 432000;
19
+ readonly securityParam: 2160;
18
20
  };
19
21
  readonly preprod: {
20
22
  readonly shelleyStartEpoch: 4;
21
23
  readonly shelleyStartSlot: 86400;
22
24
  readonly slotsPerEpoch: 432000;
25
+ readonly securityParam: 2160;
23
26
  };
24
27
  readonly preview: {
25
28
  readonly shelleyStartEpoch: 0;
26
29
  readonly shelleyStartSlot: 0;
27
30
  readonly slotsPerEpoch: 86400;
31
+ readonly securityParam: 432;
28
32
  };
29
33
  };
30
34
  /** Default Plutus execution units when dynamic evaluation is not available */
@@ -12,11 +12,12 @@ exports.CARDANO_DEFAULTS = {
12
12
  * Per-network epoch geometry anchored at the Shelley transition:
13
13
  * `epochStartSlot(epoch) = shelleyStartSlot + (epoch - shelleyStartEpoch) * slotsPerEpoch`.
14
14
  * Preview epochs are 1 day; mainnet/preprod are offset by their Byron era.
15
+ * `securityParam` (k): blocks the node keeps volatile, i.e. how far back ledger state can be acquired.
15
16
  */
16
17
  exports.EPOCH_CONFIG_BY_NETWORK = {
17
- mainnet: { shelleyStartEpoch: 208, shelleyStartSlot: 4_492_800, slotsPerEpoch: 432_000 },
18
- preprod: { shelleyStartEpoch: 4, shelleyStartSlot: 86_400, slotsPerEpoch: 432_000 },
19
- preview: { shelleyStartEpoch: 0, shelleyStartSlot: 0, slotsPerEpoch: 86_400 },
18
+ mainnet: { shelleyStartEpoch: 208, shelleyStartSlot: 4_492_800, slotsPerEpoch: 432_000, securityParam: 2160 },
19
+ preprod: { shelleyStartEpoch: 4, shelleyStartSlot: 86_400, slotsPerEpoch: 432_000, securityParam: 2160 },
20
+ preview: { shelleyStartEpoch: 0, shelleyStartSlot: 0, slotsPerEpoch: 86_400, securityParam: 432 },
20
21
  };
21
22
  /** Default Plutus execution units when dynamic evaluation is not available */
22
23
  exports.DEFAULT_EXECUTION_UNITS = {
@@ -55,6 +55,7 @@ exports.DB_INDEXES = Object.freeze([
55
55
  { name: 'odatano_cardano_ledgerutxos_address', table: 'odatano_cardano_LedgerUTxOs', columns: 'address, spentTxHash' },
56
56
  { name: 'odatano_cardano_ledgerutxos_spent', table: 'odatano_cardano_LedgerUTxOs', columns: 'spentTxHash' },
57
57
  { name: 'odatano_cardano_ledgeraddresses_stake', table: 'odatano_cardano_LedgerAddresses', columns: 'stakeAddress' },
58
+ { name: 'odatano_cardano_ledgeraddresses_paycred', table: 'odatano_cardano_LedgerAddresses', columns: 'paymentCredential' },
58
59
  { name: 'odatano_cardano_ledgerutxoassets_unit', table: 'odatano_cardano_LedgerUTxOAssets', columns: 'unit' },
59
60
  { name: 'odatano_cardano_ledgeraddressassets_unit', table: 'odatano_cardano_LedgerAddressAssets', columns: 'unit' },
60
61
  ]);
@@ -101,6 +101,14 @@ export declare class ConfigError extends Error {
101
101
  * Ogmios chain-sync frame that could not be parsed. Names the block (when readable from the raw
102
102
  * text) so the crawler can fetch that one block through the paginating backend instead.
103
103
  */
104
+ /** The Ogmios chain-sync socket closed without being asked to (server-side failure or restart). */
105
+ export declare class ChainSyncClosedError extends ProviderUnavailableError {
106
+ }
107
+ /** Chain-sync closed before delivering block `height`; the crawler fetches it over pagination. */
108
+ export declare class ChainSyncStalledError extends BackendError {
109
+ readonly height: number;
110
+ constructor(height: number, reason: string);
111
+ }
104
112
  export declare class ChainSyncFrameError extends BackendError {
105
113
  readonly height: number | null;
106
114
  readonly id: string | null;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AllBackendsInitFailedError = exports.BackendInitError = exports.ChainSyncFrameError = exports.ConfigError = exports.HsmError = exports.AllBackendsFailedError = exports.RateLimitError = exports.ProviderUnavailableError = exports.MixedAssetsError = exports.InsufficientFundsError = exports.TransactionAlreadySubmittedError = exports.ScriptValidationError = exports.TransactionValidationError = exports.NotFoundError = exports.BackendError = void 0;
3
+ exports.AllBackendsInitFailedError = exports.BackendInitError = exports.ChainSyncFrameError = exports.ChainSyncStalledError = exports.ChainSyncClosedError = exports.ConfigError = exports.HsmError = exports.AllBackendsFailedError = exports.RateLimitError = exports.ProviderUnavailableError = exports.MixedAssetsError = exports.InsufficientFundsError = exports.TransactionAlreadySubmittedError = exports.ScriptValidationError = exports.TransactionValidationError = exports.NotFoundError = exports.BackendError = void 0;
4
4
  exports.isNotFoundOnAllBackends = isNotFoundOnAllBackends;
5
5
  exports.isPostgrestServerErrorCode = isPostgrestServerErrorCode;
6
6
  exports.getErrorStatus = getErrorStatus;
@@ -297,6 +297,19 @@ exports.ConfigError = ConfigError;
297
297
  * Ogmios chain-sync frame that could not be parsed. Names the block (when readable from the raw
298
298
  * text) so the crawler can fetch that one block through the paginating backend instead.
299
299
  */
300
+ /** The Ogmios chain-sync socket closed without being asked to (server-side failure or restart). */
301
+ class ChainSyncClosedError extends ProviderUnavailableError {
302
+ }
303
+ exports.ChainSyncClosedError = ChainSyncClosedError;
304
+ /** Chain-sync closed before delivering block `height`; the crawler fetches it over pagination. */
305
+ class ChainSyncStalledError extends BackendError {
306
+ height;
307
+ constructor(height, reason) {
308
+ super(`Ogmios chain-sync closed before delivering block ${height}: ${reason}`, 503, error_codes_1.ERROR_CODES.PROVIDER_UNAVAILABLE, 'ogmios');
309
+ this.height = height;
310
+ }
311
+ }
312
+ exports.ChainSyncStalledError = ChainSyncStalledError;
300
313
  class ChainSyncFrameError extends BackendError {
301
314
  height;
302
315
  id;
@@ -44,16 +44,21 @@ export declare function mapTransactionMetadata(providerLabels: MetadataLabelTxPr
44
44
  * @returns the key, or null when the label is not a non-negative integer
45
45
  */
46
46
  export declare function metadataIdFor(label: string | number): number | string | null;
47
+ /** Where an epoch snapshot came from; `hash` is the block the ledger state was read at (Ogmios only). */
48
+ export interface SnapshotOrigin {
49
+ source: 'ogmios' | 'koios';
50
+ hash?: string | null;
51
+ }
47
52
  /** Pool observation at an epoch boundary to a non-temporal PoolEpochSnapshotRow dated by (epoch, snapshotSlot). */
48
53
  export declare function mapPoolSnapshot(providerPoolData: PoolProviderData, epoch: number, at: {
49
54
  slot: number;
50
55
  time: number;
51
- }): PoolEpochSnapshotRow;
56
+ }, origin?: SnapshotOrigin): PoolEpochSnapshotRow;
52
57
  /** DRep observation at an epoch boundary to a non-temporal DrepEpochSnapshotRow. */
53
58
  export declare function mapDrepSnapshot(providerDrepData: DrepProviderData, epoch: number, at: {
54
59
  slot: number;
55
60
  time: number;
56
- }): DrepEpochSnapshotRow;
61
+ }, origin?: SnapshotOrigin): DrepEpochSnapshotRow;
57
62
  /** Provider pool to a temporal PoolRow valid for `max_age` ms. */
58
63
  export declare function mapPool(providerPoolData: PoolProviderData, max_age: number): PoolRow;
59
64
  /** Canonical asset info to a temporal AssetRow valid for `max_age` ms; on-chain metadata is JSON-stringified. */
@@ -122,6 +127,8 @@ export interface DecodedAddress {
122
127
  isScript: boolean;
123
128
  /** Reward account (bech32) of a base address; null for every other type. */
124
129
  stakeAddress: string | null;
130
+ /** Payment key/script hash (hex) of a base, pointer or enterprise address; null otherwise. */
131
+ paymentCredential: string | null;
125
132
  /** Network nibble of the header (1 = mainnet, 0 = testnets); null when not a Shelley address. */
126
133
  networkId: number | null;
127
134
  }
@@ -132,4 +139,14 @@ export interface DecodedAddress {
132
139
  export declare function decodeShelleyAddress(address: string): DecodedAddress;
133
140
  /** DRep credential to CIP-129 DRep ID (29 bytes): header 0x22 key hash / 0x23 script hash. */
134
141
  export declare function credentialToDrepId(credentialHex: string, isScript: boolean): string;
142
+ /** Address balance from its UTxOs: lovelace first, then every native asset summed per unit. */
143
+ export declare function sumUtxoAmounts(utxos: Array<{
144
+ amount: Array<{
145
+ unit: string;
146
+ quantity: string;
147
+ }>;
148
+ }>): Array<{
149
+ unit: string;
150
+ quantity: string;
151
+ }>;
135
152
  //# sourceMappingURL=mappers.d.ts.map
@@ -45,6 +45,7 @@ exports.scriptHashToEnterpriseAddress = scriptHashToEnterpriseAddress;
45
45
  exports.credentialToStakeAddress = credentialToStakeAddress;
46
46
  exports.decodeShelleyAddress = decodeShelleyAddress;
47
47
  exports.credentialToDrepId = credentialToDrepId;
48
+ exports.sumUtxoAmounts = sumUtxoAmounts;
48
49
  const cds_1 = __importDefault(require("@sap/cds"));
49
50
  const node_util_1 = require("node:util");
50
51
  const blake2b_1 = __importDefault(require("blake2b"));
@@ -438,12 +439,14 @@ function metadataIdFor(label) {
438
439
  return safe ? Number(wrapped) : wrapped.toString();
439
440
  }
440
441
  /** Pool observation at an epoch boundary to a non-temporal PoolEpochSnapshotRow dated by (epoch, snapshotSlot). */
441
- function mapPoolSnapshot(providerPoolData, epoch, at) {
442
+ function mapPoolSnapshot(providerPoolData, epoch, at, origin = { source: 'koios' }) {
442
443
  return {
443
444
  poolId: providerPoolData.poolId,
444
445
  epoch,
445
446
  snapshotSlot: at.slot,
446
447
  snapshotTime: at.time,
448
+ snapshotHash: origin.hash ?? null,
449
+ source: origin.source,
447
450
  blocksMinted: providerPoolData.blocksMinted,
448
451
  blocksEpoch: providerPoolData.blocksEpoch,
449
452
  liveStake: providerPoolData.liveStake,
@@ -458,12 +461,17 @@ function mapPoolSnapshot(providerPoolData, epoch, at) {
458
461
  };
459
462
  }
460
463
  /** DRep observation at an epoch boundary to a non-temporal DrepEpochSnapshotRow. */
461
- function mapDrepSnapshot(providerDrepData, epoch, at) {
464
+ function mapDrepSnapshot(providerDrepData, epoch, at, origin = { source: 'koios' }) {
462
465
  return {
463
466
  drepId: providerDrepData.drepId,
464
467
  epoch,
465
468
  snapshotSlot: at.slot,
466
469
  snapshotTime: at.time,
470
+ snapshotHash: origin.hash ?? null,
471
+ source: origin.source,
472
+ deposit: providerDrepData.deposit ?? null,
473
+ expiresEpoch: providerDrepData.expiresEpoch ?? null,
474
+ delegatorCount: providerDrepData.delegatorCount ?? null,
467
475
  amount: providerDrepData.amount,
468
476
  hasScript: providerDrepData.hasScript,
469
477
  lastActiveEpoch: providerDrepData.lastActiveEpoch,
@@ -843,7 +851,7 @@ function credentialToStakeAddress(credentialHex, isScript, network) {
843
851
  * stake credential as a reward account. Byron (base58) and unparseable input yield `byron` / `unknown`.
844
852
  */
845
853
  function decodeShelleyAddress(address) {
846
- const none = { type: 'unknown', isScript: false, stakeAddress: null, networkId: null };
854
+ const none = { type: 'unknown', isScript: false, stakeAddress: null, paymentCredential: null, networkId: null };
847
855
  if (typeof address !== 'string' || !address.length)
848
856
  return none;
849
857
  let bytes;
@@ -863,6 +871,7 @@ function decodeShelleyAddress(address) {
863
871
  const type = header >> 4;
864
872
  const networkId = header & 0x0f;
865
873
  const net = networkId === 1 ? 'mainnet' : 'preview';
874
+ const paymentCredential = type <= 7 && bytes.length >= 29 ? bytes.subarray(1, 29).toString('hex') : null;
866
875
  switch (type) {
867
876
  case 0:
868
877
  case 1:
@@ -871,17 +880,17 @@ function decodeShelleyAddress(address) {
871
880
  const stakeAddress = bytes.length >= 57
872
881
  ? credentialToStakeAddress(bytes.subarray(29, 57).toString('hex'), type >= 2, net)
873
882
  : null;
874
- return { type: 'base', isScript: type === 1 || type === 3, stakeAddress, networkId };
883
+ return { type: 'base', isScript: type === 1 || type === 3, stakeAddress, paymentCredential, networkId };
875
884
  }
876
885
  case 4:
877
886
  case 5:
878
- return { type: 'pointer', isScript: type === 5, stakeAddress: null, networkId };
887
+ return { type: 'pointer', isScript: type === 5, stakeAddress: null, paymentCredential, networkId };
879
888
  case 6:
880
889
  case 7:
881
- return { type: 'enterprise', isScript: type === 7, stakeAddress: null, networkId };
890
+ return { type: 'enterprise', isScript: type === 7, stakeAddress: null, paymentCredential, networkId };
882
891
  case 14:
883
892
  case 15:
884
- return { type: 'reward', isScript: type === 15, stakeAddress: address, networkId };
893
+ return { type: 'reward', isScript: type === 15, stakeAddress: address, paymentCredential: null, networkId };
885
894
  default:
886
895
  return { ...none, networkId };
887
896
  }
@@ -897,4 +906,13 @@ function credentialToDrepId(credentialHex, isScript) {
897
906
  function fmt(code, ctx, msg) {
898
907
  return `[${code}] ${ctx}: ${msg}`;
899
908
  }
909
+ /** Address balance from its UTxOs: lovelace first, then every native asset summed per unit. */
910
+ function sumUtxoAmounts(utxos) {
911
+ const totals = new Map([['lovelace', 0n]]);
912
+ for (const u of utxos) {
913
+ for (const a of u.amount ?? [])
914
+ totals.set(a.unit, (totals.get(a.unit) ?? 0n) + BigInt(a.quantity || '0'));
915
+ }
916
+ return [...totals].map(([unit, q]) => ({ unit, quantity: q.toString() }));
917
+ }
900
918
  //# sourceMappingURL=mappers.js.map
@@ -199,7 +199,8 @@ export interface PoolData {
199
199
  liveSize: number;
200
200
  /** Fraction of the ideal (saturated) pool size, NOT percent: 0.7542 = 75.42 %. */
201
201
  liveSaturation: number;
202
- liveDelegators: number;
202
+ /** Null when the source cannot count delegators (Ogmios ledger state). */
203
+ liveDelegators: number | null;
203
204
  activeStake: string;
204
205
  activeSize: number;
205
206
  pledge: string;
@@ -216,6 +217,12 @@ export interface DrepData {
216
217
  lastActiveEpoch: number;
217
218
  retired: boolean;
218
219
  expired: boolean;
220
+ /** Registration deposit (lovelace); only set by sources that report it. */
221
+ deposit?: string | null;
222
+ /** Epoch the mandate runs out; only set by sources that report it. */
223
+ expiresEpoch?: number | null;
224
+ /** Stake credentials delegated to the DRep; only set by sources that report it. */
225
+ delegatorCount?: number | null;
219
226
  }
220
227
  /** Normalized native-asset metadata and supply; fields a backend does not expose are null. */
221
228
  export interface AssetInfo {