0

I'm interested in comparing how liquid DEX pools are, for example in order to find the pool that would have the least price impact when swapping from ETH to stablecoins.

Looking at the token balances in the pools, the DAI/WETH 0.05% pool on mainnet has $9 million total liquidity, and the USDC/WETH 0.05% pool has $154 million. Yet when querying the liquidity value from the smart contract, the DAI/WETH pool outputs a much larger value than the USDC/WETH pool. How to interpret the values?

dai_pool = web3.eth.contract(address="0x60594a405d53811d3BC4766596EFD80fd545A270", abi=v3_pool_abi)
usdc_pool = web3.eth.contract(address="0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640", abi=v3_pool_abi)
print(" DAI/WETH:", dai_pool.functions.liquidity().call())
print("USDC/WETH:", usdc_pool.functions.liquidity().call())

Output:

 DAI/WETH: 942400076766135530607937
USDC/WETH: 8454845200353069444

1 Answer 1

0

Multiply USDC/WETH liquidity by 10**6. After the multiplication it's clear that the USDC/WETH pool is indeed more liquid.

A little more detailed answer:

In order to compare the liquidity of the pools, the amounts should be normalized in order to compensate for the differences in decimals. For example, if we normalize the liquidity to 18-decimals, then the liquidity of the USDC/WETH pool should be multiplied by 10**((18-6)/2) = 10**6, since USDC has 6 decimals on the mainnet. (Similarly, for the USDC/USDT pool the liquidity should be multiplied by 10**12, since both USDC and USDT have 6 decimals.)

Even more detailed answer:

The liquidity L of a constant product AMM is defined through the formula:

L = \sqrt{x y}

where x and y are the amounts of tokens in the pool. The price impact of a trade is inversely proportional to the liquidity. In Uniswap v3 and other concentrated liquidity AMM the x and y are the virtual amounts of tokens that depend not only on the balances of the tokens in the pool but also on their price ranges (computed as in here), but that does not matter for the price impact.

When we treat x and y as the whole number of tokens with decimals d_x and d_y respectively, the formula becomes:

L = \sqrt{(10^{d_x} x ) (10^{d_y} y )}

Reordering the terms and simplifying:

L = \sqrt{10^{d_x} 10^{d_y}} \sqrt{x y}

L = 10^{\frac{d_x + d_y}{2}} \sqrt{x y}

For a pair of tokens that both have 18 decimals the first factor is equal to 10**18. For tokens with a different number of decimals, the pool's liquidity can be normalized by multiplying it with 10^{18 - \frac{d_x + d_y}{2}}.

5
  • 1
    Thanks for the great explanation. Can you please also explain how the corresponding amounts of tokens in the pool are calculated in Uniswap V3 (as there is no getReserves() function in V3), so as to get the amount of token1 in the pool equivalent to 1 unit of token0 in the same pool, and vice versa? Commented Apr 13 at 7:59
  • @SYEDASADKAZMI yeah good idea to reference this, see here ethereum.stackexchange.com/a/162522/77075
    – kfx
    Commented Apr 13 at 9:21
  • Thanks a lot. @kfx. I've asked a question in the comment there regarding how to calculate sqrtRatioX96 in V3. Kindly please see to it. Commented Apr 13 at 9:59
  • I have a question here: When I want to compare 2 pools, whose tokens decimals are for example 18/6 and 22/8, how would I proceed? Do I take the highest decimal (22) and use the formula 10**(22-((dx+dy)/2)) to normalize the liquidities for both pools? Or do I calculate one pool with 18 and the other with 22?
    – flo
    Commented May 12 at 5:55
  • 1
    @flo I don't think there any "real" tokens with decimals > 18. But if something like that appears, then yes you can take the highest decimal.
    – kfx
    Commented May 13 at 20:13

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.