@xyo-network/chain-services 1.6.0 → 1.6.2

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 (95) hide show
  1. package/dist/neutral/index.mjs +273 -361
  2. package/dist/neutral/index.mjs.map +1 -1
  3. package/dist/types/AccountBalance/{ChainAccountBalanceServiceV2.d.ts → BaseAccountBalanceService.d.ts} +4 -4
  4. package/dist/types/AccountBalance/BaseAccountBalanceService.d.ts.map +1 -0
  5. package/dist/types/AccountBalance/accountBalanceServiceFromArchivist.d.ts +4 -4
  6. package/dist/types/AccountBalance/accountBalanceServiceFromArchivist.d.ts.map +1 -1
  7. package/dist/types/AccountBalance/index.d.ts +1 -2
  8. package/dist/types/AccountBalance/index.d.ts.map +1 -1
  9. package/dist/types/BaseService.d.ts +1 -1
  10. package/dist/types/BaseService.d.ts.map +1 -1
  11. package/dist/types/BlockProducer/{XyoBlockProducer.d.ts → BaseBlockProducerService.d.ts} +4 -4
  12. package/dist/types/BlockProducer/BaseBlockProducerService.d.ts.map +1 -0
  13. package/dist/types/BlockProducer/index.d.ts +1 -1
  14. package/dist/types/BlockProducer/index.d.ts.map +1 -1
  15. package/dist/types/BlockReward/BaseBlockRewardService.d.ts +10 -0
  16. package/dist/types/BlockReward/BaseBlockRewardService.d.ts.map +1 -0
  17. package/dist/types/BlockReward/EvmBlockRewardService.d.ts +5 -4
  18. package/dist/types/BlockReward/EvmBlockRewardService.d.ts.map +1 -1
  19. package/dist/types/BlockReward/{XyoBlockRewardService.d.ts → MemoryBlockRewardService.d.ts} +5 -6
  20. package/dist/types/BlockReward/MemoryBlockRewardService.d.ts.map +1 -0
  21. package/dist/types/BlockReward/index.d.ts +2 -1
  22. package/dist/types/BlockReward/index.d.ts.map +1 -1
  23. package/dist/types/ChainBlockNumberIteration/model/Params.d.ts +1 -1
  24. package/dist/types/ChainBlockNumberIteration/model/Params.d.ts.map +1 -1
  25. package/dist/types/{Staker → ChainService}/Evm/Evm.d.ts +1 -1
  26. package/dist/types/ChainService/Evm/Evm.d.ts.map +1 -0
  27. package/dist/types/ChainService/Evm/index.d.ts.map +1 -0
  28. package/dist/types/{Staker → ChainService}/Memory/Memory.d.ts +1 -1
  29. package/dist/types/ChainService/Memory/Memory.d.ts.map +1 -0
  30. package/dist/types/ChainService/Memory/index.d.ts.map +1 -0
  31. package/dist/types/ChainService/index.d.ts.map +1 -0
  32. package/dist/types/ChainValidator/XyoValidator.d.ts +1 -1
  33. package/dist/types/ChainValidator/XyoValidator.d.ts.map +1 -1
  34. package/dist/types/Election/{XyoElectionService.d.ts → BaseElectionService.d.ts} +4 -4
  35. package/dist/types/Election/BaseElectionService.d.ts.map +1 -0
  36. package/dist/types/Election/index.d.ts +1 -1
  37. package/dist/types/Election/index.d.ts.map +1 -1
  38. package/dist/types/PendingTransactions/{PendingTransactions.d.ts → BasePendingTransactions.d.ts} +4 -4
  39. package/dist/types/PendingTransactions/BasePendingTransactions.d.ts.map +1 -0
  40. package/dist/types/PendingTransactions/index.d.ts +1 -1
  41. package/dist/types/PendingTransactions/index.d.ts.map +1 -1
  42. package/dist/types/StakeIntent/XyoStakeIntentService.d.ts +1 -1
  43. package/dist/types/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
  44. package/dist/types/index.d.ts +2 -2
  45. package/dist/types/index.d.ts.map +1 -1
  46. package/dist/types/model/Params.d.ts.map +1 -0
  47. package/dist/types/model/index.d.ts +2 -0
  48. package/dist/types/model/index.d.ts.map +1 -0
  49. package/package.json +39 -40
  50. package/src/AccountBalance/{ChainAccountBalanceServiceV2.ts → BaseAccountBalanceService.ts} +3 -3
  51. package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +8 -50
  52. package/src/AccountBalance/index.ts +1 -2
  53. package/src/BaseService.ts +1 -1
  54. package/src/BlockProducer/{XyoBlockProducer.ts → BaseBlockProducerService.ts} +7 -7
  55. package/src/BlockProducer/index.ts +1 -1
  56. package/src/BlockReward/BaseBlockRewardService.ts +16 -0
  57. package/src/BlockReward/EvmBlockRewardService.ts +6 -5
  58. package/src/BlockReward/{XyoBlockRewardService.ts → MemoryBlockRewardService.ts} +6 -6
  59. package/src/BlockReward/index.ts +2 -1
  60. package/src/ChainBlockNumberIteration/model/Params.ts +1 -1
  61. package/src/{Staker → ChainService}/Evm/Evm.ts +1 -1
  62. package/src/{Staker → ChainService}/Memory/Memory.ts +1 -1
  63. package/src/ChainValidator/XyoValidator.ts +1 -1
  64. package/src/Election/{XyoElectionService.ts → BaseElectionService.ts} +3 -3
  65. package/src/Election/index.ts +1 -1
  66. package/src/PendingTransactions/{PendingTransactions.ts → BasePendingTransactions.ts} +8 -8
  67. package/src/PendingTransactions/index.ts +1 -1
  68. package/src/StakeIntent/XyoStakeIntentService.ts +1 -1
  69. package/src/index.ts +2 -2
  70. package/src/model/index.ts +1 -0
  71. package/dist/types/AccountBalance/ChainAccountBalanceServiceV2.d.ts.map +0 -1
  72. package/dist/types/AccountBalance/XyoChainAccountBalanceService.d.ts +0 -24
  73. package/dist/types/AccountBalance/XyoChainAccountBalanceService.d.ts.map +0 -1
  74. package/dist/types/BlockProducer/XyoBlockProducer.d.ts.map +0 -1
  75. package/dist/types/BlockReward/XyoBlockRewardService.d.ts.map +0 -1
  76. package/dist/types/ChainIndexService.d.ts +0 -23
  77. package/dist/types/ChainIndexService.d.ts.map +0 -1
  78. package/dist/types/Election/XyoElectionService.d.ts.map +0 -1
  79. package/dist/types/Params.d.ts.map +0 -1
  80. package/dist/types/PendingTransactions/PendingTransactions.d.ts.map +0 -1
  81. package/dist/types/Staker/Evm/Evm.d.ts.map +0 -1
  82. package/dist/types/Staker/Evm/index.d.ts.map +0 -1
  83. package/dist/types/Staker/Memory/Memory.d.ts.map +0 -1
  84. package/dist/types/Staker/Memory/index.d.ts.map +0 -1
  85. package/dist/types/Staker/index.d.ts.map +0 -1
  86. package/src/AccountBalance/XyoChainAccountBalanceService.ts +0 -86
  87. package/src/ChainIndexService.ts +0 -46
  88. /package/dist/types/{Staker → ChainService}/Evm/index.d.ts +0 -0
  89. /package/dist/types/{Staker → ChainService}/Memory/index.d.ts +0 -0
  90. /package/dist/types/{Staker → ChainService}/index.d.ts +0 -0
  91. /package/dist/types/{Params.d.ts → model/Params.d.ts} +0 -0
  92. /package/src/{Staker → ChainService}/Evm/index.ts +0 -0
  93. /package/src/{Staker → ChainService}/Memory/index.ts +0 -0
  94. /package/src/{Staker → ChainService}/index.ts +0 -0
  95. /package/src/{Params.ts → model/Params.ts} +0 -0
