1

I am trying to create a Liquidity Pool using solidity with ETH and my custom ERC20 token. I’ve been struggling with this mainly because the example for V3 is a ERC20 to ERC20 pair.

Does Uniswap convert the ETH to WETH automatically or will I have to wrap my ETH before I create the pool for ETH/ERC20 token??

No code yet just trying to understand Uniswap V3

1 Answer 1

3

I'm assuming you refer to the official Uniswap V3 example here : https://docs.uniswap.org/sdk/guides/liquidity/adding and that your pool is initialized

Short answer: Uniswap handles the (un)wrapping.

Complete answer :

The main idea in adding liquidity is similar to how swaps are performed in V3:

  • start from a periphery (optional) "helper" (NonfungiblePositionManager.sol here), which is inheriting LiquidityManagement.sol (from periphery/base). This is where you can find the (internal) addLiquidity function which, after computing the amount (price for start and end tick and Struct packing) will...
  • ...call the low-level-ish mint function on the pool itself. This function is quite short, and can be summarized as: take note of the current pool balances - call the callback - take note and comparing the new pool balances.

The actual token transfers are done in the callback, which must be implemented by the contract calling pool.mint (here, LiquidityManagement does it for you). The callback uses pay() (from base/peripheryPayment), where you can easily see the (un)wrapping mechanism (pay is used by the swap callback too).

if (token == WETH9 && address(this).balance >= value) {
        // pay with WETH9
        IWETH9(WETH9).deposit{value: value}(); // wrap only what is needed to pay
        IWETH9(WETH9).transfer(recipient, value);

Control schema:

 Periphery                Core
addLiquidity      --->  pool.mint
mintCallback&Pay  <---  
                  --->  pool.mint
2
  • Thank you! This is extremely helpful. I have one final question. I am able to follow the control schema up until the "mintCallBack". Where/When is the callback function called? Does this happen during "pool.mint"? Nov 8, 2021 at 17:25
  • Yes, here: github.com/Uniswap/v3-core/blob/… Don't forget to mark the question as answered then;) Nov 8, 2021 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.