var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __decorateClass = (decorators, target, key, kind) => {
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
    if (decorator = decorators[i])
      result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  if (kind && result) __defProp(target, key, result);
  return result;
};
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);

// src/modules/providers/buildSimpleXyoSigner.ts
import { XyoSignerMoniker } from "@xyo-network/xl1-protocol/protocol-lib";
import { ProviderFactoryLocator, SimpleXyoSigner } from "#protocol-sdk";
async function buildSimpleXyoSigner(context, account) {
  const locator = new ProviderFactoryLocator(context);
  locator.register(
    SimpleXyoSigner.factory(SimpleXyoSigner.dependencies, { account })
  );
  return await locator.getInstance(XyoSignerMoniker);
}
var buildSimpleXyoSignerV2 = buildSimpleXyoSigner;

// src/modules/providers/creators/createRestDataLake.ts
import { RestDataLakeRunner as RestDataLakeRunner4, RestDataLakeViewer as RestDataLakeViewer6 } from "#protocol-sdk";

// src/modules/providers/locators/baseConfigFactoryLocator.ts
import {
  LocatorConfigFieldsZod,
  ProviderFactoryLocator as ProviderFactoryLocator2
} from "#protocol-sdk";
async function baseConfigFactoryLocator() {
  const config = LocatorConfigFieldsZod.parse({});
  return new ProviderFactoryLocator2({
    config,
    singletons: {},
    caches: {}
  }, {});
}

// src/modules/providers/locators/basicRemoteRunnerLocator.ts
import { isDefined as isDefined3 } from "@ariestools/sdk";
import {
  ProviderFactoryLocator as ProviderFactoryLocator4,
  RestDataLakeRunner as RestDataLakeRunner2,
  RestDataLakeViewer as RestDataLakeViewer3,
  SimpleXyoGatewayRunner as SimpleXyoGatewayRunner2
} from "#protocol-sdk";
import { JsonRpcXyoRunner as JsonRpcXyoRunner2, JsonRpcXyoSigner as JsonRpcXyoSigner2 } from "#rpc";

// src/modules/providers/SimpleXyoConnectionRunner.ts
import {
  DataLakeRunnerMoniker,
  DataLakeViewerMoniker,
  XyoConnectionMoniker,
  XyoRunnerMoniker,
  XyoViewerMoniker
} from "@xyo-network/xl1-protocol/protocol-lib";
import { AbstractCreatableProvider, creatableProvider } from "#protocol-sdk";
var SimpleXyoConnectionRunner = class extends AbstractCreatableProvider {
  moniker = SimpleXyoConnectionRunner.defaultMoniker;
  _network;
  _runner;
  _storage;
  _viewer;
  get network() {
    return this._network;
  }
  get runner() {
    return this._runner;
  }
  get storage() {
    return this._storage;
  }
  get viewer() {
    return this._viewer;
  }
  async createHandler() {
    await super.createHandler();
    this._runner = await this.locator.getInstance(XyoRunnerMoniker);
    this._viewer = await this.locator.getInstance(XyoViewerMoniker);
    const dataLakeRunner = await this.locator.tryGetInstance(DataLakeRunnerMoniker);
    const dataLakeViewer = await this.locator.tryGetInstance(DataLakeViewerMoniker);
    this._storage = dataLakeRunner ?? dataLakeViewer;
  }
};
__publicField(SimpleXyoConnectionRunner, "connectionTypes", []);
__publicField(SimpleXyoConnectionRunner, "defaultMoniker", XyoConnectionMoniker);
__publicField(SimpleXyoConnectionRunner, "dependencies", [XyoRunnerMoniker, XyoViewerMoniker]);
__publicField(SimpleXyoConnectionRunner, "monikers", [XyoConnectionMoniker]);
__publicField(SimpleXyoConnectionRunner, "surface", "node");
SimpleXyoConnectionRunner = __decorateClass([
  creatableProvider()
], SimpleXyoConnectionRunner);

// src/modules/providers/locators/basicRemoteViewerLocator.ts
import { isDefined as isDefined2 } from "@ariestools/sdk";
import {
  ActorConfigZod,
  RestDataLakeViewer as RestDataLakeViewer2,
  SimpleXyoGateway as SimpleXyoGateway2,
  synthesizeRpcConnectionBindings
} from "#protocol-sdk";

// src/modules/providers/SimpleXyoConnectionViewer.ts
import {
  DataLakeViewerMoniker as DataLakeViewerMoniker2,
  XyoConnectionMoniker as XyoConnectionMoniker2,
  XyoViewerMoniker as XyoViewerMoniker2
} from "@xyo-network/xl1-protocol/protocol-lib";
import { AbstractCreatableProvider as AbstractCreatableProvider2, creatableProvider as creatableProvider2 } from "#protocol-sdk";
var SimpleXyoConnectionViewer = class extends AbstractCreatableProvider2 {
  moniker = SimpleXyoConnectionViewer.defaultMoniker;
  _network;
  _storage;
  _viewer;
  get network() {
    return this._network;
  }
  get storage() {
    return this._storage;
  }
  get viewer() {
    return this._viewer;
  }
  async createHandler() {
    await super.createHandler();
    this._viewer = await this.locator.getInstance(XyoViewerMoniker2);
    const dataLakeViewer = await this.locator.tryGetInstance(DataLakeViewerMoniker2);
    this._storage = dataLakeViewer;
  }
};
__publicField(SimpleXyoConnectionViewer, "connectionTypes", []);
__publicField(SimpleXyoConnectionViewer, "defaultMoniker", XyoConnectionMoniker2);
__publicField(SimpleXyoConnectionViewer, "dependencies", [XyoViewerMoniker2]);
__publicField(SimpleXyoConnectionViewer, "monikers", [XyoConnectionMoniker2]);
__publicField(SimpleXyoConnectionViewer, "surface", "node");
SimpleXyoConnectionViewer = __decorateClass([
  creatableProvider2()
], SimpleXyoConnectionViewer);

// src/modules/providers/locators/remoteLocatorFromConfig.ts
import {
  needsFromConnectionTypes,
  parseLocatorConfigFields as parseLocatorConfigFields2,
  SimpleBlockValidationViewer as SimpleBlockValidationViewer2,
  SimpleStakeEventsViewer as SimpleStakeEventsViewer2,
  SimpleTransactionValidationViewer as SimpleTransactionValidationViewer2,
  SimpleWindowedBlockViewer as SimpleWindowedBlockViewer2
} from "#protocol-sdk";

// src/modules/providers/locators/locatorFromAdaptedConfig.ts
import {
  locatorFromConfig,
  needsFromProviderBindings,
  parseLocatorConfigFields,
  ProviderFactoryLocator as ProviderFactoryLocator3,
  registerFactoriesFromPlan,
  resolveProvidersFromConfig
} from "#protocol-sdk";

// src/modules/providers/locators/providerCandidates.ts
import {
  providerCandidatesFromClasses,
  RestDataLakeRunner,
  RestDataLakeViewer,
  SimpleAccountBalanceViewer,
  SimpleBlockRewardViewer,
  SimpleBlockValidationViewer,
  SimpleBlockViewer,
  SimpleChainContractViewer,
  SimpleEvmChainViewer,
  SimpleFinalizationRunner,
  SimpleFinalizationViewer,
  SimpleIndexViewer,
  SimpleMempoolRunner,
  SimpleMempoolViewer,
  SimpleStakeEventsViewer,
  SimpleStakeTotalsViewer,
  SimpleStakeViewer,
  SimpleTimeSyncViewer,
  SimpleTransactionValidationViewer,
  SimpleTransactionViewer,
  SimpleWindowedBlockViewer,
  SimpleXyoGateway,
  SimpleXyoGatewayRunner,
  SimpleXyoRunner
} from "#protocol-sdk";
import {
  RestBlockViewer,
  RestChainContractViewer,
  RestChainStateViewer,
  RestFinalizationViewer,
  RestIndexViewer
} from "#rest-block-viewer";
import {
  JsonRpcAccountBalanceViewer,
  JsonRpcBlockViewer,
  JsonRpcFinalizationViewer,
  JsonRpcMempoolRunner,
  JsonRpcMempoolViewer,
  JsonRpcNetworkStakeViewer,
  JsonRpcStakeTotalsViewer,
  JsonRpcStakeViewer,
  JsonRpcTimeSyncViewer,
  JsonRpcTransactionViewer,
  JsonRpcXyoRunner,
  JsonRpcXyoSigner,
  JsonRpcXyoViewer
} from "#rpc";

