"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[334],{4334:function(e,a,t){t.d(a,{offchainLookup:function(){return w},offchainLookupSignature:function(){return m}});var r=t(4463),n=t(4133),s=t(8871),o=t(66);class c extends s.G{constructor({callbackSelector:e,cause:a,data:t,extraData:r,sender:n,urls:s}){var c;super(a.shortMessage||"An error occurred while fetching for an offchain result.",{cause:a,metaMessages:[...a.metaMessages||[],(null===(c=a.metaMessages)||void 0===c?void 0:c.length)?"":[],"Offchain Gateway Call:",s&&["  Gateway URL(s):",...s.map(e=>"    ".concat((0,o.Gr)(e)))],"  Sender: ".concat(n),"  Data: ".concat(t),"  Callback selector: ".concat(e),"  Extra data: ".concat(r)].flat()}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupError"})}}class i extends s.G{constructor({result:e,url:a}){super("Offchain gateway response is malformed. Response data must be a hex value.",{metaMessages:["Gateway URL: ".concat((0,o.Gr)(a)),"Response: ".concat((0,n.P)(e))]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupResponseMalformedError"})}}class l extends s.G{constructor({sender:e,to:a}){super("Reverted sender address does not match target contract address (`to`).",{metaMessages:["Contract address: ".concat(a),"OffchainLookup sender address: ".concat(e)]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupSenderMismatchError"})}}var u=t(6268),d=t(7904),f=t(5491),p=t(5282),h=t(1708),y=t(7360);let m="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 w(e,a){let{blockNumber:t,blockTag:n,data:s,to:o}=a,{args:i}=(0,d.p)({data:s,abi:[b]}),[u,y,m,w,v]=i;try{if(!(0,p.E)(o,u))throw new l({sender:u,to:o});let a=await g({data:m,sender:u,urls:y}),{data:s}=await (0,r.R)(e,{blockNumber:t,blockTag:n,data:(0,h.zo)([w,(0,f.E)([{type:"bytes"},{type:"bytes"}],[a,v])]),to:o});return s}catch(e){throw new c({callbackSelector:w,cause:e,data:s,extraData:v,sender:u,urls:y})}}async function g(e){let{data:a,sender:t,urls:r}=e,s=Error("An unknown error occurred.");for(let e=0;e<r.length;e++){let c=r[e],l=c.includes("{data}")?"GET":"POST",d="POST"===l?{data:a,sender:t}:void 0;try{var o;let e;let r=await fetch(c.replace("{sender}",t).replace("{data}",a),{body:JSON.stringify(d),method:l});if(e=(null===(o=r.headers.get("Content-Type"))||void 0===o?void 0:o.startsWith("application/json"))?(await r.json()).data:await r.text(),!r.ok){s=new u.Gg({body:d,details:(null==e?void 0:e.error)?(0,n.P)(e.error):r.statusText,headers:r.headers,status:r.status,url:c});continue}if(!(0,y.v)(e)){s=new i({result:e,url:c});continue}return e}catch(e){s=new u.Gg({body:d,details:e.message,url:c})}}throw s}}}]);