carbon-orca-whirlpool-decoder 1.0.0

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

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "TwoHopSwapV2")]
pub struct TwoHopSwapV2GraphQL {
    pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
    pub amount: U64,
    pub other_amount_threshold: U64,
    pub amount_specified_is_input: bool,
    pub a_to_b_one: bool,
    pub a_to_b_two: bool,
    pub sqrt_price_limit_one: U128,
    pub sqrt_price_limit_two: U128,
    pub remaining_accounts_info: Option<RemainingAccountsInfoGraphQL>,
    pub accounts: carbon_core::graphql::primitives::Json,
}

impl TryFrom<crate::instructions::postgres::TwoHopSwapV2Row> for TwoHopSwapV2GraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::instructions::postgres::TwoHopSwapV2Row) -> Result<Self, Self::Error> {
        Ok(Self {
            instruction_metadata: row.instruction_metadata.into(),
            amount: carbon_core::graphql::primitives::U64(*row.amount),
            other_amount_threshold: carbon_core::graphql::primitives::U64(
                *row.other_amount_threshold,
            ),
            amount_specified_is_input: row.amount_specified_is_input,
            a_to_b_one: row.a_to_b_one,
            a_to_b_two: row.a_to_b_two,
            sqrt_price_limit_one: carbon_core::graphql::primitives::U128(*row.sqrt_price_limit_one),
            sqrt_price_limit_two: carbon_core::graphql::primitives::U128(*row.sqrt_price_limit_two),
            remaining_accounts_info: row.remaining_accounts_info.map(|v| v.0.into()),
            accounts: carbon_core::graphql::primitives::Json(
                serde_json::to_value(&row.accounts.0)
                    .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
            ),
        })
    }
}