const __vite__fileDeps=["assets/index-DgoFTdM0.js","main.js","main.css","assets/create-ADR5ok4y.js","assets/chain-C-Sfnq-q.js","assets/index-BieCvZm_.js"],__vite__mapDeps=i=>i.map(i=>__vite__fileDeps[i]);
var y=Object.defineProperty;var S=(a,t,n)=>t in a?y(a,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):a[t]=n;var r=(a,t,n)=>(S(a,typeof t!="symbol"?t+"":t,n),n);import{av as T,af as b,aw as x,ax as I,ay as g,az as N,a_ as E,aA as O,at as w,as as d,au as $,a$ as k,_ as A,aD as P}from"../main.js";import{C as R,P as B}from"./chain-C-Sfnq-q.js";const C="0x1::aptos_coin::AptosCoin",u="::";class v extends R{}const m="Aptos",F=a=>/^(0x)?[0-9a-fA-F]+::\w+::\w+$/.test(a),q=a=>a.split(u)[0],h=class h extends B{constructor(t,n){super(t,n??T(t,h._platform))}getRpc(t){if(t in this.config)return new b(this.config[t].rpc);throw new Error("No configuration available for chain: "+t)}getChain(t,n){if(t in this.config)return new v(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 x.tokenId(n,C)}static isNativeTokenId(t,n,i){return!this.isSupportedChain(n)||i.chain!==n?!1:this.nativeTokenId(t,n)==i}static isSupportedChain(t){return I(t)===h._platform}static async getDecimals(t,n,i){if(g(i))return N(h._platform);const s=i.toString(),c=`0x1::coin::CoinInfo<${s}>`;return(await n.getAccountResource(s.split(u)[0],c)).data.decimals}static async getBalance(t,n,i,s){const c=g(s)?C:s.toString(),e=new E(n);try{return await e.checkBalance(i,{coinType:c})}catch(o){if(o.errorCode==="resource_not_found"&&o.status===404)return null;throw o}}static async getBalances(t,n,i,s){return(await Promise.all(s.map(async e=>{const o=await this.getBalance(t,n,i,e);return{[g(e)?"native":new f(e).toString()]:o}}))).reduce((e,o)=>Object.assign(e,o),{})}static async sendWait(t,n,i){const s=[];for(const c of i){const e=await n.submitTransaction(c),o=await n.waitForTransactionWithResult(e.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=O(h._platform,BigInt(t));if(!n)throw new Error(`No matching chainId to determine network and chain: ${t}`);const[i,s]=n;return[i,s]}static async chainFromRpc(t){const i=await t.getChainId();return this.chainFromChainId(i.toString())}};r(h,"_platform",m);let l=h;function D(a){return a.length%2!==0||a.length<66?(a=a.startsWith("0x")?a.slice(2):a,"0x"+a.padStart(64,"0")):a}const p=class p{constructor(t){r(this,"platform",l._platform);r(this,"type","Native");r(this,"address");r(this,"module");if(p.instanceof(t))this.address=t.address,this.module=t.module;else if(w.instanceof(t))this.address=t.toUint8Array();else if(typeof t=="string"){if(F(t)){const n=t.split(u);this.module=n.slice(1).join(u),t=n[0]}if(t=D(t),!d.valid(t))throw new Error("Invalid Aptos address: "+t);this.address=d.decode(t)}else this.address=t}unwrap(){const t=d.encode(this.address).replace(/^0+/,""),n=this.module?u+this.module:"";return`0x${t}${n}`}toString(){return this.unwrap()}toNative(){return this}toUint8Array(){return this.address}toUniversalAddress(){return new w(this.toUint8Array())}static instanceof(t){return t.platform===l._platform}equals(t){return p.instanceof(t)?t.unwrap()===this.unwrap():this.toUniversalAddress().equals(t)}};r(p,"byteSize",32);let f=p;$(m,f);async function L(a,t){const[n,i]=await l.chainFromRpc(a);return new U(i,new k(d.decode(t)),a)}class U{constructor(t,n,i,s){r(this,"_chain");r(this,"_account");r(this,"_rpc");r(this,"_debug");this._chain=t,this._account=n,this._rpc=i,this._debug=s}chain(){return this._chain}address(){return this._account.address().hex()}async signAndSend(t){const n=[];for(const i of t){const{description:s,transaction:c}=i;this._debug&&console.log(`Signing: ${s} for ${this.address()}`);const e={gas_unit_price:"100",max_gas_amount:"30000",expiration_timestamp_secs:(BigInt(Date.now()+8*60*60*1e3)/1000n).toString()},o=await this._rpc.generateTransaction(this._account.address(),c,e),{hash:_}=await this._simSignSend(o);n.push(_)}return n}async _simSignSend(t){return await this._rpc.simulateTransaction(this._account,t).then(n=>n.forEach(i=>{if(!i.success)throw new Error(`Transaction failed: ${i.vm_status}
${JSON.stringify(i,null,2)}`)})),this._rpc.signTransaction(this._account,t).then(n=>this._rpc.submitTransaction(n)).then(n=>this._rpc.waitForTransactionWithResult(n.hash))}}const W={Address:f,Platform:l,getSigner:L,protocols:{WormholeCore:()=>A(()=>import("./index-DgoFTdM0.js"),__vite__mapDeps([0,1,2,3,4])),TokenBridge:()=>A(()=>import("./index-BieCvZm_.js"),__vite__mapDeps([5,1,2,4]))},getChain:(a,t,n)=>new v(t,new l(a,P(a,m,{[t]:n})))},M=Object.freeze(Object.defineProperty({__proto__:null,default:W},Symbol.toStringTag,{value:"Module"}));export{l as A,u as a,C as b,q as c,f as d,M as e,F as i};
