@xyo-network/chain-services 1.5.35 → 1.5.36

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 (69) hide show
  1. package/dist/neutral/index.mjs +428 -259
  2. package/dist/neutral/index.mjs.map +1 -1
  3. package/dist/types/AccountBalance/ChainAccountBalanceServiceV2.d.ts +14 -0
  4. package/dist/types/AccountBalance/ChainAccountBalanceServiceV2.d.ts.map +1 -0
  5. package/dist/types/AccountBalance/XyoChainAccountBalanceService.d.ts +12 -8
  6. package/dist/types/AccountBalance/XyoChainAccountBalanceService.d.ts.map +1 -1
  7. package/dist/types/AccountBalance/accountBalanceServiceFromArchivist.d.ts +3 -2
  8. package/dist/types/AccountBalance/accountBalanceServiceFromArchivist.d.ts.map +1 -1
  9. package/dist/types/AccountBalance/index.d.ts +1 -0
  10. package/dist/types/AccountBalance/index.d.ts.map +1 -1
  11. package/dist/types/BaseService.d.ts +7 -8
  12. package/dist/types/BaseService.d.ts.map +1 -1
  13. package/dist/types/BlockProducer/XyoBlockProducer.d.ts +28 -9
  14. package/dist/types/BlockProducer/XyoBlockProducer.d.ts.map +1 -1
  15. package/dist/types/BlockReward/EvmBlockRewardService.d.ts +2 -1
  16. package/dist/types/BlockReward/EvmBlockRewardService.d.ts.map +1 -1
  17. package/dist/types/BlockReward/XyoBlockRewardService.d.ts +2 -1
  18. package/dist/types/BlockReward/XyoBlockRewardService.d.ts.map +1 -1
  19. package/dist/types/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts +4 -2
  20. package/dist/types/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts.map +1 -1
  21. package/dist/types/ChainBlockNumberIteration/model/Params.d.ts +8 -0
  22. package/dist/types/ChainBlockNumberIteration/model/Params.d.ts.map +1 -0
  23. package/dist/types/ChainBlockNumberIteration/model/index.d.ts +1 -0
  24. package/dist/types/ChainBlockNumberIteration/model/index.d.ts.map +1 -1
  25. package/dist/types/ChainIndexService.d.ts +8 -5
  26. package/dist/types/ChainIndexService.d.ts.map +1 -1
  27. package/dist/types/ChainValidator/XyoValidator.d.ts +20 -9
  28. package/dist/types/ChainValidator/XyoValidator.d.ts.map +1 -1
  29. package/dist/types/Election/XyoElectionService.d.ts +2 -2
  30. package/dist/types/Election/XyoElectionService.d.ts.map +1 -1
  31. package/dist/types/Params.d.ts +9 -0
  32. package/dist/types/Params.d.ts.map +1 -0
  33. package/dist/types/PendingTransactions/PendingTransactions.d.ts +7 -5
  34. package/dist/types/PendingTransactions/PendingTransactions.d.ts.map +1 -1
  35. package/dist/types/StakeIntent/XyoStakeIntentService.d.ts +10 -6
  36. package/dist/types/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
  37. package/dist/types/Staker/Evm/Evm.d.ts +5 -5
  38. package/dist/types/Staker/Evm/Evm.d.ts.map +1 -1
  39. package/dist/types/Staker/Memory/Memory.d.ts +31 -0
  40. package/dist/types/Staker/Memory/Memory.d.ts.map +1 -0
  41. package/dist/types/Staker/Memory/index.d.ts +2 -0
  42. package/dist/types/Staker/Memory/index.d.ts.map +1 -0
  43. package/dist/types/Staker/index.d.ts +1 -0
  44. package/dist/types/Staker/index.d.ts.map +1 -1
  45. package/dist/types/index.d.ts +1 -0
  46. package/dist/types/index.d.ts.map +1 -1
  47. package/package.json +45 -44
  48. package/src/AccountBalance/ChainAccountBalanceServiceV2.ts +33 -0
  49. package/src/AccountBalance/XyoChainAccountBalanceService.ts +23 -19
  50. package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +67 -35
  51. package/src/AccountBalance/index.ts +1 -0
  52. package/src/BaseService.ts +10 -23
  53. package/src/BlockProducer/XyoBlockProducer.ts +53 -30
  54. package/src/BlockReward/EvmBlockRewardService.ts +5 -5
  55. package/src/BlockReward/XyoBlockRewardService.ts +5 -3
  56. package/src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts +5 -3
  57. package/src/ChainBlockNumberIteration/model/Params.ts +9 -0
  58. package/src/ChainBlockNumberIteration/model/index.ts +1 -0
  59. package/src/ChainIndexService.ts +5 -5
  60. package/src/ChainValidator/XyoValidator.ts +9 -8
  61. package/src/Election/XyoElectionService.ts +5 -7
  62. package/src/Params.ts +9 -0
  63. package/src/PendingTransactions/PendingTransactions.ts +127 -63
  64. package/src/StakeIntent/XyoStakeIntentService.ts +30 -17
  65. package/src/Staker/Evm/Evm.ts +9 -12
  66. package/src/Staker/Memory/Memory.ts +90 -0
  67. package/src/Staker/Memory/index.ts +1 -0
  68. package/src/Staker/index.ts +1 -0
  69. package/src/index.ts +1 -0
