@xyo-network/chain-services 1.20.15 → 1.20.17
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/README.md +9 -7634
- package/dist/neutral/index.mjs +7 -2
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/simple/block/runner/SimpleBlockRunner.d.ts +2 -2
- package/dist/neutral/simple/block/runner/SimpleBlockRunner.d.ts.map +1 -1
- package/package.json +123 -30
- package/src/BlockReward/EvmBlockRewardViewer.ts +0 -53
- package/src/BlockReward/index.ts +0 -1
- package/src/ChainValidator/XyoValidator.ts +0 -71
- package/src/ChainValidator/index.ts +0 -2
- package/src/ChainValidator/model/Validator.ts +0 -7
- package/src/ChainValidator/model/index.ts +0 -1
- package/src/Election/BaseElectionService.ts +0 -55
- package/src/Election/index.ts +0 -1
- package/src/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.ts +0 -99
- package/src/NetworkStakeStepReward/index.ts +0 -1
- package/src/StepStake/BaseStepStakeService.ts +0 -24
- package/src/StepStake/index.ts +0 -1
- package/src/implementation/head/createBootstrapHead.ts +0 -36
- package/src/implementation/head/index.ts +0 -1
- package/src/implementation/index.ts +0 -1
- package/src/index.ts +0 -8
- package/src/model/Params.ts +0 -10
- package/src/model/index.ts +0 -1
- package/src/simple/block/index.ts +0 -1
- package/src/simple/block/runner/SimpleBlockRunner.ts +0 -363
- package/src/simple/block/runner/generateTransactionFeeTransfers.ts +0 -56
- package/src/simple/block/runner/index.ts +0 -1
- package/src/simple/index.ts +0 -1
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import type {
|
|
3
|
-
BlockBoundWitness,
|
|
4
|
-
BlockViewer, HydratedBlockStateValidationFunction,
|
|
5
|
-
SignedHydratedTransactionWithStorageMeta,
|
|
6
|
-
} from '@xyo-network/xl1-sdk'
|
|
7
|
-
import { AbstractCreatableProvider, BlockViewerMoniker } from '@xyo-network/xl1-sdk'
|
|
8
|
-
|
|
9
|
-
import type { BaseServiceParams } from '../model/index.ts'
|
|
10
|
-
import type { Validator } from './model/index.ts'
|
|
11
|
-
|
|
12
|
-
export interface XyoValidatorParams extends BaseServiceParams {
|
|
13
|
-
// account: AccountInstance
|
|
14
|
-
// blockRewardService: BlockRewardService
|
|
15
|
-
blockViewer: BlockViewer
|
|
16
|
-
// chainId: ChainId
|
|
17
|
-
// electionService: ElectionService
|
|
18
|
-
// pendingBundledTransactionsArchivist: ArchivistInstance
|
|
19
|
-
// stakeIntentService: StakeIntentService
|
|
20
|
-
validateHydratedBlockState: HydratedBlockStateValidationFunction
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class XyoValidator<TParams extends XyoValidatorParams = XyoValidatorParams> extends AbstractCreatableProvider<TParams> implements Validator {
|
|
24
|
-
moniker = 'Validator'
|
|
25
|
-
private _blockViewer?: BlockViewer
|
|
26
|
-
// get address() {
|
|
27
|
-
// return this.account.address
|
|
28
|
-
// }
|
|
29
|
-
|
|
30
|
-
// protected get account() {
|
|
31
|
-
// return assertEx(this.params.account, () => 'account is required')
|
|
32
|
-
// }
|
|
33
|
-
|
|
34
|
-
protected get blockViewer() {
|
|
35
|
-
return this._blockViewer!
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// protected get chainInfo() {
|
|
39
|
-
// return assertEx(this.params.chainId, () => 'chainInfo is required')
|
|
40
|
-
// }
|
|
41
|
-
|
|
42
|
-
// protected get electionService() {
|
|
43
|
-
// return assertEx(this.params.electionService, () => 'electionService is required')
|
|
44
|
-
// }
|
|
45
|
-
|
|
46
|
-
// protected get pendingBundledTransactionsArchivist() {
|
|
47
|
-
// return assertEx(this.params.pendingBundledTransactionsArchivist, () => 'pendingBundledTransactions is required')
|
|
48
|
-
// }
|
|
49
|
-
|
|
50
|
-
// protected get blockRewardService() {
|
|
51
|
-
// return assertEx(this.params.blockRewardService, () => 'blockRewardService is required')
|
|
52
|
-
// }
|
|
53
|
-
|
|
54
|
-
override async createHandler() {
|
|
55
|
-
this._blockViewer = await this.locator.getInstance(BlockViewerMoniker)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
validatePendingBlock(_block: BlockBoundWitness): Promisable<Error[]> {
|
|
59
|
-
return [] // await validateBlockProtocol(block, this.chainInfo)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// TODO: Move to validator and inherit this class from validator
|
|
63
|
-
async validatePendingTransaction(hydratedTransaction: SignedHydratedTransactionWithStorageMeta): Promise<boolean> {
|
|
64
|
-
const [tx] = hydratedTransaction
|
|
65
|
-
// Ensure not confirmed already (replay attack)
|
|
66
|
-
if ((await this.blockViewer.blockByHash(tx._hash)) !== undefined) return false
|
|
67
|
-
// TODO: Ensure transaction is valid (double spend, has voucher, has required stake, etc.)
|
|
68
|
-
// TODO: Ensure validator stake is valid
|
|
69
|
-
return await Promise.resolve(true)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import type { BlockBoundWitness, SignedHydratedTransactionWithStorageMeta } from '@xyo-network/xl1-sdk'
|
|
3
|
-
|
|
4
|
-
export interface Validator {
|
|
5
|
-
validatePendingBlock(block: BlockBoundWitness): Promisable<Error[]>
|
|
6
|
-
validatePendingTransaction(tx: SignedHydratedTransactionWithStorageMeta): Promise<boolean>
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Validator.ts'
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Address, assertEx, Hash,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import { hexToLast4BytesInt, shuffleWithSeed } from '@xyo-network/chain-utils'
|
|
5
|
-
import { WithHashMeta } from '@xyo-network/sdk-js'
|
|
6
|
-
import {
|
|
7
|
-
AbstractCreatableProvider,
|
|
8
|
-
type BlockViewer,
|
|
9
|
-
type ChainStakeViewer, creatableProvider,
|
|
10
|
-
type ElectionService, type StakeIntentService,
|
|
11
|
-
} from '@xyo-network/xl1-sdk'
|
|
12
|
-
import { BlockBoundWitness } from '@xyo-network/xl1-sdk'
|
|
13
|
-
|
|
14
|
-
import { BaseServiceParams } from '../model/index.ts'
|
|
15
|
-
|
|
16
|
-
export interface BaseElectionServicesParams extends BaseServiceParams {
|
|
17
|
-
blockViewer?: BlockViewer
|
|
18
|
-
chainStakeViewer?: ChainStakeViewer
|
|
19
|
-
stakeIntentService?: StakeIntentService
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@creatableProvider()
|
|
23
|
-
export class BaseElectionService extends AbstractCreatableProvider<BaseElectionServicesParams> implements ElectionService {
|
|
24
|
-
static readonly defaultMoniker = 'Election'
|
|
25
|
-
static readonly dependencies = []
|
|
26
|
-
static readonly monikers = ['Election']
|
|
27
|
-
moniker = BaseElectionService.defaultMoniker
|
|
28
|
-
get blockViewer() {
|
|
29
|
-
return assertEx(this.params.blockViewer, () => 'No block viewer')
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get chainStakeViewer() {
|
|
33
|
-
return assertEx(this.params.chainStakeViewer, () => 'No chain stake viewer')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
get stakeIntentService() {
|
|
37
|
-
return assertEx(this.params.stakeIntentService, () => 'No staked intent service')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async getCreatorCommitteeForNextBlock(current: WithHashMeta<BlockBoundWitness>): Promise<Address[]> {
|
|
41
|
-
return await this.spanAsync('getCreatorCommitteeForNextBlock', async () => {
|
|
42
|
-
const nextBlock = current.block + 1
|
|
43
|
-
const candidates = await this.stakeIntentService.getDeclaredCandidatesForBlock(nextBlock, 'producer')
|
|
44
|
-
const previousBlockHash = current._hash
|
|
45
|
-
return this.generateCreatorCommittee(candidates, previousBlockHash)
|
|
46
|
-
}, this.context)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
protected generateCreatorCommittee(candidates: Address[], previousBlockHash: Hash, maxSize = 3): Address[] {
|
|
50
|
-
const creators = new Set<Address>(candidates)
|
|
51
|
-
const seed = hexToLast4BytesInt(previousBlockHash)
|
|
52
|
-
const creatorArray = shuffleWithSeed(creators, seed)
|
|
53
|
-
return creatorArray.slice(0, maxSize)
|
|
54
|
-
}
|
|
55
|
-
}
|
package/src/Election/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './BaseElectionService.ts'
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { Address, Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import { ReadArchivist } from '@xyo-network/sdk-js'
|
|
3
|
-
import {
|
|
4
|
-
AbstractCreatableProvider,
|
|
5
|
-
AttoXL1,
|
|
6
|
-
creatableProvider,
|
|
7
|
-
NetworkStakeStepRewardService, NetworkStakeStepRewardViewerMoniker,
|
|
8
|
-
StepIdentity,
|
|
9
|
-
StepIdentityString,
|
|
10
|
-
} from '@xyo-network/xl1-sdk'
|
|
11
|
-
import { Provider } from 'ethers'
|
|
12
|
-
|
|
13
|
-
import { BaseServiceParams } from '../model/index.ts'
|
|
14
|
-
|
|
15
|
-
export interface BaseNetworkStakeStepRewardServiceParams extends BaseServiceParams {
|
|
16
|
-
chainArchivist: ReadArchivist
|
|
17
|
-
ethProvider?: Provider
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@creatableProvider()
|
|
21
|
-
export class BaseNetworkStakeStepRewardService extends
|
|
22
|
-
AbstractCreatableProvider<BaseNetworkStakeStepRewardServiceParams> implements NetworkStakeStepRewardService {
|
|
23
|
-
static readonly defaultMoniker = NetworkStakeStepRewardViewerMoniker
|
|
24
|
-
static readonly dependencies = []
|
|
25
|
-
static readonly monikers = [NetworkStakeStepRewardViewerMoniker]
|
|
26
|
-
override moniker = BaseNetworkStakeStepRewardService.defaultMoniker
|
|
27
|
-
|
|
28
|
-
networkStakeStepRewardAddressHistory(_address: Address): Promisable<Record<Address, AttoXL1>> {
|
|
29
|
-
throw new Error('Method [networkStakeStepRewardAddressHistory] not implemented.')
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
networkStakeStepRewardAddressReward(_context: StepIdentity, _address: Address): Promisable<Record<Address, AttoXL1>> {
|
|
33
|
-
throw new Error('Method [networkStakeStepRewardAddressReward] not implemented.')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
networkStakeStepRewardAddressShare(_context: StepIdentity, _address: Address): Promisable<[bigint, bigint]> {
|
|
37
|
-
throw new Error('Method [networkStakeStepRewardAddressShare] not implemented.')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
networkStakeStepRewardClaimedByAddress(_address: Address): Promisable<AttoXL1> {
|
|
41
|
-
throw new Error('Method [networkStakeStepRewardClaimedByAddress] not implemented.')
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
networkStakeStepRewardForPosition(_position: number, _range: [number, number]): Promisable<[AttoXL1, AttoXL1]> {
|
|
45
|
-
throw new Error('Method [networkStakeStepRewardForPosition] not implemented.')
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
networkStakeStepRewardForStep(_context: StepIdentity): Promisable<AttoXL1> {
|
|
49
|
-
throw new Error('Method [networkStakeStepRewardForStep] not implemented.')
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
networkStakeStepRewardForStepForPosition(_context: StepIdentity, _position: number): Promisable<[AttoXL1, AttoXL1]> {
|
|
53
|
-
throw new Error('Method [networkStakeStepRewardForStepForPosition] not implemented.')
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
networkStakeStepRewardPoolRewards(_context: StepIdentity): Promisable<Record<Address, AttoXL1>> {
|
|
57
|
-
throw new Error('Method [networkStakeStepRewardPoolRewards] not implemented.')
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
networkStakeStepRewardPoolShares(_context: StepIdentity): Promisable<Record<Address, bigint>> {
|
|
61
|
-
throw new Error('Method [networkStakeStepRewardPoolShares] not implemented.')
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
networkStakeStepRewardPositionWeight(_context: StepIdentity, _position: number): Promisable<bigint> {
|
|
65
|
-
throw new Error('Method [networkStakeStepRewardPositionWeight] not implemented.')
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
networkStakeStepRewardPotentialPositionLoss(_context: StepIdentity, _position: number): Promisable<AttoXL1> {
|
|
69
|
-
throw new Error('Method [networkStakeStepRewardPotentialPositionLoss] not implemented.')
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
networkStakeStepRewardRandomizer(_context: StepIdentity): Promisable<AttoXL1> {
|
|
73
|
-
throw new Error('Method [networkStakeStepRewardRandomizer] not implemented.')
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
networkStakeStepRewardStakerCount(_context: StepIdentity): Promisable<number> {
|
|
77
|
-
throw new Error('Method [networkStakeStepRewardStakerCount] not implemented.')
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
networkStakeStepRewardUnclaimedByAddress(_address: Address): Promisable<AttoXL1> {
|
|
81
|
-
throw new Error('Method [networkStakeStepRewardUnclaimedByAddress] not implemented.')
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
networkStakeStepRewardWeightForAddress(_context: StepIdentity, _address: Address): Promisable<bigint> {
|
|
85
|
-
throw new Error('Method [networkStakeStepRewardWeightForAddress] not implemented.')
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
networkStakeStepRewardsForPosition(_position: number, _range: [number, number]): Promisable<Record<StepIdentityString, [AttoXL1, AttoXL1]>> {
|
|
89
|
-
throw new Error('Method [networkStakeStepRewardsForPosition] not implemented.')
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
networkStakeStepRewardsForRange(_range: [number, number]): Promisable<AttoXL1> {
|
|
93
|
-
throw new Error('Method [networkStakeStepRewardsForRange] not implemented.')
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
networkStakeStepRewardsForStepLevel(_stepLevel: number, _range: [number, number]): Promisable<AttoXL1> {
|
|
97
|
-
throw new Error('Method [networkStakeStepRewardsForStepLevel] not implemented.')
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './BaseNetworkStakeStepRewardService.ts'
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Address, Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import type { ReadArchivist } from '@xyo-network/sdk-js'
|
|
3
|
-
import type { StepIdentity, StepStakeViewer } from '@xyo-network/xl1-sdk'
|
|
4
|
-
import { AbstractCreatableProvider, StepStakeViewerMoniker } from '@xyo-network/xl1-sdk'
|
|
5
|
-
|
|
6
|
-
import type { BaseServiceParams } from '../model/index.ts'
|
|
7
|
-
|
|
8
|
-
export interface BaseStepStakeServiceParams extends BaseServiceParams {
|
|
9
|
-
chainArchivist: ReadArchivist
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export abstract class AbstractStepStakeService extends AbstractCreatableProvider<BaseStepStakeServiceParams> implements StepStakeViewer {
|
|
13
|
-
static readonly defaultMoniker = StepStakeViewerMoniker
|
|
14
|
-
static readonly monikers = [StepStakeViewerMoniker]
|
|
15
|
-
override moniker = AbstractStepStakeService.defaultMoniker
|
|
16
|
-
|
|
17
|
-
stepStake(_step: StepIdentity): Promisable<Record<Address, bigint>> {
|
|
18
|
-
throw new Error('Method [stepStake] not implemented.')
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
stepStakeForAddress(_address: Address, _step: StepIdentity): Promisable<bigint> {
|
|
22
|
-
throw new Error('Method [stepStakeForAddress] not implemented.')
|
|
23
|
-
}
|
|
24
|
-
}
|
package/src/StepStake/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './BaseStepStakeService.ts'
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import { buildNextBlock, createGenesisBlock } from '@xyo-network/chain-protocol'
|
|
3
|
-
import type { AccountInstance } from '@xyo-network/sdk-js'
|
|
4
|
-
import type {
|
|
5
|
-
AttoXL1, ChainId, SignedHydratedBlockWithHashMeta,
|
|
6
|
-
} from '@xyo-network/xl1-sdk'
|
|
7
|
-
import { createDeclarationIntent } from '@xyo-network/xl1-sdk'
|
|
8
|
-
|
|
9
|
-
export const createBootstrapHead = async (
|
|
10
|
-
account: AccountInstance,
|
|
11
|
-
chainId: ChainId,
|
|
12
|
-
genesisBlockRewardAmount: AttoXL1,
|
|
13
|
-
genesisBlockRewardAddress: Address,
|
|
14
|
-
): Promise<SignedHydratedBlockWithHashMeta[]> => {
|
|
15
|
-
const chain: SignedHydratedBlockWithHashMeta[] = []
|
|
16
|
-
|
|
17
|
-
// Create genesis block
|
|
18
|
-
const genesisBlock = await createGenesisBlock(account, chainId, genesisBlockRewardAmount, genesisBlockRewardAddress)
|
|
19
|
-
chain.push(genesisBlock)
|
|
20
|
-
|
|
21
|
-
// Create producer declaration block
|
|
22
|
-
const producerDeclarationPayload = createDeclarationIntent(
|
|
23
|
-
account.address,
|
|
24
|
-
'producer',
|
|
25
|
-
genesisBlock[0].block,
|
|
26
|
-
genesisBlock[0].block + 10_000,
|
|
27
|
-
)
|
|
28
|
-
const producerDeclarationBlock = await buildNextBlock(
|
|
29
|
-
genesisBlock[0],
|
|
30
|
-
[],
|
|
31
|
-
[producerDeclarationPayload],
|
|
32
|
-
[account],
|
|
33
|
-
)
|
|
34
|
-
chain.push(producerDeclarationBlock)
|
|
35
|
-
return chain
|
|
36
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './createBootstrapHead.ts'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './head/index.ts'
|
package/src/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './BlockReward/index.ts'
|
|
2
|
-
export * from './ChainValidator/index.ts'
|
|
3
|
-
export * from './Election/index.ts'
|
|
4
|
-
export * from './implementation/index.ts'
|
|
5
|
-
export * from './model/index.ts'
|
|
6
|
-
export * from './NetworkStakeStepReward/index.ts'
|
|
7
|
-
export * from './simple/index.ts'
|
|
8
|
-
export * from './StepStake/index.ts'
|
package/src/model/Params.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { AccountInstance } from '@xyo-network/sdk-js'
|
|
2
|
-
import type { CreatableProviderParams, OpenTelemetryProviders } from '@xyo-network/xl1-sdk'
|
|
3
|
-
|
|
4
|
-
export interface BaseServiceParams extends CreatableProviderParams, OpenTelemetryProviders {
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface BaseAccountableServiceParams extends BaseServiceParams {
|
|
9
|
-
account: AccountInstance
|
|
10
|
-
}
|
package/src/model/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Params.ts'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './runner/index.ts'
|