Solana Shadow
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.
Usage
Add this in your Cargo.toml
:
[]
= "*"
Take a look at the examples/
directory for usage examples.
Mirroring a program id and all its owned accounts:
// this is the prog id that owns all pyth oracles on mainnet
let prog = "FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epH".parse?;
let network = Mainnet;
let local = new_for_program.await?;
loop
local.worker.await?;
Mirroring few random accounts
// https://pyth.network/developers/accounts/
let ethusd = "JBu1AL4obBcCMqKBBxhpWCNUt136ijcuMZLFvTP7iWdB".parse?;
let btcusd = "GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU".parse?;
let local = new_for_accounts.await?;
loop
local.worker.await?;
Listening on changes to accounts:
// https://pyth.network/developers/accounts/
let ethusd = "JBu1AL4obBcCMqKBBxhpWCNUt136ijcuMZLFvTP7iWdB".parse?;
let btcusd = "GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU".parse?;
let solusd = "H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG".parse?;
// create an offline shadow of the on-chain data.
// whenever the data change on-chain those changes
// will be reflected immediately in this type.
let shadow = new_for_accounts
.await?;
spawn;
shadow.worker.await?;