Use _spendAllowance in ERC20FlashMint (#3226)

Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
This commit is contained in:
Hadrien Croubois
2022-03-08 20:34:24 +01:00
committed by GitHub
parent 212221d6ff
commit f8bfa560e9
3 changed files with 3 additions and 4 deletions

View File

@ -73,9 +73,7 @@ abstract contract ERC20FlashMint is ERC20, IERC3156FlashLender {
receiver.onFlashLoan(msg.sender, token, amount, fee, data) == _RETURN_VALUE,
"ERC20FlashMint: invalid return value"
);
uint256 currentAllowance = allowance(address(receiver), address(this));
require(currentAllowance >= amount + fee, "ERC20FlashMint: allowance does not allow refund");
_approve(address(receiver), address(this), currentAllowance - amount - fee);
_spendAllowance(address(receiver), address(this), amount + fee);
_burn(address(receiver), amount + fee);
return true;
}