Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 5.13 KB

trades.md

File metadata and controls

50 lines (36 loc) · 5.13 KB

Trades

Availability

{% hint style="success" %} This collection is available for the Ethereum, Polygon, Arbitrum, and Base. {% endhint %}

Points-of-Presence Tables
eu-west-1

defi_trades_ethereum_mainnet_v1
defi_trades_polygon_mainnet_v1
defi_trades_arbitrum_mainnet_v1
defi_trades_base_mainnet_v1

Methodology

The table is built by extracting data from DEXes activity and then normalizing it to fit a unified data model.

We currently support the following DEXes:

  • Uniswap V2
  • Uniswap V3
  • Curve

{% hint style="info" %} We extract data from any contract compatible with one of the above DEXes ABI.

It means that any DEXes that forked or tried to be compatible at the ABI level with these contracts will be indexed automatically. {% endhint %}

Table Schema

Column NameColumn TypeDescription
chain_namestringName of the chain (ethereum, arbitrum, polygon, ...).
chain_network_namestringname of the network (mainnet).
block_hashstringBlock hash encoded as binary string
block_numberuint64Block height
transaction_indexuint64The index of the transaction in the block
timestampdatetimeUNIX timestamp for when the block was collated
decoder_namestringThe internal name of the decoder used to decode this trade (uniswap_v2_trade, curve_trade)
factorystringThe address of the DEX factory contract (if any)
contractstringThe address of the DEX pair/pool the actually executed the trade
senderstringThe address of the account the called the contract
receiverstringThe address of the account that received the swapped amount
originstringThe address of the EOA that triggered the transaction
token_sold_addressstringThe address of the sold token
token_sold_symbolstringThe symbol of the sold token
token_sold_raw_amountuint256The amount of token sold
token_sold_amountfloat64The amount of token sold divided by pow(10, decimals) where decimals is the number of decimals declared by the token (USDT has 6 decimals)
token_bought_addressstringThe address of the bought token
token_bought_symbolstringThe symbol of the bought token
token_bought_raw_amountuint256The amount of token bought
token_bought_amountfloat64The amount of token bought divided by pow(10, decimals) where decimals is the number of decimals declared by the token (USDT has 6 decimals)
pricefloat64The price of the trade, computed by doing: token_bought_amount / token_sold_mount

Usage

The query below makes use of the defi_trades_ethereum_mainnet_v1 table to get the necessary data to display the well-known candlestick chart for the price of USDC (0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48) on the Uniswap V3 USDC/ETH Pool (0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640) for the last 30 days.

select 
  date_trunc('day', timestamp) as date,
  argMin(price, timestamp) as open,
  argMax(price, timestamp) as close,
  min(price) as _min,
  max(price) as _max
from defi_trades_ethereum_mainnet_v1
where contract = '0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640'
and token_sold_address = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
and timestamp >= now() - interval 30 day
group by date
order by date desc