@xyo-network/xl1-protocol-sdk 1.26.3 → 1.26.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/xl1-protocol-sdk",
3
- "version": "1.26.3",
3
+ "version": "1.26.6",
4
4
  "description": "XYO Layer One SDK Protocol",
5
5
  "homepage": "https://xylabs.com",
6
6
  "bugs": {
@@ -48,8 +48,8 @@
48
48
  "!**/*.test.*"
49
49
  ],
50
50
  "dependencies": {
51
- "@xyo-network/xl1-protocol-lib": "~1.26.3",
52
- "@xyo-network/xl1-schema": "~1.26.3",
51
+ "@xyo-network/xl1-protocol-lib": "~1.26.6",
52
+ "@xyo-network/xl1-schema": "~1.26.6",
53
53
  "async-mutex": "~0.5.0",
54
54
  "cosmiconfig": "^9.0.1",
55
55
  "lru-cache": "^11.2.7"
@@ -57,19 +57,20 @@
57
57
  "devDependencies": {
58
58
  "@opentelemetry/api": "^1.9.1",
59
59
  "@types/node": "^25.5.0",
60
- "@xylabs/sdk-js": "^5.0.87",
61
- "@xylabs/ts-scripts-yarn3": "~7.4.27",
62
- "@xylabs/tsconfig": "~7.4.27",
63
- "@xylabs/vitest-extended": "~5.0.87",
64
- "@xyo-network/sdk-js": "^5.3.16",
65
- "@xyo-network/xl1-network-model": "~1.26.3",
60
+ "@xylabs/sdk-js": "^5.0.90",
61
+ "@xylabs/ts-scripts-common": "~7.5.6",
62
+ "@xylabs/ts-scripts-yarn3": "~7.5.6",
63
+ "@xylabs/tsconfig": "~7.5.6",
64
+ "@xylabs/vitest-extended": "~5.0.90",
65
+ "@xyo-network/sdk-js": "^5.3.17",
66
+ "@xyo-network/xl1-network-model": "~1.26.6",
66
67
  "axios": "^1.13.6",
67
68
  "ethers": "^6.16.0",
68
69
  "ky": "^1.14.3",
69
70
  "mongodb": "~7.1.1",
70
71
  "tslib": "^2.8.1",
71
72
  "typescript": "~5.9.3",
72
- "vitest": "~4.1.1",
73
+ "vitest": "~4.1.2",
73
74
  "zod": "~4.3.6"
74
75
  },
75
76
  "peerDependencies": {
@@ -3,10 +3,11 @@ import {
3
3
  } from '@xylabs/sdk-js'
4
4
  import { span } from '@xylabs/sdk-js'
5
5
  import type { Payload } from '@xyo-network/sdk-js'
6
+ import type { BaseContext } from '@xyo-network/xl1-protocol-lib'
6
7
  import { isTransfer } from '@xyo-network/xl1-protocol-lib'
7
8
 
8
9
  /** netBalancesForPayloads constant. */
9
- export const netBalancesForPayloads = (payloads: Payload[]) => {
10
+ export const netBalancesForPayloads = (context: BaseContext, payloads: Payload[]) => {
10
11
  return span('netBalancesForPayloads', () => {
11
12
  const balances: Record<Address, bigint> = {}
12
13
  for (const payload of payloads) {
@@ -19,5 +20,5 @@ export const netBalancesForPayloads = (payloads: Payload[]) => {
19
20
  }
20
21
  }
21
22
  return balances
22
- })
23
+ }, context.traceProvider)
23
24
  }
@@ -3,10 +3,11 @@ import {
3
3
  } from '@xylabs/sdk-js'
4
4
  import { span } from '@xylabs/sdk-js'
5
5
  import type { Payload } from '@xyo-network/sdk-js'
6
+ import type { BaseContext } from '@xyo-network/xl1-protocol-lib'
6
7
  import { isTransfer } from '@xyo-network/xl1-protocol-lib'
7
8
 
8
9
  /** netSchemasForPayloads constant. */
9
- export const netSchemasForPayloads = (payloads: Payload[]) => {
10
+ export const netSchemasForPayloads = (context: BaseContext, payloads: Payload[]) => {
10
11
  return span('netSchemasForPayloads', () => {
11
12
  const balances: Record<Address, bigint> = {}
12
13
  for (const payload of payloads) {
@@ -19,5 +20,5 @@ export const netSchemasForPayloads = (payloads: Payload[]) => {
19
20
  }
20
21
  }
21
22
  return balances
22
- })
23
+ }, context.traceProvider)
23
24
  }
