Skip to content

feat(oracle): WIP add scores account #407

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

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b343951
feat(oracle): WIP add scores account
keyvankhademi Jun 7, 2024
1561e80
feat: use bitset to reduce scores account size
keyvankhademi Jun 10, 2024
b58625c
fix: pre-commit
keyvankhademi Jun 10, 2024
18c6787
fix: add price test
keyvankhademi Jun 13, 2024
32c577e
fix: rename score to cap
keyvankhademi Jun 13, 2024
2ec0004
feat: remove publisher sorting features
keyvankhademi Jun 14, 2024
a02a10b
feat: improve caps account calculations
keyvankhademi Jun 14, 2024
0c98527
feat: rename score to publisher_caps
keyvankhademi Jun 14, 2024
87f61ec
fix: bypass false positive clippy
keyvankhademi Jun 14, 2024
2f6f359
feat: optimize oracle command enum
keyvankhademi Jun 14, 2024
2697cb2
feat: test new way of calculating score
keyvankhademi Jun 14, 2024
d07a256
fix: correct rust doc format
keyvankhademi Jun 17, 2024
98a6a52
fix: clippy
keyvankhademi Jun 17, 2024
4260e2e
feat: add vscode settings
keyvankhademi Jun 17, 2024
6c9d3e6
fix: clippy warning
keyvankhademi Jun 17, 2024
8e00103
feat: change OracleCommand repr from i32 to u32
keyvankhademi Jun 17, 2024
aa1e0a7
feat: add initial tests for publisher caps
keyvankhademi Jun 17, 2024
2372be6
feat: add migration step
keyvankhademi Jun 17, 2024
63352ec
test: try a different implementation for program size
keyvankhademi Jun 17, 2024
aaa12bf
test: try manual swap to decrease program size
keyvankhademi Jun 17, 2024
e2aa645
fix: add price when initializing the caps account
keyvankhademi Jun 17, 2024
2169e8d
fix: rename scores account to cap account
keyvankhademi Jun 17, 2024
de0f7c3
refactor: rename calculate_scores to calculate_caps
keyvankhademi Jun 17, 2024
4396054
refactor: rename symbols to prices in PublisherCapsAccount
keyvankhademi Jun 17, 2024
0563db6
refactor: update publisher permission index to use price instead of s…
keyvankhademi Jun 17, 2024
6c321bf
refactor: update publisher permission index to use price instead of s…
keyvankhademi Jun 17, 2024
9e90897
chore: Update num-traits dependency to version 0.2
keyvankhademi Jun 17, 2024
5c1f750
feat: add initial quickcheck for caps account
keyvankhademi Jun 18, 2024
02f6257
refactor: update upd_price.rs to use send_message_to_message_buffer f…
keyvankhademi Jun 18, 2024
7800412
feat: send caps to message buffer for add publisher
keyvankhademi Jun 19, 2024
9b52a40
fix: comment migration code to test program size
keyvankhademi Jun 19, 2024
a18ec0c
feat: remove init mapping to reduce program size
keyvankhademi Jun 19, 2024
5932402
feat: keep init mapping for tests
keyvankhademi Jun 19, 2024
21c38c8
fix: self ref error
keyvankhademi Jun 19, 2024
413abc3
fix: revert mapping account changes
keyvankhademi Jun 19, 2024
23a1da8
feat: add cfg test flag for init mapping
keyvankhademi Jun 19, 2024
1a11ca4
temporary remove pipeline test
keyvankhademi Jun 19, 2024
1fa4c6a
remove upd_permissions to check size
keyvankhademi Jun 19, 2024
dd453fb
add feature test to be able to compile oracle for test
keyvankhademi Jun 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"rust-analyzer.check.command": "clippy",
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"rust-analyzer.rustfmt.overrideCommand": [
"rustfmt",
"+nightly"
],
"editor.formatOnSave": true,
}
17 changes: 11 additions & 6 deletions program/c/src/oracle/oracle.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ extern "C" {
#define PC_PUBKEY_SIZE 32
#define PC_PUBKEY_SIZE_64 (PC_PUBKEY_SIZE/sizeof(uint64_t))
#define PC_MAP_TABLE_SIZE 640
#define PC_MAX_PUBLISHERS 256
#define PC_MAX_SYMBOLS 1024
Copy link
Collaborator

Choose a reason for hiding this comment

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

what we do if we exceed this numbers?

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds like a Pythnet v2 problem anyway

Copy link
Author

Choose a reason for hiding this comment

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

The program doesn't allow exceeding these numbers, we will probably face a lot of issues if we decide to increase these numbers. We are hoping to go to pythnet V2 before we need to increase these numbers. From the trasactions limit that we currently have, i don't think this will an issue.
But if you think there is a chance that we exceed these number before pythnet v2, we better address it now.

// This is the number of 64-bit words needed to store the bitset of symbols
#define PC_MAX_SYMBOLS_64 (PC_MAX_SYMBOLS/64)

// Total price component slots available
// Total price component slots available
#define PC_NUM_COMP_PYTHNET 128

// PC_NUM_COMP - number of price components in use
Expand All @@ -49,11 +53,12 @@ extern "C" {
#define PC_STATUS_IGNORED 4

// account types
#define PC_ACCTYPE_MAPPING 1
#define PC_ACCTYPE_PRODUCT 2
#define PC_ACCTYPE_PRICE 3
#define PC_ACCTYPE_TEST 4
#define PC_ACCTYPE_PERMISSIONS 5
#define PC_ACCTYPE_MAPPING 1
#define PC_ACCTYPE_PRODUCT 2
#define PC_ACCTYPE_PRICE 3
#define PC_ACCTYPE_TEST 4
#define PC_ACCTYPE_PERMISSIONS 5
#define PC_ACCTYPE_SCORE 6


// Compute budget requested per price update instruction
Expand Down
4 changes: 3 additions & 1 deletion program/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ solana-program = "=1.13.3"
bytemuck = "1.11.0"
thiserror = "1.0"
num-derive = "0.3"
num-traits = "0.2"
byteorder = "1.4.3"
serde = { version = "1.0", features = ["derive"], optional = true }
strum = { version = "0.24.1", features = ["derive"], optional = true }
pythnet-sdk = { git = "https://github.com/pyth-network/pyth-crosschain", rev="60144002053a93f424be70decd8a8ccb8d618d81"}
num-traits = "0.2"


[dev-dependencies]
solana-program-test = "=1.13.3"
Expand All @@ -38,6 +39,7 @@ csv = "1.1"
check = [] # Skips make build in build.rs, use with cargo-clippy and cargo-check
debug = []
library = []
test = []

[lib]
crate-type = ["cdylib", "lib"]
6 changes: 3 additions & 3 deletions program/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ fn do_make_build(targets: Vec<&str>, out_dir: &Path) {
if !make_output.status.success() {
panic!(
"C oracle make build did not exit with 0 (code
({:?}).\n\nstdout:\n{}\n\nstderr:\n{}",
({:?}).\n\nstdout:\n{}\n\nstderr:\n{}",
make_output.status.code(),
String::from_utf8(make_output.stdout).unwrap_or("<non-utf8>".to_owned()),
String::from_utf8(make_output.stderr).unwrap_or("<non-utf8>".to_owned())
String::from_utf8(make_output.stdout).unwrap_or_else(|_| "<non-utf8>".to_owned()),
String::from_utf8(make_output.stderr).unwrap_or_else(|_| "<non-utf8>".to_owned())
);
}
}
Expand Down
20 changes: 15 additions & 5 deletions program/rust/src/accounts.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
//! Account types and utilities for working with Pyth accounts.

#[cfg(any(feature = "test", test))]
use {
crate::utils::get_rent,
crate::utils::try_convert,
solana_program::program::invoke_signed,
solana_program::pubkey::Pubkey,
solana_program::system_instruction::create_account,
};
use {
crate::{
c_oracle_header::PC_MAGIC,
deserialize::load_account_as_mut,
error::OracleError,
utils::{
check_valid_fresh_account,
get_rent,
pyth_assert,
try_convert,
},
},
bytemuck::{
Expand All @@ -18,10 +24,7 @@ use {
},
solana_program::{
account_info::AccountInfo,
program::invoke_signed,
program_error::ProgramError,
pubkey::Pubkey,
system_instruction::create_account,
},
std::{
cell::RefMut,
Expand All @@ -39,6 +42,7 @@ mod mapping;
mod permission;
mod price;
mod product;
mod publisher_caps;

// Some types only exist during use as a library.
#[cfg(feature = "strum")]
Expand All @@ -64,6 +68,7 @@ pub use {
update_product_metadata,
ProductAccount,
},
publisher_caps::PublisherCapsAccount,
};

// PDA seeds for accounts.
Expand All @@ -76,7 +81,10 @@ pub const PERMISSIONS_SEED: &str = "permissions";
/// such that the caller can authenticate its origin.
pub const UPD_PRICE_WRITE_SEED: &str = "upd_price_write";

pub const CAPS_WRITE_SEED: &str = "caps_write";

#[repr(C)]
#[cfg_attr(test, derive(Debug))]
#[derive(Copy, Clone, Zeroable, Pod)]
pub struct AccountHeader {
pub magic_number: u32,
Expand Down Expand Up @@ -131,6 +139,7 @@ pub trait PythAccount: Pod {
/// Creates PDA accounts only when needed, and initializes it as one of the Pyth accounts.
/// This PDA initialization assumes that the account has 0 lamports.
/// TO DO: Fix this once we can resize the program.
#[cfg(any(feature = "test", test))]
fn initialize_pda<'a>(
account: &AccountInfo<'a>,
funding_account: &AccountInfo<'a>,
Expand Down Expand Up @@ -158,6 +167,7 @@ pub trait PythAccount: Pod {
}
}

#[cfg(any(feature = "test", test))]
fn create<'a>(
from: &AccountInfo<'a>,
to: &AccountInfo<'a>,
Expand Down
Loading
Loading