1use af_move_type::MoveInstance;
2use af_sui_types::{Address, ObjectId, Version};
3use futures::Stream;
4use sui_gql_client::GraphQlClient;
5pub use sui_gql_client::queries::Error;
6
7use crate::Vault;
8use crate::orderbook::Order;
9use crate::position::Position;
10
11mod ch_orders;
12mod ch_positions;
13mod ch_vault;
14mod map_orders;
15mod order_maps;
16mod registry;
17
18pub use self::ch_vault::Error as ChVaultError;
19pub use self::order_maps::OrderMaps;
20
21type StdResult<T, E> = ::std::result::Result<T, E>;
22type Result<T, C> = StdResult<T, Error<<C as GraphQlClient>::Error>>;
23
24pub trait GraphQlClientExt: GraphQlClient + Sized {
26 fn clearing_house_orders(
36 &self,
37 package: Address,
38 ch: ObjectId,
39 version: Option<Version>,
40 asks: bool,
41 ) -> impl Stream<Item = Result<(u128, Order), Self>> + '_ {
42 ch_orders::query(self, package, ch, version, asks)
43 }
44
45 fn map_orders(
54 &self,
55 map: ObjectId,
56 ch_version: Option<Version>,
57 ) -> impl Stream<Item = Result<(u128, Order), Self>> + '_ {
58 map_orders::query(self, map, ch_version)
59 }
60
61 fn order_maps(
65 &self,
66 package: Address,
67 ch: ObjectId,
68 ) -> impl Future<Output = Result<OrderMaps, Self>> + Send + '_ {
69 order_maps::query(self, package, ch)
70 }
71
72 fn clearing_house_vault(
76 &self,
77 package: Address,
78 ch: ObjectId,
79 ) -> impl Future<Output = StdResult<MoveInstance<Vault>, ChVaultError<Self::Error>>> + Send + '_
80 {
81 ch_vault::query(self, package, ch)
82 }
83
84 fn clearing_house_positions(
88 &self,
89 ch: ObjectId,
90 version: Option<Version>,
91 ) -> impl Stream<Item = Result<(u64, MoveInstance<Position>), Self>> + '_ {
92 ch_positions::query(self, ch, version)
93 }
94
95 fn registered_clearing_houses(
97 &self,
98 registry_address: ObjectId,
99 version: Option<Version>,
100 ) -> impl Stream<Item = Result<ObjectId, Self>> + '_ {
101 self::registry::query(self, registry_address, version)
102 }
103}
104
105impl<T: GraphQlClient> GraphQlClientExt for T {}