@xyo-network/xl1-protocol-sdk 1.26.27 → 1.26.29

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.
@@ -11,18 +11,88 @@ var __decorateClass = (decorators, target, key, kind) => {
11
11
  };
12
12
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
13
13
 
14
+ // src/test/buildRandomTransaction.ts
15
+ import { Account } from "@xyo-network/sdk-js";
16
+ import { asXL1BlockNumber, isAllowedBlockPayload } from "@xyo-network/xl1-protocol-lib";
17
+
18
+ // src/createTransferPayload.ts
19
+ import { toHex } from "@xylabs/sdk-js";
20
+ import { PayloadBuilder } from "@xyo-network/sdk-js";
21
+ import { TransferSchema } from "@xyo-network/xl1-protocol-lib";
22
+ function createTransferPayload(from, transfers, context) {
23
+ return new PayloadBuilder({ schema: TransferSchema }).fields({
24
+ epoch: Date.now(),
25
+ from,
26
+ transfers: Object.fromEntries(Object.entries(transfers).map(([k, v]) => [k, toHex(v)])),
27
+ context
28
+ }).build();
29
+ }
30
+
31
+ // src/transaction/buildTransaction.ts
32
+ import { assertEx, toHex as toHex2 } from "@xylabs/sdk-js";
33
+ import {
34
+ asAnyPayload,
35
+ BoundWitnessBuilder,
36
+ PayloadBuilder as PayloadBuilder2
37
+ } from "@xyo-network/sdk-js";
38
+ import { defaultTransactionFees } from "@xyo-network/xl1-protocol-lib";
39
+ async function buildTransaction(chain, onChainPayloads, offChainPayloads, signer, nbf, exp, from, fees = defaultTransactionFees) {
40
+ if (from === void 0 && Array.isArray(signer)) {
41
+ throw new Error("from is required when signer is an array");
42
+ }
43
+ const txBoundWitnessFields = {
44
+ chain,
45
+ fees: {
46
+ base: toHex2(fees.base),
47
+ gasLimit: toHex2(fees.gasLimit),
48
+ gasPrice: toHex2(fees.gasPrice),
49
+ priority: toHex2(fees.priority)
50
+ },
51
+ nbf,
52
+ exp
53
+ };
54
+ const elevatedHashes = await PayloadBuilder2.hashes(onChainPayloads);
55
+ const script = [];
56
+ for (const elevatedHash of elevatedHashes) {
57
+ script.push(`elevate|${elevatedHash}`);
58
+ }
59
+ const fields = {
60
+ ...txBoundWitnessFields,
61
+ from: from ?? (Array.isArray(signer) ? assertEx(signer.at(0)?.address) : signer.address)
62
+ };
63
+ if (script.length > 0) {
64
+ fields.script = script;
65
+ }
66
+ const [tx, txPayloads] = await new BoundWitnessBuilder().fields(fields).meta({ $signatures: [] }).payloads([...onChainPayloads, ...offChainPayloads]).signers(Array.isArray(signer) ? signer : [signer]).build();
67
+ return [await PayloadBuilder2.addHashMeta(tx), await PayloadBuilder2.addHashMeta(txPayloads.map((p) => asAnyPayload(p, true)))];
68
+ }
69
+
70
+ // src/test/buildRandomTransaction.ts
71
+ var buildRandomTransaction = async (chain, payloads, account, nbf = asXL1BlockNumber(0, true), exp = asXL1BlockNumber(nbf + 1e3, true), privatePayloadSchemas = [], receiverAddress) => {
72
+ const elevatedPayloads = (payloads ?? []).filter(isAllowedBlockPayload);
73
+ const additionalPayloads = (payloads ?? []).filter((payload) => !isAllowedBlockPayload(payload));
74
+ const sender = account ?? await Account.random();
75
+ if (elevatedPayloads.length === 0) {
76
+ const receiver = receiverAddress ?? (await Account.random()).address;
77
+ const transferPayload = createTransferPayload(sender.address, { [receiver]: 1n });
78
+ elevatedPayloads.push(transferPayload);
79
+ }
80
+ const hydratedTransaction = await buildTransaction(chain, elevatedPayloads, additionalPayloads, sender, nbf, exp);
81
+ return [hydratedTransaction[0], hydratedTransaction[1].filter((payload) => !privatePayloadSchemas.includes(payload.schema))];
82
+ };
83
+
14
84
  // src/test/getSimpleBlockViewerLocator.ts
15
85
  import { XYO_ZERO_ADDRESS as XYO_ZERO_ADDRESS3 } from "@xyo-network/xl1-protocol-lib";
16
86
 
17
87
  // src/CreatableProvider/AbstractCreatableProvider.ts
18
88
  import {
19
89
  AbstractCreatable,
20
- assertEx as assertEx2,
90
+ assertEx as assertEx3,
21
91
  IdLogger
22
92
  } from "@xylabs/sdk-js";
23
93
 
24
94
  // src/CreatableProvider/ProviderFactory.ts
25
- import { assertEx } from "@xylabs/sdk-js";
95
+ import { assertEx as assertEx2 } from "@xylabs/sdk-js";
26
96
  function providerFactoryDescription(factory, labels) {
27
97
  return `${factory.providerName}:${factory.defaultMoniker}:${JSON.stringify(labels ?? factory.labels ?? {})}`;
28
98
  }
