Skip to content

Commit

Permalink
fix: add comment
Browse files Browse the repository at this point in the history
Co-authored-by: sander2 <[email protected]>
  • Loading branch information
nakul1010 and sander2 authored Dec 6, 2023
1 parent 8d768a8 commit c983b2a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/redeem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,20 @@ impl<T: Config> Pallet<T> {

ext::fee::get_premium_redeem_fee::<T>(&premium_tokens_in_collateral)?
} else {
// Formula = max_premium_collateral = (FEE * (oldTokens * EXCH * SECURE - oldCol)) / (SECURE - FEE)
// The goal of premium redeems is to get the vault back the a healthy collateralization ratio. As such,
// we only award a premium for the amount of tokens required to get the vault back to secure threshold.
// The CollateralizationRate is defined as `totalCollateral / convertToCollateral(totalTokens)`
// When paying a premium, the collateralization rate gets updated according to the following formula:
// `NewCollateralization = (oldCol - awardedPremium) / ( oldTokens*EXCH - awardedPremium/FEE)`
// To calculate the maximum premium we are willing to pay, we set the newCollateralization to
// the secure threshold, which gives:
// `SECURE = (oldCol - awardedPremium) / (oldTokens*EXCH - awardedPremium/FEE)``
// We can rewrite this formula to calculate the `premium` amount that would get us to the secure threshold:
// `maxPremium = (oldTokens * EXCH * SECURE - oldCol) * (FEE / (SECURE - FEE))`
// Which can be interpreted as:
// `maxPremium = missingCollateral * (FEE / (SECURE - FEE))
// Note that to prevent repeated premium redeems while waiting for execution, we use to_be_backed_tokens
// for `oldCol`, which takes into account pending issues and redeems

let backing_collateral = ext::vault_registry::get_backing_collateral(&vault_id)?;

Expand Down

0 comments on commit c983b2a

Please sign in to comment.