Flipside CheatSheet: Interact with Defillama data using LiveQuery

    Tutorial on how to get Defillama data using LiveQuery You can use this method to use other data sources in LiveQuery. If you have any questions, please contact me on X: https://twitter.com/0xTraevon

    Loading...

    Get chains' TVL

    WITH response AS ( 
       SELECT defillama.get('/v2/chains',{}) AS resp
    )
    
    SELECT
      VALUE:"name" as name,
      VALUE:"tvl" as tvl
    FROM response,
    LATERAL FLATTEN(input => resp:data)
    ORDER BY tvl DESC
    
    1. Get response using 'GET' with SELECT
    2. Flatten and turn result into columns with LATERAL FLATTEN
    Loading...

    Get DEX Volume on zkSync Era

    WITH response AS(
      SELECT defillama.get('/overview/dexs/zkSync%20Era',
        {
            'excludeTotalDataChart':'false',
            'excludeTotalDataChartBreakdown': 'false',
            'dataType': 'dailyVolume'}) as resp
    )
    
    
    SELECT   TO_TIMESTAMP(VALUE[0]) AS time,
             VALUE[1] AS volume
    FROM     response, 
    LATERAL FLATTEN(input => resp:data:totalDataChart)
    ORDER BY 1 DESC
    

    1. Introduction to Defillama Add-on

    The Defillama Add-on enables you to access data from the Defillama API directly within your Flipside account.

    This guide will walk you through the process of installing the add-on, finding the data you need from the Defillama documentation, and making 'GET' requests using SQL statements.

    2. Installation of Defillama Add-on

    Before you can use the Defillama Add-on in LiveQuery, you need to install it.

    Install the Defillama Add-on from the following link: https://flipsidecrypto.xyz/livequery/defillama

    3. Finding the Data You Want

    To retrieve data from Defillama, you need to understand the available API endpoints and parameters.

    Refer to the Defillama documentation for details on their API: https://defillama.com/docs/api

    Identify the data you want to access and note the API path and any required query parameters.

    4. Using Snowflake SQL with Defillama Add-on

    Use this SQL statement to make a 'GET' request to Defillama API: SELECT defillama.get('path', {query_args})

    Example request URL: https://api.llama.fi/overview/dexs/ethereum?excludeTotalDataChart=true&excludeTotalDataChartBreakdown=true&dataType=dailyVolume

    'path' => /overview/dexs/ethereum

    {query_arg} => { 'excludeTotalDataChart':'true', 'excludeTotalDataChartBreakdown': 'true', 'dataType': 'dailyVolume'}

    Example below 👇