The Solana Shadow crate adds shadows to solana on-chain accounts for off-chain processing. This create synchronises all accounts and their data related to a program in real time and allows off-chain bots to act upon changes to those accounts.
Add this in your Cargo.toml
:
toml
[dependencies]
solana-shadow = "*"
Take a look at the examples/
directory for usage examples.
```rust // this is the prog id that owns all pyth oracles on mainnet let prog = "FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epH".parse()?; let network = Network::Mainnet; let local = BlockchainShadow::newforprogram(&prog, network).await?;
loop { local.foreachaccount(|pubkey, account| { println!(" - [{}]: {:?}", pubkey, account); });
sleep(Duration::from_secs(3)).await; } ```
```rust // https://pyth.network/developers/accounts/ let ethusd = "JBu1AL4obBcCMqKBBxhpWCNUt136ijcuMZLFvTP7iWdB".parse()?; let btcusd = "GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU".parse()?;
let local = BlockchainShadow::newforaccounts(&vec![ethusd, btcusd], Network::Mainnet).await?;
loop {
let ethacc = shadow.get_account(ðusd).unwrap();
let ethprice = cast::
let btcacc = shadow.get_account(&btcusd).unwrap();
let btcprice = cast::<Price>(&btcacc.data).agg.price;
println!("ETH/USD: {}", ethprice);
println!("BTC/USD: {}", btcprice);
sleep(Duration::from_secs(3)).await;
}
```