Querying The Drift Protocol's Data

    Events
    db_img
    Loading...
    Loading...

    Drift Protocol is an open-sourced, decentralised exchange built on the Solana blockchain, enabling transparent and non-custodial trading on cryptocurrencies.

    • All of the user interactions with Drift are going through its V2 program (dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH).
    • A wide range of events are involved from placing an order to canceling it. A list of all of these events can be found in the table below.
    • Flipside's ez_events_decoded was used to get these events.
    • Each Solana transaction contains a set of instructions where each instruction contains a set of inner instructions itself.
    • Using the decoded_instruction column, you can access each instruction's accounts, args, name, and program.
    • Here, by filtering the program with the Drift's V2 contract, we only need the name and args of this JSON data to extract the details.
    Deposits and Withdrawals
    Master Query
    • Traders need to first deposit some tokens in order to be able to use the Drift Protocol. They can then withdraw the available tokens from the protocol back into their wallet.
    • All the deposits and withdrawals are into and from Drift's vault address (JCNCMFXo5M5qwUPg2Utu1u6YWp3MbygxqBsBeXXJfrw).
    • Traders can only use 7 tokens (SOL, USDC, USDT, WBTC, WETH, mSOL, and jitoSOL) as collateral at the moment.
    • To calculate the transferred amount in USD, Flipside's fact_transfers and ez_token_prices_hourly tables were utilized.
    • In the following queries, transfer transactions were joined with token prices on an hourly basis to calculate the USD amount.
    • You might need to alter the order in which the tables are joined together to optimize the query run time.
    • The following charts are only samples. Feel free to modify the queries to produce the charts you desire.
    Loading...
    Loading...
    • The following table represents the outcome of a master query that covers major events from transactions that interacted with the Drift Protocol.
    • It contains multiple CTEs each labeled based on the event they were extracted from.
    • You can use any of these CTEs in conjunction with the one named drifts.
    • The values of the known numerical columns were adjusted with the proper decimals. Their unit was also commented on in front of them.
    Loading...

    Notes

    • I wrote these queries based on my personal interaction with the protocol. Make sure to test them with some of your transactions first to be certain about the outcome.
    • The queries were tested for only the SOL perpetual.
    • Only the most common events (with the highest number of transactions) were decoded.