@xyo-network/chain-services 1.15.2 → 1.15.3

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 (35) hide show
  1. package/README.md +5302 -2235
  2. package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts +3 -5
  3. package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts.map +1 -1
  4. package/dist/neutral/AccountBalance/accountBalanceServiceFromArchivist.d.ts +3 -2
  5. package/dist/neutral/AccountBalance/accountBalanceServiceFromArchivist.d.ts.map +1 -1
  6. package/dist/neutral/AccountTransfers/BaseAccountTransfersService.d.ts +3 -6
  7. package/dist/neutral/AccountTransfers/BaseAccountTransfersService.d.ts.map +1 -1
  8. package/dist/neutral/AccountTransfers/accountTransfersServiceFromArchivist.d.ts +3 -3
  9. package/dist/neutral/AccountTransfers/accountTransfersServiceFromArchivist.d.ts.map +1 -1
  10. package/dist/neutral/BlockProducer/spec/BaseBlockProducerService.spec.d.ts.map +1 -1
  11. package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts +3 -3
  12. package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts.map +1 -1
  13. package/dist/neutral/ChainBlockNumberIteration/model/Params.d.ts +3 -2
  14. package/dist/neutral/ChainBlockNumberIteration/model/Params.d.ts.map +1 -1
  15. package/dist/neutral/ChainValidator/XyoValidator.d.ts +2 -2
  16. package/dist/neutral/ChainValidator/XyoValidator.d.ts.map +1 -1
  17. package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts +14 -13
  18. package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts.map +1 -1
  19. package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts +2 -2
  20. package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts.map +1 -1
  21. package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
  22. package/dist/neutral/index.mjs +102 -144
  23. package/dist/neutral/index.mjs.map +1 -1
  24. package/package.json +40 -40
  25. package/src/AccountBalance/BaseAccountBalanceService.ts +6 -8
  26. package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +18 -33
  27. package/src/AccountTransfers/BaseAccountTransfersService.ts +4 -12
  28. package/src/AccountTransfers/accountTransfersServiceFromArchivist.ts +18 -35
  29. package/src/BlockProducer/spec/BaseBlockProducerService.spec.ts +62 -8
  30. package/src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts +11 -11
  31. package/src/ChainBlockNumberIteration/model/Params.ts +3 -2
  32. package/src/ChainValidator/XyoValidator.ts +2 -2
  33. package/src/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.ts +20 -14
  34. package/src/PendingTransactions/BasePendingTransactions.ts +2 -2
  35. package/src/StakeIntent/XyoStakeIntentService.ts +3 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "http://json.schemastore.org/package.json",
3
3
  "name": "@xyo-network/chain-services",
4
- "version": "1.15.2",
4
+ "version": "1.15.3",
5
5
  "description": "XYO Layer One SDK Services",
6
6
  "homepage": "https://xylabs.com",
7
7
  "bugs": {
@@ -37,51 +37,51 @@
37
37
  ],
