DEX Trading: Token Transfers

Understand flows and volumes of different tokens across various exchanges.

Token Transfers

Each token transfer table records the amount of a particular token moved from any given address to any other. This includes transfers of Ethereum (ETH), ERC20 tokens, ERC721 tokens (commonly known as non-fungible tokens or NFTs), and ERC1155 tokens (a newer type of token standard that combines features of both fungible and non-fungible tokens).

The purpose of these tables is to provide a comprehensive overview of token transactions on the Ethereum blockchain, allowing users to understand the flow and volume of different types of tokens.

Net Flows in a DEX Pool

Net flows into a dex pool can be obtained by summing over the amount transferred into and out of that pool address of interest and then subtracting the inflows from the outflows to see the net flow over the past few days.

Let’s look at the correlation between Net flows into USDC-ETH Uniswap V3 pairs and price action in the past 30 days (as of 4th January 2024).

πŸ“˜

Find the dashboard version of the above query here.

To rerun the same analysis for an up-to-date result or use the similar code to check a different pair_address/token flow combination please use the SQL code bellow:

with inflows as (
  select  
    date(transfers.block_date) as date, 
    token_metadata.symbol as token_name, 
    sum(CAST(transfers.value as double)/POW(10,token_metadata.decimals)) as daily_inflow
from ethereum_mainnet.erc20_evt_transfer as transfers
LEFT JOIN ethereum_mainnet.erc20_tokens as token_metadata
ON transfers.contract_address=token_metadata.contract_address
where transfers.to_address IN ('0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640','0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8','0x7bea39867e4169dbe237d55c8242a8f2fcdcc387') -- USDC-ETH Uniswap v3 pair 0.05%, 0.3% and 1% fee
  and transfers.contract_address = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' -- USDC Token Address
and block_date >= current_date - interval '60' day
group by 1,2
order by date desc
),
outflows as (
  select  
    date(transfers.block_date) as date, 
    token_metadata.symbol as token_name,
    sum(CAST(transfers.value as DOUBLE)/POW(10,token_metadata.decimals)) as daily_outflow
from ethereum_mainnet.erc20_evt_transfer as transfers
LEFT JOIN ethereum_mainnet.erc20_tokens as token_metadata
ON transfers.contract_address=token_metadata.contract_address
where transfers.from_address IN ('0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640','0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8','0x7bea39867e4169dbe237d55c8242a8f2fcdcc387') -- USDC-ETH Uniswap v3 pair 0.05%, 0.3% and 1% fee
  and transfers.contract_address = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' -- USDC Token Address
and block_date >= current_date - interval '60' day
group by 1, 2
order by date desc
),
prices_usd as(
select
  date_trunc('day', minute) as dt,
  AVG(price) as price_usd
FROM prices.usd
WHERE symbol='ETH'
and data_creation_date >= current_date - interval '60' day
GROUP BY 1
)
select 
    coalesce(inflows.date, outflows.date) as date_time,
    inflows.token_name,
    daily_inflow,
    daily_outflow,
    sum(daily_inflow) over (order by inflows.date) as total_inflow,
    sum(daily_outflow) over (order by outflows.date) as total_outflow,
    coalesce(sum(daily_inflow) over (order by inflows.date),0) - coalesce(sum(daily_outflow) over (order by outflows.date),0) as net_flow,
    round(pr.price_usd,2) as price_usd
from inflows 
left outer join outflows on inflows.date = outflows.date and inflows.token_name = outflows.token_name
left outer join prices_usd as pr on inflows.date=pr.dt
order by 1 asc