From f9756c4925917b09c02e0aac23dadfb681dc6a43 Mon Sep 17 00:00:00 2001 From: dglowinski Date: Fri, 22 Mar 2024 20:49:04 +0100 Subject: [PATCH] rename market to vault --- src/EVault/modules/BalanceForwarder.sol | 6 +- src/EVault/modules/Borrowing.sol | 60 ++++----- src/EVault/modules/Governance.sol | 108 +++++++-------- src/EVault/modules/Initialize.sol | 12 +- src/EVault/modules/Liquidation.sol | 34 +++-- src/EVault/modules/RiskManager.sol | 32 ++--- src/EVault/modules/Token.sol | 10 +- src/EVault/modules/Vault.sol | 123 +++++++++--------- src/EVault/shared/AssetTransfers.sol | 14 +- src/EVault/shared/BalanceUtils.sol | 38 +++--- src/EVault/shared/Base.sol | 28 ++-- src/EVault/shared/BorrowUtils.sol | 76 +++++------ src/EVault/shared/Cache.sol | 104 +++++++-------- src/EVault/shared/EVCClient.sol | 4 +- src/EVault/shared/LTVUtils.sol | 8 +- src/EVault/shared/LiquidityUtils.sol | 34 ++--- src/EVault/shared/MarketStorage.sol | 23 ---- src/EVault/shared/VaultStorage.sol | 23 ++++ src/EVault/shared/types/Assets.sol | 10 +- src/EVault/shared/types/ConversionHelpers.sol | 9 +- src/EVault/shared/types/Shares.sol | 10 +- src/EVault/shared/types/Types.sol | 2 +- .../types/{MarketCache.sol => VaultCache.sol} | 2 +- .../types/{Market.sol => VaultData.sol} | 11 +- test/mocks/MockEVault.sol | 8 +- test/unit/evault/shared/AssetTransfers.t.sol | 14 +- test/unit/factory/GenericFactory.t.sol | 18 +-- 27 files changed, 404 insertions(+), 417 deletions(-) delete mode 100644 src/EVault/shared/MarketStorage.sol create mode 100644 src/EVault/shared/VaultStorage.sol rename src/EVault/shared/types/{MarketCache.sol => VaultCache.sol} (96%) rename src/EVault/shared/types/{Market.sol => VaultData.sol} (97%) diff --git a/src/EVault/modules/BalanceForwarder.sol b/src/EVault/modules/BalanceForwarder.sol index 2590241a..97a14fc5 100644 --- a/src/EVault/modules/BalanceForwarder.sol +++ b/src/EVault/modules/BalanceForwarder.sol @@ -14,7 +14,7 @@ abstract contract BalanceForwarderModule is IBalanceForwarder, Base { /// @inheritdoc IBalanceForwarder function balanceForwarderEnabled(address account) public view virtual reentrantOK returns (bool) { - return marketStorage().users[account].getBalanceForwarderEnabled(); + return vaultStorage().users[account].getBalanceForwarderEnabled(); } /// @inheritdoc IBalanceForwarder @@ -22,7 +22,7 @@ abstract contract BalanceForwarderModule is IBalanceForwarder, Base { if (address(balanceTracker) == address(0)) revert E_BalanceForwarderUnsupported(); address account = EVCAuthenticate(); - User storage user = marketStorage().users[account]; + User storage user = vaultStorage().users[account]; bool wasBalanceForwarderEnabled = user.getBalanceForwarderEnabled(); user.setBalanceForwarder(true); @@ -36,7 +36,7 @@ abstract contract BalanceForwarderModule is IBalanceForwarder, Base { if (address(balanceTracker) == address(0)) revert E_BalanceForwarderUnsupported(); address account = EVCAuthenticate(); - User storage user = marketStorage().users[account]; + User storage user = vaultStorage().users[account]; bool wasBalanceForwarderEnabled = user.getBalanceForwarderEnabled(); user.setBalanceForwarder(false); diff --git a/src/EVault/modules/Borrowing.sol b/src/EVault/modules/Borrowing.sol index 0ec18535..9fe7701a 100644 --- a/src/EVault/modules/Borrowing.sol +++ b/src/EVault/modules/Borrowing.sol @@ -33,7 +33,7 @@ abstract contract BorrowingModule is IBorrowing, Base, AssetTransfers, BalanceUt /// @inheritdoc IBorrowing function cash() public view virtual nonReentrantView returns (uint256) { - return marketStorage().cash.toUint(); + return vaultStorage().cash.toUint(); } /// @inheritdoc IBorrowing @@ -70,9 +70,9 @@ abstract contract BorrowingModule is IBorrowing, Base, AssetTransfers, BalanceUt if (!isCollateralEnabled(account, collateral)) return 0; address[] memory collaterals = getCollaterals(account); - MarketCache memory marketCache = loadMarket(); + VaultCache memory vaultCache = loadMarket(); (uint256 totalCollateralValueRiskAdjusted, uint256 liabilityValue) = - calculateLiquidity(marketCache, account, collaterals, LTVType.BORROWING); + calculateLiquidity(vaultCache, account, collaterals, LTVType.BORROWING); // if there is no liability or it has no value, collateral will not be locked if (liabilityValue == 0) return 0; @@ -92,7 +92,7 @@ abstract contract BorrowingModule is IBorrowing, Base, AssetTransfers, BalanceUt uint256 extraCollateralValue = ltv.mulInv(totalCollateralValueRiskAdjusted - liabilityValue); // convert back to collateral balance (bid) - (uint256 collateralPrice,) = marketCache.oracle.getQuotes(1e18, collateral, marketCache.unitOfAccount); + (uint256 collateralPrice,) = vaultCache.oracle.getQuotes(1e18, collateral, vaultCache.unitOfAccount); if (collateralPrice == 0) return 0; // worthless / unpriced collateral is not locked uint256 extraCollateralBalance = extraCollateralValue * 1e18 / collateralPrice; @@ -108,105 +108,105 @@ abstract contract BorrowingModule is IBorrowing, Base, AssetTransfers, BalanceUt /// @inheritdoc IBorrowing function borrow(uint256 amount, address receiver) public virtual nonReentrant returns (uint256) { - (MarketCache memory marketCache, address account) = initOperation(OP_BORROW, CHECKACCOUNT_CALLER); + (VaultCache memory vaultCache, address account) = initOperation(OP_BORROW, CHECKACCOUNT_CALLER); - Assets assets = amount == type(uint256).max ? marketCache.cash : amount.toAssets(); + Assets assets = amount == type(uint256).max ? vaultCache.cash : amount.toAssets(); if (assets.isZero()) return 0; - if (assets > marketCache.cash) revert E_InsufficientCash(); + if (assets > vaultCache.cash) revert E_InsufficientCash(); - increaseBorrow(marketCache, account, assets); + increaseBorrow(vaultCache, account, assets); - pushAssets(marketCache, receiver, assets); + pushAssets(vaultCache, receiver, assets); return assets.toUint(); } /// @inheritdoc IBorrowing function repay(uint256 amount, address receiver) public virtual nonReentrant returns (uint256) { - (MarketCache memory marketCache, address account) = initOperation(OP_REPAY, CHECKACCOUNT_NONE); + (VaultCache memory vaultCache, address account) = initOperation(OP_REPAY, CHECKACCOUNT_NONE); - uint256 owed = getCurrentOwed(marketCache, receiver).toAssetsUp().toUint(); + uint256 owed = getCurrentOwed(vaultCache, receiver).toAssetsUp().toUint(); Assets assets = (amount == type(uint256).max ? owed : amount).toAssets(); if (assets.isZero()) return 0; - pullAssets(marketCache, account, assets); + pullAssets(vaultCache, account, assets); - decreaseBorrow(marketCache, receiver, assets); + decreaseBorrow(vaultCache, receiver, assets); return assets.toUint(); } /// @inheritdoc IBorrowing function loop(uint256 amount, address sharesReceiver) public virtual nonReentrant returns (uint256) { - (MarketCache memory marketCache, address account) = initOperation(OP_LOOP, CHECKACCOUNT_CALLER); + (VaultCache memory vaultCache, address account) = initOperation(OP_LOOP, CHECKACCOUNT_CALLER); Assets assets = amount.toAssets(); if (assets.isZero()) return 0; - Shares shares = assets.toSharesUp(marketCache); - assets = shares.toAssetsUp(marketCache); + Shares shares = assets.toSharesUp(vaultCache); + assets = shares.toAssetsUp(vaultCache); // Mint DTokens - increaseBorrow(marketCache, account, assets); + increaseBorrow(vaultCache, account, assets); // Mint ETokens - increaseBalance(marketCache, sharesReceiver, account, shares, assets); + increaseBalance(vaultCache, sharesReceiver, account, shares, assets); return shares.toUint(); } /// @inheritdoc IBorrowing function deloop(uint256 amount, address debtFrom) public virtual nonReentrant returns (uint256) { - (MarketCache memory marketCache, address account) = initOperation(OP_DELOOP, CHECKACCOUNT_NONE); + (VaultCache memory vaultCache, address account) = initOperation(OP_DELOOP, CHECKACCOUNT_NONE); - Assets owed = getCurrentOwed(marketCache, debtFrom).toAssetsUp(); + Assets owed = getCurrentOwed(vaultCache, debtFrom).toAssetsUp(); if (owed.isZero()) return 0; Assets assets; Shares shares; if (amount == type(uint256).max) { - shares = marketStorage().users[account].getBalance(); - assets = shares.toAssetsDown(marketCache); + shares = vaultStorage().users[account].getBalance(); + assets = shares.toAssetsDown(vaultCache); } else { assets = amount.toAssets(); - shares = assets.toSharesUp(marketCache); + shares = assets.toSharesUp(vaultCache); } if (assets.isZero()) return 0; if (assets > owed) { assets = owed; - shares = assets.toSharesUp(marketCache); + shares = assets.toSharesUp(vaultCache); } // Burn ETokens - decreaseBalance(marketCache, account, account, account, shares, assets); + decreaseBalance(vaultCache, account, account, account, shares, assets); // Burn DTokens - decreaseBorrow(marketCache, debtFrom, assets); + decreaseBorrow(vaultCache, debtFrom, assets); return shares.toUint(); } /// @inheritdoc IBorrowing function pullDebt(uint256 amount, address from) public virtual nonReentrant returns (uint256) { - (MarketCache memory marketCache, address account) = initOperation(OP_PULL_DEBT, CHECKACCOUNT_CALLER); + (VaultCache memory vaultCache, address account) = initOperation(OP_PULL_DEBT, CHECKACCOUNT_CALLER); if (from == account) revert E_SelfTransfer(); - Assets assets = amount == type(uint256).max ? getCurrentOwed(marketCache, from).toAssetsUp() : amount.toAssets(); + Assets assets = amount == type(uint256).max ? getCurrentOwed(vaultCache, from).toAssetsUp() : amount.toAssets(); if (assets.isZero()) return 0; - transferBorrow(marketCache, from, account, assets); + transferBorrow(vaultCache, from, account, assets); return assets.toUint(); } /// @inheritdoc IBorrowing function flashLoan(uint256 amount, bytes calldata data) public virtual nonReentrant { - if (marketStorage().disabledOps.isSet(OP_FLASHLOAN)) { + if (vaultStorage().disabledOps.isSet(OP_FLASHLOAN)) { revert E_OperationDisabled(); } diff --git a/src/EVault/modules/Governance.sol b/src/EVault/modules/Governance.sol index c0d41aa9..d71dd9c2 100644 --- a/src/EVault/modules/Governance.sol +++ b/src/EVault/modules/Governance.sol @@ -36,12 +36,12 @@ abstract contract GovernanceModule is IGovernance, Base, BalanceUtils, BorrowUti event GovSetInterestFee(uint16 newFee); modifier governorOnly() { - if (msg.sender != marketStorage().governorAdmin) revert E_Unauthorized(); + if (msg.sender != vaultStorage().governorAdmin) revert E_Unauthorized(); _; } modifier governorOrPauseGuardianOnly() { - if (msg.sender != marketStorage().governorAdmin && msg.sender != marketStorage().pauseGuardian) { + if (msg.sender != vaultStorage().governorAdmin && msg.sender != vaultStorage().pauseGuardian) { revert E_Unauthorized(); } _; @@ -49,17 +49,17 @@ abstract contract GovernanceModule is IGovernance, Base, BalanceUtils, BorrowUti /// @inheritdoc IGovernance function governorAdmin() public view virtual reentrantOK returns (address) { - return marketStorage().governorAdmin; + return vaultStorage().governorAdmin; } /// @inheritdoc IGovernance function pauseGuardian() public view virtual reentrantOK returns (address) { - return marketStorage().pauseGuardian; + return vaultStorage().pauseGuardian; } /// @inheritdoc IGovernance function interestFee() public view virtual reentrantOK returns (uint16) { - return marketStorage().interestFee.toUint16(); + return vaultStorage().interestFee.toUint16(); } /// @inheritdoc IGovernance @@ -91,43 +91,43 @@ abstract contract GovernanceModule is IGovernance, Base, BalanceUtils, BorrowUti /// @inheritdoc IGovernance function LTVFull(address collateral) public view virtual reentrantOK returns (uint48, uint16, uint32, uint16) { - LTVConfig memory ltv = marketStorage().ltvLookup[collateral]; + LTVConfig memory ltv = vaultStorage().ltvLookup[collateral]; return (ltv.targetTimestamp, ltv.targetLTV.toUint16(), ltv.rampDuration, ltv.originalLTV.toUint16()); } /// @inheritdoc IGovernance function LTVList() public view virtual reentrantOK returns (address[] memory) { - return marketStorage().ltvList; + return vaultStorage().ltvList; } /// @inheritdoc IGovernance function interestRateModel() public view virtual reentrantOK returns (address) { - return marketStorage().interestRateModel; + return vaultStorage().interestRateModel; } /// @inheritdoc IGovernance function disabledOps() public view virtual reentrantOK returns (uint32) { - return (marketStorage().disabledOps.toUint32()); + return (vaultStorage().disabledOps.toUint32()); } /// @inheritdoc IGovernance function configFlags() public view virtual reentrantOK returns (uint32) { - return (marketStorage().configFlags.toUint32()); + return (vaultStorage().configFlags.toUint32()); } /// @inheritdoc IGovernance function lockedOps() public view virtual reentrantOK returns (uint32) { - return (marketStorage().lockedOps.toUint32()); + return (vaultStorage().lockedOps.toUint32()); } /// @inheritdoc IGovernance function caps() public view virtual reentrantOK returns (uint16, uint16) { - return (marketStorage().supplyCap.toRawUint16(), marketStorage().borrowCap.toRawUint16()); + return (vaultStorage().supplyCap.toRawUint16(), vaultStorage().borrowCap.toRawUint16()); } /// @inheritdoc IGovernance function feeReceiver() public view virtual reentrantOK returns (address) { - return marketStorage().feeReceiver; + return vaultStorage().feeReceiver; } /// @inheritdoc IGovernance @@ -154,13 +154,13 @@ abstract contract GovernanceModule is IGovernance, Base, BalanceUtils, BorrowUti /// @inheritdoc IGovernance function convertFees() public virtual nonReentrant { - (MarketCache memory marketCache, address account) = initOperation(OP_CONVERT_FEES, CHECKACCOUNT_NONE); + (VaultCache memory vaultCache, address account) = initOperation(OP_CONVERT_FEES, CHECKACCOUNT_NONE); - if (marketCache.accumulatedFees.isZero()) return; + if (vaultCache.accumulatedFees.isZero()) return; - Market storage _marketStorage = marketStorage(); + VaultData storage _vaultStorage = vaultStorage(); (address protocolReceiver, uint16 protocolFee) = protocolConfig.protocolFeeConfig(address(this)); - address governorReceiver = _marketStorage.feeReceiver; + address governorReceiver = _vaultStorage.feeReceiver; if (governorReceiver == address(0)) { protocolFee = 1e4; // governor forfeits fees @@ -168,21 +168,21 @@ abstract contract GovernanceModule is IGovernance, Base, BalanceUtils, BorrowUti protocolFee = MAX_PROTOCOL_FEE_SHARE; } - Shares governorShares = marketCache.accumulatedFees.mulDiv(1e4 - protocolFee, 1e4); - Shares protocolShares = marketCache.accumulatedFees - governorShares; + Shares governorShares = vaultCache.accumulatedFees.mulDiv(1e4 - protocolFee, 1e4); + Shares protocolShares = vaultCache.accumulatedFees - governorShares; - _marketStorage.accumulatedFees = marketCache.accumulatedFees = Shares.wrap(0); + _vaultStorage.accumulatedFees = vaultCache.accumulatedFees = Shares.wrap(0); // Decrease totalShares because increaseBalance will increase it by that total amount - _marketStorage.totalShares = marketCache.totalShares = marketCache.totalShares - marketCache.accumulatedFees; + _vaultStorage.totalShares = vaultCache.totalShares = vaultCache.totalShares - vaultCache.accumulatedFees; // For the Deposit events in increaseBalance the assets amount is zero - the shares are covered with the accrued interest if (!governorShares.isZero()) { - increaseBalance(marketCache, governorReceiver, address(0), governorShares, Assets.wrap(0)); + increaseBalance(vaultCache, governorReceiver, address(0), governorShares, Assets.wrap(0)); } if (!protocolShares.isZero()) { - increaseBalance(marketCache, protocolReceiver, address(0), protocolShares, Assets.wrap(0)); + increaseBalance(vaultCache, protocolReceiver, address(0), protocolShares, Assets.wrap(0)); } emit ConvertFees(account, protocolReceiver, governorReceiver, protocolShares.toUint(), governorShares.toUint()); @@ -190,31 +190,31 @@ abstract contract GovernanceModule is IGovernance, Base, BalanceUtils, BorrowUti /// @inheritdoc IGovernance function setName(string calldata newName) public virtual nonReentrant governorOnly { - marketStorage().name = newName; + vaultStorage().name = newName; emit GovSetName(newName); } /// @inheritdoc IGovernance function setSymbol(string calldata newSymbol) public virtual nonReentrant governorOnly { - marketStorage().symbol = newSymbol; + vaultStorage().symbol = newSymbol; emit GovSetSymbol(newSymbol); } /// @inheritdoc IGovernance function setGovernorAdmin(address newGovernorAdmin) public virtual nonReentrant governorOnly { - marketStorage().governorAdmin = newGovernorAdmin; + vaultStorage().governorAdmin = newGovernorAdmin; emit GovSetGovernorAdmin(newGovernorAdmin); } /// @inheritdoc IGovernance function setPauseGuardian(address newPauseGuardian) public virtual nonReentrant governorOnly { - marketStorage().pauseGuardian = newPauseGuardian; + vaultStorage().pauseGuardian = newPauseGuardian; emit GovSetPauseGuardian(newPauseGuardian); } /// @inheritdoc IGovernance function setFeeReceiver(address newFeeReceiver) public virtual nonReentrant governorOnly { - marketStorage().feeReceiver = newFeeReceiver; + vaultStorage().feeReceiver = newFeeReceiver; emit GovSetFeeReceiver(newFeeReceiver); } @@ -223,18 +223,18 @@ abstract contract GovernanceModule is IGovernance, Base, BalanceUtils, BorrowUti // self-collateralization is not allowed if (collateral == address(this)) revert E_InvalidLTVAsset(); - Market storage _marketStorage = marketStorage(); + VaultData storage _vaultStorage = vaultStorage(); ConfigAmount newLTVAmount = ltv.toConfigAmount(); - LTVConfig memory origLTV = _marketStorage.ltvLookup[collateral]; + LTVConfig memory origLTV = _vaultStorage.ltvLookup[collateral]; // If new LTV is higher than the previous, or the same, it should take effect immediately if (!(newLTVAmount < origLTV.getLTV(LTVType.LIQUIDATION)) && rampDuration > 0) revert E_LTVRamp(); LTVConfig memory newLTV = origLTV.setLTV(newLTVAmount, rampDuration); - _marketStorage.ltvLookup[collateral] = newLTV; + _vaultStorage.ltvLookup[collateral] = newLTV; - if (!origLTV.initialized) _marketStorage.ltvList.push(collateral); + if (!origLTV.initialized) _vaultStorage.ltvList.push(collateral); emit GovSetLTV( collateral, @@ -248,53 +248,53 @@ abstract contract GovernanceModule is IGovernance, Base, BalanceUtils, BorrowUti /// @inheritdoc IGovernance function clearLTV(address collateral) public virtual nonReentrant governorOnly { uint16 originalLTV = getLTV(collateral, LTVType.LIQUIDATION).toUint16(); - marketStorage().ltvLookup[collateral].clear(); + vaultStorage().ltvLookup[collateral].clear(); emit GovSetLTV(collateral, 0, 0, 0, originalLTV); } /// @inheritdoc IGovernance function setInterestRateModel(address newModel) public virtual nonReentrant governorOnly { - MarketCache memory marketCache = updateMarket(); + VaultCache memory vaultCache = updateMarket(); - Market storage _marketStorage = marketStorage(); - _marketStorage.interestRateModel = newModel; - _marketStorage.interestRate = 0; + VaultData storage _vaultStorage = vaultStorage(); + _vaultStorage.interestRateModel = newModel; + _vaultStorage.interestRate = 0; - uint256 newInterestRate = computeInterestRate(marketCache); + uint256 newInterestRate = computeInterestRate(vaultCache); - logMarketStatus(marketCache, newInterestRate); + logMarketStatus(vaultCache, newInterestRate); emit GovSetInterestRateModel(newModel); } /// @inheritdoc IGovernance function setDisabledOps(uint32 newDisabledOps) public virtual nonReentrant governorOrPauseGuardianOnly { - Market storage _marketStorage = marketStorage(); + VaultData storage _vaultStorage = vaultStorage(); // Overwrite bits of locked ops with their currently set values - newDisabledOps = (newDisabledOps & ~_marketStorage.lockedOps.toUint32()) - | (_marketStorage.disabledOps.toUint32() & _marketStorage.lockedOps.toUint32()); + newDisabledOps = (newDisabledOps & ~_vaultStorage.lockedOps.toUint32()) + | (_vaultStorage.disabledOps.toUint32() & _vaultStorage.lockedOps.toUint32()); // market is updated because: // if disabling interest accrual - the pending interest should be accrued // if re-enabling interest - last updated timestamp needs to be reset to skip the disabled period - MarketCache memory marketCache = updateMarket(); - logMarketStatus(marketCache, _marketStorage.interestRate); + VaultCache memory vaultCache = updateMarket(); + logMarketStatus(vaultCache, _vaultStorage.interestRate); - _marketStorage.disabledOps = Flags.wrap(newDisabledOps); + _vaultStorage.disabledOps = Flags.wrap(newDisabledOps); emit GovSetDisabledOps(newDisabledOps); } /// @inheritdoc IGovernance function setLockedOps(uint32 newLockedOps) public virtual nonReentrant governorOnly { - marketStorage().lockedOps = Flags.wrap(newLockedOps); + vaultStorage().lockedOps = Flags.wrap(newLockedOps); emit GovSetLockedOps(newLockedOps); } /// @inheritdoc IGovernance function setConfigFlags(uint32 newConfigFlags) public virtual nonReentrant governorOnly { - marketStorage().configFlags = Flags.wrap(newConfigFlags); + vaultStorage().configFlags = Flags.wrap(newConfigFlags); emit GovSetConfigFlags(newConfigFlags); } @@ -307,9 +307,9 @@ abstract contract GovernanceModule is IGovernance, Base, BalanceUtils, BorrowUti AmountCap _borrowCap = AmountCap.wrap(borrowCap); if (borrowCap > 0 && _borrowCap.toUint() > MAX_SANE_AMOUNT) revert E_BadBorrowCap(); - Market storage _marketStorage = marketStorage(); - _marketStorage.supplyCap = _supplyCap; - _marketStorage.borrowCap = _borrowCap; + VaultData storage _vaultStorage = vaultStorage(); + _vaultStorage.supplyCap = _supplyCap; + _vaultStorage.borrowCap = _borrowCap; emit GovSetCaps(supplyCap, borrowCap); } @@ -317,16 +317,16 @@ abstract contract GovernanceModule is IGovernance, Base, BalanceUtils, BorrowUti /// @inheritdoc IGovernance function setInterestFee(uint16 newInterestFee) public virtual nonReentrant governorOnly { // Update market to apply the current interest fee to the pending interest - MarketCache memory marketCache = updateMarket(); - Market storage _marketStorage = marketStorage(); - logMarketStatus(marketCache, _marketStorage.interestRate); + VaultCache memory vaultCache = updateMarket(); + VaultData storage _vaultStorage = vaultStorage(); + logMarketStatus(vaultCache, _vaultStorage.interestRate); // Interest fees in guaranteed range are always allowed, otherwise ask protocolConfig if (newInterestFee < GUARANTEED_INTEREST_FEE_MIN || newInterestFee > GUARANTEED_INTEREST_FEE_MAX) { if (!protocolConfig.isValidInterestFee(address(this), newInterestFee)) revert E_BadFee(); } - _marketStorage.interestFee = newInterestFee.toConfigAmount(); + _vaultStorage.interestFee = newInterestFee.toConfigAmount(); emit GovSetInterestFee(newInterestFee); } diff --git a/src/EVault/modules/Initialize.sol b/src/EVault/modules/Initialize.sol index 3c08d150..d1c851de 100644 --- a/src/EVault/modules/Initialize.sol +++ b/src/EVault/modules/Initialize.sol @@ -8,7 +8,7 @@ import {BorrowUtils} from "../shared/BorrowUtils.sol"; import {DToken} from "../DToken.sol"; import {ProxyUtils} from "../shared/lib/ProxyUtils.sol"; import {RevertBytes} from "../shared/lib/RevertBytes.sol"; -import {MarketCache} from "../shared/types/MarketCache.sol"; +import {VaultCache} from "../shared/types/VaultCache.sol"; // import {SnapshotStorage} from "../shared/SnapshotStorage.sol"; import "../shared/Constants.sol"; @@ -48,12 +48,12 @@ abstract contract InitializeModule is IInitialize, Base, BorrowUtils { // Initialize storage - Market storage _marketStorage = marketStorage(); + VaultData storage _vaultStorage = vaultStorage(); - _marketStorage.lastInterestAccumulatorUpdate = uint48(block.timestamp); - _marketStorage.interestAccumulator = INITIAL_INTEREST_ACCUMULATOR; - _marketStorage.interestFee = DEFAULT_INTEREST_FEE.toConfigAmount(); - _marketStorage.creator = _marketStorage.governorAdmin = _marketStorage.pauseGuardian = proxyCreator; + _vaultStorage.lastInterestAccumulatorUpdate = uint48(block.timestamp); + _vaultStorage.interestAccumulator = INITIAL_INTEREST_ACCUMULATOR; + _vaultStorage.interestFee = DEFAULT_INTEREST_FEE.toConfigAmount(); + _vaultStorage.creator = _vaultStorage.governorAdmin = _vaultStorage.pauseGuardian = proxyCreator; snapshotStorage().reset(); diff --git a/src/EVault/modules/Liquidation.sol b/src/EVault/modules/Liquidation.sol index 53b11147..8bcb457b 100644 --- a/src/EVault/modules/Liquidation.sol +++ b/src/EVault/modules/Liquidation.sol @@ -46,16 +46,16 @@ abstract contract LiquidationModule is ILiquidation, Base, BalanceUtils, Liquidi virtual nonReentrant { - (MarketCache memory marketCache, address liquidator) = initOperation(OP_LIQUIDATE, CHECKACCOUNT_CALLER); + (VaultCache memory vaultCache, address liquidator) = initOperation(OP_LIQUIDATE, CHECKACCOUNT_CALLER); LiquidationCache memory liqCache = - calculateLiquidation(marketCache, liquidator, violator, collateral, repayAssets); + calculateLiquidation(vaultCache, liquidator, violator, collateral, repayAssets); - executeLiquidation(marketCache, liqCache, minYieldBalance); + executeLiquidation(vaultCache, liqCache, minYieldBalance); } function calculateLiquidation( - MarketCache memory marketCache, + VaultCache memory vaultCache, address liquidator, address violator, address collateral, @@ -69,7 +69,7 @@ abstract contract LiquidationModule is ILiquidation, Base, BalanceUtils, Liquidi liqCache.repay = Assets.wrap(0); liqCache.yieldBalance = 0; - liqCache.owed = getCurrentOwed(marketCache, violator).toAssetsUp(); + liqCache.owed = getCurrentOwed(vaultCache, violator).toAssetsUp(); liqCache.collaterals = getCollaterals(violator); // Checks @@ -91,7 +91,7 @@ abstract contract LiquidationModule is ILiquidation, Base, BalanceUtils, Liquidi // Calculate max yield and repay - liqCache = calculateMaxLiquidation(liqCache, marketCache); + liqCache = calculateMaxLiquidation(liqCache, vaultCache); // Adjust for desired repay @@ -106,7 +106,7 @@ abstract contract LiquidationModule is ILiquidation, Base, BalanceUtils, Liquidi } } - function calculateMaxLiquidation(LiquidationCache memory liqCache, MarketCache memory marketCache) + function calculateMaxLiquidation(LiquidationCache memory liqCache, VaultCache memory vaultCache) private view returns (LiquidationCache memory) @@ -114,7 +114,7 @@ abstract contract LiquidationModule is ILiquidation, Base, BalanceUtils, Liquidi // Check account health (uint256 liquidityCollateralValue, uint256 liquidityLiabilityValue) = - calculateLiquidity(marketCache, liqCache.violator, liqCache.collaterals, LTVType.LIQUIDATION); + calculateLiquidity(vaultCache, liqCache.violator, liqCache.collaterals, LTVType.LIQUIDATION); // no violation if (liquidityCollateralValue >= liquidityLiabilityValue) return liqCache; @@ -131,7 +131,7 @@ abstract contract LiquidationModule is ILiquidation, Base, BalanceUtils, Liquidi uint256 collateralBalance = IERC20(liqCache.collateral).balanceOf(liqCache.violator); uint256 collateralValue = - marketCache.oracle.getQuote(collateralBalance, liqCache.collateral, marketCache.unitOfAccount); + vaultCache.oracle.getQuote(collateralBalance, liqCache.collateral, vaultCache.unitOfAccount); if (collateralValue == 0) { // worthless collateral can be claimed with no repay @@ -140,10 +140,10 @@ abstract contract LiquidationModule is ILiquidation, Base, BalanceUtils, Liquidi } uint256 liabilityValue = liqCache.owed.toUint(); - if (address(marketCache.asset) != marketCache.unitOfAccount) { + if (address(vaultCache.asset) != vaultCache.unitOfAccount) { // liquidation, in contrast to liquidity calculation, uses mid-point pricing instead of bid/ask liabilityValue = - marketCache.oracle.getQuote(liabilityValue, address(marketCache.asset), marketCache.unitOfAccount); + vaultCache.oracle.getQuote(liabilityValue, address(vaultCache.asset), vaultCache.unitOfAccount); } uint256 maxRepayValue = liabilityValue; @@ -163,18 +163,16 @@ abstract contract LiquidationModule is ILiquidation, Base, BalanceUtils, Liquidi return liqCache; } - function executeLiquidation( - MarketCache memory marketCache, - LiquidationCache memory liqCache, - uint256 minYieldBalance - ) private { + function executeLiquidation(VaultCache memory vaultCache, LiquidationCache memory liqCache, uint256 minYieldBalance) + private + { // Check minimum yield. if (minYieldBalance > liqCache.yieldBalance) revert E_MinYield(); // Handle repay: liquidator takes on violator's debt: - transferBorrow(marketCache, liqCache.violator, liqCache.liquidator, liqCache.repay); + transferBorrow(vaultCache, liqCache.violator, liqCache.liquidator, liqCache.repay); // Handle yield: liquidator receives violator's collateral @@ -205,7 +203,7 @@ abstract contract LiquidationModule is ILiquidation, Base, BalanceUtils, Liquidi && checkNoCollateral(liqCache.violator, liqCache.collaterals) ) { Assets owedRemaining = liqCache.owed - liqCache.repay; - decreaseBorrow(marketCache, liqCache.violator, owedRemaining); + decreaseBorrow(vaultCache, liqCache.violator, owedRemaining); // decreaseBorrow emits Repay without any assets entering the vault. Emit Withdraw from and to zero address to cover the missing amount for offchain trackers. emit Withdraw(liqCache.liquidator, address(0), address(0), owedRemaining.toUint(), 0); diff --git a/src/EVault/modules/RiskManager.sol b/src/EVault/modules/RiskManager.sol index 1e173401..81ab7e42 100644 --- a/src/EVault/modules/RiskManager.sol +++ b/src/EVault/modules/RiskManager.sol @@ -19,13 +19,13 @@ abstract contract RiskManagerModule is IRiskManager, Base, LiquidityUtils { nonReentrantView returns (uint256 collateralValue, uint256 liabilityValue) { - MarketCache memory marketCache = loadMarket(); + VaultCache memory vaultCache = loadMarket(); verifyController(account); address[] memory collaterals = getCollaterals(account); return - calculateLiquidity(marketCache, account, collaterals, liquidation ? LTVType.LIQUIDATION : LTVType.BORROWING); + calculateLiquidity(vaultCache, account, collaterals, liquidation ? LTVType.LIQUIDATION : LTVType.BORROWING); } /// @inheritdoc IRiskManager @@ -36,27 +36,27 @@ abstract contract RiskManagerModule is IRiskManager, Base, LiquidityUtils { nonReentrantView returns (address[] memory collaterals, uint256[] memory collateralValues, uint256 liabilityValue) { - MarketCache memory marketCache = loadMarket(); + VaultCache memory vaultCache = loadMarket(); verifyController(account); - validateOracle(marketCache); + validateOracle(vaultCache); collaterals = getCollaterals(account); collateralValues = new uint256[](collaterals.length); for (uint256 i; i < collaterals.length; ++i) { collateralValues[i] = getCollateralValue( - marketCache, account, collaterals[i], liquidation ? LTVType.LIQUIDATION : LTVType.BORROWING + vaultCache, account, collaterals[i], liquidation ? LTVType.LIQUIDATION : LTVType.BORROWING ); } - liabilityValue = getLiabilityValue(marketCache, account, marketStorage().users[account].getOwed()); + liabilityValue = getLiabilityValue(vaultCache, account, vaultStorage().users[account].getOwed()); } /// @inheritdoc IRiskManager function disableController() public virtual nonReentrant { address account = EVCAuthenticate(); - if (!marketStorage().users[account].getOwed().isZero()) revert E_OutstandingDebt(); + if (!vaultStorage().users[account].getOwed().isZero()) revert E_OutstandingDebt(); disableControllerInternal(account); } @@ -82,30 +82,30 @@ abstract contract RiskManagerModule is IRiskManager, Base, LiquidityUtils { /// @dev See comment about re-entrancy for `checkAccountStatus` function checkVaultStatus() public virtual reentrantOK onlyEVCChecks returns (bytes4 magicValue) { // Use the updating variant to make sure interest is accrued in storage before the interest rate update - MarketCache memory marketCache = updateMarket(); - uint256 newInterestRate = computeInterestRate(marketCache); + VaultCache memory vaultCache = updateMarket(); + uint256 newInterestRate = computeInterestRate(vaultCache); - logMarketStatus(marketCache, newInterestRate); + logMarketStatus(vaultCache, newInterestRate); // We use the snapshot to check if the borrows or supply grew, and if so then we check the borrow and supply caps. // If snapshot is initialized, then caps are configured. // If caps are set in the middle of a batch, then snapshots represent the state of the vault at that time. - if (marketCache.snapshotInitialized) { - marketStorage().snapshotInitialized = marketCache.snapshotInitialized = false; + if (vaultCache.snapshotInitialized) { + vaultStorage().snapshotInitialized = vaultCache.snapshotInitialized = false; Snapshot storage snapshot = snapshotStorage(); Assets snapshotCash = snapshot.cash; Assets snapshotBorrows = snapshot.borrows; uint256 prevBorrows = snapshotBorrows.toUint(); - uint256 borrows = marketCache.totalBorrows.toAssetsUp().toUint(); + uint256 borrows = vaultCache.totalBorrows.toAssetsUp().toUint(); - if (borrows > marketCache.borrowCap && borrows > prevBorrows) revert E_BorrowCapExceeded(); + if (borrows > vaultCache.borrowCap && borrows > prevBorrows) revert E_BorrowCapExceeded(); uint256 prevSupply = snapshotCash.toUint() + prevBorrows; - uint256 supply = totalAssetsInternal(marketCache); + uint256 supply = totalAssetsInternal(vaultCache); - if (supply > marketCache.supplyCap && supply > prevSupply) revert E_SupplyCapExceeded(); + if (supply > vaultCache.supplyCap && supply > prevSupply) revert E_SupplyCapExceeded(); snapshot.reset(); } diff --git a/src/EVault/modules/Token.sol b/src/EVault/modules/Token.sol index 4a2a888e..670aab5d 100644 --- a/src/EVault/modules/Token.sol +++ b/src/EVault/modules/Token.sol @@ -14,12 +14,12 @@ abstract contract TokenModule is IToken, Base, BalanceUtils { /// @inheritdoc IERC20 function name() public view virtual reentrantOK returns (string memory) { - return bytes(marketStorage().name).length > 0 ? marketStorage().name : "Unnamed Euler Vault"; + return bytes(vaultStorage().name).length > 0 ? vaultStorage().name : "Unnamed Euler Vault"; } /// @inheritdoc IERC20 function symbol() public view virtual reentrantOK returns (string memory) { - return bytes(marketStorage().symbol).length > 0 ? marketStorage().symbol : "UNKNOWN"; + return bytes(vaultStorage().symbol).length > 0 ? vaultStorage().symbol : "UNKNOWN"; } /// @inheritdoc IERC20 @@ -36,12 +36,12 @@ abstract contract TokenModule is IToken, Base, BalanceUtils { /// @inheritdoc IERC20 function balanceOf(address account) public view virtual nonReentrantView returns (uint256) { - return marketStorage().users[account].getBalance().toUint(); + return vaultStorage().users[account].getBalance().toUint(); } /// @inheritdoc IERC20 function allowance(address holder, address spender) public view virtual nonReentrantView returns (uint256) { - return marketStorage().users[holder].eTokenAllowance[spender]; + return vaultStorage().users[holder].eTokenAllowance[spender]; } /// @inheritdoc IERC20 @@ -51,7 +51,7 @@ abstract contract TokenModule is IToken, Base, BalanceUtils { /// @inheritdoc IToken function transferFromMax(address from, address to) public virtual reentrantOK returns (bool) { - return transferFrom(from, to, marketStorage().users[from].getBalance().toUint()); + return transferFrom(from, to, vaultStorage().users[from].getBalance().toUint()); } /// @inheritdoc IERC20 diff --git a/src/EVault/modules/Vault.sol b/src/EVault/modules/Vault.sol index f569c53e..88ccd0af 100644 --- a/src/EVault/modules/Vault.sol +++ b/src/EVault/modules/Vault.sol @@ -23,28 +23,28 @@ abstract contract VaultModule is IVault, Base, AssetTransfers, BalanceUtils { /// @inheritdoc IERC4626 function totalAssets() public view virtual nonReentrantView returns (uint256) { - MarketCache memory marketCache = loadMarket(); - return totalAssetsInternal(marketCache); + VaultCache memory vaultCache = loadMarket(); + return totalAssetsInternal(vaultCache); } /// @inheritdoc IERC4626 function convertToAssets(uint256 shares) public view virtual nonReentrantView returns (uint256) { - MarketCache memory marketCache = loadMarket(); - return shares.toShares().toAssetsDown(marketCache).toUint(); + VaultCache memory vaultCache = loadMarket(); + return shares.toShares().toAssetsDown(vaultCache).toUint(); } /// @inheritdoc IERC4626 function convertToShares(uint256 assets) public view virtual nonReentrantView returns (uint256) { - MarketCache memory marketCache = loadMarket(); - return assets.toAssets().toSharesDown(marketCache).toUint(); + VaultCache memory vaultCache = loadMarket(); + return assets.toAssets().toSharesDown(vaultCache).toUint(); } /// @inheritdoc IERC4626 function maxDeposit(address account) public view virtual nonReentrantView returns (uint256) { - MarketCache memory marketCache = loadMarket(); - if (marketCache.disabledOps.isSet(OP_DEPOSIT)) return 0; + VaultCache memory vaultCache = loadMarket(); + if (vaultCache.disabledOps.isSet(OP_DEPOSIT)) return 0; - return maxDepositInternal(marketCache, account); + return maxDepositInternal(vaultCache, account); } /// @inheritdoc IERC4626 @@ -54,36 +54,36 @@ abstract contract VaultModule is IVault, Base, AssetTransfers, BalanceUtils { /// @inheritdoc IERC4626 function maxMint(address account) public view virtual nonReentrantView returns (uint256) { - MarketCache memory marketCache = loadMarket(); + VaultCache memory vaultCache = loadMarket(); - if (marketCache.disabledOps.isSet(OP_MINT)) return 0; - return maxDepositInternal(marketCache, account).toAssets().toSharesDown(marketCache).toUint(); + if (vaultCache.disabledOps.isSet(OP_MINT)) return 0; + return maxDepositInternal(vaultCache, account).toAssets().toSharesDown(vaultCache).toUint(); } /// @inheritdoc IERC4626 function previewMint(uint256 shares) public view virtual nonReentrantView returns (uint256) { - MarketCache memory marketCache = loadMarket(); - return shares.toShares().toAssetsUp(marketCache).toUint(); + VaultCache memory vaultCache = loadMarket(); + return shares.toShares().toAssetsUp(vaultCache).toUint(); } /// @inheritdoc IERC4626 function maxWithdraw(address owner) public view virtual nonReentrantView returns (uint256) { - MarketCache memory marketCache = loadMarket(); - if (marketCache.disabledOps.isSet(OP_WITHDRAW)) return 0; + VaultCache memory vaultCache = loadMarket(); + if (vaultCache.disabledOps.isSet(OP_WITHDRAW)) return 0; - return maxRedeemInternal(owner).toAssetsDown(marketCache).toUint(); + return maxRedeemInternal(owner).toAssetsDown(vaultCache).toUint(); } /// @inheritdoc IERC4626 function previewWithdraw(uint256 assets) public view virtual nonReentrantView returns (uint256) { - MarketCache memory marketCache = loadMarket(); - return assets.toAssets().toSharesUp(marketCache).toUint(); + VaultCache memory vaultCache = loadMarket(); + return assets.toAssets().toSharesUp(vaultCache).toUint(); } /// @inheritdoc IERC4626 function maxRedeem(address owner) public view virtual nonReentrantView returns (uint256) { - MarketCache memory marketCache = loadMarket(); - if (marketCache.disabledOps.isSet(OP_REDEEM)) return 0; + VaultCache memory vaultCache = loadMarket(); + if (vaultCache.disabledOps.isSet(OP_REDEEM)) return 0; return maxRedeemInternal(owner).toUint(); } @@ -100,81 +100,80 @@ abstract contract VaultModule is IVault, Base, AssetTransfers, BalanceUtils { /// @inheritdoc IVault function accumulatedFeesAssets() public view virtual nonReentrantView returns (uint256) { - MarketCache memory marketCache = loadMarket(); + VaultCache memory vaultCache = loadMarket(); - return marketCache.accumulatedFees.toAssetsDown(marketCache).toUint(); + return vaultCache.accumulatedFees.toAssetsDown(vaultCache).toUint(); } /// @inheritdoc IVault function creator() public view virtual reentrantOK returns (address) { - return marketStorage().creator; + return vaultStorage().creator; } /// @inheritdoc IERC4626 function deposit(uint256 amount, address receiver) public virtual nonReentrant returns (uint256) { - (MarketCache memory marketCache, address account) = initOperation(OP_DEPOSIT, CHECKACCOUNT_NONE); + (VaultCache memory vaultCache, address account) = initOperation(OP_DEPOSIT, CHECKACCOUNT_NONE); - Assets assets = - amount == type(uint256).max ? marketCache.asset.balanceOf(account).toAssets() : amount.toAssets(); + Assets assets = amount == type(uint256).max ? vaultCache.asset.balanceOf(account).toAssets() : amount.toAssets(); if (assets.isZero()) return 0; - Shares shares = assets.toSharesDown(marketCache); + Shares shares = assets.toSharesDown(vaultCache); if (shares.isZero()) revert E_ZeroShares(); - finalizeDeposit(marketCache, assets, shares, account, receiver); + finalizeDeposit(vaultCache, assets, shares, account, receiver); return shares.toUint(); } /// @inheritdoc IERC4626 function mint(uint256 amount, address receiver) public virtual nonReentrant returns (uint256) { - (MarketCache memory marketCache, address account) = initOperation(OP_MINT, CHECKACCOUNT_NONE); + (VaultCache memory vaultCache, address account) = initOperation(OP_MINT, CHECKACCOUNT_NONE); Shares shares = amount.toShares(); if (shares.isZero()) return 0; - Assets assets = shares.toAssetsUp(marketCache); + Assets assets = shares.toAssetsUp(vaultCache); - finalizeDeposit(marketCache, assets, shares, account, receiver); + finalizeDeposit(vaultCache, assets, shares, account, receiver); return assets.toUint(); } /// @inheritdoc IERC4626 function withdraw(uint256 amount, address receiver, address owner) public virtual nonReentrant returns (uint256) { - (MarketCache memory marketCache, address account) = initOperation(OP_WITHDRAW, owner); + (VaultCache memory vaultCache, address account) = initOperation(OP_WITHDRAW, owner); Assets assets = amount.toAssets(); if (assets.isZero()) return 0; - Shares shares = assets.toSharesUp(marketCache); + Shares shares = assets.toSharesUp(vaultCache); - finalizeWithdraw(marketCache, assets, shares, account, receiver, owner); + finalizeWithdraw(vaultCache, assets, shares, account, receiver, owner); return shares.toUint(); } /// @inheritdoc IERC4626 function redeem(uint256 amount, address receiver, address owner) public virtual nonReentrant returns (uint256) { - (MarketCache memory marketCache, address account) = initOperation(OP_REDEEM, owner); + (VaultCache memory vaultCache, address account) = initOperation(OP_REDEEM, owner); - Shares shares = amount == type(uint256).max ? marketStorage().users[owner].getBalance() : amount.toShares(); + Shares shares = amount == type(uint256).max ? vaultStorage().users[owner].getBalance() : amount.toShares(); if (shares.isZero()) return 0; - Assets assets = shares.toAssetsDown(marketCache); + Assets assets = shares.toAssetsDown(vaultCache); if (assets.isZero()) revert E_ZeroAssets(); - finalizeWithdraw(marketCache, assets, shares, account, receiver, owner); + finalizeWithdraw(vaultCache, assets, shares, account, receiver, owner); return assets.toUint(); } /// @inheritdoc IVault function skim(uint256 amount, address receiver) public virtual nonReentrant returns (uint256) { - (MarketCache memory marketCache, address account) = initOperation(OP_SKIM, CHECKACCOUNT_NONE); + (VaultCache memory vaultCache, address account) = initOperation(OP_SKIM, CHECKACCOUNT_NONE); - Assets balance = marketCache.asset.balanceOf(address(this)).toAssets(); - Assets available = balance <= marketCache.cash ? Assets.wrap(0) : balance - marketCache.cash; + Assets balance = vaultCache.asset.balanceOf(address(this)).toAssets(); + Assets available = balance <= vaultCache.cash ? Assets.wrap(0) : balance - vaultCache.cash; Assets assets; if (amount == type(uint256).max) { @@ -185,53 +184,53 @@ abstract contract VaultModule is IVault, Base, AssetTransfers, BalanceUtils { } if (assets.isZero()) return 0; - Shares shares = assets.toSharesDown(marketCache); + Shares shares = assets.toSharesDown(vaultCache); if (shares.isZero()) revert E_ZeroShares(); - if (marketCache.configFlags.isSet(CFG_ONLY_ASSET_CAN_DEPOSIT) && receiver != asset()) { + if (vaultCache.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; + increaseBalance(vaultCache, receiver, account, shares, assets); + vaultStorage().cash = vaultCache.cash = vaultCache.cash + assets; return shares.toUint(); } function finalizeDeposit( - MarketCache memory marketCache, + VaultCache memory vaultCache, Assets assets, Shares shares, address sender, address receiver ) private { - if (marketCache.configFlags.isSet(CFG_ONLY_ASSET_CAN_DEPOSIT) && sender != asset()) { + if (vaultCache.configFlags.isSet(CFG_ONLY_ASSET_CAN_DEPOSIT) && sender != asset()) { revert E_OnlyAssetCanDeposit(); } - pullAssets(marketCache, sender, assets); + pullAssets(vaultCache, sender, assets); - increaseBalance(marketCache, receiver, sender, shares, assets); + increaseBalance(vaultCache, receiver, sender, shares, assets); } function finalizeWithdraw( - MarketCache memory marketCache, + VaultCache memory vaultCache, Assets assets, Shares shares, address sender, address receiver, address owner ) private { - if (marketCache.cash < assets) revert E_InsufficientCash(); + if (vaultCache.cash < assets) revert E_InsufficientCash(); decreaseAllowance(owner, sender, shares); - decreaseBalance(marketCache, owner, sender, receiver, shares, assets); + decreaseBalance(vaultCache, owner, sender, receiver, shares, assets); - pushAssets(marketCache, receiver, assets); + pushAssets(vaultCache, receiver, assets); } function maxRedeemInternal(address owner) internal view returns (Shares) { - Shares max = marketStorage().users[owner].getBalance(); + Shares max = vaultStorage().users[owner].getBalance(); if (max.isZero()) return max; // When checks are deferred, all of the balance can be withdrawn, even if only temporarily @@ -251,28 +250,28 @@ abstract contract VaultModule is IVault, Base, AssetTransfers, BalanceUtils { } } - MarketCache memory marketCache = loadMarket(); + VaultCache memory vaultCache = loadMarket(); - Shares cash = marketCache.cash.toSharesDown(marketCache); + Shares cash = vaultCache.cash.toSharesDown(vaultCache); max = max > cash ? cash : max; return max; } - function maxDepositInternal(MarketCache memory marketCache, address) private view returns (uint256) { + function maxDepositInternal(VaultCache memory vaultCache, address) private view returns (uint256) { uint256 remainingSupply; // In transient state with vault status checks deferred, supply caps will not be immediately enforced if (isVaultStatusCheckDeferred()) { remainingSupply = type(uint256).max; } else { - uint256 supply = totalAssetsInternal(marketCache); - if (supply >= marketCache.supplyCap) return 0; + uint256 supply = totalAssetsInternal(vaultCache); + if (supply >= vaultCache.supplyCap) return 0; - remainingSupply = marketCache.supplyCap - supply; + remainingSupply = vaultCache.supplyCap - supply; } - uint256 remainingCash = MAX_SANE_AMOUNT - marketCache.cash.toUint(); + uint256 remainingCash = MAX_SANE_AMOUNT - vaultCache.cash.toUint(); return remainingCash < remainingSupply ? remainingCash : remainingSupply; } diff --git a/src/EVault/shared/AssetTransfers.sol b/src/EVault/shared/AssetTransfers.sol index b73465b7..d5f82796 100644 --- a/src/EVault/shared/AssetTransfers.sol +++ b/src/EVault/shared/AssetTransfers.sol @@ -11,23 +11,23 @@ abstract contract AssetTransfers is Base { using TypesLib for uint256; using SafeERC20Lib for IERC20; - function pullAssets(MarketCache memory marketCache, address from, Assets amount) internal { - marketCache.asset.safeTransferFrom(from, address(this), amount.toUint(), permit2); - marketStorage().cash = marketCache.cash = marketCache.cash + amount; + function pullAssets(VaultCache memory vaultCache, address from, Assets amount) internal { + vaultCache.asset.safeTransferFrom(from, address(this), amount.toUint(), permit2); + vaultStorage().cash = vaultCache.cash = vaultCache.cash + amount; } - function pushAssets(MarketCache memory marketCache, address to, Assets amount) internal { + function pushAssets(VaultCache memory vaultCache, address to, Assets amount) internal { if ( to == address(0) // If the underlying asset is not EVC-compatible, do not transfer assets to any // address that the EVC knows to be a sub-account. Non-EVC-compatible tokens do // not know about sub-accounts, so the funds would be lost. - || (marketCache.configFlags.isNotSet(CFG_EVC_COMPATIBLE_ASSET) && isKnownSubaccount(to)) + || (vaultCache.configFlags.isNotSet(CFG_EVC_COMPATIBLE_ASSET) && isKnownSubaccount(to)) ) { revert E_BadAssetReceiver(); } - marketStorage().cash = marketCache.cash = marketCache.cash - amount; - marketCache.asset.safeTransfer(to, amount.toUint()); + vaultStorage().cash = vaultCache.cash = vaultCache.cash - amount; + vaultCache.asset.safeTransfer(to, amount.toUint()); } } diff --git a/src/EVault/shared/BalanceUtils.sol b/src/EVault/shared/BalanceUtils.sol index 94da3e2e..cf366d62 100644 --- a/src/EVault/shared/BalanceUtils.sol +++ b/src/EVault/shared/BalanceUtils.sol @@ -13,7 +13,7 @@ abstract contract BalanceUtils is Base { // Balances function increaseBalance( - MarketCache memory marketCache, + VaultCache memory vaultCache, address account, address sender, Shares amount, @@ -21,13 +21,13 @@ abstract contract BalanceUtils is Base { ) internal { if (account == address(0)) revert E_BadSharesReceiver(); - Market storage _marketStorage = marketStorage(); + VaultData storage _vaultStorage = vaultStorage(); (Shares origBalance, bool balanceForwarderEnabled) = - _marketStorage.users[account].getBalanceAndBalanceForwarder(); + _vaultStorage.users[account].getBalanceAndBalanceForwarder(); Shares newBalance = origBalance + amount; - _marketStorage.users[account].setBalance(newBalance); - _marketStorage.totalShares = marketCache.totalShares = marketCache.totalShares + amount; + _vaultStorage.users[account].setBalance(newBalance); + _vaultStorage.totalShares = vaultCache.totalShares = vaultCache.totalShares + amount; if (balanceForwarderEnabled) { tryBalanceTrackerHook(account, newBalance.toUint(), false); @@ -38,17 +38,17 @@ abstract contract BalanceUtils is Base { } function decreaseBalance( - MarketCache memory marketCache, + VaultCache memory vaultCache, address account, address sender, address receiver, Shares amount, Assets assets ) internal { - Market storage _marketStorage = marketStorage(); + VaultData storage _vaultStorage = vaultStorage(); (Shares origBalance, bool balanceForwarderEnabled) = - _marketStorage.users[account].getBalanceAndBalanceForwarder(); + _vaultStorage.users[account].getBalanceAndBalanceForwarder(); if (origBalance < amount) revert E_InsufficientBalance(); Shares newBalance; @@ -56,8 +56,8 @@ abstract contract BalanceUtils is Base { newBalance = origBalance - amount; } - _marketStorage.users[account].setBalance(newBalance); - _marketStorage.totalShares = marketCache.totalShares = marketCache.totalShares - amount; + _vaultStorage.users[account].setBalance(newBalance); + _vaultStorage.totalShares = vaultCache.totalShares = vaultCache.totalShares - amount; if (balanceForwarderEnabled) { tryBalanceTrackerHook(account, newBalance.toUint(), isControlCollateralInProgress()); @@ -68,14 +68,14 @@ abstract contract BalanceUtils is Base { } function transferBalance(address from, address to, Shares amount) internal { - Market storage _marketStorage = marketStorage(); + VaultData storage _vaultStorage = vaultStorage(); if (!amount.isZero()) { (Shares origFromBalance, bool fromBalanceForwarderEnabled) = - _marketStorage.users[from].getBalanceAndBalanceForwarder(); + _vaultStorage.users[from].getBalanceAndBalanceForwarder(); (Shares origToBalance, bool toBalanceForwarderEnabled) = - _marketStorage.users[to].getBalanceAndBalanceForwarder(); + _vaultStorage.users[to].getBalanceAndBalanceForwarder(); if (origFromBalance < amount) revert E_InsufficientBalance(); @@ -85,8 +85,8 @@ abstract contract BalanceUtils is Base { } Shares newToBalance = origToBalance + amount; - _marketStorage.users[from].setBalance(newFromBalance); - _marketStorage.users[to].setBalance(newToBalance); + _vaultStorage.users[from].setBalance(newFromBalance); + _vaultStorage.users[to].setBalance(newToBalance); if (fromBalanceForwarderEnabled) { tryBalanceTrackerHook(from, newFromBalance.toUint(), isControlCollateralInProgress()); @@ -105,21 +105,21 @@ abstract contract BalanceUtils is Base { function setAllowance(address owner, address spender, uint256 amount) internal { if (spender == owner) revert E_SelfApproval(); - marketStorage().users[owner].eTokenAllowance[spender] = amount; + vaultStorage().users[owner].eTokenAllowance[spender] = amount; emit Approval(owner, spender, amount); } function decreaseAllowance(address owner, address spender, Shares amount) internal { if (amount.isZero()) return; - Market storage _marketStorage = marketStorage(); + VaultData storage _vaultStorage = vaultStorage(); - uint256 allowance = _marketStorage.users[owner].eTokenAllowance[spender]; + uint256 allowance = _vaultStorage.users[owner].eTokenAllowance[spender]; if (owner != spender && allowance != type(uint256).max) { if (allowance < amount.toUint()) revert E_InsufficientAllowance(); unchecked { allowance -= amount.toUint(); } - _marketStorage.users[owner].eTokenAllowance[spender] = allowance; + _vaultStorage.users[owner].eTokenAllowance[spender] = allowance; emit Approval(owner, spender, allowance); } } diff --git a/src/EVault/shared/Base.sol b/src/EVault/shared/Base.sol index 9f361551..0021574b 100644 --- a/src/EVault/shared/Base.sol +++ b/src/EVault/shared/Base.sol @@ -34,30 +34,30 @@ abstract contract Base is EVCClient, Cache, SnapshotStorage { } // documentation only modifier nonReentrant() { - Market storage _marketStorage = marketStorage(); - if (_marketStorage.reentrancyLocked) revert E_Reentrancy(); + VaultData storage _vaultStorage = vaultStorage(); + if (_vaultStorage.reentrancyLocked) revert E_Reentrancy(); - _marketStorage.reentrancyLocked = true; + _vaultStorage.reentrancyLocked = true; _; - _marketStorage.reentrancyLocked = false; + _vaultStorage.reentrancyLocked = false; } modifier nonReentrantView() { - if (marketStorage().reentrancyLocked) revert E_Reentrancy(); + if (vaultStorage().reentrancyLocked) revert E_Reentrancy(); _; } // Generate a market snapshot and store it. // Queue vault and maybe account checks in the EVC (caller, current, onBehalfOf or none). // If needed, revert if this contract is not the controller of the authenticated account. - // Returns the MarketCache and active account. + // Returns the VaultCache and active account. function initOperation(uint32 operation, address accountToCheck) internal - returns (MarketCache memory marketCache, address account) + returns (VaultCache memory vaultCache, address account) { - marketCache = updateMarket(); + vaultCache = updateMarket(); - if (marketCache.disabledOps.isSet(operation)) { + if (vaultCache.disabledOps.isSet(operation)) { revert E_OperationDisabled(); } @@ -65,11 +65,11 @@ abstract contract Base is EVCClient, Cache, SnapshotStorage { // increased when checking the borrowing cap. Caps are not checked when the capped variables decrease (become safer). // For this reason, the snapshot is disabled if both caps are disabled. if ( - !marketCache.snapshotInitialized - && (marketCache.supplyCap < type(uint256).max || marketCache.borrowCap < type(uint256).max) + !vaultCache.snapshotInitialized + && (vaultCache.supplyCap < type(uint256).max || vaultCache.borrowCap < type(uint256).max) ) { - marketStorage().snapshotInitialized = marketCache.snapshotInitialized = true; - snapshotStorage().set(marketCache.cash, marketCache.totalBorrows.toAssetsUp()); + vaultStorage().snapshotInitialized = vaultCache.snapshotInitialized = true; + snapshotStorage().set(vaultCache.cash, vaultCache.totalBorrows.toAssetsUp()); } account = EVCAuthenticateDeferred(~CONTROLLER_REQUIRED_OPS & operation == 0); @@ -77,7 +77,7 @@ abstract contract Base is EVCClient, Cache, SnapshotStorage { EVCRequireStatusChecks(accountToCheck == CHECKACCOUNT_CALLER ? account : accountToCheck); } - function logMarketStatus(MarketCache memory a, uint256 interestRate) internal { + function logMarketStatus(VaultCache memory a, uint256 interestRate) internal { emit MarketStatus( a.totalShares.toUint(), a.totalBorrows.toAssetsUp().toUint(), diff --git a/src/EVault/shared/BorrowUtils.sol b/src/EVault/shared/BorrowUtils.sol index 6031be1e..315e4ea3 100644 --- a/src/EVault/shared/BorrowUtils.sol +++ b/src/EVault/shared/BorrowUtils.sol @@ -11,45 +11,45 @@ import "./types/Types.sol"; abstract contract BorrowUtils is Base { using TypesLib for uint256; - function getCurrentOwed(MarketCache memory marketCache, address account, Owed owed) internal view returns (Owed) { + function getCurrentOwed(VaultCache memory vaultCache, address account, Owed owed) internal view returns (Owed) { // Don't bother loading the user's accumulator if (owed.isZero()) return Owed.wrap(0); // Can't divide by 0 here: If owed is non-zero, we must've initialized the user's interestAccumulator - return owed.mulDiv(marketCache.interestAccumulator, marketStorage().users[account].interestAccumulator); + return owed.mulDiv(vaultCache.interestAccumulator, vaultStorage().users[account].interestAccumulator); } - function getCurrentOwed(MarketCache memory marketCache, address account) internal view returns (Owed) { - return getCurrentOwed(marketCache, account, marketStorage().users[account].getOwed()); + function getCurrentOwed(VaultCache memory vaultCache, address account) internal view returns (Owed) { + return getCurrentOwed(vaultCache, account, vaultStorage().users[account].getOwed()); } - function updateUserBorrow(MarketCache memory marketCache, address account) + function updateUserBorrow(VaultCache memory vaultCache, address account) private returns (Owed newOwed, Owed prevOwed) { - Market storage _marketStorage = marketStorage(); - prevOwed = _marketStorage.users[account].getOwed(); - newOwed = getCurrentOwed(marketCache, account, prevOwed); + VaultData storage _vaultStorage = vaultStorage(); + prevOwed = _vaultStorage.users[account].getOwed(); + newOwed = getCurrentOwed(vaultCache, account, prevOwed); - _marketStorage.users[account].setOwed(newOwed); - _marketStorage.users[account].interestAccumulator = marketCache.interestAccumulator; + _vaultStorage.users[account].setOwed(newOwed); + _vaultStorage.users[account].interestAccumulator = vaultCache.interestAccumulator; } - function increaseBorrow(MarketCache memory marketCache, address account, Assets assets) internal { - (Owed owed, Owed prevOwed) = updateUserBorrow(marketCache, account); + function increaseBorrow(VaultCache memory vaultCache, address account, Assets assets) internal { + (Owed owed, Owed prevOwed) = updateUserBorrow(vaultCache, account); Owed amount = assets.toOwed(); owed = owed + amount; - Market storage _marketStorage = marketStorage(); - _marketStorage.users[account].setOwed(owed); - _marketStorage.totalBorrows = marketCache.totalBorrows = marketCache.totalBorrows + amount; + VaultData storage _vaultStorage = vaultStorage(); + _vaultStorage.users[account].setOwed(owed); + _vaultStorage.totalBorrows = vaultCache.totalBorrows = vaultCache.totalBorrows + amount; logBorrowChange(account, prevOwed, owed); } - function decreaseBorrow(MarketCache memory marketCache, address account, Assets amount) internal { - (Owed owedExact, Owed prevOwed) = updateUserBorrow(marketCache, account); + function decreaseBorrow(VaultCache memory vaultCache, address account, Assets amount) internal { + (Owed owedExact, Owed prevOwed) = updateUserBorrow(vaultCache, account); Assets owed = owedExact.toAssetsUp(); if (amount > owed) revert E_RepayTooMuch(); @@ -59,19 +59,19 @@ abstract contract BorrowUtils is Base { owedRemaining = (owed - amount).toOwed(); } - Market storage _marketStorage = marketStorage(); - _marketStorage.users[account].setOwed(owedRemaining); - _marketStorage.totalBorrows = marketCache.totalBorrows = - marketCache.totalBorrows > owedExact ? marketCache.totalBorrows - owedExact + owedRemaining : owedRemaining; + VaultData storage _vaultStorage = vaultStorage(); + _vaultStorage.users[account].setOwed(owedRemaining); + _vaultStorage.totalBorrows = vaultCache.totalBorrows = + vaultCache.totalBorrows > owedExact ? vaultCache.totalBorrows - owedExact + owedRemaining : owedRemaining; logBorrowChange(account, prevOwed, owedRemaining); } - function transferBorrow(MarketCache memory marketCache, address from, address to, Assets assets) internal { + function transferBorrow(VaultCache memory vaultCache, address from, address to, Assets assets) internal { Owed amount = assets.toOwed(); - (Owed fromOwed, Owed fromOwedPrev) = updateUserBorrow(marketCache, from); - (Owed toOwed, Owed toOwedPrev) = updateUserBorrow(marketCache, to); + (Owed fromOwed, Owed fromOwedPrev) = updateUserBorrow(vaultCache, from); + (Owed toOwed, Owed toOwedPrev) = updateUserBorrow(vaultCache, to); // If amount was rounded up, or dust is left over, transfer exact amount owed if ((amount > fromOwed && (amount - fromOwed).isDust()) || (amount < fromOwed && (fromOwed - amount).isDust())) @@ -87,49 +87,49 @@ abstract contract BorrowUtils is Base { toOwed = toOwed + amount; - Market storage _marketStorage = marketStorage(); - _marketStorage.users[from].setOwed(fromOwed); - _marketStorage.users[to].setOwed(toOwed); + VaultData storage _vaultStorage = vaultStorage(); + _vaultStorage.users[from].setOwed(fromOwed); + _vaultStorage.users[to].setOwed(toOwed); logBorrowChange(from, fromOwedPrev, fromOwed); logBorrowChange(to, toOwedPrev, toOwed); } - function computeInterestRate(MarketCache memory marketCache) internal virtual returns (uint256) { + function computeInterestRate(VaultCache memory vaultCache) internal virtual returns (uint256) { // single sload - Market storage _marketStorage = marketStorage(); - address irm = _marketStorage.interestRateModel; - uint256 newInterestRate = _marketStorage.interestRate; + VaultData storage _vaultStorage = vaultStorage(); + address irm = _vaultStorage.interestRateModel; + uint256 newInterestRate = _vaultStorage.interestRate; if (irm != address(0)) { (bool success, bytes memory data) = irm.call( abi.encodeCall( IIRM.computeInterestRate, - (address(this), marketCache.cash.toUint(), marketCache.totalBorrows.toAssetsUp().toUint()) + (address(this), vaultCache.cash.toUint(), vaultCache.totalBorrows.toAssetsUp().toUint()) ) ); if (success && data.length >= 32) { newInterestRate = abi.decode(data, (uint256)); if (newInterestRate > MAX_ALLOWED_INTEREST_RATE) newInterestRate = MAX_ALLOWED_INTEREST_RATE; - marketStorage().interestRate = uint72(newInterestRate); + vaultStorage().interestRate = uint72(newInterestRate); } } return newInterestRate; } - function computeInterestRateView(MarketCache memory marketCache) internal view virtual returns (uint256) { + function computeInterestRateView(VaultCache memory vaultCache) internal view virtual returns (uint256) { // single sload - Market storage _marketStorage = marketStorage(); - address irm = _marketStorage.interestRateModel; - uint256 newInterestRate = _marketStorage.interestRate; + VaultData storage _vaultStorage = vaultStorage(); + address irm = _vaultStorage.interestRateModel; + uint256 newInterestRate = _vaultStorage.interestRate; if (irm != address(0) && isVaultStatusCheckDeferred()) { (bool success, bytes memory data) = irm.staticcall( abi.encodeCall( IIRM.computeInterestRateView, - (address(this), marketCache.cash.toUint(), marketCache.totalBorrows.toAssetsUp().toUint()) + (address(this), vaultCache.cash.toUint(), vaultCache.totalBorrows.toAssetsUp().toUint()) ) ); diff --git a/src/EVault/shared/Cache.sol b/src/EVault/shared/Cache.sol index 75f89a25..7098ba6c 100644 --- a/src/EVault/shared/Cache.sol +++ b/src/EVault/shared/Cache.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; -import {MarketStorage} from "./MarketStorage.sol"; +import {VaultStorage} from "./VaultStorage.sol"; import {Errors} from "./Errors.sol"; import {RPow} from "./lib/RPow.sol"; import {SafeERC20Lib} from "./lib/SafeERC20Lib.sol"; @@ -10,74 +10,74 @@ import {ProxyUtils} from "./lib/ProxyUtils.sol"; import "./types/Types.sol"; -contract Cache is MarketStorage, Errors { +contract Cache is VaultStorage, Errors { using TypesLib for uint256; using SafeERC20Lib for IERC20; - // Returns an updated MarketCache - // If different from MarketStorage, updates MarketStorage - function updateMarket() internal returns (MarketCache memory marketCache) { - if (initMarketCache(marketCache)) { - Market storage _marketStorage = marketStorage(); - _marketStorage.lastInterestAccumulatorUpdate = marketCache.lastInterestAccumulatorUpdate; - _marketStorage.accumulatedFees = marketCache.accumulatedFees; + // Returns an updated VaultCache + // If different from VaultStorage, updates VaultStorage + function updateMarket() internal returns (VaultCache memory vaultCache) { + if (initMarketCache(vaultCache)) { + VaultData storage _vaultStorage = vaultStorage(); + _vaultStorage.lastInterestAccumulatorUpdate = vaultCache.lastInterestAccumulatorUpdate; + _vaultStorage.accumulatedFees = vaultCache.accumulatedFees; - _marketStorage.totalShares = marketCache.totalShares; - _marketStorage.totalBorrows = marketCache.totalBorrows; + _vaultStorage.totalShares = vaultCache.totalShares; + _vaultStorage.totalBorrows = vaultCache.totalBorrows; - _marketStorage.interestAccumulator = marketCache.interestAccumulator; + _vaultStorage.interestAccumulator = vaultCache.interestAccumulator; } } - // Returns an updated MarketCache - function loadMarket() internal view returns (MarketCache memory marketCache) { - initMarketCache(marketCache); + // Returns an updated VaultCache + function loadMarket() internal view returns (VaultCache memory vaultCache) { + initMarketCache(vaultCache); } - // Takes a MarketCache struct, overwrites it with MarketStorage data and, if time has passed since MarkeStorage + // Takes a VaultCache struct, overwrites it with VaultStorage data and, if time has passed since MarkeStorage // was last updated, updates MarkeStorage. - // Returns a MarketCache updated to this block. - function initMarketCache(MarketCache memory marketCache) private view returns (bool dirty) { + // Returns a VaultCache updated to this block. + function initMarketCache(VaultCache memory vaultCache) private view returns (bool dirty) { dirty = false; // Proxy metadata - (marketCache.asset, marketCache.oracle, marketCache.unitOfAccount) = ProxyUtils.metadata(); + (vaultCache.asset, vaultCache.oracle, vaultCache.unitOfAccount) = ProxyUtils.metadata(); // Storage loads - Market storage _marketStorage = marketStorage(); - marketCache.lastInterestAccumulatorUpdate = _marketStorage.lastInterestAccumulatorUpdate; - marketCache.cash = _marketStorage.cash; - marketCache.supplyCap = _marketStorage.supplyCap.toUint(); - marketCache.borrowCap = _marketStorage.borrowCap.toUint(); - marketCache.disabledOps = _marketStorage.disabledOps; - marketCache.snapshotInitialized = _marketStorage.snapshotInitialized; + VaultData storage _vaultStorage = vaultStorage(); + vaultCache.lastInterestAccumulatorUpdate = _vaultStorage.lastInterestAccumulatorUpdate; + vaultCache.cash = _vaultStorage.cash; + vaultCache.supplyCap = _vaultStorage.supplyCap.toUint(); + vaultCache.borrowCap = _vaultStorage.borrowCap.toUint(); + vaultCache.disabledOps = _vaultStorage.disabledOps; + vaultCache.snapshotInitialized = _vaultStorage.snapshotInitialized; - marketCache.totalShares = _marketStorage.totalShares; - marketCache.totalBorrows = _marketStorage.totalBorrows; + vaultCache.totalShares = _vaultStorage.totalShares; + vaultCache.totalBorrows = _vaultStorage.totalBorrows; - marketCache.accumulatedFees = _marketStorage.accumulatedFees; - marketCache.configFlags = _marketStorage.configFlags; + vaultCache.accumulatedFees = _vaultStorage.accumulatedFees; + vaultCache.configFlags = _vaultStorage.configFlags; - marketCache.interestAccumulator = _marketStorage.interestAccumulator; + vaultCache.interestAccumulator = _vaultStorage.interestAccumulator; // Update interest accumulator and fees balance - uint256 deltaT = block.timestamp - marketCache.lastInterestAccumulatorUpdate; + uint256 deltaT = block.timestamp - vaultCache.lastInterestAccumulatorUpdate; if (deltaT > 0) { dirty = true; - if (marketCache.disabledOps.isSet(OP_ACCRUE_INTEREST)) { - marketCache.lastInterestAccumulatorUpdate = uint48(block.timestamp); + if (vaultCache.disabledOps.isSet(OP_ACCRUE_INTEREST)) { + vaultCache.lastInterestAccumulatorUpdate = uint48(block.timestamp); return dirty; } // Compute new values. Use full precision for intermediate results. - ConfigAmount interestFee = _marketStorage.interestFee; - uint256 interestRate = _marketStorage.interestRate; + ConfigAmount interestFee = _vaultStorage.interestFee; + uint256 interestRate = _vaultStorage.interestRate; - uint256 newInterestAccumulator = marketCache.interestAccumulator; + uint256 newInterestAccumulator = vaultCache.interestAccumulator; unchecked { (uint256 multiplier, bool overflow) = RPow.rpow(interestRate + 1e27, deltaT, 1e27); @@ -91,35 +91,35 @@ contract Cache is MarketStorage, Errors { } uint256 newTotalBorrows = - marketCache.totalBorrows.toUint() * newInterestAccumulator / marketCache.interestAccumulator; - uint256 newAccumulatedFees = marketCache.accumulatedFees.toUint(); - uint256 newTotalShares = marketCache.totalShares.toUint(); + vaultCache.totalBorrows.toUint() * newInterestAccumulator / vaultCache.interestAccumulator; + uint256 newAccumulatedFees = vaultCache.accumulatedFees.toUint(); + uint256 newTotalShares = vaultCache.totalShares.toUint(); uint256 feeAssets = - interestFee.mulDiv(newTotalBorrows - marketCache.totalBorrows.toUint(), 1 << INTERNAL_DEBT_PRECISION); + interestFee.mulDiv(newTotalBorrows - vaultCache.totalBorrows.toUint(), 1 << INTERNAL_DEBT_PRECISION); if (feeAssets != 0) { - uint256 newTotalAssets = marketCache.cash.toUint() + (newTotalBorrows >> INTERNAL_DEBT_PRECISION); + uint256 newTotalAssets = vaultCache.cash.toUint() + (newTotalBorrows >> INTERNAL_DEBT_PRECISION); newTotalShares = newTotalAssets * newTotalShares / (newTotalAssets - feeAssets); - newAccumulatedFees += newTotalShares - marketCache.totalShares.toUint(); + newAccumulatedFees += newTotalShares - vaultCache.totalShares.toUint(); } - // Store new values in marketCache, only if no overflows will occur. Fees are not larger than total shares, since they are included in them. + // Store new values in vaultCache, only if no overflows will occur. Fees are not larger than total shares, since they are included in them. if (newTotalShares <= MAX_SANE_AMOUNT && newTotalBorrows <= MAX_SANE_DEBT_AMOUNT) { - marketCache.totalBorrows = newTotalBorrows.toOwed(); - marketCache.interestAccumulator = newInterestAccumulator; - marketCache.lastInterestAccumulatorUpdate = uint48(block.timestamp); + vaultCache.totalBorrows = newTotalBorrows.toOwed(); + vaultCache.interestAccumulator = newInterestAccumulator; + vaultCache.lastInterestAccumulatorUpdate = uint48(block.timestamp); - if (newTotalShares != Shares.unwrap(marketCache.totalShares)) { - marketCache.accumulatedFees = newAccumulatedFees.toShares(); - marketCache.totalShares = newTotalShares.toShares(); + if (newTotalShares != Shares.unwrap(vaultCache.totalShares)) { + vaultCache.accumulatedFees = newAccumulatedFees.toShares(); + vaultCache.totalShares = newTotalShares.toShares(); } } } } - function totalAssetsInternal(MarketCache memory marketCache) internal pure returns (uint256) { + function totalAssetsInternal(VaultCache memory vaultCache) internal pure returns (uint256) { // total assets can exceed Assets max amount (MAX_SANE_AMOUNT) - return marketCache.cash.toUint() + marketCache.totalBorrows.toAssetsUp().toUint(); + return vaultCache.cash.toUint() + vaultCache.totalBorrows.toAssetsUp().toUint(); } } diff --git a/src/EVault/shared/EVCClient.sol b/src/EVault/shared/EVCClient.sol index 74631454..743f9fb1 100644 --- a/src/EVault/shared/EVCClient.sol +++ b/src/EVault/shared/EVCClient.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; -import {MarketStorage} from "./MarketStorage.sol"; +import {VaultStorage} from "./VaultStorage.sol"; import {Events} from "./Events.sol"; import {Errors} from "./Errors.sol"; import {ProxyUtils} from "./lib/ProxyUtils.sol"; @@ -11,7 +11,7 @@ import "./Constants.sol"; import {IERC20} from "../IEVault.sol"; import {IEVC} from "ethereum-vault-connector/interfaces/IEthereumVaultConnector.sol"; -abstract contract EVCClient is MarketStorage, Events, Errors { +abstract contract EVCClient is VaultStorage, Events, Errors { IEVC immutable evc; modifier onlyEVCChecks() { diff --git a/src/EVault/shared/LTVUtils.sol b/src/EVault/shared/LTVUtils.sol index 37e2a7ec..3e35aacb 100644 --- a/src/EVault/shared/LTVUtils.sol +++ b/src/EVault/shared/LTVUtils.sol @@ -2,15 +2,15 @@ pragma solidity ^0.8.0; -import {MarketStorage} from "./MarketStorage.sol"; +import {VaultStorage} from "./VaultStorage.sol"; import "./types/Types.sol"; -abstract contract LTVUtils is MarketStorage { +abstract contract LTVUtils is VaultStorage { function getLTV(address collateral, LTVType ltvType) internal view virtual returns (ConfigAmount) { - return marketStorage().ltvLookup[collateral].getLTV(ltvType); + return vaultStorage().ltvLookup[collateral].getLTV(ltvType); } function isRecognizedCollateral(address collateral) internal view virtual returns (bool) { - return marketStorage().ltvLookup[collateral].isRecognizedCollateral(); + return vaultStorage().ltvLookup[collateral].isRecognizedCollateral(); } } diff --git a/src/EVault/shared/LiquidityUtils.sol b/src/EVault/shared/LiquidityUtils.sol index ef859908..5630c571 100644 --- a/src/EVault/shared/LiquidityUtils.sol +++ b/src/EVault/shared/LiquidityUtils.sol @@ -12,36 +12,36 @@ abstract contract LiquidityUtils is BorrowUtils, LTVUtils { // Calculate the value of liabilities, and the liquidation or borrowing LTV adjusted collateral value. function calculateLiquidity( - MarketCache memory marketCache, + VaultCache memory vaultCache, address account, address[] memory collaterals, LTVType ltvType ) internal view returns (uint256 collateralValue, uint256 liabilityValue) { - validateOracle(marketCache); + validateOracle(vaultCache); for (uint256 i; i < collaterals.length; ++i) { - collateralValue += getCollateralValue(marketCache, account, collaterals[i], ltvType); + collateralValue += getCollateralValue(vaultCache, account, collaterals[i], ltvType); } - liabilityValue = getLiabilityValue(marketCache, account, marketStorage().users[account].getOwed()); + liabilityValue = getLiabilityValue(vaultCache, account, vaultStorage().users[account].getOwed()); } // Check that the value of the collateral, adjusted for borrowing TVL, is equal or greater than the liability value. - function checkLiquidity(MarketCache memory marketCache, address account, address[] memory collaterals) + function checkLiquidity(VaultCache memory vaultCache, address account, address[] memory collaterals) internal view { - validateOracle(marketCache); + validateOracle(vaultCache); - Owed owed = marketStorage().users[account].getOwed(); + Owed owed = vaultStorage().users[account].getOwed(); if (owed.isZero()) return; - uint256 liabilityValue = getLiabilityValue(marketCache, account, owed); + uint256 liabilityValue = getLiabilityValue(vaultCache, account, owed); if (liabilityValue == 0) return; uint256 collateralValue; for (uint256 i; i < collaterals.length; ++i) { - collateralValue += getCollateralValue(marketCache, account, collaterals[i], LTVType.BORROWING); + collateralValue += getCollateralValue(vaultCache, account, collaterals[i], LTVType.BORROWING); if (collateralValue >= liabilityValue) return; } @@ -65,25 +65,25 @@ abstract contract LiquidityUtils is BorrowUtils, LTVUtils { return true; } - function getLiabilityValue(MarketCache memory marketCache, address account, Owed owed) + function getLiabilityValue(VaultCache memory vaultCache, address account, Owed owed) internal view returns (uint256 value) { // update owed with interest accrued - uint256 owedAssets = getCurrentOwed(marketCache, account, owed).toAssetsUp().toUint(); + uint256 owedAssets = getCurrentOwed(vaultCache, account, owed).toAssetsUp().toUint(); if (owedAssets == 0) return 0; - if (address(marketCache.asset) == marketCache.unitOfAccount) { + if (address(vaultCache.asset) == vaultCache.unitOfAccount) { value = owedAssets; } else { // ask price for liability - (, value) = marketCache.oracle.getQuotes(owedAssets, address(marketCache.asset), marketCache.unitOfAccount); + (, value) = vaultCache.oracle.getQuotes(owedAssets, address(vaultCache.asset), vaultCache.unitOfAccount); } } - function getCollateralValue(MarketCache memory marketCache, address account, address collateral, LTVType ltvType) + function getCollateralValue(VaultCache memory vaultCache, address account, address collateral, LTVType ltvType) internal view returns (uint256 value) @@ -95,12 +95,12 @@ abstract contract LiquidityUtils is BorrowUtils, LTVUtils { if (balance == 0) return 0; // bid price for collateral - (uint256 currentCollateralValue,) = marketCache.oracle.getQuotes(balance, collateral, marketCache.unitOfAccount); + (uint256 currentCollateralValue,) = vaultCache.oracle.getQuotes(balance, collateral, vaultCache.unitOfAccount); return ltv.mul(currentCollateralValue); } - function validateOracle(MarketCache memory marketCache) internal pure { - if (address(marketCache.oracle) == address(0)) revert E_NoPriceOracle(); + function validateOracle(VaultCache memory vaultCache) internal pure { + if (address(vaultCache.oracle) == address(0)) revert E_NoPriceOracle(); } } diff --git a/src/EVault/shared/MarketStorage.sol b/src/EVault/shared/MarketStorage.sol deleted file mode 100644 index c4a223ed..00000000 --- a/src/EVault/shared/MarketStorage.sol +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -pragma solidity ^0.8.0; - -import {Market} from "./types/Market.sol"; - -abstract contract MarketStorage { - // keccak256(abi.encode(uint256(keccak256("euler.evault.storage.Market")) - 1)) & ~bytes32(uint256(0xff)) - bytes32 private constant MARKET_STORAGE = 0xb3678cae26b5810bd240885d3ce17f7b160cb73b8a97793d1d2235fc34b89500; - - /// @dev Storage for main vault data, shared by most modules, implemented on a custom ERC-7201 namespace. - /// MarketStorageStruct is wrapping Market under the same slot only to apply ERC7201 annotation. - /// @custom:storage-location erc7201:euler.evault.storage.Market - struct MarketStorageStruct { - Market market; - } - - function marketStorage() internal pure returns (Market storage data) { - assembly { - data.slot := MARKET_STORAGE - } - } -} diff --git a/src/EVault/shared/VaultStorage.sol b/src/EVault/shared/VaultStorage.sol new file mode 100644 index 00000000..95201da6 --- /dev/null +++ b/src/EVault/shared/VaultStorage.sol @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +pragma solidity ^0.8.0; + +import {VaultData} from "./types/VaultData.sol"; + +abstract contract VaultStorage { + // keccak256(abi.encode(uint256(keccak256("euler.evault.storage.Vault")) - 1)) & ~bytes32(uint256(0xff)) + bytes32 private constant VAULT_STORAGE = 0x384a0d382726f2699c0e311ad26726263e47df8cb46f208c4690e77e78465e00; + + /// @dev Storage for main vault data, shared by most modules, implemented on a custom ERC-7201 namespace. + /// VaultStorageStruct is wrapping VaultData under the same slot only to apply ERC7201 annotation. + /// @custom:storage-location erc7201:euler.evault.storage.VaultData + struct VaultStorageStruct { + VaultData market; + } + + function vaultStorage() internal pure returns (VaultData storage data) { + assembly { + data.slot := VAULT_STORAGE + } + } +} diff --git a/src/EVault/shared/types/Assets.sol b/src/EVault/shared/types/Assets.sol index 7dac6b95..5adddd37 100644 --- a/src/EVault/shared/types/Assets.sol +++ b/src/EVault/shared/types/Assets.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; import {Assets, Shares, Owed, TypesLib} from "./Types.sol"; -import {MarketCache} from "./MarketCache.sol"; +import {VaultCache} from "./VaultCache.sol"; import "../Constants.sol"; import "./ConversionHelpers.sol"; @@ -16,15 +16,15 @@ library AssetsLib { return Assets.unwrap(self) == 0; } - function toSharesDown(Assets amount, MarketCache memory marketCache) internal pure returns (Shares) { - (uint256 totalAssets, uint256 totalShares) = conversionTotals(marketCache); + function toSharesDown(Assets amount, VaultCache memory vaultCache) internal pure returns (Shares) { + (uint256 totalAssets, uint256 totalShares) = conversionTotals(vaultCache); unchecked { return TypesLib.toShares(amount.toUint() * totalShares / totalAssets); } } - function toSharesUp(Assets amount, MarketCache memory marketCache) internal pure returns (Shares) { - (uint256 totalAssets, uint256 totalShares) = conversionTotals(marketCache); + function toSharesUp(Assets amount, VaultCache memory vaultCache) internal pure returns (Shares) { + (uint256 totalAssets, uint256 totalShares) = conversionTotals(vaultCache); unchecked { return TypesLib.toShares((amount.toUint() * totalShares + (totalAssets - 1)) / totalAssets); } diff --git a/src/EVault/shared/types/ConversionHelpers.sol b/src/EVault/shared/types/ConversionHelpers.sol index 19bc5612..1182cfbf 100644 --- a/src/EVault/shared/types/ConversionHelpers.sol +++ b/src/EVault/shared/types/ConversionHelpers.sol @@ -2,15 +2,14 @@ pragma solidity ^0.8.0; -import {MarketCache} from "./MarketCache.sol"; +import {VaultCache} from "./VaultCache.sol"; // virtual deposit used in conversions between shares and assets, serving as exchange rate manipulation mitigation uint256 constant VIRTUAL_DEPOSIT_AMOUNT = 1e6; -function conversionTotals(MarketCache memory marketCache) pure returns (uint256 totalAssets, uint256 totalShares) { +function conversionTotals(VaultCache memory vaultCache) pure returns (uint256 totalAssets, uint256 totalShares) { unchecked { - totalAssets = - marketCache.cash.toUint() + marketCache.totalBorrows.toAssetsUp().toUint() + VIRTUAL_DEPOSIT_AMOUNT; - totalShares = marketCache.totalShares.toUint() + VIRTUAL_DEPOSIT_AMOUNT; + totalAssets = vaultCache.cash.toUint() + vaultCache.totalBorrows.toAssetsUp().toUint() + VIRTUAL_DEPOSIT_AMOUNT; + totalShares = vaultCache.totalShares.toUint() + VIRTUAL_DEPOSIT_AMOUNT; } } diff --git a/src/EVault/shared/types/Shares.sol b/src/EVault/shared/types/Shares.sol index 668040eb..6c07c87d 100644 --- a/src/EVault/shared/types/Shares.sol +++ b/src/EVault/shared/types/Shares.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; import {Shares, Assets, TypesLib} from "./Types.sol"; -import {MarketCache} from "./MarketCache.sol"; +import {VaultCache} from "./VaultCache.sol"; import "./ConversionHelpers.sol"; library SharesLib { @@ -15,15 +15,15 @@ library SharesLib { return Shares.unwrap(self) == 0; } - function toAssetsDown(Shares amount, MarketCache memory marketCache) internal pure returns (Assets) { - (uint256 totalAssets, uint256 totalShares) = conversionTotals(marketCache); + function toAssetsDown(Shares amount, VaultCache memory vaultCache) internal pure returns (Assets) { + (uint256 totalAssets, uint256 totalShares) = conversionTotals(vaultCache); unchecked { return TypesLib.toAssets(amount.toUint() * totalAssets / totalShares); } } - function toAssetsUp(Shares amount, MarketCache memory marketCache) internal pure returns (Assets) { - (uint256 totalAssets, uint256 totalShares) = conversionTotals(marketCache); + function toAssetsUp(Shares amount, VaultCache memory vaultCache) internal pure returns (Assets) { + (uint256 totalAssets, uint256 totalShares) = conversionTotals(vaultCache); unchecked { return TypesLib.toAssets((amount.toUint() * totalAssets + (totalShares - 1)) / totalShares); } diff --git a/src/EVault/shared/types/Types.sol b/src/EVault/shared/types/Types.sol index 8109b1c5..c9191981 100644 --- a/src/EVault/shared/types/Types.sol +++ b/src/EVault/shared/types/Types.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import "../../IEVault.sol"; -import "./Market.sol"; +import "./VaultData.sol"; import "./Snapshot.sol"; import "./User.sol"; import "./LTVConfig.sol"; diff --git a/src/EVault/shared/types/MarketCache.sol b/src/EVault/shared/types/VaultCache.sol similarity index 96% rename from src/EVault/shared/types/MarketCache.sol rename to src/EVault/shared/types/VaultCache.sol index d142a035..9aa56d56 100644 --- a/src/EVault/shared/types/MarketCache.sol +++ b/src/EVault/shared/types/VaultCache.sol @@ -7,7 +7,7 @@ import {IPriceOracle} from "../../../interfaces/IPriceOracle.sol"; import {Assets, Owed, Shares, Flags} from "./Types.sol"; -struct MarketCache { +struct VaultCache { IERC20 asset; IPriceOracle oracle; address unitOfAccount; diff --git a/src/EVault/shared/types/Market.sol b/src/EVault/shared/types/VaultData.sol similarity index 97% rename from src/EVault/shared/types/Market.sol rename to src/EVault/shared/types/VaultData.sol index 50cd71df..f29e24be 100644 --- a/src/EVault/shared/types/Market.sol +++ b/src/EVault/shared/types/VaultData.sol @@ -6,7 +6,7 @@ import {Assets, Shares, Owed, AmountCap, ConfigAmount, Flags} from "./Types.sol" import {LTVConfig} from "./LTVConfig.sol"; import {User} from "./User.sol"; -struct Market { +struct VaultData { // Packed slot 6 + 14 + 2 + 2 + 4 + 1 + 1 = 30 uint48 lastInterestAccumulatorUpdate; Assets cash; @@ -15,34 +15,25 @@ struct Market { Flags disabledOps; bool reentrancyLocked; bool snapshotInitialized; - // Packed slot 14 + 18 = 32 Shares totalShares; Owed totalBorrows; - // Packed slot 14 + 4 = 18 Shares accumulatedFees; Flags configFlags; - uint256 interestAccumulator; - // Packed slot 20 + 2 + 9 = 31 address interestRateModel; // 0% interest, if zero address ConfigAmount interestFee; uint72 interestRate; - string name; string symbol; - address creator; - address governorAdmin; address pauseGuardian; Flags lockedOps; address feeReceiver; - mapping(address account => User) users; - mapping(address collateral => LTVConfig) ltvLookup; address[] ltvList; } diff --git a/test/mocks/MockEVault.sol b/test/mocks/MockEVault.sol index f5dd16d7..1d6f196e 100644 --- a/test/mocks/MockEVault.sol +++ b/test/mocks/MockEVault.sol @@ -11,15 +11,15 @@ contract MockEVault { return "TRANSPARENT"; } - function UNPACK() internal pure returns (address marketAsset) { + function UNPACK() internal pure returns (address vaultAsset) { assembly { - marketAsset := shr(96, calldataload(sub(calldatasize(), 20))) + vaultAsset := shr(96, calldataload(sub(calldatasize(), 20))) } } function arbitraryFunction(string calldata arg) external view returns (string memory, address, address) { - (address marketAsset) = UNPACK(); - return (arg, msg.sender, marketAsset); + (address vaultAsset) = UNPACK(); + return (arg, msg.sender, vaultAsset); } function testExcludeFromCoverage() public pure { diff --git a/test/unit/evault/shared/AssetTransfers.t.sol b/test/unit/evault/shared/AssetTransfers.t.sol index b2b371aa..625371a7 100644 --- a/test/unit/evault/shared/AssetTransfers.t.sol +++ b/test/unit/evault/shared/AssetTransfers.t.sol @@ -10,7 +10,7 @@ import "../EVaultTestBase.t.sol"; contract AssetTransfersHarness is AssetTransfers { constructor() Base(Integrations(address(0), address(0), address(0), address(0))) {} - function exposed_pullAssets(MarketCache memory cache, address from, Assets amount) external { + function exposed_pullAssets(VaultCache memory cache, address from, Assets amount) external { pullAssets(cache, from, amount); } } @@ -35,7 +35,7 @@ contract AssetTransfersTest is EVaultTestBase { cash = bound(cash, 0, MAX_SANE_AMOUNT); amount = bound(amount, 0, MAX_SANE_AMOUNT); vm.assume(cash + amount < MAX_SANE_AMOUNT); - MarketCache memory cache = initCache(); + VaultCache memory cache = initCache(); cache.cash = cash.toAssets(); assetTST.setBalance(address(tc), cash); @@ -51,7 +51,7 @@ contract AssetTransfersTest is EVaultTestBase { } function test_pullAssets_zeroIsNoop() public { - MarketCache memory cache = initCache(); + VaultCache memory cache = initCache(); tc.exposed_pullAssets(cache, from, Assets.wrap(0)); uint256 cashAfter = assetTST.balanceOf(address(tc)); @@ -62,7 +62,7 @@ contract AssetTransfersTest is EVaultTestBase { } function test_pullAssets_deflationaryTransfer() public { - MarketCache memory cache = initCache(); + VaultCache memory cache = initCache(); assetTST.configure("transfer/deflationary", abi.encode(0.5e18)); @@ -75,7 +75,7 @@ contract AssetTransfersTest is EVaultTestBase { } function test_pullAssets_inflationaryTransfer() public { - MarketCache memory cache = initCache(); + VaultCache memory cache = initCache(); assetTST.configure("transfer/inflationary", abi.encode(0.5e18)); @@ -88,7 +88,7 @@ contract AssetTransfersTest is EVaultTestBase { } function test_RevertWhenCashAfterOverflows_pullAssets() public { - MarketCache memory cache = initCache(); + VaultCache memory cache = initCache(); cache.cash = MAX_ASSETS; assetTST.setBalance(address(tc), MAX_ASSETS.toUint()); @@ -103,7 +103,7 @@ contract AssetTransfersTest is EVaultTestBase { tc.exposed_pullAssets(cache, from, MAX_ASSETS); } - function initCache() internal view returns (MarketCache memory cache) { + function initCache() internal view returns (VaultCache memory cache) { cache.asset = IERC20(address(assetTST)); } } diff --git a/test/unit/factory/GenericFactory.t.sol b/test/unit/factory/GenericFactory.t.sol index 413a610e..2e1556c7 100644 --- a/test/unit/factory/GenericFactory.t.sol +++ b/test/unit/factory/GenericFactory.t.sol @@ -50,7 +50,7 @@ contract FactoryTest is Test { assertEq(factory.implementation(), address(2)); } - function test_activateMarket() public { + function test_createVault() public { // Create and install mock eVault impl MockEVault mockEvaultImpl = new MockEVault(address(factory), address(1)); vm.prank(upgradeAdmin); @@ -69,11 +69,11 @@ contract FactoryTest is Test { address randomUser = vm.addr(5000); vm.prank(randomUser); - (string memory outputArg, address theMsgSender, address marketAsset) = eTST.arbitraryFunction(inputArg); + (string memory outputArg, address theMsgSender, address vaultAsset) = eTST.arbitraryFunction(inputArg); assertEq(outputArg, inputArg); assertEq(theMsgSender, randomUser); - assertEq(marketAsset, address(asset)); + assertEq(vaultAsset, address(asset)); } } @@ -83,7 +83,7 @@ contract FactoryTest is Test { vm.prank(upgradeAdmin); factory.setImplementation(address(mockEvaultImpl)); - // Create Tokens and activate Markets + // Create Tokens and activate Vaults uint256 amountEVault = 10; for (uint256 i; i < amountEVault; i++) { TestERC20 TST = new TestERC20("Test Token", "TST", 18, false); @@ -101,7 +101,7 @@ contract FactoryTest is Test { vm.prank(upgradeAdmin); factory.setImplementation(address(mockEvaultImpl)); - // Create Tokens and activate Markets + // Create Tokens and activate Vaults uint256 amountEVaults = 100; address[] memory eVaultsList = new address[](amountEVaults); @@ -146,7 +146,7 @@ contract FactoryTest is Test { vm.prank(upgradeAdmin); factory.setImplementation(address(mockEvaultImpl)); - // Create Tokens and activate Markets + // Create Tokens and activate Vaults TestERC20 TST = new TestERC20("Test Token", "TST", 18, false); MockEVault eVault = MockEVault(factory.createProxy(true, abi.encodePacked(address(TST)))); @@ -208,7 +208,7 @@ contract FactoryTest is Test { factory.setImplementation(address(1)); } - function test_RevertIfNonReentrancy_ActivateMarket() public { + function test_RevertIfNonReentrancy_CreateVault() public { ReentrancyAttack badVaultImpl = new ReentrancyAttack(address(factory), address(1)); vm.prank(upgradeAdmin); factory.setImplementation(address(badVaultImpl)); @@ -219,7 +219,7 @@ contract FactoryTest is Test { factory.createProxy(false, abi.encodePacked(address(asset))); } - function test_RevertIfImplementation_ActivateMarket() public { + function test_RevertIfImplementation_CreateVault() public { address asset = vm.addr(1); vm.expectRevert(GenericFactory.E_Implementation.selector); @@ -242,7 +242,7 @@ contract FactoryTest is Test { vm.prank(upgradeAdmin); factory.setImplementation(address(mockEvaultImpl)); - // Create Tokens and activate Markets + // Create Tokens and activate Vaults uint256 amountEVaults = 100; address[] memory eVaultsList = new address[](amountEVaults);