Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle point ranges in AMM matching #11485

Merged
merged 1 commit into from
Jul 23, 2024

Conversation

wwestgarth
Copy link
Contributor

closes #11484

@wwestgarth wwestgarth added this to the 🏯 Suzuka Castle milestone Jul 22, 2024
@wwestgarth wwestgarth self-assigned this Jul 22, 2024
@wwestgarth wwestgarth requested a review from a team as a code owner July 22, 2024 13:01
@@ -157,6 +158,7 @@ func New(
marketActivityTracker *common.MarketActivityTracker,
parties common.Parties,
) *Engine {
oneTick, _ := num.UintFromDecimal(num.DecimalOne().Mul(priceFactor))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand a couple of things about this:

  1. this will always be 0 if the asset has less decimals than the market, is that ok?
  2. what's the point of multiplying by 1?
  3. why should it be price factor rather than just 1 if it's prices in asset than adjusting by 1 is what you want isn't it?

Copy link
Contributor Author

@wwestgarth wwestgarth Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. probably not, but none of this has been tested with negative DP's yet since they appeared half-way through the AMM feature branch's life and I just had to resolve the conflicts so we could merge. Its been on my list to revist for a while, I'll make a ticket for it now.
  2. there is no point, I'll fix it up
  3. the matching algorithm for AMMs as defined in the spec works to the resolution of order-price-levels, there is no need for it to be more granular because any incoming orders will only be at these price-factor price levels and so knowing that an AMM's fair-price is "somewhere between two price levels" is enough. Whenever we need to view an AMM as orders, or if we need to reason about what a "unit-step" is along the AMM's curve we only need to consider the order-price levels to ensure everything remains uncrossed.

For example here in this bug, when we need to uncross at auction end, we "expand" the AMM in orders to this one-tick granuality because thats all we need to ensure we remain uncrossed afterwards. Then when we submit those orders to uncross, we again only need to reason in this one-tick granuality.

We could instead view "unit-steps" along the AMM's curve in asset prices but this would cause a performance hit because there would be so many. We would also need to enforce that the commitment of an AMM is sufficient to create at least 1 volume between these "unit-steps" on the AMM curve so that the maths doesn't break down with < 1 volume price changes. If we use asset-prices for our "unit-steps" then the minimum commitment for an AMM would have to me much much higher so that this remains true with smaller steps.

@wwestgarth wwestgarth force-pushed the 11484-sla-with-no-mark-price branch from 8128d61 to 38c1ae7 Compare July 22, 2024 16:02
@jeremyletang jeremyletang merged commit 6c97fbd into develop Jul 23, 2024
16 checks passed
@jeremyletang jeremyletang deleted the 11484-sla-with-no-mark-price branch July 23, 2024 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Bug]: Panic in overnight run -- AMM uncrossing does not produce a trade
3 participants