@@ -4,13 +4,10 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
4
4
  // src/AccountBalance/accountBalanceServiceFromArchivist.ts
5
5
  import { exists } from "@xylabs/exists";
6
6
  import { asHash, isHash } from "@xylabs/hex";
7
- import { analyzeChain, BalanceAnalyzer, ChainSummaryBalancesSchema, isChainSummaryBalances } from "@xyo-network/chain-analyze";
8
7
  import { PayloadBuilder } from "@xyo-network/payload-builder";
9
- import { AttoXL1 as AttoXL12 } from "@xyo-network/xl1-protocol";
10
- import { parseSignedBigInt } from "@xyo-network/xl1-protocol-sdk";
11
8
  import { LRUCache } from "lru-cache";
12
9
 
13
- // src/AccountBalance/ChainAccountBalanceServiceV2.ts
10
+ // src/AccountBalance/BaseAccountBalanceService.ts
14
11
  import { creatable as creatable2 } from "@xylabs/creatable";
15
12
  import { AttoXL1 } from "@xyo-network/xl1-protocol";
16
13
  import { balanceSummary } from "@xyo-network/xl1-protocol-sdk";
@@ -65,7 +62,7 @@ function creatableService() {
65
62
  }
66
63
  __name(creatableService, "creatableService");
67
64
 
