"use strict";const a=require("./unsignedTransaction-DA4tlY5u.js"),m=require("./index-CPGWCfWD.js"),C=require("./signer-DyqulDUM.js"),N=require("./platform-CCG_jgOO.js");function E(e){return e.includes("rpcpool.com")?"triton":e.includes("helius-rpc.com")?"helius":e.includes("rpc.ankr.com")?"ankr":"unknown"}async function B(e,t,l,u){const n=u.transaction.transaction,d=i=>i.programId.toString()!=="ComputeBudget111111111111111111111111111111";if(a.isVersionedTransaction(n)){const i=(await Promise.all(n.message.addressTableLookups.map(c=>e.getAddressLookupTable(c.accountKey)))).map(c=>c.value).filter(c=>c!==null),r=a.TransactionMessage.decompile(n.message,{addressLookupTableAccounts:i});r.recentBlockhash=t,n.message.recentBlockhash=t,r.instructions=r.instructions.filter(d),n.message=r.compileToV0Message(i),r.instructions.push(...await L(e,n)),n.message=r.compileToV0Message(i),n.sign(u.transaction.signers??[])}else n.recentBlockhash=t,n.lastValidBlockHeight=l,n.instructions=n.instructions.filter(d),n.add(...await L(e,n)),u.transaction.signers&&n.partialSign(...u.transaction.signers);return n}async function L(e,t,l="confirmed"){let u=2e5,n=0;const d=a.ComputeBudgetProgram.setComputeUnitLimit({units:3e5});let i;if(a.isVersionedTransaction(t)){const s=(await Promise.all(t.message.addressTableLookups.map(g=>e.getAddressLookupTable(g.accountKey)))).map(g=>g.value).filter(g=>g!==null),o=a.TransactionMessage.decompile(t.message,{addressLookupTableAccounts:s});o.instructions=[...o.instructions,d],i=new a.VersionedTransaction(o.compileToV0Message(s)),i.signatures=[...t.signatures]}else{const s=new a.Transaction$1;s.recentBlockhash=t.recentBlockhash,s.feePayer=t.feePayer,s.instructions=[...t.instructions,d],s.signatures=[...t.signatures],i=s}e:for(;;){if(a.isVersionedTransaction(i)&&!i.message.recentBlockhash){const{blockhash:o}=await e.getLatestBlockhash(l);i.message.recentBlockhash=o}const s=await(a.isVersionedTransaction(i)?e.simulateTransaction(i,{commitment:l,replaceRecentBlockhash:!0}):e.simulateTransaction(i));if(s.value.err){if(I(s.value)){if(n<5){n++,await m.sleep(1e3);continue e}}else if(n<3){n++,await m.sleep(1e3);continue e}throw new Error(`Simulation failed: ${JSON.stringify(s.value.err)}
Logs:
${(s.value.logs||[]).join(`
  `)}`)}else{s.value.unitsConsumed&&(u=s.value.unitsConsumed);break}}const r=Math.floor(u*1.2),c=[];c.push(a.ComputeBudgetProgram.setComputeUnitLimit({units:r}));const y=m.config.transactionSettings?.Solana?.priorityFee||{},{percentile:p=.9,percentileMultiple:f=1,min:S=1e5,max:h=1e8}=y,P=async s=>{if(s==="triton")try{return{fee:await C.determinePriorityFeeTritonOne(e,t,p,f,S,h),methodUsed:"triton"}}catch(o){console.warn("Failed to determine priority fee using Triton RPC:",o)}try{return{fee:await C.determinePriorityFee(e,t,p,f,S,h),methodUsed:"default"}}catch(o){return console.warn("Failed to determine priority fee using Triton RPC:",o),{fee:S,methodUsed:"minimum"}}},A=E(e.rpcEndpoint),{fee:T,methodUsed:k}=await P(A),w=T/1e6/a.LAMPORTS_PER_SOL*r;return console.table({"RPC Provider":A,"Method used":k,"Percentile used":p,"Multiple used":f,"Compute budget":r,"Priority fee":T,"Max fee in SOL":w}),c.push(a.ComputeBudgetProgram.setComputeUnitPrice({microLamports:T})),c}function I(e){const t={};if(e.err==="BlockhashNotFound"&&(t.BlockhashNotFound="Blockhash not found during simulation. Trying again."),e.logs)for(const l of e.logs)l.includes("SlippageToleranceExceeded")&&(t.SlippageToleranceExceeded="Slippage failure during simulation. Trying again."),l.includes("RequireGteViolated")&&(t.RequireGteViolated="Swap instruction failure during simulation. Trying again.");return m.isEmptyObject(t)?!1:(console.table(t),!0)}function _(e){return N.chainToPlatform.has(e)&&N.chainToPlatform.get(e)==="Solana"}const v="solana:signAndSendTransaction",M="solana:signIn",O="solana:signMessage",F="solana:signTransaction",V="standard:connect",x="standard:disconnect",b="standard:events",H="solana:mainnet",R="solana:devnet",U="solana:testnet",D="solana:localnet";exports.SOLANA_DEVNET_CHAIN=R;exports.SOLANA_LOCALNET_CHAIN=D;exports.SOLANA_MAINNET_CHAIN=H;exports.SOLANA_TESTNET_CHAIN=U;exports.SolanaSignAndSendTransaction=v;exports.SolanaSignIn=M;exports.SolanaSignMessage=O;exports.SolanaSignTransaction=F;exports.StandardConnect=V;exports.StandardDisconnect=x;exports.StandardEvents=b;exports.isSvmChain=_;exports.setPriorityFeeInstructions=B;
