Uniswap
With our SDK's Uniswap interface, you can interact directly with the protocol and perform swaps, provide liquidity, collect fees, and more.
The first step will be to instantiate the SDK as usual:
Get Pools
This function retrieves the pool addresses for a specific token pair. Because multiple pools may exist for the same pair due to varying fee tiers, the function returns an array that includes each pool address and its corresponding fee. If a pool doesn't exist, the address will be null.
Get Pool Data
This function retrieves pool data such as liquidity, current tick, fee tier, and more.
Get Token IDs
Since Uniswap positions are NFTs, they each have a unique ID that can be used to access further information regarding that position. This function retrieves all token IDs owned by a given address.
Get Position
This function fetches position data by its ID.
Get Positions
This function retrieves all positions held by a given address. It can be further filtered by specifying a pool, although it’s optional.
Observe Pool
This function retrieves historical price data for a specified pool. The secondsAgoToCheck parameter should be an array of numbers representing the number of seconds before the current time to retrieve data.
Get Swap Quotation
This function provides a quotation for a specified swap. The tokenIn parameter represents the token to be spent in the swap, while tokenOut is the token to be received in return. If either token is the native currency of the protocol, pass the currency symbol (e.g., "ETH", "MATIC", "CELO") instead of an address.
The returned object contains two components: the calculated amounts from the quotation and the prepared transaction for executing the swap, if desired.
Get Mint Position Quotation (Providing Liquidity)
This function provides a quotation for minting a new position (i.e. providing liquidity). You should provide either “amountTokenA” or “amountTokenB”, this is the value that will be used as a basis to prepare the position data. The minPriceDelta parameter defines the minimum price the position will act on, expressed as a percentage of the current price. For example, if the current price is 300 and you set a minPriceDelta of 10, the minimum price for the position will be 270. Conversely, maxPriceDelta sets the maximum price; if the current price is 300 and you set a maxPriceDelta of 20, the maximum price for the position will be 360.
Similar to other quotation functions, the response includes two parts: the calculated amounts from the quotation and the prepared transaction for executing the mint, if desired.
Get Increase Liquidity Quotation
This function may be used to increase the amount of liquidity provided in a position that already exists. The tokenId parameter is used to indicate which position you want to increase the liquidity of, and the amountTokenA or amountTokenB is the value that will be used as a basis to prepare the transaction.
Similar to other quotation functions, the response includes two parts: the calculated amounts from the quotation and the prepared transaction for executing the increase of liquidity, if desired.
Create Pool
This function creates a pool with the specified parameters and returns its address. If the pool already exists, no transaction will be made, but the address will still be returned. If one of the tokens for the pool is the protocol's native currency, use its symbol instead of an address (e.g., "ETH", "MATIC", "CELO"). The valid values for fee tiers are 100, 500, 3000, or 10000.
Increase Cardinality
In order to use the observePool function, you must first increase the pool’s cardinality using this function. The cardinality represents the amount of timestamps the pool’s data structure can hold at any given time.
Decrease Liquidity
This function may be used to withdraw liquidity either partially, by specifying a percentage lower than 100, or fully by passing 100. The tokenId parameter is used to indicate which position you want to decrease the liquidity of. The slippage refers to the percentage of price difference that is still acceptable.
Collect Fees
This function collects outstanding fees from a position.
Swap
To execute a swap, simply pass the result from the getSwapQuotation function as the transaction parameter for this function.
Mint (Provide Liquidity)
To mint a position and provide liquidity, pass the result from the getMintPositionQuotation function as the transaction parameter for this function.
Increase Liquidity
To increase liquidity for a given position, pass the result from the getIncreaseLiquidityQuotation function as the transaction parameter for this function.
Last updated