estimate_sell_received_amount_raw

Documentation for eth_defi.uniswap_v2.fees.estimate_sell_received_amount_raw function.

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

Estimate how much cash we receive for a certain quantity of tokens sold.

Example:

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
)

# Sell 50 ETH
usdc_received = estimate_sell_received_amount_raw(
    uniswap_v2,
    weth.address,
    usdc.address,
    50 * 10**18,
)

usdc_received_decimals = usdc_received / 10**18
assert usdc_received_decimals == pytest.approx(80721.05538886508)

# Calculate price of ETH as $ for our purchase
price = usdc_received / (50*10**18)
assert price == pytest.approx(Decimal(1614.4211077773016))
Parameters
Returns

Expected quote token amount to receive

Raises

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

Return type

int