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 support of anchor deserialzation #93

Merged
merged 8 commits into from
Jan 5, 2023

Conversation

yhzhang0128
Copy link
Contributor

No description provided.

@yhzhang0128
Copy link
Contributor Author

yhzhang0128 commented Jan 2, 2023

@guibescos Hi Guillermo, it took me some time to fix this issue. I tried your suggestion of writing my own PythPriceFeedAccount instead of using the Anchor official Account, but it ended up with pretty long code and complex compiler errors.

My latest solution is to use Price instead of PriceFeed or PriceAccount for deserialization. Unlike PriceFeed, using Price eliminates the need of feed account key in deserialization. Unlike PriceAccount, Price is a small structure and doesn't trigger stack overflow when copying.

The code now seems neat and it is consistent with Anchor's recommended way of deserializing account from non-anchor programs. (Anchor's recommendation is here)

Please take a look. Thanks!

@guibescos
Copy link
Contributor

guibescos commented Jan 3, 2023

Did you try rewriting Account as I advised. I think that approach is easier to move to the sdk.

@yhzhang0128
Copy link
Contributor Author

yhzhang0128 commented Jan 3, 2023

Did you try rewriting Account as I advised. I think that approach is easier to move to the sdk.

Hey Guillermo, yes I did and please see this branch

I copied many things from account.rs to state.rs and renamed Account to PythPriceAccount. And then try to use PythPriceAccount directly in the Accounts struct.

I am getting compiler errors related to the Accounts macro and I don't really know how to solve it. Any help or suggestion would be appreciated!

Lastly, I feel that using the anchor Account is more consistent with anchor's recommended best-practice. I guess we can try to finish both approaches first and then compare which seems more reasonable.

@yhzhang0128
Copy link
Contributor Author

yhzhang0128 commented Jan 5, 2023

After discussing with Guillermo, we decided to drop the approach of rewriting Account.

After discussing with Ali, we decided to use PriceFeed and implement Deref for it. In this PR, the example uses a dummy key when creating the PriceFeed. Later, the SDK will remove the key field from PriceFeed and this example will be modified accordingly.

Also, I noticed that the test I added in another PR is failing. I will ask Ali what may go wrong.

@ali-bahjati ali-bahjati merged commit 5f06773 into pyth-network:main Jan 5, 2023
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