From 151b240bc45ccf27edbba376a15c4ead6ea7ca37 Mon Sep 17 00:00:00 2001 From: eboado Date: Tue, 16 Feb 2021 11:51:06 +0100 Subject: [PATCH] - Fixed _withdraw() logic StaticAToken --- contracts/protocol/tokenization/StaticAToken.sol | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/contracts/protocol/tokenization/StaticAToken.sol b/contracts/protocol/tokenization/StaticAToken.sol index 3947f7d4..782252e4 100644 --- a/contracts/protocol/tokenization/StaticAToken.sol +++ b/contracts/protocol/tokenization/StaticAToken.sol @@ -322,12 +322,15 @@ contract StaticAToken is ERC20 { ) internal { require(recipient != address(0), 'INVALID_RECIPIENT'); - _burn(owner, amount); + uint256 userBalance = balanceOf(owner); + uint256 amountToWithdraw = (amount > userBalance) ? userBalance : amount; + + _burn(owner, amountToWithdraw); if (toUnderlying) { - LENDING_POOL.withdraw(address(ASSET), staticToDynamicAmount(amount), recipient); + LENDING_POOL.withdraw(address(ASSET), staticToDynamicAmount(amountToWithdraw), recipient); } else { - ATOKEN.safeTransfer(recipient, staticToDynamicAmount(amount)); + ATOKEN.safeTransfer(recipient, staticToDynamicAmount(amountToWithdraw)); } } }