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

add functions to parse vaa to price info #37

Merged
merged 8 commits into from
Aug 2, 2023
Merged

add functions to parse vaa to price info #37

merged 8 commits into from
Aug 2, 2023

Conversation

cctdaniel
Copy link
Contributor

@cctdaniel cctdaniel commented Jul 31, 2023

classes and functions here are referenced from pyth-crosschain repo and wormhole js sdk

@@ -0,0 +1,430 @@
# Classes and functions here are referenced from pyth-crosschain repo
Copy link
Contributor

Choose a reason for hiding this comment

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

suggest linking to the specific file that has these definitions

Copy link
Contributor Author

@cctdaniel cctdaniel Aug 1, 2023

Choose a reason for hiding this comment

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

was apprehensive doing this since the original source files could change but yeah we could do it

Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

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

Left you some suggestions on how to implement this a little more cleanly. all the suggestions are minor but there are enough that i'd like to look again before approving.

return json.dumps(result)


def encode_vaa_for_chain(vaa, target_chain):
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's think through how we want to expose the encoding/target_chain in the API. I think the current "target_chain" parameters are a little questionable (yes, I know I made them in the first place, but I'm not sure it was a good idea.)

if offset != len(bytes_):
raise ValueError(f"Invalid length: {len(bytes_)}, expected: {offset}")

return {
Copy link
Contributor

Choose a reason for hiding this comment

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

why does this return a dictionary of one element?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

oh... maybe leave a comment to that effect? I'm not sure why that function does it that way either.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is because that the returned struct was BatchPriceAttestation

return None

for price_attestation in batch_attestation["price_attestations"]:
if price_attestation["price_id"] == price_feed_id:
Copy link
Contributor

Choose a reason for hiding this comment

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

(optional) you may want to make classes for all of these things. it's less error prone to access class members than keys of a dictionary like this. ofc it's also more code so there is a tradeoff there and i'm not sure which way it leans in this case.

}


def vaa_to_price_info(price_feed_id, vaa) -> PriceInfo:
Copy link
Contributor

Choose a reason for hiding this comment

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

this function signature seems questionable to me, as it's doing too much. when you parse a vaa, you should get an object that has a collection of PriceInfos in it, and then the caller can search within that list for a specific feed id. those should be separate pieces of functionality that can be composed, not conflated together in this one function signature.

Copy link
Contributor

Choose a reason for hiding this comment

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

making classes per the comment below would actually help you separate out the logic into composable bits.

Copy link
Contributor

Choose a reason for hiding this comment

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

one more note here for the future: we need to come up with a term for "a binary blob of data that you can post on-chain to update the pyth price". We are currently calling these "vaas" but I don't think that's right anymore in the accumulator world.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you mean creating a separate function like vaa_to_price_infos which returns a List[PriceInfo] and then make vaa_to_price_info call vaa_to_price_infos and return the PriceInfo from the list where it has the specified id?

Copy link
Contributor

Choose a reason for hiding this comment

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

it depends on how often people want to use vaa_to_price_info. If that's a common function that people want, then yes, you can have it. Otherwise, people can call find on the list returned by vaa_to_price_infos.

Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

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

nice!

@cctdaniel cctdaniel merged commit 81af45c into main Aug 2, 2023
@cctdaniel cctdaniel deleted the price-feeds branch August 2, 2023 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants