From 0b00030167866d97b4ea4b4a9aec2e43a5df0682 Mon Sep 17 00:00:00 2001 From: thesn10 <38666407+thesn10@users.noreply.github.com> Date: Mon, 25 May 2026 21:24:46 +0200 Subject: [PATCH] use correct sdk --- .../superpowers/plans/2026-05-19-solisting.md | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/docs/superpowers/plans/2026-05-19-solisting.md b/docs/superpowers/plans/2026-05-19-solisting.md index 8ede77d..ab64699 100644 --- a/docs/superpowers/plans/2026-05-19-solisting.md +++ b/docs/superpowers/plans/2026-05-19-solisting.md @@ -25,7 +25,7 @@ - `max_slippage_bps` argument on `create_order` protects buyer from price movement between submission and confirmation - SPL token path (`descro_spl` CPI) is not yet implemented — `create_order` errors on `payment_currency = Spl` until `descro_spl` exists; state and oracle are designed to support it without schema changes -**Tech Stack:** Rust, Anchor 1.0.x, LiteSVM 0.10.0, `pyth-sdk-solana` for oracle reads. Build order: `descro_ext_resolvers` → `descro` → `solisting`. +**Tech Stack:** Rust, Anchor 1.0.x, LiteSVM 0.10.0, `pyth-solana-receiver-sdk` for oracle reads. Build order: `descro_ext_resolvers` → `descro` → `solisting`. --- @@ -33,7 +33,7 @@ | Action | Path | Responsibility | |---|---|---| -| Create | `programs/solisting/Cargo.toml` | Crate definition + dependencies (incl. pyth-sdk-solana) | +| Create | `programs/solisting/Cargo.toml` | Crate definition + dependencies (incl. pyth-solana-receiver-sdk) | | Create | `programs/solisting/src/lib.rs` | Program entrypoints + declare_id! | | Create | `programs/solisting/src/state.rs` | `ListingAccount`, `OrderAccount`, `Currency` enum | | Create | `programs/solisting/src/error.rs` | `SolistingError` enum | @@ -87,9 +87,9 @@ custom-panic = [] anchor-lang = "1.0.2" descro = { path = "../descro", features = ["cpi"] } descro_ext_resolvers = { path = "../descro_ext_resolvers" } -# Pyth oracle SDK for on-chain price reads. -# Verify latest compatible version at https://crates.io/crates/pyth-sdk-solana -pyth-sdk-solana = "0.10" +# Pyth oracle SDK for on-chain price reads (Pull Oracle / V2 accounts). +# Verify latest compatible version at https://crates.io/crates/pyth-solana-receiver-sdk +pyth-solana-receiver-sdk = "0.3" [dev-dependencies] litesvm = "0.10.0" @@ -239,24 +239,31 @@ no second feed needed for the stable side. ```rust use anchor_lang::prelude::*; -use pyth_sdk_solana::load_price_feed_from_account_info; +use anchor_lang::AccountDeserialize; +use pyth_solana_receiver_sdk::price_update::{PriceUpdateV2, get_feed_id_from_hex}; use crate::error::SolistingError; use crate::state::Currency; /// Maximum age of the oracle price in seconds before it is considered stale. const ORACLE_MAX_AGE_SECS: u64 = 60; +/// Pyth SOL/USD price feed ID (mainnet + devnet). +const SOL_USD_FEED_ID: &str = "ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d"; + /// Reads the Pyth SOL/USD price feed and returns (price_i64, exponent_i32). /// price_i64 * 10^exponent = USD per SOL. /// Returns OraclePriceUnavailable if the price is stale or the feed account is invalid. fn sol_usd_price(oracle_account: &AccountInfo) -> Result<(i64, i32)> { - let feed = load_price_feed_from_account_info(oracle_account) + let data = oracle_account.try_borrow_data()?; + let price_update = PriceUpdateV2::try_deserialize(&mut data.as_ref()) .map_err(|_| error!(SolistingError::OraclePriceUnavailable))?; - let now = Clock::get()?.unix_timestamp; - let price = feed - .get_price_no_older_than(now, ORACLE_MAX_AGE_SECS) - .ok_or(error!(SolistingError::OraclePriceUnavailable))?; - Ok((price.price, price.expo)) + let clock = Clock::get()?; + let feed_id = get_feed_id_from_hex(SOL_USD_FEED_ID) + .map_err(|_| error!(SolistingError::OraclePriceUnavailable))?; + let price = price_update + .get_price_no_older_than(&clock, ORACLE_MAX_AGE_SECS, &feed_id) + .map_err(|_| error!(SolistingError::OraclePriceUnavailable))?; + Ok((price.price, price.exponent)) } /// Converts `canonical_amount` (in `canonical_currency`) to `target_currency` units.