// src/modules/providers/SimpleDeadLetterQueueRunner.ts
import { assertEx } from "@ariestools/sdk";
import { isHashMeta, PayloadBuilder } from "@xyo-network/sdk";
import {
  DeadLetterQueueRunnerMoniker,
  isBlockRejection,
  isTransactionRejection
} from "@xyo-network/xl1-protocol/protocol-lib";
import { AbstractCreatableProvider as AbstractCreatableProvider3, creatableProvider as creatableProvider3 } from "#protocol-sdk";
var SimpleDeadLetterQueueRunner = class extends AbstractCreatableProvider3 {
  moniker = SimpleDeadLetterQueueRunner.defaultMoniker;
  get rejectedBlocksArchivist() {
    return this.params.rejectedBlocksArchivist;
  }
  get rejectedTransactionsArchivist() {
    return this.params.rejectedTransactionsArchivist;
  }
  static async paramsHandler(params) {
    return {
      ...await super.paramsHandler(params),
      rejectedBlocksArchivist: assertEx(params?.rejectedBlocksArchivist, () => "rejectedBlocksArchivist is required"),
      rejectedTransactionsArchivist: assertEx(params?.rejectedTransactionsArchivist, () => "rejectedTransactionsArchivist is required")
    };
  }
  async pruneRejectedBlocks({
    batchSize = 10,
    maxPrune = 1e3,
    maxCheck = 1e3
  } = {}) {
    let total = 0;
    let pruned = 0;
    let cursor;
    let batch = await this.rejectedBlocksArchivist.next({
      limit: batchSize,
      cursor,
      order: "desc"
    });
    while (batch.length > 0 && pruned < maxPrune && total < maxCheck) {
      const pruneHashes = batch.filter(isHashMeta).filter((p) => !isBlockRejection(p)).map((p) => p._hash);
      pruned += pruneHashes.length;
      total += batch.length;
      if (pruneHashes.length > 0) {
        await this.rejectedBlocksArchivist.delete(pruneHashes);
      }
      const pruneSet = new Set(pruneHashes);
      const lastSurvivor = batch.findLast((p) => isHashMeta(p) && !pruneSet.has(p._hash));
      cursor = lastSurvivor?._sequence ?? cursor;
      batch = await this.rejectedBlocksArchivist.next({
        limit: batchSize,
        cursor,
        order: "desc"
      });
    }
    return [pruned, total];
  }
  async pruneRejectedTransactions({
    batchSize = 10,
    maxPrune = 1e3,
    maxCheck = 1e3
  } = {}) {
    let total = 0;
    let pruned = 0;
    let cursor;
    let batch = await this.rejectedTransactionsArchivist.next({
      limit: batchSize,
      cursor,
      order: "desc"
    });
    while (batch.length > 0 && pruned < maxPrune && total < maxCheck) {
      const pruneHashes = batch.filter(isHashMeta).filter((p) => !isTransactionRejection(p)).map((p) => p._hash);
      pruned += pruneHashes.length;
      total += batch.length;
      if (pruneHashes.length > 0) {
        await this.rejectedTransactionsArchivist.delete(pruneHashes);
      }
      const pruneSet = new Set(pruneHashes);
      const lastSurvivor = batch.findLast((p) => isHashMeta(p) && !pruneSet.has(p._hash));
      cursor = lastSurvivor?._sequence ?? cursor;
      batch = await this.rejectedTransactionsArchivist.next({
        limit: batchSize,
        cursor,
        order: "desc"
      });
    }
    return [pruned, total];
  }
  async rejectBlock(rejection) {
    const withMeta = await PayloadBuilder.addHashMeta(rejection);
    const inserted = await this.rejectedBlocksArchivist.insert([withMeta]);
    return inserted.length > 0;
  }
  async rejectTransaction(rejection) {
    const withMeta = await PayloadBuilder.addHashMeta(rejection);
    const inserted = await this.rejectedTransactionsArchivist.insert([withMeta]);
    return inserted.length > 0;
  }
};
__publicField(SimpleDeadLetterQueueRunner, "connectionTypes", ["lmdb", "mongo", "memory"]);
__publicField(SimpleDeadLetterQueueRunner, "defaultMoniker", DeadLetterQueueRunnerMoniker);
__publicField(SimpleDeadLetterQueueRunner, "dependencies", []);
__publicField(SimpleDeadLetterQueueRunner, "monikers", [DeadLetterQueueRunnerMoniker]);
__publicField(SimpleDeadLetterQueueRunner, "surface", "node");
SimpleDeadLetterQueueRunner = __decorateClass([
  creatableProvider3()
], SimpleDeadLetterQueueRunner);

// src/modules/providers/SimpleDeadLetterQueueViewer.ts
import {
  exists,
  isDefined,
  isHash
} from "@ariestools/sdk";
import { isHashMeta as isHashMeta2 } from "@xyo-network/sdk";
import {
  DeadLetterQueueViewerMoniker,
  isBlockRejection as isBlockRejection2,
  isTransactionRejection as isTransactionRejection2
} from "@xyo-network/xl1-protocol/protocol-lib";
import { AbstractCreatableProvider as AbstractCreatableProvider4, creatableProvider as creatableProvider4 } from "#protocol-sdk";
var SimpleDeadLetterQueueViewer = class extends AbstractCreatableProvider4 {
  moniker = SimpleDeadLetterQueueViewer.defaultMoniker;
  get rejectedBlocksArchivist() {
    return this.params.rejectedBlocksArchivist;
  }
  get rejectedTransactionsArchivist() {
    return this.params.rejectedTransactionsArchivist;
  }
  async rejectedBlocks({
    cursor: providedCursor,
    limit = 100,
    rejector
  } = {}) {
    let cursor;
    if (isHash(providedCursor)) {
      const [p] = await this.rejectedBlocksArchivist.get([providedCursor]);
      if (isDefined(p)) {
        cursor = p._sequence;
      }
    }
    const payloads = await this.rejectedBlocksArchivist.next({
      order: "desc",
      limit,
      cursor
    });
    const rejections = payloads.filter(isHashMeta2).map((p) => isBlockRejection2(p) ? p : void 0).filter(exists);
    if (rejector !== void 0) {
      return rejections.filter((r) => r.rejector === rejector);
    }
    return rejections;
  }
  async rejectedTransactions({
    cursor: providedCursor,
    limit = 100,
    rejector
  } = {}) {
    let cursor;
    if (isHash(providedCursor)) {
      const [p] = await this.rejectedTransactionsArchivist.get([providedCursor]);
      if (isDefined(p)) {
        cursor = p._sequence;
      }
    }
    const payloads = await this.rejectedTransactionsArchivist.next({
      order: "desc",
      limit,
      cursor
    });
    const rejections = payloads.filter(isHashMeta2).map((p) => isTransactionRejection2(p) ? p : void 0).filter(exists);
    if (rejector !== void 0) {
      return rejections.filter((r) => r.rejector === rejector);
    }
    return rejections;
  }
};
__publicField(SimpleDeadLetterQueueViewer, "connectionTypes", ["lmdb", "mongo", "memory"]);
__publicField(SimpleDeadLetterQueueViewer, "defaultMoniker", DeadLetterQueueViewerMoniker);
__publicField(SimpleDeadLetterQueueViewer, "dependencies", []);
__publicField(SimpleDeadLetterQueueViewer, "monikers", [DeadLetterQueueViewerMoniker]);
__publicField(SimpleDeadLetterQueueViewer, "surface", "node");
SimpleDeadLetterQueueViewer = __decorateClass([
  creatableProvider4()
], SimpleDeadLetterQueueViewer);

// src/modules/providers/SimpleNetworkStakeViewer.ts
import { assertEx as assertEx2 } from "@ariestools/sdk";
import {
  FinalizationViewerMoniker,
  NetworkStakeStepRewardsViewerMoniker,
  NetworkStakeViewerMoniker,
  StakeTotalsViewerMoniker,
  StakeViewerMoniker
} from "@xyo-network/xl1-protocol/protocol-lib";
import {
  AbstractCreatableProvider as AbstractCreatableProvider5,
  creatableProvider as creatableProvider5
} from "#protocol-sdk";
var SimpleNetworkStakeViewer = class extends AbstractCreatableProvider5 {
  moniker = SimpleNetworkStakeViewer.defaultMoniker;
  _finalizationViewer;
  _stake;
  _stakeTotals;
  _stepRewardsViewer;
  get stepRewards() {
    return assertEx2(this._stepRewardsViewer, () => "Step rewards viewer not initialized");
  }
  get finalizationViewer() {
    return this._finalizationViewer;
  }
  get rewardMultipliers() {
    return this.params.rewardMultipliers;
  }
  get stake() {
    return this._stake;
  }
  get stakeTotals() {
    return this._stakeTotals;
  }
  async active(blockNumber) {
    const resolvedBlockNumber = blockNumber ?? await this.finalizationViewer.headNumber();
    return [await this.stakeTotals.active(resolvedBlockNumber), resolvedBlockNumber];
  }
  async createHandler() {
    await super.createHandler();
    this._finalizationViewer = await this.locator.getInstance(FinalizationViewerMoniker);
    this._stake = await this.locator.getInstance(StakeViewerMoniker);
    this._stakeTotals = await this.locator.getInstance(StakeTotalsViewerMoniker);
    this._stepRewardsViewer = await this.locator.getInstance(NetworkStakeStepRewardsViewerMoniker);
  }
};
__publicField(SimpleNetworkStakeViewer, "connectionTypes", ["lmdb", "mongo", "memory"]);
__publicField(SimpleNetworkStakeViewer, "defaultMoniker", NetworkStakeViewerMoniker);
__publicField(SimpleNetworkStakeViewer, "dependencies", [
  FinalizationViewerMoniker,
  NetworkStakeStepRewardsViewerMoniker,
  StakeTotalsViewerMoniker,
  StakeViewerMoniker
]);
__publicField(SimpleNetworkStakeViewer, "monikers", [NetworkStakeViewerMoniker]);
__publicField(SimpleNetworkStakeViewer, "surface", "node");
SimpleNetworkStakeViewer = __decorateClass([
  creatableProvider5()
], SimpleNetworkStakeViewer);

// src/modules/providers/SimpleStepRewards/SimpleStepRewardsByPositionViewer.ts
import { isArray } from "@ariestools/sdk";
import {
  asAttoXL1,
  asXL1BlockRange,
  BlockViewerMoniker,
  FinalizationViewerMoniker as FinalizationViewerMoniker2,
  NetworkStakeStepRewardsByPositionViewerMoniker,
  StakeViewerMoniker as StakeViewerMoniker2
} from "@xyo-network/xl1-protocol/protocol-lib";
import {
  AbstractCreatableProvider as AbstractCreatableProvider6,
  blockRangeSteps,
  creatableProvider as creatableProvider6
} from "#protocol-sdk";

// src/modules/providers/SimpleStepRewards/primitives/networkStakeStepRewardEarned.ts
import { XYO_NETWORK_STAKING_ADDRESS as XYO_NETWORK_STAKING_ADDRESS2 } from "@xyo-network/xl1-protocol/protocol-lib";
import { externalBlockRangeFromStep as externalBlockRangeFromStep2, withContextCacheResponse as withContextCacheResponse2 } from "#protocol-sdk";

