UNPKG

@avalanche-sdk/client

Version:

A TypeScript SDK for interacting with the Avalanche network through JSON-RPC APIs. This SDK provides a comprehensive set of tools to interact with all Avalanche chains (P-Chain, X-Chain, C-Chain) and various APIs, including wallet functionality for transa

5 lines 164 kB
import*as e from"node:crypto";const t=BigInt(2**32-1),n=BigInt(32);function r(e,r=!1){return r?{h:Number(e&t),l:Number(e>>n&t)}:{h:0|Number(e>>n&t),l:0|Number(e&t)}}const s=e&&"object"==typeof e&&"webcrypto"in e?e.webcrypto:e&&"object"==typeof e&&"randomBytes"in e?e:void 0;function i(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function o(e,...t){if(!((n=e)instanceof Uint8Array||ArrayBuffer.isView(n)&&"Uint8Array"===n.constructor.name))throw new Error("Uint8Array expected"); /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */ var n;if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function a(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 c(e,t){o(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function u(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function f(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function d(e,t){return e<<32-t|e>>>t}function l(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const h=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])()?e=>e:function(e){for(let t=0;t<e.length;t++)e[t]=l(e[t]);return e};function b(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}(e)),o(e),e}let p=class{};function g(e){const t=t=>e().update(b(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function m(e=32){if(s&&"function"==typeof s.getRandomValues)return s.getRandomValues(new Uint8Array(e));if(s&&"function"==typeof s.randomBytes)return Uint8Array.from(s.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}const y=BigInt(0),w=BigInt(1),v=BigInt(2),x=BigInt(7),P=BigInt(256),$=BigInt(113),E=[],A=[],I=[];for(let e=0,t=w,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],E.push(2*(5*r+n)),A.push((e+1)*(e+2)/2%64);let s=y;for(let e=0;e<7;e++)t=(t<<w^(t>>x)*$)%P,t&v&&(s^=w<<(w<<BigInt(e))-w);I.push(s)}const B=function(e,t=!1){const n=e.length;let s=new Uint32Array(n),i=new Uint32Array(n);for(let o=0;o<n;o++){const{h:n,l:a}=r(e[o],t);[s[o],i[o]]=[n,a]}return[s,i]}(I,!0),z=B[0],O=B[1],S=(e,t,n)=>n>32?((e,t,n)=>t<<n-32|e>>>64-n)(e,t,n):((e,t,n)=>e<<n|t>>>32-n)(e,t,n),k=(e,t,n)=>n>32?((e,t,n)=>e<<n-32|t>>>64-n)(e,t,n):((e,t,n)=>t<<n|e>>>32-n)(e,t,n);let N=class e extends p{constructor(e,t,n,r=!1,s=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.rounds=s,i(n),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");var o;this.state=new Uint8Array(200),this.state32=(o=this.state,new Uint32Array(o.buffer,o.byteOffset,Math.floor(o.byteLength/4)))}clone(){return this._cloneInto()}keccak(){h(this.state32),function(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let t=0;t<10;t++)n[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const r=(t+8)%10,s=(t+2)%10,i=n[s],o=n[s+1],a=S(i,o,1)^n[r],c=k(i,o,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=a,e[t+n+1]^=c}let t=e[2],s=e[3];for(let n=0;n<24;n++){const r=A[n],i=S(t,s,r),o=k(t,s,r),a=E[n];t=e[a],s=e[a+1],e[a]=i,e[a+1]=o}for(let t=0;t<50;t+=10){for(let r=0;r<10;r++)n[r]=e[t+r];for(let r=0;r<10;r++)e[t+r]^=~n[(r+2)%10]&n[(r+4)%10]}e[0]^=z[r],e[1]^=O[r]}u(n)}(this.state32,this.rounds),h(this.state32),this.posOut=0,this.pos=0}update(e){a(this),o(e=b(e));const{blockLen:t,state:n}=this,r=e.length;for(let s=0;s<r;){const i=Math.min(t-this.pos,r-s);for(let t=0;t<i;t++)n[this.pos++]^=e[s++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,128&t&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){a(this,!1),o(e),this.finish();const t=this.state,{blockLen:n}=this;for(let r=0,s=e.length;r<s;){this.posOut>=n&&this.keccak();const i=Math.min(n-this.posOut,s-r);e.set(t.subarray(this.posOut,this.posOut+i),r),this.posOut+=i,r+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return i(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(c(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,u(this.state)}_cloneInto(t){const{blockLen:n,suffix:r,outputLen:s,rounds:i,enableXOF:o}=this;return t||(t=new e(n,r,s,o,i)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=i,t.suffix=r,t.outputLen=s,t.enableXOF=o,t.destroyed=this.destroyed,t}};const R=(()=>{return e=1,t=136,n=32,g(()=>new N(t,e,n));var e,t,n})();function M(e,{strict:t=!0}={}){return!!e&&("string"==typeof e&&(t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")))}const j="2.38.2";let L=({docsBaseUrl:e,docsPath:t="",docsSlug:n})=>t?`${e??"https://viem.sh"}${t}${n?`#${n}`:""}`:void 0,U=`viem@${j}`,F=class e extends Error{constructor(t,n={}){const r=n.cause instanceof e?n.cause.details:n.cause?.message?n.cause.message:n.details,s=n.cause instanceof e&&n.cause.docsPath||n.docsPath,i=L?.({...n,docsPath:s});super([t||"An error occurred.","",...n.metaMessages?[...n.metaMessages,""]:[],...i?[`Docs: ${i}`]:[],...r?[`Details: ${r}`]:[],...U?[`Version: ${U}`]:[]].join("\n"),n.cause?{cause:n.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=r,this.docsPath=s,this.metaMessages=n.metaMessages,this.name=n.name??this.name,this.shortMessage=t,this.version=j}walk(e){return C(this,e)}};function C(e,t){return t?.(e)?e:e&&"object"==typeof e&&"cause"in e&&void 0!==e.cause?C(e.cause,t):t?null:e}let T=class extends F{constructor({offset:e,position:t,size:n}){super(`Slice ${"start"===t?"starting":"ending"} at offset "${e}" is out-of-bounds (size: ${n}).`,{name:"SliceOffsetOutOfBoundsError"})}},D=class extends F{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${e}) exceeds padding size (${t}).`,{name:"SizeExceedsPaddingSizeError"})}};class q extends F{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} is expected to be ${t} ${n} long, but is ${e} ${n} long.`,{name:"InvalidBytesLengthError"})}}function _(e,{dir:t,size:n=32}={}){return"string"==typeof e?V(e,{dir:t,size:n}):function(e,{dir:t,size:n=32}={}){if(null===n)return e;if(e.length>n)throw new D({size:e.length,targetSize:n,type:"bytes"});const r=new Uint8Array(n);for(let s=0;s<n;s++){const i="right"===t;r[i?s:n-s-1]=e[i?s:e.length-s-1]}return r}(e,{dir:t,size:n})}function V(e,{dir:t,size:n=32}={}){if(null===n)return e;const r=e.replace("0x","");if(r.length>2*n)throw new D({size:Math.ceil(r.length/2),targetSize:n,type:"hex"});return`0x${r["right"===t?"padEnd":"padStart"](2*n,"0")}`}let G=class extends F{constructor({max:e,min:t,signed:n,size:r,value:s}){super(`Number "${s}" is not in safe ${r?`${8*r}-bit ${n?"signed":"unsigned"} `:""}integer range ${e?`(${t} to ${e})`:`(above ${t})`}`,{name:"IntegerOutOfRangeError"})}},H=class extends F{constructor(e){super(`Bytes value "${e}" is not a valid boolean. The bytes array must contain a single byte of either a 0 or 1 value.`,{name:"InvalidBytesBooleanError"})}};class Z extends F{constructor(e){super(`Hex value "${e}" is not a valid boolean. The hex value must be "0x0" (false) or "0x1" (true).`,{name:"InvalidHexBooleanError"})}}let W=class extends F{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}};function Y(e){return M(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}function K(e,{dir:t="left"}={}){let n="string"==typeof e?e.replace("0x",""):e,r=0;for(let e=0;e<n.length-1&&"0"===n["left"===t?e:n.length-e-1].toString();e++)r++;return n="left"===t?n.slice(r):n.slice(0,n.length-r),"string"==typeof e?(1===n.length&&"right"===t&&(n=`${n}0`),`0x${n.length%2==1?`0${n}`:n}`):n}function X(e,{size:t}){if(Y(e)>t)throw new W({givenSize:Y(e),maxSize:t})}function J(e,t={}){const{signed:n}=t;t.size&&X(e,{size:t.size});const r=BigInt(e);if(!n)return r;const s=(e.length-2)/2;return r<=(1n<<8n*BigInt(s)-1n)-1n?r:r-BigInt(`0x${"f".padStart(2*s,"f")}`)-1n}function Q(e,t={}){return Number(J(e,t))}const ee=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function te(e,t={}){return"number"==typeof e||"bigint"==typeof e?se(e,t):"string"==typeof e?oe(e,t):"boolean"==typeof e?ne(e,t):re(e,t)}function ne(e,t={}){const n=`0x${Number(e)}`;return"number"==typeof t.size?(X(n,{size:t.size}),_(n,{size:t.size})):n}function re(e,t={}){let n="";for(let t=0;t<e.length;t++)n+=ee[e[t]];const r=`0x${n}`;return"number"==typeof t.size?(X(r,{size:t.size}),_(r,{dir:"right",size:t.size})):r}function se(e,t={}){const{signed:n,size:r}=t,s=BigInt(e);let i;r?i=n?(1n<<8n*BigInt(r)-1n)-1n:2n**(8n*BigInt(r))-1n:"number"==typeof e&&(i=BigInt(Number.MAX_SAFE_INTEGER));const o="bigint"==typeof i&&n?-i-1n:0;if(i&&s>i||s<o){const t="bigint"==typeof e?"n":"";throw new G({max:i?`${i}${t}`:void 0,min:`${o}${t}`,signed:n,size:r,value:`${e}${t}`})}const a=`0x${(n&&s<0?(1n<<BigInt(8*r))+BigInt(s):s).toString(16)}`;return r?_(a,{size:r}):a}const ie=new TextEncoder;function oe(e,t={}){return re(ie.encode(e),t)}const ae=new TextEncoder;function ce(e,t={}){return"number"==typeof e||"bigint"==typeof e?function(e,t){const n=se(e,t);return de(n)}(e,t):"boolean"==typeof e?function(e,t={}){const n=new Uint8Array(1);if(n[0]=Number(e),"number"==typeof t.size)return X(n,{size:t.size}),_(n,{size:t.size});return n}(e,t):M(e)?de(e,t):le(e,t)}const ue={zero:48,nine:57,A:65,F:70,a:97,f:102};function fe(e){return e>=ue.zero&&e<=ue.nine?e-ue.zero:e>=ue.A&&e<=ue.F?e-(ue.A-10):e>=ue.a&&e<=ue.f?e-(ue.a-10):void 0}function de(e,t={}){let n=e;t.size&&(X(n,{size:t.size}),n=_(n,{dir:"right",size:t.size}));let r=n.slice(2);r.length%2&&(r=`0${r}`);const s=r.length/2,i=new Uint8Array(s);for(let e=0,t=0;e<s;e++){const n=fe(r.charCodeAt(t++)),s=fe(r.charCodeAt(t++));if(void 0===n||void 0===s)throw new F(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);i[e]=16*n+s}return i}function le(e,t={}){const n=ae.encode(e);return"number"==typeof t.size?(X(n,{size:t.size}),_(n,{dir:"right",size:t.size})):n}function he(e,t){const n=t||"hex",r=R(M(e,{strict:!1})?ce(e):e);return"bytes"===n?r:te(r)}function be(e){return"string"==typeof e[0]?pe(e):function(e){let t=0;for(const n of e)t+=n.length;const n=new Uint8Array(t);let r=0;for(const t of e)n.set(t,r),r+=t.length;return n}(e)}function pe(e){return`0x${e.reduce((e,t)=>e+t.replace("0x",""),"")}`}function ge(e,t){return he(function(e){const t="string"==typeof e?oe(e):"string"==typeof e.raw?e.raw:re(e.raw);return be([oe(`Ethereum Signed Message:\n${Y(t)}`),t])}(e),t)}function me(e){const{scheme:t,statement:n,...r}=e.match(ye)?.groups??{},{chainId:s,expirationTime:i,issuedAt:o,notBefore:a,requestId:c,...u}=e.match(we)?.groups??{},f=e.split("Resources:")[1]?.split("\n- ").slice(1);return{...r,...u,...s?{chainId:Number(s)}:{},...i?{expirationTime:new Date(i)}:{},...o?{issuedAt:new Date(o)}:{},...a?{notBefore:new Date(a)}:{},...c?{requestId:c}:{},...f?{resources:f}:{},...t?{scheme:t}:{},...n?{statement:n}:{}}}const ye=/^(?:(?<scheme>[a-zA-Z][a-zA-Z0-9+-.]*):\/\/)?(?<domain>[a-zA-Z0-9+-.]*(?::[0-9]{1,5})?) (?:wants you to sign in with your Ethereum account:\n)(?<address>0x[a-fA-F0-9]{40})\n\n(?:(?<statement>.*)\n\n)?/,we=/(?:URI: (?<uri>.+))\n(?:Version: (?<version>.+))\n(?:Chain ID: (?<chainId>\d+))\n(?:Nonce: (?<nonce>[a-zA-Z0-9]+))\n(?:Issued At: (?<issuedAt>.+))(?:\nExpiration Time: (?<expirationTime>.+))?(?:\nNot Before: (?<notBefore>.+))?(?:\nRequest ID: (?<requestId>.+))?/;let ve=class extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const t=super.get(e);return super.has(e)&&void 0!==t&&(this.delete(e),super.set(e,t)),t}set(e,t){if(super.set(e,t),this.maxSize&&this.size>this.maxSize){const e=this.keys().next().value;e&&this.delete(e)}return this}},xe=class extends F{constructor({address:e}){super(`Address "${e}" is invalid.`,{metaMessages:["- Address must be a hex value of 20 bytes (40 hex characters).","- Address must match its checksum counterpart."],name:"InvalidAddressError"})}};const Pe=new ve(8192);function $e(e,t){if(Pe.has(`${e}.${t}`))return Pe.get(`${e}.${t}`);const n=e.substring(2).toLowerCase(),r=he(le(n),"bytes"),s=n.split("");for(let e=0;e<40;e+=2)r[e>>1]>>4>=8&&s[e]&&(s[e]=s[e].toUpperCase()),(15&r[e>>1])>=8&&s[e+1]&&(s[e+1]=s[e+1].toUpperCase());const i=`0x${s.join("")}`;return Pe.set(`${e}.${t}`,i),i}function Ee(e,t){if(!Be(e,{strict:!1}))throw new xe({address:e});return $e(e,t)}const Ae=/^0x[a-fA-F0-9]{40}$/,Ie=new ve(8192);function Be(e,t){const{strict:n=!0}=t??{},r=`${e}.${n}`;if(Ie.has(r))return Ie.get(r);const s=!(!Ae.test(e)||e.toLowerCase()!==e&&n&&$e(e)!==e);return Ie.set(r,s),s}function ze(e,t){if(!Be(e,{strict:!1}))throw new xe({address:e});if(!Be(t,{strict:!1}))throw new xe({address:t});return e.toLowerCase()===t.toLowerCase()}function Oe(e){const{address:t,domain:n,message:r,nonce:s,scheme:i,time:o=new Date}=e;if(n&&r.domain!==n)return!1;if(s&&r.nonce!==s)return!1;if(i&&r.scheme!==i)return!1;if(r.expirationTime&&o>=r.expirationTime)return!1;if(r.notBefore&&o<r.notBefore)return!1;try{if(!r.address)return!1;if(!Be(r.address,{strict:!1}))return!1;if(t&&!ze(r.address,t))return!1}catch{return!1}return!0}let Se=class e extends Error{constructor(t,n={}){const r=n.cause instanceof e?n.cause.details:n.cause?.message?n.cause.message:n.details,s=n.cause instanceof e&&n.cause.docsPath||n.docsPath;super([t||"An error occurred.","",...n.metaMessages?[...n.metaMessages,""]:[],...s?[`Docs: https://abitype.dev${s}`]:[],...r?[`Details: ${r}`]:[],"Version: abitype@1.1.0"].join("\n")),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,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiTypeError"}),n.cause&&(this.cause=n.cause),this.details=r,this.docsPath=s,this.metaMessages=n.metaMessages,this.shortMessage=t}};function ke(e,t){const n=e.exec(t);return n?.groups}const Ne=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,Re=/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/,Me=/^\(.+?\).*?$/,je=/^tuple(?<array>(\[(\d*)\])*)$/;function Le(e){let t=e.type;if(je.test(e.type)&&"components"in e){t="(";const n=e.components.length;for(let r=0;r<n;r++){t+=Le(e.components[r]),r<n-1&&(t+=", ")}const r=ke(je,e.type);return t+=`)${r?.array??""}`,Le({...e,type:t})}return"indexed"in e&&e.indexed&&(t=`${t} indexed`),e.name?`${t} ${e.name}`:t}function Ue(e){let t="";const n=e.length;for(let r=0;r<n;r++){t+=Le(e[r]),r!==n-1&&(t+=", ")}return t}const Fe=/^error (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;const Ce=/^event (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;const Te=/^function (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)(?: (?<scope>external|public{1}))?(?: (?<stateMutability>pure|view|nonpayable|payable{1}))?(?: returns\s?\((?<returns>.*?)\))?$/;const De=/^struct (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) \{(?<properties>.*?)\}$/;function qe(e){return De.test(e)}function _e(e){return ke(De,e)}const Ve=/^constructor\((?<parameters>.*?)\)(?:\s(?<stateMutability>payable{1}))?$/;const Ge=/^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/;const He=/^receive\(\) external payable$/;const Ze=new Set(["memory","indexed","storage","calldata"]),We=new Set(["indexed"]),Ye=new Set(["calldata","memory","storage"]);class Ke extends Se{constructor({type:e}){super("Unknown type.",{metaMessages:[`Type "${e}" is not a valid ABI type. Perhaps you forgot to include a struct signature?`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownTypeError"})}}class Xe extends Se{constructor({type:e}){super("Unknown type.",{metaMessages:[`Type "${e}" is not a valid ABI type.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSolidityTypeError"})}}class Je extends Se{constructor({params:e}){super("Failed to parse ABI parameters.",{details:`parseAbiParameters(${JSON.stringify(e,null,2)})`,docsPath:"/api/human#parseabiparameters-1"}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidAbiParametersError"})}}class Qe extends Se{constructor({param:e}){super("Invalid ABI parameter.",{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParameterError"})}}class et extends Se{constructor({param:e,name:t}){super("Invalid ABI parameter.",{details:e,metaMessages:[`"${t}" is a protected Solidity keyword. More info: https://docs.soliditylang.org/en/latest/cheatsheet.html`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"SolidityProtectedKeywordError"})}}class tt extends Se{constructor({param:e,type:t,modifier:n}){super("Invalid ABI parameter.",{details:e,metaMessages:[`Modifier "${n}" not allowed${t?` in "${t}" type`:""}.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidModifierError"})}}class nt extends Se{constructor({param:e,type:t,modifier:n}){super("Invalid ABI parameter.",{details:e,metaMessages:[`Modifier "${n}" not allowed${t?` in "${t}" type`:""}.`,`Data location can only be specified for array, struct, or mapping types, but "${n}" was given.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidFunctionModifierError"})}}class rt extends Se{constructor({abiParameter:e}){super("Invalid ABI parameter.",{details:JSON.stringify(e,null,2),metaMessages:["ABI parameter type is invalid."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidAbiTypeParameterError"})}}class st extends Se{constructor({signature:e,type:t}){super(`Invalid ${t} signature.`,{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidSignatureError"})}}class it extends Se{constructor({signature:e}){super("Unknown signature.",{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSignatureError"})}}class ot extends Se{constructor({signature:e}){super("Invalid struct signature.",{details:e,metaMessages:["No properties exist."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidStructSignatureError"})}}class at extends Se{constructor({type:e}){super("Circular reference detected.",{metaMessages:[`Struct "${e}" is a circular reference.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"CircularReferenceError"})}}class ct extends Se{constructor({current:e,depth:t}){super("Unbalanced parentheses.",{metaMessages:[`"${e.trim()}" has too many ${t>0?"opening":"closing"} parentheses.`],details:`Depth "${t}"`}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParenthesisError"})}}const ut=new Map([["address",{type:"address"}],["bool",{type:"bool"}],["bytes",{type:"bytes"}],["bytes32",{type:"bytes32"}],["int",{type:"int256"}],["int256",{type:"int256"}],["string",{type:"string"}],["uint",{type:"uint256"}],["uint8",{type:"uint8"}],["uint16",{type:"uint16"}],["uint24",{type:"uint24"}],["uint32",{type:"uint32"}],["uint64",{type:"uint64"}],["uint96",{type:"uint96"}],["uint112",{type:"uint112"}],["uint160",{type:"uint160"}],["uint192",{type:"uint192"}],["uint256",{type:"uint256"}],["address owner",{type:"address",name:"owner"}],["address to",{type:"address",name:"to"}],["bool approved",{type:"bool",name:"approved"}],["bytes _data",{type:"bytes",name:"_data"}],["bytes data",{type:"bytes",name:"data"}],["bytes signature",{type:"bytes",name:"signature"}],["bytes32 hash",{type:"bytes32",name:"hash"}],["bytes32 r",{type:"bytes32",name:"r"}],["bytes32 root",{type:"bytes32",name:"root"}],["bytes32 s",{type:"bytes32",name:"s"}],["string name",{type:"string",name:"name"}],["string symbol",{type:"string",name:"symbol"}],["string tokenURI",{type:"string",name:"tokenURI"}],["uint tokenId",{type:"uint256",name:"tokenId"}],["uint8 v",{type:"uint8",name:"v"}],["uint256 balance",{type:"uint256",name:"balance"}],["uint256 tokenId",{type:"uint256",name:"tokenId"}],["uint256 value",{type:"uint256",name:"value"}],["event:address indexed from",{type:"address",name:"from",indexed:!0}],["event:address indexed to",{type:"address",name:"to",indexed:!0}],["event:uint indexed tokenId",{type:"uint256",name:"tokenId",indexed:!0}],["event:uint256 indexed tokenId",{type:"uint256",name:"tokenId",indexed:!0}]]);function ft(e,t={}){if(function(e){return Te.test(e)}(e))return function(e,t={}){const n=function(e){return ke(Te,e)}(e);if(!n)throw new st({signature:e,type:"function"});const r=pt(n.parameters),s=[],i=r.length;for(let e=0;e<i;e++)s.push(bt(r[e],{modifiers:Ye,structs:t,type:"function"}));const o=[];if(n.returns){const e=pt(n.returns),r=e.length;for(let n=0;n<r;n++)o.push(bt(e[n],{modifiers:Ye,structs:t,type:"function"}))}return{name:n.name,type:"function",stateMutability:n.stateMutability??"nonpayable",inputs:s,outputs:o}}(e,t);if(function(e){return Ce.test(e)}(e))return function(e,t={}){const n=function(e){return ke(Ce,e)}(e);if(!n)throw new st({signature:e,type:"event"});const r=pt(n.parameters),s=[],i=r.length;for(let e=0;e<i;e++)s.push(bt(r[e],{modifiers:We,structs:t,type:"event"}));return{name:n.name,type:"event",inputs:s}}(e,t);if(function(e){return Fe.test(e)}(e))return function(e,t={}){const n=function(e){return ke(Fe,e)}(e);if(!n)throw new st({signature:e,type:"error"});const r=pt(n.parameters),s=[],i=r.length;for(let e=0;e<i;e++)s.push(bt(r[e],{structs:t,type:"error"}));return{name:n.name,type:"error",inputs:s}}(e,t);if(function(e){return Ve.test(e)}(e))return function(e,t={}){const n=function(e){return ke(Ve,e)}(e);if(!n)throw new st({signature:e,type:"constructor"});const r=pt(n.parameters),s=[],i=r.length;for(let e=0;e<i;e++)s.push(bt(r[e],{structs:t,type:"constructor"}));return{type:"constructor",stateMutability:n.stateMutability??"nonpayable",inputs:s}}(e,t);if(function(e){return Ge.test(e)}(e))return function(e){const t=function(e){return ke(Ge,e)}(e);if(!t)throw new st({signature:e,type:"fallback"});return{type:"fallback",stateMutability:t.stateMutability??"nonpayable"}}(e);if(function(e){return He.test(e)}(e))return{type:"receive",stateMutability:"payable"};throw new it({signature:e})}const dt=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*(?:\spayable)?)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,lt=/^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,ht=/^u?int$/;function bt(e,t){const n=function(e,t,n){let r="";if(n)for(const e of Object.entries(n)){if(!e)continue;let t="";for(const n of e[1])t+=`[${n.type}${n.name?`:${n.name}`:""}]`;r+=`(${e[0]}{${t}})`}return t?`${t}:${e}${r}`:e}(e,t?.type,t?.structs);if(ut.has(n))return ut.get(n);const r=Me.test(e),s=ke(r?lt:dt,e);if(!s)throw new Qe({param:e});if(s.name&&function(e){return"address"===e||"bool"===e||"function"===e||"string"===e||"tuple"===e||Ne.test(e)||Re.test(e)||mt.test(e)}(s.name))throw new et({param:e,name:s.name});const i=s.name?{name:s.name}:{},o="indexed"===s.modifier?{indexed:!0}:{},a=t?.structs??{};let c,u={};if(r){c="tuple";const e=pt(s.type),t=[],n=e.length;for(let r=0;r<n;r++)t.push(bt(e[r],{structs:a}));u={components:t}}else if(s.type in a)c="tuple",u={components:a[s.type]};else if(ht.test(s.type))c=`${s.type}256`;else if("address payable"===s.type)c="address";else if(c=s.type,"struct"!==t?.type&&!gt(c))throw new Xe({type:c});if(s.modifier){if(!t?.modifiers?.has?.(s.modifier))throw new tt({param:e,type:t?.type,modifier:s.modifier});if(Ye.has(s.modifier)&&!function(e,t){return t||"bytes"===e||"string"===e||"tuple"===e}(c,!!s.array))throw new nt({param:e,type:t?.type,modifier:s.modifier})}const f={type:`${c}${s.array??""}`,...i,...o,...u};return ut.set(n,f),f}function pt(e,t=[],n="",r=0){const s=e.trim().length;for(let i=0;i<s;i++){const s=e[i],o=e.slice(i+1);switch(s){case",":return 0===r?pt(o,[...t,n.trim()]):pt(o,t,`${n}${s}`,r);case"(":return pt(o,t,`${n}${s}`,r+1);case")":return pt(o,t,`${n}${s}`,r-1);default:return pt(o,t,`${n}${s}`,r)}}if(""===n)return t;if(0!==r)throw new ct({current:n,depth:r});return t.push(n.trim()),t}function gt(e){return"address"===e||"bool"===e||"function"===e||"string"===e||Ne.test(e)||Re.test(e)}const mt=/^(?:after|alias|anonymous|apply|auto|byte|calldata|case|catch|constant|copyof|default|defined|error|event|external|false|final|function|immutable|implements|in|indexed|inline|internal|let|mapping|match|memory|mutable|null|of|override|partial|private|promise|public|pure|reference|relocatable|return|returns|sizeof|static|storage|struct|super|supports|switch|this|true|try|typedef|typeof|var|view|virtual)$/;function yt(e){const t={},n=e.length;for(let r=0;r<n;r++){const n=e[r];if(!qe(n))continue;const s=_e(n);if(!s)throw new st({signature:n,type:"struct"});const i=s.properties.split(";"),o=[],a=i.length;for(let e=0;e<a;e++){const t=i[e].trim();if(!t)continue;const n=bt(t,{type:"struct"});o.push(n)}if(!o.length)throw new ot({signature:n});t[s.name]=o}const r={},s=Object.entries(t),i=s.length;for(let e=0;e<i;e++){const[n,i]=s[e];r[n]=vt(i,t)}return r}const wt=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?$/;function vt(e,t,n=new Set){const r=[],s=e.length;for(let i=0;i<s;i++){const s=e[i];if(Me.test(s.type))r.push(s);else{const e=ke(wt,s.type);if(!e?.type)throw new rt({abiParameter:s});const{array:i,type:o}=e;if(o in t){if(n.has(o))throw new at({type:o});r.push({...s,type:`tuple${i??""}`,components:vt(t[o]??[],t,new Set([...n,o]))})}else{if(!gt(o))throw new Ke({type:o});r.push(s)}}}return r}function xt(e){const t=yt(e),n=[],r=e.length;for(let s=0;s<r;s++){const r=e[s];qe(r)||n.push(ft(r,t))}return n}function Pt(e){const t=[];if("string"==typeof e){const n=pt(e),r=n.length;for(let e=0;e<r;e++)t.push(bt(n[e],{modifiers:Ze}))}else{const n=yt(e),r=e.length;for(let s=0;s<r;s++){const r=e[s];if(qe(r))continue;const i=pt(r),o=i.length;for(let e=0;e<o;e++)t.push(bt(i[e],{modifiers:Ze,structs:n}))}}if(0===t.length)throw new Je({params:e});return t}class $t extends Error{constructor(e,t={}){const n=(()=>{if(t.cause instanceof $t){if(t.cause.details)return t.cause.details;if(t.cause.shortMessage)return t.cause.shortMessage}return t.cause&&"details"in t.cause&&"string"==typeof t.cause.details?t.cause.details:t.cause?.message?t.cause.message:t.details})(),r=t.cause instanceof $t&&t.cause.docsPath||t.docsPath,s=`https://oxlib.sh${r??""}`;super([e||"An error occurred.",...t.metaMessages?["",...t.metaMessages]:[],...n||r?["",n?`Details: ${n}`:void 0,r?`See: ${s}`:void 0]:[]].filter(e=>"string"==typeof e).join("\n"),t.cause?{cause:t.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docs",{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,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:"ox@0.1.1"}),this.cause=t.cause,this.details=n,this.docs=s,this.docsPath=r,this.shortMessage=e}walk(e){return Et(this,e)}}function Et(e,t){return t?.(e)?e:e&&"object"==typeof e&&"cause"in e&&e.cause?Et(e.cause,t):t?null:e}function At(e,t){if(sn(e)>t)throw new hn({givenSize:sn(e),maxSize:t})}const It=48,Bt=57,zt=65,Ot=70,St=97,kt=102;function Nt(e){return e>=It&&e<=Bt?e-It:e>=zt&&e<=Ot?e-(zt-10):e>=St&&e<=kt?e-(St-10):void 0}function Rt(e,t={}){const{dir:n="left"}=t;let r=e,s=0;for(let e=0;e<r.length-1&&"0"===r["left"===n?e:r.length-e-1].toString();e++)s++;return r="left"===n?r.slice(s):r.slice(0,r.length-s),r}function Mt(e,t){if(Ht(e)>t)throw new Kt({givenSize:Ht(e),maxSize:t})}function jt(e,t={}){const{dir:n,size:r=32}=t;if(0===r)return e;const s=e.replace("0x","");if(s.length>2*r)throw new Jt({size:Math.ceil(s.length/2),targetSize:r,type:"Hex"});return`0x${s["right"===n?"padEnd":"padStart"](2*r,"0")}`}const Lt=new TextEncoder,Ut=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ft(...e){return`0x${e.reduce((e,t)=>e+t.replace("0x",""),"")}`}function Ct(e,t={}){const n=`0x${Number(e)}`;return"number"==typeof t.size?(Mt(n,t.size),_t(n,t.size)):n}function Tt(e,t={}){let n="";for(let t=0;t<e.length;t++)n+=Ut[e[t]];const r=`0x${n}`;return"number"==typeof t.size?(Mt(r,t.size),Vt(r,t.size)):r}function Dt(e,t={}){const{signed:n,size:r}=t,s=BigInt(e);let i;r?i=n?(1n<<8n*BigInt(r)-1n)-1n:2n**(8n*BigInt(r))-1n:"number"==typeof e&&(i=BigInt(Number.MAX_SAFE_INTEGER));const o="bigint"==typeof i&&n?-i-1n:0;if(i&&s>i||s<o){const t="bigint"==typeof e?"n":"";throw new Yt({max:i?`${i}${t}`:void 0,min:`${o}${t}`,signed:n,size:r,value:`${e}${t}`})}const a=`0x${(n&&s<0?(1n<<BigInt(8*r))+BigInt(s):s).toString(16)}`;return r?_t(a,r):a}function qt(e,t={}){return Tt(Lt.encode(e),t)}function _t(e,t){return jt(e,{dir:"left",size:t})}function Vt(e,t){return jt(e,{dir:"right",size:t})}function Gt(e,t,n,r={}){const{strict:s}=r;!function(e,t){if("number"==typeof t&&t>0&&t>Ht(e)-1)throw new Xt({offset:t,position:"start",size:Ht(e)})}(e,t);const i=`0x${e.replace("0x","").slice(2*(t??0),2*(n??e.length))}`;return s&&function(e,t,n){if("number"==typeof t&&"number"==typeof n&&Ht(e)!==n-t)throw new Xt({offset:n,position:"end",size:Ht(e)})}(i,t,n),i}function Ht(e){return Math.ceil((e.length-2)/2)}function Zt(e,t={}){const{signed:n}=t;t.size&&Mt(e,t.size);const r=BigInt(e);if(!n)return r;const s=(e.length-2)/2,i=(1n<<8n*BigInt(s))-1n;return r<=i>>1n?r:r-i-1n}function Wt(e,t={}){const{signed:n,size:r}=t;return Number(n||r?Zt(e,t):e)}class Yt extends $t{constructor({max:e,min:t,signed:n,size:r,value:s}){super(`Number \`${s}\` is not in safe${r?` ${8*r}-bit`:""}${n?" signed":" unsigned"} integer range ${e?`(\`${t}\` to \`${e}\`)`:`(above \`${t}\`)`}`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.IntegerOutOfRangeError"})}}let Kt=class extends $t{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed \`${t}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeOverflowError"})}};class Xt extends $t{constructor({offset:e,position:t,size:n}){super(`Slice ${"start"===t?"starting":"ending"} at offset \`${e}\` is out-of-bounds (size: \`${n}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SliceOffsetOutOfBoundsError"})}}let Jt=class extends $t{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${t}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeExceedsPaddingSizeError"})}};const Qt=new TextDecoder,en=new TextEncoder;function tn(e){return e instanceof Uint8Array?e:"string"==typeof e?nn(e):function(e){return e instanceof Uint8Array?e:new Uint8Array(e)}(e)}function nn(e,t={}){const{size:n}=t;let r=e;n&&(Mt(e,n),r=Vt(e,n));let s=r.slice(2);s.length%2&&(s=`0${s}`);const i=s.length/2,o=new Uint8Array(i);for(let e=0,t=0;e<i;e++){const n=Nt(s.charCodeAt(t++)),r=Nt(s.charCodeAt(t++));if(void 0===n||void 0===r)throw new $t(`Invalid byte sequence ("${s[t-2]}${s[t-1]}" in "${s}").`);o[e]=16*n+r}return o}function rn(e,t={}){const{size:n}=t,r=en.encode(e);return"number"==typeof n?(At(r,n),function(e,t){return function(e,t={}){const{dir:n,size:r=32}=t;if(0===r)return e;if(e.length>r)throw new bn({size:e.length,targetSize:r,type:"Bytes"});const s=new Uint8Array(r);for(let t=0;t<r;t++){const i="right"===n;s[i?t:r-t-1]=e[i?t:e.length-t-1]}return s}(e,{dir:"right",size:t})}(r,n)):r}function sn(e){return e.length}function on(e,t,n,r={}){const{strict:s}=r;return e.slice(t,n)}function an(e,t={}){const{size:n}=t;void 0!==n&&At(e,n);return Zt(Tt(e,t),t)}function cn(e,t={}){const{size:n}=t;let r=e;if(void 0!==n&&(At(r,n),r=dn(r)),r.length>1||r[0]>1)throw new ln(r);return Boolean(r[0])}function un(e,t={}){const{size:n}=t;void 0!==n&&At(e,n);return Wt(Tt(e,t),t)}function fn(e,t={}){const{size:n}=t;let r=e;return void 0!==n&&(At(r,n),r=Rt(r,{dir:"right"})),Qt.decode(r)}function dn(e){return Rt(e,{dir:"left"})}class ln extends $t{constructor(e){super(`Bytes value \`${e}\` is not a valid boolean.`,{metaMessages:["The bytes array must contain a single byte of either a `0` or `1` value."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.InvalidBytesBooleanError"})}}class hn extends $t{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed \`${t}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeOverflowError"})}}class bn extends $t{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${t}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeExceedsPaddingSizeError"})}}class pn extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const t=super.get(e);return super.has(e)&&void 0!==t&&(this.delete(e),super.set(e,t)),t}set(e,t){if(super.set(e,t),this.maxSize&&this.size>this.maxSize){const e=this.keys().next().value;e&&this.delete(e)}return this}}const gn={checksum:new pn(8192)}.checksum;function mn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function yn(e,...t){if(!((n=e)instanceof Uint8Array||ArrayBuffer.isView(n)&&"Uint8Array"===n.constructor.name))throw new Error("Uint8Array expected"); /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */ var n;if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function wn(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 vn(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function xn(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const Pn=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])()?e=>e:function(e){for(let t=0;t<e.length;t++)e[t]=xn(e[t]);return e};function $n(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}(e)),yn(e),e}class En{}const An=BigInt(2**32-1),In=BigInt(32);function Bn(e,t=!1){return t?{h:Number(e&An),l:Number(e>>In&An)}:{h:0|Number(e>>In&An),l:0|Number(e&An)}}const zn=BigInt(0),On=BigInt(1),Sn=BigInt(2),kn=BigInt(7),Nn=BigInt(256),Rn=BigInt(113),Mn=[],jn=[],Ln=[];for(let e=0,t=On,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],Mn.push(2*(5*r+n)),jn.push((e+1)*(e+2)/2%64);let s=zn;for(let e=0;e<7;e++)t=(t<<On^(t>>kn)*Rn)%Nn,t&Sn&&(s^=On<<(On<<BigInt(e))-On);Ln.push(s)}const Un=function(e,t=!1){const n=e.length;let r=new Uint32Array(n),s=new Uint32Array(n);for(let i=0;i<n;i++){const{h:n,l:o}=Bn(e[i],t);[r[i],s[i]]=[n,o]}return[r,s]}(Ln,!0),Fn=Un[0],Cn=Un[1],Tn=(e,t,n)=>n>32?((e,t,n)=>t<<n-32|e>>>64-n)(e,t,n):((e,t,n)=>e<<n|t>>>32-n)(e,t,n),Dn=(e,t,n)=>n>32?((e,t,n)=>e<<n-32|t>>>64-n)(e,t,n):((e,t,n)=>t<<n|e>>>32-n)(e,t,n);class qn extends En{constructor(e,t,n,r=!1,s=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.rounds=s,mn(n),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");var i;this.state=new Uint8Array(200),this.state32=(i=this.state,new Uint32Array(i.buffer,i.byteOffset,Math.floor(i.byteLength/4)))}clone(){return this._cloneInto()}keccak(){Pn(this.state32),function(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let t=0;t<10;t++)n[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const r=(t+8)%10,s=(t+2)%10,i=n[s],o=n[s+1],a=Tn(i,o,1)^n[r],c=Dn(i,o,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=a,e[t+n+1]^=c}let t=e[2],s=e[3];for(let n=0;n<24;n++){const r=jn[n],i=Tn(t,s,r),o=Dn(t,s,r),a=Mn[n];t=e[a],s=e[a+1],e[a]=i,e[a+1]=o}for(let t=0;t<50;t+=10){for(let r=0;r<10;r++)n[r]=e[t+r];for(let r=0;r<10;r++)e[t+r]^=~n[(r+2)%10]&n[(r+4)%10]}e[0]^=Fn[r],e[1]^=Cn[r]}vn(n)}(this.state32,this.rounds),Pn(this.state32),this.posOut=0,this.pos=0}update(e){wn(this),yn(e=$n(e));const{blockLen:t,state:n}=this,r=e.length;for(let s=0;s<r;){const i=Math.min(t-this.pos,r-s);for(let t=0;t<i;t++)n[this.pos++]^=e[s++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,128&t&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){wn(this,!1),yn(e),this.finish();const t=this.state,{blockLen:n}=this;for(let r=0,s=e.length;r<s;){this.posOut>=n&&this.keccak();const i=Math.min(n-this.posOut,s-r);e.set(t.subarray(this.posOut,this.posOut+i),r),this.posOut+=i,r+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return mn(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(function(e,t){yn(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,vn(this.state)}_cloneInto(e){const{blockLen:t,suffix:n,outputLen:r,rounds:s,enableXOF:i}=this;return e||(e=new qn(t,n,r,i,s)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=s,e.suffix=n,e.outputLen=r,e.enableXOF=i,e.destroyed=this.destroyed,e}}const _n=(e,t,n)=>function(e){const t=t=>e().update($n(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}(()=>new qn(t,e,n)),Vn=(()=>_n(1,136,32))();const Gn=/^0x[a-fA-F0-9]{40}$/;function Hn(e,t={}){const{strict:n=!0}=t;if(!Gn.test(e))throw new Wn({address:e,cause:new Yn});if(n){if(e.toLowerCase()===e)return;if(Zn(e)!==e)throw new Wn({address:e,cause:new Kn})}}function Zn(e){if(gn.has(e))return gn.get(e);Hn(e,{strict:!1});const t=e.substring(2).toLowerCase(),n=function(e,t={}){const{as:n=("string"==typeof e?"Hex":"Bytes")}=t,r=Vn(tn(e));return"Bytes"===n?r:Tt(r)}(rn(t),{as:"Bytes"}),r=t.split("");for(let e=0;e<40;e+=2)n[e>>1]>>4>=8&&r[e]&&(r[e]=r[e].toUpperCase()),(15&n[e>>1])>=8&&r[e+1]&&(r[e+1]=r[e+1].toUpperCase());const s=`0x${r.join("")}`;return gn.set(e,s),s}class Wn extends $t{constructor({address:e,cause:t}){super(`Address "${e}" is invalid.`,{cause:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidAddressError"})}}class Yn extends $t{constructor(){super("Address is not a 20 byte (40 hexadecimal character) value."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidInputError"})}}class Kn extends $t{constructor(){super("Address does not match its checksum counterpart."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidChecksumError"})}}const Xn=/^(.*)\[([0-9]*)\]$/,Jn=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,Qn=/^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/,er=2n**256n-1n;function tr(e,t,n){const{checksumAddress:r,staticPosition:s}=n,i=or(t.type);if(i){const[n,o]=i;return function(e,t,n){const{checksumAddress:r,length:s,staticPosition:i}=n;if(!s){const n=i+un(e.readBytes(rr)),s=n+nr;e.setPosition(n);const o=un(e.readBytes(nr)),a=ar(t);let c=0;const u=[];for(let n=0;n<o;++n){e.setPosition(s+(a?32*n:c));const[i,o]=tr(e,t,{checksumAddress:r,staticPosition:s});c+=o,u.push(i)}return e.setPosition(i+32),[u,32]}if(ar(t)){const n=i+un(e.readBytes(rr)),o=[];for(let i=0;i<s;++i){e.setPosition(n+32*i);const[s]=tr(e,t,{checksumAddress:r,staticPosition:n});o.push(s)}return e.setPosition(i+32),[o,32]}let o=0;const a=[];for(let n=0;n<s;++n){const[n,s]=tr(e,t,{checksumAddress:r,staticPosition:i+o});o+=s,a.push(n)}return[a,o]}(e,{...t,type:o},{checksumAddress:r,length:n,staticPosition:s})}if("tuple"===t.type)return function(e,t,n){const{checksumAddress:r,staticPosition:s}=n,i=0===t.components.length||t.components.some(({name:e})=>!e),o=i?[]:{};let a=0;if(ar(t)){const n=s+un(e.readBytes(rr));for(let s=0;s<t.components.length;++s){const c=t.components[s];e.setPosition(n+a);const[u,f]=tr(e,c,{checksumAddress:r,staticPosition:n});a+=f,o[i?s:c?.name]=u}return e.setPosition(s+32),[o,32]}for(let n=0;n<t.components.length;++n){const c=t.components[n],[u,f]=tr(e,c,{checksumAddress:r,staticPosition:s});o[i?n:c?.name]=u,a+=f}return[o,a]}(e,t,{checksumAddress:r,staticPosition:s});if("address"===t.type)return function(e,t={}){const{checksum:n=!1}=t,r=e.readBytes(32),s=e=>n?Zn(e):e;return[s(Tt(on(r,-20))),32]}(e,{checksum:r});if("bool"===t.type)return function(e){return[cn(e.readBytes(32),{size:32}),32]}(e);if(t.type.startsWith("bytes"))return function(e,t,{staticPosition:n}){const[r,s]=t.type.split("bytes");if(!s){const t=un(e.readBytes(32));e.setPosition(n+t);const r=un(e.readBytes(32));if(0===r)return e.setPosition(n+32),["0x",32];const s=e.readBytes(r);return e.setPosition(n+32),[Tt(s),32]}const i=Tt(e.readBytes(Number.parseInt(s,10),32));return[i,32]}(e,t,{staticPosition:s});if(t.type.startsWith("uint")||t.type.startsWith("int"))return function(e,t){const n=t.type.startsWith("int"),r=Number.parseInt(t.type.split("int")[1]||"256",10),s=e.readBytes(32);return[r>48?an(s,{signed:n}):un(s,{signed:n}),32]}(e,t);if("string"===t.type)return function(e,{staticPosition:t}){const n=un(e.readBytes(32)),r=t+n;e.setPosition(r);const s=un(e.readBytes(32));if(0===s)return e.setPosition(t+32),["",32];const i=e.readBytes(s,32),o=fn(dn(i));return e.setPosition(t+32),[o,32]}(e,{staticPosition:s});throw new Pr(t.type)}const nr=32,rr=32;function sr({checksumAddress:e=!1,parameter:t,value:n}){const r=t,s=or(r.type);if(s){const[t,i]=s;return function(e,t){const{checksumAddress:n,length:r,parameter:s}=t,i=null===r;if(!Array.isArray(e))throw new xr(e);if(!i&&e.length!==r)throw new yr({expectedLength:r,givenLength:e.length,type:`${s.type}[${r}]`});let o=!1;const a=[];for(let t=0;t<e.length;t++){const r=sr({checksumAddress:n,parameter:s,value:e[t]});r.dynamic&&(o=!0),a.push(r)}if(i||o){const e=ir(a);if(i){const t=Dt(a.length,{size:32});return{dynamic:!0,encoded:a.length>0?Ft(t,e):t}}if(o)return{dynamic:!0,encoded:e}}return{dynamic:!1,encoded:Ft(...a.map(({encoded:e})=>e))}}(n,{checksumAddress:e,length:t,parameter:{...r,type:i}})}if("tuple"===r.type)return function(e,t){const{checksumAddress:n,parameter:r}=t;let s=!1;const i=[];for(let t=0;t<r.components.length;t++){const o=r.components[t],a=sr({checksumAddress:n,parameter:o,value:e[Array.isArray(e)?t:o.name]});i.push(a),a.dynamic&&(s=!0)}return{dynamic:s,encoded:s?ir(i):Ft(...i.map(({encoded:e})=>e))}}(n,{checksumAddress:e,parameter:r});if("address"===r.type)return function(e,t){const{checksum:n=!1}=t;return Hn(e,{strict:n}),{dynamic:!1,encoded:_t(e.toLowerCase())}}(n,{checksum:e});if("bool"===r.type)return function(e){if("boolean"!=typeof e)throw new $t(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:_t(Ct(e))}}(n);if(r.type.startsWith("uint")||r.type.startsWith("int")){const e=r.type.startsWith("int"),[,,t="256"]=Qn.exec(r.type)??[];return function(e,{signed:t,size:n}){if("number"==typeof n){const r=2n**(BigInt(n)-(t?1n:0n))-1n,s=t?-r-1n:0n;if(e>r||e<s)throw new Yt({max:r.toString(),min:s.toString(),signed:t,size:n/8,value:e.toString()})}return{dynamic:!1,encoded:Dt(e,{size:32,signed:t})}}(n,{signed:e,size:Number(t)})}if(r.type.startsWith("bytes"))return function(e,{type:t}){const[,n]=t.split("bytes"),r=Ht(e);if(!n){let t=e;return r%32!=0&&(t=Vt(t,32*Math.ceil((e.length-2)/2/32))),{dynamic:!0,encoded:Ft(_t(Dt(r,{size:32})),t)}}if(r!==Number.parseInt(n,10))throw new wr({expectedSize:Number.parseInt(n,10),value:e});return{dynamic:!1,encoded:Vt(e)}}(n,{type:r.type});if("string"===r.type)return function(e){const t=qt(e),n=Math.ceil(Ht(t)/32),r=[];for(let e=0;e<n;e++)r.push(Vt(Gt(t,32*e,32*(e+1))));return{dynamic:!0,encoded:Ft(Vt(Dt(Ht(t),{size:32})),...r)}}(n);throw new Pr(r.type)}function ir(e){let t=0;for(let n=0;n<e.length;n++){const{dynamic:r,encoded:s}=e[n];t+=r?32:Ht(s)}const n=[],r=[];let s=0;for(let i=0;i<e.length;i++){const{dynamic:o,encoded:a}=e[i];o?(n.push(Dt(t+s,{size:32})),r.push(a),s+=Ht(a)):n.push(a)}return Ft(...n,...r)}function or(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}function ar(e){const{type:t}=e;if("string"===t)return!0;if("bytes"===t)return!0;if(t.endsWith("[]"))return!0;if("tuple"===t)return e.components?.some(ar);const n=or(e.type);return!(!n||!ar({...e,type:n[1]}))}const cr={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 dr({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new fr({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new ur({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 ur({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 n=t??this.position;return this.assertPosition(n+e-1),this.bytes.subarray(n,n+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,255&e),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 n=this.inspectBytes(e);return this.position+=t??e,n},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.r