zksync-easy-onramp
Version:
SDK package for ZKsync easy on ramp
3 lines (2 loc) • 3.14 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-CCy6TOun.cjs");function g(o,a){if(!e.isAddress(o,{strict:!1}))throw new e.InvalidAddressError({address:o});if(!e.isAddress(a,{strict:!1}))throw new e.InvalidAddressError({address:a});return o.toLowerCase()===a.toLowerCase()}class k extends e.BaseError{constructor({callbackSelector:a,cause:r,data:i,extraData:d,sender:u,urls:s}){var c;super(r.shortMessage||"An error occurred while fetching for an offchain result.",{cause:r,metaMessages:[...r.metaMessages||[],(c=r.metaMessages)!=null&&c.length?"":[],"Offchain Gateway Call:",s&&[" Gateway URL(s):",...s.map(f=>` ${e.getUrl(f)}`)],` Sender: ${u}`,` Data: ${i}`,` Callback selector: ${a}`,` Extra data: ${d}`].flat(),name:"OffchainLookupError"})}}class L extends e.BaseError{constructor({result:a,url:r}){super("Offchain gateway response is malformed. Response data must be a hex value.",{metaMessages:[`Gateway URL: ${e.getUrl(r)}`,`Response: ${e.stringify(a)}`],name:"OffchainLookupResponseMalformedError"})}}class E extends e.BaseError{constructor({sender:a,to:r}){super("Reverted sender address does not match target contract address (`to`).",{metaMessages:[`Contract address: ${r}`,`OffchainLookup sender address: ${a}`],name:"OffchainLookupSenderMismatchError"})}}const b="0x556f1830",y={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 O(o,{blockNumber:a,blockTag:r,data:i,to:d}){const{args:u}=e.decodeErrorResult({data:i,abi:[y]}),[s,c,f,l,n]=u,{ccipRead:t}=o,h=t&&typeof(t==null?void 0:t.request)=="function"?t.request:w;try{if(!g(d,s))throw new E({sender:s,to:d});const p=c.includes(e.localBatchGatewayUrl)?await e.localBatchGatewayRequest({data:f,ccipRequest:h}):await h({data:f,sender:s,urls:c}),{data:m}=await e.call(o,{blockNumber:a,blockTag:r,data:e.concat([l,e.encodeAbiParameters([{type:"bytes"},{type:"bytes"}],[p,n])]),to:d});return m}catch(p){throw new k({callbackSelector:l,cause:p,data:i,extraData:n,sender:s,urls:c})}}async function w({data:o,sender:a,urls:r}){var d;let i=new Error("An unknown error occurred.");for(let u=0;u<r.length;u++){const s=r[u],c=s.includes("{data}")?"GET":"POST",f=c==="POST"?{data:o,sender:a}:void 0,l=c==="POST"?{"Content-Type":"application/json"}:{};try{const n=await fetch(s.replace("{sender}",a.toLowerCase()).replace("{data}",o),{body:JSON.stringify(f),headers:l,method:c});let t;if((d=n.headers.get("Content-Type"))!=null&&d.startsWith("application/json")?t=(await n.json()).data:t=await n.text(),!n.ok){i=new e.HttpRequestError({body:f,details:t!=null&&t.error?e.stringify(t.error):n.statusText,headers:n.headers,status:n.status,url:s});continue}if(!e.isHex(t)){i=new L({result:t,url:s});continue}return t}catch(n){i=new e.HttpRequestError({body:f,details:n.message,url:s})}}throw i}exports.ccipRequest=w;exports.offchainLookup=O;exports.offchainLookupAbiItem=y;exports.offchainLookupSignature=b;
//# sourceMappingURL=ccip-8652SeHi.cjs.map