Skip to content

Commit

Permalink
Merge pull request #2 from euler-xyz/remove-erc20-collateral
Browse files Browse the repository at this point in the history
Remove ERC20Collateral, add ERC20EVCCompatible
  • Loading branch information
dglowinski authored Jul 31, 2024
2 parents 3c79e34 + aa8db73 commit 7d23acc
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 103 deletions.
4 changes: 2 additions & 2 deletions docs/specs.md

Large diffs are not rendered by default.

74 changes: 0 additions & 74 deletions src/Synths/ERC20Collateral.sol

This file was deleted.

28 changes: 28 additions & 0 deletions src/Synths/ERC20EVCCompatible.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {ERC20, Context} from "openzeppelin-contracts/token/ERC20/ERC20.sol";
import {ERC20Permit} from "openzeppelin-contracts/token/ERC20/extensions/ERC20Permit.sol";
import {EVCUtil} from "ethereum-vault-connector/utils/EVCUtil.sol";

/// @title ERC20EVCCompatible
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice ERC20EVCCompatible is an ERC20-compatible token with the EVC support.
abstract contract ERC20EVCCompatible is EVCUtil, ERC20Permit {
constructor(address _evc_, string memory _name_, string memory _symbol_)
EVCUtil(_evc_)
ERC20(_name_, _symbol_)
ERC20Permit(_name_)
{}

/// @notice Retrieves the message sender in the context of the EVC.
/// @dev Overriden due to the conflict with the Context definition.
/// @dev This function returns the account on behalf of which the current operation is being performed, which is
/// either msg.sender or the account authenticated by the EVC.
/// @return The address of the message sender.
function _msgSender() internal view virtual override (EVCUtil, Context) returns (address) {
return EVCUtil._msgSender();
}
}
22 changes: 10 additions & 12 deletions src/Synths/ESynth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ pragma solidity ^0.8.0;

import {Ownable} from "openzeppelin-contracts/access/Ownable.sol";
import {EnumerableSet} from "openzeppelin-contracts/utils/structs/EnumerableSet.sol";
import {IEVC, EVCUtil} from "ethereum-vault-connector/utils/EVCUtil.sol";
import {ERC20Collateral, ERC20, Context} from "./ERC20Collateral.sol";
import {ERC20EVCCompatible, Context} from "./ERC20EVCCompatible.sol";
import {IEVault} from "../EVault/IEVault.sol";

/// @title ESynth
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice ESynth is an ERC20-compatible token with the EVC support which, thanks to relying on the EVC authentication
/// and requesting the account status checks on token transfers and burns, allows it to be used as collateral in other
/// vault. It is meant to be used as an underlying asset of the synthetic asset vault.
contract ESynth is ERC20Collateral, Ownable {
/// @notice ESynth is an ERC20-compatible token with the EVC support. It is meant to be used as an underlying asset of
/// the synthetic asset vault.
contract ESynth is ERC20EVCCompatible, Ownable {
using EnumerableSet for EnumerableSet.AddressSet;

struct MinterData {
Expand All @@ -35,8 +33,8 @@ contract ESynth is ERC20Collateral, Ownable {
error E_CapacityReached();
error E_NotEVCCompatible();

constructor(IEVC evc_, string memory name_, string memory symbol_)
ERC20Collateral(evc_, name_, symbol_)
constructor(address evc_, string memory name_, string memory symbol_)
ERC20EVCCompatible(evc_, name_, symbol_)
Ownable(msg.sender)
{
ignoredForTotalSupply.add(address(this));
Expand All @@ -54,7 +52,7 @@ contract ESynth is ERC20Collateral, Ownable {
/// @notice Mints a certain amount of tokens to the account.
/// @param account The account to mint the tokens to.
/// @param amount The amount of tokens to mint.
function mint(address account, uint256 amount) external nonReentrant {
function mint(address account, uint256 amount) external {
address sender = _msgSender();
MinterData memory minterCache = minters[sender];

Expand All @@ -80,7 +78,7 @@ contract ESynth is ERC20Collateral, Ownable {
/// have an allowance for the sender.
/// @param burnFrom The account to burn the tokens from.
/// @param amount The amount of tokens to burn.
function burn(address burnFrom, uint256 amount) external nonReentrant {
function burn(address burnFrom, uint256 amount) external {
address sender = _msgSender();
MinterData memory minterCache = minters[sender];

Expand Down Expand Up @@ -129,8 +127,8 @@ contract ESynth is ERC20Collateral, Ownable {
/// @dev This function returns the account on behalf of which the current operation is being performed, which is
/// either msg.sender or the account authenticated by the EVC.
/// @return msgSender The address of the message sender.
function _msgSender() internal view virtual override (ERC20Collateral, Context) returns (address msgSender) {
return ERC20Collateral._msgSender();
function _msgSender() internal view virtual override (ERC20EVCCompatible, Context) returns (address msgSender) {
return ERC20EVCCompatible._msgSender();
}

// -------- TotalSupply Management --------
Expand Down
5 changes: 2 additions & 3 deletions src/Synths/EulerSavingsRate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {Math} from "openzeppelin-contracts/utils/math/Math.sol";
import {IERC20} from "openzeppelin-contracts/token/ERC20/IERC20.sol";
import {ERC20} from "openzeppelin-contracts/token/ERC20/ERC20.sol";
import {ERC4626} from "openzeppelin-contracts/token/ERC20/extensions/ERC4626.sol";
import {IEVC} from "ethereum-vault-connector/interfaces/IEthereumVaultConnector.sol";
import {EVCUtil} from "ethereum-vault-connector/utils/EVCUtil.sol";

/// @title EulerSavingsRate
Expand Down Expand Up @@ -54,8 +53,8 @@ contract EulerSavingsRate is EVCUtil, ERC4626 {
esrSlot.locked = UNLOCKED;
}

constructor(IEVC _evc, address _asset, string memory _name, string memory _symbol)
EVCUtil(address(_evc))
constructor(address _evc, address _asset, string memory _name, string memory _symbol)
EVCUtil(_evc)
ERC4626(IERC20(_asset))
ERC20(_name, _symbol)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Synths/PegStabilityModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity ^0.8.0;

import {EVCUtil, IEVC} from "ethereum-vault-connector/utils/EVCUtil.sol";
import {EVCUtil} from "ethereum-vault-connector/utils/EVCUtil.sol";
import {IERC20} from "openzeppelin-contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "openzeppelin-contracts/token/ERC20/utils/SafeERC20.sol";
import {Math} from "openzeppelin-contracts/utils/math/Math.sol";
Expand Down
2 changes: 1 addition & 1 deletion test/unit/esr/lib/ESRTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract ESRTest is Test {
function setUp() public virtual {
asset = new MockToken();
evc = new EVC();
esr = new EulerSavingsRate(evc, address(asset), NAME, SYMBOL);
esr = new EulerSavingsRate(address(evc), address(asset), NAME, SYMBOL);

// Set a non zero timestamp
vm.warp(420);
Expand Down
4 changes: 2 additions & 2 deletions test/unit/esvault/ESVaultTestBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ contract ESVaultTestBase is EVaultTestBase {
function setUp() public virtual override {
super.setUp();

assetTSTAsSynth = ESynth(address(new ESynth(evc, "Test Synth", "TST")));
assetTSTAsSynth = ESynth(address(new ESynth(address(evc), "Test Synth", "TST")));
assetTST = TestERC20(address(assetTSTAsSynth));
assetTST2AsSynth = ESynth(address(new ESynth(evc, "Test Synth 2", "TST2")));
assetTST2AsSynth = ESynth(address(new ESynth(address(evc), "Test Synth 2", "TST2")));
assetTST2 = TestERC20(address(assetTST2AsSynth));

eTST = createSynthEVault(address(assetTST));
Expand Down
4 changes: 2 additions & 2 deletions test/unit/esynth/ESynth.totalSupply.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.13;

import {Test} from "forge-std/Test.sol";
import {ESynth, IEVC, Ownable} from "../../../src/Synths/ESynth.sol";
import {ESynth, Ownable} from "../../../src/Synths/ESynth.sol";

contract ESynthTotalSupplyTest is Test {
ESynth synth;
Expand All @@ -13,7 +13,7 @@ contract ESynthTotalSupplyTest is Test {

function setUp() public {
vm.startPrank(owner);
synth = new ESynth(IEVC(makeAddr("evc")), "TestSynth", "TS");
synth = new ESynth(makeAddr("evc"), "TestSynth", "TS");
synth.setCapacity(owner, 1000000e18);
vm.stopPrank();
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/esynth/ESynthGeneral.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ contract ESynthGeneralTest is ESynthTest {
vm.assume(id != 0);

vm.prank(owner);
esynth = ESynth(address(new ESynth(evc, "Test Synth", "TST")));
esynth = ESynth(address(new ESynth(address(evc), "Test Synth", "TST")));

// succeeds if called directly by an owner
vm.prank(owner);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/esynth/lib/ESynthTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract ESynthTest is EVaultTestBase {
user1 = vm.addr(1001);
user2 = vm.addr(1002);

esynth = ESynth(address(new ESynth(evc, "Test Synth", "TST")));
esynth = ESynth(address(new ESynth(address(evc), "Test Synth", "TST")));
assetTST = TestERC20(address(esynth));

eTST = createSynthEVault(address(assetTST));
Expand Down
8 changes: 4 additions & 4 deletions test/unit/pegStabilityModules/PSM.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity ^0.8.0;
import "forge-std/Test.sol";

import {PegStabilityModule, EVCUtil} from "../../../src/Synths/PegStabilityModule.sol";
import {ESynth, IEVC} from "../../../src/Synths/ESynth.sol";
import {ESynth} from "../../../src/Synths/ESynth.sol";
import {TestERC20} from "../../mocks/TestERC20.sol";
import {EthereumVaultConnector} from "ethereum-vault-connector/EthereumVaultConnector.sol";
import {EVCUtil} from "ethereum-vault-connector/utils/EVCUtil.sol";
Expand All @@ -22,7 +22,7 @@ contract PSMTest is Test {

PegStabilityModule public psm;

IEVC public evc;
EthereumVaultConnector public evc;

address public owner = makeAddr("owner");
address public wallet1 = makeAddr("wallet1");
Expand All @@ -34,7 +34,7 @@ contract PSMTest is Test {

// Deploy synth
vm.prank(owner);
synth = new ESynth(evc, "TestSynth", "TSYNTH");
synth = new ESynth(address(evc), "TestSynth", "TSYNTH");

// Deploy underlying
underlying = new TestERC20("TestUnderlying", "TUNDERLYING", 18, false);
Expand Down Expand Up @@ -266,7 +266,7 @@ contract PSMTest is Test {
assertEq(psm.quoteToUnderlyingGivenOut(underlyingAmount), synthAmount);
}

function testRoundingPriceConversionsEqualDecimals() public {
function testRoundingPriceConversionsEqualDecimals() public view {
assertEq(psm.quoteToSynthGivenIn(1), 0);
assertEq(psm.quoteToSynthGivenOut(1), 2);
assertEq(psm.quoteToUnderlyingGivenIn(1), 0);
Expand Down

0 comments on commit 7d23acc

Please sign in to comment.