Skip to content

Commit

Permalink
fix: unstake exact
Browse files Browse the repository at this point in the history
  • Loading branch information
markonmars committed Jun 21, 2024
1 parent cf750ee commit 1823f97
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion contracts/credit-manager/src/unstake_astro_lp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn unstake_lp(
available: lp_position.lp_coin.amount,
});
} else {
lp_position.lp_coin.amount.checked_sub(amt)?
amt
}
}
ActionAmount::AccountBalance => lp_position.lp_coin.amount,
Expand Down
9 changes: 6 additions & 3 deletions contracts/credit-manager/tests/tests/test_unstake_astro_lp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn unstake() {
let mut mock = MockEnv::new()
.fund_account(AccountToFund {
addr: user.clone(),
funds: coins(100, lp_denom),
funds: coins(200, lp_denom),
})
.build()
.unwrap();
Expand All @@ -60,7 +60,7 @@ fn unstake() {

let lp_coin = Coin {
denom: lp_denom.to_string(),
amount: Uint128::new(100),
amount: Uint128::new(200),
};

// stake
Expand Down Expand Up @@ -93,11 +93,14 @@ fn unstake() {

let positions = mock.query_positions(&account_id);
assert_eq!(positions.staked_astro_lps.len(), 1);
assert_eq!(positions.staked_astro_lps[0].denom, lp_denom.to_string());
assert_eq!(positions.staked_astro_lps[0].amount, Uint128::new(150));
assert_eq!(positions.deposits[0].denom, lp_denom.to_string());
assert_eq!(positions.deposits[0].amount, Uint128::new(50));

// Assert correct lp balance in contract
let cm_lp_coin = mock.query_balance(&mock.rover, lp_denom);
assert_eq!(positions.deposits[0].denom, cm_lp_coin.denom);
assert_eq!(positions.deposits[0].amount, cm_lp_coin.amount);

// Entire remaining amount
Expand All @@ -118,7 +121,7 @@ fn unstake() {
assert_eq!(positions.staked_astro_lps.len(), 0);
assert_eq!(positions.deposits.len(), 1);
assert_eq!(positions.deposits[0].denom, lp_denom.to_string());
assert_eq!(positions.deposits[0].amount, Uint128::new(100));
assert_eq!(positions.deposits[0].amount, Uint128::new(200));

// Assert correct lp balance in contract
let cm_lp_coin = mock.query_balance(&mock.rover, lp_denom);
Expand Down

0 comments on commit 1823f97

Please sign in to comment.