UniswapV3PriceHelper

Documentation for eth_defi.uniswap_v3.price.UniswapV3PriceHelper class.

class UniswapV3PriceHelper[source]

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.

__init__(uniswap_v3)[source]
Parameters

uniswap_v3 (eth_defi.uniswap_v3.deployment.UniswapV3Deployment) –

get_amount_out(amount_in, path, fees, *, slippage=0)[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[NewType.<locals>.new_type]) – 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

Return type

int

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

Get how much token we are going to spend.

Parameters
  • amount_in – Amount of output asset.

  • path (list[NewType.<locals>.new_type]) – 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

  • amount_out (int) –

Return type

int