PerpLib on Ethereum
Uniswap v4 Hook Contract 0xe65f1ca997766e55bf552a31d3a1e2ba17186acc on Ethereum · Launchpad · Verified contract
- Volume (24h)
- $0
- Value locked (TVL)
- $5.49
- All-time volume
- $0
- Pools using this hook
- 1
- Swaps (24h)
- 0 (0 traders)
- Total swaps
- 45
What it does
This hook runs a leveraged long and short perp on a bonding-curve pool, with positions that can be seized when TWAP-based health falls below threshold, and it routes a share of fees to insurance and a fixed recipient rather than to ordinary swappers or LPs.
This read was written for the hook 0x092f…aacc on Ethereum and reused here: the two share a code shape, so constants such as fees, owners and addresses can differ.
How it works step by step
- Library delegate-called by a perpetual-style hook that seeds single-sided token liquidity bands along a virtual bonding curve (1M supply, per-launch virtual reserve V).
- Maintains a 64-slot TWAP observation ring written from pool slot0 and used to gate borrows and liquidations.
- Scans open leveraged positions against TWAP-derived health and seizes whole unhealthy positions into a per-instance reserve, booking any unpaid band side as bad debt.
- Routes a fraction of borrow and close fees to an insurance balance and the rest to a hardcoded fee recipient claimable balance, and auto-heals bad debt from insurance.
- Pulls and refills liquidity in the v4 pool to lend ETH to longs and TOKEN to shorts, with per-band caps and a per-block borrow throttle.
- Swap behaviour
- No swap callbacks in this library; swaps are issued by the hook's internal helpers (swapEthForToken, swapTokenForEth, swapEthForExactToken) for position opens and closes, and the spike guard reverts opens when live price deviates more than about 50% from the prior block's price.
- Liquidity behaviour
- Seeds single-sided token-only bands at initialization and, during borrows, repays and refills, removes or adds single-sided liquidity in passed or ahead bands; no LP-facing add or remove callbacks are exposed to ordinary liquidity providers.
- Fee behaviour
- Fees are not set by the pool; the library splits borrow and close fees in base token between an insurance balance (rate depends on bad debt versus a threshold) and claimable[0x3F38...9cAF], a hardcoded leverage fee recipient. Static pool fee applies to external swaps.
- Owner & admin controls
- Not determinable from the provided library source alone; a paused flag blocks new opens, and the hook owner (not visible in this library) controls emergency stop and rebalance. The hook is an upgradeable proxy, so the implementation can be changed by its admin.
Enabled Uniswap v4 callbacks
beforeInitialize, beforeAddLiquidity, beforeRemoveLiquidity, beforeSwap, afterSwap, beforeSwapReturnDelta, afterSwapReturnDelta
beforeInitialize sets curve and seeds bands; beforeAddLiquidity and beforeRemoveLiquidity gate or handle liquidity changes; beforeSwap and afterSwap run the spike guard and TWAP writes; beforeSwapReturnDelta and afterSwapReturnDelta allow the hook to take or settle currency deltas to fund leveraged positions and fees.
Security & trust assessment
Risk level: high (verified source, medium confidence).
Who controls it: The proxy admin can upgrade the implementation and thereby change how positions are opened, liquidated, and how fees and reserves are moved; the owner can pause new opens.
Risk to user funds: The hook holds ETH and TOKEN for leveraged positions, reserves and insurance, and can move band liquidity; users face liquidation seizure, bad-debt shortfalls, and implementation-upgrade risk.
Security findings
- [high] Upgradeable proxy implementation: The hook delegates all calls to implementation 0xf52a...250a behind a proxy, so the admin can replace the logic that controls pool funds, positions and fee routing.
- [medium] Return deltas let the hook move pool funds: beforeSwapReturnDelta and afterSwapReturnDelta permit the hook to take or settle currency, and borrow and refill paths move band liquidity and tokens held by the hook.
- [medium] Liquidation seizes whole positions with bad debt in bands: scanAndLiquidate seizes entire positions into the reserve, and any unpaid band side is flagged as realized shortfall rather than settled, so LPs or lenders absorb losses until insurance or reserve recycling covers them.
- [medium] Health depends on TWAP and prior-block spike guard: Liquidation health and borrow eligibility read the TWAP ring and a 50% prior-block spike check; an observation ring that is stale or thinly updated can gate or allow liquidations unexpectedly.
- [low] Hardcoded fee recipient: Leverage fees accrue to a fixed address with no setter in this code, so fee routing cannot be changed without an implementation upgrade.
Contract details
- Verified source
- Yes (PerpLib)
- Compiler
- solc 0.8.33+commit.64118f21
- Bytecode size
- 19,491 bytes
- Upgradeable proxy
- Yes
- Detected patterns
- erc20, return-delta, upgradeable
Pools using PerpLib
- ASTEROID / ASTEROID (0.00% fee) — 24h volume $0, TVL $5.49, 0 swaps today