const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-AaqmNOLf.js","main.js","main.css","assets/chunk-OR6GFWLG-BZrmB1_W.js","assets/index-BFMIYSUy.js","assets/base64-IWuz5NCL.js","assets/index-rryJGGTI.js","assets/unsignedTransaction-DsxtoHjl.js","assets/index-BLpnEfNA.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{ae as b,af as S,ag as p,ah as C,ai as T,aj as d,ak as A,al as l,am as v,an as _,ao as E,ab as I,_ as g,a1 as N}from"../main.js";import{e as f,q as P,A as B,M as O,z as k}from"./chunk-OR6GFWLG-BZrmB1_W.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"?f.MAINNET:f.TESTNET,n=new P({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 T.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 A(t)===c._platform}static async getDecimals(t,a,n){if(l(n)||n===d)return v(c._platform);const s=n.toString();return(await a.getFungibleAssetMetadataByAssetType({assetType:s})).decimals}static async getBalance(t,a,n,s){var i;const o=l(s)?d: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{[l(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",p);let u=c;async function x(e,t){const[a,n]=await u.chainFromRpc(e),s=O.fromPrivateKey({privateKey:new k(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:u,getSigner:x,protocols:{WormholeCore:()=>g(()=>import("./index-AaqmNOLf.js"),__vite__mapDeps([0,1,2,3,4,5])),TokenBridge:()=>g(()=>import("./index-rryJGGTI.js"),__vite__mapDeps([6,1,2,7,3,4,5])),CircleBridge:()=>g(()=>import("./index-BLpnEfNA.js"),__vite__mapDeps([8,3,1,2,4,5,7]))},getChain:(e,t,a)=>new m(t,new u(e,N(e,p,{[t]:a})))},j=Object.freeze(Object.defineProperty({__proto__:null,default:L},Symbol.toStringTag,{value:"Module"}));export{u as A,j as a};
