
Counterweight
Self-custodial liquidity management with inventory-aware quotes and restricted treasury operations
Demo
About
Counterweight helps a treasury offer WETH/USDC liquidity while controlling the inventory allocated to its strategy. Assets remain in the maker wallet through Aqua's allocation model. Quotes encourage trades toward a target allocation, and an execution-time guard rejects trades that would exceed immutable exposure limits. We implement a custom SwapVM router with two custom instructions and a small patch to the pinned SwapVM base contract. It uses Aqua for strategy allocation accounting and actual token settlement. The custom logic combines inventory-seeking quotes with mandatory execution-time exposure checks.
How it's made
The pricing library values allocated WETH and USDC using the epoch's fixed reference price. It computes WETH weight in basis points, compares it with the target, and scales the difference by tuning intensity: skewBps = clamp((wethWeightBps - targetWethBps) × intensityBps / 10,000, -200, +200) The implementation uses integer arithmetic and applies the resulting price shift plus a directional spread to calculate exact-input output amounts. When the maker holds excess WETH, the quotes encourage traders to buy WETH from the maker, reducing its WETH allocation. This encourages movement toward the target. We use Solidity to implement the immutable epoch controller, custom SwapVM skew/guard instructions and guarded Aqua settlement. The modified upstream SwapVM retains its transfer path while adding entry and post-settlement checks. A Node.js pipeline applies the DEX-AMM query and normalization to two distinct deployments, validates identity/freshness and maps completed-day activity to bounded intensity/spread. Live standardized Graph observations from Uniswap and SushiSwap tune only bounded quote parameters. Privy provides the organization wallet, owner quorum, restricted updater and emergency signer.