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: improve matching speed and separate amm package #163

Merged
merged 28 commits into from
Feb 12, 2022

Conversation

hallazzang
Copy link
Contributor

@hallazzang hallazzang commented Feb 10, 2022

Description

This PR improves performance of the matching algorithm and fix bugs in PoolOrderSource.

closes: #149, #137

Tasks

  • Create a separate package for amm calculations
  • Use binary search for matching price discovery
  • Make UpTick and DownTick to no more guarantees that the price fits into ticks
  • Do not expire swap requests which are completed
  • Move util functions like parseCoin, parseDec into types/ package

this change makes Up/DownTick a little bit slower(~500ns/op slower)
but there'd be more benefits with it
- fix BuyAmountOnTick to check if XAmountOnTick returns zero
- remove caching on buy/sell amount on ticks
- use binary search to find the lowest/highest tick of pool order source
- use pointer receiver for order sources to avoid copying the value
- use approximated highest/lowest price as a start point
  and iterate through ticks to find the first price with
  non-zero order amount
@hallazzang hallazzang added bug Something isn't working enhancement New feature or request x/liquidity labels Feb 10, 2022
@hallazzang hallazzang self-assigned this Feb 10, 2022
@hallazzang hallazzang linked an issue Feb 12, 2022 that may be closed by this pull request
@hallazzang hallazzang changed the title fix: improve speed and fix bugs in PoolOrderSource fix: improve matching speed and separate amm package Feb 12, 2022
@hallazzang hallazzang marked this pull request as ready for review February 12, 2022 17:54
@hallazzang hallazzang merged commit 0372cae into main Feb 12, 2022
@hallazzang hallazzang deleted the 149-find-match-price-perf branch February 12, 2022 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request x/liquidity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve match price discovery speed refactor: create a package where algorithms live
1 participant