use {
crate::types::graphql::GraduationMethodGraphQL,
carbon_core::graphql::primitives::{Pubkey, I64, U128, U64, U8},
juniper::GraphQLObject,
serde_json,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "BondingCurveInitialize")]
pub struct BondingCurveInitializeGraphQL {
pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
pub start_price: U128,
pub end_price: U128,
pub control_points: Vec<i32>,
pub creator: Pubkey,
pub graduation_methods: Vec<GraduationMethodGraphQL>,
pub swap_fee_bps: i32,
pub quote_fee_bps: i32,
pub base_fee_bps: i32,
pub launch_time: I64,
pub creator_reward: U64,
pub graduation_reward: U64,
pub graduation_target: U64,
pub graduation_time: I64,
pub min_reserve_bps: i32,
pub buy_requires_permission: bool,
pub buy_permission_bitmap: Vec<U8>,
pub sell_requires_permission: bool,
pub sell_permission_bitmap: Vec<U8>,
pub max_buy_amount: U64,
pub max_sell_amount: U64,
pub retain_mint_authority: bool,
pub base_allocation_bps: i32,
pub accounts: carbon_core::graphql::primitives::Json,
}
impl TryFrom<crate::instructions::postgres::BondingCurveInitializeRow>
for BondingCurveInitializeGraphQL
{
type Error = carbon_core::error::Error;
fn try_from(
row: crate::instructions::postgres::BondingCurveInitializeRow,
) -> Result<Self, Self::Error> {
Ok(Self {
instruction_metadata: row.instruction_metadata.into(),
start_price: carbon_core::graphql::primitives::U128(*row.start_price),
end_price: carbon_core::graphql::primitives::U128(*row.end_price),
control_points: row.control_points.into_iter().map(|item| *item).collect(),
creator: carbon_core::graphql::primitives::Pubkey(row.creator.0),
graduation_methods: row
.graduation_methods
.0
.into_iter()
.map(|item| item.into())
.collect(),
swap_fee_bps: *row.swap_fee_bps,
quote_fee_bps: *row.quote_fee_bps,
base_fee_bps: *row.base_fee_bps,
launch_time: carbon_core::graphql::primitives::I64(row.launch_time),
creator_reward: carbon_core::graphql::primitives::U64(*row.creator_reward),
graduation_reward: carbon_core::graphql::primitives::U64(*row.graduation_reward),
graduation_target: carbon_core::graphql::primitives::U64(*row.graduation_target),
graduation_time: carbon_core::graphql::primitives::I64(row.graduation_time),
min_reserve_bps: *row.min_reserve_bps,
buy_requires_permission: row.buy_requires_permission,
buy_permission_bitmap: row
.buy_permission_bitmap
.into_iter()
.map(|x| carbon_core::graphql::primitives::U8((*x) as u8))
.collect(),
sell_requires_permission: row.sell_requires_permission,
sell_permission_bitmap: row
.sell_permission_bitmap
.into_iter()
.map(|x| carbon_core::graphql::primitives::U8((*x) as u8))
.collect(),
max_buy_amount: carbon_core::graphql::primitives::U64(*row.max_buy_amount),
max_sell_amount: carbon_core::graphql::primitives::U64(*row.max_sell_amount),
retain_mint_authority: row.retain_mint_authority,
base_allocation_bps: *row.base_allocation_bps,
accounts: carbon_core::graphql::primitives::Json(
serde_json::to_value(&row.accounts.0)
.map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
),
})
}
}