@etherna/sdk-js
Version:
Etherna SDKs for operations on the network
1,466 lines • 613 kB
JavaScript
var At = Object.defineProperty;
var Rt = (t, e, n) => e in t ? At(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
var Fe = (t, e, n) => (Rt(t, typeof e != "symbol" ? e + "" : e, n), n);
const SPAN_SIZE = 8, MAX_SPAN_LENGTH = 4294967295, SECTION_SIZE = 32, BRANCHES = 128, CHUNK_SIZE = 4096, MAX_CHUNK_PAYLOAD_SIZE = 4096, SEGMENT_SIZE = 32, SEGMENT_PAIR_SIZE = 64, HASH_SIZE = 32, MIN_PAYLOAD_SIZE = 1, MAX_PAYLOAD_SIZE = 4096, CAC_SPAN_OFFSET = 0, CAC_PAYLOAD_OFFSET = 8, IDENTIFIER_SIZE = 32, SIGNATURE_SIZE = 65, SOC_IDENTIFIER_OFFSET = 0, SOC_SIGNATURE_OFFSET = 32, SOC_SPAN_OFFSET = 97, SOC_PAYLOAD_OFFSET = 105, ADDRESS_HEX_LENGTH = 64, PSS_TARGET_HEX_LENGTH_MAX = 6, PUBKEY_HEX_LENGTH = 66, BATCH_ID_HEX_LENGTH = 64, REFERENCE_HEX_LENGTH = 64, ENCRYPTED_REFERENCE_HEX_LENGTH = 128, REFERENCE_BYTES_LENGTH = 32, ENCRYPTED_REFERENCE_BYTES_LENGTH = 64, BUCKET_DEPTH = 16, STAMPS_DEPTH_MIN = 17, STAMPS_DEPTH_MAX = 255, TAGS_LIMIT_MIN = 1, TAGS_LIMIT_MAX = 1e3, FEED_INDEX_HEX_LENGTH = 16;
function execTyped(t, e) {
return t.exec(e)?.groups;
}
const tupleRegex = /^tuple(?<array>(\[(\d*)\])*)$/;
function formatAbiParameter(t) {
let e = t.type;
if (tupleRegex.test(t.type) && "components" in t) {
e = "(";
const n = t.components.length;
for (let s = 0; s < n; s++) {
const o = t.components[s];
e += formatAbiParameter(o), s < n - 1 && (e += ", ");
}
const r = execTyped(tupleRegex, t.type);
return e += `)${r?.array ?? ""}`, formatAbiParameter({
...t,
type: e
});
}
return "indexed" in t && t.indexed && (e = `${e} indexed`), t.name ? `${e} ${t.name}` : e;
}
function formatAbiParameters(t) {
let e = "";
const n = t.length;
for (let r = 0; r < n; r++) {
const s = t[r];
e += formatAbiParameter(s), r !== n - 1 && (e += ", ");
}
return e;
}
function formatAbiItem$1(t) {
return t.type === "function" ? `function ${t.name}(${formatAbiParameters(t.inputs)})${t.stateMutability && t.stateMutability !== "nonpayable" ? ` ${t.stateMutability}` : ""}${t.outputs.length ? ` returns (${formatAbiParameters(t.outputs)})` : ""}` : t.type === "event" ? `event ${t.name}(${formatAbiParameters(t.inputs)})` : t.type === "error" ? `error ${t.name}(${formatAbiParameters(t.inputs)})` : t.type === "constructor" ? `constructor(${formatAbiParameters(t.inputs)})${t.stateMutability === "payable" ? " payable" : ""}` : t.type === "fallback" ? "fallback()" : "receive() external payable";
}
function getAction(t, e, n) {
return (r) => t[e.name || n]?.(r) ?? e(t, r);
}
function formatAbiItem(t, { includeName: e = !1 } = {}) {
if (t.type !== "function" && t.type !== "event" && t.type !== "error")
throw new InvalidDefinitionTypeError(t.type);
return `${t.name}(${formatAbiParams(t.inputs, { includeName: e })})`;
}
function formatAbiParams(t, { includeName: e = !1 } = {}) {
return t ? t.map((n) => formatAbiParam(n, { includeName: e })).join(e ? ", " : ",") : "";
}
function formatAbiParam(t, { includeName: e }) {
return t.type.startsWith("tuple") ? `(${formatAbiParams(t.components, { includeName: e })})${t.type.slice(5)}` : t.type + (e && t.name ? ` ${t.name}` : "");
}
function isHex(t, { strict: e = !0 } = {}) {
return !t || typeof t != "string" ? !1 : e ? /^0x[0-9a-fA-F]*$/.test(t) : t.startsWith("0x");
}
function size$1(t) {
return isHex(t, { strict: !1 }) ? Math.ceil((t.length - 2) / 2) : t.length;
}
const version = "2.9.16", getContractAddress = (t) => t, getUrl = (t) => t, getVersion = () => `viem@${version}`;
class BaseError extends Error {
constructor(e, n = {}) {
super(), 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: "ViemError"
}), Object.defineProperty(this, "version", {
enumerable: !0,
configurable: !0,
writable: !0,
value: getVersion()
});
const r = n.cause instanceof BaseError ? n.cause.details : n.cause?.message ? n.cause.message : n.details, s = n.cause instanceof BaseError && n.cause.docsPath || n.docsPath;
this.message = [
e || "An error occurred.",
"",
...n.metaMessages ? [...n.metaMessages, ""] : [],
...s ? [
`Docs: https://viem.sh${s}${n.docsSlug ? `#${n.docsSlug}` : ""}`
] : [],
...r ? [`Details: ${r}`] : [],
`Version: ${this.version}`
].join(`
`), n.cause && (this.cause = n.cause), this.details = r, this.docsPath = s, this.metaMessages = n.metaMessages, this.shortMessage = e;
}
walk(e) {
return walk(this, e);
}
}
function walk(t, e) {
return e?.(t) ? t : t && typeof t == "object" && "cause" in t ? walk(t.cause, e) : e ? null : t;
}
class AbiConstructorNotFoundError extends BaseError {
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
}), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "AbiConstructorNotFoundError"
});
}
}
class AbiConstructorParamsNotFoundError extends BaseError {
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
}), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "AbiConstructorParamsNotFoundError"
});
}
}
class AbiDecodingDataSizeTooSmallError extends BaseError {
constructor({ data: e, params: n, size: r }) {
super([`Data size of ${r} bytes is too small for given parameters.`].join(`
`), {
metaMessages: [
`Params: (${formatAbiParams(n, { includeName: !0 })})`,
`Data: ${e} (${r} bytes)`
]
}), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "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 = r;
}
}
class AbiDecodingZeroDataError extends BaseError {
constructor() {
super('Cannot decode zero data ("0x") with ABI parameters.'), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "AbiDecodingZeroDataError"
});
}
}
class AbiEncodingArrayLengthMismatchError extends BaseError {
constructor({ expectedLength: e, givenLength: n, type: r }) {
super([
`ABI encoding array length mismatch for type ${r}.`,
`Expected length: ${e}`,
`Given length: ${n}`
].join(`
`)), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "AbiEncodingArrayLengthMismatchError"
});
}
}
class AbiEncodingBytesSizeMismatchError extends BaseError {
constructor({ expectedSize: e, value: n }) {
super(`Size of bytes "${n}" (bytes${size$1(n)}) does not match expected size (bytes${e}).`), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "AbiEncodingBytesSizeMismatchError"
});
}
}
class AbiEncodingLengthMismatchError extends BaseError {
constructor({ expectedLength: e, givenLength: n }) {
super([
"ABI encoding params/values length mismatch.",
`Expected length (params): ${e}`,
`Given length (values): ${n}`
].join(`
`)), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "AbiEncodingLengthMismatchError"
});
}
}
class AbiErrorSignatureNotFoundError extends BaseError {
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
}), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "AbiErrorSignatureNotFoundError"
}), Object.defineProperty(this, "signature", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), this.signature = e;
}
}
class AbiEventSignatureEmptyTopicsError extends BaseError {
constructor({ docsPath: e }) {
super("Cannot extract event signature from empty topics.", {
docsPath: e
}), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "AbiEventSignatureEmptyTopicsError"
});
}
}
class AbiEventSignatureNotFoundError extends BaseError {
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
}), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "AbiEventSignatureNotFoundError"
});
}
}
class AbiEventNotFoundError extends BaseError {
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
}), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "AbiEventNotFoundError"
});
}
}
class AbiFunctionNotFoundError extends BaseError {
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
}), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "AbiFunctionNotFoundError"
});
}
}
class AbiFunctionOutputsNotFoundError extends BaseError {
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
}), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "AbiFunctionOutputsNotFoundError"
});
}
}
class AbiItemAmbiguityError extends BaseError {
constructor(e, n) {
super("Found ambiguous types in overloaded ABI items.", {
metaMessages: [
`\`${e.type}\` in \`${formatAbiItem(e.abiItem)}\`, and`,
`\`${n.type}\` in \`${formatAbiItem(n.abiItem)}\``,
"",
"These types encode differently and cannot be distinguished at runtime.",
"Remove one of the ambiguous items in the ABI."
]
}), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "AbiItemAmbiguityError"
});
}
}
class BytesSizeMismatchError extends BaseError {
constructor({ expectedSize: e, givenSize: n }) {
super(`Expected bytes${e}, got bytes${n}.`), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "BytesSizeMismatchError"
});
}
}
class DecodeLogDataMismatch extends BaseError {
constructor({ abiItem: e, data: n, params: r, size: s }) {
super([
`Data size of ${s} bytes is too small for non-indexed event parameters.`
].join(`
`), {
metaMessages: [
`Params: (${formatAbiParams(r, { includeName: !0 })})`,
`Data: ${n} (${s} bytes)`
]
}), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "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 = r, this.size = s;
}
}
class DecodeLogTopicsMismatch extends BaseError {
constructor({ abiItem: e, param: n }) {
super([
`Expected a topic for indexed event parameter${n.name ? ` "${n.name}"` : ""} on event "${formatAbiItem(e, { includeName: !0 })}".`
].join(`
`)), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "DecodeLogTopicsMismatch"
}), Object.defineProperty(this, "abiItem", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), this.abiItem = e;
}
}
class InvalidAbiEncodingTypeError extends BaseError {
constructor(e, { docsPath: n }) {
super([
`Type "${e}" is not a valid encoding type.`,
"Please provide a valid ABI type."
].join(`
`), { docsPath: n }), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "InvalidAbiEncodingType"
});
}
}
class InvalidAbiDecodingTypeError extends BaseError {
constructor(e, { docsPath: n }) {
super([
`Type "${e}" is not a valid decoding type.`,
"Please provide a valid ABI type."
].join(`
`), { docsPath: n }), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "InvalidAbiDecodingType"
});
}
}
class InvalidArrayError extends BaseError {
constructor(e) {
super([`Value "${e}" is not a valid array.`].join(`
`)), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "InvalidArrayError"
});
}
}
class InvalidDefinitionTypeError extends BaseError {
constructor(e) {
super([
`"${e}" is not a valid definition type.`,
'Valid types: "function", "event", "error"'
].join(`
`)), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "InvalidDefinitionTypeError"
});
}
}
class FilterTypeNotSupportedError extends BaseError {
constructor(e) {
super(`Filter type "${e}" is not supported.`), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "FilterTypeNotSupportedError"
});
}
}
class SliceOffsetOutOfBoundsError extends BaseError {
constructor({ offset: e, position: n, size: r }) {
super(`Slice ${n === "start" ? "starting" : "ending"} at offset "${e}" is out-of-bounds (size: ${r}).`), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "SliceOffsetOutOfBoundsError"
});
}
}
class SizeExceedsPaddingSizeError extends BaseError {
constructor({ size: e, targetSize: n, type: r }) {
super(`${r.charAt(0).toUpperCase()}${r.slice(1).toLowerCase()} size (${e}) exceeds padding size (${n}).`), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "SizeExceedsPaddingSizeError"
});
}
}
class InvalidBytesLengthError extends BaseError {
constructor({ size: e, targetSize: n, type: r }) {
super(`${r.charAt(0).toUpperCase()}${r.slice(1).toLowerCase()} is expected to be ${n} ${r} long, but is ${e} ${r} long.`), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "InvalidBytesLengthError"
});
}
}
function pad(t, { dir: e, size: n = 32 } = {}) {
return typeof t == "string" ? padHex(t, { dir: e, size: n }) : padBytes(t, { dir: e, size: n });
}
function padHex(t, { dir: e, size: n = 32 } = {}) {
if (n === null)
return t;
const r = t.replace("0x", "");
if (r.length > n * 2)
throw new SizeExceedsPaddingSizeError({
size: Math.ceil(r.length / 2),
targetSize: n,
type: "hex"
});
return `0x${r[e === "right" ? "padEnd" : "padStart"](n * 2, "0")}`;
}
function padBytes(t, { dir: e, size: n = 32 } = {}) {
if (n === null)
return t;
if (t.length > n)
throw new SizeExceedsPaddingSizeError({
size: t.length,
targetSize: n,
type: "bytes"
});
const r = new Uint8Array(n);
for (let s = 0; s < n; s++) {
const o = e === "right";
r[o ? s : n - s - 1] = t[o ? s : t.length - s - 1];
}
return r;
}
class IntegerOutOfRangeError extends BaseError {
constructor({ max: e, min: n, signed: r, size: s, value: o }) {
super(`Number "${o}" is not in safe ${s ? `${s * 8}-bit ${r ? "signed" : "unsigned"} ` : ""}integer range ${e ? `(${n} to ${e})` : `(above ${n})`}`), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "IntegerOutOfRangeError"
});
}
}
class InvalidBytesBooleanError extends BaseError {
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.`), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "InvalidBytesBooleanError"
});
}
}
class SizeOverflowError extends BaseError {
constructor({ givenSize: e, maxSize: n }) {
super(`Size cannot exceed ${n} bytes. Given size: ${e} bytes.`), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "SizeOverflowError"
});
}
}
function trim(t, { dir: e = "left" } = {}) {
let n = typeof t == "string" ? t.replace("0x", "") : t, r = 0;
for (let s = 0; s < n.length - 1 && n[e === "left" ? s : n.length - s - 1].toString() === "0"; s++)
r++;
return n = e === "left" ? n.slice(r) : n.slice(0, n.length - r), typeof t == "string" ? (n.length === 1 && e === "right" && (n = `${n}0`), `0x${n.length % 2 === 1 ? `0${n}` : n}`) : n;
}
function assertSize(t, { size: e }) {
if (size$1(t) > e)
throw new SizeOverflowError({
givenSize: size$1(t),
maxSize: e
});
}
function hexToBigInt(t, e = {}) {
const { signed: n } = e;
e.size && assertSize(t, { size: e.size });
const r = BigInt(t);
if (!n)
return r;
const s = (t.length - 2) / 2, o = (1n << BigInt(s) * 8n - 1n) - 1n;
return r <= o ? r : r - BigInt(`0x${"f".padStart(s * 2, "f")}`) - 1n;
}
function hexToNumber(t, e = {}) {
return Number(hexToBigInt(t, e));
}
const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (t, e) => e.toString(16).padStart(2, "0"));
function toHex(t, e = {}) {
return typeof t == "number" || typeof t == "bigint" ? numberToHex(t, e) : typeof t == "string" ? stringToHex(t, e) : typeof t == "boolean" ? boolToHex(t, e) : bytesToHex(t, e);
}
function boolToHex(t, e = {}) {
const n = `0x${Number(t)}`;
return typeof e.size == "number" ? (assertSize(n, { size: e.size }), pad(n, { size: e.size })) : n;
}
function bytesToHex(t, e = {}) {
let n = "";
for (let s = 0; s < t.length; s++)
n += hexes[t[s]];
const r = `0x${n}`;
return typeof e.size == "number" ? (assertSize(r, { size: e.size }), pad(r, { dir: "right", size: e.size })) : r;
}
function numberToHex(t, e = {}) {
const { signed: n, size: r } = e, s = BigInt(t);
let o;
r ? n ? o = (1n << BigInt(r) * 8n - 1n) - 1n : o = 2n ** (BigInt(r) * 8n) - 1n : typeof t == "number" && (o = BigInt(Number.MAX_SAFE_INTEGER));
const a = typeof o == "bigint" && n ? -o - 1n : 0;
if (o && s > o || s < a) {
const Q = typeof t == "bigint" ? "n" : "";
throw new IntegerOutOfRangeError({
max: o ? `${o}${Q}` : void 0,
min: `${a}${Q}`,
signed: n,
size: r,
value: `${t}${Q}`
});
}
const c = `0x${(n && s < 0 ? (1n << BigInt(r * 8)) + BigInt(s) : s).toString(16)}`;
return r ? pad(c, { size: r }) : c;
}
const encoder$1 = /* @__PURE__ */ new TextEncoder();
function stringToHex(t, e = {}) {
const n = encoder$1.encode(t);
return bytesToHex(n, e);
}
const encoder = /* @__PURE__ */ new TextEncoder();
function toBytes$1(t, e = {}) {
return typeof t == "number" || typeof t == "bigint" ? numberToBytes(t, e) : typeof t == "boolean" ? boolToBytes(t, e) : isHex(t) ? hexToBytes(t, e) : stringToBytes(t, e);
}
function boolToBytes(t, e = {}) {
const n = new Uint8Array(1);
return n[0] = Number(t), typeof e.size == "number" ? (assertSize(n, { size: e.size }), pad(n, { size: e.size })) : n;
}
const charCodeMap = {
zero: 48,
nine: 57,
A: 65,
F: 70,
a: 97,
f: 102
};
function charCodeToBase16(t) {
if (t >= charCodeMap.zero && t <= charCodeMap.nine)
return t - charCodeMap.zero;
if (t >= charCodeMap.A && t <= charCodeMap.F)
return t - (charCodeMap.A - 10);
if (t >= charCodeMap.a && t <= charCodeMap.f)
return t - (charCodeMap.a - 10);
}
function hexToBytes(t, e = {}) {
let n = t;
e.size && (assertSize(n, { size: e.size }), n = pad(n, { dir: "right", size: e.size }));
let r = n.slice(2);
r.length % 2 && (r = `0${r}`);
const s = r.length / 2, o = new Uint8Array(s);
for (let a = 0, c = 0; a < s; a++) {
const Q = charCodeToBase16(r.charCodeAt(c++)), B = charCodeToBase16(r.charCodeAt(c++));
if (Q === void 0 || B === void 0)
throw new BaseError(`Invalid byte sequence ("${r[c - 2]}${r[c - 1]}" in "${r}").`);
o[a] = Q * 16 + B;
}
return o;
}
function numberToBytes(t, e) {
const n = numberToHex(t, e);
return hexToBytes(n);
}
function stringToBytes(t, e = {}) {
const n = encoder.encode(t);
return typeof e.size == "number" ? (assertSize(n, { size: e.size }), pad(n, { dir: "right", size: e.size })) : n;
}
function number(t) {
if (!Number.isSafeInteger(t) || t < 0)
throw new Error(`Wrong positive integer: ${t}`);
}
function bytes(t, ...e) {
if (!(t instanceof Uint8Array))
throw new Error("Expected Uint8Array");
if (e.length > 0 && !e.includes(t.length))
throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`);
}
function exists(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 output(t, e) {
bytes(t);
const n = e.outputLen;
if (t.length < n)
throw new Error(`digestInto() expects output buffer of length at least ${n}`);
}
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1), _32n = /* @__PURE__ */ BigInt(32);
function fromBig(t, e = !1) {
return e ? { h: Number(t & U32_MASK64), l: Number(t >> _32n & U32_MASK64) } : { h: Number(t >> _32n & U32_MASK64) | 0, l: Number(t & U32_MASK64) | 0 };
}
function split$1(t, e = !1) {
let n = new Uint32Array(t.length), r = new Uint32Array(t.length);
for (let s = 0; s < t.length; s++) {
const { h: o, l: a } = fromBig(t[s], e);
[n[s], r[s]] = [o, a];
}
return [n, r];
}
const rotlSH = (t, e, n) => t << n | e >>> 32 - n, rotlSL = (t, e, n) => e << n | t >>> 32 - n, rotlBH = (t, e, n) => e << n - 32 | t >>> 64 - n, rotlBL = (t, e, n) => t << n - 32 | e >>> 64 - n;
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
const u8a = (t) => t instanceof Uint8Array, u32 = (t) => new Uint32Array(t.buffer, t.byteOffset, Math.floor(t.byteLength / 4)), createView = (t) => new DataView(t.buffer, t.byteOffset, t.byteLength), rotr = (t, e) => t << 32 - e | t >>> e, isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
if (!isLE)
throw new Error("Non little-endian hardware is not supported");
function utf8ToBytes(t) {
if (typeof t != "string")
throw new Error(`utf8ToBytes expected string, got ${typeof t}`);
return new Uint8Array(new TextEncoder().encode(t));
}
function toBytes(t) {
if (typeof t == "string" && (t = utf8ToBytes(t)), !u8a(t))
throw new Error(`expected Uint8Array, got ${typeof t}`);
return t;
}
class Hash {
// Safe version that clones internal state
clone() {
return this._cloneInto();
}
}
function wrapConstructor(t) {
const e = (r) => t().update(toBytes(r)).digest(), n = t();
return e.outputLen = n.outputLen, e.blockLen = n.blockLen, e.create = () => t(), e;
}
const [SHA3_PI, SHA3_ROTL, _SHA3_IOTA] = [[], [], []], _0n = /* @__PURE__ */ BigInt(0), _1n = /* @__PURE__ */ BigInt(1), _2n = /* @__PURE__ */ BigInt(2), _7n = /* @__PURE__ */ BigInt(7), _256n = /* @__PURE__ */ BigInt(256), _0x71n = /* @__PURE__ */ BigInt(113);
for (let t = 0, e = _1n, n = 1, r = 0; t < 24; t++) {
[n, r] = [r, (2 * n + 3 * r) % 5], SHA3_PI.push(2 * (5 * r + n)), SHA3_ROTL.push((t + 1) * (t + 2) / 2 % 64);
let s = _0n;
for (let o = 0; o < 7; o++)
e = (e << _1n ^ (e >> _7n) * _0x71n) % _256n, e & _2n && (s ^= _1n << (_1n << /* @__PURE__ */ BigInt(o)) - _1n);
_SHA3_IOTA.push(s);
}
const [SHA3_IOTA_H, SHA3_IOTA_L] = /* @__PURE__ */ split$1(_SHA3_IOTA, !0), rotlH = (t, e, n) => n > 32 ? rotlBH(t, e, n) : rotlSH(t, e, n), rotlL = (t, e, n) => n > 32 ? rotlBL(t, e, n) : rotlSL(t, e, n);
function keccakP(t, e = 24) {
const n = new Uint32Array(10);
for (let r = 24 - e; r < 24; r++) {
for (let a = 0; a < 10; a++)
n[a] = t[a] ^ t[a + 10] ^ t[a + 20] ^ t[a + 30] ^ t[a + 40];
for (let a = 0; a < 10; a += 2) {
const c = (a + 8) % 10, Q = (a + 2) % 10, B = n[Q], g = n[Q + 1], l = rotlH(B, g, 1) ^ n[c], E = rotlL(B, g, 1) ^ n[c + 1];
for (let I = 0; I < 50; I += 10)
t[a + I] ^= l, t[a + I + 1] ^= E;
}
let s = t[2], o = t[3];
for (let a = 0; a < 24; a++) {
const c = SHA3_ROTL[a], Q = rotlH(s, o, c), B = rotlL(s, o, c), g = SHA3_PI[a];
s = t[g], o = t[g + 1], t[g] = Q, t[g + 1] = B;
}
for (let a = 0; a < 50; a += 10) {
for (let c = 0; c < 10; c++)
n[c] = t[a + c];
for (let c = 0; c < 10; c++)
t[a + c] ^= ~n[(c + 2) % 10] & n[(c + 4) % 10];
}
t[0] ^= SHA3_IOTA_H[r], t[1] ^= SHA3_IOTA_L[r];
}
n.fill(0);
}
class Keccak extends Hash {
// NOTE: we accept arguments in bytes instead of bits here.
constructor(e, n, r, s = !1, o = 24) {
if (super(), this.blockLen = e, this.suffix = n, this.outputLen = r, this.enableXOF = s, this.rounds = o, this.pos = 0, this.posOut = 0, this.finished = !1, this.destroyed = !1, number(r), 0 >= this.blockLen || this.blockLen >= 200)
throw new Error("Sha3 supports only keccak-f1600 function");
this.state = new Uint8Array(200), this.state32 = u32(this.state);
}
keccak() {
keccakP(this.state32, this.rounds), this.posOut = 0, this.pos = 0;
}
update(e) {
exists(this);
const { blockLen: n, state: r } = this;
e = toBytes(e);
const s = e.length;
for (let o = 0; o < s; ) {
const a = Math.min(n - this.pos, s - o);
for (let c = 0; c < a; c++)
r[this.pos++] ^= e[o++];
this.pos === n && this.keccak();
}
return this;
}
finish() {
if (this.finished)
return;
this.finished = !0;
const { state: e, suffix: n, pos: r, blockLen: s } = this;
e[r] ^= n, n & 128 && r === s - 1 && this.keccak(), e[s - 1] ^= 128, this.keccak();
}
writeInto(e) {
exists(this, !1), bytes(e), this.finish();
const n = this.state, { blockLen: r } = this;
for (let s = 0, o = e.length; s < o; ) {
this.posOut >= r && this.keccak();
const a = Math.min(r - this.posOut, o - s);
e.set(n.subarray(this.posOut, this.posOut + a), s), this.posOut += a, s += a;
}
return e;
}
xofInto(e) {
if (!this.enableXOF)
throw new Error("XOF is not possible for this instance");
return this.writeInto(e);
}
xof(e) {
return number(e), this.xofInto(new Uint8Array(e));
}
digestInto(e) {
if (output(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: r, outputLen: s, rounds: o, enableXOF: a } = this;
return e || (e = new Keccak(n, r, s, a, o)), e.state32.set(this.state32), e.pos = this.pos, e.posOut = this.posOut, e.finished = this.finished, e.rounds = o, e.suffix = r, e.outputLen = s, e.enableXOF = a, e.destroyed = this.destroyed, e;
}
}
const gen = (t, e, n) => wrapConstructor(() => new Keccak(e, t, n)), keccak_256 = /* @__PURE__ */ gen(1, 136, 256 / 8);
function keccak256(t, e) {
const n = e || "hex", r = keccak_256(isHex(t, { strict: !1 }) ? toBytes$1(t) : t);
return n === "bytes" ? r : toHex(r);
}
const hash = (t) => keccak256(toBytes$1(t));
function hashSignature(t) {
return hash(t);
}
function normalizeSignature(t) {
let e = !0, n = "", r = 0, s = "", o = !1;
for (let a = 0; a < t.length; a++) {
const c = t[a];
if (["(", ")", ","].includes(c) && (e = !0), c === "(" && r++, c === ")" && r--, !!e) {
if (r === 0) {
if (c === " " && ["event", "function", ""].includes(s))
s = "";
else if (s += c, c === ")") {
o = !0;
break;
}
continue;
}
if (c === " ") {
t[a - 1] !== "," && n !== "," && n !== ",(" && (n = "", e = !1);
continue;
}
s += c, n += c;
}
}
if (!o)
throw new BaseError("Unable to normalize signature.");
return s;
}
const toSignature = (t) => {
const e = typeof t == "string" ? t : formatAbiItem$1(t);
return normalizeSignature(e);
};
function toSignatureHash(t) {
return hashSignature(toSignature(t));
}
const toEventSelector = toSignatureHash;
class InvalidAddressError extends BaseError {
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."
]
}), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "InvalidAddressError"
});
}
}
class LruMap 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;
}
}
function checksumAddress(t, e) {
const n = t.substring(2).toLowerCase(), r = keccak256(stringToBytes(n), "bytes"), s = n.split("");
for (let o = 0; o < 40; o += 2)
r[o >> 1] >> 4 >= 8 && s[o] && (s[o] = s[o].toUpperCase()), (r[o >> 1] & 15) >= 8 && s[o + 1] && (s[o + 1] = s[o + 1].toUpperCase());
return `0x${s.join("")}`;
}
const addressRegex = /^0x[a-fA-F0-9]{40}$/, isAddressCache = /* @__PURE__ */ new LruMap(8192);
function isAddress(t, e) {
const { strict: n = !0 } = e ?? {};
if (isAddressCache.has(t))
return isAddressCache.get(t);
const r = addressRegex.test(t) ? t.toLowerCase() === t ? !0 : n ? checksumAddress(t) === t : !0 : !1;
return isAddressCache.set(t, r), r;
}
function concat(t) {
return typeof t[0] == "string" ? concatHex(t) : concatBytes(t);
}
function concatBytes(t) {
let e = 0;
for (const s of t)
e += s.length;
const n = new Uint8Array(e);
let r = 0;
for (const s of t)
n.set(s, r), r += s.length;
return n;
}
function concatHex(t) {
return `0x${t.reduce((e, n) => e + n.replace("0x", ""), "")}`;
}
function slice(t, e, n, { strict: r } = {}) {
return isHex(t, { strict: !1 }) ? sliceHex(t, e, n, {
strict: r
}) : sliceBytes(t, e, n, {
strict: r
});
}
function assertStartOffset(t, e) {
if (typeof e == "number" && e > 0 && e > size$1(t) - 1)
throw new SliceOffsetOutOfBoundsError({
offset: e,
position: "start",
size: size$1(t)
});
}
function assertEndOffset(t, e, n) {
if (typeof e == "number" && typeof n == "number" && size$1(t) !== n - e)
throw new SliceOffsetOutOfBoundsError({
offset: n,
position: "end",
size: size$1(t)
});
}
function sliceBytes(t, e, n, { strict: r } = {}) {
assertStartOffset(t, e);
const s = t.slice(e, n);
return r && assertEndOffset(s, e, n), s;
}
function sliceHex(t, e, n, { strict: r } = {}) {
assertStartOffset(t, e);
const s = `0x${t.replace("0x", "").slice((e ?? 0) * 2, (n ?? t.length) * 2)}`;
return r && assertEndOffset(s, e, n), s;
}
function encodeAbiParameters(t, e) {
if (t.length !== e.length)
throw new AbiEncodingLengthMismatchError({
expectedLength: t.length,
givenLength: e.length
});
const n = prepareParams({
params: t,
values: e
}), r = encodeParams(n);
return r.length === 0 ? "0x" : r;
}
function prepareParams({ params: t, values: e }) {
const n = [];
for (let r = 0; r < t.length; r++)
n.push(prepareParam({ param: t[r], value: e[r] }));
return n;
}
function prepareParam({ param: t, value: e }) {
const n = getArrayComponents(t.type);
if (n) {
const [r, s] = n;
return encodeArray(e, { length: r, param: { ...t, type: s } });
}
if (t.type === "tuple")
return encodeTuple(e, {
param: t
});
if (t.type === "address")
return encodeAddress(e);
if (t.type === "bool")
return encodeBool(e);
if (t.type.startsWith("uint") || t.type.startsWith("int")) {
const r = t.type.startsWith("int");
return encodeNumber(e, { signed: r });
}
if (t.type.startsWith("bytes"))
return encodeBytes(e, { param: t });
if (t.type === "string")
return encodeString(e);
throw new InvalidAbiEncodingTypeError(t.type, {
docsPath: "/docs/contract/encodeAbiParameters"
});
}
function encodeParams(t) {
let e = 0;
for (let o = 0; o < t.length; o++) {
const { dynamic: a, encoded: c } = t[o];
a ? e += 32 : e += size$1(c);
}
const n = [], r = [];
let s = 0;
for (let o = 0; o < t.length; o++) {
const { dynamic: a, encoded: c } = t[o];
a ? (n.push(numberToHex(e + s, { size: 32 })), r.push(c), s += size$1(c)) : n.push(c);
}
return concat([...n, ...r]);
}
function encodeAddress(t) {
if (!isAddress(t))
throw new InvalidAddressError({ address: t });
return { dynamic: !1, encoded: padHex(t.toLowerCase()) };
}
function encodeArray(t, { length: e, param: n }) {
const r = e === null;
if (!Array.isArray(t))
throw new InvalidArrayError(t);
if (!r && t.length !== e)
throw new AbiEncodingArrayLengthMismatchError({
expectedLength: e,
givenLength: t.length,
type: `${n.type}[${e}]`
});
let s = !1;
const o = [];
for (let a = 0; a < t.length; a++) {
const c = prepareParam({ param: n, value: t[a] });
c.dynamic && (s = !0), o.push(c);
}
if (r || s) {
const a = encodeParams(o);
if (r) {
const c = numberToHex(o.length, { size: 32 });
return {
dynamic: !0,
encoded: o.length > 0 ? concat([c, a]) : c
};
}
if (s)
return { dynamic: !0, encoded: a };
}
return {
dynamic: !1,
encoded: concat(o.map(({ encoded: a }) => a))
};
}
function encodeBytes(t, { param: e }) {
const [, n] = e.type.split("bytes"), r = size$1(t);
if (!n) {
let s = t;
return r % 32 !== 0 && (s = padHex(s, {
dir: "right",
size: Math.ceil((t.length - 2) / 2 / 32) * 32
})), {
dynamic: !0,
encoded: concat([padHex(numberToHex(r, { size: 32 })), s])
};
}
if (r !== parseInt(n))
throw new AbiEncodingBytesSizeMismatchError({
expectedSize: parseInt(n),
value: t
});
return { dynamic: !1, encoded: padHex(t, { dir: "right" }) };
}
function encodeBool(t) {
if (typeof t != "boolean")
throw new BaseError(`Invalid boolean value: "${t}" (type: ${typeof t}). Expected: \`true\` or \`false\`.`);
return { dynamic: !1, encoded: padHex(boolToHex(t)) };
}
function encodeNumber(t, { signed: e }) {
return {
dynamic: !1,
encoded: numberToHex(t, {
size: 32,
signed: e
})
};
}
function encodeString(t) {
const e = stringToHex(t), n = Math.ceil(size$1(e) / 32), r = [];
for (let s = 0; s < n; s++)
r.push(padHex(slice(e, s * 32, (s + 1) * 32), {
dir: "right"
}));
return {
dynamic: !0,
encoded: concat([
padHex(numberToHex(size$1(e), { size: 32 })),
...r
])
};
}
function encodeTuple(t, { param: e }) {
let n = !1;
const r = [];
for (let s = 0; s < e.components.length; s++) {
const o = e.components[s], a = Array.isArray(t) ? s : o.name, c = prepareParam({
param: o,
value: t[a]
});
r.push(c), c.dynamic && (n = !0);
}
return {
dynamic: n,
encoded: n ? encodeParams(r) : concat(r.map(({ encoded: s }) => s))
};
}
function getArrayComponents(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 toFunctionSelector = (t) => slice(toSignatureHash(t), 0, 4);
function getAbiItem(t) {
const { abi: e, args: n = [], name: r } = t, s = isHex(r, { strict: !1 }), o = e.filter((c) => s ? c.type === "function" ? toFunctionSelector(c) === r : c.type === "event" ? toEventSelector(c) === r : !1 : "name" in c && c.name === r);
if (o.length === 0)
return;
if (o.length === 1)
return o[0];
let a;
for (const c of o) {
if (!("inputs" in c))
continue;
if (!n || n.length === 0) {
if (!c.inputs || c.inputs.length === 0)
return c;
continue;
}
if (!c.inputs || c.inputs.length === 0 || c.inputs.length !== n.length)
continue;
if (n.every((B, g) => {
const l = "inputs" in c && c.inputs[g];
return l ? isArgOfType(B, l) : !1;
})) {
if (a && "inputs" in a && a.inputs) {
const B = getAmbiguousTypes(c.inputs, a.inputs, n);
if (B)
throw new AbiItemAmbiguityError({
abiItem: c,
type: B[0]
}, {
abiItem: a,
type: B[1]
});
}
a = c;
}
}
return a || o[0];
}
function isArgOfType(t, e) {
const n = typeof t, r = e.type;
switch (r) {
case "address":
return isAddress(t, { strict: !1 });
case "bool":
return n === "boolean";
case "function":
return n === "string";
case "string":
return n === "string";
default:
return r === "tuple" && "components" in e ? Object.values(e.components).every((s, o) => isArgOfType(Object.values(t)[o], s)) : /^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" || t instanceof Uint8Array : /[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(r) ? Array.isArray(t) && t.every((s) => isArgOfType(s, {
...e,
// Pop off `[]` or `[M]` from end of type
type: r.replace(/(\[[0-9]{0,}\])$/, "")
})) : !1;
}
}
function getAmbiguousTypes(t, e, n) {
for (const r in t) {
const s = t[r], o = e[r];
if (s.type === "tuple" && o.type === "tuple" && "components" in s && "components" in o)
return getAmbiguousTypes(s.components, o.components, n[r]);
const a = [s.type, o.type];
if (a.includes("address") && a.includes("bytes20") ? !0 : a.includes("address") && a.includes("string") ? isAddress(n[r], { strict: !1 }) : a.includes("address") && a.includes("bytes") ? isAddress(n[r], { strict: !1 }) : !1)
return a;
}
}
const docsPath$4 = "/docs/contract/encodeEventTopics";
function encodeEventTopics(t) {
const { abi: e, eventName: n, args: r } = t;
let s = e[0];
if (n) {
const Q = getAbiItem({ abi: e, name: n });
if (!Q)
throw new AbiEventNotFoundError(n, { docsPath: docsPath$4 });
s = Q;
}
if (s.type !== "event")
throw new AbiEventNotFoundError(void 0, { docsPath: docsPath$4 });
const o = formatAbiItem(s), a = toEventSelector(o);
let c = [];
if (r && "inputs" in s) {
const Q = s.inputs?.filter((g) => "indexed" in g && g.indexed), B = Array.isArray(r) ? r : Object.values(r).length > 0 ? Q?.map((g) => r[g.name]) ?? [] : [];
B.length > 0 && (c = Q?.map((g, l) => Array.isArray(B[l]) ? B[l].map((E, I) => encodeArg({ param: g, value: B[l][I] })) : B[l] ? encodeArg({ param: g, value: B[l] }) : null) ?? []);
}
return [a, ...c];
}
function encodeArg({ param: t, value: e }) {
if (t.type === "string" || t.type === "bytes")
return keccak256(toBytes$1(e));
if (t.type === "tuple" || t.type.match(/^(.*)\[(\d+)?\]$/))
throw new FilterTypeNotSupportedError(t.type);
return encodeAbiParameters([t], [e]);
}
function createFilterRequestScope(t, { method: e }) {
const n = {};
return t.transport.type === "fallback" && t.transport.onResponse?.(({ method: r, response: s, status: o, transport: a }) => {
o === "success" && e === r && (n[s] = a.request);
}), (r) => n[r] || t.request;
}
async function createContractEventFilter(t, e) {
const { address: n, abi: r, args: s, eventName: o, fromBlock: a, strict: c, toBlock: Q } = e, B = createFilterRequestScope(t, {
method: "eth_newFilter"
}), g = o ? encodeEventTopics({
abi: r,
args: s,
eventName: o
}) : void 0, l = await t.request({
method: "eth_newFilter",
params: [
{
address: n,
fromBlock: typeof a == "bigint" ? numberToHex(a) : a,
toBlock: typeof Q == "bigint" ? numberToHex(Q) : Q,
topics: g
}
]
});
return {
abi: r,
args: s,
eventName: o,
id: l,
request: B(l),
strict: !!c,
type: "event"
};
}
function parseAccount(t) {
return typeof t == "string" ? { address: t, type: "json-rpc" } : t;
}
const docsPath$3 = "/docs/contract/encodeFunctionData";
function prepareEncodeFunctionData(t) {
const { abi: e, args: n, functionName: r } = t;
let s = e[0];
if (r) {
const o = getAbiItem({
abi: e,
args: n,
name: r
});
if (!o)
throw new AbiFunctionNotFoundError(r, { docsPath: docsPath$3 });
s = o;
}
if (s.type !== "function")
throw new AbiFunctionNotFoundError(void 0, { docsPath: docsPath$3 });
return {
abi: [s],
functionName: toFunctionSelector(formatAbiItem(s))
};
}
function encodeFunctionData(t) {
const { args: e } = t, { abi: n, functionName: r } = t.abi.length === 1 && t.functionName?.startsWith("0x") ? t : prepareEncodeFunctionData(t), s = n[0], o = r, a = "inputs" in s && s.inputs ? encodeAbiParameters(s.inputs, e ?? []) : void 0;
return concatHex([o, a ?? "0x"]);
}
const panicReasons = {
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."
}, solidityError = {
inputs: [
{
name: "message",
type: "string"
}
],
name: "Error",
type: "error"
}, solidityPanic = {
inputs: [
{
name: "reason",
type: "uint256"
}
],
name: "Panic",
type: "error"
};
class NegativeOffsetError extends BaseError {
constructor({ offset: e }) {
super(`Offset \`${e}\` cannot be negative.`), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "NegativeOffsetError"
});
}
}
class PositionOutOfBoundsError extends BaseError {
constructor({ length: e, position: n }) {
super(`Position \`${n}\` is out of bounds (\`0 < position < ${e}\`).`), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "PositionOutOfBoundsError"
});
}
}
class RecursiveReadLimitExceededError extends BaseError {
constructor({ count: e, limit: n }) {
super(`Recursive read limit of \`${n}\` exceeded (recursive read count: \`${e}\`).`), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "RecursiveReadLimitExceededError"
});
}
}
const staticCursor = {
bytes: new Uint8Array(),
dataView: new DataView(new ArrayBuffer(0)),
position: 0,
positionReadCount: /* @__PURE__ */ new Map(),
recursiveReadCount: 0,
recursiveReadLimit: 1 / 0,
assertReadLimit() {
if (this.recursiveReadCount >= this.recursiveReadLimit)
throw new RecursiveReadLimitExceededError({
count: this.recursiveReadCount + 1,
limit: this.recursiveReadLimit
});
},
assertPosition(t) {
if (t < 0 || t > this.bytes.length - 1)
throw new PositionOutOfBoundsError({
length: this.bytes.length,
position: t
});
},
decrementPosition(t) {
if (t < 0)
throw new NegativeOffsetError({ offset: t });
const e = this.position - t;
this.assertPosition(e), this.position = e;
},
getReadCount(t) {
return this.positionReadCount.get(t || this.position) || 0;
},
incrementPosition(t) {
if (t < 0)
throw new NegativeOffsetError({ offset: t });
const e = this.position + t;
this.assertPosition(e), this.position = e;
},
inspectByte(t) {
const e = t ?? this.position;
return this.assertPosition(e), this.bytes[e];
},
inspectBytes(t, e) {
const n = e ?? this.position;
return this.assertPosition(n + t - 1), this.bytes.subarray(n, n + t);
},
inspectUint8(t) {
const e = t ?? this.position;
return this.assertPosition(e), this.bytes[e];
},
inspectUint16(t) {
const e = t ?? this.position;
return this.assertPosition(e + 1), this.dataView.getUint16(e);
},
inspectUint24(t) {
const e = t ?? this.position;
return this.assertPosition(e + 2), (this.dataView.getUint16(e) << 8) + this.dataView.getUint8(e + 2);
},
inspectUint32(t) {
const e = t ?? this.position;
return this.assertPosition(e + 3), this.dataView.getUint32(e);
},
pushByte(t) {
this.assertPosition(this.position), this.bytes[this.position] = t, this.position++;
},
pushBytes(t) {
this.assertPosition(this.position + t.length - 1), this.bytes.set(t, this.position), this.position += t.length;
},
pushUint8(t) {
this.assertPosition(this.position), this.bytes[this.position] = t, this.position++;
},
pushUint16(t) {
this.assertPosition(this.position + 1), this.dataView.setUint16(this.position, t), this.position += 2;
},
pushUint24(t) {
this.assertPosition(this.position + 2), this.dataView.setUint16(this.position, t >> 8), this.dataView.setUint8(this.position + 2, t & 255), this.position += 3;
},
pushUint32(t) {
this.assertPosition(this.position + 3), this.dataView.setUint32(this.position, t), this.position += 4;
},
readByte() {
this.assertReadLimit(), this._touch();
const t = this.inspectByte();
return this.position++, t;
},
readBytes(t, e) {
this.assertReadLimit(), this._touch();
const n = this.inspectBytes(t);
return this.position += e ?? t, n;
},
readUint8() {
this.assertReadLimit(), this._touch();
const t = this.inspectUint8();
return this.position += 1, t;
},
readUint16() {
this.assertReadLimit(), this._touch();
const t = this.inspectUint16();
return this.position += 2, t;
},
readUint24() {
this.assertReadLimit(), this._touch();
const t = this.inspectUint24();
return this.position += 3, t;
},
readUint32() {
this.assertReadLimit(), this._touch();
const t = this.inspectUint32();
return this.position += 4, t;
},
get remaining() {
return this.bytes.length - this.position;
},
setPosition(t) {
const e = this.position;
return this.assertPosition(t), this.position = t, () => this.position = e;
},
_touch() {
if (this.recursiveReadLimit === 1 / 0)
return;
const t = this.getReadCount();
this.positionReadCount.set(this.position, t + 1), t > 0 && this.recursiveReadCount++;
}
};
function createCursor(t, { recursiveReadLimit: e = 8192 } = {}) {
const n = Object.create(staticCursor);
return n.bytes = t, n.dataView = new DataView(t.buffer, t.byteOffset, t.byteLength), n.positionReadCount = /* @__PURE__ */ new Map(), n.recur