// src/modules/rpc/engine-node/composedRpcEngineFromConnection.ts
import {
  JsonRpcEngineV2,
  JsonRpcServer
} from "@metamask/json-rpc-engine/v2";
import { XyoGatewayRunnerMoniker } from "@xyo-network/xl1-protocol/protocol-lib";

// src/modules/rpc/engine/requestSchemas.ts
var requestSchemas = {};

// src/modules/rpc/engine/rpcMethodHandlersFromAccountBalanceViewer.ts
var rpcMethodHandlersFromAccountBalanceViewer = (viewer) => {
  return {
    accountBalanceViewer_qualifiedAccountBalances: (params) => viewer.qualifiedAccountBalances(...params ?? []),
    accountBalanceViewer_qualifiedAccountBalanceHistories: (params) => viewer.qualifiedAccountBalanceHistories(...params ?? [])
  };
};

// src/modules/rpc/engine/rpcMethodHandlersFromBlockViewer.ts
var rpcMethodHandlersFromBlockViewer = (viewer) => {
  return {
    blockViewer_blocksByHash: (params) => viewer.blocksByHash(...params ?? []),
    blockViewer_blocksByNumber: (params) => viewer.blocksByNumber(...params ?? []),
    blockViewer_blocksByStep: (params) => viewer.blocksByStep(...params ?? []),
    blockViewer_currentBlock: (params) => viewer.currentBlock(...params ?? []),
    blockViewer_payloadsByHash: (params) => viewer.payloadsByHash(...params ?? [])
  };
};

// src/modules/rpc/engine/rpcMethodHandlersFromFinalizationViewer.ts
var rpcMethodHandlersFromFinalizationViewer = (viewer) => {
  return { finalizationViewer_head: (params) => viewer.head(...params ?? []) };
};

// src/modules/rpc/engine/rpcMethodHandlersFromMempoolRunner.ts
var rpcMethodHandlersFromMempoolRunner = (runner) => {
  return {
    mempoolRunner_submitBlocks: (params) => runner.submitBlocks(...params ?? []),
    mempoolRunner_submitTransactions: (params) => runner.submitTransactions(...params ?? [])
  };
};

// src/modules/rpc/engine/rpcMethodHandlersFromMempoolViewer.ts
var rpcMethodHandlersFromMempoolViewer = (viewer) => {
  return {
    mempoolViewer_pendingBlocks: (params) => viewer.pendingBlocks(...params ?? []),
    mempoolViewer_pendingTransactions: (params) => viewer.pendingTransactions(...params ?? [])
  };
};

// src/modules/rpc/engine/rpcMethodHandlersFromNetworkStakingStepRewardsByPositionViewer.ts
var rpcMethodHandlersFromNetworkStakingStepRewardsByPositionViewer = (viewer) => {
  return {
    networkStakingStepRewardsByPositionViewer_bonus: (params) => viewer.bonus(...params ?? []),
    networkStakingStepRewardsByPositionViewer_claimed: (params) => viewer.claimed(...params ?? []),
    networkStakingStepRewardsByPositionViewer_earned: (params) => viewer.earned(...params ?? []),
    networkStakingStepRewardsByPositionViewer_total: (params) => viewer.total(...params ?? []),
    networkStakingStepRewardsByPositionViewer_totalForPosition: (params) => viewer.totalForPosition(...params),
    networkStakingStepRewardsByPositionViewer_totalForStep: (params) => viewer.totalForStep(...params),
    networkStakingStepRewardsByPositionViewer_totalForStepForPosition: (params) => viewer.totalForStepForPosition(...params),
    networkStakingStepRewardsByPositionViewer_unclaimed: (params) => viewer.unclaimed(...params ?? [])
  };
};

// src/modules/rpc/engine/rpcMethodHandlersFromRunner.ts
var rpcMethodHandlersFromRunner = (runner) => {
  return { xyoRunner_broadcastTransaction: (params) => runner.broadcastTransaction(...params ?? []) };
};

// src/modules/rpc/engine/rpcMethodHandlersFromStakeTotalsViewer.ts
var rpcMethodHandlersFromStakeTotalsViewer = (viewer) => {
  return {
    stakeTotalsViewer_active: (params) => viewer.active(...params ?? []),
    stakeTotalsViewer_activeByStaked: (params) => viewer.activeByStaked(...params ?? []),
    stakeTotalsViewer_activeByStaker: (params) => viewer.activeByStaker(...params ?? []),
    stakeTotalsViewer_pending: (params) => viewer.pending(...params ?? []),
    stakeTotalsViewer_pendingByStaker: (params) => viewer.pendingByStaker(...params ?? []),
    stakeTotalsViewer_withdrawn: (params) => viewer.withdrawn(...params ?? []),
    stakeTotalsViewer_withdrawnByStaker: (params) => viewer.withdrawnByStaker(...params ?? [])
  };
};

// src/modules/rpc/engine/rpcMethodHandlersFromTimeSyncViewer.ts
var rpcMethodHandlersFromTimeSyncViewer = (viewer) => {
  return {
    timeSyncViewer_convertTime: (params) => viewer.convertTime(...params ?? []),
    timeSyncViewer_currentTime: (params) => viewer.currentTime(...params ?? []),
    timeSyncViewer_currentTimeAndHash: (params) => viewer.currentTimeAndHash(...params ?? []),
    timeSyncViewer_currentTimePayload: (params) => viewer.currentTimePayload(...params ?? [])
  };
};

// src/modules/rpc/engine/rpcMethodHandlersFromTransactionViewer.ts
var rpcMethodHandlersFromTransactionViewer = (viewer) => {
  return { transactionViewer_byHash: (params) => viewer.byHash(...params ?? []) };
};

// src/modules/rpc/engine/rpcMethodHandlersFromViewer.ts
var rpcMethodHandlersFromViewer = (viewer) => {
  return {
    xyoViewer_networkStakeStepRewardClaimedByAddress: (params) => viewer.networkStakeStepRewardClaimedByAddress(...params ?? []),
    xyoViewer_networkStakeStepRewardAddressReward: (params) => viewer.networkStakeStepRewardAddressReward(...params ?? []),
    xyoViewer_networkStakeStepRewardAddressHistory: (params) => viewer.networkStakeStepRewardAddressHistory(...params ?? []),
    xyoViewer_networkStakeStepRewardAddressShare: (params) => viewer.networkStakeStepRewardAddressShare(...params ?? []),
    xyoViewer_networkStakeStepRewardWeightForAddress: (params) => viewer.networkStakeStepRewardWeightForAddress?.(...params ?? []),
    xyoViewer_networkStakeStepRewardUnclaimedByAddress: (params) => viewer.networkStakeStepRewardUnclaimedByAddress(...params ?? []),
    xyoViewer_networkStakeStepRewardPoolShares: (params) => viewer.networkStakeStepRewardPoolShares(...params ?? []),
    xyoViewer_networkStakeStepRewardPoolRewards: (params) => viewer.networkStakeStepRewardPoolRewards(...params ?? []),
    xyoViewer_networkStakeStepRewardPositionWeight: (params) => viewer.networkStakeStepRewardPositionWeight?.(...params ?? []),
    xyoViewer_networkStakeStepRewardPotentialPositionLoss: (params) => viewer.networkStakeStepRewardPotentialPositionLoss?.(...params ?? []),
    xyoViewer_networkStakeStepRewardForStep: (params) => viewer.networkStakeStepRewardForStep?.(...params ?? []),
    xyoViewer_networkStakeStepRewardRandomizer: (params) => viewer.networkStakeStepRewardRandomizer?.(...params ?? []),
    xyoViewer_networkStakeStepRewardStakerCount: (params) => viewer.networkStakeStepRewardStakerCount?.(...params ?? []),
    xyoViewer_networkStakeStepRewardForStepForPosition: (params) => viewer.networkStakeStepRewardForStepForPosition?.(...params ?? []),
    xyoViewer_networkStakeStepRewardForPosition: (params) => viewer.networkStakeStepRewardForPosition?.(...params ?? []),
    xyoViewer_networkStakeStepRewardsForPosition: (params) => viewer.networkStakeStepRewardsForPosition?.(...params ?? []),
    xyoViewer_networkStakeStepRewardsForRange: (params) => viewer.networkStakeStepRewardsForRange?.(...params ?? []),
    xyoViewer_networkStakeStepRewardsForStepLevel: (params) => viewer.networkStakeStepRewardsForStepLevel?.(...params ?? []),
    xyoViewer_blocksByNumber: (params) => viewer.blocksByNumber(...params ?? []),
    xyoViewer_blocksByHash: (params) => viewer.blocksByHash(...params ?? []),
    xyoViewer_blocksByStep: (params) => viewer.blocksByStep(...params ?? []),
    xyoViewer_currentBlock: (params) => viewer.currentBlock(...params ?? []),
    xyoViewer_forkHistory: (params) => viewer.forkHistory(...params ?? []),
    xyoViewer_stakeById: (params) => viewer.stakeById(...params ?? []),
    xyoViewer_stakeByStaker: (params) => viewer.stakeByStaker(...params ?? []),
    xyoViewer_stakesByStaked: (params) => viewer.stakesByStaked(...params ?? []),
    xyoViewer_stakesByStaker: (params) => viewer.stakesByStaker(...params ?? []),
    xyoViewer_transactionByBlockHashAndIndex: (params) => viewer.transaction.byBlockHashAndIndex(...params ?? []),
    xyoViewer_transactionByBlockNumberAndIndex: (params) => viewer.transaction.byBlockNumberAndIndex(...params ?? []),
    xyoViewer_transactionByHash: (params) => viewer.transaction.byHash(...params ?? []),
    xyoViewer_payloadsByHash: (params) => viewer.payloadsByHash(...params ?? [])
  };
};

