Skip to content

Commit

Permalink
Add leverage calculations for tighter liquidations
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrena-Corto committed Nov 17, 2024
1 parent ddb48fb commit 0fc9203
Show file tree
Hide file tree
Showing 2 changed files with 383 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/oracle_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,34 @@ impl OraclePrice {
confidence: self.confidence,
})
}

// Converts USD amount with implied USD_DECIMALS decimals to token amount
pub fn get_token_amount(&self, asset_amount_usd: u64, token_decimals: u8) -> Result<u64> {
if asset_amount_usd == 0 || self.price == 0 {
return Ok(0);
}

math::checked_decimal_div(
asset_amount_usd,
-(Cortex::USD_DECIMALS as i32),
self.price,
self.exponent,
-(token_decimals as i32),
)
}

// Converts token amount to USD with implied USD_DECIMALS decimals
pub fn get_asset_amount_usd(&self, token_amount: u64, token_decimals: u8) -> Result<u64> {
if token_amount == 0 || self.price == 0 {
return Ok(0);
}

math::checked_decimal_mul(
token_amount,
-(token_decimals as i32),
self.price,
self.exponent,
-(Cortex::USD_DECIMALS as i32),
)
}
}
Loading

0 comments on commit 0fc9203

Please sign in to comment.