solana_central/meteora/
calculate_withdrawable_amount.rs1use crate::constants::METEORA_CONSTANTS;
2use crate::types::meteora_vault::MeteoraVault;
3use std::time::{SystemTime, UNIX_EPOCH};
4
5impl MeteoraVault {
6 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}