UNPKG

@okcontract/sdk

Version:

One-stop-shop permissionless SDK for building any blockchain frontend

20 lines 1.1 MB
var YS=Object.defineProperty;var $S=(e,t,n)=>t in e?YS(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var C=(e,t,n)=>$S(e,typeof t!="symbol"?t+"":t,n);var un,gn,LS;import{collector as hn,uncellify as Qr,cellify as It,jsonStringify as ao,WrappedCell as os,clock as zS,clockWork as JS,nextSubscriber as qS,sleep as sp,last as KS,filterPredicateCell as VS,mapArrayCell as WS,ValueCell as so,Cell as fn,asyncReduce as ZS,delayed as XS,simplifier as cp,reduce as nA,isObject as up,SheetProxy as as,reduceObject as ex,mapArray as co,Sheet as tx,flattenCellArray as uo,logger as nx,initialValue as rx,copy as ix,findIndex as gp}from"@okcontract/cells";function Ax(e,t){for(var n=0;n<t.length;n++){const r=t[n];if(typeof r!="string"&&!Array.isArray(r)){for(const i in r)if(i!=="default"&&!(i in e)){const A=Object.getOwnPropertyDescriptor(r,i);A&&Object.defineProperty(e,i,A.get?A:{enumerable:!0,get:()=>r[i]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}const ox="1.0.8";let Pt=class ip extends Error{constructor(t,n={}){const r=n.cause instanceof ip?n.cause.details:n.cause?.message?n.cause.message:n.details,i=n.cause instanceof ip&&n.cause.docsPath||n.docsPath,A=[t||"An error occurred.","",...n.metaMessages?[...n.metaMessages,""]:[],...i?[`Docs: https://abitype.dev${i}`]:[],...r?[`Details: ${r}`]:[],`Version: abitype@${ox}`].join(` `);super(A),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiTypeError"}),n.cause&&(this.cause=n.cause),this.details=r,this.docsPath=i,this.metaMessages=n.metaMessages,this.shortMessage=t}};function Jn(e,t){return e.exec(t)?.groups}const lp=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,hp=/^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)?$/,fp=/^\(.+?\).*?$/,dp=/^tuple(?<array>(\[(\d*)\])*)$/;function Gu(e){let t=e.type;if(dp.test(e.type)&&"components"in e){t="(";const n=e.components.length;for(let i=0;i<n;i++){const A=e.components[i];t+=Gu(A),i<n-1&&(t+=", ")}const r=Jn(dp,e.type);return t+=`)${r?.array??""}`,Gu({...e,type:t})}return"indexed"in e&&e.indexed&&(t=`${t} indexed`),e.name?`${t} ${e.name}`:t}function go(e){let t="";const n=e.length;for(let r=0;r<n;r++){const i=e[r];t+=Gu(i),r!==n-1&&(t+=", ")}return t}function ax(e){return e.type==="function"?`function ${e.name}(${go(e.inputs)})${e.stateMutability&&e.stateMutability!=="nonpayable"?` ${e.stateMutability}`:""}${e.outputs?.length?` returns (${go(e.outputs)})`:""}`:e.type==="event"?`event ${e.name}(${go(e.inputs)})`:e.type==="error"?`error ${e.name}(${go(e.inputs)})`:e.type==="constructor"?`constructor(${go(e.inputs)})${e.stateMutability==="payable"?" payable":""}`:e.type==="fallback"?`fallback() external${e.stateMutability==="payable"?" payable":""}`:"receive() external payable"}const Ip=/^error (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;function sx(e){return Ip.test(e)}function cx(e){return Jn(Ip,e)}const pp=/^event (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;function ux(e){return pp.test(e)}function gx(e){return Jn(pp,e)}const mp=/^function (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)(?: (?<scope>external|public{1}))?(?: (?<stateMutability>pure|view|nonpayable|payable{1}))?(?: returns\s?\((?<returns>.*?)\))?$/;function lx(e){return mp.test(e)}function hx(e){return Jn(mp,e)}const Cp=/^struct (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) \{(?<properties>.*?)\}$/;function Bp(e){return Cp.test(e)}function fx(e){return Jn(Cp,e)}const Ep=/^constructor\((?<parameters>.*?)\)(?:\s(?<stateMutability>payable{1}))?$/;function dx(e){return Ep.test(e)}function Ix(e){return Jn(Ep,e)}const yp=/^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/;function px(e){return yp.test(e)}function mx(e){return Jn(yp,e)}const Cx=/^receive\(\) external payable$/;function Bx(e){return Cx.test(e)}const Ex=new Set(["indexed"]),Ru=new Set(["calldata","memory","storage"]);class yx extends Pt{constructor({type:t}){super("Unknown type.",{metaMessages:[`Type "${t}" 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 Qx extends Pt{constructor({type:t}){super("Unknown type.",{metaMessages:[`Type "${t}" is not a valid ABI type.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSolidityTypeError"})}}class wx extends Pt{constructor({param:t}){super("Invalid ABI parameter.",{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParameterError"})}}class bx extends Pt{constructor({param:t,name:n}){super("Invalid ABI parameter.",{details:t,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 kx extends Pt{constructor({param:t,type:n,modifier:r}){super("Invalid ABI parameter.",{details:t,metaMessages:[`Modifier "${r}" not allowed${n?` in "${n}" type`:""}.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidModifierError"})}}class vx extends Pt{constructor({param:t,type:n,modifier:r}){super("Invalid ABI parameter.",{details:t,metaMessages:[`Modifier "${r}" not allowed${n?` in "${n}" type`:""}.`,`Data location can only be specified for array, struct, or mapping types, but "${r}" was given.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidFunctionModifierError"})}}class Dx extends Pt{constructor({abiParameter:t}){super("Invalid ABI parameter.",{details:JSON.stringify(t,null,2),metaMessages:["ABI parameter type is invalid."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidAbiTypeParameterError"})}}class rA extends Pt{constructor({signature:t,type:n}){super(`Invalid ${n} signature.`,{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidSignatureError"})}}class Sx extends Pt{constructor({signature:t}){super("Unknown signature.",{details:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSignatureError"})}}class xx extends Pt{constructor({signature:t}){super("Invalid struct signature.",{details:t,metaMessages:["No properties exist."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidStructSignatureError"})}}class jx extends Pt{constructor({type:t}){super("Circular reference detected.",{metaMessages:[`Struct "${t}" is a circular reference.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"CircularReferenceError"})}}class Ox extends Pt{constructor({current:t,depth:n}){super("Unbalanced parentheses.",{metaMessages:[`"${t.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 _x(e,t,n){let r="";if(n)for(const i of Object.entries(n)){if(!i)continue;let A="";for(const o of i[1])A+=`[${o.type}${o.name?`:${o.name}`:""}]`;r+=`(${i[0]}{${A}})`}return t?`${t}:${e}${r}`:e}const Uu=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 Nx(e,t={}){if(lx(e))return Fx(e,t);if(ux(e))return Mx(e,t);if(sx(e))return Gx(e,t);if(dx(e))return Rx(e,t);if(px(e))return Ux(e);if(Bx(e))return{type:"receive",stateMutability:"payable"};throw new Sx({signature:e})}function Fx(e,t={}){const n=hx(e);if(!n)throw new rA({signature:e,type:"function"});const r=en(n.parameters),i=[],A=r.length;for(let a=0;a<A;a++)i.push(ri(r[a],{modifiers:Ru,structs:t,type:"function"}));const o=[];if(n.returns){const a=en(n.returns),s=a.length;for(let c=0;c<s;c++)o.push(ri(a[c],{modifiers:Ru,structs:t,type:"function"}))}return{name:n.name,type:"function",stateMutability:n.stateMutability??"nonpayable",inputs:i,outputs:o}}function Mx(e,t={}){const n=gx(e);if(!n)throw new rA({signature:e,type:"event"});const r=en(n.parameters),i=[],A=r.length;for(let o=0;o<A;o++)i.push(ri(r[o],{modifiers:Ex,structs:t,type:"event"}));return{name:n.name,type:"event",inputs:i}}function Gx(e,t={}){const n=cx(e);if(!n)throw new rA({signature:e,type:"error"});const r=en(n.parameters),i=[],A=r.length;for(let o=0;o<A;o++)i.push(ri(r[o],{structs:t,type:"error"}));return{name:n.name,type:"error",inputs:i}}function Rx(e,t={}){const n=Ix(e);if(!n)throw new rA({signature:e,type:"constructor"});const r=en(n.parameters),i=[],A=r.length;for(let o=0;o<A;o++)i.push(ri(r[o],{structs:t,type:"constructor"}));return{type:"constructor",stateMutability:n.stateMutability??"nonpayable",inputs:i}}function Ux(e){const t=mx(e);if(!t)throw new rA({signature:e,type:"fallback"});return{type:"fallback",stateMutability:t.stateMutability??"nonpayable"}}const Tx=/^(?<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$_]*))?$/,Lx=/^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,Px=/^u?int$/;function ri(e,t){const n=_x(e,t?.type,t?.structs);if(Uu.has(n))return Uu.get(n);const r=fp.test(e),i=Jn(r?Lx:Tx,e);if(!i)throw new wx({param:e});if(i.name&&Yx(i.name))throw new bx({param:e,name:i.name});const A=i.name?{name:i.name}:{},o=i.modifier==="indexed"?{indexed:!0}:{},a=t?.structs??{};let s,c={};if(r){s="tuple";const g=en(i.type),l=[],h=g.length;for(let d=0;d<h;d++)l.push(ri(g[d],{structs:a}));c={components:l}}else if(i.type in a)s="tuple",c={components:a[i.type]};else if(Px.test(i.type))s=`${i.type}256`;else if(s=i.type,t?.type!=="struct"&&!Qp(s))throw new Qx({type:s});if(i.modifier){if(!t?.modifiers?.has?.(i.modifier))throw new kx({param:e,type:t?.type,modifier:i.modifier});if(Ru.has(i.modifier)&&!$x(s,!!i.array))throw new vx({param:e,type:t?.type,modifier:i.modifier})}const u={type:`${s}${i.array??""}`,...A,...o,...c};return Uu.set(n,u),u}function en(e,t=[],n="",r=0){const i=e.trim().length;for(let A=0;A<i;A++){const o=e[A],a=e.slice(A+1);switch(o){case",":return r===0?en(a,[...t,n.trim()]):en(a,t,`${n}${o}`,r);case"(":return en(a,t,`${n}${o}`,r+1);case")":return en(a,t,`${n}${o}`,r-1);default:return en(a,t,`${n}${o}`,r)}}if(n==="")return t;if(r!==0)throw new Ox({current:n,depth:r});return t.push(n.trim()),t}function Qp(e){return e==="address"||e==="bool"||e==="function"||e==="string"||lp.test(e)||hp.test(e)}const Hx=/^(?: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 Yx(e){return e==="address"||e==="bool"||e==="function"||e==="string"||e==="tuple"||lp.test(e)||hp.test(e)||Hx.test(e)}function $x(e,t){return t||e==="bytes"||e==="string"||e==="tuple"}function zx(e){const t={},n=e.length;for(let o=0;o<n;o++){const a=e[o];if(!Bp(a))continue;const s=fx(a);if(!s)throw new rA({signature:a,type:"struct"});const c=s.properties.split(";"),u=[],g=c.length;for(let l=0;l<g;l++){const d=c[l].trim();if(!d)continue;const I=ri(d,{type:"struct"});u.push(I)}if(!u.length)throw new xx({signature:a});t[s.name]=u}const r={},i=Object.entries(t),A=i.length;for(let o=0;o<A;o++){const[a,s]=i[o];r[a]=wp(s,t)}return r}const Jx=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?$/;function wp(e,t,n=new Set){const r=[],i=e.length;for(let A=0;A<i;A++){const o=e[A];if(fp.test(o.type))r.push(o);else{const s=Jn(Jx,o.type);if(!s?.type)throw new Dx({abiParameter:o});const{array:c,type:u}=s;if(u in t){if(n.has(u))throw new jx({type:u});r.push({...o,type:`tuple${c??""}`,components:wp(t[u]??[],t,new Set([...n,u]))})}else if(Qp(u))r.push(o);else throw new yx({type:u})}}return r}function dn(e){const t=zx(e),n=[],r=e.length;for(let i=0;i<r;i++){const A=e[i];Bp(A)||n.push(Nx(A,t))}return n}function pt(e,t,n){const r=e[t.name];if(typeof r=="function")return r;const i=e[n];return typeof i=="function"?i:A=>t(e,A)}function In(e,{includeName:t=!1}={}){if(e.type!=="function"&&e.type!=="event"&&e.type!=="error")throw new o1(e.type);return`${e.name}(${ss(e.inputs,{includeName:t})})`}function ss(e,{includeName:t=!1}={}){return e?e.map(n=>qx(n,{includeName:t})).join(t?", ":","):""}function qx(e,{includeName:t}){return e.type.startsWith("tuple")?`(${ss(e.components,{includeName:t})})${e.type.slice(5)}`:e.type+(t&&e.name?` ${e.name}`:"")}function wr(e,{strict:t=!0}={}){return!e||typeof e!="string"?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")}function ke(e){return wr(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}const bp="2.23.2";let Tu={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:n})=>t?`${e??"https://viem.sh"}${t}${n?`#${n}`:""}`:void 0,version:`viem@${bp}`};class z extends Error{constructor(t,n={}){const r=n.cause instanceof z?n.cause.details:n.cause?.message?n.cause.message:n.details,i=n.cause instanceof z&&n.cause.docsPath||n.docsPath,A=Tu.getDocsUrl?.({...n,docsPath:i}),o=[t||"An error occurred.","",...n.metaMessages?[...n.metaMessages,""]:[],...A?[`Docs: ${A}`]:[],...r?[`Details: ${r}`]:[],...Tu.version?[`Version: ${Tu.version}`]:[]].join(` `);super(o,n.cause?{cause:n.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=r,this.docsPath=i,this.metaMessages=n.metaMessages,this.name=n.name??this.name,this.shortMessage=t,this.version=bp}walk(t){return kp(this,t)}}function kp(e,t){return t?.(e)?e:e&&typeof e=="object"&&"cause"in e&&e.cause!==void 0?kp(e.cause,t):t?null:e}class Kx extends z{constructor({docsPath:t}){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:t,name:"AbiConstructorNotFoundError"})}}class vp extends z{constructor({docsPath:t}){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:t,name:"AbiConstructorParamsNotFoundError"})}}class Dp extends z{constructor({data:t,params:n,size:r}){super([`Data size of ${r} bytes is too small for given parameters.`].join(` `),{metaMessages:[`Params: (${ss(n,{includeName:!0})})`,`Data: ${t} (${r} 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=t,this.params=n,this.size=r}}class Lu extends z{constructor(){super('Cannot decode zero data ("0x") with ABI parameters.',{name:"AbiDecodingZeroDataError"})}}class Vx extends z{constructor({expectedLength:t,givenLength:n,type:r}){super([`ABI encoding array length mismatch for type ${r}.`,`Expected length: ${t}`,`Given length: ${n}`].join(` `),{name:"AbiEncodingArrayLengthMismatchError"})}}class Wx extends z{constructor({expectedSize:t,value:n}){super(`Size of bytes "${n}" (bytes${ke(n)}) does not match expected size (bytes${t}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class Sp extends z{constructor({expectedLength:t,givenLength:n}){super(["ABI encoding params/values length mismatch.",`Expected length (params): ${t}`,`Given length (values): ${n}`].join(` `),{name:"AbiEncodingLengthMismatchError"})}}class xp extends z{constructor(t,{docsPath:n}){super([`Encoded error signature "${t}" 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=${t}.`].join(` `),{docsPath:n,name:"AbiErrorSignatureNotFoundError"}),Object.defineProperty(this,"signature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.signature=t}}class Zx extends z{constructor({docsPath:t}){super("Cannot extract event signature from empty topics.",{docsPath:t,name:"AbiEventSignatureEmptyTopicsError"})}}class Xx extends z{constructor(t,{docsPath:n}){super([`Encoded event signature "${t}" 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=${t}.`].join(` `),{docsPath:n,name:"AbiEventSignatureNotFoundError"})}}class cs extends z{constructor(t,{docsPath:n}={}){super([`Function ${t?`"${t}" `:""}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 e1 extends z{constructor(t,{docsPath:n}){super([`Function "${t}" 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 t1 extends z{constructor(t,n){super("Found ambiguous types in overloaded ABI items.",{metaMessages:[`\`${t.type}\` in \`${In(t.abiItem)}\`, and`,`\`${n.type}\` in \`${In(n.abiItem)}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."],name:"AbiItemAmbiguityError"})}}class jp extends z{constructor({expectedSize:t,givenSize:n}){super(`Expected bytes${t}, got bytes${n}.`,{name:"BytesSizeMismatchError"})}}class Op extends z{constructor({abiItem:t,data:n,params:r,size:i}){super([`Data size of ${i} bytes is too small for non-indexed event parameters.`].join(` `),{metaMessages:[`Params: (${ss(r,{includeName:!0})})`,`Data: ${n} (${i} 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=t,this.data=n,this.params=r,this.size=i}}class n1 extends z{constructor({abiItem:t,param:n}){super([`Expected a topic for indexed event parameter${n.name?` "${n.name}"`:""} on event "${In(t,{includeName:!0})}".`].join(` `),{name:"DecodeLogTopicsMismatch"}),Object.defineProperty(this,"abiItem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abiItem=t}}class r1 extends z{constructor(t,{docsPath:n}){super([`Type "${t}" is not a valid encoding type.`,"Please provide a valid ABI type."].join(` `),{docsPath:n,name:"InvalidAbiEncodingType"})}}class i1 extends z{constructor(t,{docsPath:n}){super([`Type "${t}" is not a valid decoding type.`,"Please provide a valid ABI type."].join(` `),{docsPath:n,name:"InvalidAbiDecodingType"})}}class A1 extends z{constructor(t){super([`Value "${t}" is not a valid array.`].join(` `),{name:"InvalidArrayError"})}}class o1 extends z{constructor(t){super([`"${t}" is not a valid definition type.`,'Valid types: "function", "event", "error"'].join(` `),{name:"InvalidDefinitionTypeError"})}}class a1 extends z{constructor(t){super(`Type "${t}" is not supported for packed encoding.`,{name:"UnsupportedPackedAbiType"})}}class _p extends z{constructor({offset:t,position:n,size:r}){super(`Slice ${n==="start"?"starting":"ending"} at offset "${t}" is out-of-bounds (size: ${r}).`,{name:"SliceOffsetOutOfBoundsError"})}}class Np extends z{constructor({size:t,targetSize:n,type:r}){super(`${r.charAt(0).toUpperCase()}${r.slice(1).toLowerCase()} size (${t}) exceeds padding size (${n}).`,{name:"SizeExceedsPaddingSizeError"})}}class Fp extends z{constructor({size:t,targetSize:n,type:r}){super(`${r.charAt(0).toUpperCase()}${r.slice(1).toLowerCase()} is expected to be ${n} ${r} long, but is ${t} ${r} long.`,{name:"InvalidBytesLengthError"})}}function qn(e,{dir:t,size:n=32}={}){return typeof e=="string"?br(e,{dir:t,size:n}):s1(e,{dir:t,size:n})}function br(e,{dir:t,size:n=32}={}){if(n===null)return e;const r=e.replace("0x","");if(r.length>n*2)throw new Np({size:Math.ceil(r.length/2),targetSize:n,type:"hex"});return`0x${r[t==="right"?"padEnd":"padStart"](n*2,"0")}`}function s1(e,{dir:t,size:n=32}={}){if(n===null)return e;if(e.length>n)throw new Np({size:e.length,targetSize:n,type:"bytes"});const r=new Uint8Array(n);for(let i=0;i<n;i++){const A=t==="right";r[A?i:n-i-1]=e[A?i:e.length-i-1]}return r}class Mp extends z{constructor({max:t,min:n,signed:r,size:i,value:A}){super(`Number "${A}" is not in safe ${i?`${i*8}-bit ${r?"signed":"unsigned"} `:""}integer range ${t?`(${n} to ${t})`:`(above ${n})`}`,{name:"IntegerOutOfRangeError"})}}class c1 extends z{constructor(t){super(`Bytes value "${t}" is not a valid boolean. The bytes array must contain a single byte of either a 0 or 1 value.`,{name:"InvalidBytesBooleanError"})}}class u1 extends z{constructor({givenSize:t,maxSize:n}){super(`Size cannot exceed ${n} bytes. Given size: ${t} bytes.`,{name:"SizeOverflowError"})}}function ii(e,{dir:t="left"}={}){let n=typeof e=="string"?e.replace("0x",""):e,r=0;for(let i=0;i<n.length-1&&n[t==="left"?i:n.length-i-1].toString()==="0";i++)r++;return n=t==="left"?n.slice(r):n.slice(0,n.length-r),typeof e=="string"?(n.length===1&&t==="right"&&(n=`${n}0`),`0x${n.length%2===1?`0${n}`:n}`):n}function pn(e,{size:t}){if(ke(e)>t)throw new u1({givenSize:ke(e),maxSize:t})}function Ai(e,t={}){const{signed:n}=t;t.size&&pn(e,{size:t.size});const r=BigInt(e);if(!n)return r;const i=(e.length-2)/2,A=(1n<<BigInt(i)*8n-1n)-1n;return r<=A?r:r-BigInt(`0x${"f".padStart(i*2,"f")}`)-1n}function Kn(e,t={}){return Number(Ai(e,t))}const g1=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function re(e,t={}){return typeof e=="number"||typeof e=="bigint"?ce(e,t):typeof e=="string"?oi(e,t):typeof e=="boolean"?Pu(e,t):Xe(e,t)}function Pu(e,t={}){const n=`0x${Number(e)}`;return typeof t.size=="number"?(pn(n,{size:t.size}),qn(n,{size:t.size})):n}function Xe(e,t={}){let n="";for(let i=0;i<e.length;i++)n+=g1[e[i]];const r=`0x${n}`;return typeof t.size=="number"?(pn(r,{size:t.size}),qn(r,{dir:"right",size:t.size})):r}function ce(e,t={}){const{signed:n,size:r}=t,i=BigInt(e);let A;r?n?A=(1n<<BigInt(r)*8n-1n)-1n:A=2n**(BigInt(r)*8n)-1n:typeof e=="number"&&(A=BigInt(Number.MAX_SAFE_INTEGER));const o=typeof A=="bigint"&&n?-A-1n:0;if(A&&i>A||i<o){const s=typeof e=="bigint"?"n":"";throw new Mp({max:A?`${A}${s}`:void 0,min:`${o}${s}`,signed:n,size:r,value:`${e}${s}`})}const a=`0x${(n&&i<0?(1n<<BigInt(r*8))+BigInt(i):i).toString(16)}`;return r?qn(a,{size:r}):a}const l1=new TextEncoder;function oi(e,t={}){const n=l1.encode(e);return Xe(n,t)}const h1=new TextEncoder;function lo(e,t={}){return typeof e=="number"||typeof e=="bigint"?d1(e,t):typeof e=="boolean"?f1(e,t):wr(e)?mn(e,t):Rp(e,t)}function f1(e,t={}){const n=new Uint8Array(1);return n[0]=Number(e),typeof t.size=="number"?(pn(n,{size:t.size}),qn(n,{size:t.size})):n}const Vn={zero:48,nine:57,A:65,F:70,a:97,f:102};function Gp(e){if(e>=Vn.zero&&e<=Vn.nine)return e-Vn.zero;if(e>=Vn.A&&e<=Vn.F)return e-(Vn.A-10);if(e>=Vn.a&&e<=Vn.f)return e-(Vn.a-10)}function mn(e,t={}){let n=e;t.size&&(pn(n,{size:t.size}),n=qn(n,{dir:"right",size:t.size}));let r=n.slice(2);r.length%2&&(r=`0${r}`);const i=r.length/2,A=new Uint8Array(i);for(let o=0,a=0;o<i;o++){const s=Gp(r.charCodeAt(a++)),c=Gp(r.charCodeAt(a++));if(s===void 0||c===void 0)throw new z(`Invalid byte sequence ("${r[a-2]}${r[a-1]}" in "${r}").`);A[o]=s*16+c}return A}function d1(e,t){const n=ce(e,t);return mn(n)}function Rp(e,t={}){const n=h1.encode(e);return typeof t.size=="number"?(pn(n,{size:t.size}),qn(n,{dir:"right",size:t.size})):n}function us(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function I1(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function ho(e,...t){if(!I1(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function p1(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");us(e.outputLen),us(e.blockLen)}function iA(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Up(e,t){ho(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}const gs=BigInt(2**32-1),Tp=BigInt(32);function m1(e,t=!1){return t?{h:Number(e&gs),l:Number(e>>Tp&gs)}:{h:Number(e>>Tp&gs)|0,l:Number(e&gs)|0}}function C1(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let i=0;i<e.length;i++){const{h:A,l:o}=m1(e[i],t);[n[i],r[i]]=[A,o]}return[n,r]}const B1=(e,t,n)=>e<<n|t>>>32-n,E1=(e,t,n)=>t<<n|e>>>32-n,y1=(e,t,n)=>t<<n-32|e>>>64-n,Q1=(e,t,n)=>e<<n-32|t>>>64-n,AA=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function w1(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function Hu(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Cn(e,t){return e<<32-t|e>>>t}const Lp=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function b1(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function Pp(e){for(let t=0;t<e.length;t++)e[t]=b1(e[t])}function k1(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function ls(e){return typeof e=="string"&&(e=k1(e)),ho(e),e}function v1(...e){let t=0;for(let r=0;r<e.length;r++){const i=e[r];ho(i),t+=i.length}const n=new Uint8Array(t);for(let r=0,i=0;r<e.length;r++){const A=e[r];n.set(A,i),i+=A.length}return n}let Yu=class{clone(){return this._cloneInto()}};function Hp(e){const t=r=>e().update(ls(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function D1(e=32){if(AA&&typeof AA.getRandomValues=="function")return AA.getRandomValues(new Uint8Array(e));if(AA&&typeof AA.randomBytes=="function")return AA.randomBytes(e);throw new Error("crypto.getRandomValues must be defined")}const Yp=[],$p=[],zp=[],S1=BigInt(0),fo=BigInt(1),x1=BigInt(2),j1=BigInt(7),O1=BigInt(256),_1=BigInt(113);for(let e=0,t=fo,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],Yp.push(2*(5*r+n)),$p.push((e+1)*(e+2)/2%64);let i=S1;for(let A=0;A<7;A++)t=(t<<fo^(t>>j1)*_1)%O1,t&x1&&(i^=fo<<(fo<<BigInt(A))-fo);zp.push(i)}const[N1,F1]=C1(zp,!0),Jp=(e,t,n)=>n>32?y1(e,t,n):B1(e,t,n),qp=(e,t,n)=>n>32?Q1(e,t,n):E1(e,t,n);function M1(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let o=0;o<10;o++)n[o]=e[o]^e[o+10]^e[o+20]^e[o+30]^e[o+40];for(let o=0;o<10;o+=2){const a=(o+8)%10,s=(o+2)%10,c=n[s],u=n[s+1],g=Jp(c,u,1)^n[a],l=qp(c,u,1)^n[a+1];for(let h=0;h<50;h+=10)e[o+h]^=g,e[o+h+1]^=l}let i=e[2],A=e[3];for(let o=0;o<24;o++){const a=$p[o],s=Jp(i,A,a),c=qp(i,A,a),u=Yp[o];i=e[u],A=e[u+1],e[u]=s,e[u+1]=c}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)n[a]=e[o+a];for(let a=0;a<10;a++)e[o+a]^=~n[(a+2)%10]&n[(a+4)%10]}e[0]^=N1[r],e[1]^=F1[r]}n.fill(0)}let G1=class PS extends Yu{constructor(t,n,r,i=!1,A=24){if(super(),this.blockLen=t,this.suffix=n,this.outputLen=r,this.enableXOF=i,this.rounds=A,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,us(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=w1(this.state)}keccak(){Lp||Pp(this.state32),M1(this.state32,this.rounds),Lp||Pp(this.state32),this.posOut=0,this.pos=0}update(t){iA(this);const{blockLen:n,state:r}=this;t=ls(t);const i=t.length;for(let A=0;A<i;){const o=Math.min(n-this.pos,i-A);for(let a=0;a<o;a++)r[this.pos++]^=t[A++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:n,pos:r,blockLen:i}=this;t[r]^=n,n&128&&r===i-1&&this.keccak(),t[i-1]^=128,this.keccak()}writeInto(t){iA(this,!1),ho(t),this.finish();const n=this.state,{blockLen:r}=this;for(let i=0,A=t.length;i<A;){this.posOut>=r&&this.keccak();const o=Math.min(r-this.posOut,A-i);t.set(n.subarray(this.posOut,this.posOut+o),i),this.posOut+=o,i+=o}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return us(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(Up(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:n,suffix:r,outputLen:i,rounds:A,enableXOF:o}=this;return t||(t=new PS(n,r,i,o,A)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=A,t.suffix=r,t.outputLen=i,t.enableXOF=o,t.destroyed=this.destroyed,t}};const R1=(e,t,n)=>Hp(()=>new G1(t,e,n)),U1=R1(1,136,256/8);function mt(e,t){const n=t||"hex",r=U1(wr(e,{strict:!1})?lo(e):e);return n==="bytes"?r:re(r)}const T1=e=>mt(lo(e));function L1(e){return T1(e)}function P1(e){let t=!0,n="",r=0,i="",A=!1;for(let o=0;o<e.length;o++){const a=e[o];if(["(",")",","].includes(a)&&(t=!0),a==="("&&r++,a===")"&&r--,!!t){if(r===0){if(a===" "&&["event","function",""].includes(i))i="";else if(i+=a,a===")"){A=!0;break}continue}if(a===" "){e[o-1]!==","&&n!==","&&n!==",("&&(n="",t=!1);continue}i+=a,n+=a}}if(!A)throw new z("Unable to normalize signature.");return i}const Kp=e=>{const t=typeof e=="string"?e:ax(e);return P1(t)};function Vp(e){return L1(Kp(e))}const Wp=Vp;class Ct extends z{constructor({address:t}){super(`Address "${t}" is invalid.`,{metaMessages:["- Address must be a hex value of 20 bytes (40 hex characters).","- Address must match its checksum counterpart."],name:"InvalidAddressError"})}}class hs extends Map{constructor(t){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=t}get(t){const n=super.get(t);return super.has(t)&&n!==void 0&&(this.delete(t),super.set(t,n)),n}set(t,n){if(super.set(t,n),this.maxSize&&this.size>this.maxSize){const r=this.keys().next().value;r&&this.delete(r)}return this}}const $u=new hs(8192);function Io(e,t){if($u.has(`${e}.${t}`))return $u.get(`${e}.${t}`);const n=e.substring(2).toLowerCase(),r=mt(Rp(n),"bytes"),i=n.split("");for(let o=0;o<40;o+=2)r[o>>1]>>4>=8&&i[o]&&(i[o]=i[o].toUpperCase()),(r[o>>1]&15)>=8&&i[o+1]&&(i[o+1]=i[o+1].toUpperCase());const A=`0x${i.join("")}`;return $u.set(`${e}.${t}`,A),A}function Bn(e,t){if(!Se(e,{strict:!1}))throw new Ct({address:e});return Io(e,t)}const H1=/^0x[a-fA-F0-9]{40}$/,zu=new hs(8192);function Se(e,t){const{strict:n=!0}=t??{},r=`${e}.${n}`;if(zu.has(r))return zu.get(r);const i=H1.test(e)?e.toLowerCase()===e?!0:n?Io(e)===e:!0:!1;return zu.set(r,i),i}function kr(e){return typeof e[0]=="string"?En(e):Y1(e)}function Y1(e){let t=0;for(const i of e)t+=i.length;const n=new Uint8Array(t);let r=0;for(const i of e)n.set(i,r),r+=i.length;return n}function En(e){return`0x${e.reduce((t,n)=>t+n.replace("0x",""),"")}`}function po(e,t,n,{strict:r}={}){return wr(e,{strict:!1})?$1(e,t,n,{strict:r}):em(e,t,n,{strict:r})}function Zp(e,t){if(typeof t=="number"&&t>0&&t>ke(e)-1)throw new _p({offset:t,position:"start",size:ke(e)})}function Xp(e,t,n){if(typeof t=="number"&&typeof n=="number"&&ke(e)!==n-t)throw new _p({offset:n,position:"end",size:ke(e)})}function em(e,t,n,{strict:r}={}){Zp(e,t);const i=e.slice(t,n);return r&&Xp(i,t,n),i}function $1(e,t,n,{strict:r}={}){Zp(e,t);const i=`0x${e.replace("0x","").slice((t??0)*2,(n??e.length)*2)}`;return r&&Xp(i,t,n),i}const z1=/^(.*)\[([0-9]*)\]$/,tm=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,Ju=/^(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 oA(e,t){if(e.length!==t.length)throw new Sp({expectedLength:e.length,givenLength:t.length});const n=J1({params:e,values:t}),r=Ku(n);return r.length===0?"0x":r}function J1({params:e,values:t}){const n=[];for(let r=0;r<e.length;r++)n.push(qu({param:e[r],value:t[r]}));return n}function qu({param:e,value:t}){const n=Vu(e.type);if(n){const[r,i]=n;return K1(t,{length:r,param:{...e,type:i}})}if(e.type==="tuple")return ej(t,{param:e});if(e.type==="address")return q1(t);if(e.type==="bool")return W1(t);if(e.type.startsWith("uint")||e.type.startsWith("int")){const r=e.type.startsWith("int"),[,,i="256"]=Ju.exec(e.type)??[];return Z1(t,{signed:r,size:Number(i)})}if(e.type.startsWith("bytes"))return V1(t,{param:e});if(e.type==="string")return X1(t);throw new r1(e.type,{docsPath:"/docs/contract/encodeAbiParameters"})}function Ku(e){let t=0;for(let A=0;A<e.length;A++){const{dynamic:o,encoded:a}=e[A];o?t+=32:t+=ke(a)}const n=[],r=[];let i=0;for(let A=0;A<e.length;A++){const{dynamic:o,encoded:a}=e[A];o?(n.push(ce(t+i,{size:32})),r.push(a),i+=ke(a)):n.push(a)}return kr([...n,...r])}function q1(e){if(!Se(e))throw new Ct({address:e});return{dynamic:!1,encoded:br(e.toLowerCase())}}function K1(e,{length:t,param:n}){const r=t===null;if(!Array.isArray(e))throw new A1(e);if(!r&&e.length!==t)throw new Vx({expectedLength:t,givenLength:e.length,type:`${n.type}[${t}]`});let i=!1;const A=[];for(let o=0;o<e.length;o++){const a=qu({param:n,value:e[o]});a.dynamic&&(i=!0),A.push(a)}if(r||i){const o=Ku(A);if(r){const a=ce(A.length,{size:32});return{dynamic:!0,encoded:A.length>0?kr([a,o]):a}}if(i)return{dynamic:!0,encoded:o}}return{dynamic:!1,encoded:kr(A.map(({encoded:o})=>o))}}function V1(e,{param:t}){const[,n]=t.type.split("bytes"),r=ke(e);if(!n){let i=e;return r%32!==0&&(i=br(i,{dir:"right",size:Math.ceil((e.length-2)/2/32)*32})),{dynamic:!0,encoded:kr([br(ce(r,{size:32})),i])}}if(r!==Number.parseInt(n))throw new Wx({expectedSize:Number.parseInt(n),value:e});return{dynamic:!1,encoded:br(e,{dir:"right"})}}function W1(e){if(typeof e!="boolean")throw new z(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:br(Pu(e))}}function Z1(e,{signed:t,size:n=256}){if(typeof n=="number"){const r=2n**(BigInt(n)-(t?1n:0n))-1n,i=t?-r-1n:0n;if(e>r||e<i)throw new Mp({max:r.toString(),min:i.toString(),signed:t,size:n/8,value:e.toString()})}return{dynamic:!1,encoded:ce(e,{size:32,signed:t})}}function X1(e){const t=oi(e),n=Math.ceil(ke(t)/32),r=[];for(let i=0;i<n;i++)r.push(br(po(t,i*32,(i+1)*32),{dir:"right"}));return{dynamic:!0,encoded:kr([br(ce(ke(t),{size:32})),...r])}}function ej(e,{param:t}){let n=!1;const r=[];for(let i=0;i<t.components.length;i++){const A=t.components[i],o=Array.isArray(e)?i:A.name,a=qu({param:A,value:e[o]});r.push(a),a.dynamic&&(n=!0)}return{dynamic:n,encoded:n?Ku(r):kr(r.map(({encoded:i})=>i))}}function Vu(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}const mo=e=>po(Vp(e),0,4);function ai(e){const{abi:t,args:n=[],name:r}=e,i=wr(r,{strict:!1}),A=t.filter(a=>i?a.type==="function"?mo(a)===r:a.type==="event"?Wp(a)===r:!1:"name"in a&&a.name===r);if(A.length===0)return;if(A.length===1)return A[0];let o;for(const a of A){if(!("inputs"in a))continue;if(!n||n.length===0){if(!a.inputs||a.inputs.length===0)return a;continue}if(!a.inputs||a.inputs.length===0||a.inputs.length!==n.length)continue;if(n.every((c,u)=>{const g="inputs"in a&&a.inputs[u];return g?Wu(c,g):!1})){if(o&&"inputs"in o&&o.inputs){const c=nm(a.inputs,o.inputs,n);if(c)throw new t1({abiItem:a,type:c[0]},{abiItem:o,type:c[1]})}o=a}}return o||A[0]}function Wu(e,t){const n=typeof e,r=t.type;switch(r){case"address":return Se(e,{strict:!1});case"bool":return n==="boolean";case"function":return n==="string";case"string":return n==="string";default:return r==="tuple"&&"components"in t?Object.values(t.components).every((i,A)=>Wu(Object.values(e)[A],i)):/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/.test(r)?n==="number"||n==="bigint":/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(r)?n==="string"||e instanceof Uint8Array:/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(r)?Array.isArray(e)&&e.every(i=>Wu(i,{...t,type:r.replace(/(\[[0-9]{0,}\])$/,"")})):!1}}function nm(e,t,n){for(const r in e){const i=e[r],A=t[r];if(i.type==="tuple"&&A.type==="tuple"&&"components"in i&&"components"in A)return nm(i.components,A.components,n[r]);const o=[i.type,A.type];if(o.includes("address")&&o.includes("bytes20")?!0:o.includes("address")&&o.includes("string")?Se(n[r],{strict:!1}):o.includes("address")&&o.includes("bytes")?Se(n[r],{strict:!1}):!1)return o}}function Wn(e){return typeof e=="string"?{address:e,type:"json-rpc"}:e}const rm="/docs/contract/encodeFunctionData";function tj(e){const{abi:t,args:n,functionName:r}=e;let i=t[0];if(r){const A=ai({abi:t,args:n,name:r});if(!A)throw new cs(r,{docsPath:rm});i=A}if(i.type!=="function")throw new cs(void 0,{docsPath:rm});return{abi:[i],functionName:mo(In(i))}}function fs(e){const{args:t}=e,{abi:n,functionName:r}=e.abi.length===1&&e.functionName?.startsWith("0x")?e:tj(e),i=n[0],A=r,o="inputs"in i&&i.inputs?oA(i.inputs,t??[]):void 0;return En([A,o??"0x"])}const nj={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."},rj={inputs:[{name:"message",type:"string"}],name:"Error",type:"error"},ij={inputs:[{name:"reason",type:"uint256"}],name:"Panic",type:"error"};class im extends z{constructor({offset:t}){super(`Offset \`${t}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class Am extends z{constructor({length:t,position:n}){super(`Position \`${n}\` is out of bounds (\`0 < position < ${t}\`).`,{name:"PositionOutOfBoundsError"})}}class Aj extends z{constructor({count:t,limit:n}){super(`Recursive read limit of \`${n}\` exceeded (recursive read count: \`${t}\`).`,{name:"RecursiveReadLimitExceededError"})}}const oj={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 Aj({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new Am({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new im({offset:e});const t=this.position-e;this.assertPosition(t),this.position=t},getReadCount(e){return this.positionReadCount.get(e||this.position)||0},incrementPosition(e){if(e<0)throw new im({offset:e});const t=this.position+e;this.assertPosition(t),this.position=t},inspectByte(e){const t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectBytes(e,t){const n=t??this.position;return this.assertPosition(n+e-1),this.bytes.subarray(n,n+e)},inspectUint8(e){const t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectUint16(e){const t=e??this.position;return this.assertPosition(t+1),this.dataView.getUint16(t)},inspectUint24(e){const t=e??this.position;return this.assertPosition(t+2),(this.dataView.getUint16(t)<<8)+this.dataView.getUint8(t+2)},inspectUint32(e){const t=e??this.position;return this.assertPosition(t+3),this.dataView.getUint32(t)},pushByte(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushBytes(e){this.assertPosition(this.position+e.length-1),this.bytes.set(e,this.position),this.position+=e.length},pushUint8(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushUint16(e){this.assertPosition(this.position+1),this.dataView.setUint16(this.position,e),this.position+=2},pushUint24(e){this.assertPosition(this.position+2),this.dataView.setUint16(this.position,e>>8),this.dataView.setUint8(this.position+2,e&255),this.position+=3},pushUint32(e){this.assertPosition(this.position+3),this.dataView.setUint32(this.position,e),this.position+=4},readByte(){this.assertReadLimit(),this._touch();const e=this.inspectByte();return this.position++,e},readBytes(e,t){this.assertReadLimit(),this._touch();const n=this.inspectBytes(e);return this.position+=t??e,n},readUint8(){this.assertReadLimit(),this._touch();const e=this.inspectUint8();return this.position+=1,e},readUint16(){this.assertReadLimit(),this._touch();const e=this.inspectUint16();return this.position+=2,e},readUint24(){this.assertReadLimit(),this._touch();const e=this.inspectUint24();return this.position+=3,e},readUint32(){this.assertReadLimit(),this._touch();const e=this.inspectUint32();return this.position+=4,e},get remaining(){return this.bytes.length-this.position},setPosition(e){const t=this.position;return this.assertPosition(e),this.position=e,()=>this.position=t},_touch(){if(this.recursiveReadLimit===Number.POSITIVE_INFINITY)return;const e=this.getReadCount();this.positionReadCount.set(this.position,e+1),e>0&&this.recursiveReadCount++}};function Zu(e,{recursiveReadLimit:t=8192}={}){const n=Object.create(oj);return n.bytes=e,n.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),n.positionReadCount=new Map,n.recursiveReadLimit=t,n}function aj(e,t={}){typeof t.size<"u"&&pn(e,{size:t.size});const n=Xe(e,t);return Ai(n,t)}function sj(e,t={}){let n=e;if(typeof t.size<"u"&&(pn(n,{size:t.size}),n=ii(n)),n.length>1||n[0]>1)throw new c1(n);return!!n[0]}function Zn(e,t={}){typeof t.size<"u"&&pn(e,{size:t.size});const n=Xe(e,t);return Kn(n,t)}function Xu(e,t={}){let n=e;return typeof t.size<"u"&&(pn(n,{size:t.size}),n=ii(n,{dir:"right"})),new TextDecoder().decode(n)}function ds(e,t){const n=typeof t=="string"?mn(t):t,r=Zu(n);if(ke(n)===0&&e.length>0)throw new Lu;if(ke(t)&&ke(t)<32)throw new Dp({data:typeof t=="string"?t:Xe(t),params:e,size:ke(t)});let i=0;const A=[];for(let o=0;o<e.length;++o){const a=e[o];r.setPosition(i);const[s,c]=aA(r,a,{staticPosition:0});i+=c,A.push(s)}return A}function aA(e,t,{staticPosition:n}){const r=Vu(t.type);if(r){const[i,A]=r;return uj(e,{...t,type:A},{length:i,staticPosition:n})}if(t.type==="tuple")return fj(e,t,{staticPosition:n});if(t.type==="address")return cj(e);if(t.type==="bool")return gj(e);if(t.type.startsWith("bytes"))return lj(e,t,{staticPosition:n});if(t.type.startsWith("uint")||t.type.startsWith("int"))return hj(e,t);if(t.type==="string")return dj(e,{staticPosition:n});throw new i1(t.type,{docsPath:"/docs/contract/decodeAbiParameters"})}const om=32,eg=32;function cj(e){const t=e.readBytes(32);return[Io(Xe(em(t,-20))),32]}function uj(e,t,{length:n,staticPosition:r}){if(!n){const o=Zn(e.readBytes(eg)),a=r+o,s=a+om;e.setPosition(a);const c=Zn(e.readBytes(om)),u=Co(t);let g=0;const l=[];for(let h=0;h<c;++h){e.setPosition(s+(u?h*32:g));const[d,I]=aA(e,t,{staticPosition:s});g+=I,l.push(d)}return e.setPosition(r+32),[l,32]}if(Co(t)){const o=Zn(e.readBytes(eg)),a=r+o,s=[];for(let c=0;c<n;++c){e.setPosition(a+c*32);const[u]=aA(e,t,{staticPosition:a});s.push(u)}return e.setPosition(r+32),[s,32]}let i=0;const A=[];for(let o=0;o<n;++o){const[a,s]=aA(e,t,{staticPosition:r+i});i+=s,A.push(a)}return[A,i]}function gj(e){return[sj(e.readBytes(32),{size:32}),32]}function lj(e,t,{staticPosition:n}){const[r,i]=t.type.split("bytes");if(!i){const o=Zn(e.readBytes(32));e.setPosition(n+o);const a=Zn(e.readBytes(32));if(a===0)return e.setPosition(n+32),["0x",32];const s=e.readBytes(a);return e.setPosition(n+32),[Xe(s),32]}return[Xe(e.readBytes(Number.parseInt(i),32)),32]}function hj(e,t){const n=t.type.startsWith("int"),r=Number.parseInt(t.type.split("int")[1]||"256"),i=e.readBytes(32);return[r>48?aj(i,{signed:n}):Zn(i,{signed:n}),32]}function fj(e,t,{staticPosition:n}){const r=t.components.length===0||t.components.some(({name:o})=>!o),i=r?[]:{};let A=0;if(Co(t)){const o=Zn(e.readBytes(eg)),a=n+o;for(let s=0;s<t.components.length;++s){const c=t.components[s];e.setPosition(a+A);const[u,g]=aA(e,c,{staticPosition:a});A+=g,i[r?s:c?.name]=u}return e.setPosition(n+32),[i,32]}for(let o=0;o<t.components.length;++o){const a=t.components[o],[s,c]=aA(e,a,{staticPosition:n});i[r?o:a?.name]=s,A+=c}return[i,A]}function dj(e,{staticPosition:t}){const n=Zn(e.readBytes(32)),r=t+n;e.setPosition(r);const i=Zn(e.readBytes(32));if(i===0)return e.setPosition(t+32),["",32];const A=e.readBytes(i,32),o=Xu(ii(A));return e.setPosition(t+32),[o,32]}function Co(e){const{type:t}=e;if(t==="string"||t==="bytes"||t.endsWith("[]"))return!0;if(t==="tuple")return e.components?.some(Co);const n=Vu(e.type);return!!(n&&Co({...e,type:n[1]}))}function Ij(e){const{abi:t,data:n}=e,r=po(n,0,4);if(r==="0x")throw new Lu;const A=[...t||[],rj,ij].find(o=>o.type==="error"&&r===mo(In(o)));if(!A)throw new xp(r,{docsPath:"/docs/contract/decodeErrorResult"});return{abiItem:A,args:"inputs"in A&&A.inputs&&A.inputs.length>0?ds(A.inputs,po(n,4)):void 0,errorName:A.name}}const yn=(e,t,n)=>JSON.stringify(e,(r,i)=>typeof i=="bigint"?i.toString():i,n);function am({abiItem:e,args:t,includeFunctionName:n=!0,includeName:r=!1}){if("name"in e&&"inputs"in e&&e.inputs)return`${n?e.name:""}(${e.inputs.map((i,A)=>`${r&&i.name?`${i.name}: `:""}${typeof t[A]=="object"?yn(t[A]):t[A]}`).join(", ")})`}const pj={gwei:9,wei:18},sm={ether:-9,wei:9};function cm(e,t){let n=e.toString();const r=n.startsWith("-");r&&(n=n.slice(1)),n=n.padStart(t,"0");let[i,A]=[n.slice(0,n.length-t),n.slice(n.length-t)];return A=A.replace(/(0+)$/,""),`${r?"-":""}${i||"0"}${A?`.${A}`:""}`}function um(e,t="wei"){return cm(e,pj[t])}function tn(e,t="wei"){return cm(e,sm[t])}class mj extends z{constructor({address:t}){super(`State for account "${t}" is set multiple times.`,{name:"AccountStateConflictError"})}}class Cj extends z{constructor(){super("state and stateDiff are set on the same account.",{name:"StateAssignmentConflictError"})}}function Is(e){const t=Object.entries(e).map(([r,i])=>i===void 0||i===!1?null:[r,i]).filter(Boolean),n=t.reduce((r,[i])=>Math.max(r,i.length),0);return t.map(([r,i])=>` ${`${r}:`.padEnd(n+1)} ${i}`).join(` `)}class Bj extends z{constructor(){super(["Cannot specify both a `gasPrice` and a `maxFeePerGas`/`maxPriorityFeePerGas`.","Use `maxFeePerGas`/`maxPriorityFeePerGas` for EIP-1559 compatible networks, and `gasPrice` for others."].join(` `),{name:"FeeConflictError"})}}class Ej extends z{constructor({v:t}){super(`Invalid \`v\` value "${t}". Expected 27 or 28.`,{name:"InvalidLegacyVError"})}}class yj extends z{constructor({transaction:t}){super("Cannot infer a transaction type from provided transaction.",{metaMessages:["Provided Transaction:","{",Is(t),"}","","To infer the type, either provide:","- a `type` to the Transaction, or","- an EIP-1559 Transaction wit