timewave-computer / valence-services

Other
3 stars 0 forks source link

Ensure multiple messages for market makers can be executed without sequence errors #20

Closed uditvira closed 3 months ago

uditvira commented 5 months ago

Concerns:

  1. 2 auctions reaching their optimal prices at the same block (should happen very rarely given price volatility and cycle long time)
  2. MM contract doesn't have enough funds to buy the full amount of the auction.

Explanations:

  1. We have 1 MM contract that functions as default stop to 12 auctions (as of now), in rare cases 2 or more of those auction couldn't reach the optimal price on the same block, if that happens, the first bid would go through, but the second would fail we sequence error, and would only finalize on the next block, resolving in a very slightly less optimal price.
  2. If for example our MM contract holds 10 atom, but the auction sell 30 atom, we would need 3 messages to buy up the auction fully, each message would be called on a separate block resulting in less optimal pricing for the whole auction.

Solutions:

  1. We can have a queue of message to execute, and execute them on the same block using the multiMsg functionality, this will eliminate this edge case.
  2. We can use the same queue from above, but would require a small change, because we would need to calculate how much message we need to send before we are sending them, which we are doing right now.

Factors:

  1. Funds - The more funds are moving through the system, the more likely we would reach one of those edge cases.
  2. MMs - the more MMs participating in the auctions, the less likely our MM contract will be called.

Conclusion:

Given we assume the MM contract will be called rarely (and hopefully never), and even if those edge cases are reached, the price difference is very little, it is influenced by the amount moving through the auction.

I would suggest to understand the impact first before implementing those changes, as it is required some research to be done.

Art3miX commented 5 months ago

After testing live, there were no errors regarding this issue.

We still need to take care of this and see how we can send multiple messages on the same block. but not urgent at all.

stiiifff commented 5 months ago

Unassigning @Art3miX as this has been moved back to the Backlog.

uditvira commented 5 months ago

Can we close this issue? Trying to keep the board focused on the current work @Art3miX

Art3miX commented 4 months ago

I edited the issue to reflect all the data. Would suggest to keep this issue open for now, until we have more funds moving through the system and have better metrics to understand the impact of it.

Art3miX commented 3 months ago

Closing this issue as this seems to be a non-issue, and even if we reach this very rare case, it will not error anything and will be resolved automatically.