@xyo-network/xl1-protocol-sdk 1.18.22 → 1.18.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.
@@ -3060,7 +3060,7 @@ import {
3060
3060
  } from "@xylabs/sdk-js";
3061
3061
  import {
3062
3062
  asRange,
3063
- asXL1BlockNumber as asXL1BlockNumber6,
3063
+ asXL1BlockNumber as asXL1BlockNumber7,
3064
3064
  asXL1BlockRange as asXL1BlockRange10,
3065
3065
  AttoXL1 as AttoXL12,
3066
3066
  StepSizes as StepSizes12,
@@ -3108,65 +3108,68 @@ import { spanRootAsync as spanRootAsync2 } from "@xylabs/sdk-js";
3108
3108
  import { assertEx as assertEx25 } from "@xylabs/sdk-js";
3109
3109
  import { PayloadBuilder as PayloadBuilder14 } from "@xyo-network/payload-builder";
3110
3110
  import { isAnyPayload } from "@xyo-network/payload-model";
3111
- import { StepSizes as StepSizes9 } from "@xyo-network/xl1-protocol";
3111
+ import { asXL1BlockNumber as asXL1BlockNumber6, StepSizes as StepSizes9 } from "@xyo-network/xl1-protocol";
3112
3112
  async function balancesStepSummaryFromRange(context, range) {
3113
- return await spanRootAsync2("balancesStepSummaryFromRange", async () => {
3114
- const frameHeadHash = await hashFromBlockNumber(context, range[1]);
3115
- const frameSize = range[1] - range[0] + 1;
3116
- const [headHash] = await context.head();
3117
- let result;
3118
- if (frameSize === 1) {
3119
- const hash = await hashFromBlockNumber(context, range[0]);
3120
- const [, payloads] = await hydrateBlock(context.store, hash);
3121
- const balances = {};
3122
- for (const [address, balance] of Object.entries(netBalancesForPayloads(payloads))) {
3123
- balances[address] = toSignedBigInt(balance);
3124
- }
3125
- result = await PayloadBuilder14.addHashMeta({
3126
- schema: BalancesStepSummarySchema,
3127
- hash: headHash,
3128
- stepSize: -1,
3129
- balances
3130
- });
3131
- } else {
3132
- const step = StepSizes9.indexOf(frameSize);
3133
- assertEx25(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes9.join(", ")}`);
3134
- const summaryResult = await context.summaryMap.get(`${frameHeadHash}|${frameSize}`);
3135
- if (isAnyPayload(summaryResult)) {
3136
- result = summaryResult;
3137
- } else {
3138
- await context.stepSemaphores[step].acquire();
3139
- try {
3140
- const subRanges = deepCalculateFramesFromRange(range, step - 1);
3141
- const promises = subRanges.map((subRange) => balancesStepSummaryFromRange(
3142
- context,
3143
- subRange
3144
- ));
3145
- const subResults = await Promise.all(promises);
3146
- const bigIntBalances = {};
3147
- for (const subResult of subResults) {
3148
- for (const [address, balance] of Object.entries(subResult.balances)) {
3149
- bigIntBalances[address] = (bigIntBalances[address] ?? 0n) + parseSignedBigInt(balance);
3113
+ const cacheKey = `${range[0]}|${range[1]}`;
3114
+ return await withContextCacheResponse(context, "balancesStepSummaryFromRange", cacheKey, async () => {
3115
+ return await spanRootAsync2("balancesStepSummaryFromRange", async () => {
3116
+ const frameHeadHash = await hashFromBlockNumber(context, range[1]);
3117
+ const frameSize = range[1] - range[0] + 1;
3118
+ const [headHash] = await context.head();
3119
+ const key = `${frameHeadHash}|${frameSize}`;
3120
+ return frameSize === 1 ? await spanRootAsync2(`balancesStepSummaryFromRange.frameSize=1[${key}]`, async () => {
3121
+ const hash = await hashFromBlockNumber(context, range[0]);
3122
+ const [, payloads] = await hydrateBlock(context.store, hash);
3123
+ const balances = {};
3124
+ for (const [address, balance] of Object.entries(netBalancesForPayloads(payloads))) {
3125
+ balances[address] = toSignedBigInt(balance);
3126
+ }
3127
+ return await PayloadBuilder14.addHashMeta({
3128
+ schema: BalancesStepSummarySchema,
3129
+ hash: headHash,
3130
+ stepSize: -1,
3131
+ balances
3132
+ });
3133
+ }, { timeBudgetLimit: 100 }) : await spanRootAsync2(`balancesStepSummaryFromRange.frameSize>1[${key}]`, async () => {
3134
+ const step = StepSizes9.indexOf(asXL1BlockNumber6(frameSize, true));
3135
+ assertEx25(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes9.join(", ")}`);
3136
+ const summaryResult = await context.summaryMap.get(key);
3137
+ if (isAnyPayload(summaryResult)) {
3138
+ return summaryResult;
3139
+ } else {
3140
+ await context.stepSemaphores[step].acquire();
3141
+ try {
3142
+ const subRanges = deepCalculateFramesFromRange(range, step - 1);
3143
+ const promises = subRanges.map((subRange) => balancesStepSummaryFromRange(
3144
+ context,
3145
+ subRange
3146
+ ));
3147
+ const subResults = await Promise.all(promises);
3148
+ const bigIntBalances = {};
3149
+ for (const subResult of subResults) {
3150
+ for (const [address, balance] of Object.entries(subResult.balances)) {
3151
+ bigIntBalances[address] = (bigIntBalances[address] ?? 0n) + parseSignedBigInt(balance);
3152
+ }
3150
3153
  }
3154
+ const balances = {};
3155
+ for (const [address, balance] of Object.entries(bigIntBalances)) {
3156
+ balances[address] = toSignedBigInt(balance);
3157
+ }
3158
+ const result = await PayloadBuilder14.addHashMeta({
3159
+ schema: BalancesStepSummarySchema,
3160
+ hash: frameHeadHash,
3161
+ stepSize: frameSize,
3162
+ balances
3163
+ });
3164
+ await context.summaryMap.set(key, result);
3165
+ return result;
3166
+ } finally {
3167
+ context.stepSemaphores[step].release();
3151
3168
  }
3152
- const balances = {};
3153
- for (const [address, balance] of Object.entries(bigIntBalances)) {
3154
- balances[address] = toSignedBigInt(balance);
3155
- }
3156
- result = await PayloadBuilder14.addHashMeta({
3157
- schema: BalancesStepSummarySchema,
3158
- hash: frameHeadHash,
3159
- stepSize: frameSize,
3160
- balances
3161
- });
3162
- await context.summaryMap.set(`${frameHeadHash}|${frameSize}`, result);
3163
- } finally {
3164
- context.stepSemaphores[step].release();
3165
3169
  }
3166
- }
3167
- }
3168
- return result;
3169
- }, { timeBudgetLimit: 500 });
3170
+ }, { timeBudgetLimit: 100 });
3171
+ }, { timeBudgetLimit: 200 });
3172
+ }, { max: 1e5, timeBudgetMs: 200 });
3170
3173
  }
3171
3174
 
3172
3175
  // src/summary/primitives/balances/balancesSummary.ts
@@ -3614,7 +3617,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
3614
3617
  async distillTransferHistory(address, range, max = 50) {
3615
3618
  return await this.spanAsync("distillTransferHistory", async () => {
3616
3619
  if (range[1] - range[0] <= StepSizes12[0] || max <= 1) {
3617
- return Array.from({ length: range[1] - range[0] + 1 }, (_, i) => range[1] - i).slice(0, max).map((n) => asXL1BlockNumber6(n, true));
3620
+ return Array.from({ length: range[1] - range[0] + 1 }, (_, i) => range[1] - i).slice(0, max).map((n) => asXL1BlockNumber7(n, true));
3618
3621
  }
3619
3622
  const frames = deepCalculateFramesFromRange(asXL1BlockRange10(range, true));
3620
3623
  const transferSummaryPairs = await Promise.all(frames.map(
@@ -3697,7 +3700,7 @@ import {
3697
3700
  import {
3698
3701
  asSignedHydratedBlockWithHashMeta,
3699
3702
  asSignedHydratedBlockWithStorageMeta,
3700
- asXL1BlockNumber as asXL1BlockNumber7
3703
+ asXL1BlockNumber as asXL1BlockNumber8
3701
3704
  } from "@xyo-network/xl1-protocol";
3702
3705
 
3703
3706
  // src/utils/HydratedCache.ts
@@ -3809,7 +3812,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
3809
3812
  while (current && blocks.length < limit) {
3810
3813
  blocks.push(current);
3811
3814
  if (current[0].block === 0) break;
3812
- const previousNumber = asXL1BlockNumber7(current[0].block - 1, true);
3815
+ const previousNumber = asXL1BlockNumber8(current[0].block - 1, true);
3813
3816
  current = await this.blockByNumber(previousNumber);
3814
3817
  }
3815
3818
  return blocks.map((b) => asSignedHydratedBlockWithHashMeta(b, true));
@@ -4319,7 +4322,7 @@ import {
4319
4322
  } from "@xylabs/sdk-js";
4320
4323
  import { PayloadBuilder as PayloadBuilder17 } from "@xyo-network/payload-builder";
4321
4324
  import {
4322
- asXL1BlockNumber as asXL1BlockNumber8,
4325
+ asXL1BlockNumber as asXL1BlockNumber9,
4323
4326
  TransferSchema as TransferSchema3
4324
4327
  } from "@xyo-network/xl1-protocol";
4325
4328
  var SimpleXyoGatewayRunner = class {
@@ -4353,8 +4356,8 @@ var SimpleXyoGatewayRunner = class {
4353
4356
  fees
4354
4357
  } = options ?? {};
4355
4358
  const resolvedChainId = isDefined19(chain) ? chain : await viewer.chainId();
4356
- const resolvedNbf = asXL1BlockNumber8(isDefined19(nbf) ? nbf : await viewer.currentBlockNumber(), true);
4357
- const resolvedExp = asXL1BlockNumber8(isDefined19(exp) ? exp : resolvedNbf + 10, true);
4359
+ const resolvedNbf = asXL1BlockNumber9(isDefined19(nbf) ? nbf : await viewer.currentBlockNumber(), true);
4360
+ const resolvedExp = asXL1BlockNumber9(isDefined19(exp) ? exp : resolvedNbf + 10, true);
4358
4361
  const tx = await buildUnsignedTransaction(resolvedChainId, onChain, offChain, resolvedNbf, resolvedExp, await (await this.signer()).address(), fees);
4359
4362
  return await this.addTransactionToChain(tx);
4360
4363
  }
@@ -4901,7 +4904,7 @@ import {
4901
4904
  } from "@xylabs/sdk-js";
4902
4905
  import {
4903
4906
  asTimePayload as asTimePayload2,
4904
- asXL1BlockNumber as asXL1BlockNumber9,
4907
+ asXL1BlockNumber as asXL1BlockNumber10,
4905
4908
  TimeSchema
4906
4909
  } from "@xyo-network/xl1-protocol";
4907
4910
  var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
@@ -4916,7 +4919,7 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
4916
4919
  async convertTime(fromDomain, toDomain, from) {
4917
4920
  switch (fromDomain) {
4918
4921
  case "xl1": {
4919
- const [block, payloads] = assertEx36(await this.blockViewer.blockByNumber(asXL1BlockNumber9(from, true)), () => "Block not found");
4922
+ const [block, payloads] = assertEx36(await this.blockViewer.blockByNumber(asXL1BlockNumber10(from, true)), () => "Block not found");
4920
4923
  const timeSchemaIndex = block.payload_schemas.indexOf(TimeSchema);
4921
4924
  const hash = timeSchemaIndex === -1 ? void 0 : block.payload_hashes[timeSchemaIndex];
4922
4925
  const timePayload = asTimePayload2(isDefined22(hash) ? payloads.find((p) => p._hash === hash) : void 0);
@@ -5014,7 +5017,7 @@ import {
5014
5017
  exists as exists7,
5015
5018
  isNull as isNull2
5016
5019
  } from "@xylabs/sdk-js";
5017
- import { asXL1BlockNumber as asXL1BlockNumber10 } from "@xyo-network/xl1-protocol";
5020
+ import { asXL1BlockNumber as asXL1BlockNumber11 } from "@xyo-network/xl1-protocol";
5018
5021
  import { Mutex } from "async-mutex";
5019
5022
  var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
5020
5023
  moniker = WindowedBlockViewerMoniker;
@@ -5064,7 +5067,7 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
5064
5067
  let block = this._blockNumberMap.get(blockNumber);
5065
5068
  while (block && (limit === void 0 || result.length < limit)) {
5066
5069
  result.unshift(block);
5067
- const previousBlockNumber = asXL1BlockNumber10(block[0].block - 1, true);
5070
+ const previousBlockNumber = asXL1BlockNumber11(block[0].block - 1, true);
5068
5071
  block = previousBlockNumber >= 0 ? this._blockNumberMap.get(previousBlockNumber) : void 0;
5069
5072
  }
5070
5073
  return result;