Add customizable fee receiver to ERC20FlashMint (#3327)
Co-authored-by: Mazen Khalil <mazen@immunityledger.org> Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
This commit is contained in:
@ -43,6 +43,16 @@ abstract contract ERC20FlashMint is ERC20, IERC3156FlashLender {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the receiver address of the flash fee. By default this
|
||||
* implementation returns the address(0) which means the fee amount will be burnt.
|
||||
* This function can be overloaded to change the fee receiver.
|
||||
* @return The address for which the flash fee will be sent to.
|
||||
*/
|
||||
function _flashFeeReceiver() internal view virtual returns (address) {
|
||||
return address(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Performs a flash loan. New tokens are minted and sent to the
|
||||
* `receiver`, who is required to implement the {IERC3156FlashBorrower}
|
||||
@ -73,8 +83,14 @@ abstract contract ERC20FlashMint is ERC20, IERC3156FlashLender {
|
||||
receiver.onFlashLoan(msg.sender, token, amount, fee, data) == _RETURN_VALUE,
|
||||
"ERC20FlashMint: invalid return value"
|
||||
);
|
||||
address flashFeeReceiver = _flashFeeReceiver();
|
||||
_spendAllowance(address(receiver), address(this), amount + fee);
|
||||
_burn(address(receiver), amount + fee);
|
||||
if (fee == 0 || flashFeeReceiver == address(0)) {
|
||||
_burn(address(receiver), amount + fee);
|
||||
} else {
|
||||
_burn(address(receiver), amount);
|
||||
_transfer(address(receiver), flashFeeReceiver, fee);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user