"use strict";const h=require("./chunk-KJH4KKG6-BbF5W1_N.js"),s=require("./platform-CCG_jgOO.js"),l=require("./address-W9jn6Qdk.js");class u extends s.ChainContext{}class c extends s.PlatformContext{static _platform=l._platform;constructor(t,a){super(t,a??s.networkPlatformConfigs(t,c._platform))}getRpc(t){if(t in this.config){const a=this.network==="Mainnet"?h.e.MAINNET:h.e.TESTNET,e=new h.u({fullnode:this.config[t].rpc,network:a});return new h.W(e)}throw new Error("No configuration available for chain: "+t)}getChain(t,a){if(t in this.config)return new u(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 s.Wormhole.tokenId(a,l.APTOS_COIN)}static isNativeTokenId(t,a,e){return!this.isSupportedChain(a)||e.chain!==a?!1:this.nativeTokenId(t,a)==e}static isSupportedChain(t){return s.chainToPlatform(t)===c._platform}static async getDecimals(t,a,e,n){if(s.isNative(n)||n===l.APTOS_COIN)return s.nativeDecimals(c._platform);const i=n.toString();return(await e.getFungibleAssetMetadataByAssetType({assetType:i})).decimals}static async getBalance(t,a,e,n,i){const o=s.isNative(i)?l.APTOS_COIN:i.toString();try{return(await e.getCurrentFungibleAssetBalances({options:{where:{owner_address:{_eq:n},asset_type:{_eq:o}}}}))[0]?.amount??null}catch(r){if(r.status===404)return null;throw r}}static async getBalances(t,a,e,n){try{const i=await e.getCurrentFungibleAssetBalances({options:{where:{owner_address:{_eq:n}}}});let o={};for(const r of i)if(r.asset_type){let f=r.asset_type==="0x1::aptos_coin::AptosCoin"?"native":r.asset_type;o[f]=r.amount}return o}catch(i){if(i.status===404)return{};throw i}}static async sendWait(t,a,e){const n=[];for(const i of e){const o=await a.transaction.submit.simple(i.transaction),r=await a.waitForTransaction({transactionHash:o.hash});n.push(r.hash)}return n}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=s.platformNativeChainIdToNetworkChain(c._platform,BigInt(t));if(!a)throw new Error(`No matching chainId to determine network and chain: ${t}`);const[e,n]=a;return[e,n]}static async chainFromRpc(t){const a=await t.getLedgerInfo();return this.chainFromChainId(a.chain_id.toString())}}exports.AptosChain=u;exports.AptosPlatform=c;
