@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
4 lines • 230 kB
JavaScript
"use strict";var e=require("@avalabs/avalanchejs");require("viem");var t=require("node:crypto"),n=require("events"),r=require("https"),s=require("http"),o=require("net"),i=require("tls"),a=require("crypto"),c=require("stream"),u=require("url"),d=require("zlib"),f=require("buffer");function l(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 h=l(t);
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */if(!(68===new Uint8Array(new Uint32Array([287454020]).buffer)[0]))throw new Error("Non little-endian hardware is not supported");let p=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 b(e,t){const n=e.exec(t);return n?.groups}const m=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,y=/^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)?$/,g=/^\(.+?\).*?$/,w=/^tuple(?<array>(\[(\d*)\])*)$/;function v(e){let t=e.type;if(w.test(e.type)&&"components"in e){t="(";const n=e.components.length;for(let r=0;r<n;r++){t+=v(e.components[r]),r<n-1&&(t+=", ")}const r=b(w,e.type);return t+=`)${r?.array??""}`,v({...e,type:t})}return"indexed"in e&&e.indexed&&(t=`${t} indexed`),e.name?`${t} ${e.name}`:t}function x(e){let t="";const n=e.length;for(let r=0;r<n;r++){t+=v(e[r]),r!==n-1&&(t+=", ")}return t}const E=/^error (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;const _=/^event (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;const P=/^function (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)(?: (?<scope>external|public{1}))?(?: (?<stateMutability>pure|view|nonpayable|payable{1}))?(?: returns\s?\((?<returns>.*?)\))?$/;const S=/^struct (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) \{(?<properties>.*?)\}$/;function I(e){return S.test(e)}function k(e){return b(S,e)}const B=/^constructor\((?<parameters>.*?)\)(?:\s(?<stateMutability>payable{1}))?$/;const $=/^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/;const O=/^receive\(\) external payable$/;const A=new Set(["memory","indexed","storage","calldata"]),T=new Set(["indexed"]),N=new Set(["calldata","memory","storage"]);class C extends p{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 L extends p{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 R extends p{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 M extends p{constructor({param:e}){super("Failed to parse ABI parameter.",{details:`parseAbiParameter(${JSON.stringify(e,null,2)})`,docsPath:"/api/human#parseabiparameter-1"}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidAbiParameterError"})}}class z extends p{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 F extends p{constructor({param:e}){super("Invalid ABI parameter.",{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParameterError"})}}class U extends p{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 j extends p{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 G extends p{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 D extends p{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 q extends p{constructor({signature:e,type:t}){super(`Invalid ${t} signature.`,{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidSignatureError"})}}class W extends p{constructor({signature:e}){super("Unknown signature.",{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSignatureError"})}}class H extends p{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 V extends p{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 Z extends p{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 Y=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 K(e,t={}){if(function(e){return P.test(e)}(e))return function(e,t={}){const n=function(e){return b(P,e)}(e);if(!n)throw new q({signature:e,type:"function"});const r=te(n.parameters),s=[],o=r.length;for(let e=0;e<o;e++)s.push(ee(r[e],{modifiers:N,structs:t,type:"function"}));const i=[];if(n.returns){const e=te(n.returns),r=e.length;for(let n=0;n<r;n++)i.push(ee(e[n],{modifiers:N,structs:t,type:"function"}))}return{name:n.name,type:"function",stateMutability:n.stateMutability??"nonpayable",inputs:s,outputs:i}}(e,t);if(function(e){return _.test(e)}(e))return function(e,t={}){const n=function(e){return b(_,e)}(e);if(!n)throw new q({signature:e,type:"event"});const r=te(n.parameters),s=[],o=r.length;for(let e=0;e<o;e++)s.push(ee(r[e],{modifiers:T,structs:t,type:"event"}));return{name:n.name,type:"event",inputs:s}}(e,t);if(function(e){return E.test(e)}(e))return function(e,t={}){const n=function(e){return b(E,e)}(e);if(!n)throw new q({signature:e,type:"error"});const r=te(n.parameters),s=[],o=r.length;for(let e=0;e<o;e++)s.push(ee(r[e],{structs:t,type:"error"}));return{name:n.name,type:"error",inputs:s}}(e,t);if(function(e){return B.test(e)}(e))return function(e,t={}){const n=function(e){return b(B,e)}(e);if(!n)throw new q({signature:e,type:"constructor"});const r=te(n.parameters),s=[],o=r.length;for(let e=0;e<o;e++)s.push(ee(r[e],{structs:t,type:"constructor"}));return{type:"constructor",stateMutability:n.stateMutability??"nonpayable",inputs:s}}(e,t);if(function(e){return $.test(e)}(e))return function(e){const t=function(e){return b($,e)}(e);if(!t)throw new q({signature:e,type:"fallback"});return{type:"fallback",stateMutability:t.stateMutability??"nonpayable"}}(e);if(function(e){return O.test(e)}(e))return{type:"receive",stateMutability:"payable"};throw new W({signature:e})}const X=/^(?<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$_]*))?$/,J=/^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,Q=/^u?int$/;function ee(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(Y.has(n))return Y.get(n);const r=g.test(e),s=b(r?J:X,e);if(!s)throw new F({param:e});if(s.name&&function(e){return"address"===e||"bool"===e||"function"===e||"string"===e||"tuple"===e||m.test(e)||y.test(e)||re.test(e)}(s.name))throw new U({param:e,name:s.name});const o=s.name?{name:s.name}:{},i="indexed"===s.modifier?{indexed:!0}:{},a=t?.structs??{};let c,u={};if(r){c="tuple";const e=te(s.type),t=[],n=e.length;for(let r=0;r<n;r++)t.push(ee(e[r],{structs:a}));u={components:t}}else if(s.type in a)c="tuple",u={components:a[s.type]};else if(Q.test(s.type))c=`${s.type}256`;else if("address payable"===s.type)c="address";else if(c=s.type,"struct"!==t?.type&&!ne(c))throw new R({type:c});if(s.modifier){if(!t?.modifiers?.has?.(s.modifier))throw new j({param:e,type:t?.type,modifier:s.modifier});if(N.has(s.modifier)&&!function(e,t){return t||"bytes"===e||"string"===e||"tuple"===e}(c,!!s.array))throw new G({param:e,type:t?.type,modifier:s.modifier})}const d={type:`${c}${s.array??""}`,...o,...i,...u};return Y.set(n,d),d}function te(e,t=[],n="",r=0){const s=e.trim().length;for(let o=0;o<s;o++){const s=e[o],i=e.slice(o+1);switch(s){case",":return 0===r?te(i,[...t,n.trim()]):te(i,t,`${n}${s}`,r);case"(":return te(i,t,`${n}${s}`,r+1);case")":return te(i,t,`${n}${s}`,r-1);default:return te(i,t,`${n}${s}`,r)}}if(""===n)return t;if(0!==r)throw new Z({current:n,depth:r});return t.push(n.trim()),t}function ne(e){return"address"===e||"bool"===e||"function"===e||"string"===e||m.test(e)||y.test(e)}const re=/^(?: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 se(e){const t={},n=e.length;for(let r=0;r<n;r++){const n=e[r];if(!I(n))continue;const s=k(n);if(!s)throw new q({signature:n,type:"struct"});const o=s.properties.split(";"),i=[],a=o.length;for(let e=0;e<a;e++){const t=o[e].trim();if(!t)continue;const n=ee(t,{type:"struct"});i.push(n)}if(!i.length)throw new H({signature:n});t[s.name]=i}const r={},s=Object.entries(t),o=s.length;for(let e=0;e<o;e++){const[n,o]=s[e];r[n]=ie(o,t)}return r}const oe=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?$/;function ie(e,t,n=new Set){const r=[],s=e.length;for(let o=0;o<s;o++){const s=e[o];if(g.test(s.type))r.push(s);else{const e=b(oe,s.type);if(!e?.type)throw new D({abiParameter:s});const{array:o,type:i}=e;if(i in t){if(n.has(i))throw new V({type:i});r.push({...s,type:`tuple${o??""}`,components:ie(t[i]??[],t,new Set([...n,i]))})}else{if(!ne(i))throw new L({type:i});r.push(s)}}}return r}function ae(e){const t=se(e),n=[],r=e.length;for(let s=0;s<r;s++){const r=e[s];I(r)||n.push(K(r,t))}return n}function ce(e){return"string"==typeof e?{address:e,type:"json-rpc"}:e}const ue="2.38.6";let de=({docsBaseUrl:e,docsPath:t="",docsSlug:n})=>t?`${e??"https://viem.sh"}${t}${n?`#${n}`:""}`:void 0,fe=`viem@${ue}`,le=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,o=de?.({...n,docsPath:s});super([t||"An error occurred.","",...n.metaMessages?[...n.metaMessages,""]:[],...o?[`Docs: ${o}`]:[],...r?[`Details: ${r}`]:[],...fe?[`Version: ${fe}`]:[]].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=ue}walk(e){return he(this,e)}};function he(e,t){return t?.(e)?e:e&&"object"==typeof e&&"cause"in e&&void 0!==e.cause?he(e.cause,t):t?null:e}class pe extends le{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"})}}function be(e,{strict:t=!0}={}){return!!e&&("string"==typeof e&&(t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")))}class me extends le{constructor({offset:e,position:t,size:n}){super(`Slice ${"start"===t?"starting":"ending"} at offset "${e}" is out-of-bounds (size: ${n}).`,{name:"SliceOffsetOutOfBoundsError"})}}let ye=class extends le{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 ge extends le{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 we(e,{dir:t,size:n=32}={}){return"string"==typeof e?ve(e,{dir:t,size:n}):xe(e,{dir:t,size:n})}function ve(e,{dir:t,size:n=32}={}){if(null===n)return e;const r=e.replace("0x","");if(r.length>2*n)throw new ye({size:Math.ceil(r.length/2),targetSize:n,type:"hex"});return`0x${r["right"===t?"padEnd":"padStart"](2*n,"0")}`}function xe(e,{dir:t,size:n=32}={}){if(null===n)return e;if(e.length>n)throw new ye({size:e.length,targetSize:n,type:"bytes"});const r=new Uint8Array(n);for(let s=0;s<n;s++){const o="right"===t;r[o?s:n-s-1]=e[o?s:e.length-s-1]}return r}let Ee=class extends le{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"})}};class _e extends le{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 Pe extends le{constructor(e){super(`Hex value "${e}" is not a valid boolean. The hex value must be "0x0" (false) or "0x1" (true).`,{name:"InvalidHexBooleanError"})}}class Se extends le{constructor(e){super(`Hex value "${e}" is an odd length (${e.length}). It must be an even length.`,{name:"InvalidHexValueError"})}}class Ie extends le{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}}function ke(e){return be(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}function Be(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 $e(e,{size:t}){if(ke(e)>t)throw new Ie({givenSize:ke(e),maxSize:t})}function Oe(e,t={}){const{signed:n}=t;t.size&&$e(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 Ae(e,t={}){let n=e;if(t.size&&($e(n,{size:t.size}),n=Be(n)),"0x00"===Be(n))return!1;if("0x01"===Be(n))return!0;throw new Pe(n)}function Te(e,t={}){return Number(Oe(e,t))}function Ne(e,t={}){let n=He(e);return t.size&&($e(n,{size:t.size}),n=Be(n,{dir:"right"})),(new TextDecoder).decode(n)}const Ce=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Le(e,t={}){return"number"==typeof e||"bigint"==typeof e?ze(e,t):"string"==typeof e?Ue(e,t):"boolean"==typeof e?Re(e,t):Me(e,t)}function Re(e,t={}){const n=`0x${Number(e)}`;return"number"==typeof t.size?($e(n,{size:t.size}),we(n,{size:t.size})):n}function Me(e,t={}){let n="";for(let t=0;t<e.length;t++)n+=Ce[e[t]];const r=`0x${n}`;return"number"==typeof t.size?($e(r,{size:t.size}),we(r,{dir:"right",size:t.size})):r}function ze(e,t={}){const{signed:n,size:r}=t,s=BigInt(e);let o;r?o=n?(1n<<8n*BigInt(r)-1n)-1n:2n**(8n*BigInt(r))-1n:"number"==typeof e&&(o=BigInt(Number.MAX_SAFE_INTEGER));const i="bigint"==typeof o&&n?-o-1n:0;if(o&&s>o||s<i){const t="bigint"==typeof e?"n":"";throw new Ee({max:o?`${o}${t}`:void 0,min:`${i}${t}`,signed:n,size:r,value:`${e}${t}`})}const a=`0x${(n&&s<0?(1n<<BigInt(8*r))+BigInt(s):s).toString(16)}`;return r?we(a,{size:r}):a}const Fe=new TextEncoder;function Ue(e,t={}){return Me(Fe.encode(e),t)}const je=new TextEncoder;function Ge(e,t={}){return"number"==typeof e||"bigint"==typeof e?Ve(e,t):"boolean"==typeof e?De(e,t):be(e)?He(e,t):Ze(e,t)}function De(e,t={}){const n=new Uint8Array(1);return n[0]=Number(e),"number"==typeof t.size?($e(n,{size:t.size}),we(n,{size:t.size})):n}const qe={zero:48,nine:57,A:65,F:70,a:97,f:102};function We(e){return e>=qe.zero&&e<=qe.nine?e-qe.zero:e>=qe.A&&e<=qe.F?e-(qe.A-10):e>=qe.a&&e<=qe.f?e-(qe.a-10):void 0}function He(e,t={}){let n=e;t.size&&($e(n,{size:t.size}),n=we(n,{dir:"right",size:t.size}));let r=n.slice(2);r.length%2&&(r=`0${r}`);const s=r.length/2,o=new Uint8Array(s);for(let e=0,t=0;e<s;e++){const n=We(r.charCodeAt(t++)),s=We(r.charCodeAt(t++));if(void 0===n||void 0===s)throw new le(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);o[e]=16*n+s}return o}function Ve(e,t){return He(ze(e,t))}function Ze(e,t={}){const n=je.encode(e);return"number"==typeof t.size?($e(n,{size:t.size}),we(n,{dir:"right",size:t.size})):n}const Ye=BigInt(2**32-1),Ke=BigInt(32);function Xe(e,t=!1){return t?{h:Number(e&Ye),l:Number(e>>Ke&Ye)}:{h:0|Number(e>>Ke&Ye),l:0|Number(e&Ye)}}const Je=h&&"object"==typeof h&&"webcrypto"in h?h.webcrypto:h&&"object"==typeof h&&"randomBytes"in h?h:void 0;function Qe(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function et(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 tt(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 nt(e,t){et(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function rt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function st(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function ot(e,t){return e<<32-t|e>>>t}function it(e,t){return e<<t|e>>>32-t>>>0}function at(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const ct=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])()?e=>e:function(e){for(let t=0;t<e.length;t++)e[t]=at(e[t]);return e};function ut(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)),et(e),e}class dt{}function ft(e){const t=t=>e().update(ut(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function lt(e=32){if(Je&&"function"==typeof Je.getRandomValues)return Je.getRandomValues(new Uint8Array(e));if(Je&&"function"==typeof Je.randomBytes)return Uint8Array.from(Je.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}const ht=BigInt(0),pt=BigInt(1),bt=BigInt(2),mt=BigInt(7),yt=BigInt(256),gt=BigInt(113),wt=[],vt=[],xt=[];for(let e=0,t=pt,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],wt.push(2*(5*r+n)),vt.push((e+1)*(e+2)/2%64);let s=ht;for(let e=0;e<7;e++)t=(t<<pt^(t>>mt)*gt)%yt,t&bt&&(s^=pt<<(pt<<BigInt(e))-pt);xt.push(s)}const Et=function(e,t=!1){const n=e.length;let r=new Uint32Array(n),s=new Uint32Array(n);for(let o=0;o<n;o++){const{h:n,l:i}=Xe(e[o],t);[r[o],s[o]]=[n,i]}return[r,s]}(xt,!0),_t=Et[0],Pt=Et[1],St=(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),It=(e,t,n)=>n>32?((e,t,n)=>e<<n-32|t>>>64-n)(e,t,n):((e,t,n)=>t<<n|e>>>32-n)(e,t,n);class kt extends dt{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,Qe(n),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");var o;this.state=new Uint8Array(200),this.state32=(o=this.state,new Uint32Array(o.buffer,o.byteOffset,Math.floor(o.byteLength/4)))}clone(){return this._cloneInto()}keccak(){ct(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,o=n[s],i=n[s+1],a=St(o,i,1)^n[r],c=It(o,i,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=a,e[t+n+1]^=c}let t=e[2],s=e[3];for(let n=0;n<24;n++){const r=vt[n],o=St(t,s,r),i=It(t,s,r),a=wt[n];t=e[a],s=e[a+1],e[a]=o,e[a+1]=i}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]^=_t[r],e[1]^=Pt[r]}rt(n)}(this.state32,this.rounds),ct(this.state32),this.posOut=0,this.pos=0}update(e){tt(this),et(e=ut(e));const{blockLen:t,state:n}=this,r=e.length;for(let s=0;s<r;){const o=Math.min(t-this.pos,r-s);for(let t=0;t<o;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){tt(this,!1),et(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 o=Math.min(n-this.posOut,s-r);e.set(t.subarray(this.posOut,this.posOut+o),r),this.posOut+=o,r+=o}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return Qe(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(nt(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,rt(this.state)}_cloneInto(e){const{blockLen:t,suffix:n,outputLen:r,rounds:s,enableXOF:o}=this;return e||(e=new kt(t,n,r,o,s)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=s,e.suffix=n,e.outputLen=r,e.enableXOF=o,e.destroyed=this.destroyed,e}}const Bt=(()=>{return e=1,t=136,n=32,ft(()=>new kt(t,e,n));var e,t,n})();function $t(e,t){const n=t||"hex",r=Bt(be(e,{strict:!1})?Ge(e):e);return"bytes"===n?r:Le(r)}class Ot 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 At=/^0x[a-fA-F0-9]{40}$/,Tt=new Ot(8192);function Nt(e,t){const{strict:n=!0}=t??{},r=`${e}.${n}`;if(Tt.has(r))return Tt.get(r);const s=!(!At.test(e)||e.toLowerCase()!==e&&n&&Lt(e)!==e);return Tt.set(r,s),s}const Ct=new Ot(8192);function Lt(e,t){if(Ct.has(`${e}.${t}`))return Ct.get(`${e}.${t}`);const n=t?`${t}${e.toLowerCase()}`:e.substring(2).toLowerCase(),r=$t(Ze(n),"bytes"),s=(t?n.substring(`${t}0x`.length):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 o=`0x${s.join("")}`;return Ct.set(`${e}.${t}`,o),o}function Rt(e,t){if(!Nt(e,{strict:!1}))throw new pe({address:e});return Lt(e,t)}function Mt(e){return Lt(`0x${$t(`0x${e.substring(4)}`).substring(26)}`)}function zt(e,{includeName:t=!1}={}){if("function"!==e.type&&"event"!==e.type&&"error"!==e.type)throw new dn(e.type);return`${e.name}(${Ft(e.inputs,{includeName:t})})`}function Ft(e,{includeName:t=!1}={}){return e?e.map(e=>function(e,{includeName:t}){if(e.type.startsWith("tuple"))return`(${Ft(e.components,{includeName:t})})${e.type.slice(5)}`;return e.type+(t&&e.name?` ${e.name}`:"")}(e,{includeName:t})).join(t?", ":","):""}class Ut extends le{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 jt extends le{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 Gt extends le{constructor({data:e,params:t,size:n}){super([`Data size of ${n} bytes is too small for given parameters.`].join("\n"),{metaMessages:[`Params: (${Ft(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 Dt extends le{constructor(){super('Cannot decode zero data ("0x") with ABI parameters.',{name:"AbiDecodingZeroDataError"})}}class qt extends le{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 Wt extends le{constructor({expectedSize:e,value:t}){super(`Size of bytes "${t}" (bytes${ke(t)}) does not match expected size (bytes${e}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class Ht extends le{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 Vt extends le{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 Zt extends le{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 Yt extends le{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 Kt extends le{constructor({docsPath:e}){super("Cannot extract event signature from empty topics.",{docsPath:e,name:"AbiEventSignatureEmptyTopicsError"})}}class Xt extends le{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 Jt extends le{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 Qt extends le{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 en extends le{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 tn extends le{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 nn extends le{constructor(e,t){super("Found ambiguous types in overloaded ABI items.",{metaMessages:[`\`${e.type}\` in \`${zt(e.abiItem)}\`, and`,`\`${t.type}\` in \`${zt(t.abiItem)}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."],name:"AbiItemAmbiguityError"})}}class rn extends le{constructor({expectedSize:e,givenSize:t}){super(`Expected bytes${e}, got bytes${t}.`,{name:"BytesSizeMismatchError"})}}class sn extends le{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: (${Ft(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 on extends le{constructor({abiItem:e,param:t}){super([`Expected a topic for indexed event parameter${t.name?` "${t.name}"`:""} on event "${zt(e,{includeName:!0})}".`].join("\n"),{name:"DecodeLogTopicsMismatch"}),Object.defineProperty(this,"abiItem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abiItem=e}}class an extends le{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 cn extends le{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"})}}class un extends le{constructor(e){super([`Value "${e}" is not a valid array.`].join("\n"),{name:"InvalidArrayError"})}}class dn extends le{constructor(e){super([`"${e}" is not a valid definition type.`,'Valid types: "function", "event", "error"'].join("\n"),{name:"InvalidDefinitionTypeError"})}}class fn extends le{constructor(e){super(`Type "${e}" is not supported for packed encoding.`,{name:"UnsupportedPackedAbiType"})}}class ln extends le{constructor({offset:e}){super(`Offset \`${e}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class hn extends le{constructor({length:e,position:t}){super(`Position \`${t}\` is out of bounds (\`0 < position < ${e}\`).`,{name:"PositionOutOfBoundsError"})}}class pn extends le{constructor({count:e,limit:t}){super(`Recursive read limit of \`${t}\` exceeded (recursive read count: \`${e}\`).`,{name:"RecursiveReadLimitExceededError"})}}const bn={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 pn({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new hn({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new ln({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 ln({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 mn(e,{recursiveReadLimit:t=8192}={}){const n=Object.create(bn);return n.bytes=e,n.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),n.positionReadCount=new Map,n.recursiveReadLimit=t,n}function yn(e,t,n,{strict:r}={}){return be(e,{strict:!1})?xn(e,t,n,{strict:r}):vn(e,t,n,{strict:r})}function gn(e,t){if("number"==typeof t&&t>0&&t>ke(e)-1)throw new me({offset:t,position:"start",size:ke(e)})}function wn(e,t,n){if("number"==typeof t&&"number"==typeof n&&ke(e)!==n-t)throw new me({offset:n,position:"end",size:ke(e)})}function vn(e,t,n,{strict:r}={}){gn(e,t);const s=e.slice(t,n);return r&&wn(s,t,n),s}function xn(e,t,n,{strict:r}={}){gn(e,t);const s=`0x${e.replace("0x","").slice(2*(t??0),2*(n??e.length))}`;return r&&wn(s,t,n),s}function En(e,t={}){void 0!==t.size&&$e(e,{size:t.size});return Oe(Me(e,t),t)}function _n(e,t={}){let n=e;if(void 0!==t.size&&($e(n,{size:t.size}),n=Be(n)),n.length>1||n[0]>1)throw new _e(n);return Boolean(n[0])}function Pn(e,t={}){void 0!==t.size&&$e(e,{size:t.size});return Te(Me(e,t),t)}function Sn(e,t={}){let n=e;return void 0!==t.size&&($e(n,{size:t.size}),n=Be(n,{dir:"right"})),(new TextDecoder).decode(n)}function In(e){return"string"==typeof e[0]?Bn(e):kn(e)}function kn(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}function Bn(e){return`0x${e.reduce((e,t)=>e+t.replace("0x",""),"")}`}const $n=/^(.*)\[([0-9]*)\]$/,On=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,An=/^(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 Tn(e,t){if(e.length!==t.length)throw new Ht({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(Nn({param:e[r],value:t[r]}));return n}({params:e,values:t}),r=Cn(n);return 0===r.length?"0x":r}function Nn({param:e,value:t}){const n=Ln(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 un(e);if(!r&&e.length!==t)throw new qt({expectedLength:t,givenLength:e.length,type:`${n.type}[${t}]`});let s=!1;const o=[];for(let t=0;t<e.length;t++){const r=Nn({param:n,value:e[t]});r.dynamic&&(s=!0),o.push(r)}if(r||s){const e=Cn(o);if(r){const t=ze(o.length,{size:32});return{dynamic:!0,encoded:o.length>0?In([t,e]):t}}if(s)return{dynamic:!0,encoded:e}}return{dynamic:!1,encoded:In(o.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 o=t.components[s],i=Nn({param:o,value:e[Array.isArray(e)?s:o.name]});r.push(i),i.dynamic&&(n=!0)}return{dynamic:n,encoded:n?Cn(r):In(r.map(({encoded:e})=>e))}}(t,{param:e});if("address"===e.type)return function(e){if(!Nt(e))throw new pe({address:e});return{dynamic:!1,encoded:ve(e.toLowerCase())}}(t);if("bool"===e.type)return function(e){if("boolean"!=typeof e)throw new le(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:ve(Re(e))}}(t);if(e.type.startsWith("uint")||e.type.startsWith("int")){const n=e.type.startsWith("int"),[,,r="256"]=An.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 Ee({max:r.toString(),min:s.toString(),signed:t,size:n/8,value:e.toString()})}return{dynamic:!1,encoded:ze(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=ke(e);if(!n){let t=e;return r%32!=0&&(t=ve(t,{dir:"right",size:32*Math.ceil((e.length-2)/2/32)})),{dynamic:!0,encoded:In([ve(ze(r,{size:32})),t])}}if(r!==Number.parseInt(n,10))throw new Wt({expectedSize:Number.parseInt(n,10),value:e});return{dynamic:!1,encoded:ve(e,{dir:"right"})}}(t,{param:e});if("string"===e.type)return function(e){const t=Ue(e),n=Math.ceil(ke(t)/32),r=[];for(let e=0;e<n;e++)r.push(ve(yn(t,32*e,32*(e+1)),{dir:"right"}));return{dynamic:!0,encoded:In([ve(ze(ke(t),{size:32})),...r])}}(t);throw new an(e.type,{docsPath:"/docs/contract/encodeAbiParameters"})}function Cn(e){let t=0;for(let n=0;n<e.length;n++){const{dynamic:r,encoded:s}=e[n];t+=r?32:ke(s)}const n=[],r=[];let s=0;for(let o=0;o<e.length;o++){const{dynamic:i,encoded:a}=e[o];i?(n.push(ze(t+s,{size:32})),r.push(a),s+=ke(a)):n.push(a)}return In([...n,...r])}function Ln(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}function Rn(e,t){const n="string"==typeof t?He(t):t,r=mn(n);if(0===ke(n)&&e.length>0)throw new Dt;if(ke(t)&&ke(t)<32)throw new Gt({data:"string"==typeof t?t:Me(t),params:e,size:ke(t)});let s=0;const o=[];for(let t=0;t<e.length;++t){const n=e[t];r.setPosition(s);const[i,a]=Mn(r,n,{staticPosition:0});s+=a,o.push(i)}return o}function Mn(e,t,{staticPosition:n}){const r=Ln(t.type);if(r){const[s,o]=r;return function(e,t,{length:n,staticPosition:r}){if(!n){const n=r+Pn(e.readBytes(Fn)),s=n+zn;e.setPosition(n);const o=Pn(e.readBytes(zn)),i=Un(t);let a=0;const c=[];for(let n=0;n<o;++n){e.setPosition(s+(i?32*n:a));const[r,o]=Mn(e,t,{staticPosition:s});a+=o,c.push(r)}return e.setPosition(r+32),[c,32]}if(Un(t)){const s=r+Pn(e.readBytes(Fn)),o=[];for(let r=0;r<n;++r){e.setPosition(s+32*r);const[n]=Mn(e,t,{staticPosition:s});o.push(n)}return e.setPosition(r+32),[o,32]}let s=0;const o=[];for(let i=0;i<n;++i){const[n,i]=Mn(e,t,{staticPosition:r+s});s+=i,o.push(n)}return[o,s]}(e,{...t,type:o},{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 o=0;if(Un(t)){const i=n+Pn(e.readBytes(Fn));for(let n=0;n<t.components.length;++n){const a=t.components[n];e.setPosition(i+o);const[c,u]=Mn(e,a,{staticPosition:i});o+=u,s[r?n:a?.name]=c}return e.setPosition(n+32),[s,32]}for(let i=0;i<t.components.length;++i){const a=t.components[i],[c,u]=Mn(e,a,{staticPosition:n});s[r?i:a?.name]=c,o+=u}return[s,o]}(e,t,{staticPosition:n});if("address"===t.type)return function(e){const t=e.readBytes(32);return[Lt(Me(vn(t,-20))),32]}(e);if("bool"===t.type)return function(e){return[_n(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=Pn(e.readBytes(32));e.setPosition(n+t);const r=Pn(e.readBytes(32));if(0===r)return e.setPosition(n+32),["0x",32];const s=e.readBytes(r);return e.setPosition(n+32),[Me(s),32]}const o=Me(e.readBytes(Number.parseInt(s,10),32));return[o,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?En(s,{signed:n}):Pn(s,{signed:n}),32]}(e,t);if("string"===t.type)return function(e,{staticPosition:t}){const n=Pn(e.readBytes(32)),r=t+n;e.setPosition(r);const s=Pn(e.readBytes(32));if(0===s)return e.setPosition(t+32),["",32];const o=e.readBytes(s,32),i=Sn(Be(o));return e.setPosition(t+32),[i,32]}(e,{staticPosition:n});throw new cn(t.type,{docsPath:"/docs/contract/decodeAbiParameters"})}const zn=32,Fn=32;function Un(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(Un);const n=Ln(e.type);return!(!n||!Un({...e,type:n[1]}))}const jn={1:"An `assert` condition failed.",17:"Arithmetic operation resulted in underflow or overflow.",18:"Division or modulo by zero (e.g. `5 / 0` or `23 % 0`).",33:"Attempted to convert to an invalid type.",34:"Attempted to access a storage byte array that is incorrectly encoded.",49:"Performed `.pop()` on an empty array",50:"Array index is out of bounds.",65:"Allocated too much memory or created an array which is too large.",81:"Attempted to call a zero-initialized variable of internal function type."},Gn={inputs:[{name:"message",type:"string"}],name:"Error",type:"error"},Dn={inputs:[{name:"reason",type:"uint256"}],name:"Panic",type:"error"};function qn(e){return $t(Ge(e))}const Wn=e=>{var t;return function(e){let t=!0,n="",r=0,s="",o=!1;for(let i=0;i<e.length;i++){const a=e[i];if(["(",")",","].includes(a)&&(t=!0),"("===a&&r++,")"===a&&r--,t)if(0!==r)" "!==a?(s+=a,n+=a):","!==e[i-1]&&","!==n&&",("!==n&&(n="",t=!1);else if(" "===a&&["event","function",""].includes(s))s="";else if(s+=a,")"===a){o=!0;break}}if(!o)throw new le("Unable to normalize signature.");return s}("string"==typeof e?e:"function"===(t=e).type?`function ${t.name}(${x(t.inputs)})${t.stateMutability&&"nonpayable"!==t.stateMutability?` ${t.stateMutability}`:""}${t.outputs?.length?` returns (${x(t.outputs)})`:""}`:"event"===t.type?`event ${t.name}(${x(t.inputs)})`:"error"===t.type?`error ${t.name}(${x(t.inputs)})`:"constructor"===t.type?`constructor(${x(t.inputs)})${"payable"===t.stateMutability?" payable":""}`:"fallback"===t.type?"fallback() external"+("payable"===t.stateMutability?" payable":""):"receive() external payable")};function Hn(e){return qn(Wn(e))}const Vn=e=>yn(Hn(e),0,4);function Zn(e){const{abi:t,data:n}=e,r=yn(n,0,4);if("0x"===r)throw new Dt;const s=[...t||[],Gn,Dn].find(e=>"error"===e.type&&r===Vn(zt(e)));if(!s)throw new Yt(r,{docsPath:"/docs/contract/decodeErrorResult"});return{abiItem:s,args:"inputs"in s&&s.inputs&&s.inputs.length>0?Rn(s.inputs,yn(n,4)):void 0,errorName:s.name}}const Yn=Hn,Kn="/docs/contract/decodeEventLog";function Xn(e){const{abi:t,data:n,strict:r,topics:s}=e,o=r??!0,[i,...a]=s;if(!i)throw new Kt({docsPath:Kn});const c=t.find(e=>"event"===e.type&&i===Yn(zt(e)));if(!c||!("name"in c)||"event"!==c.type)throw new Xt(i,{docsPath:Kn});const{name:u,inputs:d}=c,f=d?.some(e=>!("name"in e&&e.name)),l=f?[]:{},h=d.map((e,t)=>[e,t]).filter(([e])=>"indexed"in e&&e.indexed);for(let e=0;e<h.length;e++){const[t,n]=h[e],r=a[e];if(!r)throw new on({abiItem:c,param:t});l[f?n:t.name||n]=Jn({param:t,value:r})}const p=d.filter(e=>!("indexed"in e&&e.indexed));if(p.length>0)if(n&&"0x"!==n)try{const e=Rn(p,n);if(e)if(f)for(let t=0;t<d.length;t++)l[t]=l[t]??e.shift();else for(let t=0;t<p.length;t++)l[p[t].name]=e[t]}catch(e){if(o){if(e instanceof Gt||e instanceof hn)throw new sn({abiItem:c,data:n,params:p,size:ke(n)});throw e}}else if(o)throw new sn({abiItem:c,data:"0x",params:p,size:0});return{eventName:u,args:Object.values(l).length>0?l:void 0}}function Jn({param:e,value:t}){if("string"===e.type||"bytes"===e.type||"tuple"===e.type||e.type.match(/^(.*)\[(\d+)?\]$/))return t;return(Rn([e],t)||[])[0]}function Qn(e){const{abi:t,data:n}=e,r=yn(n,0,4),s=t.find(e=>"function"===e.type&&r===Vn(zt(e)));if(!s)throw new tn(r,{docsPath:"/docs/contract/decodeFunctionData"});return{functionName:s.name,args:"inputs"in s&&s.inputs&&s.inputs.length>0?Rn(s.inputs,yn(n,4)):void 0}}function er(e){const{abi:t,args:n=[],name:r}=e,s=be(r,{strict:!1}),o=t.filter(e=>s?"function"===e.type?Vn(e)===r:"event"===e.type&&Yn(e)===r:"name"in e&&e.name===r);if(0===o.length)return;if(1===o.length)return o[0];let i;for(const e of o){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;const t=n.every((t,n)=>{const r="inputs"in e&&e.inputs[n];return!!r&&tr(t,r)});if(t){if(i&&"inputs"in i&&i.inputs){const t=nr(e.inputs,i.inputs,n);if(t)throw new nn({abiItem:e,type:t[0]},{abiItem:i,type:t[1]})}i=e}}return i||o[0]}function tr(e,t){const n=typeof e,r=t.type;switch(r){case"address":return Nt(e,{strict:!1});case"bool":return"boolean"===n;case"function":case"string":retur