IERC4626.sol 12 KB

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