I have a Uniswap V3 pool of "token A" and "token B".
Holding 1,000 of token A, and 1,000 of token B on a wallet.
Current tick in the pool is 50,000, marking the price of ~148 tokens B for 1 token A (1.0001^50000).
Want to provide liquidity in range between 45,000 and 60,000.
How can I calculate the optimal amounts to provide the largest possible liquidity?
If I simply call LiquidityAmounts.getLiquidityForAmounts()
, pool.mint()
, nonfungiblePositionManager.mint()
or any other provided function, passing it my values of 1,000 of token A and 1,000 of token B, there's going to be some excess amount (of either token A or token B) that won't be used.
So, I'm willing to swap some of the excess tokens to provide the best possible liquidity, so that all (or almost all) of the total value is used. But how to calculate the amount of tokens to swap?