af_oracle/graphql/
mod.rs

1use af_move_type::MoveInstance;
2use af_sui_types::{Address, ObjectId, Version};
3use futures::Stream;
4use sui_gql_client::GraphQlClient;
5use sui_gql_client::queries::Error;
6
7pub use crate::graphql::price_feed_for_source::Error as PfForSourceError;
8use crate::oracle::PriceFeed;
9
10pub(crate) mod price_feed_for_source;
11pub(crate) mod price_feeds;
12
13/// Extension trait to [`GraphQlClient`] collecting all defined queries in one place.
14pub trait GraphQlClientExt: GraphQlClient + Sized {
15    /// Snapshot of price feeds under the [`PriceFeedStorage`].
16    /// Returns tuples representing (`source_wrapper_id`, `price_feed`)
17    ///
18    /// [`PriceFeedStorage`]: crate::oracle::PriceFeedStorage
19    fn price_feeds(
20        &self,
21        pfs: ObjectId,
22        version: Option<Version>,
23    ) -> impl Stream<Item = Result<(ObjectId, MoveInstance<PriceFeed>), Error<Self::Error>>> + '_
24    {
25        price_feeds::query(self, pfs, version)
26    }
27
28    /// Get a price feed under the [`PriceFeedStorage`], given a specific `source_wrapper_id`.
29    ///
30    /// [`PriceFeedStorage`]: crate::oracle::PriceFeedStorage
31    fn price_feed_for_source(
32        &self,
33        af_oracle_pkg: Address,
34        pfs: ObjectId,
35        source_wrapper_id: ObjectId,
36    ) -> impl Future<Output = Result<Option<MoveInstance<PriceFeed>>, PfForSourceError<Self::Error>>>
37    + Send {
38        price_feed_for_source::query(self, af_oracle_pkg, pfs, source_wrapper_id)
39    }
40}
41
42impl<T: GraphQlClient> GraphQlClientExt for T {}