"use strict";var C=Object.defineProperty;var B=(c,t,n)=>t in c?C(c,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):c[t]=n;var m=(c,t,n)=>B(c,typeof t!="symbol"?t+"":t,n);const e=require("./address-RcMobNYE.js"),b=require("./chain-itK5uGYL.js");class y extends b.ChainContext{async getTokenAccount(t,n){const{getAssociatedTokenAddress:i}=await Promise.resolve().then(()=>require("./index-CZYUYK5K.js")),s=new e.SolanaAddress(n).unwrap(),r=new e.SolanaAddress(t).unwrap(),o=await i(s,r);return{chain:this.chain,address:new e.SolanaAddress(o.toString())}}}const v=new e.PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"),S=new e.PublicKey("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"),E=new e.PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");new e.PublicKey("So11111111111111111111111111111111111111112");new e.PublicKey("9pan9bMn5HatX4EJdBwg9VgCa7Uz5HL8N1m5D3NdXejP");const l=class l extends b.PlatformContext{constructor(t,n){super(t,n??e.networkPlatformConfigs(t,l._platform))}getRpc(t,n={commitment:"confirmed",disableRetryOnRateLimit:!0}){if(t in this.config)return new e.Connection(this.config[t].rpc,n);throw new Error("No configuration available for chain: "+t)}getChain(t,n){if(t in this.config)return new y(t,this,n);throw new Error("No configuration available for chain: "+t)}static nativeTokenId(t,n){if(!l.isSupportedChain(n))throw new Error(`invalid chain: ${n}`);return e.Wormhole.chainAddress(n,e.SolanaZeroAddress)}static isNativeTokenId(t,n,i){return!this.isSupportedChain(n)||i.chain!==n?!1:this.nativeTokenId(t,n)==i}static isSupportedChain(t){return e.chainToPlatform(t)===l._platform}static async getDecimals(t,n,i){if(e.isNative(i))return e.nativeDecimals(l._platform);let s=await n.getParsedAccountInfo(new e.SolanaAddress(i).unwrap());if(!s||!s.value)throw new Error("could not fetch token details");const{decimals:r}=s.value.data.parsed.info;return r}static async getBalance(t,n,i,s){const r=new e.PublicKey(i);if(e.isNative(s))return BigInt(await n.getBalance(r));const o=await n.getTokenAccountsByOwner(r,{mint:new e.SolanaAddress(s).unwrap()}),d=o.value.length>0?o.value[0].pubkey:r,a=await n.getTokenAccountBalance(d);return BigInt(a.value.amount)}static async getBalances(t,n,i,s){let r;s.includes("native")&&(r=BigInt(await n.getBalance(new e.PublicKey(i))));const o=(await Promise.all([v,S].map(a=>new e.PublicKey(a)).map(a=>n.getParsedTokenAccountsByOwner(new e.PublicKey(i),{programId:a})))).reduce((a,u)=>a.concat(u.value),[]);return s.map(a=>{var w,p,T,P;if(e.isNative(a))return{native:r};const u=new e.SolanaAddress(a).toString(),h=(P=(T=(p=(w=o.find(f=>{var A,k;return((k=(A=f==null?void 0:f.account.data.parsed)==null?void 0:A.info)==null?void 0:k.mint)===a.toString()}))==null?void 0:w.account.data.parsed)==null?void 0:p.info)==null?void 0:T.tokenAmount)==null?void 0:P.amount;return h?{[u]:BigInt(h)}:{[u]:null}}).reduce((a,u)=>Object.assign(a,u),{})}static async sendWait(t,n,i,s){const r=await Promise.all(i.map(a=>this.sendTxWithRetry(n,a,s))),o=r.map(a=>a.signature),d=r.filter(a=>a.response.value.err).map(a=>a.response.value.err);if(d.length>0)throw new Error(`Failed to confirm transaction: ${d}`);return o}static async sendTxWithRetry(t,n,i={},s=5e3){const r=i.preflightCommitment??t.commitment,o=await t.sendRawTransaction(n,{...i,skipPreflight:!1,maxRetries:0,preflightCommitment:r}),{blockhash:d,lastValidBlockHeight:a}=await t.getLatestBlockhash(),u=t.confirmTransaction({signature:o,blockhash:d,lastValidBlockHeight:a},r);let h=null;for(;!h&&(h=await Promise.race([u,new Promise(w=>setTimeout(()=>{w(null)},s))]),!h);)await t.sendRawTransaction(n,{...i,skipPreflight:!0,maxRetries:0,preflightCommitment:r});return{signature:o,response:h}}static async latestBlock(t,n){return t.getLatestBlockhash(n??t.commitment)}static async getLatestBlock(t){return await t.getSlot()}static async getLatestFinalizedBlock(t){const{lastValidBlockHeight:n}=await this.latestBlock(t,"finalized");return n}static chainFromChainId(t){const n=e.platformNativeChainIdToNetworkChain(l._platform,t);if(!n)throw new Error(`No matching genesis hash to determine network and chain: ${t}`);const[i,s]=n;return[i,s]}static async chainFromRpc(t){try{const n=await t.getGenesisHash();return l.chainFromChainId(n)}catch(n){if(t.rpcEndpoint.includes("http://127")||t.rpcEndpoint.includes("http://localhost")||t.rpcEndpoint==="http://solana-devnet:8899")return["Devnet","Solana"];throw n}}};m(l,"_platform",e._platform$1);let g=l;class R{constructor(t,n,i,s,r=!1){m(this,"transaction");m(this,"network");m(this,"chain");m(this,"description");m(this,"parallelizable");this.transaction=t,this.network=n,this.chain=i,this.description=s,this.parallelizable=r}}function N(c){return c.signatures!==void 0&&c.message!==void 0}exports.ASSOCIATED_TOKEN_PROGRAM_ID=E;exports.SolanaChain=y;exports.SolanaPlatform=g;exports.SolanaUnsignedTransaction=R;exports.TOKEN_2022_PROGRAM_ID=S;exports.TOKEN_PROGRAM_ID=v;exports.isVersionedTransaction=N;
