Skip to content
Open
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/red-bank/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "mars-red-bank"
description = "A smart contract that manages asset deposit, borrowing, and liquidations"
version = "2.3.1"
version = "2.3.2"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions contracts/red-bank/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,6 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, Co
match msg {
MigrateMsg::V2_2_0ToV2_3_0 {} => migrations::v2_3_0::migrate(deps),
MigrateMsg::V2_3_0ToV2_3_1 {} => migrations::v2_3_1::migrate(deps),
MigrateMsg::V2_3_1ToV2_3_2 {} => migrations::v2_3_2::migrate(deps),
}
}
1 change: 1 addition & 0 deletions contracts/red-bank/src/migrations/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod v2_3_0;
pub mod v2_3_1;
pub mod v2_3_2;
18 changes: 18 additions & 0 deletions contracts/red-bank/src/migrations/v2_3_2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use cosmwasm_std::{DepsMut, Response};
use cw2::{assert_contract_version, set_contract_version};

use crate::{contract::CONTRACT_NAME, error::ContractError};

pub const FROM_VERSION: &str = "2.3.1";
pub const TO_VERSION: &str = "2.3.2";

pub fn migrate(deps: DepsMut) -> Result<Response, ContractError> {
assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?;

set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), TO_VERSION)?;

Ok(Response::new()
.add_attribute("action", "migrate")
.add_attribute("from_version", FROM_VERSION)
.add_attribute("to_version", TO_VERSION))
}
2 changes: 1 addition & 1 deletion contracts/red-bank/src/withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn withdraw(
// Query params to verify we can withdraw
let asset_params = query_asset_params(&deps.querier, params_addr, &denom)?;

if !asset_params.red_bank.withdraw_enabled {
if !asset_params.red_bank.withdraw_enabled && !liquidation_related {
return Err(ContractError::WithdrawNotEnabled {
denom,
});
Expand Down
39 changes: 39 additions & 0 deletions contracts/red-bank/tests/tests/test_liquidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,45 @@ fn cannot_liquidate_healthy_position() {
assert_err(error_res, ContractError::CannotLiquidateHealthyPosition {});
}

#[test]
fn can_liquidate_when_withdraw_disabled() {
let mut mock_env = MockEnvBuilder::new(None, Addr::unchecked("owner"))
.target_health_factor(Decimal::from_ratio(12u128, 10u128))
.build();

let red_bank = mock_env.red_bank.clone();
let oracle = mock_env.oracle.clone();
let params = mock_env.params.clone();

let (_funded_amt, _provider, liquidatee, liquidator) = setup_env(&mut mock_env);

// disable withdraw for the collateral asset
let mut osmo_params = params.query_params(&mut mock_env, "uosmo");
osmo_params.red_bank.withdraw_enabled = false;
params.init_params(&mut mock_env, osmo_params);

// withdrawing should be blocked
assert_err(
red_bank.withdraw(&mut mock_env, &liquidatee, "uosmo", Some(Uint128::new(1))),
ContractError::WithdrawNotEnabled {
denom: "uosmo".to_string(),
},
);

// make position liquidatable
oracle.set_price_source_fixed(&mut mock_env, "uusdc", Decimal::from_ratio(68u128, 10u128));

let debt_before = red_bank.query_user_debt(&mut mock_env, &liquidatee, "uusdc").amount;

red_bank
.liquidate(&mut mock_env, &liquidator, &liquidatee, "uosmo", &[coin(120, "uusdc")])
.unwrap();

let debt_after = red_bank.query_user_debt(&mut mock_env, &liquidatee, "uusdc").amount;

assert!(debt_after < debt_before);
}

#[test]
fn max_debt_repayed() {
let mut mock_env = MockEnvBuilder::new(None, Addr::unchecked("owner"))
Expand Down
54 changes: 54 additions & 0 deletions contracts/red-bank/tests/tests/test_migration_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,57 @@ fn v2_3_0_to_v2_3_1_successful_migration() {
};
assert_eq!(cw2::get_contract_version(deps.as_ref().storage).unwrap(), new_contract_version);
}

#[test]
fn v2_3_1_to_v2_3_2_wrong_contract_name() {
let mut deps = mock_dependencies(&[]);
cw2::set_contract_version(deps.as_mut().storage, "contract_xyz", "2.3.1").unwrap();

let err = migrate(deps.as_mut(), mock_env(), MigrateMsg::V2_3_1ToV2_3_2 {}).unwrap_err();

assert_eq!(
err,
ContractError::Version(VersionError::WrongContract {
expected: "crates.io:mars-red-bank".to_string(),
found: "contract_xyz".to_string()
})
);
}

#[test]
fn v2_3_1_to_v2_3_2_wrong_contract_version() {
let mut deps = mock_dependencies(&[]);
cw2::set_contract_version(deps.as_mut().storage, "crates.io:mars-red-bank", "2.3.0").unwrap();

let err = migrate(deps.as_mut(), mock_env(), MigrateMsg::V2_3_1ToV2_3_2 {}).unwrap_err();

assert_eq!(
err,
ContractError::Version(VersionError::WrongVersion {
expected: "2.3.1".to_string(),
found: "2.3.0".to_string()
})
);
}

#[test]
fn v2_3_1_to_v2_3_2_successful_migration() {
let mut deps = mock_dependencies(&[]);
cw2::set_contract_version(deps.as_mut().storage, "crates.io:mars-red-bank", "2.3.1").unwrap();

let res = migrate(deps.as_mut(), mock_env(), MigrateMsg::V2_3_1ToV2_3_2 {}).unwrap();

assert_eq!(res.messages, vec![]);
assert_eq!(res.events, vec![] as Vec<Event>);
assert!(res.data.is_none());
assert_eq!(
res.attributes,
vec![attr("action", "migrate"), attr("from_version", "2.3.1"), attr("to_version", "2.3.2")]
);

let new_contract_version = ContractVersion {
contract: "crates.io:mars-red-bank".to_string(),
version: "2.3.2".to_string(),
};
assert_eq!(cw2::get_contract_version(deps.as_ref().storage).unwrap(), new_contract_version);
}
1 change: 1 addition & 0 deletions packages/types/src/red_bank/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,5 @@ pub enum QueryMsg {
pub enum MigrateMsg {
V2_2_0ToV2_3_0 {},
V2_3_0ToV2_3_1 {},
V2_3_1ToV2_3_2 {},
}
2 changes: 1 addition & 1 deletion schemas/mars-red-bank/mars-red-bank.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "mars-red-bank",
"contract_version": "2.3.1",
"contract_version": "2.3.2",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
Loading