// src/modules/rpc/engine/rpcMethodHandlersFromConnection.ts
var rpcMethodHandlersFromConnection = (connection) => {
  const { runner, viewer } = connection;
  let result = {};
  if (runner) result = { ...result, ...rpcMethodHandlersFromRunner(runner) };
  if (viewer) result = { ...result, ...rpcMethodHandlersFromViewer(viewer) };
  const accountBalanceViewer = viewer?.account?.balance;
  if (accountBalanceViewer) {
    result = {
      ...result,
      ...rpcMethodHandlersFromAccountBalanceViewer(accountBalanceViewer)
    };
  }
  const blockViewer = viewer?.block;
  if (blockViewer) {
    result = {
      ...result,
      ...rpcMethodHandlersFromBlockViewer(blockViewer)
    };
  }
  const finalizationViewer = viewer?.finalization;
  if (finalizationViewer) {
    result = {
      ...result,
      ...rpcMethodHandlersFromFinalizationViewer(finalizationViewer)
    };
  }
  const mempoolViewer = viewer?.mempool;
  if (mempoolViewer) {
    result = {
      ...result,
      ...rpcMethodHandlersFromMempoolViewer(mempoolViewer)
    };
  }
  const timeSyncViewer = viewer?.time;
  if (timeSyncViewer) {
    result = {
      ...result,
      ...rpcMethodHandlersFromTimeSyncViewer(timeSyncViewer)
    };
  }
  const transactionViewer = viewer?.transaction;
  if (transactionViewer) {
    result = {
      ...result,
      ...rpcMethodHandlersFromTransactionViewer(transactionViewer)
    };
  }
  const stakeTotalsViewer = viewer?.stakeTotals;
  if (stakeTotalsViewer) {
    result = {
      ...result,
      ...rpcMethodHandlersFromStakeTotalsViewer(stakeTotalsViewer)
    };
  }
  const mempoolRunner = runner?.mempool;
  if (mempoolRunner) {
    result = {
      ...result,
      ...rpcMethodHandlersFromMempoolRunner(mempoolRunner)
    };
  }
  const networkStakeViewer = viewer?.networkStake;
  if (networkStakeViewer?.stepRewards?.position) {
    result = {
      ...result,
      ...rpcMethodHandlersFromNetworkStakingStepRewardsByPositionViewer(networkStakeViewer.stepRewards.position)
    };
  }
  return result;
};

// src/modules/rpc/engine/rpcMethodHandlersFromSigner.ts
var rpcMethodHandlersFromSigner = (signer) => {
  return {
    xyoSigner_address: (params) => signer.address(...params ?? []),
    xyoSigner_sign: (params) => signer.sign(...params ?? [])
  };
};

// src/modules/rpc/types/ErrorCodes.ts
var JsonRpcErrorCodes = {
  InternalError: { code: -32603, message: "Internal JSON-RPC error (unexpected exception)." },
  InvalidParams: { code: -32602, message: "Invalid method parameter(s)." },
  InvalidRequest: { code: -32600, message: "The JSON sent is not a valid Request object." },
  MethodNotFound: { code: -32601, message: "The method does not exist or is not available." },
  UserRejected: { code: 4001, message: "User rejected the request." }
};

// src/modules/rpc/types/JsonRpc.ts
var jsonrpc = "2.0";

// src/modules/rpc/types/schema/AccountBalanceViewerRpcSchemas.ts
import { BigIntToJsonZod, JsonToBigIntZod } from "@ariestools/sdk";
import { XyoAddressZod } from "@xyo-network/sdk";
import {
  AccountBalanceHistoryItemZod,
  ChainQualifiedConfigZod,
  ChainQualifiedZod
} from "@xyo-network/xl1-protocol/protocol-lib";
import { z } from "zod";
var AccountBalanceViewerRpcSchemas = {
  accountBalanceViewer_qualifiedAccountBalances: {
    params: {
      to: z.tuple([z.array(XyoAddressZod), ChainQualifiedConfigZod]),
      from: z.tuple([z.array(XyoAddressZod), ChainQualifiedConfigZod])
    },
    result: {
      to: ChainQualifiedZod(z.record(XyoAddressZod, BigIntToJsonZod)),
      from: ChainQualifiedZod(z.record(XyoAddressZod, JsonToBigIntZod))
    }
  },
  accountBalanceViewer_qualifiedAccountBalanceHistories: {
    params: {
      to: z.tuple([z.array(XyoAddressZod), ChainQualifiedConfigZod]),
      from: z.tuple([z.array(XyoAddressZod), ChainQualifiedConfigZod])
    },
    result: {
      to: ChainQualifiedZod(z.record(XyoAddressZod, z.array(AccountBalanceHistoryItemZod))),
      from: ChainQualifiedZod(z.record(XyoAddressZod, z.array(AccountBalanceHistoryItemZod)))
    }
  }
};

// src/modules/rpc/types/schema/BlockViewerRpcSchemas.ts
import { HashZod } from "@ariestools/sdk";
import { HashMetaZod, PayloadZodLoose } from "@xyo-network/sdk";
import { SignedHydratedBlockWithHashMetaZod, XL1BlockNumberZod } from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z2 } from "zod/mini";
var WithHashMetaPayloadZodLoose = z2.extend(PayloadZodLoose, HashMetaZod.shape);
var BlockViewerRpcSchemas = {
  blockViewer_blocksByNumber: {
    params: {
      to: z2.tuple([XL1BlockNumberZod, z2.optional(z2.number())]),
      from: z2.tuple([XL1BlockNumberZod, z2.optional(z2.number())])
    },
    result: {
      to: z2.array(SignedHydratedBlockWithHashMetaZod),
      from: z2.array(SignedHydratedBlockWithHashMetaZod)
    }
  },
  blockViewer_blocksByHash: {
    params: {
      to: z2.tuple([HashZod, z2.optional(z2.number())]),
      from: z2.tuple([HashZod, z2.optional(z2.number())])
    },
    result: {
      to: z2.array(SignedHydratedBlockWithHashMetaZod),
      from: z2.array(SignedHydratedBlockWithHashMetaZod)
    }
  },
  blockViewer_blocksByStep: {
    params: {
      to: z2.tuple([z2.number(), z2.number()]),
      from: z2.tuple([z2.number(), z2.number()])
    },
    result: {
      to: z2.array(SignedHydratedBlockWithHashMetaZod),
      from: z2.array(SignedHydratedBlockWithHashMetaZod)
    }
  },
  blockViewer_currentBlock: {
    params: {
      to: z2._default(z2.tuple([]), []),
      from: z2._default(z2.tuple([]), [])
    },
    result: {
      to: SignedHydratedBlockWithHashMetaZod,
      from: SignedHydratedBlockWithHashMetaZod
    }
  },
  blockViewer_payloadsByHash: {
    params: {
      to: z2.tuple([z2.array(HashZod)]),
      from: z2.tuple([z2.array(HashZod)])
    },
    result: {
      to: z2.array(WithHashMetaPayloadZodLoose),
      from: z2.array(WithHashMetaPayloadZodLoose)
    }
  }
};

// src/modules/rpc/types/schema/DataLakeViewerRpcSchema.ts
import { HashZod as HashZod2 } from "@ariestools/sdk";
import { PayloadZod } from "@xyo-network/sdk";
import { ArrayBufferToJsonZod, JsonToArrayBufferZod } from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z3 } from "zod/mini";
var DataLakeViewerRpcSchemas = {
  dataLakeViewer_get: {
    params: {
      to: z3.tuple([z3.array(HashZod2)]),
      from: z3.tuple([z3.array(HashZod2)])
    },
    result: {
      to: z3.array(z3.union([z3.looseObject(PayloadZod.shape), ArrayBufferToJsonZod])),
      from: z3.array(z3.union([z3.looseObject(PayloadZod.shape), JsonToArrayBufferZod]))
    }
  },
  dataLakeViewer_next: {
    params: {
      to: z3.tuple([z3.looseObject({})]),
      from: z3.tuple([z3.looseObject({})])
    },
    result: {
      to: z3.array(z3.union([z3.looseObject(PayloadZod.shape), ArrayBufferToJsonZod])),
      from: z3.array(z3.union([z3.looseObject(PayloadZod.shape), JsonToArrayBufferZod]))
    }
  }
};

