use {
carbon_core::graphql::primitives::{I64, U64, U8},
juniper::GraphQLObject,
serde_json,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "InitializeConstituent")]
pub struct InitializeConstituentGraphQL {
pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
pub spot_market_index: i32,
pub decimals: U8,
pub max_weight_deviation: I64,
pub swap_fee_min: I64,
pub swap_fee_max: I64,
pub max_borrow_token_amount: U64,
pub oracle_staleness_threshold: U64,
pub cost_to_trade: i32,
pub constituent_derivative_index: Option<i32>,
pub constituent_derivative_depeg_threshold: U64,
pub derivative_weight: U64,
pub volatility: U64,
pub gamma_execution: U8,
pub gamma_inventory: U8,
pub xi: U8,
pub new_constituent_correlations: Vec<I64>,
pub accounts: carbon_core::graphql::primitives::Json,
}
impl TryFrom<crate::instructions::postgres::InitializeConstituentRow>
for InitializeConstituentGraphQL
{
type Error = carbon_core::error::Error;
fn try_from(
row: crate::instructions::postgres::InitializeConstituentRow,
) -> Result<Self, Self::Error> {
Ok(Self {
instruction_metadata: row.instruction_metadata.into(),
spot_market_index: *row.spot_market_index,
decimals: carbon_core::graphql::primitives::U8((*row.decimals) as u8),
max_weight_deviation: carbon_core::graphql::primitives::I64(row.max_weight_deviation),
swap_fee_min: carbon_core::graphql::primitives::I64(row.swap_fee_min),
swap_fee_max: carbon_core::graphql::primitives::I64(row.swap_fee_max),
max_borrow_token_amount: carbon_core::graphql::primitives::U64(
*row.max_borrow_token_amount,
),
oracle_staleness_threshold: carbon_core::graphql::primitives::U64(
*row.oracle_staleness_threshold,
),
cost_to_trade: row.cost_to_trade,
constituent_derivative_index: row.constituent_derivative_index.map(|v| v as i32),
constituent_derivative_depeg_threshold: carbon_core::graphql::primitives::U64(
*row.constituent_derivative_depeg_threshold,
),
derivative_weight: carbon_core::graphql::primitives::U64(*row.derivative_weight),
volatility: carbon_core::graphql::primitives::U64(*row.volatility),
gamma_execution: carbon_core::graphql::primitives::U8((*row.gamma_execution) as u8),
gamma_inventory: carbon_core::graphql::primitives::U8((*row.gamma_inventory) as u8),
xi: carbon_core::graphql::primitives::U8((*row.xi) as u8),
new_constituent_correlations: row
.new_constituent_correlations
.into_iter()
.map(carbon_core::graphql::primitives::I64)
.collect(),
accounts: carbon_core::graphql::primitives::Json(
serde_json::to_value(&row.accounts.0)
.map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
),
})
}
}