IERC4626.sol 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC4626.sol)
  3. pragma solidity ^0.8.0;
  4. import "../token/ERC20/IERC20.sol";
  5. import "../token/ERC20/extensions/IERC20Metadata.sol";
  6. /**
  7. * @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in
  8. * https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
  9. *
  10. * _Available since v4.7._
  11. */
  12. interface IERC4626 is IERC20, IERC20Metadata {
  13. event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
  14. event Withdraw(
  15. address indexed sender,
  16. address indexed receiver,
  17. address indexed owner,
  18. uint256 assets,
  19. uint256 shares
  20. );
  21. /**
  22. * @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
  23. *
  24. * - MUST be an ERC-20 token contract.
  25. * - MUST NOT revert.
  26. */
  27. function asset() external view returns (address assetTokenAddress);
  28. /**
  29. * @dev Returns the total amount of the underlying asset that is “managed” by Vault.
  30. *
  31. * - SHOULD include any compounding that occurs from yield.
  32. * - MUST be inclusive of any fees that are charged against assets in the Vault.
  33. * - MUST NOT revert.
  34. */
  35. function totalAssets() external view returns (uint256 totalManagedAssets);
  36. /**
  37. * @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
  38. * scenario where all the conditions are met.
  39. *
  40. * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
  41. * - MUST NOT show any variations depending on the caller.
  42. * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
  43. * - MUST NOT revert.
  44. *
  45. * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
  46. * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
  47. * from.
  48. */
  49. function convertToShares(uint256 assets) external view returns (uint256 shares);
  50. /**
  51. * @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
  52. * scenario where all the conditions are met.
  53. *
  54. * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
  55. * - MUST NOT show any variations depending on the caller.
  56. * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
  57. * - MUST NOT revert.
  58. *
  59. * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
  60. * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
  61. * from.
  62. */
  63. function convertToAssets(uint256 shares) external view returns (uint256 assets);
  64. /**
  65. * @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
  66. * through a deposit call.
  67. *
  68. * - MUST return a limited value if receiver is subject to some deposit limit.
  69. * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
  70. * - MUST NOT revert.
  71. */
  72. function maxDeposit(address receiver) external view returns (uint256 maxAssets);
  73. /**
  74. * @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
  75. * current on-chain conditions.
  76. *
  77. * - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
  78. * call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
  79. * in the same transaction.
  80. * - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
  81. * deposit would be accepted, regardless if the user has enough tokens approved, etc.
  82. * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
  83. * - MUST NOT revert.
  84. *
  85. * NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
  86. * share price or some other type of condition, meaning the depositor will lose assets by depositing.
  87. */
  88. function previewDeposit(uint256 assets) external view returns (uint256 shares);
  89. /**
  90. * @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
  91. *
  92. * - MUST emit the Deposit event.
  93. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
  94. * deposit execution, and are accounted for during deposit.
  95. * - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
  96. * approving enough underlying tokens to the Vault contract, etc).
  97. *
  98. * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
  99. */
  100. function deposit(uint256 assets, address receiver) external returns (uint256 shares);
  101. /**
  102. * @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
  103. * - MUST return a limited value if receiver is subject to some mint limit.
  104. * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
  105. * - MUST NOT revert.
  106. */
  107. function maxMint(address receiver) external view returns (uint256 maxShares);
  108. /**
  109. * @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
  110. * current on-chain conditions.
  111. *
  112. * - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
  113. * in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
  114. * same transaction.
  115. * - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
  116. * would be accepted, regardless if the user has enough tokens approved, etc.
  117. * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
  118. * - MUST NOT revert.
  119. *
  120. * NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
  121. * share price or some other type of condition, meaning the depositor will lose assets by minting.
  122. */
  123. function previewMint(uint256 shares) external view returns (uint256 assets);
  124. /**
  125. * @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
  126. *
  127. * - MUST emit the Deposit event.
  128. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
  129. * execution, and are accounted for during mint.
  130. * - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
  131. * approving enough underlying tokens to the Vault contract, etc).
  132. *
  133. * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
  134. */
  135. function mint(uint256 shares, address receiver) external returns (uint256 assets);
  136. /**
  137. * @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
  138. * Vault, through a withdraw call.
  139. *
  140. * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
  141. * - MUST NOT revert.
  142. */
  143. function maxWithdraw(address owner) external view returns (uint256 maxAssets);
  144. /**
  145. * @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
  146. * given current on-chain conditions.
  147. *
  148. * - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
  149. * call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
  150. * called
  151. * in the same transaction.
  152. * - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
  153. * the withdrawal would be accepted, regardless if the user has enough shares, etc.
  154. * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
  155. * - MUST NOT revert.
  156. *
  157. * NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
  158. * share price or some other type of condition, meaning the depositor will lose assets by depositing.
  159. */
  160. function previewWithdraw(uint256 assets) external view returns (uint256 shares);
  161. /**
  162. * @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
  163. *
  164. * - MUST emit the Withdraw event.
  165. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
  166. * withdraw execution, and are accounted for during withdraw.
  167. * - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
  168. * not having enough shares, etc).
  169. *
  170. * Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
  171. * Those methods should be performed separately.
  172. */
  173. function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
  174. /**
  175. * @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
  176. * through a redeem call.
  177. *
  178. * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
  179. * - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
  180. * - MUST NOT revert.
  181. */
  182. function maxRedeem(address owner) external view returns (uint256 maxShares);
  183. /**
  184. * @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,
  185. * given current on-chain conditions.
  186. *
  187. * - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
  188. * in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
  189. * same transaction.
  190. * - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
  191. * redemption would be accepted, regardless if the user has enough shares, etc.
  192. * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
  193. * - MUST NOT revert.
  194. *
  195. * NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
  196. * share price or some other type of condition, meaning the depositor will lose assets by redeeming.
  197. */
  198. function previewRedeem(uint256 shares) external view returns (uint256 assets);
  199. /**
  200. * @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
  201. *
  202. * - MUST emit the Withdraw event.
  203. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
  204. * redeem execution, and are accounted for during redeem.
  205. * - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
  206. * not having enough shares, etc).
  207. *
  208. * NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
  209. * Those methods should be performed separately.
  210. */
  211. function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
  212. }