// src/modules/rpc/types/schema/FinalizationViewerRpcSchemas.ts
import { SignedHydratedBlockWithHashMetaZod as SignedHydratedBlockWithHashMetaZod2 } from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z4 } from "zod";
var FinalizationViewerRpcSchemas = {
  finalizationViewer_head: {
    params: {
      to: z4.tuple([]).default([]),
      from: z4.tuple([]).default([])
    },
    result: {
      to: SignedHydratedBlockWithHashMetaZod2,
      from: SignedHydratedBlockWithHashMetaZod2
    }
  }
};

// src/modules/rpc/types/schema/MempoolRunnerRpcSchemas.ts
import { HashZod as HashZod3 } from "@ariestools/sdk";
import { SignedHydratedBlockZod, SignedHydratedTransactionZod } from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z5 } from "zod";
var MempoolRunnerRpcSchemas = {
  mempoolRunner_submitBlocks: {
    params: {
      to: z5.tuple([z5.array(SignedHydratedBlockZod)]),
      from: z5.tuple([z5.array(SignedHydratedBlockZod)])
    },
    result: {
      to: z5.array(HashZod3),
      from: z5.array(HashZod3)
    }
  },
  mempoolRunner_submitTransactions: {
    params: {
      to: z5.tuple([z5.array(SignedHydratedTransactionZod)]),
      from: z5.tuple([z5.array(SignedHydratedTransactionZod)])
    },
    result: {
      to: z5.array(HashZod3),
      from: z5.array(HashZod3)
    }
  }
};

// src/modules/rpc/types/schema/MempoolViewerRpcSchemas.ts
import {
  PendingBlocksOptionsZod,
  PendingTransactionsOptionsZod,
  SignedHydratedBlockWithHashMetaZod as SignedHydratedBlockWithHashMetaZod3,
  SignedHydratedTransactionWithHashMetaZod
} from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z6 } from "zod/mini";
var MempoolViewerRpcSchemas = {
  mempoolViewer_pendingBlocks: {
    params: {
      to: z6.tuple([z6.optional(PendingBlocksOptionsZod)]),
      from: z6.tuple([z6.optional(PendingBlocksOptionsZod)])
    },
    result: {
      to: z6.array(SignedHydratedBlockWithHashMetaZod3),
      from: z6.array(SignedHydratedBlockWithHashMetaZod3)
    }
  },
  mempoolViewer_pendingTransactions: {
    params: {
      to: z6.tuple([z6.optional(PendingTransactionsOptionsZod)]),
      from: z6.tuple([z6.optional(PendingTransactionsOptionsZod)])
    },
    result: {
      to: z6.array(SignedHydratedTransactionWithHashMetaZod),
      from: z6.array(SignedHydratedTransactionWithHashMetaZod)
    }
  }
};

// src/modules/rpc/types/schema/NetworkStakeViewerRpcSchemas.ts
import { BigIntToJsonZod as BigIntToJsonZod2, JsonToBigIntZod as JsonToBigIntZod2 } from "@ariestools/sdk";
import { BlockNumberZod } from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z7 } from "zod";
var NetworkStakeViewerRpcSchemas = {
  networkStakeViewer_active: {
    params: {
      to: z7.tuple([BlockNumberZod.optional()]),
      from: z7.tuple([BlockNumberZod.optional()])
    },
    result: {
      to: z7.tuple([BigIntToJsonZod2, z7.number()]),
      from: z7.tuple([JsonToBigIntZod2, z7.number()])
    }
  }
};

// src/modules/rpc/types/schema/RewardsByPositionViewerRpcSchemas.ts
import { BigIntToJsonZod as BigIntToJsonZod3, JsonToBigIntZod as JsonToBigIntZod3 } from "@ariestools/sdk";
import {
  asAttoXL1,
  asXL1BlockRange,
  RewardsRangeOptionsZod,
  StepIdentityZod
} from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z8 } from "zod/mini";
var NetworkStakingStepRewardsByPositionViewerRpcSchemas = {
  networkStakingStepRewardsByPositionViewer_bonus: {
    params: {
      to: z8.tuple([z8.optional(RewardsRangeOptionsZod)]),
      from: z8.tuple([z8.optional(RewardsRangeOptionsZod)])
    },
    result: {
      to: z8.record(z8.number(), BigIntToJsonZod3),
      from: z8.record(z8.number(), z8.pipe(JsonToBigIntZod3, z8.transform((val) => asAttoXL1(val))))
    }
  },
  networkStakingStepRewardsByPositionViewer_claimed: {
    params: {
      to: z8.tuple([z8.optional(RewardsRangeOptionsZod)]),
      from: z8.tuple([z8.optional(RewardsRangeOptionsZod)])
    },
    result: {
      to: z8.record(z8.number(), BigIntToJsonZod3),
      from: z8.record(z8.number(), z8.pipe(JsonToBigIntZod3, z8.transform((val) => asAttoXL1(val))))
    }
  },
  networkStakingStepRewardsByPositionViewer_earned: {
    params: {
      to: z8.tuple([z8.optional(RewardsRangeOptionsZod)]),
      from: z8.tuple([z8.optional(RewardsRangeOptionsZod)])
    },
    result: {
      to: z8.record(z8.number(), BigIntToJsonZod3),
      from: z8.record(z8.number(), z8.pipe(JsonToBigIntZod3, z8.transform((val) => asAttoXL1(val))))
    }
  },
  networkStakingStepRewardsByPositionViewer_total: {
    params: {
      to: z8.tuple([z8.optional(RewardsRangeOptionsZod)]),
      from: z8.tuple([z8.optional(RewardsRangeOptionsZod)])
    },
    result: {
      to: z8.record(z8.number(), BigIntToJsonZod3),
      from: z8.record(z8.number(), z8.pipe(JsonToBigIntZod3, z8.transform((val) => asAttoXL1(val))))
    }
  },
  networkStakingStepRewardsByPositionViewer_totalForPosition: {
    params: {
      to: z8.tuple([z8.number(), z8.tuple([z8.number(), z8.number()])]),
      from: z8.tuple([
        z8.number(),
        z8.pipe(
          z8.tuple([z8.number(), z8.number()]),
          z8.transform((value) => asXL1BlockRange([value[0], value[1]], { name: "totalForPosition" }))
        )
      ])
    },
    result: {
      to: z8.tuple([BigIntToJsonZod3, BigIntToJsonZod3]),
      from: z8.tuple([z8.pipe(JsonToBigIntZod3, z8.transform((val) => asAttoXL1(val))), z8.pipe(JsonToBigIntZod3, z8.transform((val) => asAttoXL1(val)))])
    }
  },
  networkStakingStepRewardsByPositionViewer_totalForStep: {
    params: {
      to: z8.tuple([StepIdentityZod]),
      from: z8.tuple([StepIdentityZod])
    },
    result: {
      to: BigIntToJsonZod3,
      from: z8.pipe(JsonToBigIntZod3, z8.transform((val) => asAttoXL1(val)))
    }
  },
  networkStakingStepRewardsByPositionViewer_totalForStepForPosition: {
    params: {
      to: z8.tuple([StepIdentityZod, z8.number()]),
      from: z8.tuple([StepIdentityZod, z8.number()])
    },
    result: {
      to: z8.tuple([BigIntToJsonZod3, BigIntToJsonZod3]),
      from: z8.tuple([z8.pipe(JsonToBigIntZod3, z8.transform((val) => asAttoXL1(val))), z8.pipe(JsonToBigIntZod3, z8.transform((val) => asAttoXL1(val)))])
    }
  },
  networkStakingStepRewardsByPositionViewer_unclaimed: {
    params: {
      to: z8.tuple([z8.optional(RewardsRangeOptionsZod)]),
      from: z8.tuple([z8.optional(RewardsRangeOptionsZod)])
    },
    result: {
      to: z8.record(z8.number(), BigIntToJsonZod3),
      from: z8.record(z8.number(), z8.pipe(JsonToBigIntZod3, z8.transform((val) => asAttoXL1(val))))
    }
  }
};

// src/modules/rpc/types/schema/RewardsByStakerViewerRpcSchemas.ts
import { BigIntToJsonZod as BigIntToJsonZod4, JsonToBigIntZod as JsonToBigIntZod4 } from "@ariestools/sdk";
import { XyoAddressZod as XyoAddressZod2 } from "@xyo-network/sdk";
import { asAttoXL1 as asAttoXL12, RewardsRangeOptionsZod as RewardsRangeOptionsZod2 } from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z9 } from "zod/mini";
var NetworkStakingStepRewardsByStakerViewerRpcSchemas = {
  networkStakingStepRewardsByStakerViewer_bonus: {
    params: {
      to: z9.tuple([z9.optional(RewardsRangeOptionsZod2)]),
      from: z9.tuple([z9.optional(RewardsRangeOptionsZod2)])
    },
    result: {
      to: z9.record(XyoAddressZod2, BigIntToJsonZod4),
      from: z9.record(XyoAddressZod2, z9.pipe(JsonToBigIntZod4, z9.transform((val) => asAttoXL12(val))))
    }
  },
  networkStakingStepRewardsByStakerViewer_claimed: {
    params: {
      to: z9.tuple([z9.optional(RewardsRangeOptionsZod2)]),
      from: z9.tuple([z9.optional(RewardsRangeOptionsZod2)])
    },
    result: {
      to: z9.record(XyoAddressZod2, BigIntToJsonZod4),
      from: z9.record(XyoAddressZod2, z9.pipe(JsonToBigIntZod4, z9.transform((val) => asAttoXL12(val))))
    }
  },
  networkStakingStepRewardsByStakerViewer_earned: {
    params: {
      to: z9.tuple([z9.optional(RewardsRangeOptionsZod2)]),
      from: z9.tuple([z9.optional(RewardsRangeOptionsZod2)])
    },
    result: {
      to: z9.record(XyoAddressZod2, BigIntToJsonZod4),
      from: z9.record(XyoAddressZod2, z9.pipe(JsonToBigIntZod4, z9.transform((val) => asAttoXL12(val))))
    }
  },
  networkStakingStepRewardsByStakerViewer_total: {
    params: {
      to: z9.tuple([z9.optional(RewardsRangeOptionsZod2)]),
      from: z9.tuple([z9.optional(RewardsRangeOptionsZod2)])
    },
    result: {
      to: z9.record(XyoAddressZod2, BigIntToJsonZod4),
      from: z9.record(XyoAddressZod2, z9.pipe(JsonToBigIntZod4, z9.transform((val) => asAttoXL12(val))))
    }
  },
  networkStakingStepRewardsByStakerViewer_unclaimed: {
    params: {
      to: z9.tuple([z9.optional(RewardsRangeOptionsZod2)]),
      from: z9.tuple([z9.optional(RewardsRangeOptionsZod2)])
    },
    result: {
      to: z9.record(XyoAddressZod2, BigIntToJsonZod4),
      from: z9.record(XyoAddressZod2, z9.pipe(JsonToBigIntZod4, z9.transform((val) => asAttoXL12(val))))
    }
  }
};

// src/modules/rpc/types/schema/RewardsByStepViewerRpcSchemas.ts
import { BigIntToJsonZod as BigIntToJsonZod5, JsonToBigIntZod as JsonToBigIntZod5 } from "@ariestools/sdk";
import { XyoAddressZod as XyoAddressZod3 } from "@xyo-network/sdk";
import { asAttoXL1 as asAttoXL13, RewardsRangeOptionsZod as RewardsRangeOptionsZod3 } from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z10 } from "zod/mini";
var NetworkStakingStepRewardsByStepViewerRpcSchemas = {
  networkStakingStepRewardsByStepViewer_bonus: {
    params: {
      to: z10.tuple([z10.optional(RewardsRangeOptionsZod3)]),
      from: z10.tuple([z10.optional(RewardsRangeOptionsZod3)])
    },
    result: {
      to: z10.record(XyoAddressZod3, BigIntToJsonZod5),
      from: z10.record(XyoAddressZod3, z10.pipe(JsonToBigIntZod5, z10.transform((val) => asAttoXL13(val))))
    }
  },
  networkStakingStepRewardsByStepViewer_claimed: {
    params: {
      to: z10.tuple([z10.optional(RewardsRangeOptionsZod3)]),
      from: z10.tuple([z10.optional(RewardsRangeOptionsZod3)])
    },
    result: {
      to: z10.record(XyoAddressZod3, BigIntToJsonZod5),
      from: z10.record(XyoAddressZod3, z10.pipe(JsonToBigIntZod5, z10.transform((val) => asAttoXL13(val))))
    }
  },
  networkStakingStepRewardsByStepViewer_earned: {
    params: {
      to: z10.tuple([z10.optional(RewardsRangeOptionsZod3)]),
      from: z10.tuple([z10.optional(RewardsRangeOptionsZod3)])
    },
    result: {
      to: z10.record(XyoAddressZod3, BigIntToJsonZod5),
      from: z10.record(XyoAddressZod3, z10.pipe(JsonToBigIntZod5, z10.transform((val) => asAttoXL13(val))))
    }
  },
  networkStakingStepRewardsByStepViewer_total: {
    params: {
      to: z10.tuple([z10.optional(RewardsRangeOptionsZod3)]),
      from: z10.tuple([z10.optional(RewardsRangeOptionsZod3)])
    },
    result: {
      to: z10.record(XyoAddressZod3, BigIntToJsonZod5),
      from: z10.record(XyoAddressZod3, z10.pipe(JsonToBigIntZod5, z10.transform((val) => asAttoXL13(val))))
    }
  },
  networkStakingStepRewardsByStepViewer_unclaimed: {
    params: {
      to: z10.tuple([z10.optional(RewardsRangeOptionsZod3)]),
      from: z10.tuple([z10.optional(RewardsRangeOptionsZod3)])
    },
    result: {
      to: z10.record(XyoAddressZod3, BigIntToJsonZod5),
      from: z10.record(XyoAddressZod3, z10.pipe(JsonToBigIntZod5, z10.transform((val) => asAttoXL13(val))))
    }
  }
};

// src/modules/rpc/types/schema/RewardsTotalViewerRpcSchemas.ts
import { BigIntToJsonZod as BigIntToJsonZod6, JsonToBigIntZod as JsonToBigIntZod6 } from "@ariestools/sdk";
import { asAttoXL1 as asAttoXL14, RewardsRangeOptionsZod as RewardsRangeOptionsZod4 } from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z11 } from "zod/mini";
var NetworkStakingStepRewardsTotalViewerRpcSchemas = {
  networkStakingStepRewardsTotalViewer_bonus: {
    params: {
      to: z11.tuple([z11.optional(RewardsRangeOptionsZod4)]),
      from: z11.tuple([z11.optional(RewardsRangeOptionsZod4)])
    },
    result: {
      to: BigIntToJsonZod6,
      from: z11.pipe(JsonToBigIntZod6, z11.transform((val) => asAttoXL14(val)))
    }
  },
  networkStakingStepRewardsTotalViewer_claimed: {
    params: {
      to: z11.tuple([z11.optional(RewardsRangeOptionsZod4)]),
      from: z11.tuple([z11.optional(RewardsRangeOptionsZod4)])
    },
    result: {
      to: BigIntToJsonZod6,
      from: z11.pipe(JsonToBigIntZod6, z11.transform((val) => asAttoXL14(val)))
    }
  },
  networkStakingStepRewardsTotalViewer_earned: {
    params: {
      to: z11.tuple([z11.optional(RewardsRangeOptionsZod4)]),
      from: z11.tuple([z11.optional(RewardsRangeOptionsZod4)])
    },
    result: {
      to: BigIntToJsonZod6,
      from: z11.pipe(JsonToBigIntZod6, z11.transform((val) => asAttoXL14(val)))
    }
  },
  networkStakingStepRewardsTotalViewer_total: {
    params: {
      to: z11.tuple([z11.optional(RewardsRangeOptionsZod4)]),
      from: z11.tuple([z11.optional(RewardsRangeOptionsZod4)])
    },
    result: {
      to: BigIntToJsonZod6,
      from: z11.pipe(JsonToBigIntZod6, z11.transform((val) => asAttoXL14(val)))
    }
  },
  networkStakingStepRewardsTotalViewer_unclaimed: {
    params: {
      to: z11.tuple([z11.optional(RewardsRangeOptionsZod4)]),
      from: z11.tuple([z11.optional(RewardsRangeOptionsZod4)])
    },
    result: {
      to: BigIntToJsonZod6,
      from: z11.pipe(JsonToBigIntZod6, z11.transform((val) => asAttoXL14(val)))
    }
  }
};

