Sadly we can't reliably use the on chain oracle to aggregate all fees to usd, as values are often $0 and we need this to be accurate data. Therefore we'll have to group all fees by token in their native amount, then retroactively use historical pricing data to calculate earnings for each token at a certain block and then sum together to get total protocol fees.
e.g.
tokens(block:{number:12584092}, where:{totalFees_not:"0"}, first:1000) {
totalFees
id
}
Sadly we can't reliably use the on chain oracle to aggregate all fees to usd, as values are often $0 and we need this to be accurate data. Therefore we'll have to group all fees by token in their native amount, then retroactively use historical pricing data to calculate earnings for each token at a certain block and then sum together to get total protocol fees.
e.g.