@@ -3,11 +3,12 @@ import {
3
3
  } from '@xylabs/sdk-js'
4
4
  import { span } from '@xylabs/sdk-js'
5
5
  import type { Payload } from '@xyo-network/sdk-js'
6
+ import type { BaseContext } from '@xyo-network/xl1-protocol-lib'
6
7
  import { isTransfer } from '@xyo-network/xl1-protocol-lib'
7
8
 
8
9
  // the net transfer amounts for the specified accounts only
9
10
  /** NetTransfersForPayloads helper function. */
10
- export function netTransfersForPayloads(payloads: Payload[]): Record<Address, Record<Address, bigint>> {
11
+ export function netTransfersForPayloads(context: BaseContext, payloads: Payload[]): Record<Address, Record<Address, bigint>> {
11
12
  return span('netTransfersForPayloads', () => {
12
13
  const transfers: Record<Address, Record<Address, bigint>> = {}
13
14
  for (const payload of payloads) {
@@ -22,5 +23,5 @@ export function netTransfersForPayloads(payloads: Payload[]): Record<Address, Re
22
23
  }
23
24
  }
24
25
  return transfers
25
- })
26
+ }, context.traceProvider)
26
27
  }
@@ -29,7 +29,7 @@ export async function stepRewardTotal(context: CachingContext, blockViewer: Bloc
29
29
  () => `No step transfer found for step ${step} at block ${block} (${blockBw._hash})`,
30
30
  )
31
31
  const rewards = assertEx(
32
- netTransfersForPayloads([stepTransfer])[XYO_STEP_REWARD_ADDRESS],
32
+ netTransfersForPayloads(context, [stepTransfer])[XYO_STEP_REWARD_ADDRESS],
33
33
  () => `No rewards found for step reward address ${XYO_STEP_REWARD_ADDRESS} at block ${block} (${blockBw._hash})`,
34
34
  )
35
35
  const sortedTransfers = (Object.entries(rewards)).toSorted(([,a], [,b]) => a > b ? -1 : a < b ? 1 : 0)
@@ -95,13 +95,11 @@ export class SimpleBlockViewer extends AbstractCreatableProvider<SimpleBlockView
95
95
 
96
96
  async blockByNumber(blockNumber: XL1BlockNumber): Promise<SignedHydratedBlockWithHashMeta | null> {
97
97
  return await this.spanAsync('blockByNumber', async () => {
98
- const [head] = await this.currentBlock()
99
- if (isUndefined(head)) {
98
+ const chainContext = await this.getChainContextRead()
99
+ if (isUndefined(chainContext.head)) {
100
100
  return null
101
101
  }
102
- const block = asSignedHydratedBlockWithHashMeta(await hydratedBlockByNumber(await this.getChainContextRead(), blockNumber)) ?? null
103
- const [result] = block ? await addDataLakePayloads(block, this.dataLakeViewer) : [null, []]
104
- return result
102
+ return await this.blockByNumberWithContext(chainContext, blockNumber)
105
103
  }, { ...this.context, timeBudgetLimit: 100 })
106
104
  }
107
105
 
@@ -125,13 +123,17 @@ export class SimpleBlockViewer extends AbstractCreatableProvider<SimpleBlockView
125
123
  return await this.spanAsync('blocksByNumber', async () => {
126
124
  assertEx(limit > 0, () => 'limit must be greater than 0')
127
125
  assertEx(limit <= 100, () => 'limit must be less than 100')
126
+ const chainContext = await this.getChainContextRead()
127
+ if (isUndefined(chainContext.head)) {
128
+ return []
129
+ }
128
130
  const blocks: SignedHydratedBlockWithHashMeta[] = []
129
- let current = await this.blockByNumber(blockNumber)
131
+ let current = await this.blockByNumberWithContext(chainContext, blockNumber)
130
132
  while (current && blocks.length < limit) {
131
133
  blocks.push(current)
132
134
  if (current[0].block === 0) break
133
135
  const previousNumber = asXL1BlockNumber(current[0].block - 1, true)
134
- current = await this.blockByNumber(previousNumber)
136
+ current = await this.blockByNumberWithContext(chainContext, previousNumber)
135
137
  }
136
138
  return blocks.map(b => asSignedHydratedBlockWithHashMeta(b, true))
137
139
  }, this.context)
@@ -217,4 +219,13 @@ export class SimpleBlockViewer extends AbstractCreatableProvider<SimpleBlockView
217
219
  head: (await this.finalizationViewer.head())[0],
218
220
  }
