Synthetixio / synthetix-subgraph

All sources for the handful of Synthetix subgraphs indexed by The Graph
https://docs.synthetix.io/historical-data/#subgraphs
MIT License
62 stars 63 forks source link

Exchanges in the same block as oracle do not respect transaction ordering #9

Open jjgonecrypto opened 4 years ago

jjgonecrypto commented 4 years ago

There have been times where Synthetix.exchange() invocations were in the same block yet positioned before ExchangeRate.updateRates() and traded on a price that changed in the latter transaction. When we calculate the effectiveValue of the source and destination via The Graph, it gives us the value as at the end of the block, not at the point when the exchange happens. This has lead to a few instances of reporting negative fees.

These can be seen by running the following query against the SNX Exchanges subgraph

 synthExchanges(where:{feesInUSD_lt:0}) {
    id
    account
    from
    fromCurrencyKey
    fromAmountInUSD
    toCurrencyKey
    toAmountInUSD
    feesInUSD
  }
}

We are discussing with members of The Graph engineering team as to how to deal with this issue.

jjgonecrypto commented 4 years ago

As discussed with The Graph engineering members offline, the suggested solution is to track RateUpdate events from synthetix-rates here, and to calculate effectiveValue using the rate entities.