Skip to content

Update dependency, program id and test for pyth-price-store #314

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

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ once_cell = "1.12.0"
ouroboros = "0.15.0"
pyth-oracle = { git = "https://github.com/pyth-network/pyth-client", rev = "256b57", features = ["library"] }
pythnet-sdk = { git = "https://github.com/pyth-network/pyth-crosschain", version = "1.13.6", rev = "33f901aa45f4f0005aa5a84a1479b78ca9033074" }
pyth-price-publisher = { git = "https://github.com/pyth-network/pyth-crosschain", branch = "add-publisher-program" }
pyth-price-store = "0.1.0"
rand = "0.7.0"
rayon = "1.5.3"
regex = "1.5.6"
Expand Down
3 changes: 1 addition & 2 deletions runtime/src/bank/pyth/accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ lazy_static! {
);
pub static ref BATCH_PUBLISH_PID: Pubkey = env_pubkey_or(
"BATCH_PUBLISH_PID",
// TODO: replace with real program id
"FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epA"
"3m6sv6HGqEbuyLV84mD7rJn4MAC9LhUa1y1AUNVqcPfr"
.parse()
.unwrap(),
);
Expand Down
10 changes: 5 additions & 5 deletions runtime/src/bank/pyth/batch_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
find_publisher_index, get_status_for_conf_price_ratio, solana_program::pubkey::Pubkey,
OracleError, PriceAccount,
},
pyth_price_publisher::accounts::publisher_prices as publisher_prices_account,
pyth_price_store::accounts::buffer,
solana_sdk::{account::ReadableAccount, clock::Slot},
std::collections::HashMap,
thiserror::Error,
Expand Down Expand Up @@ -37,7 +37,7 @@ pub fn extract_batch_publish_prices(
"Oracle program account index missing"
);

let publisher_prices_accounts = bank
let publish_program_accounts = bank
.get_filtered_indexed_accounts(
&IndexKey::ProgramId(*BATCH_PUBLISH_PID),
|account| account.owner() == &*BATCH_PUBLISH_PID,
Expand All @@ -49,11 +49,11 @@ pub fn extract_batch_publish_prices(
let mut all_prices = HashMap::<u32, Vec<PublisherPriceValue>>::new();
let mut num_found_accounts = 0;
let mut num_found_prices = 0;
for (account_key, account) in publisher_prices_accounts {
if !publisher_prices_account::format_matches(account.data()) {
for (account_key, account) in publish_program_accounts {
if !buffer::format_matches(account.data()) {
continue;
}
let (header, prices) = match publisher_prices_account::read(account.data()) {
let (header, prices) = match buffer::read(account.data()) {
Ok(r) => r,
Err(err) => {
warn!("invalid publisher prices account {}: {}", account_key, err);
Expand Down
61 changes: 42 additions & 19 deletions runtime/src/bank/pyth/tests/batch_publish_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ use {
pyth_oracle::{
solana_program::account_info::AccountInfo, PriceAccount, PriceAccountFlags, PythAccount,
},
pyth_price_publisher::accounts::publisher_prices::{
self as publisher_prices_account, PublisherPrice,
pyth_price_store::{
accounts::{
buffer::{self, BufferedPrice},
publisher_config,
},
instruction::PUBLISHER_CONFIG_SEED,
},
solana_sdk::{
account::{AccountSharedData, ReadableAccount, WritableAccount},
Expand All @@ -38,37 +42,55 @@ fn test_batch_publish() {
genesis_config.epoch_schedule = EpochSchedule::new(slots_in_epoch);
let mut bank = create_new_bank_for_tests_with_index(&genesis_config);

let generate_publisher = |seed, new_prices| {
let publisher1_key = keypair_from_seed(seed).unwrap();
let generate_publisher = |seed, seed2, new_prices| {
let publisher_key = keypair_from_seed(seed).unwrap();

let (publisher1_prices_key, _bump) = Pubkey::find_program_address(
&[b"BUFFER", &publisher1_key.pubkey().to_bytes()],
let (publisher_config_key, _bump) = Pubkey::find_program_address(
&[
PUBLISHER_CONFIG_SEED.as_bytes(),
&publisher_key.pubkey().to_bytes(),
],
&BATCH_PUBLISH_PID,
);
let mut publisher1_prices_account =
AccountSharedData::new(42, publisher_prices_account::size(100), &BATCH_PUBLISH_PID);
let publisher_buffer_key =
Pubkey::create_with_seed(&leader_pubkey, seed2, &BATCH_PUBLISH_PID).unwrap();

let mut publisher_config_account =
AccountSharedData::new(42, publisher_config::SIZE, &BATCH_PUBLISH_PID);

publisher_config::create(
publisher_config_account.data_mut(),
publisher_key.pubkey().to_bytes(),
publisher_buffer_key.to_bytes(),
)
.unwrap();
bank.store_account(&publisher_config_key, &publisher_config_account);

let mut publisher_buffer_account =
AccountSharedData::new(42, buffer::size(100), &BATCH_PUBLISH_PID);
{
let (header, prices) = publisher_prices_account::create(
publisher1_prices_account.data_mut(),
publisher1_key.pubkey().to_bytes(),
let (header, prices) = buffer::create(
publisher_buffer_account.data_mut(),
publisher_key.pubkey().to_bytes(),
)
.unwrap();
publisher_prices_account::extend(header, prices, cast_slice(new_prices)).unwrap();
buffer::update(header, prices, bank.slot(), cast_slice(new_prices)).unwrap();
}
bank.store_account(&publisher1_prices_key, &publisher1_prices_account);
bank.store_account(&publisher_buffer_key, &publisher_buffer_account);

publisher1_key
publisher_key
};

let publishers = [
generate_publisher(
&[1u8; 32],
"seed1",
&[
PublisherPrice::new(1, 1, 10, 2).unwrap(),
PublisherPrice::new(2, 1, 20, 3).unwrap(),
BufferedPrice::new(1, 1, 10, 2).unwrap(),
BufferedPrice::new(2, 1, 20, 3).unwrap(),
// Attempt to publish with price_index == 0,
// but it will not be applied.
PublisherPrice {
BufferedPrice {
trading_status_and_feed_index: 0,
price: 30,
confidence: 35,
Expand All @@ -77,9 +99,10 @@ fn test_batch_publish() {
),
generate_publisher(
&[2u8; 32],
"seed2",
&[
PublisherPrice::new(1, 1, 15, 2).unwrap(),
PublisherPrice::new(2, 1, 25, 3).unwrap(),
BufferedPrice::new(1, 1, 15, 2).unwrap(),
BufferedPrice::new(2, 1, 25, 3).unwrap(),
],
),
];
Expand Down
Loading