@xyo-network/chain-services 1.5.29 → 1.5.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/neutral/index.mjs +252 -384
  2. package/dist/neutral/index.mjs.map +1 -1
  3. package/dist/types/AccountBalance/XyoChainAccountBalanceService.d.ts +8 -1
  4. package/dist/types/AccountBalance/XyoChainAccountBalanceService.d.ts.map +1 -1
  5. package/dist/types/AccountBalance/accountBalanceServiceFromArchivist.d.ts.map +1 -1
  6. package/dist/types/BaseService.d.ts +2 -1
  7. package/dist/types/BaseService.d.ts.map +1 -1
  8. package/dist/types/BlockProducer/XyoBlockProducer.d.ts +4 -4
  9. package/dist/types/BlockProducer/XyoBlockProducer.d.ts.map +1 -1
  10. package/dist/types/{XyoChainBlockNumberIterator.d.ts → ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts} +4 -10
  11. package/dist/types/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts.map +1 -0
  12. package/dist/types/ChainBlockNumberIteration/index.d.ts +3 -0
  13. package/dist/types/ChainBlockNumberIteration/index.d.ts.map +1 -0
  14. package/dist/types/ChainBlockNumberIteration/model/BlockNumberIteration.d.ts +7 -0
  15. package/dist/types/ChainBlockNumberIteration/model/BlockNumberIteration.d.ts.map +1 -0
  16. package/dist/types/ChainBlockNumberIteration/model/index.d.ts +2 -0
  17. package/dist/types/ChainBlockNumberIteration/model/index.d.ts.map +1 -0
  18. package/dist/types/ChainIndexService.d.ts +2 -2
  19. package/dist/types/ChainIndexService.d.ts.map +1 -1
  20. package/dist/types/PendingTransactions/PendingTransactions.d.ts +14 -4
  21. package/dist/types/PendingTransactions/PendingTransactions.d.ts.map +1 -1
  22. package/dist/types/PendingTransactions/bundledPayloadToHydratedTransaction.d.ts +4 -0
  23. package/dist/types/PendingTransactions/bundledPayloadToHydratedTransaction.d.ts.map +1 -0
  24. package/dist/types/PendingTransactions/hydratedTransactionToPayloadBundle.d.ts +5 -0
  25. package/dist/types/PendingTransactions/hydratedTransactionToPayloadBundle.d.ts.map +1 -0
  26. package/dist/types/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
  27. package/dist/types/Staker/Evm/Evm.d.ts +5 -8
  28. package/dist/types/Staker/Evm/Evm.d.ts.map +1 -1
  29. package/dist/types/index.d.ts +1 -2
  30. package/dist/types/index.d.ts.map +1 -1
  31. package/package.json +38 -38
  32. package/src/AccountBalance/XyoChainAccountBalanceService.ts +36 -7
  33. package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +1 -0
  34. package/src/BaseService.ts +2 -1
  35. package/src/BlockProducer/XyoBlockProducer.ts +6 -6
  36. package/src/{XyoChainBlockNumberIterator.ts → ChainBlockNumberIteration/ChainBlockNumberIterationService.ts} +14 -28
  37. package/src/ChainBlockNumberIteration/index.ts +2 -0
  38. package/src/ChainBlockNumberIteration/model/BlockNumberIteration.ts +7 -0
  39. package/src/ChainBlockNumberIteration/model/index.ts +1 -0
  40. package/src/ChainIndexService.ts +2 -2
  41. package/src/PendingTransactions/PendingTransactions.ts +70 -54
  42. package/src/PendingTransactions/bundledPayloadToHydratedTransaction.ts +14 -0
  43. package/src/PendingTransactions/hydratedTransactionToPayloadBundle.ts +23 -0
  44. package/src/StakeIntent/XyoStakeIntentService.ts +3 -2
  45. package/src/Staker/Evm/Evm.ts +34 -39
  46. package/src/index.ts +1 -2
  47. package/dist/types/BaseEthProvider.d.ts +0 -56
  48. package/dist/types/BaseEthProvider.d.ts.map +0 -1
  49. package/dist/types/XyoChainBlockNumberIterator.d.ts.map +0 -1
  50. package/src/BaseEthProvider.ts +0 -219
@@ -30,6 +30,7 @@ var accountBalanceServiceFromArchivist = /* @__PURE__ */ __name(async (archivist
30
30
  isPositiveBigInt(value) ? value.positive : "0"
31
31
  ]));
32
32
  }, "getBalances"),