@@ -1,23 +1,25 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
+ import { creatable } from '@xylabs/creatable'
2
3
  import { exists } from '@xylabs/exists'
3
4
  import {
4
5
  Address, hexToBigInt, toHex,
5
6
  } from '@xylabs/hex'
6
- import { isUndefined } from '@xylabs/typeof'
7
+ import { isDefined } from '@xylabs/typeof'
7
8
  import { ArchivistInstance } from '@xyo-network/archivist-model'
8
9
  import {
9
10
  BlockRewardDiviner, FixedPercentageBlockRewardDiviner, FixedPercentageBlockRewardDivinerConfigSchema,
10
11
  } from '@xyo-network/chain-modules'
11
- import { buildBlock } from '@xyo-network/chain-protocol'
12
+ import { buildNextBlock, createDeclarationIntent } from '@xyo-network/chain-protocol'
12
13
  import { PayloadBuilder } from '@xyo-network/payload-builder'
13
14
  import { WithStorageMeta } from '@xyo-network/payload-model'
14
15
  import {
15
- AccountBalanceService,
16
- AllowedBlockPayload, asBlockBoundWitness, BlockBoundWitness, BlockNumber, BlockNumberSchema, BlockProducerService, ChainStakeIntent, ChainStakeIntentSchema,
16
+ AccountBalanceServiceV2,
17
+ AllowedBlockPayload, asBlockBoundWitness, AttoXL1, BlockBoundWitness, BlockNumber, BlockNumberSchema,
18
+ BlockProducerService, ChainStakeIntent,
17
19
  HydratedBlock, PendingTransactionsService, StakeIntentService, Transfer,
18
20
  } from '@xyo-network/xl1-protocol'
19
21
 
20
- import { BaseService, creatableService } from '../BaseService.ts'
22
+ import { BaseService } from '../BaseService.ts'
21
23
  import { XyoValidatorParams } from '../ChainValidator/index.ts'
22
24
  import { generateTransactionFeeTransfers } from './generateTransactionFeeTransfers.ts'
23
25
 
@@ -29,29 +31,56 @@ export const DEFAULT_BLOCK_SIZE = 10
29
31
  // /**
30
32
  // * The amount of time for which a producer will restake their intent
31
33
  // */
32
- export const XYO_PRODUCER_RESTAKE_DURATION = 10_000
34
+ export const XYO_PRODUCER_REDECLARATION_DURATION = 10_000
33
35
 
