@xyo-network/xl1-protocol-sdk 1.17.0 → 1.17.1

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 (200) hide show
  1. package/dist/neutral/ChainServiceCollectionV2.d.ts +6 -29
  2. package/dist/neutral/ChainServiceCollectionV2.d.ts.map +1 -1
  3. package/dist/neutral/block/hydrate/flattenHydratedBlocks.d.ts +2 -3
  4. package/dist/neutral/block/hydrate/flattenHydratedBlocks.d.ts.map +1 -1
  5. package/dist/neutral/index.d.ts +2 -0
  6. package/dist/neutral/index.d.ts.map +1 -1
  7. package/dist/neutral/index.mjs +1455 -1124
  8. package/dist/neutral/index.mjs.map +1 -1
  9. package/dist/neutral/model/PayloadBundle/bundledPayloadToHydratedBlock.d.ts +4 -0
  10. package/dist/neutral/model/PayloadBundle/bundledPayloadToHydratedBlock.d.ts.map +1 -0
  11. package/dist/neutral/model/PayloadBundle/hydratedBlockToPayloadBundle.d.ts +4 -0
  12. package/dist/neutral/model/PayloadBundle/hydratedBlockToPayloadBundle.d.ts.map +1 -0
  13. package/dist/neutral/model/PayloadBundle/index.d.ts +2 -0
  14. package/dist/neutral/model/PayloadBundle/index.d.ts.map +1 -1
  15. package/dist/neutral/model/Qualified.d.ts +6 -0
  16. package/dist/neutral/model/Qualified.d.ts.map +1 -0
  17. package/dist/neutral/model/index.d.ts +1 -1
  18. package/dist/neutral/model/index.d.ts.map +1 -1
  19. package/dist/neutral/payloads/index.d.ts +0 -1
  20. package/dist/neutral/payloads/index.d.ts.map +1 -1
  21. package/dist/neutral/primitives/index.d.ts +1 -1
  22. package/dist/neutral/primitives/index.d.ts.map +1 -1
  23. package/dist/neutral/primitives/rewardFromBlockNumber.d.ts +3 -0
  24. package/dist/neutral/primitives/rewardFromBlockNumber.d.ts.map +1 -0
  25. package/dist/neutral/provider/XyoRunner.d.ts +5 -1
  26. package/dist/neutral/provider/XyoRunner.d.ts.map +1 -1
  27. package/dist/neutral/provider/viewer/XyoViewer.d.ts +7 -2
  28. package/dist/neutral/provider/viewer/XyoViewer.d.ts.map +1 -1
  29. package/dist/neutral/runners/Block.d.ts +8 -0
  30. package/dist/neutral/runners/Block.d.ts.map +1 -0
  31. package/dist/neutral/runners/Mempool.d.ts +9 -0
  32. package/dist/neutral/runners/Mempool.d.ts.map +1 -0
  33. package/dist/neutral/runners/index.d.ts +3 -0
  34. package/dist/neutral/runners/index.d.ts.map +1 -0
  35. package/dist/neutral/services/BlockProducerService.d.ts +2 -2
  36. package/dist/neutral/services/BlockProducerService.d.ts.map +1 -1
  37. package/dist/neutral/services/Chain/ChainService.d.ts +2 -3
  38. package/dist/neutral/services/Chain/ChainService.d.ts.map +1 -1
  39. package/dist/neutral/services/Chain/index.d.ts +0 -1
  40. package/dist/neutral/services/Chain/index.d.ts.map +1 -1
  41. package/dist/neutral/services/index.d.ts +0 -2
  42. package/dist/neutral/services/index.d.ts.map +1 -1
  43. package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts +7 -3
  44. package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts.map +1 -1
  45. package/dist/neutral/simple/block/SimpleBlockViewer.d.ts +9 -4
  46. package/dist/neutral/simple/block/SimpleBlockViewer.d.ts.map +1 -1
  47. package/dist/neutral/simple/blockReward/SimpleBlockRewardViewer.d.ts +16 -0
  48. package/dist/neutral/simple/blockReward/SimpleBlockRewardViewer.d.ts.map +1 -0
  49. package/dist/neutral/simple/blockReward/index.d.ts +2 -0
  50. package/dist/neutral/simple/blockReward/index.d.ts.map +1 -0
  51. package/dist/neutral/simple/chain/SimpleChainViewer.d.ts +12 -0
  52. package/dist/neutral/simple/chain/SimpleChainViewer.d.ts.map +1 -0
  53. package/dist/neutral/simple/chain/index.d.ts +2 -0
  54. package/dist/neutral/simple/chain/index.d.ts.map +1 -0
  55. package/dist/neutral/simple/index.d.ts +2 -0
  56. package/dist/neutral/simple/index.d.ts.map +1 -1
  57. package/dist/neutral/simple/mempool/SimpleMempoolRunner.d.ts +15 -0
  58. package/dist/neutral/simple/mempool/SimpleMempoolRunner.d.ts.map +1 -0
  59. package/dist/neutral/simple/mempool/SimpleMempoolViewer.d.ts +10 -4
  60. package/dist/neutral/simple/mempool/SimpleMempoolViewer.d.ts.map +1 -1
  61. package/dist/neutral/simple/mempool/index.d.ts +1 -0
  62. package/dist/neutral/simple/mempool/index.d.ts.map +1 -1
  63. package/dist/neutral/summary/index.d.ts +3 -0
  64. package/dist/neutral/summary/index.d.ts.map +1 -0
  65. package/dist/neutral/summary/model/BalancesStepSummary.d.ts.map +1 -0
  66. package/dist/neutral/summary/model/SchemasStepSummary.d.ts.map +1 -0
  67. package/dist/neutral/summary/model/StepSummary.d.ts.map +1 -0
  68. package/dist/neutral/summary/model/TransfersSummary.d.ts.map +1 -0
  69. package/dist/neutral/{payloads/summary → summary/model}/index.d.ts +1 -0
  70. package/dist/neutral/summary/model/index.d.ts.map +1 -0
  71. package/dist/neutral/{model → summary/model}/summary.d.ts +3 -4
  72. package/dist/neutral/summary/model/summary.d.ts.map +1 -0
  73. package/dist/neutral/{primitives/summary → summary/primitives}/balances/balancesStepSummaryFromRange.d.ts +1 -2
  74. package/dist/neutral/summary/primitives/balances/balancesStepSummaryFromRange.d.ts.map +1 -0
  75. package/dist/neutral/summary/primitives/balances/balancesSummary.d.ts +5 -0
  76. package/dist/neutral/summary/primitives/balances/balancesSummary.d.ts.map +1 -0
  77. package/dist/neutral/summary/primitives/balances/index.d.ts.map +1 -0
  78. package/dist/neutral/{primitives/summary → summary/primitives}/index.d.ts.map +1 -1
  79. package/dist/neutral/summary/primitives/schemas/index.d.ts.map +1 -0
  80. package/dist/neutral/{primitives/summary → summary/primitives}/schemas/schemasStepSummaryFromRange.d.ts +1 -2
  81. package/dist/neutral/summary/primitives/schemas/schemasStepSummaryFromRange.d.ts.map +1 -0
  82. package/dist/neutral/summary/primitives/schemas/schemasSummary.d.ts +5 -0
  83. package/dist/neutral/summary/primitives/schemas/schemasSummary.d.ts.map +1 -0
  84. package/dist/neutral/summary/primitives/transfers/index.d.ts.map +1 -0
  85. package/dist/neutral/{primitives/summary → summary/primitives}/transfers/transfersStepSummaryFromRange.d.ts +1 -2
  86. package/dist/neutral/summary/primitives/transfers/transfersStepSummaryFromRange.d.ts.map +1 -0
  87. package/dist/neutral/summary/primitives/transfers/transfersSummary.d.ts +6 -0
  88. package/dist/neutral/summary/primitives/transfers/transfersSummary.d.ts.map +1 -0
  89. package/dist/neutral/viewers/AccountBalance.d.ts +5 -2
  90. package/dist/neutral/viewers/AccountBalance.d.ts.map +1 -1
  91. package/dist/neutral/viewers/Block.d.ts +3 -0
  92. package/dist/neutral/viewers/Block.d.ts.map +1 -1
  93. package/dist/neutral/viewers/BlockReward.d.ts +8 -0
  94. package/dist/neutral/viewers/BlockReward.d.ts.map +1 -0
  95. package/dist/neutral/viewers/ChainStakeViewer.d.ts +6 -0
  96. package/dist/neutral/viewers/ChainStakeViewer.d.ts.map +1 -0
  97. package/dist/neutral/viewers/Mempool.d.ts +8 -1
  98. package/dist/neutral/viewers/Mempool.d.ts.map +1 -1
  99. package/dist/neutral/viewers/StakeIntent.d.ts +10 -0
  100. package/dist/neutral/viewers/StakeIntent.d.ts.map +1 -0
  101. package/dist/neutral/viewers/index.d.ts +2 -0
  102. package/dist/neutral/viewers/index.d.ts.map +1 -1
  103. package/package.json +18 -18
  104. package/src/ChainServiceCollectionV2.ts +9 -33
  105. package/src/block/hydrate/flattenHydratedBlocks.ts +2 -3
  106. package/src/index.ts +2 -1
  107. package/src/model/PayloadBundle/bundledPayloadToHydratedBlock.ts +14 -0
  108. package/src/model/PayloadBundle/hydratedBlockToPayloadBundle.ts +18 -0
  109. package/src/model/PayloadBundle/index.ts +2 -0
  110. package/src/model/Qualified.ts +9 -0
  111. package/src/model/index.ts +1 -1
  112. package/src/payloads/index.ts +0 -1
  113. package/src/primitives/index.ts +1 -1
  114. package/src/primitives/rewardFromBlockNumber.ts +25 -0
  115. package/src/provider/XyoRunner.ts +7 -1
  116. package/src/provider/viewer/XyoViewer.ts +13 -4
  117. package/src/runners/Block.ts +10 -0
  118. package/src/runners/Mempool.ts +9 -0
  119. package/src/runners/index.ts +2 -0
  120. package/src/services/BlockProducerService.ts +3 -2
  121. package/src/services/Chain/ChainService.ts +4 -3
  122. package/src/services/Chain/index.ts +0 -1
  123. package/src/services/index.ts +0 -2
  124. package/src/simple/accountBalance/SimpleAccountBalanceViewer.ts +99 -13
  125. package/src/simple/block/SimpleBlockViewer.ts +60 -21
  126. package/src/simple/blockReward/SimpleBlockRewardViewer.ts +34 -0
  127. package/src/simple/blockReward/index.ts +1 -0
  128. package/src/simple/chain/SimpleChainViewer.ts +25 -0
  129. package/src/simple/chain/index.ts +1 -0
  130. package/src/simple/gateway/SimpleXyoGatewayRunner.ts +1 -1
  131. package/src/simple/index.ts +2 -0
  132. package/src/simple/mempool/SimpleMempoolRunner.ts +47 -0
  133. package/src/simple/mempool/SimpleMempoolViewer.ts +34 -8
  134. package/src/simple/mempool/index.ts +1 -0
  135. package/src/simple/timesync/SimpleTimeSyncViewer.ts +1 -1
  136. package/src/summary/index.ts +2 -0
  137. package/src/{payloads/summary → summary/model}/index.ts +1 -0
  138. package/src/{model → summary/model}/summary.ts +5 -4
  139. package/src/{primitives/summary → summary/primitives}/balances/balancesStepSummaryFromRange.ts +4 -3
  140. package/src/{primitives/summary → summary/primitives}/balances/balancesSummary.ts +6 -5
  141. package/src/{primitives/summary → summary/primitives}/schemas/schemasStepSummaryFromRange.ts +3 -3
  142. package/src/{primitives/summary → summary/primitives}/schemas/schemasSummary.ts +7 -6
  143. package/src/{primitives/summary → summary/primitives}/transfers/transfersStepSummaryFromRange.ts +4 -3
  144. package/src/{primitives/summary → summary/primitives}/transfers/transfersSummary.ts +6 -5
  145. package/src/viewers/AccountBalance.ts +9 -2
  146. package/src/viewers/Block.ts +3 -0
  147. package/src/viewers/BlockReward.ts +9 -0
  148. package/src/viewers/ChainStakeViewer.ts +7 -0
  149. package/src/viewers/Mempool.ts +10 -1
  150. package/src/viewers/StakeIntent.ts +14 -0
  151. package/src/viewers/index.ts +2 -0
  152. package/dist/neutral/model/summary.d.ts.map +0 -1
  153. package/dist/neutral/payloads/summary/BalancesStepSummary.d.ts.map +0 -1
  154. package/dist/neutral/payloads/summary/SchemasStepSummary.d.ts.map +0 -1
  155. package/dist/neutral/payloads/summary/StepSummary.d.ts.map +0 -1
  156. package/dist/neutral/payloads/summary/TransfersSummary.d.ts.map +0 -1
  157. package/dist/neutral/payloads/summary/index.d.ts.map +0 -1
  158. package/dist/neutral/primitives/summary/balances/balancesStepSummaryFromRange.d.ts.map +0 -1
  159. package/dist/neutral/primitives/summary/balances/balancesSummary.d.ts +0 -4
  160. package/dist/neutral/primitives/summary/balances/balancesSummary.d.ts.map +0 -1
  161. package/dist/neutral/primitives/summary/balances/index.d.ts.map +0 -1
  162. package/dist/neutral/primitives/summary/schemas/index.d.ts.map +0 -1
  163. package/dist/neutral/primitives/summary/schemas/schemasStepSummaryFromRange.d.ts.map +0 -1
  164. package/dist/neutral/primitives/summary/schemas/schemasSummary.d.ts +0 -4
  165. package/dist/neutral/primitives/summary/schemas/schemasSummary.d.ts.map +0 -1
  166. package/dist/neutral/primitives/summary/transfers/index.d.ts.map +0 -1
  167. package/dist/neutral/primitives/summary/transfers/transfersStepSummaryFromRange.d.ts.map +0 -1
  168. package/dist/neutral/primitives/summary/transfers/transfersSummary.d.ts +0 -5
  169. package/dist/neutral/primitives/summary/transfers/transfersSummary.d.ts.map +0 -1
  170. package/dist/neutral/services/BlockRewardService.d.ts +0 -5
  171. package/dist/neutral/services/BlockRewardService.d.ts.map +0 -1
  172. package/dist/neutral/services/BlockRewardServiceV2.d.ts +0 -6
  173. package/dist/neutral/services/BlockRewardServiceV2.d.ts.map +0 -1
  174. package/dist/neutral/services/Chain/interfaces/ChainStakeViewer.d.ts +0 -4
  175. package/dist/neutral/services/Chain/interfaces/ChainStakeViewer.d.ts.map +0 -1
  176. package/dist/neutral/services/Chain/interfaces/ChainStaker.d.ts +0 -6
  177. package/dist/neutral/services/Chain/interfaces/ChainStaker.d.ts.map +0 -1
  178. package/dist/neutral/services/Chain/interfaces/index.d.ts +0 -3
  179. package/dist/neutral/services/Chain/interfaces/index.d.ts.map +0 -1
  180. package/src/services/BlockRewardService.ts +0 -6
  181. package/src/services/BlockRewardServiceV2.ts +0 -8
  182. package/src/services/Chain/interfaces/ChainStakeViewer.ts +0 -7
  183. package/src/services/Chain/interfaces/ChainStaker.ts +0 -5
  184. package/src/services/Chain/interfaces/index.ts +0 -2
  185. /package/dist/neutral/{payloads/summary → summary/model}/BalancesStepSummary.d.ts +0 -0
  186. /package/dist/neutral/{payloads/summary → summary/model}/SchemasStepSummary.d.ts +0 -0
  187. /package/dist/neutral/{payloads/summary → summary/model}/StepSummary.d.ts +0 -0
  188. /package/dist/neutral/{payloads/summary → summary/model}/TransfersSummary.d.ts +0 -0
  189. /package/dist/neutral/{primitives/summary → summary/primitives}/balances/index.d.ts +0 -0
  190. /package/dist/neutral/{primitives/summary → summary/primitives}/index.d.ts +0 -0
  191. /package/dist/neutral/{primitives/summary → summary/primitives}/schemas/index.d.ts +0 -0
  192. /package/dist/neutral/{primitives/summary → summary/primitives}/transfers/index.d.ts +0 -0
  193. /package/src/{payloads/summary → summary/model}/BalancesStepSummary.ts +0 -0
  194. /package/src/{payloads/summary → summary/model}/SchemasStepSummary.ts +0 -0
  195. /package/src/{payloads/summary → summary/model}/StepSummary.ts +0 -0
  196. /package/src/{payloads/summary → summary/model}/TransfersSummary.ts +0 -0
  197. /package/src/{primitives/summary → summary/primitives}/balances/index.ts +0 -0
  198. /package/src/{primitives/summary → summary/primitives}/index.ts +0 -0
  199. /package/src/{primitives/summary → summary/primitives}/schemas/index.ts +0 -0
  200. /package/src/{primitives/summary → summary/primitives}/transfers/index.ts +0 -0
@@ -108,12 +108,12 @@ var tryHydrateBlock = /* @__PURE__ */ __name(async (archivist, hash, maxDepth =
108
108
  }, "tryHydrateBlock");
109
109
 
110
110
  // src/block/primitives/blockFromBlockNumber.ts
111
- import { asHash as asHash3, isDefined as isDefined9 } from "@xylabs/sdk-js";
111
+ import { asHash as asHash3, isDefined as isDefined6 } from "@xylabs/sdk-js";
112
112
  import { toSafeJsonString } from "@xylabs/sdk-js";
113
- import { asSignedBlockBoundWitnessWithStorageMeta, SignedBlockBoundWitnessWithHashMetaZod, StepSizes as StepSizes7 } from "@xyo-network/xl1-protocol";
113
+ import { asSignedBlockBoundWitnessWithStorageMeta, SignedBlockBoundWitnessWithHashMetaZod, StepSizes as StepSizes4 } from "@xyo-network/xl1-protocol";
114
114
 
115
115
  // src/model/ChainContext/ChainContext.ts
116
- import { isDefined as isDefined7, isUndefined } from "@xylabs/sdk-js";
116
+ import { isDefined as isDefined4, isUndefined } from "@xylabs/sdk-js";
117
117
 
118
118
  // src/driver/cache/LruCacheMap.ts
119
119
  import { LRUCache } from "lru-cache";
@@ -225,6 +225,23 @@ function readPayloadMapFromStore(store) {
225
225
  }
226
226
  __name(readPayloadMapFromStore, "readPayloadMapFromStore");
227
227
 
228
+ // src/primitives/rewardFromBlockNumber.ts
229
+ import { toFixedPoint } from "@xylabs/sdk-js";
230
+ import { asAttoXL1 } from "@xyo-network/xl1-protocol";
231
+ var rewardFromBlockNumber = /* @__PURE__ */ __name((places = 18) => {
232
+ return (blockNumber, startingReward = asAttoXL1(toFixedPoint(30000n, places)), blocksPerStep = 1e6, stepFactorNumerator = 90n, stepFactorDenominator = 100n, minBlockReward = asAttoXL1(toFixedPoint(30n, places)), creatorReward = asAttoXL1(toFixedPoint(20000000000n, places))) => {
233
+ if (blockNumber === 0) {
234
+ return creatorReward;
235
+ }
236
+ const step = Math.floor((blockNumber + blocksPerStep) / blocksPerStep);
237
+ const stepExp = BigInt(step - 1);
238
+ const poweredNumerator = stepExp > 0 ? stepFactorNumerator ** stepExp : 1n;
239
+ const poweredDenominator = stepExp > 0 ? stepFactorDenominator ** stepExp : 1n;
240
+ let reward = startingReward * poweredNumerator / poweredDenominator;
241
+ return asAttoXL1(reward < minBlockReward ? minBlockReward : reward);
242
+ };
243
+ }, "rewardFromBlockNumber");
244
+
228
245
  // src/primitives/state/findMostRecentBlock.ts
