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
4 changes: 4 additions & 0 deletions contracts/SDUtilityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ contract SDUtilityPool is ISDUtilityPool, AccessControlUpgradeable, PausableUpgr
uint256 exchangeRate = _exchangeRateStored();
delegatorCTokenBalance[msg.sender] -= _cTokenAmount;
delegatorWithdrawRequestedCTokenCount[msg.sender] += _cTokenAmount;

if(delegatorCTokenBalance[msg.sender] * exchangeRate / DECIMAL < MIN_SD_DELEGATE_LIMIT)
revert InvalidInput();

uint256 sdRequested = (exchangeRate * _cTokenAmount) / DECIMAL;
if (sdRequested < MIN_SD_WITHDRAW_LIMIT) {
revert InvalidInput();
Expand Down
21 changes: 21 additions & 0 deletions test/foundry_tests/SDUtilityPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -849,4 +849,25 @@ contract SDUtilityPoolTest is Test {
userData = sdUtilityPool.getUserData(operator);
assertEq(0, userData.totalInterestSD);
}
function test_leftOverCannotBeLessThanMinAmount() public {
address user = address(0xBAD);
deal(address(staderToken), staderAdmin, type(uint).max);
// Give tokens to participants
vm.prank(staderAdmin);
staderToken.transfer(user, 1_000_001e18);

vm.startPrank(user);
staderToken.approve(address(sdUtilityPool), 1e15);
sdUtilityPool.delegate(1e15);

uint256 userCTokens = sdUtilityPool.delegatorCTokenBalance(user);
assertEq(userCTokens, 1e15);
vm.stopPrank();

vm.startPrank(user);
uint256 withdrawAmount = 1e15 - 1; // All but 1 wei
vm.expectRevert();
uint256 requestId = sdUtilityPool.requestWithdraw(withdrawAmount);

}
}