// src/modules/providers/SimpleStepRewards/primitives/networkStakeStepRewardEarnedForPosition.ts
import { XYO_NETWORK_STAKING_ADDRESS } from "@xyo-network/xl1-protocol/protocol-lib";
import {
  externalBlockRangeFromStep,
  stepRewardTotal,
  weightedStakeForRangeByPosition,
  withContextCacheResponse
} from "#protocol-sdk";
async function networkStakeStepRewardEarnedForPosition(context, blockViewer, stakeEventsViewer, stepIdentity, position, rewardMultipliers = {}, timeAnchor) {
  const range = await externalBlockRangeFromStep(context, blockViewer, stepIdentity, timeAnchor);
  const cacheKey = `${stepIdentity.block}|${stepIdentity.step}|${position.id}|${range[0]}-${range[1]}`;
  return await withContextCacheResponse(context, "networkStakeStepRewardEarnedForPosition", cacheKey, async () => {
    const numerator = position.staked === XYO_NETWORK_STAKING_ADDRESS ? await weightedStakeForRangeByPosition(
      context,
      blockViewer,
      stakeEventsViewer,
      range,
      XYO_NETWORK_STAKING_ADDRESS,
      position.id
    ) : 0n;
    const denominator = await weightedStakeForRangeByPosition(
      context,
      blockViewer,
      stakeEventsViewer,
      range
    );
    const totalReward = await stepRewardTotal(context, blockViewer, stepIdentity, rewardMultipliers);
    const positionReward = denominator > 0n ? totalReward * numerator / denominator : 0n;
    const result = [positionReward, totalReward];
    return result;
  });
}

// src/modules/providers/SimpleStepRewards/primitives/networkStakeStepRewardEarned.ts
async function networkStakeStepRewardEarned(context, blockViewer, stakeViewer, stepIdentity, rewardMultipliers = {}, timeAnchor) {
  const range = await externalBlockRangeFromStep2(context, blockViewer, stepIdentity, timeAnchor);
  const cacheKey = `${stepIdentity.block}|${stepIdentity.step}|${range[0]}-${range[1]}`;
  return await withContextCacheResponse2(context, "networkStakeStepRewardEarned", cacheKey, async () => {
    const positions = await stakeViewer.stakesByStaked(XYO_NETWORK_STAKING_ADDRESS2);
    const results = await Promise.all(positions.map((pos) => {
      return networkStakeStepRewardEarnedForPosition(
        context,
        blockViewer,
        stakeViewer.stakeEvents,
        stepIdentity,
        pos,
        rewardMultipliers,
        timeAnchor
      );
    }));
    const numerator = results.reduce((acc, [positionReward]) => acc + positionReward, 0n);
    const result = results.length > 0 ? [numerator, results[0][1]] : [0n, 0n];
    return result;
  });
}

// src/modules/providers/SimpleStepRewards/primitives/networkStakeStepRewardEarnedForStaker.ts
import { XYO_NETWORK_STAKING_ADDRESS as XYO_NETWORK_STAKING_ADDRESS3 } from "@xyo-network/xl1-protocol/protocol-lib";
import {
  externalBlockRangeFromStep as externalBlockRangeFromStep3,
  toStepIdentityString,
  withContextCacheResponse as withContextCacheResponse3
} from "#protocol-sdk";
async function networkStakeStepRewardEarnedForStaker(context, blockViewer, stakeViewer, stepIdentity, staker, rewardMultipliers = {}, timeAnchor) {
  const stepId = toStepIdentityString(stepIdentity);
  const range = await externalBlockRangeFromStep3(context, blockViewer, stepIdentity, timeAnchor);
  const cacheKey = `${stepId}-${staker}-${range[0]}-${range[1]}`;
  return await withContextCacheResponse3(context, "networkStakeStepRewardEarnedForStaker", cacheKey, async () => {
    const stakes = await stakeViewer.stakesByStaker(staker);
    const positions = stakes.filter((pos) => pos.staked === XYO_NETWORK_STAKING_ADDRESS3);
    const results = await Promise.all(positions.map((pos) => {
      return networkStakeStepRewardEarnedForPosition(
        context,
        blockViewer,
        stakeViewer.stakeEvents,
        stepIdentity,
        pos,
        rewardMultipliers,
        timeAnchor
      );
    }));
    const numerator = results.reduce((acc, [positionReward]) => acc + positionReward, 0n);
    const result = results.length > 0 ? [numerator, results[0][1]] : [0n, 0n];
    return result;
  });
}

// src/modules/providers/SimpleStepRewards/SimpleStepRewardsByPositionViewer.ts
var SimpleStepRewardsByPositionViewer = class extends AbstractCreatableProvider6 {
  moniker = SimpleStepRewardsByPositionViewer.defaultMoniker;
  _blockViewer;
  _finalizationViewer;
  _stakeViewer;
  get rewardMultipliers() {
    return this.params.rewardMultipliers ?? {};
  }
  get timeAnchor() {
    return this.params.timeAnchor;
  }
  get blockViewer() {
    return this._blockViewer;
  }
  get finalizationViewer() {
    return this._finalizationViewer;
  }
  get stakeViewer() {
    return this._stakeViewer;
  }
  async bonus({ range, positions } = {}) {
    const total = await this.total({ range, positions });
    const earned = await this.earned({ range, positions });
    const result = {};
    for (const key of Object.keys(total)) {
      const pos = Number(key);
      result[pos] = asAttoXL1(total[pos] - (earned[pos] ?? 0n));
    }
    return result;
  }
  claimed(_options) {
    throw new Error("Method [claimed] not implemented.");
  }
  async createHandler() {
    await super.createHandler();
    this._blockViewer = await this.locator.getInstance(BlockViewerMoniker);
    this._finalizationViewer = await this.locator.getInstance(FinalizationViewerMoniker2);
    this._stakeViewer = await this.locator.getInstance(StakeViewerMoniker2);
  }
  async earned({ range, positions } = {}) {
    return await this.calculateRewards({ range, positions });
  }
  async total({ range, positions } = {}) {
    return await this.calculateRewards({ range, positions }, this.rewardMultipliers);
  }
  unclaimed(_options = {}) {
    throw new Error("Method [unclaimed] not implemented.");
  }
  async calculateRewards({ range, positions } = {}, rewardMultipliers) {
    const result = {};
    const head = await this.finalizationViewer.head();
    const steps = blockRangeSteps(asXL1BlockRange(
      range ?? [0, head[1]],
      { name: "NodeStepRewardsByPositionViewer" }
    ), [3, 4, 5, 6, 7]);
    for (const step of steps) {
      if (isArray(positions)) {
        for (const positionId of positions) {
          const position = await this.stakeViewer.stakeById(positionId);
          const reward = await networkStakeStepRewardEarnedForPosition(
            this.context,
            this.blockViewer,
            this.stakeViewer.stakeEvents,
            step,
            position,
            rewardMultipliers,
            this.timeAnchor
          );
          result[positionId] = asAttoXL1((result[positionId] ?? 0n) + reward[0]);
        }
      }
    }
    return result;
  }
};
__publicField(SimpleStepRewardsByPositionViewer, "connectionTypes", ["lmdb", "mongo", "memory", "rpc"]);
__publicField(SimpleStepRewardsByPositionViewer, "defaultMoniker", NetworkStakeStepRewardsByPositionViewerMoniker);
__publicField(SimpleStepRewardsByPositionViewer, "dependencies", [BlockViewerMoniker, FinalizationViewerMoniker2, StakeViewerMoniker2]);
__publicField(SimpleStepRewardsByPositionViewer, "monikers", [NetworkStakeStepRewardsByPositionViewerMoniker]);
__publicField(SimpleStepRewardsByPositionViewer, "surface", "node");
SimpleStepRewardsByPositionViewer = __decorateClass([
  creatableProvider6()
], SimpleStepRewardsByPositionViewer);

// src/modules/providers/SimpleStepRewards/SimpleStepRewardsByStakerViewer.ts
import { isArray as isArray2 } from "@ariestools/sdk";
import {
  asAttoXL1 as asAttoXL12,
  asXL1BlockRange as asXL1BlockRange2,
  BlockViewerMoniker as BlockViewerMoniker2,
  FinalizationViewerMoniker as FinalizationViewerMoniker3,
  NetworkStakeStepRewardsByStakerViewerMoniker,
  StakeViewerMoniker as StakeViewerMoniker3
} from "@xyo-network/xl1-protocol/protocol-lib";
import {
  AbstractCreatableProvider as AbstractCreatableProvider7,
  blockRangeSteps as blockRangeSteps2,
  creatableProvider as creatableProvider7
} from "#protocol-sdk";
var SimpleStepRewardsByStakerViewer = class extends AbstractCreatableProvider7 {
  moniker = SimpleStepRewardsByStakerViewer.defaultMoniker;
  _blockViewer;
  _finalizationViewer;
  _stakeViewer;
  get rewardMultipliers() {
    return this.params.rewardMultipliers ?? {};
  }
  get timeAnchor() {
    return this.params.timeAnchor;
  }
  get blockViewer() {
    return this._blockViewer;
  }
  get finalizationViewer() {
    return this._finalizationViewer;
  }
  get stakeViewer() {
    return this._stakeViewer;
  }
  async bonus({ range, stakers } = {}) {
    const total = await this.total({ range, stakers });
    const earned = await this.earned({ range, stakers });
    const result = {};
    for (const staker of Object.keys(total)) {
      result[staker] = asAttoXL12(total[staker] - (earned[staker] ?? 0n));
    }
    return result;
  }
  claimed(_options) {
    throw new Error("Method [claimed] not implemented.");
  }
  async createHandler() {
    await super.createHandler();
    this._blockViewer = await this.locator.getInstance(BlockViewerMoniker2);
    this._finalizationViewer = await this.locator.getInstance(FinalizationViewerMoniker3);
    this._stakeViewer = await this.locator.getInstance(StakeViewerMoniker3);
  }
  async earned(options = {}) {
    return await this.calculateRewards(options);
  }
  async total(options = {}) {
    return await this.calculateRewards(options, this.rewardMultipliers);
  }
  unclaimed(_options = {}) {
    throw new Error("Method [unclaimed] not implemented.");
  }
  async calculateRewards({ range, stakers } = {}, rewardMultipliers) {
    const result = {};
    const steps = blockRangeSteps2(asXL1BlockRange2(
      range ?? [0, await this.finalizationViewer.headNumber()],
      { name: "NodeStepRewardsByStakerViewer" }
    ), [3, 4, 5, 6, 7]);
    for (const step of steps) {
      if (isArray2(stakers)) {
        for (const staker of stakers) {
          const reward = await networkStakeStepRewardEarnedForStaker(
            this.context,
            this.blockViewer,
            this.stakeViewer,
            step,
            staker,
            rewardMultipliers,
            this.timeAnchor
          );
          result[staker] = asAttoXL12((result[staker] ?? 0n) + reward[0]);
        }
      }
    }
    return result;
  }
};
__publicField(SimpleStepRewardsByStakerViewer, "connectionTypes", ["lmdb", "mongo", "memory", "rpc"]);
__publicField(SimpleStepRewardsByStakerViewer, "defaultMoniker", NetworkStakeStepRewardsByStakerViewerMoniker);
__publicField(SimpleStepRewardsByStakerViewer, "dependencies", [BlockViewerMoniker2, FinalizationViewerMoniker3, StakeViewerMoniker3]);
__publicField(SimpleStepRewardsByStakerViewer, "monikers", [NetworkStakeStepRewardsByStakerViewerMoniker]);
__publicField(SimpleStepRewardsByStakerViewer, "surface", "node");
SimpleStepRewardsByStakerViewer = __decorateClass([
  creatableProvider7()
], SimpleStepRewardsByStakerViewer);

