var g = Object.defineProperty;
var m = (c, t, a) => t in c ? g(c, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : c[t] = a;
var l = (c, t, a) => m(c, typeof t != "symbol" ? t + "" : t, a);
import { e as f, s as w, t as C } from "./chunk-IMTC3J2M-DKLPKqnP.mjs";
import { bs as y, W as _, a5 as b, k as u, bu as T, bv as v } from "./address-CBux52Na.mjs";
import { C as N, P as k } from "./chain-sKZNJgPZ.mjs";
import { _ as I, a as h } from "./address-BWXkejmE.mjs";
class x extends N {
}
const o = class o extends k {
  constructor(t, a) {
    super(t, a ?? y(t, o._platform));
  }
  getRpc(t) {
    if (t in this.config) {
      const a = this.network === "Mainnet" ? f.MAINNET : f.TESTNET, n = new w({ 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, h);
  }
  static isNativeTokenId(t, a, n) {
    return !this.isSupportedChain(a) || n.chain !== a ? !1 : this.nativeTokenId(t, a) == n;
  }
  static isSupportedChain(t) {
    return b(t) === o._platform;
  }
  static async getDecimals(t, a, n) {
    if (u(n) || n === h)
      return T(o._platform);
    const e = n.toString();
    return (await a.getFungibleAssetMetadataByAssetType({ assetType: e })).decimals;
  }
  static async getBalance(t, a, n, e) {
    var r;
    const i = u(e) ? h : e.toString();
    try {
      return ((r = (await a.getCurrentFungibleAssetBalances({
        options: {
          where: {
            owner_address: { _eq: n },
            asset_type: { _eq: i }
          }
        }
      }))[0]) == null ? void 0 : r.amount) ?? null;
    } catch (s) {
      if (s.status === 404)
        return null;
      throw s;
    }
  }
  static async getBalances(t, a, n, e) {
    try {
      const i = await a.getCurrentFungibleAssetBalances({
        options: {
          where: {
            owner_address: { _eq: n }
          }
        }
      });
      let r = {};
      for (const s of i)
        if (s.asset_type) {
          let d = s.asset_type === "0x1::aptos_coin::AptosCoin" ? "native" : s.asset_type;
          r[d] = s.amount;
        }
      return r;
    } catch (i) {
      if (i.status === 404)
        return {};
      throw i;
    }
  }
  static async sendWait(t, a, n) {
    const e = [];
    for (const i of n) {
      const r = await a.transaction.submit.simple(i.transaction), s = await a.waitForTransaction({
        transactionHash: r.hash
      });
      e.push(s.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 = v(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());
  }
};
l(o, "_platform", I);
let p = o;
export {
  p as A,
  x as a
};
