IERC4626.sol 12 KB

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