Uniswap
The Uniswap
class from @moonup/moon-api
provides a convenient way to interact with the Uniswap protocol. This API allows you to perform various operations related to adding liquidity, removing liquidity, and swapping tokens on Uniswap.
Here's a detailed documentation for the Uniswap
class:
Initialization
To use the Uniswap
class, you need to create an instance of it with a configured HttpClient
. The HttpClient
is responsible for making HTTP requests to the Uniswap API.
Here's an example of how to create an instance of the Uniswap
class:
Class: Uniswap
Methods
addLiquidity(name: string, data: UniswapInput, params?: RequestParams)
This method is used to add liquidity to a Uniswap pool.
Parameters:
name
: The name of the Uniswap pool.data
: An object containing the input data for adding liquidity.params
: Optional request parameters.
Returns: A promise that resolves to the data of the liquidity addition.
Example:
removeLiquidity(name: string, data: UniswapInput, params?: RequestParams)
This method is used to remove liquidity from a Uniswap pool.
Parameters:
name
: The name of the Uniswap pool.data
: An object containing the input data for removing liquidity.params
: Optional request parameters.
Returns: A promise that resolves to the data of the liquidity removal.
Example:
swapExactEthForTokens(name: string, data: UniswapInput, params?: RequestParams)
This method is used to swap ETH for tokens on Uniswap.
Parameters:
name
: The name of the Uniswap pool.data
: An object containing the input data for the swap.params
: Optional request parameters.
Returns: A promise that resolves to the data of the swap.
Example:
swapExactTokensForTokens(name: string, data: UniswapInput, params?: RequestParams)
This method is used to swap tokens for tokens on Uniswap.
Parameters:
name
: The name of the Uniswap pool.data
: An object containing the input data for the swap.params
: Optional request parameters.
Returns: A promise that resolves to the data of the swap.
Example:
Usage
To use the Uniswap
class, you need to create an instance of it with a configured HttpClient
. The HttpClient
is responsible for making HTTP requests to the Uniswap API.
You can then use the uniswap
instance to call the various methods of the Uniswap
class. Make sure to handle any potential errors that may occur during the API calls using try-catch
blocks.
Last updated