New Liquidity Position
Mint a new liquidity position for an existing pool
Contract ID: SaucerSwapV2NonfungiblePositionManager
See Liquidity position fee for an example of how to obtain the current fee, payable in HBAR, for minting a new liquidity position or adding more liquidity to an existing one.
Ensure the recipient has associated the SaucerSwapV2 LP NFT ID representing the liquidity positions before minting a new position.
When working with HBAR, use the Wrapped HBAR token ID and include the HBAR amount in the setPayableAmount() method for the ContractExecuteTransaction call.
Function name: mint
⛽ Recommended gas: 900,000 gwei (~ $0.077 USD)
Struct Parameter Name | Description |
---|---|
address token0 | EVM address of the first token |
address token1 | EVM address of the second token |
int24 tickLower | The lower end of the tick range for the position |
int24 tickUpper | The upper end of the tick range for the position |
uint256 amount0Desired | The maximum amount for the first token in its smallest unit |
uint256 amount1Desired | The maximum amount for the second token in its smallest unit |
uint256 amount0Min | The minimum amount for the first token in its smallest unit |
uint256 amount1Min | The minimum amount for the second token in its smallest unit |
address recipient | EVM address to receive the new liquidity position. |
uint deadline | Deadline in Unix seconds |
Code Overview
The following code demonstrates how to create a new liquidity position with a price range being +/- 5% from the current token price, and receive a NFT representing the position.
See Fetch pool token ratio for an example how to retrieve the latest data construct the Pool object using the Uniswap SDK library.
See Fetch all pools to retrieve the pool address, token pairs, fee tier, token IDs and decimal places for the target pool of interest.
The refundETH function operates in HBAR, but its name is derived from Uniswap on Ethereum. The name was retained to simplify integration for developers familiar with Uniswap tools. It is used to refund any excess HBAR when setting up a new liquidity position.
Hedera’s EVM chain ID can be retrieved from https://chainlist.org.
The following code is intended for guidance purposes, and does not include checks and safeguards.