@xyo-network/xl1-protocol-sdk 1.16.22 → 1.16.24
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/ChainServiceCollectionV2.d.ts +3 -3
- package/dist/neutral/ChainServiceCollectionV2.d.ts.map +1 -1
- package/dist/neutral/block/primitives/index.d.ts +0 -1
- package/dist/neutral/block/primitives/index.d.ts.map +1 -1
- package/dist/neutral/config/Chain.d.ts +1 -0
- package/dist/neutral/config/Chain.d.ts.map +1 -1
- package/dist/neutral/config/Config.d.ts +10 -3
- package/dist/neutral/config/Config.d.ts.map +1 -1
- package/dist/neutral/config/Services.d.ts +6 -0
- package/dist/neutral/config/Services.d.ts.map +1 -0
- package/dist/neutral/config/Telemetry.d.ts +16 -0
- package/dist/neutral/config/Telemetry.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +1 -0
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +859 -303
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/model/summary.d.ts +5 -0
- package/dist/neutral/model/summary.d.ts.map +1 -1
- package/dist/neutral/payloads/index.d.ts +1 -0
- package/dist/neutral/payloads/index.d.ts.map +1 -1
- package/dist/neutral/payloads/netSchemasForPayloads.d.ts +4 -0
- package/dist/neutral/payloads/netSchemasForPayloads.d.ts.map +1 -0
- package/dist/neutral/payloads/summary/SchemasStepSummary.d.ts +18 -0
- package/dist/neutral/payloads/summary/SchemasStepSummary.d.ts.map +1 -0
- package/dist/neutral/payloads/summary/index.d.ts +1 -0
- package/dist/neutral/payloads/summary/index.d.ts.map +1 -1
- package/dist/neutral/primitives/summary/index.d.ts +2 -1
- package/dist/neutral/primitives/summary/index.d.ts.map +1 -1
- package/dist/neutral/primitives/summary/schemas/index.d.ts +3 -0
- package/dist/neutral/primitives/summary/schemas/index.d.ts.map +1 -0
- package/dist/neutral/primitives/summary/schemas/schemasStepSummaryFromRange.d.ts +6 -0
- package/dist/neutral/primitives/summary/schemas/schemasStepSummaryFromRange.d.ts.map +1 -0
- package/dist/neutral/primitives/summary/schemas/schemasSummary.d.ts +4 -0
- package/dist/neutral/primitives/summary/schemas/schemasSummary.d.ts.map +1 -0
- package/dist/neutral/primitives/summary/transfers/transfersStepSummaryFromRange.d.ts.map +1 -1
- package/dist/neutral/primitives/summary/transfers/transfersSummary.d.ts +3 -2
- package/dist/neutral/primitives/summary/transfers/transfersSummary.d.ts.map +1 -1
- package/dist/neutral/primitives/timeBudget.d.ts +1 -1
- package/dist/neutral/primitives/timeBudget.d.ts.map +1 -1
- package/dist/neutral/provider/viewer/XyoViewer.d.ts +2 -2
- package/dist/neutral/provider/viewer/XyoViewer.d.ts.map +1 -1
- package/dist/neutral/services/SchemasService.d.ts +9 -0
- package/dist/neutral/services/SchemasService.d.ts.map +1 -0
- package/dist/neutral/services/StakeIntentService/ChainIndexingServiceStateSchema.d.ts +2 -2
- package/dist/neutral/services/StakeIntentService/ChainIndexingServiceStateSchema.d.ts.map +1 -1
- package/dist/neutral/services/index.d.ts +1 -1
- package/dist/neutral/services/index.d.ts.map +1 -1
- package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts +2 -2
- package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts.map +1 -1
- package/dist/neutral/validation/block/HydratedBlockStateValidationFunction.d.ts +2 -2
- package/dist/neutral/validation/block/HydratedBlockStateValidationFunction.d.ts.map +1 -1
- package/dist/neutral/viewers/AccountBalance.d.ts +62 -14
- package/dist/neutral/viewers/AccountBalance.d.ts.map +1 -1
- package/dist/neutral/zod/ArrayBuffer.d.ts +4 -0
- package/dist/neutral/zod/ArrayBuffer.d.ts.map +1 -0
- package/dist/neutral/zod/BlockBoundWitness.d.ts +44 -0
- package/dist/neutral/zod/BlockBoundWitness.d.ts.map +1 -0
- package/dist/neutral/zod/BoundWitness.d.ts +123 -0
- package/dist/neutral/zod/BoundWitness.d.ts.map +1 -0
- package/dist/neutral/zod/Chain.d.ts +4 -0
- package/dist/neutral/zod/Chain.d.ts.map +1 -0
- package/dist/neutral/zod/HydratedBlock.d.ts +133 -0
- package/dist/neutral/zod/HydratedBlock.d.ts.map +1 -0
- package/dist/neutral/zod/HydratedTransaction.d.ts +210 -0
- package/dist/neutral/zod/HydratedTransaction.d.ts.map +1 -0
- package/dist/neutral/zod/Permission.d.ts +53 -0
- package/dist/neutral/zod/Permission.d.ts.map +1 -0
- package/dist/neutral/zod/RewardsRangeOptions.d.ts +11 -0
- package/dist/neutral/zod/RewardsRangeOptions.d.ts.map +1 -0
- package/dist/neutral/zod/Sequence.d.ts +9 -0
- package/dist/neutral/zod/Sequence.d.ts.map +1 -0
- package/dist/neutral/zod/Stake.d.ts +62 -0
- package/dist/neutral/zod/Stake.d.ts.map +1 -0
- package/dist/neutral/zod/TimeDomain.d.ts +3 -0
- package/dist/neutral/zod/TimeDomain.d.ts.map +1 -0
- package/dist/neutral/zod/TransactionBoundWitness.d.ts +75 -0
- package/dist/neutral/zod/TransactionBoundWitness.d.ts.map +1 -0
- package/dist/neutral/zod/TransactionFees.d.ts +53 -0
- package/dist/neutral/zod/TransactionFees.d.ts.map +1 -0
- package/dist/neutral/zod/TransferPair.d.ts +3 -0
- package/dist/neutral/zod/TransferPair.d.ts.map +1 -0
- package/dist/neutral/zod/index.d.ts +15 -0
- package/dist/neutral/zod/index.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/ChainServiceCollectionV2.ts +3 -3
- package/src/block/primitives/index.ts +0 -1
- package/src/config/Chain.ts +8 -0
- package/src/config/Config.ts +2 -2
- package/src/config/Services.ts +12 -0
- package/src/config/Telemetry.ts +19 -0
- package/src/index.ts +1 -0
- package/src/model/summary.ts +5 -0
- package/src/payloads/index.ts +1 -0
- package/src/payloads/netSchemasForPayloads.ts +22 -0
- package/src/payloads/summary/SchemasStepSummary.ts +26 -0
- package/src/payloads/summary/index.ts +1 -0
- package/src/primitives/summary/balances/balancesSummary.ts +1 -1
- package/src/primitives/summary/index.ts +2 -1
- package/src/primitives/summary/schemas/index.ts +2 -0
- package/src/primitives/summary/schemas/schemasStepSummaryFromRange.ts +83 -0
- package/src/primitives/summary/schemas/schemasSummary.ts +33 -0
- package/src/primitives/summary/transfers/transfersStepSummaryFromRange.ts +8 -6
- package/src/primitives/summary/transfers/transfersSummary.ts +11 -7
- package/src/primitives/timeBudget.ts +21 -2
- package/src/provider/viewer/XyoViewer.ts +2 -1
- package/src/services/SchemasService.ts +9 -0
- package/src/services/index.ts +1 -1
- package/src/simple/accountBalance/SimpleAccountBalanceViewer.ts +5 -5
- package/src/simple/chainStake/SimpleChainStakeViewer.ts +1 -1
- package/src/validation/block/HydratedBlockStateValidationFunction.ts +2 -2
- package/src/viewers/AccountBalance.ts +19 -17
- package/src/zod/ArrayBuffer.ts +42 -0
- package/src/zod/BlockBoundWitness.ts +36 -0
- package/src/zod/BoundWitness.ts +56 -0
- package/src/zod/Chain.ts +5 -0
- package/src/zod/HydratedBlock.ts +32 -0
- package/src/zod/HydratedTransaction.ts +37 -0
- package/src/zod/Permission.ts +23 -0
- package/src/zod/RewardsRangeOptions.ts +10 -0
- package/src/zod/Sequence.ts +15 -0
- package/src/zod/Stake.ts +43 -0
- package/src/zod/TimeDomain.ts +7 -0
- package/src/zod/TransactionBoundWitness.ts +42 -0
- package/src/zod/TransactionFees.ts +45 -0
- package/src/zod/TransferPair.ts +6 -0
- package/src/zod/index.ts +14 -0
- package/dist/neutral/block/primitives/transfers/index.d.ts +0 -3
- package/dist/neutral/block/primitives/transfers/index.d.ts.map +0 -1
- package/dist/neutral/block/primitives/transfers/transfersStepSummaryFromRange.d.ts +0 -6
- package/dist/neutral/block/primitives/transfers/transfersStepSummaryFromRange.d.ts.map +0 -1
- package/dist/neutral/block/primitives/transfers/transfersSummary.d.ts +0 -5
- package/dist/neutral/block/primitives/transfers/transfersSummary.d.ts.map +0 -1
- package/dist/neutral/config/App.d.ts +0 -6
- package/dist/neutral/config/App.d.ts.map +0 -1
- package/dist/neutral/services/AccountBalanceService.d.ts +0 -4
- package/dist/neutral/services/AccountBalanceService.d.ts.map +0 -1
- package/src/block/primitives/transfers/index.ts +0 -2
- package/src/block/primitives/transfers/transfersStepSummaryFromRange.ts +0 -98
- package/src/block/primitives/transfers/transfersSummary.ts +0 -44
- package/src/config/App.ts +0 -13
- package/src/services/AccountBalanceService.ts +0 -4
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-statements */
|
|
2
|
-
import { type Address } from '@xylabs/sdk-js'
|
|
3
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
4
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
5
|
-
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
6
|
-
import { isAnyPayload } from '@xyo-network/payload-model'
|
|
7
|
-
import type { XL1BlockRange } from '@xyo-network/xl1-protocol'
|
|
8
|
-
import { StepSizes } from '@xyo-network/xl1-protocol'
|
|
9
|
-
|
|
10
|
-
import type { TransfersStepSummaryContext } from '../../../model/index.ts'
|
|
11
|
-
import type { TransfersStepSummary } from '../../../payloads/index.ts'
|
|
12
|
-
import { netTransfersForPayloads, TransfersStepSummarySchema } from '../../../payloads/index.ts'
|
|
13
|
-
import {
|
|
14
|
-
parseSignedBigInt, type SignedBigInt, toSignedBigInt,
|
|
15
|
-
} from '../../../SignedBigInt.ts'
|
|
16
|
-
import { hydrateBlock } from '../../hydrate/index.ts'
|
|
17
|
-
import { deepCalculateFramesFromRange } from '../frames/index.ts'
|
|
18
|
-
import { hashFromBlockNumber } from '../hashFromBlockNumber.ts'
|
|
19
|
-
import { transfersSummaryKey } from './transfersSummary.ts'
|
|
20
|
-
|
|
21
|
-
export async function transfersStepSummaryFromRange(
|
|
22
|
-
context: TransfersStepSummaryContext,
|
|
23
|
-
range: XL1BlockRange,
|
|
24
|
-
): Promise<WithStorageMeta<TransfersStepSummary>> {
|
|
25
|
-
// console.log(`transfersStepSummaryFromRange: head=${context.head}, range=${range[0]}-${range[1]}`)
|
|
26
|
-
const frameHeadHash = await hashFromBlockNumber(context, range[1])
|
|
27
|
-
const frameSize = range[1] - range[0] + 1
|
|
28
|
-
const [headHash] = await context.head()
|
|
29
|
-
|
|
30
|
-
let result: TransfersStepSummary | undefined = undefined
|
|
31
|
-
|
|
32
|
-
if (frameSize === 1) {
|
|
33
|
-
const hash = await hashFromBlockNumber(context, range[0])
|
|
34
|
-
const [, payloads] = await hydrateBlock(context.store, hash)
|
|
35
|
-
const transfers: Record<Address, Record<Address, SignedBigInt>> = {}
|
|
36
|
-
for (const [from, toMap] of Object.entries(netTransfersForPayloads(payloads))) {
|
|
37
|
-
transfers[from as Address] = transfers[from as Address] ?? {}
|
|
38
|
-
for (const [to, amount] of Object.entries(toMap)) {
|
|
39
|
-
transfers[from as Address][to as Address] = toSignedBigInt(amount)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
result = {
|
|
43
|
-
schema: TransfersStepSummarySchema, hash: headHash, stepSize: -1, transfers,
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
-
const step = (StepSizes as any).indexOf(frameSize)
|
|
48
|
-
assertEx(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes.join(', ')}`)
|
|
49
|
-
|
|
50
|
-
const key = transfersSummaryKey(frameHeadHash, frameSize)
|
|
51
|
-
|
|
52
|
-
const summaryResult = await context.summaryMap.get(key)
|
|
53
|
-
if (isAnyPayload(summaryResult)) {
|
|
54
|
-
result = summaryResult as WithStorageMeta<TransfersStepSummary>
|
|
55
|
-
} else {
|
|
56
|
-
await context.stepSemaphores[step].acquire()
|
|
57
|
-
// We do not have it, so lets build it
|
|
58
|
-
try {
|
|
59
|
-
const subRanges = deepCalculateFramesFromRange(range, step - 1)
|
|
60
|
-
const promises = subRanges.map(subRange => transfersStepSummaryFromRange(
|
|
61
|
-
context,
|
|
62
|
-
subRange,
|
|
63
|
-
))
|
|
64
|
-
const subResults = await Promise.all(promises)
|
|
65
|
-
|
|
66
|
-
// add them all up
|
|
67
|
-
const bigIntBalances: Record<Address, Record<Address, bigint>> = {}
|
|
68
|
-
for (const subResult of subResults) {
|
|
69
|
-
for (const [from, toMap] of Object.entries(subResult.transfers)) {
|
|
70
|
-
bigIntBalances[from as Address] = bigIntBalances[from as Address] ?? {}
|
|
71
|
-
for (const [to, transfer] of Object.entries(toMap)) {
|
|
72
|
-
bigIntBalances[from as Address][to as Address] = (bigIntBalances[from as Address][to as Address] ?? 0n) + parseSignedBigInt(transfer)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const transfers: Record<Address, Record<Address, SignedBigInt>> = {}
|
|
78
|
-
for (const [from, toMap] of Object.entries(bigIntBalances)) {
|
|
79
|
-
transfers[from as Address] = transfers[from as Address] ?? {}
|
|
80
|
-
for (const [to, transfer] of Object.entries(toMap)) {
|
|
81
|
-
transfers[from as Address][to as Address] = toSignedBigInt(transfer)
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
result = {
|
|
86
|
-
schema: TransfersStepSummarySchema, hash: frameHeadHash, stepSize: frameSize, transfers,
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
await context.summaryMap.set(key, result)
|
|
90
|
-
} finally {
|
|
91
|
-
context.stepSemaphores[step].release()
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
// console.log(`transfersStepSummaryFromRange-result: head=${context.head}, range=${range[0]}-${range[1]}: ${toSafeJsonString(result, 10)}`)
|
|
96
|
-
const finalResult = await PayloadBuilder.addStorageMeta(result)
|
|
97
|
-
return finalResult
|
|
98
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { Address, Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import { asAddress, isDefined } from '@xylabs/sdk-js'
|
|
3
|
-
import { spanRootAsync } from '@xylabs/telemetry'
|
|
4
|
-
import {
|
|
5
|
-
asBlockBoundWitnessWithStorageMeta, asXL1BlockNumber, asXL1BlockRange,
|
|
6
|
-
} from '@xyo-network/xl1-protocol'
|
|
7
|
-
|
|
8
|
-
import type { TransfersStepSummaryContext } from '../../../model/index.ts'
|
|
9
|
-
import { parseSignedBigInt } from '../../../SignedBigInt.ts'
|
|
10
|
-
import { deepCalculateFramesFromRange } from '../frames/index.ts'
|
|
11
|
-
import { transfersStepSummaryFromRange } from './transfersStepSummaryFromRange.ts'
|
|
12
|
-
|
|
13
|
-
// the summary of amount of rewards claimed from the step reward pool by addresses
|
|
14
|
-
export async function transfersSummary(
|
|
15
|
-
transferContext: TransfersStepSummaryContext,
|
|
16
|
-
): Promise<Partial<Record<Address, Partial<Record<Address, bigint>>>>> {
|
|
17
|
-
return await spanRootAsync('transferSummary', async () => {
|
|
18
|
-
const [headHash] = await transferContext.head()
|
|
19
|
-
const headResult = await transferContext.store.chainMap.get(headHash)
|
|
20
|
-
const headBoundWitness = asBlockBoundWitnessWithStorageMeta(headResult, () => `Head block not found for hash: ${transferContext.head}`, { required: true })
|
|
21
|
-
const rangeStart = asXL1BlockNumber(isDefined(transferContext.windowSize) ? Math.max(headBoundWitness.block - transferContext.windowSize + 1, 0) : 0)
|
|
22
|
-
const ranges = deepCalculateFramesFromRange(asXL1BlockRange(
|
|
23
|
-
[rangeStart, headBoundWitness.block],
|
|
24
|
-
{ name: 'transfersSummary' },
|
|
25
|
-
))
|
|
26
|
-
const summaries = await Promise.all(ranges.map(range => transfersStepSummaryFromRange(transferContext, range)))
|
|
27
|
-
const transfers: Partial<Record<Address, Partial<Record<Address, bigint>>>> = {}
|
|
28
|
-
for (let summary of summaries) {
|
|
29
|
-
for (const [from, toMap] of Object.entries(summary.transfers)) {
|
|
30
|
-
const validFrom = asAddress(from, () => `Invalid address: ${from}`)
|
|
31
|
-
transfers[validFrom] = transfers[validFrom] ?? {}
|
|
32
|
-
for (const [to, transfer] of Object.entries(toMap)) {
|
|
33
|
-
const validTo = asAddress(to, () => `Invalid address: ${to}`)
|
|
34
|
-
transfers[validFrom][validTo] = (transfers[validFrom][validTo] ?? 0n) + parseSignedBigInt(transfer)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return transfers
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function transfersSummaryKey(frameHeadHash: Hash, frameSize: number) {
|
|
43
|
-
return `${frameHeadHash}|${frameSize}`
|
|
44
|
-
}
|
package/src/config/App.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { globalRegistry } from 'zod'
|
|
2
|
-
import * as z from 'zod'
|
|
3
|
-
|
|
4
|
-
export const AppConfigZod = z.object({
|
|
5
|
-
port: z.coerce.number().default(3000).register(globalRegistry, {
|
|
6
|
-
default: 3000,
|
|
7
|
-
description: 'Port for the application',
|
|
8
|
-
title: 'app.port',
|
|
9
|
-
type: 'number',
|
|
10
|
-
}),
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
export type AppConfig = z.infer<typeof AppConfigZod>
|