pub mod amm_config_row;
pub mod bonding_curve_row;
pub mod config_row;
pub mod locked_cp_liquidity_state_row;
pub use self::{
amm_config_row::*, bonding_curve_row::*, config_row::*, locked_cp_liquidity_state_row::*,
};
use super::BoopAccount;
pub struct BoopAccountsMigration;
impl sqlx_migrator::Migration<sqlx::Postgres> for BoopAccountsMigration {
fn app(&self) -> &str {
"boop"
}
fn name(&self) -> &str {
"boop_accounts"
}
fn operations(&self) -> Vec<Box<dyn sqlx_migrator::Operation<sqlx::Postgres>>> {
vec![
Box::new(AmmConfigMigrationOperation),
Box::new(BondingCurveMigrationOperation),
Box::new(ConfigMigrationOperation),
Box::new(LockedCpLiquidityStateMigrationOperation),
]
}
fn parents(&self) -> Vec<Box<dyn sqlx_migrator::Migration<sqlx::Postgres>>> {
vec![]
}
}
pub struct BoopAccountWithMetadata(pub BoopAccount, pub carbon_core::account::AccountMetadata);
impl From<(BoopAccount, carbon_core::account::AccountMetadata)> for BoopAccountWithMetadata {
fn from(value: (BoopAccount, carbon_core::account::AccountMetadata)) -> Self {
BoopAccountWithMetadata(value.0, value.1)
}
}
#[async_trait::async_trait]
impl carbon_core::postgres::operations::Insert for BoopAccountWithMetadata {
async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
let BoopAccountWithMetadata(account, metadata) = self;
match account {
BoopAccount::AmmConfig(account) => {
let row =
amm_config_row::AmmConfigRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
BoopAccount::BondingCurve(account) => {
let row = bonding_curve_row::BondingCurveRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.insert(pool).await?;
Ok(())
}
BoopAccount::Config(account) => {
let row = config_row::ConfigRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
BoopAccount::LockedCpLiquidityState(account) => {
let row = locked_cp_liquidity_state_row::LockedCpLiquidityStateRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.insert(pool).await?;
Ok(())
}
}
}
}
#[async_trait::async_trait]
impl carbon_core::postgres::operations::Upsert for BoopAccountWithMetadata {
async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
let BoopAccountWithMetadata(account, metadata) = self;
match account {
BoopAccount::AmmConfig(account) => {
let row =
amm_config_row::AmmConfigRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
BoopAccount::BondingCurve(account) => {
let row = bonding_curve_row::BondingCurveRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.upsert(pool).await?;
Ok(())
}
BoopAccount::Config(account) => {
let row = config_row::ConfigRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
BoopAccount::LockedCpLiquidityState(account) => {
let row = locked_cp_liquidity_state_row::LockedCpLiquidityStateRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.upsert(pool).await?;
Ok(())
}
}
}
}