@midcontract/protocol
Version:
Crypto payment protocol with escrow
1,639 lines • 571 kB
JavaScript
var ji = Object.defineProperty;
var Wi = (t, e, n) => e in t ? ji(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
var $ = (t, e, n) => Wi(t, typeof e != "symbol" ? e + "" : e, n);
const Vi = "1.0.5";
let de = class aa extends Error {
constructor(e, n = {}) {
var i;
const a = n.cause instanceof aa ? n.cause.details : (i = n.cause) != null && i.message ? n.cause.message : n.details, r = n.cause instanceof aa && 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@${Vi}`
].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 Qr = /^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/, es = /^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)?$/, ts = /^\(.+?\).*?$/, mr = /^tuple(?<array>(\[(\d*)\])*)$/;
function ra(t) {
let e = t.type;
if (mr.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 += ra(s), r < n - 1 && (e += ", ");
}
const a = He(mr, t.type);
return e += `)${(a == null ? void 0 : a.array) ?? ""}`, ra({
...t,
type: e
});
}
return "indexed" in t && t.indexed && (e = `${e} indexed`), t.name ? `${e} ${t.name}` : e;
}
function Ct(t) {
let e = "";
const n = t.length;
for (let a = 0; a < n; a++) {
const r = t[a];
e += ra(r), a !== n - 1 && (e += ", ");
}
return e;
}
function Zi(t) {
return t.type === "function" ? `function ${t.name}(${Ct(t.inputs)})${t.stateMutability && t.stateMutability !== "nonpayable" ? ` ${t.stateMutability}` : ""}${t.outputs.length ? ` returns (${Ct(t.outputs)})` : ""}` : t.type === "event" ? `event ${t.name}(${Ct(t.inputs)})` : t.type === "error" ? `error ${t.name}(${Ct(t.inputs)})` : t.type === "constructor" ? `constructor(${Ct(t.inputs)})${t.stateMutability === "payable" ? " payable" : ""}` : t.type === "fallback" ? "fallback()" : "receive() external payable";
}
const ns = /^error (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;
function Ji(t) {
return ns.test(t);
}
function Yi(t) {
return He(ns, t);
}
const as = /^event (?<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 = /^function (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)(?: (?<scope>external|public{1}))?(?: (?<stateMutability>pure|view|nonpayable|payable{1}))?(?: returns\s?\((?<returns>.*?)\))?$/;
function Qi(t) {
return rs.test(t);
}
function eo(t) {
return He(rs, t);
}
const ss = /^struct (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) \{(?<properties>.*?)\}$/;
function is(t) {
return ss.test(t);
}
function to(t) {
return He(ss, t);
}
const os = /^constructor\((?<parameters>.*?)\)(?:\s(?<stateMutability>payable{1}))?$/;
function no(t) {
return os.test(t);
}
function ao(t) {
return He(os, t);
}
const ro = /^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/;
function so(t) {
return ro.test(t);
}
const io = /^receive\(\) external payable$/;
function oo(t) {
return io.test(t);
}
const uo = /* @__PURE__ */ new Set(["indexed"]), sa = /* @__PURE__ */ new Set([
"calldata",
"memory",
"storage"
]);
class po 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 co 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 yo extends de {
constructor({ param: e }) {
super("Invalid ABI parameter.", {
details: e
}), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "InvalidParameterError"
});
}
}
class lo 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 mo 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 fo 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 bo 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 Nt 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 ho extends de {
constructor({ signature: e }) {
super("Unknown signature.", {
details: e
}), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "UnknownSignatureError"
});
}
}
class wo 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 go 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 To 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 vo(t, e) {
return e ? `${e}:${t}` : t;
}
const Ln = /* @__PURE__ */ new Map([
// Unnamed
["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" }],
// Named
["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" }],
// Indexed
[
"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 xo(t, e = {}) {
if (Qi(t)) {
const n = eo(t);
if (!n)
throw new Nt({ 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: sa,
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: sa,
structs: e,
type: "function"
}));
}
return {
name: n.name,
type: "function",
stateMutability: n.stateMutability ?? "nonpayable",
inputs: r,
outputs: i
};
}
if (Ki(t)) {
const n = Xi(t);
if (!n)
throw new Nt({ 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: uo,
structs: e,
type: "event"
}));
return { name: n.name, type: "event", inputs: r };
}
if (Ji(t)) {
const n = Yi(t);
if (!n)
throw new Nt({ 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 (no(t)) {
const n = ao(t);
if (!n)
throw new Nt({ 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 (so(t))
return { type: "fallback" };
if (oo(t))
return {
type: "receive",
stateMutability: "payable"
};
throw new ho({ signature: t });
}
const _o = /^(?<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$_]*))?$/, Eo = /^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/, Ao = /^u?int$/;
function je(t, e) {
var c, y;
const n = vo(t, e == null ? void 0 : e.type);
if (Ln.has(n))
return Ln.get(n);
const a = ts.test(t), r = He(a ? Eo : _o, t);
if (!r)
throw new yo({ param: t });
if (r.name && Mo(r.name))
throw new lo({ 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 (Ao.test(r.type))
u = `${r.type}256`;
else if (u = r.type, (e == null ? void 0 : e.type) !== "struct" && !us(u))
throw new co({ 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 mo({
param: t,
type: e == null ? void 0 : e.type,
modifier: r.modifier
});
if (sa.has(r.modifier) && !Co(u, !!r.array))
throw new fo({
param: t,
type: e == null ? void 0 : e.type,
modifier: r.modifier
});
}
const d = {
type: `${u}${r.array ?? ""}`,
...s,
...i,
...p
};
return Ln.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 To({ current: n, depth: a });
return e.push(n.trim()), e;
}
function us(t) {
return t === "address" || t === "bool" || t === "function" || t === "string" || Qr.test(t) || es.test(t);
}
const Io = /^(?: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 Mo(t) {
return t === "address" || t === "bool" || t === "function" || t === "string" || t === "tuple" || Qr.test(t) || es.test(t) || Io.test(t);
}
function Co(t, e) {
return e || t === "bytes" || t === "string" || t === "tuple";
}
function Po(t) {
const e = {}, n = t.length;
for (let i = 0; i < n; i++) {
const o = t[i];
if (!is(o))
continue;
const u = to(o);
if (!u)
throw new Nt({ 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 wo({ 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] = ps(u, e);
}
return a;
}
const So = /^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?$/;
function ps(t, e, n = /* @__PURE__ */ new Set()) {
const a = [], r = t.length;
for (let s = 0; s < r; s++) {
const i = t[s];
if (ts.test(i.type))
a.push(i);
else {
const u = He(So, i.type);
if (!(u != null && u.type))
throw new bo({ abiParameter: i });
const { array: p, type: d } = u;
if (d in e) {
if (n.has(d))
throw new go({ type: d });
a.push({
...i,
type: `tuple${p ?? ""}`,
components: ps(e[d] ?? [], e, /* @__PURE__ */ new Set([...n, d]))
});
} else if (us(d))
a.push(i);
else
throw new po({ type: d });
}
}
return a;
}
function ds(t) {
const e = Po(t), n = [], a = t.length;
for (let r = 0; r < a; r++) {
const s = t[r];
is(s) || n.push(xo(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 qo(t.type);
return `${t.name}(${_n(t.inputs, { includeName: e })})`;
}
function _n(t, { includeName: e = !1 } = {}) {
return t ? t.map((n) => No(n, { includeName: e })).join(e ? ", " : ",") : "";
}
function No(t, { includeName: e }) {
return t.type.startsWith("tuple") ? `(${_n(t.components, { includeName: e })})${t.type.slice(5)}` : t.type + (e && t.name ? ` ${t.name}` : "");
}
function ue(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 ue(t, { strict: !1 }) ? Math.ceil((t.length - 2) / 2) : t.length;
}
const cs = "2.20.0";
let dn = {
getDocsUrl: ({ docsBaseUrl: t, docsPath: e = "", docsSlug: n }) => e ? `${t ?? "https://viem.sh"}${e}${n ? `#${n}` : ""}` : void 0,
version: cs
};
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 = dn.getDocsUrl) == null ? void 0 : o.call(dn, { ...n, docsPath: r }), i = [
e || "An error occurred.",
"",
...n.metaMessages ? [...n.metaMessages, ""] : [],
...s ? [`Docs: ${s}`] : [],
...a ? [`Details: ${a}`] : [],
`Version: ${dn.version}`
].join(`
`);
super(i, n.cause ? { cause: n.cause } : void 0), Object.defineProperty(this, "details", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), Object.defineProperty(this, "docsPath", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), Object.defineProperty(this, "metaMessages", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), Object.defineProperty(this, "shortMessage", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), Object.defineProperty(this, "version", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "BaseError"
}), this.details = a, this.docsPath = r, this.metaMessages = n.metaMessages, this.name = n.name ?? this.name, this.shortMessage = e, this.version = cs;
}
walk(e) {
return ys(this, e);
}
}
function ys(t, e) {
return e != null && e(t) ? t : t && typeof t == "object" && "cause" in t ? ys(t.cause, e) : e ? null : t;
}
class Ro 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 fr 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 ls extends g {
constructor({ data: e, params: n, size: a }) {
super([`Data size of ${a} bytes is too small for given parameters.`].join(`
`), {
metaMessages: [
`Params: (${_n(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 En extends g {
constructor() {
super('Cannot decode zero data ("0x") with ABI parameters.', {
name: "AbiDecodingZeroDataError"
});
}
}
class ko 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 Bo 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 ms 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 fs 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 Do extends g {
constructor({ docsPath: e }) {
super("Cannot extract event signature from empty topics.", {
docsPath: e,
name: "AbiEventSignatureEmptyTopicsError"
});
}
}
class bs 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 br 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 wn 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 Fo 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 Oo 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 $o 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 hs 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: (${_n(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 An 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 Uo 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 zo 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 Lo extends g {
constructor(e) {
super([`Value "${e}" is not a valid array.`].join(`
`), {
name: "InvalidArrayError"
});
}
}
class qo extends g {
constructor(e) {
super([
`"${e}" is not a valid definition type.`,
'Valid types: "function", "event", "error"'
].join(`
`), { name: "InvalidDefinitionTypeError" });
}
}
class Ho extends g {
constructor(e) {
super(`Type "${e}" is not supported for packed encoding.`, {
name: "UnsupportedPackedAbiType"
});
}
}
class Go extends g {
constructor(e) {
super(`Filter type "${e}" is not supported.`, {
name: "FilterTypeNotSupportedError"
});
}
}
class ws 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 gs 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 hr 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 Ee(t, { dir: e, size: n = 32 } = {}) {
return typeof t == "string" ? Oe(t, { dir: e, size: n }) : jo(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 gs({
size: Math.ceil(a.length / 2),
targetSize: n,
type: "hex"
});
return `0x${a[e === "right" ? "padEnd" : "padStart"](n * 2, "0")}`;
}
function jo(t, { dir: e, size: n = 32 } = {}) {
if (n === null)
return t;
if (t.length > n)
throw new gs({
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 Wo 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 Vo 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 Zo extends g {
constructor({ givenSize: e, maxSize: n }) {
super(`Size cannot exceed ${n} bytes. Given size: ${e} bytes.`, { name: "SizeOverflowError" });
}
}
function In(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 we(t, { size: e }) {
if (V(t) > e)
throw new Zo({
givenSize: V(t),
maxSize: e
});
}
function $e(t, e = {}) {
const { signed: n } = e;
e.size && we(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 Ie(t, e = {}) {
return Number($e(t, e));
}
const Jo = /* @__PURE__ */ 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" ? Ra(t, e) : J(t, e);
}
function Ra(t, e = {}) {
const n = `0x${Number(t)}`;
return typeof e.size == "number" ? (we(n, { size: e.size }), Ee(n, { size: e.size })) : n;
}
function J(t, e = {}) {
let n = "";
for (let r = 0; r < t.length; r++)
n += Jo[t[r]];
const a = `0x${n}`;
return typeof e.size == "number" ? (we(a, { size: e.size }), Ee(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 Wo({
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 ? Ee(o, { size: a }) : o;
}
const Yo = /* @__PURE__ */ new TextEncoder();
function Ke(t, e = {}) {
const n = Yo.encode(t);
return J(n, e);
}
const Ko = /* @__PURE__ */ new TextEncoder();
function Ue(t, e = {}) {
return typeof t == "number" || typeof t == "bigint" ? Qo(t, e) : typeof t == "boolean" ? Xo(t, e) : ue(t) ? fe(t, e) : Je(t, e);
}
function Xo(t, e = {}) {
const n = new Uint8Array(1);
return n[0] = Number(t), typeof e.size == "number" ? (we(n, { size: e.size }), Ee(n, { size: e.size })) : n;
}
const ge = {
zero: 48,
nine: 57,
A: 65,
F: 70,
a: 97,
f: 102
};
function wr(t) {
if (t >= ge.zero && t <= ge.nine)
return t - ge.zero;
if (t >= ge.A && t <= ge.F)
return t - (ge.A - 10);
if (t >= ge.a && t <= ge.f)
return t - (ge.a - 10);
}
function fe(t, e = {}) {
let n = t;
e.size && (we(n, { size: e.size }), n = Ee(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 = wr(a.charCodeAt(o++)), p = wr(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 Qo(t, e) {
const n = N(t, e);
return fe(n);
}
function Je(t, e = {}) {
const n = Ko.encode(t);
return typeof e.size == "number" ? (we(n, { size: e.size }), Ee(n, { dir: "right", size: e.size })) : n;
}
function gn(t) {
if (!Number.isSafeInteger(t) || t < 0)
throw new Error(`positive integer expected, not ${t}`);
}
function eu(t) {
return t instanceof Uint8Array || t != null && typeof t == "object" && t.constructor.name === "Uint8Array";
}
function Kt(t, ...e) {
if (!eu(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 tu(t) {
if (typeof t != "function" || typeof t.create != "function")
throw new Error("Hash should be wrapped by utils.wrapConstructor");
gn(t.outputLen), gn(t.blockLen);
}
function lt(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 Ts(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 cn = /* @__PURE__ */ BigInt(2 ** 32 - 1), gr = /* @__PURE__ */ BigInt(32);
function nu(t, e = !1) {
return e ? { h: Number(t & cn), l: Number(t >> gr & cn) } : { h: Number(t >> gr & cn) | 0, l: Number(t & cn) | 0 };
}
function au(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 } = nu(t[r], e);
[n[r], a[r]] = [s, i];
}
return [n, a];
}
const ru = (t, e, n) => t << n | e >>> 32 - n, su = (t, e, n) => e << n | t >>> 32 - n, iu = (t, e, n) => e << n - 32 | t >>> 64 - n, ou = (t, e, n) => t << n - 32 | e >>> 64 - n, qn = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
const uu = (t) => new Uint32Array(t.buffer, t.byteOffset, Math.floor(t.byteLength / 4)), Hn = (t) => new DataView(t.buffer, t.byteOffset, t.byteLength), be = (t, e) => t << 32 - e | t >>> e, Tr = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68, pu = (t) => t << 24 & 4278190080 | t << 8 & 16711680 | t >>> 8 & 65280 | t >>> 24 & 255;
function vr(t) {
for (let e = 0; e < t.length; e++)
t[e] = pu(t[e]);
}
function du(t) {
if (typeof t != "string")
throw new Error(`utf8ToBytes expected string, got ${typeof t}`);
return new Uint8Array(new TextEncoder().encode(t));
}
function Mn(t) {
return typeof t == "string" && (t = du(t)), Kt(t), t;
}
function cu(...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 ka {
// Safe version that clones internal state
clone() {
return this._cloneInto();
}
}
function vs(t) {
const e = (a) => t().update(Mn(a)).digest(), n = t();
return e.outputLen = n.outputLen, e.blockLen = n.blockLen, e.create = () => t(), e;
}
function yu(t = 32) {
if (qn && typeof qn.getRandomValues == "function")
return qn.getRandomValues(new Uint8Array(t));
throw new Error("crypto.getRandomValues must be defined");
}
const xs = [], _s = [], Es = [], lu = /* @__PURE__ */ BigInt(0), Pt = /* @__PURE__ */ BigInt(1), mu = /* @__PURE__ */ BigInt(2), fu = /* @__PURE__ */ BigInt(7), bu = /* @__PURE__ */ BigInt(256), hu = /* @__PURE__ */ BigInt(113);
for (let t = 0, e = Pt, n = 1, a = 0; t < 24; t++) {
[n, a] = [a, (2 * n + 3 * a) % 5], xs.push(2 * (5 * a + n)), _s.push((t + 1) * (t + 2) / 2 % 64);
let r = lu;
for (let s = 0; s < 7; s++)
e = (e << Pt ^ (e >> fu) * hu) % bu, e & mu && (r ^= Pt << (Pt << /* @__PURE__ */ BigInt(s)) - Pt);
Es.push(r);
}
const [wu, gu] = /* @__PURE__ */ au(Es, !0), xr = (t, e, n) => n > 32 ? iu(t, e, n) : ru(t, e, n), _r = (t, e, n) => n > 32 ? ou(t, e, n) : su(t, e, n);
function Tu(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 = xr(p, d, 1) ^ n[o], y = _r(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 = _s[i], u = xr(r, s, o), p = _r(r, s, o), d = xs[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] ^= wu[a], t[1] ^= gu[a];
}
n.fill(0);
}
class Ba extends ka {
// NOTE: we accept arguments in bytes instead of bits here.
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, gn(a), 0 >= this.blockLen || this.blockLen >= 200)
throw new Error("Sha3 supports only keccak-f1600 function");
this.state = new Uint8Array(200), this.state32 = uu(this.state);
}
keccak() {
Tr || vr(this.state32), Tu(this.state32, this.rounds), Tr || vr(this.state32), this.posOut = 0, this.pos = 0;
}
update(e) {
lt(this);
const { blockLen: n, state: a } = this;
e = Mn(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) {
lt(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 gn(e), this.xofInto(new Uint8Array(e));
}
digestInto(e) {
if (Ts(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 Ba(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 vu = (t, e, n) => vs(() => new Ba(e, t, n)), xu = /* @__PURE__ */ vu(1, 136, 256 / 8);
function Z(t, e) {
const n = e || "hex", a = xu(ue(t, { strict: !1 }) ? Ue(t) : t);
return n === "bytes" ? a : ne(a);
}
const _u = (t) => Z(Ue(t));
function Eu(t) {
return _u(t);
}
function Au(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 Iu = (t) => {
const e = typeof t == "string" ? t : Zi(t);
return Au(e);
};
function As(t) {
return Eu(Iu(t));
}
const Da = As;
class Me 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 Fa 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 Gn = /* @__PURE__ */ new Fa(8192);
function Xt(t, e) {
if (Gn.has(`${t}.${e}`))
return Gn.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 Gn.set(`${t}.${e}`, s), s;
}
function Is(t, e) {
if (!pe(t, { strict: !1 }))
throw new Me({ address: t });
return Xt(t, e);
}
const Mu = /^0x[a-fA-F0-9]{40}$/, jn = /* @__PURE__ */ new Fa(8192);
function pe(t, e) {
const { strict: n = !0 } = e ?? {}, a = `${t}.${n}`;
if (jn.has(a))
return jn.get(a);
const r = Mu.test(t) ? t.toLowerCase() === t ? !0 : n ? Xt(t) === t : !0 : !1;
return jn.set(a, r), r;
}
function Ce(t) {
return typeof t[0] == "string" ? tt(t) : Cu(t);
}
function Cu(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 mt(t, e, n, { strict: a } = {}) {
return ue(t, { strict: !1 }) ? Ss(t, e, n, {
strict: a
}) : Ps(t, e, n, {
strict: a
});
}
function Ms(t, e) {
if (typeof e == "number" && e > 0 && e > V(t) - 1)
throw new ws({
offset: e,
position: "start",
size: V(t)
});
}
function Cs(t, e, n) {
if (typeof e == "number" && typeof n == "number" && V(t) !== n - e)
throw new ws({
offset: n,
position: "end",
size: V(t)
});
}
function Ps(t, e, n, { strict: a } = {}) {
Ms(t, e);
const r = t.slice(e, n);
return a && Cs(r, e, n), r;
}
function Ss(t, e, n, { strict: a } = {}) {
Ms(t, e);
const r = `0x${t.replace("0x", "").slice((e ?? 0) * 2, (n ?? t.length) * 2)}`;
return a && Cs(r, e, n), r;
}
function xt(t, e) {
if (t.length !== e.length)
throw new ms({
expectedLength: t.length,
givenLength: e.length
});
const n = Pu({
params: t,
values: e
}), a = $a(n);
return a.length === 0 ? "0x" : a;
}
function Pu({ params: t, values: e }) {
const n = [];
for (let a = 0; a < t.length; a++)
n.push(Oa({ param: t[a], value: e[a] }));
return n;
}
function Oa({ param: t, value: e }) {
const n = Ua(t.type);
if (n) {
const [a, r] = n;
return Nu(e, { length: a, param: { ...t, type: r } });
}
if (t.type === "tuple")
return Fu(e, {
param: t
});
if (t.type === "address")
return Su(e);
if (t.type === "bool")
return ku(e);
if (t.type.startsWith("uint") || t.type.startsWith("int")) {
const a = t.type.startsWith("int");
return Bu(e, { signed: a });
}
if (t.type.startsWith("bytes"))
return Ru(e, { param: t });
if (t.type === "string")
return Du(e);
throw new Uo(t.type, {
docsPath: "/docs/contract/encodeAbiParameters"
});
}
function $a(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 Ce([...n, ...a]);
}
function Su(t) {
if (!pe(t))
throw new Me({ address: t });
return { dynamic: !1, encoded: Oe(t.toLowerCase()) };
}
function Nu(t, { length: e, param: n }) {
const a = e === null;
if (!Array.isArray(t))
throw new Lo(t);
if (!a && t.length !== e)
throw new ko({
expectedLength: e,
givenLength: t.length,
type: `${n.type}[${e}]`
});
let r = !1;
const s = [];
for (let i = 0; i < t.length; i++) {
const o = Oa({ param: n, value: t[i] });
o.dynamic && (r = !0), s.push(o);
}
if (a || r) {
const i = $a(s);
if (a) {
const o = N(s.length, { size: 32 });
return {
dynamic: !0,
encoded: s.length > 0 ? Ce([o, i]) : o
};
}
if (r)
return { dynamic: !0, encoded: i };
}
return {
dynamic: !1,
encoded: Ce(s.map(({ encoded: i }) => i))
};
}
function Ru(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: Ce([Oe(N(a, { size: 32 })), r])
};
}
if (a !== Number.parseInt(n))
throw new Bo({
expectedSize: Number.parseInt(n),
value: t
});
return { dynamic: !1, encoded: Oe(t, { dir: "right" }) };
}
function ku(t) {
if (typeof t != "boolean")
throw new g(`Invalid boolean value: "${t}" (type: ${typeof t}). Expected: \`true\` or \`false\`.`);
return { dynamic: !1, encoded: Oe(Ra(t)) };
}
function Bu(t, { signed: e }) {
return {
dynamic: !1,
encoded: N(t, {
size: 32,
signed: e
})
};
}
function Du(t) {
const e = Ke(t), n = Math.ceil(V(e) / 32), a = [];
for (let r = 0; r < n; r++)
a.push(Oe(mt(e, r * 32, (r + 1) * 32), {
dir: "right"
}));
return {
dynamic: !0,
encoded: Ce([
Oe(N(V(e), { size: 32 })),
...a
])
};
}
function Fu(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 = Oa({
param: s,
value: t[i]
});
a.push(o), o.dynamic && (n = !0);
}
return {
dynamic: n,
encoded: n ? $a(a) : Ce(a.map(({ encoded: r }) => r))
};
}
function Ua(t) {
const e = t.match(/^(.*)\[(\d+)?\]$/);
return e ? (
// Return `null` if the array is dynamic.
[e[2] ? Number(e[2]) : null, e[1]]
) : void 0;
}
const Cn = (t) => mt(As(t), 0, 4);
function _t(t) {
const { abi: e, args: n = [], name: a } = t, r = ue(a, { strict: !1 }), s = e.filter((o) => r ? o.type === "function" ? Cn(o) === a : o.type === "event" ? Da(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 ? ia(p, c) : !1;
})) {
if (i && "inputs" in i && i.inputs) {
const p = Ns(o.inputs, i.inputs, n);
if (p)
throw new $o({
abiItem: o,
type: p[0]
}, {
abiItem: i,
type: p[1]
});
}
i = o;
}
}
return i || s[0];
}
function ia(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 === "s