// src/modules/providers/SimpleStepRewards/SimpleStepRewardsByStepViewer.ts
import {
  asAttoXL1 as asAttoXL13,
  asXL1BlockRange as asXL1BlockRange3,
  BlockViewerMoniker as BlockViewerMoniker3,
  FinalizationViewerMoniker as FinalizationViewerMoniker4,
  NetworkStakeStepRewardsByStepViewerMoniker,
  StakeViewerMoniker as StakeViewerMoniker4
} from "@xyo-network/xl1-protocol/protocol-lib";
import {
  AbstractCreatableProvider as AbstractCreatableProvider8,
  blockRangeSteps as blockRangeSteps3,
  creatableProvider as creatableProvider8,
  toStepIdentityString as toStepIdentityString2
} from "#protocol-sdk";
var SimpleStepRewardsByStepViewer = class extends AbstractCreatableProvider8 {
  moniker = SimpleStepRewardsByStepViewer.defaultMoniker;
  _blockViewer;
  _finalizationViewer;
  _stakeViewer;
  get rewardMultipliers() {
    return this.params.rewardMultipliers ?? {};
  }
  get timeAnchor() {
    return this.params.timeAnchor;
  }
  get blockViewer() {
    return this._blockViewer;
  }
  get finalizationViewer() {
    return this._finalizationViewer;
  }
  get stakeViewer() {
    return this._stakeViewer;
  }
  async bonus({ range, steps } = {}) {
    const total = await this.total({ range, steps });
    const earned = await this.earned({ range, steps });
    const result = {};
    for (const stepString of Object.keys(total)) {
      result[stepString] = asAttoXL13(total[stepString] - (earned[stepString] ?? 0n));
    }
    return result;
  }
  claimed(_options) {
    throw new Error("Method [claimed] not implemented.");
  }
  async createHandler() {
    await super.createHandler();
    this._blockViewer = await this.locator.getInstance(BlockViewerMoniker3);
    this._finalizationViewer = await this.locator.getInstance(FinalizationViewerMoniker4);
    this._stakeViewer = await this.locator.getInstance(StakeViewerMoniker4);
  }
  async earned({ range, steps } = {}) {
    const result = {};
    const resolvedSteps = steps ?? blockRangeSteps3(asXL1BlockRange3(
      range ?? [0, await this.finalizationViewer.headNumber()],
      { name: "NodeStepRewardsByStepViewer" }
    ), [3, 4, 5, 6, 7]);
    for (const step of resolvedSteps) {
      const stepIdentityString = toStepIdentityString2(step);
      const reward = await networkStakeStepRewardEarned(
        this.context,
        this.blockViewer,
        this.stakeViewer,
        step,
        void 0,
        this.timeAnchor
      );
      result[stepIdentityString] = asAttoXL13((result[stepIdentityString] ?? 0n) + reward[0]);
    }
    return result;
  }
  async total({ range, steps } = {}) {
    const result = {};
    const head = await this.finalizationViewer.head();
    const resolvedSteps = steps ?? blockRangeSteps3(asXL1BlockRange3(
      range ?? [0, head[1]],
      { name: "NodeStepRewardsByStepViewer" }
    ), [3, 4, 5, 6, 7]);
    for (const step of resolvedSteps) {
      const stepIdentityString = toStepIdentityString2(step);
      const reward = await networkStakeStepRewardEarned(
        this.context,
        this.blockViewer,
        this.stakeViewer,
        step,
        this.rewardMultipliers,
        this.timeAnchor
      );
      result[stepIdentityString] = asAttoXL13((result[stepIdentityString] ?? 0n) + reward[0]);
    }
    return result;
  }
  unclaimed(_options = {}) {
    throw new Error("Method  [unclaimed] ot implemented.");
  }
};
__publicField(SimpleStepRewardsByStepViewer, "connectionTypes", ["lmdb", "mongo", "memory", "rpc"]);
__publicField(SimpleStepRewardsByStepViewer, "defaultMoniker", NetworkStakeStepRewardsByStepViewerMoniker);
__publicField(SimpleStepRewardsByStepViewer, "dependencies", [BlockViewerMoniker3, FinalizationViewerMoniker4, StakeViewerMoniker4]);
__publicField(SimpleStepRewardsByStepViewer, "monikers", [NetworkStakeStepRewardsByStepViewerMoniker]);
__publicField(SimpleStepRewardsByStepViewer, "surface", "node");
SimpleStepRewardsByStepViewer = __decorateClass([
  creatableProvider8()
], SimpleStepRewardsByStepViewer);

// src/modules/providers/SimpleStepRewards/SimpleStepRewardsTotalViewer.ts
import { asAttoXL1 as asAttoXL14, NetworkStakeStepRewardsTotalViewerMoniker } from "@xyo-network/xl1-protocol/protocol-lib";
import {
  AbstractCreatableProvider as AbstractCreatableProvider9,
  creatableProvider as creatableProvider9
} from "#protocol-sdk";
var SimpleStepRewardsTotalViewer = class extends AbstractCreatableProvider9 {
  moniker = SimpleStepRewardsTotalViewer.defaultMoniker;
  get rewardMultipliers() {
    return this.params.rewardMultipliers ?? {};
  }
  async bonus({ range } = {}) {
    const total = await this.total({ range });
    const earned = await this.earned({ range });
    return asAttoXL14(total - earned);
  }
  claimed(_options) {
    throw new Error("Method [claimed] not implemented.");
  }
  async earned(options = {}) {
    return await this.calculateRewards(options);
  }
  async total(options = {}) {
    return await this.calculateRewards(options, this.rewardMultipliers);
  }
  unclaimed(_options = {}) {
    throw new Error("Method [unclaimed] not implemented.");
  }
  calculateRewards(_options = {}, _rewardMultipliers) {
    throw new Error("Method  [calculateRewards] not implemented.");
  }
};
__publicField(SimpleStepRewardsTotalViewer, "connectionTypes", ["lmdb", "mongo", "memory", "rpc"]);
__publicField(SimpleStepRewardsTotalViewer, "defaultMoniker", NetworkStakeStepRewardsTotalViewerMoniker);
__publicField(SimpleStepRewardsTotalViewer, "dependencies", []);
__publicField(SimpleStepRewardsTotalViewer, "monikers", [NetworkStakeStepRewardsTotalViewerMoniker]);
__publicField(SimpleStepRewardsTotalViewer, "surface", "node");
SimpleStepRewardsTotalViewer = __decorateClass([
  creatableProvider9()
], SimpleStepRewardsTotalViewer);

// src/modules/providers/SimpleStepRewards/SimpleStepRewardsViewer.ts
import { assertEx as assertEx3 } from "@ariestools/sdk";
import {
  BlockViewerMoniker as BlockViewerMoniker4,
  NetworkStakeStepRewardsByPositionViewerMoniker as NetworkStakeStepRewardsByPositionViewerMoniker2,
  NetworkStakeStepRewardsByStakerViewerMoniker as NetworkStakeStepRewardsByStakerViewerMoniker2,
  NetworkStakeStepRewardsByStepViewerMoniker as NetworkStakeStepRewardsByStepViewerMoniker2,
  NetworkStakeStepRewardsViewerMoniker as NetworkStakeStepRewardsViewerMoniker2
} from "@xyo-network/xl1-protocol/protocol-lib";
import {
  AbstractCreatableProvider as AbstractCreatableProvider10,
  creatableProvider as creatableProvider10
} from "#protocol-sdk";
var SimpleStepRewardsViewer = class extends AbstractCreatableProvider10 {
  moniker = SimpleStepRewardsViewer.defaultMoniker;
  _blockViewer;
  _position;
  _staker;
  _step;
  get position() {
    return assertEx3(this._position, () => "Position viewer not initialized");
  }
  get staker() {
    return assertEx3(this._staker, () => "Position viewer not initialized");
  }
  get step() {
    return assertEx3(this._step, () => "Step viewer not initialized");
  }
  get total() {
    throw new Error("Method [total] not implemented.");
  }
  get rewardMultipliers() {
    return this.params.rewardMultipliers;
  }
  async createHandler() {
    await super.createHandler();
    this._blockViewer = await this.locator.getInstance(BlockViewerMoniker4);
    this._position = await this.locator.getInstance(NetworkStakeStepRewardsByPositionViewerMoniker2);
    this._staker = await this.locator.getInstance(NetworkStakeStepRewardsByStakerViewerMoniker2);
    this._step = await this.locator.getInstance(NetworkStakeStepRewardsByStepViewerMoniker2);
  }
  async startHandler() {
    await super.startHandler();
    await assertEx3(this._position, () => "Position viewer not created").start();
    await assertEx3(this._staker, () => "Staker viewer not created").start();
    await assertEx3(this._step, () => "Step viewer not created").start();
  }
};
__publicField(SimpleStepRewardsViewer, "connectionTypes", ["lmdb", "mongo", "memory", "rpc"]);
__publicField(SimpleStepRewardsViewer, "defaultMoniker", NetworkStakeStepRewardsViewerMoniker2);
__publicField(SimpleStepRewardsViewer, "dependencies", [
  BlockViewerMoniker4,
  NetworkStakeStepRewardsByPositionViewerMoniker2,
  NetworkStakeStepRewardsByStakerViewerMoniker2,
  NetworkStakeStepRewardsByStepViewerMoniker2
]);
__publicField(SimpleStepRewardsViewer, "monikers", [NetworkStakeStepRewardsViewerMoniker2]);
__publicField(SimpleStepRewardsViewer, "surface", "node");
SimpleStepRewardsViewer = __decorateClass([
  creatableProvider10()
], SimpleStepRewardsViewer);

