This is what I concluded after comparing the usdt swap data from API with the usdt trades data on etherscan
The below is a sell trade where amount0 is the value of token0 which is a positive number and indicates a sale in a swap. and amount1 is the value of token1 which is a negative that indicates the token received in a swap.
"decoded_event": {
"signature": "Swap(address,address,int256,int256,uint160,uint128,int24)",
"label": "Swap",
"type": "event",
"params": [
{
"name": "sender",
"value": "0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",
"type": "address"
},
{
"name": "recipient",
"value": "0x6aacbE949F0766d3fD0E27384904d4E29C45354A",
"type": "address"
},
{
"name": "amount0",
"value": "5413310785033668975",
"type": "int256"
},
{
"name": "amount1",
"value": "-10000000000",
"type": "int256"
},
{
"name": "sqrtPriceX96",
"value": "3406058967400672189642946",
"type": "uint160"
},
{
"name": "liquidity",
"value": "11121876794809196193",
"type": "uint128"
},
{
"name": "tick",
"value": "-201101",
"type": "int24"
}
]
}
The below is a buy trade with different params data. In this case, the conditions seem like if amount0In
and amount1Out
are greater than 0 then it is a sell transaction and if amount1In
and amount0Out
are greater than 0 then it is a buy transaction.
"decoded_event": {
"signature": "Swap(address,uint256,uint256,uint256,uint256,address)",
"label": "Swap",
"type": "event",
"params": [
{
"name": "sender",
"value": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
"type": "address"
},
{
"name": "amount0In",
"value": "0",
"type": "uint256"
},
{
"name": "amount1In",
"value": "2420901171",
"type": "uint256"
},
{
"name": "amount0Out",
"value": "1305319972714076888",
"type": "uint256"
},
{
"name": "amount1Out",
"value": "0",
"type": "uint256"
},
{
"name": "to",
"value": "0xbe8BC29765E11894f803906Ee1055a344fDf2511",
"type": "address"
}
]
}
The swap params data in different swap contracts seem different so we need to identify them in the code. The above sell trade example is from uniswap v3 and buy trade example is from uniswap v2.
Let me know if there are any questions.