Core Overview

The core contracts provide the fundamental AMM functionality and safety guarantees for VinuSwap.

Contract Summary

Contract
Purpose
Source

Pool deployment and registry

contracts/core/VinuSwapFactory.sol

Concentrated liquidity AMM

contracts/core/VinuSwapPool.sol

Deterministic pool deployment

contracts/core/VinuSwapPoolDeployer.sol

NoDelegateCall

Security mixin

contracts/core/NoDelegateCall.sol

Architecture

┌─────────────────────────────────────────────────────────────────┐
│                     VinuSwapFactory                             │
│  - createPool()                                                 │
│  - getPool()                                                    │
│  - owner management                                             │
└──────────────────────────┬──────────────────────────────────────┘

                           │ creates via VinuSwapPoolDeployer

┌─────────────────────────────────────────────────────────────────┐
│                      VinuSwapPool                               │
│  ┌──────────────────┐  ┌──────────────────┐                    │
│  │      Slot0       │  │    Positions     │                    │
│  │  sqrtPriceX96    │  │  owner→liquidity │                    │
│  │  tick            │  │  feeGrowthInside │                    │
│  │  observationIdx  │  │                  │                    │
│  │  feeProtocol     │  │                  │                    │
│  └──────────────────┘  └──────────────────┘                    │
│                                                                 │
│  ┌──────────────────┐  ┌──────────────────┐                    │
│  │     Ticks        │  │   Observations   │                    │
│  │  liquidityDelta  │  │  tickCumulative  │                    │
│  │  feeGrowthOut    │  │  secondsPerLiq   │                    │
│  └──────────────────┘  └──────────────────┘                    │
│                                                                 │
│  Core Functions:                                                │
│  - initialize()  - swap()   - mint()   - burn()                │
│  - collect()     - observe()                                    │
└─────────────────────────────────────────────────────────────────┘

Key Differences from Uniswap V3

1. Fee Manager Integration

Every pool is created with a feeManager address that can dynamically modify swap fees:

The fee manager is called during swaps:

2. Owner-Only Pool Creation

Unlike Uniswap V3's permissionless pool creation, VinuSwap restricts pool creation to the factory owner:

3. Flexible Tick Spacing

VinuSwap allows custom tick spacing per pool (within bounds) rather than fixed fee-tier mappings:

Immutable Pool Parameters

Each pool stores these values immutably at deployment:

Parameter
Description

factory

Address of VinuSwapFactory

token0

First token (lower address)

token1

Second token (higher address)

fee

Swap fee in hundredths of a bip (e.g., 3000 = 0.3%)

tickSpacing

Minimum tick distance for positions

maxLiquidityPerTick

Maximum liquidity at any tick

feeManager

Address of fee computation contract

Pool State Variables

Slot0

The primary state slot containing current pool status:

Global Fee Accumulators

Protocol Fees

Liquidity

Security Features

Reentrancy Protection

All state-changing functions are protected:

Delegatecall Prevention

Core contracts cannot be used as implementation targets:

Events

Pool Events

Event
Emitted When

Initialize

Pool price is set for the first time

Mint

Liquidity is added to a position

Burn

Liquidity is removed from a position

Swap

A swap is executed

Collect

Fees are collected from a position

CollectProtocol

Protocol fees are withdrawn

SetFeeProtocol

Protocol fee setting is changed

IncreaseObservationCardinalityNext

Oracle capacity increased

Factory Events

Event
Emitted When

PoolCreated

New pool is deployed

OwnerChanged

Factory ownership transfers

Error Messages

Error
Meaning

LOK

Reentrancy detected

TLU

tickLower >= tickUpper

TLM

tickLower < MIN_TICK

TUM

tickUpper > MAX_TICK

AI

Pool already initialized

M0

Mint amount cannot be 0

AS

Amount specified cannot be 0

IIA

Invalid input amount

SPL

sqrtPriceLimit invalid

L

Liquidity overflow

Next Steps

Last updated