// src/modules/providers/SimpleStepViewer.ts
import {
  BlockViewerMoniker as BlockViewerMoniker5,
  NetworkStakeStepRewardsViewerMoniker as NetworkStakeStepRewardsViewerMoniker3,
  StakeEventsViewerMoniker,
  StakeViewerMoniker as StakeViewerMoniker5,
  StepViewerMoniker
} from "@xyo-network/xl1-protocol/protocol-lib";
import {
  AbstractCreatableProvider as AbstractCreatableProvider11,
  creatableProvider as creatableProvider11,
  externalBlockRangeFromStep as externalBlockRangeFromStep4
} from "#protocol-sdk";
var SimpleStepViewer = class extends AbstractCreatableProvider11 {
  moniker = SimpleStepViewer.defaultMoniker;
  _blockViewer;
  _networkStakeStepRewardsViewer;
  _stakeEventsViewer;
  _stakeViewer;
  get rewards() {
    return this._networkStakeStepRewardsViewer;
  }
  get timeAnchor() {
    return this.params.timeAnchor;
  }
  get blockViewer() {
    return this._blockViewer;
  }
  get stakeEventsViewer() {
    return this._stakeEventsViewer;
  }
  get stakeViewer() {
    return this._stakeViewer;
  }
  async createHandler() {
    await super.createHandler();
    this._blockViewer = await this.locator.getInstance(BlockViewerMoniker5);
    this._networkStakeStepRewardsViewer = await this.locator.getInstance(NetworkStakeStepRewardsViewerMoniker3);
    this._stakeViewer = await this.locator.getInstance(StakeViewerMoniker5);
    this._stakeEventsViewer = await this.locator.getInstance(StakeEventsViewerMoniker);
  }
  async positionCount(step) {
    const externalRange = await externalBlockRangeFromStep4(this.context, this.blockViewer, step, this.timeAnchor);
    const positionCount = await this.stakeEventsViewer.positionCount(externalRange);
    return positionCount;
  }
  // TODO: Implement paging
  async positions(step, _options) {
    const count = await this.positionCount(step);
    const externalRange = await externalBlockRangeFromStep4(this.context, this.blockViewer, step, this.timeAnchor);
    const allPositions = await Promise.all(Array.from({ length: count + 1 }, (_, i) => i).map(async (id) => this.stakeViewer.stakeById(id)));
    return allPositions.filter((pos) => pos.addBlock <= externalRange[1] && (pos.removeBlock === 0 || pos.removeBlock > externalRange[0]));
  }
  randomizer(_step) {
    throw new Error("Method [randomizer] not implemented.");
  }
  stake(_step) {
    throw new Error("Method [stake] not implemented.");
  }
  stakerCount(_step) {
    throw new Error("Method [stakerCount] not implemented.");
  }
  stakers(_step, _options) {
    throw new Error("Method [stakers] not implemented.");
  }
  weight(_step, _positionId) {
    throw new Error("Method [weight] not implemented.");
  }
};
__publicField(SimpleStepViewer, "connectionTypes", ["lmdb", "mongo", "memory", "rpc"]);
__publicField(SimpleStepViewer, "defaultMoniker", StepViewerMoniker);
__publicField(SimpleStepViewer, "dependencies", [
  BlockViewerMoniker5,
  NetworkStakeStepRewardsViewerMoniker3,
  StakeViewerMoniker5,
  StakeEventsViewerMoniker
]);
__publicField(SimpleStepViewer, "monikers", [StepViewerMoniker]);
__publicField(SimpleStepViewer, "surface", "node");
SimpleStepViewer = __decorateClass([
  creatableProvider11()
], SimpleStepViewer);

// src/modules/providers/SimpleXyoViewer.ts
import {
  assertEx as assertEx4,
  toAddress
} from "@ariestools/sdk";
import {
  AccountBalanceViewerMoniker,
  asAttoXL1 as asAttoXL15,
  asXL1BlockRange as asXL1BlockRange4,
  BlockViewerMoniker as BlockViewerMoniker6,
  ChainContractViewerMoniker,
  FinalizationViewerMoniker as FinalizationViewerMoniker5,
  MempoolViewerMoniker,
  NetworkStakeStepRewardsByPositionViewerMoniker as NetworkStakeStepRewardsByPositionViewerMoniker3,
  NetworkStakeViewerMoniker as NetworkStakeViewerMoniker2,
  StakeTotalsViewerMoniker as StakeTotalsViewerMoniker2,
  StakeViewerMoniker as StakeViewerMoniker6,
  StepViewerMoniker as StepViewerMoniker2,
  TimeSyncViewerMoniker,
  TransactionViewerMoniker,
  XYO_NETWORK_STAKING_ADDRESS as XYO_NETWORK_STAKING_ADDRESS4,
  XYO_ZERO_ADDRESS,
  XyoViewerMoniker as XyoViewerMoniker3
} from "@xyo-network/xl1-protocol/protocol-lib";
import {
  AbstractCreatableProvider as AbstractCreatableProvider12,
  allStakersForStep,
  blockRangeSteps as blockRangeSteps4,
  creatableProvider as creatableProvider12,
  externalBlockRangeFromStep as externalBlockRangeFromStep5,
  externalBlockRangeFromXL1BlockRange,
  networkStakeStepRewardPositionWeight,
  stepRewardTotal as stepRewardTotal2,
  toStepIdentityString as toStepIdentityString3,
  weightedStakeForRangeByPosition as weightedStakeForRangeByPosition2,
  withContextCacheResponse as withContextCacheResponse4
} from "#protocol-sdk";
var SimpleXyoViewer = class extends AbstractCreatableProvider12 {
  moniker = SimpleXyoViewer.defaultMoniker;
  _tracer;
  _accountBalanceViewer;
  _blockViewer;
  _chainContractViewer;
  _chainId;
  _finalizationViewer;
  _mempoolViewer;
  _networkStakeViewer;
  _networkStepRewardsByPositionViewer;
  _rewardMultipliers;
  _stakeTotalsViewer;
  _stakeViewer;
  _stepViewer;
  _timeSyncViewer;
  _transaction;
  get account() {
    return { balance: this._accountBalanceViewer };
  }
  get block() {
    return this._blockViewer;
  }
  get chainContractViewer() {
    return this._chainContractViewer;
  }
  get finalization() {
    return this._finalizationViewer;
  }
  get mempool() {
    return assertEx4(this._mempoolViewer, () => "MempoolViewer not available on this gateway (no mempool binding \u2014 read-only chain source)");
  }
  get networkStake() {
    return this._networkStakeViewer;
  }
  get stake() {
    return this._stakeViewer;
  }
  get stakeTotals() {
    return this._stakeTotalsViewer;
  }
  get step() {
    return this._stepViewer;
  }
  get time() {
    return this._timeSyncViewer;
  }
  get transaction() {
    return this._transaction;
  }
  get finalizationViewer() {
    return this._finalizationViewer;
  }
  get initRewardsCache() {
    return this.params.initRewardsCache ?? false;
  }
  get networkStepRewardsByPositionViewer() {
    return this._networkStepRewardsByPositionViewer;
  }
  get rewardMultipliers() {
    this._rewardMultipliers = this._rewardMultipliers ?? this.params.rewardMultipliers ?? {};
    return this._rewardMultipliers;
  }
  get timeAnchor() {
    return this.params.timeAnchor;
  }
  async accountBalance(address, config = {}) {
    return await this.account.balance.accountBalance(address, config);
  }
  async accountBalanceHistory(address, config = {}) {
    return await this.account.balance.accountBalanceHistory(address, config);
  }
  async blockByHash(hash) {
    return await this.block.blockByHash(hash);
  }
  async blockByNumber(blockNumber) {
    return await this.block.blockByNumber(blockNumber);
  }
  async blocksByHash(hash, limit = 10) {
    return await this.block.blocksByHash(hash, limit);
  }
  async blocksByNumber(blockNumber, limit = 10) {
    return await this.block.blocksByNumber(blockNumber, limit);
  }
  async blocksByStep(stepLevel, stepIndex) {
    return await this.block.blocksByStep(stepLevel, stepIndex);
  }
  async chainId(blockNumber = "latest") {
    return await this.spanAsync("SimpleXyoViewer:chainId", async () => {
      const chainId = assertEx4(
        blockNumber === "latest" ? this._chainId : await this.chainContractViewer.chainIdAtBlockNumber(blockNumber),
        () => `Could not find block for chainId at block ${blockNumber}`
      );
      return chainId;
    }, this.context);
  }
  async createHandler() {
    await super.createHandler();
    this._accountBalanceViewer = await this.locator.getInstance(AccountBalanceViewerMoniker);
    this._blockViewer = await this.locator.getInstance(BlockViewerMoniker6);
    this._chainContractViewer = await this.locator.getInstance(ChainContractViewerMoniker);
    this._finalizationViewer = await this.locator.getInstance(FinalizationViewerMoniker5);
    this._mempoolViewer = await this.locator.tryGetInstance(MempoolViewerMoniker);
    this._networkStakeViewer = await this.locator.getInstance(NetworkStakeViewerMoniker2);
    this._networkStepRewardsByPositionViewer = await this.locator.getInstance(NetworkStakeStepRewardsByPositionViewerMoniker3);
    this._stakeViewer = await this.locator.getInstance(StakeViewerMoniker6);
    this._stakeTotalsViewer = await this.locator.tryGetInstance(StakeTotalsViewerMoniker2);
    this._stepViewer = await this.locator.getInstance(StepViewerMoniker2);
    this._timeSyncViewer = await this.locator.getInstance(TimeSyncViewerMoniker);
    this._transaction = await this.locator.getInstance(TransactionViewerMoniker);
    this._chainId = await this._chainContractViewer.chainId();
  }
  async currentBlock() {
    return await this.block.currentBlock();
  }
  async currentBlockHash() {
    return await this.block.currentBlockHash();
  }
  async currentBlockNumber() {
    return await this.block.currentBlockNumber();
  }
  forkHistory() {
    throw new Error("Method [forkHistory] not implemented.");
  }
  networkStakeStepRewardAddressHistory(_address) {
    throw new Error("Method [networkStakeStepRewardAddressHistory] not implemented.");
  }
  networkStakeStepRewardAddressReward(_context, _address) {
    throw new Error("Method [networkStakeStepRewardAddressReward] not implemented.");
  }
  networkStakeStepRewardAddressShare(_context, _address) {
    throw new Error("Method [networkStakeStepRewardAddressShare] not implemented.");
  }
  networkStakeStepRewardClaimedByAddress(_address) {
    throw new Error("Method [networkStakeStepRewardClaimedByAddress] not implemented.");
  }
  async networkStakeStepRewardForPosition(position, range) {
    const cacheKey = `${position}|${range[0]}-${range[1]}`;
    return await withContextCacheResponse4(this.context, "SimpleXyoViewer:networkStakeStepRewardForPosition", cacheKey, async () => {
      const externalRange = await externalBlockRangeFromXL1BlockRange(this.context, this.block, range, "ethereum", this.timeAnchor);
      const positionCount = await this.stake.stakeEvents.positionCount(externalRange);
      if (positionCount === 0) {
        return [asAttoXL15(0n), asAttoXL15(0n)];
      }
      const steps = blockRangeSteps4(range, [3, 4, 5, 6, 7]);
      const rewards = await Promise.all(steps.map((step) => this.networkStakeStepRewardForStepForPosition(step, position)));
      const positionReward = asAttoXL15(rewards.reduce((a, b) => a + b[0], 0n));
      const totalReward = asAttoXL15(rewards.reduce((a, b) => a + b[1], 0n));
      return [positionReward, totalReward];
    });
  }
  async networkStakeStepRewardForStep(stepContext) {
    return await stepRewardTotal2(this.context, this.block, stepContext, this.rewardMultipliers);
  }
  async networkStakeStepRewardForStepForPosition(stepIdentity, position) {
    const stepIdentityString = toStepIdentityString3(stepIdentity);
    const range = await externalBlockRangeFromStep5(this.context, this.block, stepIdentity, this.timeAnchor);
    const cacheKey = `${stepIdentityString}|${position}|${range[0]}-${range[1]}`;
    return await withContextCacheResponse4(this.context, "SimpleXyoViewer:networkStakeStepRewardForStepForPosition", cacheKey, async () => {
      const stake = await this.stakeById(position);
      const numerator = stake.staked === XYO_NETWORK_STAKING_ADDRESS4 ? await weightedStakeForRangeByPosition2(this.context, this.block, this.stake.stakeEvents, range, XYO_NETWORK_STAKING_ADDRESS4, position) : 0n;
      const denominator = await this.stepWeightedDenominator(stepIdentity);
      const totalReward = await this.networkStakeStepRewardForStep(stepIdentity);
      const positionReward = asAttoXL15(denominator > 0n ? totalReward * numerator / denominator : 0n);
      const result = [positionReward, totalReward];
      return result;
    });
  }
  async networkStakeStepRewardPoolRewards(step) {
    const stakes = await this.stake.stakesByStaked(XYO_NETWORK_STAKING_ADDRESS4);
    const rewards = [];
    for (const stake of stakes) {
      rewards.push([stake.staker, await this.networkStakeStepRewardForStepForPosition(
        step,
        stake.id
      )]);
    }
    const result = {};
    for (const [staker, reward] of rewards) {
      result[staker] = asAttoXL15((result[staker] ?? 0n) + reward[0]);
    }
    const filtered = Object.fromEntries(Object.entries(result).filter(([_, v]) => v > 0n));
    return filtered;
  }
  networkStakeStepRewardPoolShares(_context) {
    throw new Error("Method [networkStakeStepRewardPoolShares] not implemented.");
  }
  async networkStakeStepRewardPositionWeight(stepContext, position) {
    return await networkStakeStepRewardPositionWeight(this.context, this.block, this.stake.stakeEvents, stepContext, position, this.timeAnchor);
  }
  networkStakeStepRewardPotentialPositionLoss(_context, _position) {
    throw new Error("Method [networkStakeStepRewardPotentialPositionLoss] not implemented.");
  }
  networkStakeStepRewardRandomizer(_context) {
    throw new Error("Method [networkStakeStepRewardRandomizer] not implemented.");
  }
  async networkStakeStepRewardStakerCount(stepContext) {
    return Object.keys(await allStakersForStep(
      this.context,
      this.block,
      this.stake.stakeEvents,
      stepContext,
      XYO_NETWORK_STAKING_ADDRESS4,
      this.timeAnchor
    )).length;
  }
  networkStakeStepRewardUnclaimedByAddress(_address) {
    throw new Error("Method [networkStakeStepRewardUnclaimedByAddress] not implemented.");
  }
  networkStakeStepRewardWeightForAddress(_context, _address) {
    throw new Error("Method [networkStakeStepRewardWeightForAddress] not implemented.");
  }
  async networkStakeStepRewardsForPosition(position, range) {
    const steps = blockRangeSteps4(range, [3, 4, 5, 6, 7, 8]);
    const rewards = await Promise.all(steps.map(async (step) => {
      return [toStepIdentityString3(step), await this.networkStakeStepRewardForStepForPosition(step, position)];
    }));
    const result = Object.fromEntries(rewards);
    const filtered = Object.fromEntries(Object.entries(result).filter(([_, v]) => v[0] > 0n));
    return filtered;
  }
  async networkStakeStepRewardsForRange(range) {
    return await this.spanAsync("networkStakeStepRewardsForRange", async () => {
      const steps = blockRangeSteps4(range, [3, 4, 5, 6, 7, 8]);
      const rewards = await Promise.all(steps.map(async (step) => {
        return await this.networkStakeStepRewardForStep(step);
      }));
      return asAttoXL15(rewards.reduce((a, b) => a + b, 0n));
    }, this.context);
  }
  async networkStakeStepRewardsForStepLevel(stepLevel, range) {
    const steps = blockRangeSteps4(range, [stepLevel]);
    const rewards = await Promise.all(steps.map(async (step) => {
      return await this.networkStakeStepRewardForStep(step);
    }));
    return asAttoXL15(rewards.reduce((a, b) => a + b, 0n));
  }
  payloadByHash(_hash) {
    throw new Error("Method [payloadByHash] not implemented.");
  }
  payloadsByHash(_hashes) {
    throw new Error("Method [payloadsByHash] not implemented.");
  }
  async rate(range, timeUnit) {
    return await this.block.rate(range, timeUnit);
  }
  async stakeById(id) {
    return await this.stake.stakeById(id);
  }
  async stakeByStaker(staker, slot) {
    return await this.stake.stakeByStaker(staker, slot);
  }
  async stakedByStaker(staker) {
    const result = /* @__PURE__ */ new Set();
    let slot = 0;
    while (true) {
      try {
        const ethStake = await this.stake.stakeByStaker(staker, slot);
        result.add(toAddress(ethStake.staked));
        slot++;
      } catch {
        break;
      }
    }
    return [...result];
  }
  async stakesByStaked(staked) {
    return await this.stake.stakesByStaked(staked);
  }
  async stakesByStaker(staker) {
    return await this.stake.stakesByStaker(staker);
  }
  async stepSizeRate(start, stepSizeIndex, count, timeUnit) {
    return await this.block.stepSizeRate(start, stepSizeIndex, count, timeUnit);
  }
  async timeDurationRate(timeConfig, startBlock, timeUnit, toleranceMs, maxAttempts) {
    return await this.block.timeDurationRate(timeConfig, startBlock, timeUnit, toleranceMs, maxAttempts);
  }
  async transactionByBlockHashAndIndex(blockHash, transactionIndex = 0) {
    return await this.transaction.byBlockHashAndIndex(blockHash, transactionIndex);
  }
  async transactionByBlockNumberAndIndex(blockNumber, transactionIndex = 0) {
    return await this.transaction.byBlockNumberAndIndex(blockNumber, transactionIndex);
  }
  async transactionByHash(transactionHash) {
    return await this.transaction.byHash(transactionHash);
  }
  async startHandler() {
    try {
      const currentBlockNumber = await this.currentBlockNumber();
      await this.account.balance.accountBalance(XYO_ZERO_ADDRESS);
      if (this.initRewardsCache) {
        const externalRange = await externalBlockRangeFromXL1BlockRange(
          this.context,
          this.block,
          asXL1BlockRange4([0, currentBlockNumber], { name: "startHandler" }),
          "ethereum",
          this.timeAnchor
        );
        const positionCount = await this.stake.stakeEvents.positionCount(externalRange);
        this.logger?.debug(`SimpleXyoViewer: Precomputing networkStakeStepRewardForPosition up to position ${positionCount - 1}`);
        const positions = Array.from(
          { length: positionCount },
          (_, i) => i
        );
        while (positions.length > 0) {
          const batch = positions.splice(0, 10);
          this.logger?.debug(`SimpleXyoViewer: Precomputing networkStakeStepRewardForPosition for positions ${batch.at(0)} - ${batch.at(-1)}`);
          await Promise.all(batch.map(async (_, position) => await this.networkStakeStepRewardForPosition(
            position,
            asXL1BlockRange4([0, currentBlockNumber], { name: "startHandler" })
          )));
        }
        this.logger?.debug(`SimpleXyoViewer: Precomputed networkStakeStepRewardForPosition up to position ${positionCount - 1}`);
      }
    } catch (ex) {
      this.logger?.error(`SimpleXyoViewer: Error during startHandler initialization: ${ex.message}`);
      this.logger?.error(ex.stack ?? "<No Stack>");
      throw ex;
    }
  }
  async stepWeightedDenominator(stepIdentity, staked) {
    const range = await externalBlockRangeFromStep5(this.context, this.block, stepIdentity, this.timeAnchor);
    const cacheKey = `${toStepIdentityString3(stepIdentity)}|${staked ?? "all"}|${range[0]}-${range[1]}`;
    return await withContextCacheResponse4(this.context, "NodeXyoViewer-networkStakeStepRewardForStepForPosition-denominator", cacheKey, async () => {
      return await weightedStakeForRangeByPosition2(this.context, this.block, this.stake.stakeEvents, range, staked);
    });
  }
};
__publicField(SimpleXyoViewer, "connectionTypes", ["lmdb", "mongo", "memory"]);
__publicField(SimpleXyoViewer, "defaultMoniker", XyoViewerMoniker3);
__publicField(SimpleXyoViewer, "dependencies", [
  AccountBalanceViewerMoniker,
  BlockViewerMoniker6,
  ChainContractViewerMoniker,
  FinalizationViewerMoniker5,
  NetworkStakeViewerMoniker2,
  NetworkStakeStepRewardsByPositionViewerMoniker3,
  StakeViewerMoniker6,
  StepViewerMoniker2,
  TimeSyncViewerMoniker,
  TransactionViewerMoniker
]);
__publicField(SimpleXyoViewer, "monikers", [XyoViewerMoniker3]);
__publicField(SimpleXyoViewer, "surface", "node");
SimpleXyoViewer = __decorateClass([
  creatableProvider12()
], SimpleXyoViewer);

