carbon-bonkswap-decoder 2.0.0

Carbon BonkSwap Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::graphql::{FixedPointGraphQL, TokenGraphQL},
    carbon_core::graphql::primitives::U8,
    juniper::GraphQLObject,
    serde_json,
};

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "CreatePool")]
pub struct CreatePoolGraphQL {
    pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
    pub lp_fee: FixedPointGraphQL,
    pub buyback_fee: FixedPointGraphQL,
    pub project_fee: FixedPointGraphQL,
    pub mercanti_fee: FixedPointGraphQL,
    pub initial_token_x: TokenGraphQL,
    pub initial_token_y: TokenGraphQL,
    pub bump: U8,
    pub accounts: carbon_core::graphql::primitives::Json,
}

impl TryFrom<crate::instructions::postgres::CreatePoolRow> for CreatePoolGraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::instructions::postgres::CreatePoolRow) -> Result<Self, Self::Error> {
        Ok(Self {
            instruction_metadata: row.instruction_metadata.into(),
            lp_fee: row.lp_fee.0.into(),
            buyback_fee: row.buyback_fee.0.into(),
            project_fee: row.project_fee.0.into(),
            mercanti_fee: row.mercanti_fee.0.into(),
            initial_token_x: row.initial_token_x.0.into(),
            initial_token_y: row.initial_token_y.0.into(),
            bump: carbon_core::graphql::primitives::U8((*row.bump) as u8),
            accounts: carbon_core::graphql::primitives::Json(
                serde_json::to_value(&row.accounts.0)
                    .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
            ),
        })
    }
}