Sui Dex Trading Volume Per Project

Explore Sui DEX swaps across various projects.

This document explains the process of utilizing ZettaBlock's SUI DEX data to monitor and analyze trading volume (inflows and outflows) by DEX project over time.

πŸ“˜

Find the query here.

🚧

If you do not see a project that you're interested in being captured in the following results, please contact the ZettaBlock Team via a support ticket, so it can be added.

WITH
  sui_swap_volume AS (
    SELECT
      transaction_block_digest,
      block_time,
      data_creation_date AS block_date,
      (case when token_in_symbol = 'SUI' then amount_in_original
          else amount_out_original
      end) AS amount,
      project_name
    FROM
      dex.sui_dex_swaps
    WHERE
      token_in_symbol = 'SUI'
      OR token_out_symbol = 'SUI'
  ),

  price_sui AS (
    SELECT
      data_creation_date AS DATE,
      AVG(price) AS avg_price_usd
    FROM
      prices.usd
    WHERE
      symbol = 'SUI'
      AND slug = 'sui'
    GROUP BY
      1
  ),

  price_sui_latest AS (
    SELECT price
    FROM
      prices.usd_latest
    WHERE
      symbol = 'SUI'
      AND slug = 'sui'
  )

SELECT
  block_date AS dt,
  project_name,
  SUM(amount) AS sui_volume,
  SUM(amount * coalesce(ps.avg_price_usd, pl.price)) AS sui_volume_usd
FROM
  sui_swap_volume AS sv
  LEFT JOIN price_sui AS ps ON sv.block_date = ps.date
  LEFT JOIN price_sui_latest as pl ON TRUE
GROUP BY
  1,
  2
ORDER BY
  1 

Which you can also visualize as such:

Once you are happy with the query results, you can go ahead and turn this query into a GraphQL API with data-lake refresh of 12 or 24 hrs.

πŸ‘€

In order to save CUs as your API continues to refresh, remember to utilize the Incremental Refresh feature.