use {
crate::types::graphql::{NonZeroPubkeyOptionGraphQL, OracleConfigGraphQL},
carbon_core::graphql::primitives::{Pubkey, I64, U128, U64, U8},
juniper::GraphQLObject,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "Market")]
pub struct MarketGraphQL {
pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
pub bump: U8,
pub base_decimals: U8,
pub quote_decimals: U8,
pub padding1: Vec<U8>,
pub market_authority: Pubkey,
pub time_expiry: I64,
pub collect_fee_admin: Pubkey,
pub open_orders_admin: NonZeroPubkeyOptionGraphQL,
pub consume_events_admin: NonZeroPubkeyOptionGraphQL,
pub close_market_admin: NonZeroPubkeyOptionGraphQL,
pub name: Vec<U8>,
pub bids: Pubkey,
pub asks: Pubkey,
pub event_heap: Pubkey,
pub oracle_a: NonZeroPubkeyOptionGraphQL,
pub oracle_b: NonZeroPubkeyOptionGraphQL,
pub oracle_config: OracleConfigGraphQL,
pub quote_lot_size: I64,
pub base_lot_size: I64,
pub seq_num: U64,
pub registration_time: I64,
pub maker_fee: I64,
pub taker_fee: I64,
pub fees_accrued: U128,
pub fees_to_referrers: U128,
pub referrer_rebates_accrued: U64,
pub fees_available: U64,
pub maker_volume: U128,
pub taker_volume_wo_oo: U128,
pub base_mint: Pubkey,
pub quote_mint: Pubkey,
pub market_base_vault: Pubkey,
pub base_deposit_total: U64,
pub market_quote_vault: Pubkey,
pub quote_deposit_total: U64,
pub reserved: Vec<U8>,
}
impl TryFrom<crate::accounts::postgres::MarketRow> for MarketGraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::accounts::postgres::MarketRow) -> Result<Self, Self::Error> {
Ok(Self {
account_metadata: row.account_metadata.into(),
bump: carbon_core::graphql::primitives::U8((*row.bump) as u8),
base_decimals: carbon_core::graphql::primitives::U8((*row.base_decimals) as u8),
quote_decimals: carbon_core::graphql::primitives::U8((*row.quote_decimals) as u8),
padding1: row
.padding1
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
market_authority: carbon_core::graphql::primitives::Pubkey(row.market_authority.0),
time_expiry: carbon_core::graphql::primitives::I64(row.time_expiry),
collect_fee_admin: carbon_core::graphql::primitives::Pubkey(row.collect_fee_admin.0),
open_orders_admin: row.open_orders_admin.0.into(),
consume_events_admin: row.consume_events_admin.0.into(),
close_market_admin: row.close_market_admin.0.into(),
name: row
.name
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
bids: carbon_core::graphql::primitives::Pubkey(row.bids.0),
asks: carbon_core::graphql::primitives::Pubkey(row.asks.0),
event_heap: carbon_core::graphql::primitives::Pubkey(row.event_heap.0),
oracle_a: row.oracle_a.0.into(),
oracle_b: row.oracle_b.0.into(),
oracle_config: row.oracle_config.0.into(),
quote_lot_size: carbon_core::graphql::primitives::I64(row.quote_lot_size),
base_lot_size: carbon_core::graphql::primitives::I64(row.base_lot_size),
seq_num: carbon_core::graphql::primitives::U64(*row.seq_num),
registration_time: carbon_core::graphql::primitives::I64(row.registration_time),
maker_fee: carbon_core::graphql::primitives::I64(row.maker_fee),
taker_fee: carbon_core::graphql::primitives::I64(row.taker_fee),
fees_accrued: carbon_core::graphql::primitives::U128(*row.fees_accrued),
fees_to_referrers: carbon_core::graphql::primitives::U128(*row.fees_to_referrers),
referrer_rebates_accrued: carbon_core::graphql::primitives::U64(
*row.referrer_rebates_accrued,
),
fees_available: carbon_core::graphql::primitives::U64(*row.fees_available),
maker_volume: carbon_core::graphql::primitives::U128(*row.maker_volume),
taker_volume_wo_oo: carbon_core::graphql::primitives::U128(*row.taker_volume_wo_oo),
base_mint: carbon_core::graphql::primitives::Pubkey(row.base_mint.0),
quote_mint: carbon_core::graphql::primitives::Pubkey(row.quote_mint.0),
market_base_vault: carbon_core::graphql::primitives::Pubkey(row.market_base_vault.0),
base_deposit_total: carbon_core::graphql::primitives::U64(*row.base_deposit_total),
market_quote_vault: carbon_core::graphql::primitives::Pubkey(row.market_quote_vault.0),
quote_deposit_total: carbon_core::graphql::primitives::U64(*row.quote_deposit_total),
reserved: row
.reserved
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
})
}
}