carbon-jupiter-dca-decoder 2.0.0

Jupiter DCA Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    carbon_core::graphql::primitives::{I64, U64},
    juniper::GraphQLObject,
    serde_json,
};

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "OpenDca")]
pub struct OpenDcaGraphQL {
    pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
    pub application_idx: U64,
    pub in_amount: U64,
    pub in_amount_per_cycle: U64,
    pub cycle_frequency: I64,
    pub min_out_amount: Option<U64>,
    pub max_out_amount: Option<U64>,
    pub start_at: Option<I64>,
    pub close_wsol_in_ata: Option<bool>,
    pub accounts: carbon_core::graphql::primitives::Json,
}

impl TryFrom<crate::instructions::postgres::OpenDcaRow> for OpenDcaGraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::instructions::postgres::OpenDcaRow) -> Result<Self, Self::Error> {
        Ok(Self {
            instruction_metadata: row.instruction_metadata.into(),
            application_idx: carbon_core::graphql::primitives::U64(*row.application_idx),
            in_amount: carbon_core::graphql::primitives::U64(*row.in_amount),
            in_amount_per_cycle: carbon_core::graphql::primitives::U64(*row.in_amount_per_cycle),
            cycle_frequency: carbon_core::graphql::primitives::I64(row.cycle_frequency),
            min_out_amount: row
                .min_out_amount
                .map(|v| carbon_core::graphql::primitives::U64(*v)),
            max_out_amount: row
                .max_out_amount
                .map(|v| carbon_core::graphql::primitives::U64(*v)),
            start_at: row.start_at.map(carbon_core::graphql::primitives::I64),
            close_wsol_in_ata: row.close_wsol_in_ata,
            accounts: carbon_core::graphql::primitives::Json(
                serde_json::to_value(&row.accounts.0)
                    .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
            ),
        })
    }
}