// src/modules/rpc/types/schema/StakeTotalsViewerRpcSchemas.ts
import { BigIntToJsonZod as BigIntToJsonZod7, JsonToBigIntZod as JsonToBigIntZod7 } from "@ariestools/sdk";
import { XyoAddressZod as XyoAddressZod4 } from "@xyo-network/sdk";
import { asAttoXL1 as asAttoXL15 } from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z12 } from "zod/mini";
var StakeTotalsViewerRpcSchemas = {
  stakeTotalsViewer_active: {
    params: {
      to: z12.tuple([z12.optional(z12.number())]),
      from: z12.tuple([z12.optional(z12.number())])
    },
    result: {
      to: BigIntToJsonZod7,
      from: z12.pipe(JsonToBigIntZod7, z12.transform((val) => asAttoXL15(val)))
    }
  },
  stakeTotalsViewer_activeByStaked: {
    params: {
      to: z12.tuple([XyoAddressZod4, z12.optional(z12.number())]),
      from: z12.tuple([XyoAddressZod4, z12.optional(z12.number())])
    },
    result: {
      to: BigIntToJsonZod7,
      from: z12.pipe(JsonToBigIntZod7, z12.transform((val) => asAttoXL15(val)))
    }
  },
  stakeTotalsViewer_activeByStaker: {
    params: {
      to: z12.tuple([XyoAddressZod4, z12.optional(z12.number())]),
      from: z12.tuple([XyoAddressZod4, z12.optional(z12.number())])
    },
    result: {
      to: BigIntToJsonZod7,
      from: z12.pipe(JsonToBigIntZod7, z12.transform((val) => asAttoXL15(val)))
    }
  },
  stakeTotalsViewer_pending: {
    params: {
      to: z12.tuple([z12.optional(z12.number())]),
      from: z12.tuple([z12.optional(z12.number())])
    },
    result: {
      to: BigIntToJsonZod7,
      from: z12.pipe(JsonToBigIntZod7, z12.transform((val) => asAttoXL15(val)))
    }
  },
  stakeTotalsViewer_pendingByStaker: {
    params: {
      to: z12.tuple([XyoAddressZod4, z12.optional(z12.number())]),
      from: z12.tuple([XyoAddressZod4, z12.optional(z12.number())])
    },
    result: {
      to: BigIntToJsonZod7,
      from: z12.pipe(JsonToBigIntZod7, z12.transform((val) => asAttoXL15(val)))
    }
  },
  stakeTotalsViewer_withdrawn: {
    params: {
      to: z12.tuple([z12.optional(z12.number())]),
      from: z12.tuple([z12.optional(z12.number())])
    },
    result: {
      to: BigIntToJsonZod7,
      from: z12.pipe(JsonToBigIntZod7, z12.transform((val) => asAttoXL15(val)))
    }
  },
  stakeTotalsViewer_withdrawnByStaker: {
    params: {
      to: z12.tuple([XyoAddressZod4, z12.optional(z12.number())]),
      from: z12.tuple([XyoAddressZod4, z12.optional(z12.number())])
    },
    result: {
      to: BigIntToJsonZod7,
      from: z12.pipe(JsonToBigIntZod7, z12.transform((val) => asAttoXL15(val)))
    }
  }
};

// src/modules/rpc/types/schema/StakeViewerRpcSchemas.ts
import { XyoAddressZod as XyoAddressZod5 } from "@xyo-network/sdk";
import { JsonToStakeZod, StakeToJsonZod } from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z14 } from "zod";

// src/modules/rpc/types/schema/NoArgsZod.ts
import { z as z13 } from "zod";
var NoArgsZod = z13.tuple([]).default([]);

// src/modules/rpc/types/schema/StakeViewerRpcSchemas.ts
var StakeViewerRpcSchemas = {
  stakeViewer_minWithdrawalBlocks: {
    params: {
      to: NoArgsZod,
      from: NoArgsZod
    },
    result: {
      to: z14.number(),
      from: z14.number()
    }
  },
  stakeViewer_rewardsContract: {
    params: {
      to: NoArgsZod,
      from: NoArgsZod
    },
    result: {
      to: XyoAddressZod5,
      from: XyoAddressZod5
    }
  },
  stakeViewer_stakeById: {
    params: {
      to: z14.tuple([z14.number()]),
      from: z14.tuple([z14.number()])
    },
    result: {
      to: StakeToJsonZod,
      from: JsonToStakeZod
    }
  },
  stakeViewer_stakeByStaker: {
    params: {
      to: z14.tuple([XyoAddressZod5, z14.number()]),
      from: z14.tuple([XyoAddressZod5, z14.number()])
    },
    result: {
      to: StakeToJsonZod,
      from: JsonToStakeZod
    }
  },
  stakeViewer_stakesByStaker: {
    params: {
      to: z14.tuple([XyoAddressZod5]),
      from: z14.tuple([XyoAddressZod5])
    },
    result: {
      to: z14.array(StakeToJsonZod),
      from: z14.array(JsonToStakeZod)
    }
  },
  stakeViewer_stakesByStaked: {
    params: {
      to: z14.tuple([XyoAddressZod5]),
      from: z14.tuple([XyoAddressZod5])
    },
    result: {
      to: z14.array(StakeToJsonZod),
      from: z14.array(JsonToStakeZod)
    }
  },
  stakeViewer_stakingTokenAddress: {
    params: {
      to: NoArgsZod,
      from: NoArgsZod
    },
    result: {
      to: XyoAddressZod5,
      from: XyoAddressZod5
    }
  }
};

// src/modules/rpc/types/schema/StepRewardsViewerRpcSchemas.ts
var NetworkStakingStepRewardsViewerRpcSchemas = {};

// src/modules/rpc/types/schema/StepViewerRpcSchemas.ts
import { BigIntToJsonZod as BigIntToJsonZod8, JsonToBigIntZod as JsonToBigIntZod8 } from "@ariestools/sdk";
import {
  JsonToStakeZod as JsonToStakeZod2,
  StakeToJsonZod as StakeToJsonZod2,
  StepIdentityZod as StepIdentityZod2
} from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z15 } from "zod";
var StepViewerRpcSchemas = {
  randomizer: {
    params: {
      to: z15.tuple([StepIdentityZod2]),
      from: z15.tuple([StepIdentityZod2])
    },
    result: {
      to: BigIntToJsonZod8,
      from: JsonToBigIntZod8
    }
  },
  stake: {
    params: {
      to: z15.tuple([StepIdentityZod2]),
      from: z15.tuple([StepIdentityZod2])
    },
    result: {
      to: BigIntToJsonZod8,
      from: JsonToBigIntZod8
    }
  },
  stakers: {
    params: {
      to: z15.tuple([StepIdentityZod2]),
      from: z15.tuple([StepIdentityZod2])
    },
    result: {
      to: BigIntToJsonZod8,
      from: JsonToBigIntZod8
    }
  },
  weight: {
    params: {
      to: z15.tuple([StepIdentityZod2]),
      from: z15.tuple([StepIdentityZod2])
    },
    result: {
      to: BigIntToJsonZod8,
      from: JsonToBigIntZod8
    }
  },
  positionCount: {
    params: {
      to: z15.tuple([StepIdentityZod2]),
      from: z15.tuple([StepIdentityZod2])
    },
    result: {
      to: z15.number(),
      from: z15.number()
    }
  },
  positions: {
    params: {
      to: z15.tuple([StepIdentityZod2]),
      from: z15.tuple([StepIdentityZod2])
    },
    result: {
      to: z15.array(StakeToJsonZod2),
      from: z15.array(JsonToStakeZod2)
    }
  },
  stakerCount: {
    params: {
      to: z15.tuple([StepIdentityZod2]),
      from: z15.tuple([StepIdentityZod2])
    },
    result: {
      to: z15.number(),
      from: z15.number()
    }
  }
};

// src/modules/rpc/types/schema/TimeSyncViewerRpcSchema.ts
import { TimeDomainZod, TimePayloadZod } from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z16 } from "zod";
var TimeSyncViewerRpcSchemas = {
  timeSyncViewer_convertTime: {
    params: {
      from: z16.tuple([TimeDomainZod, TimeDomainZod, z16.number()]),
      to: z16.tuple([TimeDomainZod, TimeDomainZod, z16.number()])
    },
    result: {
      from: z16.number(),
      to: z16.number()
    }
  },
  timeSyncViewer_currentTime: {
    params: {
      from: z16.tuple([TimeDomainZod]),
      to: z16.tuple([TimeDomainZod])
    },
    result: {
      from: z16.tuple([TimeDomainZod, z16.number()]),
      to: z16.tuple([TimeDomainZod, z16.number()])
    }
  },
  timeSyncViewer_currentTimeAndHash: {
    params: {
      from: z16.tuple([TimeDomainZod]),
      to: z16.tuple([TimeDomainZod])
    },
    result: {
      from: z16.tuple([z16.number(), z16.nullable(z16.string())]),
      to: z16.tuple([z16.number(), z16.nullable(z16.string())])
    }
  },
  timeSyncViewer_currentTimePayload: {
    params: {
      from: z16.tuple([]).default([]),
      to: z16.tuple([]).default([])
    },
    result: {
      from: TimePayloadZod,
      to: TimePayloadZod
    }
  }
};

// src/modules/rpc/types/schema/TransactionViewerRpcSchema.ts
import { HashZod as HashZod4 } from "@ariestools/sdk";
import { SignedHydratedTransactionWithHashMetaZod as SignedHydratedTransactionWithHashMetaZod2 } from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z17 } from "zod/mini";
var TransactionViewerRpcSchemas = {
  transactionViewer_byHash: {
    params: {
      to: z17.tuple([HashZod4]),
      from: z17.tuple([HashZod4])
    },
    result: {
      to: z17.nullable(SignedHydratedTransactionWithHashMetaZod2),
      from: z17.nullable(SignedHydratedTransactionWithHashMetaZod2)
    }
  }
};

// src/modules/rpc/types/schema/XyoPermissionsRpcSchemas.ts
import {
  InvokerPermissionZod,
  PermissionRequestZod,
  RequestedPermissionZod
} from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z18 } from "zod";
var XyoPermissionsRpcSchemas = {
  xyoPermissions_getPermissions: {
    params: {
      to: z18.tuple([]).default([]),
      from: z18.tuple([]).default([])
    },
    result: {
      to: z18.array(InvokerPermissionZod),
      from: z18.array(InvokerPermissionZod)
    }
  },
  xyoPermissions_requestPermissions: {
    params: {
      to: z18.tuple([z18.array(PermissionRequestZod)]),
      from: z18.tuple([z18.array(PermissionRequestZod)])
    },
    result: {
      to: z18.array(RequestedPermissionZod),
      from: z18.array(RequestedPermissionZod)
    }
  },
  xyoPermissions_revokePermissions: {
    params: {
      to: z18.tuple([z18.array(PermissionRequestZod)]),
      from: z18.tuple([z18.array(PermissionRequestZod)])
    },
    result: {
      to: z18.array(RequestedPermissionZod),
      from: z18.array(RequestedPermissionZod)
    }
  }
};

// src/modules/rpc/types/schema/XyoRunnerRpcSchemas.ts
import { HashToJsonZod, JsonToHashZod } from "@ariestools/sdk";
import { SignedHydratedTransactionZod as SignedHydratedTransactionZod2 } from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z19 } from "zod";
var XyoRunnerRpcSchemas = {
  xyoRunner_broadcastTransaction: {
    params: {
      to: z19.tuple([SignedHydratedTransactionZod2]),
      from: z19.tuple([SignedHydratedTransactionZod2])
    },
    result: {
      to: HashToJsonZod,
      from: JsonToHashZod
    }
  }
};

// src/modules/rpc/types/schema/XyoSignerRpcSchemas.ts
import {
  AnyUnsignedBoundWitnessZod,
  PayloadZodLoose as PayloadZodLoose2,
  SignedBoundWitnessZod,
  WithHashMetaPayloadZodLoose as WithHashMetaPayloadZodLoose2,
  WithHashMetaZod,
  XyoAddressZod as XyoAddressZod6
} from "@xyo-network/sdk";
import { z as z20 } from "zod/mini";
var UnsignedHydratedBoundWitnessLooseZod = z20.tuple([
  AnyUnsignedBoundWitnessZod,
  z20.array(PayloadZodLoose2)
]);
var WithHashMetaSignedBoundWitnessZod = WithHashMetaZod(SignedBoundWitnessZod);
var WithHashMetaSignedBoundWitnessZodLoose = z20.looseObject(WithHashMetaSignedBoundWitnessZod.shape);
var SignedHydratedBoundWitnessWithHashMetaLooseZod = z20.tuple([
  WithHashMetaSignedBoundWitnessZodLoose,
  z20.array(WithHashMetaPayloadZodLoose2)
]);
var XyoSignerRpcSchemas = {
  xyoSigner_address: {
    params: {
      to: NoArgsZod,
      from: NoArgsZod
    },
    result: {
      to: XyoAddressZod6,
      from: XyoAddressZod6
    }
  },
  xyoSigner_sign: {
    params: {
      to: z20.tuple([UnsignedHydratedBoundWitnessLooseZod]),
      from: z20.tuple([UnsignedHydratedBoundWitnessLooseZod])
    },
    result: {
      to: SignedHydratedBoundWitnessWithHashMetaLooseZod,
      from: SignedHydratedBoundWitnessWithHashMetaLooseZod
    }
  }
};

