@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 • 246 kB
JavaScript
"use strict";function e(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,Object.freeze(t)}var t=e(require("node:crypto"));const n=[{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"}],r=[{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"}]}],s=[{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"}],a=[...s,{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"}]}],o=[...s,{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"}]}],i=[{name:"text",type:"function",stateMutability:"view",inputs:[{name:"name",type:"bytes32"},{name:"key",type:"string"}],outputs:[{name:"",type:"string"}]}],c=[{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"}]}],u=[{name:"isValidSignature",type:"function",stateMutability:"view",inputs:[{name:"hash",type:"bytes32"},{name:"signature",type:"bytes"}],outputs:[{name:"",type:"bytes4"}]}],d=[{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 l(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 p(e,{strict:t=!0}={}){return!!e&&("string"==typeof e&&(t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")))}function h(e){return p(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}const b="2.38.6";let m=({docsBaseUrl:e,docsPath:t="",docsSlug:n})=>t?`${e??"https://viem.sh"}${t}${n?`#${n}`:""}`:void 0,y=`viem@${b}`,g=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=m?.({...n,docsPath:s});super([t||"An error occurred.","",...n.metaMessages?[...n.metaMessages,""]:[],...a?[`Docs: ${a}`]:[],...r?[`Details: ${r}`]:[],...y?[`Version: ${y}`]:[]].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=b}walk(e){return w(this,e)}};function w(e,t){return t?.(e)?e:e&&"object"==typeof e&&"cause"in e&&void 0!==e.cause?w(e.cause,t):t?null:e}class v extends g{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 x extends g{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 P extends g{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 E extends g{constructor(){super('Cannot decode zero data ("0x") with ABI parameters.',{name:"AbiDecodingZeroDataError"})}}class I extends g{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 B extends g{constructor({expectedSize:e,value:t}){super(`Size of bytes "${t}" (bytes${h(t)}) does not match expected size (bytes${e}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class k extends g{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 A extends g{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 g{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 N extends g{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 T extends g{constructor({docsPath:e}){super("Cannot extract event signature from empty topics.",{docsPath:e,name:"AbiEventSignatureEmptyTopicsError"})}}class O extends g{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 z extends g{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 S extends g{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 F extends g{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 C extends g{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 R extends g{constructor(e,t){super("Found ambiguous types in overloaded ABI items.",{metaMessages:[`\`${e.type}\` in \`${l(e.abiItem)}\`, and`,`\`${t.type}\` in \`${l(t.abiItem)}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."],name:"AbiItemAmbiguityError"})}}let M=class extends g{constructor({expectedSize:e,givenSize:t}){super(`Expected bytes${e}, got bytes${t}.`,{name:"BytesSizeMismatchError"})}};class L extends g{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 U extends g{constructor({abiItem:e,param:t}){super([`Expected a topic for indexed event parameter${t.name?` "${t.name}"`:""} on event "${l(e,{includeName:!0})}".`].join("\n"),{name:"DecodeLogTopicsMismatch"}),Object.defineProperty(this,"abiItem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abiItem=e}}class j extends g{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 _ extends g{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 g{constructor(e){super([`Value "${e}" is not a valid array.`].join("\n"),{name:"InvalidArrayError"})}};class G extends g{constructor(e){super([`"${e}" is not a valid definition type.`,'Valid types: "function", "event", "error"'].join("\n"),{name:"InvalidDefinitionTypeError"})}}let D=class extends g{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"})}},H=class extends g{constructor({offset:e,position:t,size:n}){super(`Slice ${"start"===t?"starting":"ending"} at offset "${e}" is out-of-bounds (size: ${n}).`,{name:"SliceOffsetOutOfBoundsError"})}},V=class extends g{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 W extends g{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 Z(e,{dir:t,size:n=32}={}){return"string"==typeof e?Y(e,{dir:t,size:n}):function(e,{dir:t,size:n=32}={}){if(null===n)return e;if(e.length>n)throw new V({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 Y(e,{dir:t,size:n=32}={}){if(null===n)return e;const r=e.replace("0x","");if(r.length>2*n)throw new V({size:Math.ceil(r.length/2),targetSize:n,type:"hex"});return`0x${r["right"===t?"padEnd":"padStart"](2*n,"0")}`}let K=class extends g{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"})}},J=class extends g{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 X extends g{constructor(e){super(`Hex value "${e}" is not a valid boolean. The hex value must be "0x0" (false) or "0x1" (true).`,{name:"InvalidHexBooleanError"})}}let Q=class extends g{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}};function ee(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 te(e,{size:t}){if(h(e)>t)throw new Q({givenSize:h(e),maxSize:t})}function ne(e,t={}){const{signed:n}=t;t.size&&te(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 re(e,t={}){return Number(ne(e,t))}const se=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ae(e,t={}){return"number"==typeof e||"bigint"==typeof e?ce(e,t):"string"==typeof e?de(e,t):"boolean"==typeof e?oe(e,t):ie(e,t)}function oe(e,t={}){const n=`0x${Number(e)}`;return"number"==typeof t.size?(te(n,{size:t.size}),Z(n,{size:t.size})):n}function ie(e,t={}){let n="";for(let t=0;t<e.length;t++)n+=se[e[t]];const r=`0x${n}`;return"number"==typeof t.size?(te(r,{size:t.size}),Z(r,{dir:"right",size:t.size})):r}function ce(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 K({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?Z(i,{size:r}):i}const ue=new TextEncoder;function de(e,t={}){return ie(ue.encode(e),t)}const le=new TextEncoder;function fe(e,t={}){return"number"==typeof e||"bigint"==typeof e?function(e,t){const n=ce(e,t);return be(n)}(e,t):"boolean"==typeof e?function(e,t={}){const n=new Uint8Array(1);if(n[0]=Number(e),"number"==typeof t.size)return te(n,{size:t.size}),Z(n,{size:t.size});return n}(e,t):p(e)?be(e,t):me(e,t)}const pe={zero:48,nine:57,A:65,F:70,a:97,f:102};function he(e){return e>=pe.zero&&e<=pe.nine?e-pe.zero:e>=pe.A&&e<=pe.F?e-(pe.A-10):e>=pe.a&&e<=pe.f?e-(pe.a-10):void 0}function be(e,t={}){let n=e;t.size&&(te(n,{size:t.size}),n=Z(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 g(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);a[e]=16*n+s}return a}function me(e,t={}){const n=le.encode(e);return"number"==typeof t.size?(te(n,{size:t.size}),Z(n,{dir:"right",size:t.size})):n}const ye=BigInt(2**32-1),ge=BigInt(32);function we(e,t=!1){return t?{h:Number(e&ye),l:Number(e>>ge&ye)}:{h:0|Number(e>>ge&ye),l:0|Number(e&ye)}}const ve=t&&"object"==typeof t&&"webcrypto"in t?t.webcrypto:t&&"object"==typeof t&&"randomBytes"in t?t:void 0;function xe(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Pe(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 Ee(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 Ie(e,t){Pe(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Be(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function ke(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ae(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 Ne=(()=>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 Te(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)),Pe(e),e}let Oe=class{};function ze(e){const t=t=>e().update(Te(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Se(e=32){if(ve&&"function"==typeof ve.getRandomValues)return ve.getRandomValues(new Uint8Array(e));if(ve&&"function"==typeof ve.randomBytes)return Uint8Array.from(ve.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}const Fe=BigInt(0),Ce=BigInt(1),Re=BigInt(2),Me=BigInt(7),Le=BigInt(256),Ue=BigInt(113),je=[],_e=[],qe=[];for(let e=0,t=Ce,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],je.push(2*(5*r+n)),_e.push((e+1)*(e+2)/2%64);let s=Fe;for(let e=0;e<7;e++)t=(t<<Ce^(t>>Me)*Ue)%Le,t&Re&&(s^=Ce<<(Ce<<BigInt(e))-Ce);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}=we(e[a],t);[r[a],s[a]]=[n,o]}return[r,s]}(qe,!0),De=Ge[0],He=Ge[1],Ve=(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),We=(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 Ze=class e extends Oe{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,xe(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(){Ne(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=Ve(a,o,1)^n[r],c=We(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=_e[n],a=Ve(t,s,r),o=We(t,s,r),i=je[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]^=De[r],e[1]^=He[r]}Be(n)}(this.state32,this.rounds),Ne(this.state32),this.posOut=0,this.pos=0}update(e){Ee(this),Pe(e=Te(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){Ee(this,!1),Pe(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 xe(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Ie(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,Be(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 Ye=(()=>{return e=1,t=136,n=32,ze(()=>new Ze(t,e,n));var e,t,n})();function Ke(e,t){const n=t||"hex",r=Ye(p(e,{strict:!1})?fe(e):e);return"bytes"===n?r:ae(r)}let Je=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 Xe=/^0x[a-fA-F0-9]{40}$/,Qe=new Je(8192);function et(e,t){const{strict:n=!0}=t??{},r=`${e}.${n}`;if(Qe.has(r))return Qe.get(r);const s=!(!Xe.test(e)||e.toLowerCase()!==e&&n&&nt(e)!==e);return Qe.set(r,s),s}const tt=new Je(8192);function nt(e,t){if(tt.has(`${e}.${t}`))return tt.get(`${e}.${t}`);const n=e.substring(2).toLowerCase(),r=Ke(me(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 tt.set(`${e}.${t}`,a),a}function rt(e,t){if(!et(e,{strict:!1}))throw new D({address:e});return nt(e,t)}let st=class extends g{constructor({offset:e}){super(`Offset \`${e}\` cannot be negative.`,{name:"NegativeOffsetError"})}},at=class extends g{constructor({length:e,position:t}){super(`Position \`${t}\` is out of bounds (\`0 < position < ${e}\`).`,{name:"PositionOutOfBoundsError"})}},ot=class extends g{constructor({count:e,limit:t}){super(`Recursive read limit of \`${t}\` exceeded (recursive read count: \`${e}\`).`,{name:"RecursiveReadLimitExceededError"})}};const it={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 ot({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new at({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new st({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 st({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 ct(e,{recursiveReadLimit:t=8192}={}){const n=Object.create(it);return n.bytes=e,n.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),n.positionReadCount=new Map,n.recursiveReadLimit=t,n}function ut(e,t,n,{strict:r}={}){return p(e,{strict:!1})?pt(e,t,n,{strict:r}):ft(e,t,n,{strict:r})}function dt(e,t){if("number"==typeof t&&t>0&&t>h(e)-1)throw new H({offset:t,position:"start",size:h(e)})}function lt(e,t,n){if("number"==typeof t&&"number"==typeof n&&h(e)!==n-t)throw new H({offset:n,position:"end",size:h(e)})}function ft(e,t,n,{strict:r}={}){dt(e,t);const s=e.slice(t,n);return r&<(s,t,n),s}function pt(e,t,n,{strict:r}={}){dt(e,t);const s=`0x${e.replace("0x","").slice(2*(t??0),2*(n??e.length))}`;return r&<(s,t,n),s}function ht(e,t={}){void 0!==t.size&&te(e,{size:t.size});return ne(ie(e,t),t)}function bt(e,t={}){let n=e;if(void 0!==t.size&&(te(n,{size:t.size}),n=ee(n)),n.length>1||n[0]>1)throw new J(n);return Boolean(n[0])}function mt(e,t={}){void 0!==t.size&&te(e,{size:t.size});return re(ie(e,t),t)}function yt(e){return"string"==typeof e[0]?gt(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 gt(e){return`0x${e.reduce((e,t)=>e+t.replace("0x",""),"")}`}const wt=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,vt=/^(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 xt(e,t){if(e.length!==t.length)throw new k({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(Pt({param:e[r],value:t[r]}));return n}({params:e,values:t}),r=Et(n);return 0===r.length?"0x":r}function Pt({param:e,value:t}){const n=It(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 I({expectedLength:t,givenLength:e.length,type:`${n.type}[${t}]`});let s=!1;const a=[];for(let t=0;t<e.length;t++){const r=Pt({param:n,value:e[t]});r.dynamic&&(s=!0),a.push(r)}if(r||s){const e=Et(a);if(r){const t=ce(a.length,{size:32});return{dynamic:!0,encoded:a.length>0?yt([t,e]):t}}if(s)return{dynamic:!0,encoded:e}}return{dynamic:!1,encoded:yt(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=Pt({param:a,value:e[Array.isArray(e)?s:a.name]});r.push(o),o.dynamic&&(n=!0)}return{dynamic:n,encoded:n?Et(r):yt(r.map(({encoded:e})=>e))}}(t,{param:e});if("address"===e.type)return function(e){if(!et(e))throw new D({address:e});return{dynamic:!1,encoded:Y(e.toLowerCase())}}(t);if("bool"===e.type)return function(e){if("boolean"!=typeof e)throw new g(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:Y(oe(e))}}(t);if(e.type.startsWith("uint")||e.type.startsWith("int")){const n=e.type.startsWith("int"),[,,r="256"]=vt.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 K({max:r.toString(),min:s.toString(),signed:t,size:n/8,value:e.toString()})}return{dynamic:!1,encoded:ce(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=Y(t,{dir:"right",size:32*Math.ceil((e.length-2)/2/32)})),{dynamic:!0,encoded:yt([Y(ce(r,{size:32})),t])}}if(r!==Number.parseInt(n,10))throw new B({expectedSize:Number.parseInt(n,10),value:e});return{dynamic:!1,encoded:Y(e,{dir:"right"})}}(t,{param:e});if("string"===e.type)return function(e){const t=de(e),n=Math.ceil(h(t)/32),r=[];for(let e=0;e<n;e++)r.push(Y(ut(t,32*e,32*(e+1)),{dir:"right"}));return{dynamic:!0,encoded:yt([Y(ce(h(t),{size:32})),...r])}}(t);throw new j(e.type,{docsPath:"/docs/contract/encodeAbiParameters"})}function Et(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(ce(t+s,{size:32})),r.push(i),s+=h(i)):n.push(i)}return yt([...n,...r])}function It(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}function Bt(e,t){const n="string"==typeof t?be(t):t,r=ct(n);if(0===h(n)&&e.length>0)throw new E;if(h(t)&&h(t)<32)throw new P({data:"string"==typeof t?t:ie(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]=kt(r,n,{staticPosition:0});s+=i,a.push(o)}return a}function kt(e,t,{staticPosition:n}){const r=It(t.type);if(r){const[s,a]=r;return function(e,t,{length:n,staticPosition:r}){if(!n){const n=r+mt(e.readBytes($t)),s=n+At;e.setPosition(n);const a=mt(e.readBytes(At)),o=Nt(t);let i=0;const c=[];for(let n=0;n<a;++n){e.setPosition(s+(o?32*n:i));const[r,a]=kt(e,t,{staticPosition:s});i+=a,c.push(r)}return e.setPosition(r+32),[c,32]}if(Nt(t)){const s=r+mt(e.readBytes($t)),a=[];for(let r=0;r<n;++r){e.setPosition(s+32*r);const[n]=kt(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]=kt(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(Nt(t)){const o=n+mt(e.readBytes($t));for(let n=0;n<t.components.length;++n){const i=t.components[n];e.setPosition(o+a);const[c,u]=kt(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]=kt(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[nt(ie(ft(t,-20))),32]}(e);if("bool"===t.type)return function(e){return[bt(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=mt(e.readBytes(32));e.setPosition(n+t);const r=mt(e.readBytes(32));if(0===r)return e.setPosition(n+32),["0x",32];const s=e.readBytes(r);return e.setPosition(n+32),[ie(s),32]}const a=ie(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}):mt(s,{signed:n}),32]}(e,t);if("string"===t.type)return function(e,{staticPosition:t}){const n=mt(e.readBytes(32)),r=t+n;e.setPosition(r);const s=mt(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&&(te(n,{size:t.size}),n=ee(n,{dir:"right"})),(new TextDecoder).decode(n)}(ee(a));return e.setPosition(t+32),[o,32]}(e,{staticPosition:n});throw new _(t.type,{docsPath:"/docs/contract/decodeAbiParameters"})}const At=32,$t=32;function Nt(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(Nt);const n=It(e.type);return!(!n||!Nt({...e,type:n[1]}))}function Tt(e){return Ke(fe(e))}let Ot=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 zt(e,t){const n=e.exec(t);return n?.groups}const St=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,Ft=/^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)?$/,Ct=/^\(.+?\).*?$/,Rt=/^tuple(?<array>(\[(\d*)\])*)$/;function Mt(e){let t=e.type;if(Rt.test(e.type)&&"components"in e){t="(";const n=e.components.length;for(let r=0;r<n;r++){t+=Mt(e.components[r]),r<n-1&&(t+=", ")}const r=zt(Rt,e.type);return t+=`)${r?.array??""}`,Mt({...e,type:t})}return"indexed"in e&&e.indexed&&(t=`${t} indexed`),e.name?`${t} ${e.name}`:t}function Lt(e){let t="";const n=e.length;for(let r=0;r<n;r++){t+=Mt(e[r]),r!==n-1&&(t+=", ")}return t}function Ut(e){return"function"===e.type?`function ${e.name}(${Lt(e.inputs)})${e.stateMutability&&"nonpayable"!==e.stateMutability?` ${e.stateMutability}`:""}${e.outputs?.length?` returns (${Lt(e.outputs)})`:""}`:"event"===e.type?`event ${e.name}(${Lt(e.inputs)})`:"error"===e.type?`error ${e.name}(${Lt(e.inputs)})`:"constructor"===e.type?`constructor(${Lt(e.inputs)})${"payable"===e.stateMutability?" payable":""}`:"fallback"===e.type?"fallback() external"+("payable"===e.stateMutability?" payable":""):"receive() external payable"}const jt=/^error (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;const _t=/^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 Dt(e){return Gt.test(e)}function Ht(e){return zt(Gt,e)}const Vt=/^constructor\((?<parameters>.*?)\)(?:\s(?<stateMutability>payable{1}))?$/;const Wt=/^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/;const Zt=/^receive\(\) external payable$/;const Yt=new Set(["memory","indexed","storage","calldata"]),Kt=new Set(["indexed"]),Jt=new Set(["calldata","memory","storage"]);class Xt extends Ot{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 Qt extends Ot{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 en extends Ot{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 tn extends Ot{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 nn extends Ot{constructor({param:e}){super("Invalid ABI parameter.",{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParameterError"})}}class rn extends Ot{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 sn extends Ot{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 an extends Ot{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 on extends Ot{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 cn extends Ot{constructor({signature:e,type:t}){super(`Invalid ${t} signature.`,{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidSignatureError"})}}class un extends Ot{constructor({signature:e}){super("Unknown signature.",{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSignatureError"})}}class dn extends Ot{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 ln extends Ot{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 Ot{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 pn=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 zt(qt,e)}(e);if(!n)throw new cn({signature:e,type:"function"});const r=wn(n.parameters),s=[],a=r.length;for(let e=0;e<a;e++)s.push(gn(r[e],{modifiers:Jt,structs:t,type:"function"}));const o=[];if(n.returns){const e=wn(n.returns),r=e.length;for(let n=0;n<r;n++)o.push(gn(e[n],{modifiers:Jt,structs:t,type:"function"}))}return{name:n.name,type:"function",stateMutability:n.stateMutability??"nonpayable",inputs:s,outputs:o}}(e,t);if(function(e){return _t.test(e)}(e))return function(e,t={}){const n=function(e){return zt(_t,e)}(e);if(!n)throw new cn({signature:e,type:"event"});const r=wn(n.parameters),s=[],a=r.length;for(let e=0;e<a;e++)s.push(gn(r[e],{modifiers:Kt,structs:t,type:"event"}));return{name:n.name,type:"event",inputs:s}}(e,t);if(function(e){return jt.test(e)}(e))return function(e,t={}){const n=function(e){return zt(jt,e)}(e);if(!n)throw new cn({signature:e,type:"error"});const r=wn(n.parameters),s=[],a=r.length;for(let e=0;e<a;e++)s.push(gn(r[e],{structs:t,type:"error"}));return{name:n.name,type:"error",inputs:s}}(e,t);if(function(e){return Vt.test(e)}(e))return function(e,t={}){const n=function(e){return zt(Vt,e)}(e);if(!n)throw new cn({signature:e,type:"constructor"});const r=wn(n.parameters),s=[],a=r.length;for(let e=0;e<a;e++)s.push(gn(r[e],{structs:t,type:"constructor"}));return{type:"constructor",stateMutability:n.stateMutability??"nonpayable",inputs:s}}(e,t);if(function(e){return Wt.test(e)}(e))return function(e){const t=function(e){return zt(Wt,e)}(e);if(!t)throw new cn({signature:e,type:"fallback"});return{type:"fallback",stateMutability:t.stateMutability??"nonpayable"}}(e);if(function(e){return Zt.test(e)}(e))return{type:"receive",stateMutability:"payable"};throw new un({signature:e})}const bn=/^(?<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$_]*))?$/,mn=/^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,yn=/^u?int$/;function gn(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(pn.has(n))return pn.get(n);const r=Ct.test(e),s=zt(r?mn:bn,e);if(!s)throw new nn({param:e});if(s.name&&function(e){return"address"===e||"bool"===e||"function"===e||"string"===e||"tuple"===e||St.test(e)||Ft.test(e)||xn.test(e)}(s.name))throw new rn({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=wn(s.type),t=[],n=e.length;for(let r=0;r<n;r++)t.push(gn(e[r],{structs:i}));u={components:t}}else if(s.type in i)c="tuple",u={components:i[s.type]};else if(yn.test(s.type))c=`${s.type}256`;else if("address payable"===s.type)c="address";else if(c=s.type,"struct"!==t?.type&&!vn(c))throw new en({type:c});if(s.modifier){if(!t?.modifiers?.has?.(s.modifier))throw new sn({param:e,type:t?.type,modifier:s.modifier});if(Jt.has(s.modifier)&&!function(e,t){return t||"bytes"===e||"string"===e||"tuple"===e}(c,!!s.array))throw new an({param:e,type:t?.type,modifier:s.modifier})}const d={type:`${c}${s.array??""}`,...a,...o,...u};return pn.set(n,d),d}function wn(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?wn(o,[...t,n.trim()]):wn(o,t,`${n}${s}`,r);case"(":return wn(o,t,`${n}${s}`,r+1);case")":return wn(o,t,`${n}${s}`,r-1);default:return wn(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 vn(e){return"address"===e||"bool"===e||"function"===e||"string"===e||St.test(e)||Ft.test(e)}const xn=/^(?: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 Pn(e){const t={},n=e.length;for(let r=0;r<n;r++){const n=e[r];if(!Dt(n))continue;const s=Ht(n);if(!s)throw new cn({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=gn(t,{type:"struct"});o.push(n)}if(!o.length)throw new dn({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]=In(a,t)}return r}const En=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?$/;function In(e,t,n=new Set){const r=[],s=e.length;for(let a=0;a<s;a++){const s=e[a];if(Ct.test(s.type))r.push(s);else{const e=zt(En,s.type);if(!e?.type)throw new on({abiParameter:s});const{array:a,type:o}=e;if(o in t){if(n.has(o))throw new ln({type:o});r.push({...s,type:`tuple${a??""}`,components:In(t[o]??[],t,new Set([...n,o]))})}else{if(!vn(o))throw new Qt({type:o});r.push(s)}}}return r}function Bn(e){const t=Pn(e),n=[],r=e.length;for(let s=0;s<r;s++){const r=e[s];Dt(r)||n.push(hn(r,t))}return n}function kn(e){let t;if("string"==typeof e)t=hn(e);else{const n=Pn(e),r=e.length;for(let s=0;s<r;s++){const r=e[s];if(!Dt(r)){t=hn(r,n);break}}}if(!t)throw new Xt({signature:e});return t}function An(e){const t=[];if("string"==typeof e){const n=wn(e),r=n.length;for(let e=0;e<r;e++)t.push(gn(n[e],{modifiers:Yt}))}else{const n=Pn(e),r=e.length;for(let s=0;s<r;s++){const r=e[s];if(Dt(r))continue;const a=wn(r),o=a.length;for(let e=0;e<o;e++)t.push(gn(a[e],{modifiers:Yt,structs:n}))}}if(0===t.length)throw new tn({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 g("Unable to normalize signature.");return s}("string"==typeof e?e:Ut(e));function Nn(e){return Tt($n(e))}const Tn=Nn,On=e=>ut(Nn(e),0,4);function zn(e){const{abi:t,args:n=[],name:r}=e,s=p(r,{strict:!1}),a=t.filter(e=>s?"function"===e.type?On(e)===r:"event"===e.type&&Tn(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&&Sn(t,r)})){if(o&&"inputs"in o&&o.inputs){const t=Fn(e.inputs,o.inputs,n);if(t)throw new R({abiItem:e,type:t[0]},{abiItem:o,type:t[1]})}o=e}}return o||a[0]}function Sn(e,t){const n=typeof e,r=t.type;switch(r){case"address":return et(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)=>Sn(Object.values(e)[n],t)):/^u?int(8|16|24|32|