33
+ name: "ArchivistAccountBalanceService",
33
34
  async sync(head2) {
34
35
  const analysis = await analyzeChain(archivist, [
35
36
  new BalanceAnalyzer()
@@ -58,8 +59,9 @@ var accountBalanceServiceFromArchivist = /* @__PURE__ */ __name(async (archivist
58
59
  // src/AccountBalance/XyoChainAccountBalanceService.ts
59
60
  import { assertEx } from "@xylabs/assert";
60
61
  import { toHex } from "@xylabs/hex";
61
- import { analyzeChain as analyzeChain2, BalanceAnalyzer as BalanceAnalyzer2, isChainSummaryBalances as isChainSummaryBalances2 } from "@xyo-network/chain-analyze";
62
+ import { analyzeChain as analyzeChain2, BalanceAnalyzer as BalanceAnalyzer2, ChainSummaryBalancesSchema as ChainSummaryBalancesSchema2, isChainSummaryBalances as isChainSummaryBalances2 } from "@xyo-network/chain-analyze";
62
63
  import { toPositiveBigInt } from "@xyo-network/chain-protocol";
64
+ import { PayloadBuilder } from "@xyo-network/payload-builder";
63
65
 
64
66
  // src/BaseService.ts
65
67
  import { BaseEmitter } from "@xylabs/events";
@@ -123,7 +125,14 @@ var XyoChainAccountBalanceService = class extends BaseService {
123
125
  __name(this, "XyoChainAccountBalanceService");
124
126
  }
125
127
  _balances = {};
126
- _previousHead = null;
128
+ /**
129
+ * The most recent head that was indexed to
130
+ */
131
+ _firstBlock = null;
132
+ /**
133
+ * The oldest block that was indexed through
134
+ */
135
+ _lastBlock = null;
127
136
  get chainArchivist() {
128
137
  return assertEx(this.params.chainArchivist, () => "chainArchivist is required");
129
138
  }
@@ -141,170 +150,30 @@ var XyoChainAccountBalanceService = class extends BaseService {
141
150
  return result;
142
151
  }
143
152
  async sync(head) {
153
+ const startingBalances = new PayloadBuilder({
154
+ schema: ChainSummaryBalancesSchema2
155
+ }).fields({
156
+ balances: this._balances,
157
+ firstBlock: this._firstBlock,
158
+ lastBlock: this._lastBlock
159
+ }).build();
144
160
  const analysis = await analyzeChain2(this.chainArchivist, [
145
- new BalanceAnalyzer2()
146
- ], head, this._previousHead, -1n, this.tracer);
147
- this._balances = assertEx(analysis.find(isChainSummaryBalances2)?.balances, () => "Failed to sync balances");
161
+ new BalanceAnalyzer2(void 0, void 0, startingBalances)
162
+ ], head, this._firstBlock);
163
+ const allAddressesBalances = analysis.find(isChainSummaryBalances2);
164
+ if (allAddressesBalances === void 0) return;
165
+ this._balances = {
166
+ ...this._balances,
167
+ ...allAddressesBalances.balances
168
+ };
169
+ this._firstBlock = allAddressesBalances.firstBlock;
170
+ if (this._lastBlock === null) this._lastBlock = allAddressesBalances.lastBlock;
148
171
  }
149
172
  };
150
173
  XyoChainAccountBalanceService = _ts_decorate([
151
174
  creatableService()
152
175
  ], XyoChainAccountBalanceService);
153
176
 
154
- // src/BaseEthProvider.ts
155
- var BaseEthProvider = class {
156
- static {
157
- __name(this, "BaseEthProvider");
158
- }
159
- eth_accounts() {
160
- throw new Error("Method not implemented.");
161
- }
162
- eth_blockNumber() {
163
- throw new Error("Method not implemented.");
164
- }
165
- eth_call(_transaction, _blockNumber) {
166
- throw new Error("Method not implemented.");
167
- }
168
- eth_clearSubscriptions(_keepSyncing) {
169
- throw new Error("Method not implemented.");
170
- }
171
- eth_coinbase() {
172
- throw new Error("Method not implemented.");
173
- }
174
- eth_compileLLL(_code) {
175
- throw new Error("Method not implemented.");
176
- }
177
- eth_compileSerpent(_code) {
178
- throw new Error("Method not implemented.");
179
- }
180
- eth_compileSolidity(_code) {
181
- throw new Error("Method not implemented.");
182
- }
183
- eth_estimateGas(_transaction, _blockNumber) {
184
- throw new Error("Method not implemented.");
185
- }
186
- eth_feeHistory(_blockCount, _newestBlock, _rewardPercentiles) {
187
- throw new Error("Method not implemented.");
188
- }
189
- eth_gasPrice() {
190
- throw new Error("Method not implemented.");
191
- }
192
- eth_getBalance(_address, _blockNumber) {
193
- throw new Error("Method not implemented.");
194
- }
195
- eth_getBlockByHash(_blockHash, _hydrated) {
196
- throw new Error("Method not implemented.");
197
- }
198
- eth_getBlockByNumber(_blockNumber, _hydrated) {
199
- throw new Error("Method not implemented.");
200
- }
201
- eth_getBlockTransactionCountByHash(_blockHash) {
202
- throw new Error("Method not implemented.");
203
- }
204
- eth_getBlockTransactionCountByNumber(_blockNumber) {
205
- throw new Error("Method not implemented.");
206
- }
207
- eth_getCode(_address, _blockNumber) {
208
- throw new Error("Method not implemented.");
209
- }
210
- eth_getCompilers() {
211
- throw new Error("Method not implemented.");
212
- }
213
- eth_getFilterChanges(_filterIdentifier) {
214
- throw new Error("Method not implemented.");
215
- }
216
- eth_getFilterLogs(_filterIdentifier) {
217
- throw new Error("Method not implemented.");
218
- }
219
- eth_getLogs(_filter) {
220
- throw new Error("Method not implemented.");
221
- }
222
- eth_getStorageAt(_address, _storageSlot, _blockNumber) {
223
- throw new Error("Method not implemented.");
224
- }
225
- eth_getTransactionByBlockHashAndIndex(_blockHash, _transactionIndex) {
226
- throw new Error("Method not implemented.");
227
- }
228
- eth_getTransactionByBlockNumberAndIndex(_blockNumber, _transactionIndex) {
229
- throw new Error("Method not implemented.");
230
- }
231
- eth_getTransactionByHash(_transactionHash) {
232
- throw new Error("Method not implemented.");
233
- }
234
- eth_getTransactionCount(_address, _blockNumber) {
235
- throw new Error("Method not implemented.");
236
- }
237
- eth_getTransactionReceipt(_transactionHash) {
238
- throw new Error("Method not implemented.");
239
- }
240
- eth_getUncleByBlockHashAndIndex(_blockHash, _uncleIndex) {
241
- throw new Error("Method not implemented.");
242
- }
243
- eth_getUncleByBlockNumberAndIndex(_blockNumber, _uncleIndex) {
244
- throw new Error("Method not implemented.");
245
- }
246
- eth_getUncleCountByBlockHash(_blockHash) {
247
- throw new Error("Method not implemented.");
248
- }
249
- eth_getUncleCountByBlockNumber(_blockNumber) {
250
- throw new Error("Method not implemented.");
251
- }
252
- eth_getWork() {
253
- throw new Error("Method not implemented.");
254
- }
255
- eth_hashrate() {
256
- throw new Error("Method not implemented.");
257
- }
258
- eth_maxPriorityFeePerGas() {
259
- throw new Error("Method not implemented.");
260
- }
261
- eth_mining() {
262
- throw new Error("Method not implemented.");
263
- }
264
- eth_newBlockFilter() {
265
- throw new Error("Method not implemented.");
266
- }
267
- eth_newFilter(_filter) {
268
- throw new Error("Method not implemented.");
269
- }
270
- eth_newPendingTransactionFilter() {
271
- throw new Error("Method not implemented.");
272
- }
273
- eth_protocolVersion() {
274
- throw new Error("Method not implemented.");
275
- }
276
- eth_sendRawTransaction(_transaction) {
277
- throw new Error("Method not implemented.");
278
- }
279
- eth_sendTransaction(_transaction) {
280
- throw new Error("Method not implemented.");
281
- }
282
- eth_sign(_address, _message) {
283
- throw new Error("Method not implemented.");
284
- }
285
- eth_signTransaction(_transaction) {
286
- throw new Error("Method not implemented.");
287
- }
288
- eth_submitHashrate(_hashRate, _id) {
289
- throw new Error("Method not implemented.");
290
- }
291
- eth_submitWork(_nonce, _hash, _digest) {
292
- throw new Error("Method not implemented.");
293
- }
294
- eth_subscribe(..._params) {
295
- throw new Error("Method not implemented.");
296
- }
297
- eth_syncing() {
298
- throw new Error("Method not implemented.");
299
- }
300
- eth_uninstallFilter(_filterIdentifier) {
301
- throw new Error("Method not implemented.");
302
- }
303
- eth_unsubscribe(_subscriptionId) {
304
- throw new Error("Method not implemented.");
305
- }
306
- };
307
-
308
177
  // src/BlockProducer/XyoBlockProducer.ts
309
178
  import { assertEx as assertEx3 } from "@xylabs/assert";
310
179
  import { exists } from "@xylabs/exists";
@@ -312,7 +181,7 @@ import { hexToBigInt, toHex as toHex2 } from "@xylabs/hex";
312
181
  import { isUndefined } from "@xylabs/typeof";
313
182
  import { FixedPercentageBlockRewardDiviner, FixedPercentageBlockRewardDivinerConfigSchema } from "@xyo-network/chain-modules";
314
183
  import { buildBlock } from "@xyo-network/chain-protocol";
315
- import { PayloadBuilder } from "@xyo-network/payload-builder";
184
+ import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
316
185
  import { asBlockBoundWitness, BlockNumberSchema, ChainStakeIntentSchema } from "@xyo-network/xl1-protocol";
317
186
 
318
187
  // src/BlockProducer/generateTransactionFeeTransfers.ts
@@ -394,8 +263,8 @@ var XyoBlockProducer = class _XyoBlockProducer extends BaseService {
394
263
  get pendingTransactionsService() {
395
264
  return assertEx3(this.params.pendingTransactionsService, () => "Missing pendingTransactionsService");
396
265
  }
397
- get rejectedBundledTransactionsArchivist() {
398
- return assertEx3(this.params.rejectedBundledTransactionsArchivist, () => "No rejected bundled transactions archivist");
266
+ get rejectedTransactionsArchivist() {
267
+ return assertEx3(this.params.rejectedTransactionsArchivist, () => "No rejected bundled transactions archivist");
399
268
  }
400
269
  get rewardAddress() {
401
270
  return assertEx3(this.params.rewardAddress, () => "No reward address provided");
@@ -428,7 +297,7 @@ var XyoBlockProducer = class _XyoBlockProducer extends BaseService {
428
297
  });
429
298
  }
430
299
  const blockHex = assertEx3(toHex2(block), () => "Failed to convert block to hex");
431
- const blockId = new PayloadBuilder({
300
+ const blockId = new PayloadBuilder2({
432
301
  schema: BlockNumberSchema
433
302
  }).fields({
434
303
  block: blockHex
@@ -454,7 +323,7 @@ var XyoBlockProducer = class _XyoBlockProducer extends BaseService {
454
323
  const currentBlock = head.block;
455
324
  const timeToProducerExpiration = currentDeclarationEnd - currentBlock;
456
325
  if (timeToProducerExpiration > XYO_PRODUCER_RESTAKE_WINDOW) return;
457
- const intent = new PayloadBuilder({
326
+ const intent = new PayloadBuilder2({
458
327
  schema: ChainStakeIntentSchema
459
328
  }).fields({
460
329
  from: this.address,
@@ -502,7 +371,7 @@ var XyoBlockProducer = class _XyoBlockProducer extends BaseService {
502
371
  if (errors.length > 0) {
503
372
  this.logger?.warn(`Validation of produced block failed: ${errors.at(0)?.message}`);
504
373
  const rejectedTransactions = block[1];
505
- await this.rejectedBundledTransactionsArchivist.insert(rejectedTransactions);
374
+ await this.rejectedTransactionsArchivist.insert(rejectedTransactions);
506
375
  } else {
507
376
  return block;
508
377
  }
@@ -616,9 +485,96 @@ XyoBlockRewardService = _ts_decorate4([
616
485
  ])
617
486
  ], XyoBlockRewardService);
618
487
 
619
- // src/ChainValidator/XyoValidator.ts
488
+ // src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts
620
489
  import { assertEx as assertEx6 } from "@xylabs/assert";
621
- import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
490
+ import { isDefined as isDefined2, isNull } from "@xylabs/typeof";
491
+ import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
492
+ import { asBlockBoundWitness as asBlockBoundWitness2, asOptionalBlockBoundWitness, isBlockBoundWitness } from "@xyo-network/xl1-protocol";
493
+ import { LRUCache } from "lru-cache";
494
+ var ChainBlockNumberIterationService = class extends BaseService {
495
+ static {
496
+ __name(this, "ChainBlockNumberIterationService");
497
+ }
498
+ _blocksByBlockNumber = new LRUCache({
499
+ max: 1e4
500
+ });
501
+ get chainArchivist() {
502
+ return assertEx6(this.params.chainArchivist);
503
+ }
504
+ get chainIdentification() {
505
+ return {
506
+ id: assertEx6(this.params.head?.chain)
507
+ };
508
+ }
509
+ async get(block) {
510
+ const head = await this.head();
511
+ assertEx6(head.block >= block, () => `Block requested is newer than the current head [${block}]`);
512
+ const cached = this._blocksByBlockNumber.get(block);
513
+ if (cached) return cached;
514
+ const startingBlock = head;
515
+ const currentBlockHash = await PayloadBuilder3.hash(startingBlock);
516
+ let currentBlock = (await this.chainArchivist.get([
517
+ currentBlockHash
518
+ ])).at(0);
519
+ while (isDefined2(currentBlock)) {
520
+ assertEx6(asBlockBoundWitness2(currentBlock), () => `Expected hash to be a block bound witness [${currentBlock?._hash}]`);
521
+ if (isBlockBoundWitness(currentBlock)) {
522
+ this._blocksByBlockNumber.set(currentBlock.block, currentBlock);
523
+ if (currentBlock.block === block) {
524
+ return currentBlock;
525
+ }
526
+ const { previous } = currentBlock;
527
+ if (isNull(previous)) break;
528
+ currentBlock = (await this.chainArchivist.get([
529
+ previous
530
+ ])).at(0);
531
+ }
532
+ }
533
+ throw new Error(`Block not found: ${block}`);
534
+ }
535
+ async head() {
536
+ return await Promise.resolve(assertEx6(this.params.head));
537
+ }
538
+ async next(block) {
539
+ const currentBlock = block;
540
+ const nextBlockNumber = currentBlock + 1;
541
+ return await this.get(nextBlockNumber);
542
+ }
543
+ // TODO: Decide on inclusive/exclusive (probably need inclusive to account for chain head)
544
+ // and then communicate via method name and documentation
545
+ async previous(block = void 0, count = 1) {
546
+ const results = [];
547
+ let currentBlock = isDefined2(block) ? await this.get(block) : await this.head();
548
+ while (currentBlock && results.length < count) {
549
+ if (isBlockBoundWitness(currentBlock)) {
550
+ results.push(currentBlock);
551
+ const { previous } = currentBlock;
552
+ if (isNull(previous)) break;
553
+ const nextBlock = await this.chainArchivist.get([
554
+ previous
555
+ ]);
556
+ currentBlock = asOptionalBlockBoundWitness(nextBlock[0]);
557
+ } else {
558
+ const hash = PayloadBuilder3.hash(currentBlock);
559
+ assertEx6(asBlockBoundWitness2(currentBlock), () => `Expected hash to be a block bound witness [${hash}]`);
560
+ }
561
+ }
562
+ return results;
563
+ }
564
+ async updateHead(head) {
565
+ await Promise.resolve();
566
+ this.params.head = head;
567
+ void this.emit("headUpdated", {
568
+ blocks: [
569
+ head
570
+ ]
571
+ });
572
+ }
573
+ };
574
+
575
+ // src/ChainValidator/XyoValidator.ts
576
+ import { assertEx as assertEx7 } from "@xylabs/assert";
577
+ import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
622
578
  function _ts_decorate5(decorators, target, key, desc) {
623
579
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
624
580
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -628,8 +584,8 @@ function _ts_decorate5(decorators, target, key, desc) {
628
584
  __name(_ts_decorate5, "_ts_decorate");
629
585
  var addStorageMeta = /* @__PURE__ */ __name(async ([tx, payloads]) => {
630
586
  return [
631
- await PayloadBuilder2.addStorageMeta(tx),
632
- await PayloadBuilder2.addStorageMeta(payloads)
587
+ await PayloadBuilder4.addStorageMeta(tx),
588
+ await PayloadBuilder4.addStorageMeta(payloads)
633
589
  ];
634
590
  }, "addStorageMeta");
635
591
  var XyoValidator = class extends BaseService {
@@ -640,22 +596,22 @@ var XyoValidator = class extends BaseService {
640
596
  return this.account.address;
641
597
  }
642
598
  get account() {
643
- return assertEx6(this.params.account, () => "account is required");
599
+ return assertEx7(this.params.account, () => "account is required");
644
600
  }
645
601
  get chainArchivist() {
646
- return assertEx6(this.params.chainArchivist, () => "chainArchivist is required");
602
+ return assertEx7(this.params.chainArchivist, () => "chainArchivist is required");
647
603
  }
648
604
  get chainInfo() {
649
- return assertEx6(this.params.chainInformation, () => "chainInfo is required");
605
+ return assertEx7(this.params.chainInformation, () => "chainInfo is required");
650
606
  }
651
607
  get electionService() {
652
- return assertEx6(this.params.electionService, () => "electionService is required");
608
+ return assertEx7(this.params.electionService, () => "electionService is required");
653
609
  }
654
610
  get pendingBundledTransactionsArchivist() {
655
- return assertEx6(this.params.pendingBundledTransactionsArchivist, () => "pendingBundledTransactions is required");
611
+ return assertEx7(this.params.pendingBundledTransactionsArchivist, () => "pendingBundledTransactions is required");
656
612
  }
657
613
  get rewardService() {
658
- return assertEx6(this.params.rewardService, () => "rewardService is required");
614
+ return assertEx7(this.params.rewardService, () => "rewardService is required");
659
615
  }
660
616
  validatePendingBlock(_block) {
661
617
  return [];
@@ -674,9 +630,9 @@ XyoValidator = _ts_decorate5([
674
630
  ], XyoValidator);
675
631
 
676
632
  // src/Election/XyoElectionService.ts
677
- import { assertEx as assertEx7 } from "@xylabs/assert";
633
+ import { assertEx as assertEx8 } from "@xylabs/assert";
678
634
  import { hexToLast4BytesInt, shuffleWithSeed } from "@xyo-network/chain-utils";
679
- import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
635
+ import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
680
636
  function _ts_decorate6(decorators, target, key, desc) {
681
637
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
682
638
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -696,19 +652,19 @@ var XyoElectionService = class extends BaseService {
696
652
  super(params);
697
653
  }
698
654
  get chainIterator() {
699
- return assertEx7(this.params.chainIterator, () => "No chain iterator");
655
+ return assertEx8(this.params.chainIterator, () => "No chain iterator");
700
656
  }
701
657
  get chainStakeViewer() {
702
- return assertEx7(this.params.chainStakeViewer, () => "No chain stake viewer");
658
+ return assertEx8(this.params.chainStakeViewer, () => "No chain stake viewer");
703
659
  }
704
660
  get stakeIntentService() {
705
- return assertEx7(this.params.stakeIntentService, () => "No staked intent service");
661
+ return assertEx8(this.params.stakeIntentService, () => "No staked intent service");
706
662
  }
707
663
  async getCreatorCommitteeForNextBlock(current) {
708
664
  return await this.spanAsync("getCreatorCommitteeForNextBlock", async () => {
709
665
  const nextBlock = current.block + 1;
710
666
  const candidates = await this.stakeIntentService.getDeclaredCandidatesForBlock(nextBlock, "producer");
711
- const previousBlockHash = await PayloadBuilder3.hash(current);
667
+ const previousBlockHash = await PayloadBuilder5.hash(current);
712
668
  return this.generateCreatorCommittee(candidates, previousBlockHash);
713
669
  });
714
670
  }
@@ -730,34 +686,56 @@ XyoElectionService = _ts_decorate6([
730
686
  // src/PendingTransactions/PendingTransactions.ts
731
687
  import { ValueType } from "@opentelemetry/api";
732
688
  import { filterAsync } from "@xylabs/array";
733
- import { assertEx as assertEx8 } from "@xylabs/assert";
689
+ import { assertEx as assertEx9 } from "@xylabs/assert";
734
690
  import { exists as exists2 } from "@xylabs/exists";
735
691
  import { forget } from "@xylabs/forget";
736
692
  import { MemoryArchivist } from "@xyo-network/archivist-memory";
737
693
  import { globalAttributes } from "@xyo-network/chain-telemetry";
738
694
  import { validateTransaction } from "@xyo-network/chain-validation";
739
- import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
740
- import { asOptionalTransactionBoundWitnessWithStorageMeta, isTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
741
- import { flattenHydratedTransaction } from "@xyo-network/xl1-protocol-sdk";
695
+ import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/payload-builder";
696
+ import { asOptionalTransactionBoundWitnessWithStorageMeta as asOptionalTransactionBoundWitnessWithStorageMeta2, isTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
742
697
  import { Mutex as Mutex2 } from "async-mutex";
743
- function _ts_decorate7(decorators, target, key, desc) {
744
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
745
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
746
- 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;
747
- return c > 3 && r && Object.defineProperty(target, key, r), r;
748
- }
749
- __name(_ts_decorate7, "_ts_decorate");
750
- async function bundledPayloadsToHydratedTransaction(payload) {
751
- const withStorageMeta = await PayloadBuilder4.addStorageMeta(payload.payloads);
698
+
699
+ // src/PendingTransactions/bundledPayloadToHydratedTransaction.ts
700
+ import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
701
+ import { asOptionalTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
702
+ var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload) => {
703
+ const withStorageMeta = await PayloadBuilder6.addStorageMeta(payload.payloads);
752
704
  const tx = asOptionalTransactionBoundWitnessWithStorageMeta(withStorageMeta.find((p) => p._hash === payload.root));
753
705
  if (tx) {
754
706
  return [
755
707
  tx,
756
- withStorageMeta.map((p) => p._hash === payload.root ? void 0 : p).filter(exists2)
708
+ withStorageMeta.filter((p) => p._hash !== payload.root)
757
709
  ];
758
710
  }
711
+ }, "bundledPayloadToHydratedTransaction");
712
+
713
+ // src/PendingTransactions/hydratedTransactionToPayloadBundle.ts
714
+ import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
715
+ import { PayloadBundleSchema } from "@xyo-network/payload-model";
716
+ import { flattenHydratedTransaction } from "@xyo-network/xl1-protocol-sdk";
717
+ var hydratedTransactionWithHashStorageMetaToPayloadBundle = /* @__PURE__ */ __name((transaction) => {
718
+ const root = transaction[0]._hash;
719
+ return bundle(root, transaction);
720
+ }, "hydratedTransactionWithHashStorageMetaToPayloadBundle");
721
+ var bundle = /* @__PURE__ */ __name((root, transaction) => {
722
+ const payloads = flattenHydratedTransaction(transaction).flatMap((p) => PayloadBuilder7.omitStorageMeta(p));
723
+ return new PayloadBuilder7({
724
+ schema: PayloadBundleSchema
725
+ }).fields({
726
+ payloads,
727
+ root
728
+ }).build();
729
+ }, "bundle");
730
+
731
+ // src/PendingTransactions/PendingTransactions.ts
732
+ function _ts_decorate7(decorators, target, key, desc) {
733
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
734
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
735
+ 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;
736
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
759
737
  }
760
- __name(bundledPayloadsToHydratedTransaction, "bundledPayloadsToHydratedTransaction");
738
+ __name(_ts_decorate7, "_ts_decorate");
761
739
  globalAttributes.setAttribute("XyoPendingTransactionsService:status", "unknown");
762
740
  var XyoPendingTransactionsService = class _XyoPendingTransactionsService extends BaseService {
763
741
  static {
@@ -795,6 +773,11 @@ var XyoPendingTransactionsService = class _XyoPendingTransactionsService extends
795
773
  * The last count of total pending transactions
796
774
  */
797
775
  _pendingTransactionsCount = 0;
776
+ /**
777
+ * A set of transaction hashes that are pending removal from the
778
+ * curated pending transactions archivist. This is used to track
779
+ * which transactions need to be removed from the archivist.
780
+ */
798
781
  _removablePendingTransactionHashes = /* @__PURE__ */ new Set();
799
782
  /**
800
783
  * A mutex to ensure that the curated pending transactions archivist is
@@ -802,23 +785,23 @@ var XyoPendingTransactionsService = class _XyoPendingTransactionsService extends
802
785
  */
803
786
  _updateCuratedPendingTransactionsArchivistMutex = new Mutex2();
804
787
  get chainArchivist() {
805
- return assertEx8(this.params.chainArchivist, () => "No completed blocks with data archivist");
788
+ return assertEx9(this.params.chainArchivist, () => "No completed blocks with data archivist");
806
789
  }
807
790
  get chainIdentification() {
808
- return assertEx8(this.params.chainIdentification, () => "No chain id");
791
+ return assertEx9(this.params.chainIdentification, () => "No chain id");
809
792
  }
810
793
  get pendingBundledTransactionsArchivist() {
811
- return assertEx8(this.params.pendingBundledTransactionsArchivist, () => "No pending bundled transactions archivist");
794
+ return assertEx9(this.params.pendingBundledTransactionsArchivist, () => "No pending bundled transactions archivist");
812
795
  }
813
796
  get pendingBundledTransactionsLocalArchivist() {
814
- return assertEx8(this._curatedPendingBundledTransactionsArchivist, () => "No pending bundled transactions curated archivist");
797
+ return assertEx9(this._curatedPendingBundledTransactionsArchivist, () => "No pending bundled transactions curated archivist");
815
798
  }
816
799
  get pendingTransactionsCount() {
817
800
  forget(this.countPendingTransactions());
818
801
  return this._pendingTransactionsCount;
819
802
  }
820
- get rejectedBundledTransactionsArchivist() {
821
- return assertEx8(this.params.rejectedBundledTransactionsArchivist, () => "No rejected bundled transactions archivist");
803
+ get rejectedTransactionsArchivist() {
804
+ return assertEx9(this.params.rejectedTransactionsArchivist, () => "No rejected transactions archivist");
822
805
  }
823
806
  async createHandler() {
824
807
  await super.createHandler();
@@ -829,10 +812,10 @@ var XyoPendingTransactionsService = class _XyoPendingTransactionsService extends
829
812
  await this.insertNewTransactions(payloads);
830
813
  });
831
814
  this.chainArchivist.on("inserted", ({ payloads }) => {
832
- this.removeFinalizedTransactions(payloads);
815
+ this.markAnyIncludedTransactionsForRemoval(payloads);
833
816
  });
834
- this.rejectedBundledTransactionsArchivist.on("inserted", ({ payloads }) => {
835
- this.removeRejectedBundledTransactions(payloads);
817
+ this.rejectedTransactionsArchivist.on("inserted", ({ payloads }) => {
818
+ this.markAnyIncludedTransactionsForRemoval(payloads);
836
819
  });
837
820
  const pendingTransactionsCounter = this.meter?.createObservableUpDownCounter("xyo_pending_transactions_counter", {
838
821
  description: "The current number of pending transactions",
@@ -861,13 +844,13 @@ var XyoPendingTransactionsService = class _XyoPendingTransactionsService extends
861
844
  const deletedTransactionBundles = payloads.filter((tx) => this._removablePendingTransactionHashes.has(tx.root));
862
845
  foundPendingTransactionsToDeleteHashes.push(...deletedTransactionBundles.map((tx) => tx._hash).filter(exists2));
863
846
  const undeletedTransactionBundles = payloads.filter((tx) => !this._removablePendingTransactionHashes.has(tx.root));
864
- const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadsToHydratedTransaction(p)))).filter(exists2);
847
+ const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(exists2);
865
848
  foundPendingTransactions.push(...transactions);
866
849
  }
850
+ await this.pendingBundledTransactionsLocalArchivist.delete(foundPendingTransactionsToDeleteHashes);
867
851
  for (const hash of foundPendingTransactionsToDeleteHashes) {
868
852
  this._removablePendingTransactionHashes.delete(hash);
869
853
  }
870
- await this.pendingBundledTransactionsLocalArchivist.delete(foundPendingTransactionsToDeleteHashes);
871
854
  return foundPendingTransactions;
872
855
  }, _XyoPendingTransactionsService.MutexPriority.ReadTransactions);
873
856
  });
@@ -887,12 +870,13 @@ var XyoPendingTransactionsService = class _XyoPendingTransactionsService extends
887
870
  return nonFinalizedTransactions;
888
871
  }
889
872
  async insertNewTransactions(payloads) {
873
+ if (payloads.length === 0) return;
890
874
  this.logger?.log("insertNewTransactions", payloads);
891
875
  return await this.spanAsync("InsertNewTransactions", async () => {
892
876
  return await this._updateCuratedPendingTransactionsArchivistMutex.runExclusive(async () => {
893
877
  const unprocessedTransactions = await this.filterAlreadyFinalizedTransactions(payloads);
894
878
  const hydratedUnprocessedTransactions = (await Promise.all(unprocessedTransactions.map(async (tx) => {
895
- return await bundledPayloadsToHydratedTransaction(tx);
879
+ return await bundledPayloadToHydratedTransaction(tx);
896
880
  }))).filter(exists2);
897
881
  const validTransactions = await filterAsync(hydratedUnprocessedTransactions, async (tx) => {
898
882
  const errors = await validateTransaction(tx, this.chainIdentification.id);
@@ -902,40 +886,36 @@ var XyoPendingTransactionsService = class _XyoPendingTransactionsService extends
902
886
  return errors.length > 0 ? false : true;
903
887
  });
904
888
  if (validTransactions.length > 0) {
905
- await this.pendingBundledTransactionsLocalArchivist.insert(validTransactions.map((tx) => {
906
- return {
907
- root: tx[0]._hash,
908
- payloads: flattenHydratedTransaction(tx)
909
- };
910
- }));
889
+ const bundledTransactions = validTransactions.map((tx) => hydratedTransactionWithHashStorageMetaToPayloadBundle(tx));
890
+ await this.pendingBundledTransactionsLocalArchivist.insert(bundledTransactions);
911
891
  }
912
892
  }, _XyoPendingTransactionsService.MutexPriority.InsertNewTransactions);
913
893
  });
914
894
  }
895
+ /**
896
+ * Marks any included transactions in the provided payloads for removal preventing them
897
+ * from being included in the curated pending transactions archivist and from being offered
898
+ * during the next retrieval of pending transactions.
899
+ * @param payloads An array of payloads that may contain transactions.
900
+ */
901
+ markAnyIncludedTransactionsForRemoval(payloads) {
902
+ const hashes = payloads.filter(isTransactionBoundWitnessWithStorageMeta).map((p) => p._hash);
903
+ for (const hash of hashes) {
904
+ this._removablePendingTransactionHashes.add(hash);
905
+ }
906
+ }
915
907
  async removeBundledTransactions(bundledPayloads, priority) {
916
908
  return await this.spanAsync(priority, async () => {
917
909
  return await this._updateCuratedPendingTransactionsArchivistMutex.runExclusive(async () => {
918
910
  const bundledTransactions = (await Promise.all(bundledPayloads.map(async (payload) => {
919
- const withStorageMeta = await PayloadBuilder4.addStorageMeta(payload.payloads);
920
- const tx = asOptionalTransactionBoundWitnessWithStorageMeta(withStorageMeta.find((p) => p._hash === payload.root));
911
+ const withStorageMeta = await PayloadBuilder8.addStorageMeta(payload.payloads);
912
+ const tx = asOptionalTransactionBoundWitnessWithStorageMeta2(withStorageMeta.find((p) => p._hash === payload.root));
921
913
  return tx !== void 0 && payload._hash !== void 0 ? tx : void 0;
922
914
  }))).filter(exists2);
923
915
  await this.pendingBundledTransactionsLocalArchivist.delete(bundledTransactions.map((btx) => btx._hash));
924
916
  }, _XyoPendingTransactionsService.MutexPriority[priority]);
925
917
  });
926
918
  }
927
- removeFinalizedTransactions(payloads) {
928
- const finalizedTransactionHashes = payloads.filter(isTransactionBoundWitnessWithStorageMeta).map((p) => p._hash);
929
- for (const hash of finalizedTransactionHashes) {
930
- this._removablePendingTransactionHashes.add(hash);
931
- }
932
- }
933
- removeRejectedBundledTransactions(payloads) {
934
- const rejectedTransactionHashes = payloads.filter(isTransactionBoundWitnessWithStorageMeta).map((p) => p._hash);
935
- for (const hash of rejectedTransactionHashes) {
936
- this._removablePendingTransactionHashes.add(hash);
937
- }
938
- }
939
919
  };
940
920
  XyoPendingTransactionsService = _ts_decorate7([
941
921
  creatableService()
@@ -970,14 +950,14 @@ var mapBoundWitnessToStakeIntentHashes = /* @__PURE__ */ __name((bw) => {
970
950
 
971
951
  // src/StakeIntent/XyoStakeIntentService.ts
972
952
  import { filterAs as filterAs2 } from "@xylabs/array";
973
- import { assertEx as assertEx9 } from "@xylabs/assert";
953
+ import { assertEx as assertEx10 } from "@xylabs/assert";
974
954
  import { asAddress } from "@xylabs/hex";
975
955
  import { analyzeChain as analyzeChain3, ChainStakeIntentAnalyzer, isChainSummaryStakeIntent } from "@xyo-network/chain-analyze";
976
956
  import { DEFAULT_FIND_FIRST_MATCHING_NEXT_OPTIONS, findFirstMatching, IntervalMap } from "@xyo-network/chain-utils";
977
- import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
978
- import { asOptionalBlockBoundWitness, asOptionalBlockBoundWitnessWithStorageMeta, asOptionalChainIndexingServiceStateWithStorageMeta, asOptionalChainStakeIntent as asOptionalChainStakeIntent2, ChainIndexingServiceStateSchema, isChainIndexingServiceState } from "@xyo-network/xl1-protocol";
957
+ import { PayloadBuilder as PayloadBuilder9 } from "@xyo-network/payload-builder";
958
+ import { asChainIndexingServiceStateWithStorageMeta, asOptionalBlockBoundWitness as asOptionalBlockBoundWitness2, asOptionalBlockBoundWitnessWithStorageMeta, asOptionalChainStakeIntent as asOptionalChainStakeIntent2, ChainIndexingServiceStateSchema, isChainIndexingServiceState } from "@xyo-network/xl1-protocol";
979
959
  import { Mutex as Mutex3 } from "async-mutex";
980
- import { LRUCache } from "lru-cache";
960
+ import { LRUCache as LRUCache2 } from "lru-cache";
981
961
  function _ts_decorate8(decorators, target, key, desc) {
982
962
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
983
963
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1006,7 +986,7 @@ var XyoStakeIntentService = class extends BaseService {
1006
986
  // in performance for small sets, and (most importantly) easily
1007
987
  // persisted so we can recover state on restart.
1008
988
  _producers = new IntervalMap();
1009
- _stakeCache = new LRUCache({
989
+ _stakeCache = new LRUCache2({
1010
990
  max: STAKE_CACHE_MAX_ENTRIES
1011
991
  });
1012
992
  _updateMutex = new Mutex3();
@@ -1017,33 +997,33 @@ var XyoStakeIntentService = class extends BaseService {
1017
997
  });
1018
998
  }
1019
999
  get chainArchivist() {
1020
- return assertEx9(this.params.chainArchivist, () => "chainArchivist not set");
1000
+ return assertEx10(this.params.chainArchivist, () => "chainArchivist not set");
1021
1001
  }
1022
1002
  get chainIterator() {
1023
- return assertEx9(this.params.chainIterator, () => "chainIterator not set");
1003
+ return assertEx10(this.params.chainIterator, () => "chainIterator not set");
1024
1004
  }
1025
1005
  get chainStakeViewer() {
1026
- return assertEx9(this.params.chainStakeViewer, () => "chainStakeViewer not set");
1006
+ return assertEx10(this.params.chainStakeViewer, () => "chainStakeViewer not set");
1027
1007
  }
1028
1008
  get stakeIntentStateArchivist() {
1029
- return assertEx9(this.params.stakeIntentStateArchivist, () => "stakeIntentStateArchivist not set");
1009
+ return assertEx10(this.params.stakeIntentStateArchivist, () => "stakeIntentStateArchivist not set");
1030
1010
  }
1031
1011
  async createHandler() {
1032
1012
  const head = await this.chainIterator.head();
1033
- const headHash = await PayloadBuilder5.hash(head);
1013
+ const headHash = await PayloadBuilder9.hash(head);
1034
1014
  if (head?.block === void 0) return;
1035
1015
  await this.recoverState(headHash);
1036
1016
  await this.updateIndex(true);
1037
1017
  }
1038
1018
  async getDeclaredCandidateRanges(address, intent) {
1039
1019
  await Promise.resolve();
1040
- assertEx9(intent === "producer", () => `Error: Support not yet added for intent ${intent}`);
1020
+ assertEx10(intent === "producer", () => `Error: Support not yet added for intent ${intent}`);
1041
1021
  const results = this._producers.get(address);
1042
1022
  return results ?? [];
1043
1023
  }
1044
1024
  async getDeclaredCandidatesForBlock(block, intent) {
1045
1025
  return await this.spanAsync("getDeclaredCandidatesForBlock", async () => {
1046
- assertEx9(intent === "producer", () => `Error: Support not yet added for intent ${intent}`);
1026
+ assertEx10(intent === "producer", () => `Error: Support not yet added for intent ${intent}`);
1047
1027
  const results = this._producers.findAllContaining(block);
1048
1028
  const candidates = [
1049
1029
  ...results
@@ -1085,7 +1065,7 @@ var XyoStakeIntentService = class extends BaseService {
1085
1065
  }
1086
1066
  async persistState(current) {
1087
1067
  const state = this._producers.serialize();
1088
- const payload = new PayloadBuilder5({
1068
+ const payload = new PayloadBuilder9({
1089
1069
  schema: ChainIndexingServiceStateSchema
1090
1070
  }).fields({
1091
1071
  endBlockHash: current,
@@ -1096,7 +1076,7 @@ var XyoStakeIntentService = class extends BaseService {
1096
1076
  ]);
1097
1077
  }
1098
1078
  async recoverState(current) {
1099
- const currentBlock = assertEx9(asOptionalBlockBoundWitness((await this.chainArchivist.get([
1079
+ const currentBlock = assertEx10(asOptionalBlockBoundWitness2((await this.chainArchivist.get([
1100
1080
  current
1101
1081
  ]))?.[0]), () => `Block ${current} not found`);
1102
1082
  const currentBlockNum = currentBlock.block;
@@ -1105,7 +1085,7 @@ var XyoStakeIntentService = class extends BaseService {
1105
1085
  };
1106
1086
  while (true) {
1107
1087
  const predicate = /* @__PURE__ */ __name((p) => {
1108
- const state2 = asOptionalChainIndexingServiceStateWithStorageMeta(p);
1088
+ const state2 = asChainIndexingServiceStateWithStorageMeta(p);
1109
1089
  return state2 ? true : false;
1110
1090
  }, "predicate");
1111
1091
  const state = await findFirstMatching(this.stakeIntentStateArchivist, predicate, opts);
@@ -1136,7 +1116,7 @@ var XyoStakeIntentService = class extends BaseService {
1136
1116
  await this._updateMutex.runExclusive(async () => {
1137
1117
  return await this.spanAsync("updateIndex", async () => {
1138
1118
  const currentHead = await this.chainIterator.head();
1139
- const currentHeadHash = await PayloadBuilder5.hash(currentHead);
1119
+ const currentHeadHash = await PayloadBuilder9.hash(currentHead);
1140
1120
  const result = await analyzeChain3(this.chainArchivist, [
1141
1121
  new ChainStakeIntentAnalyzer("producer")
1142
1122
  ], currentHeadHash, this._lastIndexedBlockHash);
@@ -1167,200 +1147,89 @@ XyoStakeIntentService = _ts_decorate8([
1167
1147
  ], XyoStakeIntentService);
1168
1148
 
1169
1149
  // src/Staker/Evm/Evm.ts
1170
- import { Base } from "@xylabs/base";
1150
+ import { assertEx as assertEx11 } from "@xylabs/assert";
1171
1151
  import { toAddress } from "@xylabs/hex";
1152
+ import { toEthAddress as toEthAddress2 } from "@xyo-network/chain-ethereum";
1172
1153
  import { StakedXyoChain__factory as StakedXyoChainFactory } from "@xyo-network/typechain";
1173
1154
  import { getAddress } from "ethers/address";
1174
- var EvmChainService = class extends Base {
1155
+ var EvmChainService = class extends BaseService {
1175
1156
  static {
1176
1157
  __name(this, "EvmChainService");
1177
1158
  }
1178
- _contract;
1179
- constructor(params) {
1180
- super(params);
1181
- this._contract = params.contract;
1159
+ get contract() {
1160
+ if (this.params.contract === void 0) {
1161
+ this.params.contract = StakedXyoChainFactory.connect(toEthAddress2(this.id), this.params.runner);
1162
+ }
1163
+ return assertEx11(this.params.contract);
1182
1164
  }
1183
1165
  get id() {
1184
- return this.params.id;
1166
+ return assertEx11(this.params.id);
1185
1167
  }
1186
1168
  get runner() {
1187
- return this.params.runner;
1188
- }
1189
- static create({ id, runner, logger, traceProvider, meterProvider }) {
1190
- const contractAddress = getAddress(id);
1191
- const contract = StakedXyoChainFactory.connect(contractAddress, runner);
1192
- return new this({
1193
- id,
1194
- contract,
1195
- runner,
1196
- logger,
1197
- traceProvider,
1198
- meterProvider
1199
- });
1169
+ return assertEx11(this.params.runner);
1200
1170
  }
1201
1171
  async active() {
1202
- return await this._contract.active();
1172
+ return await this.contract.active();
1203
1173
  }
1204
1174
  async activeByAddressStaked(address) {
1205
- return await this._contract.activeByAddressStaked(getAddress(address));
1175
+ return await this.contract.activeByAddressStaked(getAddress(address));
1206
1176
  }
1207
1177
  async activeByStaker(address) {
1208
- return await this._contract.activeByStaker(getAddress(address));
1178
+ return await this.contract.activeByStaker(getAddress(address));
1209
1179
  }
1210
1180
  async addStake(staked, amount) {
1211
- const result = await this._contract.addStake(getAddress(staked), amount);
1181
+ const result = await this.contract.addStake(getAddress(staked), amount);
1212
1182
  await result.wait();
1213
1183
  return true;
1214
1184
  }
1215
1185
  async chainId() {
1216
- return toAddress(await this._contract.chainId());
1186
+ return toAddress(await this.contract.chainId());
1217
1187
  }
1218
1188
  async forkedAtBlockNumber() {
1219
- return await this._contract.forkedAtBlockNumber();
1189
+ return await this.contract.forkedAtBlockNumber();
1220
1190
  }
1221
1191
  async forkedAtHash() {
1222
- return await this._contract.forkedAtHash();
1192
+ return await this.contract.forkedAtHash();
1223
1193
  }
1224
1194
  async forkedChainId() {
1225
- return toAddress(await this._contract.forkedChainId());
1195
+ return toAddress(await this.contract.forkedChainId());
1226
1196
  }
1227
1197
  async minWithdrawalBlocks() {
1228
- return await this._contract.minWithdrawalBlocks();
1198
+ return await this.contract.minWithdrawalBlocks();
1229
1199
  }
1230
1200
  async pending() {
1231
- return await this._contract.pending();
1201
+ return await this.contract.pending();
1232
1202
  }
1233
1203
  async pendingByStaker(staker) {
1234
- return await this._contract.pendingByStaker(getAddress(staker));
1204
+ return await this.contract.pendingByStaker(getAddress(staker));
1235
1205
  }
1236
1206
  async removeStake(slot) {
1237
- const result = await this._contract.removeStake(slot);
1207
+ const result = await this.contract.removeStake(slot);
1238
1208
  await result.wait();
1239
1209
  return true;
1240
1210
  }
1241
1211
  async rewardsContract() {
1242
- return await this._contract.rewardsContract();
1212
+ return await this.contract.rewardsContract();
1243
1213
  }
1244
1214
  async stakingTokenAddress() {
1245
- return await this._contract.stakingTokenAddress();
1215
+ return await this.contract.stakingTokenAddress();
1246
1216
  }
1247
1217
  async withdrawStake(slot) {
1248
- const result = await this._contract.withdrawStake(slot);
1218
+ const result = await this.contract.withdrawStake(slot);
1249
1219
  await result.wait();
1250
1220
  return true;
1251
1221
  }
1252
1222
  async withdrawn() {
1253
- return await this._contract.withdrawn();
1223
+ return await this.contract.withdrawn();
1254
1224
  }
1255
1225
  async withdrawnByStaker(staker) {
1256
- return await this._contract.withdrawnByStaker(getAddress(staker));
1257
- }
1258
- };
1259
-
1260
- // src/XyoChainBlockNumberIterator.ts
1261
- import { assertEx as assertEx10 } from "@xylabs/assert";
1262
- import { BaseEmitter as BaseEmitter2 } from "@xylabs/events";
1263
- import { isDefined as isDefined2, isNull } from "@xylabs/typeof";
1264
- import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
1265
- import { asBlockBoundWitness as asBlockBoundWitness2, asOptionalBlockBoundWitness as asOptionalBlockBoundWitness2, isBlockBoundWitness } from "@xyo-network/xl1-protocol";
1266
- import { LRUCache as LRUCache2 } from "lru-cache";
1267
- var XyoChainBlockNumberIterator = class _XyoChainBlockNumberIterator extends BaseEmitter2 {
1268
- static {
1269
- __name(this, "XyoChainBlockNumberIterator");
1270
- }
1271
- _blocksByBlockNumber = new LRUCache2({
1272
- max: 1e4
1273
- });
1274
- _chainArchivist;
1275
- _chainInformation;
1276
- _head;
1277
- constructor(params) {
1278
- super({});
1279
- const { chainArchivist: archivist, head } = params;
1280
- this._chainArchivist = archivist;
1281
- this._head = head;
1282
- this._chainInformation = {
1283
- id: head.chain
1284
- };
1285
- }
1286
- get archivist() {
1287
- return this._chainArchivist;
1288
- }
1289
- get chainIdentification() {
1290
- return this._chainInformation;
1291
- }
1292
- static async create(params) {
1293
- await Promise.resolve();
1294
- return new _XyoChainBlockNumberIterator(params);
1295
- }
1296
- async get(block) {
1297
- assertEx10(this._head.block >= block, () => `Block requested is newer than the current head [${block}]`);
1298
- const cached = this._blocksByBlockNumber.get(block);
1299
- if (cached) return cached;
1300
- const startingBlock = this._head;
1301
- const currentBlockHash = await PayloadBuilder6.hash(startingBlock);
1302
- let currentBlock = (await this._chainArchivist.get([
1303
- currentBlockHash
1304
- ])).at(0);
1305
- while (isDefined2(currentBlock)) {
1306
- assertEx10(asBlockBoundWitness2(currentBlock), () => `Expected hash to be a block bound witness [${currentBlock?._hash}]`);
1307
- if (isBlockBoundWitness(currentBlock)) {
1308
- this._blocksByBlockNumber.set(currentBlock.block, currentBlock);
1309
- if (currentBlock.block === block) {
1310
- return currentBlock;
1311
- }
1312
- const { previous } = currentBlock;
1313
- if (isNull(previous)) break;
1314
- currentBlock = (await this._chainArchivist.get([
1315
- previous
1316
- ])).at(0);
1317
- }
1318
- }
1319
- throw new Error(`Block not found: ${block}`);
1320
- }
1321
- async head() {
1322
- return await Promise.resolve(this._head);
1323
- }
1324
- async next(block) {
1325
- const currentBlock = block;
1326
- const nextBlockNumber = currentBlock + 1;
1327
- return await this.get(nextBlockNumber);
1328
- }
1329
- // TODO: Decide on inclusive/exclusive (probably need inclusive to account for chain head)
1330
- // and then communicate via method name and documentation
1331
- async previous(block = void 0, count = 1) {
1332
- const results = [];
1333
- let currentBlock = isDefined2(block) ? await this.get(block) : this._head;
1334
- while (currentBlock && results.length < count) {
1335
- if (isBlockBoundWitness(currentBlock)) {
1336
- results.push(currentBlock);
1337
- const { previous } = currentBlock;
1338
- if (isNull(previous)) break;
1339
- const nextBlock = await this._chainArchivist.get([
1340
- previous
1341
- ]);
1342
- currentBlock = asOptionalBlockBoundWitness2(nextBlock[0]);
1343
- } else {
1344
- const hash = PayloadBuilder6.hash(currentBlock);
1345
- assertEx10(asBlockBoundWitness2(currentBlock), () => `Expected hash to be a block bound witness [${hash}]`);
1346
- }
1347
- }
1348
- return results;
1349
- }
1350
- async updateHead(head) {
1351
- await Promise.resolve();
1352
- this._head = head;
1353
- void this.emit("headUpdated", {
1354
- blocks: [
1355
- head
1356
- ]
1357
- });
1226
+ return await this.contract.withdrawnByStaker(getAddress(staker));
1358
1227
  }
1359
1228
  };
1360
1229
  export {
1361
1230
  BaseAccountableService,
1362
- BaseEthProvider,
1363
1231
  BaseService,
1232
+ ChainBlockNumberIterationService,
1364
1233
  DEFAULT_BLOCK_SIZE,
1365
1234
  EvmBlockRewardService,
1366
1235
  EvmChainService,
@@ -1369,7 +1238,6 @@ export {
1369
1238
  XyoBlockProducer,
1370
1239
  XyoBlockRewardService,
1371
1240
  XyoChainAccountBalanceService,
1372
- XyoChainBlockNumberIterator,
1373
1241
  XyoElectionService,
1374
1242
  XyoPendingTransactionsService,
1375
1243
  XyoStakeIntentService,