229
246
  import { isSignedBlockBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
230
247
  var DEFAULT_NEXT_OPTIONS = {
@@ -330,956 +347,551 @@ function stepTransferIndex(block, step) {
330
347
  }
331
348
  __name(stepTransferIndex, "stepTransferIndex");
332
349
 
333
- // src/primitives/summary/balances/balancesStepSummaryFromRange.ts
334
- import { assertEx as assertEx6 } from "@xylabs/sdk-js";
335
- import { PayloadBuilder } from "@xyo-network/payload-builder";
336
- import { isAnyPayload } from "@xyo-network/payload-model";
337
- import { StepSizes as StepSizes4 } from "@xyo-network/xl1-protocol";
338
-
339
- // src/payloads/AddressPairPayload.ts
340
- import { AsObjectFactory } from "@xylabs/sdk-js";
341
- import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
342
- var AddressPairSchema = "network.xyo.address.pair";
343
- var isAddressPairPayload = isPayloadOfSchemaType(AddressPairSchema);
344
- var asAddressPairPayload = AsObjectFactory.create(isAddressPairPayload);
345
- var asOptionalAddressPairPayload = AsObjectFactory.createOptional(isAddressPairPayload);
346
-
347
- // src/payloads/netBalancesForPayloads.ts
348
- import { hexToBigInt, toAddress as toAddress3 } from "@xylabs/sdk-js";
349
- import { span } from "@xylabs/telemetry";
350
- import { isTransfer } from "@xyo-network/xl1-protocol";
351
- var netBalancesForPayloads = /* @__PURE__ */ __name((payloads) => {
352
- return span("netBalancesForPayloads", () => {
353
- const balances = {};
354
- for (const payload of payloads) {
355
- if (isTransfer(payload)) {
356
- const { from } = payload;
357
- for (let [address, amount] of Object.entries(payload.transfers)) {
358
- balances[toAddress3(address)] = (balances[toAddress3(address)] ?? 0n) + hexToBigInt(amount);
359
- balances[toAddress3(from)] = (balances[toAddress3(from)] ?? 0n) - hexToBigInt(amount);
360
- }
361
- }
350
+ // src/primitives/timeBudget.ts
351
+ async function timeBudget(name, logger, func, budget, status = false) {
352
+ const start = Date.now();
353
+ const timer = status ? setInterval(() => {
354
+ const duration2 = Date.now() - start;
355
+ if (budget > 0 && duration2 > budget) {
356
+ logger?.warn(`Function [${name}] execution is exceeding budget: ${duration2}ms > ${budget}ms`);
362
357
  }
363
- return balances;
364
- });
365
- }, "netBalancesForPayloads");
358
+ }, Math.max(100, budget)) : void 0;
359
+ const result = await func();
360
+ const duration = Date.now() - start;
361
+ if (!timer && budget > 0 && duration > budget) {
362
+ logger?.warn(`Function [${name}] execution exceeded budget: ${duration}ms > ${budget}ms`);
363
+ }
364
+ if (timer) {
365
+ clearInterval(timer);
366
+ }
367
+ return result;
368
+ }
369
+ __name(timeBudget, "timeBudget");
366
370
 
367
- // src/payloads/netSchemasForPayloads.ts
368
- import { hexToBigInt as hexToBigInt2, toAddress as toAddress4 } from "@xylabs/sdk-js";
369
- import { span as span2 } from "@xylabs/telemetry";
370
- import { isTransfer as isTransfer2 } from "@xyo-network/xl1-protocol";
371
- var netSchemasForPayloads = /* @__PURE__ */ __name((payloads) => {
372
- return span2("netSchemasForPayloads", () => {
373
- const balances = {};
374
- for (const payload of payloads) {
375
- if (isTransfer2(payload)) {
376
- const { from } = payload;
377
- for (let [address, amount] of Object.entries(payload.transfers)) {
378
- balances[toAddress4(address)] = (balances[toAddress4(address)] ?? 0n) + hexToBigInt2(amount);
379
- balances[toAddress4(from)] = (balances[toAddress4(from)] ?? 0n) - hexToBigInt2(amount);
380
- }
371
+ // src/primitives/transaction/elevatedPayloads.ts
372
+ import { isAllowedBlockPayload } from "@xyo-network/xl1-protocol";
373
+ var ELEVATE_OPCODE = "elevate";
374
+ function elevatedPayloads([tx, payloads]) {
375
+ const opCodes = (tx.script ?? []).filter((operation) => operation.startsWith(`${ELEVATE_OPCODE}|`));
376
+ const elevatedPayloads2 = [];
377
+ for (const opCode of opCodes) {
378
+ const [code, hash] = opCode.split("|");
379
+ if (code === ELEVATE_OPCODE) {
380
+ const elevatedPayload = payloads.find((payload) => payload._hash === hash);
381
+ if (isAllowedBlockPayload(elevatedPayload)) {
382
+ elevatedPayloads2.push(elevatedPayload);
381
383
  }
382
384
  }
383
- return balances;
384
- });
385
- }, "netSchemasForPayloads");
385
+ }
386
+ if (opCodes.length === elevatedPayloads2.length) {
387
+ return elevatedPayloads2;
388
+ }
389
+ throw new Error("Not all elevated payloads could be found in the transaction payloads");
390
+ }
391
+ __name(elevatedPayloads, "elevatedPayloads");
386
392
 
387
- // src/payloads/netTransfersForPayloads.ts
388
- import { hexToBigInt as hexToBigInt3 } from "@xylabs/sdk-js";
389
- import { span as span3 } from "@xylabs/telemetry";
390
- import { isTransfer as isTransfer3 } from "@xyo-network/xl1-protocol";
391
- function netTransfersForPayloads(payloads) {
392
- return span3("netTransfersForPayloads", () => {
393
- const transfers = {};
394
- for (const payload of payloads) {
395
- if (isTransfer3(payload)) {
396
- const { from } = payload;
397
- transfers[from] = transfers[from] ?? {};
398
- for (let [to, amount] of Object.entries(payload.transfers)) {
399
- transfers[to] = transfers[to] ?? {};
400
- transfers[to][from] = (transfers[to][from] ?? 0n) + hexToBigInt3(amount);
401
- transfers[from][to] = (transfers[from][to] ?? 0n) - hexToBigInt3(amount);
402
- }
403
- }
404
- }
405
- return transfers;
406
- });
393
+ // src/model/ChainContext/ChainContext.ts
394
+ function contextCache(context, name, create) {
395
+ if (!context.caches) {
396
+ context.caches = {};
397
+ }
398
+ if (isUndefined(context.caches[name])) {
399
+ context.caches[name] = create?.() ?? new MemoryMap();
400
+ }
401
+ return context.caches[name];
407
402
  }
408
- __name(netTransfersForPayloads, "netTransfersForPayloads");
403
+ __name(contextCache, "contextCache");
404
+ async function withContextCacheResponse(context, name, key, func, { max = 1e4, timeBudgetMs = 0 } = {}) {
405
+ const cache = contextCache(context, name, () => new LruCacheMap({
406
+ max
407
+ }));
408
+ const cacheResult = await cache.get(key);
409
+ if (isDefined4(cacheResult)) {
410
+ return cacheResult;
411
+ }
412
+ const result = timeBudgetMs > 0 ? await timeBudget(name, context.logger, func, timeBudgetMs) : await func();
413
+ await cache.set(key, result);
414
+ return result;
415
+ }
416
+ __name(withContextCacheResponse, "withContextCacheResponse");
409
417
 
410
- // src/payloads/summary/BalancesStepSummary.ts
411
- import { AsObjectFactory as AsObjectFactory2 } from "@xylabs/sdk-js";
412
- import { isPayloadOfSchemaType as isPayloadOfSchemaType2, isStorageMeta } from "@xyo-network/payload-model";
413
- var BalancesStepSummarySchema = "network.xyo.step.summary.balances";
414
- var isBalancesStepSummary = isPayloadOfSchemaType2(BalancesStepSummarySchema);
415
- var asBalancesStepSummary = AsObjectFactory2.create(isBalancesStepSummary);
416
- var isBalancesStepSummaryWithStorageMeta = /* @__PURE__ */ __name((value) => {
417
- return isBalancesStepSummary(value) && isStorageMeta(value);
418
- }, "isBalancesStepSummaryWithStorageMeta");
419
- var asBalancesStepSummaryWithStorageMeta = AsObjectFactory2.create(isBalancesStepSummaryWithStorageMeta);
418
+ // src/model/PayloadBundle/bundledPayloadToHydratedBlock.ts
419
+ import { PayloadBuilder } from "@xyo-network/payload-builder";
420
+ import { asSignedBlockBoundWitnessWithHashMeta } from "@xyo-network/xl1-protocol";
421
+ var bundledPayloadToHydratedBlock = /* @__PURE__ */ __name(async (payload) => {
422
+ const withHashMeta = await PayloadBuilder.addHashMeta(payload.payloads);
423
+ const tx = asSignedBlockBoundWitnessWithHashMeta(withHashMeta.find((p) => p._hash === payload.root));
424
+ if (tx) {
425
+ return [
426
+ tx,
427
+ withHashMeta.filter((p) => p._hash !== payload.root)
428
+ ];
429
+ }
430
+ }, "bundledPayloadToHydratedBlock");
420
431
 
421
- // src/payloads/summary/SchemasStepSummary.ts
422
- import { AsObjectFactory as AsObjectFactory3 } from "@xylabs/sdk-js";
423
- import { isPayloadOfSchemaType as isPayloadOfSchemaType3, isStorageMeta as isStorageMeta2 } from "@xyo-network/payload-model";
424
- var SchemasStepSummarySchema = "network.xyo.step.summary.schemas";
425
- var isSchemasStepSummary = isPayloadOfSchemaType3(SchemasStepSummarySchema);
426
- var asSchemasStepSummary = AsObjectFactory3.create(isSchemasStepSummary);
427
- var isSchemasStepSummaryWithStorageMeta = /* @__PURE__ */ __name((value) => {
428
- return isSchemasStepSummary(value) && isStorageMeta2(value);
429
- }, "isSchemasStepSummaryWithStorageMeta");
430
- var asSchemasStepSummaryWithStorageMeta = AsObjectFactory3.create(isSchemasStepSummaryWithStorageMeta);
432
+ // src/model/PayloadBundle/bundledPayloadToHydratedTransaction.ts
433
+ import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
434
+ import { asSignedTransactionBoundWitnessWithHashMeta } from "@xyo-network/xl1-protocol";
435
+ var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload) => {
436
+ const withHashMeta = await PayloadBuilder2.addHashMeta(payload.payloads);
437
+ const tx = asSignedTransactionBoundWitnessWithHashMeta(withHashMeta.find((p) => p._hash === payload.root));
438
+ if (tx) {
439
+ return [
440
+ tx,
441
+ withHashMeta.filter((p) => p._hash !== payload.root)
442
+ ];
443
+ }
444
+ }, "bundledPayloadToHydratedTransaction");
431
445
 
432
- // src/payloads/summary/StepSummary.ts
433
- var StepSummarySchema = "network.xyo.step.summary";
446
+ // src/model/PayloadBundle/hydratedBlockToPayloadBundle.ts
447
+ import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
448
+ import { PayloadBundleSchema } from "@xyo-network/payload-model";
449
+ var hydratedBlockToPayloadBundle = /* @__PURE__ */ __name((transaction) => {
450
+ const root = transaction[0]._hash;
451
+ return bundle(root, transaction);
452
+ }, "hydratedBlockToPayloadBundle");
453
+ var bundle = /* @__PURE__ */ __name((root, transaction) => {
454
+ const payloads = flattenHydratedBlock(transaction).flatMap((p) => PayloadBuilder3.omitStorageMeta(p));
455
+ return new PayloadBuilder3({
456
+ schema: PayloadBundleSchema
457
+ }).fields({
458
+ payloads,
459
+ root
460
+ }).build();
461
+ }, "bundle");
434
462
 
435
- // src/payloads/summary/TransfersSummary.ts
436
- import { AsObjectFactory as AsObjectFactory4 } from "@xylabs/sdk-js";
437
- import { isPayloadOfSchemaType as isPayloadOfSchemaType4, isStorageMeta as isStorageMeta3 } from "@xyo-network/payload-model";
438
- var TransfersStepSummarySchema = "network.xyo.step.summary.transfer";
439
- var isTransfersStepSummary = isPayloadOfSchemaType4(TransfersStepSummarySchema);
440
- var asTransfersStepSummary = AsObjectFactory4.create(isTransfersStepSummary);
441
- var isTransfersStepSummaryWithStorageMeta = /* @__PURE__ */ __name((value) => {
442
- return isTransfersStepSummary(value) && isStorageMeta3(value);
443
- }, "isTransfersStepSummaryWithStorageMeta");
444
- var asTransfersStepSummaryWithStorageMeta = AsObjectFactory4.create(isTransfersStepSummaryWithStorageMeta);
463
+ // src/model/PayloadBundle/hydratedTransactionToPayloadBundle.ts
464
+ import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/payload-builder";
465
+ import { PayloadBundleSchema as PayloadBundleSchema2 } from "@xyo-network/payload-model";
445
466
 
446
- // src/SignedBigInt.ts
447
- import { hexToBigInt as hexToBigInt4, toHex } from "@xylabs/sdk-js";
448
- import { isObject } from "@xylabs/sdk-js";
449
- var isNegativeBigInt = /* @__PURE__ */ __name((value) => {
450
- return isObject(value) && "negative" in value && typeof value.negative === "string";
451
- }, "isNegativeBigInt");
452
- var isPositiveBigInt = /* @__PURE__ */ __name((value) => {
453
- return isObject(value) && "positive" in value && typeof value.positive === "string";
454
- }, "isPositiveBigInt");
455
- var parseSignedBigInt = /* @__PURE__ */ __name((value) => {
456
- if (isNegativeBigInt(value)) {
457
- return -hexToBigInt4(value.negative);
458
- } else if (isPositiveBigInt(value)) {
459
- return hexToBigInt4(value.positive);
460
- } else {
461
- throw new Error("Invalid balance type");
467
+ // src/transaction/buildTransaction.ts
468
+ import { assertEx as assertEx6, toHex } from "@xylabs/sdk-js";
469
+ import { BoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
470
+ import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
471
+ import { defaultTransactionFees } from "@xyo-network/xl1-protocol";
472
+ async function buildTransaction(chain, onChainPayloads, offChainPayloads, signer, nbf, exp, from, fees = defaultTransactionFees) {
473
+ if (from === void 0 && Array.isArray(signer)) {
474
+ throw new Error("from is required when signer is an array");
462
475
  }
463
- }, "parseSignedBigInt");
464
- var toSignedBigInt = /* @__PURE__ */ __name((value) => {
465
- return value < 0n ? {
466
- negative: toHex(-value)
467
- } : {
468
- positive: toHex(value)
476
+ const txBoundWitnessFields = {
477
+ chain,
478
+ fees: {
479
+ base: toHex(fees.base),
480
+ gasLimit: toHex(fees.gasLimit),
481
+ gasPrice: toHex(fees.gasPrice),
482
+ priority: toHex(fees.priority)
483
+ },
484
+ nbf,
485
+ exp
469
486
  };
470
- }, "toSignedBigInt");
471
- var toPositiveBigInt = /* @__PURE__ */ __name((value) => {
472
- if (isNegativeBigInt(value)) {
473
- return {
474
- positive: toHex(0n)
475
- };
476
- }
477
- if (isPositiveBigInt(value)) {
478
- return {
479
- positive: value.positive
480
- };
487
+ const elevatedHashes = await PayloadBuilder4.hashes(onChainPayloads);
488
+ const script = [];
489
+ for (const elevatedHash of elevatedHashes) {
490
+ script.push(`elevate|${elevatedHash}`);
481
491
  }
482
- if (typeof value === "bigint") {
483
- return {
484
- positive: toHex(value)
485
- };
492
+ const fields = {
493
+ ...txBoundWitnessFields,
494
+ from: from ?? (Array.isArray(signer) ? assertEx6(signer.at(0)?.address) : signer.address)
495
+ };
496
+ if (script.length > 0) {
497
+ fields.script = script;
486
498
  }
487
- throw new Error("Invalid value for positive big int");
488
- }, "toPositiveBigInt");
499
+ const [tx, txPayloads] = await new BoundWitnessBuilder().fields(fields).meta({
500
+ $signatures: []
501
+ }).payloads([
502
+ ...onChainPayloads,
503
+ ...offChainPayloads
504
+ ]).signers(Array.isArray(signer) ? signer : [
505
+ signer
506
+ ]).build();
507
+ return [
508
+ await PayloadBuilder4.addHashMeta(tx),
509
+ await PayloadBuilder4.addHashMeta(txPayloads)
510
+ ];
511
+ }
512
+ __name(buildTransaction, "buildTransaction");
489
513
 
490
- // src/primitives/summary/balances/balancesStepSummaryFromRange.ts
491
- async function balancesStepSummaryFromRange(context, range) {
492
- const frameHeadHash = await hashFromBlockNumber(context, range[1]);
493
- const frameSize = range[1] - range[0] + 1;
494
- const [headHash] = await context.head();
495
- let result = void 0;
496
- if (frameSize === 1) {
497
- const hash = await hashFromBlockNumber(context, range[0]);
498
- const [, payloads] = await hydrateBlock(context.store, hash);
499
- const balances = {};
500
- for (const [address, balance] of Object.entries(netBalancesForPayloads(payloads))) {
501
- balances[address] = toSignedBigInt(balance);
502
- }
503
- result = {
504
- schema: BalancesStepSummarySchema,
505
- hash: headHash,
506
- stepSize: -1,
507
- balances
508
- };
509
- } else {
510
- const step = StepSizes4.indexOf(frameSize);
511
- assertEx6(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes4.join(", ")}`);
512
- const summaryResult = await context.summaryMap.get(`${frameHeadHash}|${frameSize}`);
513
- if (isAnyPayload(summaryResult)) {
514
- result = summaryResult;
515
- } else {
516
- await context.stepSemaphores[step].acquire();
517
- try {
518
- const subRanges = deepCalculateFramesFromRange(range, step - 1);
519
- const promises = subRanges.map((subRange) => balancesStepSummaryFromRange(context, subRange));
520
- const subResults = await Promise.all(promises);
521
- const bigIntBalances = {};
522
- for (const subResult of subResults) {
523
- for (const [address, balance] of Object.entries(subResult.balances)) {
524
- bigIntBalances[address] = (bigIntBalances[address] ?? 0n) + parseSignedBigInt(balance);
525
- }
526
- }
527
- const balances = {};
528
- for (const [address, balance] of Object.entries(bigIntBalances)) {
529
- balances[address] = toSignedBigInt(balance);
530
- }
531
- result = {
532
- schema: BalancesStepSummarySchema,
533
- hash: frameHeadHash,
534
- stepSize: frameSize,
535
- balances
536
- };
537
- await context.summaryMap.set(`${frameHeadHash}|${frameSize}`, result);
538
- } finally {
539
- context.stepSemaphores[step].release();
540
- }
541
- }
514
+ // src/transaction/buildUnsignedTransaction.ts
515
+ import { toHex as toHex2 } from "@xylabs/sdk-js";
516
+ import { BoundWitnessBuilder as BoundWitnessBuilder2 } from "@xyo-network/boundwitness-builder";
517
+ import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
518
+ import { defaultTransactionFees as defaultTransactionFees2 } from "@xyo-network/xl1-protocol";
519
+ async function buildUnsignedTransaction(chain, onChainPayloads, offChainPayloads, nbf, exp, from, fees = defaultTransactionFees2) {
520
+ const txBoundWitnessFields = {
521
+ chain,
522
+ fees: {
523
+ base: toHex2(fees.base),
524
+ gasLimit: toHex2(fees.gasLimit),
525
+ gasPrice: toHex2(fees.gasPrice),
526
+ priority: toHex2(fees.priority)
527
+ },
528
+ nbf,
529
+ exp
530
+ };
531
+ const elevatedHashes = await PayloadBuilder5.hashes(onChainPayloads);
532
+ const script = [];
533
+ for (const elevatedHash of elevatedHashes) {
534
+ script.push(`elevate|${elevatedHash}`);
542
535
  }
543
- const finalResult = await PayloadBuilder.addStorageMeta(result);
544
- return finalResult;
536
+ const fields = {
537
+ ...txBoundWitnessFields,
538
+ from
539
+ };
540
+ if (script.length > 0) {
541
+ fields.script = script;
542
+ }
543
+ const [tx, txPayloads] = await new BoundWitnessBuilder2().fields(fields).meta({
544
+ $signatures: []
545
+ }).payloads([
546
+ ...onChainPayloads,
547
+ ...offChainPayloads
548
+ ]).build(false);
549
+ return [
550
+ tx,
551
+ txPayloads
552
+ ];
545
553
  }
546
- __name(balancesStepSummaryFromRange, "balancesStepSummaryFromRange");
554
+ __name(buildUnsignedTransaction, "buildUnsignedTransaction");
547
555
 
548
- // src/primitives/summary/balances/balancesSummary.ts
549
- import { asAddress, isDefined as isDefined4 } from "@xylabs/sdk-js";
550
- import { spanRootAsync } from "@xylabs/telemetry";
551
- import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2, asXL1BlockNumber, asXL1BlockRange as asXL1BlockRange2 } from "@xyo-network/xl1-protocol";
552
- async function balancesSummary(context) {
553
- return await spanRootAsync("balancesSummary", async () => {
554
- const [headHash] = await context.head();
555
- const headResult = await context.store.chainMap.get(headHash);
556
- const headBoundWitness = asBlockBoundWitnessWithStorageMeta2(headResult, () => `Head block not found for hash: ${headHash}`);
557
- const rangeStart = asXL1BlockNumber(isDefined4(context.windowSize) ? Math.max(headBoundWitness.block - context.windowSize + 1, 0) : 0);
558
- const ranges = deepCalculateFramesFromRange(asXL1BlockRange2([
559
- rangeStart,
560
- headBoundWitness.block
561
- ], {
562
- name: "balancesSummary"
563
- }));
564
- const summaries = await Promise.all(ranges.map((range) => balancesStepSummaryFromRange(context, range)));
565
- const balances = {};
566
- for (let summary of summaries) {
567
- for (const [address, balance] of Object.entries(summary.balances)) {
568
- const validAddress = asAddress(address, () => `Invalid address: ${address}`);
569
- balances[validAddress] = (balances[validAddress] ?? 0n) + parseSignedBigInt(balance);
556
+ // src/transaction/confirmSubmittedTransaction.ts
557
+ import { delay, isDefined as isDefined5 } from "@xylabs/sdk-js";
558
+ var DEFAULT_CONFIRMATION_ATTEMPTS = 20;
559
+ var DEFAULT_DELAY_BETWEEN_ATTEMPTS = 1e3;
560
+ var confirmSubmittedTransaction = /* @__PURE__ */ __name(async (viewer, txHash, options) => {
561
+ const { attempts: maxAttempts = DEFAULT_CONFIRMATION_ATTEMPTS, delay: attemptDelay = DEFAULT_DELAY_BETWEEN_ATTEMPTS } = options ?? {};
562
+ options?.logger?.log("\u{1F680} confirming transaction:", txHash, "\n");
563
+ let attempts = 0;
564
+ while (true) {
565
+ const tx = await viewer.transactionByHash(txHash) ?? void 0;
566
+ if (isDefined5(tx)) {
567
+ options?.logger?.log("\u2705 Transaction confirmed:", txHash, "\n");
568
+ return tx;
569
+ } else {
570
+ attempts++;
571
+ if (attempts > maxAttempts) {
572
+ options?.logger?.error(`\u26A0\uFE0F Transaction not confirmed after ${maxAttempts} attempts`);
573
+ throw new Error(`Transaction ${txHash} not confirmed after ${maxAttempts} attempts`);
574
+ } else {
575
+ options?.logger?.log(`\u{1F504} Transaction not confirmed yet, attempt ${attempts}. Retrying...`, "\n");
576
+ await delay(attemptDelay);
570
577
  }
571
578
  }
572
- return balances;
573
- });
574
- }
575
- __name(balancesSummary, "balancesSummary");
579
+ }
580
+ }, "confirmSubmittedTransaction");
576
581
 
577
- // src/primitives/summary/schemas/schemasStepSummaryFromRange.ts
582
+ // src/transaction/hydrateTransaction.ts
578
583
  import { assertEx as assertEx7 } from "@xylabs/sdk-js";
579
- import { isBoundWitness } from "@xyo-network/boundwitness-model";
580
- import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
581
- import { isAnyPayload as isAnyPayload2, isHashMeta } from "@xyo-network/payload-model";
582
- import { StepSizes as StepSizes5 } from "@xyo-network/xl1-protocol";
583
- async function schemasStepSummaryFromRange(context, range) {
584
- const frameHeadHash = await hashFromBlockNumber(context, range[1]);
585
- const frameSize = range[1] - range[0] + 1;
586
- const [headHash] = await context.head();
587
- let result = void 0;
588
- if (frameSize === 1) {
589
- const hash = await hashFromBlockNumber(context, range[0]);
590
- const [block, payloads] = await hydrateBlock(context.store, hash);
591
- const boundWitnesses = [
592
- block,
593
- ...payloads.filter((x) => isBoundWitness(x) && isHashMeta(x))
594
- ];
595
- const schemas = {};
596
- for (const bw of boundWitnesses) {
597
- schemas[bw.schema] = (schemas[bw.schema] ?? 0) + 1;
598
- for (const schema of bw.payload_schemas) {
599
- schemas[schema] = (schemas[schema] ?? 0) + 1;
600
- }
584
+ import { hydrateTypedBoundWitness, tryHydrateTypedBoundWitness } from "@xyo-network/archivist-model";
585
+ import { isAllowedBlockPayload as isAllowedBlockPayload2, isSignedTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
586
+ var tryHydrateTransaction = /* @__PURE__ */ __name(async ({ chainMap }, hash) => {
587
+ return await tryHydrateTypedBoundWitness({
588
+ get(hashes) {
589
+ return chainMap.getMany(hashes);
590
+ },
591
+ next() {
592
+ throw new Error("Not implemented");
601
593
  }
602
- result = {
603
- schema: SchemasStepSummarySchema,
604
- hash: headHash,
605
- stepSize: -1,
606
- schemas
607
- };
608
- } else {
609
- const step = StepSizes5.indexOf(frameSize);
610
- assertEx7(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes5.join(", ")}`);
611
- const summaryResult = await context.summaryMap.get(`${frameHeadHash}|${frameSize}`);
612
- if (isAnyPayload2(summaryResult)) {
613
- result = summaryResult;
614
- } else {
615
- await context.stepSemaphores[step].acquire();
616
- try {
617
- const subRanges = deepCalculateFramesFromRange(range, step - 1);
618
- const promises = subRanges.map((subRange) => schemasStepSummaryFromRange(context, subRange));
619
- const subResults = await Promise.all(promises);
620
- const schemas = {};
621
- for (const subResult of subResults) {
622
- for (const [schema, count] of Object.entries(subResult.schemas)) {
623
- schemas[schema] = (schemas[schema] ?? 0) + count;
624
- }
625
- }
626
- result = {
627
- schema: SchemasStepSummarySchema,
628
- hash: frameHeadHash,
629
- stepSize: frameSize,
630
- schemas
631
- };
632
- await context.summaryMap.set(`${frameHeadHash}|${frameSize}`, result);
633
- } finally {
634
- context.stepSemaphores[step].release();
635
- }
594
+ }, hash, isSignedTransactionBoundWitnessWithStorageMeta);
595
+ }, "tryHydrateTransaction");
596
+ var hydrateTransaction = /* @__PURE__ */ __name(async ({ chainMap }, hash) => {
597
+ return await hydrateTypedBoundWitness({
598
+ get(hashes) {
599
+ return chainMap.getMany(hashes);
600
+ },
601
+ next() {
602
+ throw new Error("Not implemented");
636
603
  }
604
+ }, hash, isSignedTransactionBoundWitnessWithStorageMeta);
605
+ }, "hydrateTransaction");
606
+ var flattenHydratedTransaction = /* @__PURE__ */ __name((hydratedTransaction) => {
607
+ const [tx, txPayloads] = hydratedTransaction;
608
+ return [
609
+ ...txPayloads,
610
+ tx
611
+ ];
612
+ }, "flattenHydratedTransaction");
613
+ var flattenHydratedTransactions = /* @__PURE__ */ __name((hydratedTransactions) => hydratedTransactions.flatMap((tx) => flattenHydratedTransaction(tx)), "flattenHydratedTransactions");
614
+ var tryHydrateElevatedTransaction = /* @__PURE__ */ __name(async ({ chainMap }, hash) => {
615
+ const hydratedTransaction = await tryHydrateTransaction({
616
+ chainMap
617
+ }, hash);
618
+ if (!hydratedTransaction) {
619
+ return void 0;
637
620
  }
638
- return await PayloadBuilder2.addHashMeta(result);
639
- }
640
- __name(schemasStepSummaryFromRange, "schemasStepSummaryFromRange");
641
-
642
- // src/primitives/summary/schemas/schemasSummary.ts
643
- import { isDefined as isDefined5 } from "@xylabs/sdk-js";
644
- import { spanRootAsync as spanRootAsync2 } from "@xylabs/telemetry";
645
- import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta3, asXL1BlockNumber as asXL1BlockNumber2, asXL1BlockRange as asXL1BlockRange3 } from "@xyo-network/xl1-protocol";
646
- async function schemasSummary(context) {
647
- return await spanRootAsync2("schemasSummary", async () => {
648
- const [headHash] = await context.head();
649
- const headResult = await context.store.chainMap.get(headHash);
650
- const headBoundWitness = asBlockBoundWitnessWithStorageMeta3(headResult, () => `Head block not found for hash: ${headHash}`);
651
- const rangeStart = asXL1BlockNumber2(isDefined5(context.windowSize) ? Math.max(headBoundWitness.block - context.windowSize + 1, 0) : 0);
652
- const ranges = deepCalculateFramesFromRange(asXL1BlockRange3([
653
- rangeStart,
654
- headBoundWitness.block
655
- ], {
656
- name: "schemasSummary"
657
- }));
658
- const summaries = await Promise.all(ranges.map((range) => schemasStepSummaryFromRange(context, range)));
659
- const schemas = {};
660
- for (let summary of summaries) {
661
- for (const [schema, count] of Object.entries(summary.schemas)) {
662
- schemas[schema] = (schemas[schema] ?? 0) + count;
621
+ const [transaction, payloads] = hydratedTransaction;
622
+ const opCodes = (transaction.script ?? []).filter((operation) => operation.startsWith("elevate|"));
623
+ const elevatedPayloads2 = [];
624
+ for (const opCode of opCodes) {
625
+ const [code, hash2] = opCode.split("|");
626
+ if (code === "elevated") {
627
+ const elevatedPayload = payloads.find((payload) => payload._hash === hash2);
628
+ if (isAllowedBlockPayload2(elevatedPayload)) {
629
+ elevatedPayloads2.push(elevatedPayload);
663
630
  }
664
631
  }
665
- return schemas;
666
- });
632
+ }
633
+ if (opCodes.length === elevatedPayloads2.length) {
634
+ return [
635
+ transaction,
636
+ elevatedPayloads2
637
+ ];
638
+ }
639
+ return void 0;
640
+ }, "tryHydrateElevatedTransaction");
641
+ var hydrateElevatedTransaction = /* @__PURE__ */ __name(async (context, hash) => {
642
+ return assertEx7(await tryHydrateElevatedTransaction(context, hash), () => "Hydration failed");
643
+ }, "hydrateElevatedTransaction");
644
+
645
+ // src/transaction/primitives/transactionBlockByteCount.ts
646
+ import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
647
+ function transactionBlockByteCount([transaction, payloads]) {
648
+ const cleanTransaction = PayloadBuilder6.omitStorageMeta(transaction);
649
+ const transactionBytes = JSON.stringify(cleanTransaction).length;
650
+ const cleanPayloads = PayloadBuilder6.omitStorageMeta(payloads);
651
+ return cleanPayloads.reduce((acc, payload) => acc + JSON.stringify(payload).length, 0) + transactionBytes;
667
652
  }
668
- __name(schemasSummary, "schemasSummary");
653
+ __name(transactionBlockByteCount, "transactionBlockByteCount");
669
654
 
670
- // src/primitives/summary/transfers/transfersStepSummaryFromRange.ts
671
- import { assertEx as assertEx8 } from "@xylabs/sdk-js";
672
- import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
673
- import { isAnyPayload as isAnyPayload3 } from "@xyo-network/payload-model";
674
- import { StepSizes as StepSizes6 } from "@xyo-network/xl1-protocol";
655
+ // src/transaction/primitives/transactionElevatedPayloads.ts
656
+ import { asHash } from "@xylabs/sdk-js";
675
657
 
676
- // src/primitives/summary/transfers/transfersSummary.ts
677
- import { asAddress as asAddress2, isDefined as isDefined6 } from "@xylabs/sdk-js";
678
- import { spanRootAsync as spanRootAsync3 } from "@xylabs/telemetry";
679
- import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta4, asXL1BlockNumber as asXL1BlockNumber3, asXL1BlockRange as asXL1BlockRange4 } from "@xyo-network/xl1-protocol";
680
- async function transfersSummary(transferContext) {
681
- return await spanRootAsync3("transferSummary", async () => {
682
- const [headHash] = await transferContext.head();
683
- const headResult = await transferContext.store.chainMap.get(headHash);
684
- const headBoundWitness = asBlockBoundWitnessWithStorageMeta4(headResult, () => `Head block not found for hash: ${transferContext.head}`);
685
- const rangeStart = asXL1BlockNumber3(isDefined6(transferContext.windowSize) ? Math.max(headBoundWitness.block - transferContext.windowSize + 1, 0) : 0);
686
- const ranges = deepCalculateFramesFromRange(asXL1BlockRange4([
687
- rangeStart,
688
- headBoundWitness.block
689
- ], {
690
- name: "transfersSummary"
691
- }));
692
- const summaries = await Promise.all(ranges.map((range) => transfersStepSummaryFromRange(transferContext, range)));
693
- const transfers = {};
694
- for (let summary of summaries) {
695
- for (const [from, toMap] of Object.entries(summary.transfers)) {
696
- const validFrom = asAddress2(from, () => `Invalid address: ${from}`);
697
- transfers[validFrom] = transfers[validFrom] ?? {};
698
- for (const [to, transfer] of Object.entries(toMap)) {
699
- const validTo = asAddress2(to, () => `Invalid address: ${to}`);
700
- transfers[validFrom][validTo] = (transfers[validFrom][validTo] ?? 0n) + parseSignedBigInt(transfer);
701
- }
702
- }
703
- }
704
- return transfers;
705
- });
658
+ // src/transaction/primitives/transactionOperations.ts
659
+ function crackOperation(operation) {
660
+ const parts = operation.split("|");
661
+ if (parts.length < 2) {
662
+ throw new Error(`Invalid operation format: ${operation}`);
663
+ }
664
+ return [
665
+ parts[0],
666
+ parts.slice(1)
667
+ ];
706
668
  }
707
- __name(transfersSummary, "transfersSummary");
708
- function transfersSummaryKey(frameHeadHash, frameSize) {
709
- return `${frameHeadHash}|${frameSize}`;
669
+ __name(crackOperation, "crackOperation");
670
+ function crackOperations(operations) {
671
+ return operations.map((op) => crackOperation(op));
710
672
  }
711
- __name(transfersSummaryKey, "transfersSummaryKey");
673
+ __name(crackOperations, "crackOperations");
712
674
 
713
- // src/primitives/summary/transfers/transfersStepSummaryFromRange.ts
714
- async function transfersStepSummaryFromRange(context, range) {
715
- const frameHeadHash = await hashFromBlockNumber(context, range[1]);
716
- const frameSize = range[1] - range[0] + 1;
717
- const [headHash] = await context.head();
718
- let result = void 0;
719
- if (frameSize === 1) {
720
- const hash = await hashFromBlockNumber(context, range[0]);
721
- const [, payloads] = await hydrateBlock(context.store, hash);
722
- const transfers = {};
723
- for (const [from, toMap] of Object.entries(netTransfersForPayloads(payloads))) {
724
- transfers[from] = transfers[from] ?? {};
725
- for (const [to, amount] of Object.entries(toMap)) {
726
- transfers[from][to] = toSignedBigInt(amount);
727
- }
728
- }
729
- result = {
730
- schema: TransfersStepSummarySchema,
731
- hash: headHash,
732
- stepSize: -1,
733
- transfers
734
- };
735
- } else {
736
- const step = StepSizes6.indexOf(frameSize);
737
- assertEx8(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes6.join(", ")}`);
738
- const key = transfersSummaryKey(frameHeadHash, frameSize);
739
- const summaryResult = await context.summaryMap.get(key);
740
- if (isAnyPayload3(summaryResult)) {
741
- result = summaryResult;
742
- } else {
743
- await context.stepSemaphores[step].acquire();
744
- try {
745
- const subRanges = deepCalculateFramesFromRange(range, step - 1);
746
- const promises = subRanges.map((subRange) => transfersStepSummaryFromRange(context, subRange));
747
- const subResults = await Promise.all(promises);
748
- const bigIntBalances = {};
749
- for (const subResult of subResults) {
750
- for (const [from, toMap] of Object.entries(subResult.transfers)) {
751
- bigIntBalances[from] = bigIntBalances[from] ?? {};
752
- for (const [to, transfer] of Object.entries(toMap)) {
753
- bigIntBalances[from][to] = (bigIntBalances[from][to] ?? 0n) + parseSignedBigInt(transfer);
754
- }
755
- }
756
- }
757
- const transfers = {};
758
- for (const [from, toMap] of Object.entries(bigIntBalances)) {
759
- transfers[from] = transfers[from] ?? {};
760
- for (const [to, transfer] of Object.entries(toMap)) {
761
- transfers[from][to] = toSignedBigInt(transfer);
762
- }
763
- }
764
- result = {
765
- schema: TransfersStepSummarySchema,
766
- hash: frameHeadHash,
767
- stepSize: frameSize,
768
- transfers
769
- };
770
- await context.summaryMap.set(key, result);
771
- } finally {
772
- context.stepSemaphores[step].release();
773
- }
774
- }
775
- }
776
- const finalResult = await PayloadBuilder3.addStorageMeta(result);
777
- return finalResult;
675
+ // src/transaction/primitives/transactionElevatedPayloads.ts
676
+ function transactionElevatedPayloadHashes(transaction) {
677
+ const elevateOperations = crackOperations(transaction.script ?? []).filter((op) => op[0] === "elevate");
678
+ return elevateOperations.map((op) => asHash(op[1][0], true));
778
679
  }
779
- __name(transfersStepSummaryFromRange, "transfersStepSummaryFromRange");
780
-
781
- // src/primitives/timeBudget.ts
782
- async function timeBudget(name, logger, func, budget, status = false) {
783
- const start = Date.now();
784
- const timer = status ? setInterval(() => {
785
- const duration2 = Date.now() - start;
786
- if (budget > 0 && duration2 > budget) {
787
- logger?.warn(`Function [${name}] execution is exceeding budget: ${duration2}ms > ${budget}ms`);
788
- }
789
- }, Math.max(100, budget)) : void 0;
790
- const result = await func();
791
- const duration = Date.now() - start;
792
- if (!timer && budget > 0 && duration > budget) {
793
- logger?.warn(`Function [${name}] execution exceeded budget: ${duration}ms > ${budget}ms`);
794
- }
795
- if (timer) {
796
- clearInterval(timer);
797
- }
798
- return result;
680
+ __name(transactionElevatedPayloadHashes, "transactionElevatedPayloadHashes");
681
+ function transactionElevatedPayloads([transaction, payloads]) {
682
+ const hashes = transactionElevatedPayloadHashes(transaction);
683
+ const elevatedPayloads2 = payloads.filter((payload) => hashes.includes(payload._hash));
684
+ return elevatedPayloads2;
799
685
  }
800
- __name(timeBudget, "timeBudget");
686
+ __name(transactionElevatedPayloads, "transactionElevatedPayloads");
801
687
 
802
- // src/primitives/transaction/elevatedPayloads.ts
803
- import { isAllowedBlockPayload } from "@xyo-network/xl1-protocol";
804
- var ELEVATE_OPCODE = "elevate";
805
- function elevatedPayloads([tx, payloads]) {
806
- const opCodes = (tx.script ?? []).filter((operation) => operation.startsWith(`${ELEVATE_OPCODE}|`));
807
- const elevatedPayloads2 = [];
808
- for (const opCode of opCodes) {
809
- const [code, hash] = opCode.split("|");
810
- if (code === ELEVATE_OPCODE) {
811
- const elevatedPayload = payloads.find((payload) => payload._hash === hash);
812
- if (isAllowedBlockPayload(elevatedPayload)) {
813
- elevatedPayloads2.push(elevatedPayload);
814
- }
815
- }
816
- }
817
- if (opCodes.length === elevatedPayloads2.length) {
818
- return elevatedPayloads2;
819
- }
820
- throw new Error("Not all elevated payloads could be found in the transaction payloads");
688
+ // src/transaction/primitives/transactionRequiredGas.ts
689
+ import { AttoXL1, TransactionGasCosts } from "@xyo-network/xl1-protocol";
690
+ function transactionBytesRequiredGas([transaction, payloads]) {
691
+ const transactionBlockBytes = transactionBlockByteCount([
692
+ transaction,
693
+ payloads
694
+ ]);
695
+ return AttoXL1(TransactionGasCosts.characterStorage * BigInt(transactionBlockBytes));
821
696
  }
822
- __name(elevatedPayloads, "elevatedPayloads");
823
-
824
- // src/model/ChainContext/ChainContext.ts
825
- function contextCache(context, name, create) {
826
- if (!context.caches) {
827
- context.caches = {};
828
- }
829
- if (isUndefined(context.caches[name])) {
830
- context.caches[name] = create?.() ?? new MemoryMap();
831
- }
832
- return context.caches[name];
697
+ __name(transactionBytesRequiredGas, "transactionBytesRequiredGas");
698
+ function transactionRequiredGas(hydratedTransaction) {
699
+ const elevatedPayloads2 = transactionElevatedPayloads(hydratedTransaction);
700
+ const hashes = elevatedPayloads2.length + 1;
701
+ const signatures = hydratedTransaction[0].addresses.length;
702
+ return AttoXL1(transactionBytesRequiredGas(hydratedTransaction) + TransactionGasCosts.hashValidation * BigInt(hashes) + TransactionGasCosts.signatureValidation * BigInt(signatures) + TransactionGasCosts.payloadValidation * BigInt(elevatedPayloads2.length));
833
703
  }
834
- __name(contextCache, "contextCache");
835
- async function withContextCacheResponse(context, name, key, func, { max = 1e4, timeBudgetMs = 0 } = {}) {
836
- const cache = contextCache(context, name, () => new LruCacheMap({
837
- max
838
- }));
839
- const cacheResult = await cache.get(key);
840
- if (isDefined7(cacheResult)) {
841
- return cacheResult;
842
- }
843
- const result = timeBudgetMs > 0 ? await timeBudget(name, context.logger, func, timeBudgetMs) : await func();
844
- await cache.set(key, result);
704
+ __name(transactionRequiredGas, "transactionRequiredGas");
705
+
706
+ // src/transaction/script.ts
707
+ import { asHash as asHash2 } from "@xylabs/sdk-js";
708
+ import { assertEx as assertEx8, filterAs } from "@xylabs/sdk-js";
709
+ import { isAllowedBlockPayloadWithHashMeta } from "@xyo-network/xl1-protocol";
710
+ var tryExtractElevatedHashesFromScript = /* @__PURE__ */ __name((strings) => {
711
+ const hashes = strings.filter((str) => str.startsWith("elevate|")).map((str) => str.split("|")[1]);
712
+ return filterAs(hashes, (h) => asHash2(h));
713
+ }, "tryExtractElevatedHashesFromScript");
714
+ var extractElevatedHashesFromScript = /* @__PURE__ */ __name((strings) => {
715
+ const hashes = strings.filter((str) => str.startsWith("elevate|")).map((str) => str.split("|")[1]);
716
+ const filtered = filterAs(hashes, (h) => asHash2(h));
717
+ assertEx8(filtered.length === hashes.length, () => "Invalid elevated hashes");
718
+ return filtered;
719
+ }, "extractElevatedHashesFromScript");
720
+ var tryExtractElevatedHashes = /* @__PURE__ */ __name((tx) => {
721
+ const [bw, payloads] = tx;
722
+ const { script } = bw;
723
+ const hashes = script ? tryExtractElevatedHashesFromScript(script) : [];
724
+ return payloads.filter((p) => hashes.includes(p._hash)).filter(isAllowedBlockPayloadWithHashMeta);
725
+ }, "tryExtractElevatedHashes");
726
+ var extractElevatedHashes = /* @__PURE__ */ __name((tx) => {
727
+ const [bw, payloads] = tx;
728
+ const { script } = bw;
729
+ const hashes = script ? tryExtractElevatedHashesFromScript(script) : [];
730
+ const filtered = payloads.filter((p) => hashes.includes(p._hash)).filter(isAllowedBlockPayloadWithHashMeta);
731
+ assertEx8(filtered.length === hashes.length, () => "Invalid elevated hashes");
732
+ return filtered;
733
+ }, "extractElevatedHashes");
734
+
735
+ // src/transaction/signTransaction.ts
736
+ import { assertEx as assertEx9, hexFromArrayBuffer, toArrayBuffer } from "@xylabs/sdk-js";
737
+ import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
738
+ async function signTransaction(tx, account) {
739
+ assertEx9(tx.from === account.address, () => "Signer address does not match transaction from address");
740
+ const unsignedTx = structuredClone(tx);
741
+ unsignedTx.addresses = [
742
+ account.address
743
+ ];
744
+ unsignedTx.previous_hashes = [
745
+ account.previousHash ?? null
746
+ ];
747
+ const hash = await PayloadBuilder7.dataHash(unsignedTx);
748
+ const hashBytes = toArrayBuffer(hash);
749
+ const [signature] = await account.sign(hashBytes);
750
+ const result = {
751
+ ...unsignedTx,
752
+ $signatures: [
753
+ hexFromArrayBuffer(signature)
754
+ ]
755
+ };
845
756
  return result;
846
757
  }
847
- __name(withContextCacheResponse, "withContextCacheResponse");
848
-
849
- // src/model/PayloadBundle/bundledPayloadToHydratedTransaction.ts
850
- import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
851
- import { asSignedTransactionBoundWitnessWithHashMeta } from "@xyo-network/xl1-protocol";
852
- var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload) => {
853
- const withHashMeta = await PayloadBuilder4.addHashMeta(payload.payloads);
854
- const tx = asSignedTransactionBoundWitnessWithHashMeta(withHashMeta.find((p) => p._hash === payload.root));
855
- if (tx) {
856
- return [
857
- tx,
858
- withHashMeta.filter((p) => p._hash !== payload.root)
859
- ];
860
- }
861
- }, "bundledPayloadToHydratedTransaction");
758
+ __name(signTransaction, "signTransaction");
862
759
 
863
760
  // src/model/PayloadBundle/hydratedTransactionToPayloadBundle.ts
864
- import { PayloadBuilder as PayloadBuilder9 } from "@xyo-network/payload-builder";
865
- import { PayloadBundleSchema } from "@xyo-network/payload-model";
761
+ var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) => {
762
+ const root = transaction[0]._hash;
763
+ return bundle2(root, transaction);
764
+ }, "hydratedTransactionToPayloadBundle");
765
+ var bundle2 = /* @__PURE__ */ __name((root, transaction) => {
766
+ const payloads = flattenHydratedTransaction(transaction).flatMap((p) => PayloadBuilder8.omitStorageMeta(p));
767
+ return new PayloadBuilder8({
768
+ schema: PayloadBundleSchema2
769
+ }).fields({
770
+ payloads,
771
+ root
772
+ }).build();
773
+ }, "bundle");
866
774
 
867
- // src/transaction/buildTransaction.ts
868
- import { assertEx as assertEx9, toHex as toHex2 } from "@xylabs/sdk-js";
869
- import { BoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
870
- import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
871
- import { defaultTransactionFees } from "@xyo-network/xl1-protocol";
872
- async function buildTransaction(chain, onChainPayloads, offChainPayloads, signer, nbf, exp, from, fees = defaultTransactionFees) {
873
- if (from === void 0 && Array.isArray(signer)) {
874
- throw new Error("from is required when signer is an array");
875
- }
876
- const txBoundWitnessFields = {
877
- chain,
878
- fees: {
879
- base: toHex2(fees.base),
880
- gasLimit: toHex2(fees.gasLimit),
881
- gasPrice: toHex2(fees.gasPrice),
882
- priority: toHex2(fees.priority)
883
- },
884
- nbf,
885
- exp
886
- };
887
- const elevatedHashes = await PayloadBuilder5.hashes(onChainPayloads);
888
- const script = [];
889
- for (const elevatedHash of elevatedHashes) {
890
- script.push(`elevate|${elevatedHash}`);
891
- }
892
- const fields = {
893
- ...txBoundWitnessFields,
894
- from: from ?? (Array.isArray(signer) ? assertEx9(signer.at(0)?.address) : signer.address)
895
- };
896
- if (script.length > 0) {
897
- fields.script = script;
898
- }
899
- const [tx, txPayloads] = await new BoundWitnessBuilder().fields(fields).meta({
900
- $signatures: []
901
- }).payloads([
902
- ...onChainPayloads,
903
- ...offChainPayloads
904
- ]).signers(Array.isArray(signer) ? signer : [
905
- signer
906
- ]).build();
907
- return [
908
- await PayloadBuilder5.addHashMeta(tx),
909
- await PayloadBuilder5.addHashMeta(txPayloads)
910
- ];
775
+ // src/model/Qualified.ts
776
+ import { HashZod } from "@xylabs/sdk-js";
777
+ import { XL1BlockRangeZod } from "@xyo-network/xl1-protocol";
778
+ import z from "zod";
779
+ var QualifiedZod = /* @__PURE__ */ __name((zodType) => {
780
+ return z.tuple([
781
+ zodType,
782
+ XL1BlockRangeZod,
783
+ HashZod
784
+ ]);
785
+ }, "QualifiedZod");
786
+
787
+ // src/block/primitives/blockFromBlockNumber.ts
788
+ async function blockFromBlockNumber(context, blockNumber) {
789
+ const cacheKey = `${blockNumber}`;
790
+ return await withContextCacheResponse(context, "blockFromBlockNumber", cacheKey, async () => {
791
+ const [headHash] = await context.head();
792
+ const result = await context.store.chainMap.get(headHash);
793
+ if (!isDefined6(result)) {
794
+ throw new Error(`Head block not found for hash: ${headHash}`);
795
+ }
796
+ let currentBlock = asSignedBlockBoundWitnessWithStorageMeta(result, () => `Found Payload is not a Signed<BlockBoundWitness>: ${JSON.stringify(result, null, 2)}`);
797
+ if (currentBlock.block < blockNumber) {
798
+ throw new Error(`Block number ${blockNumber} is greater than head ${currentBlock.block}.`);
799
+ }
800
+ while (currentBlock.block > blockNumber) {
801
+ let jumpHash = currentBlock.previous;
802
+ let jumpBlockNumber = currentBlock.block - 1;
803
+ for (const [step, stepSize2] of StepSizes4.entries()) {
804
+ const possibleJumpBlockNumber = currentBlock.block - currentBlock.block % stepSize2 - 1;
805
+ if (possibleJumpBlockNumber >= blockNumber && possibleJumpBlockNumber <= jumpBlockNumber) {
806
+ jumpBlockNumber = possibleJumpBlockNumber;
807
+ jumpHash = asHash3(currentBlock.step_hashes?.at(step), () => `Step hash not found for step ${step} in block ${currentBlock.block}`);
808
+ }
809
+ }
810
+ const newBlock = await context.store.chainMap.get(asHash3(jumpHash, () => `Jump hash not found for block number [${blockNumber}]: ${jumpBlockNumber} ${toSafeJsonString(currentBlock, 10)}`));
811
+ if (!isDefined6(newBlock)) {
812
+ throw new Error(`Block not found for jump hash: ${jumpHash}`);
813
+ }
814
+ currentBlock = asSignedBlockBoundWitnessWithStorageMeta(newBlock, () => {
815
+ const result2 = SignedBlockBoundWitnessWithHashMetaZod.safeParse(newBlock);
816
+ return `Found Payload [jump hash] is not a Signed<BlockBoundWitness>: ${result2.error}`;
817
+ });
818
+ if (currentBlock.block === blockNumber) {
819
+ break;
820
+ }
821
+ if (currentBlock.block < blockNumber) {
822
+ throw new Error(`Block number ${blockNumber} is not a valid step block number for block ${headHash}.`);
823
+ }
824
+ }
825
+ return currentBlock;
826
+ });
911
827
  }
912
- __name(buildTransaction, "buildTransaction");
828
+ __name(blockFromBlockNumber, "blockFromBlockNumber");
913
829
 
914
- // src/transaction/buildUnsignedTransaction.ts
915
- import { toHex as toHex3 } from "@xylabs/sdk-js";
916
- import { BoundWitnessBuilder as BoundWitnessBuilder2 } from "@xyo-network/boundwitness-builder";
917
- import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
918
- import { defaultTransactionFees as defaultTransactionFees2 } from "@xyo-network/xl1-protocol";
919
- async function buildUnsignedTransaction(chain, onChainPayloads, offChainPayloads, nbf, exp, from, fees = defaultTransactionFees2) {
920
- const txBoundWitnessFields = {
921
- chain,
922
- fees: {
923
- base: toHex3(fees.base),
924
- gasLimit: toHex3(fees.gasLimit),
925
- gasPrice: toHex3(fees.gasPrice),
926
- priority: toHex3(fees.priority)
927
- },
928
- nbf,
929
- exp
930
- };
931
- const elevatedHashes = await PayloadBuilder6.hashes(onChainPayloads);
932
- const script = [];
933
- for (const elevatedHash of elevatedHashes) {
934
- script.push(`elevate|${elevatedHash}`);
830
+ // src/block/primitives/frames/calculateFramesFromRange.ts
831
+ import { asXL1BlockNumber, stepSize } from "@xyo-network/xl1-protocol";
832
+ function calculateFramesFromRange(range, step) {
833
+ const size = stepSize(step);
834
+ let start = Math.trunc(range[0] / size) * size;
835
+ const fitted = [];
836
+ const remaining = [];
837
+ if (start !== range[0]) {
838
+ start += size;
839
+ remaining.push([
840
+ range[0],
841
+ asXL1BlockNumber(Math.min(start - 1, range[1]), true)
842
+ ]);
935
843
  }
936
- const fields = {
937
- ...txBoundWitnessFields,
938
- from
939
- };
940
- if (script.length > 0) {
941
- fields.script = script;
844
+ for (let i = start; i <= range[1]; i += size) {
845
+ if (i + size - 1 <= range[1]) {
846
+ fitted.push([
847
+ asXL1BlockNumber(i, {
848
+ name: "calculateFramesFromRange A"
849
+ }),
850
+ asXL1BlockNumber(Math.min(i + size - 1, range[1]), {
851
+ name: "calculateFramesFromRange B"
852
+ })
853
+ ]);
854
+ } else {
855
+ remaining.push([
856
+ asXL1BlockNumber(i, {
857
+ name: "calculateFramesFromRange C"
858
+ }),
859
+ range[1]
860
+ ]);
861
+ }
942
862
  }
943
- const [tx, txPayloads] = await new BoundWitnessBuilder2().fields(fields).meta({
944
- $signatures: []
945
- }).payloads([
946
- ...onChainPayloads,
947
- ...offChainPayloads
948
- ]).build(false);
949
863
  return [
950
- tx,
951
- txPayloads
864
+ fitted,
865
+ remaining
952
866
  ];
953
867
  }
954
- __name(buildUnsignedTransaction, "buildUnsignedTransaction");
955
-
956
- // src/transaction/confirmSubmittedTransaction.ts
957
- import { delay, isDefined as isDefined8 } from "@xylabs/sdk-js";
958
- var DEFAULT_CONFIRMATION_ATTEMPTS = 20;
959
- var DEFAULT_DELAY_BETWEEN_ATTEMPTS = 1e3;
960
- var confirmSubmittedTransaction = /* @__PURE__ */ __name(async (viewer, txHash, options) => {
961
- const { attempts: maxAttempts = DEFAULT_CONFIRMATION_ATTEMPTS, delay: attemptDelay = DEFAULT_DELAY_BETWEEN_ATTEMPTS } = options ?? {};
962
- options?.logger?.log("\u{1F680} confirming transaction:", txHash, "\n");
963
- let attempts = 0;
964
- while (true) {
965
- const tx = await viewer.transactionByHash(txHash) ?? void 0;
966
- if (isDefined8(tx)) {
967
- options?.logger?.log("\u2705 Transaction confirmed:", txHash, "\n");
968
- return tx;
969
- } else {
970
- attempts++;
971
- if (attempts > maxAttempts) {
972
- options?.logger?.error(`\u26A0\uFE0F Transaction not confirmed after ${maxAttempts} attempts`);
973
- throw new Error(`Transaction ${txHash} not confirmed after ${maxAttempts} attempts`);
974
- } else {
975
- options?.logger?.log(`\u{1F504} Transaction not confirmed yet, attempt ${attempts}. Retrying...`, "\n");
976
- await delay(attemptDelay);
977
- }
978
- }
979
- }
980
- }, "confirmSubmittedTransaction");
868
+ __name(calculateFramesFromRange, "calculateFramesFromRange");
981
869
 
982
- // src/transaction/hydrateTransaction.ts
983
- import { assertEx as assertEx10 } from "@xylabs/sdk-js";
984
- import { hydrateTypedBoundWitness, tryHydrateTypedBoundWitness } from "@xyo-network/archivist-model";
985
- import { isAllowedBlockPayload as isAllowedBlockPayload2, isSignedTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
986
- var tryHydrateTransaction = /* @__PURE__ */ __name(async ({ chainMap }, hash) => {
987
- return await tryHydrateTypedBoundWitness({
988
- get(hashes) {
989
- return chainMap.getMany(hashes);
990
- },
991
- next() {
992
- throw new Error("Not implemented");
993
- }
994
- }, hash, isSignedTransactionBoundWitnessWithStorageMeta);
995
- }, "tryHydrateTransaction");
996
- var hydrateTransaction = /* @__PURE__ */ __name(async ({ chainMap }, hash) => {
997
- return await hydrateTypedBoundWitness({
998
- get(hashes) {
999
- return chainMap.getMany(hashes);
1000
- },
1001
- next() {
1002
- throw new Error("Not implemented");
1003
- }
1004
- }, hash, isSignedTransactionBoundWitnessWithStorageMeta);
1005
- }, "hydrateTransaction");
1006
- var flattenHydratedTransaction = /* @__PURE__ */ __name((hydratedTransaction) => {
1007
- const [tx, txPayloads] = hydratedTransaction;
1008
- return [
1009
- ...txPayloads,
1010
- tx
870
+ // src/block/primitives/frames/deepCalculateFramesFromRange.ts
871
+ import { StepSizes as StepSizes5 } from "@xyo-network/xl1-protocol";
872
+ function deepCalculateFramesFromRange(range, startingStep = StepSizes5.length - 1) {
873
+ const fitted = [];
874
+ let remaining = [
875
+ range
1011
876
  ];
1012
- }, "flattenHydratedTransaction");
1013
- var flattenHydratedTransactions = /* @__PURE__ */ __name((hydratedTransactions) => hydratedTransactions.flatMap((tx) => flattenHydratedTransaction(tx)), "flattenHydratedTransactions");
1014
- var tryHydrateElevatedTransaction = /* @__PURE__ */ __name(async ({ chainMap }, hash) => {
1015
- const hydratedTransaction = await tryHydrateTransaction({
1016
- chainMap
1017
- }, hash);
1018
- if (!hydratedTransaction) {
1019
- return void 0;
1020
- }
1021
- const [transaction, payloads] = hydratedTransaction;
1022
- const opCodes = (transaction.script ?? []).filter((operation) => operation.startsWith("elevate|"));
1023
- const elevatedPayloads2 = [];
1024
- for (const opCode of opCodes) {
1025
- const [code, hash2] = opCode.split("|");
1026
- if (code === "elevated") {
1027
- const elevatedPayload = payloads.find((payload) => payload._hash === hash2);
1028
- if (isAllowedBlockPayload2(elevatedPayload)) {
1029
- elevatedPayloads2.push(elevatedPayload);
1030
- }
877
+ for (let step = startingStep; step >= 0; step--) {
878
+ const newRemaining = [];
879
+ for (const range2 of remaining) {
880
+ const [newFittedFrames, newRemainingFrames] = calculateFramesFromRange(range2, step);
881
+ fitted.push(...newFittedFrames);
882
+ newRemaining.push(...newRemainingFrames);
1031
883
  }
884
+ remaining = newRemaining;
1032
885
  }
1033
- if (opCodes.length === elevatedPayloads2.length) {
1034
- return [
1035
- transaction,
1036
- elevatedPayloads2
1037
- ];
886
+ for (const range2 of remaining) {
887
+ for (let i = range2[0]; i <= range2[1]; i++) {
888
+ fitted.push([
889
+ i,
890
+ i
891
+ ]);
892
+ }
1038
893
  }
1039
- return void 0;
1040
- }, "tryHydrateElevatedTransaction");
1041
- var hydrateElevatedTransaction = /* @__PURE__ */ __name(async (context, hash) => {
1042
- return assertEx10(await tryHydrateElevatedTransaction(context, hash), () => "Hydration failed");
1043
- }, "hydrateElevatedTransaction");
1044
-
1045
- // src/transaction/primitives/transactionBlockByteCount.ts
1046
- import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
1047
- function transactionBlockByteCount([transaction, payloads]) {
1048
- const cleanTransaction = PayloadBuilder7.omitStorageMeta(transaction);
1049
- const transactionBytes = JSON.stringify(cleanTransaction).length;
1050
- const cleanPayloads = PayloadBuilder7.omitStorageMeta(payloads);
1051
- return cleanPayloads.reduce((acc, payload) => acc + JSON.stringify(payload).length, 0) + transactionBytes;
1052
- }
1053
- __name(transactionBlockByteCount, "transactionBlockByteCount");
1054
-
1055
- // src/transaction/primitives/transactionElevatedPayloads.ts
1056
- import { asHash } from "@xylabs/sdk-js";
1057
-
1058
- // src/transaction/primitives/transactionOperations.ts
1059
- function crackOperation(operation) {
1060
- const parts = operation.split("|");
1061
- if (parts.length < 2) {
1062
- throw new Error(`Invalid operation format: ${operation}`);
1063
- }
1064
- return [
1065
- parts[0],
1066
- parts.slice(1)
1067
- ];
1068
- }
1069
- __name(crackOperation, "crackOperation");
1070
- function crackOperations(operations) {
1071
- return operations.map((op) => crackOperation(op));
1072
- }
1073
- __name(crackOperations, "crackOperations");
1074
-
1075
- // src/transaction/primitives/transactionElevatedPayloads.ts
1076
- function transactionElevatedPayloadHashes(transaction) {
1077
- const elevateOperations = crackOperations(transaction.script ?? []).filter((op) => op[0] === "elevate");
1078
- return elevateOperations.map((op) => asHash(op[1][0], true));
1079
- }
1080
- __name(transactionElevatedPayloadHashes, "transactionElevatedPayloadHashes");
1081
- function transactionElevatedPayloads([transaction, payloads]) {
1082
- const hashes = transactionElevatedPayloadHashes(transaction);
1083
- const elevatedPayloads2 = payloads.filter((payload) => hashes.includes(payload._hash));
1084
- return elevatedPayloads2;
1085
- }
1086
- __name(transactionElevatedPayloads, "transactionElevatedPayloads");
1087
-
1088
- // src/transaction/primitives/transactionRequiredGas.ts
1089
- import { AttoXL1, TransactionGasCosts } from "@xyo-network/xl1-protocol";
1090
- function transactionBytesRequiredGas([transaction, payloads]) {
1091
- const transactionBlockBytes = transactionBlockByteCount([
1092
- transaction,
1093
- payloads
1094
- ]);
1095
- return AttoXL1(TransactionGasCosts.characterStorage * BigInt(transactionBlockBytes));
1096
- }
1097
- __name(transactionBytesRequiredGas, "transactionBytesRequiredGas");
1098
- function transactionRequiredGas(hydratedTransaction) {
1099
- const elevatedPayloads2 = transactionElevatedPayloads(hydratedTransaction);
1100
- const hashes = elevatedPayloads2.length + 1;
1101
- const signatures = hydratedTransaction[0].addresses.length;
1102
- return AttoXL1(transactionBytesRequiredGas(hydratedTransaction) + TransactionGasCosts.hashValidation * BigInt(hashes) + TransactionGasCosts.signatureValidation * BigInt(signatures) + TransactionGasCosts.payloadValidation * BigInt(elevatedPayloads2.length));
1103
- }
1104
- __name(transactionRequiredGas, "transactionRequiredGas");
1105
-
1106
- // src/transaction/script.ts
1107
- import { asHash as asHash2 } from "@xylabs/sdk-js";
1108
- import { assertEx as assertEx11, filterAs } from "@xylabs/sdk-js";
1109
- import { isAllowedBlockPayloadWithHashMeta } from "@xyo-network/xl1-protocol";
1110
- var tryExtractElevatedHashesFromScript = /* @__PURE__ */ __name((strings) => {
1111
- const hashes = strings.filter((str) => str.startsWith("elevate|")).map((str) => str.split("|")[1]);
1112
- return filterAs(hashes, (h) => asHash2(h));
1113
- }, "tryExtractElevatedHashesFromScript");
1114
- var extractElevatedHashesFromScript = /* @__PURE__ */ __name((strings) => {
1115
- const hashes = strings.filter((str) => str.startsWith("elevate|")).map((str) => str.split("|")[1]);
1116
- const filtered = filterAs(hashes, (h) => asHash2(h));
1117
- assertEx11(filtered.length === hashes.length, () => "Invalid elevated hashes");
1118
- return filtered;
1119
- }, "extractElevatedHashesFromScript");
1120
- var tryExtractElevatedHashes = /* @__PURE__ */ __name((tx) => {
1121
- const [bw, payloads] = tx;
1122
- const { script } = bw;
1123
- const hashes = script ? tryExtractElevatedHashesFromScript(script) : [];
1124
- return payloads.filter((p) => hashes.includes(p._hash)).filter(isAllowedBlockPayloadWithHashMeta);
1125
- }, "tryExtractElevatedHashes");
1126
- var extractElevatedHashes = /* @__PURE__ */ __name((tx) => {
1127
- const [bw, payloads] = tx;
1128
- const { script } = bw;
1129
- const hashes = script ? tryExtractElevatedHashesFromScript(script) : [];
1130
- const filtered = payloads.filter((p) => hashes.includes(p._hash)).filter(isAllowedBlockPayloadWithHashMeta);
1131
- assertEx11(filtered.length === hashes.length, () => "Invalid elevated hashes");
1132
- return filtered;
1133
- }, "extractElevatedHashes");
1134
-
1135
- // src/transaction/signTransaction.ts
1136
- import { assertEx as assertEx12, hexFromArrayBuffer, toArrayBuffer } from "@xylabs/sdk-js";
1137
- import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/payload-builder";
1138
- async function signTransaction(tx, account) {
1139
- assertEx12(tx.from === account.address, () => "Signer address does not match transaction from address");
1140
- const unsignedTx = structuredClone(tx);
1141
- unsignedTx.addresses = [
1142
- account.address
1143
- ];
1144
- unsignedTx.previous_hashes = [
1145
- account.previousHash ?? null
1146
- ];
1147
- const hash = await PayloadBuilder8.dataHash(unsignedTx);
1148
- const hashBytes = toArrayBuffer(hash);
1149
- const [signature] = await account.sign(hashBytes);
1150
- const result = {
1151
- ...unsignedTx,
1152
- $signatures: [
1153
- hexFromArrayBuffer(signature)
1154
- ]
1155
- };
1156
- return result;
1157
- }
1158
- __name(signTransaction, "signTransaction");
1159
-
1160
- // src/model/PayloadBundle/hydratedTransactionToPayloadBundle.ts
1161
- var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) => {
1162
- const root = transaction[0]._hash;
1163
- return bundle(root, transaction);
1164
- }, "hydratedTransactionToPayloadBundle");
1165
- var bundle = /* @__PURE__ */ __name((root, transaction) => {
1166
- const payloads = flattenHydratedTransaction(transaction).flatMap((p) => PayloadBuilder9.omitStorageMeta(p));
1167
- return new PayloadBuilder9({
1168
- schema: PayloadBundleSchema
1169
- }).fields({
1170
- payloads,
1171
- root
1172
- }).build();
1173
- }, "bundle");
1174
-
1175
- // src/block/primitives/blockFromBlockNumber.ts
1176
- async function blockFromBlockNumber(context, blockNumber) {
1177
- const cacheKey = `${blockNumber}`;
1178
- return await withContextCacheResponse(context, "blockFromBlockNumber", cacheKey, async () => {
1179
- const [headHash] = await context.head();
1180
- const result = await context.store.chainMap.get(headHash);
1181
- if (!isDefined9(result)) {
1182
- throw new Error(`Head block not found for hash: ${headHash}`);
1183
- }
1184
- let currentBlock = asSignedBlockBoundWitnessWithStorageMeta(result, () => `Found Payload is not a Signed<BlockBoundWitness>: ${JSON.stringify(result, null, 2)}`);
1185
- if (currentBlock.block < blockNumber) {
1186
- throw new Error(`Block number ${blockNumber} is greater than head ${currentBlock.block}.`);
1187
- }
1188
- while (currentBlock.block > blockNumber) {
1189
- let jumpHash = currentBlock.previous;
1190
- let jumpBlockNumber = currentBlock.block - 1;
1191
- for (const [step, stepSize2] of StepSizes7.entries()) {
1192
- const possibleJumpBlockNumber = currentBlock.block - currentBlock.block % stepSize2 - 1;
1193
- if (possibleJumpBlockNumber >= blockNumber && possibleJumpBlockNumber <= jumpBlockNumber) {
1194
- jumpBlockNumber = possibleJumpBlockNumber;
1195
- jumpHash = asHash3(currentBlock.step_hashes?.at(step), () => `Step hash not found for step ${step} in block ${currentBlock.block}`);
1196
- }
1197
- }
1198
- const newBlock = await context.store.chainMap.get(asHash3(jumpHash, () => `Jump hash not found for block number [${blockNumber}]: ${jumpBlockNumber} ${toSafeJsonString(currentBlock, 10)}`));
1199
- if (!isDefined9(newBlock)) {
1200
- throw new Error(`Block not found for jump hash: ${jumpHash}`);
1201
- }
1202
- currentBlock = asSignedBlockBoundWitnessWithStorageMeta(newBlock, () => {
1203
- const result2 = SignedBlockBoundWitnessWithHashMetaZod.safeParse(newBlock);
1204
- return `Found Payload [jump hash] is not a Signed<BlockBoundWitness>: ${result2.error}`;
1205
- });
1206
- if (currentBlock.block === blockNumber) {
1207
- break;
1208
- }
1209
- if (currentBlock.block < blockNumber) {
1210
- throw new Error(`Block number ${blockNumber} is not a valid step block number for block ${headHash}.`);
1211
- }
1212
- }
1213
- return currentBlock;
1214
- });
1215
- }
1216
- __name(blockFromBlockNumber, "blockFromBlockNumber");
1217
-
1218
- // src/block/primitives/frames/calculateFramesFromRange.ts
1219
- import { asXL1BlockNumber as asXL1BlockNumber4, stepSize } from "@xyo-network/xl1-protocol";
1220
- function calculateFramesFromRange(range, step) {
1221
- const size = stepSize(step);
1222
- let start = Math.trunc(range[0] / size) * size;
1223
- const fitted = [];
1224
- const remaining = [];
1225
- if (start !== range[0]) {
1226
- start += size;
1227
- remaining.push([
1228
- range[0],
1229
- asXL1BlockNumber4(Math.min(start - 1, range[1]), true)
1230
- ]);
1231
- }
1232
- for (let i = start; i <= range[1]; i += size) {
1233
- if (i + size - 1 <= range[1]) {
1234
- fitted.push([
1235
- asXL1BlockNumber4(i, {
1236
- name: "calculateFramesFromRange A"
1237
- }),
1238
- asXL1BlockNumber4(Math.min(i + size - 1, range[1]), {
1239
- name: "calculateFramesFromRange B"
1240
- })
1241
- ]);
1242
- } else {
1243
- remaining.push([
1244
- asXL1BlockNumber4(i, {
1245
- name: "calculateFramesFromRange C"
1246
- }),
1247
- range[1]
1248
- ]);
1249
- }
1250
- }
1251
- return [
1252
- fitted,
1253
- remaining
1254
- ];
1255
- }
1256
- __name(calculateFramesFromRange, "calculateFramesFromRange");
1257
-
1258
- // src/block/primitives/frames/deepCalculateFramesFromRange.ts
1259
- import { StepSizes as StepSizes8 } from "@xyo-network/xl1-protocol";
1260
- function deepCalculateFramesFromRange(range, startingStep = StepSizes8.length - 1) {
1261
- const fitted = [];
1262
- let remaining = [
1263
- range
1264
- ];
1265
- for (let step = startingStep; step >= 0; step--) {
1266
- const newRemaining = [];
1267
- for (const range2 of remaining) {
1268
- const [newFittedFrames, newRemainingFrames] = calculateFramesFromRange(range2, step);
1269
- fitted.push(...newFittedFrames);
1270
- newRemaining.push(...newRemainingFrames);
1271
- }
1272
- remaining = newRemaining;
1273
- }
1274
- for (const range2 of remaining) {
1275
- for (let i = range2[0]; i <= range2[1]; i++) {
1276
- fitted.push([
1277
- i,
1278
- i
1279
- ]);
1280
- }
1281
- }
1282
- return fitted.toSorted((a, b) => a[0] - b[0]);
894
+ return fitted.toSorted((a, b) => a[0] - b[0]);
1283
895
  }
1284
896
  __name(deepCalculateFramesFromRange, "deepCalculateFramesFromRange");
1285
897
 
@@ -1310,11 +922,11 @@ function toStepIdentityString({ block, step }) {
1310
922
  __name(toStepIdentityString, "toStepIdentityString");
1311
923
 
1312
924
  // src/config/Config.ts
1313
- import * as z15 from "zod";
925
+ import * as z16 from "zod";
1314
926
 
1315
927
  // src/config/Api.ts
1316
928
  import { globalRegistry } from "zod";
1317
- import * as z2 from "zod";
929
+ import * as z3 from "zod";
1318
930
 
1319
931
  // src/validation/block/error.ts
1320
932
  import { isValidationError, ValidationError } from "@xyo-network/xl1-protocol";
@@ -1366,8 +978,8 @@ var getUrl = /* @__PURE__ */ __name((host, port) => {
1366
978
  var TODO = true;
1367
979
 
1368
980
  // src/validation/schema/Mnemonic.ts
1369
- import * as z from "zod";
1370
- var MnemonicStringZod = z.string().transform((s) => s.trim().replaceAll(/\s+/g, " ")).refine((s) => [
981
+ import * as z2 from "zod";
982
+ var MnemonicStringZod = z2.string().transform((s) => s.trim().replaceAll(/\s+/g, " ")).refine((s) => [
1371
983
  12,
1372
984
  15,
1373
985
  18,
@@ -1378,16 +990,16 @@ var MnemonicStringZod = z.string().transform((s) => s.trim().replaceAll(/\s+/g,
1378
990
  }).describe("BIP-39 mnemonic string");
1379
991
 
1380
992
  // src/config/Api.ts
1381
- var ApiConfigZod = z2.object({
1382
- host: z2.string().default("localhost").register(globalRegistry, {
993
+ var ApiConfigZod = z3.object({
994
+ host: z3.string().default("localhost").register(globalRegistry, {
1383
995
  default: "localhost",
1384
996
  description: "Host for the API",
1385
997
  title: "api.host",
1386
998
  type: "string"
1387
999
  }),
1388
- initRewardsCache: z2.union([
1389
- z2.number(),
1390
- z2.string()
1000
+ initRewardsCache: z3.union([
1001
+ z3.number(),
1002
+ z3.string()
1391
1003
  ]).transform((v) => v !== "0" && v !== "false").default(true).register(globalRegistry, {
1392
1004
  description: "Whether to initialize the rewards cache on startup",
1393
1005
  title: "api.initRewardsCache",
@@ -1398,7 +1010,7 @@ var ApiConfigZod = z2.object({
1398
1010
  title: "api.mnemonic",
1399
1011
  type: "string"
1400
1012
  }),
1401
- port: z2.coerce.number().default(8080).register(globalRegistry, {
1013
+ port: z3.coerce.number().default(8080).register(globalRegistry, {
1402
1014
  default: 8080,
1403
1015
  description: "Port for the API",
1404
1016
  title: "api.port",
@@ -1408,9 +1020,9 @@ var ApiConfigZod = z2.object({
1408
1020
 
1409
1021
  // src/config/Bridge.ts
1410
1022
  import { globalRegistry as globalRegistry2 } from "zod";
1411
- import * as z3 from "zod";
1412
- var BridgeConfigZod = z3.object({
1413
- host: z3.string().default("localhost").register(globalRegistry2, {
1023
+ import * as z4 from "zod";
1024
+ var BridgeConfigZod = z4.object({
1025
+ host: z4.string().default("localhost").register(globalRegistry2, {
1414
1026
  default: "localhost",
1415
1027
  description: "Host for the Bridge",
1416
1028
  title: "api.host",
@@ -1421,7 +1033,7 @@ var BridgeConfigZod = z3.object({
1421
1033
  title: "api.mnemonic",
1422
1034
  type: "string"
1423
1035
  }),
1424
- port: z3.coerce.number().default(8081).register(globalRegistry2, {
1036
+ port: z4.coerce.number().default(8081).register(globalRegistry2, {
1425
1037
  default: 8081,
1426
1038
  description: "Port for the Bridge",
1427
1039
  title: "api.port",
@@ -1432,9 +1044,9 @@ var BridgeConfigZod = z3.object({
1432
1044
  // src/config/Chain.ts
1433
1045
  import { AddressZod } from "@xylabs/sdk-js";
1434
1046
  import { globalRegistry as globalRegistry3 } from "zod";
1435
- import * as z4 from "zod";
1436
- var ChainConfigZod = z4.object({
1437
- id: z4.string().optional().register(globalRegistry3, {
1047
+ import * as z5 from "zod";
1048
+ var ChainConfigZod = z5.object({
1049
+ id: z5.string().optional().register(globalRegistry3, {
1438
1050
  description: "The unique identifier for the chain. Should be the staking contract address for contract-backed chains.",
1439
1051
  title: "chain.id",
1440
1052
  type: "string"
@@ -1448,28 +1060,28 @@ var ChainConfigZod = z4.object({
1448
1060
 
1449
1061
  // src/config/Evm.ts
1450
1062
  import { globalRegistry as globalRegistry4 } from "zod";
1451
- import * as z5 from "zod";
1452
- var EvmInfuraConfigZod = z5.object({
1453
- projectId: z5.string().optional().register(globalRegistry4, {
1063
+ import * as z6 from "zod";
1064
+ var EvmInfuraConfigZod = z6.object({
1065
+ projectId: z6.string().optional().register(globalRegistry4, {
1454
1066
  description: "Infura project ID",
1455
1067
  title: "evm.infura.projectId",
1456
1068
  type: "string"
1457
1069
  }),
1458
- projectSecret: z5.string().optional().register(globalRegistry4, {
1070
+ projectSecret: z6.string().optional().register(globalRegistry4, {
1459
1071
  description: "Infura project secret",
1460
1072
  title: "evm.infura.projectSecret",
1461
1073
  type: "string"
1462
1074
  })
1463
1075
  });
1464
- var EvmJsonRpcConfigZod = z5.object({
1465
- url: z5.url().optional().register(globalRegistry4, {
1076
+ var EvmJsonRpcConfigZod = z6.object({
1077
+ url: z6.url().optional().register(globalRegistry4, {
1466
1078
  description: "JSON-RPC URL",
1467
1079
  title: "evm.jsonRpc.url",
1468
1080
  type: "string"
1469
1081
  })
1470
1082
  });
1471
- var EvmConfigZod = z5.object({
1472
- chainId: z5.string().optional().register(globalRegistry4, {
1083
+ var EvmConfigZod = z6.object({
1084
+ chainId: z6.string().optional().register(globalRegistry4, {
1473
1085
  description: "EVM chain ID",
1474
1086
  title: "evm.chainId",
1475
1087
  type: "string"
@@ -1481,17 +1093,17 @@ var EvmConfigZod = z5.object({
1481
1093
  // src/config/Log.ts
1482
1094
  import { LogLevel } from "@xylabs/sdk-js";
1483
1095
  import { globalRegistry as globalRegistry5 } from "zod";
1484
- import * as z6 from "zod";
1096
+ import * as z7 from "zod";
1485
1097
  var LogLevels = Object.keys(LogLevel);
1486
- var LogConfigZod = z6.object({
1487
- logLevel: z6.enum(LogLevels).default("info").register(globalRegistry5, {
1098
+ var LogConfigZod = z7.object({
1099
+ logLevel: z7.enum(LogLevels).default("info").register(globalRegistry5, {
1488
1100
  choices: LogLevels,
1489
1101
  default: "info",
1490
1102
  description: "Desired process verbosity",
1491
1103
  title: "logLevel",
1492
1104
  type: "string"
1493
1105
  }),
1494
- silent: z6.boolean().default(false).register(globalRegistry5, {
1106
+ silent: z7.boolean().default(false).register(globalRegistry5, {
1495
1107
  default: false,
1496
1108
  description: "Whether to run in silent mode",
1497
1109
  title: "silent",
@@ -1501,9 +1113,9 @@ var LogConfigZod = z6.object({
1501
1113
 
1502
1114
  // src/config/Mempool.ts
1503
1115
  import { globalRegistry as globalRegistry6 } from "zod";
1504
- import * as z7 from "zod";
1505
- var MempoolConfigZod = z7.object({
1506
- enabled: z7.string().default("false").transform((val, ctx) => {
1116
+ import * as z8 from "zod";
1117
+ var MempoolConfigZod = z8.object({
1118
+ enabled: z8.string().default("false").transform((val, ctx) => {
1507
1119
  const normalized = val.toLowerCase().trim();
1508
1120
  if ([
1509
1121
  "true",
@@ -1522,14 +1134,14 @@ var MempoolConfigZod = z7.object({
1522
1134
  expected: "boolean",
1523
1135
  message: `Invalid boolean value: "${val}". Use true/false, 1/0, yes/no.`
1524
1136
  });
1525
- return z7.NEVER;
1137
+ return z8.NEVER;
1526
1138
  }).register(globalRegistry6, {
1527
1139
  default: "false",
1528
1140
  description: "Enable the Mempool",
1529
1141
  title: "mempool.enabled",
1530
1142
  type: "boolean"
1531
1143
  }),
1532
- host: z7.string().default("localhost").register(globalRegistry6, {
1144
+ host: z8.string().default("localhost").register(globalRegistry6, {
1533
1145
  default: "localhost",
1534
1146
  description: "Host for the Mempool",
1535
1147
  title: "mempool.host",
@@ -1540,7 +1152,7 @@ var MempoolConfigZod = z7.object({
1540
1152
  title: "mempool.mnemonic",
1541
1153
  type: "string"
1542
1154
  }),
1543
- port: z7.coerce.number().default(8083).register(globalRegistry6, {
1155
+ port: z8.coerce.number().default(8083).register(globalRegistry6, {
1544
1156
  default: 8083,
1545
1157
  description: "Port for the Mempool",
1546
1158
  title: "mempool.port",
@@ -1549,38 +1161,38 @@ var MempoolConfigZod = z7.object({
1549
1161
  });
1550
1162
 
1551
1163
  // src/config/Producer.ts
1552
- import { AddressZod as AddressZod2, asAddress as asAddress3 } from "@xylabs/sdk-js";
1164
+ import { AddressZod as AddressZod2, asAddress } from "@xylabs/sdk-js";
1553
1165
  import { globalRegistry as globalRegistry7 } from "zod";
1554
- import * as z8 from "zod";
1555
- var ProducerConfigZod = z8.object({
1556
- allowlist: z8.preprocess((val) => {
1166
+ import * as z9 from "zod";
1167
+ var ProducerConfigZod = z9.object({
1168
+ allowlist: z9.preprocess((val) => {
1557
1169
  if (typeof val === "string") {
1558
- return val.split(",").map((s) => asAddress3(s.trim()));
1170
+ return val.split(",").map((s) => asAddress(s.trim()));
1559
1171
  }
1560
1172
  return val;
1561
- }, z8.array(AddressZod2).optional().register(globalRegistry7, {
1173
+ }, z9.array(AddressZod2).optional().register(globalRegistry7, {
1562
1174
  description: "List of allowed producer addresses, if undefined anyone can participate",
1563
1175
  title: "allowlist",
1564
1176
  type: "array"
1565
1177
  })),
1566
- disableIntentRedeclaration: z8.boolean().optional().register(globalRegistry7, {
1178
+ disableIntentRedeclaration: z9.boolean().optional().register(globalRegistry7, {
1567
1179
  description: "Should the producer skip redeclaring their intent to continue producing blocks",
1568
1180
  title: "producer.disableIntentRedeclaration",
1569
1181
  type: "boolean"
1570
1182
  }),
1571
1183
  // TODO: Port schema
1572
- healthCheckPort: z8.coerce.number().optional().register(globalRegistry7, {
1184
+ healthCheckPort: z9.coerce.number().optional().register(globalRegistry7, {
1573
1185
  description: "Port for the Producer health checks",
1574
1186
  title: "producer.healthCheckPort",
1575
1187
  type: "number"
1576
1188
  }),
1577
- heartbeatInterval: z8.coerce.number().default(36e5).register(globalRegistry7, {
1189
+ heartbeatInterval: z9.coerce.number().default(36e5).register(globalRegistry7, {
1578
1190
  description: "The number of milliseconds between heartbeats if no blocks are produced",
1579
1191
  title: "producer.heartbeatInterval",
1580
1192
  type: "number"
1581
1193
  }),
1582
1194
  // TODO: BigInt schema
1583
- minStake: z8.coerce.number().default(1).register(globalRegistry7, {
1195
+ minStake: z9.coerce.number().default(1).register(globalRegistry7, {
1584
1196
  description: "Minimum stake required to be a Producer",
1585
1197
  title: "producer.minStake",
1586
1198
  type: "number"
@@ -1591,14 +1203,14 @@ var ProducerConfigZod = z8.object({
1591
1203
  type: "string"
1592
1204
  }),
1593
1205
  // TODO: Port schema
1594
- port: z8.coerce.number().default(8081).register(globalRegistry7, {
1206
+ port: z9.coerce.number().default(8081).register(globalRegistry7, {
1595
1207
  default: 8081,
1596
1208
  description: "Port for the Producer",
1597
1209
  title: "producer.port",
1598
1210
  type: "number"
1599
1211
  }),
1600
1212
  // TODO: Address schema
1601
- rewardAddress: z8.string().optional().register(globalRegistry7, {
1213
+ rewardAddress: z9.string().optional().register(globalRegistry7, {
1602
1214
  description: "Address to receive block rewards",
1603
1215
  title: "producer.rewardAddress",
1604
1216
  type: "string"
@@ -1607,15 +1219,15 @@ var ProducerConfigZod = z8.object({
1607
1219
 
1608
1220
  // src/config/RewardRedemptionApi.ts
1609
1221
  import { globalRegistry as globalRegistry8 } from "zod";
1610
- import * as z9 from "zod";
1611
- var RewardRedemptionApiConfigZod = z9.object({
1612
- chainRpcApiUrl: z9.string().default("http://localhost:8080/rpc").register(globalRegistry8, {
1222
+ import * as z10 from "zod";
1223
+ var RewardRedemptionApiConfigZod = z10.object({
1224
+ chainRpcApiUrl: z10.string().default("http://localhost:8080/rpc").register(globalRegistry8, {
1613
1225
  default: "http://localhost:8080/rpc",
1614
1226
  description: "URL for the Chain RPC API",
1615
1227
  title: "rewardRedemptionApi.chainRpcApiUrl",
1616
1228
  type: "string"
1617
1229
  }),
1618
- host: z9.string().default("localhost").register(globalRegistry8, {
1230
+ host: z10.string().default("localhost").register(globalRegistry8, {
1619
1231
  default: "localhost",
1620
1232
  description: "Host for the Redemption API",
1621
1233
  title: "rewardRedemptionApi.host",
@@ -1626,7 +1238,7 @@ var RewardRedemptionApiConfigZod = z9.object({
1626
1238
  title: "rewardRedemptionApi.mnemonic",
1627
1239
  type: "string"
1628
1240
  }),
1629
- port: z9.coerce.number().default(8082).register(globalRegistry8, {
1241
+ port: z10.coerce.number().default(8082).register(globalRegistry8, {
1630
1242
  default: 8082,
1631
1243
  description: "Port for the Redemption API",
1632
1244
  title: "rewardRedemptionApi.port",
@@ -1636,14 +1248,14 @@ var RewardRedemptionApiConfigZod = z9.object({
1636
1248
 
1637
1249
  // src/config/Services.ts
1638
1250
  import { globalRegistry as globalRegistry9 } from "zod";
1639
- import * as z10 from "zod";
1640
- var ServicesConfigZod = z10.object({
1641
- accountBalanceViewerEndpoint: z10.string().optional().register(globalRegistry9, {
1251
+ import * as z11 from "zod";
1252
+ var ServicesConfigZod = z11.object({
1253
+ accountBalanceViewerEndpoint: z11.string().optional().register(globalRegistry9, {
1642
1254
  description: "Endpoint of the API to use for instantiating an external AccountBalanceViewer",
1643
1255
  title: "services.accountBalanceViewerEndpoint",
1644
1256
  type: "string"
1645
1257
  }),
1646
- apiEndpoint: z10.string().optional().register(globalRegistry9, {
1258
+ apiEndpoint: z11.string().optional().register(globalRegistry9, {
1647
1259
  description: "Endpoint of the API to use for instantiating an external Viewers",
1648
1260
  title: "services.apiEndpoint",
1649
1261
  type: "string"
@@ -1651,36 +1263,36 @@ var ServicesConfigZod = z10.object({
1651
1263
  });
1652
1264
 
1653
1265
  // src/config/storage/driver/Mongo.ts
1654
- import { isDefined as isDefined10, isUndefined as isUndefined2 } from "@xylabs/sdk-js";
1266
+ import { isDefined as isDefined7, isUndefined as isUndefined2 } from "@xylabs/sdk-js";
1655
1267
  import { globalRegistry as globalRegistry10 } from "zod";
1656
- import * as z11 from "zod";
1268
+ import * as z12 from "zod";
1657
1269
  var hasMongoConfig = /* @__PURE__ */ __name((config) => {
1658
1270
  if (isUndefined2(config)) return false;
1659
- return isDefined10(config.connectionString) && isDefined10(config.database) && isDefined10(config.domain) && isDefined10(config.password) && isDefined10(config.username);
1271
+ return isDefined7(config.connectionString) && isDefined7(config.database) && isDefined7(config.domain) && isDefined7(config.password) && isDefined7(config.username);
1660
1272
  }, "hasMongoConfig");
1661
- var MongoConfigZod = z11.object({
1273
+ var MongoConfigZod = z12.object({
1662
1274
  // TODO: Create from other arguments
1663
- connectionString: z11.string().nonempty().optional().register(globalRegistry10, {
1275
+ connectionString: z12.string().nonempty().optional().register(globalRegistry10, {
1664
1276
  description: "MongoDB connection string",
1665
1277
  title: "storage.mongo.connectionString",
1666
1278
  type: "string"
1667
1279
  }),
1668
- database: z11.string().nonempty().optional().register(globalRegistry10, {
1280
+ database: z12.string().nonempty().optional().register(globalRegistry10, {
1669
1281
  description: "MongoDB database name",
1670
1282
  title: "storage.mongo.database",
1671
1283
  type: "string"
1672
1284
  }),
1673
- domain: z11.string().nonempty().optional().register(globalRegistry10, {
1285
+ domain: z12.string().nonempty().optional().register(globalRegistry10, {
1674
1286
  description: "MongoDB domain",
1675
1287
  title: "storage.mongo.domain",
1676
1288
  type: "string"
1677
1289
  }),
1678
- password: z11.string().nonempty().optional().register(globalRegistry10, {
1290
+ password: z12.string().nonempty().optional().register(globalRegistry10, {
1679
1291
  description: "MongoDB password",
1680
1292
  title: "storage.mongo.password",
1681
1293
  type: "string"
1682
1294
  }),
1683
- username: z11.string().nonempty().optional().register(globalRegistry10, {
1295
+ username: z12.string().nonempty().optional().register(globalRegistry10, {
1684
1296
  description: "MongoDB username",
1685
1297
  title: "storage.mongo.username",
1686
1298
  type: "string"
@@ -1689,10 +1301,10 @@ var MongoConfigZod = z11.object({
1689
1301
 
1690
1302
  // src/config/storage/Storage.ts
1691
1303
  import { globalRegistry as globalRegistry11 } from "zod";
1692
- import * as z12 from "zod";
1693
- var StorageConfigZod = z12.object({
1304
+ import * as z13 from "zod";
1305
+ var StorageConfigZod = z13.object({
1694
1306
  mongo: MongoConfigZod.optional().describe("Configuration for the MongoD storage driver"),
1695
- root: z12.string().optional().register(globalRegistry11, {
1307
+ root: z13.string().optional().register(globalRegistry11, {
1696
1308
  description: "Root directory for local storage",
1697
1309
  title: "storage.root",
1698
1310
  type: "string"
@@ -1701,33 +1313,33 @@ var StorageConfigZod = z12.object({
1701
1313
 
1702
1314
  // src/config/Telemetry.ts
1703
1315
  import { globalRegistry as globalRegistry12 } from "zod";
1704
- import * as z13 from "zod";
1705
- var MetricsScrapeConfigZod = z13.object({
1706
- path: z13.string().default("/metrics").register(globalRegistry12, {
1316
+ import * as z14 from "zod";
1317
+ var MetricsScrapeConfigZod = z14.object({
1318
+ path: z14.string().default("/metrics").register(globalRegistry12, {
1707
1319
  default: "/metrics",
1708
1320
  description: "Path for the metrics scrape endpoint",
1709
1321
  title: "telemetry.metrics.scrape.path",
1710
1322
  type: "string"
1711
1323
  }),
1712
- port: z13.coerce.number().default(9464).register(globalRegistry12, {
1324
+ port: z14.coerce.number().default(9464).register(globalRegistry12, {
1713
1325
  default: 9464,
1714
1326
  description: "Port for the metrics scrape endpoint",
1715
1327
  title: "telemetry.metrics.scrape.port",
1716
1328
  type: "number"
1717
1329
  })
1718
1330
  }).describe("Metrics scrape configuration");
1719
- var MetricsConfigZod = z13.object({
1331
+ var MetricsConfigZod = z14.object({
1720
1332
  scrape: MetricsScrapeConfigZod
1721
1333
  }).describe("Metrics configuration options");
1722
- var OpenTelemetryConfigZod = z13.object({
1334
+ var OpenTelemetryConfigZod = z14.object({
1723
1335
  // OpenTelemetry options
1724
- otlpEndpoint: z13.url().optional().register(globalRegistry12, {
1336
+ otlpEndpoint: z14.url().optional().register(globalRegistry12, {
1725
1337
  description: "OTLP endpoint for exporting telemetry data",
1726
1338
  title: "telemetry.otel.otlpEndpoint",
1727
1339
  type: "string"
1728
1340
  })
1729
1341
  });
1730
- var TelemetryConfigZod = z13.object({
1342
+ var TelemetryConfigZod = z14.object({
1731
1343
  // Metrics configuration
1732
1344
  metrics: MetricsConfigZod.optional().describe("Metrics configuration"),
1733
1345
  // OpenTelemetry configuration
@@ -1735,26 +1347,26 @@ var TelemetryConfigZod = z13.object({
1735
1347
  }).describe("Telemetry configuration options");
1736
1348
 
1737
1349
  // src/config/Validation.ts
1738
- import { AddressZod as AddressZod3, asAddress as asAddress4 } from "@xylabs/sdk-js";
1350
+ import { AddressZod as AddressZod3, asAddress as asAddress2 } from "@xylabs/sdk-js";
1739
1351
  import { globalRegistry as globalRegistry13 } from "zod";
1740
- import * as z14 from "zod";
1741
- var ValidationConfigZod = z14.object({
1742
- allowedRewardRedeemers: z14.preprocess((val) => {
1352
+ import * as z15 from "zod";
1353
+ var ValidationConfigZod = z15.object({
1354
+ allowedRewardRedeemers: z15.preprocess((val) => {
1743
1355
  if (typeof val === "string") {
1744
- return val.split(",").map((s) => asAddress4(s.trim()));
1356
+ return val.split(",").map((s) => asAddress2(s.trim()));
1745
1357
  }
1746
1358
  return val;
1747
- }, z14.array(AddressZod3).optional().register(globalRegistry13, {
1359
+ }, z15.array(AddressZod3).optional().register(globalRegistry13, {
1748
1360
  description: "List of allowed reward redeemer addresses, if undefined anyone can participate",
1749
1361
  title: "allowedRewardRedeemers",
1750
1362
  type: "array"
1751
1363
  })),
1752
- allowedRewardEscrowAccountSigners: z14.preprocess((val) => {
1364
+ allowedRewardEscrowAccountSigners: z15.preprocess((val) => {
1753
1365
  if (typeof val === "string") {
1754
- return val.split(",").map((s) => asAddress4(s.trim()));
1366
+ return val.split(",").map((s) => asAddress2(s.trim()));
1755
1367
  }
1756
1368
  return val;
1757
- }, z14.array(AddressZod3).optional().register(globalRegistry13, {
1369
+ }, z15.array(AddressZod3).optional().register(globalRegistry13, {
1758
1370
  description: "List of allowed reward escrow account signer addresses, if undefined anyone can participate",
1759
1371
  title: "allowedRewardEscrowAccountSigners",
1760
1372
  type: "array"
@@ -1762,10 +1374,10 @@ var ValidationConfigZod = z14.object({
1762
1374
  });
1763
1375
 
1764
1376
  // src/config/Config.ts
1765
- var Xl1CommonConfigSchema = z15.object({
1377
+ var Xl1CommonConfigSchema = z16.object({
1766
1378
  ...LogConfigZod.shape
1767
1379
  }).describe("XL1 common configuration options");
1768
- var ConfigZod = z15.object({
1380
+ var ConfigZod = z16.object({
1769
1381
  ...Xl1CommonConfigSchema.shape,
1770
1382
  api: ApiConfigZod.default(ApiConfigZod.parse({})).describe("Configuration for the API node"),
1771
1383
  bridge: BridgeConfigZod.default(BridgeConfigZod.parse({})).describe("Configuration for the Bridge node"),
@@ -1782,35 +1394,35 @@ var ConfigZod = z15.object({
1782
1394
  var getDefaultConfig = /* @__PURE__ */ __name(() => ConfigZod.parse({}), "getDefaultConfig");
1783
1395
 
1784
1396
  // src/config/UsageMeta.ts
1785
- import * as z16 from "zod";
1786
- var DescriptionSchema = z16.string();
1787
- var TitleSchema = z16.string();
1788
- var JSONSchemaMetaSchema = z16.object({
1789
- id: z16.string().optional(),
1397
+ import * as z17 from "zod";
1398
+ var DescriptionSchema = z17.string();
1399
+ var TitleSchema = z17.string();
1400
+ var JSONSchemaMetaSchema = z17.object({
1401
+ id: z17.string().optional(),
1790
1402
  title: TitleSchema.optional(),
1791
1403
  description: DescriptionSchema.optional(),
1792
- deprecated: z16.boolean().optional()
1793
- }).catchall(z16.unknown());
1404
+ deprecated: z17.boolean().optional()
1405
+ }).catchall(z17.unknown());
1794
1406
  var GlobalMetaSchema = JSONSchemaMetaSchema.extend({});
1795
- var ChoicesSchema = z16.array(z16.union([
1796
- z16.string(),
1797
- z16.number(),
1798
- z16.literal(true),
1799
- z16.undefined()
1407
+ var ChoicesSchema = z17.array(z17.union([
1408
+ z17.string(),
1409
+ z17.number(),
1410
+ z17.literal(true),
1411
+ z17.undefined()
1800
1412
  ])).readonly();
1801
1413
  var UsageMetaSchema = GlobalMetaSchema.extend({
1802
1414
  choices: ChoicesSchema.optional(),
1803
- default: z16.unknown().optional(),
1415
+ default: z17.unknown().optional(),
1804
1416
  description: DescriptionSchema,
1805
- group: z16.string().optional(),
1806
- hidden: z16.boolean().optional(),
1417
+ group: z17.string().optional(),
1418
+ hidden: z17.boolean().optional(),
1807
1419
  title: TitleSchema,
1808
- type: z16.union([
1809
- z16.literal("array"),
1810
- z16.literal("count"),
1811
- z16.literal("boolean"),
1812
- z16.literal("number"),
1813
- z16.literal("string")
1420
+ type: z17.union([
1421
+ z17.literal("array"),
1422
+ z17.literal("count"),
1423
+ z17.literal("boolean"),
1424
+ z17.literal("number"),
1425
+ z17.literal("string")
1814
1426
  ])
1815
1427
  });
1816
1428
  function isUsageMeta(v) {
@@ -1823,62 +1435,62 @@ var XL1_NETWORK_STAKING_GENESIS_PERIOD_END_EPOCH = 1760572800;
1823
1435
  var XL1_NETWORK_STAKING_GENESIS_PERIOD_END_XL1_BLOCK = 107496;
1824
1436
 
1825
1437
  // src/eip-712/Payloads/EIP712Data.ts
1826
- import { AsObjectFactory as AsObjectFactory5 } from "@xylabs/sdk-js";
1438
+ import { AsObjectFactory } from "@xylabs/sdk-js";
1827
1439
  import { isPayloadOfZodType } from "@xyo-network/payload-model";
1828
- import z18 from "zod";
1440
+ import z19 from "zod";
1829
1441
 
1830
1442
  // src/eip-712/Types.ts
1831
- import z17 from "zod";
1832
- var TypedDataDomainZod = z17.object({
1833
- name: z17.string().nullable().optional(),
1834
- version: z17.string().nullable().optional(),
1835
- chainId: z17.union([
1836
- z17.string(),
1837
- z17.number(),
1838
- z17.bigint()
1443
+ import z18 from "zod";
1444
+ var TypedDataDomainZod = z18.object({
1445
+ name: z18.string().nullable().optional(),
1446
+ version: z18.string().nullable().optional(),
1447
+ chainId: z18.union([
1448
+ z18.string(),
1449
+ z18.number(),
1450
+ z18.bigint()
1839
1451
  ]).nullable().optional(),
1840
- verifyingContract: z17.string().nullable().optional(),
1841
- salt: z17.union([
1842
- z17.string(),
1843
- z17.instanceof(Uint8Array)
1452
+ verifyingContract: z18.string().nullable().optional(),
1453
+ salt: z18.union([
1454
+ z18.string(),
1455
+ z18.instanceof(Uint8Array)
1844
1456
  ]).nullable().optional()
1845
1457
  });
1846
- var TypedDataFieldZod = z17.object({
1847
- name: z17.string(),
1848
- type: z17.string()
1458
+ var TypedDataFieldZod = z18.object({
1459
+ name: z18.string(),
1460
+ type: z18.string()
1849
1461
  });
1850
- var TypedDataTypesZod = z17.record(z17.string(), z17.array(TypedDataFieldZod));
1851
- var TypedDataValueZod = z17.record(z17.string(), z17.any());
1462
+ var TypedDataTypesZod = z18.record(z18.string(), z18.array(TypedDataFieldZod));
1463
+ var TypedDataValueZod = z18.record(z18.string(), z18.any());
1852
1464
 
1853
1465
  // src/eip-712/Payloads/EIP712Data.ts
1854
- var EIP712DataPayloadFieldsZod = z18.object({
1466
+ var EIP712DataPayloadFieldsZod = z19.object({
1855
1467
  domain: TypedDataDomainZod,
1856
1468
  types: TypedDataTypesZod,
1857
1469
  values: TypedDataValueZod
1858
1470
  });
1859
1471
  var EIP712DataPayloadSchema = "network.xyo.chains.ethereum.eip712.data";
1860
1472
  var isEIP712DataPayload = isPayloadOfZodType(EIP712DataPayloadFieldsZod, EIP712DataPayloadSchema);
1861
- var asEIP712DataPayload = AsObjectFactory5.create(isEIP712DataPayload);
1473
+ var asEIP712DataPayload = AsObjectFactory.create(isEIP712DataPayload);
1862
1474
 
1863
1475
  // src/eip-712/Payloads/EIP712Signature.ts
1864
- import { AsObjectFactory as AsObjectFactory6, HashZod } from "@xylabs/sdk-js";
1476
+ import { AsObjectFactory as AsObjectFactory2, HashZod as HashZod2 } from "@xylabs/sdk-js";
1865
1477
  import { isPayloadOfZodType as isPayloadOfZodType2 } from "@xyo-network/payload-model";
1866
- import z19 from "zod";
1867
- var EIP712SignaturePayloadFieldsZod = z19.object({
1868
- address: z19.string(),
1869
- hash: HashZod,
1870
- signature: z19.string()
1478
+ import z20 from "zod";
1479
+ var EIP712SignaturePayloadFieldsZod = z20.object({
1480
+ address: z20.string(),
1481
+ hash: HashZod2,
1482
+ signature: z20.string()
1871
1483
  });
1872
1484
  var EIP712SignaturePayloadSchema = "network.xyo.chains.ethereum.eip712.signature";
1873
1485
  var isEIP712SignaturePayload = isPayloadOfZodType2(EIP712SignaturePayloadFieldsZod, EIP712SignaturePayloadSchema);
1874
- var asEIP712SignaturePayload = AsObjectFactory6.create(isEIP712SignaturePayload);
1486
+ var asEIP712SignaturePayload = AsObjectFactory2.create(isEIP712SignaturePayload);
1875
1487
 
1876
1488
  // src/eip-712/sign.ts
1877
- import { PayloadBuilder as PayloadBuilder10 } from "@xyo-network/payload-builder";
1489
+ import { PayloadBuilder as PayloadBuilder9 } from "@xyo-network/payload-builder";
1878
1490
  var signEIP712Message = /* @__PURE__ */ __name(async (signer, data) => {
1879
1491
  const { domain, types, values } = data;
1880
1492
  const signature = await signer.signTypedData(domain, types, values);
1881
- const hash = await PayloadBuilder10.hash(data);
1493
+ const hash = await PayloadBuilder9.hash(data);
1882
1494
  const address = await signer.getAddress();
1883
1495
  return {
1884
1496
  address,
@@ -1890,44 +1502,513 @@ var signEIP712Message = /* @__PURE__ */ __name(async (signer, data) => {
1890
1502
 
1891
1503
  // src/eip-712/verify.ts
1892
1504
  import { asHash as asHash4, isUndefined as isUndefined3 } from "@xylabs/sdk-js";
1893
- import { PayloadBuilder as PayloadBuilder11 } from "@xyo-network/payload-builder";
1505
+ import { PayloadBuilder as PayloadBuilder10 } from "@xyo-network/payload-builder";
1894
1506
  import { verifyTypedData } from "ethers/hash";
1895
1507
  var verifyEIP712Message = /* @__PURE__ */ __name(async (data, sig) => {
1896
1508
  const { address, signature, hash } = sig;
1897
1509
  const { schema, ...fields } = data;
1898
1510
  const signedHash = asHash4(hash);
1899
- if (isUndefined3(signedHash) || signedHash !== await PayloadBuilder11.hash(data)) return false;
1511
+ if (isUndefined3(signedHash) || signedHash !== await PayloadBuilder10.hash(data)) return false;
1900
1512
  const recoveredAddress = verifyTypedData(fields.domain, fields.types, fields.values, signature);
1901
1513
  return recoveredAddress.toLowerCase() === address.toLowerCase();
1902
1514
  }, "verifyEIP712Message");
1903
1515
 
1904
- // src/multipliers.ts
1905
- import { asAttoXL1 } from "@xyo-network/xl1-protocol";
1906
- var XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_EARNED_REWARDS = asAttoXL1(1343884111859145740576652n);
1907
- var XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_BONUS_REWARDS = asAttoXL1(100000000000000000000000000n);
1908
- var XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_REWARDS = XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_EARNED_REWARDS + XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_BONUS_REWARDS;
1909
- var RewardMultipliers = {
1910
- [`0|${XL1_NETWORK_STAKING_GENESIS_PERIOD_END_XL1_BLOCK}`]: [
1911
- XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_BONUS_REWARDS,
1912
- XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_EARNED_REWARDS
1913
- ]
1914
- };
1516
+ // src/multipliers.ts
1517
+ import { asAttoXL1 as asAttoXL12 } from "@xyo-network/xl1-protocol";
1518
+ var XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_EARNED_REWARDS = asAttoXL12(1343884111859145740576652n);
1519
+ var XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_BONUS_REWARDS = asAttoXL12(100000000000000000000000000n);
1520
+ var XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_REWARDS = XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_EARNED_REWARDS + XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_BONUS_REWARDS;
1521
+ var RewardMultipliers = {
1522
+ [`0|${XL1_NETWORK_STAKING_GENESIS_PERIOD_END_XL1_BLOCK}`]: [
1523
+ XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_BONUS_REWARDS,
1524
+ XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_EARNED_REWARDS
1525
+ ]
1526
+ };
1527
+
1528
+ // src/payloads/AddressPairPayload.ts
1529
+ import { AsObjectFactory as AsObjectFactory3 } from "@xylabs/sdk-js";
1530
+ import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
1531
+ var AddressPairSchema = "network.xyo.address.pair";
1532
+ var isAddressPairPayload = isPayloadOfSchemaType(AddressPairSchema);
1533
+ var asAddressPairPayload = AsObjectFactory3.create(isAddressPairPayload);
1534
+ var asOptionalAddressPairPayload = AsObjectFactory3.createOptional(isAddressPairPayload);
1535
+
1536
+ // src/payloads/netBalancesForPayloads.ts
1537
+ import { hexToBigInt, toAddress as toAddress3 } from "@xylabs/sdk-js";
1538
+ import { span } from "@xylabs/telemetry";
1539
+ import { isTransfer } from "@xyo-network/xl1-protocol";
1540
+ var netBalancesForPayloads = /* @__PURE__ */ __name((payloads) => {
1541
+ return span("netBalancesForPayloads", () => {
1542
+ const balances = {};
1543
+ for (const payload of payloads) {
1544
+ if (isTransfer(payload)) {
1545
+ const { from } = payload;
1546
+ for (let [address, amount] of Object.entries(payload.transfers)) {
1547
+ balances[toAddress3(address)] = (balances[toAddress3(address)] ?? 0n) + hexToBigInt(amount);
1548
+ balances[toAddress3(from)] = (balances[toAddress3(from)] ?? 0n) - hexToBigInt(amount);
1549
+ }
1550
+ }
1551
+ }
1552
+ return balances;
1553
+ });
1554
+ }, "netBalancesForPayloads");
1555
+
1556
+ // src/payloads/netSchemasForPayloads.ts
1557
+ import { hexToBigInt as hexToBigInt2, toAddress as toAddress4 } from "@xylabs/sdk-js";
1558
+ import { span as span2 } from "@xylabs/telemetry";
1559
+ import { isTransfer as isTransfer2 } from "@xyo-network/xl1-protocol";
1560
+ var netSchemasForPayloads = /* @__PURE__ */ __name((payloads) => {
1561
+ return span2("netSchemasForPayloads", () => {
1562
+ const balances = {};
1563
+ for (const payload of payloads) {
1564
+ if (isTransfer2(payload)) {
1565
+ const { from } = payload;
1566
+ for (let [address, amount] of Object.entries(payload.transfers)) {
1567
+ balances[toAddress4(address)] = (balances[toAddress4(address)] ?? 0n) + hexToBigInt2(amount);
1568
+ balances[toAddress4(from)] = (balances[toAddress4(from)] ?? 0n) - hexToBigInt2(amount);
1569
+ }
1570
+ }
1571
+ }
1572
+ return balances;
1573
+ });
1574
+ }, "netSchemasForPayloads");
1575
+
1576
+ // src/payloads/netTransfersForPayloads.ts
1577
+ import { hexToBigInt as hexToBigInt3 } from "@xylabs/sdk-js";
1578
+ import { span as span3 } from "@xylabs/telemetry";
1579
+ import { isTransfer as isTransfer3 } from "@xyo-network/xl1-protocol";
1580
+ function netTransfersForPayloads(payloads) {
1581
+ return span3("netTransfersForPayloads", () => {
1582
+ const transfers = {};
1583
+ for (const payload of payloads) {
1584
+ if (isTransfer3(payload)) {
1585
+ const { from } = payload;
1586
+ transfers[from] = transfers[from] ?? {};
1587
+ for (let [to, amount] of Object.entries(payload.transfers)) {
1588
+ transfers[to] = transfers[to] ?? {};
1589
+ transfers[to][from] = (transfers[to][from] ?? 0n) + hexToBigInt3(amount);
1590
+ transfers[from][to] = (transfers[from][to] ?? 0n) - hexToBigInt3(amount);
1591
+ }
1592
+ }
1593
+ }
1594
+ return transfers;
1595
+ });
1596
+ }
1597
+ __name(netTransfersForPayloads, "netTransfersForPayloads");
1598
+
1599
+ // src/services/StakeIntentService/ChainIndexingServiceStateSchema.ts
1600
+ import { AsObjectFactory as AsObjectFactory4 } from "@xylabs/sdk-js";
1601
+ import { isPayloadOfSchemaType as isPayloadOfSchemaType2, isStorageMeta } from "@xyo-network/payload-model";
1602
+ var ChainIndexingServiceStateSchema = "network.xyo.chain.indexing.service.state";
1603
+ var isChainIndexingServiceState = /* @__PURE__ */ __name((payload) => {
1604
+ return isPayloadOfSchemaType2(ChainIndexingServiceStateSchema)(payload);
1605
+ }, "isChainIndexingServiceState");
1606
+ var asChainIndexingServiceState = AsObjectFactory4.create(isChainIndexingServiceState);
1607
+ var isChainIndexingServiceStateWithStorageMeta = /* @__PURE__ */ __name((value) => isChainIndexingServiceState(value) && isStorageMeta(value), "isChainIndexingServiceStateWithStorageMeta");
1608
+ var asChainIndexingServiceStateWithStorageMeta = AsObjectFactory4.create(isChainIndexingServiceStateWithStorageMeta);
1609
+
1610
+ // src/SignedBigInt.ts
1611
+ import { hexToBigInt as hexToBigInt4, toHex as toHex3 } from "@xylabs/sdk-js";
1612
+ import { isObject } from "@xylabs/sdk-js";
1613
+ var isNegativeBigInt = /* @__PURE__ */ __name((value) => {
1614
+ return isObject(value) && "negative" in value && typeof value.negative === "string";
1615
+ }, "isNegativeBigInt");
1616
+ var isPositiveBigInt = /* @__PURE__ */ __name((value) => {
1617
+ return isObject(value) && "positive" in value && typeof value.positive === "string";
1618
+ }, "isPositiveBigInt");
1619
+ var parseSignedBigInt = /* @__PURE__ */ __name((value) => {
1620
+ if (isNegativeBigInt(value)) {
1621
+ return -hexToBigInt4(value.negative);
1622
+ } else if (isPositiveBigInt(value)) {
1623
+ return hexToBigInt4(value.positive);
1624
+ } else {
1625
+ throw new Error("Invalid balance type");
1626
+ }
1627
+ }, "parseSignedBigInt");
1628
+ var toSignedBigInt = /* @__PURE__ */ __name((value) => {
1629
+ return value < 0n ? {
1630
+ negative: toHex3(-value)
1631
+ } : {
1632
+ positive: toHex3(value)
1633
+ };
1634
+ }, "toSignedBigInt");
1635
+ var toPositiveBigInt = /* @__PURE__ */ __name((value) => {
1636
+ if (isNegativeBigInt(value)) {
1637
+ return {
1638
+ positive: toHex3(0n)
1639
+ };
1640
+ }
1641
+ if (isPositiveBigInt(value)) {
1642
+ return {
1643
+ positive: value.positive
1644
+ };
1645
+ }
1646
+ if (typeof value === "bigint") {
1647
+ return {
1648
+ positive: toHex3(value)
1649
+ };
1650
+ }
1651
+ throw new Error("Invalid value for positive big int");
1652
+ }, "toPositiveBigInt");
1653
+
1654
+ // src/simple/accountBalance/SimpleAccountBalanceViewer.ts
1655
+ import { AbstractCreatable, asHash as asHash5, assertEx as assertEx13, exists, isDefined as isDefined11 } from "@xylabs/sdk-js";
1656
+ import { spanRootAsync as spanRootAsync4 } from "@xylabs/telemetry";
1657
+ import { asRange, asXL1BlockNumber as asXL1BlockNumber5, asXL1BlockRange as asXL1BlockRange5, AttoXL1 as AttoXL12, StepSizes as StepSizes9, TransferSchema } from "@xyo-network/xl1-protocol";
1658
+
1659
+ // src/summary/model/BalancesStepSummary.ts
1660
+ import { AsObjectFactory as AsObjectFactory5 } from "@xylabs/sdk-js";
1661
+ import { isPayloadOfSchemaType as isPayloadOfSchemaType3, isStorageMeta as isStorageMeta2 } from "@xyo-network/payload-model";
1662
+ var BalancesStepSummarySchema = "network.xyo.step.summary.balances";
1663
+ var isBalancesStepSummary = isPayloadOfSchemaType3(BalancesStepSummarySchema);
1664
+ var asBalancesStepSummary = AsObjectFactory5.create(isBalancesStepSummary);
1665
+ var isBalancesStepSummaryWithStorageMeta = /* @__PURE__ */ __name((value) => {
1666
+ return isBalancesStepSummary(value) && isStorageMeta2(value);
1667
+ }, "isBalancesStepSummaryWithStorageMeta");
1668
+ var asBalancesStepSummaryWithStorageMeta = AsObjectFactory5.create(isBalancesStepSummaryWithStorageMeta);
1669
+
1670
+ // src/summary/model/SchemasStepSummary.ts
1671
+ import { AsObjectFactory as AsObjectFactory6 } from "@xylabs/sdk-js";
1672
+ import { isPayloadOfSchemaType as isPayloadOfSchemaType4, isStorageMeta as isStorageMeta3 } from "@xyo-network/payload-model";
1673
+ var SchemasStepSummarySchema = "network.xyo.step.summary.schemas";
1674
+ var isSchemasStepSummary = isPayloadOfSchemaType4(SchemasStepSummarySchema);
1675
+ var asSchemasStepSummary = AsObjectFactory6.create(isSchemasStepSummary);
1676
+ var isSchemasStepSummaryWithStorageMeta = /* @__PURE__ */ __name((value) => {
1677
+ return isSchemasStepSummary(value) && isStorageMeta3(value);
1678
+ }, "isSchemasStepSummaryWithStorageMeta");
1679
+ var asSchemasStepSummaryWithStorageMeta = AsObjectFactory6.create(isSchemasStepSummaryWithStorageMeta);
1680
+
1681
+ // src/summary/model/StepSummary.ts
1682
+ var StepSummarySchema = "network.xyo.step.summary";
1683
+
1684
+ // src/summary/model/TransfersSummary.ts
1685
+ import { AsObjectFactory as AsObjectFactory7 } from "@xylabs/sdk-js";
1686
+ import { isPayloadOfSchemaType as isPayloadOfSchemaType5, isStorageMeta as isStorageMeta4 } from "@xyo-network/payload-model";
1687
+ var TransfersStepSummarySchema = "network.xyo.step.summary.transfer";
1688
+ var isTransfersStepSummary = isPayloadOfSchemaType5(TransfersStepSummarySchema);
1689
+ var asTransfersStepSummary = AsObjectFactory7.create(isTransfersStepSummary);
1690
+ var isTransfersStepSummaryWithStorageMeta = /* @__PURE__ */ __name((value) => {
1691
+ return isTransfersStepSummary(value) && isStorageMeta4(value);
1692
+ }, "isTransfersStepSummaryWithStorageMeta");
1693
+ var asTransfersStepSummaryWithStorageMeta = AsObjectFactory7.create(isTransfersStepSummaryWithStorageMeta);
1694
+
1695
+ // src/summary/primitives/balances/balancesStepSummaryFromRange.ts
1696
+ import { assertEx as assertEx10 } from "@xylabs/sdk-js";
1697
+ import { PayloadBuilder as PayloadBuilder11 } from "@xyo-network/payload-builder";
1698
+ import { isAnyPayload } from "@xyo-network/payload-model";
1699
+ import { StepSizes as StepSizes6 } from "@xyo-network/xl1-protocol";
1700
+ async function balancesStepSummaryFromRange(context, range) {
1701
+ const frameHeadHash = await hashFromBlockNumber(context, range[1]);
1702
+ const frameSize = range[1] - range[0] + 1;
1703
+ const [headHash] = await context.head();
1704
+ let result = void 0;
1705
+ if (frameSize === 1) {
1706
+ const hash = await hashFromBlockNumber(context, range[0]);
1707
+ const [, payloads] = await hydrateBlock(context.store, hash);
1708
+ const balances = {};
1709
+ for (const [address, balance] of Object.entries(netBalancesForPayloads(payloads))) {
1710
+ balances[address] = toSignedBigInt(balance);
1711
+ }
1712
+ result = {
1713
+ schema: BalancesStepSummarySchema,
1714
+ hash: headHash,
1715
+ stepSize: -1,
1716
+ balances
1717
+ };
1718
+ } else {
1719
+ const step = StepSizes6.indexOf(frameSize);
1720
+ assertEx10(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes6.join(", ")}`);
1721
+ const summaryResult = await context.summaryMap.get(`${frameHeadHash}|${frameSize}`);
1722
+ if (isAnyPayload(summaryResult)) {
1723
+ result = summaryResult;
1724
+ } else {
1725
+ await context.stepSemaphores[step].acquire();
1726
+ try {
1727
+ const subRanges = deepCalculateFramesFromRange(range, step - 1);
1728
+ const promises = subRanges.map((subRange) => balancesStepSummaryFromRange(context, subRange));
1729
+ const subResults = await Promise.all(promises);
1730
+ const bigIntBalances = {};
1731
+ for (const subResult of subResults) {
1732
+ for (const [address, balance] of Object.entries(subResult.balances)) {
1733
+ bigIntBalances[address] = (bigIntBalances[address] ?? 0n) + parseSignedBigInt(balance);
1734
+ }
1735
+ }
1736
+ const balances = {};
1737
+ for (const [address, balance] of Object.entries(bigIntBalances)) {
1738
+ balances[address] = toSignedBigInt(balance);
1739
+ }
1740
+ result = {
1741
+ schema: BalancesStepSummarySchema,
1742
+ hash: frameHeadHash,
1743
+ stepSize: frameSize,
1744
+ balances
1745
+ };
1746
+ await context.summaryMap.set(`${frameHeadHash}|${frameSize}`, result);
1747
+ } finally {
1748
+ context.stepSemaphores[step].release();
1749
+ }
1750
+ }
1751
+ }
1752
+ const finalResult = await PayloadBuilder11.addStorageMeta(result);
1753
+ return finalResult;
1754
+ }
1755
+ __name(balancesStepSummaryFromRange, "balancesStepSummaryFromRange");
1756
+
1757
+ // src/summary/primitives/balances/balancesSummary.ts
1758
+ import { asAddress as asAddress3, isDefined as isDefined8 } from "@xylabs/sdk-js";
1759
+ import { spanRootAsync } from "@xylabs/telemetry";
1760
+ import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2, asXL1BlockNumber as asXL1BlockNumber2, asXL1BlockRange as asXL1BlockRange2 } from "@xyo-network/xl1-protocol";
1761
+ async function balancesSummary(context) {
1762
+ return await spanRootAsync("balancesSummary", async () => {
1763
+ const [headHash] = await context.head();
1764
+ const headResult = await context.store.chainMap.get(headHash);
1765
+ const headBoundWitness = asBlockBoundWitnessWithStorageMeta2(headResult, () => `Head block not found for hash: ${headHash}`);
1766
+ const rangeStart = asXL1BlockNumber2(isDefined8(context.windowSize) ? Math.max(headBoundWitness.block - context.windowSize + 1, 0) : 0, true);
1767
+ const ranges = deepCalculateFramesFromRange(asXL1BlockRange2([
1768
+ rangeStart,
1769
+ headBoundWitness.block
1770
+ ], {
1771
+ name: "balancesSummary"
1772
+ }));
1773
+ const summaries = await Promise.all(ranges.map((range) => balancesStepSummaryFromRange(context, range)));
1774
+ const balances = {};
1775
+ for (let summary of summaries) {
1776
+ for (const [address, balance] of Object.entries(summary.balances)) {
1777
+ const validAddress = asAddress3(address, () => `Invalid address: ${address}`);
1778
+ balances[validAddress] = (balances[validAddress] ?? 0n) + parseSignedBigInt(balance);
1779
+ }
1780
+ }
1781
+ return [
1782
+ balances,
1783
+ [
1784
+ rangeStart,
1785
+ headBoundWitness.block
1786
+ ],
1787
+ headHash
1788
+ ];
1789
+ });
1790
+ }
1791
+ __name(balancesSummary, "balancesSummary");
1792
+
1793
+ // src/summary/primitives/schemas/schemasStepSummaryFromRange.ts
1794
+ import { assertEx as assertEx11 } from "@xylabs/sdk-js";
1795
+ import { isBoundWitness } from "@xyo-network/boundwitness-model";
1796
+ import { PayloadBuilder as PayloadBuilder12 } from "@xyo-network/payload-builder";
1797
+ import { isAnyPayload as isAnyPayload2, isHashMeta } from "@xyo-network/payload-model";
1798
+ import { StepSizes as StepSizes7 } from "@xyo-network/xl1-protocol";
1799
+ async function schemasStepSummaryFromRange(context, range) {
1800
+ const frameHeadHash = await hashFromBlockNumber(context, range[1]);
1801
+ const frameSize = range[1] - range[0] + 1;
1802
+ const [headHash] = await context.head();
1803
+ let result = void 0;
1804
+ if (frameSize === 1) {
1805
+ const hash = await hashFromBlockNumber(context, range[0]);
1806
+ const [block, payloads] = await hydrateBlock(context.store, hash);
1807
+ const boundWitnesses = [
1808
+ block,
1809
+ ...payloads.filter((x) => isBoundWitness(x) && isHashMeta(x))
1810
+ ];
1811
+ const schemas = {};
1812
+ for (const bw of boundWitnesses) {
1813
+ schemas[bw.schema] = (schemas[bw.schema] ?? 0) + 1;
1814
+ for (const schema of bw.payload_schemas) {
1815
+ schemas[schema] = (schemas[schema] ?? 0) + 1;
1816
+ }
1817
+ }
1818
+ result = {
1819
+ schema: SchemasStepSummarySchema,
1820
+ hash: headHash,
1821
+ stepSize: -1,
1822
+ schemas
1823
+ };
1824
+ } else {
1825
+ const step = StepSizes7.indexOf(frameSize);
1826
+ assertEx11(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes7.join(", ")}`);
1827
+ const summaryResult = await context.summaryMap.get(`${frameHeadHash}|${frameSize}`);
1828
+ if (isAnyPayload2(summaryResult)) {
1829
+ result = summaryResult;
1830
+ } else {
1831
+ await context.stepSemaphores[step].acquire();
1832
+ try {
1833
+ const subRanges = deepCalculateFramesFromRange(range, step - 1);
1834
+ const promises = subRanges.map((subRange) => schemasStepSummaryFromRange(context, subRange));
1835
+ const subResults = await Promise.all(promises);
1836
+ const schemas = {};
1837
+ for (const subResult of subResults) {
1838
+ for (const [schema, count] of Object.entries(subResult.schemas)) {
1839
+ schemas[schema] = (schemas[schema] ?? 0) + count;
1840
+ }
1841
+ }
1842
+ result = {
1843
+ schema: SchemasStepSummarySchema,
1844
+ hash: frameHeadHash,
1845
+ stepSize: frameSize,
1846
+ schemas
1847
+ };
1848
+ await context.summaryMap.set(`${frameHeadHash}|${frameSize}`, result);
1849
+ } finally {
1850
+ context.stepSemaphores[step].release();
1851
+ }
1852
+ }
1853
+ }
1854
+ return await PayloadBuilder12.addHashMeta(result);
1855
+ }
1856
+ __name(schemasStepSummaryFromRange, "schemasStepSummaryFromRange");
1857
+
1858
+ // src/summary/primitives/schemas/schemasSummary.ts
1859
+ import { isDefined as isDefined9 } from "@xylabs/sdk-js";
1860
+ import { spanRootAsync as spanRootAsync2 } from "@xylabs/telemetry";
1861
+ import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta3, asXL1BlockNumber as asXL1BlockNumber3, asXL1BlockRange as asXL1BlockRange3 } from "@xyo-network/xl1-protocol";
1862
+ async function schemasSummary(context) {
1863
+ return await spanRootAsync2("schemasSummary", async () => {
1864
+ const [headHash] = await context.head();
1865
+ const headResult = await context.store.chainMap.get(headHash);
1866
+ const headBoundWitness = asBlockBoundWitnessWithStorageMeta3(headResult, () => `Head block not found for hash: ${headHash}`);
1867
+ const rangeStart = asXL1BlockNumber3(isDefined9(context.windowSize) ? Math.max(headBoundWitness.block - context.windowSize + 1, 0) : 0, true);
1868
+ const ranges = deepCalculateFramesFromRange(asXL1BlockRange3([
1869
+ rangeStart,
1870
+ headBoundWitness.block
1871
+ ], {
1872
+ name: "schemasSummary"
1873
+ }));
1874
+ const summaries = await Promise.all(ranges.map((range) => schemasStepSummaryFromRange(context, range)));
1875
+ const results = {};
1876
+ for (let summary of summaries) {
1877
+ for (const [schema, count] of Object.entries(summary.schemas)) {
1878
+ results[schema] = (results[schema] ?? 0) + count;
1879
+ }
1880
+ }
1881
+ return [
1882
+ results,
1883
+ [
1884
+ rangeStart,
1885
+ headBoundWitness.block
1886
+ ],
1887
+ headHash
1888
+ ];
1889
+ });
1890
+ }
1891
+ __name(schemasSummary, "schemasSummary");
1892
+
1893
+ // src/summary/primitives/transfers/transfersStepSummaryFromRange.ts
1894
+ import { assertEx as assertEx12 } from "@xylabs/sdk-js";
1895
+ import { PayloadBuilder as PayloadBuilder13 } from "@xyo-network/payload-builder";
1896
+ import { isAnyPayload as isAnyPayload3 } from "@xyo-network/payload-model";
1897
+ import { StepSizes as StepSizes8 } from "@xyo-network/xl1-protocol";
1898
+
1899
+ // src/summary/primitives/transfers/transfersSummary.ts
1900
+ import { asAddress as asAddress4, isDefined as isDefined10 } from "@xylabs/sdk-js";
1901
+ import { spanRootAsync as spanRootAsync3 } from "@xylabs/telemetry";
1902
+ import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta4, asXL1BlockNumber as asXL1BlockNumber4, asXL1BlockRange as asXL1BlockRange4 } from "@xyo-network/xl1-protocol";
1903
+ async function transfersSummary(transferContext) {
1904
+ return await spanRootAsync3("transferSummary", async () => {
1905
+ const [headHash] = await transferContext.head();
1906
+ const headResult = await transferContext.store.chainMap.get(headHash);
1907
+ const headBoundWitness = asBlockBoundWitnessWithStorageMeta4(headResult, () => `Head block not found for hash: ${transferContext.head}`);
1908
+ const rangeStart = asXL1BlockNumber4(isDefined10(transferContext.windowSize) ? Math.max(headBoundWitness.block - transferContext.windowSize + 1, 0) : 0, true);
1909
+ const ranges = deepCalculateFramesFromRange(asXL1BlockRange4([
1910
+ rangeStart,
1911
+ headBoundWitness.block
1912
+ ], {
1913
+ name: "transfersSummary"
1914
+ }));
1915
+ const summaries = await Promise.all(ranges.map((range) => transfersStepSummaryFromRange(transferContext, range)));
1916
+ const transfers = {};
1917
+ for (let summary of summaries) {
1918
+ for (const [from, toMap] of Object.entries(summary.transfers)) {
1919
+ const validFrom = asAddress4(from, () => `Invalid address: ${from}`);
1920
+ transfers[validFrom] = transfers[validFrom] ?? {};
1921
+ for (const [to, transfer] of Object.entries(toMap)) {
1922
+ const validTo = asAddress4(to, () => `Invalid address: ${to}`);
1923
+ transfers[validFrom][validTo] = (transfers[validFrom][validTo] ?? 0n) + parseSignedBigInt(transfer);
1924
+ }
1925
+ }
1926
+ }
1927
+ return [
1928
+ transfers,
1929
+ [
1930
+ rangeStart,
1931
+ headBoundWitness.block
1932
+ ],
1933
+ headHash
1934
+ ];
1935
+ });
1936
+ }
1937
+ __name(transfersSummary, "transfersSummary");
1938
+ function transfersSummaryKey(frameHeadHash, frameSize) {
1939
+ return `${frameHeadHash}|${frameSize}`;
1940
+ }
1941
+ __name(transfersSummaryKey, "transfersSummaryKey");
1915
1942
 
1916
- // src/services/StakeIntentService/ChainIndexingServiceStateSchema.ts
1917
- import { AsObjectFactory as AsObjectFactory7 } from "@xylabs/sdk-js";
1918
- import { isPayloadOfSchemaType as isPayloadOfSchemaType5, isStorageMeta as isStorageMeta4 } from "@xyo-network/payload-model";
1919
- var ChainIndexingServiceStateSchema = "network.xyo.chain.indexing.service.state";
1920
- var isChainIndexingServiceState = /* @__PURE__ */ __name((payload) => {
1921
- return isPayloadOfSchemaType5(ChainIndexingServiceStateSchema)(payload);
1922
- }, "isChainIndexingServiceState");
1923
- var asChainIndexingServiceState = AsObjectFactory7.create(isChainIndexingServiceState);
1924
- var isChainIndexingServiceStateWithStorageMeta = /* @__PURE__ */ __name((value) => isChainIndexingServiceState(value) && isStorageMeta4(value), "isChainIndexingServiceStateWithStorageMeta");
1925
- var asChainIndexingServiceStateWithStorageMeta = AsObjectFactory7.create(isChainIndexingServiceStateWithStorageMeta);
1943
+ // src/summary/primitives/transfers/transfersStepSummaryFromRange.ts
1944
+ async function transfersStepSummaryFromRange(context, range) {
1945
+ const frameHeadHash = await hashFromBlockNumber(context, range[1]);
1946
+ const frameSize = range[1] - range[0] + 1;
1947
+ const [headHash] = await context.head();
1948
+ let result = void 0;
1949
+ if (frameSize === 1) {
1950
+ const hash = await hashFromBlockNumber(context, range[0]);
1951
+ const [, payloads] = await hydrateBlock(context.store, hash);
1952
+ const transfers = {};
1953
+ for (const [from, toMap] of Object.entries(netTransfersForPayloads(payloads))) {
1954
+ transfers[from] = transfers[from] ?? {};
1955
+ for (const [to, amount] of Object.entries(toMap)) {
1956
+ transfers[from][to] = toSignedBigInt(amount);
1957
+ }
1958
+ }
1959
+ result = {
1960
+ schema: TransfersStepSummarySchema,
1961
+ hash: headHash,
1962
+ stepSize: -1,
1963
+ transfers
1964
+ };
1965
+ } else {
1966
+ const step = StepSizes8.indexOf(frameSize);
1967
+ assertEx12(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes8.join(", ")}`);
1968
+ const key = transfersSummaryKey(frameHeadHash, frameSize);
1969
+ const summaryResult = await context.summaryMap.get(key);
1970
+ if (isAnyPayload3(summaryResult)) {
1971
+ result = summaryResult;
1972
+ } else {
1973
+ await context.stepSemaphores[step].acquire();
1974
+ try {
1975
+ const subRanges = deepCalculateFramesFromRange(range, step - 1);
1976
+ const promises = subRanges.map((subRange) => transfersStepSummaryFromRange(context, subRange));
1977
+ const subResults = await Promise.all(promises);
1978
+ const bigIntBalances = {};
1979
+ for (const subResult of subResults) {
1980
+ for (const [from, toMap] of Object.entries(subResult.transfers)) {
1981
+ bigIntBalances[from] = bigIntBalances[from] ?? {};
1982
+ for (const [to, transfer] of Object.entries(toMap)) {
1983
+ bigIntBalances[from][to] = (bigIntBalances[from][to] ?? 0n) + parseSignedBigInt(transfer);
1984
+ }
1985
+ }
1986
+ }
1987
+ const transfers = {};
1988
+ for (const [from, toMap] of Object.entries(bigIntBalances)) {
1989
+ transfers[from] = transfers[from] ?? {};
1990
+ for (const [to, transfer] of Object.entries(toMap)) {
1991
+ transfers[from][to] = toSignedBigInt(transfer);
1992
+ }
1993
+ }
1994
+ result = {
1995
+ schema: TransfersStepSummarySchema,
1996
+ hash: frameHeadHash,
1997
+ stepSize: frameSize,
1998
+ transfers
1999
+ };
2000
+ await context.summaryMap.set(key, result);
2001
+ } finally {
2002
+ context.stepSemaphores[step].release();
2003
+ }
2004
+ }
2005
+ }
2006
+ const finalResult = await PayloadBuilder13.addStorageMeta(result);
2007
+ return finalResult;
2008
+ }
2009
+ __name(transfersStepSummaryFromRange, "transfersStepSummaryFromRange");
1926
2010
 
1927
2011
  // src/simple/accountBalance/SimpleAccountBalanceViewer.ts
1928
- import { AbstractCreatable, assertEx as assertEx13, exists, isDefined as isDefined11 } from "@xylabs/sdk-js";
1929
- import { spanRootAsync as spanRootAsync4 } from "@xylabs/telemetry";
1930
- import { asRange, asXL1BlockNumber as asXL1BlockNumber5, asXL1BlockRange as asXL1BlockRange5, AttoXL1 as AttoXL12, StepSizes as StepSizes9, TransferSchema } from "@xyo-network/xl1-protocol";
1931
2012
  var SimpleAccountBalanceViewer = class extends AbstractCreatable {
1932
2013
  static {
1933
2014
  __name(this, "SimpleAccountBalanceViewer");
@@ -1950,11 +2031,14 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatable {
1950
2031
  };
1951
2032
  }
1952
2033
  async accountBalance(address, headOrRange) {
1953
- const balances = await this.accountsBalances([
2034
+ const balances = await this.accountBalances([
1954
2035
  address
1955
2036
  ], headOrRange);
1956
2037
  return balances[address] ?? AttoXL12(0n);
1957
2038
  }
2039
+ accountBalanceHistories(_addresses, _rangeOrHash) {
2040
+ throw new Error("Method [accountBalanceHistories] not implemented.");
2041
+ }
1958
2042
  async accountBalanceHistory(address, headOrRange) {
1959
2043
  const range = asRange(headOrRange);
1960
2044
  const startingRange = asXL1BlockRange5(range ?? [
@@ -1987,20 +2071,53 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatable {
1987
2071
  }
1988
2072
  return result;
1989
2073
  }
1990
- async accountsBalances(address, _headOrRange) {
1991
- return await spanRootAsync4("balances", async () => {
1992
- const summary = await balancesSummary(this.context);
2074
+ async accountBalances(address, _headOrRange) {
2075
+ const [result] = await this.qualifiedAccountBalances(address, _headOrRange);
2076
+ return result;
2077
+ }
2078
+ async qualifiedAccountBalanceHistories(addresses, headOrRange) {
2079
+ const head = asHash5(headOrRange) ?? await this.blockViewer.currentBlockHash();
2080
+ const range = asXL1BlockRange5(headOrRange) ?? asXL1BlockRange5([
2081
+ 0,
2082
+ assertEx13(await this.blockViewer.blockByHash(head), () => `Error: Could not find block with hash ${head}`)[0].block
2083
+ ]);
2084
+ const qualifiedEntries = await Promise.all(addresses.map(async (address) => [
2085
+ address,
2086
+ await this.qualifiedAccountBalanceHistory(address, range)
2087
+ ]));
2088
+ const entries = qualifiedEntries.map(([address, [history]]) => {
2089
+ return [
2090
+ address,
2091
+ history
2092
+ ];
2093
+ });
2094
+ const qualifiedRange = qualifiedEntries[0][1][1];
2095
+ const qualifiedHeadHash = qualifiedEntries[0][1][2];
2096
+ for (const [_, [__, range2, headHash]] of qualifiedEntries) {
2097
+ assertEx13(range2[0] === qualifiedRange[0] && range2[1] === qualifiedRange[1], () => "Inconsistent ranges in qualifiedAccountBalanceHistories");
2098
+ assertEx13(headHash === qualifiedHeadHash, () => "Inconsistent head hashes in qualifiedAccountBalanceHistories");
2099
+ }
2100
+ return [
2101
+ Object.fromEntries(entries),
2102
+ qualifiedRange,
2103
+ qualifiedHeadHash
2104
+ ];
2105
+ }
2106
+ async qualifiedAccountBalances(address, _headOrRange) {
2107
+ return await spanRootAsync4("qualifiedAccountsBalances", async () => {
2108
+ const qualifiedSummary = await balancesSummary(this.context);
1993
2109
  const result = {};
1994
2110
  for (const addr of address) {
1995
- const summaryBalance = summary[addr] ?? 0n;
2111
+ const summaryBalance = qualifiedSummary[0][addr] ?? 0n;
1996
2112
  result[addr] = AttoXL12(summaryBalance < 0n ? 0n : summaryBalance);
1997
2113
  }
1998
- return result;
2114
+ return [
2115
+ result,
2116
+ qualifiedSummary[1],
2117
+ qualifiedSummary[2]
2118
+ ];
1999
2119
  });
2000
2120
  }
2001
- accountsBalancesHistory(_addresses, _rangeOrHash) {
2002
- throw new Error("Method not implemented.");
2003
- }
2004
2121
  async distillTransferHistory(address, range, max = 50) {
2005
2122
  if (range[1] - range[0] <= StepSizes9[0] || max <= 1) {
2006
2123
  return Array.from({
@@ -2042,10 +2159,48 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatable {
2042
2159
  ...resultBlockNumbers
2043
2160
  ].toSorted((a, b) => b - a).slice(0, max);
2044
2161
  }
2162
+ async qualifiedAccountBalanceHistory(address, headOrRange) {
2163
+ const range = asRange(headOrRange);
2164
+ const headHash = asHash5(headOrRange);
2165
+ const [head] = assertEx13(isDefined11(headHash) ? await this.blockViewer.blockByHash(headHash) : await this.blockViewer.currentBlock(), () => "Could not resolve head block");
2166
+ const startingRange = asXL1BlockRange5(range ?? [
2167
+ 0,
2168
+ head.block
2169
+ ], true);
2170
+ const blockNumbers = await this.distillTransferHistory(address, startingRange);
2171
+ const blocks = (await Promise.all(blockNumbers.map(async (bn) => await this.blockViewer.blockByNumber(bn)))).filter(exists);
2172
+ const result = [];
2173
+ for (const block of blocks) {
2174
+ const transferIndexes = block[0].payload_schemas.map((schema, index) => schema === TransferSchema ? index : void 0).filter(exists);
2175
+ const transfers = transferIndexes.map((index) => {
2176
+ const hash = block[0].payload_hashes[index];
2177
+ return assertEx13(block[1].find((p) => p._hash === hash), () => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`);
2178
+ }).filter(exists).filter((t) => t.from === address || isDefined11(t.transfers[address]));
2179
+ if (transfers.length === 0) {
2180
+ continue;
2181
+ }
2182
+ const pairs = transfers.map((transfer) => {
2183
+ return [
2184
+ block[0],
2185
+ transfer
2186
+ ];
2187
+ });
2188
+ result.push(...pairs.map(([block2, transfer]) => [
2189
+ block2,
2190
+ null,
2191
+ transfer
2192
+ ]));
2193
+ }
2194
+ return [
2195
+ result,
2196
+ startingRange,
2197
+ head._hash
2198
+ ];
2199
+ }
2045
2200
  };
2046
2201
 
2047
2202
  // src/simple/block/SimpleBlockViewer.ts
2048
- import { AbstractCreatable as AbstractCreatable2, assertEx as assertEx14, spanRootAsync as spanRootAsync5 } from "@xylabs/sdk-js";
2203
+ import { AbstractCreatable as AbstractCreatable2, assertEx as assertEx14, exists as exists2, isDefined as isDefined12, spanRootAsync as spanRootAsync5 } from "@xylabs/sdk-js";
2049
2204
  import { asSignedHydratedBlockWithHashMeta, asXL1BlockNumber as asXL1BlockNumber6 } from "@xyo-network/xl1-protocol";
2050
2205
 
2051
2206
  // src/utils/HydratedCache.ts
@@ -2079,12 +2234,12 @@ var HydratedCache = class {
2079
2234
  };
2080
2235
 
2081
2236
  // src/utils/isZodError.ts
2082
- import * as z20 from "zod";
2237
+ import * as z21 from "zod";
2083
2238
  var isZodError = /* @__PURE__ */ __name((error) => {
2084
- return error instanceof z20.ZodError;
2239
+ return error instanceof z21.ZodError;
2085
2240
  }, "isZodError");
2086
2241
  var prettifyZodError = /* @__PURE__ */ __name((error) => {
2087
- return z20.prettifyError(error);
2242
+ return z21.prettifyError(error);
2088
2243
  }, "prettifyZodError");
2089
2244
 
2090
2245
  // src/simple/block/SimpleBlockViewer.ts
@@ -2092,6 +2247,7 @@ var SimpleBlockViewer = class extends AbstractCreatable2 {
2092
2247
  static {
2093
2248
  __name(this, "SimpleBlockViewer");
2094
2249
  }
2250
+ _payloadCache;
2095
2251
  _signedHydratedBlockCache;
2096
2252
  get context() {
2097
2253
  return this.params.context;
@@ -2099,6 +2255,24 @@ var SimpleBlockViewer = class extends AbstractCreatable2 {
2099
2255
  get finalizedArchivist() {
2100
2256
  return this.params.finalizedArchivist;
2101
2257
  }
2258
+ get hydratedBlockCache() {
2259
+ if (this._signedHydratedBlockCache) return this._signedHydratedBlockCache;
2260
+ const chainMap = this.context.store.chainMap;
2261
+ this._signedHydratedBlockCache = new HydratedCache(chainMap, async ({ chainMap: chainMap2 }, hash, maxDepth, minDepth) => {
2262
+ const result = await hydrateBlock({
2263
+ chainMap: chainMap2
2264
+ }, hash, maxDepth, minDepth);
2265
+ return asSignedHydratedBlockWithHashMeta(result, true);
2266
+ }, 200);
2267
+ return this._signedHydratedBlockCache;
2268
+ }
2269
+ get payloadCache() {
2270
+ if (this._payloadCache) return this._payloadCache;
2271
+ this._payloadCache = new LruCacheMap({
2272
+ max: 1e4
2273
+ });
2274
+ return this._payloadCache;
2275
+ }
2102
2276
  static async paramsHandler(params) {
2103
2277
  assertEx14(params.context, () => "context is required");
2104
2278
  assertEx14(params.finalizedArchivist, () => "finalizedArchivist is required");
@@ -2108,7 +2282,7 @@ var SimpleBlockViewer = class extends AbstractCreatable2 {
2108
2282
  }
2109
2283
  async blockByHash(hash) {
2110
2284
  return await spanRootAsync5("blockByHash", async () => {
2111
- const cache = this.getHydratedBlockCache();
2285
+ const cache = this.hydratedBlockCache;
2112
2286
  return await cache.get(hash);
2113
2287
  }, this.tracer);
2114
2288
  }
@@ -2150,7 +2324,7 @@ var SimpleBlockViewer = class extends AbstractCreatable2 {
2150
2324
  async currentBlock() {
2151
2325
  return await spanRootAsync5("currentBlock", async () => {
2152
2326
  const currentHead = assertEx14(await this.getCurrentHead(), () => "Could not find most recent block");
2153
- const cache = this.getHydratedBlockCache();
2327
+ const cache = this.hydratedBlockCache;
2154
2328
  const block = await cache.get(currentHead._hash);
2155
2329
  if (!block) {
2156
2330
  console.log(`Could not find current block with hash ${currentHead._hash}`);
@@ -2172,38 +2346,76 @@ var SimpleBlockViewer = class extends AbstractCreatable2 {
2172
2346
  });
2173
2347
  }, this.tracer);
2174
2348
  }
2349
+ async payloadByHash(hash) {
2350
+ const cachedPayload = await this.payloadCache.get(hash);
2351
+ if (cachedPayload) {
2352
+ return cachedPayload;
2353
+ } else {
2354
+ const [result] = await this.finalizedArchivist.get([
2355
+ hash
2356
+ ]);
2357
+ if (isDefined12(result)) {
2358
+ await this.payloadCache.set(hash, result);
2359
+ }
2360
+ return result ?? null;
2361
+ }
2362
+ }
2363
+ async payloadsByHash(hashes) {
2364
+ let remainingHashes = [
2365
+ ...hashes
2366
+ ];
2367
+ const cachedPayloads = await this.payloadCache.getMany(remainingHashes);
2368
+ const cachedHashes = new Set(cachedPayloads.map((p) => p._hash));
2369
+ remainingHashes = remainingHashes.filter((h) => !cachedHashes.has(h));
2370
+ const remainingPayloads = remainingHashes.length > 0 ? await this.finalizedArchivist.get(remainingHashes) : [];
2371
+ return [
2372
+ ...cachedPayloads,
2373
+ ...remainingPayloads.filter(exists2)
2374
+ ];
2375
+ }
2175
2376
  async getCurrentHead() {
2176
2377
  const chainArchivist = this.finalizedArchivist;
2177
2378
  return await findMostRecentBlock(chainArchivist);
2178
2379
  }
2179
- getHydratedBlockCache() {
2180
- if (this._signedHydratedBlockCache) return this._signedHydratedBlockCache;
2181
- const chainMap = this.context.store.chainMap;
2182
- this._signedHydratedBlockCache = new HydratedCache(chainMap, async ({ chainMap: chainMap2 }, hash, maxDepth, minDepth) => {
2183
- const result = await hydrateBlock({
2184
- chainMap: chainMap2
2185
- }, hash, maxDepth, minDepth);
2186
- return asSignedHydratedBlockWithHashMeta(result, true);
2187
- }, 200);
2188
- return this._signedHydratedBlockCache;
2380
+ };
2381
+
2382
+ // src/simple/blockReward/SimpleBlockRewardViewer.ts
2383
+ import { AbstractCreatable as AbstractCreatable3, creatable } from "@xylabs/sdk-js";
2384
+ function _ts_decorate(decorators, target, key, desc) {
2385
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2386
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2387
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2388
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2389
+ }
2390
+ __name(_ts_decorate, "_ts_decorate");
2391
+ var SimpleBlockRewardViewer = class extends AbstractCreatable3 {
2392
+ static {
2393
+ __name(this, "SimpleBlockRewardViewer");
2394
+ }
2395
+ rewardFromBlockNumber = rewardFromBlockNumber(18);
2396
+ allowedRewardForBlock(block) {
2397
+ return this.rewardFromBlockNumber(block, this.params.initialReward, this.params.stepSize, this.params.stepFactorNumerator, this.params.stepFactorDenominator, this.params.minRewardPerBlock, this.params.creatorReward);
2189
2398
  }
2190
2399
  };
2400
+ SimpleBlockRewardViewer = _ts_decorate([
2401
+ creatable()
2402
+ ], SimpleBlockRewardViewer);
2191
2403
 
2192
2404
  // src/simple/chainStake/SimpleChainStakeViewer.ts
2193
2405
  import { asAddress as asAddress5, toAddress as toAddress5 } from "@xylabs/sdk-js";
2194
- import { AbstractCreatable as AbstractCreatable4, assertEx as assertEx15, creatable as creatable2 } from "@xylabs/sdk-js";
2406
+ import { AbstractCreatable as AbstractCreatable5, assertEx as assertEx15, creatable as creatable3 } from "@xylabs/sdk-js";
2195
2407
  import { Account } from "@xyo-network/account";
2196
2408
 
2197
2409
  // src/simple/chainStakeEvents/SimpleChainStakeEventsViewer.ts
2198
- import { AbstractCreatable as AbstractCreatable3, creatable, isDefined as isDefined12 } from "@xylabs/sdk-js";
2199
- function _ts_decorate(decorators, target, key, desc) {
2410
+ import { AbstractCreatable as AbstractCreatable4, creatable as creatable2, isDefined as isDefined13 } from "@xylabs/sdk-js";
2411
+ function _ts_decorate2(decorators, target, key, desc) {
2200
2412
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2201
2413
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2202
2414
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2203
2415
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2204
2416
  }
2205
- __name(_ts_decorate, "_ts_decorate");
2206
- var SimpleChainStakeEventsViewer = class extends AbstractCreatable3 {
2417
+ __name(_ts_decorate2, "_ts_decorate");
2418
+ var SimpleChainStakeEventsViewer = class extends AbstractCreatable4 {
2207
2419
  static {
2208
2420
  __name(this, "SimpleChainStakeEventsViewer");
2209
2421
  }
@@ -2216,7 +2428,7 @@ var SimpleChainStakeEventsViewer = class extends AbstractCreatable3 {
2216
2428
  stakeEvents(range, { name } = {}) {
2217
2429
  const positions = this.positionsFromRange(range);
2218
2430
  const events = this.eventsFromPositions(positions);
2219
- if (isDefined12(name)) {
2431
+ if (isDefined13(name)) {
2220
2432
  return events.filter((event) => event.name === name);
2221
2433
  }
2222
2434
  return events;
@@ -2275,19 +2487,19 @@ var SimpleChainStakeEventsViewer = class extends AbstractCreatable3 {
2275
2487
  return filteredPositions;
2276
2488
  }
2277
2489
  };
2278
- SimpleChainStakeEventsViewer = _ts_decorate([
2279
- creatable()
2490
+ SimpleChainStakeEventsViewer = _ts_decorate2([
2491
+ creatable2()
2280
2492
  ], SimpleChainStakeEventsViewer);
2281
2493
 
2282
2494
  // src/simple/chainStake/SimpleChainStakeViewer.ts
2283
- function _ts_decorate2(decorators, target, key, desc) {
2495
+ function _ts_decorate3(decorators, target, key, desc) {
2284
2496
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2285
2497
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2286
2498
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2287
2499
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2288
2500
  }
2289
- __name(_ts_decorate2, "_ts_decorate");
2290
- var SimpleChainStakeViewer = class extends AbstractCreatable4 {
2501
+ __name(_ts_decorate3, "_ts_decorate");
2502
+ var SimpleChainStakeViewer = class extends AbstractCreatable5 {
2291
2503
  static {
2292
2504
  __name(this, "SimpleChainStakeViewer");
2293
2505
  }
@@ -2405,8 +2617,8 @@ var SimpleChainStakeViewer = class extends AbstractCreatable4 {
2405
2617
  });
2406
2618
  }
2407
2619
  };
2408
- SimpleChainStakeViewer = _ts_decorate2([
2409
- creatable2()
2620
+ SimpleChainStakeViewer = _ts_decorate3([
2621
+ creatable3()
2410
2622
  ], SimpleChainStakeViewer);
2411
2623
 
2412
2624
  // src/simple/client/SimpleXyoClient.ts
@@ -2527,8 +2739,8 @@ var SimpleXyoGateway = class {
2527
2739
  };
2528
2740
 
2529
2741
  // src/simple/gateway/SimpleXyoGatewayRunner.ts
2530
- import { assertEx as assertEx16, BigIntToJsonZod, isDefined as isDefined13 } from "@xylabs/sdk-js";
2531
- import { PayloadBuilder as PayloadBuilder12 } from "@xyo-network/payload-builder";
2742
+ import { assertEx as assertEx16, BigIntToJsonZod, isDefined as isDefined14 } from "@xylabs/sdk-js";
2743
+ import { PayloadBuilder as PayloadBuilder14 } from "@xyo-network/payload-builder";
2532
2744
  import { asXL1BlockNumber as asXL1BlockNumber7, TransferSchema as TransferSchema2 } from "@xyo-network/xl1-protocol";
2533
2745
  var SimpleXyoGatewayRunner = class {
2534
2746
  static {
@@ -2548,7 +2760,7 @@ var SimpleXyoGatewayRunner = class {
2548
2760
  return this._connection;
2549
2761
  }
2550
2762
  get dataLakes() {
2551
- throw new Error("Method not implemented.");
2763
+ throw new Error("Method [dataLakes] not implemented.");
2552
2764
  }
2553
2765
  get signerInstance() {
2554
2766
  return this._signer;
@@ -2560,9 +2772,9 @@ var SimpleXyoGatewayRunner = class {
2560
2772
  async addPayloadsToChain(onChain, offChain, options) {
2561
2773
  const viewer = assertEx16(this.connectionInstance.viewer, () => "No viewer available on connection");
2562
2774
  const { nbf, exp, chain, fees } = options ?? {};
2563
- const resolvedChainId = isDefined13(chain) ? chain : await viewer.chainId();
2564
- const resolvedNbf = asXL1BlockNumber7(isDefined13(nbf) ? nbf : await viewer.currentBlockNumber(), true);
2565
- const resolvedExp = asXL1BlockNumber7(isDefined13(exp) ? exp : resolvedNbf + 10, true);
2775
+ const resolvedChainId = isDefined14(chain) ? chain : await viewer.chainId();
2776
+ const resolvedNbf = asXL1BlockNumber7(isDefined14(nbf) ? nbf : await viewer.currentBlockNumber(), true);
2777
+ const resolvedExp = asXL1BlockNumber7(isDefined14(exp) ? exp : resolvedNbf + 10, true);
2566
2778
  const tx = await buildUnsignedTransaction(resolvedChainId, onChain, offChain, resolvedNbf, resolvedExp, await (await this.signer()).address(), fees);
2567
2779
  return await this.addTransactionToChain(tx);
2568
2780
  }
@@ -2601,7 +2813,7 @@ var SimpleXyoGatewayRunner = class {
2601
2813
  address,
2602
2814
  BigIntToJsonZod.parse(amount)
2603
2815
  ]));
2604
- const transfer = new PayloadBuilder12({
2816
+ const transfer = new PayloadBuilder14({
2605
2817
  schema: TransferSchema2
2606
2818
  }).fields({
2607
2819
  from,
@@ -2626,6 +2838,112 @@ var SimpleXyoGatewayRunner = class {
2626
2838
  }
2627
2839
  };
2628
2840
 
2841
+ // src/simple/mempool/SimpleMempoolRunner.ts
2842
+ import { AbstractCreatable as AbstractCreatable6, creatable as creatable4 } from "@xylabs/sdk-js";
2843
+ import { PayloadBuilder as PayloadBuilder15 } from "@xyo-network/payload-builder";
2844
+ function _ts_decorate4(decorators, target, key, desc) {
2845
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2846
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2847
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2848
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2849
+ }
2850
+ __name(_ts_decorate4, "_ts_decorate");
2851
+ var SimpleMempoolRunner = class extends AbstractCreatable6 {
2852
+ static {
2853
+ __name(this, "SimpleMempoolRunner");
2854
+ }
2855
+ get pendingBlocksArchivist() {
2856
+ return this.params.pendingBlocksArchivist;
2857
+ }
2858
+ get pendingTransactionsArchivist() {
2859
+ return this.params.pendingTransactionsArchivist;
2860
+ }
2861
+ async submitBlocks(blocks) {
2862
+ const bundles = await Promise.all(blocks.map(async ([bw, payloads]) => {
2863
+ return hydratedBlockToPayloadBundle([
2864
+ await PayloadBuilder15.addHashMeta(bw),
2865
+ await PayloadBuilder15.addHashMeta(payloads)
2866
+ ]);
2867
+ }));
2868
+ const inserted = await this.pendingBlocksArchivist.insert(bundles);
2869
+ return inserted.map((p) => p._hash);
2870
+ }
2871
+ async submitTransactions(transactions) {
2872
+ const bundles = await Promise.all(transactions.map(async ([tx, payloads]) => {
2873
+ return hydratedTransactionToPayloadBundle([
2874
+ await PayloadBuilder15.addHashMeta(tx),
2875
+ await PayloadBuilder15.addHashMeta(payloads)
2876
+ ]);
2877
+ }));
2878
+ const inserted = await this.pendingBlocksArchivist.insert(bundles);
2879
+ return inserted.map((p) => p._hash);
2880
+ }
2881
+ };
2882
+ SimpleMempoolRunner = _ts_decorate4([
2883
+ creatable4()
2884
+ ], SimpleMempoolRunner);
2885
+
2886
+ // src/simple/mempool/SimpleMempoolViewer.ts
2887
+ import { AbstractCreatable as AbstractCreatable7, creatable as creatable5, exists as exists3, isDefined as isDefined15, isHash } from "@xylabs/sdk-js";
2888
+ import { isHashMeta as isHashMeta2, isPayloadBundle } from "@xyo-network/payload-model";
2889
+ function _ts_decorate5(decorators, target, key, desc) {
2890
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2891
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2892
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2893
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2894
+ }
2895
+ __name(_ts_decorate5, "_ts_decorate");
2896
+ var SimpleMempoolViewer = class extends AbstractCreatable7 {
2897
+ static {
2898
+ __name(this, "SimpleMempoolViewer");
2899
+ }
2900
+ get pendingBlocksArchivist() {
2901
+ return this.params.pendingBlocksArchivist;
2902
+ }
2903
+ get pendingTransactionsArchivist() {
2904
+ return this.params.pendingTransactionsArchivist;
2905
+ }
2906
+ async pendingBlocks({ cursor: providedCursor } = {}) {
2907
+ let cursor = void 0;
2908
+ if (isHash(providedCursor)) {
2909
+ const [p] = await this.pendingBlocksArchivist.get([
2910
+ providedCursor
2911
+ ]);
2912
+ if (isDefined15(p)) {
2913
+ cursor = p._sequence;
2914
+ }
2915
+ }
2916
+ const bundles = await this.pendingBlocksArchivist.next({
2917
+ order: "asc",
2918
+ limit: 100,
2919
+ cursor
2920
+ });
2921
+ const filteredBundles = bundles.filter(isPayloadBundle).filter(isHashMeta2);
2922
+ return (await Promise.all(filteredBundles.map(async (bundle3) => await bundledPayloadToHydratedBlock(bundle3)))).filter(exists3);
2923
+ }
2924
+ async pendingTransactions({ cursor: providedCursor } = {}) {
2925
+ let cursor = void 0;
2926
+ if (isHash(providedCursor)) {
2927
+ const [p] = await this.pendingTransactionsArchivist.get([
2928
+ providedCursor
2929
+ ]);
2930
+ if (isDefined15(p)) {
2931
+ cursor = p._sequence;
2932
+ }
2933
+ }
2934
+ const bundles = await this.pendingTransactionsArchivist.next({
2935
+ order: "asc",
2936
+ limit: 100,
2937
+ cursor
2938
+ });
2939
+ const filteredBundles = bundles.filter(isPayloadBundle).filter(isHashMeta2);
2940
+ return (await Promise.all(filteredBundles.map(async (bundle3) => await bundledPayloadToHydratedTransaction(bundle3)))).filter(exists3);
2941
+ }
2942
+ };
2943
+ SimpleMempoolViewer = _ts_decorate5([
2944
+ creatable5()
2945
+ ], SimpleMempoolViewer);
2946
+
2629
2947
  // src/simple/network/SimpleXyoNetwork.ts
2630
2948
  import { isUndefined as isUndefined4 } from "@xylabs/sdk-js";
2631
2949
  import { isNetworkStatus } from "@xyo-network/xl1-protocol";
@@ -2794,7 +3112,7 @@ var MemoryPermissionsStore = class {
2794
3112
 
2795
3113
  // src/simple/runner/SimpleXyoRunner.ts
2796
3114
  import { MemoryArchivist } from "@xyo-network/archivist-memory";
2797
- import { PayloadBuilder as PayloadBuilder13 } from "@xyo-network/payload-builder";
3115
+ import { PayloadBuilder as PayloadBuilder16 } from "@xyo-network/payload-builder";
2798
3116
  var SimpleXyoRunner = class {
2799
3117
  static {
2800
3118
  __name(this, "SimpleXyoRunner");
@@ -2806,7 +3124,7 @@ var SimpleXyoRunner = class {
2806
3124
  async broadcastTransaction(transaction) {
2807
3125
  const archivist = await this.getMempoolArchivist();
2808
3126
  await archivist.insert(flattenHydratedTransaction(transaction));
2809
- return await PayloadBuilder13.hash(transaction[0]);
3127
+ return await PayloadBuilder16.hash(transaction[0]);
2810
3128
  }
2811
3129
  async getMempoolArchivist() {
2812
3130
  if (!this._mempoolArchivist) {
@@ -2819,7 +3137,7 @@ var SimpleXyoRunner = class {
2819
3137
  };
2820
3138
 
2821
3139
  // src/simple/signer/SimpleXyoSigner.ts
2822
- import { PayloadBuilder as PayloadBuilder14 } from "@xyo-network/payload-builder";
3140
+ import { PayloadBuilder as PayloadBuilder17 } from "@xyo-network/payload-builder";
2823
3141
  import { SignedHydratedTransactionWithHashMetaZod } from "@xyo-network/xl1-protocol";
2824
3142
  var SimpleXyoSigner = class {
2825
3143
  static {
@@ -2840,14 +3158,14 @@ var SimpleXyoSigner = class {
2840
3158
  async signTransaction(tx) {
2841
3159
  const txBW = await signTransaction(tx[0], this._account);
2842
3160
  return SignedHydratedTransactionWithHashMetaZod.parse([
2843
- await PayloadBuilder14.addStorageMeta(txBW),
2844
- await PayloadBuilder14.addStorageMeta(tx[1])
3161
+ await PayloadBuilder17.addStorageMeta(txBW),
3162
+ await PayloadBuilder17.addStorageMeta(tx[1])
2845
3163
  ]);
2846
3164
  }
2847
3165
  };
2848
3166
 
2849
3167
  // src/simple/timesync/SimpleTimeSyncViewer.ts
2850
- import { asHash as asHash5, assertEx as assertEx19, isDefined as isDefined14 } from "@xylabs/sdk-js";
3168
+ import { asHash as asHash6, assertEx as assertEx19, isDefined as isDefined16 } from "@xylabs/sdk-js";
2851
3169
  import { asTimePayload, asXL1BlockNumber as asXL1BlockNumber8, TimeSchema } from "@xyo-network/xl1-protocol";
2852
3170
  var SimpleTimeSyncViewer = class {
2853
3171
  static {
@@ -2865,7 +3183,7 @@ var SimpleTimeSyncViewer = class {
2865
3183
  const [block, payloads] = assertEx19(await this.blockViewer.blockByNumber(asXL1BlockNumber8(from, true)), () => "Block not found");
2866
3184
  const timeSchemaIndex = block.payload_schemas.indexOf(TimeSchema);
2867
3185
  const hash = timeSchemaIndex === -1 ? void 0 : block.payload_hashes[timeSchemaIndex];
2868
- const timePayload = asTimePayload(isDefined14(hash) ? payloads.find((p) => p._hash === hash) : void 0);
3186
+ const timePayload = asTimePayload(isDefined16(hash) ? payloads.find((p) => p._hash === hash) : void 0);
2869
3187
  if (timePayload === void 0) return 0;
2870
3188
  switch (toDomain) {
2871
3189
  case "xl1": {
@@ -2931,7 +3249,7 @@ var SimpleTimeSyncViewer = class {
2931
3249
  const provider = assertEx19(this.ethProvider, () => "Ethereum provider not configured");
2932
3250
  const blockNumber = await provider.getBlockNumber() ?? 0;
2933
3251
  const block = await provider.getBlock(blockNumber);
2934
- const blockHash = asHash5(assertEx19(block?.hash, () => "Block hash not found"), true);
3252
+ const blockHash = asHash6(assertEx19(block?.hash, () => "Block hash not found"), true);
2935
3253
  return [
2936
3254
  blockNumber,
2937
3255
  blockHash
@@ -2943,7 +3261,7 @@ var SimpleTimeSyncViewer = class {
2943
3261
  }
2944
3262
  }
2945
3263
  currentTimePayload() {
2946
- throw new Error("Method not implemented.");
3264
+ throw new Error("Method [currentTimePayload] not implemented.");
2947
3265
  }
2948
3266
  };
2949
3267
 
@@ -2964,21 +3282,26 @@ __name(xl1BlockNumberToEthBlockNumber, "xl1BlockNumberToEthBlockNumber");
2964
3282
  import { WithHashMetaZod } from "@xyo-network/payload-model";
2965
3283
  import { TransferZod } from "@xyo-network/xl1-protocol";
2966
3284
  import { BlockBoundWitnessZod, TransactionBoundWitnessZod } from "@xyo-network/xl1-protocol";
2967
- import z21 from "zod";
2968
- var AccountBalanceHistoryItemZod = z21.tuple([
3285
+ import z22 from "zod";
3286
+ var AccountBalanceHistoryItemZod = z22.tuple([
2969
3287
  WithHashMetaZod(BlockBoundWitnessZod),
2970
3288
  WithHashMetaZod(TransactionBoundWitnessZod).nullable(),
2971
3289
  WithHashMetaZod(TransferZod)
2972
3290
  ]);
2973
3291
 
2974
3292
  // src/viewers/Mempool.ts
2975
- import { HashZod as HashZod2 } from "@xylabs/sdk-js";
2976
- import { XL1BlockRangeZod } from "@xyo-network/xl1-protocol";
2977
- import z22 from "zod";
2978
- var PendingTransactionsOptionsZod = z22.object({
2979
- cursor: HashZod2.optional(),
2980
- limit: z22.number().int().positive().optional(),
2981
- window: XL1BlockRangeZod.optional()
3293
+ import { HashZod as HashZod3 } from "@xylabs/sdk-js";
3294
+ import { XL1BlockRangeZod as XL1BlockRangeZod2 } from "@xyo-network/xl1-protocol";
3295
+ import z23 from "zod";
3296
+ var PendingTransactionsOptionsZod = z23.object({
3297
+ cursor: HashZod3.optional(),
3298
+ limit: z23.number().int().positive().optional(),
3299
+ window: XL1BlockRangeZod2.optional()
3300
+ });
3301
+ var PendingBlocksOptionsZod = z23.object({
3302
+ cursor: HashZod3.optional(),
3303
+ limit: z23.number().int().positive().optional(),
3304
+ window: XL1BlockRangeZod2.optional()
2982
3305
  });
2983
3306
 
2984
3307
  // src/viewers/StakeEvents.ts
@@ -3040,14 +3363,19 @@ export {
3040
3363
  MemoryMap,
3041
3364
  MemoryPermissionsStore,
3042
3365
  MnemonicStringZod,
3366
+ PendingBlocksOptionsZod,
3043
3367
  PendingTransactionsOptionsZod,
3368
+ QualifiedZod,
3044
3369
  RewardMultipliers,
3045
3370
  SchemasStepSummarySchema,
3046
3371
  SimpleAccountBalanceViewer,
3372
+ SimpleBlockRewardViewer,
3047
3373
  SimpleBlockViewer,
3048
3374
  SimpleChainStakeViewer,
3049
3375
  SimpleDataLakeRunner,
3050
3376
  SimpleDataLakeViewer,
3377
+ SimpleMempoolRunner,
3378
+ SimpleMempoolViewer,
3051
3379
  SimpleTimeSyncViewer,
3052
3380
  SimpleXyoClient,
3053
3381
  SimpleXyoGateway,
@@ -3091,6 +3419,7 @@ export {
3091
3419
  blockPayloadsFromHydratedBlock,
3092
3420
  buildTransaction,
3093
3421
  buildUnsignedTransaction,
3422
+ bundledPayloadToHydratedBlock,
3094
3423
  bundledPayloadToHydratedTransaction,
3095
3424
  calculateFramesFromRange,
3096
3425
  completedStepRewardAddress,
@@ -3117,6 +3446,7 @@ export {
3117
3446
  hydrateElevatedTransaction,
3118
3447
  hydrateTransaction,
3119
3448
  hydratedBlockByNumber,
3449
+ hydratedBlockToPayloadBundle,
3120
3450
  hydratedTransactionToPayloadBundle,
3121
3451
  isAddressPairPayload,
3122
3452
  isBalancesStepSummary,
@@ -3146,6 +3476,7 @@ export {
3146
3476
  parseSignedBigInt,
3147
3477
  prettifyZodError,
3148
3478
  readPayloadMapFromStore,
3479
+ rewardFromBlockNumber,
3149
3480
  schemasStepSummaryFromRange,
3150
3481
  schemasSummary,
3151
3482
  signEIP712Message,