IDiamondSwapV3Factory

DiamondSwap V3 Factory Interface (IDiamondSwapV3Factory)

The DiamondSwap V3 Factory Interface (IDiamondSwapV3Factory) is a critical component in the DiamondSwap protocol. It serves as the central point for creating and managing liquidity pools. This interface defines the essential functions and events that allow users to deploy new pools, manage existing ones, and query pool information. Below is a detailed breakdown of the functions and events associated with the DiamondSwap V3 Factory Interface.

Functions

feeAmountTickSpacing(uint24 fee) → int24

This function returns the tick spacing for a given fee amount. Tick spacing dictates the minimum price difference between ticks in the pool and thus influences the granularity of liquidity provision.

  • fee: The fee tier for which tick spacing is being queried.
  • Returns: An integer representing the tick spacing for the specified fee tier.

getPool(address tokenA, address tokenB, uint24 fee) → address

This function returns the address of the pool corresponding to the given token pair and fee tier. If the pool does not exist, the function will return the zero address (0x0000000000000000000000000000000000000000).

  • tokenA: The address of the first token in the pair.
  • tokenB: The address of the second token in the pair.
  • fee: The fee tier of the pool.
  • Returns: The address of the pool, or the zero address if the pool does not exist.

createPool(address tokenA, address tokenB, uint24 fee) → address

This function creates a new pool for the given token pair and fee tier. If a pool with the same parameters already exists, it will return the address of the existing pool instead of deploying a new one. This ensures that each token pair and fee tier combination has only one corresponding pool.

  • tokenA: The address of the first token in the pair.
  • tokenB: The address of the second token in the pair.
  • fee: The fee tier for the pool.
  • Returns: The address of the newly created pool or the existing pool.

setOwner(address _owner)

This function allows the current owner of the DiamondSwap V3 Factory to transfer ownership to a new address. Ownership transfer is a sensitive operation, as it confers control over the factory's administrative functions.

  • _owner: The address of the new owner.

enableFeeAmount(uint24 fee, int24 tickSpacing)

This function enables a new fee tier in the DiamondSwap V3 Factory. The fee tier determines the swap fee percentage in the pools, and the tick spacing controls the granularity of liquidity positions.

  • fee: The fee tier to be enabled.
  • tickSpacing: The tick spacing associated with the new fee tier.

owner() → address

This function returns the address of the current owner of the DiamondSwap V3 Factory. The owner has special privileges within the protocol, including enabling new fee tiers and managing factory-level parameters.

  • Returns: The address of the factory owner.

Events

OwnerChanged(address indexed oldOwner, address indexed newOwner)

This event is emitted whenever ownership of the DiamondSwap V3 Factory is transferred. It provides a record of the change in control, ensuring transparency within the protocol.

  • oldOwner: The address of the previous owner.
  • newOwner: The address of the new owner.

PoolCreated(address indexed token0, address indexed token1, uint24 indexed fee, int24 tickSpacing, address pool)

This event is emitted whenever a new pool is created in the DiamondSwap V3 Factory. It includes detailed information about the pool, such as the tokens involved, the fee tier, and the pool's address.

  • token0: The address of the first token in the pair.
  • token1: The address of the second token in the pair.
  • fee: The fee tier of the pool.
  • tickSpacing: The tick spacing of the pool.
  • pool: The address of the newly created pool.

Variables

mapping(uint24 => int24) public feeAmountTickSpacing

This mapping stores the tick spacing for each enabled fee tier. It ensures that each fee tier has a corresponding tick spacing, which influences how liquidity providers can position their liquidity within the pool.

mapping(address => mapping(address => mapping(uint24 => address))) public getPool

This is a three-level mapping that returns the address of a pool based on the two tokens involved and the fee tier. It allows for efficient lookups of pool addresses, ensuring that users can quickly find the pool they need.

  • First key: The address of the first token in the pair (tokenA).
  • Second key: The address of the second token in the pair (tokenB).
  • Third key: The fee tier for the pool.

address public owner

This variable stores the address of the current owner of the DiamondSwap V3 Factory. The owner has privileged control over the factory's operations, including the ability to enable new fee tiers and transfer ownership.

Conclusion

The DiamondSwap V3 Factory Interface (IDiamondSwapV3Factory) is a fundamental part of the DiamondSwap protocol. It provides the necessary functions to create and manage liquidity pools, query pool information, and handle administrative tasks like ownership transfer and fee tier management. Understanding this interface is crucial for developers and users who wish to interact with or build on top of the DiamondSwap protocol. Whether you're deploying new pools, managing existing ones, or simply querying pool details, this interface is your gateway to the core functionality of DiamondSwap.