34
36
  /**
35
37
  * The number of blocks within which a producer will redeclare
36
38
  * their intent to produce blocks
37
39
  */
38
- export const XYO_PRODUCER_RESTAKE_WINDOW = 500n
40
+ export const XYO_PRODUCER_REDECLARATION_WINDOW = 500
39
41
 
40
42
  export interface XyoBlockProducerParams extends XyoValidatorParams {
41
- balanceService: AccountBalanceService
43
+ balanceService: AccountBalanceServiceV2
42
44
  pendingTransactionsService: PendingTransactionsService
43
45
  rejectedTransactionsArchivist: ArchivistInstance
44
46
  rewardAddress: Address
45
47
  }
46
48
 
47
- @creatableService()
49
+ @creatable()
48
50
  export class XyoBlockProducer extends BaseService<XyoBlockProducerParams> implements BlockProducerService {
49
51
  protected _blockRewardDiviner: BlockRewardDiviner | undefined
50
52
 
53
+ /**
54
+ * The default block size for a block
55
+ */
51
56
  static get DefaultBlockSize(): number {
52
57
  return DEFAULT_BLOCK_SIZE
53
58
  }
54
59
 
60
+ /**
61
+ * The amount of time for which the producer will redeclare
62
+ * their intent to continue producing blocks
63
+ */
64
+ static get RedeclarationDuration(): number {
65
+ return XYO_PRODUCER_REDECLARATION_DURATION
66
+ }
67
+
68
+ /**
69
+ * The number of blocks within which the producer will redeclare
70
+ * their intent to continue producing blocks
71
+ */
72
+ static get RedeclarationWindow(): number {
73
+ return XYO_PRODUCER_REDECLARATION_WINDOW
74
+ }
75
+
76
+ /**
77
+ * Should the producer should redeclare
78
+ * their intent to continue producing blocks
79
+ */
80
+ static get RedeclareIntent(): boolean {
81
+ return isDefined(process.env.XYO_PRODUCER_SKIP_REDECLARE_INTENT) ? false : true
82
+ }
83
+
55
84
  get address() {
56
85
  return this.account.address
57
86
  }
@@ -68,8 +97,8 @@ export class XyoBlockProducer extends BaseService<XyoBlockProducerParams> implem
68
97
  return assertEx(this.params.chainArchivist, () => 'chainArchivist is required')
69
98
  }
70
99
 
