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