// src/modules/providers/locators/providerCandidates.ts
var PROVIDER_IMPLEMENTATIONS = [
  JsonRpcAccountBalanceViewer,
  JsonRpcBlockViewer,
  JsonRpcFinalizationViewer,
  JsonRpcMempoolRunner,
  JsonRpcMempoolViewer,
  JsonRpcNetworkStakeViewer,
  JsonRpcStakeTotalsViewer,
  JsonRpcStakeViewer,
  JsonRpcTimeSyncViewer,
  JsonRpcTransactionViewer,
  JsonRpcXyoRunner,
  JsonRpcXyoSigner,
  JsonRpcXyoViewer,
  RestBlockViewer,
  RestChainContractViewer,
  RestChainStateViewer,
  RestDataLakeRunner,
  RestDataLakeViewer,
  RestFinalizationViewer,
  RestIndexViewer,
  SimpleAccountBalanceViewer,
  SimpleBlockRewardViewer,
  SimpleBlockValidationViewer,
  SimpleBlockViewer,
  SimpleChainContractViewer,
  SimpleDeadLetterQueueRunner,
  SimpleDeadLetterQueueViewer,
  SimpleEvmChainViewer,
  SimpleFinalizationRunner,
  SimpleFinalizationViewer,
  SimpleIndexViewer,
  SimpleMempoolRunner,
  SimpleMempoolViewer,
  SimpleNetworkStakeViewer,
  SimpleStakeEventsViewer,
  SimpleStakeTotalsViewer,
  SimpleStakeViewer,
  SimpleStepRewardsByPositionViewer,
  SimpleStepRewardsByStakerViewer,
  SimpleStepRewardsByStepViewer,
  SimpleStepRewardsTotalViewer,
  SimpleStepRewardsViewer,
  SimpleStepViewer,
  SimpleTimeSyncViewer,
  SimpleTransactionValidationViewer,
  SimpleTransactionViewer,
  SimpleWindowedBlockViewer,
  SimpleXyoConnectionRunner,
  SimpleXyoConnectionViewer,
  SimpleXyoGateway,
  SimpleXyoGatewayRunner,
  SimpleXyoRunner,
  SimpleXyoViewer
];
function allProviderCandidates() {
  return providerCandidatesFromClasses(PROVIDER_IMPLEMENTATIONS);
}

// src/modules/providers/locators/locatorFromAdaptedConfig.ts
function locatorFromAdaptedConfig(options) {
  const adapted = parseLocatorConfigFields(options.config);
  const needs = options.needs ?? needsFromProviderBindings(adapted);
  const candidates = options.candidates ?? allProviderCandidates();
  if (options.validateDepsOnRegister === true) {
    const plan = resolveProvidersFromConfig(needs, candidates, adapted);
    const locator = new ProviderFactoryLocator3({
      singletons: {},
      caches: {},
      ...options.context,
      config: adapted
    }, {}, true);
    registerFactoriesFromPlan(locator, plan);
    return locator;
  }
  return locatorFromConfig({
    candidates,
    config: adapted,
    context: options.context,
    needs
  });
}

// src/modules/providers/locators/remoteLocatorFromConfig.ts
function remoteLocatorFromConfig(context, validateDepsOnRegister = false, validators) {
  const config = parseLocatorConfigFields2(context.config);
  const locator = locatorFromAdaptedConfig({
    config,
    context: {
      caches: context.caches,
      singletons: context.singletons
    },
    needs: needsFromConnectionTypes(config, ["rpc"]),
    validateDepsOnRegister
  });
  locator.register(
    SimpleStakeEventsViewer2.factory(
      SimpleStakeEventsViewer2.dependencies,
      { positions: [] }
    )
  );
  locator.register(
    SimpleWindowedBlockViewer2.factory(
      SimpleWindowedBlockViewer2.dependencies,
      { maxWindowSize: 1e3, syncInterval: 1e4 }
    )
  );
  locator.register(
    SimpleTransactionValidationViewer2.factory(
      SimpleTransactionValidationViewer2.dependencies,
      {}
    )
  );
  if (validators?.validateHydratedBlock !== void 0 || validators?.validateHydratedBlockState !== void 0) {
    locator.register(
      SimpleBlockValidationViewer2.factory(
        SimpleBlockValidationViewer2.dependencies,
        {
          protocol: validators.validateHydratedBlock,
          state: validators.validateHydratedBlockState
        }
      )
    );
  }
  return locator;
}

// src/modules/providers/locators/basicRemoteViewerLocator.ts
async function basicRemoteViewerLocator(name, rpcConnection, dataLakeEndpoint, options) {
  const config = ActorConfigZod.parse({
    name,
    connections: { "default-rpc": { type: "rpc", ...rpcConnection } },
    providerBindings: synthesizeRpcConnectionBindings()
  });
  const locator = await remoteLocatorFromConfig(
    {
      config,
      singletons: {},
      caches: {}
    },
    false,
    options?.validators
  );
  locator.registerMany([
    SimpleXyoGateway2.factory(SimpleXyoGateway2.dependencies, {}),
    SimpleXyoConnectionViewer.factory(SimpleXyoConnectionViewer.dependencies, {}),
    ...options?.additionalProviders ?? []
  ]);
  if (isDefined2(dataLakeEndpoint)) {
    const dataLakeViewerParams = { endpoint: dataLakeEndpoint };
    locator.register(RestDataLakeViewer2.factory(RestDataLakeViewer2.dependencies, dataLakeViewerParams));
  }
  locator.freeze();
  return locator;
}

// src/modules/providers/locators/basicRemoteRunnerLocator.ts
async function basicRemoteRunnerLocator(name, rpcConnection, signerTransport, dataLakeEndpoint, options) {
  const remoteViewerLocator = await basicRemoteViewerLocator(name, rpcConnection, dataLakeEndpoint, options);
  const locator = new ProviderFactoryLocator4(remoteViewerLocator.context, {});
  const providers = [
    SimpleXyoConnectionRunner.factory(SimpleXyoConnectionRunner.dependencies, {}),
    JsonRpcXyoRunner2.factory(JsonRpcXyoRunner2.dependencies, {})
  ];
  if (options?.skipGatewayRunner !== true) {
    providers.push(
      SimpleXyoGatewayRunner2.factory(SimpleXyoGatewayRunner2.dependencies, {})
    );
  }
  locator.registerMany([
    ...providers,
    ...options?.additionalRunnerProviders ?? []
  ]);
  if (options?.signerFactory) {
    locator.register(options.signerFactory);
  } else if (isDefined3(signerTransport)) {
    locator.register(
      JsonRpcXyoSigner2.factory(JsonRpcXyoSigner2.dependencies, { transport: signerTransport })
    );
  } else {
    throw new Error("basicRemoteRunnerLocator requires either signerTransport or options.signerFactory");
  }
  if (isDefined3(dataLakeEndpoint)) {
    const dataLakeParams = { endpoint: dataLakeEndpoint };
    locator.register(RestDataLakeViewer3.factory(RestDataLakeViewer3.dependencies, dataLakeParams));
    locator.register(RestDataLakeRunner2.factory(RestDataLakeRunner2.dependencies, dataLakeParams));
  }
  locator.freeze();
  return locator;
}

