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.
To mint, call nonfungiblePositionManager.mint with MintParams.
/// @notice Calls the mint function defined in periphery, mints the same amount of each token. For this example we are providing 1000 DAI and 1000 USDC in liquidity
/// @return tokenId The id of the newly minted ERC721
/// @return liquidity The amount of liquidity for the position
/// @return amount0 The amount of token0
/// @return amount1 The amount of token1
function mintNewPosition()
external
returns (
uint256 tokenId,
uint128 liquidity,
uint256 amount0,
uint256 amount1
)
{
uint256 amount0ToMint = 1000;
uint256 amount1ToMint = 1000;
Calling Mint
TickMath.MIN_TICK / TickMath.MAX_TICK provides liquidity across the whole range. For other fee tiers, snap to the pool’s tick spacing: (TickMath.MIN_TICK / tickSpacing) * tickSpacing. Get tick spacing via pool.tickSpacing(). Tick spacings: 0.01% = 1, 0.05% = 10, 0.3% = 60, 1% = 200.
amount0Min / amount1Min are set to zero here. In production, set slippage protection to prevent frontrunning.
- This will not initialize a pool that does not yet exist.
// Approve the position manager
TransferHelper.safeApprove(DAI, address(nonfungiblePositionManager), amount0ToMint);
TransferHelper.safeApprove(USDC, address(nonfungiblePositionManager), amount1ToMint);
IRamsesV3PositionManager.MintParams memory params =
IRamsesV3PositionManager.MintParams({
token0: DAI,
token1: USDC,
fee: poolFee,
tickLower: TickMath.MIN_TICK,
tickUpper: TickMath.MAX_TICK,
amount0Desired: amount0ToMint,
amount1Desired: amount1ToMint,
amount0Min: 0,
amount1Min: 0,
recipient: address(this),
deadline: block.timestamp
});
// Note that the pool defined by DAI/USDC and fee tier 0.3% must already be created and initialized in order to mint
(tokenId, liquidity, amount0, amount1) = nonfungiblePositionManager.mint(params);
Updating The Deposit Mapping And Refunding
// Create a deposit
_createDeposit(msg.sender, tokenId);
// Remove allowance and refund in both assets.
if (amount0 < amount0ToMint) {
TransferHelper.safeApprove(DAI, address(nonfungiblePositionManager), 0);
uint256 refund0 = amount0ToMint - amount0;
TransferHelper.safeTransfer(DAI, msg.sender, refund0);
}
if (amount1 < amount1ToMint) {
TransferHelper.safeApprove(USDC, address(nonfungiblePositionManager), 0);
uint256 refund1 = amount1ToMint - amount1;
TransferHelper.safeTransfer(USDC, msg.sender, refund1);
}
}