@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,25 +1,25 @@
1
1
  import type { Address } from '@xylabs/hex';
2
2
  import type { StakedXyoChain } from '@xyo-network/typechain';
3
- import type { BaseServiceParams, ChainService } from '@xyo-network/xl1-protocol';
3
+ import type { ChainService } from '@xyo-network/xl1-protocol';
4
4
  import type { ContractRunner } from 'ethers/providers';
5
5
  import { BaseService } from '../../BaseService.ts';
6
- export type EvmChainServiceParams = BaseServiceParams<{
6
+ import type { BaseServiceParams } from '../../Params.ts';
7
+ export interface EvmChainServiceParams extends BaseServiceParams {
7
8
  contract: StakedXyoChain;
8
9
  id: Address;
9
10
  runner: ContractRunner;
10
- }>;
11
+ }
11
12
  /**
12
13
  * A class that represents a chain stake as backed by an EVM smart contract
13
14
  */
14
15
  export declare class EvmChainService extends BaseService<EvmChainServiceParams> implements ChainService {
16
+ get chainId(): Address;
15
17
  get contract(): StakedXyoChain;
16
- get id(): Address;
17
18
  get runner(): ContractRunner;
18
19
  active(): Promise<bigint>;
19
20
  activeByAddressStaked(address: string): Promise<bigint>;
20
21
  activeByStaker(address: string): Promise<bigint>;
21
22
  addStake(staked: string, amount: bigint): Promise<boolean>;
22
- chainId(): Promise<Address>;
23
23
  forkedAtBlockNumber(): Promise<bigint>;
24
24
  forkedAtHash(): Promise<bigint>;
25
25
  forkedChainId(): Promise<Address>;
@@ -1 +1 @@
1
- {"version":3,"file":"Evm.d.ts","sourceRoot":"","sources":["../../../../src/Staker/Ev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OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIhD,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAM1D,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAI/B,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC;IAIjC,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAI1B,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIhD,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAM3C,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IAIlC,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAM7C,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAI5B,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAGzD"}
@@ -0,0 +1,31 @@
1
+ import type { Address } from '@xylabs/hex';
2
+ import type { ChainService } from '@xyo-network/xl1-protocol';
3
+ import { BaseService } from '../../BaseService.ts';
4
+ import type { BaseServiceParams } from '../../Params.ts';
5
+ export interface MemoryChainServiceParams extends BaseServiceParams {
6
+ }
7
+ /**
8
+ * A class that represents a chain stake as backed in memory
9
+ */
10
+ export declare class MemoryChainService extends BaseService<MemoryChainServiceParams> implements ChainService {
11
+ protected _simulatedStake: bigint;
12
+ get chainId(): Address;
13
+ active(): Promise<bigint>;
14
+ activeByAddressStaked(_address: string): Promise<bigint>;
15
+ activeByStaker(_address: string): Promise<bigint>;
16
+ addStake(_staked: string, _amount: bigint): Promise<boolean>;
17
+ createHandler(): void;
18
+ forkedAtBlockNumber(): Promise<bigint>;
19
+ forkedAtHash(): Promise<bigint>;
20
+ forkedChainId(): Promise<Address>;
21
+ minWithdrawalBlocks(): Promise<bigint>;
22
+ pending(): Promise<bigint>;
23
+ pendingByStaker(_staker: string): Promise<bigint>;
24
+ removeStake(_slot: bigint): Promise<boolean>;
25
+ rewardsContract(): Promise<string>;
26
+ stakingTokenAddress(): Promise<string>;
27
+ withdrawStake(_slot: bigint): Promise<boolean>;
28
+ withdrawn(): Promise<bigint>;
29
+ withdrawnByStaker(_staker: string): Promise<bigint>;
30
+ }
31
+ //# sourceMappingURL=Memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Memory.d.ts","sourceRoot":"","sources":["../../../../src/Staker/Memory/Memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAG1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAExD,MAAM,WAAW,wBAAyB,SAAQ,iBAAiB;CAAG;AAEtE;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,WAAW,CAAC,wBAAwB,CAAE,YAAW,YAAY;IACnG,SAAS,CAAC,eAAe,EAAE,MAAM,CAAK;IAEtC,IAAI,OAAO,IAAI,OAAO,CAErB;IAEK,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IAIzB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIxD,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIjD,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIzD,aAAa,IAAI,IAAI;IAMxB,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAI/B,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC;IAIjC,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAI1B,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIjD,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI5C,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IAIlC,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI9C,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAI5B,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAG1D"}
@@ -0,0 +1,2 @@
1
+ export * from './Memory.ts';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Staker/Memory/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
@@ -1,2 +1,3 @@
1
1
  export * from './Evm/index.ts';
2
+ export * from './Memory/index.ts';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Staker/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Staker/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA"}
@@ -5,6 +5,7 @@ export * from './BlockReward/index.ts';
5
5
  export * from './ChainBlockNumberIteration/index.ts';
6
6
  export * from './ChainValidator/index.ts';
7
7
  export * from './Election/index.ts';
8
+ export * from './Params.ts';
8
9
  export * from './PendingTransactions/index.ts';
9
10
  export * from './StakeIntent/index.ts';
10
11
  export * from './Staker/index.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,kBAAkB,CAAA;AAChC,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,sCAAsC,CAAA;AACpD,cAAc,2BAA2B,CAAA;AACzC,cAAc,qBAAqB,CAAA;AACnC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,wBAAwB,CAAA;AACtC,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,kBAAkB,CAAA;AAChC,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,sCAAsC,CAAA;AACpD,cAAc,2BAA2B,CAAA;AACzC,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,gCAAgC,CAAA;AAC9C,cAAc,wBAAwB,CAAA;AACtC,cAAc,mBAAmB,CAAA"}
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.5.35",
4
+ "version": "1.5.36",
5
5
  "description": "XYO Layer One SDK Services",
6
6
  "homepage": "https://xylabs.com",
7
7
  "bugs": {
@@ -35,55 +35,56 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@opentelemetry/api": "^1.9.0",
38
- "@xylabs/array": "^4.11.21",
39
- "@xylabs/assert": "^4.11.21",
40
- "@xylabs/base": "^4.11.21",
41
- "@xylabs/decimal-precision": "^4.11.21",
42
- "@xylabs/events": "^4.11.21",
43
- "@xylabs/exists": "^4.11.21",
44
- "@xylabs/forget": "^4.11.21",
45
- "@xylabs/hex": "^4.11.21",
46
- "@xylabs/promise": "^4.11.21",
47
- "@xylabs/telemetry": "^4.11.21",
48
- "@xylabs/typeof": "^4.11.21",
49
- "@xyo-network/account-model": "^3.18.8",
50
- "@xyo-network/archivist-memory": "^3.18.8",
51
- "@xyo-network/archivist-model": "^3.18.8",
52
- "@xyo-network/boundwitness-model": "^3.18.8",
53
- "@xyo-network/boundwitness-validator": "^3.18.8",
54
- "@xyo-network/boundwitness-wrapper": "^3.18.8",
55
- "@xyo-network/chain-analyze": "^1.5.35",
56
- "@xyo-network/chain-ethereum": "^1.5.35",
57
- "@xyo-network/chain-modules": "^1.5.35",
58
- "@xyo-network/chain-protocol": "^1.5.35",
59
- "@xyo-network/chain-telemetry": "^1.5.35",
60
- "@xyo-network/chain-utils": "^1.5.35",
61
- "@xyo-network/chain-validation": "^1.5.35",
62
- "@xyo-network/chain-wrappers": "^1.5.35",
63
- "@xyo-network/payload-builder": "^3.18.8",
64
- "@xyo-network/payload-model": "^3.18.8",
38
+ "@xylabs/array": "^4.12.29",
39
+ "@xylabs/assert": "^4.12.29",
40
+ "@xylabs/creatable": "^4.12.29",
41
+ "@xylabs/decimal-precision": "^4.12.29",
42
+ "@xylabs/events": "^4.12.29",
43
+ "@xylabs/exists": "^4.12.29",
44
+ "@xylabs/forget": "^4.12.29",
45
+ "@xylabs/hex": "^4.12.29",
46
+ "@xylabs/object": "^4.12.29",
47
+ "@xylabs/promise": "^4.12.29",
48
+ "@xylabs/telemetry": "^4.12.29",
49
+ "@xylabs/typeof": "^4.12.29",
50
+ "@xyo-network/account-model": "^3.18.10",
51
+ "@xyo-network/archivist-memory": "^3.18.10",
52
+ "@xyo-network/archivist-model": "^3.18.10",
53
+ "@xyo-network/boundwitness-model": "^3.18.10",
54
+ "@xyo-network/boundwitness-validator": "^3.18.10",
55
+ "@xyo-network/boundwitness-wrapper": "^3.18.10",
56
+ "@xyo-network/chain-analyze": "^1.5.36",
57
+ "@xyo-network/chain-ethereum": "^1.5.36",
58
+ "@xyo-network/chain-modules": "^1.5.36",
59
+ "@xyo-network/chain-protocol": "^1.5.36",
60
+ "@xyo-network/chain-telemetry": "^1.5.36",
61
+ "@xyo-network/chain-utils": "^1.5.36",
62
+ "@xyo-network/chain-validation": "^1.5.36",
63
+ "@xyo-network/chain-wrappers": "^1.5.36",
64
+ "@xyo-network/payload-builder": "^3.18.10",
65
+ "@xyo-network/payload-model": "^3.18.10",
65
66
  "@xyo-network/typechain": "^3.5.4",
66
- "@xyo-network/xl1-protocol": "^1.4.36",
67
- "@xyo-network/xl1-protocol-sdk": "^1.5.35",
67
+ "@xyo-network/xl1-protocol": "^1.5.16",
68
+ "@xyo-network/xl1-protocol-sdk": "^1.5.36",
68
69
  "async-mutex": "^0.5.0",
69
70
  "ethers": "6.14.4",
70
- "lru-cache": "^11.1.0",
71
- "web3-types": "^1.10.0"
71
+ "lru-cache": "^11.1.0"
72
72
  },
73
73
  "devDependencies": {
74
- "@types/node": "^24.0.1",
75
- "@xylabs/delay": "^4.11.21",
76
- "@xylabs/ts-scripts-yarn3": "^6.5.8",
77
- "@xylabs/tsconfig": "^6.5.8",
78
- "@xylabs/vitest-extended": "^4.11.21",
79
- "@xyo-network/account": "^3.18.8",
80
- "@xyo-network/account-model": "^3.18.8",
81
- "@xyo-network/chain-validation": "^1.5.35",
82
- "@xyo-network/wallet": "^3.18.8",
83
- "knip": "^5.61.0",
74
+ "@types/node": "^24.0.8",
75
+ "@xylabs/delay": "^4.12.29",
76
+ "@xylabs/ts-scripts-yarn3": "^6.5.12",
77
+ "@xylabs/tsconfig": "^6.5.12",
78
+ "@xylabs/vitest-extended": "^4.12.29",
79
+ "@xyo-network/account": "^3.18.10",
80
+ "@xyo-network/account-model": "^3.18.10",
81
+ "@xyo-network/chain-validation": "^1.5.36",
82
+ "@xyo-network/wallet": "^3.18.10",
83
+ "knip": "^5.61.3",
84
84
  "typescript": "^5.8.3",
85
- "vitest": "^3.2.3",
86
- "vitest-mock-extended": "^3.1.0"
85
+ "vitest": "^3.2.4",
86
+ "vitest-mock-extended": "^3.1.0",
87
+ "web3-types": "^1.10.0"
87
88
  },
88
89
  "engines": {
89
90
  "node": ">=22.3 <23"
@@ -0,0 +1,33 @@
1
+ import { creatable } from '@xylabs/creatable'
2
+ import { Address, Hash } from '@xylabs/hex'
3
+ import { ReadArchivist } from '@xyo-network/archivist-model'
4
+ import {
5
+ AccountBalanceServiceV2,
6
+ AttoXL1, PayloadRepository,
7
+ } from '@xyo-network/xl1-protocol'
8
+ import {
9
+ BalancesStepSummary,
10
+ balanceSummary,
11
+ } from '@xyo-network/xl1-protocol-sdk'
12
+
13
+ import { BaseService } from '../BaseService.ts'
14
+ import { BaseServiceParams } from '../Params.ts'
15
+
16
+ export interface ChainAccountBalanceServiceParamsV2 extends BaseServiceParams {
17
+ chainArchivist: ReadArchivist
18
+ summaryRepository: PayloadRepository<Hash, BalancesStepSummary>
19
+ }
20
+
21
+ @creatable()
22
+ export class ChainAccountBalanceServiceV2 extends BaseService<ChainAccountBalanceServiceParamsV2> implements AccountBalanceServiceV2 {
23
+ async balances(head: Hash, address: Address[]): Promise<Partial<Record<Address, AttoXL1>>> {
24
+ const summary = await balanceSummary({
25
+ chainArchivist: this.params.chainArchivist, summaryRepository: this.params.summaryRepository, head,
26
+ })
27
+ const result: Record<Address, AttoXL1> = {}
28
+ for (const addr of address) {
29
+ result[addr] = AttoXL1(summary[addr] ?? 0n)
30
+ }
31
+ return result
32
+ }
33
+ }
@@ -1,24 +1,23 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
- import {
3
- Address, Hash, Hex,
4
- toHex,
5
- } from '@xylabs/hex'
2
+ import { creatable } from '@xylabs/creatable'
3
+ import { Address, Hash } from '@xylabs/hex'
4
+ import { isDefined } from '@xylabs/typeof'
6
5
  import {
7
6
  analyzeChain, BalanceAnalyzer, ChainSummaryBalances, ChainSummaryBalancesSchema, isChainSummaryBalances,
8
7
  } from '@xyo-network/chain-analyze'
9
- import { SignedBigInt, toPositiveBigInt } from '@xyo-network/chain-protocol'
10
8
  import { PayloadBuilder } from '@xyo-network/payload-builder'
11
9
  import {
12
- AccountBalanceService, BaseServiceParams,
13
- ChainServiceCollection,
10
+ AccountBalanceServiceV2, AttoXL1, ChainServiceCollection,
14
11
  } from '@xyo-network/xl1-protocol'
12
+ import { parseSignedBigInt, SignedBigInt } from '@xyo-network/xl1-protocol-sdk'
15
13
 
16
- import { BaseService, creatableService } from '../BaseService.ts'
14
+ import { BaseService } from '../BaseService.ts'
15
+ import { BaseServiceParams } from '../Params.ts'
17
16
 
18
- export type ChainAccountBalanceServiceParams = BaseServiceParams<Partial<Pick<ChainServiceCollection, 'chainArchivist'>>>
17
+ export interface ChainAccountBalanceServiceParams extends BaseServiceParams, Partial<Pick<ChainServiceCollection, 'chainArchivist'>> { head?: Hash }
19
18
 
20
- @creatableService()
21
- export class XyoChainAccountBalanceService extends BaseService<ChainAccountBalanceServiceParams> implements AccountBalanceService {
19
+ @creatable()
20
+ export class XyoChainAccountBalanceService extends BaseService<ChainAccountBalanceServiceParams> implements AccountBalanceServiceV2 {
22
21
  private _balances: Partial<Record<Address, SignedBigInt>> = {}
23
22
  /**
24
23
  * The most recent head that was indexed to
@@ -34,17 +33,22 @@ export class XyoChainAccountBalanceService extends BaseService<ChainAccountBalan
34
33
  return assertEx(this.params.chainArchivist, () => 'chainArchivist is required')
35
34
  }
36
35
 
37
- getBalance(address: Address): Hex {
38
- return toPositiveBigInt(this._balances[address] ?? { positive: toHex(0n) }).positive
36
+ balances(head: Hash, address: Address[]): Partial<Record<Address, AttoXL1>> {
37
+ const result: Record<Address, AttoXL1> = {}
38
+ for (const addr of address) {
39
+ const balance = this._balances[addr]
40
+ const signedBalance = balance ? parseSignedBigInt(balance) : 0n
41
+ result[addr] = AttoXL1(signedBalance >= 0n ? signedBalance : 0n)
42
+ }
43
+ return result
39
44
  }
40
45
 
41
- getBalances(): Record<Address, Hex> {
42
- const result: Record<Address, Hex> = {}
43
- const entries = Object.entries(this._balances) as [Address, SignedBigInt][]
44
- for (const [address, balance] of entries) {
45
- result[address] = toPositiveBigInt(balance).positive
46
+ override async startHandler() {
47
+ // If we were passed in a head
48
+ if (isDefined(this.params.head)) {
49
+ // Sync from that
50
+ await this.sync(this.params.head)
46
51
  }
47
- return result
48
52
  }
49
53
 
50
54
  async sync(head: Hash): Promise<void> {
@@ -1,58 +1,90 @@
1
+ import { exists } from '@xylabs/exists'
1
2
  import {
2
- type Address, type Hash, type Hex,
3
+ type Address, asHash, type Hash,
3
4
  isHash,
4
5
  } from '@xylabs/hex'
5
- import { isDefined } from '@xylabs/typeof'
6
6
  import type { ArchivistInstance } from '@xyo-network/archivist-model'
7
7
  import type { ChainSummaryBalances } from '@xyo-network/chain-analyze'
8
8
  import {
9
9
  analyzeChain, BalanceAnalyzer, ChainSummaryBalancesSchema, isChainSummaryBalances,
10
10
  } from '@xyo-network/chain-analyze'
11
- import { isPositiveBigInt } from '@xyo-network/chain-protocol'
12
- import { type AccountBalanceService, isBlockBoundWitnessWithStorageMeta } from '@xyo-network/xl1-protocol'
11
+ import { PayloadBuilder } from '@xyo-network/payload-builder'
12
+ import type { WithStorageMeta } from '@xyo-network/payload-model'
13
+ import type { AccountBalanceServiceV2 } from '@xyo-network/xl1-protocol'
14
+ import { AttoXL1 } from '@xyo-network/xl1-protocol'
15
+ import type { BalancesStepSummary, StepSummary } from '@xyo-network/xl1-protocol-sdk'
16
+ import { parseSignedBigInt } from '@xyo-network/xl1-protocol-sdk'
17
+ import { LRUCache } from 'lru-cache'
13
18
 
14
- export const accountBalanceServiceFromArchivist = async (archivist: ArchivistInstance, head?: Hash): Promise<AccountBalanceService> => {
19
+ import { ChainAccountBalanceServiceV2 } from './ChainAccountBalanceServiceV2.ts'
20
+
21
+ export const accountBalanceServiceFromArchivist = async (archivist: ArchivistInstance, head?: Hash): Promise<AccountBalanceServiceV2> => {
15
22
  let allAddressesBalances: ChainSummaryBalances = {
16
23
  schema: ChainSummaryBalancesSchema, balances: {}, firstBlock: null, lastBlock: null,
17
24
  }
18
25
 
19
- const result: AccountBalanceService = {
20
- getBalance: (address: Address): Hex => {
21
- if (allAddressesBalances === undefined) {
22
- return '00'
26
+ const result: AccountBalanceServiceV2 = {
27
+ balances: async (head: Hash, addresses: Address[]): Promise<Partial<Record<Address, AttoXL1>>> => {
28
+ const sync = async (head: Hash): Promise<void> => {
29
+ const analysis = await analyzeChain(
30
+ archivist,
31
+ [new BalanceAnalyzer()],
32
+ head,
33
+ null,
34
+ -1n,
35
+ )
36
+ allAddressesBalances = analysis.find(isChainSummaryBalances) ?? {
37
+ schema: ChainSummaryBalancesSchema, balances: {}, firstBlock: null, lastBlock: null,
38
+ }
39
+ return await Promise.resolve()
23
40
  }
24
- const signedValue = allAddressesBalances.balances[address] ?? { positive: '00' }
25
- return isPositiveBigInt(signedValue) ? signedValue.positive : '00'
26
- },
27
- getBalances: (): Record<Address, Hex> => {
28
- return Object.fromEntries(Object.entries(allAddressesBalances.balances).map(([key, value]) => ([key, isPositiveBigInt(value) ? value.positive : '0'])))
29
- },
30
- name: 'ArchivistAccountBalanceService',
31
- async sync(head: Hash): Promise<void> {
32
- const analysis = await analyzeChain(
33
- archivist,
34
- [new BalanceAnalyzer()],
35
- head,
36
- null,
37
- -1n,
38
- )
39
- allAddressesBalances = analysis.find(isChainSummaryBalances) ?? {
40
- schema: ChainSummaryBalancesSchema, balances: {}, firstBlock: null, lastBlock: null,
41
+
42
+ await sync(head)
43
+
44
+ const result: Record<Address, AttoXL1> = {}
45
+ for (const addr of addresses) {
46
+ const signedValue = parseSignedBigInt(allAddressesBalances.balances[addr] ?? { positive: '00' })
47
+ result[addr] = AttoXL1(signedValue > 0n ? signedValue : 0n)
41
48
  }
42
- return await Promise.resolve()
49
+ return result
43
50
  },
44
51
  }
45
52
 
46
53
  if (isHash(head)) {
47
- await result.sync(head)
54
+ await result.balances(head, [])
48
55
  }
49
56
 
50
- archivist.on('inserted', ({ payloads }) => {
51
- const block = payloads.find(p => isBlockBoundWitnessWithStorageMeta(p))
52
- if (isDefined(block)) {
53
- void result.sync(block._hash)
54
- }
55
- })
56
-
57
57
  return result
58
58
  }
59
+
60
+ export const accountBalanceServiceFromArchivistV2 = async (archivist: ArchivistInstance): Promise<AccountBalanceServiceV2> => {
61
+ const summaryArchivistCache = new LRUCache<Hash, WithStorageMeta<BalancesStepSummary>>({
62
+ max: 100_000,
63
+ allowStale: true,
64
+ noDisposeOnSet: false,
65
+ updateAgeOnGet: true,
66
+ })
67
+ const summaryRepository = {
68
+ get: (hashes: Hash[]) => {
69
+ const results = hashes.map((hash) => {
70
+ return summaryArchivistCache.get(hash)
71
+ }).filter(exists)
72
+ return results
73
+ },
74
+ insert: async (payloads: BalancesStepSummary[]) => {
75
+ const results = (await PayloadBuilder.addStorageMeta(payloads)).map((payload) => {
76
+ const hash = asHash((payload as WithStorageMeta<StepSummary>).hash)
77
+ if (isHash(hash)) {
78
+ summaryArchivistCache.set(hash, payload)
79
+ return payload
80
+ }
81
+ }).filter(exists)
82
+ return results
83
+ },
84
+ next: () => {
85
+ throw new Error('Not implemented')
86
+ },
87
+ }
88
+ const service = await ChainAccountBalanceServiceV2.create({ chainArchivist: archivist, summaryRepository })
89
+ return service
90
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './accountBalanceServiceFromArchivist.ts'
2
+ export * from './ChainAccountBalanceServiceV2.ts'
2
3
  export * from './XyoChainAccountBalanceService.ts'
@@ -1,47 +1,34 @@
1
+ import { AbstractCreatable, creatable } from '@xylabs/creatable'
1
2
  import type { EventData } from '@xylabs/events'
2
- import { BaseEmitter } from '@xylabs/events'
3
3
  import type { Promisable } from '@xylabs/promise'
4
4
  import { span, spanAsync } from '@xylabs/telemetry'
5
- import type {
6
- BaseAccountableServiceParams, BaseServiceParams, Service,
7
- } from '@xyo-network/xl1-protocol'
5
+ import type { Service } from '@xyo-network/xl1-protocol'
8
6
  import { Mutex } from 'async-mutex'
9
7
 
8
+ import type { BaseAccountableServiceParams, BaseServiceParams } from './Params.ts'
9
+
10
10
  declare global {
11
11
  var xyoServiceSingletons: Record<string, unknown>
12
12
  }
13
13
 
14
+ @creatable()
14
15
  export class BaseService<TParams extends BaseServiceParams = BaseServiceParams, TEventData extends EventData = EventData>
15
- extends BaseEmitter<Partial<TParams>, TEventData> {
16
+ extends AbstractCreatable<TParams, TEventData> {
16
17
  private static singletonInitMutex = new Mutex()
17
18
 
18
19
  static get singletons() {
19
20
  return globalThis['xyoServiceSingletons'] ?? (globalThis['xyoServiceSingletons'] = {})
20
21
  }
21
22
 
22
- get name() {
23
- return this.constructor.name
24
- }
25
-
26
- static async create<TService extends BaseService<TParams>, TParams extends BaseServiceParams = TService['params']>(
27
- this: CreatableService<TService>,
28
- params: Partial<TParams>,
29
- ): Promise<TService> {
30
- const result = new this(params)
31
- if (result.name === 'BaseService') throw new Error('Cannot create BaseService')
32
- await result.createHandler()
33
- return result
34
- }
35
-
36
- static initSingleton<TService extends BaseService<TParams>, TParams extends BaseServiceParams>(params: TParams) {
23
+ static initSingleton<TService extends BaseService<TParams>, TParams extends BaseServiceParams>(params: Partial<TParams>) {
37
24
  if (this.singletons[this.name]) throw new Error(`Singleton already initialized for ${this.name}`)
38
25
  return this.singletonInitMutex.runExclusive(async () => {
39
26
  return await this.create(params) as TService
40
27
  })
41
28
  }
42
29
 
43
- createHandler(): Promisable<void> {
44
- return
30
+ paramsHandler(params?: Partial<TParams>): TParams {
31
+ return params as TParams
45
32
  }
46
33
 
47
34
  span<T>(name: string, fn: () => T): T {
@@ -61,7 +48,7 @@ export abstract class BaseAccountableService<
61
48
 
62
49
  export interface CreatableService<T extends BaseService = BaseService> extends Service {
63
50
  new(params: T['params']): T
64
- create<T extends BaseService>(this: CreatableService<T>, params: T['params']): Promisable<T>
51
+ create<T extends BaseService>(this: CreatableService<T>, params?: Partial<T['params']>): Promisable<T>
65
52
  }
66
53
 
67
54
  export function creatableService<T extends BaseService = BaseService>() {