analyse_trade_by_receipt

Documentation for eth_defi.uniswap_v2.analysis.analyse_trade_by_receipt function.

analyse_trade_by_receipt(web3, uniswap, tx, tx_hash, tx_receipt, pair_fee=None)[source]

Analyse details of a Uniswap trade based on already received receipt.

See also analyse_trade_by_hash(). This function is more ideal for the cases where you know your transaction is already confirmed and you do not need to poll the chain for a receipt.

Warning

Assumes one trade per TX - cannot decode TXs with multiple trades in them.

Example:

tx_hash = router.functions.swapExactTokensForTokens(
    all_weth_amount,
    0,
    reverse_path,
    user_1,
    FOREVER_DEADLINE,
).transact({"from": user_1})

tx = web3.eth.get_transaction(tx_hash)
receipt = web3.eth.get_transaction_receipt(tx_hash)

analysis = analyse_trade_by_receipt(web3, uniswap_v2, tx, tx_hash, receipt)
assert isinstance(analysis, TradeSuccess)
assert analysis.price == pytest.approx(Decimal("1744.899124998896692270848706"))
Parameters
  • web3 (web3.main.Web3) – Web3 instance

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

  • tx (dict) – Transaction data as a dictionary: needs to have data or input field to decode

  • tx_hash (str) – Transaction hash: needed for the call for the revert reason)

  • tx_receipt (dict) – Transaction receipt to analyse

  • pair_fee (Optional[float]) – The lp fee for this pair.

Returns

TradeSuccess or TradeFail instance

Return type

Union[eth_defi.trade.TradeSuccess, eth_defi.trade.TradeFail]