MCPcopy Create free account
hub / github.com/clockwork-xyz/examples / create_feed

Function create_feed

pyth_feed/client/src/main.rs:31–70  ·  view source on GitHub ↗
(client: &Client)

Source from the content-addressed store, hash-verified

29}
30
31fn create_feed(client: &Client) -> ClientResult<()> {
32 let feed_pubkey = pyth_feed::state::Feed::pubkey(client.payer_pubkey());
33 let feed_thread_pubkey = Thread::pubkey(feed_pubkey, "feed".into());
34
35 // SOL/USD price feed: https://pyth.network/price-feeds/crypto-sol-usd?cluster=mainnet-beta
36 // copied account to test validator using https://book.anchor-lang.com/anchor_references/anchor-toml_reference.html#testvalidatorclone
37 #[cfg(feature = "localnet")]
38 let sol_usd_pubkey = Pubkey::from_str("H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG").unwrap();
39 #[cfg(not(feature = "localnet"))] // for devnet
40 let sol_usd_pubkey = Pubkey::from_str("J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix").unwrap();
41
42 println!(
43 "thread: 🔗 {}",
44 explorer().thread_url(feed_thread_pubkey, thread_program_ID)
45 );
46
47 // airdrop thread
48 std::thread::sleep(std::time::Duration::from_secs(1));
49 client.airdrop(&feed_thread_pubkey, 1 * LAMPORTS_PER_SOL)?;
50
51 let create_feed_ix = Instruction {
52 program_id: pyth_feed::ID,
53 accounts: vec![
54 AccountMeta::new_readonly(thread_program_ID, false),
55 AccountMeta::new(feed_pubkey, false),
56 AccountMeta::new(feed_thread_pubkey, false),
57 AccountMeta::new_readonly(sol_usd_pubkey, false),
58 AccountMeta::new(client.payer_pubkey(), true),
59 AccountMeta::new_readonly(system_program::ID, false),
60 ],
61 data: pyth_feed::instruction::CreateFeed {}.data(),
62 };
63 sign_send_and_confirm_tx(
64 &client,
65 [create_feed_ix].to_vec(),
66 None,
67 "create_feed".into(),
68 )?;
69 Ok(())
70}
71
72pub fn sign_send_and_confirm_tx(
73 client: &Client,

Callers 1

mainFunction · 0.70

Calls 2

sleepFunction · 0.85
sign_send_and_confirm_txFunction · 0.70

Tested by

no test coverage detected