carbon-orca-whirlpool-decoder 1.0.0

Orca Whirlpool Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {carbon_core::graphql::primitives::U32, juniper::GraphQLObject, serde_json};

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "SetAdaptiveFeeConstants")]
pub struct SetAdaptiveFeeConstantsGraphQL {
    pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
    pub filter_period: Option<i32>,
    pub decay_period: Option<i32>,
    pub reduction_factor: Option<i32>,
    pub adaptive_fee_control_factor: Option<U32>,
    pub max_volatility_accumulator: Option<U32>,
    pub tick_group_size: Option<i32>,
    pub major_swap_threshold_ticks: Option<i32>,
    pub accounts: carbon_core::graphql::primitives::Json,
}

impl TryFrom<crate::instructions::postgres::SetAdaptiveFeeConstantsRow>
    for SetAdaptiveFeeConstantsGraphQL
{
    type Error = carbon_core::error::Error;
    fn try_from(
        row: crate::instructions::postgres::SetAdaptiveFeeConstantsRow,
    ) -> Result<Self, Self::Error> {
        Ok(Self {
            instruction_metadata: row.instruction_metadata.into(),
            filter_period: row.filter_period.map(|v| *v),
            decay_period: row.decay_period.map(|v| *v),
            reduction_factor: row.reduction_factor.map(|v| *v),
            adaptive_fee_control_factor: row
                .adaptive_fee_control_factor
                .map(|v| carbon_core::graphql::primitives::U32((*v) as u32)),
            max_volatility_accumulator: row
                .max_volatility_accumulator
                .map(|v| carbon_core::graphql::primitives::U32((*v) as u32)),
            tick_group_size: row.tick_group_size.map(|v| *v),
            major_swap_threshold_ticks: row.major_swap_threshold_ticks.map(|v| *v),
            accounts: carbon_core::graphql::primitives::Json(
                serde_json::to_value(&row.accounts.0)
                    .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
            ),
        })
    }
}