UNPKG

@midcontract/sdk

Version:

Typescript SDK to interact with Midcontract contracts

20 lines 490 kB
"use strict";var Lc=Object.defineProperty;var qc=(t,e,n)=>e in t?Lc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var G=(t,e,n)=>qc(t,typeof e!="symbol"?e+"":e,n);const Hc="1.0.8";let we=class fr extends Error{constructor(e,n={}){var i;const a=n.cause instanceof fr?n.cause.details:(i=n.cause)!=null&&i.message?n.cause.message:n.details,r=n.cause instanceof fr&&n.cause.docsPath||n.docsPath,s=[e||"An error occurred.","",...n.metaMessages?[...n.metaMessages,""]:[],...r?[`Docs: https://abitype.dev${r}`]:[],...a?[`Details: ${a}`]:[],`Version: abitype@${Hc}`].join(` `);super(s),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=a,this.docsPath=r,this.metaMessages=n.metaMessages,this.shortMessage=e}};function Ke(t,e){const n=t.exec(e);return n==null?void 0:n.groups}const eo=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,to=/^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)?$/,no=/^\(.+?\).*?$/,Vs=/^tuple(?<array>(\[(\d*)\])*)$/;function hr(t){let e=t.type;if(Vs.test(t.type)&&"components"in t){e="(";const n=t.components.length;for(let r=0;r<n;r++){const s=t.components[r];e+=hr(s),r<n-1&&(e+=", ")}const a=Ke(Vs,t.type);return e+=`)${(a==null?void 0:a.array)??""}`,hr({...t,type:e})}return"indexed"in t&&t.indexed&&(e=`${e} indexed`),t.name?`${e} ${t.name}`:e}function cn(t){let e="";const n=t.length;for(let a=0;a<n;a++){const r=t[a];e+=hr(r),a!==n-1&&(e+=", ")}return e}function ca(t){var e;return t.type==="function"?`function ${t.name}(${cn(t.inputs)})${t.stateMutability&&t.stateMutability!=="nonpayable"?` ${t.stateMutability}`:""}${(e=t.outputs)!=null&&e.length?` returns (${cn(t.outputs)})`:""}`:t.type==="event"?`event ${t.name}(${cn(t.inputs)})`:t.type==="error"?`error ${t.name}(${cn(t.inputs)})`:t.type==="constructor"?`constructor(${cn(t.inputs)})${t.stateMutability==="payable"?" payable":""}`:t.type==="fallback"?`fallback() external${t.stateMutability==="payable"?" payable":""}`:"receive() external payable"}const ao=/^error (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;function jc(t){return ao.test(t)}function Gc(t){return Ke(ao,t)}const ro=/^event (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;function Wc(t){return ro.test(t)}function Vc(t){return Ke(ro,t)}const so=/^function (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)(?: (?<scope>external|public{1}))?(?: (?<stateMutability>pure|view|nonpayable|payable{1}))?(?: returns\s?\((?<returns>.*?)\))?$/;function Zc(t){return so.test(t)}function Jc(t){return Ke(so,t)}const io=/^struct (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) \{(?<properties>.*?)\}$/;function rs(t){return io.test(t)}function Kc(t){return Ke(io,t)}const oo=/^constructor\((?<parameters>.*?)\)(?:\s(?<stateMutability>payable{1}))?$/;function Yc(t){return oo.test(t)}function Xc(t){return Ke(oo,t)}const uo=/^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/;function Qc(t){return uo.test(t)}function ed(t){return Ke(uo,t)}const td=/^receive\(\) external payable$/;function nd(t){return td.test(t)}const ad=new Set(["indexed"]),br=new Set(["calldata","memory","storage"]);class rd extends we{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 sd extends we{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 id extends we{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 od extends we{constructor({param:e}){super("Invalid ABI parameter.",{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParameterError"})}}class ud extends we{constructor({param:e,name:n}){super("Invalid ABI parameter.",{details:e,metaMessages:[`"${n}" 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 cd extends we{constructor({param:e,type:n,modifier:a}){super("Invalid ABI parameter.",{details:e,metaMessages:[`Modifier "${a}" not allowed${n?` in "${n}" type`:""}.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidModifierError"})}}class dd extends we{constructor({param:e,type:n,modifier:a}){super("Invalid ABI parameter.",{details:e,metaMessages:[`Modifier "${a}" not allowed${n?` in "${n}" type`:""}.`,`Data location can only be specified for array, struct, or mapping types, but "${a}" was given.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidFunctionModifierError"})}}class pd extends we{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 Yt extends we{constructor({signature:e,type:n}){super(`Invalid ${n} signature.`,{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidSignatureError"})}}class ld extends we{constructor({signature:e}){super("Unknown signature.",{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSignatureError"})}}class yd extends we{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 md extends we{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 fd extends we{constructor({current:e,depth:n}){super("Unbalanced parentheses.",{metaMessages:[`"${e.trim()}" has too many ${n>0?"opening":"closing"} parentheses.`],details:`Depth "${n}"`}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParenthesisError"})}}function hd(t,e,n){let a="";if(n)for(const r of Object.entries(n)){if(!r)continue;let s="";for(const i of r[1])s+=`[${i.type}${i.name?`:${i.name}`:""}]`;a+=`(${r[0]}{${s}})`}return e?`${e}:${t}${a}`:t}const ja=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 wr(t,e={}){if(Zc(t))return bd(t,e);if(Wc(t))return wd(t,e);if(jc(t))return gd(t,e);if(Yc(t))return Td(t,e);if(Qc(t))return xd(t);if(nd(t))return{type:"receive",stateMutability:"payable"};throw new ld({signature:t})}function bd(t,e={}){const n=Jc(t);if(!n)throw new Yt({signature:t,type:"function"});const a=_e(n.parameters),r=[],s=a.length;for(let o=0;o<s;o++)r.push(ft(a[o],{modifiers:br,structs:e,type:"function"}));const i=[];if(n.returns){const o=_e(n.returns),u=o.length;for(let c=0;c<u;c++)i.push(ft(o[c],{modifiers:br,structs:e,type:"function"}))}return{name:n.name,type:"function",stateMutability:n.stateMutability??"nonpayable",inputs:r,outputs:i}}function wd(t,e={}){const n=Vc(t);if(!n)throw new Yt({signature:t,type:"event"});const a=_e(n.parameters),r=[],s=a.length;for(let i=0;i<s;i++)r.push(ft(a[i],{modifiers:ad,structs:e,type:"event"}));return{name:n.name,type:"event",inputs:r}}function gd(t,e={}){const n=Gc(t);if(!n)throw new Yt({signature:t,type:"error"});const a=_e(n.parameters),r=[],s=a.length;for(let i=0;i<s;i++)r.push(ft(a[i],{structs:e,type:"error"}));return{name:n.name,type:"error",inputs:r}}function Td(t,e={}){const n=Xc(t);if(!n)throw new Yt({signature:t,type:"constructor"});const a=_e(n.parameters),r=[],s=a.length;for(let i=0;i<s;i++)r.push(ft(a[i],{structs:e,type:"constructor"}));return{type:"constructor",stateMutability:n.stateMutability??"nonpayable",inputs:r}}function xd(t){const e=ed(t);if(!e)throw new Yt({signature:t,type:"fallback"});return{type:"fallback",stateMutability:e.stateMutability??"nonpayable"}}const vd=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,Ed=/^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,_d=/^u?int$/;function ft(t,e){var p,l;const n=hd(t,e==null?void 0:e.type,e==null?void 0:e.structs);if(ja.has(n))return ja.get(n);const a=no.test(t),r=Ke(a?Ed:vd,t);if(!r)throw new od({param:t});if(r.name&&Id(r.name))throw new ud({param:t,name:r.name});const s=r.name?{name:r.name}:{},i=r.modifier==="indexed"?{indexed:!0}:{},o=(e==null?void 0:e.structs)??{};let u,c={};if(a){u="tuple";const y=_e(r.type),f=[],h=y.length;for(let m=0;m<h;m++)f.push(ft(y[m],{structs:o}));c={components:f}}else if(r.type in o)u="tuple",c={components:o[r.type]};else if(_d.test(r.type))u=`${r.type}256`;else if(u=r.type,(e==null?void 0:e.type)!=="struct"&&!co(u))throw new id({type:u});if(r.modifier){if(!((l=(p=e==null?void 0:e.modifiers)==null?void 0:p.has)!=null&&l.call(p,r.modifier)))throw new cd({param:t,type:e==null?void 0:e.type,modifier:r.modifier});if(br.has(r.modifier)&&!Md(u,!!r.array))throw new dd({param:t,type:e==null?void 0:e.type,modifier:r.modifier})}const d={type:`${u}${r.array??""}`,...s,...i,...c};return ja.set(n,d),d}function _e(t,e=[],n="",a=0){const r=t.trim().length;for(let s=0;s<r;s++){const i=t[s],o=t.slice(s+1);switch(i){case",":return a===0?_e(o,[...e,n.trim()]):_e(o,e,`${n}${i}`,a);case"(":return _e(o,e,`${n}${i}`,a+1);case")":return _e(o,e,`${n}${i}`,a-1);default:return _e(o,e,`${n}${i}`,a)}}if(n==="")return e;if(a!==0)throw new fd({current:n,depth:a});return e.push(n.trim()),e}function co(t){return t==="address"||t==="bool"||t==="function"||t==="string"||eo.test(t)||to.test(t)}const Ad=/^(?: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 Id(t){return t==="address"||t==="bool"||t==="function"||t==="string"||t==="tuple"||eo.test(t)||to.test(t)||Ad.test(t)}function Md(t,e){return e||t==="bytes"||t==="string"||t==="tuple"}function po(t){const e={},n=t.length;for(let i=0;i<n;i++){const o=t[i];if(!rs(o))continue;const u=Kc(o);if(!u)throw new Yt({signature:o,type:"struct"});const c=u.properties.split(";"),d=[],p=c.length;for(let l=0;l<p;l++){const f=c[l].trim();if(!f)continue;const h=ft(f,{type:"struct"});d.push(h)}if(!d.length)throw new yd({signature:o});e[u.name]=d}const a={},r=Object.entries(e),s=r.length;for(let i=0;i<s;i++){const[o,u]=r[i];a[o]=lo(u,e)}return a}const Sd=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?$/;function lo(t,e,n=new Set){const a=[],r=t.length;for(let s=0;s<r;s++){const i=t[s];if(no.test(i.type))a.push(i);else{const u=Ke(Sd,i.type);if(!(u!=null&&u.type))throw new pd({abiParameter:i});const{array:c,type:d}=u;if(d in e){if(n.has(d))throw new md({type:d});a.push({...i,type:`tuple${c??""}`,components:lo(e[d]??[],e,new Set([...n,d]))})}else if(co(d))a.push(i);else throw new sd({type:d})}}return a}function yo(t){const e=po(t),n=[],a=t.length;for(let r=0;r<a;r++){const s=t[r];rs(s)||n.push(wr(s,e))}return n}function Zs(t){let e;if(typeof t=="string")e=wr(t);else{const n=po(t),a=t.length;for(let r=0;r<a;r++){const s=t[r];if(!rs(s)){e=wr(s,n);break}}}if(!e)throw new rd({signature:t});return e}function F(t,e,n){const a=t[e.name];if(typeof a=="function")return a;const r=t[n];return typeof r=="function"?r:s=>e(t,s)}function Be(t,{includeName:e=!1}={}){if(t.type!=="function"&&t.type!=="event"&&t.type!=="error")throw new zd(t.type);return`${t.name}(${ha(t.inputs,{includeName:e})})`}function ha(t,{includeName:e=!1}={}){return t?t.map(n=>Cd(n,{includeName:e})).join(e?", ":","):""}function Cd(t,{includeName:e}){return t.type.startsWith("tuple")?`(${ha(t.components,{includeName:e})})${t.type.slice(5)}`:t.type+(e&&t.name?` ${t.name}`:"")}function Ae(t,{strict:e=!0}={}){return!t||typeof t!="string"?!1:e?/^0x[0-9a-fA-F]*$/.test(t):t.startsWith("0x")}function Q(t){return Ae(t,{strict:!1})?Math.ceil((t.length-2)/2):t.length}const mo="2.24.1";let dn={getDocsUrl:({docsBaseUrl:t,docsPath:e="",docsSlug:n})=>e?`${t??"https://viem.sh"}${e}${n?`#${n}`:""}`:void 0,version:`viem@${mo}`},E=class gr extends Error{constructor(e,n={}){var o;const a=(()=>{var u;return n.cause instanceof gr?n.cause.details:(u=n.cause)!=null&&u.message?n.cause.message:n.details})(),r=n.cause instanceof gr&&n.cause.docsPath||n.docsPath,s=(o=dn.getDocsUrl)==null?void 0:o.call(dn,{...n,docsPath:r}),i=[e||"An error occurred.","",...n.metaMessages?[...n.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...a?[`Details: ${a}`]:[],...dn.version?[`Version: ${dn.version}`]:[]].join(` `);super(i,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=a,this.docsPath=r,this.metaMessages=n.metaMessages,this.name=n.name??this.name,this.shortMessage=e,this.version=mo}walk(e){return fo(this,e)}};function fo(t,e){return e!=null&&e(t)?t:t&&typeof t=="object"&&"cause"in t&&t.cause!==void 0?fo(t.cause,e):e?null:t}class Pd extends E{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(` `),{docsPath:e,name:"AbiConstructorNotFoundError"})}}class Js extends E{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(` `),{docsPath:e,name:"AbiConstructorParamsNotFoundError"})}}class ho extends E{constructor({data:e,params:n,size:a}){super([`Data size of ${a} bytes is too small for given parameters.`].join(` `),{metaMessages:[`Params: (${ha(n,{includeName:!0})})`,`Data: ${e} (${a} 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=n,this.size=a}}class Bn extends E{constructor(){super('Cannot decode zero data ("0x") with ABI parameters.',{name:"AbiDecodingZeroDataError"})}}class Rd extends E{constructor({expectedLength:e,givenLength:n,type:a}){super([`ABI encoding array length mismatch for type ${a}.`,`Expected length: ${e}`,`Given length: ${n}`].join(` `),{name:"AbiEncodingArrayLengthMismatchError"})}}class Nd extends E{constructor({expectedSize:e,value:n}){super(`Size of bytes "${n}" (bytes${Q(n)}) does not match expected size (bytes${e}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class bo extends E{constructor({expectedLength:e,givenLength:n}){super(["ABI encoding params/values length mismatch.",`Expected length (params): ${e}`,`Given length (values): ${n}`].join(` `),{name:"AbiEncodingLengthMismatchError"})}}class wo extends E{constructor(e,{docsPath:n}){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(` `),{docsPath:n,name:"AbiErrorSignatureNotFoundError"}),Object.defineProperty(this,"signature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.signature=e}}class Bd extends E{constructor({docsPath:e}){super("Cannot extract event signature from empty topics.",{docsPath:e,name:"AbiEventSignatureEmptyTopicsError"})}}class go extends E{constructor(e,{docsPath:n}){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(` `),{docsPath:n,name:"AbiEventSignatureNotFoundError"})}}class Ks extends E{constructor(e,{docsPath:n}={}){super([`Event ${e?`"${e}" `:""}not found on ABI.`,"Make sure you are using the correct ABI and that the event exists on it."].join(` `),{docsPath:n,name:"AbiEventNotFoundError"})}}class da extends E{constructor(e,{docsPath:n}={}){super([`Function ${e?`"${e}" `:""}not found on ABI.`,"Make sure you are using the correct ABI and that the function exists on it."].join(` `),{docsPath:n,name:"AbiFunctionNotFoundError"})}}class kd extends E{constructor(e,{docsPath:n}){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(` `),{docsPath:n,name:"AbiFunctionOutputsNotFoundError"})}}class Fd extends E{constructor(e,{docsPath:n}){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(` `),{docsPath:n,name:"AbiFunctionSignatureNotFoundError"})}}class Dd extends E{constructor(e,n){super("Found ambiguous types in overloaded ABI items.",{metaMessages:[`\`${e.type}\` in \`${Be(e.abiItem)}\`, and`,`\`${n.type}\` in \`${Be(n.abiItem)}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."],name:"AbiItemAmbiguityError"})}}let To=class extends E{constructor({expectedSize:e,givenSize:n}){super(`Expected bytes${e}, got bytes${n}.`,{name:"BytesSizeMismatchError"})}};class mn extends E{constructor({abiItem:e,data:n,params:a,size:r}){super([`Data size of ${r} bytes is too small for non-indexed event parameters.`].join(` `),{metaMessages:[`Params: (${ha(a,{includeName:!0})})`,`Data: ${n} (${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=n,this.params=a,this.size=r}}class ba extends E{constructor({abiItem:e,param:n}){super([`Expected a topic for indexed event parameter${n.name?` "${n.name}"`:""} on event "${Be(e,{includeName:!0})}".`].join(` `),{name:"DecodeLogTopicsMismatch"}),Object.defineProperty(this,"abiItem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abiItem=e}}class Od extends E{constructor(e,{docsPath:n}){super([`Type "${e}" is not a valid encoding type.`,"Please provide a valid ABI type."].join(` `),{docsPath:n,name:"InvalidAbiEncodingType"})}}class $d extends E{constructor(e,{docsPath:n}){super([`Type "${e}" is not a valid decoding type.`,"Please provide a valid ABI type."].join(` `),{docsPath:n,name:"InvalidAbiDecodingType"})}}let Ud=class extends E{constructor(e){super([`Value "${e}" is not a valid array.`].join(` `),{name:"InvalidArrayError"})}};class zd extends E{constructor(e){super([`"${e}" is not a valid definition type.`,'Valid types: "function", "event", "error"'].join(` `),{name:"InvalidDefinitionTypeError"})}}class Ld extends E{constructor(e){super(`Type "${e}" is not supported for packed encoding.`,{name:"UnsupportedPackedAbiType"})}}class qd extends E{constructor(e){super(`Filter type "${e}" is not supported.`,{name:"FilterTypeNotSupportedError"})}}let xo=class extends E{constructor({offset:e,position:n,size:a}){super(`Slice ${n==="start"?"starting":"ending"} at offset "${e}" is out-of-bounds (size: ${a}).`,{name:"SliceOffsetOutOfBoundsError"})}},vo=class extends E{constructor({size:e,targetSize:n,type:a}){super(`${a.charAt(0).toUpperCase()}${a.slice(1).toLowerCase()} size (${e}) exceeds padding size (${n}).`,{name:"SizeExceedsPaddingSizeError"})}};class Ys extends E{constructor({size:e,targetSize:n,type:a}){super(`${a.charAt(0).toUpperCase()}${a.slice(1).toLowerCase()} is expected to be ${n} ${a} long, but is ${e} ${a} long.`,{name:"InvalidBytesLengthError"})}}function Ge(t,{dir:e,size:n=32}={}){return typeof t=="string"?tt(t,{dir:e,size:n}):Hd(t,{dir:e,size:n})}function tt(t,{dir:e,size:n=32}={}){if(n===null)return t;const a=t.replace("0x","");if(a.length>n*2)throw new vo({size:Math.ceil(a.length/2),targetSize:n,type:"hex"});return`0x${a[e==="right"?"padEnd":"padStart"](n*2,"0")}`}function Hd(t,{dir:e,size:n=32}={}){if(n===null)return t;if(t.length>n)throw new vo({size:t.length,targetSize:n,type:"bytes"});const a=new Uint8Array(n);for(let r=0;r<n;r++){const s=e==="right";a[s?r:n-r-1]=t[s?r:t.length-r-1]}return a}let Eo=class extends E{constructor({max:e,min:n,signed:a,size:r,value:s}){super(`Number "${s}" is not in safe ${r?`${r*8}-bit ${a?"signed":"unsigned"} `:""}integer range ${e?`(${n} to ${e})`:`(above ${n})`}`,{name:"IntegerOutOfRangeError"})}};class jd extends E{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 Gd extends E{constructor(e){super(`Hex value "${e}" is not a valid boolean. The hex value must be "0x0" (false) or "0x1" (true).`,{name:"InvalidHexBooleanError"})}}let Wd=class extends E{constructor({givenSize:e,maxSize:n}){super(`Size cannot exceed ${n} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}};function ct(t,{dir:e="left"}={}){let n=typeof t=="string"?t.replace("0x",""):t,a=0;for(let r=0;r<n.length-1&&n[e==="left"?r:n.length-r-1].toString()==="0";r++)a++;return n=e==="left"?n.slice(a):n.slice(0,n.length-a),typeof t=="string"?(n.length===1&&e==="right"&&(n=`${n}0`),`0x${n.length%2===1?`0${n}`:n}`):n}function Me(t,{size:e}){if(Q(t)>e)throw new Wd({givenSize:Q(t),maxSize:e})}function ke(t,e={}){const{signed:n}=e;e.size&&Me(t,{size:e.size});const a=BigInt(t);if(!n)return a;const r=(t.length-2)/2,s=(1n<<BigInt(r)*8n-1n)-1n;return a<=s?a:a-BigInt(`0x${"f".padStart(r*2,"f")}`)-1n}function Vd(t,e={}){let n=t;if(e.size&&(Me(n,{size:e.size}),n=ct(n)),ct(n)==="0x00")return!1;if(ct(n)==="0x01")return!0;throw new Gd(n)}function Ve(t,e={}){return Number(ke(t,e))}const Zd=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function pe(t,e={}){return typeof t=="number"||typeof t=="bigint"?k(t,e):typeof t=="string"?ht(t,e):typeof t=="boolean"?ss(t,e):ne(t,e)}function ss(t,e={}){const n=`0x${Number(t)}`;return typeof e.size=="number"?(Me(n,{size:e.size}),Ge(n,{size:e.size})):n}function ne(t,e={}){let n="";for(let r=0;r<t.length;r++)n+=Zd[t[r]];const a=`0x${n}`;return typeof e.size=="number"?(Me(a,{size:e.size}),Ge(a,{dir:"right",size:e.size})):a}function k(t,e={}){const{signed:n,size:a}=e,r=BigInt(t);let s;a?n?s=(1n<<BigInt(a)*8n-1n)-1n:s=2n**(BigInt(a)*8n)-1n:typeof t=="number"&&(s=BigInt(Number.MAX_SAFE_INTEGER));const i=typeof s=="bigint"&&n?-s-1n:0;if(s&&r>s||r<i){const u=typeof t=="bigint"?"n":"";throw new Eo({max:s?`${s}${u}`:void 0,min:`${i}${u}`,signed:n,size:a,value:`${t}${u}`})}const o=`0x${(n&&r<0?(1n<<BigInt(a*8))+BigInt(r):r).toString(16)}`;return a?Ge(o,{size:a}):o}const Jd=new TextEncoder;function ht(t,e={}){const n=Jd.encode(t);return ne(n,e)}const Kd=new TextEncoder;function Xt(t,e={}){return typeof t=="number"||typeof t=="bigint"?Xd(t,e):typeof t=="boolean"?Yd(t,e):Ae(t)?Ie(t,e):dt(t,e)}function Yd(t,e={}){const n=new Uint8Array(1);return n[0]=Number(t),typeof e.size=="number"?(Me(n,{size:e.size}),Ge(n,{size:e.size})):n}const $e={zero:48,nine:57,A:65,F:70,a:97,f:102};function Xs(t){if(t>=$e.zero&&t<=$e.nine)return t-$e.zero;if(t>=$e.A&&t<=$e.F)return t-($e.A-10);if(t>=$e.a&&t<=$e.f)return t-($e.a-10)}function Ie(t,e={}){let n=t;e.size&&(Me(n,{size:e.size}),n=Ge(n,{dir:"right",size:e.size}));let a=n.slice(2);a.length%2&&(a=`0${a}`);const r=a.length/2,s=new Uint8Array(r);for(let i=0,o=0;i<r;i++){const u=Xs(a.charCodeAt(o++)),c=Xs(a.charCodeAt(o++));if(u===void 0||c===void 0)throw new E(`Invalid byte sequence ("${a[o-2]}${a[o-1]}" in "${a}").`);s[i]=u*16+c}return s}function Xd(t,e){const n=k(t,e);return Ie(n)}function dt(t,e={}){const n=Kd.encode(t);return typeof e.size=="number"?(Me(n,{size:e.size}),Ge(n,{dir:"right",size:e.size})):n}function pa(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Qd(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function kn(t,...e){if(!Qd(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function ep(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");pa(t.outputLen),pa(t.blockLen)}function jt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function _o(t,e){kn(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}const Jn=BigInt(2**32-1),Qs=BigInt(32);function tp(t,e=!1){return e?{h:Number(t&Jn),l:Number(t>>Qs&Jn)}:{h:Number(t>>Qs&Jn)|0,l:Number(t&Jn)|0}}function np(t,e=!1){let n=new Uint32Array(t.length),a=new Uint32Array(t.length);for(let r=0;r<t.length;r++){const{h:s,l:i}=tp(t[r],e);[n[r],a[r]]=[s,i]}return[n,a]}const ap=(t,e,n)=>t<<n|e>>>32-n,rp=(t,e,n)=>e<<n|t>>>32-n,sp=(t,e,n)=>e<<n-32|t>>>64-n,ip=(t,e,n)=>t<<n-32|e>>>64-n,Nt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function op(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Ga(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Pe(t,e){return t<<32-e|t>>>e}const ei=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function up(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function ti(t){for(let e=0;e<t.length;e++)t[e]=up(t[e])}function cp(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function wa(t){return typeof t=="string"&&(t=cp(t)),kn(t),t}function dp(...t){let e=0;for(let a=0;a<t.length;a++){const r=t[a];kn(r),e+=r.length}const n=new Uint8Array(e);for(let a=0,r=0;a<t.length;a++){const s=t[a];n.set(s,r),r+=s.length}return n}class is{clone(){return this._cloneInto()}}function Ao(t){const e=a=>t().update(wa(a)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function pp(t=32){if(Nt&&typeof Nt.getRandomValues=="function")return Nt.getRandomValues(new Uint8Array(t));if(Nt&&typeof Nt.randomBytes=="function")return Nt.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}const Io=[],Mo=[],So=[],lp=BigInt(0),pn=BigInt(1),yp=BigInt(2),mp=BigInt(7),fp=BigInt(256),hp=BigInt(113);for(let t=0,e=pn,n=1,a=0;t<24;t++){[n,a]=[a,(2*n+3*a)%5],Io.push(2*(5*a+n)),Mo.push((t+1)*(t+2)/2%64);let r=lp;for(let s=0;s<7;s++)e=(e<<pn^(e>>mp)*hp)%fp,e&yp&&(r^=pn<<(pn<<BigInt(s))-pn);So.push(r)}const[bp,wp]=np(So,!0),ni=(t,e,n)=>n>32?sp(t,e,n):ap(t,e,n),ai=(t,e,n)=>n>32?ip(t,e,n):rp(t,e,n);function gp(t,e=24){const n=new Uint32Array(10);for(let a=24-e;a<24;a++){for(let i=0;i<10;i++)n[i]=t[i]^t[i+10]^t[i+20]^t[i+30]^t[i+40];for(let i=0;i<10;i+=2){const o=(i+8)%10,u=(i+2)%10,c=n[u],d=n[u+1],p=ni(c,d,1)^n[o],l=ai(c,d,1)^n[o+1];for(let y=0;y<50;y+=10)t[i+y]^=p,t[i+y+1]^=l}let r=t[2],s=t[3];for(let i=0;i<24;i++){const o=Mo[i],u=ni(r,s,o),c=ai(r,s,o),d=Io[i];r=t[d],s=t[d+1],t[d]=u,t[d+1]=c}for(let i=0;i<50;i+=10){for(let o=0;o<10;o++)n[o]=t[i+o];for(let o=0;o<10;o++)t[i+o]^=~n[(o+2)%10]&n[(o+4)%10]}t[0]^=bp[a],t[1]^=wp[a]}n.fill(0)}class os extends is{constructor(e,n,a,r=!1,s=24){if(super(),this.blockLen=e,this.suffix=n,this.outputLen=a,this.enableXOF=r,this.rounds=s,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,pa(a),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=op(this.state)}keccak(){ei||ti(this.state32),gp(this.state32,this.rounds),ei||ti(this.state32),this.posOut=0,this.pos=0}update(e){jt(this);const{blockLen:n,state:a}=this;e=wa(e);const r=e.length;for(let s=0;s<r;){const i=Math.min(n-this.pos,r-s);for(let o=0;o<i;o++)a[this.pos++]^=e[s++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:n,pos:a,blockLen:r}=this;e[a]^=n,n&128&&a===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){jt(this,!1),kn(e),this.finish();const n=this.state,{blockLen:a}=this;for(let r=0,s=e.length;r<s;){this.posOut>=a&&this.keccak();const i=Math.min(a-this.posOut,s-r);e.set(n.subarray(this.posOut,this.posOut+i),r),this.posOut+=i,r+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return pa(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(_o(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,this.state.fill(0)}_cloneInto(e){const{blockLen:n,suffix:a,outputLen:r,rounds:s,enableXOF:i}=this;return e||(e=new os(n,a,r,i,s)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=s,e.suffix=a,e.outputLen=r,e.enableXOF=i,e.destroyed=this.destroyed,e}}const Tp=(t,e,n)=>Ao(()=>new os(e,t,n)),Co=Tp(1,136,256/8);function ie(t,e){const n=e||"hex",a=Co(Ae(t,{strict:!1})?Xt(t):t);return n==="bytes"?a:pe(a)}const xp=t=>ie(Xt(t));function vp(t){return xp(t)}function Ep(t){let e=!0,n="",a=0,r="",s=!1;for(let i=0;i<t.length;i++){const o=t[i];if(["(",")",","].includes(o)&&(e=!0),o==="("&&a++,o===")"&&a--,!!e){if(a===0){if(o===" "&&["event","function",""].includes(r))r="";else if(r+=o,o===")"){s=!0;break}continue}if(o===" "){t[i-1]!==","&&n!==","&&n!==",("&&(n="",e=!1);continue}r+=o,n+=o}}if(!s)throw new E("Unable to normalize signature.");return r}const _p=t=>{const e=typeof t=="string"?t:ca(t);return Ep(e)};function Po(t){return vp(_p(t))}const ga=Po;let Ze=class extends E{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"})}},Ta=class extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const n=super.get(e);return super.has(e)&&n!==void 0&&(this.delete(e),super.set(e,n)),n}set(e,n){if(super.set(e,n),this.maxSize&&this.size>this.maxSize){const a=this.keys().next().value;a&&this.delete(a)}return this}};const Wa=new Ta(8192);function Fn(t,e){if(Wa.has(`${t}.${e}`))return Wa.get(`${t}.${e}`);const n=t.substring(2).toLowerCase(),a=ie(dt(n),"bytes"),r=n.split("");for(let i=0;i<40;i+=2)a[i>>1]>>4>=8&&r[i]&&(r[i]=r[i].toUpperCase()),(a[i>>1]&15)>=8&&r[i+1]&&(r[i+1]=r[i+1].toUpperCase());const s=`0x${r.join("")}`;return Wa.set(`${t}.${e}`,s),s}function Ro(t,e){if(!Te(t,{strict:!1}))throw new Ze({address:t});return Fn(t,e)}const Ap=/^0x[a-fA-F0-9]{40}$/,Va=new Ta(8192);function Te(t,e){const{strict:n=!0}=e??{},a=`${t}.${n}`;if(Va.has(a))return Va.get(a);const r=Ap.test(t)?t.toLowerCase()===t?!0:n?Fn(t)===t:!0:!1;return Va.set(a,r),r}function Fe(t){return typeof t[0]=="string"?_t(t):Ip(t)}function Ip(t){let e=0;for(const r of t)e+=r.length;const n=new Uint8Array(e);let a=0;for(const r of t)n.set(r,a),a+=r.length;return n}function _t(t){return`0x${t.reduce((e,n)=>e+n.replace("0x",""),"")}`}function Gt(t,e,n,{strict:a}={}){return Ae(t,{strict:!1})?Fo(t,e,n,{strict:a}):ko(t,e,n,{strict:a})}function No(t,e){if(typeof e=="number"&&e>0&&e>Q(t)-1)throw new xo({offset:e,position:"start",size:Q(t)})}function Bo(t,e,n){if(typeof e=="number"&&typeof n=="number"&&Q(t)!==n-e)throw new xo({offset:n,position:"end",size:Q(t)})}function ko(t,e,n,{strict:a}={}){No(t,e);const r=t.slice(e,n);return a&&Bo(r,e,n),r}function Fo(t,e,n,{strict:a}={}){No(t,e);const r=`0x${t.replace("0x","").slice((e??0)*2,(n??t.length)*2)}`;return a&&Bo(r,e,n),r}const Mp=/^(.*)\[([0-9]*)\]$/,Do=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,us=/^(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 At(t,e){if(t.length!==e.length)throw new bo({expectedLength:t.length,givenLength:e.length});const n=Sp({params:t,values:e}),a=ds(n);return a.length===0?"0x":a}function Sp({params:t,values:e}){const n=[];for(let a=0;a<t.length;a++)n.push(cs({param:t[a],value:e[a]}));return n}function cs({param:t,value:e}){const n=ps(t.type);if(n){const[a,r]=n;return Pp(e,{length:a,param:{...t,type:r}})}if(t.type==="tuple")return Fp(e,{param:t});if(t.type==="address")return Cp(e);if(t.type==="bool")return Np(e);if(t.type.startsWith("uint")||t.type.startsWith("int")){const a=t.type.startsWith("int"),[,,r="256"]=us.exec(t.type)??[];return Bp(e,{signed:a,size:Number(r)})}if(t.type.startsWith("bytes"))return Rp(e,{param:t});if(t.type==="string")return kp(e);throw new Od(t.type,{docsPath:"/docs/contract/encodeAbiParameters"})}function ds(t){let e=0;for(let s=0;s<t.length;s++){const{dynamic:i,encoded:o}=t[s];i?e+=32:e+=Q(o)}const n=[],a=[];let r=0;for(let s=0;s<t.length;s++){const{dynamic:i,encoded:o}=t[s];i?(n.push(k(e+r,{size:32})),a.push(o),r+=Q(o)):n.push(o)}return Fe([...n,...a])}function Cp(t){if(!Te(t))throw new Ze({address:t});return{dynamic:!1,encoded:tt(t.toLowerCase())}}function Pp(t,{length:e,param:n}){const a=e===null;if(!Array.isArray(t))throw new Ud(t);if(!a&&t.length!==e)throw new Rd({expectedLength:e,givenLength:t.length,type:`${n.type}[${e}]`});let r=!1;const s=[];for(let i=0;i<t.length;i++){const o=cs({param:n,value:t[i]});o.dynamic&&(r=!0),s.push(o)}if(a||r){const i=ds(s);if(a){const o=k(s.length,{size:32});return{dynamic:!0,encoded:s.length>0?Fe([o,i]):o}}if(r)return{dynamic:!0,encoded:i}}return{dynamic:!1,encoded:Fe(s.map(({encoded:i})=>i))}}function Rp(t,{param:e}){const[,n]=e.type.split("bytes"),a=Q(t);if(!n){let r=t;return a%32!==0&&(r=tt(r,{dir:"right",size:Math.ceil((t.length-2)/2/32)*32})),{dynamic:!0,encoded:Fe([tt(k(a,{size:32})),r])}}if(a!==Number.parseInt(n))throw new Nd({expectedSize:Number.parseInt(n),value:t});return{dynamic:!1,encoded:tt(t,{dir:"right"})}}function Np(t){if(typeof t!="boolean")throw new E(`Invalid boolean value: "${t}" (type: ${typeof t}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:tt(ss(t))}}function Bp(t,{signed:e,size:n=256}){if(typeof n=="number"){const a=2n**(BigInt(n)-(e?1n:0n))-1n,r=e?-a-1n:0n;if(t>a||t<r)throw new Eo({max:a.toString(),min:r.toString(),signed:e,size:n/8,value:t.toString()})}return{dynamic:!1,encoded:k(t,{size:32,signed:e})}}function kp(t){const e=ht(t),n=Math.ceil(Q(e)/32),a=[];for(let r=0;r<n;r++)a.push(tt(Gt(e,r*32,(r+1)*32),{dir:"right"}));return{dynamic:!0,encoded:Fe([tt(k(Q(e),{size:32})),...a])}}function Fp(t,{param:e}){let n=!1;const a=[];for(let r=0;r<e.components.length;r++){const s=e.components[r],i=Array.isArray(t)?r:s.name,o=cs({param:s,value:t[i]});a.push(o),o.dynamic&&(n=!0)}return{dynamic:n,encoded:n?ds(a):Fe(a.map(({encoded:r})=>r))}}function ps(t){const e=t.match(/^(.*)\[(\d+)?\]$/);return e?[e[2]?Number(e[2]):null,e[1]]:void 0}const xa=t=>Gt(Po(t),0,4);function Dn(t){const{abi:e,args:n=[],name:a}=t,r=Ae(a,{strict:!1}),s=e.filter(o=>r?o.type==="function"?xa(o)===a:o.type==="event"?ga(o)===a:!1:"name"in o&&o.name===a);if(s.length===0)return;if(s.length===1)return s[0];let i;for(const o of s){if(!("inputs"in o))continue;if(!n||n.length===0){if(!o.inputs||o.inputs.length===0)return o;continue}if(!o.inputs||o.inputs.length===0||o.inputs.length!==n.length)continue;if(n.every((c,d)=>{const p="inputs"in o&&o.inputs[d];return p?Tr(c,p):!1})){if(i&&"inputs"in i&&i.inputs){const c=Oo(o.inputs,i.inputs,n);if(c)throw new Dd({abiItem:o,type:c[0]},{abiItem:i,type:c[1]})}i=o}}return i||s[0]}function Tr(t,e){const n=typeof t,a=e.type;switch(a){case"address":return Te(t,{strict:!1});case"bool":return n==="boolean";case"function":return n==="string";case"string":return n==="string";default:return a==="tuple"&&"components"in e?Object.values(e.components).every((r,s)=>Tr(Object.values(t)[s],r)):/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/.test(a)?n==="number"||n==="bigint":/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(a)?n==="string"||t instanceof Uint8Array:/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(a)?Array.isArray(t)&&t.every(r=>Tr(r,{...e,type:a.replace(/(\[[0-9]{0,}\])$/,"")})):!1}}function Oo(t,e,n){for(const a in t){const r=t[a],s=e[a];if(r.type==="tuple"&&s.type==="tuple"&&"components"in r&&"components"in s)return Oo(r.components,s.components,n[a]);const i=[r.type,s.type];if(i.includes("address")&&i.includes("bytes20")?!0:i.includes("address")&&i.includes("string")?Te(n[a],{strict:!1}):i.includes("address")&&i.includes("bytes")?Te(n[a],{strict:!1}):!1)return i}}const ri="/docs/contract/encodeEventTopics";function On(t){var u;const{abi:e,eventName:n,args:a}=t;let r=e[0];if(n){const c=Dn({abi:e,name:n});if(!c)throw new Ks(n,{docsPath:ri});r=c}if(r.type!=="event")throw new Ks(void 0,{docsPath:ri});const s=Be(r),i=ga(s);let o=[];if(a&&"inputs"in r){const c=(u=r.inputs)==null?void 0:u.filter(p=>"indexed"in p&&p.indexed),d=Array.isArray(a)?a:Object.values(a).length>0?(c==null?void 0:c.map(p=>a[p.name]))??[]:[];d.length>0&&(o=(c==null?void 0:c.map((p,l)=>Array.isArray(d[l])?d[l].map((y,f)=>si({param:p,value:d[l][f]})):typeof d[l]<"u"&&d[l]!==null?si({param:p,value:d[l]}):null))??[])}return[i,...o]}function si({param:t,value:e}){if(t.type==="string"||t.type==="bytes")return ie(Xt(e));if(t.type==="tuple"||t.type.match(/^(.*)\[(\d+)?\]$/))throw new qd(t.type);return At([t],[e])}function va(t,{method:e}){var a,r;const n={};return t.transport.type==="fallback"&&((r=(a=t.transport).onResponse)==null||r.call(a,({method:s,response:i,status:o,transport:u})=>{o==="success"&&e===s&&(n[i]=u.request)})),s=>n[s]||t.request}async function $o(t,e){const{address:n,abi:a,args:r,eventName:s,fromBlock:i,strict:o,toBlock:u}=e,c=va(t,{method:"eth_newFilter"}),d=s?On({abi:a,args:r,eventName:s}):void 0,p=await t.request({method:"eth_newFilter",params:[{address:n,fromBlock:typeof i=="bigint"?k(i):i,toBlock:typeof u=="bigint"?k(u):u,topics:d}]});return{abi:a,args:r,eventName:s,id:p,request:c(p),strict:!!o,type:"event"}}function ae(t){return typeof t=="string"?{address:t,type:"json-rpc"}:t}const ii="/docs/contract/encodeFunctionData";function Dp(t){const{abi:e,args:n,functionName:a}=t;let r=e[0];if(a){const s=Dn({abi:e,args:n,name:a});if(!s)throw new da(a,{docsPath:ii});r=s}if(r.type!=="function")throw new da(void 0,{docsPath:ii});return{abi:[r],functionName:xa(Be(r))}}function ve(t){const{args:e}=t,{abi:n,functionName:a}=(()=>{var o;return t.abi.length===1&&((o=t.functionName)!=null&&o.startsWith("0x"))?t:Dp(t)})(),r=n[0],s=a,i="inputs"in r&&r.inputs?At(r.inputs,e??[]):void 0;return _t([s,i??"0x"])}const Uo={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."},Op={inputs:[{name:"message",type:"string"}],name:"Error",type:"error"},$p={inputs:[{name:"reason",type:"uint256"}],name:"Panic",type:"error"};class oi extends E{constructor({offset:e}){super(`Offset \`${e}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class zo extends E{constructor({length:e,position:n}){super(`Position \`${n}\` is out of bounds (\`0 < position < ${e}\`).`,{name:"PositionOutOfBoundsError"})}}class Up extends E{constructor({count:e,limit:n}){super(`Recursive read limit of \`${n}\` exceeded (recursive read count: \`${e}\`).`,{name:"RecursiveReadLimitExceededError"})}}const zp={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 Up({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(t){if(t<0||t>this.bytes.length-1)throw new zo({length:this.bytes.length,position:t})},decrementPosition(t){if(t<0)throw new oi({offset:t});const e=this.position-t;this.assertPosition(e),this.position=e},getReadCount(t){return this.positionReadCount.get(t||this.position)||0},incrementPosition(t){if(t<0)throw new oi({offset:t});const e=this.position+t;this.assertPosition(e),this.position=e},inspectByte(t){const e=t??this.position;return this.assertPosition(e),this.bytes[e]},inspectBytes(t,e){const n=e??this.position;return this.assertPosition(n+t-1),this.bytes.subarray(n,n+t)},inspectUint8(t){const e=t??this.position;return this.assertPosition(e),this.bytes[e]},inspectUint16(t){const e=t??this.position;return this.assertPosition(e+1),this.dataView.getUint16(e)},inspectUint24(t){const e=t??this.position;return this.assertPosition(e+2),(this.dataView.getUint16(e)<<8)+this.dataView.getUint8(e+2)},inspectUint32(t){const e=t??this.position;return this.assertPosition(e+3),this.dataView.getUint32(e)},pushByte(t){this.assertPosition(this.position),this.bytes[this.position]=t,this.position++},pushBytes(t){this.assertPosition(this.position+t.length-1),this.bytes.set(t,this.position),this.position+=t.length},pushUint8(t){this.assertPosition(this.position),this.bytes[this.position]=t,this.position++},pushUint16(t){this.assertPosition(this.position+1),this.dataView.setUint16(this.position,t),this.position+=2},pushUint24(t){this.assertPosition(this.position+2),this.dataView.setUint16(this.position,t>>8),this.dataView.setUint8(this.position+2,t&255),this.position+=3},pushUint32(t){this.assertPosition(this.position+3),this.dataView.setUint32(this.position,t),this.position+=4},readByte(){this.assertReadLimit(),this._touch();const t=this.inspectByte();return this.position++,t},readBytes(t,e){this.assertReadLimit(),this._touch();const n=this.inspectBytes(t);return this.position+=e??t,n},readUint8(){this.assertReadLimit(),this._touch();const t=this.inspectUint8();return this.position+=1,t},readUint16(){this.assertReadLimit(),this._touch();const t=this.inspectUint16();return this.position+=2,t},readUint24(){this.assertReadLimit(),this._touch();const t=this.inspectUint24();return this.position+=3,t},readUint32(){this.assertReadLimit(),this._touch();const t=this.inspectUint32();return this.position+=4,t},get remaining(){return this.bytes.length-this.position},setPosition(t){const e=this.position;return this.assertPosition(t),this.position=t,()=>this.position=e},_touch(){if(this.recursiveReadLimit===Number.POSITIVE_INFINITY)return;const t=this.getReadCount();this.positionReadCount.set(this.position,t+1),t>0&&this.recursiveReadCount++}};function ls(t,{recursiveReadLimit:e=8192}={}){const n=Object.create(zp);return n.bytes=t,n.dataView=new DataView(t.buffer,t.byteOffset,t.byteLength),n.positionReadCount=new Map,n.recursiveReadLimit=e,n}function Lp(t,e={}){typeof e.size<"u"&&Me(t,{size:e.size});const n=ne(t,e);return ke(n,e)}function qp(t,e={}){let n=t;if(typeof e.size<"u"&&(Me(n,{size:e.size}),n=ct(n)),n.length>1||n[0]>1)throw new jd(n);return!!n[0]}function We(t,e={}){typeof e.size<"u"&&Me(t,{size:e.size});const n=ne(t,e);return Ve(n,e)}function Hp(t,e={}){let n=t;return typeof e.size<"u"&&(Me(n,{size:e.size}),n=ct(n,{dir:"right"})),new TextDecoder().decode(n)}function $n(t,e){const n=typeof e=="string"?Ie(e):e,a=ls(n);if(Q(n)===0&&t.length>0)throw new Bn;if(Q(e)&&Q(e)<32)throw new ho({data:typeof e=="string"?e:ne(e),params:t,size:Q(e)});let r=0;const s=[];for(let i=0;i<t.length;++i){const o=t[i];a.setPosition(r);const[u,c]=$t(a,o,{staticPosition:0});r+=c,s.push(u)}return s}function $t(t,e,{staticPosition:n}){const a=ps(e.type);if(a){const[r,s]=a;return Gp(t,{...e,type:s},{length:r,staticPosition:n})}if(e.type==="tuple")return Jp(t,e,{staticPosition:n});if(e.type==="address")return jp(t);if(e.type==="bool")return Wp(t);if(e.type.startsWith("bytes"))return Vp(t,e,{staticPosition:n});if(e.type.startsWith("uint")||e.type.startsWith("int"))return Zp(t,e);if(e.type==="string")return Kp(t,{staticPosition:n});throw new $d(e.type,{docsPath:"/docs/contract/decodeAbiParameters"})}const ui=32,xr=32;function jp(t){const e=t.readBytes(32);return[Fn(ne(ko(e,-20))),32]}function Gp(t,e,{length:n,staticPosition:a}){if(!n){const i=We(t.readBytes(xr)),o=a+i,u=o+ui;t.setPosition(o);const c=We(t.readBytes(ui)),d=fn(e);let p=0;const l=[];for(let y=0;y<c;++y){t.setPosition(u+(d?y*32:p));const[f,h]=$t(t,e,{staticPosition:u});p+=h,l.push(f)}return t.setPosition(a+32),[l,32]}if(fn(e)){const i=We(t.readBytes(xr)),o=a+i,u=[];for(let c=0;c<n;++c){t.setPosition(o+c*32);const[d]=$t(t,e,{staticPosition:o});u.push(d)}return t.setPosition(a+32),[u,32]}let r=0;const s=[];for(let i=0;i<n;++i){const[o,u]=$t(t,e,{staticPosition:a+r});r+=u,s.push(o)}return[s,r]}function Wp(t){return[qp(t.readBytes(32),{size:32}),32]}function Vp(t,e,{staticPosition:n}){const[a,r]=e.type.split("bytes");if(!r){const i=We(t.readBytes(32));t.setPosition(n+i);const o=We(t.readBytes(32));if(o===0)return t.setPosition(n+32),["0x",32];const u=t.readBytes(o);return t.setPosition(n+32),[ne(u),32]}return[ne(t.readBytes(Number.parseInt(r),32)),32]}function Zp(t,e){const n=e.type.startsWith("int"),a=Number.parseInt(e.type.split("int")[1]||"256"),r=t.readBytes(32);return[a>48?Lp(r,{signed:n}):We(r,{signed:n}),32]}function Jp(t,e,{staticPosition:n}){const a=e.components.length===0||e.components.some(({name:i})=>!i),r=a?[]:{};let s=0;if(fn(e)){const i=We(t.readBytes(xr)),o=n+i;for(let u=0;u<e.components.length;++u){const c=e.components[u];t.setPosition(o+s);const[d,p]=$t(t,c,{staticPosition:o});s+=p,r[a?u:c==null?void 0:c.name]=d}return t.setPosition(n+32),[r,32]}for(let i=0;i<e.components.length;++i){const o=e.components[i],[u,c]=$t(t,o,{staticPosition:n});r[a?i:o==null?void 0:o.name]=u,s+=c}return[r,s]}function Kp(t,{staticPosition:e}){const n=We(t.readBytes(32)),a=e+n;t.setPosition(a)