Skip to content

Commit

Permalink
Merge branch 'master' into hooked-ops
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpawlowski committed Mar 24, 2024
2 parents 785a33d + 09e516a commit 93cad6e
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/EVault/EVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ contract EVault is Dispatch {

function clearLTV(address collateral) public override virtual use(MODULE_GOVERNANCE) {}

function setIRM(address newModel) public override virtual use(MODULE_GOVERNANCE) {}
function setInterestRateModel(address newModel) public override virtual use(MODULE_GOVERNANCE) {}

function setConfigFlags(uint32 newConfigFlags) public override virtual use(MODULE_GOVERNANCE) {}

Expand Down
2 changes: 1 addition & 1 deletion src/EVault/IEVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ interface IGovernance {

/// @notice Set a new interest rate model contract
/// @param newModel Address of the contract
function setIRM(address newModel) external;
function setInterestRateModel(address newModel) external;

/// @notice Set a new hook target and a new bitmap indicating which operations should call the hook target. Operations are defined in Constants.sol
function setHookConfig(address newHookTarget, uint32 newHookedOps) external;
Expand Down
6 changes: 3 additions & 3 deletions src/EVault/modules/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract contract GovernanceModule is IGovernance, Base, BalanceUtils, BorrowUti
event GovSetLTV(
address indexed collateral, uint48 targetTimestamp, uint16 targetLTV, uint32 rampDuration, uint16 originalLTV
);
event GovSetIRM(address interestRateModel);
event GovSetInterestRateModel(address interestRateModel);
event GovSetHookConfig(address indexed newHookTarget, uint32 newHookedOps);
event GovSetConfigFlags(uint32 newConfigFlags);
event GovSetCaps(uint16 newSupplyCap, uint16 newBorrowCap);
Expand Down Expand Up @@ -227,7 +227,7 @@ abstract contract GovernanceModule is IGovernance, Base, BalanceUtils, BorrowUti
}

/// @inheritdoc IGovernance
function setIRM(address newModel) public virtual nonReentrant governorOnly {
function setInterestRateModel(address newModel) public virtual nonReentrant governorOnly {
MarketCache memory marketCache = updateMarket();

marketStorage.interestRateModel = newModel;
Expand All @@ -237,7 +237,7 @@ abstract contract GovernanceModule is IGovernance, Base, BalanceUtils, BorrowUti

logMarketStatus(marketCache, newInterestRate);

emit GovSetIRM(newModel);
emit GovSetInterestRateModel(newModel);
}

/// @inheritdoc IGovernance
Expand Down
22 changes: 22 additions & 0 deletions src/EVault/shared/lib/ConversionHelpers.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {MarketCache} from "../types/MarketCache.sol";

library ConversionHelpers {
// 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)
internal
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;
}
}
}
6 changes: 3 additions & 3 deletions src/EVault/shared/types/Assets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pragma solidity ^0.8.0;

import {Assets, Shares, Owed, TypesLib} from "./Types.sol";
import {MarketCache} from "./MarketCache.sol";
import {ConversionHelpers} from "../lib/ConversionHelpers.sol";
import "../Constants.sol";
import "./ConversionHelpers.sol";

