Solidity – Getting DEX Trade Details from Uniswap Router Transactions

solidityuniswap

I'm trying to understand Uniswap trade decoding. I'm looking at Swap events, and for figuring out Swap events emitted by a Uniswap token pair contract this is straightforward. However I have a Swap event which is emitted by the ERC20 token contract itself and I can't quite make sense of what's happening so I wonder if someone could explain? Thanks!

This is the transaction: 0xae3888aed74cfd92efa884d10c05b1325e9721b2b2de7e676b3c5e76ccc5a2ca
https://etherscan.io/tx/0xae3888aed74cfd92efa884d10c05b1325e9721b2b2de7e676b3c5e76ccc5a2ca

It comes from 0x564b4B1e0671E239f04E97f03e21DaF2c5D91B80, which looks like a regular EOA.

Sent to 0xD1A15671c772032123719a1C9bCC2182E5cb1D08, which is a smart contract for an ERC20 token, Kermit.

It calls a function on this contract called execute that looks like this:

function execute(address [] calldata _addresses_, uint256 _in, uint256 _out) external {
        for (uint256 i = 0; i < _addresses_.length; i++) {
            emit Swap(_universal, _in, 0, 0, _out, _addresses_[i]);
            emit Transfer(_pair, _addresses_[i], _out);
        }
    }

with these params:

0       _addresses_     address[]       0x4c27BA1c4f44a487031c83818d8d1de62B8088d2
1       _in     uint256 1000000000000000000
2       _out    uint256 2296103435739971388790164659

This emits a Swap event,

0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822
1 0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD (The Uniswap router)
2 0x4c27BA1c4f44a487031c83818d8d1de62B8088d2 (The address which gets the tokens)

Then a Transfer event:

0 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
1 0xb253DdD5C64A1C521D87a637C8D4bC1eCdc05411 (The token contract owner)
2 0x4c27BA1c4f44a487031c83818d8d1de62B8088d2 (The address which gets the tokens)

Which transfers the Kermit tokens from 0xb253DdD5C64A1C521D87a637C8D4bC1eCdc05411 to 0x4c27BA1c4f44a487031c83818d8d1de62B8088d2

I don't understand how or where the pair contract is involved in this. The pair contract is 0xcc89ef16e9921d71a12dfbcec94e429cb58c5537

I noticed in the erc20 contract it has this function called setup with onlyOwner perms to set a variable called _pair to something.

    function setup(address _pair_) external onlyOwner {
        _pair = _pair_;
    }

I don't know how I can see or inspect this. I'm also not sure of the indirection here. I thought instigating trades from a smart contract was something MEV bots did to enabled their transactions to either all go through or all fail, but this is the token contract firing it.

Any ideas in how I can understand this?

Thanks!

Best Answer

First of all the contract looks quite suspicious. The functions implemented in this ERC20 should be implemented on the router instead and called through the router.

Secondly, executing the function execute() as is, doesn't transfer anything. It only emits events, which Etherscan understands as a transfer and displays it as such. It seems like the developer wanted users to think their tokens were transferred.

Concerning the pair variable, it doesn't really play any role in this function call. If the contract was implemented correctly, then the router would be handling transactions and the pair would be accessible through router.

Related Topic