use {
crate::types::graphql::{
AssetGraphQL, ExpirySeriesGraphQL, HaltStateGraphQL, MarginParametersGraphQL,
PerpParametersGraphQL, PricingParametersGraphQL, ProductGraphQL,
},
carbon_core::graphql::primitives::{Pubkey, U32, U8},
juniper::GraphQLObject,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "ZetaGroup")]
pub struct ZetaGroupGraphQL {
pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
pub nonce: U8,
pub nonce_padding: Vec<U8>,
pub front_expiry_index: U8,
pub halt_state: HaltStateGraphQL,
pub underlying_mint: Pubkey,
pub oracle: Pubkey,
pub greeks: Pubkey,
pub pricing_parameters: PricingParametersGraphQL,
pub margin_parameters: MarginParametersGraphQL,
pub margin_parameters_padding: Vec<U8>,
pub products: Vec<ProductGraphQL>,
pub products_padding: Vec<ProductGraphQL>,
pub perp: ProductGraphQL,
pub expiry_series: Vec<ExpirySeriesGraphQL>,
pub expiry_series_padding: Vec<ExpirySeriesGraphQL>,
pub deprecated_padding: Vec<U8>,
pub asset: AssetGraphQL,
pub expiry_interval_seconds: U32,
pub new_expiry_threshold_seconds: U32,
pub perp_parameters: PerpParametersGraphQL,
pub perp_sync_queue: Pubkey,
pub oracle_backup_feed: Pubkey,
pub perps_only: bool,
pub flex_underlying: bool,
pub padding: Vec<U8>,
}
impl TryFrom<crate::accounts::postgres::ZetaGroupRow> for ZetaGroupGraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::accounts::postgres::ZetaGroupRow) -> Result<Self, Self::Error> {
Ok(Self {
account_metadata: row.account_metadata.into(),
nonce: carbon_core::graphql::primitives::U8((*row.nonce) as u8),
nonce_padding: row
.nonce_padding
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
front_expiry_index: carbon_core::graphql::primitives::U8(
(*row.front_expiry_index) as u8,
),
halt_state: row.halt_state.0.into(),
underlying_mint: carbon_core::graphql::primitives::Pubkey(row.underlying_mint.0),
oracle: carbon_core::graphql::primitives::Pubkey(row.oracle.0),
greeks: carbon_core::graphql::primitives::Pubkey(row.greeks.0),
pricing_parameters: row.pricing_parameters.0.into(),
margin_parameters: row.margin_parameters.0.into(),
margin_parameters_padding: row
.margin_parameters_padding
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
products: row.products.0.into_iter().map(|item| item.into()).collect(),
products_padding: row
.products_padding
.0
.into_iter()
.map(|item| item.into())
.collect(),
perp: row.perp.0.into(),
expiry_series: row
.expiry_series
.0
.into_iter()
.map(|item| item.into())
.collect(),
expiry_series_padding: row
.expiry_series_padding
.0
.into_iter()
.map(|item| item.into())
.collect(),
deprecated_padding: row
.deprecated_padding
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
asset: row.asset.0.into(),
expiry_interval_seconds: carbon_core::graphql::primitives::U32(
(*row.expiry_interval_seconds) as u32,
),
new_expiry_threshold_seconds: carbon_core::graphql::primitives::U32(
(*row.new_expiry_threshold_seconds) as u32,
),
perp_parameters: row.perp_parameters.0.into(),
perp_sync_queue: carbon_core::graphql::primitives::Pubkey(row.perp_sync_queue.0),
oracle_backup_feed: carbon_core::graphql::primitives::Pubkey(row.oracle_backup_feed.0),
perps_only: row.perps_only,
flex_underlying: row.flex_underlying,
padding: row
.padding
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
})
}
}