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

chore: rename pyth programs #143

Merged
merged 1 commit 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
4 changes: 2 additions & 2 deletions src/agent/services/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ mod exporter {
&network_state_rx,
key_store.accumulator_key,
&publish_keypair,
key_store.oracle_program_key,
key_store.publish_program_key,
key_store.pyth_oracle_program_key,
key_store.pyth_price_store_program_key,
publisher_buffer_key,
config.exporter.max_batch_size,
config.exporter.staleness_threshold,
Expand Down
8 changes: 4 additions & 4 deletions src/agent/services/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ where
state.clone(),
key_store.mapping_key,
key_store.publish_keypair,
key_store.publish_program_key,
key_store.pyth_price_store_program_key,
config.oracle.max_lookup_batch_size,
)));

Expand All @@ -74,7 +74,7 @@ where
config.clone(),
network,
state.clone(),
key_store.oracle_program_key,
key_store.pyth_oracle_program_key,
)
.await
{
Expand Down Expand Up @@ -160,7 +160,7 @@ async fn poller<S>(
state: Arc<S>,
mapping_key: Pubkey,
publish_keypair: Option<Keypair>,
publish_program_key: Option<Pubkey>,
pyth_price_store_program_key: Option<Pubkey>,
max_lookup_batch_size: usize,
) where
S: Oracle,
Expand All @@ -185,7 +185,7 @@ async fn poller<S>(
network,
mapping_key,
publish_keypair.as_ref(),
publish_program_key,
pyth_price_store_program_key,
&client,
max_lookup_batch_size,
)
Expand Down
28 changes: 14 additions & 14 deletions src/agent/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,49 +88,49 @@ pub mod key_store {
/// to a non-existent file path, the system expects a keypair
/// to be loaded via the remote keypair loader. If the path is
/// valid, the remote keypair loading is disabled.
pub publish_keypair_path: PathBuf,
pub publish_keypair_path: PathBuf,
/// The public key of the Oracle program
#[serde(
serialize_with = "pubkey_string_ser",
deserialize_with = "pubkey_string_de",
alias = "program_key" // for compatibility
)]
pub oracle_program_key: Pubkey,
/// The public key of the Publish program
pub pyth_oracle_program_key: Pubkey,
/// The public key of the pyth-price-store program
#[serde(
serialize_with = "opt_pubkey_string_ser",
deserialize_with = "opt_pubkey_string_de",
default
)]
pub publish_program_key: Option<Pubkey>,
pub pyth_price_store_program_key: Option<Pubkey>,
/// The public key of the root mapping account
#[serde(
serialize_with = "pubkey_string_ser",
deserialize_with = "pubkey_string_de"
)]
pub mapping_key: Pubkey,
pub mapping_key: Pubkey,
/// The public key of the accumulator program.
#[serde(
serialize_with = "opt_pubkey_string_ser",
deserialize_with = "opt_pubkey_string_de",
default
)]
pub accumulator_key: Option<Pubkey>,
pub accumulator_key: Option<Pubkey>,
}

pub struct KeyStore {
/// The keypair used to publish price updates. When None,
/// publishing will not start until a new keypair is supplied
/// via the remote loading endpoint
pub publish_keypair: Option<Keypair>,
pub publish_keypair: Option<Keypair>,
/// Public key of the Oracle program
pub oracle_program_key: Pubkey,
/// Public key of the Publish program
pub publish_program_key: Option<Pubkey>,
pub pyth_oracle_program_key: Pubkey,
/// Public key of the pyth-price-store program
pub pyth_price_store_program_key: Option<Pubkey>,
/// Public key of the root mapping account
pub mapping_key: Pubkey,
pub mapping_key: Pubkey,
/// Public key of the accumulator program (if provided)
pub accumulator_key: Option<Pubkey>,
pub accumulator_key: Option<Pubkey>,
}

