UniswapV2FeeCalculator

Documentation for eth_defi.uniswap_v2.fees.UniswapV2FeeCalculator class.

class UniswapV2FeeCalculator[source]

A helper class to estimate Uniswap fees.

Methods summary

__init__(uniswap_v2)

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

Get how much token we are going to spend.

get_amount_in_from_reserves(amount_out, ...)

Returns the minimum input asset amount required to buy the given output asset amount (accounting for fees) given reserves.

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

Get how much token we are going to receive.

get_amount_out_from_reserves(amount_in, ...)

Given an input asset amount, returns the maximum output amount of the other asset (accounting for fees) given reserves.

get_reserves(token_a, token_b)

Gets the reserves of token_0 and token_1 used to price trades and distribute liquidity as well as the timestamp of the last block during which an interaction occurred for the pair.

__init__(uniswap_v2)[source]
Parameters

uniswap_v2 (eth_defi.uniswap_v2.deployment.UniswapV2Deployment) –

get_reserves(token_a, token_b)[source]

Gets the reserves of token_0 and token_1 used to price trades and distribute liquidity as well as the timestamp of the last block during which an interaction occurred for the pair.

Parameters
  • pair – Address of the pair.

  • token_a (HexAddress) –

  • token_b (HexAddress) –

Returns

  • reserve_0 - Amount of token_0 in the contract.

  • reserve_1 - Amount of token_1 in the contract.

  • liquidity - Unix timestamp of the block containing the last pair interaction.

Return type

tuple[int]

get_amount_out(amount_in, path, *, fee=30, slippage=0)[source]

Get how much token we are going to receive.

Parameters
  • amount_in (int) – Amount of input asset.

  • path (list[NewType.<locals>.new_type]) – List of token addresses how to route the trade

  • fee (int) – Trading fee express in bps, default = 30 bps (0.3%)

  • slippage (float) – Slippage express in bps

Returns

Return type

int

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

Get how much token we are going to spend.

Parameters
  • amount_out (int) – Amount of output asset.

  • path (list[NewType.<locals>.new_type]) – List of token addresses how to route the trade

  • fee (int) – Trading fee express in bps, default = 30 bps (0.3%)

  • slippage (float) – Slippage express in bps

Returns

Return type

int

static get_amount_in_from_reserves(amount_out, reserve_in, reserve_out, *, fee=30)[source]

Returns the minimum input asset amount required to buy the given output asset amount (accounting for fees) given reserves.

Parameters
  • amount_out (int) – Amount of output asset.

  • reserve_in (int) – Reserve of input asset in the pair contract.

  • reserve_out (int) – Reserve of output asset in the pair contract.

  • fee (int) – Trading fee express in bps, default = 30 bps (0.3%)

Returns

Required amount of input asset.

Return type

int

static get_amount_out_from_reserves(amount_in, reserve_in, reserve_out, *, fee=30)[source]

Given an input asset amount, returns the maximum output amount of the other asset (accounting for fees) given reserves.

Parameters
  • amount_in (int) – Amount of input asset.

  • reserve_in (int) – Reserve of input asset in the pair contract.

  • reserve_out (int) – Reserve of output asset in the pair contract.

  • fee (int) – Trading fee express in bps, default = 30 bps (0.3%)

Returns

Maximum amount of output asset.

Return type

int