gmsol_sdk/market/
caluclator.rs1use gmsol_model::price::{Price, Prices};
2use gmsol_programs::{gmsol_store::types::MarketMeta, model::MarketModel};
3use solana_sdk::pubkey::Pubkey;
4
5pub trait MarketCalculator {
7 fn get_token_prices_for_market_meta(&self, meta: &MarketMeta) -> Option<Prices<u128>> {
9 let index_token_price = self.get_token_price(&meta.index_token_mint)?;
10 let long_token_price = self.get_token_price(&meta.long_token_mint)?;
11 let short_token_price = self.get_token_price(&meta.short_token_mint)?;
12 Some(Prices {
13 index_token_price,
14 long_token_price,
15 short_token_price,
16 })
17 }
18
19 fn get_market_model_with_prices(
21 &self,
22 market_token: &Pubkey,
23 ) -> crate::Result<(&MarketModel, Prices<u128>)> {
24 let market = self
25 .get_market_model(market_token)
26 .ok_or_else(|| crate::Error::NotFound)?;
27 let meta = &market.meta;
28 let prices = self
29 .get_token_prices_for_market_meta(meta)
30 .ok_or_else(|| crate::Error::NotFound)?;
31 Ok((market, prices))
32 }
33
34 fn get_market_model(&self, market_token: &Pubkey) -> Option<&MarketModel>;
36
37 fn get_token_price(&self, token: &Pubkey) -> Option<Price<u128>>;
39}