38
38
  "dependencies": {
39
39
  "@opentelemetry/api": "~1.9.0",
40
- "@xylabs/array": "~5.0.11",
41
- "@xylabs/assert": "~5.0.11",
42
- "@xylabs/creatable": "~5.0.11",
43
- "@xylabs/decimal-precision": "~5.0.11",
44
- "@xylabs/events": "~5.0.11",
45
- "@xylabs/exists": "~5.0.11",
46
- "@xylabs/forget": "~5.0.11",
47
- "@xylabs/hex": "~5.0.11",
48
- "@xylabs/promise": "~5.0.11",
49
- "@xylabs/telemetry": "~5.0.11",
50
- "@xylabs/typeof": "~5.0.11",
51
- "@xyo-network/account-model": "~5.1.3",
52
- "@xyo-network/archivist-memory": "~5.1.3",
53
- "@xyo-network/archivist-model": "~5.1.3",
54
- "@xyo-network/boundwitness-model": "~5.1.3",
55
- "@xyo-network/boundwitness-validator": "~5.1.3",
56
- "@xyo-network/boundwitness-wrapper": "~5.1.3",
57
- "@xyo-network/chain-analyze": "~1.15.2",
58
- "@xyo-network/chain-modules": "~1.15.2",
59
- "@xyo-network/chain-protocol": "~1.15.2",
60
- "@xyo-network/chain-utils": "~1.15.2",
61
- "@xyo-network/payload-builder": "~5.1.3",
62
- "@xyo-network/payload-model": "~5.1.3",
63
- "@xyo-network/typechain": "~4.0.8",
64
- "@xyo-network/xl1-protocol": "~1.12.40",
65
- "@xyo-network/xl1-protocol-sdk": "~1.15.2",
66
- "@xyo-network/xl1-validation": "~1.15.2",
67
- "@xyo-network/xl1-wrappers": "~1.15.2",
40
+ "@xylabs/array": "~5.0.12",
41
+ "@xylabs/assert": "~5.0.12",
42
+ "@xylabs/creatable": "~5.0.12",
43
+ "@xylabs/decimal-precision": "~5.0.12",
44
+ "@xylabs/events": "~5.0.12",
45
+ "@xylabs/exists": "~5.0.12",
46
+ "@xylabs/forget": "~5.0.12",
47
+ "@xylabs/hex": "~5.0.12",
48
+ "@xylabs/promise": "~5.0.12",
49
+ "@xylabs/telemetry": "~5.0.12",
50
+ "@xylabs/typeof": "~5.0.12",
51
+ "@xyo-network/account-model": "~5.1.6",
52
+ "@xyo-network/archivist-memory": "~5.1.6",
53
+ "@xyo-network/archivist-model": "~5.1.6",
54
+ "@xyo-network/boundwitness-model": "~5.1.6",
55
+ "@xyo-network/boundwitness-validator": "~5.1.6",
56
+ "@xyo-network/boundwitness-wrapper": "~5.1.6",
57
+ "@xyo-network/chain-analyze": "~1.15.3",
58
+ "@xyo-network/chain-modules": "~1.15.3",
59
+ "@xyo-network/chain-protocol": "~1.15.3",
60
+ "@xyo-network/chain-utils": "~1.15.3",
61
+ "@xyo-network/payload-builder": "~5.1.6",
62
+ "@xyo-network/payload-model": "~5.1.6",
63
+ "@xyo-network/typechain": "~4.0.10",
64
+ "@xyo-network/xl1-protocol": "~1.12.66",
65
+ "@xyo-network/xl1-protocol-sdk": "~1.15.3",
66
+ "@xyo-network/xl1-validation": "~1.15.3",
67
+ "@xyo-network/xl1-wrappers": "~1.15.3",
68
68
  "async-mutex": "~0.5.0",
69
69
  "ethers": "6.15.0",
70
70
  "lru-cache": "~11.2.2"
71
71
  },
