import { ae as i, ar as T, au as A, aG as d, d as p } from "./address-CBux52Na.mjs";
import { b as k, p as r, u as f } from "./web3-B3Usc-Qj.mjs";
const c = new i("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"), S = new i("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"), I = new i("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"), D = new i("So11111111111111111111111111111111111111112");
new i("9pan9bMn5HatX4EJdBwg9VgCa7Uz5HL8N1m5D3NdXejP");
class a extends Error {
  constructor(e) {
    super(e);
  }
}
class E extends a {
  constructor() {
    super(...arguments), this.name = "TokenAccountNotFoundError";
  }
}
class x extends a {
  constructor() {
    super(...arguments), this.name = "TokenInvalidAccountError";
  }
}
class v extends a {
  constructor() {
    super(...arguments), this.name = "TokenInvalidAccountOwnerError";
  }
}
class l extends a {
  constructor() {
    super(...arguments), this.name = "TokenInvalidAccountSizeError";
  }
}
class B extends a {
  constructor() {
    super(...arguments), this.name = "TokenInvalidMintError";
  }
}
class O extends a {
  constructor() {
    super(...arguments), this.name = "TokenOwnerOffCurveError";
  }
}
class H extends a {
  constructor() {
    super(...arguments), this.name = "TokenTransferHookAccountNotFound";
  }
}
class L extends a {
  constructor() {
    super(...arguments), this.name = "TokenTransferHookInvalidSeed";
  }
}
class U extends a {
  constructor() {
    super(...arguments), this.name = "TokenTransferHookAccountDataNotFound";
  }
}
var g;
(function(t) {
  t[t.Uninitialized = 0] = "Uninitialized", t[t.Mint = 1] = "Mint", t[t.Account = 2] = "Account";
})(g || (g = {}));
const N = 1, P = T([
  A("m"),
  A("n"),
  k("isInitialized"),
  r("signer1"),
  r("signer2"),
  r("signer3"),
  r("signer4"),
  r("signer5"),
  r("signer6"),
  r("signer7"),
  r("signer8"),
  r("signer9"),
  r("signer10"),
  r("signer11")
]), y = P.span;
var h;
(function(t) {
  t[t.Uninitialized = 0] = "Uninitialized", t[t.Initialized = 1] = "Initialized", t[t.Frozen = 2] = "Frozen";
})(h || (h = {}));
const z = T([
  r("mint"),
  r("owner"),
  f("amount"),
  d("delegateOption"),
  r("delegate"),
  A("state"),
  d("isNativeOption"),
  f("isNative"),
  f("delegatedAmount"),
  d("closeAuthorityOption"),
  r("closeAuthority")
]), u = z.span;
async function G(t, e, s, n = c) {
  const o = await t.getAccountInfo(e, s);
  return _(e, o, n);
}
function _(t, e, s = c) {
  if (!e)
    throw new E();
  if (!e.owner.equals(s))
    throw new v();
  if (e.data.length < u)
    throw new l();
  const n = z.decode(e.data.slice(0, u));
  let o = p.Buffer.alloc(0);
  if (e.data.length > u) {
    if (e.data.length === y)
      throw new l();
    if (e.data[u] != g.Account)
      throw new x();
    o = e.data.slice(u + N);
  }
  return {
    address: t,
    mint: n.mint,
    owner: n.owner,
    amount: n.amount,
    delegate: n.delegateOption ? n.delegate : null,
    delegatedAmount: n.delegatedAmount,
    isInitialized: n.state !== h.Uninitialized,
    isFrozen: n.state === h.Frozen,
    isNative: !!n.isNativeOption,
    rentExemptReserve: n.isNativeOption ? n.isNative : null,
    closeAuthority: n.closeAuthorityOption ? n.closeAuthority : null,
    tlvData: o
  };
}
const M = T([
  d("mintAuthorityOption"),
  r("mintAuthority"),
  f("supply"),
  A("decimals"),
  k("isInitialized"),
  d("freezeAuthorityOption"),
  r("freezeAuthority")
]), m = M.span;
async function R(t, e, s, n = c) {
  const o = await t.getAccountInfo(e, s);
  return b(e, o, n);
}
function b(t, e, s = c) {
  if (!e)
    throw new E();
  if (!e.owner.equals(s))
    throw new v();
  if (e.data.length < m)
    throw new l();
  const n = M.decode(e.data.slice(0, m));
  let o = p.Buffer.alloc(0);
  if (e.data.length > m) {
    if (e.data.length <= u)
      throw new l();
    if (e.data.length === y)
      throw new l();
    if (e.data[u] != g.Mint)
      throw new B();
    o = e.data.slice(u + N);
  }
  return {
    address: t,
    mintAuthority: n.mintAuthorityOption ? n.mintAuthority : null,
    supply: n.supply,
    decimals: n.decimals,
    isInitialized: n.isInitialized,
    freezeAuthority: n.freezeAuthorityOption ? n.freezeAuthority : null,
    tlvData: o
  };
}
async function K(t, e, s = !1, n = c, o = I) {
  if (!s && !i.isOnCurve(e.toBuffer()))
    throw new O();
  const [w] = await i.findProgramAddress([e.toBuffer(), n.toBuffer(), t.toBuffer()], o);
  return w;
}
function Z(t, e, s = !1, n = c, o = I) {
  if (!s && !i.isOnCurve(e.toBuffer()))
    throw new O();
  const [w] = i.findProgramAddressSync([e.toBuffer(), n.toBuffer(), t.toBuffer()], o);
  return w;
}
export {
  I as A,
  D as N,
  c as T,
  S as a,
  Z as b,
  L as c,
  U as d,
  H as e,
  R as f,
  G as g,
  K as h
};
