import{B as m,b6 as g,x as w,b7 as R,X as x,b8 as M,b9 as S,ba as $,d as A,bb as T,bc as p,bd as k,be as b,ah as C}from"./liveTradeBalances-D3JyJrhV.js";import"./index-tiSqwqFl.js";class G extends m{constructor({callbackSelector:a,cause:t,data:d,extraData:r,sender:c,urls:s}){super(t.shortMessage||"An error occurred while fetching for an offchain result.",{cause:t,metaMessages:[...t.metaMessages||[],t.metaMessages?.length?"":[],"Offchain Gateway Call:",s&&["  Gateway URL(s):",...s.map(o=>`    ${g(o)}`)],`  Sender: ${c}`,`  Data: ${d}`,`  Callback selector: ${a}`,`  Extra data: ${r}`].flat(),name:"OffchainLookupError"})}}class D extends m{constructor({result:a,url:t}){super("Offchain gateway response is malformed. Response data must be a hex value.",{metaMessages:[`Gateway URL: ${g(t)}`,`Response: ${w(a)}`],name:"OffchainLookupResponseMalformedError"})}}class O extends m{constructor({sender:a,to:t}){super("Reverted sender address does not match target contract address (`to`).",{metaMessages:[`Contract address: ${t}`,`OffchainLookup sender address: ${a}`],name:"OffchainLookupSenderMismatchError"})}}const v="0x556f1830",B={name:"OffchainLookup",type:"error",inputs:[{name:"sender",type:"address"},{name:"urls",type:"string[]"},{name:"callData",type:"bytes"},{name:"callbackFunction",type:"bytes4"},{name:"extraData",type:"bytes"}]};async function H(i,{blockNumber:a,blockTag:t,data:d,requestOptions:r,to:c}){const{args:s}=R({data:d,abi:[B]}),[o,l,h,e,n]=s,{ccipRead:u}=i,y=u&&typeof u?.request=="function"?u.request:P;try{if(!x(c,o))throw new O({sender:o,to:c});const f=l.includes(M)?await S({data:h,ccipRequest:L=>y({...L,requestOptions:r})}):await y({data:h,requestOptions:r,sender:o,urls:l}),{data:E}=await $(i,{blockNumber:a,blockTag:t,data:A([e,T([{type:"bytes"},{type:"bytes"}],[f,n])]),requestOptions:r,to:c});return E}catch(f){throw r?.signal?.aborted?p(r.signal):k(f)?f:new G({callbackSelector:e,cause:f,data:d,extraData:n,sender:o,urls:l})}}async function P({data:i,requestOptions:a,sender:t,urls:d}){let r=new Error("An unknown error occurred.");for(let c=0;c<d.length;c++){if(a?.signal?.aborted)throw p(a.signal);const s=d[c],o=s.includes("{data}")?"GET":"POST",l=o==="POST"?{data:i,sender:t}:void 0,h=o==="POST"?{"Content-Type":"application/json"}:{};try{const e=await fetch(s.replace("{sender}",t.toLowerCase()).replace("{data}",i),{body:JSON.stringify(l),headers:h,method:o,...a?.signal?{signal:a.signal}:{}});let n;if(e.headers.get("Content-Type")?.startsWith("application/json")?n=(await e.json()).data:n=await e.text(),!e.ok){r=new b({body:l,details:n?.error?w(n.error):e.statusText,headers:e.headers,status:e.status,url:s});continue}if(!C(n)){r=new D({result:n,url:s});continue}return n}catch(e){if(a?.signal?.aborted)throw p(a.signal);if(k(e))throw e;r=new b({body:l,details:e.message,url:s})}}throw r}export{P as ccipRequest,H as offchainLookup,B as offchainLookupAbiItem,v as offchainLookupSignature};
