Average value of a SmartContractEvent argument, for x period

hi guys, i’m trying to calculate the individual averages for 4 arguments, from a smartContractEvent, for a period (1 day). Using this formula.
I have the actual averages of these 4 arguments, and this isn’t returning the correct numbers.
Where am I going wrong?

query MyQuery {
  ethereum {
    arguments(
      smartContractAddress: {is: "0x0EF1B8a0E726Fc3948E15b23993015eB1627f210"}
      smartContractEvent: {is: "Sync"}
      options: {desc: "date.date"}
      date: {is: "21-06-12"}
    ) {
       date {
        date(format: "%y-%m-%d")
      }
      SwapFee: number(argument: {is: "fee"}, calculate: average)
      PriceImpactFee: number(argument: {is: "slippageFee"}, calculate: average)
      ReferralShare: number(argument: {is: "referralShare"}, calculate: average)
      GovernanceShare: number(argument: {is: "governanceShare"}, calculate: average)
      
    }
  }
}

Is this what you looking for?

{
  ethereum(network: ethereum) {
    arguments(
      smartContractAddress: {in: "0x0EF1B8a0E726Fc3948E15b23993015eB1627f210"}
      smartContractEvent: {is: "Sync"}
      date: {is: "21-06-12"}
    ) {
      SwapFee: number(argument: {is: "fee"}, calculate: average)
      PriceImpactFee: number(argument: {is: "slippageFee"}, calculate: average)
      ReferralShare: number(argument: {is: "referralShare"}, calculate: average)
      GovernanceShare: number(argument: {is: "governanceShare"}, calculate: average)
    }
  }
}

this actually gives the same results as my the top query.
I used the query below to get each block’s fee actual fee number, for the whole day.
Averaged that result, and it doesn’t match to the queries above.

Code here… Which of one these queries provides the correct value?

============================================
query MyQuery {
ethereum {
arguments(
smartContractAddress: {is: “0x0EF1B8a0E726Fc3948E15b23993015eB1627f210”}
smartContractEvent: {is: “Sync”}
options: {desc: “block.timestamp.unixtime”}
date: {is: “21-06-10”}
) {
block {
height
timestamp {
unixtime
}
}
index
SwapFee: any(of: argument_value, argument: {is: “fee”})
PriceImpactFee: any(of: argument_value, argument: {is: “slippageFee”})
ReferralShare: any(of: argument_value, argument: {is: “referralShare”})
GovernanceShare: any(of: argument_value, argument: {is: “governanceShare”})
}
}
}

Date is different in the query mention.

Yes thanks. But i ran all the queries on the 10th and the numbers don’t match up.
Just wanting to check to make sure the last formula I pasted, does what its meant to.
So there, trying to sum all the argument values for each event for 1 day

This don’t give me any result, check here getting events block by block

I believe it will give you 1 event per block… can you confirm?

If not check it if give string or number?

from my results “block_height”, there are no duplicates of any block in the repsonse.
Not sure if that is conclusive.
What code would I use to return every occurrence of an smartContractEvent?

I believe then it’s only showing 1 event per block, therefore it not taking all the events into the account, therefore you are getting different results.

How would you suggest i order the results, to disregard block?
So that multiple results from within 1 block are returned…

You can either average the results Like shown in the very first answer by me…

or get all results, use query below

query MyQuery {
  ethereum {
    smartContractEvents(
      smartContractAddress: {is: "0x0EF1B8a0E726Fc3948E15b23993015eB1627f210"}
      smartContractEvent: {is: "Sync"}
      date: {is: "21-06-10"}
    ) {
      arguments {
        argument
        argumentType
        value
      }
    }
  }
}

However need to check how to sort it… will update on that soon

hi Gaurav, your suggestion returns, a list of all the arguments, for a particular event. This is handy for verification purposes. However, I was after all occurrences of a particular event, on a given day. Perhaps filtered by argument (if too hard, not necessary).

think i have sorted out, all good

1 Like