pub mod bonding_curve_row;
pub mod fee_config_row;
pub mod global_config_row;
pub mod global_volume_accumulator_row;
pub mod pool_row;
pub mod sharing_config_row;
pub mod user_volume_accumulator_row;
pub use self::{
bonding_curve_row::*, fee_config_row::*, global_config_row::*,
global_volume_accumulator_row::*, pool_row::*, sharing_config_row::*,
user_volume_accumulator_row::*,
};
use super::PumpSwapAccount;
pub struct PumpSwapAccountsMigration;
impl sqlx_migrator::Migration<sqlx::Postgres> for PumpSwapAccountsMigration {
fn app(&self) -> &str {
"pump-swap"
}
fn name(&self) -> &str {
"pump_swap_accounts"
}
fn operations(&self) -> Vec<Box<dyn sqlx_migrator::Operation<sqlx::Postgres>>> {
vec![
Box::new(BondingCurveMigrationOperation),
Box::new(FeeConfigMigrationOperation),
Box::new(GlobalConfigMigrationOperation),
Box::new(GlobalVolumeAccumulatorMigrationOperation),
Box::new(PoolMigrationOperation),
Box::new(SharingConfigMigrationOperation),
Box::new(UserVolumeAccumulatorMigrationOperation),
]
}
fn parents(&self) -> Vec<Box<dyn sqlx_migrator::Migration<sqlx::Postgres>>> {
vec![]
}
}
pub struct PumpSwapAccountWithMetadata(
pub PumpSwapAccount,
pub carbon_core::account::AccountMetadata,
);
impl From<(PumpSwapAccount, carbon_core::account::AccountMetadata)>
for PumpSwapAccountWithMetadata
{
fn from(value: (PumpSwapAccount, carbon_core::account::AccountMetadata)) -> Self {
PumpSwapAccountWithMetadata(value.0, value.1)
}
}
#[async_trait::async_trait]
impl carbon_core::postgres::operations::Insert for PumpSwapAccountWithMetadata {
async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
let PumpSwapAccountWithMetadata(account, metadata) = self;
match account {
PumpSwapAccount::BondingCurve(account) => {
let row = bonding_curve_row::BondingCurveRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.insert(pool).await?;
Ok(())
}
PumpSwapAccount::FeeConfig(account) => {
let row =
fee_config_row::FeeConfigRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
PumpSwapAccount::GlobalConfig(account) => {
let row = global_config_row::GlobalConfigRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.insert(pool).await?;
Ok(())
}
PumpSwapAccount::GlobalVolumeAccumulator(account) => {
let row = global_volume_accumulator_row::GlobalVolumeAccumulatorRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.insert(pool).await?;
Ok(())
}
PumpSwapAccount::Pool(account) => {
let row = pool_row::PoolRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
PumpSwapAccount::SharingConfig(account) => {
let row = sharing_config_row::SharingConfigRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.insert(pool).await?;
Ok(())
}
PumpSwapAccount::UserVolumeAccumulator(account) => {
let row = user_volume_accumulator_row::UserVolumeAccumulatorRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.insert(pool).await?;
Ok(())
}
}
}
}
#[async_trait::async_trait]
impl carbon_core::postgres::operations::Upsert for PumpSwapAccountWithMetadata {
async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
let PumpSwapAccountWithMetadata(account, metadata) = self;
match account {
PumpSwapAccount::BondingCurve(account) => {
let row = bonding_curve_row::BondingCurveRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.upsert(pool).await?;
Ok(())
}
PumpSwapAccount::FeeConfig(account) => {
let row =
fee_config_row::FeeConfigRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
PumpSwapAccount::GlobalConfig(account) => {
let row = global_config_row::GlobalConfigRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.upsert(pool).await?;
Ok(())
}
PumpSwapAccount::GlobalVolumeAccumulator(account) => {
let row = global_volume_accumulator_row::GlobalVolumeAccumulatorRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.upsert(pool).await?;
Ok(())
}
PumpSwapAccount::Pool(account) => {
let row = pool_row::PoolRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
PumpSwapAccount::SharingConfig(account) => {
let row = sharing_config_row::SharingConfigRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.upsert(pool).await?;
Ok(())
}
PumpSwapAccount::UserVolumeAccumulator(account) => {
let row = user_volume_accumulator_row::UserVolumeAccumulatorRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.upsert(pool).await?;
Ok(())
}
}
}
}