Liquidity Positions | Uniswap (2024)

Introduction

This guide will introduce us to liquidity positions in Uniswap V3 and present the v3-sdk classes and Contracts used to interact with the protocol.The concepts and code snippets showcased here can be found across the Pooling Liquidity examples in the Uniswap code examples repository.

In this guide, we will take a look at the Position and NonfungiblePositionManager classes, as well as the NonfungiblePositionManager Contract.

At the end of the guide, we should be familiar with the most important classes used to interact with liquidity positions.We should also understand how to fetch positions from the NonfungiblePositionManager Contract.

For this guide, the following Uniswap packages are used:

The code mentioned in this guide can be found across the minting Position, collecting Fees, modifying positions and swap and add liquidity examples.

Prerequisites

To understand what Positions are, we need to understand some underlying concepts of the Uniswap protocol.

Consider checking out the Concepts section as well as the Uniswap Book.

Concentrated liquidity

Uniswap V3 Pools use concentrated liquidity to allow a denser concentration of liquidity at specific prices.Compared to the full range liquidity model Uniswap V2 uses, this allows traders to make larger trades with less price impact.Liquidity providers can choose a specific price range in which they want their liquidity to be used by trades.

To achieve this, Uniswap V3 Pools discriminate the price range with Ticks.

Ticks

Ticks are the boundaries between discrete price ranges.A change of 1 Tick always represents a price change of 0.01% from the current price.Uniswap V3 Pools can have different tickSpacings, a constant that describes which ticks can be used by the Pool.Only ticks at indices that are divisible by the tickSpacing can be initialized.This value is dependant on the fee of the Pool, Pools with higher fees have higher tickSpacing.

For example, a Pool with HIGH fee (1%) has a tickSpacing of 200, meaning the price difference between initializable Ticks is:

1.0001200=1.02021.0001^{200} = 1.02021.0001200=1.0202 or 2.022.022.02%

Liquidity Positions

When someone provides liquidity to a Pool, they create a Liquidity Position.This position is defined by the amount of liquidity provided and the start tick and the end tick, or price range, of the Position.

Because V3 Pools allow users to choose any price range in which they want to provide liquidity, it is possible to create positions that do not contain the current Price of the Pool.In this case, the liquidity provider will pay only one type of Token into the Pool, creating a single side liquidity position.

To learn more about how Ticks and Liquidity positions work, consider reading the whitepaper or the other resources mentioned above.

Now that we have a rough understanding of liquidity positions in Uniswap V3, let's look at the correspondent classes the SDK offers us.

Position class

The sdk provides a Position class used to create local representations of an onchain position.It is used to create the calldata for onchain calls to mint or modify an onchain position.

There are four ways to construct a position.

Directly with the constructor:

import { Pool, Position } from '@uniswap/v3-sdk'
import JSBI from 'jsbi'

const pool = new Pool(...)
const tickLower: number = -100
const tickUpper: number = 200
const liquidity: JSBI = JSBI.BigInt('1000000000000000000')

const position = new Position({
pool,
liquidity,
tickLower,
tickUpper
})

Using the fromAmounts() function:

import { BigIntish } from '@uniswap/sdk-core'

const pool = new Pool(...)
const tickLower: number = -100
const tickUpper: number = 200
const amount0: BigIntish = '1000000000000000000'
const amount1: BigIntish = JSBI.BigInt('1000000000000000000')
const useFullPrecision: boolean = true

const position = Position.fromAmounts({
pool,
tickLower,
tickUpper,
amount0,
amount1,
useFullPrecision
})

Or using the fromAmount0() or fromAmount1() functions:

import { BigIntish } from '@uniswap/sdk-core'
...

const pool = new Pool(...)
const tickLower: number = -200
const tickUpper: number = 100
const amount0: BigIntish = '1000000000000000000'
const useFullPrecision: boolean = true

const singleSidePositionToken0 = Position.fromAmount0({
pool,
tickLower,
tickUpper,
amount0,
useFullPrecision
})

const amount1: BigIntish = 100000000

const singleSidePositionToken1 = Position.fromAmount1({
pool,
tickLower,
tickUpper,
amount1,
useFullPrecision
})

These last two functions calculate a position at the given tick range given the amount of token0 or token1. The amount of the second token is calculated from the ratio of the tokens inside the tick range and the amount of token one.

A create transaction would then fail if the wallet doesn't hold enough token1 or the Contract is not given the necessary Transfer Approval.

All of these functions take an Object with named values as a call parameter. The amount and liquidity values are of type BigIntish which accepts number, string and JSBI.

The values of tickLower and tickUpper must match initializable ticks of the Pool.

NonfungiblePositionManager

The NonfungiblePositionManager class is mainly used to create calldata for functions on the NonfungiblePositionManager Contract.

We will look at the sdk class and write functions on the Contract in this section.

Creating a Position

To create a position on a Pool, the mint function is called on the Contract.The sdk class provides the addCallParameters function to create the calldata for the transaction:

import { MintOptions, NonfungiblePositionManager } from '@uniswap/v3-sdk'

const mintOptions: MintOptions = {
recipient: address,
deadline: Math.floor(Date.now() / 1000) + 60 * 20,
slippageTolerance: new Percent(50, 10_000),
}

// get calldata for minting a position
const { calldata, value } = NonfungiblePositionManager.addCallParameters(
positionToMint,
mintOptions
)

This call creates a position if it doesn't exist, but can also be used to increase an existing position.Take a look at the Mint Position guide and Modify Position guide to learn more.

Decreasing and Increasing a Position

To decrease or increase the liquidity of a Position, the decreaseLiquidity or increaseLiquidity functions are called on the Contract.To increase, addCallParameters is used as mentioned above, to decrease we use removeCallParameters:

const { calldata, value } = NonfungiblePositionManager.removeCallParameters(
currentPosition,
removeLiquidityOptions
)

Take a look at the Modify Positions guide to learn how to create the currentPosition and removeLiquidityOptions parameters.

Collecting Fees

To collect fees accrued, the collect function is called on the Contract.The sdk class provides the collectCallParameters function to create the calldata for that:

const { calldata, value } =
NonfungiblePositionManager.collectCallParameters(collectOptions)

Next steps

Now that you are familiar with the most important classes and Contract to interact with Liquidity Positions, continue with the next guide on Minting Positions.

Liquidity Positions | Uniswap (2024)

FAQs

Liquidity Positions | Uniswap? ›

Liquidity Positions​

What is a liquidity provider position? ›

Core liquidity providers make a market for an asset by offering their holdings for sale at any given time while simultaneously buying more of them. This pushes the volume of sales higher. But it also permits investors to buy shares whenever they want to without waiting for another investor to decide to sell.

What do I receive when I provide liquidity to the pool? ›

This most often comes in the form of liquidity providers receiving crypto rewards and a portion of the trading fees that their liquidity helps facilitate. Upon providing a pool with liquidity, the provider usually receives a reward in the form of liquidity provider (LP) tokens.

What is liquidity in dex? ›

Liquidity pools are a mechanism by which users can pool their assets in a DEX's smart contracts to provide asset liquidity for traders to swap between currencies. Liquidity pools provide much-needed liquidity, speed, and convenience to the DeFi ecosystem.

What does remove liquidity mean? ›

Removing liquidity is a process of redeeming received Liquidity Provider Tokens back into the deposited tokens. By doing this, the user receives back their portion of the tokens locked in the liquidity pool.

What are liquidity positions? ›

liquidity position means the position disclosed in the liquidity report (“Liquidity Report”) required by the Trust Deed (as amended) or disclosed by methodology agreed between the Trustee and the Company if the parties agree on a different form of liquidity report.

What is a strong liquidity position? ›

A good liquidity ratio is anything greater than 1. It indicates that the company is in good financial health and is less likely to face financial hardships. The higher ratio, the higher is the safety margin that the business possesses to meet its current liabilities.

How do liquidity providers get paid? ›

LPs earn rewards through trading fees that traders pay to DEXs for every transaction. In addition, some DEXs reward LPs with governance tokens for their contribution, based on their share of the total pool liquidity. This entire process is called liquidity mining.

Do liquidity pools make money? ›

Liquidity pools pave a way for liquidity providers to earn interest on their digital assets. By locking their tokens into a smart contract, users can earn a portion of the transaction fees generated from trading activity in the pool.

What does it mean to provide liquidity? ›

Providing liquidity simply means posting a limit order (an offer to buy or sell at a specified price). A trade occurs when another trader (a liquidity demander) uses a market order to accept the terms of a posted offer.

Are liquidity pools safe? ›

Depositing your cryptoassets into a liquidity pool comes with risks. The most common risks are from DApp developers, smart contracts, and market volatility. DApp developers could steal deposited assets or squander them. Smart contracts might have flaws or exploits that lock or allow funds to be stolen.

What is an example of a liquidity pool? ›

Examples of Popular Liquidity Pools

The pool maintains a fixed product of tokens. As an example, say you deposit 1 BTC and 16 ETH, the pool will always maintain this product of tokens. The total value of ETH will always equal the total value of BTC. Constant Sum: This is also known as a Balancer pool.

Who are liquidity providers? ›

