use {
crate::types::{
LiquidityDistributionConfig, LiquidityVestingInfo, LockedVestingConfig, PoolFeesConfig,
},
carbon_core::{
account::AccountMetadata,
postgres::{
metadata::AccountRowMetadata,
primitives::{Pubkey, U128, U16, U64, U8},
},
},
};
#[derive(sqlx::FromRow, Debug, Clone)]
pub struct PoolConfigRow {
#[sqlx(flatten)]
pub account_metadata: AccountRowMetadata,
pub quote_mint: Pubkey,
pub fee_claimer: Pubkey,
pub leftover_receiver: Pubkey,
pub pool_fees: sqlx::types::Json<PoolFeesConfig>,
pub partner_liquidity_vesting_info: sqlx::types::Json<LiquidityVestingInfo>,
pub creator_liquidity_vesting_info: sqlx::types::Json<LiquidityVestingInfo>,
pub padding0: Vec<u8>,
pub padding1: U16,
pub collect_fee_mode: U8,
pub migration_option: U8,
pub activation_type: U8,
pub token_decimal: U8,
pub version: U8,
pub token_type: U8,
pub quote_token_flag: U8,
pub partner_permanent_locked_liquidity_percentage: U8,
pub partner_liquidity_percentage: U8,
pub creator_permanent_locked_liquidity_percentage: U8,
pub creator_liquidity_percentage: U8,
pub migration_fee_option: U8,
pub fixed_token_supply_flag: U8,
pub creator_trading_fee_percentage: U8,
pub token_update_authority: U8,
pub migration_fee_percentage: U8,
pub creator_migration_fee_percentage: U8,
pub padding2: Vec<u8>,
pub swap_base_amount: U64,
pub migration_quote_threshold: U64,
pub migration_base_threshold: U64,
pub migration_sqrt_price: U128,
pub locked_vesting_config: sqlx::types::Json<LockedVestingConfig>,
pub pre_migration_token_supply: U64,
pub post_migration_token_supply: U64,
pub migrated_collect_fee_mode: U8,
pub migrated_dynamic_fee: U8,
pub migrated_pool_fee_bps: U16,
pub migrated_pool_base_fee_mode: U8,
pub enable_first_swap_with_min_fee: U8,
pub migrated_compounding_fee_bps: U16,
pub pool_creation_fee: U64,
pub migrated_pool_base_fee_bytes: Vec<u8>,
pub sqrt_start_price: U128,
pub curve: sqlx::types::Json<Vec<LiquidityDistributionConfig>>,
}
impl PoolConfigRow {
pub fn from_parts(
source: crate::accounts::pool_config::PoolConfig,
metadata: AccountMetadata,
) -> Self {
Self {
account_metadata: metadata.into(),
quote_mint: source.quote_mint.into(),
fee_claimer: source.fee_claimer.into(),
leftover_receiver: source.leftover_receiver.into(),
pool_fees: sqlx::types::Json(source.pool_fees),
partner_liquidity_vesting_info: sqlx::types::Json(
source.partner_liquidity_vesting_info,
),
creator_liquidity_vesting_info: sqlx::types::Json(
source.creator_liquidity_vesting_info,
),
padding0: source.padding0.to_vec(),
padding1: source.padding1.into(),
collect_fee_mode: source.collect_fee_mode.into(),
migration_option: source.migration_option.into(),
activation_type: source.activation_type.into(),
token_decimal: source.token_decimal.into(),
version: source.version.into(),
token_type: source.token_type.into(),
quote_token_flag: source.quote_token_flag.into(),
partner_permanent_locked_liquidity_percentage: source
.partner_permanent_locked_liquidity_percentage
.into(),
partner_liquidity_percentage: source.partner_liquidity_percentage.into(),
creator_permanent_locked_liquidity_percentage: source
.creator_permanent_locked_liquidity_percentage
.into(),
creator_liquidity_percentage: source.creator_liquidity_percentage.into(),
migration_fee_option: source.migration_fee_option.into(),
fixed_token_supply_flag: source.fixed_token_supply_flag.into(),
creator_trading_fee_percentage: source.creator_trading_fee_percentage.into(),
token_update_authority: source.token_update_authority.into(),
migration_fee_percentage: source.migration_fee_percentage.into(),
creator_migration_fee_percentage: source.creator_migration_fee_percentage.into(),
padding2: source.padding2.to_vec(),
swap_base_amount: source.swap_base_amount.into(),
migration_quote_threshold: source.migration_quote_threshold.into(),
migration_base_threshold: source.migration_base_threshold.into(),
migration_sqrt_price: source.migration_sqrt_price.into(),
locked_vesting_config: sqlx::types::Json(source.locked_vesting_config),
pre_migration_token_supply: source.pre_migration_token_supply.into(),
post_migration_token_supply: source.post_migration_token_supply.into(),
migrated_collect_fee_mode: source.migrated_collect_fee_mode.into(),
migrated_dynamic_fee: source.migrated_dynamic_fee.into(),
migrated_pool_fee_bps: source.migrated_pool_fee_bps.into(),
migrated_pool_base_fee_mode: source.migrated_pool_base_fee_mode.into(),
enable_first_swap_with_min_fee: source.enable_first_swap_with_min_fee.into(),
migrated_compounding_fee_bps: source.migrated_compounding_fee_bps.into(),
pool_creation_fee: source.pool_creation_fee.into(),
migrated_pool_base_fee_bytes: source.migrated_pool_base_fee_bytes.to_vec(),
sqrt_start_price: source.sqrt_start_price.into(),
curve: sqlx::types::Json(source.curve.to_vec()),
}
}
}
impl TryFrom<PoolConfigRow> for crate::accounts::pool_config::PoolConfig {
type Error = carbon_core::error::Error;
fn try_from(source: PoolConfigRow) -> Result<Self, Self::Error> {
Ok(Self {
quote_mint: *source.quote_mint,
fee_claimer: *source.fee_claimer,
leftover_receiver: *source.leftover_receiver,
pool_fees: source.pool_fees.0,
partner_liquidity_vesting_info: source.partner_liquidity_vesting_info.0,
creator_liquidity_vesting_info: source.creator_liquidity_vesting_info.0,
padding0: source.padding0.as_slice().try_into().map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert padding from postgres primitive: expected 14 bytes"
.to_string(),
)
})?,
padding1: source.padding1.try_into().map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
collect_fee_mode: source.collect_fee_mode.try_into().map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
migration_option: source.migration_option.try_into().map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
activation_type: source.activation_type.try_into().map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
token_decimal: source.token_decimal.try_into().map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
version: source.version.try_into().map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
token_type: source.token_type.try_into().map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
quote_token_flag: source.quote_token_flag.try_into().map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
partner_permanent_locked_liquidity_percentage: source
.partner_permanent_locked_liquidity_percentage
.try_into()
.map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
partner_liquidity_percentage: source.partner_liquidity_percentage.try_into().map_err(
|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
},
)?,
creator_permanent_locked_liquidity_percentage: source
.creator_permanent_locked_liquidity_percentage
.try_into()
.map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
creator_liquidity_percentage: source.creator_liquidity_percentage.try_into().map_err(
|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
},
)?,
migration_fee_option: source.migration_fee_option.try_into().map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
fixed_token_supply_flag: source.fixed_token_supply_flag.try_into().map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
creator_trading_fee_percentage: source
.creator_trading_fee_percentage
.try_into()
.map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
token_update_authority: source.token_update_authority.try_into().map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
migration_fee_percentage: source.migration_fee_percentage.try_into().map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
creator_migration_fee_percentage: source
.creator_migration_fee_percentage
.try_into()
.map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
padding2: source.padding2.as_slice().try_into().map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert padding from postgres primitive: expected 7 bytes"
.to_string(),
)
})?,
swap_base_amount: *source.swap_base_amount,
migration_quote_threshold: *source.migration_quote_threshold,
migration_base_threshold: *source.migration_base_threshold,
migration_sqrt_price: *source.migration_sqrt_price,
locked_vesting_config: source.locked_vesting_config.0,
pre_migration_token_supply: *source.pre_migration_token_supply,
post_migration_token_supply: *source.post_migration_token_supply,
migrated_collect_fee_mode: source.migrated_collect_fee_mode.try_into().map_err(
|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
},
)?,
migrated_dynamic_fee: source.migrated_dynamic_fee.try_into().map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
migrated_pool_fee_bps: source.migrated_pool_fee_bps.try_into().map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
migrated_pool_base_fee_mode: source.migrated_pool_base_fee_mode.try_into().map_err(
|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
},
)?,
enable_first_swap_with_min_fee: source
.enable_first_swap_with_min_fee
.try_into()
.map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
migrated_compounding_fee_bps: source.migrated_compounding_fee_bps.try_into().map_err(
|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
},
)?,
pool_creation_fee: *source.pool_creation_fee,
migrated_pool_base_fee_bytes: source
.migrated_pool_base_fee_bytes
.as_slice()
.try_into()
.map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert padding from postgres primitive: expected 16 bytes"
.to_string(),
)
})?,
sqrt_start_price: *source.sqrt_start_price,
curve: source
.curve
.0
.into_iter()
.collect::<Vec<_>>()
.try_into()
.map_err(|_| {
carbon_core::error::Error::Custom(
"Failed to convert value from postgres primitive".to_string(),
)
})?,
})
}
}
impl carbon_core::postgres::operations::Table for crate::accounts::pool_config::PoolConfig {
fn table() -> &'static str {
"pool_config_account"
}
fn columns() -> Vec<&'static str> {
vec![
"__pubkey",
"__slot",
"quote_mint",
"fee_claimer",
"leftover_receiver",
"pool_fees",
"partner_liquidity_vesting_info",
"creator_liquidity_vesting_info",
"padding0",
"padding1",
"collect_fee_mode",
"migration_option",
"activation_type",
"token_decimal",
"version",
"token_type",
"quote_token_flag",
"partner_permanent_locked_liquidity_percentage",
"partner_liquidity_percentage",
"creator_permanent_locked_liquidity_percentage",
"creator_liquidity_percentage",
"migration_fee_option",
"fixed_token_supply_flag",
"creator_trading_fee_percentage",
"token_update_authority",
"migration_fee_percentage",
"creator_migration_fee_percentage",
"padding2",
"swap_base_amount",
"migration_quote_threshold",
"migration_base_threshold",
"migration_sqrt_price",
"locked_vesting_config",
"pre_migration_token_supply",
"post_migration_token_supply",
"migrated_collect_fee_mode",
"migrated_dynamic_fee",
"migrated_pool_fee_bps",
"migrated_pool_base_fee_mode",
"enable_first_swap_with_min_fee",
"migrated_compounding_fee_bps",
"pool_creation_fee",
"migrated_pool_base_fee_bytes",
"sqrt_start_price",
"curve",
]
}
}
#[async_trait::async_trait]
impl carbon_core::postgres::operations::Insert for PoolConfigRow {
async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
sqlx::query(r#"
INSERT INTO pool_config_account (
"quote_mint",
"fee_claimer",
"leftover_receiver",
"pool_fees",
"partner_liquidity_vesting_info",
"creator_liquidity_vesting_info",
"padding0",
"padding1",
"collect_fee_mode",
"migration_option",
"activation_type",
"token_decimal",
"version",
"token_type",
"quote_token_flag",
"partner_permanent_locked_liquidity_percentage",
"partner_liquidity_percentage",
"creator_permanent_locked_liquidity_percentage",
"creator_liquidity_percentage",
"migration_fee_option",
"fixed_token_supply_flag",
"creator_trading_fee_percentage",
"token_update_authority",
"migration_fee_percentage",
"creator_migration_fee_percentage",
"padding2",
"swap_base_amount",
"migration_quote_threshold",
"migration_base_threshold",
"migration_sqrt_price",
"locked_vesting_config",
"pre_migration_token_supply",
"post_migration_token_supply",
"migrated_collect_fee_mode",
"migrated_dynamic_fee",
"migrated_pool_fee_bps",
"migrated_pool_base_fee_mode",
"enable_first_swap_with_min_fee",
"migrated_compounding_fee_bps",
"pool_creation_fee",
"migrated_pool_base_fee_bytes",
"sqrt_start_price",
"curve",
__pubkey, __slot
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, $41, $42, $43, $44, $45
)"#)
.bind(self.quote_mint)
.bind(self.fee_claimer)
.bind(self.leftover_receiver)
.bind(&self.pool_fees)
.bind(&self.partner_liquidity_vesting_info)
.bind(&self.creator_liquidity_vesting_info)
.bind(&self.padding0)
.bind(self.padding1)
.bind(self.collect_fee_mode)
.bind(self.migration_option)
.bind(self.activation_type)
.bind(self.token_decimal)
.bind(self.version)
.bind(self.token_type)
.bind(self.quote_token_flag)
.bind(self.partner_permanent_locked_liquidity_percentage)
.bind(self.partner_liquidity_percentage)
.bind(self.creator_permanent_locked_liquidity_percentage)
.bind(self.creator_liquidity_percentage)
.bind(self.migration_fee_option)
.bind(self.fixed_token_supply_flag)
.bind(self.creator_trading_fee_percentage)
.bind(self.token_update_authority)
.bind(self.migration_fee_percentage)
.bind(self.creator_migration_fee_percentage)
.bind(&self.padding2)
.bind(&self.swap_base_amount)
.bind(&self.migration_quote_threshold)
.bind(&self.migration_base_threshold)
.bind(&self.migration_sqrt_price)
.bind(&self.locked_vesting_config)
.bind(&self.pre_migration_token_supply)
.bind(&self.post_migration_token_supply)
.bind(self.migrated_collect_fee_mode)
.bind(self.migrated_dynamic_fee)
.bind(self.migrated_pool_fee_bps)
.bind(self.migrated_pool_base_fee_mode)
.bind(self.enable_first_swap_with_min_fee)
.bind(self.migrated_compounding_fee_bps)
.bind(&self.pool_creation_fee)
.bind(&self.migrated_pool_base_fee_bytes)
.bind(&self.sqrt_start_price)
.bind(&self.curve)
.bind(self.account_metadata.pubkey)
.bind(&self.account_metadata.slot)
.execute(pool).await
.map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?;
Ok(())
}
}
#[async_trait::async_trait]
impl carbon_core::postgres::operations::Upsert for PoolConfigRow {
async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
sqlx::query(r#"INSERT INTO pool_config_account (
"quote_mint",
"fee_claimer",
"leftover_receiver",
"pool_fees",
"partner_liquidity_vesting_info",
"creator_liquidity_vesting_info",
"padding0",
"padding1",
"collect_fee_mode",
"migration_option",
"activation_type",
"token_decimal",
"version",
"token_type",
"quote_token_flag",
"partner_permanent_locked_liquidity_percentage",
"partner_liquidity_percentage",
"creator_permanent_locked_liquidity_percentage",
"creator_liquidity_percentage",
"migration_fee_option",
"fixed_token_supply_flag",
"creator_trading_fee_percentage",
"token_update_authority",
"migration_fee_percentage",
"creator_migration_fee_percentage",
"padding2",
"swap_base_amount",
"migration_quote_threshold",
"migration_base_threshold",
"migration_sqrt_price",
"locked_vesting_config",
"pre_migration_token_supply",
"post_migration_token_supply",
"migrated_collect_fee_mode",
"migrated_dynamic_fee",
"migrated_pool_fee_bps",
"migrated_pool_base_fee_mode",
"enable_first_swap_with_min_fee",
"migrated_compounding_fee_bps",
"pool_creation_fee",
"migrated_pool_base_fee_bytes",
"sqrt_start_price",
"curve",
__pubkey, __slot
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, $41, $42, $43, $44, $45
) ON CONFLICT (
__pubkey
) DO UPDATE SET
"quote_mint" = EXCLUDED."quote_mint",
"fee_claimer" = EXCLUDED."fee_claimer",
"leftover_receiver" = EXCLUDED."leftover_receiver",
"pool_fees" = EXCLUDED."pool_fees",
"partner_liquidity_vesting_info" = EXCLUDED."partner_liquidity_vesting_info",
"creator_liquidity_vesting_info" = EXCLUDED."creator_liquidity_vesting_info",
"padding0" = EXCLUDED."padding0",
"padding1" = EXCLUDED."padding1",
"collect_fee_mode" = EXCLUDED."collect_fee_mode",
"migration_option" = EXCLUDED."migration_option",
"activation_type" = EXCLUDED."activation_type",
"token_decimal" = EXCLUDED."token_decimal",
"version" = EXCLUDED."version",
"token_type" = EXCLUDED."token_type",
"quote_token_flag" = EXCLUDED."quote_token_flag",
"partner_permanent_locked_liquidity_percentage" = EXCLUDED."partner_permanent_locked_liquidity_percentage",
"partner_liquidity_percentage" = EXCLUDED."partner_liquidity_percentage",
"creator_permanent_locked_liquidity_percentage" = EXCLUDED."creator_permanent_locked_liquidity_percentage",
"creator_liquidity_percentage" = EXCLUDED."creator_liquidity_percentage",
"migration_fee_option" = EXCLUDED."migration_fee_option",
"fixed_token_supply_flag" = EXCLUDED."fixed_token_supply_flag",
"creator_trading_fee_percentage" = EXCLUDED."creator_trading_fee_percentage",
"token_update_authority" = EXCLUDED."token_update_authority",
"migration_fee_percentage" = EXCLUDED."migration_fee_percentage",
"creator_migration_fee_percentage" = EXCLUDED."creator_migration_fee_percentage",
"padding2" = EXCLUDED."padding2",
"swap_base_amount" = EXCLUDED."swap_base_amount",
"migration_quote_threshold" = EXCLUDED."migration_quote_threshold",
"migration_base_threshold" = EXCLUDED."migration_base_threshold",
"migration_sqrt_price" = EXCLUDED."migration_sqrt_price",
"locked_vesting_config" = EXCLUDED."locked_vesting_config",
"pre_migration_token_supply" = EXCLUDED."pre_migration_token_supply",
"post_migration_token_supply" = EXCLUDED."post_migration_token_supply",
"migrated_collect_fee_mode" = EXCLUDED."migrated_collect_fee_mode",
"migrated_dynamic_fee" = EXCLUDED."migrated_dynamic_fee",
"migrated_pool_fee_bps" = EXCLUDED."migrated_pool_fee_bps",
"migrated_pool_base_fee_mode" = EXCLUDED."migrated_pool_base_fee_mode",
"enable_first_swap_with_min_fee" = EXCLUDED."enable_first_swap_with_min_fee",
"migrated_compounding_fee_bps" = EXCLUDED."migrated_compounding_fee_bps",
"pool_creation_fee" = EXCLUDED."pool_creation_fee",
"migrated_pool_base_fee_bytes" = EXCLUDED."migrated_pool_base_fee_bytes",
"sqrt_start_price" = EXCLUDED."sqrt_start_price",
"curve" = EXCLUDED."curve",
__slot = EXCLUDED.__slot
"#)
.bind(self.quote_mint)
.bind(self.fee_claimer)
.bind(self.leftover_receiver)
.bind(&self.pool_fees)
.bind(&self.partner_liquidity_vesting_info)
.bind(&self.creator_liquidity_vesting_info)
.bind(&self.padding0)
.bind(self.padding1)
.bind(self.collect_fee_mode)
.bind(self.migration_option)
.bind(self.activation_type)
.bind(self.token_decimal)
.bind(self.version)
.bind(self.token_type)
.bind(self.quote_token_flag)
.bind(self.partner_permanent_locked_liquidity_percentage)
.bind(self.partner_liquidity_percentage)
.bind(self.creator_permanent_locked_liquidity_percentage)
.bind(self.creator_liquidity_percentage)
.bind(self.migration_fee_option)
.bind(self.fixed_token_supply_flag)
.bind(self.creator_trading_fee_percentage)
.bind(self.token_update_authority)
.bind(self.migration_fee_percentage)
.bind(self.creator_migration_fee_percentage)
.bind(&self.padding2)
.bind(&self.swap_base_amount)
.bind(&self.migration_quote_threshold)
.bind(&self.migration_base_threshold)
.bind(&self.migration_sqrt_price)
.bind(&self.locked_vesting_config)
.bind(&self.pre_migration_token_supply)
.bind(&self.post_migration_token_supply)
.bind(self.migrated_collect_fee_mode)
.bind(self.migrated_dynamic_fee)
.bind(self.migrated_pool_fee_bps)
.bind(self.migrated_pool_base_fee_mode)
.bind(self.enable_first_swap_with_min_fee)
.bind(self.migrated_compounding_fee_bps)
.bind(&self.pool_creation_fee)
.bind(&self.migrated_pool_base_fee_bytes)
.bind(&self.sqrt_start_price)
.bind(&self.curve)
.bind(self.account_metadata.pubkey)
.bind(&self.account_metadata.slot)
.execute(pool).await
.map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?;
Ok(())
}
}
#[async_trait::async_trait]
impl carbon_core::postgres::operations::Delete for PoolConfigRow {
type Key = carbon_core::postgres::primitives::Pubkey;
async fn delete(key: Self::Key, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
sqlx::query(
r#"DELETE FROM pool_config_account WHERE
__pubkey = $1
"#,
)
.bind(key)
.execute(pool)
.await
.map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?;
Ok(())
}
}
#[async_trait::async_trait]
impl carbon_core::postgres::operations::Lookup for PoolConfigRow {
type Key = carbon_core::postgres::primitives::Pubkey;
async fn lookup(
key: Self::Key,
pool: &sqlx::PgPool,
) -> carbon_core::error::CarbonResult<Option<Self>> {
let row = sqlx::query_as(
r#"SELECT * FROM pool_config_account WHERE
__pubkey = $1
"#,
)
.bind(key)
.fetch_optional(pool)
.await
.map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?;
Ok(row)
}
}
pub struct PoolConfigMigrationOperation;
#[async_trait::async_trait]
impl sqlx_migrator::Operation<sqlx::Postgres> for PoolConfigMigrationOperation {
async fn up(
&self,
connection: &mut sqlx::PgConnection,
) -> Result<(), sqlx_migrator::error::Error> {
sqlx::query(
r#"CREATE TABLE IF NOT EXISTS pool_config_account (
-- Account data
"quote_mint" BYTEA NOT NULL,
"fee_claimer" BYTEA NOT NULL,
"leftover_receiver" BYTEA NOT NULL,
"pool_fees" JSONB NOT NULL,
"partner_liquidity_vesting_info" JSONB NOT NULL,
"creator_liquidity_vesting_info" JSONB NOT NULL,
"padding0" BYTEA NOT NULL,
"padding1" INT4 NOT NULL,
"collect_fee_mode" INT2 NOT NULL,
"migration_option" INT2 NOT NULL,
"activation_type" INT2 NOT NULL,
"token_decimal" INT2 NOT NULL,
"version" INT2 NOT NULL,
"token_type" INT2 NOT NULL,
"quote_token_flag" INT2 NOT NULL,
"partner_permanent_locked_liquidity_percentage" INT2 NOT NULL,
"partner_liquidity_percentage" INT2 NOT NULL,
"creator_permanent_locked_liquidity_percentage" INT2 NOT NULL,
"creator_liquidity_percentage" INT2 NOT NULL,
"migration_fee_option" INT2 NOT NULL,
"fixed_token_supply_flag" INT2 NOT NULL,
"creator_trading_fee_percentage" INT2 NOT NULL,
"token_update_authority" INT2 NOT NULL,
"migration_fee_percentage" INT2 NOT NULL,
"creator_migration_fee_percentage" INT2 NOT NULL,
"padding2" BYTEA NOT NULL,
"swap_base_amount" NUMERIC(20) NOT NULL,
"migration_quote_threshold" NUMERIC(20) NOT NULL,
"migration_base_threshold" NUMERIC(20) NOT NULL,
"migration_sqrt_price" NUMERIC(39) NOT NULL,
"locked_vesting_config" JSONB NOT NULL,
"pre_migration_token_supply" NUMERIC(20) NOT NULL,
"post_migration_token_supply" NUMERIC(20) NOT NULL,
"migrated_collect_fee_mode" INT2 NOT NULL,
"migrated_dynamic_fee" INT2 NOT NULL,
"migrated_pool_fee_bps" INT4 NOT NULL,
"migrated_pool_base_fee_mode" INT2 NOT NULL,
"enable_first_swap_with_min_fee" INT2 NOT NULL,
"migrated_compounding_fee_bps" INT4 NOT NULL,
"pool_creation_fee" NUMERIC(20) NOT NULL,
"migrated_pool_base_fee_bytes" BYTEA NOT NULL,
"sqrt_start_price" NUMERIC(39) NOT NULL,
"curve" JSONB NOT NULL,
-- Account metadata
__pubkey BYTEA NOT NULL,
__slot NUMERIC(20),
PRIMARY KEY (__pubkey)
)"#,
)
.execute(connection)
.await?;
Ok(())
}
async fn down(
&self,
connection: &mut sqlx::PgConnection,
) -> Result<(), sqlx_migrator::error::Error> {
sqlx::query(r#"DROP TABLE IF EXISTS pool_config_account"#)
.execute(connection)
.await?;
Ok(())
}
}