library AssetsLib {
function toUint(Assets self) internal pure returns (uint256) {
Expand All @@ -17,14 +17,14 @@ library AssetsLib {
}

function toSharesDown(Assets amount, MarketCache memory marketCache) internal pure returns (Shares) {
(uint256 totalAssets, uint256 totalShares) = conversionTotals(marketCache);
(uint256 totalAssets, uint256 totalShares) = ConversionHelpers.conversionTotals(marketCache);
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);
(uint256 totalAssets, uint256 totalShares) = ConversionHelpers.conversionTotals(marketCache);
unchecked {
return TypesLib.toShares((amount.toUint() * totalShares + (totalAssets - 1)) / totalAssets);
}
Expand Down
16 changes: 0 additions & 16 deletions src/EVault/shared/types/ConversionHelpers.sol

This file was deleted.

7 changes: 4 additions & 3 deletions src/EVault/shared/types/Shares.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ pragma solidity ^0.8.0;

import {Shares, Assets, TypesLib} from "./Types.sol";
import {MarketCache} from "./MarketCache.sol";
import "./ConversionHelpers.sol";

import {ConversionHelpers} from "../lib/ConversionHelpers.sol";

library SharesLib {
function toUint(Shares self) internal pure returns (uint256) {
Expand All @@ -16,14 +17,14 @@ library SharesLib {
}

function toAssetsDown(Shares amount, MarketCache memory marketCache) internal pure returns (Assets) {
(uint256 totalAssets, uint256 totalShares) = conversionTotals(marketCache);
(uint256 totalAssets, uint256 totalShares) = ConversionHelpers.conversionTotals(marketCache);
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);
(uint256 totalAssets, uint256 totalShares) = ConversionHelpers.conversionTotals(marketCache);
unchecked {
return TypesLib.toAssets((amount.toUint() * totalAssets + (totalShares - 1)) / totalShares);
}
Expand Down
3 changes: 3 additions & 0 deletions src/slither.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"filter_paths": "(/test/|/lib/|/scripts/)"
}
6 changes: 3 additions & 3 deletions test/unit/evault/EVaultTestBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ contract EVaultTestBase is AssertionsCustomTypes, Test, DeployPermit2 {
assetTST2 = new TestERC20("Test Token 2", "TST2", 18, false);

eTST = IEVault(factory.createProxy(true, abi.encodePacked(address(assetTST), address(oracle), unitOfAccount)));
eTST.setIRM(address(new IRMTestDefault()));
eTST.setInterestRateModel(address(new IRMTestDefault()));

eTST2 = IEVault(factory.createProxy(true, abi.encodePacked(address(assetTST2), address(oracle), unitOfAccount)));
eTST2.setIRM(address(new IRMTestDefault()));
eTST2.setInterestRateModel(address(new IRMTestDefault()));
}

address internal SYNTH_VAULT_HOOK_TARGET = address(new MockHook());
uint32 internal constant SYNTH_VAULT_HOOKED_OPS = OP_DEPOSIT | OP_MINT | OP_REDEEM | OP_SKIM | OP_LOOP | OP_DELOOP;

function createSynthEVault(address asset) internal returns (IEVault) {
IEVault v = IEVault(factory.createProxy(true, abi.encodePacked(address(asset), address(oracle), unitOfAccount)));
v.setIRM(address(new IRMTestDefault()));
v.setInterestRateModel(address(new IRMTestDefault()));

v.setInterestFee(1e4);

Expand Down
6 changes: 3 additions & 3 deletions test/unit/evault/modules/Governance/interestRates.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract GovernanceTest is EVaultTestBase {
eTST.borrow(5e18, borrower);
}

function test_Governance_setIRM_setAddressZero() public {
function test_Governance_setInterestRateModel_setAddressZero() public {
assertEq(eTST.totalAssets(), 100e18);

skip(1 days);
Expand All @@ -57,7 +57,7 @@ contract GovernanceTest is EVaultTestBase {

vm.stopPrank();
address previousIRM = eTST.interestRateModel();
eTST.setIRM(address(0));
eTST.setInterestRateModel(address(0));

// the previous interest accrued is recorded in the accumulator
assertEq(beforePause, eTST.totalAssets());
Expand All @@ -68,7 +68,7 @@ contract GovernanceTest is EVaultTestBase {
assertEq(beforePause, eTST.totalAssets());

// set the previous IRM back
eTST.setIRM(previousIRM);
eTST.setInterestRateModel(previousIRM);
// no change yet
assertEq(beforePause, eTST.totalAssets());

Expand Down

0 comments on commit 93cad6e

Please sign in to comment.