71
- protected get chainInfo() {
72
- return assertEx(this.params.chainInformation, () => 'chainInfo is required')
100
+ protected get chainId() {
101
+ return assertEx(this.params.chainId, () => 'chainId is required')
73
102
  }
74
103
 
75
104
  protected get electionService() {
@@ -102,12 +131,12 @@ export class XyoBlockProducer extends BaseService<XyoBlockProducerParams> implem
102
131
 
103
132
  async next(head: WithStorageMeta<BlockBoundWitness>): Promise<HydratedBlock | undefined> {
104
133
  // If the block is for another chain, ignore
105
- if (head.chain !== this.chainInfo.id) return
134
+ if (head.chain !== this.chainId) return
106
135
  const leaders = await this.electionService.getCreatorCommitteeForNextBlock(head)
107
136
  // TODO: Should we propose block if creator committee is empty?
108
137
  // TODO: Handle the case where we're not the 1st leader but they're not responding
109
138
  // at a higher level than here as that's a network issue
110
- if (leaders?.[0] !== this.address) return
139
+ if (!leaders.includes(this.address)) return
111
140
  return this.proposeNextValidBlock(head)
112
141
  }
113
142
 
@@ -137,9 +166,9 @@ export class XyoBlockProducer extends BaseService<XyoBlockProducerParams> implem
137
166
  * @returns
138
167
  */
139
168
  protected async getProducerRedeclaration(head: WithStorageMeta<BlockBoundWitness>): Promise<ChainStakeIntent | undefined> {
140
- const redeclareIntent = process.env.XYO_PRODUCER_REDECLARE_INTENT
141
- if (isUndefined(redeclareIntent)) return
142
- // Decide if we need to redeclare
169
+ // Decide if we should redeclare intent
170
+ if (!XyoBlockProducer.RedeclareIntent) return
171
+ // Decide if we need to redeclare intent
143
172
  const ranges = await this.stakeIntentService.getDeclaredCandidateRanges(this.address, 'producer')
144
173
  // TODO: This doesn't handle the case where the producer had declared a range for the future
145
174
  // but we're in a range that's not the future
@@ -149,15 +178,8 @@ export class XyoBlockProducer extends BaseService<XyoBlockProducerParams> implem
149
178
  const [, currentDeclarationEnd] = lastRange
150
179
  const currentBlock = head.block
151
180
  const timeToProducerExpiration = currentDeclarationEnd - currentBlock
152
- if (timeToProducerExpiration > XYO_PRODUCER_RESTAKE_WINDOW) return
153
- // Create redeclaration
154
- const intent = new PayloadBuilder<ChainStakeIntent>({ schema: ChainStakeIntentSchema }).fields({
155
- from: this.address,
156
- intent: 'producer',
157
- nbf: currentBlock,
158
- exp: currentBlock + XYO_PRODUCER_RESTAKE_DURATION,
159
- }).build()
160
- return intent
181
+ if (timeToProducerExpiration > XyoBlockProducer.RedeclarationWindow) return
182
+ return createDeclarationIntent(this.address, 'producer', currentBlock, currentBlock + XyoBlockProducer.RedeclarationDuration)
161
183
  }
162
184
 
163
185
  protected async proposeNextValidBlock(head: WithStorageMeta<BlockBoundWitness>, validateBalances = false): Promise<HydratedBlock | undefined> {
@@ -183,12 +205,13 @@ export class XyoBlockProducer extends BaseService<XyoBlockProducerParams> implem
183
205
  const transactionTransfers = await generateTransactionFeeTransfers(this.address, nextBlockTransactions)
184
206
 
185
207
  const fundedTransfers: Transfer[] = []
186
- const fundedNextBlockTransactions = nextBlockTransactions.map((tx) => {
208
+ const fundedNextBlockTransactions = (await Promise.all(nextBlockTransactions.map(async (tx) => {
187
209
  const transfer: Transfer | undefined = transactionTransfers.find(txTransfer => txTransfer.from === tx[0].from)
188
210
  if (!transfer) return
189
211
  const totalTransferCost = Object.values(transfer?.transfers).reduce((acc, t) => acc + hexToBigInt(t ?? '00'), 0n)
190
212
  if (validateBalances) {
191
- if (hexToBigInt(this.balanceService.getBalance(transfer.from)) >= totalTransferCost) {
213
+ const balance = (await this.balanceService.balances(head._hash, [transfer.from]))[transfer.from] ?? AttoXL1(0n)
214
+ if (balance >= totalTransferCost) {
192
215
  fundedTransfers.push(transfer)
193
216
  return tx
194
217
  }
@@ -196,13 +219,13 @@ export class XyoBlockProducer extends BaseService<XyoBlockProducerParams> implem
196
219
  fundedTransfers.push(transfer)
197
220
  return tx
198
221
  }
199
- }).filter(exists)
222
+ }))).filter(exists)
200
223
  blockPayloads.push(...fundedTransfers)
201
224
 
202
225
  // Build the block
203
- const block = await buildBlock(head, fundedNextBlockTransactions, blockPayloads, [this.account])
226
+ const block = await buildNextBlock(head, fundedNextBlockTransactions, blockPayloads, [this.account])
204
227
  this.logger?.warn(`buildBlock: ${block[0].block} with ${block[1].length} payloads`)
205
- const errors = await this.validateHydratedBlockState(block, this.chainInfo.id, { accountBalance: this.balanceService })
228
+ const errors = await this.validateHydratedBlockState(block, this.chainId, { accountBalance: this.balanceService })
206
229
  if (errors.length > 0) {
207
230
  this.logger?.warn(`Validation of produced block failed: ${errors.at(0)?.message}`)
208
231
  const rejectedTransactions = block[1]
@@ -1,19 +1,19 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
+ import { creatable } from '@xylabs/creatable'
2
3
  import { toEthAddress } from '@xyo-network/chain-ethereum'
3
4
  import { XyoChainRewards__factory as XyoChainRewardsFactory } from '@xyo-network/typechain'
4
- import {
5
- BaseAccountableServiceParams, BlockRewardService, ChainService,
6
- } from '@xyo-network/xl1-protocol'
5
+ import { BlockRewardService, ChainService } from '@xyo-network/xl1-protocol'
7
6
  import { Provider } from 'ethers/providers'
8
7
 
9
- import { BaseService, creatableService } from '../BaseService.ts'
8
+ import { BaseService } from '../BaseService.ts'
9
+ import { BaseAccountableServiceParams } from '../Params.ts'
10
10
 
11
11
  export interface EvmBlockRewardServiceParams extends BaseAccountableServiceParams {
12
12
  chainService?: ChainService
13
13
  provider?: Provider
14
14
  }
15
15
 
16
- @creatableService<EvmBlockRewardService>()
16
+ @creatable()
17
17
  export class EvmBlockRewardService extends BaseService<EvmBlockRewardServiceParams> implements BlockRewardService {
18
18
  protected _contractAddress: string | undefined
19
19
 
@@ -1,10 +1,12 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
+ import { creatable } from '@xylabs/creatable'
2
3
  import { toFixedPoint } from '@xylabs/decimal-precision'
3
4
  import { Promisable } from '@xylabs/promise'
4
5
  import { rewardFromBlockNumber } from '@xyo-network/chain-protocol'
5
- import { BaseServiceParams, BlockRewardService } from '@xyo-network/xl1-protocol'
6
+ import { BlockRewardService } from '@xyo-network/xl1-protocol'
6
7
 
7
- import { BaseService, creatableService } from '../BaseService.ts'
8
+ import { BaseService } from '../BaseService.ts'
9
+ import { BaseServiceParams } from '../Params.ts'
8
10
 
9
11
  export interface XyoBlockRewardServiceParams extends BaseServiceParams {
10
12
  creatorReward?: bigint
@@ -15,7 +17,7 @@ export interface XyoBlockRewardServiceParams extends BaseServiceParams {
15
17
  stepSize?: bigint
16
18
  }
17
19
 
18
- @creatableService()
20
+ @creatable()
19
21
  export class XyoBlockRewardService extends BaseService<XyoBlockRewardServiceParams> implements BlockRewardService {
20
22
  protected readonly rewardFromBlockNumber = rewardFromBlockNumber(18)
21
23
 
@@ -1,12 +1,12 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
+ import type { Address } from '@xylabs/hex'
2
3
  import { isDefined, isNull } from '@xylabs/typeof'
3
4
  import type { ArchivistInstance } from '@xyo-network/archivist-model'
4
5
  import { PayloadBuilder } from '@xyo-network/payload-builder'
5
6
  import type {
6
- BlockBoundWitness, ChainIdentification,
7
+ BlockBoundWitness,
7
8
  ChainIteratorEventData,
8
9
  EventingChainBlockNumberIterator,
9
- XyoChainIteratorParams,
10
10
  } from '@xyo-network/xl1-protocol'
11
11
  import {
12
12
  asBlockBoundWitness,
@@ -15,16 +15,18 @@ import {
15
15
  import { LRUCache } from 'lru-cache'
16
16
 
17
17
  import { BaseService } from '../BaseService.ts'
18
+ import type { XyoChainIteratorParams } from './model/Params.ts'
18
19
 
19
20
  export class ChainBlockNumberIterationService extends BaseService<XyoChainIteratorParams, ChainIteratorEventData> implements EventingChainBlockNumberIterator {
20
21
  protected _blocksByBlockNumber = new LRUCache<number, BlockBoundWitness>({ max: 10_000 })
21
22
 
22
23
  get chainArchivist(): ArchivistInstance { return assertEx(this.params.chainArchivist) }
23
24
 
24
- get chainIdentification(): ChainIdentification { return { id: assertEx(this.params.head?.chain) } }
25
+ get chainId(): Address { return assertEx(this.params.head?.chain) }
25
26
 
26
27
  async get(block: number): Promise<BlockBoundWitness> {
27
28
  const head = await this.head()
29
+ // if(isUndefined(head)) return undefined
28
30
  // Bail early if the block requested is newer than the current head
29
31
  assertEx(head.block >= block, () => `Block requested is newer than the current head [${block}]`)
30
32
  const cached = this._blocksByBlockNumber.get(block)
@@ -0,0 +1,9 @@
1
+ import type { ArchivistInstance } from '@xyo-network/archivist-model'
2
+ import type { BlockBoundWitness } from '@xyo-network/xl1-protocol'
3
+
4
+ import type { BaseServiceParams } from '../../Params.ts'
5
+
6
+ export interface XyoChainIteratorParams extends BaseServiceParams {
7
+ chainArchivist: ArchivistInstance
8
+ head: BlockBoundWitness
9
+ }
@@ -1 +1,2 @@
1
1
  export * from './BlockNumberIteration.ts'
2
+ export * from './Params.ts'
@@ -1,13 +1,13 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
+ import { creatable } from '@xylabs/creatable'
2
3
  import { Hash, Hex } from '@xylabs/hex'
3
4
  import { Promisable } from '@xylabs/promise'
4
5
  import { MemoryArchivist } from '@xyo-network/archivist-memory'
5
6
  import { ArchivistInstance } from '@xyo-network/archivist-model'
6
- import {
7
- BaseServiceParams, HydratedBlock, Service,
8
- } from '@xyo-network/xl1-protocol'
7
+ import { HydratedBlock, Service } from '@xyo-network/xl1-protocol'
9
8
 
10
- import { BaseService, creatableService } from './BaseService.ts'
9
+ import { BaseService } from './BaseService.ts'
10
+ import { BaseServiceParams } from './Params.ts'
11
11
 
12
12
  export interface ChainIndexServiceParams extends BaseServiceParams {
13
13
  archivist?: ArchivistInstance
@@ -18,7 +18,7 @@ export interface ChainIndexService extends Service {
18
18
  updateHead(head: Hash | null): Promisable<void>
19
19
  }
20
20
 
21
- @creatableService()
21
+ @creatable()
22
22
  export class XyoChainIndexService extends BaseService<ChainIndexServiceParams> implements ChainIndexService {
23
23
  private _head: Hash | null = null
24
24
  private _internalArchivist: ArchivistInstance | undefined
@@ -1,33 +1,34 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
+ import { creatable } from '@xylabs/creatable'
3
+ import { Address } from '@xylabs/hex'
2
4
  import { Promisable } from '@xylabs/promise'
3
5
  import { AccountInstance } from '@xyo-network/account-model'
4
6
  import { ArchivistInstance, ReadArchivist } from '@xyo-network/archivist-model'
5
7
  import {
6
- BaseServiceParams,
7
8
  BlockBoundWitness,
8
9
  BlockRewardService,
9
- ChainInformation,
10
10
  ElectionService,
11
- HydratedBlockStateValidationFunction,
11
+ HydratedBlockStateValidationFunctionV2,
12
12
  HydratedTransaction,
13
13
  StakeIntentService,
14
14
  } from '@xyo-network/xl1-protocol'
15
15
 
16
- import { BaseService, creatableService } from '../BaseService.ts'
16
+ import { BaseService } from '../BaseService.ts'
17
+ import { BaseServiceParams } from '../Params.ts'
17
18
  import { Validator } from './model/index.ts'
18
19
 
19
20
  export interface XyoValidatorParams extends BaseServiceParams {
20
21
  account: AccountInstance
21
22
  chainArchivist: ReadArchivist
22
- chainInformation: ChainInformation
23
+ chainId: Address
23
24
  electionService: ElectionService
24
25
  pendingBundledTransactionsArchivist: ArchivistInstance
25
26
  rewardService: BlockRewardService
26
27
  stakeIntentService: StakeIntentService
27
- validateHydratedBlockState: HydratedBlockStateValidationFunction
28
+ validateHydratedBlockState: HydratedBlockStateValidationFunctionV2
28
29
  }
29
30
 
30
- @creatableService()
31
+ @creatable()
31
32
  export class XyoValidator<TParams extends XyoValidatorParams = XyoValidatorParams> extends BaseService<TParams> implements Validator {
32
33
  get address() {
33
34
  return this.account.address
@@ -42,7 +43,7 @@ export class XyoValidator<TParams extends XyoValidatorParams = XyoValidatorParam
42
43
  }
43
44
 
44
45
  protected get chainInfo() {
45
- return assertEx(this.params.chainInformation, () => 'chainInfo is required')
46
+ return assertEx(this.params.chainId, () => 'chainInfo is required')
46
47
  }
47
48
 
48
49
  protected get electionService() {
@@ -1,13 +1,15 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
+ import { creatable } from '@xylabs/creatable'
2
3
  import { Address, Hash } from '@xylabs/hex'
3
4
  import { hexToLast4BytesInt, shuffleWithSeed } from '@xyo-network/chain-utils'
4
5
  import { PayloadBuilder } from '@xyo-network/payload-builder'
5
6
  import type {
6
- BaseServiceParams, ChainBlockNumberIterator, ChainStakeViewer, StakeIntentService,
7
+ ChainBlockNumberIterator, ChainStakeViewer, StakeIntentService,
7
8
  } from '@xyo-network/xl1-protocol'
8
9
  import { BlockBoundWitness, ElectionService } from '@xyo-network/xl1-protocol'
9
10
 
10
- import { BaseService, creatableService } from '../BaseService.ts'
11
+ import { BaseService } from '../BaseService.ts'
12
+ import { BaseServiceParams } from '../Params.ts'
11
13
 
12
14
  export interface XyoElectionServicesParams extends BaseServiceParams {
13
15
  chainIterator?: ChainBlockNumberIterator
@@ -15,12 +17,8 @@ export interface XyoElectionServicesParams extends BaseServiceParams {
15
17
  stakeIntentService?: StakeIntentService
16
18
  }
17
19
 
18
- @creatableService()
20
+ @creatable()
19
21
  export class XyoElectionService extends BaseService<XyoElectionServicesParams> implements ElectionService {
20
- constructor(params: XyoElectionServicesParams) {
21
- super(params)
22
- }
23
-
24
22
  get chainIterator() {
25
23
  return assertEx(this.params.chainIterator, () => 'No chain iterator')
26
24
  }
package/src/Params.ts ADDED
@@ -0,0 +1,9 @@
1
+ import type { CreatableParams } from '@xylabs/creatable'
2
+ import type { AccountInstance } from '@xyo-network/account-model'
3
+ import type { OpenTelemetryProviders } from '@xyo-network/xl1-protocol'
4
+
5
+ export interface BaseServiceParams extends CreatableParams, OpenTelemetryProviders {}
6
+
7
+ export interface BaseAccountableServiceParams extends BaseServiceParams {
8
+ account: AccountInstance
9
+ }