import{Hn as e,Qt as t,dn as n,ft as r,l as i,mt as a,on as o,st as s,u as c}from"./ccip.js";import{Nt as l,Ut as u,_t as d,at as f,ht as p,it as m,mt as h,rt as g,vt as _}from"./_esm.js";function v({chain:e,currentChainId:t}){if(!e)throw new c;if(t!==e.id)throw new i({chain:e,currentChainId:t})}var y=new n(128);async function b(n,i){let{account:c=n.account,assertChainId:b=!0,chain:x=n.chain,accessList:S,authorizationList:C,blobs:w,data:T,dataSuffix:E=typeof n.dataSuffix==`string`?n.dataSuffix:n.dataSuffix?.value,gas:D,gasPrice:O,maxFeePerBlobGas:k,maxFeePerGas:A,maxPriorityFeePerGas:j,nonce:M,type:N,value:P,...F}=i;if(c===void 0)throw new m({docsPath:`/docs/actions/wallet/sendTransaction`});let I=c?t(c):null,L;try{s(i);let t=await(async()=>{if(i.to)return i.to;if(i.to!==null&&C&&C.length>0)return await l({authorization:C[0]}).catch(()=>{throw new e("`to` is required. Could not infer from `authorizationList`.")})})();if(I?.type===`json-rpc`||I===null){let e;x!==null&&(e=await u(n,d,`getChainId`)({}),b&&v({currentChainId:e,chain:x}));let i=n.chain?.formatters?.transactionRequest?.format,s=(i||r)({...a(F,{format:i}),accessList:S,account:I,authorizationList:C,blobs:w,chainId:e,data:E?o([T??`0x`,E]):T,gas:D,gasPrice:O,maxFeePerBlobGas:k,maxFeePerGas:A,maxPriorityFeePerGas:j,nonce:M,to:t,type:N,value:P},`sendTransaction`),c=y.get(n.uid),l=c?`wallet_sendTransaction`:`eth_sendTransaction`;try{return await n.request({method:l,params:[s]},{retryCount:0})}catch(e){if(c===!1)throw e;let t=e;if(t.name===`InvalidInputRpcError`||t.name===`InvalidParamsRpcError`||t.name===`MethodNotFoundRpcError`||t.name===`MethodNotSupportedRpcError`)return await n.request({method:`wallet_sendTransaction`,params:[s]},{retryCount:0}).then(e=>(y.set(n.uid,!0),e)).catch(e=>{let r=e;throw r.name===`MethodNotFoundRpcError`||r.name===`MethodNotSupportedRpcError`?(y.set(n.uid,!1),t):r});throw t}}if(I?.type===`local`){if(I.nonceManager&&M===void 0){let e=F.chainId,t=await(async()=>typeof e==`number`?e:x?x.id:u(n,d,`getChainId`)({}))();L={address:I.address,chainId:t}}let e=await u(n,p,`prepareTransactionRequest`)({account:I,accessList:S,authorizationList:C,blobs:w,chain:x,data:E?o([T??`0x`,E]):T,gas:D,gasPrice:O,maxFeePerBlobGas:k,maxFeePerGas:A,maxPriorityFeePerGas:j,nonce:M,nonceManager:I.nonceManager,parameters:[...h,`sidecars`],type:N,value:P,...F,to:t}),r=x?.serializers?.transaction,i=await I.signTransaction(e,{serializer:r});return await u(n,g,`sendRawTransaction`)({serializedTransaction:i})}throw I?.type===`smart`?new f({metaMessages:["Consider using the `sendUserOperation` Action instead."],docsPath:`/docs/actions/bundler/sendUserOperation`,type:`smart`}):new f({docsPath:`/docs/actions/wallet/sendTransaction`,type:I?.type})}catch(e){throw e instanceof f?e:(L&&I?.nonceManager?.reset(L),_(e,{...i,account:I,chain:i.chain||void 0}))}}export{v as n,b as t};