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
Returns

Expected quote token amount to receive

Raises

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

Return type

int