Sandwich Trades

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

direction

Indicates whether the transaction is the front or back of the sandwich trade

back

project

The project or DEX name where the trade occurred

uniswap

protocol

The protocol used within the project

uniswap_v2

block_timestamp

The timestamp of the block containing the trade

2024-06-13 01:00:11.000

block_number

The block number containing the trade

20079481

transaction_index

The index of the transaction within the block

7

sandwich_transaction_index

The transaction index of the corresponding sandwich within the block (back/front)

5

log_index

The index of the log within the block

56

transaction_hash

The hash of the transaction

0x07fe3f18c82800b63072d14606d85d72ccdda9a5cf1c8a6aed900450d761e363

sandwich_transaction_hash

The hash of the corresponding end of sandwich (back/front)

0x25273ef2808f689f8621daf2c2ae25746f30367780c54dc2ec90938d0c37efcc

liquidity_pool_address

The address of the liquidity pool involved in the trade

0xbf16540c857b4e32ce6c37d2f7725c8eec869b8b

transaction_from_address

The address initiating the transaction

0x8ef57238cd4178eed96cd30a13cbc7448925328e

transaction_to_address

The address receiving the transaction

0x00000023c10000eecb940000b914cdfd76cc83d1

token_sold_address

The address of the token sold in the transaction

0x3ffeea07a27fab7ad1df5297fa75e77a43cb5790

token_sold_symbol

The symbol of the token sold in the transaction

PEIPEI

token_sold_name

The name of the token sold in the transaction

PeiPei

token_sold_amount

The amount of the token sold

50279216370.7169

token_sold_amount_str

The amount of the token sold, in string format for precision.

50279216370.716897543345668096

token_sold_amount_raw

The raw string representation of the amount of the token sold

50279216370716897543345668096

token_bought_address

The address of the token bought in the transaction

0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2

token_bought_symbol

The symbol of the token bought in the transaction

WETH

token_bought_name

The name of the token bought in the transaction

Wrapped Ether

token_bought_amount

The amount of the token bought

2.759992254

token_bought_amount_str

The amount of the token bought, in string format for precision.

2.759992254092279808

token_bought_amount_raw

The raw string representation of the amount of the token bought

2759992254092279808

usd_amount

The USD value of the swap log

9817.485647264

sender_address

The address of the sender in the swap

0x00000023c10000eecb940000b914cdfd76cc83d1

recipient_address

The address of the recipient in the swap

0x00000023c10000eecb940000b914cdfd76cc83d1

unique_id

The unique identifier for the transaction

txn-0x07fe3f18c82800b63072d14606d85d72ccdda9a5cf1c8a6aed900450d761e363_log_index-56


Last updated