@xyo-network/chain-services 1.5.34 → 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.
- package/dist/neutral/index.mjs +428 -259
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/types/AccountBalance/ChainAccountBalanceServiceV2.d.ts +14 -0
- package/dist/types/AccountBalance/ChainAccountBalanceServiceV2.d.ts.map +1 -0
- package/dist/types/AccountBalance/XyoChainAccountBalanceService.d.ts +12 -8
- package/dist/types/AccountBalance/XyoChainAccountBalanceService.d.ts.map +1 -1
- package/dist/types/AccountBalance/accountBalanceServiceFromArchivist.d.ts +3 -2
- package/dist/types/AccountBalance/accountBalanceServiceFromArchivist.d.ts.map +1 -1
- package/dist/types/AccountBalance/index.d.ts +1 -0
- package/dist/types/AccountBalance/index.d.ts.map +1 -1
- package/dist/types/BaseService.d.ts +7 -8
- package/dist/types/BaseService.d.ts.map +1 -1
- package/dist/types/BlockProducer/XyoBlockProducer.d.ts +28 -9
- package/dist/types/BlockProducer/XyoBlockProducer.d.ts.map +1 -1
- package/dist/types/BlockReward/EvmBlockRewardService.d.ts +2 -1
- package/dist/types/BlockReward/EvmBlockRewardService.d.ts.map +1 -1
- package/dist/types/BlockReward/XyoBlockRewardService.d.ts +2 -1
- package/dist/types/BlockReward/XyoBlockRewardService.d.ts.map +1 -1
- package/dist/types/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts +4 -2
- package/dist/types/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts.map +1 -1
- package/dist/types/ChainBlockNumberIteration/model/Params.d.ts +8 -0
- package/dist/types/ChainBlockNumberIteration/model/Params.d.ts.map +1 -0
- package/dist/types/ChainBlockNumberIteration/model/index.d.ts +1 -0
- package/dist/types/ChainBlockNumberIteration/model/index.d.ts.map +1 -1
- package/dist/types/ChainIndexService.d.ts +8 -5
- package/dist/types/ChainIndexService.d.ts.map +1 -1
- package/dist/types/ChainValidator/XyoValidator.d.ts +20 -9
- package/dist/types/ChainValidator/XyoValidator.d.ts.map +1 -1
- package/dist/types/Election/XyoElectionService.d.ts +2 -2
- package/dist/types/Election/XyoElectionService.d.ts.map +1 -1
- package/dist/types/Params.d.ts +9 -0
- package/dist/types/Params.d.ts.map +1 -0
- package/dist/types/PendingTransactions/PendingTransactions.d.ts +7 -5
- package/dist/types/PendingTransactions/PendingTransactions.d.ts.map +1 -1
- package/dist/types/StakeIntent/XyoStakeIntentService.d.ts +10 -6
- package/dist/types/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
- package/dist/types/Staker/Evm/Evm.d.ts +5 -5
- package/dist/types/Staker/Evm/Evm.d.ts.map +1 -1
- package/dist/types/Staker/Memory/Memory.d.ts +31 -0
- package/dist/types/Staker/Memory/Memory.d.ts.map +1 -0
- package/dist/types/Staker/Memory/index.d.ts +2 -0
- package/dist/types/Staker/Memory/index.d.ts.map +1 -0
- package/dist/types/Staker/index.d.ts +1 -0
- package/dist/types/Staker/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +45 -44
- package/src/AccountBalance/ChainAccountBalanceServiceV2.ts +33 -0
- package/src/AccountBalance/XyoChainAccountBalanceService.ts +23 -19
- package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +67 -35
- package/src/AccountBalance/index.ts +1 -0
- package/src/BaseService.ts +10 -23
- package/src/BlockProducer/XyoBlockProducer.ts +53 -30
- package/src/BlockReward/EvmBlockRewardService.ts +5 -5
- package/src/BlockReward/XyoBlockRewardService.ts +5 -3
- package/src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts +5 -3
- package/src/ChainBlockNumberIteration/model/Params.ts +9 -0
- package/src/ChainBlockNumberIteration/model/index.ts +1 -0
- package/src/ChainIndexService.ts +5 -5
- package/src/ChainValidator/XyoValidator.ts +9 -8
- package/src/Election/XyoElectionService.ts +5 -7
- package/src/Params.ts +9 -0
- package/src/PendingTransactions/PendingTransactions.ts +127 -63
- package/src/StakeIntent/XyoStakeIntentService.ts +30 -17
- package/src/Staker/Evm/Evm.ts +9 -12
- package/src/Staker/Memory/Memory.ts +90 -0
- package/src/Staker/Memory/index.ts +1 -0
- package/src/Staker/index.ts +1 -0
- 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 {
|
|
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
|
-
|
|
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/Evm/Evm.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAG1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAE5D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"Evm.d.ts","sourceRoot":"","sources":["../../../../src/Staker/Evm/Evm.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAG1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAE5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEtD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAExD,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,QAAQ,EAAE,cAAc,CAAA;IACxB,EAAE,EAAE,OAAO,CAAA;IACX,MAAM,EAAE,cAAc,CAAA;CACvB;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,WAAW,CAAC,qBAAqB,CAAE,YAAW,YAAY;IAC7F,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,QAAQ,mBAQX;IAED,IAAI,MAAM,IAAI,cAAc,CAE3B;IAEK,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IAIzB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIvD,cAAc,CAAC,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 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Staker/Memory/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
|
|
@@ -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"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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.
|
|
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.
|
|
39
|
-
"@xylabs/assert": "^4.
|
|
40
|
-
"@xylabs/
|
|
41
|
-
"@xylabs/decimal-precision": "^4.
|
|
42
|
-
"@xylabs/events": "^4.
|
|
43
|
-
"@xylabs/exists": "^4.
|
|
44
|
-
"@xylabs/forget": "^4.
|
|
45
|
-
"@xylabs/hex": "^4.
|
|
46
|
-
"@xylabs/
|
|
47
|
-
"@xylabs/
|
|
48
|
-
"@xylabs/
|
|
49
|
-
"@
|
|
50
|
-
"@xyo-network/
|
|
51
|
-
"@xyo-network/archivist-
|
|
52
|
-
"@xyo-network/
|
|
53
|
-
"@xyo-network/boundwitness-
|
|
54
|
-
"@xyo-network/boundwitness-
|
|
55
|
-
"@xyo-network/
|
|
56
|
-
"@xyo-network/chain-
|
|
57
|
-
"@xyo-network/chain-
|
|
58
|
-
"@xyo-network/chain-
|
|
59
|
-
"@xyo-network/chain-
|
|
60
|
-
"@xyo-network/chain-
|
|
61
|
-
"@xyo-network/chain-
|
|
62
|
-
"@xyo-network/chain-
|
|
63
|
-
"@xyo-network/
|
|
64
|
-
"@xyo-network/payload-
|
|
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.
|
|
67
|
-
"@xyo-network/xl1-protocol-sdk": "^1.5.
|
|
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.
|
|
75
|
-
"@xylabs/delay": "^4.
|
|
76
|
-
"@xylabs/ts-scripts-yarn3": "^6.5.
|
|
77
|
-
"@xylabs/tsconfig": "^6.5.
|
|
78
|
-
"@xylabs/vitest-extended": "^4.
|
|
79
|
-
"@xyo-network/account": "^3.18.
|
|
80
|
-
"@xyo-network/account-model": "^3.18.
|
|
81
|
-
"@xyo-network/chain-validation": "^1.5.
|
|
82
|
-
"@xyo-network/wallet": "^3.18.
|
|
83
|
-
"knip": "^5.61.
|
|
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.
|
|
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
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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
|
|
14
|
+
import { BaseService } from '../BaseService.ts'
|
|
15
|
+
import { BaseServiceParams } from '../Params.ts'
|
|
17
16
|
|
|
18
|
-
export
|
|
17
|
+
export interface ChainAccountBalanceServiceParams extends BaseServiceParams, Partial<Pick<ChainServiceCollection, 'chainArchivist'>> { head?: Hash }
|
|
19
18
|
|
|
20
|
-
@
|
|
21
|
-
export class XyoChainAccountBalanceService extends BaseService<ChainAccountBalanceServiceParams> implements
|
|
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
|
-
|
|
38
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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,
|
|
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 {
|
|
12
|
-
import
|
|
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
|
-
|
|
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:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
49
|
+
return result
|
|
43
50
|
},
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
if (isHash(head)) {
|
|
47
|
-
await result.
|
|
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
|
+
}
|
package/src/BaseService.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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>() {
|