synthetix-subgraph
synthetix-subgraph copied to clipboard
Exchanges in the same block as oracle do not respect transaction ordering
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.
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.