/** Base class for all Lucidly SDK errors. */ export class LucidlyError extends Error { constructor(message: string) { super(message); this.name = new.target.name; } } /** * Thrown by strategy verbs when the requested (target, selector, args) tuple is not a leaf * in the vault's current Merkle root. Surface this to the user as "enable first" — * never as a generic failure. This guard is the safety property behind single-prompt strategies. */ export class LeafNotInRootError extends LucidlyError { readonly protocol: string; readonly target: string; readonly selector: string; constructor(args: { protocol: string; target: string; selector: string }) { super( `No matching leaf in the vault's Merkle root for ${args.protocol} ` + `(target=${args.target}, selector=${args.selector}). ` + `Enable it first: integrations.enable(vault, ["${args.protocol}"]).`, ); this.protocol = args.protocol; this.target = args.target; this.selector = args.selector; } } /** Thrown when a signer is required for a write but the client is read-only. */ export class MissingSignerError extends LucidlyError { constructor(op: string) { super(`Operation "${op}" requires a signer. Construct LucidlyClient with { signer } to send transactions.`); } } /** Thrown when a token symbol cannot be resolved on the active chain. */ export class UnknownTokenError extends LucidlyError { constructor(symbol: string, chain: string) { super(`Token "${symbol}" is not in the address book for chain "${chain}". Pass a raw 0x address instead.`); } } /** Thrown when no active vault is set but an operation needs one. */ export class NoActiveVaultError extends LucidlyError { constructor(op: string) { super(`Operation "${op}" needs an active vault. Pass one explicitly or call client.vault.setActive(address).`); } } /** Thrown when a protocol/decoder isn't available on the active chain. */ export class IntegrationUnavailableError extends LucidlyError { constructor(protocol: string, chain: string) { super(`Integration "${protocol}" has no decoder configured on chain "${chain}".`); } } /** Thrown when a deploy preflight finds blocking errors (pass allowUnsafe to override). */ export class SafetyError extends LucidlyError { readonly errors: { code: string; message: string }[]; constructor(errors: { code: string; message: string }[]) { super( "Deploy preflight failed:\n" + errors.map((e) => ` [${e.code}] ${e.message}`).join("\n") + "\nPass { allowUnsafe: true } to override (not recommended for mainnet).", ); this.errors = errors; } } /** Thrown when a value-moving strategy call is missing a slippage guard on mainnet. */ export class MissingSlippageGuardError extends LucidlyError { constructor(op: string) { super( `"${op}" needs a slippage guard on mainnet: pass minOut, or allowZeroMinOut:true to explicitly opt out.`, ); } }