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