@xyo-network/chain-services 1.14.4 → 1.15.0
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 +0 -2
- package/dist/neutral/AccountBalance/accountBalanceServiceFromArchivist.d.ts.map +1 -1
- package/dist/neutral/AccountTransfers/BaseAccountTransfersService.d.ts +16 -0
- package/dist/neutral/AccountTransfers/BaseAccountTransfersService.d.ts.map +1 -0
- package/dist/neutral/AccountTransfers/accountTransfersServiceFromArchivist.d.ts +5 -0
- package/dist/neutral/AccountTransfers/accountTransfersServiceFromArchivist.d.ts.map +1 -0
- package/dist/neutral/AccountTransfers/index.d.ts +3 -0
- package/dist/neutral/AccountTransfers/index.d.ts.map +1 -0
- package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts +13 -4
- package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts.map +1 -1
- package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts +27 -0
- package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts.map +1 -0
- package/dist/neutral/NetworkStakeStepReward/index.d.ts +2 -0
- package/dist/neutral/NetworkStakeStepReward/index.d.ts.map +1 -0
- package/dist/neutral/Time/BaseTimeSyncService.d.ts +9 -2
- package/dist/neutral/Time/BaseTimeSyncService.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +2 -1
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +296 -128
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +12 -12
- package/src/AccountBalance/BaseAccountBalanceService.ts +2 -2
- package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +0 -3
- package/src/AccountTransfers/BaseAccountTransfersService.ts +46 -0
- package/src/AccountTransfers/accountTransfersServiceFromArchivist.ts +48 -0
- package/src/AccountTransfers/index.ts +2 -0
- package/src/BlockProducer/BaseBlockProducerService.ts +44 -24
- package/src/BlockProducer/spec/BaseBlockProducerService.spec.ts +3 -3
- package/src/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.ts +66 -0
- package/src/NetworkStakeStepReward/index.ts +1 -0
- package/src/Time/BaseTimeSyncService.ts +36 -2
- package/src/index.ts +2 -1
- package/dist/neutral/Bridge/BaseBridgeService.d.ts +0 -15
- package/dist/neutral/Bridge/BaseBridgeService.d.ts.map +0 -1
- package/dist/neutral/Bridge/index.d.ts +0 -2
- package/dist/neutral/Bridge/index.d.ts.map +0 -1
- package/src/Bridge/BaseBridgeService.ts +0 -35
- package/src/Bridge/index.ts +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@xyo-network/chain-services",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.15.0",
|
|
5
5
|
"description": "XYO Layer One SDK Services",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -54,32 +54,32 @@
|
|
|
54
54
|
"@xyo-network/boundwitness-model": "~5.1.2",
|
|
55
55
|
"@xyo-network/boundwitness-validator": "~5.1.2",
|
|
56
56
|
"@xyo-network/boundwitness-wrapper": "~5.1.2",
|
|
57
|
-
"@xyo-network/chain-analyze": "~1.
|
|
58
|
-
"@xyo-network/chain-modules": "~1.
|
|
59
|
-
"@xyo-network/chain-protocol": "~1.
|
|
60
|
-
"@xyo-network/chain-utils": "~1.
|
|
57
|
+
"@xyo-network/chain-analyze": "~1.15.0",
|
|
58
|
+
"@xyo-network/chain-modules": "~1.15.0",
|
|
59
|
+
"@xyo-network/chain-protocol": "~1.15.0",
|
|
60
|
+
"@xyo-network/chain-utils": "~1.15.0",
|
|
61
61
|
"@xyo-network/payload-builder": "~5.1.2",
|
|
62
62
|
"@xyo-network/payload-model": "~5.1.2",
|
|
63
63
|
"@xyo-network/typechain": "~4.0.8",
|
|
64
|
-
"@xyo-network/xl1-protocol": "~1.12.
|
|
65
|
-
"@xyo-network/xl1-protocol-sdk": "~1.
|
|
66
|
-
"@xyo-network/xl1-validation": "~1.
|
|
67
|
-
"@xyo-network/xl1-wrappers": "~1.
|
|
64
|
+
"@xyo-network/xl1-protocol": "~1.12.32",
|
|
65
|
+
"@xyo-network/xl1-protocol-sdk": "~1.15.0",
|
|
66
|
+
"@xyo-network/xl1-validation": "~1.15.0",
|
|
67
|
+
"@xyo-network/xl1-wrappers": "~1.15.0",
|
|
68
68
|
"async-mutex": "~0.5.0",
|
|
69
69
|
"ethers": "6.15.0",
|
|
70
70
|
"lru-cache": "~11.2.1"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@types/node": "~24.
|
|
73
|
+
"@types/node": "~24.4.0",
|
|
74
74
|
"@xylabs/delay": "~5.0.11",
|
|
75
75
|
"@xylabs/ts-scripts-yarn3": "~7.1.7",
|
|
76
76
|
"@xylabs/tsconfig": "~7.1.7",
|
|
77
77
|
"@xylabs/vitest-extended": "~5.0.11",
|
|
78
78
|
"@xyo-network/account": "~5.1.2",
|
|
79
79
|
"@xyo-network/account-model": "~5.1.2",
|
|
80
|
-
"@xyo-network/chain-validation": "~1.
|
|
80
|
+
"@xyo-network/chain-validation": "~1.15.0",
|
|
81
81
|
"@xyo-network/wallet": "~5.1.2",
|
|
82
|
-
"eslint": "^9.
|
|
82
|
+
"eslint": "^9.35.0",
|
|
83
83
|
"tslib": "~2.8.1",
|
|
84
84
|
"typescript": "~5.9.2",
|
|
85
85
|
"vitest": "~3.2.4",
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from '@xyo-network/xl1-protocol'
|
|
9
9
|
import {
|
|
10
10
|
BalancesStepSummary,
|
|
11
|
-
|
|
11
|
+
balancesSummary,
|
|
12
12
|
} from '@xyo-network/xl1-protocol-sdk'
|
|
13
13
|
|
|
14
14
|
import { BaseService } from '../BaseService.ts'
|
|
@@ -23,7 +23,7 @@ export interface BaseAccountBalanceServiceParams extends BaseServiceParams {
|
|
|
23
23
|
export class BaseAccountBalanceService extends BaseService<BaseAccountBalanceServiceParams> implements AccountBalanceServiceV2 {
|
|
24
24
|
async balances(head: Hash, address: Address[]): Promise<Partial<Record<Address, AttoXL1>>> {
|
|
25
25
|
return await spanRootAsync('balances', async () => {
|
|
26
|
-
const summary = await
|
|
26
|
+
const summary = await balancesSummary({
|
|
27
27
|
chainArchivist: this.params.chainArchivist, summaryRepository: this.params.summaryRepository, head,
|
|
28
28
|
})
|
|
29
29
|
const result: Record<Address, AttoXL1> = {}
|
|
@@ -43,6 +43,3 @@ export const accountBalanceServiceFromArchivist = async (archivist: ReadArchivis
|
|
|
43
43
|
const service = await BaseAccountBalanceService.create({ chainArchivist: archivist, summaryRepository })
|
|
44
44
|
return service
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
/** @deprecated use accountBalanceServiceFromArchivist */
|
|
48
|
-
export const accountBalanceServiceFromArchivistV2 = accountBalanceServiceFromArchivist
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { creatable } from '@xylabs/creatable'
|
|
2
|
+
import { Address, Hash } from '@xylabs/hex'
|
|
3
|
+
import { Promisable } from '@xylabs/promise'
|
|
4
|
+
import { spanRootAsync } from '@xylabs/telemetry'
|
|
5
|
+
import { ReadArchivist } from '@xyo-network/archivist-model'
|
|
6
|
+
import {
|
|
7
|
+
AccountTransfersService,
|
|
8
|
+
AttoXL1, PayloadRepository,
|
|
9
|
+
} from '@xyo-network/xl1-protocol'
|
|
10
|
+
import {
|
|
11
|
+
TransfersStepSummary,
|
|
12
|
+
transfersSummary,
|
|
13
|
+
} from '@xyo-network/xl1-protocol-sdk'
|
|
14
|
+
|
|
15
|
+
import { BaseService } from '../BaseService.ts'
|
|
16
|
+
import { BaseServiceParams } from '../model/index.ts'
|
|
17
|
+
|
|
18
|
+
export interface BaseAccountTransferServiceParams extends BaseServiceParams {
|
|
19
|
+
account: Address
|
|
20
|
+
chainArchivist: ReadArchivist
|
|
21
|
+
summaryRepository: PayloadRepository<Hash, TransfersStepSummary>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@creatable()
|
|
25
|
+
export class BaseAccountTransfersService extends BaseService<BaseAccountTransferServiceParams> implements AccountTransfersService {
|
|
26
|
+
async transfer(head: Hash, address: Address): Promise<AttoXL1> {
|
|
27
|
+
return (await this.transfers(head, [address]))[address] ?? AttoXL1(0n)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async transfers(head: Hash, addresses: Address[]): Promise<Partial<Record<Address, AttoXL1>>> {
|
|
31
|
+
return await spanRootAsync('transfers', async () => {
|
|
32
|
+
const {
|
|
33
|
+
chainArchivist, summaryRepository, account,
|
|
34
|
+
} = this.params
|
|
35
|
+
const summary = await transfersSummary({
|
|
36
|
+
chainArchivist, summaryRepository, head, account,
|
|
37
|
+
})
|
|
38
|
+
const result: Record<Address, AttoXL1> = {}
|
|
39
|
+
for (const addr of addresses) {
|
|
40
|
+
const summaryBalance = summary[addr] ?? 0n
|
|
41
|
+
result[addr] = AttoXL1(summaryBalance)
|
|
42
|
+
}
|
|
43
|
+
return result
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { exists } from '@xylabs/exists'
|
|
2
|
+
import type { Address, Hash } from '@xylabs/hex'
|
|
3
|
+
import {
|
|
4
|
+
asHash,
|
|
5
|
+
isHash,
|
|
6
|
+
} from '@xylabs/hex'
|
|
7
|
+
import type { ReadArchivist } from '@xyo-network/archivist-model'
|
|
8
|
+
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
9
|
+
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
10
|
+
import type { AccountTransfersService } from '@xyo-network/xl1-protocol'
|
|
11
|
+
import type { StepSummary, TransfersStepSummary } from '@xyo-network/xl1-protocol-sdk'
|
|
12
|
+
import { LRUCache } from 'lru-cache'
|
|
13
|
+
|
|
14
|
+
import { BaseAccountTransfersService } from './BaseAccountTransfersService.ts'
|
|
15
|
+
|
|
16
|
+
export const accountTransferServiceFromArchivist = async (archivist: ReadArchivist, account: Address): Promise<AccountTransfersService> => {
|
|
17
|
+
const summaryArchivistCache = new LRUCache<Hash, WithStorageMeta<TransfersStepSummary>>({
|
|
18
|
+
max: 100_000,
|
|
19
|
+
allowStale: true,
|
|
20
|
+
noDisposeOnSet: false,
|
|
21
|
+
updateAgeOnGet: true,
|
|
22
|
+
})
|
|
23
|
+
const summaryRepository = {
|
|
24
|
+
get: (hashes: Hash[]) => {
|
|
25
|
+
const results = hashes.map((hash) => {
|
|
26
|
+
return summaryArchivistCache.get(hash)
|
|
27
|
+
}).filter(exists)
|
|
28
|
+
return results
|
|
29
|
+
},
|
|
30
|
+
insert: async (payloads: TransfersStepSummary[]) => {
|
|
31
|
+
const results = (await PayloadBuilder.addStorageMeta(payloads)).map((payload) => {
|
|
32
|
+
const hash = asHash((payload as WithStorageMeta<StepSummary>).hash)
|
|
33
|
+
if (isHash(hash)) {
|
|
34
|
+
summaryArchivistCache.set(hash, payload)
|
|
35
|
+
return payload
|
|
36
|
+
}
|
|
37
|
+
}).filter(exists)
|
|
38
|
+
return results
|
|
39
|
+
},
|
|
40
|
+
next: () => {
|
|
41
|
+
throw new Error('Not implemented')
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
const service = await BaseAccountTransfersService.create({
|
|
45
|
+
chainArchivist: archivist, account, summaryRepository,
|
|
46
|
+
})
|
|
47
|
+
return service
|
|
48
|
+
}
|
|
@@ -4,6 +4,7 @@ import { exists } from '@xylabs/exists'
|
|
|
4
4
|
import {
|
|
5
5
|
Address, Hex, hexToBigInt, toHex,
|
|
6
6
|
} from '@xylabs/hex'
|
|
7
|
+
import { isDefined } from '@xylabs/typeof'
|
|
7
8
|
import { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
8
9
|
import {
|
|
9
10
|
BlockRewardDiviner, FixedPercentageBlockRewardDiviner, FixedPercentageBlockRewardDivinerConfigSchema,
|
|
@@ -12,12 +13,10 @@ import { buildNextBlock, createDeclarationIntent } from '@xyo-network/chain-prot
|
|
|
12
13
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
13
14
|
import { WithStorageMeta } from '@xyo-network/payload-model'
|
|
14
15
|
import {
|
|
15
|
-
AccountBalanceServiceV2,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
HydratedBlock, PendingTransactionsService, SignedHydratedTransaction, StakeIntentService,
|
|
20
|
-
TimePayload, TimeSchema, TimeSyncViewInterface, Transfer,
|
|
16
|
+
AccountBalanceServiceV2, AllowedBlockPayload, asBlockBoundWitness, AttoXL1, BlockBoundWitness, BlockNumber, BlockNumberSchema, BlockProducerService,
|
|
17
|
+
ChainStakeIntent, defaultRewardRatio, HydratedBlock, PendingTransactionsService, SignedHydratedTransaction, StakeIntentService, TimePayload, TimeSchema,
|
|
18
|
+
TimeSyncViewInterfaceV2, Transfer,
|
|
19
|
+
XYO_STEP_REWARD_ADDRESS,
|
|
21
20
|
} from '@xyo-network/xl1-protocol'
|
|
22
21
|
|
|
23
22
|
import { BaseService } from '../BaseService.ts'
|
|
@@ -29,9 +28,9 @@ import { generateTransactionFeeTransfers } from './generateTransactionFeeTransfe
|
|
|
29
28
|
*/
|
|
30
29
|
export const DEFAULT_BLOCK_SIZE = 10
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The amount of time for which a producer will restake their intent
|
|
33
|
+
*/
|
|
35
34
|
export const XYO_PRODUCER_REDECLARATION_DURATION = 10_000
|
|
36
35
|
|
|
37
36
|
/**
|
|
@@ -45,7 +44,7 @@ export interface BaseBlockProducerServiceParams extends XyoValidatorParams {
|
|
|
45
44
|
pendingTransactionsService: PendingTransactionsService
|
|
46
45
|
rejectedTransactionsArchivist: ArchivistInstance
|
|
47
46
|
rewardAddress: Address
|
|
48
|
-
time:
|
|
47
|
+
time: TimeSyncViewInterfaceV2
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
@creatable()
|
|
@@ -119,7 +118,7 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
|
|
|
119
118
|
return assertEx(this.params.stakeIntentService, () => 'No StakeIntentService provided')
|
|
120
119
|
}
|
|
121
120
|
|
|
122
|
-
protected get time():
|
|
121
|
+
protected get time(): TimeSyncViewInterfaceV2 {
|
|
123
122
|
return assertEx(this.params.time, () => 'No TimeSyncViewInterface provided')
|
|
124
123
|
}
|
|
125
124
|
|
|
@@ -138,7 +137,7 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
|
|
|
138
137
|
return this.proposeNextValidBlock(head)
|
|
139
138
|
}
|
|
140
139
|
|
|
141
|
-
protected async
|
|
140
|
+
protected async getBlockRewardTransfers(block: number): Promise<Transfer[]> {
|
|
142
141
|
if (!this._blockRewardDiviner) {
|
|
143
142
|
// TODO: Adjust to allow for genesis block reward vs. normal block reward
|
|
144
143
|
this._blockRewardDiviner = await FixedPercentageBlockRewardDiviner.create({
|
|
@@ -154,8 +153,7 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
|
|
|
154
153
|
const blockHex = assertEx(toHex(block), () => 'Failed to convert block to hex')
|
|
155
154
|
const blockId = new PayloadBuilder<BlockNumber>({ schema: BlockNumberSchema }).fields({ block: blockHex }).build()
|
|
156
155
|
const rewards = await this._blockRewardDiviner.divine([blockId])
|
|
157
|
-
|
|
158
|
-
return reward as Transfer | undefined
|
|
156
|
+
return rewards as Transfer[]
|
|
159
157
|
}
|
|
160
158
|
|
|
161
159
|
/**
|
|
@@ -193,15 +191,15 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
|
|
|
193
191
|
const producerRedeclarationPayload = await this.getProducerRedeclaration(head)
|
|
194
192
|
if (producerRedeclarationPayload) blockPayloads.push(producerRedeclarationPayload)
|
|
195
193
|
|
|
196
|
-
// If there are no transactions and no
|
|
197
|
-
if (blockPayloads.length === 0 && nextBlockTransactions.length === 0) return
|
|
194
|
+
// If there are no transactions, no payloads and no heartbeat required, we don't need to create a block
|
|
195
|
+
if (blockPayloads.length === 0 && nextBlockTransactions.length === 0 && !this.heartbeatRequired(head)) return
|
|
198
196
|
|
|
199
197
|
// Calculate the optional block reward transfer and add if necessary
|
|
200
|
-
const
|
|
201
|
-
|
|
198
|
+
const rewardTransferPayloads = await this.getBlockRewardTransfers(nextBlock)
|
|
199
|
+
blockPayloads.push(...rewardTransferPayloads)
|
|
202
200
|
|
|
203
201
|
const transactionTransfers = await generateTransactionFeeTransfers(this.address, nextBlockTransactions)
|
|
204
|
-
const timePayload = await this.generateTimePayload(
|
|
202
|
+
const timePayload = await this.generateTimePayload(head)
|
|
205
203
|
|
|
206
204
|
const [fundedNextBlockTransactions, fundedTransfers] = await this.filterByFunded(head, nextBlockTransactions, transactionTransfers, validateBalances)
|
|
207
205
|
|
|
@@ -210,7 +208,8 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
|
|
|
210
208
|
// Build the block
|
|
211
209
|
this.logger?.info(`Building block ${head.block + 1}`)
|
|
212
210
|
const startBuild = Date.now()
|
|
213
|
-
const
|
|
211
|
+
const stepRewardPoolBalance = (await this.balanceService.balances(head._hash, [XYO_STEP_REWARD_ADDRESS]))[XYO_STEP_REWARD_ADDRESS]
|
|
212
|
+
const block = await buildNextBlock(head, fundedNextBlockTransactions, blockPayloads, [this.account], XYO_STEP_REWARD_ADDRESS, stepRewardPoolBalance)
|
|
214
213
|
|
|
215
214
|
this.logger?.info(
|
|
216
215
|
`Built block ${block[0].block} in ${Date.now() - startBuild}ms with ${block[1].length} payloads`,
|
|
@@ -259,14 +258,35 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
|
|
|
259
258
|
return [fundedTransactions, fundedTransfers]
|
|
260
259
|
}
|
|
261
260
|
|
|
262
|
-
private async generateTimePayload(
|
|
261
|
+
private async generateTimePayload(head: WithStorageMeta<BlockBoundWitness>) {
|
|
262
|
+
const [ethereum, ethHashOrNull] = await this.time.currentTimeAndHash('ethereum')
|
|
263
|
+
const ethereumHash = assertEx(ethHashOrNull, () => 'No ethereum hash available from time sync service')
|
|
263
264
|
const timePayload: TimePayload = {
|
|
264
265
|
schema: TimeSchema,
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
266
|
+
// note, this is for the previous block
|
|
267
|
+
xl1: head.block,
|
|
268
|
+
// note, this is for the previous block
|
|
269
|
+
xl1Hash: head._hash,
|
|
270
|
+
ethereum,
|
|
271
|
+
ethereumHash,
|
|
268
272
|
epoch: Date.now(),
|
|
269
273
|
}
|
|
270
274
|
return timePayload
|
|
271
275
|
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Check if a heartbeat block is required based on network activity.
|
|
279
|
+
* @param head The current head block
|
|
280
|
+
* @returns True if a heartbeat is required, false otherwise
|
|
281
|
+
*/
|
|
282
|
+
private heartbeatRequired(head: WithStorageMeta<BlockBoundWitness>): boolean {
|
|
283
|
+
const epoch = head.$epoch
|
|
284
|
+
if (isDefined(epoch)) {
|
|
285
|
+
const { heartbeatInterval } = this.params.config.producer
|
|
286
|
+
if (Date.now() - epoch > heartbeatInterval) {
|
|
287
|
+
return true
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return false
|
|
291
|
+
}
|
|
272
292
|
}
|
|
@@ -23,7 +23,7 @@ import type {
|
|
|
23
23
|
HydratedBlock,
|
|
24
24
|
HydratedBlockStateValidationFunctionV2,
|
|
25
25
|
StakeIntentService,
|
|
26
|
-
|
|
26
|
+
TimeSyncViewInterfaceV2,
|
|
27
27
|
} from '@xyo-network/xl1-protocol'
|
|
28
28
|
import {
|
|
29
29
|
asBlockBoundWitness,
|
|
@@ -61,7 +61,7 @@ describe('XyoBlockProducer', () => {
|
|
|
61
61
|
let rewardAddress = '1111111111111111111111111111111111111111' as Address
|
|
62
62
|
let rewardService: BlockRewardService
|
|
63
63
|
let stakeIntentService: ReturnType<typeof mock<StakeIntentService>>
|
|
64
|
-
let time:
|
|
64
|
+
let time: TimeSyncViewInterfaceV2
|
|
65
65
|
let transactionAccount: AccountInstance
|
|
66
66
|
const validPendingTransactions = Math.ceil(BaseBlockProducerService.DefaultBlockSize)
|
|
67
67
|
let config: Config
|
|
@@ -95,7 +95,7 @@ describe('XyoBlockProducer', () => {
|
|
|
95
95
|
|
|
96
96
|
stakeIntentService = mock<StakeIntentService>()
|
|
97
97
|
stakeIntentService.getDeclaredCandidateRanges.mockResolvedValue([])
|
|
98
|
-
time = mock<
|
|
98
|
+
time = mock<TimeSyncViewInterfaceV2>()
|
|
99
99
|
rewardService = await MemoryBlockRewardService.create()
|
|
100
100
|
const balanceService = await accountBalanceServiceFromArchivist(chainArchivist)
|
|
101
101
|
const params: BaseBlockProducerServiceParams = {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { creatable } from '@xylabs/creatable'
|
|
2
|
+
import { Address } from '@xylabs/hex'
|
|
3
|
+
import { Promisable } from '@xylabs/promise'
|
|
4
|
+
import { ReadArchivist } from '@xyo-network/archivist-model'
|
|
5
|
+
import { EventingChainBlockNumberIteratorService, NetworkStakeStepRewardService } from '@xyo-network/xl1-protocol'
|
|
6
|
+
import { Provider } from 'ethers'
|
|
7
|
+
|
|
8
|
+
import { BaseService } from '../BaseService.ts'
|
|
9
|
+
import { BaseServiceParams } from '../model/index.ts'
|
|
10
|
+
|
|
11
|
+
export interface BaseNetworkStakeStepRewardServiceParams extends BaseServiceParams {
|
|
12
|
+
chainArchivist: ReadArchivist
|
|
13
|
+
chainIterator: EventingChainBlockNumberIteratorService
|
|
14
|
+
ethProvider?: Provider
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@creatable()
|
|
18
|
+
export class BaseNetworkStakeStepRewardService extends BaseService<BaseNetworkStakeStepRewardServiceParams> implements NetworkStakeStepRewardService {
|
|
19
|
+
claimedRewards(address: Address): Promisable<bigint> {
|
|
20
|
+
throw new Error('Method not implemented.')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
networkStakeStepAddressReward(address: Address, step: number, block: number): Promisable<Record<Address, bigint>> {
|
|
24
|
+
throw new Error('Method not implemented.')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
networkStakeStepPoolRewardShares(step: number, block: number): Promisable<Record<Address, bigint>> {
|
|
28
|
+
throw new Error('Method not implemented.')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
networkStakeStepPoolRewards(step: number, block: number): Promisable<Record<Address, bigint>> {
|
|
32
|
+
throw new Error('Method not implemented.')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
networkStakeStepRewardAddressHistory(address: Address): Promisable<Record<Address, bigint>> {
|
|
36
|
+
throw new Error('Method not implemented.')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
networkStakeStepRewardAddressShare(address: Address, step: number, block: number): Promisable<[bigint, bigint]> {
|
|
40
|
+
throw new Error('Method not implemented.')
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
networkStakeStepRewardForStep(step: number): Promisable<bigint> {
|
|
44
|
+
throw new Error('Method not implemented.')
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
networkStakeStepRewardPositionWeight(position: bigint, step: number): Promisable<number> {
|
|
48
|
+
throw new Error('Method not implemented.')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
networkStakeStepRewardPotentialPositionLoss(position: bigint, step: number): Promisable<bigint> {
|
|
52
|
+
throw new Error('Method not implemented.')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
networkStakeStepRewardRandomizer(step: number, block: number): Promisable<bigint> {
|
|
56
|
+
throw new Error('Method not implemented.')
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
networkStakeStepRewardWeightForAddress(address: Address, step: number): Promisable<bigint> {
|
|
60
|
+
throw new Error('Method not implemented.')
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
unclaimedRewards(address: Address): Promisable<bigint> {
|
|
64
|
+
throw new Error('Method not implemented.')
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './BaseNetworkStakeStepRewardService.ts'
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import { creatable } from '@xylabs/creatable'
|
|
3
|
+
import { asHash, Hash } from '@xylabs/hex'
|
|
4
|
+
import { Promisable } from '@xylabs/promise'
|
|
3
5
|
import { ReadArchivist } from '@xyo-network/archivist-model'
|
|
6
|
+
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
4
7
|
import {
|
|
5
8
|
asTimePayload,
|
|
6
|
-
EventingChainBlockNumberIteratorService, TimeDomain,
|
|
9
|
+
EventingChainBlockNumberIteratorService, TimeDomain, TimePayload, TimeSchema,
|
|
10
|
+
TimeSyncServiceV2,
|
|
7
11
|
} from '@xyo-network/xl1-protocol'
|
|
8
12
|
import { Provider } from 'ethers'
|
|
9
13
|
|
|
10
14
|
import { BaseService } from '../BaseService.ts'
|
|
11
15
|
import { BaseServiceParams } from '../model/index.ts'
|
|
12
16
|
|
|
17
|
+
export interface TimeProvider {
|
|
18
|
+
currentTime(): Promise<[string, number]>
|
|
19
|
+
}
|
|
20
|
+
|
|
13
21
|
export interface BaseTimeServiceParams extends BaseServiceParams {
|
|
14
22
|
chainArchivist: ReadArchivist
|
|
15
23
|
chainIterator: EventingChainBlockNumberIteratorService
|
|
@@ -17,7 +25,7 @@ export interface BaseTimeServiceParams extends BaseServiceParams {
|
|
|
17
25
|
}
|
|
18
26
|
|
|
19
27
|
@creatable()
|
|
20
|
-
export class BaseTimeSyncService extends BaseService<BaseTimeServiceParams> implements
|
|
28
|
+
export class BaseTimeSyncService extends BaseService<BaseTimeServiceParams> implements TimeSyncServiceV2 {
|
|
21
29
|
get chainArchivist() {
|
|
22
30
|
return this.params.chainArchivist
|
|
23
31
|
}
|
|
@@ -76,4 +84,30 @@ export class BaseTimeSyncService extends BaseService<BaseTimeServiceParams> impl
|
|
|
76
84
|
}
|
|
77
85
|
}
|
|
78
86
|
}
|
|
87
|
+
|
|
88
|
+
async currentTimeAndHash(domain: TimeDomain): Promise<[number, Hash | null]> {
|
|
89
|
+
switch (domain) {
|
|
90
|
+
case 'xl1': {
|
|
91
|
+
const head = await this.chainIterator.head()
|
|
92
|
+
return [head.block, await PayloadBuilder.hash(head)]
|
|
93
|
+
}
|
|
94
|
+
case 'epoch': {
|
|
95
|
+
return [Date.now(), null]
|
|
96
|
+
}
|
|
97
|
+
case 'ethereum': {
|
|
98
|
+
const provider = assertEx(this.ethProvider, () => 'Ethereum provider not configured')
|
|
99
|
+
const blockNumber = (await provider.getBlockNumber()) ?? 0
|
|
100
|
+
const block = await provider.getBlock(blockNumber)
|
|
101
|
+
const blockHash = asHash(assertEx(block?.hash, () => 'Block hash not found'), true)
|
|
102
|
+
return [blockNumber, blockHash]
|
|
103
|
+
}
|
|
104
|
+
default: {
|
|
105
|
+
throw new Error(`Unknown time domain: ${domain}`)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
currentTimePayload(): Promisable<TimePayload> {
|
|
111
|
+
throw new Error('Method not implemented.')
|
|
112
|
+
}
|
|
79
113
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export * from './AccountBalance/index.ts'
|
|
2
|
+
export * from './AccountTransfers/index.ts'
|
|
2
3
|
export * from './BaseService.ts'
|
|
3
4
|
export * from './BlockProducer/index.ts'
|
|
4
5
|
export * from './BlockReward/index.ts'
|
|
5
|
-
export * from './Bridge/index.ts'
|
|
6
6
|
export * from './ChainBlockNumberIteration/index.ts'
|
|
7
7
|
export * from './ChainService/index.ts'
|
|
8
8
|
export * from './ChainValidator/index.ts'
|
|
9
9
|
export * from './Election/index.ts'
|
|
10
10
|
export * from './model/index.ts'
|
|
11
|
+
export * from './NetworkStakeStepReward/index.ts'
|
|
11
12
|
export * from './PendingTransactions/index.ts'
|
|
12
13
|
export * from './StakeIntent/index.ts'
|
|
13
14
|
export * from './StepStake/index.ts'
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Promisable } from '@xylabs/promise';
|
|
2
|
-
import { ReadArchivist } from '@xyo-network/archivist-model';
|
|
3
|
-
import { BridgeBack, BridgeComplete, BridgeRequest, BridgeService } from '@xyo-network/xl1-protocol';
|
|
4
|
-
import { BaseService } from '../BaseService.ts';
|
|
5
|
-
import { BaseServiceParams } from '../model/index.ts';
|
|
6
|
-
export interface BaseBridgeServiceParams extends BaseServiceParams {
|
|
7
|
-
chainArchivist: ReadArchivist;
|
|
8
|
-
}
|
|
9
|
-
export declare class BaseBridgeService extends BaseService<BaseBridgeServiceParams> implements BridgeService {
|
|
10
|
-
completedBridgeBack(): Promisable<BridgeBack[]>;
|
|
11
|
-
completedBridgeRequests(): Promisable<[BridgeRequest, BridgeComplete][]>;
|
|
12
|
-
pendingBridgeBack(): Promisable<BridgeBack[]>;
|
|
13
|
-
pendingBridgeRequests(): Promisable<BridgeRequest[]>;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=BaseBridgeService.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseBridgeService.d.ts","sourceRoot":"","sources":["../../../src/Bridge/BaseBridgeService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAC5D,OAAO,EACL,UAAU,EACV,cAAc,EACd,aAAa,EACb,aAAa,EACd,MAAM,2BAA2B,CAAA;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAErD,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,cAAc,EAAE,aAAa,CAAA;CAC9B;AAED,qBACa,iBAAkB,SAAQ,WAAW,CAAC,uBAAuB,CAAE,YAAW,aAAa;IAClG,mBAAmB,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;IAI/C,uBAAuB,IAAI,UAAU,CAAC,CAAC,aAAa,EAAE,cAAc,CAAC,EAAE,CAAC;IAIxE,iBAAiB,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;IAI7C,qBAAqB,IAAI,UAAU,CAAC,aAAa,EAAE,CAAC;CAGrD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Bridge/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { creatable } from '@xylabs/creatable'
|
|
2
|
-
import { Promisable } from '@xylabs/promise'
|
|
3
|
-
import { ReadArchivist } from '@xyo-network/archivist-model'
|
|
4
|
-
import {
|
|
5
|
-
BridgeBack,
|
|
6
|
-
BridgeComplete,
|
|
7
|
-
BridgeRequest,
|
|
8
|
-
BridgeService,
|
|
9
|
-
} from '@xyo-network/xl1-protocol'
|
|
10
|
-
|
|
11
|
-
import { BaseService } from '../BaseService.ts'
|
|
12
|
-
import { BaseServiceParams } from '../model/index.ts'
|
|
13
|
-
|
|
14
|
-
export interface BaseBridgeServiceParams extends BaseServiceParams {
|
|
15
|
-
chainArchivist: ReadArchivist
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@creatable()
|
|
19
|
-
export class BaseBridgeService extends BaseService<BaseBridgeServiceParams> implements BridgeService {
|
|
20
|
-
completedBridgeBack(): Promisable<BridgeBack[]> {
|
|
21
|
-
throw new Error('Method not implemented.')
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
completedBridgeRequests(): Promisable<[BridgeRequest, BridgeComplete][]> {
|
|
25
|
-
throw new Error('Method not implemented.')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
pendingBridgeBack(): Promisable<BridgeBack[]> {
|
|
29
|
-
throw new Error('Method not implemented.')
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
pendingBridgeRequests(): Promisable<BridgeRequest[]> {
|
|
33
|
-
throw new Error('Method not implemented.')
|
|
34
|
-
}
|
|
35
|
-
}
|
package/src/Bridge/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './BaseBridgeService.ts'
|