impl KeyStore {
Expand All @@ -149,8 +149,8 @@ pub mod key_store {

Ok(KeyStore {
publish_keypair,
oracle_program_key: config.oracle_program_key,
publish_program_key: config.publish_program_key,
pyth_oracle_program_key: config.pyth_oracle_program_key,
pyth_price_store_program_key: config.pyth_price_store_program_key,
mapping_key: config.mapping_key,
accumulator_key: config.accumulator_key,
})
Expand Down
43 changes: 21 additions & 22 deletions src/agent/state/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ pub async fn publish_batches<S>(
network_state_rx: &watch::Receiver<NetworkState>,
accumulator_key: Option<Pubkey>,
publish_keypair: &Keypair,
oracle_program_key: Pubkey,
publish_program_key: Option<Pubkey>,
pyth_oracle_program_key: Pubkey,
pyth_price_store_program_key: Option<Pubkey>,
publisher_buffer_key: Option<Pubkey>,
max_batch_size: usize,
staleness_threshold: Duration,
Expand Down Expand Up @@ -502,8 +502,8 @@ where
network_state,
accumulator_key,
publish_keypair,
oracle_program_key,
publish_program_key,
pyth_oracle_program_key,
pyth_price_store_program_key,
publisher_buffer_key,
batch,
staleness_threshold,
Expand Down Expand Up @@ -547,8 +547,8 @@ async fn publish_batch<S>(
network_state: NetworkState,
accumulator_key: Option<Pubkey>,
publish_keypair: &Keypair,
oracle_program_key: Pubkey,
publish_program_key: Option<Pubkey>,
pyth_oracle_program_key: Pubkey,
pyth_price_store_program_key: Option<Pubkey>,
publisher_buffer_key: Option<Pubkey>,
batch: &[PermissionedUpdate],
staleness_threshold: Duration,
Expand Down Expand Up @@ -592,12 +592,11 @@ where
updates.push(update);
}

if let Some(publish_program_key) = publish_program_key {
let instruction = create_instruction_with_publish_program(
if let Some(pyth_price_store_program_key) = pyth_price_store_program_key {
let instruction = create_instruction_with_price_store_program(
publish_keypair.pubkey(),
publish_program_key,
publisher_buffer_key
.context("must specify publisher_buffer_key if publish_program_key is specified")?,
pyth_price_store_program_key,
publisher_buffer_key.context("failed to fetch publisher buffer key")?,
updates,
)?;
instructions.push(instruction);
Expand All @@ -606,7 +605,7 @@ where
let instruction = if let Some(accumulator_program_key) = accumulator_key {
create_instruction_with_accumulator(
publish_keypair.pubkey(),
oracle_program_key,
pyth_oracle_program_key,
Pubkey::from(update.feed_id.to_bytes()),
&update.info,
network_state.current_slot,
Expand All @@ -615,7 +614,7 @@ where
} else {
create_instruction_without_accumulator(
publish_keypair.pubkey(),
oracle_program_key,
pyth_oracle_program_key,
Pubkey::from(update.feed_id.to_bytes()),
&update.info,
network_state.current_slot,
Expand Down Expand Up @@ -775,13 +774,13 @@ where

fn create_instruction_without_accumulator(
publish_pubkey: Pubkey,
oracle_program_key: Pubkey,
pyth_oracle_program_key: Pubkey,
price_id: Pubkey,
price_info: &PriceInfo,
current_slot: u64,
) -> Result<Instruction> {
Ok(Instruction {
program_id: oracle_program_key,
program_id: pyth_oracle_program_key,
accounts: vec![
AccountMeta {
pubkey: publish_pubkey,
Expand Down Expand Up @@ -816,9 +815,9 @@ fn create_instruction_without_accumulator(
})
}

fn create_instruction_with_publish_program(
fn create_instruction_with_price_store_program(
publish_pubkey: Pubkey,
publish_program_key: Pubkey,
pyth_price_store_program_key: Pubkey,
publisher_buffer_key: Pubkey,
prices: Vec<PermissionedUpdate>,
) -> Result<Instruction> {
Expand All @@ -829,7 +828,7 @@ fn create_instruction_with_publish_program(
};
let (publisher_config_key, publisher_config_bump) = Pubkey::find_program_address(
&[PUBLISHER_CONFIG_SEED.as_bytes(), &publish_pubkey.to_bytes()],
&publish_program_key,
&pyth_price_store_program_key,
);

let mut values = Vec::new();
Expand All @@ -851,7 +850,7 @@ fn create_instruction_with_publish_program(
data.extend(cast_slice(&values));

let instruction = Instruction {
program_id: publish_program_key,
program_id: pyth_price_store_program_key,
accounts: vec![
AccountMeta {
pubkey: publish_pubkey,
Expand All @@ -876,7 +875,7 @@ fn create_instruction_with_publish_program(

fn create_instruction_with_accumulator(
publish_pubkey: Pubkey,
oracle_program_key: Pubkey,
pyth_oracle_program_key: Pubkey,
price_id: Pubkey,
price_info: &PriceInfo,
current_slot: u64,
Expand All @@ -889,7 +888,7 @@ fn create_instruction_with_accumulator(

let (oracle_auth_pda, _) = Pubkey::find_program_address(
&[b"upd_price_write", &accumulator_program_key.to_bytes()],
&oracle_program_key,
&pyth_oracle_program_key,
);

let (accumulator_data_pubkey, _accumulator_data_pubkey) = Pubkey::find_program_address(
Expand All @@ -902,7 +901,7 @@ fn create_instruction_with_accumulator(
);

Ok(Instruction {
program_id: oracle_program_key,
program_id: pyth_oracle_program_key,
accounts: vec![
AccountMeta {
pubkey: publish_pubkey,
Expand Down
14 changes: 7 additions & 7 deletions src/agent/state/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub trait Oracle {
network: Network,
mapping_key: Pubkey,
publish_keypair: Option<&Keypair>,
publish_program_key: Option<Pubkey>,
pyth_price_store_program_key: Option<Pubkey>,
rpc_client: &RpcClient,
max_lookup_batch_size: usize,
) -> Result<()>;
Expand Down Expand Up @@ -271,7 +271,7 @@ where
network: Network,
mapping_key: Pubkey,
publish_keypair: Option<&Keypair>,
publish_program_key: Option<Pubkey>,
pyth_price_store_program_key: Option<Pubkey>,
rpc_client: &RpcClient,
max_lookup_batch_size: usize,
) -> Result<()> {
Expand Down Expand Up @@ -317,12 +317,12 @@ where
}

let mut publisher_buffer_key = None;
if let (Some(publish_program_key), Some(publish_keypair)) =
(publish_program_key, publish_keypair)
if let (Some(pyth_price_store_program_key), Some(publish_keypair)) =
(pyth_price_store_program_key, publish_keypair)
{
match fetch_publisher_buffer_key(
rpc_client,
publish_program_key,
pyth_price_store_program_key,
publish_keypair.pubkey(),
)
.await
Expand Down Expand Up @@ -396,15 +396,15 @@ where

async fn fetch_publisher_buffer_key(
rpc_client: &RpcClient,
publish_program_key: Pubkey,
pyth_price_store_program_key: Pubkey,
publisher_pubkey: Pubkey,
) -> Result<Pubkey> {
let (publisher_config_key, _bump) = Pubkey::find_program_address(
&[
PUBLISHER_CONFIG_SEED.as_bytes(),
&publisher_pubkey.to_bytes(),
],
&publish_program_key,
&pyth_price_store_program_key,
);
let data = rpc_client.get_account_data(&publisher_config_key).await?;
let config = pyth_price_store::accounts::publisher_config::read(&data)?;
Expand Down
Loading