duality-labs / hapi-indexer

A Node.js based indexer for the Duality Cosmos chain
1 stars 0 forks source link

fix: do not skip known indexes in price data table #71

Open dib542 opened 6 months ago

dib542 commented 6 months ago

This PR attempts to fix the setting of LastTickIndex1To0 values in the derived.tx_price_data table.

Previously an update would be skipped if the price on the specific reserve's side TickIndex (HighestNormalizedTickIndex0 or LowestNormalizedTickIndex1 had not changed) had not changed. This is incorrect behavior.

The original intent of the HighestNormalizedTickIndex0 and LowestNormalizedTickIndex1 values was to create a "indicative price" of the pair where a reserve deposit that was "closer to the middle" than any other deposit or previous trade would indicate that the price had changed to that value. This was supposed to be helpful but is not that helpful. It may also even introduce attack vectors where users can influence the recorded price with small deposits at extreme positions.

It is much simpler to keep the definition of price as the last price that a trade occurred on, without accepting prices from any deposit events.

After removing the previous logic, the previous data columns for tracking HighestNormalizedTickIndex0 and LowestNormalizedTickIndex1 values were removed.