const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DpE68DZK.js","main.js","main.css","assets/create-DVH68Enz.js","assets/chain-CD0L3DEi.js","assets/chunk-KJH4KKG6-BBmtrtLw.js","assets/index-CRyep_1R.js","assets/index-VWaDGczM.js","assets/index-DdyOGjTL.js","assets/unsignedTransaction-DsxtoHjl.js","assets/index-D065KnY9.js"])))=>i.map(i=>d[i]);
var w=Object.defineProperty;var y=(e,t,a)=>t in e?w(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a;var h=(e,t,a)=>y(e,typeof t!="symbol"?t+"":t,a);import{ak as C,aZ as f,am as b,ao as v,a_ as d,m as S,aq as g,ar as T,at as A,aY as E,_ as p,a$ as I,aw as k}from"../main.js";import{C as N}from"./chain-CD0L3DEi.js";import{e as _,u as x,W as B,v as F,z as P}from"./chunk-KJH4KKG6-BBmtrtLw.js";class m extends N{}const c=class c extends C{constructor(t,a){super(t,a??b(t,c._platform))}getRpc(t){if(t in this.config){const a=this.network==="Mainnet"?_.MAINNET:_.TESTNET,n=new x({fullnode:this.config[t].rpc,network:a});return new B(n)}throw new Error("No configuration available for chain: "+t)}getChain(t,a){if(t in this.config)return new m(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 v.tokenId(a,d)}static isNativeTokenId(t,a,n){return!this.isSupportedChain(a)||n.chain!==a?!1:this.nativeTokenId(t,a)==n}static isSupportedChain(t){return S(t)===c._platform}static async getDecimals(t,a,n,s){if(g(s)||s===d)return T(c._platform);const i=s.toString();return(await n.getFungibleAssetMetadataByAssetType({assetType:i})).decimals}static async getBalance(t,a,n,s,i){var r;const o=g(i)?d:i.toString();try{return((r=(await n.getCurrentFungibleAssetBalances({options:{where:{owner_address:{_eq:s},asset_type:{_eq:o}}}}))[0])==null?void 0:r.amount)??null}catch(u){if(u.status===404)return null;throw u}}static async getBalances(t,a,n,s){try{const i=await n.getCurrentFungibleAssetBalances({options:{where:{owner_address:{_eq:s}}}});let o={};for(const r of i)if(r.asset_type){let u=r.asset_type==="0x1::aptos_coin::AptosCoin"?"native":r.asset_type;o[u]=r.amount}return o}catch(i){if(i.status===404)return{};throw i}}static async sendWait(t,a,n){const s=[];for(const i of n){const o=await a.transaction.submit.simple(i.transaction),r=await a.waitForTransaction({transactionHash:o.hash});s.push(r.hash)}return s}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=A(c._platform,BigInt(t));if(!a)throw new Error(`No matching chainId to determine network and chain: ${t}`);const[n,s]=a;return[n,s]}static async chainFromRpc(t){const a=await t.getLedgerInfo();return this.chainFromChainId(a.chain_id.toString())}};h(c,"_platform",f);let l=c;async function O(e,t){const[a,n]=await l.chainFromRpc(e),s=F.fromPrivateKey({privateKey:new P(E.decode(t))});return new L(n,s,e)}class L{constructor(t,a,n,s){h(this,"_chain");h(this,"_account");h(this,"_rpc");h(this,"_debug");this._chain=t,this._account=a,this._rpc=n,this._debug=s}chain(){return this._chain}address(){return this._account.accountAddress.toString()}async signAndSend(t){const a=[];for(const n of t){const{description:s,transaction:i}=n;this._debug&&console.log(`Signing: ${s} for ${this.address()}`);const o=await this._rpc.transaction.build.simple({sender:this._account.accountAddress,data:i}),{hash:r}=await this._simSignSend(o);a.push(r)}return a}async _simSignSend(t){return await this._rpc.transaction.simulate.simple({signerPublicKey:this._account.publicKey,transaction:t}).then(a=>a.forEach(n=>{if(!n.success)throw new Error(`Transaction failed: ${n.vm_status}
${JSON.stringify(n,null,2)}`)})),this._rpc.signAndSubmitTransaction({signer:this._account,transaction:t}).then(a=>this._rpc.waitForTransaction({transactionHash:a.hash}))}}const $={Address:I,Platform:l,getSigner:O,protocols:{WormholeCore:()=>p(()=>import("./index-DpE68DZK.js"),__vite__mapDeps([0,1,2,3,4,5,6,7])),TokenBridge:()=>p(()=>import("./index-DdyOGjTL.js"),__vite__mapDeps([8,1,2,9,4,5,6,7])),CircleBridge:()=>p(()=>import("./index-D065KnY9.js"),__vite__mapDeps([10,5,1,2,6,7,9,4]))},getChain:(e,t,a)=>new m(t,new l(e,k(e,f,{[t]:a})))},K=Object.freeze(Object.defineProperty({__proto__:null,default:$},Symbol.toStringTag,{value:"Module"}));export{l as A,K as a};
