Index of every page on this site: llms.txt
All skills
whetstoneresearch avatar

/uniswap-fundamentals

@4f654fe
Run it yourself

Reference for Uniswap V3/V4 concepts used in Doppler development, including tick math, sqrtPriceX96, concentrated liquidity formulas, and V4 hooks/singleton architecture.

Use this Skill: https://skilld.dev/gh/whetstoneresearch/doppler-skills/uniswap-fundamentals

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesV4-ARCHITECTURE.md

≈1.5k tokens on demand. Your agent reads this file only when SKILL.md points to it.

V4 Architecture

Uniswap V4-specific architectural features. All content on this page is V4-only.


V3 → V4 Architecture Comparison

Aspect V3 V4
Pool contracts One contract per pool Single PoolManager for all pools
Pool creation Deploy new contract Call PoolManager.initialize()
Pool identifier Contract address PoolKey hash (PoolId)
Token transfers Per-operation Batched via flash accounting
Fee configuration Fixed at creation Dynamic (can change per-swap)
Native ETH No (WETH required) Yes
Extensibility Limited Hooks system

Singleton Design [V4 Only]

All pools are managed by a single PoolManager.sol contract.

Benefits

  • Gas efficiency: No cross-contract calls between pools
  • Simplified routing: Multi-hop swaps in single transaction
  • Flash accounting: Net token transfers across operations

Pool Identification

Pools are identified by PoolKey:

struct PoolKey {
    Currency currency0;      // First token (lower address)
    Currency currency1;      // Second token (higher address)
    uint24 fee;             // Fee tier
    int24 tickSpacing;      // Tick spacing
    IHooks hooks;           // Hook contract address
}

PoolId is the keccak256 hash of the PoolKey.

V3 difference: In V3, each pool has its own contract address. In V4, pools don't have addresses - they're identified by their PoolKey.

Source: Uniswap V4 Docs


Flash Accounting (EIP-1153) [V4 Only]

V4 uses transient storage (EIP-1153) for efficient balance tracking.

How It Works

  1. Start: Call PoolManager.unlock()
  2. Operations: Perform swaps, mints, burns (no token transfers yet)
  3. Tracking: PoolManager tracks net balance changes in transient storage
  4. Settlement: At end, settle net amounts with actual transfers
  5. Clear: Transient storage auto-clears after transaction

Benefits

  • Gas savings: Only net amounts transferred
  • Multi-operation efficiency: Swap A→B→C with single A-in, C-out transfer
  • Atomicity: All operations succeed or all fail

Code Pattern

// V4 pattern with flash accounting
poolManager.unlock(callbackData);

function unlockCallback(bytes calldata data) external {
    // Perform multiple operations
    poolManager.swap(...);
    poolManager.modifyLiquidity(...);

    // Settle net balances
    poolManager.settle(currency);  // Pay what you owe
    poolManager.take(currency);    // Receive what you're owed
}

V3 difference: V3 transfers tokens for each operation. V4 batches all transfers to the end.

Source: Uniswap V4 Docs


Dynamic Fees [V4 Only]

V4 allows fees to change dynamically.

Fee Types

Type Description
Static Set at pool creation, never changes (like V3)
Dynamic Can be updated by hooks

Dynamic Fee Implementation

Hooks can implement getFee() to return custom fees:

function getFee(
    address sender,
    PoolKey calldata key,
    IPoolManager.SwapParams calldata params,
    bytes calldata hookData
) external view returns (uint24 fee);

Fee Update Methods

  • Per-swap: Hook returns fee in beforeSwap
  • Per-block: Hook tracks block number, updates periodically
  • Custom schedule: Any logic the hook implements

V3 difference: V3 fees are immutable after pool creation (0.01%, 0.05%, 0.30%, or 1.00%).

Source: Uniswap V4 Docs


Native ETH Support [V4 Only]

V4 supports native Ether directly, without WETH wrapping.

How It Works

  • Pools can use address(0) or a special ETH sentinel as currency
  • Swaps can send/receive native ETH
  • No WETH9 wrapping/unwrapping required

Benefits

  • Gas savings: No wrap/unwrap transactions
  • UX improvement: Users transact with native ETH
  • Fewer approvals: No WETH approval needed

V3 difference: V3 requires WETH9 wrapping for all ETH operations.

Source: Uniswap V4 Docs


Custom Accounting [V4 Only]

Hooks can modify token amounts in swaps and liquidity operations.

Capabilities

  • Custom curves: Implement non-x*y=k pricing
  • Hook fees: Take additional fees beyond LP fees
  • Rebates: Return tokens to users under certain conditions
  • Synthetic assets: Mint/burn tokens based on swap activity

Implementation

Hooks use return deltas to adjust amounts:

function afterSwap(
    address sender,
    PoolKey calldata key,
    IPoolManager.SwapParams calldata params,
    BalanceDelta delta,
    bytes calldata hookData
) external returns (bytes4, int128 hookDelta);

V3 difference: V3 has no mechanism for custom accounting - amounts are determined solely by the AMM formula.


Pool Initialization [V4 Only]

Creating a V4 pool:

poolManager.initialize(
    PoolKey({
        currency0: Currency.wrap(token0),
        currency1: Currency.wrap(token1),
        fee: 3000,           // 0.30%
        tickSpacing: 60,
        hooks: IHooks(hookAddress)  // or address(0) for no hooks
    }),
    sqrtPriceX96           // Initial price
);

V3 difference: V3 uses a factory pattern (UniswapV3Factory.createPool()), which deploys a new contract.


Doppler V4 Usage

Doppler's V4 contracts (Doppler hook, UniswapV4MulticurveInitializer) use:

V4 Feature Doppler Usage
Singleton All pools via single PoolManager
Flash accounting Unlock pattern for position management
Hooks Doppler.sol implements beforeSwap/afterSwap for rebalancing
Dynamic fees initialLpFee set at init, can be overridden
PoolKey identification Store state by PoolId hash

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts2mo5 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill serves as a mathematical and architectural reference for Uniswap V3 and V4 protocols, specifically tailored for the Doppler project. It contains documentation on liquidity formulas, tick math, and V4 hook lifecycles. All external links point to official documentation or the author's own code repository.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

  • Runlayer8mo

    5 files scanned · No issues

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 4f654fe. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 9 months ago
metadata
{
  "author": "uniswap",
  "version": "2.0",
  "source": "docs.uniswap.org"
}

README badge

README badge for whetstoneresearch/doppler-skills/uniswap-fundamentals