dydx

Chain ID: dydx_mainnet

For dydx you'll find the following tables (new schema):

Raw Tables

When querying in BigQeury make sure you add the prefix dydx_ to all of the name tables below. For example, the table blocks should be:

select * from numia-data.dydx_mainnet.dydx_blocks

Contains each validated block in the chain. block_timestamp is only available in this table, so you need to do an inner join on block_height to get block_timestamp to the other tables.

FieldType

block_height

STRING

block_timestamp

TIMESTAMP

chain_id

STRING

proposer_address

STRING

validators_hash

STRING

Example Queries

Example queries for a given address, example used here is: dydx000000000000000000000000000000000000000 (replace with address that is of interest)

Trades

This outputs all the trades for a given address

SELECT *
  FROM `numia-data.dydx_mainnet.dydx_match` 
  WHERE taker = 'dydx000000000000000000000000000000000000000'
     OR maker = 'dydx000000000000000000000000000000000000000'

Deposits

This outputs all the deposits for a given address

SELECT *
  FROM `numia-data.dydx_mainnet.dydx_deposit`
 WHERE recipient = 'dydx000000000000000000000000000000000000000'

Transfers

This outputs all the subaccount transfers for a given address

SELECT *
  FROM `numia-data.dydx_mainnet.dydx_transfer`
 WHERE sender = 'dydx000000000000000000000000000000000000000' 
    OR recipient = 'dydx000000000000000000000000000000000000000'

Withdrawals

This outputs all the withdrawals for a given address

SELECT *
  FROM `numia-data.dydx_mainnet.dydx_withdrawal`
  WHERE sender = 'dydx000000000000000000000000000000000000000'

Maker Rebate

This calculates all the maker rebates for a given address

SELECT SUM(maker_order_fee_quote_quantums)/1e6 AS maker_rebate_usdc
  FROM `numia-data.dydx_mainnet.dydx_match` 
  WHERE maker = 'dydx000000000000000000000000000000000000000'

Funding

This outputs all the funding for a given address

SELECT *
  FROM `numia-data.dydx_mainnet.dydx_settled_funding` 
 WHERE subaccount = 'dydx000000000000000000000000000000000000000'

Wallet transfers

This outputs all the wallet to wallet transfers of DYDX for a given sender

SELECT  tm.tx_id
      , CAST(JSON_EXTRACT_SCALAR(JSON_EXTRACT(tm.message, '$.amount')[0], '$.amount') AS NUMERIC)/1e18 AS amount
      , JSON_EXTRACT_SCALAR(tm.message, '$.from_address') AS sender
      , JSON_EXTRACT_SCALAR(tm.message, '$.to_address') AS recipient
  FROM `numia-data.dydx_mainnet.dydx_tx_messages` tm
  -- need to join to ensure the txn didn't fail
  JOIN `numia-data.dydx_mainnet.dydx_transactions` t
   ON tm.tx_id = t.tx_id 
   AND t.tx_log_message IS NULL
 WHERE tm.message_type = '/cosmos.bank.v1beta1.MsgSend' 
   AND JSON_EXTRACT_SCALAR(JSON_EXTRACT(tm.message, '$.amount')[0], '$.denom') = 'adydx'
   AND JSON_EXTRACT_SCALAR(tm.message, '$.from_address') = 'dydx000000000000000000000000000000000000000'

Trading Rewards

This outputs the trading rewards received in dydx in each block for each address

SELECT block_height
     , JSON_EXTRACT_SCALAR(event_attributes, '$.recipient')
     , CAST(SUBSTR(JSON_EXTRACT_SCALAR(event_attributes, '$.amount'), 1, LENGTH(JSON_EXTRACT_SCALAR(event_attributes, '$.amount'))-5) AS NUMERIC)/1e18  AS dydx_received
  FROM `numia-data.dydx_mainnet.dydx_block_events` 
 WHERE event_type = 'transfer'
 -- dydx16wrau2x4tsg033xfrrdpae6kxfn9kyuerr5jjp is the rewards treasury address
 AND JSON_EXTRACT_SCALAR(event_attributes, '$.sender') = 'dydx16wrau2x4tsg033xfrrdpae6kxfn9kyuerr5jjp'
 AND JSON_EXTRACT_SCALAR(event_attributes, '$.recipient') = 'dydx000000000000000000000000000000000000000'

Last updated