import{z as m,A as w,C as p,D as g,G as k,H as O,J as E,K as R,M as b,N as x,O as M,P as y,Q as C}from"./page-DggIj5Ru.js";import"./api-client-CCi1ieuC.js";import"./api-ClUvtz75.js";import"./notifications-C31aY_-Z.js";function S(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 $ 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 q 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 v="0x556f1830",G={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 B(t,{blockNumber:e,blockTag:a,data:n,to:c}){const{args:i}=O({data:n,abi:[G]}),[r,d,f,s,o]=i,{ccipRead:l}=t,h=l&&typeof l?.request=="function"?l.request:T;try{if(!S(c,r))throw new A({sender:r,to:c});const u=d.includes(E)?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 $({callbackSelector:s,cause:u,data:n,extraData:o,sender:r,urls:d})}}async function T({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(!C(o)){n=new q({result:o,url:i});continue}return o}catch(s){n=new y({body:d,details:s.message,url:i})}}throw n}export{T as ccipRequest,B as offchainLookup,G as offchainLookupAbiItem,v as offchainLookupSignature};
