use {
crate::types::graphql::RemainingAccountsInfoGraphQL,
carbon_core::graphql::primitives::{U128, U64},
juniper::GraphQLObject,
serde_json,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "SwapV2")]
pub struct SwapV2GraphQL {
pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
pub amount: U64,
pub other_amount_threshold: U64,
pub sqrt_price_limit: U128,
pub amount_specified_is_input: bool,
pub a_to_b: bool,
pub remaining_accounts_info: Option<RemainingAccountsInfoGraphQL>,
pub accounts: carbon_core::graphql::primitives::Json,
}
impl TryFrom<crate::instructions::postgres::SwapV2Row> for SwapV2GraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::instructions::postgres::SwapV2Row) -> 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,
),
sqrt_price_limit: carbon_core::graphql::primitives::U128(*row.sqrt_price_limit),
amount_specified_is_input: row.amount_specified_is_input,
a_to_b: row.a_to_b,
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()))?,
),
})
}
}