pub mod claim_fee_operator_row;
pub mod config_row;
pub mod lock_escrow_row;
pub mod meteora_damm_migration_metadata_row;
pub mod operator_row;
pub mod partner_metadata_row;
pub mod pool_config_row;
pub mod virtual_pool_metadata_row;
pub mod virtual_pool_row;
pub use self::{
claim_fee_operator_row::*, config_row::*, lock_escrow_row::*,
meteora_damm_migration_metadata_row::*, operator_row::*, partner_metadata_row::*,
pool_config_row::*, virtual_pool_metadata_row::*, virtual_pool_row::*,
};
use super::MeteoraDbcAccount;
pub struct MeteoraDbcAccountsMigration;
impl sqlx_migrator::Migration<sqlx::Postgres> for MeteoraDbcAccountsMigration {
fn app(&self) -> &str {
"meteora-dbc"
}
fn name(&self) -> &str {
"meteora_dbc_accounts"
}
fn operations(&self) -> Vec<Box<dyn sqlx_migrator::Operation<sqlx::Postgres>>> {
vec![
Box::new(ClaimFeeOperatorMigrationOperation),
Box::new(ConfigMigrationOperation),
Box::new(LockEscrowMigrationOperation),
Box::new(MeteoraDammMigrationMetadataMigrationOperation),
Box::new(OperatorMigrationOperation),
Box::new(PartnerMetadataMigrationOperation),
Box::new(PoolConfigMigrationOperation),
Box::new(VirtualPoolMigrationOperation),
Box::new(VirtualPoolMetadataMigrationOperation),
]
}
fn parents(&self) -> Vec<Box<dyn sqlx_migrator::Migration<sqlx::Postgres>>> {
vec![]
}
}
pub struct MeteoraDbcAccountWithMetadata(
pub MeteoraDbcAccount,
pub carbon_core::account::AccountMetadata,
);
impl From<(MeteoraDbcAccount, carbon_core::account::AccountMetadata)>
for MeteoraDbcAccountWithMetadata
{
fn from(value: (MeteoraDbcAccount, carbon_core::account::AccountMetadata)) -> Self {
MeteoraDbcAccountWithMetadata(value.0, value.1)
}
}
#[async_trait::async_trait]
impl carbon_core::postgres::operations::Insert for MeteoraDbcAccountWithMetadata {
async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
let MeteoraDbcAccountWithMetadata(account, metadata) = self;
match account {
MeteoraDbcAccount::ClaimFeeOperator(account) => {
let row = claim_fee_operator_row::ClaimFeeOperatorRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.insert(pool).await?;
Ok(())
}
MeteoraDbcAccount::Config(account) => {
let row = config_row::ConfigRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
MeteoraDbcAccount::LockEscrow(account) => {
let row =
lock_escrow_row::LockEscrowRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
MeteoraDbcAccount::MeteoraDammMigrationMetadata(account) => {
let row = meteora_damm_migration_metadata_row::MeteoraDammMigrationMetadataRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
MeteoraDbcAccount::Operator(account) => {
let row = operator_row::OperatorRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
MeteoraDbcAccount::PartnerMetadata(account) => {
let row = partner_metadata_row::PartnerMetadataRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.insert(pool).await?;
Ok(())
}
MeteoraDbcAccount::PoolConfig(account) => {
let row =
pool_config_row::PoolConfigRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
MeteoraDbcAccount::VirtualPool(account) => {
let row = virtual_pool_row::VirtualPoolRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.insert(pool).await?;
Ok(())
}
MeteoraDbcAccount::VirtualPoolMetadata(account) => {
let row = virtual_pool_metadata_row::VirtualPoolMetadataRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.insert(pool).await?;
Ok(())
}
}
}
}
#[async_trait::async_trait]
impl carbon_core::postgres::operations::Upsert for MeteoraDbcAccountWithMetadata {
async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
let MeteoraDbcAccountWithMetadata(account, metadata) = self;
match account {
MeteoraDbcAccount::ClaimFeeOperator(account) => {
let row = claim_fee_operator_row::ClaimFeeOperatorRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.upsert(pool).await?;
Ok(())
}
MeteoraDbcAccount::Config(account) => {
let row = config_row::ConfigRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
MeteoraDbcAccount::LockEscrow(account) => {
let row =
lock_escrow_row::LockEscrowRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
MeteoraDbcAccount::MeteoraDammMigrationMetadata(account) => {
let row = meteora_damm_migration_metadata_row::MeteoraDammMigrationMetadataRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
MeteoraDbcAccount::Operator(account) => {
let row = operator_row::OperatorRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
MeteoraDbcAccount::PartnerMetadata(account) => {
let row = partner_metadata_row::PartnerMetadataRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.upsert(pool).await?;
Ok(())
}
MeteoraDbcAccount::PoolConfig(account) => {
let row =
pool_config_row::PoolConfigRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
MeteoraDbcAccount::VirtualPool(account) => {
let row = virtual_pool_row::VirtualPoolRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.upsert(pool).await?;
Ok(())
}
MeteoraDbcAccount::VirtualPoolMetadata(account) => {
let row = virtual_pool_metadata_row::VirtualPoolMetadataRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.upsert(pool).await?;
Ok(())
}
}
}
}