2

I've subscribed to pending transactions of Uniswap V2 and V3 and am inspecting them, by decoding input of the transactions. I'm getting data as follows:

//1
data: {
  method: 'swapExactETHForTokens',
  types: [ 'uint256', 'address[]', 'address', 'uint256' ],
  inputs: [
    BigNumber { _hex: '0x010c3ff3bae4bd84', _isBigNumber: true },
    [
      'C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
      '3a1311B8C404629E38f61D566cefEFed083B9670'
    ],
    '463ceb903480827E1d4140aE1df007eA44DfAc10',
    BigNumber { _hex: '0x6187bb69', _isBigNumber: true }
  ],
  names: [ 'amountOutMin', 'path', 'to', 'deadline' ]
}

and

//2
data: {
  method: 'swapExactTokensForTokens',
  types: [ 'uint256', 'uint256', 'address[]', 'address', 'uint256' ],
  inputs: [
    BigNumber { _hex: '0x0b1a2bc2ec500000', _isBigNumber: true },
    BigNumber { _hex: '0x2a967f2b8cb4b4c043', _isBigNumber: true },
    [
      '8B3192f5eEBD8579568A2Ed41E6FEB402f93f73F',
      'C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
      '4da08a1Bff50BE96bdeD5C7019227164b49C2bFc'
    ],
    'A07503510F3A09DA0513e1040F7869a52E2b052D',
    BigNumber { _hex: '0x619cb502', _isBigNumber: true }
  ],
  names: [ 'amountIn', 'amountOutMin', 'path', 'to', 'deadline' ]
}

There're also multicall methods which I've not included.

Help me make sense of the (1) and (2) please. What I'm interested in is:

  • what it's that's being swaped (ETH-token, or token-token)
  • and the amounts of a deal/swap

Where the logs is those?


And in general, I'll also need:

  • slippage
  • fees
  • the wallets of a deal

How to get yet these too? Via additional calls? How?

1 Answer 1

1

It's all already there. Have you done some research on the actual Router contract to see how it executes the swap methods?

If the method name is swapExactTokensForTokens, as in your example, it is pretty clear to me that a token-token swap is occuring instead of an ETH-token swap. Otherwise the method would be called swapExactEthForTokens.

The amount of the deal is there as well, in the amountIn input. If you want to calculate the amountOut, you must execute basic constant product mathematics. I suggest you to read the Uniswap Library contract that executes these calculations.

Once again, the slippage can also be derived from the data you already have. Simply, take the percentage change of the amountOutMin input and the formerly calculated amountOut, and there you have your slippage.

Fees are a constant which is dictated by the protocol, in Uniswap's case it is 0.3%. To calculate the numerical value of the fee you must loop within the path, calculate the amountOut of each pair, multiply it by 0.3% and add them up. Take into consideration that the fee is subtracted at every path step, therefore the amountIn of pair N+1 will be the amountOut * (1 - 0.3%) of pair N.

And lastly, what do you mean with the wallets of a deal? The receiver? In that case that would be the to tx input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.