@@ -43,7 +113,7 @@ var ProviderFactory = class _ProviderFactory {
43
113
  this.dependencies = dependencies;
44
114
  this.monikers = creatableProvider2.monikers;
45
115
  this.scope = scope;
46
- assertEx(this.monikers.includes(this.defaultMoniker), () => "defaultMoniker must be in monikers");
116
+ assertEx2(this.monikers.includes(this.defaultMoniker), () => "defaultMoniker must be in monikers");
47
117
  this.labels = Object.assign({}, creatableProvider2.labels ?? {}, labels ?? {});
48
118
  this.providerName = creatableProvider2.name;
49
119
  this._uniqueId = Symbol(providerFactoryDescription(this));
@@ -71,7 +141,7 @@ var ProviderFactory = class _ProviderFactory {
71
141
  break;
72
142
  }
73
143
  case "context": {
74
- const context = assertEx(
144
+ const context = assertEx2(
75
145
  params?.context,
76
146
  () => "Context is required for context-scoped providers"
77
147
  );
@@ -92,7 +162,7 @@ var ProviderFactory = class _ProviderFactory {
92
162
  scopeObject[this.resolvedMoniker] = resultPromise;
93
163
  const result = await resultPromise;
94
164
  if (start) {
95
- assertEx(await result.start(), () => `Failed to start provider instance [${this.resolvedMoniker}]`);
165
+ assertEx2(await result.start(), () => `Failed to start provider instance [${this.resolvedMoniker}]`);
96
166
  }
97
167
  return result;
98
168
  }
@@ -137,9 +207,9 @@ var AbstractCreatableProvider = class extends AbstractCreatable {
137
207
  return factory;
138
208
  }
139
209
  static async paramsHandler(params = {}) {
140
- const context = assertEx2(params.context, () => new Error("Context is required"));
141
- const config = assertEx2(context.config, () => new Error("Context config is required"));
142
- const locator = assertEx2(context.locator, () => new Error("Context locator is required"));
210
+ const context = assertEx3(params.context, () => new Error("Context is required"));
211
+ const config = assertEx3(context.config, () => new Error("Context config is required"));
212
+ const locator = assertEx3(context.locator, () => new Error("Context locator is required"));
143
213
  return await super.paramsHandler({
144
214
  ...params,
145
215
  statusReporter: params.statusReporter ?? context.statusReporter,
@@ -234,7 +304,7 @@ var hasLabels = (factory) => {
234
304
 
235
305
  // src/CreatableProvider/ProviderFactoryLocator.ts
236
306
  import { hasAllLabels } from "@xylabs/sdk-js";
237
- import { assertEx as assertEx3 } from "@xylabs/sdk-js";
307
+ import { assertEx as assertEx4 } from "@xylabs/sdk-js";
238
308
  var ProviderFactoryLocator = class _ProviderFactoryLocator {
239
309
  _context;
240
310
  _registry;
@@ -266,7 +336,7 @@ var ProviderFactoryLocator = class _ProviderFactoryLocator {
266
336
  this._frozen = true;
267
337
  }
268
338
  async getInstance(moniker, { start = true, labels } = {}) {
269
- return assertEx3(
339
+ return assertEx4(
270
340
  await this.tryGetInstance(moniker, { start, labels }),
271
341
  () => `No provider instance for the supplied config moniker [${moniker}]${labels ? ` & labels [${JSON.stringify(labels)}]` : ""} could be created`
272
342
  );
@@ -281,7 +351,7 @@ var ProviderFactoryLocator = class _ProviderFactoryLocator {
281
351
  * @returns A provider factory that matches the supplied moniker and labels or throws if one is not found
282
352
  */
283
353
  locate(moniker, labels) {
284
- return assertEx3(
354
+ return assertEx4(
285
355
  this.tryLocate(moniker, labels),
286
356
  () => `No module factory for the supplied config moniker [${moniker}]${labels ? ` & labels [${JSON.stringify(labels)}]` : ""} registered`
287
357
  );
@@ -303,10 +373,10 @@ var ProviderFactoryLocator = class _ProviderFactoryLocator {
303
373
  * @param labels The labels for the module factory
304
374
  */
305
375
  register(factory, labels, primary = false) {
306
- assertEx3(!this._frozen, () => "Cannot register a module factory after the locator has been frozen");
376
+ assertEx4(!this._frozen, () => "Cannot register a module factory after the locator has been frozen");
307
377
  if (this.validateDepsOnRegister) {
308
378
  const missingDeps = factory.dependencies.filter((dep) => !this.registered(dep));
309
- assertEx3(missingDeps.length === 0, () => `Cannot register module factory [${factory.uniqueId.description}] due to missing dependencies: ${missingDeps.join(", ")}`);
379
+ assertEx4(missingDeps.length === 0, () => `Cannot register module factory [${factory.uniqueId.description}] due to missing dependencies: ${missingDeps.join(", ")}`);
310
380
  }
311
381
  registerCreatableProviderFactory(this._registry, factory, labels, primary);
312
382
  return this;
@@ -354,7 +424,7 @@ var ProviderFactoryLocator = class _ProviderFactoryLocator {
354
424
  for (const moniker in this.registry) {
355
425
  for (const factory of this.registry[moniker] ?? []) {
356
426
  const missingDeps = factory.dependencies.filter((dep) => !this.registered(dep));
357
- assertEx3(missingDeps.length === 0, () => `Module factory [${factory.uniqueId.description}] is missing dependencies: ${missingDeps.join(", ")}`);
427
+ assertEx4(missingDeps.length === 0, () => `Module factory [${factory.uniqueId.description}] is missing dependencies: ${missingDeps.join(", ")}`);
358
428
  }
359
429
  }
360
430
  }
@@ -640,7 +710,7 @@ import { isDefined as isDefined3, isFalsy } from "@xylabs/sdk-js";
640
710
  import { asXL1BlockRange } from "@xyo-network/xl1-protocol-lib";
641
711
 
642
712
  // src/primitives/block/rate/timeHelpers.ts
643
- import { assertEx as assertEx4, isDefined as isDefined2 } from "@xylabs/sdk-js";
713
+ import { assertEx as assertEx5, isDefined as isDefined2 } from "@xylabs/sdk-js";
644
714
  var rateMultipliers = {
645
715
  millis: 1,
646
716
  seconds: 1e3,
@@ -658,7 +728,7 @@ var timeDurations = (timeInMs) => ({
658
728
  weeks: timeInMs / (1e3 * 60 * 60 * 24 * 7)
659
729
  });
660
730
  var getTimeConfigInMilliseconds = (timeConfig) => {
661
- const assertedTimeConfig = assertEx4(isDefined2(timeConfig) ? timeConfig : void 0, () => "Time configuration must be provided");
731
+ const assertedTimeConfig = assertEx5(isDefined2(timeConfig) ? timeConfig : void 0, () => "Time configuration must be provided");
662
732
  let totalMilliseconds = 0;
663
733
  if ("years" in assertedTimeConfig) {
664
734
  totalMilliseconds += assertedTimeConfig.years * 31536e6;
@@ -733,7 +803,7 @@ var calculateBlockRate = async (viewer, range, timeUnit) => {
733
803
  };
734
804
 
735
805
  // src/primitives/block/rate/stepRate.ts
736
- import { assertEx as assertEx5 } from "@xylabs/sdk-js";
806
+ import { assertEx as assertEx6 } from "@xylabs/sdk-js";
737
807
  import {
738
808
  asXL1BlockRange as asXL1BlockRange2,
739
809
  isValidStep,
@@ -745,26 +815,26 @@ var stepRate = async (viewer, start, step, count = 1, timeUnit) => {
745
815
  return await calculateBlockRate(viewer, range, timeUnit);
746
816
  };
747
817
  var calculateStepSizeRate = async (viewer, start, stepIndex, count = 1, timeUnit) => {
748
- assertEx5(isValidStep(stepIndex), () => `Invalid step index: ${stepIndex}`);
818
+ assertEx6(isValidStep(stepIndex), () => `Invalid step index: ${stepIndex}`);
749
819
  const step = StepSizes[stepIndex];
750
820
  return await stepRate(viewer, start, step, count, timeUnit);
751
821
  };
752
822
 
753
823
  // src/primitives/block/rate/timeRate.ts
754
824
  import {
755
- assertEx as assertEx6,
825
+ assertEx as assertEx7,
756
826
  isDefined as isDefined4,
757
827
  isDefinedNotNull
758
828
  } from "@xylabs/sdk-js";
759
- import { asXL1BlockNumber, asXL1BlockRange as asXL1BlockRange3 } from "@xyo-network/xl1-protocol-lib";
829
+ import { asXL1BlockNumber as asXL1BlockNumber2, asXL1BlockRange as asXL1BlockRange3 } from "@xyo-network/xl1-protocol-lib";
760
830
  var DEFAULT_TOLERANCE_MS = 3e4;
761
831
  var DEFAULT_MAX_ATTEMPTS = 10;
762
832
  var calculateTimeRate = async (viewer, timeConfig, startBlockNumber, timeUnit, toleranceMs = DEFAULT_TOLERANCE_MS, maxAttempts = DEFAULT_MAX_ATTEMPTS) => {
763
- assertEx6(Object.keys(timeConfig ?? {}).length === 1, () => "Only one time unit should be specified in timeConfig");
833
+ assertEx7(Object.keys(timeConfig ?? {}).length === 1, () => "Only one time unit should be specified in timeConfig");
764
834
  const startBlock = isDefinedNotNull(startBlockNumber) ? await viewer.blockByNumber(startBlockNumber) : null;
765
835
  const resolvedStartBlock = isDefinedNotNull(startBlock) ? startBlock[0] : (await viewer.currentBlock())[0];
766
836
  const timeInMilliseconds = getTimeConfigInMilliseconds(timeConfig);
767
- assertEx6(timeInMilliseconds > 0, () => "Time duration must be greater than zero");
837
+ assertEx7(timeInMilliseconds > 0, () => "Time duration must be greater than zero");
768
838
  const blocksPerMillisecondRate = 1 / (12 * 1e3);
769
839
  const initialBlocksInDuration = Math.floor(blocksPerMillisecondRate * timeInMilliseconds);
770
840
  const endBlockNumber = await findEndBlockRecursive(
@@ -783,14 +853,14 @@ var calculateTimeRate = async (viewer, timeConfig, startBlockNumber, timeUnit, t
783
853
  };
784
854
  var findEndBlockRecursive = async (viewer, startBlock, targetTimeMs, estimatedBlocksBack, toleranceMs, attemptsRemaining) => {
785
855
  console.log(`Attempts remaining: ${attemptsRemaining}, Estimated blocks back: ${estimatedBlocksBack}`);
786
- assertEx6(attemptsRemaining >= 0, () => "Maximum attempts reached while searching for end block");
856
+ assertEx7(attemptsRemaining >= 0, () => "Maximum attempts reached while searching for end block");
787
857
  const startBlockEpoch = startBlock.$epoch;
788
- const estimatedEndBlockNumber = asXL1BlockNumber(startBlock.block - estimatedBlocksBack, true);
858
+ const estimatedEndBlockNumber = asXL1BlockNumber2(startBlock.block - estimatedBlocksBack, true);
789
859
  if (estimatedEndBlockNumber < 0) {
790
860
  throw new Error("Estimated end block number is less than zero");
791
861
  }
792
862
  const endBlock = await viewer.blockByNumber(estimatedEndBlockNumber);
793
- const resolvedEndBlock = assertEx6(
863
+ const resolvedEndBlock = assertEx7(
794
864
  isDefined4(endBlock?.[0]) ? endBlock[0] : void 0,
795
865
  () => `Could not retrieve block ${estimatedEndBlockNumber} for time rate calculation`
796
866
  );
@@ -825,16 +895,6 @@ var findEndBlockRecursive = async (viewer, startBlock, targetTimeMs, estimatedBl
825
895
  );
826
896
  };
827
897
 
828
- // src/primitives/step/completedStepRewardAddress.ts
829
- import { toAddress } from "@xylabs/sdk-js";
830
- import { StepSizes as StepSizes2 } from "@xyo-network/xl1-protocol-lib";
831
- import { keccak256 } from "ethers";
832
- function completedStepRewardAddress({ block, step }) {
833
- const resolvedStepSize = step < StepSizes2.length ? StepSizes2[step] : step;
834
- const addressKey = new TextEncoder().encode(`${block}|${resolvedStepSize}`);
835
- return toAddress(keccak256(addressKey).slice(-40), { prefix: false });
836
- }
837
-
838
898
  // src/ChainContextHelpers.ts
839
899
  import {
840
900
  isDefined as isDefined6,
@@ -964,30 +1024,30 @@ var flattenHydratedBlock = (hydratedBlock) => {
964
1024
  var flattenHydratedBlocks = (hydratedBlocks) => hydratedBlocks.flatMap((blk) => flattenHydratedBlock(blk));
965
1025
 
966
1026
  // src/block/hydrate/hydrateBlock.ts
967
- import { assertEx as assertEx7 } from "@xylabs/sdk-js";
968
- import { asAnyPayload } from "@xyo-network/sdk-js";
1027
+ import { assertEx as assertEx8 } from "@xylabs/sdk-js";
1028
+ import { asAnyPayload as asAnyPayload2 } from "@xyo-network/sdk-js";
969
1029
  import { asBlockBoundWitnessWithStorageMeta, isTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol-lib";
970
1030
  var hydrateBlock = async (context, hash, maxDepth = 1, minDepth = maxDepth) => {
971
- assertEx7(maxDepth >= 0, () => "maxDepth must be greater than or equal to 0");
972
- assertEx7(minDepth >= 0, () => "minDepth must be greater than or equal to 0");
973
- assertEx7(maxDepth >= minDepth, () => "maxDepth must be greater than or equal to minDepth");
1031
+ assertEx8(maxDepth >= 0, () => "maxDepth must be greater than or equal to 0");
1032
+ assertEx8(minDepth >= 0, () => "minDepth must be greater than or equal to 0");
1033
+ assertEx8(maxDepth >= minDepth, () => "maxDepth must be greater than or equal to minDepth");
974
1034
  const { chainMap } = context;
975
1035
  const [block] = await chainMap.get([hash]);
976
- const bw = assertEx7(asBlockBoundWitnessWithStorageMeta(
977
- assertEx7(block, () => `block ${hash} not found`)
1036
+ const bw = assertEx8(asBlockBoundWitnessWithStorageMeta(
1037
+ assertEx8(block, () => `block ${hash} not found`)
978
1038
  ), () => `hash ${hash} is not a BlockBoundWitness`);
979
1039
  if (maxDepth === 0) return [bw, []];
980
- const blkPayloads = (await chainMap.get(bw.payload_hashes)).map((p) => asAnyPayload(p, true));
981
- if (minDepth === 1) assertEx7(allHashesPresent(bw.payload_hashes, blkPayloads), () => `Unable to find all payloads for block ${hash}`);
1040
+ const blkPayloads = (await chainMap.get(bw.payload_hashes)).map((p) => asAnyPayload2(p, true));
1041
+ if (minDepth === 1) assertEx8(allHashesPresent(bw.payload_hashes, blkPayloads), () => `Unable to find all payloads for block ${hash}`);
982
1042
  if (maxDepth === 1) return [bw, blkPayloads];
983
1043
  const transactions = blkPayloads.filter(isTransactionBoundWitnessWithStorageMeta);
984
1044
  const transactionsPayloadHashes = transactions.flatMap((tx) => tx.payload_hashes);
985
- const transactionsPayloads = (await chainMap.get(transactionsPayloadHashes)).map((p) => asAnyPayload(p, true));
986
- assertEx7(allHashesPresent(transactionsPayloadHashes, transactionsPayloads), () => `Unable to find all payloads for transactions in block ${hash}`);
1045
+ const transactionsPayloads = (await chainMap.get(transactionsPayloadHashes)).map((p) => asAnyPayload2(p, true));
1046
+ assertEx8(allHashesPresent(transactionsPayloadHashes, transactionsPayloads), () => `Unable to find all payloads for transactions in block ${hash}`);
987
1047
  const allPayloadsHashes = new Set([...blkPayloads, ...transactionsPayloads].flatMap((p) => p._hash));
988
- const allPayloads = (await chainMap.get([...allPayloadsHashes])).map((p) => asAnyPayload(p, true));
1048
+ const allPayloads = (await chainMap.get([...allPayloadsHashes])).map((p) => asAnyPayload2(p, true));
989
1049
  const allPayloadsFiltered = allPayloads.filter((p) => allPayloadsHashes.has(p._hash));
990
- if (maxDepth === 2) assertEx7(allHashesPresent(
1050
+ if (maxDepth === 2) assertEx8(allHashesPresent(
991
1051
  [...allPayloadsHashes],
992
1052
  allPayloadsFiltered
993
1053
  ), () => `Unable to find all payloads for transactions in block ${hash}`);
@@ -1004,7 +1064,7 @@ import { toSafeJsonString } from "@xylabs/sdk-js";
1004
1064
  import {
1005
1065
  asSignedBlockBoundWitnessWithStorageMeta,
1006
1066
  SignedBlockBoundWitnessWithHashMetaZod,
1007
- StepSizes as StepSizes3
1067
+ StepSizes as StepSizes2
1008
1068
  } from "@xyo-network/xl1-protocol-lib";
1009
1069
  async function blockFromBlockNumber(context, blockNumber) {
1010
1070
  return await spanAsync("blockFromBlockNumber", async () => {
@@ -1025,7 +1085,7 @@ async function blockFromBlockNumber(context, blockNumber) {
1025
1085
  while (currentBlock.block > blockNumber) {
1026
1086
  let jumpHash = currentBlock.previous;
1027
1087
  let jumpBlockNumber = currentBlock.block - 1;
1028
- for (const [step, stepSize] of StepSizes3.entries()) {
1088
+ for (const [step, stepSize] of StepSizes2.entries()) {
1029
1089
  const possibleJumpBlockNumber = currentBlock.block - currentBlock.block % stepSize - 1;
1030
1090
  if (possibleJumpBlockNumber >= blockNumber && possibleJumpBlockNumber <= jumpBlockNumber) {
1031
1091
  jumpBlockNumber = possibleJumpBlockNumber;
@@ -1059,12 +1119,12 @@ async function blockFromBlockNumber(context, blockNumber) {
1059
1119
 
1060
1120
  // src/block/primitives/validateTransactionOpcodes.ts
1061
1121
  import {
1062
- assertEx as assertEx8,
1122
+ assertEx as assertEx9,
1063
1123
  isHash,
1064
1124
  toSafeJsonString as toSafeJsonString2
1065
1125
  } from "@xylabs/sdk-js";
1066
1126
  import {
1067
- PayloadBuilder
1127
+ PayloadBuilder as PayloadBuilder3
1068
1128
  } from "@xyo-network/sdk-js";
1069
1129
  import { isExecutable } from "@xyo-network/xl1-protocol-lib";
1070
1130
  async function validateTransactionsOpcodes(txs) {
@@ -1076,14 +1136,14 @@ async function validateTransactionsOpcodes(txs) {
1076
1136
  switch (opCode) {
1077
1137
  case "elevate": {
1078
1138
  const [hash, ...rest] = args;
1079
- const txPayloadsWithStorageMeta = await PayloadBuilder.addStorageMeta(txPayloads);
1080
- assertEx8(rest.length === 0, () => `Invalid elevate operation ${opCode} ${args.join(", ")} - Too many Arguments`);
1139
+ const txPayloadsWithStorageMeta = await PayloadBuilder3.addStorageMeta(txPayloads);
1140
+ assertEx9(rest.length === 0, () => `Invalid elevate operation ${opCode} ${args.join(", ")} - Too many Arguments`);
1081
1141
  if (isHash(hash)) {
1082
- assertEx8(
1142
+ assertEx9(
1083
1143
  txBw.payload_hashes.includes(hash),
1084
1144
  () => `Invalid elevate operation ${opCode} ${args.join(", ")} - Hash not in payload hashes => ${toSafeJsonString2(txBw, 20)}`
1085
1145
  );
1086
- const txPayload = assertEx8(
1146
+ const txPayload = assertEx9(
1087
1147
  txPayloadsWithStorageMeta.find((p) => p._hash === hash),
1088
1148
  () => `Invalid elevate operation ${opCode} ${args.join(", ")} - Payload not found`
1089
1149
  );
@@ -1105,12 +1165,12 @@ async function validateTransactionsOpcodes(txs) {
1105
1165
 
1106
1166
  // src/primitives/datalake/addDataLakePayloadsToPayloads.ts
1107
1167
  import { isUndefined as isUndefined3 } from "@xylabs/sdk-js";
1108
- import { isAnyPayload, PayloadBuilder as PayloadBuilder2 } from "@xyo-network/sdk-js";
1168
+ import { isAnyPayload, PayloadBuilder as PayloadBuilder4 } from "@xyo-network/sdk-js";
1109
1169
  async function addDataLakePayloadsToPayloads(hashes, payloads, dataLakeViewer) {
1110
1170
  if (isUndefined3(dataLakeViewer)) return [payloads, []];
1111
1171
  const missingPayloadHashes = hashes.filter((hash) => !payloads.some((p) => p._hash === hash));
1112
- const payloadsFromDataLake = await PayloadBuilder2.addHashMeta(
1113
- await PayloadBuilder2.addHashMeta((await dataLakeViewer.get(missingPayloadHashes)).filter(isAnyPayload))
1172
+ const payloadsFromDataLake = await PayloadBuilder4.addHashMeta(
1173
+ await PayloadBuilder4.addHashMeta((await dataLakeViewer.get(missingPayloadHashes)).filter(isAnyPayload))
1114
1174
  );
1115
1175
  return [[...payloads, ...payloadsFromDataLake], payloadsFromDataLake.map((p) => p._hash)];
1116
1176
  }
@@ -1155,7 +1215,7 @@ var findMostRecentBlock = async (chainArchivist, nextOptions = DEFAULT_NEXT_OPTI
1155
1215
  };
1156
1216
 
1157
1217
  // src/primitives/state/hydratedBlockByNumber.ts
1158
- import { assertEx as assertEx9, spanAsync as spanAsync2 } from "@xylabs/sdk-js";
1218
+ import { assertEx as assertEx10, spanAsync as spanAsync2 } from "@xylabs/sdk-js";
1159
1219
  async function hydratedBlockByNumber(context, blockNumber) {
1160
1220
  return await spanAsync2("hydratedBlockByNumber", async () => {
1161
1221
  if (blockNumber < 0) throw new Error(`Block number ${blockNumber} is less than 0`);
@@ -1163,7 +1223,7 @@ async function hydratedBlockByNumber(context, blockNumber) {
1163
1223
  if (blockNumber % 1 !== 0) throw new Error(`Block number ${blockNumber} is not an integer`);
1164
1224
  const cacheKey = `${blockNumber}`;
1165
1225
  return await withContextCacheResponse(context, "hydratedBlockByNumber", cacheKey, async () => {
1166
- const block = assertEx9(
1226
+ const block = assertEx10(
1167
1227
  await blockFromBlockNumber(context, blockNumber),
1168
1228
  () => `Could not find block for block number ${blockNumber}`
1169
1229
  );
@@ -1252,14 +1312,14 @@ var ConfigZod = BaseConfigZod.extend({ actors: ActorsConfigZod }).describe("The
1252
1312
 
1253
1313
  // src/simple/block/SimpleBlockViewer.ts
1254
1314
  import {
1255
- assertEx as assertEx10,
1315
+ assertEx as assertEx11,
1256
1316
  exists,
1257
1317
  isUndefined as isUndefined4
1258
1318
  } from "@xylabs/sdk-js";
1259
1319
  import {
1260
1320
  asSignedHydratedBlockWithHashMeta,
1261
1321
  asSignedHydratedBlockWithStorageMeta,
1262
- asXL1BlockNumber as asXL1BlockNumber2,
1322
+ asXL1BlockNumber as asXL1BlockNumber3,
1263
1323
  BlockViewerMoniker,
1264
1324
  DataLakeViewerMoniker,
1265
1325
  FinalizationViewerMoniker
@@ -1315,7 +1375,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
1315
1375
  static async paramsHandler(params) {
1316
1376
  return {
1317
1377
  ...await super.paramsHandler(params),
1318
- finalizedArchivist: assertEx10(params.finalizedArchivist, () => "finalizedArchivist is required")
1378
+ finalizedArchivist: assertEx11(params.finalizedArchivist, () => "finalizedArchivist is required")
1319
1379
  };
1320
1380
  }
1321
1381
  async blockByHash(hash) {
@@ -1344,8 +1404,8 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
1344
1404
  }
1345
1405
  async blocksByHash(hash, limit = 50) {
1346
1406
  return await this.spanAsync("blocksByHash", async () => {
1347
- assertEx10(limit > 0, () => "limit must be greater than 0");
1348
- assertEx10(limit <= 100, () => "limit must be less than 100");
1407
+ assertEx11(limit > 0, () => "limit must be greater than 0");
1408
+ assertEx11(limit <= 100, () => "limit must be less than 100");
1349
1409
  const blocks = [];
1350
1410
  let current = await this.blockByHash(hash);
1351
1411
  while (current && blocks.length < limit) {
@@ -1359,8 +1419,8 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
1359
1419
  }
1360
1420
  async blocksByNumber(blockNumber, limit = 50) {
1361
1421
  return await this.spanAsync("blocksByNumber", async () => {
1362
- assertEx10(limit > 0, () => "limit must be greater than 0");
1363
- assertEx10(limit <= 100, () => "limit must be less than 100");
1422
+ assertEx11(limit > 0, () => "limit must be greater than 0");
1423
+ assertEx11(limit <= 100, () => "limit must be less than 100");
1364
1424
  const chainContext = await this.getChainContextRead();
1365
1425
  if (isUndefined4(chainContext.head)) {
1366
1426
  return [];
@@ -1370,7 +1430,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
1370
1430
  while (current && blocks.length < limit) {
1371
1431
  blocks.push(current);
1372
1432
  if (current[0].block === 0) break;
1373
- const previousNumber = asXL1BlockNumber2(current[0].block - 1, true);
1433
+ const previousNumber = asXL1BlockNumber3(current[0].block - 1, true);
1374
1434
  current = await this.blockByNumberWithContext(chainContext, previousNumber);
1375
1435
  }
1376
1436
  return blocks.map((b) => asSignedHydratedBlockWithHashMeta(b, true));
@@ -1378,7 +1438,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
1378
1438
  }
1379
1439
  async chainId(blockNumber = "latest") {
1380
1440
  return await this.spanAsync("chainId", async () => {
1381
- return blockNumber === "latest" ? (await this.finalizationViewer.headBlock()).chain : assertEx10(await this.blockByNumber(blockNumber), () => `Block not found [${blockNumber}]`)[0].chain;
1441
+ return blockNumber === "latest" ? (await this.finalizationViewer.headBlock()).chain : assertEx11(await this.blockByNumber(blockNumber), () => `Block not found [${blockNumber}]`)[0].chain;
1382
1442
  }, this.context);
1383
1443
  }
1384
1444
  async createHandler() {
@@ -1449,7 +1509,7 @@ SimpleBlockViewer = __decorateClass([
1449
1509
 
1450
1510
  // src/simple/chainContractViewer/SimpleChainContractViewer.ts
1451
1511
  import {
1452
- assertEx as assertEx11
1512
+ assertEx as assertEx12
1453
1513
  } from "@xylabs/sdk-js";
1454
1514
  import {
1455
1515
  ChainContractViewerMoniker,
@@ -1470,7 +1530,7 @@ var SimpleChainContractViewer = class extends AbstractCreatableProvider {
1470
1530
  let contractViewer = this;
1471
1531
  let forkedAtBlockNumber = await contractViewer.forkedAtBlockNumber();
1472
1532
  while (forkedAtBlockNumber !== null && blockNumber <= forkedAtBlockNumber) {
1473
- contractViewer = assertEx11(await contractViewer.forkedChainContractViewer());
1533
+ contractViewer = assertEx12(await contractViewer.forkedChainContractViewer());
1474
1534
  forkedAtBlockNumber = await contractViewer.forkedAtBlockNumber();
1475
1535
  chainId = await contractViewer.chainId();
1476
1536
  }
@@ -1512,7 +1572,7 @@ SimpleChainContractViewer = __decorateClass([
1512
1572
 
1513
1573
  // src/simple/finalization/SimpleFinalizationViewer.ts
1514
1574
  import {
1515
- assertEx as assertEx12
1575
+ assertEx as assertEx13
1516
1576
  } from "@xylabs/sdk-js";
1517
1577
  import {
1518
1578
  asSignedHydratedBlockWithStorageMeta as asSignedHydratedBlockWithStorageMeta2,
@@ -1542,7 +1602,7 @@ var SimpleFinalizationViewer = class extends AbstractCreatableProvider {
1542
1602
  static async paramsHandler(params) {
1543
1603
  return {
1544
1604
  ...await super.paramsHandler(params),
1545
- finalizedArchivist: assertEx12(params.finalizedArchivist, () => "finalizedArchivist is required")
1605
+ finalizedArchivist: assertEx13(params.finalizedArchivist, () => "finalizedArchivist is required")
1546
1606
  };
1547
1607
  }
1548
1608
  chainId() {
@@ -1550,18 +1610,18 @@ var SimpleFinalizationViewer = class extends AbstractCreatableProvider {
1550
1610
  }
1551
1611
  async createHandler() {
1552
1612
  await super.createHandler();
1553
- this._chainId = assertEx12(this.config.chain.id ?? (await findMostRecentBlock(this.params.finalizedArchivist))?.chain, () => "chain.id is required if empty archivist");
1613
+ this._chainId = assertEx13(this.config.chain.id ?? (await findMostRecentBlock(this.params.finalizedArchivist))?.chain, () => "chain.id is required if empty archivist");
1554
1614
  this._store = { chainMap: this.params.finalizedArchivist };
1555
1615
  }
1556
1616
  async head() {
1557
1617
  return await this.spanAsync("head", async () => {
1558
- const currentHead = assertEx12(await this.getCurrentHead(), () => "Could not find most recent block [currentBlock]");
1618
+ const currentHead = assertEx13(await this.getCurrentHead(), () => "Could not find most recent block [currentBlock]");
1559
1619
  const cache = this.hydratedBlockCache;
1560
1620
  const block = await cache.get(currentHead._hash);
1561
1621
  if (!block) {
1562
1622
  console.log(`Could not find current block with hash ${currentHead._hash}`);
1563
1623
  }
1564
- return assertEx12(block, () => "Could not find current block");
1624
+ return assertEx13(block, () => "Could not find current block");
1565
1625
  }, this.context);
1566
1626
  }
1567
1627
  async headBlock() {
@@ -1587,8 +1647,8 @@ var SimpleFinalizationViewer = class extends AbstractCreatableProvider {
1587
1647
  }
1588
1648
  async getCurrentHead() {
1589
1649
  const chainArchivist = this.finalizedArchivist;
1590
- const result = assertEx12(await findMostRecentBlock(chainArchivist), () => "Could not find most recent block [getCurrentHead]");
1591
- assertEx12(result?.chain === this._chainId, () => "Chain ID does not match head block chain ID");
1650
+ const result = assertEx13(await findMostRecentBlock(chainArchivist), () => "Could not find most recent block [getCurrentHead]");
1651
+ assertEx13(result?.chain === this._chainId, () => "Chain ID does not match head block chain ID");
1592
1652
  return result;
1593
1653
  }
1594
1654
  };
@@ -1599,76 +1659,6 @@ SimpleFinalizationViewer = __decorateClass([
1599
1659
  creatableProvider()
1600
1660
  ], SimpleFinalizationViewer);
1601
1661
 
1602
- // src/transaction/buildRandomTransaction.ts
1603
- import { Account } from "@xyo-network/sdk-js";
1604
- import { asXL1BlockNumber as asXL1BlockNumber3, isAllowedBlockPayload } from "@xyo-network/xl1-protocol-lib";
1605
-
1606
- // src/createTransferPayload.ts
1607
- import { toHex } from "@xylabs/sdk-js";
1608
- import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/sdk-js";
1609
- import { TransferSchema } from "@xyo-network/xl1-protocol-lib";
1610
- function createTransferPayload(from, transfers, context) {
1611
- return new PayloadBuilder3({ schema: TransferSchema }).fields({
1612
- epoch: Date.now(),
1613
- from,
1614
- transfers: Object.fromEntries(Object.entries(transfers).map(([k, v]) => [k, toHex(v)])),
1615
- context
1616
- }).build();
1617
- }
1618
-
1619
- // src/transaction/buildTransaction.ts
1620
- import { assertEx as assertEx13, toHex as toHex2 } from "@xylabs/sdk-js";
1621
- import {
1622
- asAnyPayload as asAnyPayload2,
1623
- BoundWitnessBuilder,
1624
- PayloadBuilder as PayloadBuilder4
1625
- } from "@xyo-network/sdk-js";
1626
- import { defaultTransactionFees } from "@xyo-network/xl1-protocol-lib";
1627
- async function buildTransaction(chain, onChainPayloads, offChainPayloads, signer, nbf, exp, from, fees = defaultTransactionFees) {
1628
- if (from === void 0 && Array.isArray(signer)) {
1629
- throw new Error("from is required when signer is an array");
1630
- }
1631
- const txBoundWitnessFields = {
1632
- chain,
1633
- fees: {
1634
- base: toHex2(fees.base),
1635
- gasLimit: toHex2(fees.gasLimit),
1636
- gasPrice: toHex2(fees.gasPrice),
1637
- priority: toHex2(fees.priority)
1638
- },
1639
- nbf,
1640
- exp
1641
- };
1642
- const elevatedHashes = await PayloadBuilder4.hashes(onChainPayloads);
1643
- const script = [];
1644
- for (const elevatedHash of elevatedHashes) {
1645
- script.push(`elevate|${elevatedHash}`);
1646
- }
1647
- const fields = {
1648
- ...txBoundWitnessFields,
1649
- from: from ?? (Array.isArray(signer) ? assertEx13(signer.at(0)?.address) : signer.address)
1650
- };
1651
- if (script.length > 0) {
1652
- fields.script = script;
1653
- }
1654
- const [tx, txPayloads] = await new BoundWitnessBuilder().fields(fields).meta({ $signatures: [] }).payloads([...onChainPayloads, ...offChainPayloads]).signers(Array.isArray(signer) ? signer : [signer]).build();
1655
- return [await PayloadBuilder4.addHashMeta(tx), await PayloadBuilder4.addHashMeta(txPayloads.map((p) => asAnyPayload2(p, true)))];
1656
- }
1657
-
1658
- // src/transaction/buildRandomTransaction.ts
1659
- var buildRandomTransaction = async (chain, payloads, account, nbf = asXL1BlockNumber3(0, true), exp = asXL1BlockNumber3(nbf + 1e3, true), privatePayloadSchemas = [], receiverAddress) => {
1660
- const elevatedPayloads = (payloads ?? []).filter(isAllowedBlockPayload);
1661
- const additionalPayloads = (payloads ?? []).filter((payload) => !isAllowedBlockPayload(payload));
1662
- const sender = account ?? await Account.random();
1663
- if (elevatedPayloads?.length === 0) {
1664
- const receiver = receiverAddress ?? (await Account.random()).address;
1665
- const transferPayload = createTransferPayload(sender.address, { [receiver]: 1n });
1666
- elevatedPayloads.push(transferPayload);
1667
- }
1668
- const hydratedTransaction = await buildTransaction(chain, elevatedPayloads, additionalPayloads, sender, nbf, exp);
1669
- return [hydratedTransaction[0], hydratedTransaction[1].filter((p) => !privatePayloadSchemas.includes(p.schema))];
1670
- };
1671
-
1672
1662
  // src/test/buildRandomChain.ts
1673
1663
  import { asAddress as asAddress3, assertEx as assertEx16 } from "@xylabs/sdk-js";
1674
1664
  import {
@@ -1698,9 +1688,10 @@ import {
1698
1688
  import {
1699
1689
  asXL1BlockNumber as asXL1BlockNumber4,
1700
1690
  AttoXL1,
1691
+ completedStepRewardAddress,
1701
1692
  isBlockBoundWitness,
1702
1693
  StepRewardFractions,
1703
- StepSizes as StepSizes4,
1694
+ StepSizes as StepSizes3,
1704
1695
  XL1_PROTOCOL_VERSION,
1705
1696
  XYO_STEP_REWARD_ADDRESS,
1706
1697
  XYO_ZERO_ADDRESS
@@ -1782,7 +1773,7 @@ async function buildBlock(options) {
1782
1773
  }
1783
1774
  }
1784
1775
  const completedStepRewardTransfers = [];
1785
- for (const [i, step] of StepSizes4.entries()) {
1776
+ for (const [i, step] of StepSizes3.entries()) {
1786
1777
  if (blockNumber < step) {
1787
1778
  break;
1788
1779
  }
@@ -1997,6 +1988,7 @@ function getTestProviderContext2(config) {
1997
1988
  return getTestProviderContext(config);
1998
1989
  }
1999
1990
  export {
1991
+ buildRandomTransaction,
2000
1992
  getTestProviderContext2 as getTestProviderContext,
2001
1993
  getTestSimpleBlockViewerLocator
2002
1994
  };