require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../error-handling/error-codes.constants.cjs`);require(`../../constants/index.cjs`);const r=require(`../../API/admin-calls.cjs`),i=require(`../../functions/utils/token-check.utils.cjs`),a=require(`../../functions/utils/create-provider.cjs`),o=require(`../../functions/pre-transaction/constructAdminData.cjs`),s=require(`../AccountActions/AccountActions.cjs`),c=require(`../../functions/pre-transaction/sendV0Transaction.cjs`),l=require(`../../functions/pre-transaction/getFeeStructure.cjs`),u=require(`../../functions/pre-transaction/solanaTransfer.utils.cjs`);require(`../AccountActions/index.cjs`);let d=require(`@solana/web3.js`);var f=async(e,t)=>{let{addressLookupTableAccount:n,instructionLists:r}=JSON.parse(t).data,i=await Promise.all(n.map(async t=>{let n=await e.getAddressLookupTable(new d.PublicKey(t));if(!n.value)throw Error(`Failed to fetch lookup table: ${t}`);return n.value}));if(r.length===0)throw Error(`No instructions found`);return{instructions:r.map(e=>new d.TransactionInstruction({keys:e.accounts.map(e=>({pubkey:new d.PublicKey(e.pubkey),isSigner:e.isSigner,isWritable:e.isWritable})),programId:new d.PublicKey(e.programId),data:Buffer.from(e.data,`base64`)})),lookupTableAccounts:i}},p=async(e,t)=>{let n=d.VersionedTransaction.deserialize(Buffer.from(t,`base64`)),r=await Promise.all(n.message.addressTableLookups.map(async({accountKey:t})=>{let n=await e.getAddressLookupTable(t);if(!n.value)throw Error(`Failed to fetch lookup table: ${t.toBase58()}`);return n.value})),{instructions:i}=d.TransactionMessage.decompile(n.message,{addressLookupTableAccounts:r});return{instructions:i,lookupTableAccounts:r}},m=async(n,r,i,o)=>{let c=s.AccountActions.getAddressFromSubAccount(n,i);if(!c)throw Error(`Public account address is not available`);let{fetchRpcUrl:l}=t.networkRegistry[n];if(!l)throw Error(`RPC URL not found for the specified chain ID`);let u=a.createCustomSolanaConnection(l),m=new d.PublicKey(c),{instructions:h,lookupTableAccounts:g}=o===e.ExternalActionId.Lifi?await p(u,r):await f(u,r);return{connection:u,walletPublicKey:m,instructions:h,lookupTableAccounts:g}},h=async(t,a,s,f,p,h,g,_,v)=>{let y=i.validateAndGetChainId(a),b=h===e.ExternalActionId.Lifi,[{connection:x,walletPublicKey:S,instructions:C,lookupTableAccounts:w},T,E]=await Promise.all([m(y,f,p,h),b?Promise.resolve(null):t.getRandomRelay(y),t.getEthereumAddressByChain(y)]),D=C;if(!b){if(!T)throw Error(n.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let t=a[1],r=s[1]*(_??await l.getFeeStructure(y,g,a.map(e=>e.erc20TokenAddress),e.ExternalActionId.Emporium)).variableRate/10000n,{instructions:i}=await u.buildSolanaTransferInstructions(x,S,new d.PublicKey(T),t,r);D=[...C,...i]}let O=await c.sendProxyV0Transaction({connection:x,chainId:y,subAccount:p,payerPublicKey:S,instructions:D,lookupTableAccounts:w});return r.emitTxPublicData(o.constructAdminData(v,y,a.map(e=>e.erc20TokenAddress),s,E,a)),O},g=async(t,n,r,i)=>{if(i===e.ExternalActionId.Lifi)return n;let{connection:a,walletPublicKey:o,instructions:s,lookupTableAccounts:l}=await m(t,n,r,i);return c.serializeProxyV0Transaction(a,o,s,l)};exports.getSolanaProxySwapSerializedTransaction=g,exports.hinkalSolanaProxySwap=h;