72
72
  "devDependencies": {
73
- "@types/node": "~24.5.2",
74
- "@xylabs/delay": "~5.0.11",
75
- "@xylabs/ts-scripts-yarn3": "~7.1.7",
76
- "@xylabs/tsconfig": "~7.1.7",
77
- "@xylabs/vitest-extended": "~5.0.11",
78
- "@xyo-network/account": "~5.1.3",
79
- "@xyo-network/account-model": "~5.1.3",
80
- "@xyo-network/chain-validation": "~1.15.2",
81
- "@xyo-network/wallet": "~5.1.3",
82
- "eslint": "^9.36.0",
73
+ "@types/node": "~24.7.2",
74
+ "@xylabs/delay": "~5.0.12",
75
+ "@xylabs/ts-scripts-yarn3": "~7.1.8",
76
+ "@xylabs/tsconfig": "~7.1.8",
77
+ "@xylabs/vitest-extended": "~5.0.12",
78
+ "@xyo-network/account": "~5.1.6",
79
+ "@xyo-network/account-model": "~5.1.6",
80
+ "@xyo-network/chain-validation": "~1.15.3",
81
+ "@xyo-network/wallet": "~5.1.6",
82
+ "eslint": "^9.37.0",
83
83
  "tslib": "~2.8.1",
84
- "typescript": "~5.9.2",
84
+ "typescript": "~5.9.3",
85
85
  "vitest": "~3.2.4",
86
86
  "vitest-mock-extended": "~3.1.0",
87
87
  "web3-types": "~1.10.0"
@@ -1,31 +1,29 @@
1
1
  import { creatable } from '@xylabs/creatable'
2
2
  import { Address, Hash } from '@xylabs/hex'
3
3
  import { spanRootAsync } from '@xylabs/telemetry'
4
- import { ReadArchivist } from '@xyo-network/archivist-model'
5
4
  import {
6
5
  AccountBalanceServiceV2,
7
- AttoXL1, PayloadRepository,
6
+ AttoXL1,
8
7
  } from '@xyo-network/xl1-protocol'
9
8
  import {
10
- BalancesStepSummary,
11
9
  balancesSummary,
10
+ BalanceStepSummaryContext,
12
11
  } from '@xyo-network/xl1-protocol-sdk'
13
12
 
14
13
  import { BaseService } from '../BaseService.ts'
15
14
  import { BaseServiceParams } from '../model/index.ts'
16
15
 
17
16
  export interface BaseAccountBalanceServiceParams extends BaseServiceParams {
18
- chainArchivist: ReadArchivist
19
- summaryRepository: PayloadRepository<Hash, BalancesStepSummary>
17
+ context: BalanceStepSummaryContext
20
18
  }
21
19
 
22
20
  @creatable()
23
21
  export class BaseAccountBalanceService extends BaseService<BaseAccountBalanceServiceParams> implements AccountBalanceServiceV2 {
24
22
  async balances(head: Hash, address: Address[]): Promise<Partial<Record<Address, AttoXL1>>> {
25
23
  return await spanRootAsync('balances', async () => {
26
- const summary = await balancesSummary({
27
- chainArchivist: this.params.chainArchivist, summaryRepository: this.params.summaryRepository, head,
28
- })
24
+ const summary = await balancesSummary(
25
+ this.params.context,
26
+ )
29
27
  const result: Record<Address, AttoXL1> = {}
30
28
  for (const addr of address) {
31
29
  const summaryBalance = summary[addr] ?? 0n
@@ -1,45 +1,30 @@
1
- import { exists } from '@xylabs/exists'
2
- import {
3
- asHash, type Hash,
4
- isHash,
5
- } from '@xylabs/hex'
1
+ import { ZERO_HASH } from '@xylabs/hex'
6
2
  import type { ReadArchivist } from '@xyo-network/archivist-model'
7
- import { PayloadBuilder } from '@xyo-network/payload-builder'
8
- import type { WithStorageMeta } from '@xyo-network/payload-model'
9
- import type { AccountBalanceServiceV2 } from '@xyo-network/xl1-protocol'
10
- import type { BalancesStepSummary, StepSummary } from '@xyo-network/xl1-protocol-sdk'
11
- import { LRUCache } from 'lru-cache'
3
+ import { LruCacheMap } from '@xyo-network/chain-protocol'
4
+ import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
5
+ import type { AccountBalanceServiceV2, ChainId } from '@xyo-network/xl1-protocol'
6
+ import { type BalancesStepSummary, readPayloadMapFromStore } from '@xyo-network/xl1-protocol-sdk'
12
7
 
13
8
  import { BaseAccountBalanceService } from './BaseAccountBalanceService.ts'
14
9
 
15
- export const accountBalanceServiceFromArchivist = async (archivist: ReadArchivist): Promise<AccountBalanceServiceV2> => {
16
- const summaryArchivistCache = new LRUCache<Hash, WithStorageMeta<BalancesStepSummary>>({
10
+ export const accountBalancesServiceFromArchivist = async (
11
+ chainId: ChainId,
12
+ archivist: ReadArchivist<WithStorageMeta<Payload>>,
13
+ ): Promise<AccountBalanceServiceV2> => {
14
+ const summaryMap = new LruCacheMap<string, BalancesStepSummary>({
17
15
  max: 100_000,
18
16
  allowStale: true,
19
17
  noDisposeOnSet: false,
20
18
  updateAgeOnGet: true,
21
19
  })
22
- const summaryRepository = {
23
- get: (hashes: Hash[]) => {
24
- const results = hashes.map((hash) => {
25
- return summaryArchivistCache.get(hash)
26
- }).filter(exists)
27
- return results
20
+ const chainMap = readPayloadMapFromStore<WithStorageMeta<Payload>>(archivist)
21
+ const service = await BaseAccountBalanceService.create({
22
+ context: {
23
+ chainId,
24
+ store: { chainMap },
25
+ summaryMap,
26
+ head: () => ZERO_HASH,
28
27
  },
29
- insert: async (payloads: BalancesStepSummary[]) => {
30
- const results = (await PayloadBuilder.addStorageMeta(payloads)).map((payload) => {
31
- const hash = asHash((payload as WithStorageMeta<StepSummary>).hash)
32
- if (isHash(hash)) {
33
- summaryArchivistCache.set(hash, payload)
34
- return payload
35
- }
36
- }).filter(exists)
37
- return results
38
- },
39
- next: () => {
40
- throw new Error('Not implemented')
41
- },
42
- }
43
- const service = await BaseAccountBalanceService.create({ chainArchivist: archivist, summaryRepository })
28
+ })
44
29
  return service
45
30
  }
@@ -1,13 +1,12 @@
1
1
  import { creatable } from '@xylabs/creatable'
2
2
  import { Address, Hash } from '@xylabs/hex'
3
3
  import { spanRootAsync } from '@xylabs/telemetry'
4
- import { ReadArchivist } from '@xyo-network/archivist-model'
5
4
  import {
6
5
  AccountTransfersService,
7
- AttoXL1, PayloadRepository,
6
+ AttoXL1,
8
7
  } from '@xyo-network/xl1-protocol'
9
8
  import {
10
- TransfersStepSummary,
9
+ TransfersStepSummaryContext,
11
10
  transfersSummary,
12
11
  } from '@xyo-network/xl1-protocol-sdk'
13
12
 
@@ -15,9 +14,7 @@ import { BaseService } from '../BaseService.ts'
15
14
  import { BaseServiceParams } from '../model/index.ts'
16
15
 
17
16
  export interface BaseAccountTransferServiceParams extends BaseServiceParams {
18
- account: Address
19
- chainArchivist: ReadArchivist
20
- summaryRepository: PayloadRepository<Hash, TransfersStepSummary>
17
+ context: TransfersStepSummaryContext
21
18
  }
22
19
 
23
20
  @creatable()
@@ -28,12 +25,7 @@ export class BaseAccountTransfersService extends BaseService<BaseAccountTransfer
28
25
 
29
26
  async transfers(head: Hash, addresses: Address[]): Promise<Partial<Record<Address, AttoXL1>>> {
30
27
  return await spanRootAsync('transfers', async () => {
31
- const {
32
- chainArchivist, summaryRepository, account,
33
- } = this.params
34
- const summary = await transfersSummary({
35
- chainArchivist, summaryRepository, head, account,
36
- })
28
+ const summary = await transfersSummary(this.params.context)
37
29
  const result: Record<Address, AttoXL1> = {}
38
30
  for (const addr of addresses) {
39
31
  const summaryBalance = summary[addr] ?? 0n
@@ -1,48 +1,31 @@
1
- import { exists } from '@xylabs/exists'
2
- import type { Address, Hash } from '@xylabs/hex'
3
- import {
4
- asHash,
5
- isHash,
6
- } from '@xylabs/hex'
1
+ import { ZERO_HASH } from '@xylabs/hex'
7
2
  import type { ReadArchivist } from '@xyo-network/archivist-model'
8
- import { PayloadBuilder } from '@xyo-network/payload-builder'
9
- import type { WithStorageMeta } from '@xyo-network/payload-model'
10
- import type { AccountTransfersService } from '@xyo-network/xl1-protocol'
11
- import type { StepSummary, TransfersStepSummary } from '@xyo-network/xl1-protocol-sdk'
12
- import { LRUCache } from 'lru-cache'
3
+ import { LruCacheMap } from '@xyo-network/chain-protocol'
4
+ import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
5
+ import type { AccountTransfersService, ChainId } from '@xyo-network/xl1-protocol'
6
+ import type { TransfersStepSummary } from '@xyo-network/xl1-protocol-sdk'
7
+ import { readPayloadMapFromStore } from '@xyo-network/xl1-protocol-sdk'
13
8
 
14
9
  import { BaseAccountTransfersService } from './BaseAccountTransfersService.ts'
15
10
 
16
- export const accountTransferServiceFromArchivist = async (archivist: ReadArchivist, account: Address): Promise<AccountTransfersService> => {
17
- const summaryArchivistCache = new LRUCache<Hash, WithStorageMeta<TransfersStepSummary>>({
11
+ export const accountTransfersServiceFromArchivist = async (
12
+ chainId: ChainId,
13
+ archivist: ReadArchivist<WithStorageMeta<Payload>>,
14
+ ): Promise<AccountTransfersService> => {
15
+ const summaryMap = new LruCacheMap<string, TransfersStepSummary>({
18
16
  max: 100_000,
19
17
  allowStale: true,
20
18
  noDisposeOnSet: false,
21
19
  updateAgeOnGet: true,
22
20
  })
23
- const summaryRepository = {
24
- get: (hashes: Hash[]) => {
25
- const results = hashes.map((hash) => {
26
- return summaryArchivistCache.get(hash)
27
- }).filter(exists)
28
- return results
29
- },
30
- insert: async (payloads: TransfersStepSummary[]) => {
31
- const results = (await PayloadBuilder.addStorageMeta(payloads)).map((payload) => {
32
- const hash = asHash((payload as WithStorageMeta<StepSummary>).hash)
33
- if (isHash(hash)) {
34
- summaryArchivistCache.set(hash, payload)
35
- return payload
36
- }
37
- }).filter(exists)
38
- return results
39
- },
40
- next: () => {
41
- throw new Error('Not implemented')
42
- },
43
- }
21
+ const chainMap = readPayloadMapFromStore<WithStorageMeta<Payload>>(archivist)
44
22
  const service = await BaseAccountTransfersService.create({
45
- chainArchivist: archivist, account, summaryRepository,
23
+ context: {
24
+ chainId,
25
+ store: { chainMap },
26
+ summaryMap,
27
+ head: () => ZERO_HASH,
28
+ },
46
29
  })
47
30
  return service
48
31
  }
@@ -1,13 +1,15 @@
1
+ /* eslint-disable max-statements */
1
2
  import '@xylabs/vitest-extended'
2
3
 
3
4
  import { filterAs } from '@xylabs/array'
4
5
  import { assertEx } from '@xylabs/assert'
5
6
  import type { CreatableName } from '@xylabs/creatable'
6
7
  import { delay } from '@xylabs/delay'
7
- import type { Address } from '@xylabs/hex'
8
+ import type { Address, Hash } from '@xylabs/hex'
8
9
  import {
9
10
  asAddress, hexToBigInt, ZERO_HASH,
10
11
  } from '@xylabs/hex'
12
+ import type { Promisable } from '@xylabs/promise'
11
13
  import { Account } from '@xyo-network/account'
12
14
  import type { AccountInstance } from '@xyo-network/account-model'
13
15
  import { MemoryArchivist } from '@xyo-network/archivist-memory'
@@ -19,10 +21,11 @@ import {
19
21
  } from '@xyo-network/payload-model'
20
22
  import { HDWallet } from '@xyo-network/wallet'
21
23
  import type {
22
- BlockBoundWitness, BlockRewardService, Chain, ElectionService,
24
+ BlockBoundWitness, BlockRewardService, ChainId, ElectionService,
23
25
  HydratedBlock,
24
26
  HydratedBlockStateValidationFunctionV2,
25
27
  StakeIntentService,
28
+ TimeDomain, TimePayload,
26
29
  TimeSyncViewInterfaceV2,
27
30
  } from '@xyo-network/xl1-protocol'
28
31
  import {
@@ -31,6 +34,7 @@ import {
31
34
  asTransactionBoundWitness,
32
35
  asTransfer,
33
36
  HydratedBlockStateValidationError,
37
+ TimeSchema,
34
38
  XYO_ZERO_ADDRESS,
35
39
  } from '@xyo-network/xl1-protocol'
36
40
  import type { Config } from '@xyo-network/xl1-protocol-sdk'
@@ -42,7 +46,7 @@ import {
42
46
  } from 'vitest'
43
47
  import { mock } from 'vitest-mock-extended'
44
48
 
45
- import { accountBalanceServiceFromArchivist } from '../../AccountBalance/index.ts'
49
+ import { accountBalancesServiceFromArchivist } from '../../AccountBalance/index.ts'
46
50
  import { MemoryBlockRewardService } from '../../BlockReward/index.ts'
47
51
  import type { BasePendingTransactionsServiceParams } from '../../PendingTransactions/index.ts'
48
52
  import { BasePendingTransactionsService } from '../../PendingTransactions/index.ts'
@@ -95,9 +99,56 @@ describe('XyoBlockProducer', () => {
95
99
 
96
100
  stakeIntentService = mock<StakeIntentService>()
97
101
  stakeIntentService.getDeclaredCandidateRanges.mockResolvedValue([])
98
- time = mock<TimeSyncViewInterfaceV2>()
102
+ time = {
103
+ currentTimeAndHash(domain: TimeDomain): Promisable<[number, Hash | null]> {
104
+ switch (domain) {
105
+ case 'epoch': {
106
+ return [Date.now(), null]
107
+ }
108
+ case 'xl1': {
109
+ return [1, '00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff' as Hash]
110
+ }
111
+ case 'ethereum': {
112
+ return [1, '00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff' as Hash]
113
+ }
114
+ // No default
115
+ }
116
+ },
117
+ currentTime(domain: TimeDomain): Promisable<[string, number]> {
118
+ switch (domain) {
119
+ case 'epoch': {
120
+ return ['epoch', Date.now()]
121
+ }
122
+ case 'xl1': {
123
+ return ['xl1', 1]
124
+ }
125
+ case 'ethereum': {
126
+ return ['ethereum', 1]
127
+ }
128
+ // No default
129
+ }
130
+ },
131
+ currentTimePayload(): Promisable<TimePayload> {
132
+ return {
133
+ schema: TimeSchema, epoch: Date.now(), xl1: 1,
134
+ }
135
+ },
136
+ /** Convert time between different domains */
137
+ convertTime(fromDomain: TimeDomain, toDomain: TimeDomain, from: number): Promisable<number> {
138
+ if (fromDomain === toDomain) {
139
+ return from
140
+ }
141
+ if (fromDomain === 'epoch' && toDomain === 'xl1') {
142
+ return 1
143
+ }
144
+ if (fromDomain === 'xl1' && toDomain === 'epoch') {
145
+ return Date.now()
146
+ }
147
+ return from
148
+ },
149
+ }
99
150
  rewardService = await MemoryBlockRewardService.create()
100
- const balanceService = await accountBalanceServiceFromArchivist(chainArchivist)
151
+ const balanceService = await accountBalancesServiceFromArchivist(chainId, chainArchivist)
101
152
  const params: BaseBlockProducerServiceParams = {
102
153
  name: 'TestXyoBlockProducerParams' as CreatableName,
103
154
  account,
@@ -179,11 +230,11 @@ describe('XyoBlockProducer', () => {
179
230
  let rejectBlock = true
180
231
  const validateHydratedBlockState: HydratedBlockStateValidationFunctionV2 = async (
181
232
  hydratedBlock: HydratedBlock,
182
- chainId: Chain,
233
+ chainId: ChainId,
183
234
  ) => {
184
235
  return rejectBlock ? [await Promise.resolve(new HydratedBlockStateValidationError(ZERO_HASH, chainId, hydratedBlock, 'Invalid block'))] : []
185
236
  }
186
- const balanceService = await accountBalanceServiceFromArchivist(chainArchivist)
237
+ const balanceService = await accountBalancesServiceFromArchivist(chainId, chainArchivist)
187
238
  const params: BaseBlockProducerServiceParams = {
188
239
  name: 'TestXyoBlockProducerParams' as CreatableName,
189
240
  account,
@@ -234,11 +285,14 @@ describe('XyoBlockProducer', () => {
234
285
  const transfers = filterAs(assertEx(transactionsAndData), asTransfer)
235
286
  const blockRewardTransfer = transfers.find(transfer => transfer.from === XYO_ZERO_ADDRESS)
236
287
  expect(blockRewardTransfer).toBeDefined()
288
+ let totalTransfer = 0n
237
289
  for (const value of Object.values(blockRewardTransfer?.transfers ?? {})) {
238
290
  if (value) {
239
- expect(hexToBigInt(value)).toEqual(1_500_000_000_000_000_000_000n)
291
+ const bigIntValue = hexToBigInt(value)
292
+ totalTransfer += bigIntValue
240
293
  }
241
294
  }
295
+ expect(totalTransfer).toEqual(3_000_000_000_000_000_000_000n)
242
296
  }
243
297
  })
244
298
  })
@@ -3,15 +3,15 @@ import type { Hex } from '@xylabs/hex'
3
3
  import {
4
4
  isDefined, isNull, isUndefined,
5
5
  } from '@xylabs/typeof'
6
- import type { ArchivistInstance } from '@xyo-network/archivist-model'
7
6
  import { PayloadBuilder } from '@xyo-network/payload-builder'
8
- import type { WithStorageMeta } from '@xyo-network/payload-model'
7
+ import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
9
8
  import type {
10
9
  BlockBoundWitness, ChainIteratorServiceEventData, EventingChainBlockNumberIteratorService,
11
10
  } from '@xyo-network/xl1-protocol'
12
11
  import {
13
12
  asBlockBoundWitness, asBlockBoundWitnessWithStorageMeta, isBlockBoundWitnessWithHashStorageMeta,
14
13
  } from '@xyo-network/xl1-protocol'
14
+ import type { PayloadMapRead } from '@xyo-network/xl1-protocol-sdk'
15
15
  import { LRUCache } from 'lru-cache'
16
16
 
17
17
  import { BaseService } from '../BaseService.ts'
@@ -22,10 +22,10 @@ export class ChainBlockNumberIterationService extends BaseService<XyoChainIterat
22
22
  protected _blocksByBlockNumber = new LRUCache<number, WithStorageMeta<BlockBoundWitness>>({ max: 10_000 })
23
23
  protected _currentHead: WithStorageMeta<BlockBoundWitness> | undefined
24
24
 
25
- get chainArchivist(): ArchivistInstance { return assertEx(this.params.chainArchivist) }
26
-
27
25
  get chainId(): Hex { return assertEx(this._currentHead?.chain ?? this.params?.head?.chain, () => 'Current head is not set') }
28
26
 
27
+ get chainMap(): PayloadMapRead<WithStorageMeta<Payload>> { return assertEx(this.params.chainMap) }
28
+
29
29
  async get(block: number): Promise<WithStorageMeta<BlockBoundWitness>> {
30
30
  const head = await this.head()
31
31
  // if(isUndefined(head)) return undefined
@@ -36,7 +36,7 @@ export class ChainBlockNumberIterationService extends BaseService<XyoChainIterat
36
36
  // Start at the current head and traverse backwards until the requested block is found
37
37
  const startingBlock = head
38
38
  const currentBlockHash = await PayloadBuilder.hash(startingBlock)
39
- let currentBlock = (await this.chainArchivist.get([currentBlockHash])).at(0)
39
+ let currentBlock = (await this.chainMap.get(currentBlockHash))
40
40
  while (isDefined(currentBlock)) {
41
41
  assertEx(asBlockBoundWitness(currentBlock), () => `Expected hash to be a block bound witness [${currentBlock?._hash}]`)
42
42
  if (isBlockBoundWitnessWithHashStorageMeta(currentBlock)) {
@@ -46,7 +46,7 @@ export class ChainBlockNumberIterationService extends BaseService<XyoChainIterat
46
46
  }
47
47
  const { previous } = currentBlock
48
48
  if (isNull(previous)) break
49
- currentBlock = (await this.chainArchivist.get([previous])).at(0)
49
+ currentBlock = (await this.chainMap.get(previous))
50
50
  }
51
51
  }
52
52
  throw new Error(`Block not found: ${block}`)
@@ -73,13 +73,13 @@ export class ChainBlockNumberIterationService extends BaseService<XyoChainIterat
73
73
  async previous(block: number | undefined = undefined, count: number = 1): Promise<WithStorageMeta<BlockBoundWitness>[]> {
74
74
  const results: WithStorageMeta<BlockBoundWitness>[] = []
75
75
  let currentBlock: WithStorageMeta<BlockBoundWitness> | undefined = isDefined(block) ? (await this.get(block)) : await this.head()
76
- while (currentBlock && results.length < count) {
76
+ while (isDefined(currentBlock) && (results.length < count)) {
77
77
  if (isBlockBoundWitnessWithHashStorageMeta(currentBlock)) {
78
78
  results.push(currentBlock)
79
- const { previous } = currentBlock
79
+ const { previous } = currentBlock as BlockBoundWitness
80
80
  if (isNull(previous)) break
81
- const nextBlock = await this.chainArchivist.get([previous])
82
- currentBlock = asBlockBoundWitnessWithStorageMeta(nextBlock[0])
81
+ const nextBlock = await this.chainMap.get(previous)
82
+ currentBlock = asBlockBoundWitnessWithStorageMeta(nextBlock)
83
83
  } else {
84
84
  const hash = PayloadBuilder.hash(currentBlock)
85
85
  assertEx(asBlockBoundWitnessWithStorageMeta(currentBlock), () => `Expected hash to be a block bound witness [${hash}]`)
@@ -96,7 +96,7 @@ export class ChainBlockNumberIterationService extends BaseService<XyoChainIterat
96
96
 
97
97
  private async getBoundWitnessAsBlockBoundWitnessWithStorageMeta(head: BlockBoundWitness): Promise<WithStorageMeta<BlockBoundWitness>> {
98
98
  const hash = await PayloadBuilder.hash(head)
99
- const stored = (await this.chainArchivist.get([hash])).at(-1)
99
+ const stored = (await this.chainMap.get(hash))
100
100
  const newHead = asBlockBoundWitnessWithStorageMeta(stored)
101
101
  if (isUndefined(newHead)) throw new Error(`Head block not found in archivist [${hash}]`)
102
102
  return newHead
@@ -1,9 +1,10 @@
1
- import type { ArchivistInstance } from '@xyo-network/archivist-model'
1
+ import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
2
2
  import type { BlockBoundWitness } from '@xyo-network/xl1-protocol'
3
+ import type { PayloadMapRead } from '@xyo-network/xl1-protocol-sdk'
3
4
 
4
5
  import type { BaseServiceParams } from '../../model/index.ts'
5
6
 
6
7
  export interface XyoChainIteratorParams extends BaseServiceParams {
7
- chainArchivist: ArchivistInstance
8
+ chainMap: PayloadMapRead<WithStorageMeta<Payload>>
8
9
  head: BlockBoundWitness
9
10
  }
@@ -6,7 +6,7 @@ import { ArchivistInstance, ReadArchivist } from '@xyo-network/archivist-model'
6
6
  import {
7
7
  BlockBoundWitness,
8
8
  BlockRewardService,
9
- Chain,
9
+ ChainId,
10
10
  ElectionService,
11
11
  HydratedBlockStateValidationFunctionV2,
12
12
  SignedHydratedTransactionWithStorageMeta,
@@ -20,7 +20,7 @@ import { Validator } from './model/index.ts'
20
20
  export interface XyoValidatorParams extends BaseServiceParams {
21
21
  account: AccountInstance
22
22
  chainArchivist: ReadArchivist
23
- chainId: Chain
23
+ chainId: ChainId
24
24
  electionService: ElectionService
25
25
  pendingBundledTransactionsArchivist: ArchivistInstance
26
26
  rewardService: BlockRewardService
@@ -2,7 +2,9 @@ import { creatable } from '@xylabs/creatable'
2
2
  import { Address } from '@xylabs/hex'
3
3
  import { Promisable } from '@xylabs/promise'
4
4
  import { ReadArchivist } from '@xyo-network/archivist-model'
5
- import { EventingChainBlockNumberIteratorService, NetworkStakeStepRewardService } from '@xyo-network/xl1-protocol'
5
+ import {
6
+ EventingChainBlockNumberIteratorService, NetworkStakeStepRewardService, StepContext,
7
+ } from '@xyo-network/xl1-protocol'
6
8
  import { Provider } from 'ethers'
7
9
 
8
10
  import { BaseService } from '../BaseService.ts'
@@ -16,55 +18,59 @@ export interface BaseNetworkStakeStepRewardServiceParams extends BaseServicePara
16
18
 
17
19
  @creatable()
18
20
  export class BaseNetworkStakeStepRewardService extends BaseService<BaseNetworkStakeStepRewardServiceParams> implements NetworkStakeStepRewardService {
19
- claimedRewards(_address: Address): Promisable<bigint> {
21
+ networkStakeStepRewardAddressHistory(_address: Address): Promisable<Record<Address, bigint>> {
20
22
  throw new Error('Method not implemented.')
21
23
  }
22
24
 
23
- networkStakeStepAddressReward(_address: Address, _step: number, _block: number): Promisable<Record<Address, bigint>> {
25
+ networkStakeStepRewardAddressReward(_context: StepContext, _address: Address): Promisable<Record<Address, bigint>> {
24
26
  throw new Error('Method not implemented.')
25
27
  }
26
28
 
27
- networkStakeStepPoolRewardShares(_step: number, _block: number): Promisable<Record<Address, bigint>> {
29
+ networkStakeStepRewardAddressShare(_context: StepContext, _address: Address): Promisable<[bigint, bigint]> {
28
30
  throw new Error('Method not implemented.')
29
31
  }
30
32
 
31
- networkStakeStepPoolRewards(_step: number, _block: number): Promisable<Record<Address, bigint>> {
33
+ networkStakeStepRewardClaimedByAddress(_address: Address): Promisable<bigint> {
32
34
  throw new Error('Method not implemented.')
33
35
  }
34
36
 
35
- networkStakeStepRewardAddressHistory(_address: Address): Promisable<Record<Address, bigint>> {
37
+ networkStakeStepRewardForStep(_context: StepContext): Promisable<bigint> {
38
+ throw new Error('Method not implemented.')
39
+ }
40
+
41
+ networkStakeStepRewardForStepForPosition(_context: StepContext, _position: number): Promisable<[bigint, bigint]> {
36
42
  throw new Error('Method not implemented.')
37
43
  }
38
44
 
39
- networkStakeStepRewardAddressShare(_address: Address, _step: number, _block: number): Promisable<[bigint, bigint]> {
45
+ networkStakeStepRewardPoolRewards(_context: StepContext): Promisable<Record<Address, bigint>> {
40
46
  throw new Error('Method not implemented.')
41
47
  }
42
48
 
43
- networkStakeStepRewardForStep(_step: number): Promisable<bigint> {
49
+ networkStakeStepRewardPoolShares(_context: StepContext): Promisable<Record<Address, bigint>> {
44
50
  throw new Error('Method not implemented.')
45
51
  }
46
52
 
47
- networkStakeStepRewardPositionWeight(_position: bigint, _step: number): Promisable<number> {
53
+ networkStakeStepRewardPositionWeight(_context: StepContext, _position: number): Promisable<bigint> {
48
54
  throw new Error('Method not implemented.')
49
55
  }
50
56
 
51
- networkStakeStepRewardPotentialPositionLoss(_position: bigint, _step: number): Promisable<bigint> {
57
+ networkStakeStepRewardPotentialPositionLoss(_context: StepContext, _position: number): Promisable<bigint> {
52
58
  throw new Error('Method not implemented.')
53
59
  }
54
60
 
55
- networkStakeStepRewardRandomizer(_step: number, _block: number): Promisable<bigint> {
61
+ networkStakeStepRewardRandomizer(_context: StepContext): Promisable<bigint> {
56
62
  throw new Error('Method not implemented.')
57
63
  }
58
64
 
59
- networkStakeStepRewardStakerCount(_step: number, _block: number): Promisable<number> {
65
+ networkStakeStepRewardStakerCount(_context: StepContext): Promisable<number> {
60
66
  throw new Error('Method not implemented.')
61
67
  }
62
68
 
63
- networkStakeStepRewardWeightForAddress(_address: Address, _step: number): Promisable<bigint> {
69
+ networkStakeStepRewardUnclaimedByAddress(_address: Address): Promisable<bigint> {
64
70
  throw new Error('Method not implemented.')
65
71
  }
66
72
 
67
- unclaimedRewards(_address: Address): Promisable<bigint> {
73
+ networkStakeStepRewardWeightForAddress(_context: StepContext, _address: Address): Promisable<bigint> {
68
74
  throw new Error('Method not implemented.')
69
75
  }
70
76
  }