use {
carbon_core::graphql::primitives::{Pubkey, I64, U64, U8},
juniper::GraphQLObject,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "IfRebalanceConfig")]
pub struct IfRebalanceConfigGraphQL {
pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
pub pubkey: Pubkey,
pub total_in_amount: U64,
pub current_in_amount: U64,
pub current_out_amount: U64,
pub current_out_amount_transferred: U64,
pub current_in_amount_since_last_transfer: U64,
pub epoch_start_ts: I64,
pub epoch_in_amount: U64,
pub epoch_max_in_amount: U64,
pub epoch_duration: I64,
pub out_market_index: i32,
pub in_market_index: i32,
pub max_slippage_bps: i32,
pub swap_mode: U8,
pub status: U8,
pub padding2: Vec<U8>,
}
impl TryFrom<crate::accounts::postgres::IfRebalanceConfigRow> for IfRebalanceConfigGraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::accounts::postgres::IfRebalanceConfigRow) -> Result<Self, Self::Error> {
Ok(Self {
account_metadata: row.account_metadata.into(),
pubkey: carbon_core::graphql::primitives::Pubkey(row.pubkey.0),
total_in_amount: carbon_core::graphql::primitives::U64(*row.total_in_amount),
current_in_amount: carbon_core::graphql::primitives::U64(*row.current_in_amount),
current_out_amount: carbon_core::graphql::primitives::U64(*row.current_out_amount),
current_out_amount_transferred: carbon_core::graphql::primitives::U64(
*row.current_out_amount_transferred,
),
current_in_amount_since_last_transfer: carbon_core::graphql::primitives::U64(
*row.current_in_amount_since_last_transfer,
),
epoch_start_ts: carbon_core::graphql::primitives::I64(row.epoch_start_ts),
epoch_in_amount: carbon_core::graphql::primitives::U64(*row.epoch_in_amount),
epoch_max_in_amount: carbon_core::graphql::primitives::U64(*row.epoch_max_in_amount),
epoch_duration: carbon_core::graphql::primitives::I64(row.epoch_duration),
out_market_index: *row.out_market_index,
in_market_index: *row.in_market_index,
max_slippage_bps: *row.max_slippage_bps,
swap_mode: carbon_core::graphql::primitives::U8((*row.swap_mode) as u8),
status: carbon_core::graphql::primitives::U8((*row.status) as u8),
padding2: row
.padding2
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
})
}
}