UNPKG

@midcontract/protocol

Version:

Crypto payment protocol with escrow

28 lines 420 kB
"use strict";var Vi=Object.defineProperty;var Zi=(t,e,n)=>e in t?Vi(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var $=(t,e,n)=>Zi(t,typeof e!="symbol"?e+"":e,n);const Ji="1.0.5";let de=class sa extends Error{constructor(e,n={}){var i;const a=n.cause instanceof sa?n.cause.details:(i=n.cause)!=null&&i.message?n.cause.message:n.details,r=n.cause instanceof sa&&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@${Ji}`].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 He(t,e){const n=t.exec(e);return n==null?void 0:n.groups}const es=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,ts=/^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)?$/,ns=/^\(.+?\).*?$/,fr=/^tuple(?<array>(\[(\d*)\])*)$/;function ia(t){let e=t.type;if(fr.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+=ia(s),r<n-1&&(e+=", ")}const a=He(fr,t.type);return e+=`)${(a==null?void 0:a.array)??""}`,ia({...t,type:e})}return"indexed"in t&&t.indexed&&(e=`${e} indexed`),t.name?`${e} ${t.name}`:e}function Pt(t){let e="";const n=t.length;for(let a=0;a<n;a++){const r=t[a];e+=ia(r),a!==n-1&&(e+=", ")}return e}function Yi(t){return t.type==="function"?`function ${t.name}(${Pt(t.inputs)})${t.stateMutability&&t.stateMutability!=="nonpayable"?` ${t.stateMutability}`:""}${t.outputs.length?` returns (${Pt(t.outputs)})`:""}`:t.type==="event"?`event ${t.name}(${Pt(t.inputs)})`:t.type==="error"?`error ${t.name}(${Pt(t.inputs)})`:t.type==="constructor"?`constructor(${Pt(t.inputs)})${t.stateMutability==="payable"?" payable":""}`:t.type==="fallback"?"fallback()":"receive() external payable"}const as=/^error (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;function Ki(t){return as.test(t)}function Xi(t){return He(as,t)}const rs=/^event (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;function Qi(t){return rs.test(t)}function eo(t){return He(rs,t)}const ss=/^function (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)(?: (?<scope>external|public{1}))?(?: (?<stateMutability>pure|view|nonpayable|payable{1}))?(?: returns\s?\((?<returns>.*?)\))?$/;function to(t){return ss.test(t)}function no(t){return He(ss,t)}const is=/^struct (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) \{(?<properties>.*?)\}$/;function os(t){return is.test(t)}function ao(t){return He(is,t)}const us=/^constructor\((?<parameters>.*?)\)(?:\s(?<stateMutability>payable{1}))?$/;function ro(t){return us.test(t)}function so(t){return He(us,t)}const io=/^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/;function oo(t){return io.test(t)}const uo=/^receive\(\) external payable$/;function po(t){return uo.test(t)}const co=new Set(["indexed"]),oa=new Set(["calldata","memory","storage"]);class yo extends de{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 lo extends de{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 mo extends de{constructor({param:e}){super("Invalid ABI parameter.",{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParameterError"})}}class fo extends de{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 bo extends de{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 ho extends de{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 wo extends de{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 Rt extends de{constructor({signature:e,type:n}){super(`Invalid ${n} signature.`,{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidSignatureError"})}}class go extends de{constructor({signature:e}){super("Unknown signature.",{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSignatureError"})}}class To extends de{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 vo extends de{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 xo extends de{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 _o(t,e){return e?`${e}:${t}`:t}const Hn=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 Eo(t,e={}){if(to(t)){const n=no(t);if(!n)throw new Rt({signature:t,type:"function"});const a=me(n.parameters),r=[],s=a.length;for(let o=0;o<s;o++)r.push(je(a[o],{modifiers:oa,structs:e,type:"function"}));const i=[];if(n.returns){const o=me(n.returns),u=o.length;for(let p=0;p<u;p++)i.push(je(o[p],{modifiers:oa,structs:e,type:"function"}))}return{name:n.name,type:"function",stateMutability:n.stateMutability??"nonpayable",inputs:r,outputs:i}}if(Qi(t)){const n=eo(t);if(!n)throw new Rt({signature:t,type:"event"});const a=me(n.parameters),r=[],s=a.length;for(let i=0;i<s;i++)r.push(je(a[i],{modifiers:co,structs:e,type:"event"}));return{name:n.name,type:"event",inputs:r}}if(Ki(t)){const n=Xi(t);if(!n)throw new Rt({signature:t,type:"error"});const a=me(n.parameters),r=[],s=a.length;for(let i=0;i<s;i++)r.push(je(a[i],{structs:e,type:"error"}));return{name:n.name,type:"error",inputs:r}}if(ro(t)){const n=so(t);if(!n)throw new Rt({signature:t,type:"constructor"});const a=me(n.parameters),r=[],s=a.length;for(let i=0;i<s;i++)r.push(je(a[i],{structs:e,type:"constructor"}));return{type:"constructor",stateMutability:n.stateMutability??"nonpayable",inputs:r}}if(oo(t))return{type:"fallback"};if(po(t))return{type:"receive",stateMutability:"payable"};throw new go({signature:t})}const Ao=/^(?<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$_]*))?$/,Io=/^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,Mo=/^u?int$/;function je(t,e){var c,y;const n=_o(t,e==null?void 0:e.type);if(Hn.has(n))return Hn.get(n);const a=ns.test(t),r=He(a?Io:Ao,t);if(!r)throw new mo({param:t});if(r.name&&Po(r.name))throw new fo({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,p={};if(a){u="tuple";const m=me(r.type),f=[],l=m.length;for(let b=0;b<l;b++)f.push(je(m[b],{structs:o}));p={components:f}}else if(r.type in o)u="tuple",p={components:o[r.type]};else if(Mo.test(r.type))u=`${r.type}256`;else if(u=r.type,(e==null?void 0:e.type)!=="struct"&&!ps(u))throw new lo({type:u});if(r.modifier){if(!((y=(c=e==null?void 0:e.modifiers)==null?void 0:c.has)!=null&&y.call(c,r.modifier)))throw new bo({param:t,type:e==null?void 0:e.type,modifier:r.modifier});if(oa.has(r.modifier)&&!So(u,!!r.array))throw new ho({param:t,type:e==null?void 0:e.type,modifier:r.modifier})}const d={type:`${u}${r.array??""}`,...s,...i,...p};return Hn.set(n,d),d}function me(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?me(o,[...e,n.trim()]):me(o,e,`${n}${i}`,a);case"(":return me(o,e,`${n}${i}`,a+1);case")":return me(o,e,`${n}${i}`,a-1);default:return me(o,e,`${n}${i}`,a)}}if(n==="")return e;if(a!==0)throw new xo({current:n,depth:a});return e.push(n.trim()),e}function ps(t){return t==="address"||t==="bool"||t==="function"||t==="string"||es.test(t)||ts.test(t)}const Co=/^(?: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 Po(t){return t==="address"||t==="bool"||t==="function"||t==="string"||t==="tuple"||es.test(t)||ts.test(t)||Co.test(t)}function So(t,e){return e||t==="bytes"||t==="string"||t==="tuple"}function No(t){const e={},n=t.length;for(let i=0;i<n;i++){const o=t[i];if(!os(o))continue;const u=ao(o);if(!u)throw new Rt({signature:o,type:"struct"});const p=u.properties.split(";"),d=[],c=p.length;for(let y=0;y<c;y++){const f=p[y].trim();if(!f)continue;const l=je(f,{type:"struct"});d.push(l)}if(!d.length)throw new To({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]=ds(u,e)}return a}const Ro=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?$/;function ds(t,e,n=new Set){const a=[],r=t.length;for(let s=0;s<r;s++){const i=t[s];if(ns.test(i.type))a.push(i);else{const u=He(Ro,i.type);if(!(u!=null&&u.type))throw new wo({abiParameter:i});const{array:p,type:d}=u;if(d in e){if(n.has(d))throw new vo({type:d});a.push({...i,type:`tuple${p??""}`,components:ds(e[d]??[],e,new Set([...n,d]))})}else if(ps(d))a.push(i);else throw new yo({type:d})}}return a}function cs(t){const e=No(t),n=[],a=t.length;for(let r=0;r<a;r++){const s=t[r];os(s)||n.push(Eo(s,e))}return n}function R(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 he(t,{includeName:e=!1}={}){if(t.type!=="function"&&t.type!=="event"&&t.type!=="error")throw new Go(t.type);return`${t.name}(${En(t.inputs,{includeName:e})})`}function En(t,{includeName:e=!1}={}){return t?t.map(n=>ko(n,{includeName:e})).join(e?", ":","):""}function ko(t,{includeName:e}){return t.type.startsWith("tuple")?`(${En(t.components,{includeName:e})})${t.type.slice(5)}`:t.type+(e&&t.name?` ${t.name}`:"")}function se(t,{strict:e=!0}={}){return!t||typeof t!="string"?!1:e?/^0x[0-9a-fA-F]*$/.test(t):t.startsWith("0x")}function V(t){return se(t,{strict:!1})?Math.ceil((t.length-2)/2):t.length}const ys="2.20.0";let cn={getDocsUrl:({docsBaseUrl:t,docsPath:e="",docsSlug:n})=>e?`${t??"https://viem.sh"}${e}${n?`#${n}`:""}`:void 0,version:ys};class g extends Error{constructor(e,n={}){var o;const a=(()=>{var u;return n.cause instanceof g?n.cause.details:(u=n.cause)!=null&&u.message?n.cause.message:n.details})(),r=n.cause instanceof g&&n.cause.docsPath||n.docsPath,s=(o=cn.getDocsUrl)==null?void 0:o.call(cn,{...n,docsPath:r}),i=[e||"An error occurred.","",...n.metaMessages?[...n.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...a?[`Details: ${a}`]:[],`Version: ${cn.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=ys}walk(e){return ls(this,e)}}function ls(t,e){return e!=null&&e(t)?t:t&&typeof t=="object"&&"cause"in t?ls(t.cause,e):e?null:t}class Bo extends g{constructor({docsPath:e}){super(["A constructor was not found on the ABI.","Make sure you are using the correct ABI and that the constructor exists on it."].join(` `),{docsPath:e,name:"AbiConstructorNotFoundError"})}}class br extends g{constructor({docsPath:e}){super(["Constructor arguments were provided (`args`), but a constructor parameters (`inputs`) were not found on the ABI.","Make sure you are using the correct ABI, and that the `inputs` attribute on the constructor exists."].join(` `),{docsPath:e,name:"AbiConstructorParamsNotFoundError"})}}class ms extends g{constructor({data:e,params:n,size:a}){super([`Data size of ${a} bytes is too small for given parameters.`].join(` `),{metaMessages:[`Params: (${En(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 An extends g{constructor(){super('Cannot decode zero data ("0x") with ABI parameters.',{name:"AbiDecodingZeroDataError"})}}class Do extends g{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 Fo extends g{constructor({expectedSize:e,value:n}){super(`Size of bytes "${n}" (bytes${V(n)}) does not match expected size (bytes${e}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class fs extends g{constructor({expectedLength:e,givenLength:n}){super(["ABI encoding params/values length mismatch.",`Expected length (params): ${e}`,`Given length (values): ${n}`].join(` `),{name:"AbiEncodingLengthMismatchError"})}}class bs extends g{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 Oo extends g{constructor({docsPath:e}){super("Cannot extract event signature from empty topics.",{docsPath:e,name:"AbiEventSignatureEmptyTopicsError"})}}class hs extends g{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 hr extends g{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 gn extends g{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 $o extends g{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 Uo extends g{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 zo extends g{constructor(e,n){super("Found ambiguous types in overloaded ABI items.",{metaMessages:[`\`${e.type}\` in \`${he(e.abiItem)}\`, and`,`\`${n.type}\` in \`${he(n.abiItem)}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."],name:"AbiItemAmbiguityError"})}}class ws extends g{constructor({expectedSize:e,givenSize:n}){super(`Expected bytes${e}, got bytes${n}.`,{name:"BytesSizeMismatchError"})}}class kt extends g{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: (${En(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 In extends g{constructor({abiItem:e,param:n}){super([`Expected a topic for indexed event parameter${n.name?` "${n.name}"`:""} on event "${he(e,{includeName:!0})}".`].join(` `),{name:"DecodeLogTopicsMismatch"}),Object.defineProperty(this,"abiItem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abiItem=e}}class Lo extends g{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 qo extends g{constructor(e,{docsPath:n}){super([`Type "${e}" is not a valid decoding type.`,"Please provide a valid ABI type."].join(` `),{docsPath:n,name:"InvalidAbiDecodingType"})}}class Ho extends g{constructor(e){super([`Value "${e}" is not a valid array.`].join(` `),{name:"InvalidArrayError"})}}class Go extends g{constructor(e){super([`"${e}" is not a valid definition type.`,'Valid types: "function", "event", "error"'].join(` `),{name:"InvalidDefinitionTypeError"})}}class jo extends g{constructor(e){super(`Type "${e}" is not supported for packed encoding.`,{name:"UnsupportedPackedAbiType"})}}class Wo extends g{constructor(e){super(`Filter type "${e}" is not supported.`,{name:"FilterTypeNotSupportedError"})}}class gs extends g{constructor({offset:e,position:n,size:a}){super(`Slice ${n==="start"?"starting":"ending"} at offset "${e}" is out-of-bounds (size: ${a}).`,{name:"SliceOffsetOutOfBoundsError"})}}class Ts extends g{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 wr extends g{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 Ae(t,{dir:e,size:n=32}={}){return typeof t=="string"?Oe(t,{dir:e,size:n}):Vo(t,{dir:e,size:n})}function Oe(t,{dir:e,size:n=32}={}){if(n===null)return t;const a=t.replace("0x","");if(a.length>n*2)throw new Ts({size:Math.ceil(a.length/2),targetSize:n,type:"hex"});return`0x${a[e==="right"?"padEnd":"padStart"](n*2,"0")}`}function Vo(t,{dir:e,size:n=32}={}){if(n===null)return t;if(t.length>n)throw new Ts({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}class Zo extends g{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 Jo extends g{constructor(e){super(`Bytes value "${e}" is not a valid boolean. The bytes array must contain a single byte of either a 0 or 1 value.`,{name:"InvalidBytesBooleanError"})}}class Yo extends g{constructor({givenSize:e,maxSize:n}){super(`Size cannot exceed ${n} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}}function Mn(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 ge(t,{size:e}){if(V(t)>e)throw new Yo({givenSize:V(t),maxSize:e})}function $e(t,e={}){const{signed:n}=e;e.size&&ge(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 Me(t,e={}){return Number($e(t,e))}const Ko=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function ne(t,e={}){return typeof t=="number"||typeof t=="bigint"?N(t,e):typeof t=="string"?Ke(t,e):typeof t=="boolean"?Ba(t,e):J(t,e)}function Ba(t,e={}){const n=`0x${Number(t)}`;return typeof e.size=="number"?(ge(n,{size:e.size}),Ae(n,{size:e.size})):n}function J(t,e={}){let n="";for(let r=0;r<t.length;r++)n+=Ko[t[r]];const a=`0x${n}`;return typeof e.size=="number"?(ge(a,{size:e.size}),Ae(a,{dir:"right",size:e.size})):a}function N(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 Zo({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?Ae(o,{size:a}):o}const Xo=new TextEncoder;function Ke(t,e={}){const n=Xo.encode(t);return J(n,e)}const Qo=new TextEncoder;function Ue(t,e={}){return typeof t=="number"||typeof t=="bigint"?tu(t,e):typeof t=="boolean"?eu(t,e):se(t)?fe(t,e):Je(t,e)}function eu(t,e={}){const n=new Uint8Array(1);return n[0]=Number(t),typeof e.size=="number"?(ge(n,{size:e.size}),Ae(n,{size:e.size})):n}const Te={zero:48,nine:57,A:65,F:70,a:97,f:102};function gr(t){if(t>=Te.zero&&t<=Te.nine)return t-Te.zero;if(t>=Te.A&&t<=Te.F)return t-(Te.A-10);if(t>=Te.a&&t<=Te.f)return t-(Te.a-10)}function fe(t,e={}){let n=t;e.size&&(ge(n,{size:e.size}),n=Ae(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=gr(a.charCodeAt(o++)),p=gr(a.charCodeAt(o++));if(u===void 0||p===void 0)throw new g(`Invalid byte sequence ("${a[o-2]}${a[o-1]}" in "${a}").`);s[i]=u*16+p}return s}function tu(t,e){const n=N(t,e);return fe(n)}function Je(t,e={}){const n=Qo.encode(t);return typeof e.size=="number"?(ge(n,{size:e.size}),Ae(n,{dir:"right",size:e.size})):n}function Tn(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`positive integer expected, not ${t}`)}function nu(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Kt(t,...e){if(!nu(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}function au(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Tn(t.outputLen),Tn(t.blockLen)}function ft(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 vs(t,e){Kt(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const yn=BigInt(2**32-1),Tr=BigInt(32);function ru(t,e=!1){return e?{h:Number(t&yn),l:Number(t>>Tr&yn)}:{h:Number(t>>Tr&yn)|0,l:Number(t&yn)|0}}function su(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}=ru(t[r],e);[n[r],a[r]]=[s,i]}return[n,a]}const iu=(t,e,n)=>t<<n|e>>>32-n,ou=(t,e,n)=>e<<n|t>>>32-n,uu=(t,e,n)=>e<<n-32|t>>>64-n,pu=(t,e,n)=>t<<n-32|e>>>64-n,Gn=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const du=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4)),jn=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),be=(t,e)=>t<<32-e|t>>>e,vr=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68,cu=t=>t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255;function xr(t){for(let e=0;e<t.length;e++)t[e]=cu(t[e])}function yu(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Cn(t){return typeof t=="string"&&(t=yu(t)),Kt(t),t}function lu(...t){let e=0;for(let a=0;a<t.length;a++){const r=t[a];Kt(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 Da{clone(){return this._cloneInto()}}function xs(t){const e=a=>t().update(Cn(a)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function mu(t=32){if(Gn&&typeof Gn.getRandomValues=="function")return Gn.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}const _s=[],Es=[],As=[],fu=BigInt(0),St=BigInt(1),bu=BigInt(2),hu=BigInt(7),wu=BigInt(256),gu=BigInt(113);for(let t=0,e=St,n=1,a=0;t<24;t++){[n,a]=[a,(2*n+3*a)%5],_s.push(2*(5*a+n)),Es.push((t+1)*(t+2)/2%64);let r=fu;for(let s=0;s<7;s++)e=(e<<St^(e>>hu)*gu)%wu,e&bu&&(r^=St<<(St<<BigInt(s))-St);As.push(r)}const[Tu,vu]=su(As,!0),_r=(t,e,n)=>n>32?uu(t,e,n):iu(t,e,n),Er=(t,e,n)=>n>32?pu(t,e,n):ou(t,e,n);function xu(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,p=n[u],d=n[u+1],c=_r(p,d,1)^n[o],y=Er(p,d,1)^n[o+1];for(let m=0;m<50;m+=10)t[i+m]^=c,t[i+m+1]^=y}let r=t[2],s=t[3];for(let i=0;i<24;i++){const o=Es[i],u=_r(r,s,o),p=Er(r,s,o),d=_s[i];r=t[d],s=t[d+1],t[d]=u,t[d+1]=p}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]^=Tu[a],t[1]^=vu[a]}n.fill(0)}class Fa extends Da{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,Tn(a),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=du(this.state)}keccak(){vr||xr(this.state32),xu(this.state32,this.rounds),vr||xr(this.state32),this.posOut=0,this.pos=0}update(e){ft(this);const{blockLen:n,state:a}=this;e=Cn(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){ft(this,!1),Kt(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 Tn(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(vs(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 Fa(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 _u=(t,e,n)=>xs(()=>new Fa(e,t,n)),Eu=_u(1,136,256/8);function Z(t,e){const n=e||"hex",a=Eu(se(t,{strict:!1})?Ue(t):t);return n==="bytes"?a:ne(a)}const Au=t=>Z(Ue(t));function Iu(t){return Au(t)}function Mu(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 g("Unable to normalize signature.");return r}const Cu=t=>{const e=typeof t=="string"?t:Yi(t);return Mu(e)};function Is(t){return Iu(Cu(t))}const Oa=Is;class Ce extends g{constructor({address:e}){super(`Address "${e}" is invalid.`,{metaMessages:["- Address must be a hex value of 20 bytes (40 hex characters).","- Address must match its checksum counterpart."],name:"InvalidAddressError"})}}class $a extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}set(e,n){return super.set(e,n),this.maxSize&&this.size>this.maxSize&&this.delete(this.keys().next().value),this}}const Wn=new $a(8192);function Xt(t,e){if(Wn.has(`${t}.${e}`))return Wn.get(`${t}.${e}`);const n=t.substring(2).toLowerCase(),a=Z(Je(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 Wn.set(`${t}.${e}`,s),s}function Ms(t,e){if(!pe(t,{strict:!1}))throw new Ce({address:t});return Xt(t,e)}const Pu=/^0x[a-fA-F0-9]{40}$/,Vn=new $a(8192);function pe(t,e){const{strict:n=!0}=e??{},a=`${t}.${n}`;if(Vn.has(a))return Vn.get(a);const r=Pu.test(t)?t.toLowerCase()===t?!0:n?Xt(t)===t:!0:!1;return Vn.set(a,r),r}function we(t){return typeof t[0]=="string"?tt(t):Su(t)}function Su(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 tt(t){return`0x${t.reduce((e,n)=>e+n.replace("0x",""),"")}`}function bt(t,e,n,{strict:a}={}){return se(t,{strict:!1})?Ns(t,e,n,{strict:a}):Ss(t,e,n,{strict:a})}function Cs(t,e){if(typeof e=="number"&&e>0&&e>V(t)-1)throw new gs({offset:e,position:"start",size:V(t)})}function Ps(t,e,n){if(typeof e=="number"&&typeof n=="number"&&V(t)!==n-e)throw new gs({offset:n,position:"end",size:V(t)})}function Ss(t,e,n,{strict:a}={}){Cs(t,e);const r=t.slice(e,n);return a&&Ps(r,e,n),r}function Ns(t,e,n,{strict:a}={}){Cs(t,e);const r=`0x${t.replace("0x","").slice((e??0)*2,(n??t.length)*2)}`;return a&&Ps(r,e,n),r}function nt(t,e){if(t.length!==e.length)throw new fs({expectedLength:t.length,givenLength:e.length});const n=Nu({params:t,values:e}),a=za(n);return a.length===0?"0x":a}function Nu({params:t,values:e}){const n=[];for(let a=0;a<t.length;a++)n.push(Ua({param:t[a],value:e[a]}));return n}function Ua({param:t,value:e}){const n=La(t.type);if(n){const[a,r]=n;return ku(e,{length:a,param:{...t,type:r}})}if(t.type==="tuple")return $u(e,{param:t});if(t.type==="address")return Ru(e);if(t.type==="bool")return Du(e);if(t.type.startsWith("uint")||t.type.startsWith("int")){const a=t.type.startsWith("int");return Fu(e,{signed:a})}if(t.type.startsWith("bytes"))return Bu(e,{param:t});if(t.type==="string")return Ou(e);throw new Lo(t.type,{docsPath:"/docs/contract/encodeAbiParameters"})}function za(t){let e=0;for(let s=0;s<t.length;s++){const{dynamic:i,encoded:o}=t[s];i?e+=32:e+=V(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(N(e+r,{size:32})),a.push(o),r+=V(o)):n.push(o)}return we([...n,...a])}function Ru(t){if(!pe(t))throw new Ce({address:t});return{dynamic:!1,encoded:Oe(t.toLowerCase())}}function ku(t,{length:e,param:n}){const a=e===null;if(!Array.isArray(t))throw new Ho(t);if(!a&&t.length!==e)throw new Do({expectedLength:e,givenLength:t.length,type:`${n.type}[${e}]`});let r=!1;const s=[];for(let i=0;i<t.length;i++){const o=Ua({param:n,value:t[i]});o.dynamic&&(r=!0),s.push(o)}if(a||r){const i=za(s);if(a){const o=N(s.length,{size:32});return{dynamic:!0,encoded:s.length>0?we([o,i]):o}}if(r)return{dynamic:!0,encoded:i}}return{dynamic:!1,encoded:we(s.map(({encoded:i})=>i))}}function Bu(t,{param:e}){const[,n]=e.type.split("bytes"),a=V(t);if(!n){let r=t;return a%32!==0&&(r=Oe(r,{dir:"right",size:Math.ceil((t.length-2)/2/32)*32})),{dynamic:!0,encoded:we([Oe(N(a,{size:32})),r])}}if(a!==Number.parseInt(n))throw new Fo({expectedSize:Number.parseInt(n),value:t});return{dynamic:!1,encoded:Oe(t,{dir:"right"})}}function Du(t){if(typeof t!="boolean")throw new g(`Invalid boolean value: "${t}" (type: ${typeof t}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:Oe(Ba(t))}}function Fu(t,{signed:e}){return{dynamic:!1,encoded:N(t,{size:32,signed:e})}}function Ou(t){const e=Ke(t),n=Math.ceil(V(e)/32),a=[];for(let r=0;r<n;r++)a.push(Oe(bt(e,r*32,(r+1)*32),{dir:"right"}));return{dynamic:!0,encoded:we([Oe(N(V(e),{size:32})),...a])}}function $u(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=Ua({param:s,value:t[i]});a.push(o),o.dynamic&&(n=!0)}return{dynamic:n,encoded:n?za(a):we(a.map(({encoded:r})=>r))}}function La(t){const e=t.match(/^(.*)\[(\d+)?\]$/);return e?[e[2]?Number(e[2]):null,e[1]]:void 0}const Pn=t=>bt(Is(t),0,4);function Et(t){const{abi:e,args:n=[],name:a}=t,r=se(a,{strict:!1}),s=e.filter(o=>r?o.type==="function"?Pn(o)===a:o.type==="event"?Oa(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((p,d)=>{const c="inputs"in o&&o.inputs[d];return c?ua(p,c):!1})){if(i&&"inputs"in i&&i.inputs){const p=Rs(o.inputs,i.inputs,n);if(p)throw new zo({abiItem:o,type:p[0]},{abiItem:i,type:p[1]})}i=o}}return i||s[0]}function ua(t,e){const n=typeof t,a=e.type;switch(a){case"address":return pe(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)=>ua(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=>ua(r,{...e,type:a.replace(/(\[[0-9]{0,}\])$/,"")})):!1}}function Rs(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 Rs(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")?pe(n[a],{strict:!1}):i.includes("address")&&i.includes("bytes")?pe(n[a],{strict:!1}):!1)return i}}const Ar="/docs/contract/encodeEventTopics";function Qt(t){var u;const{abi:e,eventName:n,args:a}=t;let r=e[0];if(n){const p=Et({abi:e,name:n});if(!p)throw new hr(n,{docsPath:Ar});r=p}if(r.type!=="event")throw new hr(void 0,{docsPath:Ar});const s=he(r),i=Oa(s);let o=[];if(a&&"inputs"in r){const p=(u=r.inputs)==null?void 0:u.filter(c=>"indexed"in c&&c.indexed),d=Array.isArray(a)?a:Object.values(a).length>0?(p==null?void 0:p.map(c=>a[c.name]))??[]:[];d.length>0&&(o=(p==null?void 0:p.map((c,y)=>Array.isArray(d[y])?d[y].map((m,f)=>Ir({param:c,value:d[y][f]})):d[y]?Ir({param:c,value:d[y]}):null))??[])}return[i,...o]}function Ir({param:t,value:e}){if(t.type==="string"||t.type==="bytes")return Z(Ue(e));if(t.type==="tuple"||t.type.match(/^(.*)\[(\d+)?\]$/))throw new Wo(t.type);return nt([t],[e])}function Sn(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 ks(t,e){const{address:n,abi:a,args:r,eventName:s,fromBlock:i,strict:o,toBlock:u}=e,p=Sn(t,{method:"eth_newFilter"}),d=s?Qt({abi:a,args:r,eventName:s}):void 0,c=await t.request({method:"eth_newFilter",params:[{address:n,fromBlock:typeof i=="bigint"?N(i):i,toBlock:typeof u=="bigint"?N(u):u,topics:d}]});return{abi:a,args:r,eventName:s,id:c,request:p(c),strict:!!o,type:"event"}}function ie(t){return typeof t=="string"?{address:t,type:"json-rpc"}:t}const Mr="/docs/contract/encodeFunctionData";function Uu(t){const{abi:e,args:n,functionName:a}=t;let r=e[0];if(a){const s=Et({abi:e,args:n,name:a});if(!s)throw new gn(a,{docsPath:Mr});r=s}if(r.type!=="function")throw new gn(void 0,{docsPath:Mr});return{abi:[r],functionName:Pn(he(r))}}function Se(t){const{args:e}=t,{abi:n,functionName:a}=(()=>{var o;return t.abi.length===1&&((o=t.functionName)!=null&&o.startsWith("0x"))?t:Uu(t)})(),r=n[0],s=a,i="inputs"in r&&r.inputs?nt(r.inputs,e??[]):void 0;return tt([s,i??"0x"])}const Bs={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."},zu={inputs:[{name:"message",type:"string"}],name:"Error",type:"error"},Lu={inputs:[{name:"reason",type:"uint256"}],name:"Panic",type:"error"};class Cr extends g{constructor({offset:e}){super(`Offset \`${e}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class Ds extends g{constructor({length:e,position:n}){super(`Position \`${n}\` is out of bounds (\`0 < position < ${e}\`).`,{name:"PositionOutOfBoundsError"})}}class qu extends g{constructor({count:e,limit:n}){super(`Recursive read limit of \`${n}\` exceeded (recursive read count: \`${e}\`).`,{name:"RecursiveReadLimitExceededError"})}}const Hu={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 qu({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(t){if(t<0||t>this.bytes.length-1)throw new Ds({length:this.bytes.length,position:t})},decrementPosition(t){if(t<0)throw new Cr({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 Cr({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 qa(t,{recursiveReadLimit:e=8192}={}){const n=Object.create(Hu);return n.bytes=t,n.dataView=new DataView(t.buffer,t.byteOffset,t.byteLength),n.positionReadCount=new Map,n.recursiveReadLimit=e,n}function Gu(t,e={}){typeof e.size<"u"&&ge(t,{size:e.size});const n=J(t,e);return $e(n,e)}function ju(t,e={}){let n=t;if(typeof e.size<"u"&&(ge(n,{size:e.size}),n=Mn(n)),n.length>1||n[0]>1)throw new Jo(n);return!!n[0]}function Ie(t,e={}){typeof e.size<"u"&&ge(t,{size:e.size});const n=J(t,e);return Me(n,e)}function Wu(t,e={}){let n=t;return typeof e.size<"u"&&(ge(n,{size:e.size}),n=Mn(n,{dir:"right"})),new TextDecoder().decode(n)}function en(t,e){const n=typeof e=="string"?fe(e):e,a=qa(n);if(V(n)===0&&t.length>0)throw new An;if(V(e)&&V(e)<32)throw new ms({data:typeof e=="string"?e:J(e),params:t,size:V(e)});let r=0;const s=[];for(let i=0;i<t.length;++i){const o=t[i];a.setPosition(r);const[u,p]=pt(a,o,{staticPosition:0});r+=p,s.push(u)}return s}function pt(t,e,{staticPosition:n}){const a=La(e.type);if(a){const[r,s]=a;return Zu(t,{...e,type:s},{length:r,staticPosition:n})}if(e.type==="tuple")return Xu(t,e,{staticPosition:n});if(e.type==="address")return Vu(t);if(e.type==="bool")return Ju(t);if(e.type.startsWith("bytes"))return Yu(t,e,{staticPosition:n});if(e.type.startsWith("uint")||e.type.startsWith("int"))return Ku(t,e);if(e.type==="string")return Qu(t,{staticPosition:n});throw new qo(e.type,{docsPath:"/docs/contract/decodeAbiParameters"})}const Pr=32,pa=32;function Vu(t){const e=t.readBytes(32);return[Xt(J(Ss(e,-20))),32]}function Zu(t,e,{length:n,staticPosition:a}){if(!n){const i=Ie(t.readBytes(pa)),o=a+i,u=o+Pr;t.setPosition(o);const p=Ie(t.readBytes(Pr)),d=Bt(e);let c=0;const y=[];for(let m=0;m<p;++m){t.setPosition(u+(d?m*32:c));const[f,l]=pt(t,e,{staticPosition:u});c+=l,y.push(f)}return t.setPosition(a+32),[y,32]}if(Bt(e)){const i=Ie(t.readBytes(pa)),o=a+i,u=[];for(let p=0;p<n;++p){t.setPosition(o+p*32);const[d]=pt(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]=pt(t,e,{staticPosition:a+r});r+=u,s.push(o)}return[s,r]}function Ju(t){return[ju(t.readBytes(32),{size:32}),32]}function Yu(t,e,{staticPosition:n}){const[a,r]=e.type.split("bytes");if(!r){const i=Ie(t.readBytes(32));t.setPosition(n+i);const o=Ie(t.readBytes(32));if(o===0)return t.setPosition(n+32),["0x",32];const u=t.readBytes(o);return t.setPosition(n+32),[J(u),32]}return[J(t.readBytes(Number.parseInt(r),32)),32]}function Ku(t,e){const n=e.type.startsWith("int"),a=Number.parseInt(e.type.split("int")[1]||"256"),r=t.readBytes(32);return[a>48?Gu(r,{signed:n}):Ie(r,{signed:n}),32]}function Xu(t,e,{staticPosition:n}){const a=e.components.length===0||e.components.some(({name:i})=>!i),r=a?[]:{};let s=0;if(Bt(e)){const i=Ie(t.readBytes(pa)),o=n+i;for(let u=0;u<e.components.length;++u){const p=e.components[u];t.setPosition(o+s);const[d,c]=pt(t,p,{staticPosition:o});s+=c,r[a?u:p==null?void 0:p.name]=d}return t.setPosition(n+32),[r,32]}for(let i=0;i<e.components.length;++i){const o=e.components[i],[u,p]=pt(t,o,{staticPosition:n});r[a?i:o==null?void 0:o.name]=u,s+=p}return[r,s]}function Qu(t,{staticPosition:e}){const n=Ie(t.readBytes(32)),a=e+n;t.setPosition(a);const r=Ie(t.readBytes(32));if(r===0)return t.setPosition(e+32),["",32];const s=t.readBytes(r,32),i=Wu(Mn(s));return t.setPosition(e+32),[i,32]}function Bt(t){var a;const{type:e}=t;if(e==="string"||e==="bytes"||e.endsWith("[]"))return!0;if(e==="tuple")return(a=t.components)==null?void 0:a.some(Bt);const n=La(t.type);return!!(n&&Bt({...t,type:n[1]}))}function Fs(t){const{abi:e,data:n}=t,a=bt(n,0,4);if(a==="0x")throw new An;const s=[...e||[],zu,Lu].find(i=>i.type==="error"&&a===Pn(he(i)));if(!s)throw new bs(a,{docsPath:"/docs/contract/decodeErrorResult"});return{abiItem:s,args:"inputs"in s&&s.inputs&&s.inputs.length>0?en(s.inputs,bt(n,4)):void 0,errorName:s.name}}const X=(t,e,n)=>JSON.stringify(t,(a,r)=>typeof r=="bigint"?r.toString():r,n);function Os({abiItem:t,args:e,includeFunctionName:n=!0,includeName:a=!1}){if("name"in t&&"inputs"in t&&t.inputs)return`${n?t.name:""}(${t.inputs.map((r,s)=>`${a&&r.name?`${r.name}: `:""}${typeof e[s]=="object"?X(e[s]):e[s]}`).join(", ")})`}const ep={gwei:9,wei:18},tp={ether:-9,wei:9};function z(t,e){let n=t.toString();const a=n.startsWith("-");a&&(n=n.slice(1)),n=n.padStart(e,"0");let[r,s]=[n.slice(0,n.length-e),n.slice(n.length-e)];return s=s.replace(/(0+)$/,""),`${a?"-":""}${r||"0"}${s?`.${s}`:""}`}function Ha(t,e="wei"){return z(t,ep[e])}function ae(t,e="wei"){return z(t,tp[e])}class np extends g{constructor({address:e}){super(`State for account "${e}" is set multiple times.`,{name:"AccountStateConflictError"})}}class ap extends g{constructor(){super("state and stateDiff are set on the same account.",{name:"StateAssignmentConflictError"})}}function Sr(t){return t.reduce((e,{slot:n,value:a})=>`${e} ${n}: ${a} `,"")}function rp(t){return t.reduce((e,{address:n,...a})=>{let r=`${e} ${n}: `;return a.nonce&&(r+=` nonce: ${a.nonce} `),a.balance&&(r+=` balance: ${a.balance} `),a.code&&(r+=` code: ${a.code} `),a.state&&(r+=` state: `,r+=Sr(a.state)),a.stateDiff&&(r+=` stateDiff: `,r+=Sr(a.stateDiff)),r},` State Override: `).slice(0,-1)}function tn(t){const e=Object.entries(t).map(([a,r])=>r===void 0||r===!1?null:[a,r])