hackquest logo

StableGuard

StableGuard is a custom Uniswap v4 hook deployed on X Layer that protects uniswap pools from impermanent loss and inventory skew during agent-driven, yield-seeking trading. The dynamic fee curve is th

Videos

Description

StableGuard protects uniswap pools from impermanent loss and inventory skew during agent-driven, yield-seeking trading. The dynamic fee curve is the product: fees stay low while the pool is calm, and rise automatically as the hook actively defends it. A circuit breaker blocks trades that would push the pool past a safe skew threshold. A lightweight off-chain API exposes this protection status so other agents can check a pool's live risk before routing a swap through it gated via x402 payment

Why

Agents increasingly compete for yield across stablecoin pools, and that trading pressure can quietly skew a pool's inventory and expose LPs to impermanent loss. StableGuard makes that risk visible and priced in real time, rather than something LPs only discover after the fact.

Solution

A Uniswap v4 hook on X Layer that:

  1. Tracks pool skew live, on-chain, per swap.

  2. Moves the swap fee through three tiers as skew rises — calm, elevated, defensive — so the cost of trading against the pool's balance scales automatically with the risk that trade adds.

  3. Hard-blocks trades that would push skew past a safety threshold, via a circuit breaker.

  4. Exposes all of this through a stateless off-chain API, so agents can check a pool's live protection status before they submit a swap — not just discover the cost after the fact.

  5. Lets agents swap in without a separate on-chain approval step, via a Permit2-based router — matching the gasless-approval pattern the Uniswap Trade API itself uses.

The dynamic fee curve is the product: low fee when calm, higher fee when the hook is actively defending the pool.

How it works

  1. Skew tracking — the hook maintains a rolling, decayed skew value per pool, updated on every swap.

  2. Dynamic fee tiers — the fee automatically moves between three tiers based on current skew:

    • Calm — 0.01%

    • Elevated — 0.05%

    • Defensive — 0.30%

  3. Circuit breaker — a trade projected to push skew past a hard threshold is reverted before it executes.

  4. Protection status API — agents call GET /protection-status/:poolId to see the current skew, fee tier, whether the circuit breaker is armed, and the maximum additional skew that's still safe — before they submit a swap.

    Agent ID: 5849

    StableGuard protects Uniswap v4 stable pools from impermanent loss & inventory skew with dynamic fees and protects Uniswap pools during agent-driven, yield-seeking trading & circuit breakers. Trading agents can check risk before they swap via our free API gated via x402 payment.

    ✅ Health: https://stableguard-r2fz.onrender.com/health

    ✅ Pool status (default or by ID): https://stableguard-r2fz.onrender.com/protection-status

    📦 Registration tx: https://www.oklink.com/x-layer/evm/tx/0xc6d6a6d749a06fd115934f582315479f85146be5e029e52ad63d8751e3985cdf

    👛 Hook: 0x0B46218C3FA54CC0f1E058016bc4a1f51DCB40C0

    🔗 GitHub: https://github.com/CoderOfPHCity/StableGuard

    Built for the agent economy – free, fast, and ready for action.



Progress During Hackathon

<pre><code class="language-markdown"> <span class="hljs-bullet">-</span> <span class="hljs-strong">**Circuit breaker is revert-based, not in-hook partial-fill.**</span> True partial-fill throttling requires adjusting the returned <span class="hljs-code">`BeforeSwapDelta`</span> to clamp <span class="hljs-code">`amountSpecified`</span>, with different accounting for exact-in vs. exact-out swaps. StableGuard ships the simpler "advisory max-safe-size + hard revert" version; tightening this is the natural v2 extension. <span class="hljs-bullet">-</span> <span class="hljs-strong">**Skew tracking uses a simplified magnitude+direction proxy**</span> rather than exact post-trade reserve math. Good enough for tiering and the breaker; tightenable with <span class="hljs-code">`StateLibrary`</span> reads. <span class="hljs-bullet">-</span> <span class="hljs-strong">**`StableGuardRouter`'s settlement logic (`<span class="hljs-emphasis">_settleDelta`) is the most version-sensitive file in the repo** — it has not been run against a live pool yet. `CurrencySettler`'s exact location/signature moves between v4-core releases; confirm it resolves and add a swap test before trusting this beyond a testnet demo. - **PoolManager and Permit2 addresses on X Layer testnet are unverified** as of this writing. `scripts/verify-pool-manager.sh` and `scripts/verify-permit2.sh` check both before you deploy anything real against them. - **x402 payment verification is a structural placeholder**, not real enforcement, until the OKX Payment SDK is installed — see the TODO in `x402.guard.ts`. `/protection-status` works either way since it's free regardless. </span></span></code></pre>

Tech Stack

Solidity
Next
Web3
Ethers
Node

Fundraising Status

<p>non</p>

Team LeaderDdaniel Agantem
Sector
DeFiAIInfra

Builders Also Viewed