IERC3156.sol 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. /**
  4. * @dev Interface of the ERC3156 FlashBorrower, as defined in
  5. * https://eips.ethereum.org/EIPS/eip-3156[ERC-3156].
  6. *
  7. * _Available since v4.1._
  8. */
  9. interface IERC3156FlashBorrower {
  10. /**
  11. * @dev Receive a flash loan.
  12. * @param initiator The initiator of the loan.
  13. * @param token The loan currency.
  14. * @param amount The amount of tokens lent.
  15. * @param fee The additional amount of tokens to repay.
  16. * @param data Arbitrary data structure, intended to contain user-defined parameters.
  17. * @return The keccak256 hash of "ERC3156FlashBorrower.onFlashLoan"
  18. */
  19. function onFlashLoan(
  20. address initiator,
  21. address token,
  22. uint256 amount,
  23. uint256 fee,
  24. bytes calldata data
  25. ) external returns (bytes32);
  26. }
  27. /**
  28. * @dev Interface of the ERC3156 FlashLender, as defined in
  29. * https://eips.ethereum.org/EIPS/eip-3156[ERC-3156].
  30. */
  31. interface IERC3156FlashLender {
  32. /**
  33. * @dev The amount of currency available to be lended.
  34. * @param token The loan currency.
  35. * @return The amount of `token` that can be borrowed.
  36. */
  37. function maxFlashLoan(address token) external view returns (uint256);
  38. /**
  39. * @dev The fee to be charged for a given loan.
  40. * @param token The loan currency.
  41. * @param amount The amount of tokens lent.
  42. * @return The amount of `token` to be charged for the loan, on top of the returned principal.
  43. */
  44. function flashFee(address token, uint256 amount) external view returns (uint256);
  45. /**
  46. * @dev Initiate a flash loan.
  47. * @param receiver The receiver of the tokens in the loan, and the receiver of the callback.
  48. * @param token The loan currency.
  49. * @param amount The amount of tokens lent.
  50. * @param data Arbitrary data structure, intended to contain user-defined parameters.
  51. */
  52. function flashLoan(
  53. IERC3156FlashBorrower receiver,
  54. address token,
  55. uint256 amount,
  56. bytes calldata data
  57. ) external returns (bool);
  58. }