Complete reference for ShibaSwap v2 core smart contracts, interfaces, and libraries
ShibaSwap v2’s core smart contracts provide the foundation for decentralized trading, liquidity provision, and pool management. This reference covers all core contracts, interfaces, and libraries.
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.
Provides mathematical functions for working with ticks and prices.
Copy
library TickMath { /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128 int24 internal constant MIN_TICK = -887272; /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128 int24 internal constant MAX_TICK = -MIN_TICK; /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK) uint160 internal constant MIN_SQRT_RATIO = 4295128739; /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK) uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342; /// @dev Returns the sqrt ratio as a Q64.96 for the given tick. The sqrt ratio is computed as sqrt(1.0001)^tick /// @param tick the tick for which to compute the sqrt ratio function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96); /// @dev Returns the tick corresponding to a given sqrt ratio, reverting if input is not between MIN_SQRT_RATIO and MAX_SQRT_RATIO /// @param sqrtPriceX96 the sqrt ratio for which to compute the tick as a Q64.96 function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick);}
Provides mathematical functions for working with fixed-point numbers.
Copy
library FullMath { /// @dev Returns the full product of two unsigned 256-bit numbers function mulDiv( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result); /// @dev Returns the full product of two unsigned 256-bit numbers, and the intermediate value function mulDivRoundingUp( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result);}
library LiquidityMath { /// @dev Add a signed liquidity delta to liquidity and revert if it overflows or underflows function addDelta(uint128 x, int128 y) internal pure returns (uint128 z);}
Provides functions for square root price calculations.
Copy
library SqrtPriceMath { /// @dev Returns the next sqrt price given an input amount of token0 or token1 function getNextSqrtPriceFromInput( uint160 sqrtPriceX96, uint128 liquidity, uint256 amountIn, bool zeroForOne ) internal pure returns (uint160 sqrtPriceNextX96); /// @dev Returns the next sqrt price given an output amount of token0 or token1 function getNextSqrtPriceFromOutput( uint160 sqrtPriceX96, uint128 liquidity, uint256 amountOut, bool zeroForOne ) internal pure returns (uint160 sqrtPriceNextX96); /// @dev Returns the amount0 delta between two prices function getAmount0Delta( uint160 sqrtPriceAX96, uint160 sqrtPriceBX96, uint128 liquidity, bool roundUp ) internal pure returns (uint256 amount0); /// @dev Returns the amount1 delta between two prices function getAmount1Delta( uint160 sqrtPriceAX96, uint160 sqrtPriceBX96, uint128 liquidity, bool roundUp ) internal pure returns (uint256 amount1);}
// Deploy a new poolIShibaSwapV2Factory factory = IShibaSwapV2Factory(FACTORY_ADDRESS);address pool = factory.createPool(SHIB_ADDRESS, WETH_ADDRESS, 3000);// Initialize the pool with a priceIShibaSwapV2Pool(pool).initialize(encodeSqrtRatioX96(1, 1)); // 1:1 price
// Mint liquidity in a specific rangeIShibaSwapV2Pool pool = IShibaSwapV2Pool(POOL_ADDRESS);(uint256 amount0, uint256 amount1) = pool.mint( recipient, tickLower, tickUpper, liquidity, data);