Uniswap V3 | The Concentrated Liquidity [Python]

Solidity Programming Language
2 min readAug 18, 2021
https://thegraph.com/legacy-explorer/subgraph/uniswap/uniswap-v3

How to find the datas of liquidity graph in any pool of uniswap v3? For example, we want to get the datas of USDC/ETH pool (%3).

https://info.uniswap.org/#/pools/0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8

1- Firstly we go to graphql and we write the following code:

{
pools (where:{id:”0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8"})

{tick
liquidity
}
}

Output is:

liquidity”: “21590320992428719859”,
tick”: “196224”

2- Our Python code is:

tick=196224
tickA=(int(tick/60))*60
tickB=tickA+60

liquidity=21590320992428719859

USDC=6
WETH=18
decimals=WETH-USDC

sqrtB=(1.0001**(tickB/2)*(2**96))
sqrtA=(1.0001**(tickA/2)*(2**96))

amount0=((liquidity*2**96*(sqrtB-sqrtA)/sqrtB/sqrtA)/10**6)
print(amount0)

amount1=liquidity*(sqrtB-sqrtA)/2**96/10**18
print(amount1)

Output is:

amount0=3552151.9362286837 USDC
amount1=1180.9352124661852 ETH

3- We find the price

price=amount1/amount0
price

0.00033

4- Cross Check from uniswap analytics web page

https://info.uniswap.org/#/pools/0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8

ETHLocked amount is 1.18k=1180 ETH in the red bar.

USDCLocked amount is 3.552.151 USDC in the red bar.

You directly see the price ranges from app.

https://app.uniswap.org/#/add/ETH/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/

Thanks to uniswap subgraph-api discord team : kfx, loc and thogard

Do you want to see all ETH and USDC amounts in each tick ?

Atis Elsts

Mr Atis wrote the very smart and basic codes for this aim. You can see from your web site. Here and his article here

19/09/2021

Dr. Engin YILMAZ

Ankara

--

--

Solidity Programming Language

Solidity basics for beginners: Learn the fundamentals of smart contract development and build your first DApp! #Solidity #Foundry #Ethereum #Opcodes #DApps