0.5.5
This commit is contained in:
134
kb_lib/src/db/dtos/liquidity_event.rs
Normal file
134
kb_lib/src/db/dtos/liquidity_event.rs
Normal file
@@ -0,0 +1,134 @@
|
||||
// file: kb_lib/src/db/dtos/liquidity_event.rs
|
||||
|
||||
//! Liquidity event DTO.
|
||||
|
||||
/// Application-facing normalized liquidity event DTO.
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct KbLiquidityEventDto {
|
||||
/// Optional numeric primary key.
|
||||
pub id: std::option::Option<i64>,
|
||||
/// Related DEX id.
|
||||
pub dex_id: i64,
|
||||
/// Related pool id.
|
||||
pub pool_id: i64,
|
||||
/// Optional related pair id.
|
||||
pub pair_id: std::option::Option<i64>,
|
||||
/// Transaction signature.
|
||||
pub signature: std::string::String,
|
||||
/// Instruction index inside the transaction.
|
||||
pub instruction_index: i64,
|
||||
/// Optional slot number.
|
||||
pub slot: std::option::Option<u64>,
|
||||
/// Liquidity event kind.
|
||||
pub event_kind: crate::KbLiquidityEventKind,
|
||||
/// Optional actor wallet.
|
||||
pub actor_wallet: std::option::Option<std::string::String>,
|
||||
/// Base token id.
|
||||
pub base_token_id: i64,
|
||||
/// Quote token id.
|
||||
pub quote_token_id: i64,
|
||||
/// Optional LP token id.
|
||||
pub lp_token_id: std::option::Option<i64>,
|
||||
/// Base amount as decimal text.
|
||||
pub base_amount: std::string::String,
|
||||
/// Quote amount as decimal text.
|
||||
pub quote_amount: std::string::String,
|
||||
/// Optional LP amount as decimal text.
|
||||
pub lp_amount: std::option::Option<std::string::String>,
|
||||
/// Execution timestamp.
|
||||
pub executed_at: chrono::DateTime<chrono::Utc>,
|
||||
}
|
||||
|
||||
impl KbLiquidityEventDto {
|
||||
/// Creates a new liquidity event DTO.
|
||||
pub fn new(
|
||||
dex_id: i64,
|
||||
pool_id: i64,
|
||||
pair_id: std::option::Option<i64>,
|
||||
signature: std::string::String,
|
||||
instruction_index: i64,
|
||||
slot: std::option::Option<u64>,
|
||||
event_kind: crate::KbLiquidityEventKind,
|
||||
actor_wallet: std::option::Option<std::string::String>,
|
||||
base_token_id: i64,
|
||||
quote_token_id: i64,
|
||||
lp_token_id: std::option::Option<i64>,
|
||||
base_amount: std::string::String,
|
||||
quote_amount: std::string::String,
|
||||
lp_amount: std::option::Option<std::string::String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: None,
|
||||
dex_id,
|
||||
pool_id,
|
||||
pair_id,
|
||||
signature,
|
||||
instruction_index,
|
||||
slot,
|
||||
event_kind,
|
||||
actor_wallet,
|
||||
base_token_id,
|
||||
quote_token_id,
|
||||
lp_token_id,
|
||||
base_amount,
|
||||
quote_amount,
|
||||
lp_amount,
|
||||
executed_at: chrono::Utc::now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<crate::KbLiquidityEventEntity> for KbLiquidityEventDto {
|
||||
type Error = crate::KbError;
|
||||
|
||||
fn try_from(entity: crate::KbLiquidityEventEntity) -> Result<Self, Self::Error> {
|
||||
let event_kind_result = crate::KbLiquidityEventKind::from_i16(entity.event_kind);
|
||||
let event_kind = match event_kind_result {
|
||||
Ok(event_kind) => event_kind,
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
let executed_at_result = chrono::DateTime::parse_from_rfc3339(&entity.executed_at);
|
||||
let executed_at = match executed_at_result {
|
||||
Ok(executed_at) => executed_at.with_timezone(&chrono::Utc),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot parse liquidity event executed_at '{}': {}",
|
||||
entity.executed_at, error
|
||||
)));
|
||||
}
|
||||
};
|
||||
let slot = match entity.slot {
|
||||
Some(slot) => {
|
||||
let slot_result = u64::try_from(slot);
|
||||
match slot_result {
|
||||
Ok(slot) => Some(slot),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot convert liquidity event slot '{}' to u64: {}",
|
||||
slot, error
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
Ok(Self {
|
||||
id: Some(entity.id),
|
||||
dex_id: entity.dex_id,
|
||||
pool_id: entity.pool_id,
|
||||
pair_id: entity.pair_id,
|
||||
signature: entity.signature,
|
||||
instruction_index: entity.instruction_index,
|
||||
slot,
|
||||
event_kind,
|
||||
actor_wallet: entity.actor_wallet,
|
||||
base_token_id: entity.base_token_id,
|
||||
quote_token_id: entity.quote_token_id,
|
||||
lp_token_id: entity.lp_token_id,
|
||||
base_amount: entity.base_amount,
|
||||
quote_amount: entity.quote_amount,
|
||||
lp_amount: entity.lp_amount,
|
||||
executed_at,
|
||||
})
|
||||
}
|
||||
}
|
||||
129
kb_lib/src/db/dtos/swap.rs
Normal file
129
kb_lib/src/db/dtos/swap.rs
Normal file
@@ -0,0 +1,129 @@
|
||||
// file: kb_lib/src/db/dtos/swap.rs
|
||||
|
||||
//! Swap DTO.
|
||||
|
||||
/// Application-facing normalized swap DTO.
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct KbSwapDto {
|
||||
/// Optional numeric primary key.
|
||||
pub id: std::option::Option<i64>,
|
||||
/// Related DEX id.
|
||||
pub dex_id: i64,
|
||||
/// Related pool id.
|
||||
pub pool_id: i64,
|
||||
/// Optional related pair id.
|
||||
pub pair_id: std::option::Option<i64>,
|
||||
/// Transaction signature.
|
||||
pub signature: std::string::String,
|
||||
/// Instruction index inside the transaction.
|
||||
pub instruction_index: i64,
|
||||
/// Optional slot number.
|
||||
pub slot: std::option::Option<u64>,
|
||||
/// Optional trader wallet.
|
||||
pub trader_wallet: std::option::Option<std::string::String>,
|
||||
/// Base token id.
|
||||
pub base_token_id: i64,
|
||||
/// Quote token id.
|
||||
pub quote_token_id: i64,
|
||||
/// Base amount as decimal text.
|
||||
pub base_amount: std::string::String,
|
||||
/// Quote amount as decimal text.
|
||||
pub quote_amount: std::string::String,
|
||||
/// Optional price in quote units as decimal text.
|
||||
pub price_quote: std::option::Option<std::string::String>,
|
||||
/// Trade side relative to the base token.
|
||||
pub trade_side: crate::KbSwapTradeSide,
|
||||
/// Execution timestamp.
|
||||
pub executed_at: chrono::DateTime<chrono::Utc>,
|
||||
}
|
||||
|
||||
impl KbSwapDto {
|
||||
/// Creates a new swap DTO.
|
||||
pub fn new(
|
||||
dex_id: i64,
|
||||
pool_id: i64,
|
||||
pair_id: std::option::Option<i64>,
|
||||
signature: std::string::String,
|
||||
instruction_index: i64,
|
||||
slot: std::option::Option<u64>,
|
||||
trader_wallet: std::option::Option<std::string::String>,
|
||||
base_token_id: i64,
|
||||
quote_token_id: i64,
|
||||
base_amount: std::string::String,
|
||||
quote_amount: std::string::String,
|
||||
price_quote: std::option::Option<std::string::String>,
|
||||
trade_side: crate::KbSwapTradeSide,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: None,
|
||||
dex_id,
|
||||
pool_id,
|
||||
pair_id,
|
||||
signature,
|
||||
instruction_index,
|
||||
slot,
|
||||
trader_wallet,
|
||||
base_token_id,
|
||||
quote_token_id,
|
||||
base_amount,
|
||||
quote_amount,
|
||||
price_quote,
|
||||
trade_side,
|
||||
executed_at: chrono::Utc::now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<crate::KbSwapEntity> for KbSwapDto {
|
||||
type Error = crate::KbError;
|
||||
|
||||
fn try_from(entity: crate::KbSwapEntity) -> Result<Self, Self::Error> {
|
||||
let trade_side_result = crate::KbSwapTradeSide::from_i16(entity.trade_side);
|
||||
let trade_side = match trade_side_result {
|
||||
Ok(trade_side) => trade_side,
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
let executed_at_result = chrono::DateTime::parse_from_rfc3339(&entity.executed_at);
|
||||
let executed_at = match executed_at_result {
|
||||
Ok(executed_at) => executed_at.with_timezone(&chrono::Utc),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot parse swap executed_at '{}': {}",
|
||||
entity.executed_at, error
|
||||
)));
|
||||
}
|
||||
};
|
||||
let slot = match entity.slot {
|
||||
Some(slot) => {
|
||||
let slot_result = u64::try_from(slot);
|
||||
match slot_result {
|
||||
Ok(slot) => Some(slot),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot convert swap slot '{}' to u64: {}",
|
||||
slot, error
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
Ok(Self {
|
||||
id: Some(entity.id),
|
||||
dex_id: entity.dex_id,
|
||||
pool_id: entity.pool_id,
|
||||
pair_id: entity.pair_id,
|
||||
signature: entity.signature,
|
||||
instruction_index: entity.instruction_index,
|
||||
slot,
|
||||
trader_wallet: entity.trader_wallet,
|
||||
base_token_id: entity.base_token_id,
|
||||
quote_token_id: entity.quote_token_id,
|
||||
base_amount: entity.base_amount,
|
||||
quote_amount: entity.quote_amount,
|
||||
price_quote: entity.price_quote,
|
||||
trade_side,
|
||||
executed_at,
|
||||
})
|
||||
}
|
||||
}
|
||||
103
kb_lib/src/db/dtos/token_burn_event.rs
Normal file
103
kb_lib/src/db/dtos/token_burn_event.rs
Normal file
@@ -0,0 +1,103 @@
|
||||
// file: kb_lib/src/db/dtos/token_burn_event.rs
|
||||
|
||||
//! Token burn event DTO.
|
||||
|
||||
/// Application-facing normalized token burn event DTO.
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct KbTokenBurnEventDto {
|
||||
/// Optional numeric primary key.
|
||||
pub id: std::option::Option<i64>,
|
||||
/// Related token id.
|
||||
pub token_id: i64,
|
||||
/// Transaction signature.
|
||||
pub signature: std::string::String,
|
||||
/// Instruction index inside the transaction.
|
||||
pub instruction_index: i64,
|
||||
/// Optional slot number.
|
||||
pub slot: std::option::Option<u64>,
|
||||
/// Optional authority wallet.
|
||||
pub authority_wallet: std::option::Option<std::string::String>,
|
||||
/// Optional source wallet.
|
||||
pub source_wallet: std::option::Option<std::string::String>,
|
||||
/// Burned amount as decimal text.
|
||||
pub amount: std::string::String,
|
||||
/// Optional supply after burn as decimal text.
|
||||
pub supply_after: std::option::Option<std::string::String>,
|
||||
/// Execution timestamp.
|
||||
pub executed_at: chrono::DateTime<chrono::Utc>,
|
||||
}
|
||||
|
||||
impl KbTokenBurnEventDto {
|
||||
/// Creates a new token burn event DTO.
|
||||
pub fn new(
|
||||
token_id: i64,
|
||||
signature: std::string::String,
|
||||
instruction_index: i64,
|
||||
slot: std::option::Option<u64>,
|
||||
authority_wallet: std::option::Option<std::string::String>,
|
||||
source_wallet: std::option::Option<std::string::String>,
|
||||
amount: std::string::String,
|
||||
supply_after: std::option::Option<std::string::String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: None,
|
||||
token_id,
|
||||
signature,
|
||||
instruction_index,
|
||||
slot,
|
||||
authority_wallet,
|
||||
source_wallet,
|
||||
amount,
|
||||
supply_after,
|
||||
executed_at: chrono::Utc::now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<crate::KbTokenBurnEventEntity> for KbTokenBurnEventDto {
|
||||
type Error = crate::KbError;
|
||||
|
||||
fn try_from(
|
||||
entity: crate::KbTokenBurnEventEntity,
|
||||
) -> Result<Self, Self::Error> {
|
||||
let executed_at_result = chrono::DateTime::parse_from_rfc3339(&entity.executed_at);
|
||||
let executed_at = match executed_at_result {
|
||||
Ok(executed_at) => executed_at.with_timezone(&chrono::Utc),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot parse token burn event executed_at '{}': {}",
|
||||
entity.executed_at,
|
||||
error
|
||||
)));
|
||||
},
|
||||
};
|
||||
let slot = match entity.slot {
|
||||
Some(slot) => {
|
||||
let slot_result = u64::try_from(slot);
|
||||
match slot_result {
|
||||
Ok(slot) => Some(slot),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot convert token burn event slot '{}' to u64: {}",
|
||||
slot,
|
||||
error
|
||||
)));
|
||||
},
|
||||
}
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
Ok(Self {
|
||||
id: Some(entity.id),
|
||||
token_id: entity.token_id,
|
||||
signature: entity.signature,
|
||||
instruction_index: entity.instruction_index,
|
||||
slot,
|
||||
authority_wallet: entity.authority_wallet,
|
||||
source_wallet: entity.source_wallet,
|
||||
amount: entity.amount,
|
||||
supply_after: entity.supply_after,
|
||||
executed_at,
|
||||
})
|
||||
}
|
||||
}
|
||||
99
kb_lib/src/db/dtos/token_mint_event.rs
Normal file
99
kb_lib/src/db/dtos/token_mint_event.rs
Normal file
@@ -0,0 +1,99 @@
|
||||
// file: kb_lib/src/db/dtos/token_mint_event.rs
|
||||
|
||||
//! Token mint event DTO.
|
||||
|
||||
/// Application-facing normalized token mint event DTO.
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct KbTokenMintEventDto {
|
||||
/// Optional numeric primary key.
|
||||
pub id: std::option::Option<i64>,
|
||||
/// Related token id.
|
||||
pub token_id: i64,
|
||||
/// Transaction signature.
|
||||
pub signature: std::string::String,
|
||||
/// Instruction index inside the transaction.
|
||||
pub instruction_index: i64,
|
||||
/// Optional slot number.
|
||||
pub slot: std::option::Option<u64>,
|
||||
/// Optional mint authority wallet.
|
||||
pub authority_wallet: std::option::Option<std::string::String>,
|
||||
/// Optional destination wallet.
|
||||
pub destination_wallet: std::option::Option<std::string::String>,
|
||||
/// Minted amount as decimal text.
|
||||
pub amount: std::string::String,
|
||||
/// Optional supply after mint as decimal text.
|
||||
pub supply_after: std::option::Option<std::string::String>,
|
||||
/// Execution timestamp.
|
||||
pub executed_at: chrono::DateTime<chrono::Utc>,
|
||||
}
|
||||
|
||||
impl KbTokenMintEventDto {
|
||||
/// Creates a new token mint event DTO.
|
||||
pub fn new(
|
||||
token_id: i64,
|
||||
signature: std::string::String,
|
||||
instruction_index: i64,
|
||||
slot: std::option::Option<u64>,
|
||||
authority_wallet: std::option::Option<std::string::String>,
|
||||
destination_wallet: std::option::Option<std::string::String>,
|
||||
amount: std::string::String,
|
||||
supply_after: std::option::Option<std::string::String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: None,
|
||||
token_id,
|
||||
signature,
|
||||
instruction_index,
|
||||
slot,
|
||||
authority_wallet,
|
||||
destination_wallet,
|
||||
amount,
|
||||
supply_after,
|
||||
executed_at: chrono::Utc::now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<crate::KbTokenMintEventEntity> for KbTokenMintEventDto {
|
||||
type Error = crate::KbError;
|
||||
|
||||
fn try_from(entity: crate::KbTokenMintEventEntity) -> Result<Self, Self::Error> {
|
||||
let executed_at_result = chrono::DateTime::parse_from_rfc3339(&entity.executed_at);
|
||||
let executed_at = match executed_at_result {
|
||||
Ok(executed_at) => executed_at.with_timezone(&chrono::Utc),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot parse token mint event executed_at '{}': {}",
|
||||
entity.executed_at, error
|
||||
)));
|
||||
}
|
||||
};
|
||||
let slot = match entity.slot {
|
||||
Some(slot) => {
|
||||
let slot_result = u64::try_from(slot);
|
||||
match slot_result {
|
||||
Ok(slot) => Some(slot),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot convert token mint event slot '{}' to u64: {}",
|
||||
slot, error
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
Ok(Self {
|
||||
id: Some(entity.id),
|
||||
token_id: entity.token_id,
|
||||
signature: entity.signature,
|
||||
instruction_index: entity.instruction_index,
|
||||
slot,
|
||||
authority_wallet: entity.authority_wallet,
|
||||
destination_wallet: entity.destination_wallet,
|
||||
amount: entity.amount,
|
||||
supply_after: entity.supply_after,
|
||||
executed_at,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user