Uniswap

Git Source

State Variables

_INIT_CODE_HASH

bytes32 private constant _INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54;

Functions

info

Wrapper around IUniswapV3Pool.positions() that assumes positions is owned by this

function info(Position memory position, IUniswapV3Pool pool) internal view returns (PositionInfo memory positionInfo);

info

Wrapper around IUniswapV3Pool.positions().

function info(
    Position memory position,
    IUniswapV3Pool pool,
    address owner
) internal view returns (PositionInfo memory positionInfo);

fees

function fees(
    Position memory position,
    IUniswapV3Pool pool,
    PositionInfo memory positionInfo,
    FeeComputationCache memory c
) internal view returns (uint256 amount0, uint256 amount1);

liquidityForAmount0

function liquidityForAmount0(Position memory position, uint256 amount0) internal pure returns (uint128);

liquidityForAmount0

Computes the amount of liquidity received for a given amount of token0 and price range

Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower))

function liquidityForAmount0(
    uint160 sqrtRatioAX96,
    uint160 sqrtRatioBX96,
    uint256 amount0
) internal pure returns (uint128 liquidity);

Parameters

NameTypeDescription
sqrtRatioAX96uint160A sqrt price representing the first tick boundary
sqrtRatioBX96uint160A sqrt price representing the second tick boundary
amount0uint256The amount0 being sent in

Returns

NameTypeDescription
liquidityuint128The amount of returned liquidity

liquidityForAmount1

function liquidityForAmount1(Position memory position, uint256 amount1) internal pure returns (uint128);

liquidityForAmount1

Computes the amount of liquidity received for a given amount of token1 and price range

Calculates amount1 / (sqrt(upper) - sqrt(lower)).

function liquidityForAmount1(
    uint160 sqrtRatioAX96,
    uint160 sqrtRatioBX96,
    uint256 amount1
) internal pure returns (uint128 liquidity);

Parameters

NameTypeDescription
sqrtRatioAX96uint160A sqrt price representing the first tick boundary
sqrtRatioBX96uint160A sqrt price representing the second tick boundary
amount1uint256The amount1 being sent in

Returns

NameTypeDescription
liquidityuint128The amount of returned liquidity

liquidityForAmounts

function liquidityForAmounts(
    Position memory position,
    uint160 sqrtPriceX96,
    uint256 amount0,
    uint256 amount1
) internal pure returns (uint128);

liquidityForAmounts

Computes the maximum amount of liquidity received for a given amount of token0, token1, the current pool prices and the prices at the tick boundaries

function liquidityForAmounts(
    uint160 sqrtRatioX96,
    uint160 sqrtRatioAX96,
    uint160 sqrtRatioBX96,
    uint256 amount0,
    uint256 amount1
) internal pure returns (uint128 liquidity);

Parameters

NameTypeDescription
sqrtRatioX96uint160A sqrt price representing the current pool prices
sqrtRatioAX96uint160A sqrt price representing the first tick boundary
sqrtRatioBX96uint160A sqrt price representing the second tick boundary
amount0uint256The amount of token0 being sent in
amount1uint256The amount of token1 being sent in

Returns

NameTypeDescription
liquidityuint128The maximum amount of liquidity received

amountsForLiquidity

Wrapper around LiquidityAmounts.getAmountsForLiquidity().

function amountsForLiquidity(
    Position memory position,
    uint160 sqrtPriceX96,
    uint128 liquidity
) internal pure returns (uint256, uint256);

valueOfLiquidity

Wrapper around LiquidityAmounts.getValueOfLiquidity()

function valueOfLiquidity(
    Position memory position,
    uint160 sqrtPriceX96,
    uint128 liquidity
) internal pure returns (uint256);

computePoolAddress

function computePoolAddress(
    address factory,
    address token0,
    address token1,
    uint24 fee
) internal pure returns (IUniswapV3Pool pool);

_fees

function _fees(
    PositionInfo memory positionInfo,
    uint256 feeGrowthInside0X128,
    uint256 feeGrowthInside1X128
) private pure returns (uint256 amount0, uint256 amount1);

Structs

Position

struct Position {
    int24 lower;
    int24 upper;
}

PositionInfo

struct PositionInfo {
    uint128 liquidity;
    uint256 feeGrowthInside0LastX128;
    uint256 feeGrowthInside1LastX128;
    uint128 tokensOwed0;
    uint128 tokensOwed1;
}

FeeComputationCache

struct FeeComputationCache {
    int24 currentTick;
    uint256 feeGrowthGlobal0X128;
    uint256 feeGrowthGlobal1X128;
}