pub mod adaptive_fee_tier_row;
pub mod dynamic_tick_array_row;
pub mod fee_tier_row;
pub mod lock_config_row;
pub mod oracle_row;
pub mod position_bundle_row;
pub mod position_row;
pub mod tick_array_row;
pub mod token_badge_row;
pub mod whirlpool_row;
pub mod whirlpools_config_extension_row;
pub mod whirlpools_config_row;
pub use self::{
adaptive_fee_tier_row::*, dynamic_tick_array_row::*, fee_tier_row::*, lock_config_row::*,
oracle_row::*, position_bundle_row::*, position_row::*, tick_array_row::*, token_badge_row::*,
whirlpool_row::*, whirlpools_config_extension_row::*, whirlpools_config_row::*,
};
use super::OrcaWhirlpoolAccount;
pub struct OrcaWhirlpoolAccountsMigration;
impl sqlx_migrator::Migration<sqlx::Postgres> for OrcaWhirlpoolAccountsMigration {
fn app(&self) -> &str {
"orca-whirlpool"
}
fn name(&self) -> &str {
"orca_whirlpool_accounts"
}
fn operations(&self) -> Vec<Box<dyn sqlx_migrator::Operation<sqlx::Postgres>>> {
vec![
Box::new(AdaptiveFeeTierMigrationOperation),
Box::new(DynamicTickArrayMigrationOperation),
Box::new(FeeTierMigrationOperation),
Box::new(LockConfigMigrationOperation),
Box::new(OracleMigrationOperation),
Box::new(PositionMigrationOperation),
Box::new(PositionBundleMigrationOperation),
Box::new(TickArrayMigrationOperation),
Box::new(TokenBadgeMigrationOperation),
Box::new(WhirlpoolMigrationOperation),
Box::new(WhirlpoolsConfigMigrationOperation),
Box::new(WhirlpoolsConfigExtensionMigrationOperation),
]
}
fn parents(&self) -> Vec<Box<dyn sqlx_migrator::Migration<sqlx::Postgres>>> {
vec![]
}
}
pub struct OrcaWhirlpoolAccountWithMetadata(
pub OrcaWhirlpoolAccount,
pub carbon_core::account::AccountMetadata,
);
impl From<(OrcaWhirlpoolAccount, carbon_core::account::AccountMetadata)>
for OrcaWhirlpoolAccountWithMetadata
{
fn from(value: (OrcaWhirlpoolAccount, carbon_core::account::AccountMetadata)) -> Self {
OrcaWhirlpoolAccountWithMetadata(value.0, value.1)
}
}
#[async_trait::async_trait]
impl carbon_core::postgres::operations::Insert for OrcaWhirlpoolAccountWithMetadata {
async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
let OrcaWhirlpoolAccountWithMetadata(account, metadata) = self;
match account {
OrcaWhirlpoolAccount::AdaptiveFeeTier(account) => {
let row = adaptive_fee_tier_row::AdaptiveFeeTierRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.insert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::DynamicTickArray(account) => {
let row = dynamic_tick_array_row::DynamicTickArrayRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.insert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::FeeTier(account) => {
let row = fee_tier_row::FeeTierRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::LockConfig(account) => {
let row =
lock_config_row::LockConfigRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::Oracle(account) => {
let row = oracle_row::OracleRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::Position(account) => {
let row = position_row::PositionRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::PositionBundle(account) => {
let row = position_bundle_row::PositionBundleRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.insert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::TickArray(account) => {
let row =
tick_array_row::TickArrayRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::TokenBadge(account) => {
let row =
token_badge_row::TokenBadgeRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::Whirlpool(account) => {
let row =
whirlpool_row::WhirlpoolRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::WhirlpoolsConfig(account) => {
let row = whirlpools_config_row::WhirlpoolsConfigRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.insert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::WhirlpoolsConfigExtension(account) => {
let row = whirlpools_config_extension_row::WhirlpoolsConfigExtensionRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.insert(pool).await?;
Ok(())
}
}
}
}
#[async_trait::async_trait]
impl carbon_core::postgres::operations::Upsert for OrcaWhirlpoolAccountWithMetadata {
async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
let OrcaWhirlpoolAccountWithMetadata(account, metadata) = self;
match account {
OrcaWhirlpoolAccount::AdaptiveFeeTier(account) => {
let row = adaptive_fee_tier_row::AdaptiveFeeTierRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.upsert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::DynamicTickArray(account) => {
let row = dynamic_tick_array_row::DynamicTickArrayRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.upsert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::FeeTier(account) => {
let row = fee_tier_row::FeeTierRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::LockConfig(account) => {
let row =
lock_config_row::LockConfigRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::Oracle(account) => {
let row = oracle_row::OracleRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::Position(account) => {
let row = position_row::PositionRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::PositionBundle(account) => {
let row = position_bundle_row::PositionBundleRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.upsert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::TickArray(account) => {
let row =
tick_array_row::TickArrayRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::TokenBadge(account) => {
let row =
token_badge_row::TokenBadgeRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::Whirlpool(account) => {
let row =
whirlpool_row::WhirlpoolRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::WhirlpoolsConfig(account) => {
let row = whirlpools_config_row::WhirlpoolsConfigRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.upsert(pool).await?;
Ok(())
}
OrcaWhirlpoolAccount::WhirlpoolsConfigExtension(account) => {
let row = whirlpools_config_extension_row::WhirlpoolsConfigExtensionRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.upsert(pool).await?;
Ok(())
}
}
}
}