Vocabulary fixes

This commit is contained in:
timurgordon
2025-05-05 11:32:09 +03:00
parent a7c0772d9b
commit 2760f00a30
27 changed files with 588 additions and 329 deletions

View File

@@ -5,7 +5,7 @@ use uuid::Uuid;
/// Asset types representing different categories of digital assets
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum AssetType {
NFT,
Artwork,
Token,
RealEstate,
Commodity,
@@ -18,7 +18,7 @@ pub enum AssetType {
impl AssetType {
pub fn as_str(&self) -> &str {
match self {
AssetType::NFT => "NFT",
AssetType::Artwork => "Artwork",
AssetType::Token => "Token",
AssetType::RealEstate => "Real Estate",
AssetType::Commodity => "Commodity",

View File

@@ -28,8 +28,8 @@ impl DefiPositionStatus {
// DeFi position type
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum DefiPositionType {
Lending,
Borrowing,
Providing,
Receiving,
Liquidity,
Staking,
Collateral,
@@ -38,8 +38,8 @@ pub enum DefiPositionType {
impl DefiPositionType {
pub fn as_str(&self) -> &str {
match self {
DefiPositionType::Lending => "Lending",
DefiPositionType::Borrowing => "Borrowing",
DefiPositionType::Providing => "Providing",
DefiPositionType::Receiving => "Receiving",
DefiPositionType::Liquidity => "Liquidity",
DefiPositionType::Staking => "Staking",
DefiPositionType::Collateral => "Collateral",
@@ -58,24 +58,24 @@ pub struct DefiPosition {
pub asset_symbol: String,
pub amount: f64,
pub value_usd: f64,
pub apy: f64,
pub expected_return: f64,
pub created_at: DateTime<Utc>,
pub expires_at: Option<DateTime<Utc>>,
pub user_id: String,
}
// Lending position
// Providing position
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LendingPosition {
pub struct ProvidingPosition {
pub base: DefiPosition,
pub duration_days: i32,
pub interest_earned: f64,
pub profit_share_earned: f64,
pub return_amount: f64,
}
// Borrowing position
// Receiving position
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BorrowingPosition {
pub struct ReceivingPosition {
pub base: DefiPosition,
pub collateral_asset_id: String,
pub collateral_asset_name: String,
@@ -83,61 +83,61 @@ pub struct BorrowingPosition {
pub collateral_amount: f64,
pub collateral_value_usd: f64,
pub duration_days: i32,
pub interest_rate: f64,
pub interest_owed: f64,
pub profit_share_rate: f64,
pub profit_share_owed: f64,
pub total_to_repay: f64,
pub collateral_ratio: f64,
}
// In-memory database for DeFi positions
pub struct DefiDatabase {
lending_positions: HashMap<String, LendingPosition>,
borrowing_positions: HashMap<String, BorrowingPosition>,
providing_positions: HashMap<String, ProvidingPosition>,
receiving_positions: HashMap<String, ReceivingPosition>,
}
impl DefiDatabase {
pub fn new() -> Self {
Self {
lending_positions: HashMap::new(),
borrowing_positions: HashMap::new(),
providing_positions: HashMap::new(),
receiving_positions: HashMap::new(),
}
}
// Lending operations
pub fn add_lending_position(&mut self, position: LendingPosition) {
self.lending_positions.insert(position.base.id.clone(), position);
// Providing operations
pub fn add_providing_position(&mut self, position: ProvidingPosition) {
self.providing_positions.insert(position.base.id.clone(), position);
}
pub fn get_lending_position(&self, id: &str) -> Option<&LendingPosition> {
self.lending_positions.get(id)
pub fn get_providing_position(&self, id: &str) -> Option<&ProvidingPosition> {
self.providing_positions.get(id)
}
pub fn get_all_lending_positions(&self) -> Vec<&LendingPosition> {
self.lending_positions.values().collect()
pub fn get_all_providing_positions(&self) -> Vec<&ProvidingPosition> {
self.providing_positions.values().collect()
}
pub fn get_user_lending_positions(&self, user_id: &str) -> Vec<&LendingPosition> {
self.lending_positions
pub fn get_user_providing_positions(&self, user_id: &str) -> Vec<&ProvidingPosition> {
self.providing_positions
.values()
.filter(|p| p.base.user_id == user_id)
.collect()
}
// Borrowing operations
pub fn add_borrowing_position(&mut self, position: BorrowingPosition) {
self.borrowing_positions.insert(position.base.id.clone(), position);
// Receiving operations
pub fn add_receiving_position(&mut self, position: ReceivingPosition) {
self.receiving_positions.insert(position.base.id.clone(), position);
}
pub fn get_borrowing_position(&self, id: &str) -> Option<&BorrowingPosition> {
self.borrowing_positions.get(id)
pub fn get_receiving_position(&self, id: &str) -> Option<&ReceivingPosition> {
self.receiving_positions.get(id)
}
pub fn get_all_borrowing_positions(&self) -> Vec<&BorrowingPosition> {
self.borrowing_positions.values().collect()
pub fn get_all_receiving_positions(&self) -> Vec<&ReceivingPosition> {
self.receiving_positions.values().collect()
}
pub fn get_user_borrowing_positions(&self, user_id: &str) -> Vec<&BorrowingPosition> {
self.borrowing_positions
pub fn get_user_receiving_positions(&self, user_id: &str) -> Vec<&ReceivingPosition> {
self.receiving_positions
.values()
.filter(|p| p.base.user_id == user_id)
.collect()
@@ -153,40 +153,40 @@ lazy_static! {
pub fn initialize_mock_data() {
let mut db = DEFI_DB.lock().unwrap();
// Add mock lending positions
let lending_position = LendingPosition {
// Add mock providing positions
let providing_position = ProvidingPosition {
base: DefiPosition {
id: Uuid::new_v4().to_string(),
position_type: DefiPositionType::Lending,
position_type: DefiPositionType::Providing,
status: DefiPositionStatus::Active,
asset_id: "TFT".to_string(),
asset_name: "ThreeFold Token".to_string(),
asset_symbol: "TFT".to_string(),
amount: 1000.0,
value_usd: 500.0,
apy: 4.2,
expected_return: 4.2,
created_at: Utc::now(),
expires_at: Some(Utc::now() + chrono::Duration::days(30)),
user_id: "user123".to_string(),
},
duration_days: 30,
interest_earned: 3.5,
profit_share_earned: 3.5,
return_amount: 1003.5,
};
db.add_lending_position(lending_position);
db.add_providing_position(providing_position);
// Add mock borrowing positions
let borrowing_position = BorrowingPosition {
// Add mock receiving positions
let receiving_position = ReceivingPosition {
base: DefiPosition {
id: Uuid::new_v4().to_string(),
position_type: DefiPositionType::Borrowing,
position_type: DefiPositionType::Receiving,
status: DefiPositionStatus::Active,
asset_id: "ZAZ".to_string(),
asset_id: "ZDFZ".to_string(),
asset_name: "Zanzibar Token".to_string(),
asset_symbol: "ZAZ".to_string(),
asset_symbol: "ZDFZ".to_string(),
amount: 500.0,
value_usd: 250.0,
apy: 5.8,
expected_return: 5.8,
created_at: Utc::now(),
expires_at: Some(Utc::now() + chrono::Duration::days(90)),
user_id: "user123".to_string(),
@@ -197,10 +197,10 @@ pub fn initialize_mock_data() {
collateral_amount: 1500.0,
collateral_value_usd: 750.0,
duration_days: 90,
interest_rate: 5.8,
interest_owed: 3.625,
profit_share_rate: 5.8,
profit_share_owed: 3.625,
total_to_repay: 503.625,
collateral_ratio: 300.0,
};
db.add_borrowing_position(borrowing_position);
db.add_receiving_position(receiving_position);
}

View File

@@ -14,4 +14,4 @@ pub use user::User;
pub use ticket::{Ticket, TicketComment, TicketStatus, TicketPriority};
pub use calendar::{CalendarEvent, CalendarViewMode};
pub use marketplace::{Listing, ListingStatus, ListingType, Bid, BidStatus, MarketplaceStatistics};
pub use defi::{DefiPosition, DefiPositionType, DefiPositionStatus, LendingPosition, BorrowingPosition, DEFI_DB, initialize_mock_data};
pub use defi::{DefiPosition, DefiPositionType, DefiPositionStatus, ProvidingPosition, ReceivingPosition, DEFI_DB, initialize_mock_data};