Abbas_ra21Untitled Query
Updated 2022-07-06
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
›
⌄
with pools AS (select pool_address,PLATFORM,TOKEN0,TOKEN1 FROM ethereum.core.dim_dex_liquidity_pools
where PLATFORM!='curve')
tpken_prices AS (
(select date_trunc('day', HOUR) as date,
max(PRICE) as token0_price ,
null AS token1_price
from ethereum.core.fact_hourly_token_prices
WHERE contract_address=(SELECT token_0 FROM pools)
UNION
select date_trunc('day', HOUR) as date,
null AS token0_price
max(PRICE) as token1_price
from ethereum.core.fact_hourly_token_prices
WHERE contract_address=(SELECT token_1 FROM pools))
GROUP BY 1 having (date=CURRENT_DATE)),
balances as (
select
case when CONTRACT_ADDRESS=token0 then symbol end as token0_symbol,
case when CONTRACT_ADDRESS=token1 then symbol end as token1_symbol,
case when CONTRACT_ADDRESS=token0 then DECIMALS end as token0_DECIMALS,
case when CONTRACT_ADDRESS=token1 then DECIMALS end as token1_DECIMALS,
case when CONTRACT_ADDRESS=token0 then NON_ADJUSTED_BALANCE end as token0_NON_ADJUSTED_BALANCE,
case when CONTRACT_ADDRESS=token1 then NON_ADJUSTED_BALANCE end as token1_NON_ADJUSTED_BALANCE,
case when CONTRACT_ADDRESS=token0 then BALANCE end as token0_BALANCE,
case when CONTRACT_ADDRESS=token1 then BALANCE end as token1_BALANCE
from flipside_prod_db.ethereum.erc20_balances where USER_ADDRESS in (SELECT pool_address from pools)
where BALANCE_DATE=CURRENT_DATE
)
select
A.pool_address,
A.token0,
B.token0_symbol
B.token0_decimal
Run a query to Download Data