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

3 lines 245 kB
import*as e from"node:crypto";const t=[{inputs:[{components:[{name:"target",type:"address"},{name:"allowFailure",type:"bool"},{name:"callData",type:"bytes"}],name:"calls",type:"tuple[]"}],name:"aggregate3",outputs:[{components:[{name:"success",type:"bool"},{name:"returnData",type:"bytes"}],name:"returnData",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockTimestamp",outputs:[{internalType:"uint256",name:"timestamp",type:"uint256"}],stateMutability:"view",type:"function"}],n=[{name:"query",type:"function",stateMutability:"view",inputs:[{type:"tuple[]",name:"queries",components:[{type:"address",name:"sender"},{type:"string[]",name:"urls"},{type:"bytes",name:"data"}]}],outputs:[{type:"bool[]",name:"failures"},{type:"bytes[]",name:"responses"}]},{name:"HttpError",type:"error",inputs:[{type:"uint16",name:"status"},{type:"string",name:"message"}]}],r=[{inputs:[{name:"dns",type:"bytes"}],name:"DNSDecodingFailed",type:"error"},{inputs:[{name:"ens",type:"string"}],name:"DNSEncodingFailed",type:"error"},{inputs:[],name:"EmptyAddress",type:"error"},{inputs:[{name:"status",type:"uint16"},{name:"message",type:"string"}],name:"HttpError",type:"error"},{inputs:[],name:"InvalidBatchGatewayResponse",type:"error"},{inputs:[{name:"errorData",type:"bytes"}],name:"ResolverError",type:"error"},{inputs:[{name:"name",type:"bytes"},{name:"resolver",type:"address"}],name:"ResolverNotContract",type:"error"},{inputs:[{name:"name",type:"bytes"}],name:"ResolverNotFound",type:"error"},{inputs:[{name:"primary",type:"string"},{name:"primaryAddress",type:"bytes"}],name:"ReverseAddressMismatch",type:"error"},{inputs:[{internalType:"bytes4",name:"selector",type:"bytes4"}],name:"UnsupportedResolverProfile",type:"error"}],s=[...r,{name:"resolveWithGateways",type:"function",stateMutability:"view",inputs:[{name:"name",type:"bytes"},{name:"data",type:"bytes"},{name:"gateways",type:"string[]"}],outputs:[{name:"",type:"bytes"},{name:"address",type:"address"}]}],a=[...r,{name:"reverseWithGateways",type:"function",stateMutability:"view",inputs:[{type:"bytes",name:"reverseName"},{type:"uint256",name:"coinType"},{type:"string[]",name:"gateways"}],outputs:[{type:"string",name:"resolvedName"},{type:"address",name:"resolver"},{type:"address",name:"reverseResolver"}]}],o=[{name:"text",type:"function",stateMutability:"view",inputs:[{name:"name",type:"bytes32"},{name:"key",type:"string"}],outputs:[{name:"",type:"string"}]}],i=[{name:"addr",type:"function",stateMutability:"view",inputs:[{name:"name",type:"bytes32"}],outputs:[{name:"",type:"address"}]},{name:"addr",type:"function",stateMutability:"view",inputs:[{name:"name",type:"bytes32"},{name:"coinType",type:"uint256"}],outputs:[{name:"",type:"bytes"}]}],c=[{name:"isValidSignature",type:"function",stateMutability:"view",inputs:[{name:"hash",type:"bytes32"},{name:"signature",type:"bytes"}],outputs:[{name:"",type:"bytes4"}]}],u=[{inputs:[{name:"_signer",type:"address"},{name:"_hash",type:"bytes32"},{name:"_signature",type:"bytes"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[{name:"_signer",type:"address"},{name:"_hash",type:"bytes32"},{name:"_signature",type:"bytes"}],outputs:[{type:"bool"}],stateMutability:"nonpayable",type:"function",name:"isValidSig"}];function d(e,{includeName:t=!1}={}){if("function"!==e.type&&"event"!==e.type&&"error"!==e.type)throw new G(e.type);return`${e.name}(${f(e.inputs,{includeName:t})})`}function f(e,{includeName:t=!1}={}){return e?e.map(e=>function(e,{includeName:t}){if(e.type.startsWith("tuple"))return`(${f(e.components,{includeName:t})})${e.type.slice(5)}`;return e.type+(t&&e.name?` ${e.name}`:"")}(e,{includeName:t})).join(t?", ":","):""}function l(e,{strict:t=!0}={}){return!!e&&("string"==typeof e&&(t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")))}function h(e){return l(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}const p="2.38.2";let b=({docsBaseUrl:e,docsPath:t="",docsSlug:n})=>t?`${e??"https://viem.sh"}${t}${n?`#${n}`:""}`:void 0,m=`viem@${p}`,y=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,a=b?.({...n,docsPath:s});super([t||"An error occurred.","",...n.metaMessages?[...n.metaMessages,""]:[],...a?[`Docs: ${a}`]:[],...r?[`Details: ${r}`]:[],...m?[`Version: ${m}`]:[]].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=p}walk(e){return g(this,e)}};function g(e,t){return t?.(e)?e:e&&"object"==typeof e&&"cause"in e&&void 0!==e.cause?g(e.cause,t):t?null:e}class w extends y{constructor({docsPath:e}){super(["A constructor was not found on the ABI.","Make sure you are using the correct ABI and that the constructor exists on it."].join("\n"),{docsPath:e,name:"AbiConstructorNotFoundError"})}}class v extends y{constructor({docsPath:e}){super(["Constructor arguments were provided (`args`), but a constructor parameters (`inputs`) were not found on the ABI.","Make sure you are using the correct ABI, and that the `inputs` attribute on the constructor exists."].join("\n"),{docsPath:e,name:"AbiConstructorParamsNotFoundError"})}}class x extends y{constructor({data:e,params:t,size:n}){super([`Data size of ${n} bytes is too small for given parameters.`].join("\n"),{metaMessages:[`Params: (${f(t,{includeName:!0})})`,`Data: ${e} (${n} bytes)`],name:"AbiDecodingDataSizeTooSmallError"}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"params",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"size",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=e,this.params=t,this.size=n}}class P extends y{constructor(){super('Cannot decode zero data ("0x") with ABI parameters.',{name:"AbiDecodingZeroDataError"})}}class E extends y{constructor({expectedLength:e,givenLength:t,type:n}){super([`ABI encoding array length mismatch for type ${n}.`,`Expected length: ${e}`,`Given length: ${t}`].join("\n"),{name:"AbiEncodingArrayLengthMismatchError"})}}class k extends y{constructor({expectedSize:e,value:t}){super(`Size of bytes "${t}" (bytes${h(t)}) does not match expected size (bytes${e}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class B extends y{constructor({expectedLength:e,givenLength:t}){super(["ABI encoding params/values length mismatch.",`Expected length (params): ${e}`,`Given length (values): ${t}`].join("\n"),{name:"AbiEncodingLengthMismatchError"})}}class I extends y{constructor(e,{docsPath:t}){super([`Arguments (\`args\`) were provided to "${e}", but "${e}" on the ABI does not contain any parameters (\`inputs\`).`,"Cannot encode error result without knowing what the parameter types are.","Make sure you are using the correct ABI and that the inputs exist on it."].join("\n"),{docsPath:t,name:"AbiErrorInputsNotFoundError"})}}class $ extends y{constructor(e,{docsPath:t}={}){super([`Error ${e?`"${e}" `:""}not found on ABI.`,"Make sure you are using the correct ABI and that the error exists on it."].join("\n"),{docsPath:t,name:"AbiErrorNotFoundError"})}}class A extends y{constructor(e,{docsPath:t}){super([`Encoded error signature "${e}" not found on ABI.`,"Make sure you are using the correct ABI and that the error exists on it.",`You can look up the decoded signature here: https://openchain.xyz/signatures?query=${e}.`].join("\n"),{docsPath:t,name:"AbiErrorSignatureNotFoundError"}),Object.defineProperty(this,"signature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.signature=e}}class N extends y{constructor({docsPath:e}){super("Cannot extract event signature from empty topics.",{docsPath:e,name:"AbiEventSignatureEmptyTopicsError"})}}class z extends y{constructor(e,{docsPath:t}){super([`Encoded event signature "${e}" not found on ABI.`,"Make sure you are using the correct ABI and that the event exists on it.",`You can look up the signature here: https://openchain.xyz/signatures?query=${e}.`].join("\n"),{docsPath:t,name:"AbiEventSignatureNotFoundError"})}}class O extends y{constructor(e,{docsPath:t}={}){super([`Event ${e?`"${e}" `:""}not found on ABI.`,"Make sure you are using the correct ABI and that the event exists on it."].join("\n"),{docsPath:t,name:"AbiEventNotFoundError"})}}class T extends y{constructor(e,{docsPath:t}={}){super([`Function ${e?`"${e}" `:""}not found on ABI.`,"Make sure you are using the correct ABI and that the function exists on it."].join("\n"),{docsPath:t,name:"AbiFunctionNotFoundError"})}}class S extends y{constructor(e,{docsPath:t}){super([`Function "${e}" does not contain any \`outputs\` on ABI.`,"Cannot decode function result without knowing what the parameter types are.","Make sure you are using the correct ABI and that the function exists on it."].join("\n"),{docsPath:t,name:"AbiFunctionOutputsNotFoundError"})}}class F extends y{constructor(e,{docsPath:t}){super([`Encoded function signature "${e}" not found on ABI.`,"Make sure you are using the correct ABI and that the function exists on it.",`You can look up the signature here: https://openchain.xyz/signatures?query=${e}.`].join("\n"),{docsPath:t,name:"AbiFunctionSignatureNotFoundError"})}}class C extends y{constructor(e,t){super("Found ambiguous types in overloaded ABI items.",{metaMessages:[`\`${e.type}\` in \`${d(e.abiItem)}\`, and`,`\`${t.type}\` in \`${d(t.abiItem)}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."],name:"AbiItemAmbiguityError"})}}let R=class extends y{constructor({expectedSize:e,givenSize:t}){super(`Expected bytes${e}, got bytes${t}.`,{name:"BytesSizeMismatchError"})}};class U extends y{constructor({abiItem:e,data:t,params:n,size:r}){super([`Data size of ${r} bytes is too small for non-indexed event parameters.`].join("\n"),{metaMessages:[`Params: (${f(n,{includeName:!0})})`,`Data: ${t} (${r} bytes)`],name:"DecodeLogDataMismatch"}),Object.defineProperty(this,"abiItem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"params",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"size",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abiItem=e,this.data=t,this.params=n,this.size=r}}class M extends y{constructor({abiItem:e,param:t}){super([`Expected a topic for indexed event parameter${t.name?` "${t.name}"`:""} on event "${d(e,{includeName:!0})}".`].join("\n"),{name:"DecodeLogTopicsMismatch"}),Object.defineProperty(this,"abiItem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abiItem=e}}class L extends y{constructor(e,{docsPath:t}){super([`Type "${e}" is not a valid encoding type.`,"Please provide a valid ABI type."].join("\n"),{docsPath:t,name:"InvalidAbiEncodingType"})}}class j extends y{constructor(e,{docsPath:t}){super([`Type "${e}" is not a valid decoding type.`,"Please provide a valid ABI type."].join("\n"),{docsPath:t,name:"InvalidAbiDecodingType"})}}let q=class extends y{constructor(e){super([`Value "${e}" is not a valid array.`].join("\n"),{name:"InvalidArrayError"})}};class G extends y{constructor(e){super([`"${e}" is not a valid definition type.`,'Valid types: "function", "event", "error"'].join("\n"),{name:"InvalidDefinitionTypeError"})}}let _=class extends y{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"})}},D=class extends y{constructor({offset:e,position:t,size:n}){super(`Slice ${"start"===t?"starting":"ending"} at offset "${e}" is out-of-bounds (size: ${n}).`,{name:"SliceOffsetOutOfBoundsError"})}},H=class extends y{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 V extends y{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 W(e,{dir:t,size:n=32}={}){return"string"==typeof e?Z(e,{dir:t,size:n}):function(e,{dir:t,size:n=32}={}){if(null===n)return e;if(e.length>n)throw new H({size:e.length,targetSize:n,type:"bytes"});const r=new Uint8Array(n);for(let s=0;s<n;s++){const a="right"===t;r[a?s:n-s-1]=e[a?s:e.length-s-1]}return r}(e,{dir:t,size:n})}function Z(e,{dir:t,size:n=32}={}){if(null===n)return e;const r=e.replace("0x","");if(r.length>2*n)throw new H({size:Math.ceil(r.length/2),targetSize:n,type:"hex"});return`0x${r["right"===t?"padEnd":"padStart"](2*n,"0")}`}let Y=class extends y{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"})}},K=class extends y{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 J extends y{constructor(e){super(`Hex value "${e}" is not a valid boolean. The hex value must be "0x0" (false) or "0x1" (true).`,{name:"InvalidHexBooleanError"})}}let X=class extends y{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}};function Q(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 ee(e,{size:t}){if(h(e)>t)throw new X({givenSize:h(e),maxSize:t})}function te(e,t={}){const{signed:n}=t;t.size&&ee(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 ne(e,t={}){return Number(te(e,t))}const re=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function se(e,t={}){return"number"==typeof e||"bigint"==typeof e?ie(e,t):"string"==typeof e?ue(e,t):"boolean"==typeof e?ae(e,t):oe(e,t)}function ae(e,t={}){const n=`0x${Number(e)}`;return"number"==typeof t.size?(ee(n,{size:t.size}),W(n,{size:t.size})):n}function oe(e,t={}){let n="";for(let t=0;t<e.length;t++)n+=re[e[t]];const r=`0x${n}`;return"number"==typeof t.size?(ee(r,{size:t.size}),W(r,{dir:"right",size:t.size})):r}function ie(e,t={}){const{signed:n,size:r}=t,s=BigInt(e);let a;r?a=n?(1n<<8n*BigInt(r)-1n)-1n:2n**(8n*BigInt(r))-1n:"number"==typeof e&&(a=BigInt(Number.MAX_SAFE_INTEGER));const o="bigint"==typeof a&&n?-a-1n:0;if(a&&s>a||s<o){const t="bigint"==typeof e?"n":"";throw new Y({max:a?`${a}${t}`:void 0,min:`${o}${t}`,signed:n,size:r,value:`${e}${t}`})}const i=`0x${(n&&s<0?(1n<<BigInt(8*r))+BigInt(s):s).toString(16)}`;return r?W(i,{size:r}):i}const ce=new TextEncoder;function ue(e,t={}){return oe(ce.encode(e),t)}const de=new TextEncoder;function fe(e,t={}){return"number"==typeof e||"bigint"==typeof e?function(e,t){const n=ie(e,t);return pe(n)}(e,t):"boolean"==typeof e?function(e,t={}){const n=new Uint8Array(1);if(n[0]=Number(e),"number"==typeof t.size)return ee(n,{size:t.size}),W(n,{size:t.size});return n}(e,t):l(e)?pe(e,t):be(e,t)}const le={zero:48,nine:57,A:65,F:70,a:97,f:102};function he(e){return e>=le.zero&&e<=le.nine?e-le.zero:e>=le.A&&e<=le.F?e-(le.A-10):e>=le.a&&e<=le.f?e-(le.a-10):void 0}function pe(e,t={}){let n=e;t.size&&(ee(n,{size:t.size}),n=W(n,{dir:"right",size:t.size}));let r=n.slice(2);r.length%2&&(r=`0${r}`);const s=r.length/2,a=new Uint8Array(s);for(let e=0,t=0;e<s;e++){const n=he(r.charCodeAt(t++)),s=he(r.charCodeAt(t++));if(void 0===n||void 0===s)throw new y(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);a[e]=16*n+s}return a}function be(e,t={}){const n=de.encode(e);return"number"==typeof t.size?(ee(n,{size:t.size}),W(n,{dir:"right",size:t.size})):n}const me=BigInt(2**32-1),ye=BigInt(32);function ge(e,t=!1){return t?{h:Number(e&me),l:Number(e>>ye&me)}:{h:0|Number(e>>ye&me),l:0|Number(e&me)}}const we=e&&"object"==typeof e&&"webcrypto"in e?e.webcrypto:e&&"object"==typeof e&&"randomBytes"in e?e:void 0;function ve(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function xe(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 Pe(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 Ee(e,t){xe(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function ke(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Be(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ie(e,t){return e<<32-t|e>>>t}function $e(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const Ae=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])()?e=>e:function(e){for(let t=0;t<e.length;t++)e[t]=$e(e[t]);return e};function Ne(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)),xe(e),e}let ze=class{};function Oe(e){const t=t=>e().update(Ne(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Te(e=32){if(we&&"function"==typeof we.getRandomValues)return we.getRandomValues(new Uint8Array(e));if(we&&"function"==typeof we.randomBytes)return Uint8Array.from(we.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}const Se=BigInt(0),Fe=BigInt(1),Ce=BigInt(2),Re=BigInt(7),Ue=BigInt(256),Me=BigInt(113),Le=[],je=[],qe=[];for(let e=0,t=Fe,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],Le.push(2*(5*r+n)),je.push((e+1)*(e+2)/2%64);let s=Se;for(let e=0;e<7;e++)t=(t<<Fe^(t>>Re)*Me)%Ue,t&Ce&&(s^=Fe<<(Fe<<BigInt(e))-Fe);qe.push(s)}const Ge=function(e,t=!1){const n=e.length;let r=new Uint32Array(n),s=new Uint32Array(n);for(let a=0;a<n;a++){const{h:n,l:o}=ge(e[a],t);[r[a],s[a]]=[n,o]}return[r,s]}(qe,!0),_e=Ge[0],De=Ge[1],He=(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),Ve=(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 We=class e extends ze{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,ve(n),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");var a;this.state=new Uint8Array(200),this.state32=(a=this.state,new Uint32Array(a.buffer,a.byteOffset,Math.floor(a.byteLength/4)))}clone(){return this._cloneInto()}keccak(){Ae(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,a=n[s],o=n[s+1],i=He(a,o,1)^n[r],c=Ve(a,o,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=i,e[t+n+1]^=c}let t=e[2],s=e[3];for(let n=0;n<24;n++){const r=je[n],a=He(t,s,r),o=Ve(t,s,r),i=Le[n];t=e[i],s=e[i+1],e[i]=a,e[i+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]^=_e[r],e[1]^=De[r]}ke(n)}(this.state32,this.rounds),Ae(this.state32),this.posOut=0,this.pos=0}update(e){Pe(this),xe(e=Ne(e));const{blockLen:t,state:n}=this,r=e.length;for(let s=0;s<r;){const a=Math.min(t-this.pos,r-s);for(let t=0;t<a;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){Pe(this,!1),xe(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 a=Math.min(n-this.posOut,s-r);e.set(t.subarray(this.posOut,this.posOut+a),r),this.posOut+=a,r+=a}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return ve(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Ee(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,ke(this.state)}_cloneInto(t){const{blockLen:n,suffix:r,outputLen:s,rounds:a,enableXOF:o}=this;return t||(t=new e(n,r,s,o,a)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=a,t.suffix=r,t.outputLen=s,t.enableXOF=o,t.destroyed=this.destroyed,t}};const Ze=(()=>{return e=1,t=136,n=32,Oe(()=>new We(t,e,n));var e,t,n})();function Ye(e,t){const n=t||"hex",r=Ze(l(e,{strict:!1})?fe(e):e);return"bytes"===n?r:se(r)}let Ke=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}};const Je=/^0x[a-fA-F0-9]{40}$/,Xe=new Ke(8192);function Qe(e,t){const{strict:n=!0}=t??{},r=`${e}.${n}`;if(Xe.has(r))return Xe.get(r);const s=!(!Je.test(e)||e.toLowerCase()!==e&&n&&tt(e)!==e);return Xe.set(r,s),s}const et=new Ke(8192);function tt(e,t){if(et.has(`${e}.${t}`))return et.get(`${e}.${t}`);const n=e.substring(2).toLowerCase(),r=Ye(be(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 a=`0x${s.join("")}`;return et.set(`${e}.${t}`,a),a}function nt(e,t){if(!Qe(e,{strict:!1}))throw new _({address:e});return tt(e,t)}let rt=class extends y{constructor({offset:e}){super(`Offset \`${e}\` cannot be negative.`,{name:"NegativeOffsetError"})}},st=class extends y{constructor({length:e,position:t}){super(`Position \`${t}\` is out of bounds (\`0 < position < ${e}\`).`,{name:"PositionOutOfBoundsError"})}},at=class extends y{constructor({count:e,limit:t}){super(`Recursive read limit of \`${t}\` exceeded (recursive read count: \`${e}\`).`,{name:"RecursiveReadLimitExceededError"})}};const ot={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 at({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new st({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new rt({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 rt({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.recursiveReadCount++}};function it(e,{recursiveReadLimit:t=8192}={}){const n=Object.create(ot);return n.bytes=e,n.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),n.positionReadCount=new Map,n.recursiveReadLimit=t,n}function ct(e,t,n,{strict:r}={}){return l(e,{strict:!1})?lt(e,t,n,{strict:r}):ft(e,t,n,{strict:r})}function ut(e,t){if("number"==typeof t&&t>0&&t>h(e)-1)throw new D({offset:t,position:"start",size:h(e)})}function dt(e,t,n){if("number"==typeof t&&"number"==typeof n&&h(e)!==n-t)throw new D({offset:n,position:"end",size:h(e)})}function ft(e,t,n,{strict:r}={}){ut(e,t);const s=e.slice(t,n);return r&&dt(s,t,n),s}function lt(e,t,n,{strict:r}={}){ut(e,t);const s=`0x${e.replace("0x","").slice(2*(t??0),2*(n??e.length))}`;return r&&dt(s,t,n),s}function ht(e,t={}){void 0!==t.size&&ee(e,{size:t.size});return te(oe(e,t),t)}function pt(e,t={}){let n=e;if(void 0!==t.size&&(ee(n,{size:t.size}),n=Q(n)),n.length>1||n[0]>1)throw new K(n);return Boolean(n[0])}function bt(e,t={}){void 0!==t.size&&ee(e,{size:t.size});return ne(oe(e,t),t)}function mt(e){return"string"==typeof e[0]?yt(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 yt(e){return`0x${e.reduce((e,t)=>e+t.replace("0x",""),"")}`}const gt=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,wt=/^(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)?$/;function vt(e,t){if(e.length!==t.length)throw new B({expectedLength:e.length,givenLength:t.length});const n=function({params:e,values:t}){const n=[];for(let r=0;r<e.length;r++)n.push(xt({param:e[r],value:t[r]}));return n}({params:e,values:t}),r=Pt(n);return 0===r.length?"0x":r}function xt({param:e,value:t}){const n=Et(e.type);if(n){const[r,s]=n;return function(e,{length:t,param:n}){const r=null===t;if(!Array.isArray(e))throw new q(e);if(!r&&e.length!==t)throw new E({expectedLength:t,givenLength:e.length,type:`${n.type}[${t}]`});let s=!1;const a=[];for(let t=0;t<e.length;t++){const r=xt({param:n,value:e[t]});r.dynamic&&(s=!0),a.push(r)}if(r||s){const e=Pt(a);if(r){const t=ie(a.length,{size:32});return{dynamic:!0,encoded:a.length>0?mt([t,e]):t}}if(s)return{dynamic:!0,encoded:e}}return{dynamic:!1,encoded:mt(a.map(({encoded:e})=>e))}}(t,{length:r,param:{...e,type:s}})}if("tuple"===e.type)return function(e,{param:t}){let n=!1;const r=[];for(let s=0;s<t.components.length;s++){const a=t.components[s],o=xt({param:a,value:e[Array.isArray(e)?s:a.name]});r.push(o),o.dynamic&&(n=!0)}return{dynamic:n,encoded:n?Pt(r):mt(r.map(({encoded:e})=>e))}}(t,{param:e});if("address"===e.type)return function(e){if(!Qe(e))throw new _({address:e});return{dynamic:!1,encoded:Z(e.toLowerCase())}}(t);if("bool"===e.type)return function(e){if("boolean"!=typeof e)throw new y(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:Z(ae(e))}}(t);if(e.type.startsWith("uint")||e.type.startsWith("int")){const n=e.type.startsWith("int"),[,,r="256"]=wt.exec(e.type)??[];return function(e,{signed:t,size:n=256}){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 Y({max:r.toString(),min:s.toString(),signed:t,size:n/8,value:e.toString()})}return{dynamic:!1,encoded:ie(e,{size:32,signed:t})}}(t,{signed:n,size:Number(r)})}if(e.type.startsWith("bytes"))return function(e,{param:t}){const[,n]=t.type.split("bytes"),r=h(e);if(!n){let t=e;return r%32!=0&&(t=Z(t,{dir:"right",size:32*Math.ceil((e.length-2)/2/32)})),{dynamic:!0,encoded:mt([Z(ie(r,{size:32})),t])}}if(r!==Number.parseInt(n,10))throw new k({expectedSize:Number.parseInt(n,10),value:e});return{dynamic:!1,encoded:Z(e,{dir:"right"})}}(t,{param:e});if("string"===e.type)return function(e){const t=ue(e),n=Math.ceil(h(t)/32),r=[];for(let e=0;e<n;e++)r.push(Z(ct(t,32*e,32*(e+1)),{dir:"right"}));return{dynamic:!0,encoded:mt([Z(ie(h(t),{size:32})),...r])}}(t);throw new L(e.type,{docsPath:"/docs/contract/encodeAbiParameters"})}function Pt(e){let t=0;for(let n=0;n<e.length;n++){const{dynamic:r,encoded:s}=e[n];t+=r?32:h(s)}const n=[],r=[];let s=0;for(let a=0;a<e.length;a++){const{dynamic:o,encoded:i}=e[a];o?(n.push(ie(t+s,{size:32})),r.push(i),s+=h(i)):n.push(i)}return mt([...n,...r])}function Et(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}function kt(e,t){const n="string"==typeof t?pe(t):t,r=it(n);if(0===h(n)&&e.length>0)throw new P;if(h(t)&&h(t)<32)throw new x({data:"string"==typeof t?t:oe(t),params:e,size:h(t)});let s=0;const a=[];for(let t=0;t<e.length;++t){const n=e[t];r.setPosition(s);const[o,i]=Bt(r,n,{staticPosition:0});s+=i,a.push(o)}return a}function Bt(e,t,{staticPosition:n}){const r=Et(t.type);if(r){const[s,a]=r;return function(e,t,{length:n,staticPosition:r}){if(!n){const n=r+bt(e.readBytes($t)),s=n+It;e.setPosition(n);const a=bt(e.readBytes(It)),o=At(t);let i=0;const c=[];for(let n=0;n<a;++n){e.setPosition(s+(o?32*n:i));const[r,a]=Bt(e,t,{staticPosition:s});i+=a,c.push(r)}return e.setPosition(r+32),[c,32]}if(At(t)){const s=r+bt(e.readBytes($t)),a=[];for(let r=0;r<n;++r){e.setPosition(s+32*r);const[n]=Bt(e,t,{staticPosition:s});a.push(n)}return e.setPosition(r+32),[a,32]}let s=0;const a=[];for(let o=0;o<n;++o){const[n,o]=Bt(e,t,{staticPosition:r+s});s+=o,a.push(n)}return[a,s]}(e,{...t,type:a},{length:s,staticPosition:n})}if("tuple"===t.type)return function(e,t,{staticPosition:n}){const r=0===t.components.length||t.components.some(({name:e})=>!e),s=r?[]:{};let a=0;if(At(t)){const o=n+bt(e.readBytes($t));for(let n=0;n<t.components.length;++n){const i=t.components[n];e.setPosition(o+a);const[c,u]=Bt(e,i,{staticPosition:o});a+=u,s[r?n:i?.name]=c}return e.setPosition(n+32),[s,32]}for(let o=0;o<t.components.length;++o){const i=t.components[o],[c,u]=Bt(e,i,{staticPosition:n});s[r?o:i?.name]=c,a+=u}return[s,a]}(e,t,{staticPosition:n});if("address"===t.type)return function(e){const t=e.readBytes(32);return[tt(oe(ft(t,-20))),32]}(e);if("bool"===t.type)return function(e){return[pt(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=bt(e.readBytes(32));e.setPosition(n+t);const r=bt(e.readBytes(32));if(0===r)return e.setPosition(n+32),["0x",32];const s=e.readBytes(r);return e.setPosition(n+32),[oe(s),32]}const a=oe(e.readBytes(Number.parseInt(s,10),32));return[a,32]}(e,t,{staticPosition:n});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?ht(s,{signed:n}):bt(s,{signed:n}),32]}(e,t);if("string"===t.type)return function(e,{staticPosition:t}){const n=bt(e.readBytes(32)),r=t+n;e.setPosition(r);const s=bt(e.readBytes(32));if(0===s)return e.setPosition(t+32),["",32];const a=e.readBytes(s,32),o=function(e,t={}){let n=e;return void 0!==t.size&&(ee(n,{size:t.size}),n=Q(n,{dir:"right"})),(new TextDecoder).decode(n)}(Q(a));return e.setPosition(t+32),[o,32]}(e,{staticPosition:n});throw new j(t.type,{docsPath:"/docs/contract/decodeAbiParameters"})}const It=32,$t=32;function At(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(At);const n=Et(e.type);return!(!n||!At({...e,type:n[1]}))}function Nt(e){return Ye(fe(e))}let zt=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 Ot(e,t){const n=e.exec(t);return n?.groups}const Tt=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,St=/^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)?$/,Ft=/^\(.+?\).*?$/,Ct=/^tuple(?<array>(\[(\d*)\])*)$/;function Rt(e){let t=e.type;if(Ct.test(e.type)&&"components"in e){t="(";const n=e.components.length;for(let r=0;r<n;r++){t+=Rt(e.components[r]),r<n-1&&(t+=", ")}const r=Ot(Ct,e.type);return t+=`)${r?.array??""}`,Rt({...e,type:t})}return"indexed"in e&&e.indexed&&(t=`${t} indexed`),e.name?`${t} ${e.name}`:t}function Ut(e){let t="";const n=e.length;for(let r=0;r<n;r++){t+=Rt(e[r]),r!==n-1&&(t+=", ")}return t}function Mt(e){return"function"===e.type?`function ${e.name}(${Ut(e.inputs)})${e.stateMutability&&"nonpayable"!==e.stateMutability?` ${e.stateMutability}`:""}${e.outputs?.length?` returns (${Ut(e.outputs)})`:""}`:"event"===e.type?`event ${e.name}(${Ut(e.inputs)})`:"error"===e.type?`error ${e.name}(${Ut(e.inputs)})`:"constructor"===e.type?`constructor(${Ut(e.inputs)})${"payable"===e.stateMutability?" payable":""}`:"fallback"===e.type?"fallback() external"+("payable"===e.stateMutability?" payable":""):"receive() external payable"}const Lt=/^error (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;const jt=/^event (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;const qt=/^function (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)(?: (?<scope>external|public{1}))?(?: (?<stateMutability>pure|view|nonpayable|payable{1}))?(?: returns\s?\((?<returns>.*?)\))?$/;const Gt=/^struct (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) \{(?<properties>.*?)\}$/;function _t(e){return Gt.test(e)}function Dt(e){return Ot(Gt,e)}const Ht=/^constructor\((?<parameters>.*?)\)(?:\s(?<stateMutability>payable{1}))?$/;const Vt=/^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/;const Wt=/^receive\(\) external payable$/;const Zt=new Set(["memory","indexed","storage","calldata"]),Yt=new Set(["indexed"]),Kt=new Set(["calldata","memory","storage"]);class Jt extends zt{constructor({signature:e}){super("Failed to parse ABI item.",{details:`parseAbiItem(${JSON.stringify(e,null,2)})`,docsPath:"/api/human#parseabiitem-1"}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidAbiItemError"})}}class Xt extends zt{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 Qt extends zt{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 en extends zt{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 tn extends zt{constructor({param:e}){super("Invalid ABI parameter.",{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParameterError"})}}class nn extends zt{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 rn extends zt{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 sn extends zt{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 an extends zt{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 on extends zt{constructor({signature:e,type:t}){super(`Invalid ${t} signature.`,{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidSignatureError"})}}class cn extends zt{constructor({signature:e}){super("Unknown signature.",{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSignatureError"})}}class un extends zt{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 dn extends zt{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 fn extends zt{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 ln=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 hn(e,t={}){if(function(e){return qt.test(e)}(e))return function(e,t={}){const n=function(e){return Ot(qt,e)}(e);if(!n)throw new on({signature:e,type:"function"});const r=gn(n.parameters),s=[],a=r.length;for(let e=0;e<a;e++)s.push(yn(r[e],{modifiers:Kt,structs:t,type:"function"}));const o=[];if(n.returns){const e=gn(n.returns),r=e.length;for(let n=0;n<r;n++)o.push(yn(e[n],{modifiers:Kt,structs:t,type:"function"}))}return{name:n.name,type:"function",stateMutability:n.stateMutability??"nonpayable",inputs:s,outputs:o}}(e,t);if(function(e){return jt.test(e)}(e))return function(e,t={}){const n=function(e){return Ot(jt,e)}(e);if(!n)throw new on({signature:e,type:"event"});const r=gn(n.parameters),s=[],a=r.length;for(let e=0;e<a;e++)s.push(yn(r[e],{modifiers:Yt,structs:t,type:"event"}));return{name:n.name,type:"event",inputs:s}}(e,t);if(function(e){return Lt.test(e)}(e))return function(e,t={}){const n=function(e){return Ot(Lt,e)}(e);if(!n)throw new on({signature:e,type:"error"});const r=gn(n.parameters),s=[],a=r.length;for(let e=0;e<a;e++)s.push(yn(r[e],{structs:t,type:"error"}));return{name:n.name,type:"error",inputs:s}}(e,t);if(function(e){return Ht.test(e)}(e))return function(e,t={}){const n=function(e){return Ot(Ht,e)}(e);if(!n)throw new on({signature:e,type:"constructor"});const r=gn(n.parameters),s=[],a=r.length;for(let e=0;e<a;e++)s.push(yn(r[e],{structs:t,type:"constructor"}));return{type:"constructor",stateMutability:n.stateMutability??"nonpayable",inputs:s}}(e,t);if(function(e){return Vt.test(e)}(e))return function(e){const t=function(e){return Ot(Vt,e)}(e);if(!t)throw new on({signature:e,type:"fallback"});return{type:"fallback",stateMutability:t.stateMutability??"nonpayable"}}(e);if(function(e){return Wt.test(e)}(e))return{type:"receive",stateMutability:"payable"};throw new cn({signature:e})}const pn=/^(?<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$_]*))?$/,bn=/^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,mn=/^u?int$/;function yn(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(ln.has(n))return ln.get(n);const r=Ft.test(e),s=Ot(r?bn:pn,e);if(!s)throw new tn({param:e});if(s.name&&function(e){return"address"===e||"bool"===e||"function"===e||"string"===e||"tuple"===e||Tt.test(e)||St.test(e)||vn.test(e)}(s.name))throw new nn({param:e,name:s.name});const a=s.name?{name:s.name}:{},o="indexed"===s.modifier?{indexed:!0}:{},i=t?.structs??{};let c,u={};if(r){c="tuple";const e=gn(s.type),t=[],n=e.length;for(let r=0;r<n;r++)t.push(yn(e[r],{structs:i}));u={components:t}}else if(s.type in i)c="tuple",u={components:i[s.type]};else if(mn.test(s.type))c=`${s.type}256`;else if("address payable"===s.type)c="address";else if(c=s.type,"struct"!==t?.type&&!wn(c))throw new Qt({type:c});if(s.modifier){if(!t?.modifiers?.has?.(s.modifier))throw new rn({param:e,type:t?.type,modifier:s.modifier});if(Kt.has(s.modifier)&&!function(e,t){return t||"bytes"===e||"string"===e||"tuple"===e}(c,!!s.array))throw new sn({param:e,type:t?.type,modifier:s.modifier})}const d={type:`${c}${s.array??""}`,...a,...o,...u};return ln.set(n,d),d}function gn(e,t=[],n="",r=0){const s=e.trim().length;for(let a=0;a<s;a++){const s=e[a],o=e.slice(a+1);switch(s){case",":return 0===r?gn(o,[...t,n.trim()]):gn(o,t,`${n}${s}`,r);case"(":return gn(o,t,`${n}${s}`,r+1);case")":return gn(o,t,`${n}${s}`,r-1);default:return gn(o,t,`${n}${s}`,r)}}if(""===n)return t;if(0!==r)throw new fn({current:n,depth:r});return t.push(n.trim()),t}function wn(e){return"address"===e||"bool"===e||"function"===e||"string"===e||Tt.test(e)||St.test(e)}const vn=/^(?: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 xn(e){const t={},n=e.length;for(let r=0;r<n;r++){const n=e[r];if(!_t(n))continue;const s=Dt(n);if(!s)throw new on({signature:n,type:"struct"});const a=s.properties.split(";"),o=[],i=a.length;for(let e=0;e<i;e++){const t=a[e].trim();if(!t)continue;const n=yn(t,{type:"struct"});o.push(n)}if(!o.length)throw new un({signature:n});t[s.name]=o}const r={},s=Object.entries(t),a=s.length;for(let e=0;e<a;e++){const[n,a]=s[e];r[n]=En(a,t)}return r}const Pn=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?$/;function En(e,t,n=new Set){const r=[],s=e.length;for(let a=0;a<s;a++){const s=e[a];if(Ft.test(s.type))r.push(s);else{const e=Ot(Pn,s.type);if(!e?.type)throw new an({abiParameter:s});const{array:a,type:o}=e;if(o in t){if(n.has(o))throw new dn({type:o});r.push({...s,type:`tuple${a??""}`,components:En(t[o]??[],t,new Set([...n,o]))})}else{if(!wn(o))throw new Xt({type:o});r.push(s)}}}return r}function kn(e){const t=xn(e),n=[],r=e.length;for(let s=0;s<r;s++){const r=e[s];_t(r)||n.push(hn(r,t))}return n}function Bn(e){let t;if("string"==typeof e)t=hn(e);else{const n=xn(e),r=e.length;for(let s=0;s<r;s++){const r=e[s];if(!_t(r)){t=hn(r,n);break}}}if(!t)throw new Jt({signature:e});return t}function In(e){const t=[];if("string"==typeof e){const n=gn(e),r=n.length;for(let e=0;e<r;e++)t.push(yn(n[e],{modifiers:Zt}))}else{const n=xn(e),r=e.length;for(let s=0;s<r;s++){const r=e[s];if(_t(r))continue;const a=gn(r),o=a.length;for(let e=0;e<o;e++)t.push(yn(a[e],{modifiers:Zt,structs:n}))}}if(0===t.length)throw new en({params:e});return t}const $n=e=>function(e){let t=!0,n="",r=0,s="",a=!1;for(let o=0;o<e.length;o++){const i=e[o];if(["(",")",","].includes(i)&&(t=!0),"("===i&&r++,")"===i&&r--,t)if(0!==r)" "!==i?(s+=i,n+=i):","!==e[o-1]&&","!==n&&",("!==n&&(n="",t=!1);else if(" "===i&&["event","function",""].includes(s))s="";else if(s+=i,")"===i){a=!0;break}}if(!a)throw new y("Unable to normalize signature.");return s}("string"==typeof e?e:Mt(e));function An(e){return Nt($n(e))}const Nn=An,zn=e=>ct(An(e),0,4);function On(e){const{abi:t,args:n=[],name:r}=e,s=l(r,{strict:!1}),a=t.filter(e=>s?"function"===e.type?zn(e)===r:"event"===e.type&&Nn(e)===r:"name"in e&&e.name===r);if(0===a.length)return;if(1===a.length)return a[0];let o;for(const e of a){if(!("inputs"in e))continue;if(!n||0===n.length){if(!e.inputs||0===e.inputs.length)return e;continue}if(!e.inputs)continue;if(0===e.inputs.length)continue;if(e.inputs.length!==n.length)continue;if(n.every((t,n)=>{const r="inputs"in e&&e.inputs[n];return!!r&&Tn(t,r)})){if(o&&"inputs"in o&&o.inputs){const t=Sn(e.inputs,o.inputs,n);if(t)throw new C({abiItem:e,type:t[0]},{abiItem:o,type:t[1]})}o=e}}return o||a[0]}function Tn(e,t){const n=typeof e,r=t.type;switch(r){case"address":return Qe(e,{strict:!1});case"bool":return"boolean"===n;case"function":case"string":return"string"===n;default:return"tuple"===r&&"components"in t?Object.values(t.components).every((t,n)=>Tn(Object.values(e)[n],t)):/^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)?$/.test(r)?"number"===n||"bigint"===n:/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(r)?"string"===n||e instanceof Uint8Array:!!/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(r)&&(