use {
crate::types::graphql::WrappedI80F48GraphQL,
carbon_core::graphql::primitives::{Pubkey, U32},
juniper::GraphQLObject,
serde_json,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "EditGlobalFeeState")]
pub struct EditGlobalFeeStateGraphQL {
pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
pub admin: Pubkey,
pub fee_wallet: Pubkey,
pub bank_init_flat_sol_fee: U32,
pub liquidation_flat_sol_fee: U32,
pub order_init_flat_sol_fee: U32,
pub program_fee_fixed: WrappedI80F48GraphQL,
pub program_fee_rate: WrappedI80F48GraphQL,
pub liquidation_max_fee: WrappedI80F48GraphQL,
pub order_execution_max_fee: WrappedI80F48GraphQL,
pub accounts: carbon_core::graphql::primitives::Json,
}
impl TryFrom<crate::instructions::postgres::EditGlobalFeeStateRow> for EditGlobalFeeStateGraphQL {
type Error = carbon_core::error::Error;
fn try_from(
row: crate::instructions::postgres::EditGlobalFeeStateRow,
) -> Result<Self, Self::Error> {
Ok(Self {
instruction_metadata: row.instruction_metadata.into(),
admin: carbon_core::graphql::primitives::Pubkey(row.admin.0),
fee_wallet: carbon_core::graphql::primitives::Pubkey(row.fee_wallet.0),
bank_init_flat_sol_fee: carbon_core::graphql::primitives::U32(
(*row.bank_init_flat_sol_fee) as u32,
),
liquidation_flat_sol_fee: carbon_core::graphql::primitives::U32(
(*row.liquidation_flat_sol_fee) as u32,
),
order_init_flat_sol_fee: carbon_core::graphql::primitives::U32(
(*row.order_init_flat_sol_fee) as u32,
),
program_fee_fixed: row.program_fee_fixed.0.into(),
program_fee_rate: row.program_fee_rate.0.into(),
liquidation_max_fee: row.liquidation_max_fee.0.into(),
order_execution_max_fee: row.order_execution_max_fee.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()))?,
),
})
}
}