Last active
November 5, 2020 16:19
-
-
Save johngrantuk/00aed4ca7f5cebfb3f78d3d1db305622 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // npm add @ethersproject/abi | |
| import { Interface } from '@ethersproject/abi'; | |
| function transactionParsing(){ | |
| console.log(`transactionParsing`); | |
| const proxyArtifact = require('./abi/ExchangeProxy.json'); // See below | |
| const iface = new Interface(proxyArtifact.abi); | |
| let ipData = `0x86b2ecc40000000000000000000000000000000000000000000000000000000000000080000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000000000b8b44000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000d386bb106e6fb44f91e180228edeca24ef73c812000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000ba45a8b5d5575935b8158a88c631e9f9c95a2e500000000000000000000000000000000000000000000000000933cf2568bbd33ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000838d504010d83a343db2462256180ca311d29d900000000000000000000000000ba45a8b5d5575935b8158a88c631e9f9c95a2e50000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000de0b6b3a7640000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff`; | |
| let test = iface.parseTransaction({ data: ipData }); | |
| console.log(test); | |
| console.log(test.args.swapSequences); | |
| console.log(test.functionFragment.name); | |
| /* | |
| Lets filter out and display: | |
| function type | |
| tokenIn | |
| tokenOut | |
| And would be good to start parsing swapSequences for future | |
| Example output: | |
| function multihopBatchSwapExactOut( | |
| Swap[][] memory swapSequences, | |
| TokenInterface tokenIn, | |
| TokenInterface tokenOut, | |
| uint maxTotalAmountIn | |
| ) | |
| public payable | |
| returns (uint totalAmountIn) | |
| { | |
| */ | |
| } | |
| transactionParsing(); | |
| /* | |
| ./abi/ExchangeProxy.json | |
| { | |
| "contractName": "ExchangeProxy", | |
| "abi": [ | |
| { | |
| "inputs": [ | |
| { | |
| "internalType": "address", | |
| "name": "_weth", | |
| "type": "address" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "nonpayable", | |
| "type": "constructor" | |
| }, | |
| { | |
| "anonymous": false, | |
| "inputs": [ | |
| { | |
| "indexed": true, | |
| "internalType": "address", | |
| "name": "previousOwner", | |
| "type": "address" | |
| }, | |
| { | |
| "indexed": true, | |
| "internalType": "address", | |
| "name": "newOwner", | |
| "type": "address" | |
| } | |
| ], | |
| "name": "OwnershipTransferred", | |
| "type": "event" | |
| }, | |
| { | |
| "payable": true, | |
| "stateMutability": "payable", | |
| "type": "fallback" | |
| }, | |
| { | |
| "constant": false, | |
| "inputs": [ | |
| { | |
| "components": [ | |
| { | |
| "internalType": "address", | |
| "name": "pool", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "address", | |
| "name": "tokenIn", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "address", | |
| "name": "tokenOut", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "swapAmount", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "limitReturnAmount", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "maxPrice", | |
| "type": "uint256" | |
| } | |
| ], | |
| "internalType": "struct ExchangeProxy.Swap[]", | |
| "name": "swaps", | |
| "type": "tuple[]" | |
| }, | |
| { | |
| "internalType": "contract TokenInterface", | |
| "name": "tokenIn", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "contract TokenInterface", | |
| "name": "tokenOut", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "totalAmountIn", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "minTotalAmountOut", | |
| "type": "uint256" | |
| } | |
| ], | |
| "name": "batchSwapExactIn", | |
| "outputs": [ | |
| { | |
| "internalType": "uint256", | |
| "name": "totalAmountOut", | |
| "type": "uint256" | |
| } | |
| ], | |
| "payable": true, | |
| "stateMutability": "payable", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": false, | |
| "inputs": [ | |
| { | |
| "components": [ | |
| { | |
| "internalType": "address", | |
| "name": "pool", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "address", | |
| "name": "tokenIn", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "address", | |
| "name": "tokenOut", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "swapAmount", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "limitReturnAmount", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "maxPrice", | |
| "type": "uint256" | |
| } | |
| ], | |
| "internalType": "struct ExchangeProxy.Swap[]", | |
| "name": "swaps", | |
| "type": "tuple[]" | |
| }, | |
| { | |
| "internalType": "contract TokenInterface", | |
| "name": "tokenIn", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "contract TokenInterface", | |
| "name": "tokenOut", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "maxTotalAmountIn", | |
| "type": "uint256" | |
| } | |
| ], | |
| "name": "batchSwapExactOut", | |
| "outputs": [ | |
| { | |
| "internalType": "uint256", | |
| "name": "totalAmountIn", | |
| "type": "uint256" | |
| } | |
| ], | |
| "payable": true, | |
| "stateMutability": "payable", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": true, | |
| "inputs": [], | |
| "name": "isOwner", | |
| "outputs": [ | |
| { | |
| "internalType": "bool", | |
| "name": "", | |
| "type": "bool" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "view", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": false, | |
| "inputs": [ | |
| { | |
| "components": [ | |
| { | |
| "internalType": "address", | |
| "name": "pool", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "address", | |
| "name": "tokenIn", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "address", | |
| "name": "tokenOut", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "swapAmount", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "limitReturnAmount", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "maxPrice", | |
| "type": "uint256" | |
| } | |
| ], | |
| "internalType": "struct ExchangeProxy.Swap[][]", | |
| "name": "swapSequences", | |
| "type": "tuple[][]" | |
| }, | |
| { | |
| "internalType": "contract TokenInterface", | |
| "name": "tokenIn", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "contract TokenInterface", | |
| "name": "tokenOut", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "totalAmountIn", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "minTotalAmountOut", | |
| "type": "uint256" | |
| } | |
| ], | |
| "name": "multihopBatchSwapExactIn", | |
| "outputs": [ | |
| { | |
| "internalType": "uint256", | |
| "name": "totalAmountOut", | |
| "type": "uint256" | |
| } | |
| ], | |
| "payable": true, | |
| "stateMutability": "payable", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": false, | |
| "inputs": [ | |
| { | |
| "components": [ | |
| { | |
| "internalType": "address", | |
| "name": "pool", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "address", | |
| "name": "tokenIn", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "address", | |
| "name": "tokenOut", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "swapAmount", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "limitReturnAmount", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "maxPrice", | |
| "type": "uint256" | |
| } | |
| ], | |
| "internalType": "struct ExchangeProxy.Swap[][]", | |
| "name": "swapSequences", | |
| "type": "tuple[][]" | |
| }, | |
| { | |
| "internalType": "contract TokenInterface", | |
| "name": "tokenIn", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "contract TokenInterface", | |
| "name": "tokenOut", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "maxTotalAmountIn", | |
| "type": "uint256" | |
| } | |
| ], | |
| "name": "multihopBatchSwapExactOut", | |
| "outputs": [ | |
| { | |
| "internalType": "uint256", | |
| "name": "totalAmountIn", | |
| "type": "uint256" | |
| } | |
| ], | |
| "payable": true, | |
| "stateMutability": "payable", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": true, | |
| "inputs": [], | |
| "name": "owner", | |
| "outputs": [ | |
| { | |
| "internalType": "address", | |
| "name": "", | |
| "type": "address" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "view", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": false, | |
| "inputs": [], | |
| "name": "renounceOwnership", | |
| "outputs": [], | |
| "payable": false, | |
| "stateMutability": "nonpayable", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": false, | |
| "inputs": [ | |
| { | |
| "internalType": "address", | |
| "name": "_registry", | |
| "type": "address" | |
| } | |
| ], | |
| "name": "setRegistry", | |
| "outputs": [], | |
| "payable": false, | |
| "stateMutability": "nonpayable", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": false, | |
| "inputs": [ | |
| { | |
| "internalType": "contract TokenInterface", | |
| "name": "tokenIn", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "contract TokenInterface", | |
| "name": "tokenOut", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "totalAmountIn", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "minTotalAmountOut", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "nPools", | |
| "type": "uint256" | |
| } | |
| ], | |
| "name": "smartSwapExactIn", | |
| "outputs": [ | |
| { | |
| "internalType": "uint256", | |
| "name": "totalAmountOut", | |
| "type": "uint256" | |
| } | |
| ], | |
| "payable": true, | |
| "stateMutability": "payable", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": false, | |
| "inputs": [ | |
| { | |
| "internalType": "contract TokenInterface", | |
| "name": "tokenIn", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "contract TokenInterface", | |
| "name": "tokenOut", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "totalAmountOut", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "maxTotalAmountIn", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "nPools", | |
| "type": "uint256" | |
| } | |
| ], | |
| "name": "smartSwapExactOut", | |
| "outputs": [ | |
| { | |
| "internalType": "uint256", | |
| "name": "totalAmountIn", | |
| "type": "uint256" | |
| } | |
| ], | |
| "payable": true, | |
| "stateMutability": "payable", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": false, | |
| "inputs": [ | |
| { | |
| "internalType": "address", | |
| "name": "newOwner", | |
| "type": "address" | |
| } | |
| ], | |
| "name": "transferOwnership", | |
| "outputs": [], | |
| "payable": false, | |
| "stateMutability": "nonpayable", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": true, | |
| "inputs": [ | |
| { | |
| "internalType": "address", | |
| "name": "tokenIn", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "address", | |
| "name": "tokenOut", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "swapAmount", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "nPools", | |
| "type": "uint256" | |
| } | |
| ], | |
| "name": "viewSplitExactIn", | |
| "outputs": [ | |
| { | |
| "components": [ | |
| { | |
| "internalType": "address", | |
| "name": "pool", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "address", | |
| "name": "tokenIn", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "address", | |
| "name": "tokenOut", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "swapAmount", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "limitReturnAmount", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "maxPrice", | |
| "type": "uint256" | |
| } | |
| ], | |
| "internalType": "struct ExchangeProxy.Swap[]", | |
| "name": "swaps", | |
| "type": "tuple[]" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "totalOutput", | |
| "type": "uint256" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "view", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": true, | |
| "inputs": [ | |
| { | |
| "internalType": "address", | |
| "name": "tokenIn", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "address", | |
| "name": "tokenOut", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "swapAmount", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "nPools", | |
| "type": "uint256" | |
| } | |
| ], | |
| "name": "viewSplitExactOut", | |
| "outputs": [ | |
| { | |
| "components": [ | |
| { | |
| "internalType": "address", | |
| "name": "pool", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "address", | |
| "name": "tokenIn", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "address", | |
| "name": "tokenOut", | |
| "type": "address" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "swapAmount", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "limitReturnAmount", | |
| "type": "uint256" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "maxPrice", | |
| "type": "uint256" | |
| } | |
| ], | |
| "internalType": "struct ExchangeProxy.Swap[]", | |
| "name": "swaps", | |
| "type": "tuple[]" | |
| }, | |
| { | |
| "internalType": "uint256", | |
| "name": "totalOutput", | |
| "type": "uint256" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "view", | |
| "type": "function" | |
| } | |
| ] | |
| } | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment