estimate_buy_received_amount_raw

Documentation for eth_defi.uniswap_v2.fees.estimate_buy_received_amount_raw function.

estimate_buy_received_amount_raw(uniswap, base_token_address, quote_token_address, quantity_raw, *, fee=30, slippage=0, intermediate_token_address=None)[source]

Estimate how much we receive for a certain cash amount.

Example:

# Create the trading pair and add initial liquidity
deploy_trading_pair(
    web3,
    deployer,
    uniswap_v2,
    weth,
    usdc,
    1_000 * 10**18,  # 1000 ETH liquidity
    1_700_000 * 10**18,  # 1.7M USDC liquidity
)

# Estimate the price of buying 1650 USDC worth of ETH
eth_received = estimate_buy_received_amount_raw(
    uniswap_v2,
    weth.address,
    usdc.address,
    1650 * 10**18,
)

assert eth_received / (10**18) == pytest.approx(0.9667409780905836)

# Calculate price of ETH as $ for our purchase
price = (1650*10**18) / eth_received
assert price == pytest.approx(Decimal(1706.7653460381143))
Parameters
  • quantity – How much of the base token we want to buy

  • uniswap (eth_defi.uniswap_v2.deployment.UniswapV2Deployment) – Uniswap v2 deployment

  • base_token – Base token of the trading pair

  • quote_token – Quote token of the trading pair

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

  • slippage (float) – Slippage express in bps

  • base_token_address (eth_typing.evm.HexAddress) –

  • quote_token_address (eth_typing.evm.HexAddress) –

  • quantity_raw (decimal.Decimal) –

  • intermediate_token_address (Optional[eth_typing.evm.HexAddress]) –

Returns

Expected quote token amount to receive

Raises

TokenDetailError – If we have an issue with ERC-20 contracts

Return type

int