@gardenfi/core 0.2.0-beta.62 → 0.2.0-beta.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";var Us=Object.defineProperty;var Ns=(e,t,r)=>t in e?Us(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var pt=(e,t,r)=>Ns(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("@catalogfi/utils"),J=require("@gardenfi/orderbook"),ge=require("@gardenfi/utils"),He=require("viem"),Ms=require("varuint-bitcoin"),Ds=require("tiny-secp256k1"),Sn=require("@catalogfi/wallets"),bi=require("bitcoinjs-lib"),$s=require("bignumber.js");function fn(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const In=fn(Ms),wt=fn(Ds),ye=fn(bi);var or=(e=>(e[e.evm=14400]="evm",e[e.btc=288]="btc",e))(or||{}),ue=(e=>(e.Idle="Idle",e.Initiate="Initiate",e.Redeem="Redeem",e.Refund="Refund",e))(ue||{});function qt(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}const yi="2.21.30";let Pt={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:r})=>t?`${e??"https://viem.sh"}${t}${r?`#${r}`:""}`:void 0,version:`viem@${yi}`};class Z extends Error{constructor(t,r={}){var f;const n=(()=>{var l;return r.cause instanceof Z?r.cause.details:(l=r.cause)!=null&&l.message?r.cause.message:r.details})(),i=r.cause instanceof Z&&r.cause.docsPath||r.docsPath,a=(f=Pt.getDocsUrl)==null?void 0:f.call(Pt,{...r,docsPath:i}),u=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...a?[`Docs: ${a}`]:[],...n?[`Details: ${n}`]:[],...Pt.version?[`Version: ${Pt.version}`]:[]].join(`
2
2
  `);super(u,r.cause?{cause:r.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=n,this.docsPath=i,this.metaMessages=r.metaMessages,this.name=r.name??this.name,this.shortMessage=t,this.version=yi}walk(t){return gi(this,t)}}function gi(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e?gi(e.cause,t):t?null:e}class Hs extends Z{constructor({max:t,min:r,signed:n,size:i,value:a}){super(`Number "${a}" is not in safe ${i?`${i*8}-bit ${n?"signed":"unsigned"} `:""}integer range ${t?`(${r} to ${t})`:`(above ${r})`}`,{name:"IntegerOutOfRangeError"})}}class zs extends Z{constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${t} bytes.`,{name:"SizeOverflowError"})}}function Wt(e,{strict:t=!0}={}){return!e||typeof e!="string"?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")}function xt(e){return Wt(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}function ar(e,{dir:t="left"}={}){let r=typeof e=="string"?e.replace("0x",""):e,n=0;for(let i=0;i<r.length-1&&r[t==="left"?i:r.length-i-1].toString()==="0";i++)n++;return r=t==="left"?r.slice(n):r.slice(0,r.length-n),typeof e=="string"?(r.length===1&&t==="right"&&(r=`${r}0`),`0x${r.length%2===1?`0${r}`:r}`):r}class js extends Z{constructor({offset:t,position:r,size:n}){super(`Slice ${r==="start"?"starting":"ending"} at offset "${t}" is out-of-bounds (size: ${n}).`,{name:"SliceOffsetOutOfBoundsError"})}}class mi extends Z{constructor({size:t,targetSize:r,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${t}) exceeds padding size (${r}).`,{name:"SizeExceedsPaddingSizeError"})}}function St(e,{dir:t,size:r=32}={}){return typeof e=="string"?Gs(e,{dir:t,size:r}):qs(e,{dir:t,size:r})}function Gs(e,{dir:t,size:r=32}={}){if(r===null)return e;const n=e.replace("0x","");if(n.length>r*2)throw new mi({size:Math.ceil(n.length/2),targetSize:r,type:"hex"});return`0x${n[t==="right"?"padEnd":"padStart"](r*2,"0")}`}function qs(e,{dir:t,size:r=32}={}){if(r===null)return e;if(e.length>r)throw new mi({size:e.length,targetSize:r,type:"bytes"});const n=new Uint8Array(r);for(let i=0;i<r;i++){const a=t==="right";n[a?i:r-i-1]=e[a?i:e.length-i-1]}return n}const Ws=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function q(e,t={}){return typeof e=="number"||typeof e=="bigint"?_i(e,t):typeof e=="string"?Ys(e,t):typeof e=="boolean"?Vs(e,t):Ze(e,t)}function Vs(e,t={}){const r=`0x${Number(e)}`;return typeof t.size=="number"?(It(r,{size:t.size}),St(r,{size:t.size})):r}function Ze(e,t={}){let r="";for(let i=0;i<e.length;i++)r+=Ws[e[i]];const n=`0x${r}`;return typeof t.size=="number"?(It(n,{size:t.size}),St(n,{dir:"right",size:t.size})):n}function _i(e,t={}){const{signed:r,size:n}=t,i=BigInt(e);let a;n?r?a=(1n<<BigInt(n)*8n-1n)-1n:a=2n**(BigInt(n)*8n)-1n:typeof e=="number"&&(a=BigInt(Number.MAX_SAFE_INTEGER));const u=typeof a=="bigint"&&r?-a-1n:0;if(a&&i>a||i<u){const l=typeof e=="bigint"?"n":"";throw new Hs({max:a?`${a}${l}`:void 0,min:`${u}${l}`,signed:r,size:n,value:`${e}${l}`})}const f=`0x${(r&&i<0?(1n<<BigInt(n*8))+BigInt(i):i).toString(16)}`;return n?St(f,{size:n}):f}const Ks=new TextEncoder;function Ys(e,t={}){const r=Ks.encode(e);return Ze(r,t)}const Js=new TextEncoder;function wi(e,t={}){return typeof e=="number"||typeof e=="bigint"?Qs(e,t):typeof e=="boolean"?Xs(e,t):Wt(e)?st(e,t):xi(e,t)}function Xs(e,t={}){const r=new Uint8Array(1);return r[0]=Number(e),typeof t.size=="number"?(It(r,{size:t.size}),St(r,{size:t.size})):r}const Me={zero:48,nine:57,A:65,F:70,a:97,f:102};function An(e){if(e>=Me.zero&&e<=Me.nine)return e-Me.zero;if(e>=Me.A&&e<=Me.F)return e-(Me.A-10);if(e>=Me.a&&e<=Me.f)return e-(Me.a-10)}function st(e,t={}){let r=e;t.size&&(It(r,{size:t.size}),r=St(r,{dir:"right",size:t.size}));let n=r.slice(2);n.length%2&&(n=`0${n}`);const i=n.length/2,a=new Uint8Array(i);for(let u=0,f=0;u<i;u++){const l=An(n.charCodeAt(f++)),b=An(n.charCodeAt(f++));if(l===void 0||b===void 0)throw new Z(`Invalid byte sequence ("${n[f-2]}${n[f-1]}" in "${n}").`);a[u]=l*16+b}return a}function Qs(e,t){const r=_i(e,t);return st(r)}function xi(e,t={}){const r=Js.encode(e);return typeof t.size=="number"?(It(r,{size:t.size}),St(r,{dir:"right",size:t.size})):r}function It(e,{size:t}){if(xt(e)>t)throw new zs({givenSize:xt(e),maxSize:t})}function gt(e,t={}){const{signed:r}=t;t.size&&It(e,{size:t.size});const n=BigInt(e);if(!r)return n;const i=(e.length-2)/2,a=(1n<<BigInt(i)*8n-1n)-1n;return n<=a?n:n-BigInt(`0x${"f".padStart(i*2,"f")}`)-1n}function fr(e,t={}){return Number(gt(e,t))}function un(e,t){return({exclude:r,format:n})=>({exclude:r,format:i=>{const a=t(i);if(r)for(const u of r)delete a[u];return{...a,...n(i)}},type:e})}const vi={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function cn(e){const t={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?fr(e.chainId):void 0,gas:e.gas?BigInt(e.gas):void 0,gasPrice:e.gasPrice?BigInt(e.gasPrice):void 0,maxFeePerBlobGas:e.maxFeePerBlobGas?BigInt(e.maxFeePerBlobGas):void 0,maxFeePerGas:e.maxFeePerGas?BigInt(e.maxFeePerGas):void 0,maxPriorityFeePerGas:e.maxPriorityFeePerGas?BigInt(e.maxPriorityFeePerGas):void 0,nonce:e.nonce?fr(e.nonce):void 0,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,type:e.type?vi[e.type]:void 0,typeHex:e.type?e.type:void 0,value:e.value?BigInt(e.value):void 0,v:e.v?BigInt(e.v):void 0};return e.authorizationList&&(t.authorizationList=eo(e.authorizationList)),t.yParity=(()=>{if(e.yParity)return Number(e.yParity);if(typeof t.v=="bigint"){if(t.v===0n||t.v===27n)return 0;if(t.v===1n||t.v===28n)return 1;if(t.v>=35n)return t.v%2n===0n?1:0}})(),t.type==="legacy"&&(delete t.accessList,delete t.maxFeePerBlobGas,delete t.maxFeePerGas,delete t.maxPriorityFeePerGas,delete t.yParity),t.type==="eip2930"&&(delete t.maxFeePerBlobGas,delete t.maxFeePerGas,delete t.maxPriorityFeePerGas),t.type==="eip1559"&&delete t.maxFeePerBlobGas,t}const Zs=un("transaction",cn);function eo(e){return e.map(t=>({contractAddress:t.address,chainId:Number(t.chainId),nonce:Number(t.nonce),r:t.r,s:t.s,yParity:Number(t.yParity)}))}function to(e){var r;const t=(r=e.transactions)==null?void 0:r.map(n=>typeof n=="string"?n:cn(n));return{...e,baseFeePerGas:e.baseFeePerGas?BigInt(e.baseFeePerGas):null,blobGasUsed:e.blobGasUsed?BigInt(e.blobGasUsed):void 0,difficulty:e.difficulty?BigInt(e.difficulty):void 0,excessBlobGas:e.excessBlobGas?BigInt(e.excessBlobGas):void 0,gasLimit:e.gasLimit?BigInt(e.gasLimit):void 0,gasUsed:e.gasUsed?BigInt(e.gasUsed):void 0,hash:e.hash?e.hash:null,logsBloom:e.logsBloom?e.logsBloom:null,nonce:e.nonce?e.nonce:null,number:e.number?BigInt(e.number):null,size:e.size?BigInt(e.size):void 0,timestamp:e.timestamp?BigInt(e.timestamp):void 0,transactions:t,totalDifficulty:e.totalDifficulty?BigInt(e.totalDifficulty):null}}const ro=un("block",to);function no(e,{args:t,eventName:r}={}){return{...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,logIndex:e.logIndex?Number(e.logIndex):null,transactionHash:e.transactionHash?e.transactionHash:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,...r?{args:t,eventName:r}:{}}}const io={"0x0":"reverted","0x1":"success"};function so(e){const t={...e,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,contractAddress:e.contractAddress?e.contractAddress:null,cumulativeGasUsed:e.cumulativeGasUsed?BigInt(e.cumulativeGasUsed):null,effectiveGasPrice:e.effectiveGasPrice?BigInt(e.effectiveGasPrice):null,gasUsed:e.gasUsed?BigInt(e.gasUsed):null,logs:e.logs?e.logs.map(r=>no(r)):null,to:e.to?e.to:null,transactionIndex:e.transactionIndex?fr(e.transactionIndex):null,status:e.status?io[e.status]:null,type:e.type?vi[e.type]||e.type:null};return e.blobGasPrice&&(t.blobGasPrice=BigInt(e.blobGasPrice)),e.blobGasUsed&&(t.blobGasUsed=BigInt(e.blobGasUsed)),t}const oo=un("transactionReceipt",so),ln=2n**256n-1n;function Vt(e){return`0x${e.reduce((t,r)=>t+r.replace("0x",""),"")}`}class Rn extends Z{constructor({offset:t}){super(`Offset \`${t}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class ao extends Z{constructor({length:t,position:r}){super(`Position \`${r}\` is out of bounds (\`0 < position < ${t}\`).`,{name:"PositionOutOfBoundsError"})}}class fo extends Z{constructor({count:t,limit:r}){super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${t}\`).`,{name:"RecursiveReadLimitExceededError"})}}const uo={bytes:new Uint8Array,dataView:new DataView(new ArrayBuffer(0)),position:0,positionReadCount:new Map,recursiveReadCount:0,recursiveReadLimit:Number.POSITIVE_INFINITY,assertReadLimit(){if(this.recursiveReadCount>=this.recursiveReadLimit)throw new fo({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new ao({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new Rn({offset:e});const t=this.position-e;this.assertPosition(t),this.position=t},getReadCount(e){return this.positionReadCount.get(e||this.position)||0},incrementPosition(e){if(e<0)throw new Rn({offset:e});const t=this.position+e;this.assertPosition(t),this.position=t},inspectByte(e){const t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectBytes(e,t){const r=t??this.position;return this.assertPosition(r+e-1),this.bytes.subarray(r,r+e)},inspectUint8(e){const t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectUint16(e){const t=e??this.position;return this.assertPosition(t+1),this.dataView.getUint16(t)},inspectUint24(e){const t=e??this.position;return this.assertPosition(t+2),(this.dataView.getUint16(t)<<8)+this.dataView.getUint8(t+2)},inspectUint32(e){const t=e??this.position;return this.assertPosition(t+3),this.dataView.getUint32(t)},pushByte(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushBytes(e){this.assertPosition(this.position+e.length-1),this.bytes.set(e,this.position),this.position+=e.length},pushUint8(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushUint16(e){this.assertPosition(this.position+1),this.dataView.setUint16(this.position,e),this.position+=2},pushUint24(e){this.assertPosition(this.position+2),this.dataView.setUint16(this.position,e>>8),this.dataView.setUint8(this.position+2,e&255),this.position+=3},pushUint32(e){this.assertPosition(this.position+3),this.dataView.setUint32(this.position,e),this.position+=4},readByte(){this.assertReadLimit(),this._touch();const e=this.inspectByte();return this.position++,e},readBytes(e,t){this.assertReadLimit(),this._touch();const r=this.inspectBytes(e);return this.position+=t??e,r},readUint8(){this.assertReadLimit(),this._touch();const e=this.inspectUint8();return this.position+=1,e},readUint16(){this.assertReadLimit(),this._touch();const e=this.inspectUint16();return this.position+=2,e},readUint24(){this.assertReadLimit(),this._touch();const e=this.inspectUint24();return this.position+=3,e},readUint32(){this.assertReadLimit(),this._touch();const e=this.inspectUint32();return this.position+=4,e},get remaining(){return this.bytes.length-this.position},setPosition(e){const t=this.position;return this.assertPosition(e),this.position=e,()=>this.position=t},_touch(){if(this.recursiveReadLimit===Number.POSITIVE_INFINITY)return;const e=this.getReadCount();this.positionReadCount.set(this.position,e+1),e>0&&this.recursiveReadCount++}};function Ei(e,{recursiveReadLimit:t=8192}={}){const r=Object.create(uo);return r.bytes=e,r.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),r.positionReadCount=new Map,r.recursiveReadLimit=t,r}function ot(e,t="hex"){const r=Bi(e),n=Ei(new Uint8Array(r.length));return r.encode(n),t==="hex"?Ze(n.bytes):n.bytes}function Bi(e){return Array.isArray(e)?co(e.map(t=>Bi(t))):lo(e)}function co(e){const t=e.reduce((i,a)=>i+a.length,0),r=Si(t);return{length:t<=55?1+t:1+r+t,encode(i){t<=55?i.pushByte(192+t):(i.pushByte(247+r),r===1?i.pushUint8(t):r===2?i.pushUint16(t):r===3?i.pushUint24(t):i.pushUint32(t));for(const{encode:a}of e)a(i)}}}function lo(e){const t=typeof e=="string"?st(e):e,r=Si(t.length);return{length:t.length===1&&t[0]<128?1:t.length<=55?1+t.length:1+r+t.length,encode(i){t.length===1&&t[0]<128?i.pushBytes(t):t.length<=55?(i.pushByte(128+t.length),i.pushBytes(t)):(i.pushByte(183+r),r===1?i.pushUint8(t.length):r===2?i.pushUint16(t.length):r===3?i.pushUint24(t.length):i.pushUint32(t.length),i.pushBytes(t))}}}function Si(e){if(e<2**8)return 1;if(e<2**16)return 2;if(e<2**24)return 3;if(e<2**32)return 4;throw new Z("Length is too large.")}const ho={ether:-9,wei:9};function po(e,t){let r=e.toString();const n=r.startsWith("-");n&&(r=r.slice(1)),r=r.padStart(t,"0");let[i,a]=[r.slice(0,r.length-t),r.slice(r.length-t)];return a=a.replace(/(0+)$/,""),`${n?"-":""}${i||"0"}${a?`.${a}`:""}`}function Xr(e,t="wei"){return po(e,ho[t])}function bo(e){const t=Object.entries(e).map(([n,i])=>i===void 0||i===!1?null:[n,i]).filter(Boolean),r=t.reduce((n,[i])=>Math.max(n,i.length),0);return t.map(([n,i])=>` ${`${n}:`.padEnd(r+1)} ${i}`).join(`
3
3
  `)}class yo extends Z{constructor({v:t}){super(`Invalid \`v\` value "${t}". Expected 27 or 28.`,{name:"InvalidLegacyVError"})}}class go extends Z{constructor({transaction:t}){super("Cannot infer a transaction type from provided transaction.",{metaMessages:["Provided Transaction:","{",bo(t),"}","","To infer the type, either provide:","- a `type` to the Transaction, or","- an EIP-1559 Transaction with `maxFeePerGas`, or","- an EIP-2930 Transaction with `gasPrice` & `accessList`, or","- an EIP-4844 Transaction with `blobs`, `blobVersionedHashes`, `sidecars`, or","- an EIP-7702 Transaction with `authorizationList`, or","- a Legacy Transaction with `gasPrice`"],name:"InvalidSerializableTransactionError"})}}class mo extends Z{constructor({storageKey:t}){super(`Size for storage key "${t}" is invalid. Expected 32 bytes. Got ${Math.floor((t.length-2)/2)} bytes.`,{name:"InvalidStorageKeySizeError"})}}function Ii(e){const{kzg:t}=e,r=e.to??(typeof e.blobs[0]=="string"?"hex":"bytes"),n=typeof e.blobs[0]=="string"?e.blobs.map(a=>st(a)):e.blobs,i=[];for(const a of n)i.push(Uint8Array.from(t.blobToKzgCommitment(a)));return r==="bytes"?i:i.map(a=>Ze(a))}function Ai(e){const{kzg:t}=e,r=e.to??(typeof e.blobs[0]=="string"?"hex":"bytes"),n=typeof e.blobs[0]=="string"?e.blobs.map(u=>st(u)):e.blobs,i=typeof e.commitments[0]=="string"?e.commitments.map(u=>st(u)):e.commitments,a=[];for(let u=0;u<n.length;u++){const f=n[u],l=i[u];a.push(Uint8Array.from(t.computeBlobKzgProof(f,l)))}return r==="bytes"?a:a.map(u=>Ze(u))}function Tn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function _o(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function hn(e,...t){if(!_o(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function ur(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ri(e,t){hn(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const wo=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),Cr=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Oe=(e,t)=>e<<32-t|e>>>t,kn=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68,xo=e=>e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255;function Pn(e){for(let t=0;t<e.length;t++)e[t]=xo(e[t])}function vo(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function dn(e){return typeof e=="string"&&(e=vo(e)),hn(e),e}let Ti=class{clone(){return this._cloneInto()}};function ki(e){const t=n=>e().update(dn(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Eo(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const i=BigInt(32),a=BigInt(4294967295),u=Number(r>>i&a),f=Number(r&a),l=n?4:0,b=n?0:4;e.setUint32(t+l,u,n),e.setUint32(t+b,f,n)}const Bo=(e,t,r)=>e&t^~e&r,So=(e,t,r)=>e&t^e&r^t&r;class Io extends Ti{constructor(t,r,n,i){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Cr(this.buffer)}update(t){ur(this);const{view:r,buffer:n,blockLen:i}=this;t=dn(t);const a=t.length;for(let u=0;u<a;){const f=Math.min(i-this.pos,a-u);if(f===i){const l=Cr(t);for(;i<=a-u;u+=i)this.process(l,u);continue}n.set(t.subarray(u,u+f),this.pos),this.pos+=f,u+=f,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ur(this),Ri(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:a}=this;let{pos:u}=this;r[u++]=128,this.buffer.subarray(u).fill(0),this.padOffset>i-u&&(this.process(n,0),u=0);for(let m=u;m<i;m++)r[m]=0;Eo(n,i-8,BigInt(this.length*8),a),this.process(n,0);const f=Cr(t),l=this.outputLen;if(l%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const b=l/4,g=this.get();if(b>g.length)throw new Error("_sha2: outputLen bigger than state");for(let m=0;m<b;m++)f.setUint32(4*m,g[m],a)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:n,length:i,finished:a,destroyed:u,pos:f}=this;return t.length=i,t.pos=f,t.finished=a,t.destroyed=u,i%r&&t.buffer.set(n),t}}const Ao=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Ye=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Je=new Uint32Array(64);class Ro extends Io{constructor(){super(64,32,8,!1),this.A=Ye[0]|0,this.B=Ye[1]|0,this.C=Ye[2]|0,this.D=Ye[3]|0,this.E=Ye[4]|0,this.F=Ye[5]|0,this.G=Ye[6]|0,this.H=Ye[7]|0}get(){const{A:t,B:r,C:n,D:i,E:a,F:u,G:f,H:l}=this;return[t,r,n,i,a,u,f,l]}set(t,r,n,i,a,u,f,l){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=a|0,this.F=u|0,this.G=f|0,this.H=l|0}process(t,r){for(let m=0;m<16;m++,r+=4)Je[m]=t.getUint32(r,!1);for(let m=16;m<64;m++){const v=Je[m-15],S=Je[m-2],I=Oe(v,7)^Oe(v,18)^v>>>3,R=Oe(S,17)^Oe(S,19)^S>>>10;Je[m]=R+Je[m-7]+I+Je[m-16]|0}let{A:n,B:i,C:a,D:u,E:f,F:l,G:b,H:g}=this;for(let m=0;m<64;m++){const v=Oe(f,6)^Oe(f,11)^Oe(f,25),S=g+v+Bo(f,l,b)+Ao[m]+Je[m]|0,R=(Oe(n,2)^Oe(n,13)^Oe(n,22))+So(n,i,a)|0;g=b,b=l,l=f,f=u+S|0,u=a,a=i,i=n,n=S+R|0}n=n+this.A|0,i=i+this.B|0,a=a+this.C|0,u=u+this.D|0,f=f+this.E|0,l=l+this.F|0,b=b+this.G|0,g=g+this.H|0,this.set(n,i,a,u,f,l,b,g)}roundClean(){Je.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const To=ki(()=>new Ro);function ko(e,t){return To(Wt(e,{strict:!1})?wi(e):e)}function Po(e){const{commitment:t,version:r=1}=e,n=e.to??(typeof t=="string"?"hex":"bytes"),i=ko(t);return i.set([r],0),n==="bytes"?i:Ze(i)}function Co(e){const{commitments:t,version:r}=e,n=e.to??(typeof t[0]=="string"?"hex":"bytes"),i=[];for(const a of t)i.push(Po({commitment:a,to:n,version:r}));return i}const Cn=6,Pi=32,pn=4096,Ci=Pi*pn,Ln=Ci*Cn-1-1*pn*Cn,Li=1;class Lo extends Z{constructor({maxSize:t,size:r}){super("Blob size is too large.",{metaMessages:[`Max: ${t} bytes`,`Given: ${r} bytes`],name:"BlobSizeTooLargeError"})}}class Oi extends Z{constructor(){super("Blob data must not be empty.",{name:"EmptyBlobError"})}}class Oo extends Z{constructor({hash:t,size:r}){super(`Versioned hash "${t}" size is invalid.`,{metaMessages:["Expected: 32",`Received: ${r}`],name:"InvalidVersionedHashSizeError"})}}class Fo extends Z{constructor({hash:t,version:r}){super(`Versioned hash "${t}" version is invalid.`,{metaMessages:[`Expected: ${Li}`,`Received: ${r}`],name:"InvalidVersionedHashVersionError"})}}function Uo(e){const t=e.to??(typeof e.data=="string"?"hex":"bytes"),r=typeof e.data=="string"?st(e.data):e.data,n=xt(r);if(!n)throw new Oi;if(n>Ln)throw new Lo({maxSize:Ln,size:n});const i=[];let a=!0,u=0;for(;a;){const f=Ei(new Uint8Array(Ci));let l=0;for(;l<pn;){const b=r.slice(u,u+(Pi-1));if(f.pushByte(0),f.pushBytes(b),b.length<31){f.pushByte(128),a=!1;break}l++,u+=31}i.push(f)}return t==="bytes"?i.map(f=>f.bytes):i.map(f=>Ze(f.bytes))}function No(e){const{data:t,kzg:r,to:n}=e,i=e.blobs??Uo({data:t,to:n}),a=e.commitments??Ii({blobs:i,kzg:r,to:n}),u=e.proofs??Ai({blobs:i,commitments:a,kzg:r,to:n}),f=[];for(let l=0;l<i.length;l++)f.push({blob:i[l],commitment:a[l],proof:u[l]});return f}function Mo(e){if(!e||e.length===0)return[];const t=[];for(const r of e){const{contractAddress:n,chainId:i,nonce:a,...u}=r;t.push([q(i),n,a?q(a):"0x",...Kt({},u)])}return t}class at extends Z{constructor({address:t}){super(`Address "${t}" is invalid.`,{metaMessages:["- Address must be a hex value of 20 bytes (40 hex characters).","- Address must match its checksum counterpart."],name:"InvalidAddressError"})}}class gr extends Z{constructor({chainId:t}){super(typeof t=="number"?`Chain ID "${t}" is invalid.`:"Chain ID is invalid.",{name:"InvalidChainIdError"})}}class mr extends Z{constructor({cause:t,maxFeePerGas:r}={}){super(`The fee cap (\`maxFeePerGas\`${r?` = ${Xr(r)} gwei`:""}) cannot be higher than the maximum allowed value (2^256-1).`,{cause:t,name:"FeeCapTooHighError"})}}Object.defineProperty(mr,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max fee per gas higher than 2\^256-1|fee cap higher than 2\^256-1/});class Fi extends Z{constructor({cause:t,maxPriorityFeePerGas:r,maxFeePerGas:n}={}){super([`The provided tip (\`maxPriorityFeePerGas\`${r?` = ${Xr(r)} gwei`:""}) cannot be higher than the fee cap (\`maxFeePerGas\`${n?` = ${Xr(n)} gwei`:""}).`].join(`
4
- `),{cause:t,name:"TipAboveFeeCapError"})}}Object.defineProperty(Fi,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max priority fee per gas higher than max fee per gas|tip higher than fee cap/});class Ui extends Map{constructor(t){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=t}get(t){const r=super.get(t);return super.has(t)&&r!==void 0&&(this.delete(t),super.set(t,r)),r}set(t,r){if(super.set(t,r),this.maxSize&&this.size>this.maxSize){const n=this.keys().next().value;n&&this.delete(n)}return this}}const tr=BigInt(2**32-1),On=BigInt(32);function Do(e,t=!1){return t?{h:Number(e&tr),l:Number(e>>On&tr)}:{h:Number(e>>On&tr)|0,l:Number(e&tr)|0}}function $o(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let i=0;i<e.length;i++){const{h:a,l:u}=Do(e[i],t);[r[i],n[i]]=[a,u]}return[r,n]}const Ho=(e,t,r)=>e<<r|t>>>32-r,zo=(e,t,r)=>t<<r|e>>>32-r,jo=(e,t,r)=>t<<r-32|e>>>64-r,Go=(e,t,r)=>e<<r-32|t>>>64-r,Ni=[],Mi=[],Di=[],qo=BigInt(0),Ct=BigInt(1),Wo=BigInt(2),Vo=BigInt(7),Ko=BigInt(256),Yo=BigInt(113);for(let e=0,t=Ct,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],Ni.push(2*(5*n+r)),Mi.push((e+1)*(e+2)/2%64);let i=qo;for(let a=0;a<7;a++)t=(t<<Ct^(t>>Vo)*Yo)%Ko,t&Wo&&(i^=Ct<<(Ct<<BigInt(a))-Ct);Di.push(i)}const[Jo,Xo]=$o(Di,!0),Fn=(e,t,r)=>r>32?jo(e,t,r):Ho(e,t,r),Un=(e,t,r)=>r>32?Go(e,t,r):zo(e,t,r);function Qo(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let u=0;u<10;u++)r[u]=e[u]^e[u+10]^e[u+20]^e[u+30]^e[u+40];for(let u=0;u<10;u+=2){const f=(u+8)%10,l=(u+2)%10,b=r[l],g=r[l+1],m=Fn(b,g,1)^r[f],v=Un(b,g,1)^r[f+1];for(let S=0;S<50;S+=10)e[u+S]^=m,e[u+S+1]^=v}let i=e[2],a=e[3];for(let u=0;u<24;u++){const f=Mi[u],l=Fn(i,a,f),b=Un(i,a,f),g=Ni[u];i=e[g],a=e[g+1],e[g]=l,e[g+1]=b}for(let u=0;u<50;u+=10){for(let f=0;f<10;f++)r[f]=e[u+f];for(let f=0;f<10;f++)e[u+f]^=~r[(f+2)%10]&r[(f+4)%10]}e[0]^=Jo[n],e[1]^=Xo[n]}r.fill(0)}class bn extends Ti{constructor(t,r,n,i=!1,a=24){if(super(),this.blockLen=t,this.suffix=r,this.outputLen=n,this.enableXOF=i,this.rounds=a,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,Tn(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=wo(this.state)}keccak(){kn||Pn(this.state32),Qo(this.state32,this.rounds),kn||Pn(this.state32),this.posOut=0,this.pos=0}update(t){ur(this);const{blockLen:r,state:n}=this;t=dn(t);const i=t.length;for(let a=0;a<i;){const u=Math.min(r-this.pos,i-a);for(let f=0;f<u;f++)n[this.pos++]^=t[a++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:r,pos:n,blockLen:i}=this;t[n]^=r,r&128&&n===i-1&&this.keccak(),t[i-1]^=128,this.keccak()}writeInto(t){ur(this,!1),hn(t),this.finish();const r=this.state,{blockLen:n}=this;for(let i=0,a=t.length;i<a;){this.posOut>=n&&this.keccak();const u=Math.min(n-this.posOut,a-i);t.set(r.subarray(this.posOut,this.posOut+u),i),this.posOut+=u,i+=u}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return Tn(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(Ri(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:r,suffix:n,outputLen:i,rounds:a,enableXOF:u}=this;return t||(t=new bn(r,n,i,u,a)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=a,t.suffix=n,t.outputLen=i,t.enableXOF=u,t.destroyed=this.destroyed,t}}const Zo=(e,t,r)=>ki(()=>new bn(t,e,r)),ea=Zo(1,136,256/8);function ta(e,t){return ea(Wt(e,{strict:!1})?wi(e):e)}const Lr=new Ui(8192);function ra(e,t){if(Lr.has(`${e}.${t}`))return Lr.get(`${e}.${t}`);const r=e.substring(2).toLowerCase(),n=ta(xi(r)),i=r.split("");for(let u=0;u<40;u+=2)n[u>>1]>>4>=8&&i[u]&&(i[u]=i[u].toUpperCase()),(n[u>>1]&15)>=8&&i[u+1]&&(i[u+1]=i[u+1].toUpperCase());const a=`0x${i.join("")}`;return Lr.set(`${e}.${t}`,a),a}const na=/^0x[a-fA-F0-9]{40}$/,Or=new Ui(8192);function ft(e,t){const{strict:r=!0}=t??{},n=`${e}.${r}`;if(Or.has(n))return Or.get(n);const i=na.test(e)?e.toLowerCase()===e?!0:r?ra(e)===e:!0:!1;return Or.set(n,i),i}function ia(e,t,r,{strict:n}={}){return Wt(e,{strict:!1})?oa(e,t,r,{strict:n}):sa(e,t,r,{strict:n})}function $i(e,t,r){if(xt(e)!==r-t)throw new js({offset:r,position:"end",size:xt(e)})}function sa(e,t,r,{strict:n}={}){const i=e.slice(t,r);return n&&$i(i,t,r),i}function oa(e,t,r,{strict:n}={}){const i=`0x${e.replace("0x","").slice(t*2,r*2)}`;return n&&$i(i,t,r),i}function aa(e){const{authorizationList:t}=e;if(t)for(const r of t){const{contractAddress:n,chainId:i}=r;if(!ft(n))throw new at({address:n});if(i<=0)throw new gr({chainId:i})}yn(e)}function fa(e){const{blobVersionedHashes:t}=e;if(t){if(t.length===0)throw new Oi;for(const r of t){const n=xt(r),i=fr(ia(r,0,1));if(n!==32)throw new Oo({hash:r,size:n});if(i!==Li)throw new Fo({hash:r,version:i})}}yn(e)}function yn(e){const{chainId:t,maxPriorityFeePerGas:r,maxFeePerGas:n,to:i}=e;if(t<=0)throw new gr({chainId:t});if(i&&!ft(i))throw new at({address:i});if(n&&n>ln)throw new mr({maxFeePerGas:n});if(r&&n&&r>n)throw new Fi({maxFeePerGas:n,maxPriorityFeePerGas:r})}function ua(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:a}=e;if(t<=0)throw new gr({chainId:t});if(a&&!ft(a))throw new at({address:a});if(r||i)throw new Z("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");if(n&&n>ln)throw new mr({maxFeePerGas:n})}function ca(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:a}=e;if(a&&!ft(a))throw new at({address:a});if(typeof t<"u"&&t<=0)throw new gr({chainId:t});if(r||i)throw new Z("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");if(n&&n>ln)throw new mr({maxFeePerGas:n})}function la(e){if(e.type)return e.type;if(typeof e.authorizationList<"u")return"eip7702";if(typeof e.blobs<"u"||typeof e.blobVersionedHashes<"u"||typeof e.maxFeePerBlobGas<"u"||typeof e.sidecars<"u")return"eip4844";if(typeof e.maxFeePerGas<"u"||typeof e.maxPriorityFeePerGas<"u")return"eip1559";if(typeof e.gasPrice<"u")return typeof e.accessList<"u"?"eip2930":"legacy";throw new go({transaction:e})}function _r(e){if(!e||e.length===0)return[];const t=[];for(let r=0;r<e.length;r++){const{address:n,storageKeys:i}=e[r];for(let a=0;a<i.length;a++)if(i[a].length-2!==64)throw new mo({storageKey:i[a]});if(!ft(n,{strict:!1}))throw new at({address:n});t.push([n,i])}return t}function ha(e,t){const r=la(e);return r==="eip1559"?ba(e,t):r==="eip2930"?ya(e,t):r==="eip4844"?pa(e,t):r==="eip7702"?da(e,t):ga(e,t)}function da(e,t){const{authorizationList:r,chainId:n,gas:i,nonce:a,to:u,value:f,maxFeePerGas:l,maxPriorityFeePerGas:b,accessList:g,data:m}=e;aa(e);const v=_r(g),S=Mo(r);return Vt(["0x04",ot([q(n),a?q(a):"0x",b?q(b):"0x",l?q(l):"0x",i?q(i):"0x",u??"0x",f?q(f):"0x",m??"0x",v,S,...Kt(e,t)])])}function pa(e,t){const{chainId:r,gas:n,nonce:i,to:a,value:u,maxFeePerBlobGas:f,maxFeePerGas:l,maxPriorityFeePerGas:b,accessList:g,data:m}=e;fa(e);let v=e.blobVersionedHashes,S=e.sidecars;if(e.blobs&&(typeof v>"u"||typeof S>"u")){const O=typeof e.blobs[0]=="string"?e.blobs:e.blobs.map(B=>Ze(B)),L=e.kzg,U=Ii({blobs:O,kzg:L});if(typeof v>"u"&&(v=Co({commitments:U})),typeof S>"u"){const B=Ai({blobs:O,commitments:U,kzg:L});S=No({blobs:O,commitments:U,proofs:B})}}const I=_r(g),R=[q(r),i?q(i):"0x",b?q(b):"0x",l?q(l):"0x",n?q(n):"0x",a??"0x",u?q(u):"0x",m??"0x",I,f?q(f):"0x",v??[],...Kt(e,t)],k=[],C=[],F=[];if(S)for(let O=0;O<S.length;O++){const{blob:L,commitment:U,proof:B}=S[O];k.push(L),C.push(U),F.push(B)}return Vt(["0x03",ot(S?[R,k,C,F]:R)])}function ba(e,t){const{chainId:r,gas:n,nonce:i,to:a,value:u,maxFeePerGas:f,maxPriorityFeePerGas:l,accessList:b,data:g}=e;yn(e);const m=_r(b),v=[q(r),i?q(i):"0x",l?q(l):"0x",f?q(f):"0x",n?q(n):"0x",a??"0x",u?q(u):"0x",g??"0x",m,...Kt(e,t)];return Vt(["0x02",ot(v)])}function ya(e,t){const{chainId:r,gas:n,data:i,nonce:a,to:u,value:f,accessList:l,gasPrice:b}=e;ua(e);const g=_r(l),m=[q(r),a?q(a):"0x",b?q(b):"0x",n?q(n):"0x",u??"0x",f?q(f):"0x",i??"0x",g,...Kt(e,t)];return Vt(["0x01",ot(m)])}function ga(e,t){const{chainId:r=0,gas:n,data:i,nonce:a,to:u,value:f,gasPrice:l}=e;ca(e);let b=[a?q(a):"0x",l?q(l):"0x",n?q(n):"0x",u??"0x",f?q(f):"0x",i??"0x"];if(t){const g=(()=>{if(t.v>=35n)return(t.v-35n)/2n>0?t.v:27n+(t.v===35n?0n:1n);if(r>0)return BigInt(r*2)+BigInt(35n+t.v-27n);const S=27n+(t.v===27n?0n:1n);if(t.v!==S)throw new yo({v:t.v});return S})(),m=ar(t.r),v=ar(t.s);b=[...b,q(g),m==="0x00"?"0x":m,v==="0x00"?"0x":v]}else r>0&&(b=[...b,q(r),"0x","0x"]);return ot(b)}function Kt(e,t){const r=t??e,{v:n,yParity:i}=r;if(typeof r.r>"u")return[];if(typeof r.s>"u")return[];if(typeof n>"u"&&typeof i>"u")return[];const a=ar(r.r),u=ar(r.s);return[typeof i=="number"?i?q(1):"0x":n===0n?"0x":n===1n?q(1):n===27n?"0x":q(1),a==="0x00"?"0x":a,u==="0x00"?"0x":u]}const ma={gasPriceOracle:{address:"0x420000000000000000000000000000000000000F"},l1Block:{address:"0x4200000000000000000000000000000000000015"},l2CrossDomainMessenger:{address:"0x4200000000000000000000000000000000000007"},l2Erc721Bridge:{address:"0x4200000000000000000000000000000000000014"},l2StandardBridge:{address:"0x4200000000000000000000000000000000000010"},l2ToL1MessagePasser:{address:"0x4200000000000000000000000000000000000016"}},_a={block:ro({format(e){var r;return{transactions:(r=e.transactions)==null?void 0:r.map(n=>{if(typeof n=="string")return n;const i=cn(n);return i.typeHex==="0x7e"&&(i.isSystemTx=n.isSystemTx,i.mint=n.mint?gt(n.mint):void 0,i.sourceHash=n.sourceHash,i.type="deposit"),i}),stateRoot:e.stateRoot}}}),transaction:Zs({format(e){const t={};return e.type==="0x7e"&&(t.isSystemTx=e.isSystemTx,t.mint=e.mint?gt(e.mint):void 0,t.sourceHash=e.sourceHash,t.type="deposit"),t}}),transactionReceipt:oo({format(e){return{l1GasPrice:e.l1GasPrice?gt(e.l1GasPrice):null,l1GasUsed:e.l1GasUsed?gt(e.l1GasUsed):null,l1Fee:e.l1Fee?gt(e.l1Fee):null,l1FeeScalar:e.l1FeeScalar?Number(e.l1FeeScalar):null}}})};function wa(e,t){return Ea(e)?va(e):ha(e,t)}const xa={transaction:wa};function va(e){Ba(e);const{sourceHash:t,data:r,from:n,gas:i,isSystemTx:a,mint:u,to:f,value:l}=e,b=[t,n,f??"0x",u?q(u):"0x",l?q(l):"0x",i?q(i):"0x",a?"0x1":"0x",r??"0x"];return Vt(["0x7e",ot(b)])}function Ea(e){return e.type==="deposit"||typeof e.sourceHash<"u"}function Ba(e){const{from:t,to:r}=e;if(t&&!ft(t))throw new at({address:t});if(r&&!ft(r))throw new at({address:r})}const Nn={contracts:ma,formatters:_a,serializers:xa},Sa=qt({id:42161,name:"Arbitrum One",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://arb1.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://arbiscan.io",apiUrl:"https://api.arbiscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:7654707}}}),Ia=qt({id:421614,name:"Arbitrum Sepolia",nativeCurrency:{name:"Arbitrum Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia-rollup.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://sepolia.arbiscan.io",apiUrl:"https://api-sepolia.arbiscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:81930}},testnet:!0}),Lt=11155111,Aa=qt({...Nn,id:84532,network:"base-sepolia",name:"Base Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia.base.org"]}},blockExplorers:{default:{name:"Basescan",url:"https://sepolia.basescan.org",apiUrl:"https://api-sepolia.basescan.org/api"}},contracts:{...Nn.contracts,disputeGameFactory:{[Lt]:{address:"0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"}},l2OutputOracle:{[Lt]:{address:"0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"}},portal:{[Lt]:{address:"0x49f53e41452c74589e85ca1677426ba426459e85",blockCreated:4446677}},l1StandardBridge:{[Lt]:{address:"0xfd0Bf71F60660E2f608ed56e1659C450eB113120",blockCreated:4446677}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:1059647}},testnet:!0,sourceId:Lt}),Ra=qt({id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://cloudflare-eth.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io",apiUrl:"https://api.etherscan.io/api"}},contracts:{ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xce01f8eee7E479C928F8919abD53E553a36CeF67",blockCreated:19258213},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:14353601}}}),Ta=qt({id:11155111,name:"Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc2.sepolia.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io",apiUrl:"https://api-sepolia.etherscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:751532},ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xc8Af999e38273D658BE1b921b88A9Ddf005769cC",blockCreated:5317080}},testnet:!0});function Qr(e){return typeof e=="string"&&(e=Buffer.from(e,"hex")),e.length===32?e:e.subarray(1,33)}function bt(e,t){if(!e)throw new Error(t)}function ka(e){return Buffer.concat([Uint8Array.from([192]),Pa(e)])}function Pa(e){const t=In.encodingLength(e.length),r=Buffer.allocUnsafe(t);return In.encode(e.length,r),Buffer.concat([r,e])}function Ca(e,t){if(e.compare(t)>0){const r=e;e=t,t=r}return[e,t]}const Ot=e=>e.length===64?e:e.slice(2),La=e=>{if(!e)return!1;try{const t=Buffer.from(e,"hex");return wt.isPoint(t)}catch{return!1}},Oa={ethereum:Ra,ethereum_arbitrum:Sa,ethereum_sepolia:Ta,arbitrum_sepolia:Ia,ethereum_localnet:J.EthereumLocalnet,arbitrum_localnet:J.ArbitrumLocalnet,base_sepolia:Aa},Fa=async(e,t)=>{var n;const r=Oa[e];if(r)try{if(r.id===((n=t.chain)==null?void 0:n.id))return P.Ok({message:"Already on the network",walletClient:t});await t.switchChain({id:r.id});const i=He.createWalletClient({account:t.account,chain:r,transport:He.custom(window.ethereum)});return P.Ok({message:"Switched chain",walletClient:i})}catch(i){if(Ua(i))try{await t.addChain({chain:r});const a=He.createWalletClient({account:t.account,chain:r,transport:He.custom(window.ethereum)});return P.Ok({message:"Added network",walletClient:a})}catch{return P.Err("Failed to add network")}else return P.Err("Failed to switch network")}else return P.Err("Chain not supported")},Ua=e=>typeof e=="object"&&e!==null&&"code"in e&&e.code===4902,Hi=(e,t,r,n)=>e+":"+t.toLowerCase()+"::"+r+":"+n.toLowerCase();var ne=(e=>(e.Created="Created",e.Matched="Matched",e.InitiateDetected="InitiateDetected",e.Initiated="Initiated",e.CounterPartyInitiateDetected="CounterPartyInitiateDetected",e.CounterPartyInitiated="CounterPartyInitiated",e.RedeemDetected="RedeemDetected",e.Redeemed="Redeemed",e.CounterPartyRedeemDetected="CounterPartyRedeemDetected",e.CounterPartyRedeemed="CounterPartyRedeemed",e.Completed="Completed",e.CounterPartySwapExpired="CounterPartySwapExpired",e.Expired="Expired",e.RefundDetected="RefundDetected",e.Refunded="Refunded",e.CounterPartyRefundDetected="CounterPartyRefundDetected",e.CounterPartyRefunded="CounterPartyRefunded",e.Cancelled="Cancelled",e.DeadLineExceeded="DeadLineExceeded",e))(ne||{}),Q=(e=>(e.Idle="Idle",e.InitiateDetected="InitiateDetected",e.Initiated="Initiated",e.RedeemDetected="RedeemDetected",e.Redeemed="Redeemed",e.RefundDetected="RefundDetected",e.Refunded="Refunded",e.Expired="Expired",e))(Q||{});const zi=(e,t,r)=>{const n=cr(e.source_swap,t),i=cr(e.destination_swap,r);if(i===Q.RedeemDetected)return ne.RedeemDetected;if(n===Q.Redeemed)return ne.CounterPartyRedeemed;if(n===Q.RedeemDetected)return ne.CounterPartyRedeemDetected;if(i===Q.Redeemed)return ne.Redeemed;if(n===Q.Refunded)return ne.Refunded;if(n===Q.RefundDetected)return ne.RefundDetected;if(i===Q.Refunded)return ne.CounterPartyRefunded;if(i===Q.RefundDetected)return ne.CounterPartyRefundDetected;if(i===Q.Expired)return ne.CounterPartySwapExpired;if(n===Q.Expired)return ne.Expired;const a=Number(e.create_order.additional_data.deadline);return i===Q.Initiated?ne.CounterPartyInitiated:i===Q.InitiateDetected?ne.CounterPartyInitiateDetected:zt(a,12)?ne.DeadLineExceeded:n===Q.Initiated?ne.Initiated:zt(a,1)?ne.DeadLineExceeded:n===Q.InitiateDetected?ne.InitiateDetected:ne.Matched},cr=(e,t)=>{if(e.redeem_tx_hash)return Number(e.redeem_block_number)?Q.Redeemed:Q.RedeemDetected;if(e.refund_tx_hash)return Number(e.refund_block_number)?Q.Refunded:Q.RefundDetected;if(Number(e.initiate_block_number)){const r=Number(e.initiate_block_number)+e.timelock;if(t>r)return Q.Expired}return e.initiate_tx_hash?Number(e.initiate_block_number)?Q.Initiated:Q.InitiateDetected:Q.Idle},ji=(e,t,r)=>{switch(zi(e,t,r)){case ne.Matched:return ue.Initiate;case ne.CounterPartyInitiated:case ne.CounterPartyInitiateDetected:case ne.RedeemDetected:return ue.Redeem;case ne.Expired:return ue.Refund;default:return ue.Idle}},zt=(e,t=0)=>{const r=Date.now(),n=e*1e3+t*36e5;return r>=n},Gi=e=>e.filter(t=>{const{source_swap:r,create_order:n}=t,{initiate_tx_hash:i,initiate_block_number:a}=r,{deadline:u}=n.additional_data;return i&&Number(a)?!0:i&&!Number(a)?!zt(Number(u),12):i?!0:!zt(Number(u),1)}),Na=[{inputs:[{internalType:"address",name:"token_",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"InvalidShortString",type:"error"},{inputs:[{internalType:"string",name:"str",type:"string"}],name:"StringTooLong",type:"error"},{anonymous:!1,inputs:[],name:"EIP712DomainChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"secretHash",type:"bytes32"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"}],name:"Initiated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"secretHash",type:"bytes32"},{indexed:!1,internalType:"bytes",name:"secret",type:"bytes"}],name:"Redeemed",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"}],name:"Refunded",type:"event"},{inputs:[],name:"eip712Domain",outputs:[{internalType:"bytes1",name:"fields",type:"bytes1"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"},{internalType:"uint256",name:"chainId",type:"uint256"},{internalType:"address",name:"verifyingContract",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"uint256[]",name:"extensions",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"}],name:"initiate",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"initiateWithSignature",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"instantRefund",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"expiry",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],internalType:"struct HTLC.InitWithSig[]",name:"inits",type:"tuple[]"},{components:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"secret",type:"bytes"}],internalType:"struct HTLC.Redeem[]",name:"redeems",type:"tuple[]"},{components:[{internalType:"bytes32",name:"orderID",type:"bytes32"}],internalType:"struct HTLC.Refund[]",name:"refunds",type:"tuple[]"}],name:"multicall",outputs:[{internalType:"bool[]",name:"results",type:"bool[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"}],name:"orders",outputs:[{internalType:"bool",name:"isFulfilled",type:"bool"},{internalType:"address",name:"initiator",type:"address"},{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"initiatedAt",type:"uint256"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"secret",type:"bytes"}],name:"redeem",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"}],name:"refund",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"token",outputs:[{internalType:"contract IERC20",name:"",type:"address"}],stateMutability:"view",type:"function"}];class qi{constructor(t,r,n){this.url=new ge.Url("/relayer",r),this.auth=n,this.order=t}async init(t,r){if(!t.account)return P.Err("No account found");if(t.account.address.toLowerCase()!==this.order.source_swap.initiator.toLowerCase())return P.Err("Account address and order initiator mismatch");if(!r){const g=await ge.fetchEVMBlockNumber(t);if(g.error)return P.Err(g.error);r=g.val}if(cr(this.order.source_swap,r)!==Q.Idle)return P.Err("Invalid swap status");const{create_order:i,source_swap:a}=this.order;if(!a.amount||!a.redeemer||!i.timelock||!i.secret_hash)return P.Err("Invalid order");const u=ge.with0x(i.secret_hash),f=BigInt(i.timelock),l=ge.with0x(a.redeemer),b=BigInt(a.amount);try{const g=await this.auth.getToken();if(g.error)return P.Err(g.error);const m=He.getContract({address:ge.with0x(this.order.source_swap.asset),abi:Na,client:t}),v=await m.read.token(),S=await ge.checkAllowanceAndApprove(Number(b),v,this.order.source_swap.asset,t);if(S.error)return P.Err(S.error);const I=await m.read.eip712Domain(),R=await t.signTypedData({account:t.account,domain:{name:I[1],version:I[2],chainId:Number(I[3]),verifyingContract:I[4]},types:{Initiate:[{name:"redeemer",type:"address"},{name:"timelock",type:"uint256"},{name:"amount",type:"uint256"},{name:"secretHash",type:"bytes32"}]},primaryType:"Initiate",message:{redeemer:l,timelock:f,amount:b,secretHash:u}}),k=await P.Fetcher.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:i.create_id,signature:R,perform_on:"Source"}),headers:{Authorization:ge.Authorization(g.val),"Content-Type":"application/json"}});return k.error?P.Err(k.error):k.result?P.Ok(k.result):P.Err("Init: No result found")}catch(g){return console.log("init error :",g),P.Err(String(g))}}async redeem(t,r){try{const n=await this.auth.getToken();if(n.error)return P.Err(n.error);const i=await P.Fetcher.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t,secret:P.trim0x(r),perform_on:"Destination"}),headers:{Authorization:ge.Authorization(n.val),"Content-Type":"application/json"}});return i.error?P.Err(i.error):i.result?P.Ok(i.result):P.Err("Redeem: No result found")}catch(n){return P.Err(String(n))}}}const Ma=Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),Da=Buffer.from("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8","hex"),$a=Buffer.concat([Ma,Da]),Ha=Buffer.from("0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0","hex"),Mn={failedToCreateInternalPubkey:"failed to create internal pubkey",failedToTweakPubkey:"failed to tweak pubkey"};function za(){const e=bi.crypto.sha256(Buffer.from("GardenHTLC","utf-8")),t=wt.pointMultiply(Buffer.concat([Buffer.from("04","hex"),$a]),e);if(!t)throw new Error(Mn.failedToCreateInternalPubkey);const r=wt.pointAdd(Ha,t);if(!r)throw new Error(Mn.failedToCreateInternalPubkey);return Qr(Buffer.from(r))}const _e={secretMismatch:"invalid secret",secretHashLenMismatch:"secret hash should be 32 bytes",pubkeyLenMismatch:"pubkey should be 32 bytes",zeroOrNegativeExpiry:"expiry should be greater than 0",htlcAddressGenerationFailed:"failed to generate htlc address",notFunded:"address not funded",noCounterpartySigs:"counterparty signatures are required",counterPartySigNotFound:e=>"counterparty signature not found for utxo "+e,invalidCounterpartySigForUTXO:e=>"invalid counterparty signature for utxo "+e,htlcNotExpired:e=>`HTLC not expired, need more ${e} blocks`,controlBlockGenerationFailed:"failed to generate control block",invalidLeaf:"invalid leaf"},rr=192;ye.initEccLib(wt);class lr{constructor(t,r,n,i,a,u,f,l){this.secretHash=n,this.redeemerPubkey=i,this.initiatorPubkey=a,this.expiry=u,this.signer=t,this.network=f,this.internalPubkey=za(),this.initiateAmount=r,this.utxoHashes=l}static async from(t,r,n,i,a,u,f){n=n.startsWith("0x")?n.slice(2):n,bt(n.length===64,_e.secretHashLenMismatch),bt(i.length===64||i.length===66,`initiator ${_e.pubkeyLenMismatch}`),bt(a.length===64||a.length===66,`redeemer ${_e.pubkeyLenMismatch}`),bt(u>0,_e.zeroOrNegativeExpiry);const l=await t.getNetwork();return new lr(t,r,n,Qr(a).toString("hex"),Qr(i).toString("hex"),u,l,f)}address(){const{address:t}=ye.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves()});if(!t)throw new Error(_e.htlcAddressGenerationFailed);return t}id(){return this.address()}async _buildRawTx(t,r){const n=new ye.Transaction;n.version=2;const i=this.address(),a=await this.signer.getProvider();let u=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const l of this.utxoHashes){const b=await a.getTransaction(l);for(let g=0;g<b.vout.length;g++){const m=b.vout[g];m.scriptpubkey_address===i&&u.push({txid:b.txid,vout:g,value:m.value,status:{confirmed:!1}})}}else u=await a.getUTXOs(i);const f=u.reduce((l,b)=>l+b.value,0);if(f===0)throw new Error(`${i} ${_e.notFunded}`);for(let l=0;l<u.length;l++)n.addInput(Buffer.from(u[l].txid,"hex").reverse(),u[l].vout);return r??(r=await a.suggestFee(i,f,Sn.Urgency.MEDIUM)),n.addOutput(ye.address.toOutputScript(t,this.network),f-r),{tx:n,usedUtxos:u}}async buildRawTx(t){return await this._buildRawTx(await this.signer.getAddress(),t)}getOutputScript(){return ye.address.toOutputScript(this.address(),this.network)}async init(t){return t??(t=await(await this.signer.getProvider()).suggestFee(await this.signer.getAddress(),this.initiateAmount,Sn.Urgency.MEDIUM)),await this.signer.send(this.address(),this.initiateAmount,t)}async instantRefund(t,r){bt(t.length>0,_e.noCounterpartySigs);const{tx:n,usedUtxos:i}=await this.buildRawTx(r);for(const m of i)if(!t.find(v=>v.utxo===m.txid))throw new Error(_e.counterPartySigNotFound(m.txid));const a=this.getOutputScript(),u=ye.Transaction.SIGHASH_DEFAULT,f=this.leafHash(2),l=i.map(m=>m.value),b=Fr(a,i.length);for(let m=0;m<n.ins.length;m++){const v=n.hashForWitnessV1(m,b,l,u,f);if(!wt.verifySchnorr(v,Buffer.from(this.redeemerPubkey,"hex"),Buffer.from(t[m].sig,"hex")))throw new Error(_e.invalidCounterpartySigForUTXO(t[m].utxo));const S=await this.signer.signSchnorr(v),I=Buffer.from(n.ins[m].hash).reverse().toString("hex"),R=t.find(k=>k.utxo===I);if(!R)throw new Error(_e.counterPartySigNotFound(I));n.setWitness(m,[Buffer.from(R.sig,"hex"),S,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async redeem(t,r,n){bt(ye.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,_e.secretMismatch);const{tx:i,usedUtxos:a}=await this._buildRawTx(r??await this.signer.getAddress(),n),u=this.leafHash(1),f=a.map(m=>m.value),l=Fr(this.getOutputScript(),a.length),b=ye.Transaction.SIGHASH_DEFAULT;for(let m=0;m<i.ins.length;m++){const v=i.hashForWitnessV1(m,l,f,b,u),S=await this.signer.signSchnorr(v);i.setWitness(m,[S,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return await(await this.signer.getProvider()).broadcast(i.toHex())}async refund(t,r){const{tx:n,usedUtxos:i}=await this._buildRawTx(t??await this.signer.getAddress(),r),[a,u]=await this.canRefund(i);if(!a)throw new Error(_e.htlcNotExpired(u));const f=this.leafHash(0),l=i.map(v=>v.value),b=Fr(this.getOutputScript(),i.length),g=ye.Transaction.SIGHASH_DEFAULT;for(let v=0;v<n.ins.length;v++){n.ins[v].sequence=this.expiry;const S=n.hashForWitnessV1(v,b,l,g,f),I=await this.signer.signSchnorr(S);n.setWitness(v,[I,this.refundLeaf(),this.generateControlBlockFor(0)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async canRefund(t){const n=await(await this.signer.getProvider()).getLatestTip();for(const i of t){let a=0;if(i.status.confirmed&&i.status.block_height+this.expiry>n?a=i.status.block_height+this.expiry-n+1:i.status.confirmed||(a=this.expiry+1),a>0)return[!1,a]}return[!0,0]}generateControlBlockFor(t){let r;switch(t){case 1:r=this.redeemLeaf();break;case 0:r=this.refundLeaf();break;case 2:r=this.instantRefundLeaf();break;default:throw new Error(_e.invalidLeaf)}const n=ye.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves(),redeem:{output:r,redeemVersion:rr}});if(!n.witness)throw new Error(_e.controlBlockGenerationFailed);return n.witness[n.witness.length-1]}leafHash(t){let r=this.redeemLeaf();return t===0&&(r=this.refundLeaf()),t===2&&(r=this.instantRefundLeaf()),ye.crypto.taggedHash("TapLeaf",ka(r))}refundLeaf(){return ye.script.fromASM(`
4
+ `),{cause:t,name:"TipAboveFeeCapError"})}}Object.defineProperty(Fi,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max priority fee per gas higher than max fee per gas|tip higher than fee cap/});class Ui extends Map{constructor(t){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=t}get(t){const r=super.get(t);return super.has(t)&&r!==void 0&&(this.delete(t),super.set(t,r)),r}set(t,r){if(super.set(t,r),this.maxSize&&this.size>this.maxSize){const n=this.keys().next().value;n&&this.delete(n)}return this}}const tr=BigInt(2**32-1),On=BigInt(32);function Do(e,t=!1){return t?{h:Number(e&tr),l:Number(e>>On&tr)}:{h:Number(e>>On&tr)|0,l:Number(e&tr)|0}}function $o(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let i=0;i<e.length;i++){const{h:a,l:u}=Do(e[i],t);[r[i],n[i]]=[a,u]}return[r,n]}const Ho=(e,t,r)=>e<<r|t>>>32-r,zo=(e,t,r)=>t<<r|e>>>32-r,jo=(e,t,r)=>t<<r-32|e>>>64-r,Go=(e,t,r)=>e<<r-32|t>>>64-r,Ni=[],Mi=[],Di=[],qo=BigInt(0),Ct=BigInt(1),Wo=BigInt(2),Vo=BigInt(7),Ko=BigInt(256),Yo=BigInt(113);for(let e=0,t=Ct,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],Ni.push(2*(5*n+r)),Mi.push((e+1)*(e+2)/2%64);let i=qo;for(let a=0;a<7;a++)t=(t<<Ct^(t>>Vo)*Yo)%Ko,t&Wo&&(i^=Ct<<(Ct<<BigInt(a))-Ct);Di.push(i)}const[Jo,Xo]=$o(Di,!0),Fn=(e,t,r)=>r>32?jo(e,t,r):Ho(e,t,r),Un=(e,t,r)=>r>32?Go(e,t,r):zo(e,t,r);function Qo(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let u=0;u<10;u++)r[u]=e[u]^e[u+10]^e[u+20]^e[u+30]^e[u+40];for(let u=0;u<10;u+=2){const f=(u+8)%10,l=(u+2)%10,b=r[l],g=r[l+1],m=Fn(b,g,1)^r[f],v=Un(b,g,1)^r[f+1];for(let S=0;S<50;S+=10)e[u+S]^=m,e[u+S+1]^=v}let i=e[2],a=e[3];for(let u=0;u<24;u++){const f=Mi[u],l=Fn(i,a,f),b=Un(i,a,f),g=Ni[u];i=e[g],a=e[g+1],e[g]=l,e[g+1]=b}for(let u=0;u<50;u+=10){for(let f=0;f<10;f++)r[f]=e[u+f];for(let f=0;f<10;f++)e[u+f]^=~r[(f+2)%10]&r[(f+4)%10]}e[0]^=Jo[n],e[1]^=Xo[n]}r.fill(0)}class bn extends Ti{constructor(t,r,n,i=!1,a=24){if(super(),this.blockLen=t,this.suffix=r,this.outputLen=n,this.enableXOF=i,this.rounds=a,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,Tn(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=wo(this.state)}keccak(){kn||Pn(this.state32),Qo(this.state32,this.rounds),kn||Pn(this.state32),this.posOut=0,this.pos=0}update(t){ur(this);const{blockLen:r,state:n}=this;t=dn(t);const i=t.length;for(let a=0;a<i;){const u=Math.min(r-this.pos,i-a);for(let f=0;f<u;f++)n[this.pos++]^=t[a++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:r,pos:n,blockLen:i}=this;t[n]^=r,r&128&&n===i-1&&this.keccak(),t[i-1]^=128,this.keccak()}writeInto(t){ur(this,!1),hn(t),this.finish();const r=this.state,{blockLen:n}=this;for(let i=0,a=t.length;i<a;){this.posOut>=n&&this.keccak();const u=Math.min(n-this.posOut,a-i);t.set(r.subarray(this.posOut,this.posOut+u),i),this.posOut+=u,i+=u}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return Tn(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(Ri(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:r,suffix:n,outputLen:i,rounds:a,enableXOF:u}=this;return t||(t=new bn(r,n,i,u,a)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=a,t.suffix=n,t.outputLen=i,t.enableXOF=u,t.destroyed=this.destroyed,t}}const Zo=(e,t,r)=>ki(()=>new bn(t,e,r)),ea=Zo(1,136,256/8);function ta(e,t){return ea(Wt(e,{strict:!1})?wi(e):e)}const Lr=new Ui(8192);function ra(e,t){if(Lr.has(`${e}.${t}`))return Lr.get(`${e}.${t}`);const r=e.substring(2).toLowerCase(),n=ta(xi(r)),i=r.split("");for(let u=0;u<40;u+=2)n[u>>1]>>4>=8&&i[u]&&(i[u]=i[u].toUpperCase()),(n[u>>1]&15)>=8&&i[u+1]&&(i[u+1]=i[u+1].toUpperCase());const a=`0x${i.join("")}`;return Lr.set(`${e}.${t}`,a),a}const na=/^0x[a-fA-F0-9]{40}$/,Or=new Ui(8192);function ft(e,t){const{strict:r=!0}=t??{},n=`${e}.${r}`;if(Or.has(n))return Or.get(n);const i=na.test(e)?e.toLowerCase()===e?!0:r?ra(e)===e:!0:!1;return Or.set(n,i),i}function ia(e,t,r,{strict:n}={}){return Wt(e,{strict:!1})?oa(e,t,r,{strict:n}):sa(e,t,r,{strict:n})}function $i(e,t,r){if(xt(e)!==r-t)throw new js({offset:r,position:"end",size:xt(e)})}function sa(e,t,r,{strict:n}={}){const i=e.slice(t,r);return n&&$i(i,t,r),i}function oa(e,t,r,{strict:n}={}){const i=`0x${e.replace("0x","").slice(t*2,r*2)}`;return n&&$i(i,t,r),i}function aa(e){const{authorizationList:t}=e;if(t)for(const r of t){const{contractAddress:n,chainId:i}=r;if(!ft(n))throw new at({address:n});if(i<=0)throw new gr({chainId:i})}yn(e)}function fa(e){const{blobVersionedHashes:t}=e;if(t){if(t.length===0)throw new Oi;for(const r of t){const n=xt(r),i=fr(ia(r,0,1));if(n!==32)throw new Oo({hash:r,size:n});if(i!==Li)throw new Fo({hash:r,version:i})}}yn(e)}function yn(e){const{chainId:t,maxPriorityFeePerGas:r,maxFeePerGas:n,to:i}=e;if(t<=0)throw new gr({chainId:t});if(i&&!ft(i))throw new at({address:i});if(n&&n>ln)throw new mr({maxFeePerGas:n});if(r&&n&&r>n)throw new Fi({maxFeePerGas:n,maxPriorityFeePerGas:r})}function ua(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:a}=e;if(t<=0)throw new gr({chainId:t});if(a&&!ft(a))throw new at({address:a});if(r||i)throw new Z("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");if(n&&n>ln)throw new mr({maxFeePerGas:n})}function ca(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:a}=e;if(a&&!ft(a))throw new at({address:a});if(typeof t<"u"&&t<=0)throw new gr({chainId:t});if(r||i)throw new Z("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");if(n&&n>ln)throw new mr({maxFeePerGas:n})}function la(e){if(e.type)return e.type;if(typeof e.authorizationList<"u")return"eip7702";if(typeof e.blobs<"u"||typeof e.blobVersionedHashes<"u"||typeof e.maxFeePerBlobGas<"u"||typeof e.sidecars<"u")return"eip4844";if(typeof e.maxFeePerGas<"u"||typeof e.maxPriorityFeePerGas<"u")return"eip1559";if(typeof e.gasPrice<"u")return typeof e.accessList<"u"?"eip2930":"legacy";throw new go({transaction:e})}function _r(e){if(!e||e.length===0)return[];const t=[];for(let r=0;r<e.length;r++){const{address:n,storageKeys:i}=e[r];for(let a=0;a<i.length;a++)if(i[a].length-2!==64)throw new mo({storageKey:i[a]});if(!ft(n,{strict:!1}))throw new at({address:n});t.push([n,i])}return t}function ha(e,t){const r=la(e);return r==="eip1559"?ba(e,t):r==="eip2930"?ya(e,t):r==="eip4844"?pa(e,t):r==="eip7702"?da(e,t):ga(e,t)}function da(e,t){const{authorizationList:r,chainId:n,gas:i,nonce:a,to:u,value:f,maxFeePerGas:l,maxPriorityFeePerGas:b,accessList:g,data:m}=e;aa(e);const v=_r(g),S=Mo(r);return Vt(["0x04",ot([q(n),a?q(a):"0x",b?q(b):"0x",l?q(l):"0x",i?q(i):"0x",u??"0x",f?q(f):"0x",m??"0x",v,S,...Kt(e,t)])])}function pa(e,t){const{chainId:r,gas:n,nonce:i,to:a,value:u,maxFeePerBlobGas:f,maxFeePerGas:l,maxPriorityFeePerGas:b,accessList:g,data:m}=e;fa(e);let v=e.blobVersionedHashes,S=e.sidecars;if(e.blobs&&(typeof v>"u"||typeof S>"u")){const O=typeof e.blobs[0]=="string"?e.blobs:e.blobs.map(B=>Ze(B)),L=e.kzg,U=Ii({blobs:O,kzg:L});if(typeof v>"u"&&(v=Co({commitments:U})),typeof S>"u"){const B=Ai({blobs:O,commitments:U,kzg:L});S=No({blobs:O,commitments:U,proofs:B})}}const I=_r(g),R=[q(r),i?q(i):"0x",b?q(b):"0x",l?q(l):"0x",n?q(n):"0x",a??"0x",u?q(u):"0x",m??"0x",I,f?q(f):"0x",v??[],...Kt(e,t)],k=[],C=[],F=[];if(S)for(let O=0;O<S.length;O++){const{blob:L,commitment:U,proof:B}=S[O];k.push(L),C.push(U),F.push(B)}return Vt(["0x03",ot(S?[R,k,C,F]:R)])}function ba(e,t){const{chainId:r,gas:n,nonce:i,to:a,value:u,maxFeePerGas:f,maxPriorityFeePerGas:l,accessList:b,data:g}=e;yn(e);const m=_r(b),v=[q(r),i?q(i):"0x",l?q(l):"0x",f?q(f):"0x",n?q(n):"0x",a??"0x",u?q(u):"0x",g??"0x",m,...Kt(e,t)];return Vt(["0x02",ot(v)])}function ya(e,t){const{chainId:r,gas:n,data:i,nonce:a,to:u,value:f,accessList:l,gasPrice:b}=e;ua(e);const g=_r(l),m=[q(r),a?q(a):"0x",b?q(b):"0x",n?q(n):"0x",u??"0x",f?q(f):"0x",i??"0x",g,...Kt(e,t)];return Vt(["0x01",ot(m)])}function ga(e,t){const{chainId:r=0,gas:n,data:i,nonce:a,to:u,value:f,gasPrice:l}=e;ca(e);let b=[a?q(a):"0x",l?q(l):"0x",n?q(n):"0x",u??"0x",f?q(f):"0x",i??"0x"];if(t){const g=(()=>{if(t.v>=35n)return(t.v-35n)/2n>0?t.v:27n+(t.v===35n?0n:1n);if(r>0)return BigInt(r*2)+BigInt(35n+t.v-27n);const S=27n+(t.v===27n?0n:1n);if(t.v!==S)throw new yo({v:t.v});return S})(),m=ar(t.r),v=ar(t.s);b=[...b,q(g),m==="0x00"?"0x":m,v==="0x00"?"0x":v]}else r>0&&(b=[...b,q(r),"0x","0x"]);return ot(b)}function Kt(e,t){const r=t??e,{v:n,yParity:i}=r;if(typeof r.r>"u")return[];if(typeof r.s>"u")return[];if(typeof n>"u"&&typeof i>"u")return[];const a=ar(r.r),u=ar(r.s);return[typeof i=="number"?i?q(1):"0x":n===0n?"0x":n===1n?q(1):n===27n?"0x":q(1),a==="0x00"?"0x":a,u==="0x00"?"0x":u]}const ma={gasPriceOracle:{address:"0x420000000000000000000000000000000000000F"},l1Block:{address:"0x4200000000000000000000000000000000000015"},l2CrossDomainMessenger:{address:"0x4200000000000000000000000000000000000007"},l2Erc721Bridge:{address:"0x4200000000000000000000000000000000000014"},l2StandardBridge:{address:"0x4200000000000000000000000000000000000010"},l2ToL1MessagePasser:{address:"0x4200000000000000000000000000000000000016"}},_a={block:ro({format(e){var r;return{transactions:(r=e.transactions)==null?void 0:r.map(n=>{if(typeof n=="string")return n;const i=cn(n);return i.typeHex==="0x7e"&&(i.isSystemTx=n.isSystemTx,i.mint=n.mint?gt(n.mint):void 0,i.sourceHash=n.sourceHash,i.type="deposit"),i}),stateRoot:e.stateRoot}}}),transaction:Zs({format(e){const t={};return e.type==="0x7e"&&(t.isSystemTx=e.isSystemTx,t.mint=e.mint?gt(e.mint):void 0,t.sourceHash=e.sourceHash,t.type="deposit"),t}}),transactionReceipt:oo({format(e){return{l1GasPrice:e.l1GasPrice?gt(e.l1GasPrice):null,l1GasUsed:e.l1GasUsed?gt(e.l1GasUsed):null,l1Fee:e.l1Fee?gt(e.l1Fee):null,l1FeeScalar:e.l1FeeScalar?Number(e.l1FeeScalar):null}}})};function wa(e,t){return Ea(e)?va(e):ha(e,t)}const xa={transaction:wa};function va(e){Ba(e);const{sourceHash:t,data:r,from:n,gas:i,isSystemTx:a,mint:u,to:f,value:l}=e,b=[t,n,f??"0x",u?q(u):"0x",l?q(l):"0x",i?q(i):"0x",a?"0x1":"0x",r??"0x"];return Vt(["0x7e",ot(b)])}function Ea(e){return e.type==="deposit"||typeof e.sourceHash<"u"}function Ba(e){const{from:t,to:r}=e;if(t&&!ft(t))throw new at({address:t});if(r&&!ft(r))throw new at({address:r})}const Nn={contracts:ma,formatters:_a,serializers:xa},Sa=qt({id:42161,name:"Arbitrum One",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://arb1.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://arbiscan.io",apiUrl:"https://api.arbiscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:7654707}}}),Ia=qt({id:421614,name:"Arbitrum Sepolia",nativeCurrency:{name:"Arbitrum Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia-rollup.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://sepolia.arbiscan.io",apiUrl:"https://api-sepolia.arbiscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:81930}},testnet:!0}),Lt=11155111,Aa=qt({...Nn,id:84532,network:"base-sepolia",name:"Base Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia.base.org"]}},blockExplorers:{default:{name:"Basescan",url:"https://sepolia.basescan.org",apiUrl:"https://api-sepolia.basescan.org/api"}},contracts:{...Nn.contracts,disputeGameFactory:{[Lt]:{address:"0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"}},l2OutputOracle:{[Lt]:{address:"0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"}},portal:{[Lt]:{address:"0x49f53e41452c74589e85ca1677426ba426459e85",blockCreated:4446677}},l1StandardBridge:{[Lt]:{address:"0xfd0Bf71F60660E2f608ed56e1659C450eB113120",blockCreated:4446677}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:1059647}},testnet:!0,sourceId:Lt}),Ra=qt({id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://cloudflare-eth.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io",apiUrl:"https://api.etherscan.io/api"}},contracts:{ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xce01f8eee7E479C928F8919abD53E553a36CeF67",blockCreated:19258213},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:14353601}}}),Ta=qt({id:11155111,name:"Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc2.sepolia.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io",apiUrl:"https://api-sepolia.etherscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:751532},ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xc8Af999e38273D658BE1b921b88A9Ddf005769cC",blockCreated:5317080}},testnet:!0});function Qr(e){return typeof e=="string"&&(e=Buffer.from(e,"hex")),e.length===32?e:e.subarray(1,33)}function bt(e,t){if(!e)throw new Error(t)}function ka(e){return Buffer.concat([Uint8Array.from([192]),Pa(e)])}function Pa(e){const t=In.encodingLength(e.length),r=Buffer.allocUnsafe(t);return In.encode(e.length,r),Buffer.concat([r,e])}function Ca(e,t){if(e.compare(t)>0){const r=e;e=t,t=r}return[e,t]}const Ot=e=>e.length===64?e:e.slice(2),La=e=>{if(!e)return!1;try{const t=Buffer.from(e,"hex");return wt.isPoint(t)}catch{return!1}},Oa={ethereum:Ra,ethereum_arbitrum:Sa,ethereum_sepolia:Ta,arbitrum_sepolia:Ia,ethereum_localnet:J.EthereumLocalnet,arbitrum_localnet:J.ArbitrumLocalnet,base_sepolia:Aa},Fa=async(e,t)=>{var n;const r=Oa[e];if(r)try{if(r.id===((n=t.chain)==null?void 0:n.id))return P.Ok({message:"Already on the network",walletClient:t});await t.switchChain({id:r.id});const i=He.createWalletClient({account:t.account,chain:r,transport:He.custom(window.ethereum)});return P.Ok({message:"Switched chain",walletClient:i})}catch(i){if(Ua(i))try{await t.addChain({chain:r});const a=He.createWalletClient({account:t.account,chain:r,transport:He.custom(window.ethereum)});return P.Ok({message:"Added network",walletClient:a})}catch{return P.Err("Failed to add network")}else return P.Err("Failed to switch network")}else return P.Err("Chain not supported")},Ua=e=>typeof e=="object"&&e!==null&&"code"in e&&e.code===4902,Hi=(e,t,r,n)=>e+":"+t.toLowerCase()+"::"+r+":"+n.toLowerCase();var ne=(e=>(e.Created="Created",e.Matched="Matched",e.InitiateDetected="InitiateDetected",e.Initiated="Initiated",e.CounterPartyInitiateDetected="CounterPartyInitiateDetected",e.CounterPartyInitiated="CounterPartyInitiated",e.RedeemDetected="RedeemDetected",e.Redeemed="Redeemed",e.CounterPartyRedeemDetected="CounterPartyRedeemDetected",e.CounterPartyRedeemed="CounterPartyRedeemed",e.Completed="Completed",e.CounterPartySwapExpired="CounterPartySwapExpired",e.Expired="Expired",e.RefundDetected="RefundDetected",e.Refunded="Refunded",e.CounterPartyRefundDetected="CounterPartyRefundDetected",e.CounterPartyRefunded="CounterPartyRefunded",e.Cancelled="Cancelled",e.DeadLineExceeded="DeadLineExceeded",e))(ne||{}),Q=(e=>(e.Idle="Idle",e.InitiateDetected="InitiateDetected",e.Initiated="Initiated",e.RedeemDetected="RedeemDetected",e.Redeemed="Redeemed",e.RefundDetected="RefundDetected",e.Refunded="Refunded",e.Expired="Expired",e))(Q||{});const zi=(e,t,r)=>{const n=cr(e.source_swap,t),i=cr(e.destination_swap,r);if(i===Q.RedeemDetected)return ne.RedeemDetected;if(n===Q.Redeemed)return ne.CounterPartyRedeemed;if(n===Q.RedeemDetected)return ne.CounterPartyRedeemDetected;if(i===Q.Redeemed)return ne.Redeemed;if(n===Q.Refunded)return ne.Refunded;if(n===Q.RefundDetected)return ne.RefundDetected;if(i===Q.Expired)return ne.CounterPartySwapExpired;if(n===Q.Expired)return ne.Expired;if(i===Q.Refunded)return ne.CounterPartyRefunded;if(i===Q.RefundDetected)return ne.CounterPartyRefundDetected;const a=Number(e.create_order.additional_data.deadline);return i===Q.Initiated?ne.CounterPartyInitiated:i===Q.InitiateDetected?ne.CounterPartyInitiateDetected:zt(a,12)?ne.DeadLineExceeded:n===Q.Initiated?ne.Initiated:zt(a,1)?ne.DeadLineExceeded:n===Q.InitiateDetected?ne.InitiateDetected:ne.Matched},cr=(e,t)=>{if(e.redeem_tx_hash)return Number(e.redeem_block_number)?Q.Redeemed:Q.RedeemDetected;if(e.refund_tx_hash)return Number(e.refund_block_number)?Q.Refunded:Q.RefundDetected;if(Number(e.initiate_block_number)){const r=Number(e.initiate_block_number)+e.timelock;if(t>r)return Q.Expired}return e.initiate_tx_hash?Number(e.initiate_block_number)?Q.Initiated:Q.InitiateDetected:Q.Idle},ji=(e,t,r)=>{switch(zi(e,t,r)){case ne.Matched:return ue.Initiate;case ne.CounterPartyInitiated:case ne.CounterPartyInitiateDetected:case ne.RedeemDetected:return ue.Redeem;case ne.Expired:return ue.Refund;default:return ue.Idle}},zt=(e,t=0)=>{const r=Date.now(),n=e*1e3+t*36e5;return r>=n},Gi=e=>e.filter(t=>{const{source_swap:r,create_order:n}=t,{initiate_tx_hash:i,initiate_block_number:a}=r,{deadline:u}=n.additional_data;return i&&Number(a)?!0:i&&!Number(a)?!zt(Number(u),12):i?!0:!zt(Number(u),1)}),Na=[{inputs:[{internalType:"address",name:"token_",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"InvalidShortString",type:"error"},{inputs:[{internalType:"string",name:"str",type:"string"}],name:"StringTooLong",type:"error"},{anonymous:!1,inputs:[],name:"EIP712DomainChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"secretHash",type:"bytes32"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"}],name:"Initiated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"secretHash",type:"bytes32"},{indexed:!1,internalType:"bytes",name:"secret",type:"bytes"}],name:"Redeemed",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"}],name:"Refunded",type:"event"},{inputs:[],name:"eip712Domain",outputs:[{internalType:"bytes1",name:"fields",type:"bytes1"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"},{internalType:"uint256",name:"chainId",type:"uint256"},{internalType:"address",name:"verifyingContract",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"uint256[]",name:"extensions",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"}],name:"initiate",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"initiateWithSignature",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"instantRefund",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"expiry",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],internalType:"struct HTLC.InitWithSig[]",name:"inits",type:"tuple[]"},{components:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"secret",type:"bytes"}],internalType:"struct HTLC.Redeem[]",name:"redeems",type:"tuple[]"},{components:[{internalType:"bytes32",name:"orderID",type:"bytes32"}],internalType:"struct HTLC.Refund[]",name:"refunds",type:"tuple[]"}],name:"multicall",outputs:[{internalType:"bool[]",name:"results",type:"bool[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"}],name:"orders",outputs:[{internalType:"bool",name:"isFulfilled",type:"bool"},{internalType:"address",name:"initiator",type:"address"},{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"initiatedAt",type:"uint256"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"secret",type:"bytes"}],name:"redeem",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"}],name:"refund",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"token",outputs:[{internalType:"contract IERC20",name:"",type:"address"}],stateMutability:"view",type:"function"}];class qi{constructor(t,r,n){this.url=new ge.Url("/relayer",r),this.auth=n,this.order=t}async init(t,r){if(!t.account)return P.Err("No account found");if(t.account.address.toLowerCase()!==this.order.source_swap.initiator.toLowerCase())return P.Err("Account address and order initiator mismatch");if(!r){const g=await ge.fetchEVMBlockNumber(t);if(g.error)return P.Err(g.error);r=g.val}if(cr(this.order.source_swap,r)!==Q.Idle)return P.Err("Invalid swap status");const{create_order:i,source_swap:a}=this.order;if(!a.amount||!a.redeemer||!i.timelock||!i.secret_hash)return P.Err("Invalid order");const u=ge.with0x(i.secret_hash),f=BigInt(i.timelock),l=ge.with0x(a.redeemer),b=BigInt(a.amount);try{const g=await this.auth.getToken();if(g.error)return P.Err(g.error);const m=He.getContract({address:ge.with0x(this.order.source_swap.asset),abi:Na,client:t}),v=await m.read.token(),S=await ge.checkAllowanceAndApprove(Number(b),v,this.order.source_swap.asset,t);if(S.error)return P.Err(S.error);const I=await m.read.eip712Domain(),R=await t.signTypedData({account:t.account,domain:{name:I[1],version:I[2],chainId:Number(I[3]),verifyingContract:I[4]},types:{Initiate:[{name:"redeemer",type:"address"},{name:"timelock",type:"uint256"},{name:"amount",type:"uint256"},{name:"secretHash",type:"bytes32"}]},primaryType:"Initiate",message:{redeemer:l,timelock:f,amount:b,secretHash:u}}),k=await P.Fetcher.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:i.create_id,signature:R,perform_on:"Source"}),headers:{Authorization:ge.Authorization(g.val),"Content-Type":"application/json"}});return k.error?P.Err(k.error):k.result?P.Ok(k.result):P.Err("Init: No result found")}catch(g){return console.log("init error :",g),P.Err(String(g))}}async redeem(t,r){try{const n=await this.auth.getToken();if(n.error)return P.Err(n.error);const i=await P.Fetcher.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t,secret:P.trim0x(r),perform_on:"Destination"}),headers:{Authorization:ge.Authorization(n.val),"Content-Type":"application/json"}});return i.error?P.Err(i.error):i.result?P.Ok(i.result):P.Err("Redeem: No result found")}catch(n){return P.Err(String(n))}}}const Ma=Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),Da=Buffer.from("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8","hex"),$a=Buffer.concat([Ma,Da]),Ha=Buffer.from("0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0","hex"),Mn={failedToCreateInternalPubkey:"failed to create internal pubkey",failedToTweakPubkey:"failed to tweak pubkey"};function za(){const e=bi.crypto.sha256(Buffer.from("GardenHTLC","utf-8")),t=wt.pointMultiply(Buffer.concat([Buffer.from("04","hex"),$a]),e);if(!t)throw new Error(Mn.failedToCreateInternalPubkey);const r=wt.pointAdd(Ha,t);if(!r)throw new Error(Mn.failedToCreateInternalPubkey);return Qr(Buffer.from(r))}const _e={secretMismatch:"invalid secret",secretHashLenMismatch:"secret hash should be 32 bytes",pubkeyLenMismatch:"pubkey should be 32 bytes",zeroOrNegativeExpiry:"expiry should be greater than 0",htlcAddressGenerationFailed:"failed to generate htlc address",notFunded:"address not funded",noCounterpartySigs:"counterparty signatures are required",counterPartySigNotFound:e=>"counterparty signature not found for utxo "+e,invalidCounterpartySigForUTXO:e=>"invalid counterparty signature for utxo "+e,htlcNotExpired:e=>`HTLC not expired, need more ${e} blocks`,controlBlockGenerationFailed:"failed to generate control block",invalidLeaf:"invalid leaf"},rr=192;ye.initEccLib(wt);class lr{constructor(t,r,n,i,a,u,f,l){this.secretHash=n,this.redeemerPubkey=i,this.initiatorPubkey=a,this.expiry=u,this.signer=t,this.network=f,this.internalPubkey=za(),this.initiateAmount=r,this.utxoHashes=l}static async from(t,r,n,i,a,u,f){n=n.startsWith("0x")?n.slice(2):n,bt(n.length===64,_e.secretHashLenMismatch),bt(i.length===64||i.length===66,`initiator ${_e.pubkeyLenMismatch}`),bt(a.length===64||a.length===66,`redeemer ${_e.pubkeyLenMismatch}`),bt(u>0,_e.zeroOrNegativeExpiry);const l=await t.getNetwork();return new lr(t,r,n,Qr(a).toString("hex"),Qr(i).toString("hex"),u,l,f)}address(){const{address:t}=ye.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves()});if(!t)throw new Error(_e.htlcAddressGenerationFailed);return t}id(){return this.address()}async _buildRawTx(t,r){const n=new ye.Transaction;n.version=2;const i=this.address(),a=await this.signer.getProvider();let u=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const l of this.utxoHashes){const b=await a.getTransaction(l);for(let g=0;g<b.vout.length;g++){const m=b.vout[g];m.scriptpubkey_address===i&&u.push({txid:b.txid,vout:g,value:m.value,status:{confirmed:!1}})}}else u=await a.getUTXOs(i);const f=u.reduce((l,b)=>l+b.value,0);if(f===0)throw new Error(`${i} ${_e.notFunded}`);for(let l=0;l<u.length;l++)n.addInput(Buffer.from(u[l].txid,"hex").reverse(),u[l].vout);return r??(r=await a.suggestFee(i,f,Sn.Urgency.MEDIUM)),n.addOutput(ye.address.toOutputScript(t,this.network),f-r),{tx:n,usedUtxos:u}}async buildRawTx(t){return await this._buildRawTx(await this.signer.getAddress(),t)}getOutputScript(){return ye.address.toOutputScript(this.address(),this.network)}async init(t){return t??(t=await(await this.signer.getProvider()).suggestFee(await this.signer.getAddress(),this.initiateAmount,Sn.Urgency.MEDIUM)),await this.signer.send(this.address(),this.initiateAmount,t)}async instantRefund(t,r){bt(t.length>0,_e.noCounterpartySigs);const{tx:n,usedUtxos:i}=await this.buildRawTx(r);for(const m of i)if(!t.find(v=>v.utxo===m.txid))throw new Error(_e.counterPartySigNotFound(m.txid));const a=this.getOutputScript(),u=ye.Transaction.SIGHASH_DEFAULT,f=this.leafHash(2),l=i.map(m=>m.value),b=Fr(a,i.length);for(let m=0;m<n.ins.length;m++){const v=n.hashForWitnessV1(m,b,l,u,f);if(!wt.verifySchnorr(v,Buffer.from(this.redeemerPubkey,"hex"),Buffer.from(t[m].sig,"hex")))throw new Error(_e.invalidCounterpartySigForUTXO(t[m].utxo));const S=await this.signer.signSchnorr(v),I=Buffer.from(n.ins[m].hash).reverse().toString("hex"),R=t.find(k=>k.utxo===I);if(!R)throw new Error(_e.counterPartySigNotFound(I));n.setWitness(m,[Buffer.from(R.sig,"hex"),S,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async redeem(t,r,n){bt(ye.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,_e.secretMismatch);const{tx:i,usedUtxos:a}=await this._buildRawTx(r??await this.signer.getAddress(),n),u=this.leafHash(1),f=a.map(m=>m.value),l=Fr(this.getOutputScript(),a.length),b=ye.Transaction.SIGHASH_DEFAULT;for(let m=0;m<i.ins.length;m++){const v=i.hashForWitnessV1(m,l,f,b,u),S=await this.signer.signSchnorr(v);i.setWitness(m,[S,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return await(await this.signer.getProvider()).broadcast(i.toHex())}async refund(t,r){const{tx:n,usedUtxos:i}=await this._buildRawTx(t??await this.signer.getAddress(),r),[a,u]=await this.canRefund(i);if(!a)throw new Error(_e.htlcNotExpired(u));const f=this.leafHash(0),l=i.map(v=>v.value),b=Fr(this.getOutputScript(),i.length),g=ye.Transaction.SIGHASH_DEFAULT;for(let v=0;v<n.ins.length;v++){n.ins[v].sequence=this.expiry;const S=n.hashForWitnessV1(v,b,l,g,f),I=await this.signer.signSchnorr(S);n.setWitness(v,[I,this.refundLeaf(),this.generateControlBlockFor(0)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async canRefund(t){const n=await(await this.signer.getProvider()).getLatestTip();for(const i of t){let a=0;if(i.status.confirmed&&i.status.block_height+this.expiry>n?a=i.status.block_height+this.expiry-n+1:i.status.confirmed||(a=this.expiry+1),a>0)return[!1,a]}return[!0,0]}generateControlBlockFor(t){let r;switch(t){case 1:r=this.redeemLeaf();break;case 0:r=this.refundLeaf();break;case 2:r=this.instantRefundLeaf();break;default:throw new Error(_e.invalidLeaf)}const n=ye.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves(),redeem:{output:r,redeemVersion:rr}});if(!n.witness)throw new Error(_e.controlBlockGenerationFailed);return n.witness[n.witness.length-1]}leafHash(t){let r=this.redeemLeaf();return t===0&&(r=this.refundLeaf()),t===2&&(r=this.instantRefundLeaf()),ye.crypto.taggedHash("TapLeaf",ka(r))}refundLeaf(){return ye.script.fromASM(`
5
5
  ${ye.script.number.encode(this.expiry).toString("hex")}
6
6
  OP_CHECKSEQUENCEVERIFY
7
7
  OP_DROP
package/dist/index.js CHANGED
@@ -1735,13 +1735,13 @@ const qa = (e, t, r) => {
1735
1735
  if (n === te.Refunded) return re.Refunded;
1736
1736
  if (n === te.RefundDetected)
1737
1737
  return re.RefundDetected;
1738
+ if (i === te.Expired)
1739
+ return re.CounterPartySwapExpired;
1740
+ if (n === te.Expired) return re.Expired;
1738
1741
  if (i === te.Refunded)
1739
1742
  return re.CounterPartyRefunded;
1740
1743
  if (i === te.RefundDetected)
1741
1744
  return re.CounterPartyRefundDetected;
1742
- if (i === te.Expired)
1743
- return re.CounterPartySwapExpired;
1744
- if (n === te.Expired) return re.Expired;
1745
1745
  const a = Number(
1746
1746
  e.create_order.additional_data.deadline
1747
1747
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/core",
3
- "version": "0.2.0-beta.62",
3
+ "version": "0.2.0-beta.63",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"