Periphery Overview

Periphery contracts provide user-friendly interfaces to interact with VinuSwap core pools.

Contract Summary

Contract
Purpose
Source

Execute token swaps

contracts/periphery/SwapRouter.sol

NFT position management

contracts/periphery/NonfungiblePositionManager.sol

Estimate swap amounts

contracts/periphery/VinuSwapQuoter.sol

NFT metadata

contracts/periphery/NonfungibleTokenPositionDescriptor.sol

Architecture

┌─────────────────────────────────────────────────────────────────────────────┐
│                              USER INTERFACE                                 │
└─────────────────────────────────────────────────────────────────────────────┘
                    │                    │                    │
        exactInput/Output         mint/collect         quoteExact
                    │                    │                    │
                    ▼                    ▼                    ▼
┌─────────────────────────┐ ┌─────────────────────────┐ ┌──────────────────┐
│      SwapRouter         │ │  NonfungiblePosition    │ │  VinuSwapQuoter  │
│ ┌─────────────────────┐ │ │       Manager           │ │                  │
│ │ PeripheryPayments   │ │ │ ┌─────────────────────┐ │ │ - quoteExact     │
│ │ PeripheryValidation │ │ │ │   ERC721 + Permit   │ │ │   InputSingle    │
│ │ Multicall           │ │ │ │   Position Locking  │ │ │ - quoteExact     │
│ │ SelfPermit          │ │ │ │   LiquidityMgmt     │ │ │   OutputSingle   │
│ └─────────────────────┘ │ │ └─────────────────────┘ │ │                  │
└────────────┬────────────┘ └───────────┬─────────────┘ └────────┬─────────┘
             │                          │                        │
             │          swap()          │       mint()           │ (read-only)
             │                          │                        │
             ▼                          ▼                        ▼
┌─────────────────────────────────────────────────────────────────────────────┐
│                              VinuSwapPool                                   │
└─────────────────────────────────────────────────────────────────────────────┘

Base Contracts (Mixins)

Periphery contracts inherit from several base contracts:

PeripheryImmutableState

Stores immutable references to factory and WVC:

PeripheryPayments

Handles token transfers and VC wrapping:

PeripheryPaymentsWithFee

Extends PeripheryPayments with fee extraction:

PeripheryValidation

Provides deadline checking:

Multicall

Allows batching multiple calls:

SelfPermit

Enables permit-based approvals:

LiquidityManagement

Provides callback handling for minting:

ERC721Permit

Extends ERC721 with permit functionality for gasless approvals.

Contract Details

SwapRouter

The SwapRouter executes swaps through VinuSwap pools.

Key Features:

  • Single and multi-hop swaps

  • Exact input and exact output modes

  • Deadline and slippage protection

  • VC ↔ WVC handling

  • Permit support for gasless approvals

Full Reference →

NonfungiblePositionManager

Manages liquidity positions as ERC721 NFTs.

Key Features:

  • Mint, increase, decrease liquidity

  • Fee collection

  • Position locking (VinuSwap extension)

  • ERC721 permit support

Full Reference →

VinuSwapQuoter

Simulates swaps to return expected amounts.

Key Features:

  • Quote exact input amounts

  • Quote exact output amounts

  • Returns price after swap

  • Estimates gas cost (ticks crossed)

Full Reference →

NonfungibleTokenPositionDescriptor

Generates NFT metadata and SVG visualizations.

Key Features:

  • On-chain SVG generation

  • Token symbol/decimal lookup

  • Position visualization

Full Reference →

Common Patterns

Deadline Protection

All state-changing operations accept a deadline:

Slippage Protection

Specify minimum output (exact input) or maximum input (exact output):

Multicall Usage

Batch multiple operations:

VC Handling

The periphery contracts handle VC automatically:

VinuSwap Extensions

Position Locking

The NonfungiblePositionManager adds position locking:

Security Considerations

  1. Deadline: Always set reasonable deadlines to prevent stale transactions.

  2. Slippage: Set appropriate minimums/maximums based on market conditions.

  3. Recipient: Use address(0) for ETH unwrapping, actual address for tokens.

  4. Permit Signatures: Verify permit parameters carefully to prevent replay attacks.

Next Steps

Last updated