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

proto: allow more information in ValueView #3800

Merged
merged 1 commit into from
Feb 12, 2024
Merged

Conversation

hdevalence
Copy link
Member

This attempts to make the ValueView more useful for frontends, and prevent frontend code from having to invent its own handling of numeraires. Here, we make two extensions to the ValueView:

  1. Allow adding a list of "equivalent values" in different numeraires. We want to have support for multiple equivalent values because it may be useful to relate the viewed value to multiple different assets. For instance, a delegation token has at least two relevant numeraires: how many staking tokens it represents (using the per-validator exchange rate) and what its cash value is (in, say, USDC).

  2. Allow adding arbitrary extended data using an Any. This could be used to insert a component.dex.Position with the complete position state into the ValueView of an LPNFT, allowing frontend code that has knowledge of LPNFTs to show a rendering of the position's current reserves, price, etc. Using an Any provides extensibility and graceful degradation.

These extensions are not added to the Rust domain types yet, since they're intended for the web context.

This attempts to make the ValueView more useful for frontends, and prevent
frontend code from having to invent its own handling of numeraires.  Here, we
make two extensions to the ValueView:

1. Allow adding a list of "equivalent values" in different numeraires. We want
to have support for multiple equivalent values because it may be useful to
relate the viewed value to multiple different assets. For instance, a
delegation token has at least two relevant numeraires: how many staking tokens
it represents (using the per-validator exchange rate) and what its cash value
is (in, say, USDC).

2. Allow adding arbitrary extended data using an `Any`. This could be used to
insert a `component.dex.Position` with the complete position state into the
`ValueView` of an LPNFT, allowing frontend code that has knowledge of LPNFTs to
show a rendering of the position's current reserves, price, etc. Using an `Any`
provides extensibility and graceful degradation.

These extensions are not added to the Rust domain types yet, since they're
intended for the web context.
// with their position information (trading pair, etc). However, because
// this is in an extension, a frontend that does not have special handling
// logic would fall back on the ordinary asset metadata.
google.protobuf.Any extended_metadata = 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it not be better to have a oneof that we add to when we have more needs? Or does having it strongly typed like this make it not forward compatible?

Copy link
Member Author

Choose a reason for hiding this comment

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

Having a oneof means we need to write out the types explicitly, and because the ValueView is in a "base" proto depended on by other packages, this causes problems — we can't import the dex proto package, because it depends on this one, for instance.

Using Any allows runtime type checking and extensibility to any kind of metadata.

Comment on lines +102 to +108
repeated EquivalentValue equivalent_values = 3;
message EquivalentValue {
// The equivalent amount of the parent Value in terms of the numeraire.
core.num.v1.Amount equivalent_amount = 1;
// Metadata describing the numeraire.
Metadata numeraire = 2;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean:
A) every item in this list is equal to the original (aka many options)
or
B) when summed, the list in total is equal in value to the original (aka parts of a whole)

It appears that it's option A, however, in the case of an LP NFT, option B is more helpful in communicating the equivalent value

Copy link
Member Author

Choose a reason for hiding this comment

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

It means (A).

For the LPNFT case, we probably don't just want to have reserves but also information about the position state, price, etc. So rather than try to shoehorn that into a "price" mechanism I think it's better to put the Position state into an Any.

@hdevalence
Copy link
Member Author

closes #3795

@hdevalence hdevalence merged commit ca2edb0 into main Feb 12, 2024
7 checks passed
@hdevalence hdevalence deleted the more-info-in-value-view branch February 12, 2024 17:56
@cratelyn cratelyn added the protobuf-changes Makes changes to the protobuf definitions. label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
protobuf-changes Makes changes to the protobuf definitions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants