|
| 1 | +use pyth_price_publisher::instruction::PUBLISHER_CONFIG_SEED; |
| 2 | +use solana_sdk::signer::Signer; |
| 3 | + |
1 | 4 | #[allow(deprecated)] |
2 | 5 | use crate::agent::legacy_schedule::LegacySchedule; |
3 | 6 | use { |
@@ -135,6 +138,7 @@ pub struct Data { |
135 | 138 | pub price_accounts: HashMap<Pubkey, PriceEntry>, |
136 | 139 | /// publisher => {their permissioned price accounts => price publishing metadata} |
137 | 140 | pub publisher_permissions: HashMap<Pubkey, HashMap<Pubkey, PricePublishingMetadata>>, |
| 141 | + pub publisher_buffer_key: Option<Pubkey>, |
138 | 142 | } |
139 | 143 |
|
140 | 144 | #[derive(Clone, Serialize, Deserialize, Debug)] |
@@ -193,6 +197,7 @@ pub trait Oracle { |
193 | 197 | network: Network, |
194 | 198 | mapping_key: Pubkey, |
195 | 199 | publish_keypair: Option<&Keypair>, |
| 200 | + publish_program_key: Option<Pubkey>, |
196 | 201 | rpc_client: &RpcClient, |
197 | 202 | max_lookup_batch_size: usize, |
198 | 203 | ) -> Result<()>; |
@@ -267,6 +272,7 @@ where |
267 | 272 | network: Network, |
268 | 273 | mapping_key: Pubkey, |
269 | 274 | publish_keypair: Option<&Keypair>, |
| 275 | + publish_program_key: Option<Pubkey>, |
270 | 276 | rpc_client: &RpcClient, |
271 | 277 | max_lookup_batch_size: usize, |
272 | 278 | ) -> Result<()> { |
@@ -311,22 +317,38 @@ where |
311 | 317 | } |
312 | 318 | } |
313 | 319 |
|
| 320 | + let mut publisher_buffer_key = None; |
| 321 | + if let (Some(publish_program_key), Some(publish_keypair)) = (publish_program_key, publish_keypair) { |
| 322 | + match fetch_publisher_buffer_key(rpc_client, publish_program_key, publish_keypair.pubkey()).await { |
| 323 | + Ok(r) => { |
| 324 | + publisher_buffer_key = Some(r); |
| 325 | + } |
| 326 | + Err(err) => { |
| 327 | + tracing::warn!( |
| 328 | + "failed to fetch publisher buffer key: {:?}", err |
| 329 | + ); |
| 330 | + } |
| 331 | + } |
| 332 | + } |
| 333 | + |
314 | 334 | let new_data = Data { |
315 | 335 | mapping_accounts, |
316 | 336 | product_accounts, |
317 | 337 | price_accounts, |
318 | 338 | publisher_permissions, |
| 339 | + publisher_buffer_key, |
319 | 340 | }; |
320 | 341 |
|
321 | 342 | let mut data = self.into().data.write().await; |
322 | 343 | log_data_diff(&data, &new_data); |
323 | 344 | *data = new_data; |
324 | 345 |
|
325 | | - Exporter::update_permissions( |
| 346 | + Exporter::update_on_chain_state( |
326 | 347 | self, |
327 | 348 | network, |
328 | 349 | publish_keypair, |
329 | 350 | data.publisher_permissions.clone(), |
| 351 | + data.publisher_buffer_key, |
330 | 352 | ) |
331 | 353 | .await?; |
332 | 354 |
|
@@ -367,6 +389,23 @@ where |
367 | 389 | } |
368 | 390 | } |
369 | 391 |
|
| 392 | +async fn fetch_publisher_buffer_key( |
| 393 | + rpc_client: &RpcClient, |
| 394 | + publish_program_key: Pubkey, |
| 395 | + publisher_pubkey: Pubkey, |
| 396 | +) -> Result<Pubkey> { |
| 397 | + let (publisher_config_key, _bump) = Pubkey::find_program_address( |
| 398 | + &[ |
| 399 | + PUBLISHER_CONFIG_SEED.as_bytes(), |
| 400 | + &publisher_pubkey.to_bytes(), |
| 401 | + ], |
| 402 | + &publish_program_key, |
| 403 | + ); |
| 404 | + let data = rpc_client.get_account_data(&publisher_config_key).await?; |
| 405 | + let config = pyth_price_publisher::accounts::publisher_config::read(&data)?; |
| 406 | + Ok(config.buffer_account.into()) |
| 407 | +} |
| 408 | + |
370 | 409 | #[instrument(skip(rpc_client))] |
371 | 410 | async fn fetch_mapping_accounts( |
372 | 411 | rpc_client: &RpcClient, |
|
0 commit comments