ShibaSwapV2Factory
The factory contract deploys and manages all ShibaSwap v2 pools. It’s responsible for creating new pools and maintaining the registry of all deployed pools.address
required
The main factory contract address that deploys all ShibaSwap v2 pools.
Functions
createPool
address
required
First token in the pool pair
address
required
Second token in the pool pair
uint24
required
Fee tier for the pool (500, 3000, 10000 for 0.05%, 0.3%, 1%)
address
required
Address of the newly created pool contract
setOwner
address
required
New owner address for the factory
enableFeeAmount
uint24
required
Fee amount in hundredths of a bip (1e-6)
int24
required
Spacing between ticks for pools with this fee tier
Once enabled, fee amounts cannot be removed from the factory.
ShibaSwapV2Pool
The core pool contract that handles all trading logic, liquidity provision, and price calculations.Key Functions
initialize
uint160
required
Initial square root price as Q64.96 fixed point number
mint
address
required
Address that will receive the liquidity position
int24
required
Lower tick boundary of the position
int24
required
Upper tick boundary of the position
uint128
required
Amount of liquidity to mint
bytes
required
Additional data passed to the callback
uint256
required
Amount of token0 required for the liquidity
uint256
required
Amount of token1 required for the liquidity
swap
address
required
Address to receive the swapped tokens
bool
required
True for token0→token1, false for token1→token0
int256
required
Amount to swap (positive for exact input, negative for exact output)
uint160
required
Price limit to prevent excessive slippage
bytes
required
Data passed to the swap callback
int256
required
Delta of token0 balance (negative = exact, positive = minimum)
int256
required
Delta of token1 balance (negative = exact, positive = minimum)
collect
address
required
Address to receive the collected fees
int24
required
Lower tick of the position
int24
required
Upper tick of the position
uint128
required
Maximum amount of token0 to collect
uint128
required
Maximum amount of token1 to collect
uint128
required
Amount of token0 fees collected
uint128
required
Amount of token1 fees collected
burn
int24
required
Lower tick of the position
int24
required
Upper tick of the position
uint128
required
Amount of liquidity to burn
uint256
required
Amount of token0 returned
uint256
required
Amount of token1 returned
flash
address
required
Address to receive the flash loan
uint256
required
Amount of token0 to flash loan
uint256
required
Amount of token1 to flash loan
bytes
required
Data passed to the flash callback
ShibaSwapV2PoolDeployer
Handles the deployment of new pool contracts.Functions
deploy
address
required
Factory contract address
address
required
First token in the pool
address
required
Second token in the pool
uint24
required
Fee tier for the pool
int24
required
Tick spacing for the pool
address
required
Address of the deployed pool contract
Interfaces
IShibaSwapV2Factory
IShibaSwapV2Pool
IShibaSwapV2PoolDeployer
Libraries
TickMath
Provides mathematical functions for working with ticks and prices.FullMath
Provides mathematical functions for working with fixed-point numbers.LiquidityMath
Provides functions for liquidity calculations.SqrtPriceMath
Provides functions for square root price calculations.Usage Examples
Creating a Pool
Adding Liquidity
Executing a Swap
Error Codes
Pool Errors
Pool Errors
LOK: Pool is lockedTLM: Tick limit exceededSPL: Slippage limit exceededIIA: Invalid input amountOF: OverflowZERO_LIQUIDITY: No liquidity in range
Factory Errors
Factory Errors
POOL_EXISTS: Pool already existsINVALID_FEE: Fee tier not enabledINVALID_TOKENS: Invalid token addressesNOT_OWNER: Only owner can call
Math Errors
Math Errors
T: Tick out of boundsPRICE_OVERFLOW: Price calculation overflowLIQUIDITY_OVERFLOW: Liquidity calculation overflow
Best Practices
1
Always check pool existence
Verify a pool exists before attempting operations.
Use
factory.getPool(tokenA, tokenB, fee) to check pool existence.2
Handle slippage properly
Set appropriate price limits for swaps.
3
Validate tick ranges
Ensure tick ranges are within valid bounds.
Ticks must be between MIN_TICK (-887272) and MAX_TICK (887272).
4
Use safe math operations
Leverage the provided libraries for mathematical operations.