Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Conversation

@jayantk
Copy link
Collaborator

@jayantk jayantk commented Dec 21, 2021

This PR adds an abstraction for performing arithmetic operations on prices with confidence intervals. This abstraction lets you do two things:

  1. Build synthetic price feeds e.g., by combining mSOL/USD and SOL/USD to get the price of mSOL/SOL.
  2. Price baskets of tokens, like LP tokens. E.g., you can get a price +- confidence for a basket of 0.1 SOL and 0.1 BTC.

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 v2 branch until all that stuff is done, then will merge into main. Things to address before merging into main are:

  1. better integration tests and instruction counts
  2. (possibly) instruction count optimizations
  3. math audit
  4. add CI to this repo

Review Guide: read price_conf.rs, which is where all the action is. The rest is largely boilerplate for the integration testing.

src/lib.rs Outdated
*/
pub fn normalize(&self) -> Option<PriceConf> {
if self.price > 0 {
// BPF only supports unsigned division
Copy link
Collaborator Author

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)

* 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> {

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 jayantk merged commit 25cbde5 into v2 Dec 28, 2021
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]>
@ali-behjati ali-behjati deleted the other_helper branch February 17, 2022 09:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants