Skip to content

Instantly share code, notes, and snippets.

@BlockmanCodes
Last active March 20, 2024 06:44
Show Gist options
  • Save BlockmanCodes/9d0652ca76674bd43df095b2fc54f46c to your computer and use it in GitHub Desktop.
Save BlockmanCodes/9d0652ca76674bd43df095b2fc54f46c to your computer and use it in GitHub Desktop.
Uniswap V3: decode exactInput paths
const hashes = [
'0x04fffe0fb9d0ac806b0f3c329a83d8dd5ddcd598ee82779043d83802d6ee784a',
'0x8df99a1c9bbbf7cda5a9f1bc11d3b3cd0c6d99f31039396a29779fea252960f6',
'0x3f94bc2af1300a01827e59a745b05af8517ae4fc5e25ee1add9789d19c9bfd00',
'0x68cf26f581d6c0add08c9fcf9b1d4d31cff660d8bfb6b7d9e3636a7aa1e0a91f',
'0xed797fb4d05950dca9279c55f2436211a3eb585f1f20877e7384017500951fe4',
'0x7596c887baea532f2a2370af06d1990dac8be04f68e8f906dd82025d2ce42ad7',
'0x8892ffda5398dbf54d0fb6bc4d2bbdbc31de250f633cf1becc568a92fbe63c51',
'0x9219aa3bc64b325f84f9e3c101e602c83f65f61272a982c8f2fd1c55874ecc6d',
'0x81995eb1d1a62c3dbdb817663e39b40d235861e4ee6513962299d8a15905dded',
'0xd9727c3b97e878ed32c9cf8f4203bf5c4a0bfb37027ccd944f550b2024f4152d',
'0x496226187f9b7810f9d64530cd57163c1ce15cf85119e6da85e7f91ba2dee0a7',
'0x779bcb8991a8a66fd0ce2b3328b71791f71a8878d24d2acce5dbc22d27cb538f',
]
const ethers = require("ethers")
require('dotenv').config()
const provider = new ethers.providers.JsonRpcProvider(process.env.INFURA_URL)
const swapRouter02Abi = [
// copy from https://etherscan.io/address/0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45
]
const contractInterface = new ethers.utils.Interface(swapRouter02Abi);
const main = () => {
hashes.forEach(async (hash) => {
const tx = await provider.getTransaction(hash)
const data = tx.data
const decodedData = contractInterface.parseTransaction({ data: data })
// console.log('------')
// console.log(decodedData)
const params = decodedData.args.params
const path = params.path
decodePath(path)
})
}
const decodePath = (path) => {
const decodedPath = []
const pathData = path.slice(2)
let idx = 0;
let inputToken
inputToken = `0x${pathData.slice(idx, idx + 40)}`
idx += 40;
while (idx < pathData.length) {
const fee = parseInt(pathData.slice(idx, idx + 6), 16)
idx += 6;
const outputToken = `0x${pathData.slice(idx, idx + 40)}`
idx += 40;
decodedPath.push({ inputToken: inputToken, fee, outputToken: outputToken })
inputToken = outputToken
}
console.log(decodedPath)
}
main()
/*
node scripts/08_decodeExactInputPath.js
*/
require("@nomiclabs/hardhat-waffle");
require('dotenv').config()
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.18",
networks: {
hardhat: {
forking: {
url: process.env.INFURA_URL
}
}
}
};
{
"name": "YouTubeTutorials",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@nomiclabs/hardhat-waffle": "^2.0.6",
"@types/sinon-chai": "^3.2.9",
"@uniswap/sdk": "^3.0.3",
"@uniswap/sdk-core": "^4.0.2",
"@uniswap/universal-router-sdk": "^1.5.7",
"@uniswap/v3-core": "^1.0.1",
"@uniswap/v3-periphery": "^1.4.3",
"@uniswap/v3-sdk": "^3.9.0",
"dotenv": "^16.3.1",
"ethereum-waffle": "^4.0.10",
"ethers": "^5.7.2",
"hardhat": "^2.14.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment