diff --git a/contracts/credit/CreditManagerV3.sol b/contracts/credit/CreditManagerV3.sol index 43c20c11..b1e47862 100644 --- a/contracts/credit/CreditManagerV3.sol +++ b/contracts/credit/CreditManagerV3.sol @@ -1016,9 +1016,7 @@ contract CreditManagerV3 is ICreditManagerV3, SanityCheckTrait, ReentrancyGuard, uint256 balanceBefore = _balanceOf(token, address(withdrawalManager)); _creditAccountSafeTransfer(creditAccount, token, address(withdrawalManager), amount); amount = _balanceOf(token, address(withdrawalManager)) - balanceBefore; - if (amount > 1) { - withdrawalManager.addImmediateWithdrawal(to, token, amount); - } + withdrawalManager.addImmediateWithdrawal(to, token, amount); } } } diff --git a/contracts/interfaces/IWithdrawalManager.sol b/contracts/interfaces/IWithdrawalManager.sol index a81287c6..714a8a38 100644 --- a/contracts/interfaces/IWithdrawalManager.sol +++ b/contracts/interfaces/IWithdrawalManager.sol @@ -76,7 +76,6 @@ interface IWithdrawalManager is IWithdrawalManagerEvents, IVersion { /// @param account Account to add immediate withdrawal for /// @param token Token to withdraw /// @param amount Amount to withdraw - /// @custom:expects `amount` is greater than 1 /// @custom:expects Credit manager transferred `amount` of `token` to this contract prior to calling this function function addImmediateWithdrawal(address account, address token, uint256 amount) external; diff --git a/contracts/support/WithdrawalManager.sol b/contracts/support/WithdrawalManager.sol index 833f4998..837ebb13 100644 --- a/contracts/support/WithdrawalManager.sol +++ b/contracts/support/WithdrawalManager.sol @@ -22,10 +22,11 @@ import {ACLTrait} from "../traits/ACLTrait.sol"; /// There are two kinds of withdrawals: immediate and scheduled. /// - Immediate withdrawals can be claimed, well, immediately, and exist to support liquidation of accounts /// whose owners are blacklisted in credit manager's underlying. +/// Also, when scheduled withdrawals are claimed, they turn into immediate withdrawals. /// - Scheduled withdrawals can be claimed after a certain delay, and exist to support partial withdrawals /// from credit accounts. One credit account can have up to two immature withdrawals at the same time. /// Additional rules for scheduled withdrawals: -/// + if account is closed, both mature and immature withdrawals are claimed (turned into immediate withdrawals) +/// + if account is closed, both mature and immature withdrawals are claimed /// + if account is liquidated, immature withdrawals are cancelled and mature ones are claimed /// + if account is liquidated in emergency mode, both mature and immature withdrawals are cancelled /// + in emergency mode, claiming is disabled @@ -91,8 +92,10 @@ contract WithdrawalManager is IWithdrawalManager, ACLTrait { /// @dev Increases account's immediately withdrawable balance of token function _addImmediateWithdrawal(address account, address token, uint256 amount) internal { - immediateWithdrawals[account][token] += amount; - emit AddImmediateWithdrawal(account, token, amount); + if (amount > 1) { + immediateWithdrawals[account][token] += amount; + emit AddImmediateWithdrawal(account, token, amount); + } } /// --------------------- ///