Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: lp indexing #4771

Merged
merged 8 commits into from
Jul 30, 2024
Merged

feat: lp indexing #4771

merged 8 commits into from
Jul 30, 2024

Conversation

vacekj
Copy link
Member

@vacekj vacekj commented Jul 25, 2024

Describe your changes

implements lp positions and execution indexing

TODO from reviews:

  • We want to store the trading pair likely as a new derived type (tuple) of (BYTEA, BYTEA)
  • We definitely need a table storing the current state of any given position, including permanent information like the trading pair, price, fees.
  • We need to include the reserve amounts in the lp_updates table, to have a history of the reserves over time.
  • Price info, for both updates and current state

Issue ticket number and link

fixes #4739

Checklist before requesting a review

  • If this code contains consensus-breaking changes, I have added the "consensus-breaking" label. Otherwise, I declare my belief that there are not consensus-breaking changes, for the following reason:

indexer-only changes

@vacekj vacekj requested review from cronokirby and aubrika and removed request for cronokirby July 25, 2024 20:17
@cronokirby
Copy link
Contributor

This is a good start, but I think we want to compute some more derived information for use in the explorer, for example the price, so that the explorer can easily sort and fetch by price.

@conorsch conorsch marked this pull request as draft July 25, 2024 21:17
Copy link
Contributor

@cronokirby cronokirby left a comment

Choose a reason for hiding this comment

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

Let's clean up the accidental formatting changes and make sure that we have all the information we need to implement the APIs.

@conorsch
Copy link
Contributor

This is a good start, but I think we want to compute some more derived information for use in the explorer

Downgrading to "draft", mostly to signal that we don't intend to block on upcoming point-release until this lands. Feel free to promote back to ready for review whenever, @vacekj!

@cronokirby
Copy link
Contributor

A few more things I noticed:

  • We want to store the trading pair likely as a new derived type (tuple) of (BYTEA, BYTEA)
  • We definitely need a table storing the current state of any given position, including permanent information like the trading pair, price, fees.
  • We need to include the reserve amounts in the lp_updates table, to have a history of the reserves over time.

@vacekj
Copy link
Member Author

vacekj commented Jul 26, 2024

@cronokirby I addressed your feedback:

  • Reserve amounts are already included in the table and events, including reserve amounts pre and post execution.
  • I've added a new TradingPair type to postgres and made relevant changes
  • The formatting in the sql file was intentional. If necessary, I'm open to reverting to the previous one.
  • Fixed an oversight in the inserts where I was not passing in the actual data correctly
  • added a table storing current state of positions, implemented as a view over the lp_updates table

Question about #: I might be misunderstanding, but the price here should just be reserves_1/reserves_2 right? I think we can calculate this on the fly in queries, but I can also add it to the view if necessary.

let me know how this looks to you @conorsch @cronokirby

also, who else should i be tagging ƒor reviews? don't wanna overload just aubrey, conor and lucas 😃

@vacekj vacekj marked this pull request as ready for review July 26, 2024 15:56
@vacekj vacekj requested review from cronokirby and conorsch July 26, 2024 15:56
@cronokirby
Copy link
Contributor

cronokirby commented Jul 26, 2024

The problem with calculating the price as based on reserves is that it changes over time, as the reserves change, but in fact the price is static. It's based on https://buf.build/penumbra-zone/penumbra/docs/main:penumbra.core.component.dex.v1#penumbra.core.component.dex.v1.BareTradingFunction as present in the position.

If you're trading asset1 into asset2, the price is p / q, and if you're doing the opposite, it's q / p. For the effective price, which is what the dex explorer uses, you also need to take fees into account, so you get a worse price.

@vacekj
Copy link
Member Author

vacekj commented Jul 29, 2024

@cronokirby this leads me to believe we then have all we need in the data? Can we proceed to review and merge?

@vacekj vacekj changed the title feat: lp feat: lp indexing Jul 29, 2024
@cronokirby
Copy link
Contributor

I think we want:

  • to store the price directly so that we can easily replicate the search by price queries
  • to actually materialize each LP rather than computing it by taking the last seen update, because we need extra information like the price, and can avoid storing information that doesn't change in every update

but more broadly with this one we can actually test that it works by modifying the dex explorer raw indexing database queries to use it, and we should do that.

Copy link
Contributor

@cronokirby cronokirby left a comment

Choose a reason for hiding this comment

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

It would also be nice if we didn't create a diff over the parts of the database we haven't changed, we can format in a separate PR

This restructures the dex tables to be a bit richer and de-duplicated
Copy link
Contributor

@cronokirby cronokirby left a comment

Choose a reason for hiding this comment

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

Looks good to me now, did some brief testing as well

Because it's unitless, we need decimals, woops.
@vacekj vacekj merged commit 935a17c into main Jul 30, 2024
13 checks passed
@vacekj vacekj deleted the 4739-pindexer-lp branch July 30, 2024 15:03
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pindexer: dex: implement /api/lp related events and tables
3 participants