Query editor
with defy_txt as (SELECTa.call_block_time as block_date,a.call_tx_hash,b.n AS defy_path,b.path_token as defy_contract,cast(b.output_amounts_token as double)/1e18 as defy_amtFROM quickswap_polygon.UniswapV2Router02_call_swapExactTokensForTokens aCROSS JOIN UNNEST(a.path,a.output_amounts) WITH ORDINALITY AS b (path_token,output_amounts_token,n)where path_token=0xBF9f916bBda29A7F990F5F55c7607D94D7C3A60b and call_success=trueand call_block_time >= cast('2022-08-06' as timestamp)),usdc_txt as (SELECTa.call_tx_hash,b.n AS usdc_path,b.path_token as usdc_contract,cast(b.output_amounts_token as double)/1e6 as usdc_amtFROM quickswap_polygon.UniswapV2Router02_call_swapExactTokensForTokens aCROSS JOIN UNNEST(a.path,a.output_amounts) WITH ORDINALITY AS b (path_token,output_amounts_token,n)where path_token=0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 and call_success=trueand call_block_time >= cast('2022-08-06' as timestamp)),price_info as (select date_trunc('day', block_date) as block_date, sum(usdc_amt)/sum(defy_amt) as defy_price, sum(usdc_amt) as volume from(select * from defy_txt g left join usdc_txt w on g.call_tx_hash = w.call_tx_hash) ftgroup by 1order by block_date),supply AS(select sum(cast(value as double))/1e18 as total_supplyfrom erc20_ethereum.evt_Transferwhere contract_address = 0x205eD31C867bF715E4182137Af95AFE9177Cd8E7 and "from" = 0x0000000000000000000000000000000000000000and evt_block_time >= cast('2022-07-27' as timestamp))select *,Lag(defy_price, 7) OVER(order by block_date asc) AS price_7days_lag,(defy_price/(Lag(defy_price, 7) OVER(order by block_date asc))-1)*100 AS price_7days_change,total_supply, total_supply * defy_price as market_cap_fdvfrom price_info, supplywhere block_date > now() - interval '{{Trailing Trading Days}}' dayand 1 <= {{Synchronize}}