use {
crate::types::graphql::{CurrencyGraphQL, CurveTypeGraphQL, MigrationTargetGraphQL},
carbon_core::graphql::primitives::{Pubkey, U32, U64, U8},
juniper::GraphQLObject,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "CurveAccount")]
pub struct CurveAccountGraphQL {
pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
pub total_supply: U64,
pub curve_amount: U64,
pub mint: Pubkey,
pub decimals: U8,
pub collateral_currency: CurrencyGraphQL,
pub curve_type: CurveTypeGraphQL,
pub marketcap_threshold: U64,
pub marketcap_currency: CurrencyGraphQL,
pub migration_fee: U64,
pub coef_b: U32,
pub bump: U8,
pub migration_target: MigrationTargetGraphQL,
}
impl TryFrom<crate::accounts::postgres::CurveAccountRow> for CurveAccountGraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::accounts::postgres::CurveAccountRow) -> Result<Self, Self::Error> {
Ok(Self {
account_metadata: row.account_metadata.into(),
total_supply: carbon_core::graphql::primitives::U64(*row.total_supply),
curve_amount: carbon_core::graphql::primitives::U64(*row.curve_amount),
mint: carbon_core::graphql::primitives::Pubkey(row.mint.0),
decimals: carbon_core::graphql::primitives::U8((*row.decimals) as u8),
collateral_currency: row.collateral_currency.0.into(),
curve_type: row.curve_type.0.into(),
marketcap_threshold: carbon_core::graphql::primitives::U64(*row.marketcap_threshold),
marketcap_currency: row.marketcap_currency.0.into(),
migration_fee: carbon_core::graphql::primitives::U64(*row.migration_fee),
coef_b: carbon_core::graphql::primitives::U32((*row.coef_b) as u32),
bump: carbon_core::graphql::primitives::U8((*row.bump) as u8),
migration_target: row.migration_target.0.into(),
})
}
}