"use strict";var f=Object.defineProperty;var p=(i,t,n)=>t in i?f(i,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[t]=n;var l=(i,t,n)=>p(i,typeof t!="symbol"?t+"":t,n);const a=require("./index-BLlpWXP6.js"),u=require("./chunk-IMTC3J2M-DATbOiv9.js");class g extends a.ChainContext{}const h=class h extends a.PlatformContext{constructor(t,n){super(t,n??a.networkPlatformConfigs(t,h._platform))}getRpc(t){if(t in this.config){const n=this.network==="Mainnet"?u.e.MAINNET:u.e.TESTNET,e=new u.s({fullnode:this.config[t].rpc,network:n});return new u.t(e)}throw new Error("No configuration available for chain: "+t)}getChain(t,n){if(t in this.config)return new g(t,this);throw new Error("No configuration available for chain: "+t)}static nativeTokenId(t,n){if(!this.isSupportedChain(n))throw new Error(`invalid chain: ${n}`);return a.Wormhole.tokenId(n,a.APTOS_COIN)}static isNativeTokenId(t,n,e){return!this.isSupportedChain(n)||e.chain!==n?!1:this.nativeTokenId(t,n)==e}static isSupportedChain(t){return a.chainToPlatform(t)===h._platform}static async getDecimals(t,n,e){if(a.isNative(e)||e===a.APTOS_COIN)return a.nativeDecimals(h._platform);const s=e.toString();return(await n.getFungibleAssetMetadataByAssetType({assetType:s})).decimals}static async getBalance(t,n,e,s){var r;const c=a.isNative(s)?a.APTOS_COIN:s.toString();try{return((r=(await n.getCurrentFungibleAssetBalances({options:{where:{owner_address:{_eq:e},asset_type:{_eq:c}}}}))[0])==null?void 0:r.amount)??null}catch(o){if(o.status===404)return null;throw o}}static async getBalances(t,n,e,s){return(await Promise.all(s.map(async r=>{const o=await this.getBalance(t,n,e,r);return{[a.isNative(r)?"native":new a.AptosAddress(r).toString()]:o}}))).reduce((r,o)=>Object.assign(r,o),{})}static async sendWait(t,n,e){const s=[];for(const c of e){const r=await n.transaction.submit.simple(c.transaction),o=await n.waitForTransaction({transactionHash:r.hash});s.push(o.hash)}return s}static async getLatestBlock(t){const n=await t.getLedgerInfo();return Number(n.block_height)}static async getLatestFinalizedBlock(t){const n=await t.getLedgerInfo();return Number(n.block_height)}static chainFromChainId(t){const n=a.platformNativeChainIdToNetworkChain(h._platform,BigInt(t));if(!n)throw new Error(`No matching chainId to determine network and chain: ${t}`);const[e,s]=n;return[e,s]}static async chainFromRpc(t){const n=await t.getLedgerInfo();return this.chainFromChainId(n.chain_id.toString())}};l(h,"_platform",a._platform$2);let d=h;async function m(i,t){const[n,e]=await d.chainFromRpc(i),s=u.o.fromPrivateKey({privateKey:new u.z(a.hex.decode(t))});return new w(e,s,i)}class w{constructor(t,n,e,s){l(this,"_chain");l(this,"_account");l(this,"_rpc");l(this,"_debug");this._chain=t,this._account=n,this._rpc=e,this._debug=s}chain(){return this._chain}address(){return this._account.accountAddress.toString()}async signAndSend(t){const n=[];for(const e of t){const{description:s,transaction:c}=e;this._debug&&console.log(`Signing: ${s} for ${this.address()}`);const r=await this._rpc.transaction.build.simple({sender:this._account.accountAddress,data:c}),{hash:o}=await this._simSignSend(r);n.push(o)}return n}async _simSignSend(t){return await this._rpc.transaction.simulate.simple({signerPublicKey:this._account.publicKey,transaction:t}).then(n=>n.forEach(e=>{if(!e.success)throw new Error(`Transaction failed: ${e.vm_status}
${JSON.stringify(e,null,2)}`)})),this._rpc.signAndSubmitTransaction({signer:this._account,transaction:t}).then(n=>this._rpc.waitForTransaction({transactionHash:n.hash}))}}const _={Address:a.AptosAddress,Platform:d,getSigner:m,protocols:{WormholeCore:()=>Promise.resolve().then(()=>require("./index-BTF-tAOp.js")),TokenBridge:()=>Promise.resolve().then(()=>require("./index-B63Rp6mZ.js")),CircleBridge:()=>Promise.resolve().then(()=>require("./index-je5coaxE.js"))},getChain:(i,t,n)=>new g(t,new d(i,a.applyChainsConfigConfigOverrides(i,a._platform$2,{[t]:n})))},y=Object.freeze(Object.defineProperty({__proto__:null,default:_},Symbol.toStringTag,{value:"Module"}));exports.AptosPlatform=d;exports.aptos=y;
