Skip to content

Commit

Permalink
Merge pull request #68 from euler-xyz/fix-unify-esvault
Browse files Browse the repository at this point in the history
Unify ESVault fixes
  • Loading branch information
kasperpawlowski authored Mar 22, 2024
2 parents ceed9b6 + 847d2f7 commit 0288f45
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 64 deletions.
11 changes: 0 additions & 11 deletions src/EVault/modules/Initialize.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ abstract contract InitializeModule is IInitialize, Base, BorrowUtils {

snapshot.reset();

{
uint32 defaultConfigFlags = CFG_SOCIALIZE_DEBT;
if (isEVCCompatible(address(asset))) defaultConfigFlags |= CFG_EVC_COMPATIBLE_ASSET;
marketStorage.configFlags = Flags.wrap(defaultConfigFlags);
}

// Emit logs

emit EVaultCreated(proxyCreator, address(asset), dToken);
Expand All @@ -62,11 +56,6 @@ abstract contract InitializeModule is IInitialize, Base, BorrowUtils {
constructor() {
initialized = true;
}

function isEVCCompatible(address asset) private view returns (bool) {
(bool success, bytes memory data) = asset.staticcall(abi.encodeCall(IGovernance.EVC, ()));
return success && data.length >= 32 && abi.decode(data, (address)) == address(evc);
}
}

contract Initialize is InitializeModule {
Expand Down
2 changes: 1 addition & 1 deletion src/EVault/modules/Liquidation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ abstract contract LiquidationModule is ILiquidation, Base, BalanceUtils, Liquidi
// Handle debt socialization

if (
marketCache.configFlags.isSet(CFG_SOCIALIZE_DEBT) && liqCache.owed > liqCache.repay
marketCache.configFlags.isNotSet(CFG_DONT_SOCIALIZE_DEBT) && liqCache.owed > liqCache.repay
&& checkNoCollateral(liqCache.violator, liqCache.collaterals)
) {
Assets owedRemaining = liqCache.owed - liqCache.repay;
Expand Down
4 changes: 4 additions & 0 deletions src/EVault/modules/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ abstract contract VaultModule is IVault, Base, AssetTransfers, BalanceUtils {
Shares shares = assets.toSharesDown(marketCache);
if (shares.isZero()) revert E_ZeroShares();

if (marketCache.configFlags.isSet(CFG_ONLY_ASSET_CAN_DEPOSIT) && receiver != asset()) {
revert E_OnlyAssetCanDeposit();
}

increaseBalance(marketCache, receiver, account, shares, assets);
marketStorage.cash = marketCache.cash = marketCache.cash + assets;

Expand Down
2 changes: 1 addition & 1 deletion src/EVault/shared/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ uint32 constant OP_ACCRUE_INTEREST = 1 << 15;

// Config Flags

uint32 constant CFG_SOCIALIZE_DEBT = 1 << 0;
uint32 constant CFG_DONT_SOCIALIZE_DEBT = 1 << 0;
uint32 constant CFG_EVC_COMPATIBLE_ASSET = 1 << 1;
uint32 constant CFG_ONLY_ASSET_CAN_DEPOSIT = 1 << 2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,30 @@ pragma solidity ^0.8.0;
import {ESVaultTestBase, ESynth} from "./ESVaultTestBase.t.sol";
import {Errors} from "../../../src/EVault/shared/Errors.sol";

contract ESVaultTestDeposit is ESVaultTestBase {
contract ESVaultTestAllocate is ESVaultTestBase {
function setUp() public override {
super.setUp();

assetTSTAsSynth.setCapacity(address(this), 10000e18);
}

function test_deposit_from_non_synth() public {
function test_allocate_from_non_synth() public {
// enable all the ops to show that when only asset is configured to deposit, mint and skim will fail
eTST.setLockedOps(0);
eTST.setDisabledOps(0);

vm.expectRevert(Errors.E_OnlyAssetCanDeposit.selector);
eTST.deposit(100, address(this));

vm.expectRevert(Errors.E_OnlyAssetCanDeposit.selector);
eTST.mint(100, address(this));

assetTSTAsSynth.mint(address(eTST), 100);
vm.expectRevert(Errors.E_OnlyAssetCanDeposit.selector);
eTST.skim(100, address(this));
}

function test_deposit_from_synth() public {
function test_allocate_from_synth() public {
assetTSTAsSynth.mint(address(assetTSTAsSynth), 100);
assetTSTAsSynth.allocate(address(eTST), 100);

Expand Down
48 changes: 0 additions & 48 deletions test/unit/evault/modules/Initialize/configflags.t.sol

This file was deleted.

0 comments on commit 0288f45

Please sign in to comment.