IERC3156.sol 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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(
  38. address token
  39. ) external view returns (uint256);
  40. /**
  41. * @dev The fee to be charged for a given loan.
  42. * @param token The loan currency.
  43. * @param amount The amount of tokens lent.
  44. * @return The amount of `token` to be charged for the loan, on top of the returned principal.
  45. */
  46. function flashFee(
  47. address token,
  48. uint256 amount
  49. ) external view returns (uint256);
  50. /**
  51. * @dev Initiate a flash loan.
  52. * @param receiver The receiver of the tokens in the loan, and the receiver of the callback.
  53. * @param token The loan currency.
  54. * @param amount The amount of tokens lent.
  55. * @param data Arbitrary data structure, intended to contain user-defined parameters.
  56. */
  57. function flashLoan(
  58. IERC3156FlashBorrower receiver,
  59. address token,
  60. uint256 amount,
  61. bytes calldata data
  62. ) external returns (bool);
  63. }