IERC3156.sol 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. interface IERC3156FlashBorrower {
  8. /**
  9. * @dev Receive a flash loan.
  10. * @param initiator The initiator of the loan.
  11. * @param token The loan currency.
  12. * @param amount The amount of tokens lent.
  13. * @param fee The additional amount of tokens to repay.
  14. * @param data Arbitrary data structure, intended to contain user-defined parameters.
  15. * @return The keccak256 hash of "ERC3156FlashBorrower.onFlashLoan"
  16. */
  17. function onFlashLoan(
  18. address initiator,
  19. address token,
  20. uint256 amount,
  21. uint256 fee,
  22. bytes calldata data
  23. ) external returns (bytes32);
  24. }
  25. /**
  26. * @dev Interface of the ERC3156 FlashLender, as defined in
  27. * https://eips.ethereum.org/EIPS/eip-3156[ERC-3156].
  28. */
  29. interface IERC3156FlashLender {
  30. /**
  31. * @dev The amount of currency available to be lended.
  32. * @param token The loan currency.
  33. * @return The amount of `token` that can be borrowed.
  34. */
  35. function maxFlashLoan(
  36. address token
  37. ) 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(
  45. address token,
  46. uint256 amount
  47. ) external view returns (uint256);
  48. /**
  49. * @dev Initiate a flash loan.
  50. * @param receiver The receiver of the tokens in the loan, and the receiver of the callback.
  51. * @param token The loan currency.
  52. * @param amount The amount of tokens lent.
  53. * @param data Arbitrary data structure, intended to contain user-defined parameters.
  54. */
  55. function flashLoan(
  56. IERC3156FlashBorrower receiver,
  57. address token,
  58. uint256 amount,
  59. bytes calldata data
  60. ) external returns (bool);
  61. }