Skip to main content

UniswapV3PoolLibrary

Git Source

Title: UniswapV3PoolLibrary

Author: 0xJem

Library for common functions on Uniswap V3 pool contracts

State Variables​

SLIPPAGE_SCALE​

uint16 public constant SLIPPAGE_SCALE = 10_000

Functions​

isValidPool​

Determines if pool_ is a valid Uniswap V3 pool

function isValidPool(address pool_) public view returns (bool);

Parameters

NameTypeDescription
pool_addressThe address of the Uniswap V3 pool

Returns

NameTypeDescription
<none>boolbool True if pool_ is a valid Uniswap V3 pool, otherwise false

getPoolTokens​

Gets the tokens for the given Uniswap V3 pool

function getPoolTokens(address pool_) public view returns (address, address);

Parameters

NameTypeDescription
pool_addressThe address of the Uniswap V3 pool

Returns

NameTypeDescription
<none>addressaddress The address of token0
<none>addressaddress The address of token1

getPoolTokenAmounts​

Gets the ordered token amounts for the given Uniswap V3 pool

function getPoolTokenAmounts(address pool_, address tokenA_, uint256 amountA_, uint256 amountB_)
public
view
returns (address token0Address, address token1Address, uint256 token0Amount, uint256 token1Amount);

Parameters

NameTypeDescription
pool_addressThe address of the Uniswap V3 pool
tokenA_addressThe address of the token to swap
amountA_uint256The amount of tokenA_ to swap
amountB_uint256The amount of tokenB_ to swap

Returns

NameTypeDescription
token0AddressaddressThe address of token0
token1AddressaddressThe address of token1
token0Amountuint256The amount of token0
token1Amountuint256The amount of token1

getAmountMin​

Convenience method to calculate the minimum amount of tokens to receive

This is calculated as amount_ * (1 - slippageTolerance)

function getAmountMin(uint256 amount_, uint16 slippageBps_) public pure returns (uint256);

Parameters

NameTypeDescription
amount_uint256The amount of tokens to calculate the minimum for
slippageBps_uint16The maximum percentage slippage allowed in basis points (100 = 1%)

Returns

NameTypeDescription
<none>uint256uint256 The minimum amount of tokens to receive

Errors​

InvalidSlippage​

Emitted if the given slippage is invalid

error InvalidSlippage(uint16 slippage_, uint16 maxSlippage_);

Parameters

NameTypeDescription
slippage_uint16The invalid slippage
maxSlippage_uint16The maximum value for slippage

InvalidParams​

error InvalidParams();