Fee buyback: Limit MNGO price by stable price (#485)

This makes it much harder to temporarily manipulate the MNGO price to
get a more favorable buyback deal.
This commit is contained in:
Christian Kamm 2023-03-01 09:58:47 +01:00 committed by GitHub
parent c48d9c94d9
commit 255c6fb138
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -74,7 +74,7 @@ pub fn account_buyback_fees_with_mngo(
&AccountInfoRef::borrow(&ctx.accounts.mngo_oracle.as_ref())?,
Some(Clock::get()?.slot),
)?;
let mngo_buyback_price = mngo_oracle_price * bonus_factor;
let mngo_buyback_price = mngo_oracle_price.min(mngo_bank.stable_price()) * bonus_factor;
// mngo is exchanged at a discount
let mut max_buyback_mngo = max_buyback / mngo_buyback_price;
// buyback is restricted to account's token position