VinuSwapPoolDeployer

The VinuSwapPoolDeployer contract handles the deterministic deployment of VinuSwap pools.

Source: contracts/core/VinuSwapPoolDeployer.sol

Overview

The deployer is responsible for:

  • Creating pools with deterministic addresses using CREATE2

  • Passing deployment parameters to new pools

How It Works

The deployer uses a transient storage pattern to pass parameters to newly created pools:

1. Factory calls deploy() with parameters
2. Deployer stores parameters in transient storage
3. Deployer creates pool using CREATE2 with salt
4. Pool constructor calls back to deployer.parameters()
5. Pool retrieves its configuration from deployer

This pattern avoids passing constructor arguments in the bytecode, enabling deterministic addresses.

State Variables

Internal Parameter Storage

Temporarily holds deployment parameters during pool creation. Set before new VinuSwapPool() and read via parameters() during pool constructor.

parameters

Returns the current deployment parameters. Called by the pool constructor to retrieve its configuration.

Functions

deploy

Deploys a new VinuSwapPool.

Access: Internal (called by VinuSwapFactory)

Parameters:

Name
Type
Description

factory

address

Factory address

token0

address

First token (must be < token1)

token1

address

Second token

fee

uint24

Swap fee

tickSpacing

int24

Tick spacing

feeManager

address

Fee manager contract

Returns:

Name
Type
Description

pool

address

Deployed pool address

Address Computation

Pool addresses are deterministic based on:

  • Factory address (deployer)

  • Token pair and fee (salt)

  • Pool bytecode (init code hash)

Salt Calculation

Off-Chain Address Computation

PoolInitHelper

The PoolInitHelper contract provides the init code hash needed for address computation:

Source: contracts/extra/PoolInitHelper.sol

Getting the Init Code Hash

Interface

Security Considerations

  1. Inheritance: The deployer is inherited by the factory, not a standalone contract.

  2. Parameter Storage: Parameters are stored in internal variables and overwritten on each deployment. Since deploy() is internal and only callable by the factory, the parameters cannot be manipulated externally.

  3. Deterministic Addresses: The CREATE2 pattern ensures pool addresses can be computed without querying the chain.

Last updated