uniswap_v3.utils
Documentation for eth_defi.uniswap_v3.utils Python module.
Uniswap v3 helper functions.
Functions
|
Decodes the path. |
|
Encode the routing path to be suitable to use with Quoter and SwapRouter. |
|
Returns the sqrt ratio as a Q64.96 corresponding to a given ratio of amount1 and amount0 |
Returns min and max tick for a given fee, this is used by default if the pool owner doesn't want to apply concentrated liquidity initially. |
|
|
Returns max tick for given fee. |
|
Returns min tick for given fee. |
|
|
|
Returns token0 (base token) amount in a liquidity range |
|
Returns token1 (quote token) amount in a liquidity range |
|
Run query on Uniswap v3 subgraph |
|
Returns price corresponding to a tick |
|
Returns square root price corresponding to a tick |
- encode_sqrt_ratio_x96(*, amount0, amount1)
Returns the sqrt ratio as a Q64.96 corresponding to a given ratio of amount1 and amount0
- Parameters
- Returns
the sqrt ratio
- Return type
- encode_path(path, fees, exact_output=False)
Encode the routing path to be suitable to use with Quoter and SwapRouter.
- For example if we would like to route the swap from token1 -> token3 through 2 pools:
pool1: token1/token2
pool2: token2/token3
then encoded path would have this format: token1 - pool1’s fee - token2 - pool2’s - token3, in which each token address length is 20 bytes and fee length is 3 bytes
- Parameters
path (list[eth_typing.evm.HexAddress]) – List of token addresses how to route the trade
fees (list) – List of trading fees of the pools in the route. BPS * 100.
exact_output (bool) – Whether the encoded path be used for exactOutput quote or swap
- Return type
- decode_path(full_path_encoded)
Decodes the path. A bit tricky. Thanks to https://degencode.substack.com/p/project-uniswapv3-mempool-watcher
- get_min_tick(fee)
Returns min tick for given fee.
Adapted from https://github.com/Uniswap/v3-periphery/blob/v1.0.0/test/shared/ticks.ts
- get_max_tick(fee)
Returns max tick for given fee.
Adapted from https://github.com/Uniswap/v3-periphery/blob/v1.0.0/test/shared/ticks.ts
- get_default_tick_range(fee)
Returns min and max tick for a given fee, this is used by default if the pool owner doesn’t want to apply concentrated liquidity initially.
- tick_to_price(tick)
Returns price corresponding to a tick
- tick_to_sqrt_price(tick)
Returns square root price corresponding to a tick
- get_token0_amount_in_range(liquidity, sp, sb)
Returns token0 (base token) amount in a liquidity range
This is derived formula based on: https://atiselsts.github.io/pdfs/uniswap-v3-liquidity-math.pdf
- Parameters
liquidity – current virtual liquidity
sp – square root current price
sb – square root upper price
- get_token1_amount_in_range(liquidity, sp, sa)
Returns token1 (quote token) amount in a liquidity range
This is derived formula based on: https://atiselsts.github.io/pdfs/uniswap-v3-liquidity-math.pdf
- Parameters
liquidity – current virtual liquidity
sp – square root current price
sb – square root lower price