Created
November 1, 2023 02:31
-
-
Save alebaffa/dc42b15410024e308852a1cc8d5b8381 to your computer and use it in GitHub Desktop.
Decode Uniswap V3 multicall (web3.py)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
w3 = web3.Web3(HTTPProvider("PUT HERE YOUR PROVIDER")) | |
UNISWAP_V3_POSITIONS_NFT = "0xC36442b4a4522E871399CD717aBDD847Ab11FE88" | |
# example of Ethereum transaction calling multicall on Uniswap v3 (Etherscan) | |
tx = w3.eth.get_transaction(HexBytes("0xb835f4ab29be621eca1b2520a1e85d06b2e4fc03b84772e3fe05c220509e88b7")) | |
abi = await get_abi(Chain.ETHEREUM, UNISWAP_V3_POSITIONS_NFT) | |
contract = w3.eth.contract(HexBytes(UNISWAP_V3_POSITIONS_NFT), abi=abi) | |
fn, params = contract.decode_function_input(tx.input) | |
fn_and_params: dict[str, list[dict[str, str]]] = {} | |
for key, value in params.items(): | |
for v in value: | |
fn, params = contract.decode_function_input(v) | |
if fn.fn_name == "multicall": | |
params = params["data"] | |
for p in params: | |
fn, params = contract.decode_function_input(p) | |
fn_and_params[fn.fn_name] = params.get("params", params) | |
else: | |
fn_and_params[fn.fn_name] = params.get("params", params) | |
for key, value in fn_and_params.items(): | |
print(f"\n{key}: {value}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment