Sandwich Trades Table

The Sandwich Trades table captures DEX events where sandwich trading activity is detected.

Sandwich trading involves placing two trades (a front-run and a back-run) around a victim’s trade to manipulate the market price for profit.

More on Sandwich Attack

Sample Query

Finding the total USD amount of sandwich trades by project and date:

select 
  date_trunc('week', block_timestamp) as date,
  project,
  sum(usd_amount) as sandwich_trade_volume_usd
from ethereum.dex.sandwich_trades
group by date, project

Methodology

We use the dex.trades table to construct this table. This table contains all trade events from DEX protocols. We identify sandwich trades using the following criteria:

  1. Trade Pair Identification:

    • The sandwich trade (swap1 , swap2) must occur within the same block.

    • It must be executed in the same liquidity pool (same liquidity_pool_address).

    • It must be executed by the same signer (transaction_from_address).

    • The transaction indices must be different (transaction_index).

  2. Direction Determination:

    • If s1.transaction_index > s2.transaction_index, the trade is a “back” part of the sandwich.

    • If s1.transaction_index < s2.transaction_index, the trade is a “front” part of the sandwich.

  3. Token Matching:

    • The token bought in the first trade (s1) must match the token sold in the second trade (s2).

    • Alternatively, the token sold in the first trade (s1) should be the token bought in the second trade (s2).

Exclusion of Non-Applicable Projects:

  • Exclude DEXs without the concept of liquidity pools, such as RFQ protocols like Airswap.

Table Columns

Column NameDescriptionExample
directionIndicates whether the transaction is the front or back of the sandwich tradeback
projectThe project or DEX name where the trade occurreduniswap
protocolThe protocol used within the projectuniswap_v2
block_timestampThe timestamp of the block containing the trade2024-06-13 01:00:11.000
block_numberThe block number containing the trade20079481
transaction_indexThe index of the transaction within the block7
sandwich_transaction_indexThe transaction index of the corresponding sandwich within the block (back/front)5
log_indexThe index of the log within the block56
transaction_hashThe hash of the transaction0x07fe3f18c82800b63072d14606d85d72ccdda9a5cf1c8a6aed900450d761e363
sandwich_transaction_hashThe hash of the corresponding end of sandwich (back/front)0x25273ef2808f689f8621daf2c2ae25746f30367780c54dc2ec90938d0c37efcc
liquidity_pool_addressThe address of the liquidity pool involved in the trade0xbf16540c857b4e32ce6c37d2f7725c8eec869b8b
transaction_from_addressThe address initiating the transaction0x8ef57238cd4178eed96cd30a13cbc7448925328e
transaction_to_addressThe address receiving the transaction0x00000023c10000eecb940000b914cdfd76cc83d1
token_sold_addressThe address of the token sold in the transaction0x3ffeea07a27fab7ad1df5297fa75e77a43cb5790
token_sold_symbolThe symbol of the token sold in the transactionPEIPEI
token_sold_nameThe name of the token sold in the transactionPeiPei
token_sold_amountThe amount of the token sold50279216370.7169
token_sold_amount_strThe amount of the token sold, in string format for precision.50279216370.716897543345668096
token_sold_amount_rawThe raw string representation of the amount of the token sold50279216370716897543345668096
token_bought_addressThe address of the token bought in the transaction0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
token_bought_symbolThe symbol of the token bought in the transactionWETH
token_bought_nameThe name of the token bought in the transactionWrapped Ether
token_bought_amountThe amount of the token bought2.759992254
token_bought_amount_strThe amount of the token bought, in string format for precision.2.759992254092279808
token_bought_amount_rawThe raw string representation of the amount of the token bought2759992254092279808
usd_amountThe USD value of the swap log9817.485647264
sender_addressThe address of the sender in the swap0x00000023c10000eecb940000b914cdfd76cc83d1
recipient_addressThe address of the recipient in the swap0x00000023c10000eecb940000b914cdfd76cc83d1
unique_idThe unique identifier for the transactiontxn-0x07fe3f18c82800b63072d14606d85d72ccdda9a5cf1c8a6aed900450d761e363_log_index-56