// src/modules/rpc/types/schema/XyoViewerRpcSchemas.ts
import {
  BigIntToJsonZod as BigIntToJsonZod9,
  HashZod as HashZod5,
  HexZod,
  JsonToBigIntZod as JsonToBigIntZod9
} from "@ariestools/sdk";
import { PayloadZodLoose as PayloadZodLoose3, XyoAddressZod as XyoAddressZod7 } from "@xyo-network/sdk";
import {
  asAttoXL1 as asAttoXL16,
  JsonToStakeZod as JsonToStakeZod3,
  SignedHydratedBlockWithHashMetaZod as SignedHydratedBlockWithHashMetaZod4,
  SignedHydratedTransactionZod as SignedHydratedTransactionZod3,
  StakeToJsonZod as StakeToJsonZod3,
  StepIdentityZod as StepIdentityZod3,
  XL1BlockNumberZod as XL1BlockNumberZod2
} from "@xyo-network/xl1-protocol/protocol-lib";
import { z as z21 } from "zod/mini";
var XyoViewerRpcSchemas = {
  xyoViewer_networkStakeStepRewardClaimedByAddress: {
    params: {
      to: z21.tuple([XyoAddressZod7]),
      from: z21.tuple([XyoAddressZod7])
    },
    result: {
      to: BigIntToJsonZod9,
      from: z21.pipe(JsonToBigIntZod9, z21.transform((val) => asAttoXL16(val)))
    }
  },
  xyoViewer_networkStakeStepRewardAddressReward: {
    params: {
      to: z21.tuple([StepIdentityZod3, XyoAddressZod7]),
      from: z21.tuple([StepIdentityZod3, XyoAddressZod7])
    },
    result: {
      to: z21.record(XyoAddressZod7, BigIntToJsonZod9),
      from: z21.record(XyoAddressZod7, z21.pipe(JsonToBigIntZod9, z21.transform((val) => asAttoXL16(val))))
    }
  },
  xyoViewer_networkStakeStepRewardAddressHistory: {
    params: {
      to: z21.tuple([XyoAddressZod7]),
      from: z21.tuple([XyoAddressZod7])
    },
    result: {
      to: z21.record(XyoAddressZod7, BigIntToJsonZod9),
      from: z21.record(XyoAddressZod7, z21.pipe(JsonToBigIntZod9, z21.transform((val) => asAttoXL16(val))))
    }
  },
  xyoViewer_networkStakeStepRewardAddressShare: {
    params: {
      to: z21.tuple([StepIdentityZod3, XyoAddressZod7]),
      from: z21.tuple([StepIdentityZod3, XyoAddressZod7])
    },
    result: {
      to: z21.tuple([BigIntToJsonZod9, BigIntToJsonZod9]),
      from: z21.tuple([JsonToBigIntZod9, JsonToBigIntZod9])
    }
  },
  xyoViewer_networkStakeStepRewardWeightForAddress: {
    params: {
      to: z21.tuple([StepIdentityZod3, XyoAddressZod7]),
      from: z21.tuple([StepIdentityZod3, XyoAddressZod7])
    },
    result: {
      to: BigIntToJsonZod9,
      from: JsonToBigIntZod9
    }
  },
  xyoViewer_networkStakeStepRewardUnclaimedByAddress: {
    params: {
      to: z21.tuple([XyoAddressZod7]),
      from: z21.tuple([XyoAddressZod7])
    },
    result: {
      to: BigIntToJsonZod9,
      from: z21.pipe(JsonToBigIntZod9, z21.transform((val) => asAttoXL16(val)))
    }
  },
  xyoViewer_networkStakeStepRewardPoolRewards: {
    params: {
      to: z21.tuple([StepIdentityZod3]),
      from: z21.tuple([StepIdentityZod3])
    },
    result: {
      to: z21.record(XyoAddressZod7, BigIntToJsonZod9),
      from: z21.record(XyoAddressZod7, z21.pipe(JsonToBigIntZod9, z21.transform((val) => asAttoXL16(val))))
    }
  },
  xyoViewer_networkStakeStepRewardPositionWeight: {
    params: {
      to: z21.tuple([StepIdentityZod3, z21.number()]),
      from: z21.tuple([StepIdentityZod3, z21.number()])
    },
    result: {
      to: BigIntToJsonZod9,
      from: JsonToBigIntZod9
    }
  },
  xyoViewer_networkStakeStepRewardPotentialPositionLoss: {
    params: {
      to: z21.tuple([StepIdentityZod3, z21.number()]),
      from: z21.tuple([StepIdentityZod3, z21.number()])
    },
    result: {
      to: BigIntToJsonZod9,
      from: z21.pipe(JsonToBigIntZod9, z21.transform((val) => asAttoXL16(val)))
    }
  },
  xyoViewer_networkStakeStepRewardForStep: {
    params: {
      to: z21.tuple([StepIdentityZod3]),
      from: z21.tuple([StepIdentityZod3])
    },
    result: {
      to: BigIntToJsonZod9,
      from: z21.pipe(JsonToBigIntZod9, z21.transform((val) => asAttoXL16(val)))
    }
  },
  xyoViewer_networkStakeStepRewardRandomizer: {
    params: {
      to: z21.tuple([StepIdentityZod3]),
      from: z21.tuple([StepIdentityZod3])
    },
    result: {
      to: BigIntToJsonZod9,
      from: z21.pipe(JsonToBigIntZod9, z21.transform((val) => asAttoXL16(val)))
    }
  },
  xyoViewer_networkStakeStepRewardStakerCount: {
    params: {
      to: z21.tuple([StepIdentityZod3]),
      from: z21.tuple([StepIdentityZod3])
    },
    result: {
      to: z21.number(),
      from: z21.number()
    }
  },
  xyoViewer_networkStakeStepRewardPoolShares: {
    params: {
      to: z21.tuple([StepIdentityZod3]),
      from: z21.tuple([StepIdentityZod3])
    },
    result: {
      to: z21.record(XyoAddressZod7, BigIntToJsonZod9),
      from: z21.record(XyoAddressZod7, JsonToBigIntZod9)
    }
  },
  xyoViewer_networkStakeStepRewardForStepForPosition: {
    params: {
      to: z21.tuple([StepIdentityZod3, z21.number()]),
      from: z21.tuple([StepIdentityZod3, z21.number()])
    },
    result: {
      to: z21.tuple([BigIntToJsonZod9, BigIntToJsonZod9]),
      from: z21.tuple([z21.pipe(JsonToBigIntZod9, z21.transform((val) => asAttoXL16(val))), z21.pipe(JsonToBigIntZod9, z21.transform((val) => asAttoXL16(val)))])
    }
  },
  xyoViewer_networkStakeStepRewardForPosition: {
    params: {
      to: z21.tuple([z21.number(), z21.tuple([z21.number(), z21.number()])]),
      from: z21.tuple([z21.number(), z21.tuple([z21.number(), z21.number()])])
    },
    result: {
      to: z21.tuple([BigIntToJsonZod9, BigIntToJsonZod9]),
      from: z21.tuple([z21.pipe(JsonToBigIntZod9, z21.transform((val) => asAttoXL16(val))), z21.pipe(JsonToBigIntZod9, z21.transform((val) => asAttoXL16(val)))])
    }
  },
  xyoViewer_networkStakeStepRewardsForRange: {
    params: {
      to: z21.tuple([z21.tuple([z21.number(), z21.number()])]),
      from: z21.tuple([z21.tuple([z21.number(), z21.number()])])
    },
    result: {
      to: BigIntToJsonZod9,
      from: z21.pipe(JsonToBigIntZod9, z21.transform((val) => asAttoXL16(val)))
    }
  },
  xyoViewer_networkStakeStepRewardsForStepLevel: {
    params: {
      to: z21.tuple([z21.number(), z21.tuple([z21.number(), z21.number()])]),
      from: z21.tuple([z21.number(), z21.tuple([z21.number(), z21.number()])])
    },
    result: {
      to: BigIntToJsonZod9,
      from: z21.pipe(JsonToBigIntZod9, z21.transform((val) => asAttoXL16(val)))
    }
  },
  xyoViewer_networkStakeStepRewardsForPosition: {
    params: {
      to: z21.tuple([z21.number(), z21.tuple([z21.number(), z21.number()])]),
      from: z21.tuple([z21.number(), z21.tuple([z21.number(), z21.number()])])
    },
    result: {
      to: z21.record(z21.string(), z21.tuple([BigIntToJsonZod9, BigIntToJsonZod9])),
      from: z21.record(z21.string(), z21.tuple([z21.pipe(JsonToBigIntZod9, z21.transform((val) => asAttoXL16(val))), z21.pipe(JsonToBigIntZod9, z21.transform((val) => asAttoXL16(val)))]))
    }
  },
  xyoViewer_blocksByNumber: {
    params: {
      to: z21.tuple([XL1BlockNumberZod2, z21.optional(z21.number())]),
      from: z21.tuple([XL1BlockNumberZod2, z21.optional(z21.number())])
    },
    result: {
      to: z21.array(SignedHydratedBlockWithHashMetaZod4),
      from: z21.array(SignedHydratedBlockWithHashMetaZod4)
    }
  },
  xyoViewer_blocksByHash: {
    params: {
      to: z21.tuple([HashZod5, z21.optional(z21.number())]),
      from: z21.tuple([HashZod5, z21.optional(z21.number())])
    },
    result: {
      to: z21.array(SignedHydratedBlockWithHashMetaZod4),
      from: z21.array(SignedHydratedBlockWithHashMetaZod4)
    }
  },
  xyoViewer_blocksByStep: {
    params: {
      to: z21.tuple([z21.number(), z21.number()]),
      from: z21.tuple([z21.number(), z21.number()])
    },
    result: {
      to: z21.array(SignedHydratedBlockWithHashMetaZod4),
      from: z21.array(SignedHydratedBlockWithHashMetaZod4)
    }
  },
  xyoViewer_currentBlock: {
    params: {
      to: z21._default(z21.tuple([]), []),
      from: z21._default(z21.tuple([]), [])
    },
    result: {
      to: SignedHydratedBlockWithHashMetaZod4,
      from: SignedHydratedBlockWithHashMetaZod4
    }
  },
  xyoViewer_forkHistory: {
    params: {
      to: z21._default(z21.tuple([]), []),
      from: z21._default(z21.tuple([]), [])
    },
    result: {
      to: z21.record(z21.number(), HexZod),
      from: z21.record(z21.number(), HexZod)
    }
  },
  xyoViewer_stakeByStaker: {
    params: {
      to: z21.tuple([XyoAddressZod7, z21.number()]),
      from: z21.tuple([XyoAddressZod7, z21.number()])
    },
    result: {
      to: StakeToJsonZod3,
      from: JsonToStakeZod3
    }
  },
  xyoViewer_stakeById: {
    params: {
      to: z21.tuple([z21.number()]),
      from: z21.tuple([z21.number()])
    },
    result: {
      to: StakeToJsonZod3,
      from: JsonToStakeZod3
    }
  },
  xyoViewer_stakesByStaker: {
    params: {
      to: z21.tuple([XyoAddressZod7]),
      from: z21.tuple([XyoAddressZod7])
    },
    result: {
      to: z21.array(StakeToJsonZod3),
      from: z21.array(JsonToStakeZod3)
    }
  },
  xyoViewer_stakesByStaked: {
    params: {
      to: z21.tuple([XyoAddressZod7]),
      from: z21.tuple([XyoAddressZod7])
    },
    result: {
      to: z21.array(StakeToJsonZod3),
      from: z21.array(JsonToStakeZod3)
    }
  },
  xyoViewer_transactionByBlockHashAndIndex: {
    params: {
      to: z21.tuple([HashZod5, z21.number()]),
      from: z21.tuple([HashZod5, z21.number()])
    },
    result: {
      to: z21.nullable(SignedHydratedTransactionZod3),
      from: z21.nullable(SignedHydratedTransactionZod3)
    }
  },
  xyoViewer_transactionByBlockNumberAndIndex: {
    params: {
      to: z21.tuple([z21.number(), z21.number()]),
      from: z21.tuple([z21.number(), z21.number()])
    },
    result: {
      to: z21.nullable(SignedHydratedTransactionZod3),
      from: z21.nullable(SignedHydratedTransactionZod3)
    }
  },
  xyoViewer_transactionByHash: {
    params: {
      to: z21.tuple([HashZod5]),
      from: z21.tuple([HashZod5])
    },
    result: {
      to: z21.nullable(SignedHydratedTransactionZod3),
      from: z21.nullable(SignedHydratedTransactionZod3)
    }
  },
  xyoViewer_payloadsByHash: {
    params: {
      to: z21.tuple([z21.array(HashZod5)]),
      from: z21.tuple([z21.array(HashZod5)])
    },
    result: {
      to: z21.array(PayloadZodLoose3),
      from: z21.array(PayloadZodLoose3)
    }
  }
};

// src/modules/rpc/types/schema/AllRpcSchemas.ts
var AllRpcSchemas = {
  ...AccountBalanceViewerRpcSchemas,
  ...XyoRunnerRpcSchemas,
  ...XyoSignerRpcSchemas,
  ...XyoViewerRpcSchemas,
  ...XyoPermissionsRpcSchemas,
  ...NetworkStakeViewerRpcSchemas,
  ...BlockViewerRpcSchemas,
  ...MempoolViewerRpcSchemas,
  ...MempoolRunnerRpcSchemas,
  ...TimeSyncViewerRpcSchemas,
  ...StepViewerRpcSchemas,
  ...DataLakeViewerRpcSchemas,
  ...StakeTotalsViewerRpcSchemas,
  ...StakeViewerRpcSchemas,
  ...NetworkStakingStepRewardsViewerRpcSchemas,
  ...NetworkStakingStepRewardsTotalViewerRpcSchemas,
  ...NetworkStakingStepRewardsByStepViewerRpcSchemas,
  ...NetworkStakingStepRewardsByStakerViewerRpcSchemas,
  ...NetworkStakingStepRewardsByPositionViewerRpcSchemas,
  ...TransactionViewerRpcSchemas,
  ...FinalizationViewerRpcSchemas
};

