import { as as ft, aX as A, aY as H, au as Ct, aZ as ot, az as lt, aE as V, a_ as gt, a$ as It, aH as p, b0 as zt, b1 as Et, b2 as tt, b3 as Ot, b4 as Zt, b5 as ut } from "./index-CjwA7HmM.mjs";
import { a as bt, g as Yt } from "./wallets-B07Re9vF.mjs";
import { d as Qt } from "./signer-BAztlcE7.mjs";
class D extends Error {
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
  constructor(t, e) {
    super(t), this.error = e;
  }
}
class L extends D {
  constructor() {
    super(...arguments), this.name = "WalletNotReadyError";
  }
}
class mt extends D {
  constructor() {
    super(...arguments), this.name = "WalletLoadError";
  }
}
class b extends D {
  constructor() {
    super(...arguments), this.name = "WalletConfigError";
  }
}
class K extends D {
  constructor() {
    super(...arguments), this.name = "WalletConnectionError";
  }
}
class st extends D {
  constructor() {
    super(...arguments), this.name = "WalletDisconnectedError";
  }
}
class _ extends D {
  constructor() {
    super(...arguments), this.name = "WalletDisconnectionError";
  }
}
class y extends D {
  constructor() {
    super(...arguments), this.name = "WalletAccountError";
  }
}
class Z extends D {
  constructor() {
    super(...arguments), this.name = "WalletPublicKeyError";
  }
}
class g extends D {
  constructor() {
    super(...arguments), this.name = "WalletNotConnectedError";
  }
}
class f extends D {
  constructor() {
    super(...arguments), this.name = "WalletSendTransactionError";
  }
}
class u extends D {
  constructor() {
    super(...arguments), this.name = "WalletSignTransactionError";
  }
}
class P extends D {
  constructor() {
    super(...arguments), this.name = "WalletSignMessageError";
  }
}
class Nt extends D {
  constructor() {
    super(...arguments), this.name = "WalletSignInError";
  }
}
class Wt extends D {
  constructor() {
    super(...arguments), this.name = "WalletWindowClosedError";
  }
}
var M;
(function(a) {
  a.Installed = "Installed", a.NotDetected = "NotDetected", a.Loadable = "Loadable", a.Unsupported = "Unsupported";
})(M || (M = {}));
class Lt extends ft {
  get connected() {
    return !!this.publicKey;
  }
  async autoConnect() {
    await this.connect();
  }
  async prepareTransaction(t, e, i = {}) {
    const n = this.publicKey;
    if (!n)
      throw new g();
    return t.feePayer = t.feePayer || n, t.recentBlockhash = t.recentBlockhash || (await e.getLatestBlockhash({
      commitment: i.preflightCommitment,
      minContextSlot: i.minContextSlot
    })).blockhash, t;
  }
}
function B(a) {
  if (typeof window > "u" || typeof document > "u")
    return;
  const t = [];
  function e() {
    if (a())
      for (const s of t)
        s();
  }
  const i = (
    // TODO: #334 Replace with idle callback strategy.
    setInterval(e, 1e3)
  );
  t.push(() => clearInterval(i)), // Implies that `DOMContentLoaded` has not yet fired.
  document.readyState === "loading" && (document.addEventListener("DOMContentLoaded", e, { once: !0 }), t.push(() => document.removeEventListener("DOMContentLoaded", e))), // If the `complete` state has been reached, we're too late.
  document.readyState !== "complete" && (window.addEventListener("load", e, { once: !0 }), t.push(() => window.removeEventListener("load", e))), e();
}
function C(a) {
  return "version" in a;
}
class at extends Lt {
  async sendTransaction(t, e, i = {}) {
    let n = !0;
    try {
      if (C(t)) {
        if (!this.supportedTransactionVersions)
          throw new f("Sending versioned transactions isn't supported by this wallet");
        if (!this.supportedTransactionVersions.has(t.version))
          throw new f(`Sending transaction version ${t.version} isn't supported by this wallet`);
        try {
          t = await this.signTransaction(t);
          const s = t.serialize();
          return await e.sendRawTransaction(s, i);
        } catch (s) {
          throw s instanceof u ? (n = !1, s) : new f(s == null ? void 0 : s.message, s);
        }
      } else
        try {
          const { signers: s, ...l } = i;
          t = await this.prepareTransaction(t, e, l), s != null && s.length && t.partialSign(...s), t = await this.signTransaction(t);
          const c = t.serialize();
          return await e.sendRawTransaction(c, l);
        } catch (s) {
          throw s instanceof u ? (n = !1, s) : new f(s == null ? void 0 : s.message, s);
        }
    } catch (s) {
      throw n && this.emit("error", s), s;
    }
  }
  async signAllTransactions(t) {
    for (const i of t)
      if (C(i)) {
        if (!this.supportedTransactionVersions)
          throw new u("Signing versioned transactions isn't supported by this wallet");
        if (!this.supportedTransactionVersions.has(i.version))
          throw new u(`Signing transaction version ${i.version} isn't supported by this wallet`);
      }
    const e = [];
    for (const i of t)
      e.push(await this.signTransaction(i));
    return e;
  }
}
class v extends at {
}
const m = "solana:signAndSendTransaction", q = "solana:signIn", W = "solana:signMessage", N = "solana:signTransaction", St = "standard:connect", wt = "standard:disconnect", xt = "standard:events";
function Ut(a) {
  return St in a.features && xt in a.features && (m in a.features || N in a.features);
}
var G;
(function(a) {
  a.Mainnet = "mainnet-beta", a.Testnet = "testnet", a.Devnet = "devnet";
})(G || (G = {}));
const kt = "Bitget";
class Gt extends v {
  constructor(t = {}) {
    super(), this.name = kt, this.url = "https://web3.bitget.com", this.icon = "data:image/svg+xml;base64, ", this.supportedTransactionVersions = null, this._readyState = typeof window > "u" || typeof document > "u" ? M.Unsupported : M.NotDetected, this._connecting = !1, this._wallet = null, this._publicKey = null, this._readyState !== M.Unsupported && B(() => {
      var e, i;
      return (i = (e = window.bitkeep) == null ? void 0 : e.solana) != null && i.isBitKeep ? (this._readyState = M.Installed, this.emit("readyStateChange", this._readyState), !0) : !1;
    });
  }
  get publicKey() {
    return this._publicKey;
  }
  get connecting() {
    return this._connecting;
  }
  get readyState() {
    return this._readyState;
  }
  async connect() {
    try {
      if (this.connected || this.connecting)
        return;
      if (this._readyState !== M.Installed)
        throw new L();
      this._connecting = !0;
      const t = window.bitkeep.solana;
      let e;
      try {
        e = await t.getAccount();
      } catch (n) {
        throw new y(n == null ? void 0 : n.message, n);
      }
      let i;
      try {
        i = new A(e);
      } catch (n) {
        throw new Z(n == null ? void 0 : n.message, n);
      }
      this._wallet = t, this._publicKey = i, this.emit("connect", i);
    } catch (t) {
      throw this.emit("error", t), t;
    } finally {
      this._connecting = !1;
    }
  }
  async disconnect() {
    const t = this._wallet;
    if (t) {
      this._wallet = null, this._publicKey = null;
      try {
        await t.disconnect();
      } catch (e) {
        this.emit("error", new _(e == null ? void 0 : e.message, e));
      }
    }
    this.emit("disconnect");
  }
  async signTransaction(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        return await e.signTransaction(t) || t;
      } catch (i) {
        throw new u(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
  async signAllTransactions(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        return await e.signAllTransactions(t) || t;
      } catch (i) {
        throw new u(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
  async signMessage(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        const { signature: i } = await e.signMessage(t);
        return i;
      } catch (i) {
        throw new u(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
}
const _t = "Clover";
class Pt extends v {
  constructor(t = {}) {
    super(), this.name = _t, this.url = "https://clv.org", this.icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDgiIGhlaWdodD0iNDgiIHZpZXdCb3g9IjAgMCA0OCA0OCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTM2LjQ4IDBIMTEuNTJDNS4xNTc2OCAwIDAgNS4xNTc2OCAwIDExLjUyVjM2LjQ4QzAgNDIuODQyMyA1LjE1NzY4IDQ4IDExLjUyIDQ4SDM2LjQ4QzQyLjg0MjMgNDggNDggNDIuODQyMyA0OCAzNi40OFYxMS41MkM0OCA1LjE1NzY4IDQyLjg0MjMgMCAzNi40OCAwWiIgZmlsbD0idXJsKCNwYWludDBfbGluZWFyXzc5MTBfMTYzMzUxKSIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTI0LjAwMDYgMzkuMzYwNkMzMi40ODM3IDM5LjM2MDYgMzkuMzYwNiAzMi40ODM3IDM5LjM2MDYgMjQuMDAwNkMzOS4zNjA2IDE1LjUxNzUgMzIuNDgzNyA4LjY0MDYyIDI0LjAwMDYgOC42NDA2MkMxNS41MTc1IDguNjQwNjIgOC42NDA2MiAxNS41MTc1IDguNjQwNjIgMjQuMDAwNkM4LjY0MDYyIDMyLjQ4MzcgMTUuNTE3NSAzOS4zNjA2IDI0LjAwMDYgMzkuMzYwNlpNMjEuMjg5OSAxNS44Njg4SDI2LjcxMVYyMS4zNDdIMjEuMjkwNFYyNi42NTRIMjYuNzExVjMyLjEzMjJIMjEuMjg5OVYyNi44MjUySDE1Ljg2OTNWMjEuMzQ3SDIxLjI4OTlWMTUuODY4OFpNMjYuNzEyIDIxLjM0N0gzMi4xMzMxVjI2LjgyNTJIMjYuNzEyVjIxLjM0N1oiIGZpbGw9ImJsYWNrIi8+CjxkZWZzPgo8bGluZWFyR3JhZGllbnQgaWQ9InBhaW50MF9saW5lYXJfNzkxMF8xNjMzNTEiIHgxPSI0OCIgeTE9Ii0xLjQzMDUxZS0wNiIgeDI9IjEuNDMwNTFlLTA2IiB5Mj0iNDgiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIj4KPHN0b3Agc3RvcC1jb2xvcj0iI0E5RkZFMCIvPgo8c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiM4NkQ1RkYiLz4KPC9saW5lYXJHcmFkaWVudD4KPC9kZWZzPgo8L3N2Zz4=", this.supportedTransactionVersions = null, this._readyState = typeof window > "u" || typeof document > "u" ? M.Unsupported : M.NotDetected, this._connecting = !1, this._wallet = null, this._publicKey = null, this._readyState !== M.Unsupported && B(() => {
      var e;
      return (e = window.clover_solana) != null && e.isCloverWallet ? (this._readyState = M.Installed, this.emit("readyStateChange", this._readyState), !0) : !1;
    });
  }
  get publicKey() {
    return this._publicKey;
  }
  get connecting() {
    return this._connecting;
  }
  get readyState() {
    return this._readyState;
  }
  async connect() {
    try {
      if (this.connected || this.connecting)
        return;
      if (this._readyState !== M.Installed)
        throw new L();
      this._connecting = !0;
      const t = window.clover_solana;
      let e;
      try {
        e = await t.getAccount();
      } catch (n) {
        throw new y(n == null ? void 0 : n.message, n);
      }
      let i;
      try {
        i = new A(e);
      } catch (n) {
        throw new Z(n == null ? void 0 : n.message, n);
      }
      this._wallet = t, this._publicKey = i, this.emit("connect", i);
    } catch (t) {
      throw this.emit("error", t), t;
    } finally {
      this._connecting = !1;
    }
  }
  async disconnect() {
    this._wallet && (this._wallet = null, this._publicKey = null), this.emit("disconnect");
  }
  async signTransaction(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        return await e.signTransaction(t) || t;
      } catch (i) {
        throw new u(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
  async signAllTransactions(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        return await e.signAllTransactions(t) || t;
      } catch (i) {
        throw new u(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
  async signMessage(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        const { signature: i } = await e.signMessage(t);
        return Uint8Array.from(i);
      } catch (i) {
        throw new P(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
}
const Bt = "Coin98";
class vt extends v {
  constructor(t = {}) {
    super(), this.name = Bt, this.url = "https://coin98.com", this.icon = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA3NiA3NSI+CiAgPGRlZnM+CiAgICA8bGluZWFyR3JhZGllbnQgaWQ9ImEiIHgxPSIxMDEuNjgxJSIgeDI9Ii0xLjU1NyUiIHkxPSIxNS4yNjglIiB5Mj0iODQuOTE3JSI+CiAgICAgIDxzdG9wIG9mZnNldD0iMCUiIHN0b3AtY29sb3I9IiNGMUQ5NjEiLz4KICAgICAgPHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjQ0RBMTQ2Ii8+CiAgICA8L2xpbmVhckdyYWRpZW50PgogIDwvZGVmcz4KICA8ZyBmaWxsPSJub25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tMS43NVoiLz4KICA8L2c+Cjwvc3ZnPgo=", this.supportedTransactionVersions = null, this._readyState = typeof window > "u" || typeof document > "u" ? M.Unsupported : M.NotDetected, this._connecting = !1, this._wallet = null, this._publicKey = null, this._readyState !== M.Unsupported && B(() => {
      var e;
      return (e = window.coin98) != null && e.sol ? (this._readyState = M.Installed, this.emit("readyStateChange", this._readyState), !0) : !1;
    });
  }
  get publicKey() {
    return this._publicKey;
  }
  get connecting() {
    return this._connecting;
  }
  get connected() {
    var t;
    return !!((t = this._wallet) != null && t.isConnected());
  }
  get readyState() {
    return this._readyState;
  }
  async connect() {
    try {
      if (this.connected || this.connecting)
        return;
      if (this._readyState !== M.Installed)
        throw new L();
      this._connecting = !0;
      const t = window.coin98.sol;
      let e;
      try {
        e = (await t.connect())[0];
      } catch (n) {
        throw new y(n == null ? void 0 : n.message, n);
      }
      let i;
      try {
        i = new A(e);
      } catch (n) {
        throw new Z(n == null ? void 0 : n.message, n);
      }
      this._wallet = t, this._publicKey = i, this.emit("connect", i);
    } catch (t) {
      throw this.emit("error", t), t;
    } finally {
      this._connecting = !1;
    }
  }
  async disconnect() {
    const t = this._wallet;
    if (t) {
      this._wallet = null, this._publicKey = null;
      try {
        await t.disconnect();
      } catch (e) {
        this.emit("error", new _(e == null ? void 0 : e.message, e));
      }
    }
    this.emit("disconnect");
  }
  async signTransaction(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        const i = await e.request({ method: "sol_sign", params: [t] }), n = new A(i.publicKey), s = H.decode(i.signature);
        return t.addSignature(n, s), t;
      } catch (i) {
        throw new u(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
  async signAllTransactions(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        const i = await e.request({ method: "sol_signAllTransactions", params: [t] }), n = new A(i.publicKey), s = i.signatures;
        return t.map((l, c) => {
          const h = H.decode(s[c]);
          return l.addSignature(n, h), l;
        });
      } catch (i) {
        throw new u(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
  async signMessage(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        const i = await e.request({ method: "sol_signMessage", params: [t] });
        return H.decode(i.signature);
      } catch (i) {
        throw new P(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
}
const Vt = "Nightly";
class Ht extends v {
  constructor() {
    super(), this.name = Vt, this.url = "https://nightly.app", this.icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iOTYiIGhlaWdodD0iOTYiIHZpZXdCb3g9IjAgMCA5NiA5NiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTQ4IDk2Qzc0LjUwOTcgOTYgOTYgNzQuNTA5NyA5NiA0OEM5NiAyMS40OTAzIDc0LjUwOTcgMCA0OCAwQzIxLjQ5MDMgMCAwIDIxLjQ5MDMgMCA0OEMwIDc0LjUwOTcgMjEuNDkwMyA5NiA0OCA5NloiIGZpbGw9IiM2RDczRjgiLz4KPHBhdGggZD0iTTQ4IDg1LjYzNTZDNDggODUuNjM1NiA1Mi40NTMzIDg1LjYzNTYgNTUuNDQgODIuNTg2N0M1OC45MTU1IDc5LjI4MDEgNTcuMzUxMSA3NS40MzEyIDYyLjI3NTUgNzEuNDMxMkM2Ni45ODY2IDY3LjY0NDUgNzIuOTI0NCA3MC4zMzc5IDcyLjkyNDQgNzAuMzM3OUM3Ny4wMjIyIDYyLjEyNDUgNzQuNzkxMSA1Mi41NjkgNzQuNzkxMSA1Mi41NjlDODEuNzY4OCAzNC4yNTc5IDc1Ljk2NDQgMjEuMTU1NyA3NC40NDQ0IDE3LjM2MDFDNjkuNDQ4OCAyNC4zMzc5IDYzLjE5MTEgMjkuMTczNCA1NS43OTU1IDMyLjQwOUM1My4yMjY2IDMxLjcwNjggNTAuNTk1NSAzMS4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Ny4yNjI0IDYzLjc4NjYgNTkuODIyNEM2My43ODY2IDU5LjgyMjQgNjMuMTQ2NiA2Mi40MzU4IDYwLjE1OTkgNjMuNzUxM0M1Ny43MjQzIDY0LjgyNjkgNTYuNjc1NSA2My4zODY5IDUzLjUxOTkgNjUuMjk4WiIgZmlsbD0iIzdCODFGOSIvPgo8cGF0aCBkPSJNNzMuNTAyMiAyMy4wOTM1Qzc1LjkxMTEgMzEuNTQ2OCA3NC44NzExIDQyLjI0MDIgNzEuMDY2NiA1MC4wMjY5QzY3LjE3MzMgNDcuMjcxMyA2My4wODQ0IDQzLjAxMzUgNjAuOTA2NiAzOC41MDY5QzY2LjAzNTUgMzQuNzExMyA3MC4zMzc3IDMxLjEwMjQgNzMuNTAyMiAyMy4wOTM1WiIgZmlsbD0iIzdCODFGOSIvPgo8cGF0aCBkPSJNNDcuOTk5OSA4NS4zMDY5QzUwLjE0MDQgODUuMzA2OSA1MS44NzU1IDgzLjc3ODcgNTEuODc1NSA4MS44OTM2QzUxLjg3NTUgODAuMDA4NCA1MC4xNDA0IDc4LjQ4MDIgNDcuOTk5OSA3OC40ODAyQzQ1Ljg1OTUgNzguNDgwMiA0NC4xMjQ0IDgwLjAwODQgNDQuMTI0NCA4MS44OTM2QzQ0LjEyNDQgODMuNzc4NyA0NS44NTk1IDg1LjMwNjkgNDcuOTk5OSA4NS4zMDY5WiIgZmlsbD0iIzdCODFGOSIvPgo8L3N2Zz4K", this.supportedTransactionVersions = /* @__PURE__ */ new Set(["legacy", 0]), this._readyState = typeof window > "u" || typeof document > "u" ? M.Unsupported : M.NotDetected, this._connecting = !1, this._publicKey = null, this._wallet = null, this._readyState !== M.Unsupported && B(() => {
      var t;
      return (t = window == null ? void 0 : window.nightly) != null && t.solana ? (this._readyState = M.Installed, this.emit("readyStateChange", this._readyState), !0) : !1;
    });
  }
  get connecting() {
    return this._connecting;
  }
  get readyState() {
    return this._readyState;
  }
  get publicKey() {
    return this._publicKey;
  }
  async connect() {
    try {
      if (this.connected || this.connecting)
        return;
      if (this._readyState !== M.Installed)
        throw new L();
      this._connecting = !0;
      const t = window.nightly.solana;
      try {
        await t.connect();
      } catch (i) {
        throw new K(i == null ? void 0 : i.message, i);
      }
      if (t.publicKey.toString() === "11111111111111111111111111111111")
        throw new y();
      let e;
      try {
        e = new A(t.publicKey.toBytes());
      } catch (i) {
        throw new Z(i == null ? void 0 : i.message, i);
      }
      this._wallet = t, this._publicKey = e, this.emit("connect", e);
    } catch (t) {
      throw this.emit("error", t), t;
    } finally {
      this._connecting = !1;
    }
  }
  async disconnect() {
    const t = this._wallet;
    if (t) {
      this._wallet = null, this._publicKey = null;
      try {
        await t.disconnect();
      } catch {
        this.emit("error", new st());
      }
    }
    this.emit("disconnect");
  }
  async signTransaction(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        return await e.signTransaction(t);
      } catch (i) {
        throw new u(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
  async signAllTransactions(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        return await e.signAllTransactions(t);
      } catch (i) {
        throw new u(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
  async signMessage(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        return e.signMessage(new TextDecoder().decode(t));
      } catch (i) {
        throw new u(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
}
const Dt = "solana:mainnet", Jt = "solana:devnet", Rt = "solana:testnet", Xt = "solana:localnet", Kt = "Solong";
class Ft extends at {
  constructor(t = {}) {
    super(), this.name = Kt, this.url = "https://solongwallet.io", this.icon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAGlklEQVR4Ae3bA5DsyhfH8TNr49r2/du2bdu2bdu2zcdNrm3b9toz533rvctUn3Umk9p01WfdvVW/6nROBxJVS1rSk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YBJgEmASYCJJMAkwBi6A3xCqZhiBz8+AAAAAElFTkSuQmCC", this.supportedTransactionVersions = null, this._readyState = typeof window > "u" || typeof document > "u" ? M.Unsupported : M.NotDetected, this._connecting = !1, this._wallet = null, this._publicKey = null, this._readyState !== M.Unsupported && B(() => window.solong ? (this._readyState = M.Installed, this.emit("readyStateChange", this._readyState), !0) : !1);
  }
  get publicKey() {
    return this._publicKey;
  }
  get connecting() {
    return this._connecting;
  }
  get connected() {
    var t;
    return !!((t = this._wallet) != null && t.currentAccount);
  }
  get readyState() {
    return this._readyState;
  }
  async connect() {
    try {
      if (this.connected || this.connecting)
        return;
      if (this._readyState !== M.Installed)
        throw new L();
      this._connecting = !0;
      const t = window.solong;
      let e;
      try {
        e = await t.selectAccount();
      } catch (n) {
        throw new y(n == null ? void 0 : n.message, n);
      }
      let i;
      try {
        i = new A(e);
      } catch (n) {
        throw new Z(n == null ? void 0 : n.message, n);
      }
      this._wallet = t, this._publicKey = i, this.emit("connect", i);
    } catch (t) {
      throw this.emit("error", t), t;
    } finally {
      this._connecting = !1;
    }
  }
  async disconnect() {
    this._wallet && (this._wallet = null, this._publicKey = null), this.emit("disconnect");
  }
  async signTransaction(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        return await e.signTransaction(t) || t;
      } catch (i) {
        throw new u(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
}
const qt = "Torus";
class $t extends v {
  constructor({ params: t = { showTorusButton: !1 } } = { params: { showTorusButton: !1 } }) {
    super(), this.name = qt, this.url = "https://tor.us", this.icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzMiIGhlaWdodD0iMzIiIHZpZXdCb3g9IjAgMCAzMyAzMiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGNpcmNsZSBjeD0iMTYuNSIgY3k9IjE2IiByPSIxNiIgZmlsbD0iIzAzNjRGRiIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTExLjIxODYgOS40OTIxOUMxMC40NTM5IDkuNDkyMTkgOS44MzM5OCAxMC4xMTIxIDkuODMzOTggMTAuODc2OFYxMi40ODk4QzkuODMzOTggMTMuMjU0NSAxMC40NTM5IDEzLjg3NDQgMTEuMjE4NiAxMy44NzQ0SDEzLjY2ODRWMjIuODk3NkMxMy42Njg0IDIzLjY2MjMgMTQuMjg4MyAyNC4yODIyIDE1LjA1MyAyNC4yODIySDE2LjY2NkMxNy40MzA3IDI0LjI4MjIgMTguMDUwNiAyMy42NjIzIDE4LjA1MDYgMjIuODk3NlYxMi41MDE1QzE4LjA1MDYgMTIuNDk3NiAxOC4wNTA2IDEyLjQ5MzcgMTguMDUwNiAxMi40ODk4VjEwLjg3NjhDMTguMDUwNiAxMC4xMTIxIDE3LjQzMDcgOS40OTIxOSAxNi42NjYgOS40OTIxOUgxNS4wNTNIMTEuMjE4NloiIGZpbGw9IndoaXRlIi8+CjxwYXRoIGQ9Ik0yMS4zMzc2IDEzLjg3NDRDMjIuNTQ3NyAxMy44NzQ0IDIzLjUyODcgMTIuODkzNCAyMy41Mjg3IDExLjY4MzNDMjMuNTI4NyAxMC40NzMyIDIyLjU0NzcgOS40OTIxOSAyMS4zMzc2IDkuNDkyMTlDMjAuMTI3NSA5LjQ5MjE5IDE5LjE0NjUgMTAuNDczMiAxOS4xNDY1IDExLjY4MzNDMTkuMTQ2NSAxMi44OTM0IDIwLjEyNzUgMTMuODc0NCAyMS4zMzc2IDEzLjg3NDRaIiBmaWxsPSJ3aGl0ZSIvPgo8L3N2Zz4K", this.supportedTransactionVersions = null, this._readyState = typeof window > "u" || typeof document > "u" ? M.Unsupported : M.Loadable, this._connecting = !1, this._wallet = null, this._publicKey = null, this._params = t;
  }
  get publicKey() {
    return this._publicKey;
  }
  get connecting() {
    return this._connecting;
  }
  get connected() {
    var t;
    return !!((t = this._wallet) != null && t.isLoggedIn);
  }
  get readyState() {
    return this._readyState;
  }
  async connect() {
    try {
      if (this.connected || this.connecting)
        return;
      if (this._readyState !== M.Loadable)
        throw new L();
      this._connecting = !0;
      let t;
      try {
        t = (await import("./solanaEmbed.esm-DfSXcnar.mjs")).default;
      } catch (s) {
        throw new mt(s == null ? void 0 : s.message, s);
      }
      let e;
      try {
        e = window.torus || new t();
      } catch (s) {
        throw new b(s == null ? void 0 : s.message, s);
      }
      if (!e.isInitialized)
        try {
          await e.init(this._params);
        } catch (s) {
          throw new K(s == null ? void 0 : s.message, s);
        }
      let i;
      try {
        i = await e.login();
      } catch (s) {
        throw new y(s == null ? void 0 : s.message, s);
      }
      let n;
      try {
        n = new A(i[0]);
      } catch (s) {
        throw new Z(s == null ? void 0 : s.message, s);
      }
      this._wallet = e, this._publicKey = n, this.emit("connect", n);
    } catch (t) {
      throw this.emit("error", t), t;
    } finally {
      this._connecting = !1;
    }
  }
  async disconnect() {
    const t = this._wallet;
    if (t) {
      this._wallet = null, this._publicKey = null;
      try {
        t.isLoggedIn && await t.cleanUp();
      } catch (e) {
        this.emit("error", new _(e == null ? void 0 : e.message, e));
      }
    }
    this.emit("disconnect");
  }
  async sendTransaction(t, e, i = {}) {
    try {
      const n = this._wallet;
      if (!n)
        throw new g();
      try {
        const { signers: s, ...l } = i;
        t = await this.prepareTransaction(t, e, l), s != null && s.length && t.partialSign(...s), l.preflightCommitment = l.preflightCommitment || e.commitment;
        const { signature: c } = await n.signAndSendTransaction(t, l);
        return c;
      } catch (s) {
        throw s instanceof D ? s : new f(s == null ? void 0 : s.message, s);
      }
    } catch (n) {
      throw this.emit("error", n), n;
    }
  }
  async signTransaction(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        return await e.signTransaction(t) || t;
      } catch (i) {
        throw new u(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
  async signAllTransactions(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        return await e.signAllTransactions(t) || t;
      } catch (i) {
        throw new u(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
  async signMessage(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        return await e.signMessage(t);
      } catch (i) {
        throw new P(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
}
function $(a) {
  switch (a) {
    case "processed":
    case "confirmed":
    case "finalized":
    case void 0:
      return a;
    case "recent":
      return "processed";
    case "single":
    case "singleGossip":
      return "confirmed";
    case "max":
    case "root":
      return "finalized";
    default:
      return;
  }
}
const te = "https://api.mainnet-beta.solana.com";
function ee(a) {
  return a.includes(te) ? Dt : /\bdevnet\b/i.test(a) ? Jt : /\btestnet\b/i.test(a) ? Rt : /\blocalhost\b/i.test(a) || /\b127\.0\.0\.1\b/.test(a) ? Xt : Dt;
}
const ie = "WalletConnect";
class ne extends at {
  constructor(t) {
    super(), this.name = ie, this.url = "https://walletconnect.org", this.icon = "data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjE4NSIgdmlld0JveD0iMCAwIDMwMCAxODUiIHdpZHRoPSIzMDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0ibTYxLjQzODU0MjkgMzYuMjU2MjYxMmM0OC45MTEyMjQxLTQ3Ljg4ODE2NjMgMTI4LjIxMTk4NzEtNDcuODg4MTY2MyAxNzcuMTIzMjA5MSAwbDUuODg2NTQ1IDUuNzYzNDE3NGMyLjQ0NTU2MSAyLjM5NDQwODEgMi40NDU1NjEgNi4yNzY1MTEyIDAgOC42NzA5MjA0bC0yMC4xMzY2OTUgMTkuNzE1NTAzYy0xLjIyMjc4MSAxLjE5NzIwNTEtMy4yMDUzIDEuMTk3MjA1MS00LjQyODA4MSAwbC04LjEwMDU4NC03LjkzMTE0NzljLTM0LjEyMTY5Mi0zMy40MD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S0yLjM5NDQwODIgOC44NTYxNjAyIDBsNTcuMzU0OTc3NSA1Ni4xNTUzNTdjLjYxMTM5MDguNTk4NjAyIDEuNjAyNjQ5LjU5ODYwMiAyLjIxNDAzOTggMCAuMDAwMDA5Mi0uMDAwMDA5LjAwMDAxNzQtLjAwMDAxNy4wMDAwMjY1LS4wMDAwMjRsNTcuMzUyMTAzMS01Ni4xNTUzMzNjMi40NDU1MDUtMi4zOTQ0NjMzIDYuNDEwNTQ0LTIuMzk0NTUzMSA4Ljg1NjE2MS0uMDAwMi4wMDAwMzQuMDAwMDMzNi4wMDAwNjguMDAwMDY3My4wMDAxMDEuMDAwMTAxbDU3LjM1NDkwMiA1Ni4xNTU0MzJjLjYxMTM5LjU5ODYwMSAxLjYwMjY1LjU5ODYwMSAyLjIxNDA0IDBsNTcuMzUzOTc1LTU2LjE1NDMyNDljMi40NDU1NjEtMi4zOTQ0MDkyIDYuNDEwNTk5LTIuMzk0NDA5MiA4Ljg1NjE2IDB6IiBmaWxsPSIjM2I5OWZjIi8+PC9zdmc+", this.supportedTransactionVersions = /* @__PURE__ */ new Set(["legacy", 0]), this._readyState = typeof window > "u" ? M.Unsupported : M.Loadable, this._disconnected = () => {
      const e = this._wallet;
      e && (e.client.off("session_delete", this._disconnected), this._wallet = null, this._publicKey = null, this.emit("error", new st()), this.emit("disconnect"));
    }, this._publicKey = null, this._connecting = !1, this._wallet = null, this._config = t;
  }
  get publicKey() {
    return this._publicKey;
  }
  get connecting() {
    return this._connecting;
  }
  get readyState() {
    return this._readyState;
  }
  async connect() {
    try {
      if (this.connected || this.connecting)
        return;
      if (this._readyState !== M.Loadable)
        throw new L();
      this._connecting = !0;
      let t, e;
      try {
        ({ WalletConnectWallet: t, WalletConnectChainID: e } = await import("./index-yd8RiLQo.mjs"));
      } catch (s) {
        throw new mt(s == null ? void 0 : s.message, s);
      }
      let i, n;
      try {
        i = new t({
          network: this._config.network === G.Mainnet ? e.Mainnet : e.Devnet,
          options: this._config.options
        }), { publicKey: n } = await i.connect();
      } catch (s) {
        throw s.constructor.name === "QRCodeModalError" ? new Wt() : new K(s == null ? void 0 : s.message, s);
      }
      i.client.on("session_delete", this._disconnected), this._wallet = i, this._publicKey = n, this.emit("connect", n);
    } catch (t) {
      throw this.emit("error", t), t;
    } finally {
      this._connecting = !1;
    }
  }
  async disconnect() {
    const t = this._wallet;
    if (t) {
      t.client.off("session_delete", this._disconnected), this._wallet = null, this._publicKey = null;
      try {
        await t.disconnect();
      } catch (e) {
        this.emit("error", new _(e == null ? void 0 : e.message, e));
      }
    }
    this.emit("disconnect");
  }
  async signTransaction(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        return await e.signTransaction(t);
      } catch (i) {
        throw new u(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
  async signMessage(t) {
    try {
      const e = this._wallet;
      if (!e)
        throw new g();
      try {
        return await e.signMessage(t);
      } catch (i) {
        throw new P(i == null ? void 0 : i.message, i);
      }
    } catch (e) {
      throw this.emit("error", e), e;
    }
  }
}
const se = {
  icon: "data:image/svg+xml;base64, ",
  name: "Bitget Wallet"
}, ae = [se], re = (a) => ae.find((t) => t.name.toLocaleLowerCase().includes(a.name.toLocaleLowerCase())) || a, ce = (a, t, e) => t[a] || e[a], ht = (a, t) => ce(a, re(t), t);
class z extends Ct {
  constructor(t, e) {
    super(), this.adapter = t, this.connection = e;
  }
  /** Retrieve the underlying solana adapter */
  getAdapter() {
    return this.adapter;
  }
  getName() {
    return ht("name", this.adapter);
  }
  getUrl() {
    return this.adapter.url;
  }
  async connect() {
    if (this.isConnected())
      return this.getAddresses();
    const t = await new Promise((e, i) => {
      this.adapter.on("connect", () => {
        this.adapter.off("connect"), this.adapter.off("error"), e(this.getAddresses());
      }), this.adapter.on("error", (n) => {
        this.adapter.off("connect"), this.adapter.off("error"), i(n);
      }), this.adapter.connect().catch(i);
    });
    return this.emit("connect"), this.adapter.on("disconnect", () => this.emit("disconnect")), t;
  }
  getNetworkInfo() {
    return {};
  }
  isConnected() {
    return this.adapter.connected;
  }
  async disconnect() {
    this.isConnected() && (await new Promise((t, e) => {
      this.adapter.on("disconnect", () => {
        this.adapter.off("disconnect"), this.adapter.off("error"), t(void 0);
      }), this.adapter.on("error", (i) => {
        this.adapter.off("disconnect"), this.adapter.off("error"), e(i);
      }), this.adapter.disconnect().catch(e);
    }), this.adapter.removeAllListeners(), this.emit("disconnect"));
  }
  getChainId() {
    return ot;
  }
  getAddress() {
    var t;
    return (t = this.adapter.publicKey) == null ? void 0 : t.toString();
  }
  getAddresses() {
    const t = this.getAddress();
    return t ? [t] : [];
  }
  setMainAddress() {
    throw new Error("Not supported");
  }
  getBalance() {
    throw new Error("Not supported");
  }
  async signTransaction(t) {
    if (!this.adapter.signTransaction || !this.adapter.signAllTransactions)
      throw new Error("Not supported");
    return Array.isArray(t) ? this.adapter.signAllTransactions(t) : this.adapter.signTransaction(t);
  }
  async sendTransaction(t) {
    var s;
    const { transaction: e } = t, i = Array.isArray(e) ? e : [e];
    if (i.length === 0)
      throw new Error("Empty transactions array");
    const n = [];
    for (const l of i) {
      const c = await this.adapter.sendTransaction(l, this.connection, {
        ...t.options
      });
      n.push(c);
    }
    return await this.connection.confirmTransaction(n[0], (s = t.options) == null ? void 0 : s.commitment), {
      id: n[0],
      data: n.length === 1 ? n[0] : n
    };
  }
  async signAndSendTransaction(t) {
    return this.sendTransaction(t);
  }
  signMessage(t) {
    if (!this.adapter.signMessage)
      throw new Error("Not supported");
    return this.adapter.signMessage(t);
  }
  getIcon() {
    return ht("icon", this.adapter);
  }
  getWalletState() {
    const t = this.adapter.readyState;
    if (!(t in lt))
      throw new Error(`Unknown wallet state ${t}`);
    return lt[t];
  }
  getFeatures() {
    const t = [
      V.SendTransaction,
      V.SignAndSendTransaction
    ];
    return this.adapter.signTransaction && this.adapter.signAllTransactions && t.push(V.SignTransaction), this.adapter.signMessage && t.push(V.SignMessage), t;
  }
  supportsChain(t) {
    return t === ot;
  }
}
var I = function(a, t, e, i, n) {
  if (i === "m") throw new TypeError("Private method is not writable");
  if (i === "a" && !n) throw new TypeError("Private accessor was defined without a setter");
  if (typeof t == "function" ? a !== t || !n : !t.has(a)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
  return i === "a" ? n.call(a, e) : n ? n.value = e : t.set(a, e), e;
}, r = function(a, t, e, i) {
  if (e === "a" && !i) throw new TypeError("Private accessor was defined without a getter");
  if (typeof t == "function" ? a !== t || !i : !t.has(a)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
  return e === "m" ? i : e === "a" ? i.call(a) : i ? i.value : t.get(a);
}, w, d, E, O, x, U, R, o, X, et, J, it, k, nt, dt, yt, jt, At;
class Me extends Lt {
  constructor({ wallet: t }) {
    super(), w.add(this), d.set(this, void 0), E.set(this, void 0), O.set(this, void 0), x.set(this, void 0), U.set(this, void 0), R.set(this, void 0), o.set(this, void 0), X.set(this, typeof window > "u" || typeof document > "u" ? M.Unsupported : M.Installed), nt.set(this, (e) => {
      if ("accounts" in e) {
        const i = r(this, o, "f").accounts[0];
        r(this, d, "f") && !r(this, x, "f") && i !== r(this, d, "f") && (i ? r(this, w, "m", J).call(this, i) : (this.emit("error", new st()), r(this, w, "m", it).call(this)));
      }
      "features" in e && r(this, w, "m", k).call(this);
    }), I(this, o, t, "f"), I(this, d, null, "f"), I(this, E, null, "f"), I(this, O, !1, "f"), I(this, x, !1, "f"), I(this, U, r(this, o, "f").features[xt].on("change", r(this, nt, "f")), "f"), r(this, w, "m", k).call(this);
  }
  get name() {
    return r(this, o, "f").name;
  }
  get url() {
    return "https://github.com/solana-labs/wallet-standard";
  }
  get icon() {
    return r(this, o, "f").icon;
  }
  get readyState() {
    return r(this, X, "f");
  }
  get publicKey() {
    return r(this, E, "f");
  }
  get connecting() {
    return r(this, O, "f");
  }
  get supportedTransactionVersions() {
    return r(this, R, "f");
  }
  get wallet() {
    return r(this, o, "f");
  }
  get standard() {
    return !0;
  }
  destroy() {
    I(this, d, null, "f"), I(this, E, null, "f"), I(this, O, !1, "f"), I(this, x, !1, "f");
    const t = r(this, U, "f");
    t && (I(this, U, null, "f"), t());
  }
  async autoConnect() {
    return r(this, w, "m", et).call(this, { silent: !0 });
  }
  async connect() {
    return r(this, w, "m", et).call(this);
  }
  async disconnect() {
    if (wt in r(this, o, "f").features)
      try {
        I(this, x, !0, "f"), await r(this, o, "f").features[wt].disconnect();
      } catch (t) {
        this.emit("error", new _(t == null ? void 0 : t.message, t));
      } finally {
        I(this, x, !1, "f");
      }
    r(this, w, "m", it).call(this);
  }
  async sendTransaction(t, e, i = {}) {
    try {
      const n = r(this, d, "f");
      if (!n)
        throw new g();
      let s;
      if (m in r(this, o, "f").features)
        if (n.features.includes(m))
          s = m;
        else if (N in r(this, o, "f").features && n.features.includes(N))
          s = N;
        else
          throw new y();
      else if (N in r(this, o, "f").features) {
        if (!n.features.includes(N))
          throw new y();
        s = N;
      } else
        throw new b();
      const l = ee(e.rpcEndpoint);
      if (!n.chains.includes(l))
        throw new f();
      try {
        const { signers: c, ...h } = i;
        let S;
        if (C(t) ? (c != null && c.length && t.sign(c), S = t.serialize()) : (t = await this.prepareTransaction(t, e, h), c != null && c.length && t.partialSign(...c), S = new Uint8Array(t.serialize({
          requireAllSignatures: !1,
          verifySignatures: !1
        }))), s === m) {
          const [j] = await r(this, o, "f").features[m].signAndSendTransaction({
            account: n,
            chain: l,
            transaction: S,
            options: {
              preflightCommitment: $(h.preflightCommitment || e.commitment),
              skipPreflight: h.skipPreflight,
              maxRetries: h.maxRetries,
              minContextSlot: h.minContextSlot
            }
          });
          return H.encode(j.signature);
        } else {
          const [j] = await r(this, o, "f").features[N].signTransaction({
            account: n,
            chain: l,
            transaction: S,
            options: {
              preflightCommitment: $(h.preflightCommitment || e.commitment),
              minContextSlot: h.minContextSlot
            }
          });
          return await e.sendRawTransaction(j.signedTransaction, {
            ...h,
            preflightCommitment: $(h.preflightCommitment || e.commitment)
          });
        }
      } catch (c) {
        throw c instanceof D ? c : new f(c == null ? void 0 : c.message, c);
      }
    } catch (n) {
      throw this.emit("error", n), n;
    }
  }
}
d = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), R = /* @__PURE__ */ new WeakMap(), o = /* @__PURE__ */ new WeakMap(), X = /* @__PURE__ */ new WeakMap(), nt = /* @__PURE__ */ new WeakMap(), w = /* @__PURE__ */ new WeakSet(), et = async function(t) {
  try {
    if (this.connected || this.connecting)
      return;
    if (r(this, X, "f") !== M.Installed)
      throw new L();
    if (I(this, O, !0, "f"), !r(this, o, "f").accounts.length)
      try {
        await r(this, o, "f").features[St].connect(t);
      } catch (i) {
        throw new K(i == null ? void 0 : i.message, i);
      }
    const e = r(this, o, "f").accounts[0];
    if (!e)
      throw new y();
    r(this, w, "m", J).call(this, e);
  } catch (e) {
    throw this.emit("error", e), e;
  } finally {
    I(this, O, !1, "f");
  }
}, J = function(t) {
  let e;
  try {
    e = new A(t.address);
  } catch (i) {
    throw new Z(i == null ? void 0 : i.message, i);
  }
  I(this, d, t, "f"), I(this, E, e, "f"), r(this, w, "m", k).call(this), this.emit("connect", e);
}, it = function() {
  I(this, d, null, "f"), I(this, E, null, "f"), r(this, w, "m", k).call(this), this.emit("disconnect");
}, k = function() {
  var e, i;
  const t = m in r(this, o, "f").features ? r(this, o, "f").features[m].supportedTransactionVersions : r(this, o, "f").features[N].supportedTransactionVersions;
  I(this, R, bt(t, ["legacy"]) ? null : new Set(t), "f"), N in r(this, o, "f").features && ((e = r(this, d, "f")) != null && e.features.includes(N)) ? (this.signTransaction = r(this, w, "m", dt), this.signAllTransactions = r(this, w, "m", yt)) : (delete this.signTransaction, delete this.signAllTransactions), W in r(this, o, "f").features && ((i = r(this, d, "f")) != null && i.features.includes(W)) ? this.signMessage = r(this, w, "m", jt) : delete this.signMessage, q in r(this, o, "f").features ? this.signIn = r(this, w, "m", At) : delete this.signIn;
}, dt = async function(t) {
  try {
    const e = r(this, d, "f");
    if (!e)
      throw new g();
    if (!(N in r(this, o, "f").features))
      throw new b();
    if (!e.features.includes(N))
      throw new y();
    try {
      const n = (await r(this, o, "f").features[N].signTransaction({
        account: e,
        transaction: C(t) ? t.serialize() : new Uint8Array(t.serialize({
          requireAllSignatures: !1,
          verifySignatures: !1
        }))
      }))[0].signedTransaction;
      return C(t) ? gt.deserialize(n) : It.from(n);
    } catch (i) {
      throw i instanceof D ? i : new u(i == null ? void 0 : i.message, i);
    }
  } catch (e) {
    throw this.emit("error", e), e;
  }
}, yt = async function(t) {
  try {
    const e = r(this, d, "f");
    if (!e)
      throw new g();
    if (!(N in r(this, o, "f").features))
      throw new b();
    if (!e.features.includes(N))
      throw new y();
    try {
      const i = await r(this, o, "f").features[N].signTransaction(...t.map((n) => ({
        account: e,
        transaction: C(n) ? n.serialize() : new Uint8Array(n.serialize({
          requireAllSignatures: !1,
          verifySignatures: !1
        }))
      })));
      return t.map((n, s) => {
        const l = i[s].signedTransaction;
        return C(n) ? gt.deserialize(l) : It.from(l);
      });
    } catch (i) {
      throw new u(i == null ? void 0 : i.message, i);
    }
  } catch (e) {
    throw this.emit("error", e), e;
  }
}, jt = async function(t) {
  try {
    const e = r(this, d, "f");
    if (!e)
      throw new g();
    if (!(W in r(this, o, "f").features))
      throw new b();
    if (!e.features.includes(W))
      throw new y();
    try {
      return (await r(this, o, "f").features[W].signMessage({
        account: e,
        message: t
      }))[0].signature;
    } catch (i) {
      throw new P(i == null ? void 0 : i.message, i);
    }
  } catch (e) {
    throw this.emit("error", e), e;
  }
}, At = async function(t = {}) {
  try {
    if (!(q in r(this, o, "f").features))
      throw new b();
    let e;
    try {
      [e] = await r(this, o, "f").features[q].signIn(t);
    } catch (i) {
      throw new Nt(i == null ? void 0 : i.message, i);
    }
    if (!e)
      throw new Nt();
    return r(this, w, "m", J).call(this, e.account), e;
  } catch (e) {
    throw this.emit("error", e), e;
  }
};
function oe(a) {
  return Yt().get().filter(Ut).map((t) => new z(new Me({ wallet: t }), a));
}
const le = (a) => a.getName().toLowerCase().replaceAll("wallet", "").trim();
function we() {
  const a = p.isMainnet ? "mainnet-beta" : "devnet", t = new zt(p.rpcs.Solana || Et(a));
  return {
    ...oe(t).reduce((e, i) => (e[le(i)] = i, e), {}),
    bitget: new z(new Gt(), t),
    clover: new z(new Pt(), t),
    coin98: new z(new vt(), t),
    solong: new z(new Ft(), t),
    torus: new z(new $t(), t),
    nightly: new z(new Ht(), t),
    ...p.ui.walletConnectProjectId ? {
      walletConnect: new z(
        new ne({
          network: p.isMainnet ? G.Mainnet : G.Devnet,
          options: {
            projectId: p.ui.walletConnectProjectId
          }
        }),
        t
      )
    } : {}
  };
}
async function De(a, t, e) {
  if (!t) throw new Error("Wallet not found");
  if (!p.rpcs.Solana) throw new Error("Solana RPC not found");
  const i = (e == null ? void 0 : e.commitment) ?? "finalized", n = a.transaction.transaction, s = new zt(p.rpcs.Solana), { blockhash: l, lastValidBlockHeight: c } = await s.getLatestBlockhash(i), h = (T) => T.programId.toString() !== "ComputeBudget111111111111111111111111111111";
  if (tt(n)) {
    const T = (await Promise.all(
      n.message.addressTableLookups.map(
        (Q) => s.getAddressLookupTable(Q.accountKey)
      )
    )).map((Q) => Q.value).filter((Q) => Q !== null), Y = Ot.decompile(n.message, {
      addressLookupTableAccounts: T
    });
    Y.recentBlockhash = l, n.message.recentBlockhash = l, Y.instructions = Y.instructions.filter(h), Y.instructions.push(
      ...await Tt(s, n)
    ), n.message = Y.compileToV0Message(T), n.sign(a.transaction.signers ?? []);
  } else
    n.recentBlockhash = l, n.lastValidBlockHeight = c, n.instructions = n.instructions.filter(
      h
    ), n.add(
      ...await Tt(s, n)
    ), a.transaction.signers && n.partialSign(...a.transaction.signers);
  let S = null, j = null, pt = 1, F = "";
  const rt = (await t.signTransaction(n)).serialize(), ct = {
    skipPreflight: !0,
    maxRetries: 0,
    preFlightCommitment: i
    // See PR and linked issue for why setting this matters: https://github.com/anza-xyz/agave/pull/483
  };
  F = await s.sendRawTransaction(rt, ct), S = s.confirmTransaction(
    {
      signature: F,
      blockhash: l,
      lastValidBlockHeight: c
    },
    i
  );
  const Mt = 5e3;
  for (; !j && (j = await Promise.race([
    S,
    new Promise(
      (T) => setTimeout(() => {
        T(null);
      }, Mt)
    )
  ]), !j); ) {
    console.log(
      `Tx not confirmed after ${Mt * pt++}ms, resending`
    );
    try {
      await s.sendRawTransaction(rt, ct);
    } catch (T) {
      console.error("Failed to resend transaction:", T);
    }
  }
  if (j.value.err)
    throw new Error(`Transaction failed: ${j.value.err}`);
  return F;
}
async function Tt(a, t, e) {
  if (tt(t) && !t.message.recentBlockhash) {
    const { blockhash: c } = await a.getLatestBlockhash(e);
    t.message.recentBlockhash = c;
  }
  let i = 2e5, n = 0;
  t: for (; n < 5; ) {
    n++;
    const c = await (tt(t) ? a.simulateTransaction(t, {
      commitment: e,
      replaceRecentBlockhash: !0
    }) : a.simulateTransaction(t));
    if (c.value.err) {
      if (c.value.logs) {
        for (const h of c.value.logs)
          if (h.includes("SlippageToleranceExceeded")) {
            console.info("Slippage failure during simulation. Trying again."), Zt(1e3);
            continue t;
          }
      }
      throw new Error(
        `Simulation failed: ${JSON.stringify(c.value.err)}
Logs:
${(c.value.logs || []).join(`
  `)}`
      );
    } else {
      c.value.unitsConsumed && (i = c.value.unitsConsumed);
      break;
    }
  }
  const s = [];
  s.push(
    ut.setComputeUnitLimit({
      // Set compute budget to 120% of the units used in the simulated transaction
      units: i * 1.2
    })
  );
  const l = await Qt(a, t, 0.95);
  return s.push(
    ut.setComputeUnitPrice({ microLamports: l })
  ), s;
}
export {
  we as fetchOptions,
  De as signAndSendTransaction
};
