Decode transaction sent to Uniswap universal router
Project description
Uniswap Universal Router Decoder
Description
The object of this library is to decode the transaction input sent to the Uniswap universal router
(address 0xEf1c6E67703c7BD7107eed8303Fbe6EC2554BF6B
on Ethereum Mainnet).
⚠ Not all commands are decoded yet. Below a list of the ones already implemented.
Command Id | Function Name | Is Implemented |
---|---|---|
0x00 | V3_SWAP_EXACT_IN | ✅ |
0x01 | V3_SWAP_EXACT_OUT | ✅ |
0x08 | V2_SWAP_EXACT_IN | ✅ |
0x09 | V2_SWAP_EXACT_OUT | ✅ |
0x0a | PERMIT2_PERMIT | ✅ |
0x0b | WRAP_ETH | ✅ |
0x0c | UNWRAP_WETH | ✅ |
Installation
# update pip to latest version if needed
pip install -U pip
# install the decoder from pypi.org
pip install uniswap-universal-router-decoder
Usage
The library exposes a class, RouterDecoder
with 2 public methods decode_function_input
and decode_transaction
.
How to decode a transaction input
To decode a transaction input, use the decode_function_input
method as follow:
from uniswap_universal_router_decoder.router_decoder import RouterDecoder
trx_input = "0x3593564c000000000000000000 ... 90095b5c4e9f5845bba" # the trx input to decode
decoder = RouterDecoder()
decoded_trx_input = decoder.decode_function_input(trx_input)
How to decode a transaction
It's also possible to decode the whole transaction, given its hash and providing the decoder has been built with either a valid Web3 instance or the link to a rpc endpoint:
# Using a web3 instance
from web3 import Web3
from uniswap_universal_router_decoder.router_decoder import RouterDecoder
w3 = Web3(...) # your web3 instance
decoder = RouterDecoder(w3=w3)
# Using a rpc endpoint
from web3 import Web3
from uniswap_universal_router_decoder.router_decoder import RouterDecoder
rpc_link = "https://..." # your rpc enpoint
decoder = RouterDecoder(rpc_endpoint=rpc_link)
And then the decoder will get the transaction from the blockchain and decode it, along with its input data:
# Using a rpc endpoint
trx_hash = "0x52e63b7 ... 11b979dd9"
decoded_transaction = decoder.decode_transaction(trx_hash)
How to decode an Uniswap V3 swap path
The RouterDecoder
class exposes also the static method decode_v3_path
which can be used to decode a given Uniswap V3 path.
from uniswap_universal_router_decoder.router_decoder import RouterDecoder
uniswap_v3_path = b"\xc0*\xaa9\xb2#\xfe\x8d\n\x0e ... \xd7\x89" # bytes or str hex
fn_name = "V3_SWAP_EXACT_IN" # Or V3_SWAP_EXACT_OUT
decoded_path = RouterDecoder.decode_v3_path(fn_name, uniswap_v3_path)
The result is a tuple, starting with the "in-token" and ending with the "out-token", with the pool fees between each pair.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for uniswap-universal-router-decoder-0.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5927e4bda5d5ca37b640bb7b87ade28b4553922fe4ccbf62614e5bfa28566e61 |
|
MD5 | c2989b41d2829e0a6c616eef604bb712 |
|
BLAKE2b-256 | cb5f5292d81a7bc02f54db4e288e0156524178aba0dc88de84a706e899b9f3e4 |
Hashes for uniswap_universal_router_decoder-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c568e1797a2e4fb9c3963a6cca9aedd0f37c421e7fe250c85a1a14bdcb0032f4 |
|
MD5 | 4f8654e79b2f925aca14fe141f2646d5 |
|
BLAKE2b-256 | d83167240a0053abc38d66ce7d0e2e9b70a913288a164bff9d6b5d4acbcd6fd1 |