coderofphcity/stableguard — explained in plain English
Analysis updated 2026-05-18
Protect a Uniswap v4 liquidity pool from impermanent loss caused by automated trading agents skewing its token balance.
Check a pool's live risk level and safe trade size via an API before submitting a swap.
Let trading agents swap without a separate token approval transaction using a Permit2-based router.
| coderofphcity/stableguard | agus-ops/amphi | alexzoid-eth/morpho-midnight-fv | |
|---|---|---|---|
| Stars | 0 | 0 | 0 |
| Language | Solidity | Solidity | Solidity |
| Setup difficulty | hard | hard | moderate |
| Complexity | 4/5 | 4/5 | 4/5 |
| Audience | developer | developer | developer |
Figures from each repo's GitHub metadata at analysis time.
Requires Foundry for the Solidity contracts and testnet tokens for the deployed chain, the hackathon demo runs on the Arc testnet instead of the originally intended X Layer.
StableGuard is a smart contract built for the Uniswap decentralized exchange, made for a hackathon called the OKX.AI Genesis Hackathon. It plugs into Uniswap version 4's hook system, which lets developers add custom logic that runs before and after each trade in a liquidity pool. Its purpose is to protect the people who provide liquidity to a pool from a specific risk: as automated trading agents chase yield across stablecoin pools, their trading can quietly push a pool's balance of tokens out of proportion, exposing liquidity providers to losses. The contract tracks how skewed a pool's balance is after every trade and automatically raises the trading fee as that skew increases, moving through three tiers described as calm, elevated, and defensive. If a trade would push the pool's imbalance past a safety limit, the contract blocks that trade outright rather than letting it through. A separate, simple web service lets other automated trading agents check a pool's current risk level, fee tier, and how much more imbalance it can safely absorb before they submit a trade, so they can decide in advance whether a swap is safe. The project also includes a router that lets agents swap without a separate approval transaction first, using a token approval standard called Permit2. The README is upfront about two simplifications in the current version: instead of partially filling an oversized trade, the circuit breaker currently blocks it entirely, and the imbalance calculation uses an approximate measure rather than exact reserve math. The author notes the contracts were meant for a different blockchain network called X Layer, but were deployed to a testnet called Arc instead due to trouble obtaining test tokens, with plans to extend to more chains later. The project is licensed under MIT.
A Uniswap v4 hook smart contract that protects liquidity providers by raising trading fees and blocking trades as a pool's token balance becomes skewed by automated trading agents.
Mainly Solidity. The stack also includes Solidity, Foundry, Uniswap v4.
MIT license, free to use, modify, and distribute, including commercially, as long as you keep the copyright notice.
Setup difficulty is rated hard, with roughly 1h+ to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Don't trust strangers blindly. Verify against the repo.