"use strict";var p=Object.defineProperty;var m=(h,t,e)=>t in h?p(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e;var w=(h,t,e)=>m(h,typeof t!="symbol"?t+"":t,e);const u=require("./chunk-KJH4KKG6-B9iq51o1.js"),i=require("./address-XxuWo72f.js"),C=require("./chain-CSpjwyBt.js"),f=require("./address-BWzhA9di.js");class g extends C.ChainContext{}const c=class c extends i.PlatformContext{constructor(t,e){super(t,e??i.networkPlatformConfigs(t,c._platform))}getRpc(t){if(t in this.config){const e=this.network==="Mainnet"?u.e.MAINNET:u.e.TESTNET,a=new u.u({fullnode:this.config[t].rpc,network:e});return new u.W(a)}throw new Error("No configuration available for chain: "+t)}getChain(t,e){if(t in this.config)return new g(t,this);throw new Error("No configuration available for chain: "+t)}static nativeTokenId(t,e){if(!this.isSupportedChain(e))throw new Error(`invalid chain: ${e}`);return i.Wormhole.tokenId(e,f.APTOS_COIN)}static isNativeTokenId(t,e,a){return!this.isSupportedChain(e)||a.chain!==e?!1:this.nativeTokenId(t,e)==a}static isSupportedChain(t){return i.chainToPlatform(t)===c._platform}static async getDecimals(t,e,a,n){if(i.isNative(n)||n===f.APTOS_COIN)return i.nativeDecimals(c._platform);const s=n.toString();return(await a.getFungibleAssetMetadataByAssetType({assetType:s})).decimals}static async getBalance(t,e,a,n,s){var r;const o=i.isNative(s)?f.APTOS_COIN:s.toString();try{return((r=(await a.getCurrentFungibleAssetBalances({options:{where:{owner_address:{_eq:n},asset_type:{_eq:o}}}}))[0])==null?void 0:r.amount)??null}catch(l){if(l.status===404)return null;throw l}}static async getBalances(t,e,a,n){try{const s=await a.getCurrentFungibleAssetBalances({options:{where:{owner_address:{_eq:n}}}});let o={};for(const r of s)if(r.asset_type){let l=r.asset_type==="0x1::aptos_coin::AptosCoin"?"native":r.asset_type;o[l]=r.amount}return o}catch(s){if(s.status===404)return{};throw s}}static async sendWait(t,e,a){const n=[];for(const s of a){const o=await e.transaction.submit.simple(s.transaction),r=await e.waitForTransaction({transactionHash:o.hash});n.push(r.hash)}return n}static async getLatestBlock(t){const e=await t.getLedgerInfo();return Number(e.block_height)}static async getLatestFinalizedBlock(t){const e=await t.getLedgerInfo();return Number(e.block_height)}static chainFromChainId(t){const e=i.platformNativeChainIdToNetworkChain(c._platform,BigInt(t));if(!e)throw new Error(`No matching chainId to determine network and chain: ${t}`);const[a,n]=e;return[a,n]}static async chainFromRpc(t){const e=await t.getLedgerInfo();return this.chainFromChainId(e.chain_id.toString())}};w(c,"_platform",f._platform);let d=c;exports.AptosChain=g;exports.AptosPlatform=d;
