solana_central/meteora/
calculate_withdrawable_amount.rs

1use crate::constants::METEORA_CONSTANTS;
2use crate::types::meteora_vault::MeteoraVault;
3use std::time::{SystemTime, UNIX_EPOCH};
4
5impl MeteoraVault {
6  /// Calculate the withdrawable amount from a Meteora vault
7  ///
8  /// Accounts for locked profit degradation over time. The locked profit gradually
9  /// becomes available based on the degradation rate and time since last report.
10  pub fn calculate_withdrawable_amount(&self) -> u64 {
11    let current_time: u128 = SystemTime::now()
12      .duration_since(UNIX_EPOCH)
13      .unwrap()
14      .as_millis();
15    let duration: u128 = current_time - self.last_report as u128;
16    let locked_fund_ratio: u128 = duration * self.locked_profit_degradation as u128;
17    if locked_fund_ratio > METEORA_CONSTANTS.locked_profit_degradation_denominator {
18      return self.total_amount;
19    }
20    let locked_profit: u128 = (self.last_updated_locked_profit as u128)
21      * (METEORA_CONSTANTS.locked_profit_degradation_denominator - locked_fund_ratio)
22      / METEORA_CONSTANTS.locked_profit_degradation_denominator;
23    self.total_amount - locked_profit as u64
24  }
25}