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