Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unstake() fails for getting insufficient assets from AssetManager #158

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 4 additions & 5 deletions contracts/user/UserManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -717,15 +717,14 @@ contract UserManager is Controller, IUserManager, ReentrancyGuardUpgradeable {
comptroller.withdrawRewards(msg.sender, stakingToken);

uint256 remaining = IAssetManager(assetManager).withdraw(stakingToken, msg.sender, amount);
if (remaining > amount) {
if (remaining > 0) {
revert AssetManagerWithdrawFailed();
}
uint96 actualAmount = amount - remaining.toUint96();

staker.stakedAmount -= actualAmount;
totalStaked -= actualAmount;
staker.stakedAmount -= amount;
totalStaked -= amount;

emit LogUnstake(msg.sender, actualAmount);
emit LogUnstake(msg.sender, amount);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions test/foundry/userManager/TestStake.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ contract TestStakeAndUnstake is TestUserManagerBase {
abi.encodeWithSelector(AssetManager.withdraw.selector, daiMock, MEMBER, amount),
abi.encode(1 ether)
);
vm.expectRevert(UserManager.AssetManagerWithdrawFailed.selector);
userManager.unstake(amount);
uint256 stakeAmount = userManager.getStakerBalance(MEMBER);
assertEq(stakeAmount, 1 ether);
vm.stopPrank();
}
}