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