import{s as u,t as O,i as v,f as S,j as te,S as C,n as g,q as h,l as ne,r as re,k as w,b as oe}from"./toBytes-HmJa1ieM.js";import{B as c,L,s as se}from"./page-BQckNtVy.js";import{o as ie}from"./notifications-YV6F4GS-.js";import{L as ae}from"./api-CJCsP-f4.js";function A(e,{includeName:t=!1}={}){if(e.type!=="function"&&e.type!=="event"&&e.type!=="error")throw new me(e.type);return`${e.name}(${E(e.inputs,{includeName:t})})`}function E(e,{includeName:t=!1}={}){return e?e.map(n=>ce(n,{includeName:t})).join(t?", ":","):""}function ce(e,{includeName:t}){return e.type.startsWith("tuple")?`(${E(e.components,{includeName:t})})${e.type.slice(5)}`:e.type+(t&&e.name?` ${e.name}`:"")}class _e extends c{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 et extends c{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 tt extends c{constructor({data:t,params:n,size:r}){super([`Data size of ${r} bytes is too small for given parameters.`].join(`
`),{metaMessages:[`Params: (${E(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 nt extends c{constructor({cause:t}={}){super('Cannot decode zero data ("0x") with ABI parameters.',{name:"AbiDecodingZeroDataError",cause:t})}}class ue extends c{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 de extends c{constructor({expectedSize:t,value:n}){super(`Size of bytes "${n}" (bytes${u(n)}) does not match expected size (bytes${t}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class fe extends c{constructor({expectedLength:t,givenLength:n}){super(["ABI encoding params/values length mismatch.",`Expected length (params): ${t}`,`Given length (values): ${n}`].join(`
`),{name:"AbiEncodingLengthMismatchError"})}}class rt extends c{constructor(t,{docsPath:n}){super([`Arguments (\`args\`) were provided to "${t}", but "${t}" on the ABI does not contain any parameters (\`inputs\`).`,"Cannot encode error result without knowing what the parameter types are.","Make sure you are using the correct ABI and that the inputs exist on it."].join(`
`),{docsPath:n,name:"AbiErrorInputsNotFoundError"})}}class ot extends c{constructor(t,{docsPath:n}={}){super([`Error ${t?`"${t}" `:""}not found on ABI.`,"Make sure you are using the correct ABI and that the error exists on it."].join(`
`),{docsPath:n,name:"AbiErrorNotFoundError"})}}class st extends c{constructor(t,{docsPath:n,cause:r}){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://4byte.sourcify.dev/?q=${t}.`].join(`
`),{docsPath:n,name:"AbiErrorSignatureNotFoundError",cause:r}),Object.defineProperty(this,"signature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.signature=t}}class it extends c{constructor({docsPath:t}){super("Cannot extract event signature from empty topics.",{docsPath:t,name:"AbiEventSignatureEmptyTopicsError"})}}class at extends c{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://4byte.sourcify.dev/?q=${t}.`].join(`
`),{docsPath:n,name:"AbiEventSignatureNotFoundError"})}}class ct extends c{constructor(t,{docsPath:n}={}){super([`Event ${t?`"${t}" `:""}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 k extends c{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 ut extends c{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 dt extends c{constructor(t,{docsPath:n}){super([`Encoded function signature "${t}" 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://4byte.sourcify.dev/?q=${t}.`].join(`
`),{docsPath:n,name:"AbiFunctionSignatureNotFoundError"})}}class pe extends c{constructor(t,n){super("Found ambiguous types in overloaded ABI items.",{metaMessages:[`\`${t.type}\` in \`${A(t.abiItem)}\`, and`,`\`${n.type}\` in \`${A(n.abiItem)}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."],name:"AbiItemAmbiguityError"})}}class le extends c{constructor({expectedSize:t,givenSize:n}){super(`Expected bytes${t}, got bytes${n}.`,{name:"BytesSizeMismatchError"})}}class ft extends c{constructor({abiItem:t,data:n,params:r,size:o}){super([`Data size of ${o} bytes is too small for non-indexed event parameters.`].join(`
`),{metaMessages:[`Params: (${E(r,{includeName:!0})})`,`Data:   ${n} (${o} 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=o}}class pt extends c{constructor({abiItem:t,param:n}){super([`Expected a topic for indexed event parameter${n.name?` "${n.name}"`:""} on event "${A(t,{includeName:!0})}".`].join(`
`),{name:"DecodeLogTopicsMismatch"}),Object.defineProperty(this,"abiItem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abiItem=t}}class ye extends c{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 lt extends c{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 he extends c{constructor(t){super([`Value "${t}" is not a valid array.`].join(`
`),{name:"InvalidArrayError"})}}class me extends c{constructor(t){super([`"${t}" is not a valid definition type.`,'Valid types: "function", "event", "error"'].join(`
`),{name:"InvalidDefinitionTypeError"})}}class yt extends c{constructor(t){super(`Type "${t}" is not supported for packed encoding.`,{name:"UnsupportedPackedAbiType"})}}function f(e,t){const n=t||"hex",r=ae(v(e,{strict:!1})?O(e):e);return n==="bytes"?r:S(r)}const ge=e=>f(O(e));function be(e){return ge(e)}function Ae(e){let t=!0,n="",r=0,o="",i=!1;for(let s=0;s<e.length;s++){const a=e[s];if(["(",")",","].includes(a)&&(t=!0),a==="("&&r++,a===")"&&r--,!!t){if(r===0){if(a===" "&&["event","function",""].includes(o))o="";else if(o+=a,a===")"){i=!0;break}continue}if(a===" "){e[s-1]!==","&&n!==","&&n!==",("&&(n="",t=!1);continue}o+=a,n+=a}}if(!i)throw new c("Unable to normalize signature.");return o}const Ee=e=>{const t=typeof e=="string"?e:ie(e);return Ae(t)};function H(e){return be(Ee(e))}const xe=H;class T extends c{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"})}}const x=new L(8192);function W(e,t){if(x.has(`${e}.${t}`))return x.get(`${e}.${t}`);const n=e.substring(2).toLowerCase(),r=f(te(n),"bytes"),o=n.split("");for(let s=0;s<40;s+=2)r[s>>1]>>4>=8&&o[s]&&(o[s]=o[s].toUpperCase()),(r[s>>1]&15)>=8&&o[s+1]&&(o[s+1]=o[s+1].toUpperCase());const i=`0x${o.join("")}`;return x.set(`${e}.${t}`,i),i}function ht(e,t){if(!m(e,{strict:!1}))throw new T({address:e});return W(e,t)}const $e=/^0x[a-fA-F0-9]{40}$/,$=new L(8192);function m(e,t){const{strict:n=!0}=t??{},r=`${e}.${n}`;if($.has(r))return $.get(r);const o=$e.test(e)?e.toLowerCase()===e?!0:n?W(e)===e:!0:!1;return $.set(r,o),o}function p(e){return typeof e[0]=="string"?U(e):we(e)}function we(e){let t=0;for(const o of e)t+=o.length;const n=new Uint8Array(t);let r=0;for(const o of e)n.set(o,r),r+=o.length;return n}function U(e){return`0x${e.reduce((t,n)=>t+n.replace("0x",""),"")}`}function R(e,t,n,{strict:r}={}){return v(e,{strict:!1})?ve(e,t,n,{strict:r}):Ie(e,t,n,{strict:r})}function q(e,t){if(typeof t=="number"&&t>0&&t>u(e)-1)throw new C({offset:t,position:"start",size:u(e)})}function V(e,t,n){if(typeof t=="number"&&typeof n=="number"&&u(e)!==n-t)throw new C({offset:n,position:"end",size:u(e)})}function Ie(e,t,n,{strict:r}={}){q(e,t);const o=e.slice(t,n);return r&&V(o,t,n),o}function ve(e,t,n,{strict:r}={}){q(e,t);const o=`0x${e.replace("0x","").slice((t??0)*2,(n??e.length)*2)}`;return r&&V(o,t,n),o}const mt=/^(.*)\[([0-9]*)\]$/,Se=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,G=/^(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 P(e,t){if(e.length!==t.length)throw new fe({expectedLength:e.length,givenLength:t.length});const n=Te({params:e,values:t}),r=D(n);return r.length===0?"0x":r}function Te({params:e,values:t}){const n=[];for(let r=0;r<e.length;r++)n.push(B({param:e[r],value:t[r]}));return n}function B({param:e,value:t}){const n=ke(e.type);if(n){const[r,o]=n;return Be(t,{length:r,param:{...e,type:o}})}if(e.type==="tuple")return ze(t,{param:e});if(e.type==="address")return Pe(t);if(e.type==="bool")return Me(t);if(e.type.startsWith("uint")||e.type.startsWith("int")){const r=e.type.startsWith("int"),[,,o="256"]=G.exec(e.type)??[];return je(t,{signed:r,size:Number(o)})}if(e.type.startsWith("bytes"))return De(t,{param:e});if(e.type==="string")return Fe(t);throw new ye(e.type,{docsPath:"/docs/contract/encodeAbiParameters"})}function D(e){let t=0;for(let i=0;i<e.length;i++){const{dynamic:s,encoded:a}=e[i];s?t+=32:t+=u(a)}const n=[],r=[];let o=0;for(let i=0;i<e.length;i++){const{dynamic:s,encoded:a}=e[i];s?(n.push(g(t+o,{size:32})),r.push(a),o+=u(a)):n.push(a)}return p([...n,...r])}function Pe(e){if(!m(e))throw new T({address:e});return{dynamic:!1,encoded:h(e.toLowerCase())}}function Be(e,{length:t,param:n}){const r=t===null;if(!Array.isArray(e))throw new he(e);if(!r&&e.length!==t)throw new ue({expectedLength:t,givenLength:e.length,type:`${n.type}[${t}]`});let o=!1;const i=[];for(let s=0;s<e.length;s++){const a=B({param:n,value:e[s]});a.dynamic&&(o=!0),i.push(a)}if(r||o){const s=D(i);if(r){const a=g(i.length,{size:32});return{dynamic:!0,encoded:i.length>0?p([a,s]):a}}if(o)return{dynamic:!0,encoded:s}}return{dynamic:!1,encoded:p(i.map(({encoded:s})=>s))}}function De(e,{param:t}){const[,n]=t.type.split("bytes"),r=u(e);if(!n){let o=e;return r%32!==0&&(o=h(o,{dir:"right",size:Math.ceil((e.length-2)/2/32)*32})),{dynamic:!0,encoded:p([h(g(r,{size:32})),o])}}if(r!==Number.parseInt(n,10))throw new de({expectedSize:Number.parseInt(n,10),value:e});return{dynamic:!1,encoded:h(e,{dir:"right"})}}function Me(e){if(typeof e!="boolean")throw new c(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:h(ne(e))}}function je(e,{signed:t,size:n=256}){if(typeof n=="number"){const r=2n**(BigInt(n)-(t?1n:0n))-1n,o=t?-r-1n:0n;if(e>r||e<o)throw new re({max:r.toString(),min:o.toString(),signed:t,size:n/8,value:e.toString()})}return{dynamic:!1,encoded:g(e,{size:32,signed:t})}}function Fe(e){const t=w(e),n=Math.ceil(u(t)/32),r=[];for(let o=0;o<n;o++)r.push(h(R(t,o*32,(o+1)*32),{dir:"right"}));return{dynamic:!0,encoded:p([h(g(u(t),{size:32})),...r])}}function ze(e,{param:t}){let n=!1;const r=[];for(let o=0;o<t.components.length;o++){const i=t.components[o],s=Array.isArray(e)?o:i.name,a=B({param:i,value:e[s]});r.push(a),a.dynamic&&(n=!0)}return{dynamic:n,encoded:n?D(r):p(r.map(({encoded:o})=>o))}}function ke(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}const Y=e=>R(H(e),0,4);function Ne(e){const{abi:t,args:n=[],name:r}=e,o=v(r,{strict:!1}),i=t.filter(a=>o?a.type==="function"?Y(a)===r:a.type==="event"?xe(a)===r:!1:"name"in a&&a.name===r);if(i.length===0)return;if(i.length===1)return i[0];let s;for(const a of i){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((l,y)=>{const d="inputs"in a&&a.inputs[y];return d?I(l,d):!1})){if(s&&"inputs"in s&&s.inputs){const l=J(a.inputs,s.inputs,n);if(l)throw new pe({abiItem:a,type:l[0]},{abiItem:s,type:l[1]})}s=a}}return s||i[0]}function I(e,t){const n=typeof e,r=t.type;switch(r){case"address":return m(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((o,i)=>n==="object"&&I(Object.values(e)[i],o)):/^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(o=>I(o,{...t,type:r.replace(/(\[[0-9]{0,}\])$/,"")})):!1}}function J(e,t,n){for(const r in e){const o=e[r],i=t[r];if(o.type==="tuple"&&i.type==="tuple"&&"components"in o&&"components"in i)return J(o.components,i.components,n[r]);const s=[o.type,i.type];if(s.includes("address")&&s.includes("bytes20")?!0:s.includes("address")&&s.includes("string")?m(n[r],{strict:!1}):s.includes("address")&&s.includes("bytes")?m(n[r],{strict:!1}):!1)return s}}const N="/docs/contract/encodeFunctionData";function Oe(e){const{abi:t,args:n,functionName:r}=e;let o=t[0];if(r){const i=Ne({abi:t,args:n,name:r});if(!i)throw new k(r,{docsPath:N});o=i}if(o.type!=="function")throw new k(void 0,{docsPath:N});return{abi:[o],functionName:Y(A(o))}}function gt(e){const{args:t}=e,{abi:n,functionName:r}=e.abi.length===1&&e.functionName?.startsWith("0x")?e:Oe(e),o=n[0],i=r,s="inputs"in o&&o.inputs?P(o.inputs,t??[]):void 0;return U([i,s??"0x"])}const Ce=`Ethereum Signed Message:
`;function Le(e){const t=typeof e=="string"?w(e):typeof e.raw=="string"?e.raw:oe(e.raw),n=w(`${Ce}${u(t)}`);return p([n,t])}function bt(e,t){return f(Le(e),t)}class He extends c{constructor({domain:t}){super(`Invalid domain "${se(t)}".`,{metaMessages:["Must be a valid EIP-712 domain."]})}}class We extends c{constructor({primaryType:t,types:n}){super(`Invalid primary type \`${t}\` must be one of \`${JSON.stringify(Object.keys(n))}\`.`,{docsPath:"/api/glossary/Errors#typeddatainvalidprimarytypeerror",metaMessages:["Check that the primary type is a key in `types`."]})}}class Ue extends c{constructor({type:t}){super(`Struct type "${t}" is invalid.`,{metaMessages:["Struct type must not be a Solidity type."],name:"InvalidStructTypeError"})}}function Re(e){const{domain:t,message:n,primaryType:r,types:o}=e,i=(s,a)=>{for(const M of s){const{name:l,type:y}=M,d=a[l],j=y.match(G);if(j&&(typeof d=="number"||typeof d=="bigint")){const[_,b,ee]=j;g(d,{signed:b==="int",size:Number.parseInt(ee,10)/8})}if(y==="address"&&typeof d=="string"&&!m(d))throw new T({address:d});const F=y.match(Se);if(F){const[_,b]=F;if(b&&u(d)!==Number.parseInt(b,10))throw new le({expectedSize:Number.parseInt(b,10),givenSize:u(d)})}const z=o[y];z&&(Ve(y),i(z,d))}};if(o.EIP712Domain&&t){if(typeof t!="object")throw new He({domain:t});i(o.EIP712Domain,t)}if(r!=="EIP712Domain")if(o[r])i(o[r],n);else throw new We({primaryType:r,types:o})}function qe({domain:e}){return[typeof e?.name=="string"&&{name:"name",type:"string"},e?.version&&{name:"version",type:"string"},(typeof e?.chainId=="number"||typeof e?.chainId=="bigint")&&{name:"chainId",type:"uint256"},e?.verifyingContract&&{name:"verifyingContract",type:"address"},e?.salt&&{name:"salt",type:"bytes32"}].filter(Boolean)}function Ve(e){if(e==="address"||e==="bool"||e==="string"||e.startsWith("bytes")||e.startsWith("uint")||e.startsWith("int"))throw new Ue({type:e})}function At(e){const{domain:t={},message:n,primaryType:r}=e,o={EIP712Domain:qe({domain:t}),...e.types};Re({domain:t,message:n,primaryType:r,types:o});const i=["0x1901"];return t&&i.push(Ge({domain:t,types:o})),r!=="EIP712Domain"&&i.push(K({data:n,primaryType:r,types:o})),f(p(i))}function Ge({domain:e,types:t}){return K({data:e,primaryType:"EIP712Domain",types:t})}function K({data:e,primaryType:t,types:n}){const r=Z({data:e,primaryType:t,types:n});return f(r)}function Z({data:e,primaryType:t,types:n}){const r=[{type:"bytes32"}],o=[Ye({primaryType:t,types:n})];for(const i of n[t]){const[s,a]=X({types:n,name:i.name,type:i.type,value:e[i.name]});r.push(s),o.push(a)}return P(r,o)}function Ye({primaryType:e,types:t}){const n=S(Je({primaryType:e,types:t}));return f(n)}function Je({primaryType:e,types:t}){let n="";const r=Q({primaryType:e,types:t});r.delete(e);const o=[e,...Array.from(r).sort()];for(const i of o)n+=`${i}(${t[i].map(({name:s,type:a})=>`${a} ${s}`).join(",")})`;return n}function Q({primaryType:e,types:t},n=new Set){const o=e.match(/^\w*/u)?.[0];if(n.has(o)||t[o]===void 0)return n;n.add(o);for(const i of t[o])Q({primaryType:i.type,types:t},n);return n}function X({types:e,name:t,type:n,value:r}){if(e[n]!==void 0)return[{type:"bytes32"},f(Z({data:r,primaryType:n,types:e}))];if(n==="bytes")return[{type:"bytes32"},f(r)];if(n==="string")return[{type:"bytes32"},f(S(r))];if(n.lastIndexOf("]")===n.length-1){const o=n.slice(0,n.lastIndexOf("[")),i=r.map(s=>X({name:t,type:o,types:e,value:s}));return[{type:"bytes32"},f(P(i.map(([s])=>s),i.map(([,s])=>s)))]}return[{type:n},r]}export{ct as A,ve as B,dt as C,pt as D,ot as E,rt as F,he as G,p as H,lt as I,ht as J,fe as K,G as L,Se as M,le as N,mt as O,yt as U,At as a,P as b,nt as c,tt as d,gt as e,A as f,Ne as g,bt as h,ke as i,W as j,f as k,R as l,Y as m,st as n,U as o,m as p,T as q,it as r,Ie as s,xe as t,at as u,ft as v,k as w,ut as x,_e as y,et as z};