// src/modules/providers/locators/basicRestRunnerLocator.ts
import { isDefined as isDefined5 } from "@ariestools/sdk";
import {
  ProviderFactoryLocator as ProviderFactoryLocator5,
  RestDataLakeRunner as RestDataLakeRunner3,
  RestDataLakeViewer as RestDataLakeViewer5,
  SimpleXyoGatewayRunner as SimpleXyoGatewayRunner3
} from "#protocol-sdk";
import { JsonRpcMempoolRunner as JsonRpcMempoolRunner2, JsonRpcXyoRunner as JsonRpcXyoRunner3 } from "#rpc";

// src/modules/providers/locators/basicRestViewerLocator.ts
import { isDefined as isDefined4 } from "@ariestools/sdk";
import {
  ActorConfigZod as ActorConfigZod2,
  RestDataLakeViewer as RestDataLakeViewer4,
  SimpleStakeEventsViewer as SimpleStakeEventsViewer3,
  SimpleXyoGateway as SimpleXyoGateway3,
  synthesizeMemoryViewerBindings
} from "#protocol-sdk";
import {
  RestBlockViewer as RestBlockViewer2,
  RestChainContractViewer as RestChainContractViewer2,
  RestChainStateViewer as RestChainStateViewer2,
  RestIndexViewer as RestIndexViewer2
} from "#rest-block-viewer";
async function basicRestViewerLocator(name, restConfig, dataLakeEndpoint, options) {
  const connections = {
    "rest-blocks": restConfig.blocks,
    "memory": { type: "memory" }
  };
  const providerBindings = {
    BlockViewer: { connection: "rest-blocks" },
    ChainContractViewer: { connection: "rest-blocks" },
    ChainStateViewer: { connection: "rest-blocks" },
    FinalizationViewer: { connection: "rest-blocks" },
    IndexViewer: { connection: "rest-blocks" },
    ...synthesizeMemoryViewerBindings()
  };
  if (isDefined4(restConfig.chainState)) {
    connections["rest-chain-state"] = restConfig.chainState;
    providerBindings.ChainStateViewer = { connection: "rest-chain-state" };
    providerBindings.ChainContractViewer = { connection: "rest-chain-state" };
  }
  if (isDefined4(restConfig.index)) {
    connections["rest-index"] = restConfig.index;
    providerBindings.IndexViewer = { connection: "rest-index" };
  }
  const config = ActorConfigZod2.parse({
    name,
    connections,
    providerBindings
  });
  const locator = locatorFromAdaptedConfig({
    config,
    context: { singletons: {}, caches: {} }
  });
  locator.registerMany([
    SimpleXyoGateway3.factory(SimpleXyoGateway3.dependencies, {}),
    SimpleXyoConnectionViewer.factory(SimpleXyoConnectionViewer.dependencies, {}),
    SimpleStakeEventsViewer3.factory(SimpleStakeEventsViewer3.dependencies, { positions: [] }),
    // always registered with an explicit initRewardsCache: the REST default is false (see
    // BasicRestViewerLocatorOptions) — SimpleXyoViewer's own default of true would walk the whole
    // chain one round trip per position/step during gateway construction
    SimpleXyoViewer.factory(SimpleXyoViewer.dependencies, { initRewardsCache: options?.initRewardsCache ?? false })
  ]);
  const fetchFn = options?.fetchFn;
  const chainStateBaseUrl = (restConfig.chainState ?? restConfig.blocks).baseUrl;
  const indexBaseUrl = (restConfig.index ?? restConfig.blocks).baseUrl;
  locator.registerMany([
    RestBlockViewer2.factory(RestBlockViewer2.dependencies, {
      chainStateBaseUrl,
      fetchFn,
      finalizedBaseUrl: restConfig.blocks.baseUrl,
      indexBaseUrl
    }),
    RestChainStateViewer2.factory(RestChainStateViewer2.dependencies, { chainStateBaseUrl, fetchFn }),
    RestChainContractViewer2.factory(RestChainContractViewer2.dependencies, { contractBaseUrl: chainStateBaseUrl, fetchFn }),
    RestIndexViewer2.factory(RestIndexViewer2.dependencies, { fetchFn, indexBaseUrl })
  ]);
  const endpoint = dataLakeEndpoint ?? options?.dataLakeEndpoint;
  if (isDefined4(endpoint)) {
    const dataLakeViewerParams = { endpoint };
    locator.register(RestDataLakeViewer4.factory(RestDataLakeViewer4.dependencies, dataLakeViewerParams));
  }
  locator.freeze();
  return locator;
}

// src/modules/providers/locators/basicRestRunnerLocator.ts
async function basicRestRunnerLocator(name, restConfig, dataLakeEndpoint, options) {
  const restViewerLocator = await basicRestViewerLocator(name, restConfig, dataLakeEndpoint, options);
  const locator = new ProviderFactoryLocator5(restViewerLocator.context, {});
  const { rpcUrl } = options;
  const providers = [
    SimpleXyoConnectionRunner.factory(SimpleXyoConnectionRunner.dependencies, {}),
    // Explicit rpcUrl — REST actor config has no `default-rpc` connection for discovery.
    JsonRpcMempoolRunner2.factory(JsonRpcMempoolRunner2.dependencies, { rpcUrl }),
    JsonRpcXyoRunner3.factory(JsonRpcXyoRunner3.dependencies, { rpcUrl })
  ];
  if (options.skipGatewayRunner !== true) {
    providers.push(
      SimpleXyoGatewayRunner3.factory(SimpleXyoGatewayRunner3.dependencies, {})
    );
  }
  locator.registerMany([
    ...providers,
    options.signerFactory,
    ...options.additionalRunnerProviders ?? []
  ]);
  if (isDefined5(dataLakeEndpoint)) {
    const dataLakeParams = { endpoint: dataLakeEndpoint };
    locator.register(RestDataLakeViewer5.factory(RestDataLakeViewer5.dependencies, dataLakeParams));
    locator.register(RestDataLakeRunner3.factory(RestDataLakeRunner3.dependencies, dataLakeParams));
  }
  locator.freeze();
  return locator;
}

// src/modules/providers/locators/rootLocatorFromConfig.ts
import { assertEx as assertEx5 } from "@ariestools/sdk";
async function rootLocatorFromConfig(context, validateDepsOnRegister = false, validators) {
  const { config } = context;
  const hasRpcConnection = config.connections?.["default-rpc"] !== void 0 || Object.values(config.connections ?? {}).some((connection) => connection?.type === "rpc");
  const newLocator = hasRpcConnection ? await remoteLocatorFromConfig(context, validateDepsOnRegister, validators) : void 0;
  const locator = assertEx5(newLocator, () => "Root locator could not be created from config. No supported configuration found.");
  locator.freeze();
  return locator;
}

// src/modules/providers/creators/createRestDataLake.ts
async function createRestDataLakeViewer(dataLakeEndpoint) {
  const locator = await baseConfigFactoryLocator();
  const dataLakeViewerParams = { endpoint: dataLakeEndpoint };
  locator.register(RestDataLakeViewer6.factory(RestDataLakeViewer6.dependencies, dataLakeViewerParams));
  locator.freeze();
  return await locator.getInstance(RestDataLakeViewer6.defaultMoniker);
}
async function createRestDataLakeRunner(dataLakeEndpoint) {
  const locator = await baseConfigFactoryLocator();
  const dataLakeRunnerParams = { endpoint: dataLakeEndpoint };
  locator.register(RestDataLakeRunner4.factory(RestDataLakeRunner4.dependencies, dataLakeRunnerParams));
  locator.freeze();
  return await locator.getInstance(RestDataLakeRunner4.defaultMoniker);
}

// src/modules/providers/registerHelpers.ts
import {
  SimpleStakeEventsViewer as SimpleStakeEventsViewer4,
  SimpleStakeViewer as SimpleStakeViewer2,
  SimpleXyoGateway as SimpleXyoGateway4,
  SimpleXyoGatewayRunner as SimpleXyoGatewayRunner4,
  SimpleXyoSigner as SimpleXyoSigner2
} from "#protocol-sdk";
var registerGatewayWithLocator = (locator, account) => {
  locator.registerMany([
    SimpleXyoConnectionRunner.factory(SimpleXyoConnectionRunner.dependencies, {}),
    SimpleXyoGateway4.factory(SimpleXyoGateway4.dependencies, {})
  ]);
  if (account) {
    locator.registerMany([
      SimpleXyoSigner2.factory(SimpleXyoSigner2.dependencies, { account }),
      SimpleXyoGatewayRunner4.factory(SimpleXyoGatewayRunner4.dependencies, {})
    ]);
  }
  return locator;
};
var registerSimpleStakeViewerWithLocator = (locator, positions) => {
  locator.registerMany([
    SimpleStakeViewer2.factory(SimpleStakeViewer2.dependencies, { positions }),
    SimpleStakeEventsViewer4.factory(SimpleStakeEventsViewer4.dependencies, { positions })
  ]);
  return locator;
};
export {
  SimpleDeadLetterQueueRunner,
  SimpleDeadLetterQueueViewer,
  SimpleNetworkStakeViewer,
  SimpleStepRewardsByPositionViewer,
  SimpleStepRewardsByStakerViewer,
  SimpleStepRewardsByStepViewer,
  SimpleStepRewardsTotalViewer,
  SimpleStepRewardsViewer,
  SimpleStepViewer,
  SimpleXyoConnectionRunner,
  SimpleXyoConnectionViewer,
  SimpleXyoViewer,
  allProviderCandidates,
  baseConfigFactoryLocator,
  basicRemoteRunnerLocator,
  basicRemoteViewerLocator,
  basicRestRunnerLocator,
  basicRestViewerLocator,
  buildSimpleXyoSigner,
  buildSimpleXyoSignerV2,
  createRestDataLakeRunner,
  createRestDataLakeViewer,
  locatorFromAdaptedConfig,
  registerGatewayWithLocator,
  registerSimpleStakeViewerWithLocator,
  remoteLocatorFromConfig,
  rootLocatorFromConfig
};
//# sourceMappingURL=providers.mjs.map
