carbon-pump-swap-decoder 2.0.0

PumpSwap Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::graphql::OptionBoolGraphQL, carbon_core::graphql::primitives::U64,
    juniper::GraphQLObject, serde_json,
};

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "Buy")]
pub struct BuyGraphQL {
    pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
    pub base_amount_out: U64,
    pub max_quote_amount_in: U64,
    pub track_volume: OptionBoolGraphQL,
    pub accounts: carbon_core::graphql::primitives::Json,
}

impl TryFrom<crate::instructions::postgres::BuyRow> for BuyGraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::instructions::postgres::BuyRow) -> Result<Self, Self::Error> {
        Ok(Self {
            instruction_metadata: row.instruction_metadata.into(),
            base_amount_out: carbon_core::graphql::primitives::U64(*row.base_amount_out),
            max_quote_amount_in: carbon_core::graphql::primitives::U64(*row.max_quote_amount_in),
            track_volume: row.track_volume.0 .0,
            accounts: carbon_core::graphql::primitives::Json(
                serde_json::to_value(&row.accounts.0)
                    .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
            ),
        })
    }
}