Skip to content

Commit ac02550

Browse files
committed
WIP: ERC7540
1 parent 8ff78ff commit ac02550

File tree

9 files changed

+628
-272
lines changed

9 files changed

+628
-272
lines changed

contracts/interfaces/IERC4626.sol

Lines changed: 30 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
pragma solidity >=0.6.2;
55

66
import {IERC20} from "../token/ERC20/IERC20.sol";
7+
import {IERC20Vault} from "../token/ERC20/extensions/IERC20Vault.sol";
78
import {IERC20Metadata} from "../token/ERC20/extensions/IERC20Metadata.sol";
89

910
/**
1011
* @dev Interface of the ERC-4626 "Tokenized Vault Standard", as defined in
1112
* https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
1213
*/
13-
interface IERC4626 is IERC20, IERC20Metadata {
14+
interface IERC4626 is IERC20, IERC20Metadata, IERC20Vault {
1415
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
1516

1617
event Withdraw(
@@ -21,74 +22,17 @@ interface IERC4626 is IERC20, IERC20Metadata {
2122
uint256 shares
2223
);
2324

24-
/**
25-
* @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
26-
*
27-
* - MUST be an ERC-20 token contract.
28-
* - MUST NOT revert.
29-
*/
30-
function asset() external view returns (address assetTokenAddress);
31-
32-
/**
33-
* @dev Returns the total amount of the underlying asset that is “managed” by Vault.
34-
*
35-
* - SHOULD include any compounding that occurs from yield.
36-
* - MUST be inclusive of any fees that are charged against assets in the Vault.
37-
* - MUST NOT revert.
38-
*/
39-
function totalAssets() external view returns (uint256 totalManagedAssets);
40-
41-
/**
42-
* @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
43-
* scenario where all the conditions are met.
44-
*
45-
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
46-
* - MUST NOT show any variations depending on the caller.
47-
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
48-
* - MUST NOT revert.
49-
*
50-
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
51-
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
52-
* from.
53-
*/
54-
function convertToShares(uint256 assets) external view returns (uint256 shares);
55-
56-
/**
57-
* @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
58-
* scenario where all the conditions are met.
59-
*
60-
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
61-
* - MUST NOT show any variations depending on the caller.
62-
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
63-
* - MUST NOT revert.
64-
*
65-
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
66-
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
67-
* from.
68-
*/
69-
function convertToAssets(uint256 shares) external view returns (uint256 assets);
70-
71-
/**
72-
* @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
73-
* through a deposit call.
74-
*
75-
* - MUST return a limited value if receiver is subject to some deposit limit.
76-
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
77-
* - MUST NOT revert.
78-
*/
79-
function maxDeposit(address receiver) external view returns (uint256 maxAssets);
80-
8125
/**
8226
* @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
8327
* current on-chain conditions.
8428
*
85-
* - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
29+
* * MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
8630
* call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
8731
* in the same transaction.
88-
* - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
32+
* * MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
8933
* deposit would be accepted, regardless if the user has enough tokens approved, etc.
90-
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
91-
* - MUST NOT revert.
34+
* * MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
35+
* * MUST NOT revert.
9236
*
9337
* NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
9438
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
@@ -98,35 +42,27 @@ interface IERC4626 is IERC20, IERC20Metadata {
9842
/**
9943
* @dev Deposit `assets` underlying tokens and send the corresponding number of vault shares (`shares`) to `receiver`.
10044
*
101-
* - MUST emit the Deposit event.
102-
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
45+
* * MUST emit the Deposit event.
46+
* * MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
10347
* deposit execution, and are accounted for during deposit.
104-
* - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
48+
* * MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
10549
* approving enough underlying tokens to the Vault contract, etc).
10650
*
10751
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
10852
*/
10953
function deposit(uint256 assets, address receiver) external returns (uint256 shares);
11054

111-
/**
112-
* @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
113-
* - MUST return a limited value if receiver is subject to some mint limit.
114-
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
115-
* - MUST NOT revert.
116-
*/
117-
function maxMint(address receiver) external view returns (uint256 maxShares);
118-
11955
/**
12056
* @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
12157
* current on-chain conditions.
12258
*
123-
* - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
59+
* * MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
12460
* in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
12561
* same transaction.
126-
* - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
62+
* * MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
12763
* would be accepted, regardless if the user has enough tokens approved, etc.
128-
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
129-
* - MUST NOT revert.
64+
* * MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
65+
* * MUST NOT revert.
13066
*
13167
* NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
13268
* share price or some other type of condition, meaning the depositor will lose assets by minting.
@@ -136,37 +72,28 @@ interface IERC4626 is IERC20, IERC20Metadata {
13672
/**
13773
* @dev Mints exactly `shares` vault shares to `receiver` in exchange for `assets` underlying tokens.
13874
*
139-
* - MUST emit the Deposit event.
140-
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
75+
* * MUST emit the Deposit event.
76+
* * MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
14177
* execution, and are accounted for during mint.
142-
* - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
78+
* * MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
14379
* approving enough underlying tokens to the Vault contract, etc).
14480
*
14581
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
14682
*/
14783
function mint(uint256 shares, address receiver) external returns (uint256 assets);
14884

149-
/**
150-
* @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
151-
* Vault, through a withdraw call.
152-
*
153-
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
154-
* - MUST NOT revert.
155-
*/
156-
function maxWithdraw(address owner) external view returns (uint256 maxAssets);
157-
15885
/**
15986
* @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
16087
* given current on-chain conditions.
16188
*
162-
* - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
89+
* * MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
16390
* call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
16491
* called
16592
* in the same transaction.
166-
* - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
93+
* * MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
16794
* the withdrawal would be accepted, regardless if the user has enough shares, etc.
168-
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
169-
* - MUST NOT revert.
95+
* * MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
96+
* * MUST NOT revert.
17097
*
17198
* NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
17299
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
@@ -176,38 +103,28 @@ interface IERC4626 is IERC20, IERC20Metadata {
176103
/**
177104
* @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
178105
*
179-
* - MUST emit the Withdraw event.
180-
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
106+
* * MUST emit the Withdraw event.
107+
* * MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
181108
* withdraw execution, and are accounted for during withdraw.
182-
* - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
109+
* * MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
183110
* not having enough shares, etc).
184111
*
185112
* Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
186113
* Those methods should be performed separately.
187114
*/
188115
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
189116

190-
/**
191-
* @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
192-
* through a redeem call.
193-
*
194-
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
195-
* - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
196-
* - MUST NOT revert.
197-
*/
198-
function maxRedeem(address owner) external view returns (uint256 maxShares);
199-
200117
/**
201118
* @dev Allows an on-chain or off-chain user to simulate the effects of their redemption at the current block,
202119
* given current on-chain conditions.
203120
*
204-
* - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
121+
* * MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
205122
* in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
206123
* same transaction.
207-
* - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
124+
* * MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
208125
* redemption would be accepted, regardless if the user has enough shares, etc.
209-
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
210-
* - MUST NOT revert.
126+
* * MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
127+
* * MUST NOT revert.
211128
*
212129
* NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
213130
* share price or some other type of condition, meaning the depositor will lose assets by redeeming.
@@ -217,10 +134,10 @@ interface IERC4626 is IERC20, IERC20Metadata {
217134
/**
218135
* @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
219136
*
220-
* - MUST emit the Withdraw event.
221-
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
137+
* * MUST emit the Withdraw event.
138+
* * MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
222139
* redeem execution, and are accounted for during redeem.
223-
* - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
140+
* * MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
224141
* not having enough shares, etc).
225142
*
226143
* NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.

0 commit comments

Comments
 (0)