diff --git a/src/BaseKeeper.sol b/src/BaseKeeper.sol index 9b0a012..3aa9659 100644 --- a/src/BaseKeeper.sol +++ b/src/BaseKeeper.sol @@ -223,12 +223,16 @@ contract BaseKeeper is Ownable, ReentrancyGuard { depositAmount += deposits[i].amount; } } - if (withdrawAmount > 0) { + if (withdrawAmount > 0 && depositAmount == 0) { sortedWithdraws[sortedWithdrawIndex++] = Withdraw(j, withdrawAmount); - } - if (depositAmount > 0) { + } else if (depositAmount > 0 && withdrawAmount == 0) { sortedDeposits[sortedDepositIndex++] = Deposit(j, depositAmount); + } else if (withdrawAmount > depositAmount) { + sortedWithdraws[sortedWithdrawIndex++] = Withdraw(j, withdrawAmount - depositAmount); + } else if (depositAmount > withdrawAmount) { + sortedDeposits[sortedDepositIndex++] = Deposit(j, depositAmount - withdrawAmount); } + } Withdraw[] memory finalWithdraws = new Withdraw[](sortedWithdrawIndex);