This repository was archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Helper method for pricing a base currency in a quote currency #8
Merged
+859
−30
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jayantk
commented
Dec 22, 2021
src/lib.rs
Outdated
| */ | ||
| pub fn normalize(&self) -> Option<PriceConf> { | ||
| if self.price > 0 { | ||
| // BPF only supports unsigned division |
Collaborator
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I think this comment isn't actually true. We had some issue with this in the on-chain pyth program, but i just tested and it seems to work just fine here. will fix in the future)
hendrikhofstadt
approved these changes
Dec 28, 2021
| * numbers. Returns None if price information is currently unavailable. | ||
| */ | ||
| pub fn get_current_price(&self) -> Option<(i64, u64, i32)> { | ||
| pub fn get_current_price(&self) -> Option<PriceConf> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should also offer to return an enum
Live(Price)
Stale(OldPrice, Age)
"Dead"
jayantk
added a commit
that referenced
this pull request
Jan 5, 2022
* Helper method for pricing a base currency in a quote currency (#8) * Add method for getting twap * initial implementation, seems to work * minor * minor * refactor * found bad case * use u128 * working on it * clarify * cleanup * more cleanup * pretty sure i need this * better * bad merge * no println * adding solana tx stuff * change approach a bit * this seems to work * comment * cleanup * refactor * refactor * initial implementation of mul * exponent * tests for normalize * tests for normalize * negative numbers in div * handle negative numbers * comments * stuff * cleanup * unused * minor Co-authored-by: Jayant Krishnamurthy <[email protected]> * Instruction counts and optimizations (#9) * instruction counts * reduce normalize opcount * instruction counts * tests Co-authored-by: Jayant Krishnamurthy <[email protected]> * Docs and utilities (#12) * uh oh * docs * fix error docs Co-authored-by: Jayant Krishnamurthy <[email protected]> * bump version number * bump version number * ignore more files * docs * remove mod * checked ops Co-authored-by: Jayant Krishnamurthy <[email protected]>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds an abstraction for performing arithmetic operations on prices with confidence intervals. This abstraction lets you do two things:
I also started adding some code for instruction counting / integration testing, but have decided to punt the rest to a later PR to prevent this PR from getting way too big. I'm going to merge changes into the
v2branch until all that stuff is done, then will merge intomain. Things to address before merging into main are:Review Guide: read
price_conf.rs, which is where all the action is. The rest is largely boilerplate for the integration testing.