Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions contracts/red-bank/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ pub enum ContractError {
#[error("Amount to repay is greater than total debt")]
CannotRepayMoreThanDebt {},

#[error("User cannot issue liquidation of own account")]
CannotLiquidateSelf {},

#[error("User has a positive uncollateralized loan limit and thus cannot be liquidated")]
CannotLiquidateWhenPositiveUncollateralizedLoanLimit {},

Expand Down
6 changes: 6 additions & 0 deletions contracts/red-bank/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,12 @@ pub fn liquidate(
let recipient = User(&recipient_addr);

// 1. Validate liquidation

// User cannot liquidate themselves
if info.sender == user_addr {
return Err(ContractError::CannotLiquidateSelf {});
}

// If user (contract) has a positive uncollateralized limit then the user
// cannot be liquidated
if !user.uncollateralized_loan_limit(deps.storage, &debt_denom)?.is_zero() {
Expand Down
18 changes: 18 additions & 0 deletions contracts/red-bank/tests/test_liquidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,24 @@ fn liquidate_if_no_coins_sent() {
assert_eq!(error_res, PaymentError::NoFunds {}.into());
}

#[test]
fn cannot_self_liquidate() {
let TestSuite {
mut deps,
..
} = setup_test();

let env = mock_env(MockEnvParams::default());
let info = mock_info("liquidator", &[coin(100, "somecoin1")]);
let msg = ExecuteMsg::Liquidate {
user: "liquidator".to_string(),
collateral_denom: "collateral".to_string(),
recipient: None,
};
let error_res = execute(deps.as_mut(), env, info, msg).unwrap_err();
assert_eq!(error_res, ContractError::CannotLiquidateSelf {}.into());
}

#[test]
fn liquidate_if_many_coins_sent() {
let TestSuite {
Expand Down