// src/modules/rpc/types/schema/createRequestSchema.ts
import { z as z22 } from "zod/mini";
var createRequestSchema = (methodName, paramsSchema = z22.undefined()) => z22.object({
  id: z22.union([z22.string(), z22.number()]),
  jsonrpc: z22.literal(jsonrpc),
  method: z22.literal(methodName),
  params: paramsSchema
});

// src/modules/rpc/engine-node/middleware/createHandlerMiddleware.ts
import { createScaffoldMiddleware } from "@metamask/json-rpc-engine/v2";
var buildHandlerScaffold = (handlers) => {
  const scaffold = {};
  for (const [method, handler] of Object.entries(handlers)) {
    if (handler === void 0) continue;
    scaffold[method] = async ({ context }) => {
      const schema = context.assertGet("schema");
      const params = context.assertGet("params");
      const result = await handler(params);
      return schema.result.to.parse(result);
    };
  }
  return createScaffoldMiddleware(scaffold);
};
var createTypedHandlerMiddleware = (_schemas, handlers) => buildHandlerScaffold(handlers);

// src/modules/rpc/engine-node/middleware/createLoggingMiddleware.ts
var createLoggingMiddleware = (logger) => async ({ request, next }) => {
  try {
    return await next();
  } catch (error) {
    logger?.error(`RPC ${request.method} failed`, error);
    throw error;
  }
};

// src/modules/rpc/engine-node/middleware/createMethodNotFoundMiddleware.ts
var createMethodNotFoundMiddleware = () => ({ request }) => {
  throw new Error(`${JsonRpcErrorCodes.MethodNotFound.message} (${request.method})`);
};

// src/modules/rpc/engine-node/middleware/createValidationMiddleware.ts
var createValidationMiddleware = (schemas) => ({
  request,
  context,
  next
}) => {
  const schema = schemas[request.method];
  if (schema === void 0) return next();
  let requestSchema = requestSchemas[request.method];
  if (requestSchema === void 0) {
    requestSchema = createRequestSchema(request.method, schema.params.from);
    requestSchemas[request.method] = requestSchema;
  }
  const parsed = requestSchema.safeParse(request);
  if (!parsed.success) {
    throw new Error(parsed.error.message);
  }
  context.set("schema", schema);
  context.set("params", parsed.data.params);
  return next();
};

// src/modules/rpc/engine-node/composedRpcEngineFromConnection.ts
var buildTypedSubEngine = (schemas, handlers) => JsonRpcEngineV2.create({
  middleware: [
    createValidationMiddleware(schemas),
    createTypedHandlerMiddleware(schemas, handlers)
  ]
});
var composedRpcEngineFromConnection = (connection, logger) => {
  const { runner, viewer } = connection;
  const subEngines = [];
  if (runner) {
    subEngines.push(buildTypedSubEngine(XyoRunnerRpcSchemas, rpcMethodHandlersFromRunner(runner)));
  }
  if (viewer) {
    subEngines.push(buildTypedSubEngine(XyoViewerRpcSchemas, rpcMethodHandlersFromViewer(viewer)));
  }
  const accountBalanceViewer = viewer?.account?.balance;
  if (accountBalanceViewer) {
    subEngines.push(buildTypedSubEngine(
      AccountBalanceViewerRpcSchemas,
      rpcMethodHandlersFromAccountBalanceViewer(accountBalanceViewer)
    ));
  }
  const blockViewer = viewer?.block;
  if (blockViewer) {
    subEngines.push(buildTypedSubEngine(
      BlockViewerRpcSchemas,
      rpcMethodHandlersFromBlockViewer(blockViewer)
    ));
  }
  const finalizationViewer = viewer?.finalization;
  if (finalizationViewer) {
    subEngines.push(buildTypedSubEngine(
      FinalizationViewerRpcSchemas,
      rpcMethodHandlersFromFinalizationViewer(finalizationViewer)
    ));
  }
  const mempoolViewer = viewer?.mempool;
  if (mempoolViewer) {
    subEngines.push(buildTypedSubEngine(
      MempoolViewerRpcSchemas,
      rpcMethodHandlersFromMempoolViewer(mempoolViewer)
    ));
  }
  const timeSyncViewer = viewer?.time;
  if (timeSyncViewer) {
    subEngines.push(buildTypedSubEngine(
      TimeSyncViewerRpcSchemas,
      rpcMethodHandlersFromTimeSyncViewer(timeSyncViewer)
    ));
  }
  const transactionViewer = viewer?.transaction;
  if (transactionViewer) {
    subEngines.push(buildTypedSubEngine(
      TransactionViewerRpcSchemas,
      rpcMethodHandlersFromTransactionViewer(transactionViewer)
    ));
  }
  const stakeTotalsViewer = viewer?.stakeTotals;
  if (stakeTotalsViewer) {
    subEngines.push(buildTypedSubEngine(
      StakeTotalsViewerRpcSchemas,
      rpcMethodHandlersFromStakeTotalsViewer(stakeTotalsViewer)
    ));
  }
  const mempoolRunner = runner?.mempool;
  if (mempoolRunner) {
    subEngines.push(buildTypedSubEngine(
      MempoolRunnerRpcSchemas,
      rpcMethodHandlersFromMempoolRunner(mempoolRunner)
    ));
  }
  const networkStakeViewer = viewer?.networkStake;
  if (networkStakeViewer?.stepRewards?.position) {
    subEngines.push(buildTypedSubEngine(
      NetworkStakingStepRewardsByPositionViewerRpcSchemas,
      rpcMethodHandlersFromNetworkStakingStepRewardsByPositionViewer(networkStakeViewer.stepRewards.position)
    ));
  }
  const middleware = [
    createLoggingMiddleware(logger),
    ...subEngines.map((engine) => engine.asMiddleware()),
    createMethodNotFoundMiddleware()
  ];
  return JsonRpcEngineV2.create({ middleware });
};
var composedRpcServerFromConnection = (connection, logger) => {
  const engine = composedRpcEngineFromConnection(connection, logger);
  return new JsonRpcServer({ engine });
};
var composedRpcEngineFromGateway = (gateway, logger) => {
  const runner = gateway.moniker === XyoGatewayRunnerMoniker ? gateway : void 0;
  const middleware = [createLoggingMiddleware(logger)];
  if (runner) {
    middleware.push(
      buildTypedSubEngine(XyoSignerRpcSchemas, rpcMethodHandlersFromSigner(runner.signer)).asMiddleware()
    );
  }
  middleware.push(composedRpcEngineFromConnection(gateway.connection).asMiddleware());
  return JsonRpcEngineV2.create({ middleware });
};
var composedRpcServerFromGateway = (gateway, logger) => {
  const engine = composedRpcEngineFromGateway(gateway, logger);
  return new JsonRpcServer({ engine });
};

// src/modules/rpc/engine-node/createRpcDispatchMiddleware.ts
var createRpcDispatchMiddleware = (schemas, handlers, options) => async ({ request }) => {
  const method = request.method;
  const handler = handlers[method];
  const schema = schemas[method];
  if (schema === void 0 || handler === void 0) {
    const createError = options?.methodNotFound ?? (() => new Error(JsonRpcErrorCodes.MethodNotFound.message));
    throw createError(method);
  }
  let requestSchema = requestSchemas[method];
  if (requestSchema == void 0) {
    requestSchema = createRequestSchema(method, schema.params.from);
    requestSchemas[method] = requestSchema;
  }
  const parsed = requestSchema.safeParse(request);
  if (!parsed.success) {
    options?.logger?.error("RPC Request Validation Error", parsed.error);
    throw new Error(parsed.error.message);
  }
  const { params } = parsed.data;
  try {
    const result = await handler(params);
    return schema.result.to.parse(result);
  } catch (error) {
    options?.logger?.error("RPC Response Handler Error", error);
    throw error;
  }
};

// src/modules/rpc/engine-node/rpcEngineFromConnection.ts
import { JsonRpcEngineV2 as JsonRpcEngineV22, JsonRpcServer as JsonRpcServer2 } from "@metamask/json-rpc-engine/v2";
var rpcEngineFromConnection = (connection, logger) => {
  const handlers = rpcMethodHandlersFromConnection(connection);
  const middleware = createRpcDispatchMiddleware(AllRpcSchemas, handlers, { logger });
  return JsonRpcEngineV22.create({ middleware: [middleware] });
};
function rpcServerFromConnection(connection, logger) {
  const engine = rpcEngineFromConnection(connection, logger);
  return new JsonRpcServer2({ engine });
}
export {
  composedRpcEngineFromConnection,
  composedRpcEngineFromGateway,
  composedRpcServerFromConnection,
  composedRpcServerFromGateway,
  createLoggingMiddleware,
  createMethodNotFoundMiddleware,
  createRpcDispatchMiddleware,
  createTypedHandlerMiddleware,
  createValidationMiddleware,
  rpcEngineFromConnection,
  rpcServerFromConnection
};
//# sourceMappingURL=rpc.server.mjs.map