219
221
  }
222
+
223
+ private async blockByNumberWithContext(
224
+ chainContext: ChainContextRead,
225
+ blockNumber: XL1BlockNumber,
226
+ ): Promise<SignedHydratedBlockWithHashMeta | null> {
227
+ const block = asSignedHydratedBlockWithHashMeta(await hydratedBlockByNumber(chainContext, blockNumber)) ?? null
228
+ const [result] = block ? await addDataLakePayloads(block, this.dataLakeViewer) : [null, []]
229
+ return result
230
+ }
220
231
  }
@@ -18,6 +18,8 @@ import {
18
18
  isHydratedBlockWithHashMeta, isHydratedTransactionWithHashMeta, isSignedHydratedBlockWithHashMeta, isSignedHydratedTransactionWithHashMeta, MempoolPruneOptions, MempoolRunner,
19
19
  MempoolRunnerMoniker, type MempoolViewer, type SignedHydratedBlock, SignedHydratedBlockWithHashMeta, type SignedHydratedTransaction,
20
20
  SignedHydratedTransactionWithHashMeta,
21
+ TransactionValidationViewer,
22
+ TransactionValidationViewerMoniker,
21
23
  } from '@xyo-network/xl1-protocol-lib'
22
24
  import { Mutex } from 'async-mutex'
23
25
 
