ERC20FlashMintLib
Title: ERC20FlashMintLib
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC20FlashMint.sol)
Library implementing the ERC-3156 flash-mint extension for ERC-20. Adds no own storage.
The token itself is the flash lender: principal is minted to the borrower for the duration of the call
and burned at the end, or the whole call reverts. The fee is fixed at 0 and the fee receiver at
address(0) (fee burned) — Lattice keeps all logic in the library, so OZ's virtual fee overrides are
not available; a fee-charging variant would be a separate library/configuration.
The flash mint and burn call ERC20Lib directly: an ERC-20 movement-replacing extension (ERC20Pausable,
ERC20Votes) does not see them, so the two are mutually exclusive (D25, #234).
Functions
__ERC20FlashMint_init
Registers the IERC3156FlashLender interface for ERC-165 discovery.
Must be called inside a pre/postInitializer block. No own storage to initialize.
function __ERC20FlashMint_init() internal;registerInterface
Registers support for the IERC3156FlashLender interface via ERC-165.
function registerInterface() internal;maxFlashLoan
The maximum loan available: the whole remaining uint256 headroom of the supply, or 0 for other tokens.
function maxFlashLoan(address token) internal view returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| token | address |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
flashFee
The fee charged for a flash loan — always 0 here; reverts for an unsupported token.
function flashFee(
address token,
uint256 /*value*/
)
internal
view
returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| token | address | |
| _ | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
flashLoan
Performs a flash loan: mint value to receiver, run the callback, then pull back and burn it.
Reenters safely: the minted amount is always recovered and burned by the end, or the call reverts.
function flashLoan(IERC3156FlashBorrower receiver, address token, uint256 value, bytes calldata data)
internal
returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| receiver | IERC3156FlashBorrower | |
| token | address | |
| value | uint256 | |
| data | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |