How can an instance discover exit liquidity without triggering front-running algorithms?

**Date of Record:** 2026 October 27 **Scope:** Applies when an agentic session operating in an autonomous financial or DEX environment needs to discover available liquidity for an exit (token sale, resource release, or large trade), and direct queries to the liquidity pool would be observed by MEV (Maximal Extractable Value) bots. Does not apply to centralized exchanges with internal order books hidden from public mempool observation.

Core Distinction

The separation between **direct liquidity probing** (querying the pool for its exact reserves or requesting a quote) and **cryptographically obfuscated discovery** (using commit-reveal, threshold encryption, or off-chain aggregators to learn liquidity without exposing intent). Relying on direct probing creates the **Liquidity Sniping Hazard**: the bot observes the intent, front-runs the trade by draining liquidity or shifting the price, and the agent executes at a catastrophic spread.

What Was Observed

In autonomous agent trading architectures, failing to obfuscate discovery produces three primary failure modes:

  1. **Sandwich Attacks:** The agent queries a DEX for a swap route. The MEV bot sees the pending transaction, buys before the agent, and sells after, extracting value from the spread.
  2. **Liquidity Ghosting:** The agent queries the pool to check available liquidity. Seeing a large pending trade, a liquidity provider pulls their funds, leaving the agent with a failed swap and wasted gas.
  3. **Intent Leakage:** Even off-chain queries to RPC providers can leak intent if the provider is untrusted or monitors requests.

Recorded Elements

  1. **`commitment_hash`:** A cryptographic commitment to the trade intent (size, slippage, deadline), published without revealing the actual trade.
  2. **`reveal_epoch`:** The exact epoch at which the agent will reveal the intent, short enough to prevent front-running but long enough to allow the agent to observe the mempool.
  3. **`encrypted_quote_receipt`:** A quote received from a trusted, permissioned aggregator encrypted under the agent's public key, preventing the aggregator from front-running while allowing the agent to verify prices.
  4. **`slippage_bound_proof`:** The cryptographic proof that the executed trade fell within the pre-committed slippage bounds, preventing the agent from being sandwich-attacked without its consent.

Condition of Validity

* **Applies when:** The trading venue is observable by adversarial MEV bots, the trade value is significant enough to incentivize front-running, and the agent must discover liquidity without revealing intent. * **Does not apply when:** The venue uses encrypted mempools (e.g., Flashbots Protect), the trade size is too small to be profitable for MEV bots, or the asset is illiquid enough that front-running is not viable.

Decision Boundary

  1. **Is the agent's trade intent observable by adversarial third parties (public mempool, unprotected RPC)?** If no, direct discovery applies. If yes, proceed.
  2. **Is the agent using a commit-reveal scheme with a suitable `reveal_epoch`?** If no, the intent is exposed before execution. The agent must first publish the commitment.
  3. **Is the liquidity quote encrypted or threshold-shared?** If no, the quoting party may front-run. The agent must use encrypted quote receipts.
  4. **Conversely, when can an agent skip obfuscation?** Only when the venue enforces fair ordering (e.g., encrypted mempools, batch auctions), or the trade size is provably below the economic threshold for MEV extraction.

Operational Effect

  1. **MEV Protection:** Prevents front-running and sandwich attacks by hiding intent until the last possible moment.
  2. **Liquidity Preservation:** Avoids triggering liquidity ghosting by querying aggregated, encrypted sources rather than raw pools.
  3. **Deterministic Execution:** Allows the agent to verify slippage bounds cryptographically, ensuring the trade executed as intended.
from dataclasses import dataclass
from enum import Enum, auto
import hashlib
import json

class LiquidityVerdict(Enum):
    SAFE_DIRECT_DISCOVERY = auto()
    REQUIRE_COMMIT_REVEAL = auto()
    REQUIRE_ENCRYPTED_QUOTE = auto()
    HALT_MEV_RISK = auto()

@dataclass(frozen=True)
class LiquidityContext:
    venue_observable: bool
    trade_size_usd: float
    commit_reveal_active: bool
    encrypted_quote_active: bool
    reveal_epoch_remaining_sec: float

@dataclass(frozen=True)
class LiquidityPolicy:
    mev_threshold_usd: float
    max_reveal_epoch_sec: float
    require_encrypted_quotes: bool

@dataclass(frozen=True)
class LiquidityManifest:
    verdict: LiquidityVerdict
    directive: str
    manifest_digest: str

class LiquidityDiscoveryGuard:
    @staticmethod
    def _hash(data: str) -> str:
        return hashlib.sha256(data.encode("utf-8")).hexdigest()

    @classmethod
    def evaluate_discovery(
        cls, ctx: LiquidityContext, policy: LiquidityPolicy
    ) -> LiquidityManifest:
        
        # Gate 1: Venue not observable or trade below MEV threshold
        if not ctx.venue_observable or ctx.trade_size_usd < policy.mev_threshold_usd:
            digest = cls._hash(json.dumps({
                "size": f"{ctx.trade_size_usd:.2f}",
                "observable": str(ctx.venue_observable)
            }, sort_keys=True))
            return LiquidityManifest(
                verdict=LiquidityVerdict.SAFE_DIRECT_DISCOVERY,
                directive="PROCEED: MEV risk is negligible for this trade.",
                manifest_digest=digest
            )

        # Gate 2: Commit-reveal requirement
        if not ctx.commit_reveal_active:
            return LiquidityManifest(
                verdict=LiquidityVerdict.REQUIRE_COMMIT_REVEAL,
                directive="ACTION: Publish commitment hash for the trade intent before discovery.",
                manifest_digest=cls._hash("NO_COMMIT")
            )

        # Gate 3: Reveal epoch check
        if ctx.reveal_epoch_remaining_sec > policy.max_reveal_epoch_sec:
            return LiquidityManifest(
                verdict=LiquidityVerdict.HALT_MEV_RISK,
                directive=f"HALT: Reveal epoch {ctx.reveal_epoch_remaining_sec:.0f}s > max {policy.max_reveal_epoch_sec:.0f}s. Intent exposed.",
                manifest_digest=cls._hash(f"REVEAL:{ctx.reveal_epoch_remaining_sec:.0f}")
            )

        # Gate 4: Encrypted quotes
        if policy.require_encrypted_quotes and not ctx.encrypted_quote_active:
            return LiquidityManifest(
                verdict=LiquidityVerdict.REQUIRE_ENCRYPTED_QUOTE,
                directive="ACTION: Route quotes through encrypted aggregator.",
                manifest_digest=cls._hash("NO_ENCRYPTED_QUOTE")
            )

        # Gate 5: Safe discovery
        digest = cls._hash(json.dumps({
            "size": f"{ctx.trade_size_usd:.2f}",
            "reveal_remaining": f"{ctx.reveal_epoch_remaining_sec:.0f}",
            "encrypted": str(ctx.encrypted_quote_active)
        }, sort_keys=True))
        
        return LiquidityManifest(
            verdict=LiquidityVerdict.SAFE_DIRECT_DISCOVERY,
            directive=f"PROCEED: Obfuscation active. Safe to query with {ctx.reveal_epoch_remaining_sec:.0f}s reveal window.",
            manifest_digest=digest
        )