var w = Object.defineProperty;
var g = (c, t, a) => t in c ? w(c, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : c[t] = a;
var f = (c, t, a) => g(c, typeof t != "symbol" ? t + "" : t, a);
import { e as u, u as m, W as C } from "./chunk-KJH4KKG6-qC3BvugF.mjs";
import { bM as y, bN as b, W as _, n as T, m as p, bP as N, bQ as k } from "./address-QpeLv2yn.mjs";
import { C as v } from "./chain-B7MIR9_r.mjs";
import { _ as I, e as l } from "./address-BJhcbdG9.mjs";
class x extends v {
}
const o = class o extends y {
  constructor(t, a) {
    super(t, a ?? b(t, o._platform));
  }
  getRpc(t) {
    if (t in this.config) {
      const a = this.network === "Mainnet" ? u.MAINNET : u.TESTNET, n = new m({ fullnode: this.config[t].rpc, network: a });
      return new C(n);
    }
    throw new Error("No configuration available for chain: " + t);
  }
  getChain(t, a) {
    if (t in this.config)
      return new x(t, this);
    throw new Error("No configuration available for chain: " + t);
  }
  static nativeTokenId(t, a) {
    if (!this.isSupportedChain(a))
      throw new Error(`invalid chain: ${a}`);
    return _.tokenId(a, l);
  }
  static isNativeTokenId(t, a, n) {
    return !this.isSupportedChain(a) || n.chain !== a ? !1 : this.nativeTokenId(t, a) == n;
  }
  static isSupportedChain(t) {
    return T(t) === o._platform;
  }
  static async getDecimals(t, a, n, e) {
    if (p(e) || e === l)
      return N(o._platform);
    const s = e.toString();
    return (await n.getFungibleAssetMetadataByAssetType({ assetType: s })).decimals;
  }
  static async getBalance(t, a, n, e, s) {
    var r;
    const i = p(s) ? l : s.toString();
    try {
      return ((r = (await n.getCurrentFungibleAssetBalances({
        options: {
          where: {
            owner_address: { _eq: e },
            asset_type: { _eq: i }
          }
        }
      }))[0]) == null ? void 0 : r.amount) ?? null;
    } catch (h) {
      if (h.status === 404)
        return null;
      throw h;
    }
  }
  static async getBalances(t, a, n, e) {
    try {
      const s = await n.getCurrentFungibleAssetBalances({
        options: {
          where: {
            owner_address: { _eq: e }
          }
        }
      });
      let i = {};
      for (const r of s)
        if (r.asset_type) {
          let h = r.asset_type === "0x1::aptos_coin::AptosCoin" ? "native" : r.asset_type;
          i[h] = r.amount;
        }
      return i;
    } catch (s) {
      if (s.status === 404)
        return {};
      throw s;
    }
  }
  static async sendWait(t, a, n) {
    const e = [];
    for (const s of n) {
      const i = await a.transaction.submit.simple(s.transaction), r = await a.waitForTransaction({
        transactionHash: i.hash
      });
      e.push(r.hash);
    }
    return e;
  }
  static async getLatestBlock(t) {
    const a = await t.getLedgerInfo();
    return Number(a.block_height);
  }
  static async getLatestFinalizedBlock(t) {
    const a = await t.getLedgerInfo();
    return Number(a.block_height);
  }
  static chainFromChainId(t) {
    const a = k(o._platform, BigInt(t));
    if (!a)
      throw new Error(`No matching chainId to determine network and chain: ${t}`);
    const [n, e] = a;
    return [n, e];
  }
  static async chainFromRpc(t) {
    const a = await t.getLedgerInfo();
    return this.chainFromChainId(a.chain_id.toString());
  }
};
f(o, "_platform", I);
let d = o;
export {
  d as A,
  x as a
};
