Skip to content

Commit

Permalink
Fix Oak no. 1 - liquidatees staking rewards.
Browse files Browse the repository at this point in the history
  • Loading branch information
piobab committed Jun 20, 2024
1 parent cf750ee commit 37611b3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
9 changes: 9 additions & 0 deletions contracts/credit-manager/src/liquidate_astro_lp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ pub fn liquidate_astro_lp(
total_lp_amount,
)?;

// Rewards are not accounted for in the liquidation calculation (health computer includes
// only staked astro lps in HF calculation).
// Rewards could increase the HF (they increase deposit balance - collateral), but the impact
// is minimal and additional complexity is not worth it.
// We only update liquidatee's balance with rewards.
for reward in lp_position.rewards.iter() {
increment_coin_balance(deps.storage, liquidatee_account_id, reward)?;
}

// Liquidator pays down debt on behalf of liquidatee
let repay_msg =
repay_debt(deps.storage, &env, liquidator_account_id, liquidatee_account_id, &debt)?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{coins, Addr, Decimal, Uint128};
use cosmwasm_std::{coin, coins, Addr, Decimal, Uint128};
use mars_credit_manager::error::{ContractError, ContractError::NotLiquidatable};
use mars_mock_oracle::msg::CoinPrice;
use mars_testing::multitest::helpers::coin_info;
Expand Down Expand Up @@ -203,6 +203,16 @@ fn staked_lp_position_partially_liquidated() {
)
.unwrap();

// Add rewards
let astro_reward = coin(54, "uastro");
let atom_reward = coin(4, "uatom");
mock.add_astro_incentive_reward(
&liquidatee_account_id,
&uosmo_info.denom,
astro_reward.clone(),
);
mock.add_astro_incentive_reward(&liquidatee_account_id, &uosmo_info.denom, atom_reward.clone());

mock.price_change(CoinPrice {
pricing: ActionKind::Liquidation,
denom: uatom_info.denom.clone(),
Expand Down Expand Up @@ -234,11 +244,13 @@ fn staked_lp_position_partially_liquidated() {

// Assert liquidatee's new position
let position = mock.query_positions(&liquidatee_account_id);
assert_eq!(position.deposits.len(), 2);
assert_eq!(position.deposits.len(), 3);
let osmo_balance = get_coin("uosmo", &position.deposits);
assert_eq!(osmo_balance.amount, Uint128::new(600));
let atom_balance = get_coin("uatom", &position.deposits);
assert_eq!(atom_balance.amount, Uint128::new(1000));
assert_eq!(atom_balance.amount, Uint128::new(1000) + atom_reward.amount);
let astro_balance = get_coin(&astro_reward.denom, &position.deposits);
assert_eq!(astro_balance.amount, astro_reward.amount);

assert_eq!(position.debts.len(), 1);
let atom_debt = get_debt("uatom", &position.debts);
Expand Down

0 comments on commit 37611b3

Please sign in to comment.