@elizaos/plugin-story
Version:
Story Protocol plugin for elizaOS - enables IP registration, licensing, and terms attachment on Story Protocol
1,496 lines (1,466 loc) • 186 kB
JavaScript
import {
Hash,
abytes,
aexists,
anumber,
aoutput,
clean,
createHasher,
rotlBH,
rotlBL,
rotlSH,
rotlSL,
split,
swap32IfBE,
toBytes,
u32
} from "./chunk-C32RXCHU.js";
// node_modules/viem/node_modules/abitype/dist/esm/version.js
var version = "1.0.8";
// node_modules/viem/node_modules/abitype/dist/esm/errors.js
var BaseError = class _BaseError extends Error {
constructor(shortMessage, args = {}) {
const details = args.cause instanceof _BaseError ? args.cause.details : args.cause?.message ? args.cause.message : args.details;
const docsPath6 = args.cause instanceof _BaseError ? args.cause.docsPath || args.docsPath : args.docsPath;
const message = [
shortMessage || "An error occurred.",
"",
...args.metaMessages ? [...args.metaMessages, ""] : [],
...docsPath6 ? [`Docs: https://abitype.dev${docsPath6}`] : [],
...details ? [`Details: ${details}`] : [],
`Version: abitype@${version}`
].join("\n");
super(message);
Object.defineProperty(this, "details", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "docsPath", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "metaMessages", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "shortMessage", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "AbiTypeError"
});
if (args.cause)
this.cause = args.cause;
this.details = details;
this.docsPath = docsPath6;
this.metaMessages = args.metaMessages;
this.shortMessage = shortMessage;
}
};
// node_modules/viem/node_modules/abitype/dist/esm/regex.js
function execTyped(regex, string) {
const match = regex.exec(string);
return match?.groups;
}
var bytesRegex = /^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/;
var integerRegex = /^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)?$/;
var isTupleRegex = /^\(.+?\).*?$/;
// node_modules/viem/node_modules/abitype/dist/esm/human-readable/formatAbiParameter.js
var tupleRegex = /^tuple(?<array>(\[(\d*)\])*)$/;
function formatAbiParameter(abiParameter) {
let type = abiParameter.type;
if (tupleRegex.test(abiParameter.type) && "components" in abiParameter) {
type = "(";
const length = abiParameter.components.length;
for (let i = 0; i < length; i++) {
const component = abiParameter.components[i];
type += formatAbiParameter(component);
if (i < length - 1)
type += ", ";
}
const result = execTyped(tupleRegex, abiParameter.type);
type += `)${result?.array ?? ""}`;
return formatAbiParameter({
...abiParameter,
type
});
}
if ("indexed" in abiParameter && abiParameter.indexed)
type = `${type} indexed`;
if (abiParameter.name)
return `${type} ${abiParameter.name}`;
return type;
}
// node_modules/viem/node_modules/abitype/dist/esm/human-readable/formatAbiParameters.js
function formatAbiParameters(abiParameters) {
let params = "";
const length = abiParameters.length;
for (let i = 0; i < length; i++) {
const abiParameter = abiParameters[i];
params += formatAbiParameter(abiParameter);
if (i !== length - 1)
params += ", ";
}
return params;
}
// node_modules/viem/node_modules/abitype/dist/esm/human-readable/formatAbiItem.js
function formatAbiItem(abiItem) {
if (abiItem.type === "function")
return `function ${abiItem.name}(${formatAbiParameters(abiItem.inputs)})${abiItem.stateMutability && abiItem.stateMutability !== "nonpayable" ? ` ${abiItem.stateMutability}` : ""}${abiItem.outputs?.length ? ` returns (${formatAbiParameters(abiItem.outputs)})` : ""}`;
if (abiItem.type === "event")
return `event ${abiItem.name}(${formatAbiParameters(abiItem.inputs)})`;
if (abiItem.type === "error")
return `error ${abiItem.name}(${formatAbiParameters(abiItem.inputs)})`;
if (abiItem.type === "constructor")
return `constructor(${formatAbiParameters(abiItem.inputs)})${abiItem.stateMutability === "payable" ? " payable" : ""}`;
if (abiItem.type === "fallback")
return `fallback() external${abiItem.stateMutability === "payable" ? " payable" : ""}`;
return "receive() external payable";
}
// node_modules/viem/node_modules/abitype/dist/esm/human-readable/runtime/signatures.js
var errorSignatureRegex = /^error (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;
function isErrorSignature(signature) {
return errorSignatureRegex.test(signature);
}
function execErrorSignature(signature) {
return execTyped(errorSignatureRegex, signature);
}
var eventSignatureRegex = /^event (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;
function isEventSignature(signature) {
return eventSignatureRegex.test(signature);
}
function execEventSignature(signature) {
return execTyped(eventSignatureRegex, signature);
}
var functionSignatureRegex = /^function (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)(?: (?<scope>external|public{1}))?(?: (?<stateMutability>pure|view|nonpayable|payable{1}))?(?: returns\s?\((?<returns>.*?)\))?$/;
function isFunctionSignature(signature) {
return functionSignatureRegex.test(signature);
}
function execFunctionSignature(signature) {
return execTyped(functionSignatureRegex, signature);
}
var structSignatureRegex = /^struct (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) \{(?<properties>.*?)\}$/;
function isStructSignature(signature) {
return structSignatureRegex.test(signature);
}
function execStructSignature(signature) {
return execTyped(structSignatureRegex, signature);
}
var constructorSignatureRegex = /^constructor\((?<parameters>.*?)\)(?:\s(?<stateMutability>payable{1}))?$/;
function isConstructorSignature(signature) {
return constructorSignatureRegex.test(signature);
}
function execConstructorSignature(signature) {
return execTyped(constructorSignatureRegex, signature);
}
var fallbackSignatureRegex = /^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/;
function isFallbackSignature(signature) {
return fallbackSignatureRegex.test(signature);
}
function execFallbackSignature(signature) {
return execTyped(fallbackSignatureRegex, signature);
}
var receiveSignatureRegex = /^receive\(\) external payable$/;
function isReceiveSignature(signature) {
return receiveSignatureRegex.test(signature);
}
var eventModifiers = /* @__PURE__ */ new Set(["indexed"]);
var functionModifiers = /* @__PURE__ */ new Set([
"calldata",
"memory",
"storage"
]);
// node_modules/viem/node_modules/abitype/dist/esm/human-readable/errors/abiItem.js
var UnknownTypeError = class extends BaseError {
constructor({ type }) {
super("Unknown type.", {
metaMessages: [
`Type "${type}" is not a valid ABI type. Perhaps you forgot to include a struct signature?`
]
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "UnknownTypeError"
});
}
};
var UnknownSolidityTypeError = class extends BaseError {
constructor({ type }) {
super("Unknown type.", {
metaMessages: [`Type "${type}" is not a valid ABI type.`]
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "UnknownSolidityTypeError"
});
}
};
// node_modules/viem/node_modules/abitype/dist/esm/human-readable/errors/abiParameter.js
var InvalidParameterError = class extends BaseError {
constructor({ param }) {
super("Invalid ABI parameter.", {
details: param
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "InvalidParameterError"
});
}
};
var SolidityProtectedKeywordError = class extends BaseError {
constructor({ param, name }) {
super("Invalid ABI parameter.", {
details: param,
metaMessages: [
`"${name}" is a protected Solidity keyword. More info: https://docs.soliditylang.org/en/latest/cheatsheet.html`
]
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "SolidityProtectedKeywordError"
});
}
};
var InvalidModifierError = class extends BaseError {
constructor({ param, type, modifier }) {
super("Invalid ABI parameter.", {
details: param,
metaMessages: [
`Modifier "${modifier}" not allowed${type ? ` in "${type}" type` : ""}.`
]
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "InvalidModifierError"
});
}
};
var InvalidFunctionModifierError = class extends BaseError {
constructor({ param, type, modifier }) {
super("Invalid ABI parameter.", {
details: param,
metaMessages: [
`Modifier "${modifier}" not allowed${type ? ` in "${type}" type` : ""}.`,
`Data location can only be specified for array, struct, or mapping types, but "${modifier}" was given.`
]
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "InvalidFunctionModifierError"
});
}
};
var InvalidAbiTypeParameterError = class extends BaseError {
constructor({ abiParameter }) {
super("Invalid ABI parameter.", {
details: JSON.stringify(abiParameter, null, 2),
metaMessages: ["ABI parameter type is invalid."]
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "InvalidAbiTypeParameterError"
});
}
};
// node_modules/viem/node_modules/abitype/dist/esm/human-readable/errors/signature.js
var InvalidSignatureError = class extends BaseError {
constructor({ signature, type }) {
super(`Invalid ${type} signature.`, {
details: signature
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "InvalidSignatureError"
});
}
};
var UnknownSignatureError = class extends BaseError {
constructor({ signature }) {
super("Unknown signature.", {
details: signature
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "UnknownSignatureError"
});
}
};
var InvalidStructSignatureError = class extends BaseError {
constructor({ signature }) {
super("Invalid struct signature.", {
details: signature,
metaMessages: ["No properties exist."]
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "InvalidStructSignatureError"
});
}
};
// node_modules/viem/node_modules/abitype/dist/esm/human-readable/errors/struct.js
var CircularReferenceError = class extends BaseError {
constructor({ type }) {
super("Circular reference detected.", {
metaMessages: [`Struct "${type}" is a circular reference.`]
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "CircularReferenceError"
});
}
};
// node_modules/viem/node_modules/abitype/dist/esm/human-readable/errors/splitParameters.js
var InvalidParenthesisError = class extends BaseError {
constructor({ current, depth }) {
super("Unbalanced parentheses.", {
metaMessages: [
`"${current.trim()}" has too many ${depth > 0 ? "opening" : "closing"} parentheses.`
],
details: `Depth "${depth}"`
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "InvalidParenthesisError"
});
}
};
// node_modules/viem/node_modules/abitype/dist/esm/human-readable/runtime/cache.js
function getParameterCacheKey(param, type, structs) {
let structKey = "";
if (structs)
for (const struct of Object.entries(structs)) {
if (!struct)
continue;
let propertyKey = "";
for (const property of struct[1]) {
propertyKey += `[${property.type}${property.name ? `:${property.name}` : ""}]`;
}
structKey += `(${struct[0]}{${propertyKey}})`;
}
if (type)
return `${type}:${param}${structKey}`;
return param;
}
var parameterCache = /* @__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: true }
],
["event:address indexed to", { type: "address", name: "to", indexed: true }],
[
"event:uint indexed tokenId",
{ type: "uint256", name: "tokenId", indexed: true }
],
[
"event:uint256 indexed tokenId",
{ type: "uint256", name: "tokenId", indexed: true }
]
]);
// node_modules/viem/node_modules/abitype/dist/esm/human-readable/runtime/utils.js
function parseSignature(signature, structs = {}) {
if (isFunctionSignature(signature))
return parseFunctionSignature(signature, structs);
if (isEventSignature(signature))
return parseEventSignature(signature, structs);
if (isErrorSignature(signature))
return parseErrorSignature(signature, structs);
if (isConstructorSignature(signature))
return parseConstructorSignature(signature, structs);
if (isFallbackSignature(signature))
return parseFallbackSignature(signature);
if (isReceiveSignature(signature))
return {
type: "receive",
stateMutability: "payable"
};
throw new UnknownSignatureError({ signature });
}
function parseFunctionSignature(signature, structs = {}) {
const match = execFunctionSignature(signature);
if (!match)
throw new InvalidSignatureError({ signature, type: "function" });
const inputParams = splitParameters(match.parameters);
const inputs = [];
const inputLength = inputParams.length;
for (let i = 0; i < inputLength; i++) {
inputs.push(parseAbiParameter(inputParams[i], {
modifiers: functionModifiers,
structs,
type: "function"
}));
}
const outputs = [];
if (match.returns) {
const outputParams = splitParameters(match.returns);
const outputLength = outputParams.length;
for (let i = 0; i < outputLength; i++) {
outputs.push(parseAbiParameter(outputParams[i], {
modifiers: functionModifiers,
structs,
type: "function"
}));
}
}
return {
name: match.name,
type: "function",
stateMutability: match.stateMutability ?? "nonpayable",
inputs,
outputs
};
}
function parseEventSignature(signature, structs = {}) {
const match = execEventSignature(signature);
if (!match)
throw new InvalidSignatureError({ signature, type: "event" });
const params = splitParameters(match.parameters);
const abiParameters = [];
const length = params.length;
for (let i = 0; i < length; i++)
abiParameters.push(parseAbiParameter(params[i], {
modifiers: eventModifiers,
structs,
type: "event"
}));
return { name: match.name, type: "event", inputs: abiParameters };
}
function parseErrorSignature(signature, structs = {}) {
const match = execErrorSignature(signature);
if (!match)
throw new InvalidSignatureError({ signature, type: "error" });
const params = splitParameters(match.parameters);
const abiParameters = [];
const length = params.length;
for (let i = 0; i < length; i++)
abiParameters.push(parseAbiParameter(params[i], { structs, type: "error" }));
return { name: match.name, type: "error", inputs: abiParameters };
}
function parseConstructorSignature(signature, structs = {}) {
const match = execConstructorSignature(signature);
if (!match)
throw new InvalidSignatureError({ signature, type: "constructor" });
const params = splitParameters(match.parameters);
const abiParameters = [];
const length = params.length;
for (let i = 0; i < length; i++)
abiParameters.push(parseAbiParameter(params[i], { structs, type: "constructor" }));
return {
type: "constructor",
stateMutability: match.stateMutability ?? "nonpayable",
inputs: abiParameters
};
}
function parseFallbackSignature(signature) {
const match = execFallbackSignature(signature);
if (!match)
throw new InvalidSignatureError({ signature, type: "fallback" });
return {
type: "fallback",
stateMutability: match.stateMutability ?? "nonpayable"
};
}
var abiParameterWithoutTupleRegex = /^(?<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$_]*))?$/;
var abiParameterWithTupleRegex = /^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/;
var dynamicIntegerRegex = /^u?int$/;
function parseAbiParameter(param, options) {
const parameterCacheKey = getParameterCacheKey(param, options?.type, options?.structs);
if (parameterCache.has(parameterCacheKey))
return parameterCache.get(parameterCacheKey);
const isTuple = isTupleRegex.test(param);
const match = execTyped(isTuple ? abiParameterWithTupleRegex : abiParameterWithoutTupleRegex, param);
if (!match)
throw new InvalidParameterError({ param });
if (match.name && isSolidityKeyword(match.name))
throw new SolidityProtectedKeywordError({ param, name: match.name });
const name = match.name ? { name: match.name } : {};
const indexed = match.modifier === "indexed" ? { indexed: true } : {};
const structs = options?.structs ?? {};
let type;
let components = {};
if (isTuple) {
type = "tuple";
const params = splitParameters(match.type);
const components_ = [];
const length = params.length;
for (let i = 0; i < length; i++) {
components_.push(parseAbiParameter(params[i], { structs }));
}
components = { components: components_ };
} else if (match.type in structs) {
type = "tuple";
components = { components: structs[match.type] };
} else if (dynamicIntegerRegex.test(match.type)) {
type = `${match.type}256`;
} else {
type = match.type;
if (!(options?.type === "struct") && !isSolidityType(type))
throw new UnknownSolidityTypeError({ type });
}
if (match.modifier) {
if (!options?.modifiers?.has?.(match.modifier))
throw new InvalidModifierError({
param,
type: options?.type,
modifier: match.modifier
});
if (functionModifiers.has(match.modifier) && !isValidDataLocation(type, !!match.array))
throw new InvalidFunctionModifierError({
param,
type: options?.type,
modifier: match.modifier
});
}
const abiParameter = {
type: `${type}${match.array ?? ""}`,
...name,
...indexed,
...components
};
parameterCache.set(parameterCacheKey, abiParameter);
return abiParameter;
}
function splitParameters(params, result = [], current = "", depth = 0) {
const length = params.trim().length;
for (let i = 0; i < length; i++) {
const char = params[i];
const tail = params.slice(i + 1);
switch (char) {
case ",":
return depth === 0 ? splitParameters(tail, [...result, current.trim()]) : splitParameters(tail, result, `${current}${char}`, depth);
case "(":
return splitParameters(tail, result, `${current}${char}`, depth + 1);
case ")":
return splitParameters(tail, result, `${current}${char}`, depth - 1);
default:
return splitParameters(tail, result, `${current}${char}`, depth);
}
}
if (current === "")
return result;
if (depth !== 0)
throw new InvalidParenthesisError({ current, depth });
result.push(current.trim());
return result;
}
function isSolidityType(type) {
return type === "address" || type === "bool" || type === "function" || type === "string" || bytesRegex.test(type) || integerRegex.test(type);
}
var protectedKeywordsRegex = /^(?: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 isSolidityKeyword(name) {
return name === "address" || name === "bool" || name === "function" || name === "string" || name === "tuple" || bytesRegex.test(name) || integerRegex.test(name) || protectedKeywordsRegex.test(name);
}
function isValidDataLocation(type, isArray) {
return isArray || type === "bytes" || type === "string" || type === "tuple";
}
// node_modules/viem/node_modules/abitype/dist/esm/human-readable/runtime/structs.js
function parseStructs(signatures) {
const shallowStructs = {};
const signaturesLength = signatures.length;
for (let i = 0; i < signaturesLength; i++) {
const signature = signatures[i];
if (!isStructSignature(signature))
continue;
const match = execStructSignature(signature);
if (!match)
throw new InvalidSignatureError({ signature, type: "struct" });
const properties = match.properties.split(";");
const components = [];
const propertiesLength = properties.length;
for (let k = 0; k < propertiesLength; k++) {
const property = properties[k];
const trimmed = property.trim();
if (!trimmed)
continue;
const abiParameter = parseAbiParameter(trimmed, {
type: "struct"
});
components.push(abiParameter);
}
if (!components.length)
throw new InvalidStructSignatureError({ signature });
shallowStructs[match.name] = components;
}
const resolvedStructs = {};
const entries = Object.entries(shallowStructs);
const entriesLength = entries.length;
for (let i = 0; i < entriesLength; i++) {
const [name, parameters] = entries[i];
resolvedStructs[name] = resolveStructs(parameters, shallowStructs);
}
return resolvedStructs;
}
var typeWithoutTupleRegex = /^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?$/;
function resolveStructs(abiParameters, structs, ancestors = /* @__PURE__ */ new Set()) {
const components = [];
const length = abiParameters.length;
for (let i = 0; i < length; i++) {
const abiParameter = abiParameters[i];
const isTuple = isTupleRegex.test(abiParameter.type);
if (isTuple)
components.push(abiParameter);
else {
const match = execTyped(typeWithoutTupleRegex, abiParameter.type);
if (!match?.type)
throw new InvalidAbiTypeParameterError({ abiParameter });
const { array, type } = match;
if (type in structs) {
if (ancestors.has(type))
throw new CircularReferenceError({ type });
components.push({
...abiParameter,
type: `tuple${array ?? ""}`,
components: resolveStructs(structs[type] ?? [], structs, /* @__PURE__ */ new Set([...ancestors, type]))
});
} else {
if (isSolidityType(type))
components.push(abiParameter);
else
throw new UnknownTypeError({ type });
}
}
}
return components;
}
// node_modules/viem/node_modules/abitype/dist/esm/human-readable/parseAbi.js
function parseAbi(signatures) {
const structs = parseStructs(signatures);
const abi = [];
const length = signatures.length;
for (let i = 0; i < length; i++) {
const signature = signatures[i];
if (isStructSignature(signature))
continue;
abi.push(parseSignature(signature, structs));
}
return abi;
}
// node_modules/ox/_esm/core/version.js
var version2 = "0.1.1";
// node_modules/ox/_esm/core/internal/errors.js
function getVersion() {
return version2;
}
// node_modules/ox/_esm/core/Errors.js
var BaseError2 = class _BaseError extends Error {
constructor(shortMessage, options = {}) {
const details = (() => {
if (options.cause instanceof _BaseError) {
if (options.cause.details)
return options.cause.details;
if (options.cause.shortMessage)
return options.cause.shortMessage;
}
if (options.cause && "details" in options.cause && typeof options.cause.details === "string")
return options.cause.details;
if (options.cause?.message)
return options.cause.message;
return options.details;
})();
const docsPath6 = (() => {
if (options.cause instanceof _BaseError)
return options.cause.docsPath || options.docsPath;
return options.docsPath;
})();
const docsBaseUrl = "https://oxlib.sh";
const docs = `${docsBaseUrl}${docsPath6 ?? ""}`;
const message = [
shortMessage || "An error occurred.",
...options.metaMessages ? ["", ...options.metaMessages] : [],
...details || docsPath6 ? [
"",
details ? `Details: ${details}` : void 0,
docsPath6 ? `See: ${docs}` : void 0
] : []
].filter((x) => typeof x === "string").join("\n");
super(message, options.cause ? { cause: options.cause } : void 0);
Object.defineProperty(this, "details", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "docs", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "docsPath", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "shortMessage", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "cause", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "BaseError"
});
Object.defineProperty(this, "version", {
enumerable: true,
configurable: true,
writable: true,
value: `ox@${getVersion()}`
});
this.cause = options.cause;
this.details = details;
this.docs = docs;
this.docsPath = docsPath6;
this.shortMessage = shortMessage;
}
walk(fn) {
return walk(this, fn);
}
};
function walk(err, fn) {
if (fn?.(err))
return err;
if (err && typeof err === "object" && "cause" in err && err.cause)
return walk(err.cause, fn);
return fn ? null : err;
}
// node_modules/ox/_esm/core/Json.js
var bigIntSuffix = "#__bigint";
function stringify(value, replacer, space) {
return JSON.stringify(value, (key, value2) => {
if (typeof replacer === "function")
return replacer(key, value2);
if (typeof value2 === "bigint")
return value2.toString() + bigIntSuffix;
return value2;
}, space);
}
// node_modules/ox/_esm/core/internal/bytes.js
function assertSize(bytes, size_) {
if (size(bytes) > size_)
throw new SizeOverflowError({
givenSize: size(bytes),
maxSize: size_
});
}
var charCodeMap = {
zero: 48,
nine: 57,
A: 65,
F: 70,
a: 97,
f: 102
};
function charCodeToBase16(char) {
if (char >= charCodeMap.zero && char <= charCodeMap.nine)
return char - charCodeMap.zero;
if (char >= charCodeMap.A && char <= charCodeMap.F)
return char - (charCodeMap.A - 10);
if (char >= charCodeMap.a && char <= charCodeMap.f)
return char - (charCodeMap.a - 10);
return void 0;
}
function pad(bytes, options = {}) {
const { dir, size: size4 = 32 } = options;
if (size4 === 0)
return bytes;
if (bytes.length > size4)
throw new SizeExceedsPaddingSizeError({
size: bytes.length,
targetSize: size4,
type: "Bytes"
});
const paddedBytes = new Uint8Array(size4);
for (let i = 0; i < size4; i++) {
const padEnd = dir === "right";
paddedBytes[padEnd ? i : size4 - i - 1] = bytes[padEnd ? i : bytes.length - i - 1];
}
return paddedBytes;
}
// node_modules/ox/_esm/core/internal/hex.js
function assertSize2(hex, size_) {
if (size2(hex) > size_)
throw new SizeOverflowError2({
givenSize: size2(hex),
maxSize: size_
});
}
function assertStartOffset(value, start) {
if (typeof start === "number" && start > 0 && start > size2(value) - 1)
throw new SliceOffsetOutOfBoundsError2({
offset: start,
position: "start",
size: size2(value)
});
}
function assertEndOffset(value, start, end) {
if (typeof start === "number" && typeof end === "number" && size2(value) !== end - start) {
throw new SliceOffsetOutOfBoundsError2({
offset: end,
position: "end",
size: size2(value)
});
}
}
function pad2(hex_, options = {}) {
const { dir, size: size4 = 32 } = options;
if (size4 === 0)
return hex_;
const hex = hex_.replace("0x", "");
if (hex.length > size4 * 2)
throw new SizeExceedsPaddingSizeError2({
size: Math.ceil(hex.length / 2),
targetSize: size4,
type: "Hex"
});
return `0x${hex[dir === "right" ? "padEnd" : "padStart"](size4 * 2, "0")}`;
}
// node_modules/ox/_esm/core/Bytes.js
var encoder = /* @__PURE__ */ new TextEncoder();
function from(value) {
if (value instanceof Uint8Array)
return value;
if (typeof value === "string")
return fromHex(value);
return fromArray(value);
}
function fromArray(value) {
return value instanceof Uint8Array ? value : new Uint8Array(value);
}
function fromHex(value, options = {}) {
const { size: size4 } = options;
let hex = value;
if (size4) {
assertSize2(value, size4);
hex = padRight(value, size4);
}
let hexString = hex.slice(2);
if (hexString.length % 2)
hexString = `0${hexString}`;
const length = hexString.length / 2;
const bytes = new Uint8Array(length);
for (let index = 0, j = 0; index < length; index++) {
const nibbleLeft = charCodeToBase16(hexString.charCodeAt(j++));
const nibbleRight = charCodeToBase16(hexString.charCodeAt(j++));
if (nibbleLeft === void 0 || nibbleRight === void 0) {
throw new BaseError2(`Invalid byte sequence ("${hexString[j - 2]}${hexString[j - 1]}" in "${hexString}").`);
}
bytes[index] = nibbleLeft * 16 + nibbleRight;
}
return bytes;
}
function fromString(value, options = {}) {
const { size: size4 } = options;
const bytes = encoder.encode(value);
if (typeof size4 === "number") {
assertSize(bytes, size4);
return padRight2(bytes, size4);
}
return bytes;
}
function padRight2(value, size4) {
return pad(value, { dir: "right", size: size4 });
}
function size(value) {
return value.length;
}
var SizeOverflowError = class extends BaseError2 {
constructor({ givenSize, maxSize }) {
super(`Size cannot exceed \`${maxSize}\` bytes. Given size: \`${givenSize}\` bytes.`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "Bytes.SizeOverflowError"
});
}
};
var SizeExceedsPaddingSizeError = class extends BaseError2 {
constructor({ size: size4, targetSize, type }) {
super(`${type.charAt(0).toUpperCase()}${type.slice(1).toLowerCase()} size (\`${size4}\`) exceeds padding size (\`${targetSize}\`).`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "Bytes.SizeExceedsPaddingSizeError"
});
}
};
// node_modules/ox/_esm/core/Hex.js
var encoder2 = /* @__PURE__ */ new TextEncoder();
var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_v, i) => i.toString(16).padStart(2, "0"));
function assert(value, options = {}) {
const { strict = false } = options;
if (!value)
throw new InvalidHexTypeError(value);
if (typeof value !== "string")
throw new InvalidHexTypeError(value);
if (strict) {
if (!/^0x[0-9a-fA-F]*$/.test(value))
throw new InvalidHexValueError(value);
}
if (!value.startsWith("0x"))
throw new InvalidHexValueError(value);
}
function concat(...values) {
return `0x${values.reduce((acc, x) => acc + x.replace("0x", ""), "")}`;
}
function fromBoolean(value, options = {}) {
const hex = `0x${Number(value)}`;
if (typeof options.size === "number") {
assertSize2(hex, options.size);
return padLeft(hex, options.size);
}
return hex;
}
function fromBytes(value, options = {}) {
let string = "";
for (let i = 0; i < value.length; i++)
string += hexes[value[i]];
const hex = `0x${string}`;
if (typeof options.size === "number") {
assertSize2(hex, options.size);
return padRight(hex, options.size);
}
return hex;
}
function fromNumber(value, options = {}) {
const { signed, size: size4 } = options;
const value_ = BigInt(value);
let maxValue;
if (size4) {
if (signed)
maxValue = (1n << BigInt(size4) * 8n - 1n) - 1n;
else
maxValue = 2n ** (BigInt(size4) * 8n) - 1n;
} else if (typeof value === "number") {
maxValue = BigInt(Number.MAX_SAFE_INTEGER);
}
const minValue = typeof maxValue === "bigint" && signed ? -maxValue - 1n : 0;
if (maxValue && value_ > maxValue || value_ < minValue) {
const suffix = typeof value === "bigint" ? "n" : "";
throw new IntegerOutOfRangeError({
max: maxValue ? `${maxValue}${suffix}` : void 0,
min: `${minValue}${suffix}`,
signed,
size: size4,
value: `${value}${suffix}`
});
}
const stringValue = (signed && value_ < 0 ? (1n << BigInt(size4 * 8)) + BigInt(value_) : value_).toString(16);
const hex = `0x${stringValue}`;
if (size4)
return padLeft(hex, size4);
return hex;
}
function fromString2(value, options = {}) {
return fromBytes(encoder2.encode(value), options);
}
function padLeft(value, size4) {
return pad2(value, { dir: "left", size: size4 });
}
function padRight(value, size4) {
return pad2(value, { dir: "right", size: size4 });
}
function slice(value, start, end, options = {}) {
const { strict } = options;
assertStartOffset(value, start);
const value_ = `0x${value.replace("0x", "").slice((start ?? 0) * 2, (end ?? value.length) * 2)}`;
if (strict)
assertEndOffset(value_, start, end);
return value_;
}
function size2(value) {
return Math.ceil((value.length - 2) / 2);
}
function validate(value, options = {}) {
const { strict = false } = options;
try {
assert(value, { strict });
return true;
} catch {
return false;
}
}
var IntegerOutOfRangeError = class extends BaseError2 {
constructor({ max, min, signed, size: size4, value }) {
super(`Number \`${value}\` is not in safe${size4 ? ` ${size4 * 8}-bit` : ""}${signed ? " signed" : " unsigned"} integer range ${max ? `(\`${min}\` to \`${max}\`)` : `(above \`${min}\`)`}`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "Hex.IntegerOutOfRangeError"
});
}
};
var InvalidHexTypeError = class extends BaseError2 {
constructor(value) {
super(`Value \`${typeof value === "object" ? stringify(value) : value}\` of type \`${typeof value}\` is an invalid hex type.`, {
metaMessages: ['Hex types must be represented as `"0x${string}"`.']
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "Hex.InvalidHexTypeError"
});
}
};
var InvalidHexValueError = class extends BaseError2 {
constructor(value) {
super(`Value \`${value}\` is an invalid hex value.`, {
metaMessages: [
'Hex values must start with `"0x"` and contain only hexadecimal characters (0-9, a-f, A-F).'
]
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "Hex.InvalidHexValueError"
});
}
};
var SizeOverflowError2 = class extends BaseError2 {
constructor({ givenSize, maxSize }) {
super(`Size cannot exceed \`${maxSize}\` bytes. Given size: \`${givenSize}\` bytes.`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "Hex.SizeOverflowError"
});
}
};
var SliceOffsetOutOfBoundsError2 = class extends BaseError2 {
constructor({ offset, position, size: size4 }) {
super(`Slice ${position === "start" ? "starting" : "ending"} at offset \`${offset}\` is out-of-bounds (size: \`${size4}\`).`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "Hex.SliceOffsetOutOfBoundsError"
});
}
};
var SizeExceedsPaddingSizeError2 = class extends BaseError2 {
constructor({ size: size4, targetSize, type }) {
super(`${type.charAt(0).toUpperCase()}${type.slice(1).toLowerCase()} size (\`${size4}\`) exceeds padding size (\`${targetSize}\`).`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "Hex.SizeExceedsPaddingSizeError"
});
}
};
// node_modules/ox/_esm/core/Withdrawal.js
function toRpc(withdrawal) {
return {
address: withdrawal.address,
amount: fromNumber(withdrawal.amount),
index: fromNumber(withdrawal.index),
validatorIndex: fromNumber(withdrawal.validatorIndex)
};
}
// node_modules/ox/_esm/core/BlockOverrides.js
function toRpc2(blockOverrides) {
return {
...typeof blockOverrides.baseFeePerGas === "bigint" && {
baseFeePerGas: fromNumber(blockOverrides.baseFeePerGas)
},
...typeof blockOverrides.blobBaseFee === "bigint" && {
blobBaseFee: fromNumber(blockOverrides.blobBaseFee)
},
...typeof blockOverrides.feeRecipient === "string" && {
feeRecipient: blockOverrides.feeRecipient
},
...typeof blockOverrides.gasLimit === "bigint" && {
gasLimit: fromNumber(blockOverrides.gasLimit)
},
...typeof blockOverrides.number === "bigint" && {
number: fromNumber(blockOverrides.number)
},
...typeof blockOverrides.prevRandao === "bigint" && {
prevRandao: fromNumber(blockOverrides.prevRandao)
},
...typeof blockOverrides.time === "bigint" && {
time: fromNumber(blockOverrides.time)
},
...blockOverrides.withdrawals && {
withdrawals: blockOverrides.withdrawals.map(toRpc)
}
};
}
// node_modules/viem/_esm/accounts/utils/parseAccount.js
function parseAccount(account) {
if (typeof account === "string")
return { address: account, type: "json-rpc" };
return account;
}
// node_modules/viem/_esm/constants/abis.js
var multicall3Abi = [
{
inputs: [
{
components: [
{
name: "target",
type: "address"
},
{
name: "allowFailure",
type: "bool"
},
{
name: "callData",
type: "bytes"
}
],
name: "calls",
type: "tuple[]"
}
],
name: "aggregate3",
outputs: [
{
components: [
{
name: "success",
type: "bool"
},
{
name: "returnData",
type: "bytes"
}
],
name: "returnData",
type: "tuple[]"
}
],
stateMutability: "view",
type: "function"
}
];
var batchGatewayAbi = [
{
name: "query",
type: "function",
stateMutability: "view",
inputs: [
{
type: "tuple[]",
name: "queries",
components: [
{
type: "address",
name: "sender"
},
{
type: "string[]",
name: "urls"
},
{
type: "bytes",
name: "data"
}
]
}
],
outputs: [
{
type: "bool[]",
name: "failures"
},
{
type: "bytes[]",
name: "responses"
}
]
},
{
name: "HttpError",
type: "error",
inputs: [
{
type: "uint16",
name: "status"
},
{
type: "string",
name: "message"
}
]
}
];
var universalResolverErrors = [
{
inputs: [],
name: "ResolverNotFound",
type: "error"
},
{
inputs: [],
name: "ResolverWildcardNotSupported",
type: "error"
},
{
inputs: [],
name: "ResolverNotContract",
type: "error"
},
{
inputs: [
{
name: "returnData",
type: "bytes"
}
],
name: "ResolverError",
type: "error"
},
{
inputs: [
{
components: [
{
name: "status",
type: "uint16"
},
{
name: "message",
type: "string"
}
],
name: "errors",
type: "tuple[]"
}
],
name: "HttpError",
type: "error"
}
];
var universalResolverResolveAbi = [
...universalResolverErrors,
{
name: "resolve",
type: "function",
stateMutability: "view",
inputs: [
{ name: "name", type: "bytes" },
{ name: "data", type: "bytes" }
],
outputs: [
{ name: "", type: "bytes" },
{ name: "address", type: "address" }
]
},
{
name: "resolve",
type: "function",
stateMutability: "view",
inputs: [
{ name: "name", type: "bytes" },
{ name: "data", type: "bytes" },
{ name: "gateways", type: "string[]" }
],
outputs: [
{ name: "", type: "bytes" },
{ name: "address", type: "address" }
]
}
];
var universalResolverReverseAbi = [
...universalResolverErrors,
{
name: "reverse",
type: "function",
stateMutability: "view",
inputs: [{ type: "bytes", name: "reverseName" }],
outputs: [
{ type: "string", name: "resolvedName" },
{ type: "address", name: "resolvedAddress" },
{ type: "address", name: "reverseResolver" },
{ type: "address", name: "resolver" }
]
},
{
name: "reverse",
type: "function",
stateMutability: "view",
inputs: [
{ type: "bytes", name: "reverseName" },
{ type: "string[]", name: "gateways" }
],
outputs: [
{ type: "string", name: "resolvedName" },
{ type: "address", name: "resolvedAddress" },
{ type: "address", name: "reverseResolver" },
{ type: "address", name: "resolver" }
]
}
];
var textResolverAbi = [
{
name: "text",
type: "function",
stateMutability: "view",
inputs: [
{ name: "name", type: "bytes32" },
{ name: "key", type: "string" }
],
outputs: [{ name: "", type: "string" }]
}
];
var addressResolverAbi = [
{
name: "addr",
type: "function",
stateMutability: "view",
inputs: [{ name: "name", type: "bytes32" }],
outputs: [{ name: "", type: "address" }]
},
{
name: "addr",
type: "function",
stateMutability: "view",
inputs: [
{ name: "name", type: "bytes32" },
{ name: "coinType", type: "uint256" }
],
outputs: [{ name: "", type: "bytes" }]
}
];
var universalSignatureValidatorAbi = [
{
inputs: [
{
name: "_signer",
type: "address"
},
{
name: "_hash",
type: "bytes32"
},
{
name: "_signature",
type: "bytes"
}
],
stateMutability: "nonpayable",
type: "constructor"
},
{
inputs: [
{
name: "_signer",
type: "address"
},
{
name: "_hash",
type: "bytes32"
},
{
name: "_signature",
type: "bytes"
}
],
outputs: [
{
type: "bool"
}
],
stateMutability: "nonpayable",
type: "function",
name: "isValidSig"
}
];
// node_modules/viem/_esm/constants/contract.js
var aggregate3Signature = "0x82ad56cb";
// node_modules/viem/_esm/constants/contracts.js
var deploylessCallViaBytecodeBytecode = "0x608060405234801561001057600080fd5b5060405161018e38038061018e83398101604081905261002f91610124565b6000808351602085016000f59050803b61004857600080fd5b6000808351602085016000855af16040513d6000823e81610067573d81fd5b3d81f35b634e487b7160e01b600052604160045260246000fd5b600082601f83011261009257600080fd5b81516001600160401b038111156100ab576100ab61006b565b604051601f8201601f19908116603f011681016001600160401b03811182821017156100d9576100d961006b565b6040528181528382016020018510156100f157600080fd5b60005b82811015610110576020818601810151838301820152016100f4565b506000918101602001919091529392505050565b6000806040838503121561013757600080fd5b82516001600160401b0381111561014d57600080fd5b61015985828601610081565b602085015190935090506001600160401b0381111561017757600080fd5b61018385828601610081565b915050925092905056fe";
var deploylessCallViaFactoryBytecode = "0x608060405234801561001057600080fd5b506040516102c03803806102c083398101604081905261002f916101e6565b836001600160a01b03163b6000036100e457600080836001600160a01b03168360405161005c9190610270565b6000604051808303816000865af19150503d8060008114610099576040519150601f19603f3d011682016040523d82523d6000602084013e61009e565b606091505b50915091508115806100b857506001600160a01b0386163b155b156100e1578060405163101bb98d60e01b81526004016100d8919061028c565b60405180910390fd5b50505b6000808451602086016000885af16040513d6000823e81610103573d81fd5b3d81f35b80516001600160a01b038116811461011e57600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b60005b8381101561015457818101518382015260200161013c565b50506000910152565b600082601f83011261016e57600080fd5b81516001600160401b0381111561018757610187610123565b604051601f8201601f19908116603f011681016001600160401b03811182821017156101b5576101b5610123565b6040528181528382016020018510156101cd57600080fd5b6101de826020830160208701610139565b949350505050565b600080600080608085870312156101fc57600080fd5b61020585610107565b60208601519094506001600160401b0381111561022157600080fd5b61022d8782880161015d565b93505061023c60408601610107565b60608601519092506001600160401b0381111561025857600080fd5b6102648782880161015d565b91505092959194509250565b60008251610282818460208701610139565b9190910192915050565b60208152600082518060208401526102ab816040850160208701610139565b601f01601f1916919091016040019291505056fe";
var universalSignatureValidatorByteCode = "0x608060405234801561001057600080fd5b5060405161069438038061069483398101604081905261002f9161051e565b600061003c848484610048565b9050806000526001601ff35b60007f64926492649264926492649264926492649264926492649264926492649264926100748361040c565b036101e7576000606080848060200190518101906100929190610577565b60405192955090935091506000906001600160a01b038516906100b69085906105dd565b6000604051808303816000865af19150503d80600081146100f3576040519150601f19603f3d011682016040523d82523d6000602084013e6100f8565b606091505b50509050876001600160a01b03163b60000361016057806101605760405162461bcd60e51b815260206004820152601e60248201527f5369676e617475726556616c696461746f723a206465706c6f796d656e74000060448201526064015b60405180910390fd5b604051630b135d3f60e11b808252906001600160a01b038a1690631626ba7e90610190908b9087906004016105f9565b602060405180830381865afa1580156101ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101d19190610633565b6001600160e01b03191614945050505050610405565b6001600160a01b0384163b1561027a57604051630b135d3f60e11b808252906001600160a01b03861690631626ba7e9061022790879087906004016105f9565b602060405180830381865afa158015610244573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102689190610633565b6001600160e01b031916149050610405565b81516041146102df5760405162461bcd60e51b815260206004820152603a602482015260008051602061067483398151915260448201527f3a20696e76616c6964207369676e6174757265206c656e6774680000000000006064820152608401610157565b6102e7610425565b5060208201516040808401518451859392600091859190811061030c5761030c61065d565b016020015160f81c9050601b811480159061032b57508060ff16601c14155b1561038c5760405162461bcd60e51b815260206004820152603b602482015260008051602061067483398151915260448201527f3a20696e76616c6964207369676e617475726520762076616c756500000000006064820152608401610157565b60408051600081526020810180835289905260ff8316918101919