Query editor
-- DUNE ANALYTICS SQL QUERY FOR ELEPHANT MONEY STATISTICS - TREASURIES, HOLDERS AND LIQUIDITY-- Created on 16/05/2022 by dedalus (https://t.me/dedalus76)---- Updated 18/05/2022 by dedalus - added BUSD/TRUNK peg to History graph---- This query extracts the historical liquidity of the TRUNK / BUSD LP in TRUNK and BUSD currency.-- Additionally, the BUSD/TRUNK price is calculated.-- This query uses the following Dune Analytics decoded data:-- BEP20.BEP20_evt_Transfer to query the token transfers to/from contracts. This method does not keep-- track of reflections and cannot be used for Elephant token---- Please don't use this query blindly. I try to avoid / solve mistakes in the code but I am only human.-- Additionally, I am an SQL newbie, so don't take my code as a reference for your own work.---- BEGIN CODEWITH-- Load EM contractscontracts as (SELECT * FROM query_2118328 -- Elephant Money Contracts),-- Balance is computed as the sum of all in&out transfers of BUSD token from/to the TRUNK BUSD LP, grouped by wallettransfers_TRUNK AS(SELECTDAY,address,SUM(amount) AS amountFROM(SELECTDATE_TRUNC('day', evt_block_time) AS DAY,tr."to" AS address,cast(value as double) AS amountFROM elephant_bnb.ElephantDollar_evt_Transfer trWHERE contains((select address from contracts where name = 'TRUNK'), contract_address) -- TRUNKAND contains((select address from contracts where name = 'TRUNKLP'), to) -- TRUNK ReserveAND value IS NOT NULLUNION ALLSELECTdate_trunc('day', evt_block_time) AS DAY,tr."from" AS address,-cast(value as double) AS amountFROM elephant_bnb.ElephantDollar_evt_Transfer trWHERE contains((select address from contracts where name = 'TRUNK'), contract_address) -- TRUNKAND contains((select address from contracts where name = 'TRUNKLP'), "from") -- TRUNK ReserveAND value IS NOT NULL) as tGROUP BY 1, 2),-- Balance is computed as the sum of all in&out transfers of BUSD token from/to the TRUNK BUSD LP, grouped by wallettransfers_BUSD AS(SELECTday,SUM(amount) as amountFROM(