68
- // src/AccountBalance/ChainAccountBalanceServiceV2.ts
65
+ // src/AccountBalance/BaseAccountBalanceService.ts
69
66
  function _ts_decorate2(decorators, target, key, desc) {
70
67
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
71
68
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -73,9 +70,9 @@ function _ts_decorate2(decorators, target, key, desc) {
73
70
  return c > 3 && r && Object.defineProperty(target, key, r), r;
74
71
  }
75
72
  __name(_ts_decorate2, "_ts_decorate");
76
- var ChainAccountBalanceServiceV2 = class extends BaseService {
73
+ var BaseAccountBalanceService = class extends BaseService {
77
74
  static {
78
- __name(this, "ChainAccountBalanceServiceV2");
75
+ __name(this, "BaseAccountBalanceService");
79
76
  }
80
77
  async balances(head, address) {
81
78
  const summary = await balanceSummary({
@@ -90,49 +87,12 @@ var ChainAccountBalanceServiceV2 = class extends BaseService {
90
87
  return result;
91
88
  }
92
89
  };
93
- ChainAccountBalanceServiceV2 = _ts_decorate2([
90
+ BaseAccountBalanceService = _ts_decorate2([
94
91
  creatable2()
95
- ], ChainAccountBalanceServiceV2);
92
+ ], BaseAccountBalanceService);
96
93
 
97
94
  // src/AccountBalance/accountBalanceServiceFromArchivist.ts
98
- var accountBalanceServiceFromArchivist = /* @__PURE__ */ __name(async (archivist, head) => {
99
- let allAddressesBalances = {
100
- schema: ChainSummaryBalancesSchema,
101
- balances: {},
102
- firstBlock: null,
103
- lastBlock: null
104
- };
105
- const result = {
106
- balances: /* @__PURE__ */ __name(async (head2, addresses) => {
107
- const sync = /* @__PURE__ */ __name(async (head3) => {
108
- const analysis = await analyzeChain(archivist, [
109
- new BalanceAnalyzer()
110
- ], head3, null, -1n);
111
- allAddressesBalances = analysis.find(isChainSummaryBalances) ?? {
112
- schema: ChainSummaryBalancesSchema,
113
- balances: {},
114
- firstBlock: null,
115
- lastBlock: null
116
- };
117
- return await Promise.resolve();
118
- }, "sync");
119
- await sync(head2);
120
- const result2 = {};
121
- for (const addr of addresses) {
122
- const signedValue = parseSignedBigInt(allAddressesBalances.balances[addr] ?? {
123
- positive: "00"
124
- });
125
- result2[addr] = AttoXL12(signedValue > 0n ? signedValue : 0n);
126
- }
127
- return result2;
128
- }, "balances")
129
- };
130
- if (isHash(head)) {
131
- await result.balances(head, []);
132
- }
133
- return result;
134
- }, "accountBalanceServiceFromArchivist");
135
- var accountBalanceServiceFromArchivistV2 = /* @__PURE__ */ __name(async (archivist) => {
95
+ var accountBalanceServiceFromArchivist = /* @__PURE__ */ __name(async (archivist) => {
136
96
  const summaryArchivistCache = new LRUCache({
137
97
  max: 1e5,
138
98
  allowStale: true,
@@ -160,96 +120,27 @@ var accountBalanceServiceFromArchivistV2 = /* @__PURE__ */ __name(async (archivi
160
120
  throw new Error("Not implemented");
161
121
  }, "next")
162
122
  };
163
- const service = await ChainAccountBalanceServiceV2.create({
123
+ const service = await BaseAccountBalanceService.create({
164
124
  chainArchivist: archivist,
165
125
  summaryRepository
166
126
  });
167
127
  return service;
168
- }, "accountBalanceServiceFromArchivistV2");
128
+ }, "accountBalanceServiceFromArchivist");
129
+ var accountBalanceServiceFromArchivistV2 = accountBalanceServiceFromArchivist;
169
130
 
170
- // src/AccountBalance/XyoChainAccountBalanceService.ts
171
- import { assertEx } from "@xylabs/assert";
131
+ // src/BlockProducer/BaseBlockProducerService.ts
132
+ import { assertEx as assertEx2 } from "@xylabs/assert";
172
133
  import { creatable as creatable3 } from "@xylabs/creatable";
173
- import { isDefined } from "@xylabs/typeof";
174
- import { analyzeChain as analyzeChain2, BalanceAnalyzer as BalanceAnalyzer2, ChainSummaryBalancesSchema as ChainSummaryBalancesSchema2, isChainSummaryBalances as isChainSummaryBalances2 } from "@xyo-network/chain-analyze";
175
- import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
176
- import { AttoXL1 as AttoXL13 } from "@xyo-network/xl1-protocol";
177
- import { parseSignedBigInt as parseSignedBigInt2 } from "@xyo-network/xl1-protocol-sdk";
178
- function _ts_decorate3(decorators, target, key, desc) {
179
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
180
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
181
- 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;
182
- return c > 3 && r && Object.defineProperty(target, key, r), r;
183
- }
184
- __name(_ts_decorate3, "_ts_decorate");
185
- var XyoChainAccountBalanceService = class extends BaseService {
186
- static {
187
- __name(this, "XyoChainAccountBalanceService");
188
- }
189
- _balances = {};
190
- /**
191
- * The most recent head that was indexed to
192
- */
193
- _firstBlock = null;
194
- /**
195
- * The oldest block that was indexed through
196
- */
197
- _lastBlock = null;
198
- get chainArchivist() {
199
- return assertEx(this.params.chainArchivist, () => "chainArchivist is required");
200
- }
201
- balances(head, address) {
202
- const result = {};
203
- for (const addr of address) {
204
- const balance = this._balances[addr];
205
- const signedBalance = balance ? parseSignedBigInt2(balance) : 0n;
206
- result[addr] = AttoXL13(signedBalance >= 0n ? signedBalance : 0n);
207
- }
208
- return result;
209
- }
210
- async startHandler() {
211
- if (isDefined(this.params.head)) {
212
- await this.sync(this.params.head);
213
- }
214
- }
215
- async sync(head) {
216
- const startingBalances = new PayloadBuilder2({
217
- schema: ChainSummaryBalancesSchema2
218
- }).fields({
219
- balances: this._balances,
220
- firstBlock: this._firstBlock,
221
- lastBlock: this._lastBlock
222
- }).build();
223
- const analysis = await analyzeChain2(this.chainArchivist, [
224
- new BalanceAnalyzer2(void 0, void 0, startingBalances)
225
- ], head, this._firstBlock);
226
- const allAddressesBalances = analysis.find(isChainSummaryBalances2);
227
- if (allAddressesBalances === void 0) return;
228
- this._balances = {
229
- ...this._balances,
230
- ...allAddressesBalances.balances
231
- };
232
- this._firstBlock = allAddressesBalances.firstBlock;
233
- if (this._lastBlock === null) this._lastBlock = allAddressesBalances.lastBlock;
234
- }
235
- };
236
- XyoChainAccountBalanceService = _ts_decorate3([
237
- creatable3()
238
- ], XyoChainAccountBalanceService);
239
-
240
- // src/BlockProducer/XyoBlockProducer.ts
241
- import { assertEx as assertEx3 } from "@xylabs/assert";
242
- import { creatable as creatable4 } from "@xylabs/creatable";
243
134
  import { exists as exists2 } from "@xylabs/exists";
244
135
  import { hexToBigInt, toHex } from "@xylabs/hex";
245
- import { isDefined as isDefined2 } from "@xylabs/typeof";
136
+ import { isDefined } from "@xylabs/typeof";
246
137
  import { FixedPercentageBlockRewardDiviner, FixedPercentageBlockRewardDivinerConfigSchema } from "@xyo-network/chain-modules";
247
138
  import { buildNextBlock, createDeclarationIntent } from "@xyo-network/chain-protocol";
248
- import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
249
- import { asBlockBoundWitness, AttoXL1 as AttoXL14, BlockNumberSchema } from "@xyo-network/xl1-protocol";
139
+ import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
140
+ import { asBlockBoundWitness, AttoXL1 as AttoXL12, BlockNumberSchema } from "@xyo-network/xl1-protocol";
250
141
 
251
142
  // src/BlockProducer/generateTransactionFeeTransfers.ts
252
- import { assertEx as assertEx2 } from "@xylabs/assert";
143
+ import { assertEx } from "@xylabs/assert";
253
144
  import { hexFromBigInt } from "@xylabs/hex";
254
145
  import { XYO_ZERO_ADDRESS } from "@xyo-network/chain-utils";
255
146
  import { HydratedTransactionWrapper } from "@xyo-network/chain-wrappers";
@@ -280,27 +171,27 @@ async function generateTransactionFeeTransfers(address, transactions) {
280
171
  return payload;
281
172
  });
282
173
  for (const [from, amount] of Object.entries(txGasCosts)) {
283
- const fromPayload = assertEx2(payloads.find((p) => p.from === from), () => "from payload not found");
174
+ const fromPayload = assertEx(payloads.find((p) => p.from === from), () => "from payload not found");
284
175
  fromPayload.transfers[address] = hexFromBigInt(amount);
285
176
  }
286
177
  return payloads;
287
178
  }
288
179
  __name(generateTransactionFeeTransfers, "generateTransactionFeeTransfers");
289
180
 
290
- // src/BlockProducer/XyoBlockProducer.ts
291
- function _ts_decorate4(decorators, target, key, desc) {
181
+ // src/BlockProducer/BaseBlockProducerService.ts
182
+ function _ts_decorate3(decorators, target, key, desc) {
292
183
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
293
184
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
294
185
  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;
295
186
  return c > 3 && r && Object.defineProperty(target, key, r), r;
296
187
  }
297
- __name(_ts_decorate4, "_ts_decorate");
188
+ __name(_ts_decorate3, "_ts_decorate");
298
189
  var DEFAULT_BLOCK_SIZE = 10;
299
190
  var XYO_PRODUCER_REDECLARATION_DURATION = 1e4;
300
191
  var XYO_PRODUCER_REDECLARATION_WINDOW = 500;
301
- var XyoBlockProducer = class _XyoBlockProducer extends BaseService {
192
+ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseService {
302
193
  static {
303
- __name(this, "XyoBlockProducer");
194
+ __name(this, "BaseBlockProducerService");
304
195
  }
305
196
  _blockRewardDiviner;
306
197
  /**
@@ -328,43 +219,43 @@ var XyoBlockProducer = class _XyoBlockProducer extends BaseService {
328
219
  * their intent to continue producing blocks
329
220
  */
330
221
  static get RedeclareIntent() {
331
- return isDefined2(process.env.XYO_PRODUCER_SKIP_REDECLARE_INTENT) ? false : true;
222
+ return isDefined(process.env.XYO_PRODUCER_SKIP_REDECLARE_INTENT) ? false : true;
332
223
  }
333
224
  get address() {
334
225
  return this.account.address;
335
226
  }
336
227
  get account() {
337
- return assertEx3(this.params.account, () => "account is required");
228
+ return assertEx2(this.params.account, () => "account is required");
338
229
  }
339
230
  get balanceService() {
340
- return assertEx3(this.params.balanceService, () => "balanceService is required");
231
+ return assertEx2(this.params.balanceService, () => "balanceService is required");
341
232
  }
342
233
  get chainArchivist() {
343
- return assertEx3(this.params.chainArchivist, () => "chainArchivist is required");
234
+ return assertEx2(this.params.chainArchivist, () => "chainArchivist is required");
344
235
  }
345
236
  get chainId() {
346
- return assertEx3(this.params.chainId, () => "chainId is required");
237
+ return assertEx2(this.params.chainId, () => "chainId is required");
347
238
  }
348
239
  get electionService() {
349
- return assertEx3(this.params.electionService, () => "electionService is required");
240
+ return assertEx2(this.params.electionService, () => "electionService is required");
350
241
  }
351
242
  get pendingTransactionsService() {
352
- return assertEx3(this.params.pendingTransactionsService, () => "Missing pendingTransactionsService");
243
+ return assertEx2(this.params.pendingTransactionsService, () => "Missing pendingTransactionsService");
353
244
  }
354
245
  get rejectedTransactionsArchivist() {
355
- return assertEx3(this.params.rejectedTransactionsArchivist, () => "No rejected bundled transactions archivist");
246
+ return assertEx2(this.params.rejectedTransactionsArchivist, () => "No rejected bundled transactions archivist");
356
247
  }
357
248
  get rewardAddress() {
358
- return assertEx3(this.params.rewardAddress, () => "No reward address provided");
249
+ return assertEx2(this.params.rewardAddress, () => "No reward address provided");
359
250
  }
360
251
  get rewardService() {
361
- return assertEx3(this.params.rewardService, () => "rewardService is required");
252
+ return assertEx2(this.params.rewardService, () => "rewardService is required");
362
253
  }
363
254
  get stakeIntentService() {
364
- return assertEx3(this.params.stakeIntentService, () => "No StakeIntentService provided");
255
+ return assertEx2(this.params.stakeIntentService, () => "No StakeIntentService provided");
365
256
  }
366
257
  get validateHydratedBlockState() {
367
- return assertEx3(this.params.validateHydratedBlockState, () => "validateHydratedBlockState is required");
258
+ return assertEx2(this.params.validateHydratedBlockState, () => "validateHydratedBlockState is required");
368
259
  }
369
260
  async next(head) {
370
261
  if (head.chain !== this.chainId) return;
@@ -384,8 +275,8 @@ var XyoBlockProducer = class _XyoBlockProducer extends BaseService {
384
275
  }
385
276
  });
386
277
  }
387
- const blockHex = assertEx3(toHex(block), () => "Failed to convert block to hex");
388
- const blockId = new PayloadBuilder3({
278
+ const blockHex = assertEx2(toHex(block), () => "Failed to convert block to hex");
279
+ const blockId = new PayloadBuilder2({
389
280
  schema: BlockNumberSchema
390
281
  }).fields({
391
282
  block: blockHex
@@ -399,24 +290,24 @@ var XyoBlockProducer = class _XyoBlockProducer extends BaseService {
399
290
  /**
400
291
  * Handles the producer redeclaration logic
401
292
  * @param head The current head block
402
- * @returns
293
+ * @returns chain stake intent for the producer redeclaration, or undefined if no redeclaration is needed
403
294
  */
404
295
  async getProducerRedeclaration(head) {
405
- if (!_XyoBlockProducer.RedeclareIntent) return;
296
+ if (!_BaseBlockProducerService.RedeclareIntent) return;
406
297
  const ranges = await this.stakeIntentService.getDeclaredCandidateRanges(this.address, "producer");
407
298
  const lastRange = ranges.toSorted((a, b) => a[1] > b[1] ? 1 : -1).at(-1);
408
299
  if (!lastRange) return;
409
300
  const [, currentDeclarationEnd] = lastRange;
410
301
  const currentBlock = head.block;
411
302
  const timeToProducerExpiration = currentDeclarationEnd - currentBlock;
412
- if (timeToProducerExpiration > _XyoBlockProducer.RedeclarationWindow) return;
413
- return createDeclarationIntent(this.address, "producer", currentBlock, currentBlock + _XyoBlockProducer.RedeclarationDuration);
303
+ if (timeToProducerExpiration > _BaseBlockProducerService.RedeclarationWindow) return;
304
+ return createDeclarationIntent(this.address, "producer", currentBlock, currentBlock + _BaseBlockProducerService.RedeclarationDuration);
414
305
  }
415
306
  async proposeNextValidBlock(head, validateBalances = false) {
416
307
  return await this.spanAsync("proposeNextValidBlock", async () => {
417
- const { block: previousBlock } = assertEx3(asBlockBoundWitness(head), () => "Invalid head block");
308
+ const { block: previousBlock } = assertEx2(asBlockBoundWitness(head), () => "Invalid head block");
418
309
  const nextBlock = previousBlock + 1;
419
- const nextBlockTransactions = await this.pendingTransactionsService.getPendingTransactions(head._hash, _XyoBlockProducer.DefaultBlockSize);
310
+ const nextBlockTransactions = await this.pendingTransactionsService.getPendingTransactions(head._hash, _BaseBlockProducerService.DefaultBlockSize);
420
311
  const blockPayloads = [];
421
312
  const producerRedeclarationPayload = await this.getProducerRedeclaration(head);
422
313
  if (producerRedeclarationPayload) blockPayloads.push(producerRedeclarationPayload);
@@ -432,7 +323,7 @@ var XyoBlockProducer = class _XyoBlockProducer extends BaseService {
432
323
  if (validateBalances) {
433
324
  const balance = (await this.balanceService.balances(head._hash, [
434
325
  transfer.from
435
- ]))[transfer.from] ?? AttoXL14(0n);
326
+ ]))[transfer.from] ?? AttoXL12(0n);
436
327
  if (balance >= totalTransferCost) {
437
328
  fundedTransfers.push(transfer);
438
329
  return tx;
@@ -460,12 +351,33 @@ var XyoBlockProducer = class _XyoBlockProducer extends BaseService {
460
351
  });
461
352
  }
462
353
  };
463
- XyoBlockProducer = _ts_decorate4([
354
+ BaseBlockProducerService = _ts_decorate3([
355
+ creatable3()
356
+ ], BaseBlockProducerService);
357
+
358
+ // src/BlockReward/BaseBlockRewardService.ts
359
+ import { creatable as creatable4 } from "@xylabs/creatable";
360
+ function _ts_decorate4(decorators, target, key, desc) {
361
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
362
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
363
+ 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;
364
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
365
+ }
366
+ __name(_ts_decorate4, "_ts_decorate");
367
+ var BaseBlockRewardService = class extends BaseService {
368
+ static {
369
+ __name(this, "BaseBlockRewardService");
370
+ }
371
+ getRewardForBlock(_blockNumber) {
372
+ throw new Error("getRewardForBlock method must be implemented in derived classes");
373
+ }
374
+ };
375
+ BaseBlockRewardService = _ts_decorate4([
464
376
  creatable4()
465
- ], XyoBlockProducer);
377
+ ], BaseBlockRewardService);
466
378
 
467
379
  // src/BlockReward/EvmBlockRewardService.ts
468
- import { assertEx as assertEx4 } from "@xylabs/assert";
380
+ import { assertEx as assertEx3 } from "@xylabs/assert";
469
381
  import { creatable as creatable5 } from "@xylabs/creatable";
470
382
  import { toEthAddress } from "@xyo-network/chain-ethereum";
471
383
  import { XyoChainRewards__factory as XyoChainRewardsFactory } from "@xyo-network/typechain";
@@ -476,19 +388,19 @@ function _ts_decorate5(decorators, target, key, desc) {
476
388
  return c > 3 && r && Object.defineProperty(target, key, r), r;
477
389
  }
478
390
  __name(_ts_decorate5, "_ts_decorate");
479
- var EvmBlockRewardService = class extends BaseService {
391
+ var EvmBlockRewardService = class extends BaseBlockRewardService {
480
392
  static {
481
393
  __name(this, "EvmBlockRewardService");
482
394
  }
483
395
  _contractAddress;
484
396
  get chainService() {
485
- return assertEx4(this.params.chainService, () => "chainService is required");
397
+ return assertEx3(this.params.chainService, () => "chainService is required");
486
398
  }
487
399
  get contractAddress() {
488
- return assertEx4(this._contractAddress, () => "contractAddress is required");
400
+ return assertEx3(this._contractAddress, () => "contractAddress is required");
489
401
  }
490
402
  get provider() {
491
- return assertEx4(this.params.provider, () => "provider is required");
403
+ return assertEx3(this.params.provider, () => "provider is required");
492
404
  }
493
405
  async createHandler() {
494
406
  await super.createHandler();
@@ -508,8 +420,8 @@ EvmBlockRewardService = _ts_decorate5([
508
420
  creatable5()
509
421
  ], EvmBlockRewardService);
510
422
 
511
- // src/BlockReward/XyoBlockRewardService.ts
512
- import { assertEx as assertEx5 } from "@xylabs/assert";
423
+ // src/BlockReward/MemoryBlockRewardService.ts
424
+ import { assertEx as assertEx4 } from "@xylabs/assert";
513
425
  import { creatable as creatable6 } from "@xylabs/creatable";
514
426
  import { toFixedPoint } from "@xylabs/decimal-precision";
515
427
  import { rewardFromBlockNumber } from "@xyo-network/chain-protocol";
@@ -520,28 +432,28 @@ function _ts_decorate6(decorators, target, key, desc) {
520
432
  return c > 3 && r && Object.defineProperty(target, key, r), r;
521
433
  }
522
434
  __name(_ts_decorate6, "_ts_decorate");
523
- var XyoBlockRewardService = class extends BaseService {
435
+ var MemoryBlockRewardService = class extends BaseBlockRewardService {
524
436
  static {
525
- __name(this, "XyoBlockRewardService");
437
+ __name(this, "MemoryBlockRewardService");
526
438
  }
527
439
  rewardFromBlockNumber = rewardFromBlockNumber(18);
528
440
  get creatorReward() {
529
- return assertEx5(this.params.creatorReward, () => "creatorReward is required");
441
+ return assertEx4(this.params.creatorReward, () => "creatorReward is required");
530
442
  }
531
443
  get initialReward() {
532
- return assertEx5(this.params.initialStepReward, () => "initialStepReward is required");
444
+ return assertEx4(this.params.initialStepReward, () => "initialStepReward is required");
533
445
  }
534
446
  get minRewardPerBlock() {
535
- return assertEx5(this.params.minRewardPerBlock, () => "minRewardPerBlock is required");
447
+ return assertEx4(this.params.minRewardPerBlock, () => "minRewardPerBlock is required");
536
448
  }
537
449
  get stepFactorDenominator() {
538
- return assertEx5(this.params.stepFactorDenominator, () => "stepFactorDenominator is required");
450
+ return assertEx4(this.params.stepFactorDenominator, () => "stepFactorDenominator is required");
539
451
  }
540
452
  get stepFactorNumerator() {
541
- return assertEx5(this.params.stepFactorNumerator, () => "stepFactorNumerator is required");
453
+ return assertEx4(this.params.stepFactorNumerator, () => "stepFactorNumerator is required");
542
454
  }
543
455
  get stepSize() {
544
- return assertEx5(this.params.stepSize, () => "stepSize is required");
456
+ return assertEx4(this.params.stepSize, () => "stepSize is required");
545
457
  }
546
458
  static async paramsHandler(inParams) {
547
459
  return {
@@ -558,14 +470,14 @@ var XyoBlockRewardService = class extends BaseService {
558
470
  return this.rewardFromBlockNumber(blockNumber, this.initialReward, this.stepSize, this.stepFactorNumerator, this.stepFactorDenominator, this.minRewardPerBlock, this.creatorReward);
559
471
  }
560
472
  };
561
- XyoBlockRewardService = _ts_decorate6([
473
+ MemoryBlockRewardService = _ts_decorate6([
562
474
  creatable6()
563
- ], XyoBlockRewardService);
475
+ ], MemoryBlockRewardService);
564
476
 
565
477
  // src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts
566
- import { assertEx as assertEx6 } from "@xylabs/assert";
567
- import { isDefined as isDefined3, isNull } from "@xylabs/typeof";
568
- import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
478
+ import { assertEx as assertEx5 } from "@xylabs/assert";
479
+ import { isDefined as isDefined2, isNull } from "@xylabs/typeof";
480
+ import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
569
481
  import { asBlockBoundWitness as asBlockBoundWitness2, isBlockBoundWitness } from "@xyo-network/xl1-protocol";
570
482
  import { LRUCache as LRUCache2 } from "lru-cache";
571
483
  var ChainBlockNumberIterationService = class extends BaseService {
@@ -576,23 +488,23 @@ var ChainBlockNumberIterationService = class extends BaseService {
576
488
  max: 1e4
577
489
  });
578
490
  get chainArchivist() {
579
- return assertEx6(this.params.chainArchivist);
491
+ return assertEx5(this.params.chainArchivist);
580
492
  }
581
493
  get chainId() {
582
- return assertEx6(this.params.head?.chain);
494
+ return assertEx5(this.params.head?.chain);
583
495
  }
584
496
  async get(block) {
585
497
  const head = await this.head();
586
- assertEx6(head.block >= block, () => `Block requested is newer than the current head [${block}]`);
498
+ assertEx5(head.block >= block, () => `Block requested is newer than the current head [${block}]`);
587
499
  const cached = this._blocksByBlockNumber.get(block);
588
500
  if (cached) return cached;
589
501
  const startingBlock = head;
590
- const currentBlockHash = await PayloadBuilder4.hash(startingBlock);
502
+ const currentBlockHash = await PayloadBuilder3.hash(startingBlock);
591
503
  let currentBlock = (await this.chainArchivist.get([
592
504
  currentBlockHash
593
505
  ])).at(0);
594
- while (isDefined3(currentBlock)) {
595
- assertEx6(asBlockBoundWitness2(currentBlock), () => `Expected hash to be a block bound witness [${currentBlock?._hash}]`);
506
+ while (isDefined2(currentBlock)) {
507
+ assertEx5(asBlockBoundWitness2(currentBlock), () => `Expected hash to be a block bound witness [${currentBlock?._hash}]`);
596
508
  if (isBlockBoundWitness(currentBlock)) {
597
509
  this._blocksByBlockNumber.set(currentBlock.block, currentBlock);
598
510
  if (currentBlock.block === block) {
@@ -608,7 +520,7 @@ var ChainBlockNumberIterationService = class extends BaseService {
608
520
  throw new Error(`Block not found: ${block}`);
609
521
  }
610
522
  async head() {
611
- return await Promise.resolve(assertEx6(this.params.head));
523
+ return await Promise.resolve(assertEx5(this.params.head));
612
524
  }
613
525
  async next(block) {
614
526
  const currentBlock = block;
@@ -619,7 +531,7 @@ var ChainBlockNumberIterationService = class extends BaseService {
619
531
  // and then communicate via method name and documentation
620
532
  async previous(block = void 0, count = 1) {
621
533
  const results = [];
622
- let currentBlock = isDefined3(block) ? await this.get(block) : await this.head();
534
+ let currentBlock = isDefined2(block) ? await this.get(block) : await this.head();
623
535
  while (currentBlock && results.length < count) {
624
536
  if (isBlockBoundWitness(currentBlock)) {
625
537
  results.push(currentBlock);
@@ -630,8 +542,8 @@ var ChainBlockNumberIterationService = class extends BaseService {
630
542
  ]);
631
543
  currentBlock = asBlockBoundWitness2(nextBlock[0]);
632
544
  } else {
633
- const hash = PayloadBuilder4.hash(currentBlock);
634
- assertEx6(asBlockBoundWitness2(currentBlock), () => `Expected hash to be a block bound witness [${hash}]`);
545
+ const hash = PayloadBuilder3.hash(currentBlock);
546
+ assertEx5(asBlockBoundWitness2(currentBlock), () => `Expected hash to be a block bound witness [${hash}]`);
635
547
  }
636
548
  }
637
549
  return results;
@@ -647,6 +559,148 @@ var ChainBlockNumberIterationService = class extends BaseService {
647
559
  }
648
560
  };
649
561
 
562
+ // src/ChainService/Evm/Evm.ts
563
+ import { assertEx as assertEx6 } from "@xylabs/assert";
564
+ import { toAddress } from "@xylabs/hex";
565
+ import { toEthAddress as toEthAddress2 } from "@xyo-network/chain-ethereum";
566
+ import { StakedXyoChain__factory as StakedXyoChainFactory } from "@xyo-network/typechain";
567
+ import { getAddress } from "ethers/address";
568
+ var EvmChainService = class extends BaseService {
569
+ static {
570
+ __name(this, "EvmChainService");
571
+ }
572
+ get chainId() {
573
+ return assertEx6(this.params.id);
574
+ }
575
+ get contract() {
576
+ if (this.params.contract === void 0) {
577
+ this.params.contract = StakedXyoChainFactory.connect(toEthAddress2(this.chainId), this.params.runner);
578
+ }
579
+ return assertEx6(this.params.contract);
580
+ }
581
+ get runner() {
582
+ return assertEx6(this.params.runner);
583
+ }
584
+ async active() {
585
+ return await this.contract.active();
586
+ }
587
+ async activeByAddressStaked(address) {
588
+ return await this.contract.activeByAddressStaked(getAddress(address));
589
+ }
590
+ async activeByStaker(address) {
591
+ return await this.contract.activeByStaker(getAddress(address));
592
+ }
593
+ async addStake(staked, amount) {
594
+ const result = await this.contract.addStake(getAddress(staked), amount);
595
+ await result.wait();
596
+ return true;
597
+ }
598
+ async forkedAtBlockNumber() {
599
+ return await this.contract.forkedAtBlockNumber();
600
+ }
601
+ async forkedAtHash() {
602
+ return await this.contract.forkedAtHash();
603
+ }
604
+ async forkedChainId() {
605
+ return toAddress(await this.contract.forkedChainId());
606
+ }
607
+ async minWithdrawalBlocks() {
608
+ return await this.contract.minWithdrawalBlocks();
609
+ }
610
+ async pending() {
611
+ return await this.contract.pending();
612
+ }
613
+ async pendingByStaker(staker) {
614
+ return await this.contract.pendingByStaker(getAddress(staker));
615
+ }
616
+ async removeStake(slot) {
617
+ const result = await this.contract.removeStake(slot);
618
+ await result.wait();
619
+ return true;
620
+ }
621
+ async rewardsContract() {
622
+ return await this.contract.rewardsContract();
623
+ }
624
+ async stakingTokenAddress() {
625
+ return await this.contract.stakingTokenAddress();
626
+ }
627
+ async withdrawStake(slot) {
628
+ const result = await this.contract.withdrawStake(slot);
629
+ await result.wait();
630
+ return true;
631
+ }
632
+ async withdrawn() {
633
+ return await this.contract.withdrawn();
634
+ }
635
+ async withdrawnByStaker(staker) {
636
+ return await this.contract.withdrawnByStaker(getAddress(staker));
637
+ }
638
+ };
639
+
640
+ // src/ChainService/Memory/Memory.ts
641
+ import { ZERO_ADDRESS } from "@xylabs/hex";
642
+ import { isDefined as isDefined3 } from "@xylabs/typeof";
643
+ var MemoryChainService = class extends BaseService {
644
+ static {
645
+ __name(this, "MemoryChainService");
646
+ }
647
+ _simulatedStake = 1n;
648
+ get chainId() {
649
+ return ZERO_ADDRESS;
650
+ }
651
+ async active() {
652
+ return await Promise.resolve(this._simulatedStake);
653
+ }
654
+ async activeByAddressStaked(_address) {
655
+ return await Promise.resolve(this._simulatedStake);
656
+ }
657
+ async activeByStaker(_address) {
658
+ return await Promise.resolve(this._simulatedStake);
659
+ }
660
+ async addStake(_staked, _amount) {
661
+ return await Promise.resolve(true);
662
+ }
663
+ createHandler() {
664
+ this._simulatedStake = isDefined3(process.env.XYO_PRODUCER_MIN_STAKE) ? BigInt(process.env.XYO_PRODUCER_MIN_STAKE) : 1n;
665
+ }
666
+ async forkedAtBlockNumber() {
667
+ return await Promise.resolve(0n);
668
+ }
669
+ async forkedAtHash() {
670
+ return await Promise.resolve(0n);
671
+ }
672
+ async forkedChainId() {
673
+ return await Promise.resolve(ZERO_ADDRESS);
674
+ }
675
+ async minWithdrawalBlocks() {
676
+ return await Promise.resolve(1n);
677
+ }
678
+ async pending() {
679
+ return await Promise.resolve(0n);
680
+ }
681
+ async pendingByStaker(_staker) {
682
+ return await Promise.resolve(0n);
683
+ }
684
+ async removeStake(_slot) {
685
+ return await Promise.resolve(true);
686
+ }
687
+ async rewardsContract() {
688
+ return await Promise.resolve("");
689
+ }
690
+ async stakingTokenAddress() {
691
+ return await Promise.resolve("");
692
+ }
693
+ async withdrawStake(_slot) {
694
+ return await Promise.resolve(true);
695
+ }
696
+ async withdrawn() {
697
+ return await Promise.resolve(0n);
698
+ }
699
+ async withdrawnByStaker(_staker) {
700
+ return await Promise.resolve(0n);
701
+ }
702
+ };
703
+
650
704
  // src/ChainValidator/XyoValidator.ts
651
705
  import { assertEx as assertEx7 } from "@xylabs/assert";
652
706
  import { creatable as creatable7 } from "@xylabs/creatable";
@@ -698,11 +752,11 @@ XyoValidator = _ts_decorate7([
698
752
  creatable7()
699
753
  ], XyoValidator);
700
754
 
701
- // src/Election/XyoElectionService.ts
755
+ // src/Election/BaseElectionService.ts
702
756
  import { assertEx as assertEx8 } from "@xylabs/assert";
703
757
  import { creatable as creatable8 } from "@xylabs/creatable";
704
758
  import { hexToLast4BytesInt, shuffleWithSeed } from "@xyo-network/chain-utils";
705
- import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
759
+ import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
706
760
  function _ts_decorate8(decorators, target, key, desc) {
707
761
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
708
762
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -710,9 +764,9 @@ function _ts_decorate8(decorators, target, key, desc) {
710
764
  return c > 3 && r && Object.defineProperty(target, key, r), r;
711
765
  }
712
766
  __name(_ts_decorate8, "_ts_decorate");
713
- var XyoElectionService = class extends BaseService {
767
+ var BaseElectionService = class extends BaseService {
714
768
  static {
715
- __name(this, "XyoElectionService");
769
+ __name(this, "BaseElectionService");
716
770
  }
717
771
  get chainIterator() {
718
772
  return assertEx8(this.params.chainIterator, () => "No chain iterator");
@@ -727,7 +781,7 @@ var XyoElectionService = class extends BaseService {
727
781
  return await this.spanAsync("getCreatorCommitteeForNextBlock", async () => {
728
782
  const nextBlock = current.block + 1;
729
783
  const candidates = await this.stakeIntentService.getDeclaredCandidatesForBlock(nextBlock, "producer");
730
- const previousBlockHash = await PayloadBuilder5.hash(current);
784
+ const previousBlockHash = await PayloadBuilder4.hash(current);
731
785
  return this.generateCreatorCommittee(candidates, previousBlockHash);
732
786
  });
733
787
  }
@@ -738,11 +792,11 @@ var XyoElectionService = class extends BaseService {
738
792
  return creatorArray.slice(0, maxSize);
739
793
  }
740
794
  };
741
- XyoElectionService = _ts_decorate8([
795
+ BaseElectionService = _ts_decorate8([
742
796
  creatable8()
743
- ], XyoElectionService);
797
+ ], BaseElectionService);
744
798
 
745
- // src/PendingTransactions/PendingTransactions.ts
799
+ // src/PendingTransactions/BasePendingTransactions.ts
746
800
  import { ValueType } from "@opentelemetry/api";
747
801
  import { filterAs, filterAsync } from "@xylabs/array";
748
802
  import { assertEx as assertEx9 } from "@xylabs/assert";
@@ -758,10 +812,10 @@ import { asBlockBoundWitnessWithHashStorageMeta, isTransactionBoundWitnessWithSt
758
812
  import { Mutex as Mutex2 } from "async-mutex";
759
813
 
760
814
  // src/PendingTransactions/bundledPayloadToHydratedTransaction.ts
761
- import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
815
+ import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
762
816
  import { asTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
763
817
  var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload) => {
764
- const withStorageMeta = await PayloadBuilder6.addStorageMeta(payload.payloads);
818
+ const withStorageMeta = await PayloadBuilder5.addStorageMeta(payload.payloads);
765
819
  const tx = asTransactionBoundWitnessWithStorageMeta(withStorageMeta.find((p) => p._hash === payload.root));
766
820
  if (tx) {
767
821
  return [
@@ -772,7 +826,7 @@ var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload)
772
826
  }, "bundledPayloadToHydratedTransaction");
773
827
 
774
828
  // src/PendingTransactions/hydratedTransactionToPayloadBundle.ts
775
- import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
829
+ import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
776
830
  import { PayloadBundleSchema } from "@xyo-network/payload-model";
777
831
  import { flattenHydratedTransaction } from "@xyo-network/xl1-protocol-sdk";
778
832
  var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) => {
@@ -780,8 +834,8 @@ var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) =>
780
834
  return bundle(root, transaction);
781
835
  }, "hydratedTransactionToPayloadBundle");
782
836
  var bundle = /* @__PURE__ */ __name((root, transaction) => {
783
- const payloads = flattenHydratedTransaction(transaction).flatMap((p) => PayloadBuilder7.omitStorageMeta(p));
784
- return new PayloadBuilder7({
837
+ const payloads = flattenHydratedTransaction(transaction).flatMap((p) => PayloadBuilder6.omitStorageMeta(p));
838
+ return new PayloadBuilder6({
785
839
  schema: PayloadBundleSchema
786
840
  }).fields({
787
841
  payloads,
@@ -789,7 +843,7 @@ var bundle = /* @__PURE__ */ __name((root, transaction) => {
789
843
  }).build();
790
844
  }, "bundle");
791
845
 
792
- // src/PendingTransactions/PendingTransactions.ts
846
+ // src/PendingTransactions/BasePendingTransactions.ts
793
847
  function _ts_decorate9(decorators, target, key, desc) {
794
848
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
795
849
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -797,10 +851,10 @@ function _ts_decorate9(decorators, target, key, desc) {
797
851
  return c > 3 && r && Object.defineProperty(target, key, r), r;
798
852
  }
799
853
  __name(_ts_decorate9, "_ts_decorate");
800
- globalAttributes.setAttribute("XyoPendingTransactionsService:status", "unknown");
801
- var XyoPendingTransactionsService = class _XyoPendingTransactionsService extends BaseService {
854
+ globalAttributes.setAttribute("BasePendingTransactionsService:status", "unknown");
855
+ var BasePendingTransactionsService = class _BasePendingTransactionsService extends BaseService {
802
856
  static {
803
- __name(this, "XyoPendingTransactionsService");
857
+ __name(this, "BasePendingTransactionsService");
804
858
  }
805
859
  static MutexPriority = {
806
860
  /**
@@ -884,7 +938,7 @@ var XyoPendingTransactionsService = class _XyoPendingTransactionsService extends
884
938
  pendingTransactionsCounter?.addCallback((observer) => {
885
939
  observer.observe(this.pendingTransactionsCount);
886
940
  });
887
- globalAttributes.setAttribute("XyoPendingTransactionsService:status", "created");
941
+ globalAttributes.setAttribute("BasePendingTransactionsService:status", "created");
888
942
  }
889
943
  async getPendingTransactions(head, limit) {
890
944
  return await this.spanAsync("getPendingTransactions", async () => {
@@ -916,14 +970,14 @@ var XyoPendingTransactionsService = class _XyoPendingTransactionsService extends
916
970
  }
917
971
  }
918
972
  return foundPendingTransactions;
919
- }, _XyoPendingTransactionsService.MutexPriority.ReadTransactions);
973
+ }, _BasePendingTransactionsService.MutexPriority.ReadTransactions);
920
974
  });
921
975
  }
922
976
  async cleanupWorker() {
923
977
  return await this._updateCuratedPendingTransactionsArchivistMutex.runExclusive(async () => {
924
978
  const lastHead = await findMostRecentBlock(this.chainArchivist);
925
979
  if (isDefined4(lastHead)) await this.pruneCuratedPendingTransactionsArchivist(lastHead._hash);
926
- }, _XyoPendingTransactionsService.MutexPriority.PurgeTransactions);
980
+ }, _BasePendingTransactionsService.MutexPriority.PurgeTransactions);
927
981
  }
928
982
  async countPendingTransactions() {
929
983
  if (this._countPendingTransactionsMutex.isLocked()) return;
@@ -958,7 +1012,7 @@ var XyoPendingTransactionsService = class _XyoPendingTransactionsService extends
958
1012
  const bundledTransactions = validTransactions.map((tx) => hydratedTransactionToPayloadBundle(tx));
959
1013
  await this.pendingBundledTransactionsLocalArchivist.insert(bundledTransactions);
960
1014
  }
961
- }, _XyoPendingTransactionsService.MutexPriority.InsertNewTransactions);
1015
+ }, _BasePendingTransactionsService.MutexPriority.InsertNewTransactions);
962
1016
  });
963
1017
  }
964
1018
  /**
@@ -1014,9 +1068,9 @@ var XyoPendingTransactionsService = class _XyoPendingTransactionsService extends
1014
1068
  });
1015
1069
  }
1016
1070
  };
1017
- XyoPendingTransactionsService = _ts_decorate9([
1071
+ BasePendingTransactionsService = _ts_decorate9([
1018
1072
  creatable9()
1019
- ], XyoPendingTransactionsService);
1073
+ ], BasePendingTransactionsService);
1020
1074
  var isTransactionExpired = /* @__PURE__ */ __name((block) => ([txBw]) => txBw.exp < block, "isTransactionExpired");
1021
1075
  var isTransactionActive = /* @__PURE__ */ __name((block) => ([txBw]) => txBw.nbf <= block && txBw.exp >= block, "isTransactionActive");
1022
1076
 
@@ -1053,9 +1107,9 @@ import { assertEx as assertEx10 } from "@xylabs/assert";
1053
1107
  import { creatable as creatable10 } from "@xylabs/creatable";
1054
1108
  import { asAddress } from "@xylabs/hex";
1055
1109
  import { isDefined as isDefined5, isUndefined as isUndefined2 } from "@xylabs/typeof";
1056
- import { analyzeChain as analyzeChain3, ChainStakeIntentAnalyzer, isChainSummaryStakeIntent } from "@xyo-network/chain-analyze";
1110
+ import { analyzeChain, ChainStakeIntentAnalyzer, isChainSummaryStakeIntent } from "@xyo-network/chain-analyze";
1057
1111
  import { DEFAULT_FIND_FIRST_MATCHING_NEXT_OPTIONS, findFirstMatching, IntervalMap } from "@xyo-network/chain-utils";
1058
- import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/payload-builder";
1112
+ import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
1059
1113
  import { asBlockBoundWitness as asBlockBoundWitness3, asBlockBoundWitnessWithStorageMeta, asChainIndexingServiceStateWithStorageMeta, asChainStakeIntent as asChainStakeIntent2, ChainIndexingServiceStateSchema, isChainIndexingServiceState } from "@xyo-network/xl1-protocol";
1060
1114
  import { Mutex as Mutex3 } from "async-mutex";
1061
1115
  import { LRUCache as LRUCache3 } from "lru-cache";
@@ -1105,7 +1159,7 @@ var XyoStakeIntentService = class extends BaseService {
1105
1159
  });
1106
1160
  const head = await this.chainIterator.head();
1107
1161
  if (isUndefined2(head)) return;
1108
- const headHash = await PayloadBuilder8.hash(head);
1162
+ const headHash = await PayloadBuilder7.hash(head);
1109
1163
  await this.recoverState(headHash);
1110
1164
  }
1111
1165
  async getDeclaredCandidateRanges(address, intent) {
@@ -1170,7 +1224,7 @@ var XyoStakeIntentService = class extends BaseService {
1170
1224
  }
1171
1225
  async persistState(current) {
1172
1226
  const state = this._producers.serialize();
1173
- const payload = new PayloadBuilder8({
1227
+ const payload = new PayloadBuilder7({
1174
1228
  schema: ChainIndexingServiceStateSchema
1175
1229
  }).fields({
1176
1230
  endBlockHash: current,
@@ -1222,8 +1276,8 @@ var XyoStakeIntentService = class extends BaseService {
1222
1276
  return await this.spanAsync("updateIndex", async () => {
1223
1277
  const currentHead = await this.chainIterator.head();
1224
1278
  if (isUndefined2(currentHead)) return;
1225
- const currentHeadHash = await PayloadBuilder8.hash(currentHead);
1226
- const result = await analyzeChain3(this.chainArchivist, [
1279
+ const currentHeadHash = await PayloadBuilder7.hash(currentHead);
1280
+ const result = await analyzeChain(this.chainArchivist, [
1227
1281
  new ChainStakeIntentAnalyzer("producer")
1228
1282
  ], currentHeadHash, this._lastIndexedBlockHash);
1229
1283
  const signedDeclarations = filterAs3(result.find(isChainSummaryStakeIntent)?.intents ?? [], asChainStakeIntent2);
@@ -1247,164 +1301,22 @@ var XyoStakeIntentService = class extends BaseService {
1247
1301
  XyoStakeIntentService = _ts_decorate10([
1248
1302
  creatable10()
1249
1303
  ], XyoStakeIntentService);
1250
-
1251
- // src/Staker/Evm/Evm.ts
1252
- import { assertEx as assertEx11 } from "@xylabs/assert";
1253
- import { toAddress } from "@xylabs/hex";
1254
- import { toEthAddress as toEthAddress2 } from "@xyo-network/chain-ethereum";
1255
- import { StakedXyoChain__factory as StakedXyoChainFactory } from "@xyo-network/typechain";
1256
- import { getAddress } from "ethers/address";
1257
- var EvmChainService = class extends BaseService {
1258
- static {
1259
- __name(this, "EvmChainService");
1260
- }
1261
- get chainId() {
1262
- return assertEx11(this.params.id);
1263
- }
1264
- get contract() {
1265
- if (this.params.contract === void 0) {
1266
- this.params.contract = StakedXyoChainFactory.connect(toEthAddress2(this.chainId), this.params.runner);
1267
- }
1268
- return assertEx11(this.params.contract);
1269
- }
1270
- get runner() {
1271
- return assertEx11(this.params.runner);
1272
- }
1273
- async active() {
1274
- return await this.contract.active();
1275
- }
1276
- async activeByAddressStaked(address) {
1277
- return await this.contract.activeByAddressStaked(getAddress(address));
1278
- }
1279
- async activeByStaker(address) {
1280
- return await this.contract.activeByStaker(getAddress(address));
1281
- }
1282
- async addStake(staked, amount) {
1283
- const result = await this.contract.addStake(getAddress(staked), amount);
1284
- await result.wait();
1285
- return true;
1286
- }
1287
- async forkedAtBlockNumber() {
1288
- return await this.contract.forkedAtBlockNumber();
1289
- }
1290
- async forkedAtHash() {
1291
- return await this.contract.forkedAtHash();
1292
- }
1293
- async forkedChainId() {
1294
- return toAddress(await this.contract.forkedChainId());
1295
- }
1296
- async minWithdrawalBlocks() {
1297
- return await this.contract.minWithdrawalBlocks();
1298
- }
1299
- async pending() {
1300
- return await this.contract.pending();
1301
- }
1302
- async pendingByStaker(staker) {
1303
- return await this.contract.pendingByStaker(getAddress(staker));
1304
- }
1305
- async removeStake(slot) {
1306
- const result = await this.contract.removeStake(slot);
1307
- await result.wait();
1308
- return true;
1309
- }
1310
- async rewardsContract() {
1311
- return await this.contract.rewardsContract();
1312
- }
1313
- async stakingTokenAddress() {
1314
- return await this.contract.stakingTokenAddress();
1315
- }
1316
- async withdrawStake(slot) {
1317
- const result = await this.contract.withdrawStake(slot);
1318
- await result.wait();
1319
- return true;
1320
- }
1321
- async withdrawn() {
1322
- return await this.contract.withdrawn();
1323
- }
1324
- async withdrawnByStaker(staker) {
1325
- return await this.contract.withdrawnByStaker(getAddress(staker));
1326
- }
1327
- };
1328
-
1329
- // src/Staker/Memory/Memory.ts
1330
- import { ZERO_ADDRESS } from "@xylabs/hex";
1331
- import { isDefined as isDefined6 } from "@xylabs/typeof";
1332
- var MemoryChainService = class extends BaseService {
1333
- static {
1334
- __name(this, "MemoryChainService");
1335
- }
1336
- _simulatedStake = 1n;
1337
- get chainId() {
1338
- return ZERO_ADDRESS;
1339
- }
1340
- async active() {
1341
- return await Promise.resolve(this._simulatedStake);
1342
- }
1343
- async activeByAddressStaked(_address) {
1344
- return await Promise.resolve(this._simulatedStake);
1345
- }
1346
- async activeByStaker(_address) {
1347
- return await Promise.resolve(this._simulatedStake);
1348
- }
1349
- async addStake(_staked, _amount) {
1350
- return await Promise.resolve(true);
1351
- }
1352
- createHandler() {
1353
- this._simulatedStake = isDefined6(process.env.XYO_PRODUCER_MIN_STAKE) ? BigInt(process.env.XYO_PRODUCER_MIN_STAKE) : 1n;
1354
- }
1355
- async forkedAtBlockNumber() {
1356
- return await Promise.resolve(0n);
1357
- }
1358
- async forkedAtHash() {
1359
- return await Promise.resolve(0n);
1360
- }
1361
- async forkedChainId() {
1362
- return await Promise.resolve(ZERO_ADDRESS);
1363
- }
1364
- async minWithdrawalBlocks() {
1365
- return await Promise.resolve(1n);
1366
- }
1367
- async pending() {
1368
- return await Promise.resolve(0n);
1369
- }
1370
- async pendingByStaker(_staker) {
1371
- return await Promise.resolve(0n);
1372
- }
1373
- async removeStake(_slot) {
1374
- return await Promise.resolve(true);
1375
- }
1376
- async rewardsContract() {
1377
- return await Promise.resolve("");
1378
- }
1379
- async stakingTokenAddress() {
1380
- return await Promise.resolve("");
1381
- }
1382
- async withdrawStake(_slot) {
1383
- return await Promise.resolve(true);
1384
- }
1385
- async withdrawn() {
1386
- return await Promise.resolve(0n);
1387
- }
1388
- async withdrawnByStaker(_staker) {
1389
- return await Promise.resolve(0n);
1390
- }
1391
- };
1392
1304
  export {
1305
+ BaseAccountBalanceService,
1393
1306
  BaseAccountableService,
1307
+ BaseBlockProducerService,
1308
+ BaseBlockRewardService,
1309
+ BaseElectionService,
1310
+ BasePendingTransactionsService,
1394
1311
  BaseService,
1395
- ChainAccountBalanceServiceV2,
1396
1312
  ChainBlockNumberIterationService,
1397
1313
  DEFAULT_BLOCK_SIZE,
1398
1314
  EvmBlockRewardService,
1399
1315
  EvmChainService,
1316
+ MemoryBlockRewardService,
1400
1317
  MemoryChainService,
1401
1318
  XYO_PRODUCER_REDECLARATION_DURATION,
1402
1319
  XYO_PRODUCER_REDECLARATION_WINDOW,
1403
- XyoBlockProducer,
1404
- XyoBlockRewardService,
1405
- XyoChainAccountBalanceService,
1406
- XyoElectionService,
1407
- XyoPendingTransactionsService,
1408
1320
  XyoStakeIntentService,
1409
1321
  XyoValidator,
1410
1322
  accountBalanceServiceFromArchivist,