const pe = "2.38.4";
let re = {
  getDocsUrl: ({ docsBaseUrl: r, docsPath: e = "", docsSlug: t }) => e ? `${r ?? "https://viem.sh"}${e}${t ? `#${t}` : ""}` : void 0,
  version: `viem@${pe}`
};
class i extends Error {
  constructor(e, t = {}) {
    const n = t.cause instanceof i ? t.cause.details : t.cause?.message ? t.cause.message : t.details, s = t.cause instanceof i && t.cause.docsPath || t.docsPath, a = re.getDocsUrl?.({ ...t, docsPath: s }), c = [
      e || "An error occurred.",
      "",
      ...t.metaMessages ? [...t.metaMessages, ""] : [],
      ...a ? [`Docs: ${a}`] : [],
      ...n ? [`Details: ${n}`] : [],
      ...re.version ? [`Version: ${re.version}`] : []
    ].join(`
`);
    super(c, t.cause ? { cause: t.cause } : void 0), Object.defineProperty(this, "details", {
      enumerable: !0,
      configurable: !0,
      writable: !0,
      value: void 0
    }), Object.defineProperty(this, "docsPath", {
      enumerable: !0,
      configurable: !0,
      writable: !0,
      value: void 0
    }), Object.defineProperty(this, "metaMessages", {
      enumerable: !0,
      configurable: !0,
      writable: !0,
      value: void 0
    }), Object.defineProperty(this, "shortMessage", {
      enumerable: !0,
      configurable: !0,
      writable: !0,
      value: void 0
    }), Object.defineProperty(this, "version", {
      enumerable: !0,
      configurable: !0,
      writable: !0,
      value: void 0
    }), Object.defineProperty(this, "name", {
      enumerable: !0,
      configurable: !0,
      writable: !0,
      value: "BaseError"
    }), this.details = n, this.docsPath = s, this.metaMessages = t.metaMessages, this.name = t.name ?? this.name, this.shortMessage = e, this.version = pe;
  }
  walk(e) {
    return be(this, e);
  }
}
function be(r, e) {
  return e?.(r) ? r : r && typeof r == "object" && "cause" in r && r.cause !== void 0 ? be(r.cause, e) : e ? null : r;
}
function Oe(r, { strict: e = !0 } = {}) {
  return !r || typeof r != "string" ? !1 : e ? /^0x[0-9a-fA-F]*$/.test(r) : r.startsWith("0x");
}
class dt extends i {
  constructor({ offset: e, position: t, size: n }) {
    super(`Slice ${t === "start" ? "starting" : "ending"} at offset "${e}" is out-of-bounds (size: ${n}).`, { name: "SliceOffsetOutOfBoundsError" });
  }
}
class ge extends i {
  constructor({ size: e, targetSize: t, type: n }) {
    super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${e}) exceeds padding size (${t}).`, { name: "SizeExceedsPaddingSizeError" });
  }
}
function se(r, { dir: e, size: t = 32 } = {}) {
  return typeof r == "string" ? je(r, { dir: e, size: t }) : Te(r, { dir: e, size: t });
}
function je(r, { dir: e, size: t = 32 } = {}) {
  if (t === null)
    return r;
  const n = r.replace("0x", "");
  if (n.length > t * 2)
    throw new ge({
      size: Math.ceil(n.length / 2),
      targetSize: t,
      type: "hex"
    });
  return `0x${n[e === "right" ? "padEnd" : "padStart"](t * 2, "0")}`;
}
function Te(r, { dir: e, size: t = 32 } = {}) {
  if (t === null)
    return r;
  if (r.length > t)
    throw new ge({
      size: r.length,
      targetSize: t,
      type: "bytes"
    });
  const n = new Uint8Array(t);
  for (let s = 0; s < t; s++) {
    const a = e === "right";
    n[a ? s : t - s - 1] = r[a ? s : r.length - s - 1];
  }
  return n;
}
class Me extends i {
  constructor({ max: e, min: t, signed: n, size: s, value: a }) {
    super(`Number "${a}" is not in safe ${s ? `${s * 8}-bit ${n ? "signed" : "unsigned"} ` : ""}integer range ${e ? `(${t} to ${e})` : `(above ${t})`}`, { name: "IntegerOutOfRangeError" });
  }
}
class Se extends i {
  constructor({ givenSize: e, maxSize: t }) {
    super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`, { name: "SizeOverflowError" });
  }
}
function le(r) {
  return Oe(r, { strict: !1 }) ? Math.ceil((r.length - 2) / 2) : r.length;
}
function ae(r, { size: e }) {
  if (le(r) > e)
    throw new Se({
      givenSize: le(r),
      maxSize: e
    });
}
function qe(r, e = {}) {
  const { signed: t } = e;
  e.size && ae(r, { size: e.size });
  const n = BigInt(r);
  if (!t)
    return n;
  const s = (r.length - 2) / 2, a = (1n << BigInt(s) * 8n - 1n) - 1n;
  return n <= a ? n : n - BigInt(`0x${"f".padStart(s * 2, "f")}`) - 1n;
}
function lt(r, e = {}) {
  return Number(qe(r, e));
}
const Ie = /* @__PURE__ */ Array.from({ length: 256 }, (r, e) => e.toString(16).padStart(2, "0"));
function ht(r, e = {}) {
  return typeof r == "number" || typeof r == "bigint" ? ze(r, e) : typeof r == "string" ? me(r, e) : typeof r == "boolean" ? Ne(r, e) : we(r, e);
}
function Ne(r, e = {}) {
  const t = `0x${Number(r)}`;
  return typeof e.size == "number" ? (ae(t, { size: e.size }), se(t, { size: e.size })) : t;
}
function we(r, e = {}) {
  let t = "";
  for (let s = 0; s < r.length; s++)
    t += Ie[r[s]];
  const n = `0x${t}`;
  return typeof e.size == "number" ? (ae(n, { size: e.size }), se(n, { dir: "right", size: e.size })) : n;
}
function ze(r, e = {}) {
  const { signed: t, size: n } = e, s = BigInt(r);
  let a;
  n ? t ? a = (1n << BigInt(n) * 8n - 1n) - 1n : a = 2n ** (BigInt(n) * 8n) - 1n : typeof r == "number" && (a = BigInt(Number.MAX_SAFE_INTEGER));
  const c = typeof a == "bigint" && t ? -a - 1n : 0;
  if (a && s > a || s < c) {
    const f = typeof r == "bigint" ? "n" : "";
    throw new Me({
      max: a ? `${a}${f}` : void 0,
      min: `${c}${f}`,
      signed: t,
      size: n,
      value: `${r}${f}`
    });
  }
  const d = `0x${(t && s < 0 ? (1n << BigInt(n * 8)) + BigInt(s) : s).toString(16)}`;
  return n ? se(d, { size: n }) : d;
}
const Ce = /* @__PURE__ */ new TextEncoder();
function me(r, e = {}) {
  const t = Ce.encode(r);
  return we(t, e);
}
class Ue extends Map {
  constructor(e) {
    super(), Object.defineProperty(this, "maxSize", {
      enumerable: !0,
      configurable: !0,
      writable: !0,
      value: void 0
    }), this.maxSize = e;
  }
  get(e) {
    const t = super.get(e);
    return super.has(e) && t !== void 0 && (this.delete(e), super.set(e, t)), t;
  }
  set(e, t) {
    if (super.set(e, t), this.maxSize && this.size > this.maxSize) {
      const n = this.keys().next().value;
      n && this.delete(n);
    }
    return this;
  }
}
const x = (r, e, t) => JSON.stringify(r, (n, s) => typeof s == "bigint" ? s.toString() : s, t), ft = {
  gwei: 9,
  wei: 18
}, Ae = {
  ether: -9,
  wei: 9
};
function ke(r, e) {
  let t = r.toString();
  const n = t.startsWith("-");
  n && (t = t.slice(1)), t = t.padStart(e, "0");
  let [s, a] = [
    t.slice(0, t.length - e),
    t.slice(t.length - e)
  ];
  return a = a.replace(/(0+)$/, ""), `${n ? "-" : ""}${s || "0"}${a ? `.${a}` : ""}`;
}
function Z(r, e = "wei") {
  return ke(r, Ae[e]);
}
class ye extends i {
  constructor({ cause: e, message: t } = {}) {
    const n = t?.replace("execution reverted: ", "")?.replace("execution reverted", "");
    super(`Execution reverted ${n ? `with reason: ${n}` : "for an unknown reason"}.`, {
      cause: e,
      name: "ExecutionRevertedError"
    });
  }
}
Object.defineProperty(ye, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: 3
});
Object.defineProperty(ye, "nodeMessage", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: /execution reverted/
});
class Fe extends i {
  constructor({ cause: e, maxFeePerGas: t } = {}) {
    super(`The fee cap (\`maxFeePerGas\`${t ? ` = ${Z(t)} gwei` : ""}) cannot be higher than the maximum allowed value (2^256-1).`, {
      cause: e,
      name: "FeeCapTooHighError"
    });
  }
}
Object.defineProperty(Fe, "nodeMessage", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: /max fee per gas higher than 2\^256-1|fee cap higher than 2\^256-1/
});
class Be extends i {
  constructor({ cause: e, maxFeePerGas: t } = {}) {
    super(`The fee cap (\`maxFeePerGas\`${t ? ` = ${Z(t)}` : ""} gwei) cannot be lower than the block base fee.`, {
      cause: e,
      name: "FeeCapTooLowError"
    });
  }
}
Object.defineProperty(Be, "nodeMessage", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: /max fee per gas less than block base fee|fee cap less than block base fee|transaction is outdated/
});
class He extends i {
  constructor({ cause: e, nonce: t } = {}) {
    super(`Nonce provided for the transaction ${t ? `(${t}) ` : ""}is higher than the next one expected.`, { cause: e, name: "NonceTooHighError" });
  }
}
Object.defineProperty(He, "nodeMessage", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: /nonce too high/
});
class Le extends i {
  constructor({ cause: e, nonce: t } = {}) {
    super([
      `Nonce provided for the transaction ${t ? `(${t}) ` : ""}is lower than the current nonce of the account.`,
      "Try increasing the nonce or find the latest nonce with `getTransactionCount`."
    ].join(`
`), { cause: e, name: "NonceTooLowError" });
  }
}
Object.defineProperty(Le, "nodeMessage", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: /nonce too low|transaction already imported|already known/
});
class De extends i {
  constructor({ cause: e, nonce: t } = {}) {
    super(`Nonce provided for the transaction ${t ? `(${t}) ` : ""}exceeds the maximum allowed nonce.`, { cause: e, name: "NonceMaxValueError" });
  }
}
Object.defineProperty(De, "nodeMessage", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: /nonce has max value/
});
class Je extends i {
  constructor({ cause: e } = {}) {
    super([
      "The total cost (gas * gas fee + value) of executing this transaction exceeds the balance of the account."
    ].join(`
`), {
      cause: e,
      metaMessages: [
        "This error could arise when the account does not have enough funds to:",
        " - pay for the total gas fee,",
        " - pay for the value to send.",
        " ",
        "The cost of the transaction is calculated as `gas * gas fee + value`, where:",
        " - `gas` is the amount of gas needed for transaction to execute,",
        " - `gas fee` is the gas fee,",
        " - `value` is the amount of ether to send to the recipient."
      ],
      name: "InsufficientFundsError"
    });
  }
}
Object.defineProperty(Je, "nodeMessage", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: /insufficient funds|exceeds transaction sender account balance/
});
class We extends i {
  constructor({ cause: e, gas: t } = {}) {
    super(`The amount of gas ${t ? `(${t}) ` : ""}provided for the transaction exceeds the limit allowed for the block.`, {
      cause: e,
      name: "IntrinsicGasTooHighError"
    });
  }
}
Object.defineProperty(We, "nodeMessage", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: /intrinsic gas too high|gas limit reached/
});
class Ge extends i {
  constructor({ cause: e, gas: t } = {}) {
    super(`The amount of gas ${t ? `(${t}) ` : ""}provided for the transaction is too low.`, {
      cause: e,
      name: "IntrinsicGasTooLowError"
    });
  }
}
Object.defineProperty(Ge, "nodeMessage", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: /intrinsic gas too low/
});
class Ve extends i {
  constructor({ cause: e }) {
    super("The transaction type is not supported for this chain.", {
      cause: e,
      name: "TransactionTypeNotSupportedError"
    });
  }
}
Object.defineProperty(Ve, "nodeMessage", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: /transaction type not valid/
});
class Ke extends i {
  constructor({ cause: e, maxPriorityFeePerGas: t, maxFeePerGas: n } = {}) {
    super([
      `The provided tip (\`maxPriorityFeePerGas\`${t ? ` = ${Z(t)} gwei` : ""}) cannot be higher than the fee cap (\`maxFeePerGas\`${n ? ` = ${Z(n)} gwei` : ""}).`
    ].join(`
`), {
      cause: e,
      name: "TipAboveFeeCapError"
    });
  }
}
Object.defineProperty(Ke, "nodeMessage", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: /max priority fee per gas higher than max fee per gas|tip higher than fee cap/
});
class pt extends i {
  constructor({ cause: e }) {
    super(`An error occurred while executing: ${e?.shortMessage}`, {
      cause: e,
      name: "UnknownNodeError"
    });
  }
}
const ce = (r) => r;
class O extends i {
  constructor({ body: e, cause: t, details: n, headers: s, status: a, url: c }) {
    super("HTTP request failed.", {
      cause: t,
      details: n,
      metaMessages: [
        a && `Status: ${a}`,
        `URL: ${ce(c)}`,
        e && `Request body: ${x(e)}`
      ].filter(Boolean),
      name: "HttpRequestError"
    }), Object.defineProperty(this, "body", {
      enumerable: !0,
      configurable: !0,
      writable: !0,
      value: void 0
    }), Object.defineProperty(this, "headers", {
      enumerable: !0,
      configurable: !0,
      writable: !0,
      value: void 0
    }), Object.defineProperty(this, "status", {
      enumerable: !0,
      configurable: !0,
      writable: !0,
      value: void 0
    }), Object.defineProperty(this, "url", {
      enumerable: !0,
      configurable: !0,
      writable: !0,
      value: void 0
    }), this.body = e, this.headers = s, this.status = a, this.url = c;
  }
}
class ve extends i {
  constructor({ body: e, error: t, url: n }) {
    super("RPC Request failed.", {
      cause: t,
      details: t.message,
      metaMessages: [`URL: ${ce(n)}`, `Request body: ${x(e)}`],
      name: "RpcRequestError"
    }), Object.defineProperty(this, "code", {
      enumerable: !0,
      configurable: !0,
      writable: !0,
      value: void 0
    }), Object.defineProperty(this, "data", {
      enumerable: !0,
      configurable: !0,
      writable: !0,
      value: void 0
    }), this.code = t.code, this.data = t.data;
  }
}
class he extends i {
  constructor({ body: e, url: t }) {
    super("The request took too long to respond.", {
      details: "The request timed out.",
      metaMessages: [`URL: ${ce(t)}`, `Request body: ${x(e)}`],
      name: "TimeoutError"
    });
  }
}
const Xe = -1;
class b extends i {
  constructor(e, { code: t, docsPath: n, metaMessages: s, name: a, shortMessage: c }) {
    super(c, {
      cause: e,
      docsPath: n,
      metaMessages: s || e?.metaMessages,
      name: a || "RpcError"
    }), Object.defineProperty(this, "code", {
      enumerable: !0,
      configurable: !0,
      writable: !0,
      value: void 0
    }), this.name = a || e.name, this.code = e instanceof ve ? e.code : t ?? Xe;
  }
}
class g extends b {
  constructor(e, t) {
    super(e, t), Object.defineProperty(this, "data", {
      enumerable: !0,
      configurable: !0,
      writable: !0,
      value: void 0
    }), this.data = t.data;
  }
}
class j extends b {
  constructor(e) {
    super(e, {
      code: j.code,
      name: "ParseRpcError",
      shortMessage: "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."
    });
  }
}
Object.defineProperty(j, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: -32700
});
class T extends b {
  constructor(e) {
    super(e, {
      code: T.code,
      name: "InvalidRequestRpcError",
      shortMessage: "JSON is not a valid request object."
    });
  }
}
Object.defineProperty(T, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: -32600
});
class M extends b {
  constructor(e, { method: t } = {}) {
    super(e, {
      code: M.code,
      name: "MethodNotFoundRpcError",
      shortMessage: `The method${t ? ` "${t}"` : ""} does not exist / is not available.`
    });
  }
}
Object.defineProperty(M, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: -32601
});
class S extends b {
  constructor(e) {
    super(e, {
      code: S.code,
      name: "InvalidParamsRpcError",
      shortMessage: [
        "Invalid parameters were provided to the RPC method.",
        "Double check you have provided the correct parameters."
      ].join(`
`)
    });
  }
}
Object.defineProperty(S, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: -32602
});
class $ extends b {
  constructor(e) {
    super(e, {
      code: $.code,
      name: "InternalRpcError",
      shortMessage: "An internal error was received."
    });
  }
}
Object.defineProperty($, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: -32603
});
class q extends b {
  constructor(e) {
    super(e, {
      code: q.code,
      name: "InvalidInputRpcError",
      shortMessage: [
        "Missing or invalid parameters.",
        "Double check you have provided the correct parameters."
      ].join(`
`)
    });
  }
}
Object.defineProperty(q, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: -32e3
});
class I extends b {
  constructor(e) {
    super(e, {
      code: I.code,
      name: "ResourceNotFoundRpcError",
      shortMessage: "Requested resource not found."
    }), Object.defineProperty(this, "name", {
      enumerable: !0,
      configurable: !0,
      writable: !0,
      value: "ResourceNotFoundRpcError"
    });
  }
}
Object.defineProperty(I, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: -32001
});
class N extends b {
  constructor(e) {
    super(e, {
      code: N.code,
      name: "ResourceUnavailableRpcError",
      shortMessage: "Requested resource not available."
    });
  }
}
Object.defineProperty(N, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: -32002
});
class z extends b {
  constructor(e) {
    super(e, {
      code: z.code,
      name: "TransactionRejectedRpcError",
      shortMessage: "Transaction creation failed."
    });
  }
}
Object.defineProperty(z, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: -32003
});
class v extends b {
  constructor(e, { method: t } = {}) {
    super(e, {
      code: v.code,
      name: "MethodNotSupportedRpcError",
      shortMessage: `Method${t ? ` "${t}"` : ""} is not supported.`
    });
  }
}
Object.defineProperty(v, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: -32004
});
class R extends b {
  constructor(e) {
    super(e, {
      code: R.code,
      name: "LimitExceededRpcError",
      shortMessage: "Request exceeds defined limit."
    });
  }
}
Object.defineProperty(R, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: -32005
});
class C extends b {
  constructor(e) {
    super(e, {
      code: C.code,
      name: "JsonRpcVersionUnsupportedError",
      shortMessage: "Version of JSON-RPC protocol is not supported."
    });
  }
}
Object.defineProperty(C, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: -32006
});
class P extends g {
  constructor(e) {
    super(e, {
      code: P.code,
      name: "UserRejectedRequestError",
      shortMessage: "User rejected the request."
    });
  }
}
Object.defineProperty(P, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: 4001
});
class U extends g {
  constructor(e) {
    super(e, {
      code: U.code,
      name: "UnauthorizedProviderError",
      shortMessage: "The requested method and/or account has not been authorized by the user."
    });
  }
}
Object.defineProperty(U, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: 4100
});
class A extends g {
  constructor(e, { method: t } = {}) {
    super(e, {
      code: A.code,
      name: "UnsupportedProviderMethodError",
      shortMessage: `The Provider does not support the requested method${t ? ` " ${t}"` : ""}.`
    });
  }
}
Object.defineProperty(A, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: 4200
});
class k extends g {
  constructor(e) {
    super(e, {
      code: k.code,
      name: "ProviderDisconnectedError",
      shortMessage: "The Provider is disconnected from all chains."
    });
  }
}
Object.defineProperty(k, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: 4900
});
class F extends g {
  constructor(e) {
    super(e, {
      code: F.code,
      name: "ChainDisconnectedError",
      shortMessage: "The Provider is not connected to the requested chain."
    });
  }
}
Object.defineProperty(F, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: 4901
});
class B extends g {
  constructor(e) {
    super(e, {
      code: B.code,
      name: "SwitchChainError",
      shortMessage: "An error occurred when attempting to switch chain."
    });
  }
}
Object.defineProperty(B, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: 4902
});
class H extends g {
  constructor(e) {
    super(e, {
      code: H.code,
      name: "UnsupportedNonOptionalCapabilityError",
      shortMessage: "This Wallet does not support a capability that was not marked as optional."
    });
  }
}
Object.defineProperty(H, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: 5700
});
class L extends g {
  constructor(e) {
    super(e, {
      code: L.code,
      name: "UnsupportedChainIdError",
      shortMessage: "This Wallet does not support the requested chain ID."
    });
  }
}
Object.defineProperty(L, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: 5710
});
class D extends g {
  constructor(e) {
    super(e, {
      code: D.code,
      name: "DuplicateIdError",
      shortMessage: "There is already a bundle submitted with this ID."
    });
  }
}
Object.defineProperty(D, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: 5720
});
class J extends g {
  constructor(e) {
    super(e, {
      code: J.code,
      name: "UnknownBundleIdError",
      shortMessage: "This bundle id is unknown / has not been submitted"
    });
  }
}
Object.defineProperty(J, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: 5730
});
class W extends g {
  constructor(e) {
    super(e, {
      code: W.code,
      name: "BundleTooLargeError",
      shortMessage: "The call bundle is too large for the Wallet to process."
    });
  }
}
Object.defineProperty(W, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: 5740
});
class G extends g {
  constructor(e) {
    super(e, {
      code: G.code,
      name: "AtomicReadyWalletRejectedUpgradeError",
      shortMessage: "The Wallet can support atomicity after an upgrade, but the user rejected the upgrade."
    });
  }
}
Object.defineProperty(G, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: 5750
});
class V extends g {
  constructor(e) {
    super(e, {
      code: V.code,
      name: "AtomicityNotSupportedError",
      shortMessage: "The wallet does not support atomic execution but the request requires it."
    });
  }
}
Object.defineProperty(V, "code", {
  enumerable: !0,
  configurable: !0,
  writable: !0,
  value: 5760
});
class Qe extends b {
  constructor(e) {
    super(e, {
      name: "UnknownRpcError",
      shortMessage: "An unknown RPC error occurred."
    });
  }
}
const X = /* @__PURE__ */ new Ue(8192);
function Ye(r, { enabled: e = !0, id: t }) {
  if (!e || !t)
    return r();
  if (X.get(t))
    return X.get(t);
  const n = r().finally(() => X.delete(t));
  return X.set(t, n), n;
}
async function Ze(r) {
  return new Promise((e) => setTimeout(e, r));
}
function _e(r, { delay: e = 100, retryCount: t = 2, shouldRetry: n = () => !0 } = {}) {
  return new Promise((s, a) => {
    const c = async ({ count: d = 0 } = {}) => {
      const f = async ({ error: h }) => {
        const l = typeof e == "function" ? e({ count: d, error: h }) : e;
        l && await Ze(l), c({ count: d + 1 });
      };
      try {
        const h = await r();
        s(h);
      } catch (h) {
        if (d < t && await n({ count: d, error: h }))
          return f({ error: h });
        a(h);
      }
    };
    c();
  });
}
function et(r, e = {}) {
  return async (t, n = {}) => {
    const { dedupe: s = !1, methods: a, retryDelay: c = 150, retryCount: d = 3, uid: f } = {
      ...e,
      ...n
    }, { method: h } = t;
    if (a?.exclude?.includes(h))
      throw new v(new Error("method not supported"), {
        method: h
      });
    if (a?.include && !a.include.includes(h))
      throw new v(new Error("method not supported"), {
        method: h
      });
    const l = s ? me(`${f}.${x(t)}`) : void 0;
    return Ye(() => _e(async () => {
      try {
        return await r(t);
      } catch (p) {
        const o = p;
        switch (o.code) {
          // -32700
          case j.code:
            throw new j(o);
          // -32600
          case T.code:
            throw new T(o);
          // -32601
          case M.code:
            throw new M(o, { method: t.method });
          // -32602
          case S.code:
            throw new S(o);
          // -32603
          case $.code:
            throw new $(o);
          // -32000
          case q.code:
            throw new q(o);
          // -32001
          case I.code:
            throw new I(o);
          // -32002
          case N.code:
            throw new N(o);
          // -32003
          case z.code:
            throw new z(o);
          // -32004
          case v.code:
            throw new v(o, {
              method: t.method
            });
          // -32005
          case R.code:
            throw new R(o);
          // -32006
          case C.code:
            throw new C(o);
          // 4001
          case P.code:
            throw new P(o);
          // 4100
          case U.code:
            throw new U(o);
          // 4200
          case A.code:
            throw new A(o);
          // 4900
          case k.code:
            throw new k(o);
          // 4901
          case F.code:
            throw new F(o);
          // 4902
          case B.code:
            throw new B(o);
          // 5700
          case H.code:
            throw new H(o);
          // 5710
          case L.code:
            throw new L(o);
          // 5720
          case D.code:
            throw new D(o);
          // 5730
          case J.code:
            throw new J(o);
          // 5740
          case W.code:
            throw new W(o);
          // 5750
          case G.code:
            throw new G(o);
          // 5760
          case V.code:
            throw new V(o);
          // CAIP-25: User Rejected Error
          // https://docs.walletconnect.com/2.0/specs/clients/sign/error-codes#rejected-caip-25
          case 5e3:
            throw new P(o);
          default:
            throw p instanceof i ? p : new Qe(o);
        }
      }
    }, {
      delay: ({ count: p, error: o }) => {
        if (o && o instanceof O) {
          const u = o?.headers?.get("Retry-After");
          if (u?.match(/\d/))
            return Number.parseInt(u, 10) * 1e3;
        }
        return ~~(1 << p) * c;
      },
      retryCount: d,
      shouldRetry: ({ error: p }) => tt(p)
    }), { enabled: s, id: l });
  };
}
function tt(r) {
  return "code" in r && typeof r.code == "number" ? r.code === -1 || r.code === R.code || r.code === $.code : r instanceof O && r.status ? r.status === 403 || r.status === 408 || r.status === 413 || r.status === 429 || r.status === 500 || r.status === 502 || r.status === 503 || r.status === 504 : !0;
}
function rt() {
  let r = () => {
  }, e = () => {
  };
  return { promise: new Promise((n, s) => {
    r = n, e = s;
  }), resolve: r, reject: e };
}
const ne = /* @__PURE__ */ new Map();
function nt({ fn: r, id: e, shouldSplitBatch: t, wait: n = 0, sort: s }) {
  const a = async () => {
    const l = f();
    c();
    const p = l.map(({ args: o }) => o);
    p.length !== 0 && r(p).then((o) => {
      s && Array.isArray(o) && o.sort(s);
      for (let u = 0; u < l.length; u++) {
        const { resolve: w } = l[u];
        w?.([o[u], o]);
      }
    }).catch((o) => {
      for (let u = 0; u < l.length; u++) {
        const { reject: w } = l[u];
        w?.(o);
      }
    });
  }, c = () => ne.delete(e), d = () => f().map(({ args: l }) => l), f = () => ne.get(e) || [], h = (l) => ne.set(e, [...f(), l]);
  return {
    flush: c,
    async schedule(l) {
      const { promise: p, resolve: o, reject: u } = rt();
      return t?.([...d(), l]) && a(), f().length > 0 ? (h({ args: l, resolve: o, reject: u }), p) : (h({ args: l, resolve: o, reject: u }), setTimeout(a, n), p);
    }
  };
}
function ot(r, { errorInstance: e = new Error("timed out"), timeout: t, signal: n }) {
  return new Promise((s, a) => {
    (async () => {
      let c;
      try {
        const d = new AbortController();
        t > 0 && (c = setTimeout(() => {
          n ? d.abort() : a(e);
        }, t)), s(await r({ signal: d?.signal || null }));
      } catch (d) {
        d?.name === "AbortError" && a(e), a(d);
      } finally {
        clearTimeout(c);
      }
    })();
  });
}
function st() {
  return {
    current: 0,
    take() {
      return this.current++;
    },
    reset() {
      this.current = 0;
    }
  };
}
const fe = /* @__PURE__ */ st();
function at(r, e = {}) {
  return {
    async request(t) {
      const { body: n, fetchFn: s = e.fetchFn ?? fetch, onRequest: a = e.onRequest, onResponse: c = e.onResponse, timeout: d = e.timeout ?? 1e4 } = t, f = {
        ...e.fetchOptions ?? {},
        ...t.fetchOptions ?? {}
      }, { headers: h, method: l, signal: p } = f;
      try {
        const o = await ot(async ({ signal: w }) => {
          const E = {
            ...f,
            body: Array.isArray(n) ? x(n.map((m) => ({
              jsonrpc: "2.0",
              id: m.id ?? fe.take(),
              ...m
            }))) : x({
              jsonrpc: "2.0",
              id: n.id ?? fe.take(),
              ...n
            }),
            headers: {
              "Content-Type": "application/json",
              ...h
            },
            method: l || "POST",
            signal: p || (d > 0 ? w : null)
          }, _ = new Request(r, E), K = await a?.(_, E) ?? { ...E, url: r };
          return await s(K.url ?? r, K);
        }, {
          errorInstance: new he({ body: n, url: r }),
          timeout: d,
          signal: !0
        });
        c && await c(o);
        let u;
        if (o.headers.get("Content-Type")?.startsWith("application/json"))
          u = await o.json();
        else {
          u = await o.text();
          try {
            u = JSON.parse(u || "{}");
          } catch (w) {
            if (o.ok)
              throw w;
            u = { error: u };
          }
        }
        if (!o.ok)
          throw new O({
            body: n,
            details: x(u.error) || o.statusText,
            headers: o.headers,
            status: o.status,
            url: r
          });
        return u;
      } catch (o) {
        throw o instanceof O || o instanceof he ? o : new O({
          body: n,
          cause: o,
          url: r
        });
      }
    }
  };
}
const oe = 256;
let Q = oe, Y;
function ct(r = 11) {
  if (!Y || Q + r > oe * 2) {
    Y = "", Q = 0;
    for (let e = 0; e < oe; e++)
      Y += (256 + Math.random() * 256 | 0).toString(16).substring(1);
  }
  return Y.substring(Q, Q++ + r);
}
function ut({ key: r, methods: e, name: t, request: n, retryCount: s = 3, retryDelay: a = 150, timeout: c, type: d }, f) {
  const h = ct();
  return {
    config: {
      key: r,
      methods: e,
      name: t,
      request: n,
      retryCount: s,
      retryDelay: a,
      timeout: c,
      type: d
    },
    request: et(n, { methods: e, retryCount: s, retryDelay: a, uid: h }),
    value: f
  };
}
class it extends i {
  constructor() {
    super("No URL was provided to the Transport. Please provide a valid RPC URL to the Transport.", {
      docsPath: "/docs/clients/intro",
      name: "UrlRequiredError"
    });
  }
}
function bt(r, e = {}) {
  const { batch: t, fetchFn: n, fetchOptions: s, key: a = "http", methods: c, name: d = "HTTP JSON-RPC", onFetchRequest: f, onFetchResponse: h, retryDelay: l, raw: p } = e;
  return ({ chain: o, retryCount: u, timeout: w }) => {
    const { batchSize: E = 1e3, wait: _ = 0 } = typeof t == "object" ? t : {}, K = e.retryCount ?? u, ee = w ?? e.timeout ?? 1e4, m = r || o?.rpcUrls.default.http[0];
    if (!m)
      throw new it();
    const ue = at(m, {
      fetchFn: n,
      fetchOptions: s,
      onRequest: f,
      onResponse: h,
      timeout: ee
    });
    return ut({
      key: a,
      methods: c,
      name: d,
      async request({ method: xe, params: Ee }) {
        const ie = { method: xe, params: Ee }, { schedule: Pe } = nt({
          id: m,
          wait: _,
          shouldSplitBatch(y) {
            return y.length > E;
          },
          fn: (y) => ue.request({
            body: y
          }),
          sort: (y, Re) => y.id - Re.id
        }), $e = async (y) => t ? Pe(y) : [
          await ue.request({
            body: y
          })
        ], [{ error: te, result: de }] = await $e(ie);
        if (p)
          return { error: te, result: de };
        if (te)
          throw new ve({
            body: ie,
            error: te,
            url: m
          });
        return de;
      },
      retryCount: K,
      retryDelay: l,
      timeout: ee,
      type: "http"
    }, {
      fetchOptions: s,
      url: m
    });
  };
}
export {
  Ze as A,
  i as B,
  ye as E,
  Fe as F,
  Je as I,
  Ue as L,
  He as N,
  N as R,
  dt as S,
  Ke as T,
  pt as U,
  ae as a,
  we as b,
  Z as c,
  Be as d,
  ft as e,
  ke as f,
  Le as g,
  lt as h,
  Oe as i,
  De as j,
  We as k,
  Ge as l,
  Ve as m,
  ze as n,
  qe as o,
  se as p,
  B as q,
  P as r,
  le as s,
  ht as t,
  ct as u,
  ot as v,
  _e as w,
  bt as x,
  ut as y,
  z
};
