@xyo-network/chain-services 1.16.23 → 1.16.24
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.
- package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts +10 -3
- package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts.map +1 -1
- package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts +9 -0
- package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts.map +1 -1
- package/dist/neutral/index.mjs +114 -78
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +11 -10
- package/src/AccountBalance/BaseAccountBalanceService.ts +30 -13
- package/src/BlockProducer/BaseBlockProducerService.ts +16 -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.16.
|
|
4
|
+
"version": "1.16.24",
|
|
5
5
|
"description": "XYO Layer One SDK Services",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -48,20 +48,21 @@
|
|
|
48
48
|
"@xyo-network/boundwitness-model": "~5.1.24",
|
|
49
49
|
"@xyo-network/boundwitness-validator": "~5.1.24",
|
|
50
50
|
"@xyo-network/boundwitness-wrapper": "~5.1.24",
|
|
51
|
-
"@xyo-network/chain-analyze": "~1.16.
|
|
52
|
-
"@xyo-network/chain-modules": "~1.16.
|
|
53
|
-
"@xyo-network/chain-protocol": "~1.16.
|
|
54
|
-
"@xyo-network/chain-utils": "~1.16.
|
|
51
|
+
"@xyo-network/chain-analyze": "~1.16.24",
|
|
52
|
+
"@xyo-network/chain-modules": "~1.16.24",
|
|
53
|
+
"@xyo-network/chain-protocol": "~1.16.24",
|
|
54
|
+
"@xyo-network/chain-utils": "~1.16.24",
|
|
55
55
|
"@xyo-network/payload-builder": "~5.1.24",
|
|
56
56
|
"@xyo-network/payload-model": "~5.1.24",
|
|
57
57
|
"@xyo-network/typechain": "~4.0.10",
|
|
58
58
|
"@xyo-network/xl1-protocol": "~1.13.13",
|
|
59
|
-
"@xyo-network/xl1-protocol-sdk": "~1.16.
|
|
60
|
-
"@xyo-network/xl1-validation": "~1.16.
|
|
61
|
-
"@xyo-network/xl1-wrappers": "~1.16.
|
|
59
|
+
"@xyo-network/xl1-protocol-sdk": "~1.16.24",
|
|
60
|
+
"@xyo-network/xl1-validation": "~1.16.24",
|
|
61
|
+
"@xyo-network/xl1-wrappers": "~1.16.24",
|
|
62
62
|
"async-mutex": "~0.5.0",
|
|
63
63
|
"ethers": "6.15.0",
|
|
64
|
-
"lru-cache": "~11.2.2"
|
|
64
|
+
"lru-cache": "~11.2.2",
|
|
65
|
+
"zod": "~4.1.12"
|
|
65
66
|
},
|
|
66
67
|
"devDependencies": {
|
|
67
68
|
"@types/node": "~24.10.1",
|
|
@@ -71,7 +72,7 @@
|
|
|
71
72
|
"@xylabs/vitest-extended": "~5.0.39",
|
|
72
73
|
"@xyo-network/account": "~5.1.24",
|
|
73
74
|
"@xyo-network/account-model": "~5.1.24",
|
|
74
|
-
"@xyo-network/chain-validation": "~1.16.
|
|
75
|
+
"@xyo-network/chain-validation": "~1.16.24",
|
|
75
76
|
"@xyo-network/wallet": "~5.1.24",
|
|
76
77
|
"eslint": "^9.39.1",
|
|
77
78
|
"tslib": "~2.8.1",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Address, creatable, Hash,
|
|
3
|
-
Promisable,
|
|
2
|
+
Address, assertEx, creatable, Hash,
|
|
4
3
|
} from '@xylabs/sdk-js'
|
|
5
4
|
import { spanRootAsync } from '@xylabs/telemetry'
|
|
6
5
|
import { ReadArchivist } from '@xyo-network/archivist-model'
|
|
@@ -15,11 +14,19 @@ import {
|
|
|
15
14
|
SimpleAccountBalanceViewer,
|
|
16
15
|
TransfersStepSummaryContext,
|
|
17
16
|
} from '@xyo-network/xl1-protocol-sdk'
|
|
17
|
+
import z from 'zod'
|
|
18
18
|
|
|
19
19
|
import { BaseService } from '../BaseService.ts'
|
|
20
20
|
import { blockViewerFromChainIteratorAndArchivist } from '../blockViewerFromChainIteratorAndArchivist.ts'
|
|
21
21
|
import { BaseServiceParams } from '../model/index.ts'
|
|
22
22
|
|
|
23
|
+
export const BaseAccountBalanceServiceParamsZod = z.object({
|
|
24
|
+
chainArchivist: z.object().loose(),
|
|
25
|
+
chainIterator: z.object().loose(),
|
|
26
|
+
context: z.object().loose(),
|
|
27
|
+
transferContext: z.object().loose(),
|
|
28
|
+
})
|
|
29
|
+
|
|
23
30
|
export interface BaseAccountBalanceServiceParams extends BaseServiceParams {
|
|
24
31
|
chainArchivist: ReadArchivist
|
|
25
32
|
chainIterator: EventingChainBlockNumberIteratorService
|
|
@@ -32,22 +39,36 @@ export class BaseAccountBalanceService extends BaseService<BaseAccountBalanceSer
|
|
|
32
39
|
protected accountBalanceViewer!: AccountBalanceViewer
|
|
33
40
|
protected blockViewer!: BlockViewer
|
|
34
41
|
|
|
42
|
+
static override async paramsHandler(params?: Partial<BaseAccountBalanceServiceParams> | undefined): Promise<BaseAccountBalanceServiceParams> {
|
|
43
|
+
// TODO: Use a real zod and move the zod check to the AbstractCreatable class
|
|
44
|
+
BaseAccountBalanceServiceParamsZod.parse(params)
|
|
45
|
+
assertEx(params?.context?.head, () => 'BalanceStepSummaryContext is required in BaseAccountBalanceServiceParams')
|
|
46
|
+
return { ...(await super.paramsHandler(params)), ...params } as BaseAccountBalanceServiceParams
|
|
47
|
+
}
|
|
48
|
+
|
|
35
49
|
async accountBalance(address: Address, headOrRange?: XL1BlockRange | Hash): Promise<AttoXL1> {
|
|
36
|
-
const balances = await this.
|
|
50
|
+
const balances = await this.accountsBalances([address], headOrRange)
|
|
37
51
|
return balances[address] ?? AttoXL1(0n)
|
|
38
52
|
}
|
|
39
53
|
|
|
40
54
|
async accountBalanceHistory(address: Address): Promise<AccountBalanceHistoryItem[]>
|
|
41
55
|
async accountBalanceHistory(address: Address, head: Hash): Promise<AccountBalanceHistoryItem[]>
|
|
42
56
|
async accountBalanceHistory(address: Address, range: XL1BlockRange): Promise<AccountBalanceHistoryItem[]>
|
|
43
|
-
|
|
44
|
-
|
|
57
|
+
accountBalanceHistory(_address: Address, _headOrRange?: Hash | XL1BlockRange): Promise<AccountBalanceHistoryItem[]> {
|
|
58
|
+
throw new Error('Method not implemented.')
|
|
45
59
|
}
|
|
46
60
|
|
|
47
|
-
async
|
|
61
|
+
async accountsBalances(address: Address[], _headOrRange?: Hash | XL1BlockRange): Promise<Partial<Record<Address, AttoXL1>>> {
|
|
48
62
|
return await spanRootAsync('balances', async () => {
|
|
63
|
+
const context = {
|
|
64
|
+
head: this.params.context.head,
|
|
65
|
+
stepSemaphores: this.params.context.stepSemaphores,
|
|
66
|
+
store: this.params.context.store,
|
|
67
|
+
chainId: this.params.context.chainId,
|
|
68
|
+
summaryMap: this.params.context.summaryMap,
|
|
69
|
+
} satisfies BalanceStepSummaryContext
|
|
49
70
|
const summary = await balancesSummary(
|
|
50
|
-
|
|
71
|
+
context,
|
|
51
72
|
)
|
|
52
73
|
const result: Record<Address, AttoXL1> = {}
|
|
53
74
|
for (const addr of address) {
|
|
@@ -58,15 +79,11 @@ export class BaseAccountBalanceService extends BaseService<BaseAccountBalanceSer
|
|
|
58
79
|
})
|
|
59
80
|
}
|
|
60
81
|
|
|
61
|
-
accountsBalances(address: Address[], headOrRange?: Hash | XL1BlockRange): Promisable<Partial<Record<Address, AttoXL1>>> {
|
|
62
|
-
throw new Error('Method not implemented.')
|
|
63
|
-
}
|
|
64
|
-
|
|
65
82
|
async accountsBalancesHistory(addresses: Address[]): Promise<Partial<Record<Address, AccountBalanceHistoryItem[]>>>
|
|
66
83
|
async accountsBalancesHistory(addresses: Address[], head: Hash): Promise<Partial<Record<Address, AccountBalanceHistoryItem[]>>>
|
|
67
84
|
async accountsBalancesHistory(addresses: Address[], range: XL1BlockRange): Promise<Partial<Record<Address, AccountBalanceHistoryItem[]>>>
|
|
68
|
-
|
|
69
|
-
|
|
85
|
+
accountsBalancesHistory(_addresses: Address[], _headOrRange?: Hash | XL1BlockRange): Promise<Partial<Record<Address, AccountBalanceHistoryItem[]>>> {
|
|
86
|
+
throw new Error('Method not implemented.')
|
|
70
87
|
}
|
|
71
88
|
|
|
72
89
|
override createHandler() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable max-statements */
|
|
2
2
|
import {
|
|
3
|
-
Address, asHash, assertEx, creatable,
|
|
3
|
+
Address, AddressZod, asHash, assertEx, creatable,
|
|
4
4
|
exists,
|
|
5
5
|
Hex,
|
|
6
6
|
hexToBigInt,
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
import {
|
|
24
24
|
AccountBalanceViewer, BlockProducerService, Config, PendingTransactionsService, StakeIntentService, TimeSyncViewer,
|
|
25
25
|
} from '@xyo-network/xl1-protocol-sdk'
|
|
26
|
+
import z from 'zod'
|
|
26
27
|
|
|
27
28
|
import { BaseService } from '../BaseService.ts'
|
|
28
29
|
import { XyoValidatorParams } from '../ChainValidator/index.ts'
|
|
@@ -44,6 +45,14 @@ export const XYO_PRODUCER_REDECLARATION_DURATION = 10_000
|
|
|
44
45
|
*/
|
|
45
46
|
export const XYO_PRODUCER_REDECLARATION_WINDOW = 500
|
|
46
47
|
|
|
48
|
+
export const BaseBlockProducerServiceParamsZod = z.object({
|
|
49
|
+
balanceService: z.object().loose(),
|
|
50
|
+
pendingTransactionsService: z.object().loose(),
|
|
51
|
+
rejectedTransactionsArchivist: z.object().loose(),
|
|
52
|
+
rewardAddress: AddressZod,
|
|
53
|
+
time: z.object().loose(),
|
|
54
|
+
})
|
|
55
|
+
|
|
47
56
|
export interface BaseBlockProducerServiceParams extends XyoValidatorParams<Pick<Config, 'producer'>> {
|
|
48
57
|
balanceService: AccountBalanceViewer
|
|
49
58
|
pendingTransactionsService: PendingTransactionsService
|
|
@@ -131,6 +140,12 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
|
|
|
131
140
|
return assertEx(this.params.validateHydratedBlockState, () => 'validateHydratedBlockState is required')
|
|
132
141
|
}
|
|
133
142
|
|
|
143
|
+
static override async paramsHandler(params?: Partial<BaseBlockProducerServiceParams> | undefined): Promise<BaseBlockProducerServiceParams> {
|
|
144
|
+
// TODO: Use a real zod and move the zod check to the AbstractCreatable class
|
|
145
|
+
BaseBlockProducerServiceParamsZod.parse(params)
|
|
146
|
+
return { ...(await super.paramsHandler(params)), ...params } as BaseBlockProducerServiceParams
|
|
147
|
+
}
|
|
148
|
+
|
|
134
149
|
async next(head: WithStorageMeta<BlockBoundWitness>): Promise<HydratedBlock | undefined> {
|
|
135
150
|
// If the block is for another chain, ignore
|
|
136
151
|
if (head.chain !== this.chainId) return
|