uniswap_v2.analysis
Documentation for eth_defi.uniswap_v2.analysis Python module.
Uniswap v2 individual trade analysis.
Functions
|
Analyse details of a Uniswap trade based on a transaction id. |
|
Analyse details of a Uniswap trade based on already received receipt. |
- analyse_trade_by_hash(web3, uniswap, tx_hash)
Analyse details of a Uniswap trade based on a transaction id.
Analyses trade fees, etc. based on the event signatures in the transaction. Works only simp;e trades.
Currently only supports simple analysis where there is one input token and one output token.
Note
Only works if you have one trade per transaction.
Example:
analysis = analyse_trade(web3, uniswap_v2, tx_hash) assert isinstance(analysis, TradeSuccess) # Trade was successful assert analysis.price == pytest.approx(Decimal("1744.899124998896692270848706")) # ETC/USDC price assert analysis.get_effective_gas_price_gwei() == 1 # What gas was paid for this price
Note
This code is still much under development and unlikely to support any advanced use cases yet.
- Parameters
web3 (web3.main.Web3) – Web3 instance
uniswap (eth_defi.uniswap_v2.deployment.UniswapV2Deployment) – Uniswap deployment description
tx_hash (str | hexbytes.main.HexBytes) – Transaction hash as a string
- Returns
TradeSuccessorTradeFailinstance- Return type
Union[eth_defi.trade.TradeSuccess, eth_defi.trade.TradeFail]
- analyse_trade_by_receipt(web3, uniswap, tx, tx_hash, tx_receipt, pair_fee=None, sender_address=None)
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.Note
Only works if you have one trade per transaction.
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 | None) – 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 | None) – Transaction receipt to analyse
pair_fee (float) – The lp fee for this pair.
sender_address (str | None) –
- Returns
TradeSuccessorTradeFailinstance- Return type
Union[eth_defi.trade.TradeSuccess, eth_defi.trade.TradeFail]