Query editor
-- The big picture of this query is that it calculates the balances in each of the liquidity provider addresses.-- tracks aUSDT balance of 0xad7e2165FEa1d29030dF806cE4d530fa7a44511Bwith receive_ausdt as (select evt_block_time, evt_tx_hash, cast(value as decimal) as quantityfrom erc20_arbitrum.evt_Transferwhere "to" = 0xad7e2165FEa1d29030dF806cE4d530fa7a44511Band contract_address = 0x6ab707Aca953eDAeFBc4fD23bA73294241490620 --aUSDT),send_ausdt as (select evt_block_time, evt_tx_hash, -cast(value as decimal) as quantityfrom erc20_arbitrum.evt_Transferwhere "from" = 0xad7e2165FEa1d29030dF806cE4d530fa7a44511Band contract_address = 0x6ab707Aca953eDAeFBc4fD23bA73294241490620 --aUSDT),receive_ausdc as (select evt_block_time, evt_tx_hash, cast(value as decimal) as quantityfrom erc20_arbitrum.evt_Transferwhere "to" = 0x91beb5c41df001175b588c9510327d53f278972aand contract_address = 0x724dc807b04555b71ed48a6896b6F41593b8C637 --aUSDC),send_ausdc as (select evt_block_time, evt_tx_hash, -cast(value as decimal) as quantityfrom erc20_arbitrum.evt_Transferwhere "from" = 0x91beb5c41df001175b588c9510327d53f278972aand contract_address = 0x724dc807b04555b71ed48a6896b6F41593b8C637 --aUSDC),receive_adai as (select evt_block_time, evt_tx_hash, cast(value as decimal) as quantityfrom erc20_arbitrum.evt_Transferwhere "to" = 0xB7D37C5b15CDF29265C20668c20cD78586c423A8and contract_address = 0x82E64f49Ed5EC1bC6e43DAD4FC8Af9bb3A2312EE --aDAI),send_adai as (select evt_block_time, evt_tx_hash, -cast(value as decimal) as quantityfrom erc20_arbitrum.evt_Transferwhere "from" = 0xB7D37C5b15CDF29265C20668c20cD78586c423A8and contract_address = 0x82E64f49Ed5EC1bC6e43DAD4FC8Af9bb3A2312EE --aDAI),transfers as (select token, sum(quantity / POW(10, decimals)) as total_transferredfrom(select *, 'aUSDT' as token, 6 as decimals from receive_ausdtunion all -- required otherwise it undercountsselect *, 'aUSDT' as token, 6 as decimals from send_ausdtunion allselect *, 'aUSDC' as token, 6 as decimals from receive_ausdcunion allselect *, 'aUSDC' as token, 6 as decimals from send_ausdcunion allselect *, 'aDAI' as token, 18 as decimals from receive_adaiunion allselect *, 'aDAI' as token, 18 as decimals from send_adai)group by token)select round(sum(total_transferred * coalesce(price, 1)), 2) as tvlfrom transfers