Skip to content
Closed
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
6 changes: 6 additions & 0 deletions contracts/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ contract-reader-interface-secondary = "9SFyk8NmGYh5D612mJwUYhguCRY9cFgaS2vksrige
dummy_receiver = "5z38tFCAmcPJb1DXUHSoKQhR8qQ8o9aNZ8rZFWe6gH4L"
keystone_forwarder = "whV7Q5pi17hPPyaPksToDw1nMx6Lh8qmNWKFaLRQ4wz"
data_feeds_cache = "3kX63udXtYcsdj2737Wi2KGd2PhqiKPgAFAxstrjtRUa"
data_feeds_store = "9qCsUGTdKCanybkroJuPzAhuRU8P2SZN4NCexevSZAwu"
log-read-test = "J1zQwrBNBngz26jRPNWsUSZMHJwBwpkoDitXRV95LdK4"
mock-ccip-events = "CGn5MQX5GK9qKqERhjnADhd6i2LiSF6XUC2ewUHND1Mw"
mock_forwarder = "7kuEAA3mSC1Tz8gQjnvH7bKFda9xSPRRin9SZbH49cNK"
Expand All @@ -31,3 +32,8 @@ wallet = "id.json"

[scripts]
test = "pnpm run test"

[test]
# Workspace programs are upgradeable by the provider wallet: store and proxy initialize require
# the program's upgrade authority.
upgradeable = true
19 changes: 19 additions & 0 deletions contracts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"programs/*",
"crates/arrayvec",
"crates/chainlink-solana-data-feeds-cache",
"crates/chainlink-solana-data-feeds-store",
# Exclude crates/chainlink-solana-data-streams: it uses solana-sdk 1.17 which
# pulls zeroize <1.4, conflicting with anchor-spl 0.31 (zeroize ^1.7).
# Not used by any program; only for off-chain/tests (cfg(not(target_os = "solana"))).
Expand Down
20 changes: 20 additions & 0 deletions contracts/crates/chainlink-solana-data-feeds-store/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "chainlink_solana_data_feeds_store"
description = "CPI accessors for the Chainlink Data Feeds store on Solana"
version = "0.0.1"
edition = "2021"
license = "MIT"

[lib]
crate-type = ["cdylib", "lib"]
name = "chainlink_solana_data_feeds_store"

[features]
default = []

[dependencies]
anchor-lang = "0.31.0"
data-feeds-store = { path = "../../programs/data-feeds-store", features = ["cpi"] }

[lints]
workspace = true
82 changes: 82 additions & 0 deletions contracts/crates/chainlink-solana-data-feeds-store/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//! CPI client for the reader interface of the Chainlink Data Feeds store: the latest or a stored
//! round of a data ID (answer with 18 decimals), the latest rounds of several data IDs, the stored
//! decimals and the feed description.
//!
//! Proxies read through this interface, so a store version that keeps it can replace the store
//! behind a proxy. Reads that need other decimals go through the data feeds proxy, not here.

use anchor_lang::prelude::*;
use data_feeds_store::cpi::accounts::{DescriptionRead, FeedRead, FeedsRead};

pub use data_feeds_store::state::ReaderRound;
pub use data_feeds_store::ID as DATA_FEEDS_STORE_ID;

/// Latest round of a data ID. Fails with the store's `NoDataPresent` while the feed has no report.
pub fn get_latest_round<'info>(
store_program: AccountInfo<'info>,
state: AccountInfo<'info>,
feed: AccountInfo<'info>,
data_id: [u8; 16],
) -> Result<ReaderRound> {
let ctx = CpiContext::new(store_program, FeedRead { state, feed });
Ok(data_feeds_store::cpi::get_latest_round(ctx, data_id)?.get())
}

/// Latest rounds of up to 31 data IDs, `feeds` in the same order. A feed without a report yields
/// a zero round (round ID 0).
pub fn get_latest_rounds<'info>(
store_program: AccountInfo<'info>,
state: AccountInfo<'info>,
feeds: Vec<AccountInfo<'info>>,
data_ids: Vec<[u8; 16]>,
) -> Result<Vec<ReaderRound>> {
let ctx = CpiContext::new(store_program, FeedsRead { state }).with_remaining_accounts(feeds);
Ok(data_feeds_store::cpi::get_latest_rounds(ctx, data_ids)?.get())
}

/// A stored round of a data ID. Fails with the store's `NoDataPresent` for a round that was never
/// written or has been overwritten.
pub fn get_round<'info>(
store_program: AccountInfo<'info>,
state: AccountInfo<'info>,
feed: AccountInfo<'info>,
data_id: [u8; 16],
round_id: u64,
) -> Result<ReaderRound> {
let ctx = CpiContext::new(store_program, FeedRead { state, feed });
Ok(data_feeds_store::cpi::get_round(ctx, data_id, round_id)?.get())
}

/// Decimals the store keeps answers with.
pub fn get_decimals<'info>(
store_program: AccountInfo<'info>,
state: AccountInfo<'info>,
data_id: [u8; 16],
) -> Result<u8> {
let ctx = CpiContext::new(
store_program,
DescriptionRead {
state,
feed_description: None,
},
);
Ok(data_feeds_store::cpi::get_decimals(ctx, data_id)?.get())
}

/// Description of the feed of a data ID, empty when none is set. Pass the feed description
/// account to get it.
pub fn get_description<'info>(
store_program: AccountInfo<'info>,
state: AccountInfo<'info>,
feed_description: Option<AccountInfo<'info>>,
data_id: [u8; 16],
) -> Result<String> {
let ctx = CpiContext::new(
store_program,
DescriptionRead {
state,
feed_description,
},
);
Ok(data_feeds_store::cpi::get_description(ctx, data_id)?.get())
}
93 changes: 93 additions & 0 deletions contracts/generated/data_feeds_store/accounts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions contracts/generated/data_feeds_store/constants.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions contracts/generated/data_feeds_store/discriminators.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions contracts/generated/data_feeds_store/errors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading