Skip to content

Commit

Permalink
Rename ERC20TokenizedVault to ERC4626 (#3467)
Browse files Browse the repository at this point in the history
(cherry picked from commit a55b7d1)
Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com>
  • Loading branch information
Amxx committed Jun 14, 2022
1 parent e30ea41 commit 80c7a3e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* `TimelockController`: Migrate `_call` to `_execute` and allow inheritance and overriding similar to `Governor`. ([#3317](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3317))
* `CrossChainEnabledPolygonChild`: replace the `require` statement with the custom error `NotCrossChainCall`. ([#3380](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3380))
* `ERC20FlashMint`: Add customizable flash fee receiver. ([#3327](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3327))
* `ERC20TokenizedVault`: add an extension of `ERC20` that implements the ERC4626 Tokenized Vault Standard. ([#3171](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3171))
* `ERC4626`: add an extension of `ERC20` that implements the ERC4626 Tokenized Vault Standard. ([#3171](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3171))
* `SafeERC20`: add `safePermit` as mitigation against phantom permit functions. ([#3280](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3280))
* `Math`: add a `mulDiv` function that can round the result either up or down. ([#3171](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3171))
* `Math`: Add a `sqrt` function to compute square roots of integers, rounding either up or down. ([#3242](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3242))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

pragma solidity ^0.8.0;

import "../token/ERC20/extensions/ERC20TokenizedVault.sol";
import "../token/ERC20/extensions/ERC4626.sol";

// mock class using ERC20
contract ERC20TokenizedVaultMock is ERC20TokenizedVault {
contract ERC4626Mock is ERC4626 {
constructor(
IERC20Metadata asset,
string memory name,
string memory symbol
) ERC20(name, symbol) ERC20TokenizedVault(asset) {}
) ERC20(name, symbol) ERC4626(asset) {}

function mockMint(address account, uint256 amount) public {
_mint(account, amount);
Expand Down
4 changes: 2 additions & 2 deletions contracts/token/ERC20/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Additionally there are multiple custom extensions, including:
* {ERC20Votes}: support for voting and vote delegation.
* {ERC20VotesComp}: support for voting and vote delegation (compatible with Compound's token, with uint96 restrictions).
* {ERC20Wrapper}: wrapper to create an ERC20 backed by another ERC20, with deposit and withdraw methods. Useful in conjunction with {ERC20Votes}.
* {ERC20TokenizedVault}: tokenized vault that manages shares (represented as ERC20) that are backed by assets (another ERC20).
* {ERC4626}: tokenized vault that manages shares (represented as ERC20) that are backed by assets (another ERC20).
Finally, there are some utilities to interact with ERC20 contracts in various ways.

Expand Down Expand Up @@ -63,7 +63,7 @@ NOTE: This core set of contracts is designed to be unopinionated, allowing devel

{{ERC20FlashMint}}

{{ERC20TokenizedVault}}
{{ERC4626}}

== Draft EIPs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import "../../../utils/math/Math.sol";
*
* _Available since v4.7._
*/
abstract contract ERC20TokenizedVault is ERC20, IERC4626 {
abstract contract ERC4626 is ERC20, IERC4626 {
using Math for uint256;

IERC20Metadata private immutable _asset;
Expand Down Expand Up @@ -93,7 +93,7 @@ abstract contract ERC20TokenizedVault is ERC20, IERC4626 {

/** @dev See {IERC4262-deposit} */
function deposit(uint256 assets, address receiver) public virtual override returns (uint256) {
require(assets <= maxDeposit(receiver), "ERC20TokenizedVault: deposit more than max");
require(assets <= maxDeposit(receiver), "ERC4626: deposit more than max");

uint256 shares = previewDeposit(assets);
_deposit(_msgSender(), receiver, assets, shares);
Expand All @@ -103,7 +103,7 @@ abstract contract ERC20TokenizedVault is ERC20, IERC4626 {

/** @dev See {IERC4262-mint} */
function mint(uint256 shares, address receiver) public virtual override returns (uint256) {
require(shares <= maxMint(receiver), "ERC20TokenizedVault: mint more than max");
require(shares <= maxMint(receiver), "ERC4626: mint more than max");

uint256 assets = previewMint(shares);
_deposit(_msgSender(), receiver, assets, shares);
Expand All @@ -117,7 +117,7 @@ abstract contract ERC20TokenizedVault is ERC20, IERC4626 {
address receiver,
address owner
) public virtual override returns (uint256) {
require(assets <= maxWithdraw(owner), "ERC20TokenizedVault: withdraw more than max");
require(assets <= maxWithdraw(owner), "ERC4626: withdraw more than max");

uint256 shares = previewWithdraw(assets);
_withdraw(_msgSender(), receiver, owner, assets, shares);
Expand All @@ -131,7 +131,7 @@ abstract contract ERC20TokenizedVault is ERC20, IERC4626 {
address receiver,
address owner
) public virtual override returns (uint256) {
require(shares <= maxRedeem(owner), "ERC20TokenizedVault: redeem more than max");
require(shares <= maxRedeem(owner), "ERC4626: redeem more than max");

uint256 assets = previewRedeem(shares);
_withdraw(_msgSender(), receiver, owner, assets, shares);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ const { BN, constants, expectEvent, expectRevert } = require('@openzeppelin/test
const { expect } = require('chai');

const ERC20DecimalsMock = artifacts.require('ERC20DecimalsMock');
const ERC20TokenizedVaultMock = artifacts.require('ERC20TokenizedVaultMock');
const ERC4626Mock = artifacts.require('ERC4626Mock');

const parseToken = (token) => (new BN(token)).mul(new BN('1000000000000'));
const parseShare = (share) => (new BN(share)).mul(new BN('1000000000000000000'));

contract('ERC20TokenizedVault', function (accounts) {
contract('ERC4626', function (accounts) {
const [ holder, recipient, spender, other, user1, user2 ] = accounts;

const name = 'My Token';
const symbol = 'MTKN';

beforeEach(async function () {
this.token = await ERC20DecimalsMock.new(name, symbol, 12);
this.vault = await ERC20TokenizedVaultMock.new(this.token.address, name + ' Vault', symbol + 'V');
this.vault = await ERC4626Mock.new(this.token.address, name + ' Vault', symbol + 'V');

await this.token.mint(holder, web3.utils.toWei('100'));
await this.token.approve(this.vault.address, constants.MAX_UINT256, { from: holder });
Expand Down Expand Up @@ -227,7 +227,7 @@ contract('ERC20TokenizedVault', function (accounts) {
await expectRevert.unspecified(this.vault.previewDeposit(parseToken(1)));
await expectRevert(
this.vault.deposit(parseToken(1), recipient, { from: holder }),
'ERC20TokenizedVault: deposit more than max',
'ERC4626: deposit more than max',
);
});

Expand Down Expand Up @@ -400,7 +400,7 @@ contract('ERC20TokenizedVault', function (accounts) {
it('multiple mint, deposit, redeem & withdrawal', async function () {
// test designed with both asset using similar decimals
this.token = await ERC20DecimalsMock.new(name, symbol, 18);
this.vault = await ERC20TokenizedVaultMock.new(this.token.address, name + ' Vault', symbol + 'V');
this.vault = await ERC4626Mock.new(this.token.address, name + ' Vault', symbol + 'V');

await this.token.mint(user1, 4000);
await this.token.mint(user2, 7001);
Expand Down

0 comments on commit 80c7a3e

Please sign in to comment.