const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-z2SBICrL.js","main.js","main.css","assets/chunk-IMTC3J2M-DIjpRZZk.js","assets/index-WlpSU6Q6.js","assets/base64-IWuz5NCL.js","assets/index-DnDUIJZk.js","assets/unsignedTransaction-DsxtoHjl.js","assets/index-ndTMsj-g.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{ag as b,ah as S,ai as f,aj as C,ak as T,al as u,am as v,an as d,ao as A,ap as _,aq as E,af as I,_ as g,a3 as N}from"../main.js";import{e as p,s as P,x,M as B,z as O}from"./chunk-IMTC3J2M-DIjpRZZk.js";class m extends b{}const c=class c extends S{constructor(t,a){super(t,a??C(t,c._platform))}getRpc(t){if(t in this.config){const a=this.network==="Mainnet"?p.MAINNET:p.TESTNET,n=new P({fullnode:this.config[t].rpc,network:a});return new x(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 T.tokenId(a,u)}static isNativeTokenId(t,a,n){return!this.isSupportedChain(a)||n.chain!==a?!1:this.nativeTokenId(t,a)==n}static isSupportedChain(t){return v(t)===c._platform}static async getDecimals(t,a,n){if(d(n)||n===u)return A(c._platform);const s=n.toString();return(await a.getFungibleAssetMetadataByAssetType({assetType:s})).decimals}static async getBalance(t,a,n,s){var i;const o=d(s)?u:s.toString();try{return((i=(await a.getCurrentFungibleAssetBalances({options:{where:{owner_address:{_eq:n},asset_type:{_eq:o}}}}))[0])==null?void 0:i.amount)??null}catch(r){if(r.status===404)return null;throw r}}static async getBalances(t,a,n,s){return(await Promise.all(s.map(async i=>{const r=await this.getBalance(t,a,n,i);return{[d(i)?"native":new _(i).toString()]:r}}))).reduce((i,r)=>Object.assign(i,r),{})}static async sendWait(t,a,n){const s=[];for(const o of n){const i=await a.transaction.submit.simple(o.transaction),r=await a.waitForTransaction({transactionHash:i.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=E(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 k(e,t){const[a,n]=await l.chainFromRpc(e),s=B.fromPrivateKey({privateKey:new O(I.decode(t))});return new F(n,s,e)}class F{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:o}=n;this._debug&&console.log(`Signing: ${s} for ${this.address()}`);const i=await this._rpc.transaction.build.simple({sender:this._account.accountAddress,data:o}),{hash:r}=await this._simSignSend(i);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 L={Address:_,Platform:l,getSigner:k,protocols:{WormholeCore:()=>g(()=>import("./index-z2SBICrL.js"),__vite__mapDeps([0,1,2,3,4,5])),TokenBridge:()=>g(()=>import("./index-DnDUIJZk.js"),__vite__mapDeps([6,1,2,7,3,4,5])),CircleBridge:()=>g(()=>import("./index-ndTMsj-g.js"),__vite__mapDeps([8,3,1,2,4,5,7]))},getChain:(e,t,a)=>new m(t,new l(e,N(e,f,{[t]:a})))},j=Object.freeze(Object.defineProperty({__proto__:null,default:L},Symbol.toStringTag,{value:"Module"}));export{l as A,j as a};
