Documentation Index
Fetch the complete documentation index at: https://tech.ramses.xyz/llms.txt
Use this file to discover all available pages before exploring further.
Introduction
This guide will cover how to create (or mint) a liquidity position on the Ramses V3 protocol. It is based on the minting a position code example, found in the Uniswap code examples repository. To run this example, check out the examples’s README and follow the setup instructions.If you need a briefer on the SDK and to learn more about how these guides connect to the examples repository, please visit our background page!
NonfungiblePositionManager class to help us mint a liquidity position for the USDC - DAI pair. The inputs to our guide are the two tokens that we are pooling for, the amount of each token we are pooling for and the Pool fee.
The guide will cover:
- Giving approval to transfer our tokens
- Creating an instance of a
Pool - Calculating our
Positionfrom our input tokens - Configuring and executing our minting transaction
mintPosition()
Giving approval to transfer our tokens
We want to use theRamsesV3PositionManager contract to create our liqudity position.
In situations where a smart contract is transfering tokens on our behalf, we need to give it approval to do so.
This is done by interacting with the Contract of the contract, considering ERC20 Tokens are smart contracts of their own.
Considering this, the first step to create our position is to give approval to the protocol’s RamsesV3PositionManager to transfer our tokens:
getTokenTransferApprovals function. In short, since both USDC and DAI are ERC20 tokens, we setup a reference to their smart contracts and call the approve function:
0xC36442b4a4522E871399CD717aBDD847Ab11FE88.
In our example, this is defined in the constants.ts file.
Creating an instance of a Pool
Having approved the transfer of our tokens, we now need to get data about the pool for which we will provide liquidity, in order to instantiate a Pool class.
To start, we compute our Pool’s address by using a helper function and passing in the unique identifiers of a Pool - the two tokens and the Pool fee.
The fee input parameter represents the swap fee that is distributed to all in range liquidity at the time of the swap.
0x1F98431c8aD98523631AE4a59f267346ea31F984.
In our example, it is defined in constants.ts
Then, we get the Pool’s data by creating a reference to the Pool’s smart contract and accessing its methods, very similar to what we did in the Quoting guide:
Pool class:
Calculating our Position from our input tokens
Having created the instance of the Pool class, we can now use that to create an instance of a Position class, which represents the price range for a specific pool that LPs choose to provide in:
fromAmounts static function of the Position class to create an instance of it, which uses the following parameters:
- The tickLower and tickUpper parameters specify the price range at which to provide liquidity. This example calls nearestUsableTick to get the current useable tick and adjust the lower parameter to be below it by two tickSpacing and the upper to be above it by two tickSpacing. This guarantees that the provided liquidity is “in range”, meaning it will be earning fees upon minting this position
- amount0 and amount1 define the maximum amount of currency the liquidity position can use. In this example, we supply these from our configuration parameters.
fromAmounts will attempt to calculate the maximum amount of liquidity we can supply.
Configuring and executing our minting transaction
The Position instance is then passed as input to theRamsesV3PositionManager’s addCallParameters function. The function also requires an AddLiquidityOptions object as its second parameter. This is either of type MintOptions for minting a new position or IncreaseOptions for adding liquidity to an existing position. For this example, we’re using a MintOptions to create our position.
MintOptions interface requires three keys:
recipientdefines the address of the Position owner, so in our case the address of our wallet.deadlinedefines the latest point in time at which we want our transaction to be included in the blockchain.slippageTolerancedefines the maximum amount of change of the ratio of the Tokens we provide. The ratio can change if for example trades that change the price of the Pool are included before our transaction.
addCallParameters function returns the calldata as well as the value required to execute the transaction:
trace_transaction.
You can find an example of that in the Range Order guide.
In this example, we don’t need the result of the transaction.
The effect of the transaction is to mint a new Position NFT. We should see a new position with liquidity in our list of positions.
