i am using this code to create and initialize a pool and mint a new position on it.
// 1 ETH (y) = 2000 USDC (x)
pool = IUniswapV3Pool(factory.createPool(address(weth), address(usdc), 500));
pool.initialize(1771595571142957166518320255467520); // current tick : 200311
// mint a new position
INonfungiblePositionManager.MintParams memory params =
INonfungiblePositionManager.MintParams(
address(usdc),
address(weth),
500,
200310,
200320,
2000 * 10 ** 6, // Desired amount of token0
1 * 10 ** 18, // Desired amount of token1
1900 * 10 ** 6, // Minimum amount of token1
0.1 * 10 ** 18, // Minimum amount of token0
recepient,
block.timestamp + 33600 // Deadline 1 hour from now
);
in the above code i have initialized a pool between usdc and weth for 500 bip fee (remember usdc has 6 decimals and weth has 18) i then initialize with a sqrtpricex96 that is based upon the price exchange 1 eth = 2000 usdc.
when i use this code to calculate price from sqrtpricex96 i get the correct price
def sqrtp_to_price(p):
return (p/q96) ** 2
p = sqrtp_to_price(1771595571142957166518320255467520)
q = p * 1e6/1e18
print(q) // 0.0005
when minting a new position, i pass exactly that amount the 2000 usdc which gets used up fully but only o.1 of my 1 weth get used up, why? Is thehre a way to calculate the amounts that are going to get used up before hand as to avoid trial and error in slippage tolerance.