-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1417b1
commit f2a2137
Showing
6 changed files
with
1,192 additions
and
1,156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use ethers::types::U256; | ||
use fixed_point::{fixed, FixedPoint}; | ||
|
||
use crate::State; | ||
|
||
impl State { | ||
/// Calculates the number of share reserves that are not reserved by open | ||
/// positions. | ||
pub fn calculate_idle_share_reserves(&self) -> FixedPoint { | ||
let long_exposure = self.long_exposure().div_up(self.vault_share_price()); | ||
match self.share_reserves() > long_exposure + self.minimum_share_reserves() { | ||
true => self.share_reserves() - long_exposure - self.minimum_share_reserves(), | ||
false => fixed!(0), | ||
} | ||
} | ||
|
||
/// Calculates the number of base that are not reserved by open positions. | ||
pub fn calculate_idle_share_reserves_in_base(&self) -> FixedPoint { | ||
// NOTE: Round up to underestimate the pool's idle. | ||
let long_exposure = self.long_exposure().div_up(self.vault_share_price()); | ||
|
||
// Calculate the idle base reserves. | ||
let mut idle_shares_in_base = fixed!(0); | ||
if self.share_reserves() > (long_exposure + self.minimum_share_reserves()) { | ||
idle_shares_in_base = | ||
(self.share_reserves() - long_exposure - self.minimum_share_reserves()) | ||
* self.vault_share_price(); | ||
} | ||
|
||
idle_shares_in_base | ||
} | ||
|
||
/// Function that takes in a scaled FixedPoint maturity time and calculates | ||
/// normalized time remaining with higher precision. | ||
pub fn calculate_scaled_normalized_time_remaining( | ||
&self, | ||
scaled_maturity_time: FixedPoint, | ||
current_time: U256, | ||
) -> FixedPoint { | ||
let scaled_latest_checkpoint = | ||
FixedPoint::from(self.to_checkpoint(current_time)) * fixed!(1e36); | ||
let scaled_position_duration = self.position_duration() * fixed!(1e36); | ||
if scaled_maturity_time > scaled_latest_checkpoint { | ||
// NOTE: Round down to underestimate the time remaining. | ||
(scaled_maturity_time - scaled_latest_checkpoint).div_down(scaled_position_duration) | ||
} else { | ||
fixed!(0) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod base; | ||
mod long; | ||
mod lp; | ||
mod short; | ||
|
Oops, something went wrong.