CryptoLionaave flashloans
    Updated 2021-08-31
    with addys as (
    select
    block_timestamp,
    tx_id,
    target_address,
    aave_market,
    symbol,
    flashloan_amount_usd as flash_volume,
    premium_amount_usd as premium_amount
    from aave.flashloans
    where block_timestamp >= getdate() - interval '4 month'
    -- group by 1,2
    -- order by 1 desc
    ),
    pools as (
    select
    addys.tx_id,
    contract_name,
    contract_address,
    event_name,
    target_address,
    case
    when event_name = 'Swap' then
    case
    when contract_name like '%UNI-V2%' or contract_name like '%UniswapV2%' or contract_name like '%uniswap v2%' then 'UNI V2'
    when contract_name like '%UNI-V3%' or contract_name like '%UniswapV3%' then 'UNI V3'
    when contract_name like '%SLP%' or contract_name like '%sushi%' then 'sushi'
    when contract_name is null then 'UNKNOWN'
    when contract_name = 'Vault' then 'Balancer'
    when contract_name = 'Root' then 'SyUSD'
    else contract_name end
    when event_name = 'RepayBorrow' then
    case
    when contract_name like 'c%' then 'compound'
    else null end
    when event_name = 'TokenExchange' then
    Run a query to Download Data