text: -- https://duneanalytics.com/queries/25297/51964
  
  WITH mint_burn AS (
  
      SELECT 
          date_trunc('day', evt_block_time) AS day, 
          SUM("_quantity"/1e18) AS amount 
          FROM setprotocol_v2."BasicIssuanceModule_evt_SetTokenIssued"
          WHERE "_setToken" = '\xada0a1202462085999652dc5310a7a9e2bf3ed42'
          GROUP BY 1
  
      UNION ALL
  
      SELECT 
          date_trunc('day', evt_block_time) AS day, 
          -SUM("_quantity"/1e18) AS amount 
      FROM setprotocol_v2."BasicIssuanceModule_evt_SetTokenRedeemed" 
      WHERE "_setToken" = '\xada0a1202462085999652dc5310a7a9e2bf3ed42'
      GROUP BY 1
  
  ),
  
  days AS (
      
      SELECT generate_series('2021-02-10'::timestamp, date_trunc('day', NOW()), '1 day') AS day -- Generate all days since the first contract
      
  ),
  
  units AS (
  
      SELECT
          d.day,
          COALESCE(m.amount, 0) AS amount
      FROM days d
      LEFT JOIN mint_burn m ON d.day = m.day
      
  )
  
  SELECT 
      day, 
      SUM(amount) OVER (ORDER BY day) AS cgi
  FROM units
  