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