A liquidity provider by definition is a market broker or institution which behaves as a market maker in a chosen asset class. What does it mean? The liquidity provider acts at both ends of currency transactions. He sells and buys a particular asset at certain prices. It means that he is making the market.

Why is liquidity bad? ›

If a company has poor liquidity levels, it can indicate that the company will have trouble growing due to lack of short-term funds and that it may not generate enough profits to its current obligations.

How do you cash out liquidity? ›

In the "Withdraw Liquidity" panel, enter the amount of tokens you would like to withdraw from the liquidity pool (or use the slider!) and click “Withdraw Liquidity” at the bottom. Once you have entered the amounts of tokens you would like to provide to the liquidity pool, review, approve, and withdraw your liquidity!

Can you lose money providing liquidity? ›

It refers to the temporary loss of value that occurs when a user provides liquidity to a decentralised exchange (DEX) or yield-farming protocol. This loss is termed 'impermanent', as it is only realised if the user withdraws the assets from the pool.

What does a liquidity provider do? ›

A liquidity provider (often abbreviated to 'LP') is an entity which provides access to liquidity for another entity in order to achieve a specific financial purpose. In simple terms, a liquidity provider offers access to tradable instruments for another company to trade.

Do liquidity providers make money? ›

Liquidity providers use pools (like ETH/USDT, ETH/USDC, etc.) rather than traditional order books. These pools establish markets for specific token pairs, enabling anyone, including hedge funds, to participate. LPs receive tokens for their liquidity contribution and earn rewards from trading fees.

What is the difference between a broker and a liquidity provider? ›

Liquidity providers ensure that the market has tradable currency pairs and provide pricing information. While brokers link traders to liquidity providers and execute trades on behalf of the traders.

Can anyone be a liquidity provider? ›

Anyone can become a liquidity provider (LP) for a pool by depositing an equivalent value of each underlying token in return for pool tokens.

Top Articles
FBGRX - Fidelity ® Blue Chip Growth Fund
10 Best Minecraft Maps On The Marketplace
Somboun Asian Market
Cold Air Intake - High-flow, Roto-mold Tube - TOYOTA TACOMA V6-4.0
Urist Mcenforcer
Ffxiv Shelfeye Reaver
Craftsman M230 Lawn Mower Oil Change
Wisconsin Women's Volleyball Team Leaked Pictures
Cad Calls Meriden Ct
Wmu Course Offerings
Top Financial Advisors in the U.S.
Corpse Bride Soap2Day
Optum Medicare Support
Pbr Wisconsin Baseball
454 Cu In Liters
7 Low-Carb Foods That Fill You Up - Keto Tips
4156303136
Painting Jobs Craigslist
Pricelinerewardsvisa Com Activate
Kamzz Llc
EASYfelt Plafondeiland
Japanese Mushrooms: 10 Popular Varieties and Simple Recipes - Japan Travel Guide MATCHA
At&T Outage Today 2022 Map
Jordan Poyer Wiki
kvoa.com | News 4 Tucson
Cornedbeefapproved
Aes Salt Lake City Showdown
Stockton (California) – Travel guide at Wikivoyage
Kelley Fliehler Wikipedia
Willys Pickup For Sale Craigslist
County Cricket Championship, day one - scores, radio commentary & live text
Otis Offender Michigan
Stolen Touches Neva Altaj Read Online Free
Www Craigslist Com Shreveport Louisiana
How to Watch the X Trilogy Starring Mia Goth in Chronological Order
Seymour Johnson AFB | MilitaryINSTALLATIONS
Tds Wifi Outage
Elgin Il Building Department
Hindilinks4U Bollywood Action Movies
Pokemon Reborn Locations
Craigslist Tulsa Ok Farm And Garden
Cranston Sewer Tax
412Doctors
Timothy Warren Cobb Obituary
Professors Helpers Abbreviation
Dontrell Nelson - 2016 - Football - University of Memphis Athletics
Copd Active Learning Template
Bonecrusher Upgrade Rs3
The 13 best home gym equipment and machines of 2023
Kidcheck Login
Guidance | GreenStar™ 3 2630 Display
Latest Posts
Article information

Author: Amb. Frankie Simonis

Last Updated:

Views: 6073

Rating: 4.6 / 5 (76 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Amb. Frankie Simonis

Birthday: 1998-02-19

Address: 64841 Delmar Isle, North Wiley, OR 74073

Phone: +17844167847676

Job: Forward IT Agent

Hobby: LARPing, Kitesurfing, Sewing, Digital arts, Sand art, Gardening, Dance

Introduction: My name is Amb. Frankie Simonis, I am a hilarious, enchanting, energetic, cooperative, innocent, cute, joyous person who loves writing and wants to share my knowledge and understanding with you.