XGuard Hook is a dynamic risk-fee Uniswap v4 Hook for new asset pools, meme pools, and low-cap pools on X Layer. It increases LP fees under high-impact or abnormal swap conditions while exposing transparent onchain risk states for traders and LPs.
中文:XGuard Hook 是 X Layer 上面向 Uniswap v4 新资产池的动态风险费率 Hook。它会根据交易冲击和异常 swap 行为实时调整 LP 手续费,并向交易者和 LP 展示链上可验证的池子风险状态。
- Dynamic LP fee override in
beforeSwap - Risk state tracking:
Normal,Warning,Protected - MVP signals: swap impact, consecutive same-direction large swaps, and block-based risk decay
- Hard threshold blocking through
XGuardSwapBlockedcustom error, not a reverted transaction event - A demo router and frontend for faucet, approval, normal swap, large swap, stress test, blocked swap, risk preview, and event stream
| State | Fee | Meaning |
|---|---|---|
| Normal | 0.30% | Normal market flow, low-cost trading |
| Warning | 1.00% | High-impact flow appears, LPs receive higher risk compensation |
| Protected | 3.00% | Pool is in a high-risk state; trading can continue with clearly higher cost |
| Hard Block | Revert | Single swap exceeds the 8% hard threshold and is rejected by custom error |
XGuard pools must be initialized as dynamic-fee Uniswap v4 pools. If the PoolKey does not use LPFeeLibrary.DYNAMIC_FEE_FLAG, the Hook's fee override will not be applied.
XGuardHook: Uniswap v4 Hook with dynamic fee and protection logicHookDeployer: small CREATE2 deployer used to mine a valid Uniswap v4 Hook address on any EVM chainDemoToken: mintable ERC20 forXGuard Meme (XGM)andGuard USD (gUSD)XGuardDemoRouter: faucet, initial liquidity helper, and exact-input swap helperDeployXGuard: X Layer mainnet deployment script
npm installFoundry is required for Solidity build and tests:
curl -L https://foundry.paradigm.xyz | bash
foundryup
forge testOn macOS, Homebrew is also a valid route:
brew install foundry
forge testFrontend build:
npm run web:buildSolidity compile fallback when forge is not available:
npm run sol:compileCombined local verification:
npm run verify
forge test
npm run submission:checkFrontend dev server:
npm run web:devThe frontend is a static Vite app and is ready for Vercel deployment.
Vercel settings are captured in vercel.json:
- install command:
npm ci - build command:
npm run web:build - output directory:
dist - deployment JSON path:
/deployments/xlayer-mainnet.json
Do not upload .env or private keys to Vercel. The frontend only needs public values:
VITE_XLAYER_RPC_URL=https://rpc.xlayer.tech
VITE_DEPLOYMENT_URL=/deployments/xlayer-mainnet.jsonCurrent X Layer mainnet deployment:
- HookDeployer:
0x2660118f58288A3bCe5041724a070aee86Fb2BCa - XGuardHook:
0xA8e58263Dd5337af93CcB29400f7341c67F200c0 - DemoRouter:
0xee9431f43B978578Db583CF49f2e0a62089c155d - XGM:
0xBeeC9123bF466a2F5C3F5C09B50F0556E978b745 - gUSD:
0x590CAE3fcc46Dc4Fc7d2C017C449a601119f545e - PoolId:
0xf296bc633edb99d1e68aa6ed981fbd496c4f1f54482d849844d8efa1025d778f
The deployed pool was restored to Normal, score 0, fee 0.30%, at block 61070079 after the onchain demo trace.
Create .env from .env.example and fund the deployer wallet with OKB for gas.
cp .env.example .env
npm run preflight:xlayer:deploy
forge script script/DeployXGuard.s.sol:DeployXGuard \
--rpc-url "$XLAYER_RPC_URL" \
--broadcastThe script writes both deployments/xlayer-mainnet.json and public/deployments/xlayer-mainnet.json, so the frontend can read the deployed addresses directly.
After deployment:
npm run verify:xlayer-deployment
npm run demo:xlayer:run
npm run submission:check:finalIf Foundry is not available, use the Node deployment fallback:
npm run deploy:xlayer:dry-run
npm run preflight:xlayer:deploy
npm run deploy:xlayer:node- Connect wallet on X Layer.
- Claim faucet tokens.
- Approve the demo router for
currency0. - Run
Normal Swapto keep the pool inNormalwith a 0.30% fee. - Run
Large Swapto trigger Warning and a higher fee. - Run
Stress Testto push the pool toward Protected. - Run
Blocked Swapto demonstrate the hard-threshold custom error surfaced in the UI.
For a repeatable onchain demo trace after deployment, run:
npm run demo:xlayer:runIt writes deployments/xlayer-demo-results.json with transaction hashes and OKLink URLs for the judge walkthrough.
- Final form fields and explorer links:
docs/final-submission-package.md - Google Form copy source:
docs/google-form-answers.md - Remaining publication steps:
docs/publication-runbook.md - Demo video script:
docs/demo-script.md - X/Twitter post drafts:
docs/social-post.md - Vercel deployment config:
vercel.json - GitHub CI workflow:
.github/workflows/ci.yml - GitHub Pages deployment workflow:
.github/workflows/pages.yml
- X Layer chain id:
196 - Uniswap v4 PoolManager:
0x360E68faccca8cA495c1B759Fd9EEe466db9FB32 - Uniswap v4 StateView:
0x76Fd297e2D437cd7f76d50F01AfE6160f86e9990 - Dynamic fee pool flag:
0x800000 - Hook address permissions:
beforeSwapandafterSwap - Hook address mining does not rely on a predeployed singleton factory; the project deploys its own
HookDeployer.
Chinese name: XGuard Hook:新资产池的动态保护层
One-liner: XGuard is a dynamic risk-fee Hook for Uniswap v4 pools on X Layer, increasing LP fees under high-impact or abnormal swap conditions while exposing transparent onchain risk states.
MIT — see LICENSE.
The license covers the source code in this repository. It does not grant rights to any third-party trademarks or brand names referenced in the documentation. The deployment addresses listed above are reference deployments, not production infrastructure.
The contracts have not been audited. Do not deploy them to mainnet with real funds without an independent security review.