@xyo-network/chain-services 1.18.1 → 1.18.4
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/accountBalanceServiceFromArchivist.d.ts.map +1 -1
- package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts +14 -14
- package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts.map +1 -1
- package/dist/neutral/Schemas/BaseSchemasService.d.ts.map +1 -1
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
- package/dist/neutral/implementation/index.d.ts +0 -1
- package/dist/neutral/implementation/index.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +0 -1
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +91 -290
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/simple/block/runner/SimpleBlockRunner.d.ts +4 -2
- package/dist/neutral/simple/block/runner/SimpleBlockRunner.d.ts.map +1 -1
- package/package.json +28 -28
- package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +7 -3
- package/src/BlockReward/EvmBlockRewardViewer.ts +2 -2
- package/src/Election/BaseElectionService.ts +1 -1
- package/src/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.ts +14 -13
- package/src/PendingTransactions/BasePendingTransactions.ts +3 -3
- package/src/Schemas/BaseSchemasService.ts +3 -3
- package/src/StakeIntent/XyoStakeIntentService.ts +19 -21
- package/src/implementation/index.ts +0 -1
- package/src/index.ts +0 -1
- package/src/simple/block/runner/SimpleBlockRunner.ts +25 -29
- package/dist/neutral/ChainService/Evm/Evm.d.ts +0 -38
- package/dist/neutral/ChainService/Evm/Evm.d.ts.map +0 -1
- package/dist/neutral/ChainService/Evm/index.d.ts +0 -2
- package/dist/neutral/ChainService/Evm/index.d.ts.map +0 -1
- package/dist/neutral/ChainService/Memory/Memory.d.ts +0 -37
- package/dist/neutral/ChainService/Memory/Memory.d.ts.map +0 -1
- package/dist/neutral/ChainService/Memory/index.d.ts +0 -2
- package/dist/neutral/ChainService/Memory/index.d.ts.map +0 -1
- package/dist/neutral/ChainService/index.d.ts +0 -3
- package/dist/neutral/ChainService/index.d.ts.map +0 -1
- package/dist/neutral/implementation/chain/evm.d.ts +0 -6
- package/dist/neutral/implementation/chain/evm.d.ts.map +0 -1
- package/dist/neutral/implementation/chain/index.d.ts +0 -5
- package/dist/neutral/implementation/chain/index.d.ts.map +0 -1
- package/src/ChainService/Evm/Evm.ts +0 -106
- package/src/ChainService/Evm/index.ts +0 -1
- package/src/ChainService/Memory/Memory.ts +0 -105
- package/src/ChainService/Memory/index.ts +0 -1
- package/src/ChainService/index.ts +0 -2
- package/src/implementation/chain/evm.ts +0 -38
- package/src/implementation/chain/index.ts +0 -43
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ChainService/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Config, Initializable } from '@xyo-network/xl1-sdk';
|
|
2
|
-
import { EvmChainViewer } from '../../ChainService/index.ts';
|
|
3
|
-
import type { BaseAccountableServiceParams } from '../../model/index.ts';
|
|
4
|
-
export declare const canUseEvmContractChainService: (config: Pick<Config, "chain" | "evm">) => boolean;
|
|
5
|
-
export declare const initEvmContractChainService: Initializable<BaseAccountableServiceParams, EvmChainViewer>;
|
|
6
|
-
//# sourceMappingURL=evm.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"evm.d.ts","sourceRoot":"","sources":["../../../../src/implementation/chain/evm.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAIjE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAA;AAKxE,eAAO,MAAM,6BAA6B,GAAI,QAAQ,IAAI,CAAC,MAAM,EAAE,OAAO,GAAG,KAAK,CAAC,YAGlF,CAAA;AAED,eAAO,MAAM,2BAA2B,EAAE,aAAa,CAAC,4BAA4B,EAAE,cAAc,CAkBnG,CAAA"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { ChainService, Initializable } from '@xyo-network/xl1-sdk';
|
|
2
|
-
import type { BaseAccountableServiceParams } from '../../model/index.ts';
|
|
3
|
-
export declare const initChainService: Initializable<BaseAccountableServiceParams, ChainService>;
|
|
4
|
-
export declare const initMemoryChainService: Initializable<BaseAccountableServiceParams, ChainService>;
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/implementation/chain/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAGvE,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAA;AAKxE,eAAO,MAAM,gBAAgB,EAAE,aAAa,CAAC,4BAA4B,EACvE,YAAY,CAUb,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAE,aAAa,CAAC,4BAA4B,EAAE,YAAY,CAO5F,CAAA"}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Address, Hex, Promisable,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import { toAddress, toEthAddress } from '@xylabs/sdk-js'
|
|
5
|
-
import type { StakedXyoChain } from '@xyo-network/typechain'
|
|
6
|
-
import type {
|
|
7
|
-
AttoXL1, ChainService, XL1BlockNumber,
|
|
8
|
-
} from '@xyo-network/xl1-sdk'
|
|
9
|
-
import { AbstractCreatableProvider, ChainContractViewerMoniker } from '@xyo-network/xl1-sdk'
|
|
10
|
-
import { getAddress } from 'ethers/address'
|
|
11
|
-
import type { ContractRunner } from 'ethers/providers'
|
|
12
|
-
|
|
13
|
-
import type { BaseServiceParams } from '../../model/index.ts'
|
|
14
|
-
|
|
15
|
-
export interface EvmChainViewerParams extends BaseServiceParams {
|
|
16
|
-
contract: StakedXyoChain
|
|
17
|
-
id: Hex
|
|
18
|
-
runner: ContractRunner
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* A class that represents a chain stake as backed by an EVM smart contract
|
|
23
|
-
*/
|
|
24
|
-
export class EvmChainViewer extends AbstractCreatableProvider<EvmChainViewerParams> implements ChainService {
|
|
25
|
-
static readonly defaultMoniker = ChainContractViewerMoniker
|
|
26
|
-
static readonly monikers = [ChainContractViewerMoniker]
|
|
27
|
-
override moniker = EvmChainViewer.defaultMoniker
|
|
28
|
-
|
|
29
|
-
protected get contract() {
|
|
30
|
-
return this.params.contract
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async active(): Promise<bigint> {
|
|
34
|
-
return await (this.contract).active()
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async activeByStaked(staked: Address): Promise<bigint> {
|
|
38
|
-
return await (this.contract).activeByAddressStaked(getAddress(toEthAddress(staked)))
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async activeByStaker(address: Address): Promise<bigint> {
|
|
42
|
-
return await (this.contract).activeByStaker(getAddress(toEthAddress(address)))
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async addStake(staked: Address, amount: bigint): Promise<boolean> {
|
|
46
|
-
const result = await (this.contract).addStake(getAddress(toEthAddress(staked)), amount)
|
|
47
|
-
await result.wait()
|
|
48
|
-
return true
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async forkedAtBlockNumber(): Promise<bigint> {
|
|
52
|
-
return await (this.contract).forkedAtBlockNumber()
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async forkedAtHash(): Promise<bigint> {
|
|
56
|
-
return await (this.contract).forkedAtHash()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async forkedChainId(): Promise<Address> {
|
|
60
|
-
return toAddress(await (this.contract).forkedChainId())
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async minWithdrawalBlocks(): Promise<bigint> {
|
|
64
|
-
return await (this.contract).minWithdrawalBlocks()
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async pending(): Promise<bigint> {
|
|
68
|
-
return await (this.contract).pending()
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async pendingByStaker(staker: Address): Promise<bigint> {
|
|
72
|
-
return await (this.contract).pendingByStaker(getAddress(toEthAddress(staker)))
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async removeStake(slot: bigint): Promise<boolean> {
|
|
76
|
-
const result = await (this.contract).removeStake(slot)
|
|
77
|
-
await result.wait()
|
|
78
|
-
return true
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
rewardForBlock(_block: XL1BlockNumber): Promisable<AttoXL1> {
|
|
82
|
-
throw new Error('Method not implemented.')
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async rewardsContract(): Promise<string> {
|
|
86
|
-
return await (this.contract).rewardsContract()
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async stakingTokenAddress(): Promise<string> {
|
|
90
|
-
return await (this.contract).stakingTokenAddress()
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async withdrawStake(slot: bigint): Promise<boolean> {
|
|
94
|
-
const result = await (this.contract).withdrawStake(slot)
|
|
95
|
-
await result.wait()
|
|
96
|
-
return true
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async withdrawn(): Promise<bigint> {
|
|
100
|
-
return await (this.contract).withdrawn()
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async withdrawnByStaker(staker: string): Promise<bigint> {
|
|
104
|
-
return await (this.contract).withdrawnByStaker(getAddress(staker))
|
|
105
|
-
}
|
|
106
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Evm.ts'
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Address, Hex, Promisable,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import { toAddress, ZERO_ADDRESS } from '@xylabs/sdk-js'
|
|
5
|
-
import type {
|
|
6
|
-
AttoXL1,
|
|
7
|
-
ChainService, XL1BlockNumber,
|
|
8
|
-
} from '@xyo-network/xl1-sdk'
|
|
9
|
-
import { AbstractCreatableProvider, ChainContractViewerMoniker } from '@xyo-network/xl1-sdk'
|
|
10
|
-
|
|
11
|
-
import type { BaseServiceParams } from '../../model/index.ts'
|
|
12
|
-
|
|
13
|
-
export interface MemoryChainViewerParams extends BaseServiceParams {
|
|
14
|
-
chainId: Hex
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A class that represents a chain stake as backed in memory
|
|
19
|
-
*/
|
|
20
|
-
export class MemoryChainViewer extends AbstractCreatableProvider<MemoryChainViewerParams> implements ChainService {
|
|
21
|
-
static readonly defaultMoniker = ChainContractViewerMoniker
|
|
22
|
-
static readonly monikers = [ChainContractViewerMoniker]
|
|
23
|
-
override moniker = MemoryChainViewer.defaultMoniker
|
|
24
|
-
|
|
25
|
-
protected _chainId: Hex | undefined
|
|
26
|
-
protected _simulatedStake: bigint = 1n
|
|
27
|
-
|
|
28
|
-
async active(): Promise<bigint> {
|
|
29
|
-
return await Promise.resolve(this._simulatedStake)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async activeByStaked(_staked: Address): Promise<bigint> {
|
|
33
|
-
return await Promise.resolve(this._simulatedStake)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async activeByStaker(_address: string): Promise<bigint> {
|
|
37
|
-
return await Promise.resolve(this._simulatedStake)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async addStake(_staked: string, _amount: bigint): Promise<boolean> {
|
|
41
|
-
return await Promise.resolve(true)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
override createHandler(): void {
|
|
45
|
-
const { minStake = 1 } = this.params.context.config.producer ?? {}
|
|
46
|
-
this._simulatedStake = BigInt(minStake)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async forkedAtBlockNumber(): Promise<bigint> {
|
|
50
|
-
return await Promise.resolve(0n)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async forkedAtHash(): Promise<bigint> {
|
|
54
|
-
return await Promise.resolve(0n)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async forkedChainId(): Promise<Address> {
|
|
58
|
-
return await Promise.resolve(ZERO_ADDRESS)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async minWithdrawalBlocks(): Promise<bigint> {
|
|
62
|
-
return await Promise.resolve(1n)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async pending(): Promise<bigint> {
|
|
66
|
-
return await Promise.resolve(0n)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async pendingByStaker(_staker: string): Promise<bigint> {
|
|
70
|
-
return await Promise.resolve(0n)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async removeStake(_slot: bigint): Promise<boolean> {
|
|
74
|
-
return await Promise.resolve(true)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
rewardForBlock(_block: XL1BlockNumber): Promisable<AttoXL1> {
|
|
78
|
-
throw new Error('Method not implemented.')
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async rewardsContract(): Promise<string> {
|
|
82
|
-
return await Promise.resolve('')
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async stakingTokenAddress(): Promise<string> {
|
|
86
|
-
return await Promise.resolve('')
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async withdrawStake(_slot: bigint): Promise<boolean> {
|
|
90
|
-
return await Promise.resolve(true)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async withdrawn(): Promise<bigint> {
|
|
94
|
-
return await Promise.resolve(0n)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async withdrawnByStaker(_staker: string): Promise<bigint> {
|
|
98
|
-
return await Promise.resolve(0n)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
protected override async startHandler(): Promise<void> {
|
|
102
|
-
await super.startHandler()
|
|
103
|
-
this._chainId = this.params.chainId ?? toAddress(1n)
|
|
104
|
-
}
|
|
105
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Memory.ts'
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { Address, Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import {
|
|
3
|
-
asAddress, assertEx, isDefined, ZERO_ADDRESS,
|
|
4
|
-
} from '@xylabs/sdk-js'
|
|
5
|
-
import type { Config, Initializable } from '@xyo-network/xl1-sdk'
|
|
6
|
-
import type { ContractRunner } from 'ethers'
|
|
7
|
-
import { Wallet } from 'ethers/wallet'
|
|
8
|
-
|
|
9
|
-
import { EvmChainViewer } from '../../ChainService/index.ts'
|
|
10
|
-
import type { BaseAccountableServiceParams } from '../../model/index.ts'
|
|
11
|
-
import { canUseEvmProvider, initEvmProvider } from '../evm/index.ts'
|
|
12
|
-
|
|
13
|
-
let chainStakeServiceSingleton: Promisable<EvmChainViewer> | undefined
|
|
14
|
-
|
|
15
|
-
export const canUseEvmContractChainService = (config: Pick<Config, 'chain' | 'evm'>) => {
|
|
16
|
-
const { id } = config.chain
|
|
17
|
-
return isDefined(id) && id !== ZERO_ADDRESS && canUseEvmProvider({ config })
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const initEvmContractChainService: Initializable<BaseAccountableServiceParams, EvmChainViewer> = async ({
|
|
21
|
-
account, context: { config }, traceProvider, meterProvider, logger,
|
|
22
|
-
}) => {
|
|
23
|
-
if (chainStakeServiceSingleton) return chainStakeServiceSingleton
|
|
24
|
-
// Parse config
|
|
25
|
-
const emvStakingContractAddress = assertEx(config.chain.id, () => 'config.chain.id is required')
|
|
26
|
-
// Configure ContractRunner
|
|
27
|
-
const id: Address = assertEx(asAddress(emvStakingContractAddress), () => 'config.chain.id is not a valid address')
|
|
28
|
-
const provider = assertEx(await initEvmProvider({ config }))
|
|
29
|
-
const privateKey = assertEx(account.private?.hex, () => 'Account does not have a private key')
|
|
30
|
-
const runner: ContractRunner = new Wallet(privateKey, provider)
|
|
31
|
-
// Create service
|
|
32
|
-
chainStakeServiceSingleton = EvmChainViewer.create({
|
|
33
|
-
id, runner, traceProvider, meterProvider, logger,
|
|
34
|
-
})
|
|
35
|
-
const result = await chainStakeServiceSingleton
|
|
36
|
-
await result.start()
|
|
37
|
-
return result
|
|
38
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
assertEx, type CreatableName, type Promisable,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import type { ChainService, Initializable } from '@xyo-network/xl1-sdk'
|
|
5
|
-
|
|
6
|
-
import { MemoryChainViewer } from '../../ChainService/index.ts'
|
|
7
|
-
import type { BaseAccountableServiceParams } from '../../model/index.ts'
|
|
8
|
-
import { canUseEvmContractChainService, initEvmContractChainService } from './evm.ts'
|
|
9
|
-
|
|
10
|
-
let chainStakeServiceSingleton: Promisable<ChainService> | undefined
|
|
11
|
-
|
|
12
|
-
export const initChainService: Initializable<BaseAccountableServiceParams,
|
|
13
|
-
ChainService> = ({ account, context }) => {
|
|
14
|
-
const { logger } = context
|
|
15
|
-
logger?.log('ChainService: Initializing...')
|
|
16
|
-
const result = init({
|
|
17
|
-
context,
|
|
18
|
-
name: 'ChainService' as CreatableName,
|
|
19
|
-
account,
|
|
20
|
-
})
|
|
21
|
-
logger?.log('ChainService: Initialized')
|
|
22
|
-
return result
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const initMemoryChainService: Initializable<BaseAccountableServiceParams, ChainService> = async ({ context }) => {
|
|
26
|
-
const result = await MemoryChainViewer.create({
|
|
27
|
-
context,
|
|
28
|
-
name: 'MemoryChainService' as CreatableName,
|
|
29
|
-
})
|
|
30
|
-
assertEx(await result.start(), () => 'Failed to start MemoryChainService')
|
|
31
|
-
return result
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const init: Initializable<BaseAccountableServiceParams,
|
|
35
|
-
ChainService> = async (params): Promise<ChainService> => {
|
|
36
|
-
if (chainStakeServiceSingleton) return chainStakeServiceSingleton
|
|
37
|
-
const { config } = params.context
|
|
38
|
-
chainStakeServiceSingleton = canUseEvmContractChainService(config)
|
|
39
|
-
? await initEvmContractChainService({ ...params, name: 'ChainStakeService' as CreatableName })
|
|
40
|
-
: await initMemoryChainService(params)
|
|
41
|
-
// Create service
|
|
42
|
-
return chainStakeServiceSingleton
|
|
43
|
-
}
|