UniswapV3PriceHelper

Documentation for eth_defi.uniswap_v3.price.UniswapV3PriceHelper Python class.

class UniswapV3PriceHelper[source]

Internal helper class for price calculations.

Methods summary

__init__(uniswap_v3)

get_amount_in(amount_out, path, fees, *[, ...])

Get how much token we are going to spend.

get_amount_out(amount_in, path, fees, *[, ...])

Get how much token we are going to receive.

validate_args(path, fees, slippage, amount)

__init__(uniswap_v3)[source]
Parameters

uniswap_v3 (eth_defi.uniswap_v3.deployment.UniswapV3Deployment) –

get_amount_out(amount_in, path, fees, *, slippage=0, block_identifier=None)[source]

Get how much token we are going to receive.

Example:

# Estimate how much DAI we will receive for 1000 WETH
# using the route of 2 pools: WETH/USDC 0.3% and USDC/DAI 1%
# with slippage tolerance is 0.5%
price_helper = UniswapV3PriceHelper(uniswap_v3_deployment)
amount_out = price_helper.get_amount_out(
    1000,
    [
        weth.address,
        usdc.address,
        dai.address,
    ],
    [
        3000,
        10000,
    ],
    slippage=50,
)
Parameters
  • amount_in (int) – Amount of input asset.

  • path (list[eth_typing.evm.HexAddress]) – List of token addresses how to route the trade

  • fees (list[int]) – List of trading fees of the pools in the route

  • slippage (float) – Slippage express in bps

  • block_identifier (Optional[int]) – A specific block to estimate price

Return type

int

get_amount_in(amount_out, path, fees, *, slippage=0, block_identifier=None)[source]

Get how much token we are going to spend.

Parameters
  • amount_in – Amount of output asset.

  • path (list[eth_typing.evm.HexAddress]) – List of token addresses how to route the trade

  • fees (list[int]) – List of trading fees of the pools in the route

  • slippage (float) – Slippage express in bps

  • block_identifier (Optional[int]) – A specific block to estimate price

  • amount_out (int) –

Return type

int