@@ -48,13 +50,14 @@ export interface SimpleMempoolRunnerParams extends CreatableProviderParams {
48
50
  @creatableProvider()
49
51
  export class SimpleMempoolRunner extends AbstractCreatableProvider<SimpleMempoolRunnerParams> implements MempoolRunner {
50
52
  static readonly defaultMoniker = MempoolRunnerMoniker
51
- static readonly dependencies = [FinalizationViewerMoniker, BlockValidationViewerMoniker, ChainContractViewerMoniker]
53
+ static readonly dependencies = [FinalizationViewerMoniker, BlockValidationViewerMoniker, TransactionValidationViewerMoniker, ChainContractViewerMoniker]
52
54
  static readonly monikers = [MempoolRunnerMoniker]
53
55
  moniker = SimpleMempoolRunner.defaultMoniker
54
56
 
55
57
  protected _blockValidationViewer!: BlockValidationViewer
56
58
  protected _chainContractViewer!: ChainContractViewer
57
59
  protected _finalizationViewer!: FinalizationViewer
60
+ protected _transactionValidationViewer!: TransactionValidationViewer
58
61
 
59
62
  private _syncMutex = new Mutex()
60
63
  private _syncTimerId: ReturnType<typeof setInterval> | null = null
@@ -95,6 +98,10 @@ export class SimpleMempoolRunner extends AbstractCreatableProvider<SimpleMempool
95
98
  return this.params.syncLimit ?? DEFAULT_SYNC_LIMIT
96
99
  }
97
100
 
101
+ protected get transactionValidationViewer() {
102
+ return this._transactionValidationViewer!
103
+ }
104
+
98
105
  static override async paramsHandler(params?: Partial<SimpleMempoolRunnerParams>): Promise<SimpleMempoolRunnerParams> {
99
106
  return {
100
107
  ...await super.paramsHandler(params),
@@ -108,6 +115,7 @@ export class SimpleMempoolRunner extends AbstractCreatableProvider<SimpleMempool
108
115
  this._blockValidationViewer = await this.locator.getInstance<BlockValidationViewer>(BlockValidationViewerMoniker)
109
116
  this._chainContractViewer = await this.locator.getInstance<ChainContractViewer>(ChainContractViewerMoniker)
110
117
  this._finalizationViewer = await this.locator.getInstance<FinalizationViewer>(FinalizationViewerMoniker)
118
+ this._transactionValidationViewer = await this.locator.getInstance<TransactionValidationViewer>(TransactionValidationViewerMoniker)
111
119
  }
112
120
 
113
121
  async prunePendingBlocks({
@@ -137,8 +145,7 @@ export class SimpleMempoolRunner extends AbstractCreatableProvider<SimpleMempool
137
145
  remainingBlockMap.length === remainingBlocks.length,
138
146
  () => `remainingBlockMap length should match remainingBlocks length [${remainingBlockMap.length}/${remainingBlocks.length}]`,
139
147
  )
140
- // const validationResults = await this.blockValidationViewer.validateBlocks(remainingBlocks, { value: true, state: false })
141
- const validationResults = remainingBlocks.map(b => b) // Skip full validation for now, just use simple checks
148
+ const validationResults = await this.blockValidationViewer.validateBlocks(remainingBlocks, { value: true, state: true })
142
149
  for (const [i, r] of validationResults.entries()) {
143
150
  const validated = isHydratedBlockWithHashMeta(r)
144
151
  if (!validated) {
@@ -197,7 +204,7 @@ export class SimpleMempoolRunner extends AbstractCreatableProvider<SimpleMempool
197
204
  () => `remainingTransactionMap length should match remainingTransactions length [${remainingTransactionMap.length}/${remainingTransactions.length}]`,
198
205
  )
199
206
 
200
- const validationResults = remainingTransactions.map(t => t) // Skip full validation for now, just use simple checks
207
+ const validationResults = await this.transactionValidationViewer.validateTransactions(remainingTransactions, { value: true, state: true })
201
208
  for (const [i, r] of validationResults.entries()) {
202
209
  const validated = isHydratedTransactionWithHashMeta(r)
203
210
  if (!validated) {
@@ -37,7 +37,7 @@ export async function balancesStepSummaryFromRange(
37
37
  ? await spanRootAsync(`balancesStepSummaryFromRange.frameSize=1[${key}]`, async () => {
38
38
  const [,payloads] = assertEx(await blockViewer.blockByNumber(range[0]), () => `Block not found for number: ${range[0]}`)
39
39
  const balances: Record<Address, SignedBigInt> = {}
40
- for (const [address, balance] of Object.entries(netBalancesForPayloads(payloads))) {
40
+ for (const [address, balance] of Object.entries(netBalancesForPayloads(context, payloads))) {
41
41
  balances[address as Address] = toSignedBigInt(balance)
42
42
  }
43
43
  return {
@@ -42,7 +42,7 @@ export async function transfersStepSummaryFromRange(
42
42
  if (frameSize === 1) {
43
43
  const [, payloads] = assertEx(await blockViewer.blockByNumber(range[0]), () => `Block not found for number: ${range[0]}`)
44
44
  const transfers: Record<Address, Record<Address, SignedBigInt>> = {}
45
- for (const [from, toMap] of Object.entries(netTransfersForPayloads(payloads))) {
45
+ for (const [from, toMap] of Object.entries(netTransfersForPayloads(context, payloads))) {
46
46
  transfers[from as Address] = transfers[from as Address] ?? {}
47
47
  for (const [to, amount] of Object.entries(toMap)) {
48
48
  transfers[from as Address][to as Address] = toSignedBigInt(amount)