From a360ba43d7008c3fbd512e69655343ccb3db7df2 Mon Sep 17 00:00:00 2001 From: dglowinski Date: Wed, 20 Mar 2024 14:51:10 +0100 Subject: [PATCH 1/3] add public getters for module addresses --- src/EVault/IEVault.sol | 19 +++++++++++++- src/EVault/modules/Dispatch.sol | 16 ++++++------ test/unit/evault/Dispatch.t.sol | 20 +++++++++++++++ test/unit/evault/EVaultTestBase.t.sol | 36 +++++++++++++++++++++------ 4 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 test/unit/evault/Dispatch.t.sol diff --git a/src/EVault/IEVault.sol b/src/EVault/IEVault.sol index 3370399a..1948e5d6 100644 --- a/src/EVault/IEVault.sol +++ b/src/EVault/IEVault.sol @@ -415,4 +415,21 @@ interface IEVault is IRiskManager, IBalanceForwarder, IGovernance -{} +{ + /// @notice Fetch address of the `Initialize` module + function MODULE_INITIALIZE() external view returns(address); + /// @notice Fetch address of the `Token` module + function MODULE_TOKEN() external view returns(address); + /// @notice Fetch address of the `Vault` module + function MODULE_VAULT() external view returns(address); + /// @notice Fetch address of the `Borrowing` module + function MODULE_BORROWING() external view returns(address); + /// @notice Fetch address of the `Liquidation` module + function MODULE_LIQUIDATION() external view returns(address); + /// @notice Fetch address of the `RiskManager` module + function MODULE_RISKMANAGER() external view returns(address); + /// @notice Fetch address of the `BalanceForwarder` module + function MODULE_BALANCE_FORWARDER() external view returns(address); + /// @notice Fetch address of the `Governance` module + function MODULE_GOVERNANCE() external view returns(address); +} diff --git a/src/EVault/modules/Dispatch.sol b/src/EVault/modules/Dispatch.sol index 42542b12..8040454f 100644 --- a/src/EVault/modules/Dispatch.sol +++ b/src/EVault/modules/Dispatch.sol @@ -26,14 +26,14 @@ abstract contract Dispatch is BalanceForwarderModule, GovernanceModule { - address immutable MODULE_INITIALIZE; - address immutable MODULE_TOKEN; - address immutable MODULE_VAULT; - address immutable MODULE_BORROWING; - address immutable MODULE_LIQUIDATION; - address immutable MODULE_RISKMANAGER; - address immutable MODULE_BALANCE_FORWARDER; - address immutable MODULE_GOVERNANCE; + address immutable public MODULE_INITIALIZE; + address immutable public MODULE_TOKEN; + address immutable public MODULE_VAULT; + address immutable public MODULE_BORROWING; + address immutable public MODULE_LIQUIDATION; + address immutable public MODULE_RISKMANAGER; + address immutable public MODULE_BALANCE_FORWARDER; + address immutable public MODULE_GOVERNANCE; struct DeployedModules { address initialize; diff --git a/test/unit/evault/Dispatch.t.sol b/test/unit/evault/Dispatch.t.sol new file mode 100644 index 00000000..d4dd95e7 --- /dev/null +++ b/test/unit/evault/Dispatch.t.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +pragma solidity ^0.8.0; + +import "./EVaultTestBase.t.sol"; + +import { console2 as console } from "forge-std/console2.sol"; + +contract DispatchTest is EVaultTestBase { + function test_Dispatch_moduleGetters() public view { + assertEq(eTST.MODULE_INITIALIZE(), initializeModule); + assertEq(eTST.MODULE_TOKEN(), tokenModule); + assertEq(eTST.MODULE_VAULT(), vaultModule); + assertEq(eTST.MODULE_BORROWING(), borrowingModule); + assertEq(eTST.MODULE_LIQUIDATION(), liquidationModule); + assertEq(eTST.MODULE_RISKMANAGER(), riskManagerModule); + assertEq(eTST.MODULE_BALANCE_FORWARDER(), balanceForwarderModule); + assertEq(eTST.MODULE_GOVERNANCE(), governanceModule); + } +} diff --git a/test/unit/evault/EVaultTestBase.t.sol b/test/unit/evault/EVaultTestBase.t.sol index c8647693..1284203a 100644 --- a/test/unit/evault/EVaultTestBase.t.sol +++ b/test/unit/evault/EVaultTestBase.t.sol @@ -55,6 +55,17 @@ contract EVaultTestBase is AssertionsCustomTypes, Test, DeployPermit2 { IEVault public eTST; IEVault public eTST2; + + address initializeModule; + address tokenModule; + address vaultModule; + address borrowingModule; + address liquidationModule; + address riskManagerModule; + address balanceForwarderModule; + address governanceModule; + + function setUp() public virtual { admin = vm.addr(1000); feeReceiver = makeAddr("feeReceiver"); @@ -68,15 +79,24 @@ contract EVaultTestBase is AssertionsCustomTypes, Test, DeployPermit2 { permit2 = deployPermit2(); integrations = Base.Integrations(address(evc), address(protocolConfig), balanceTracker, permit2); + initializeModule = address(new Initialize(integrations)); + tokenModule = address(new Token(integrations)); + vaultModule = address(new Vault(integrations)); + borrowingModule = address(new Borrowing(integrations)); + liquidationModule = address(new Liquidation(integrations)); + riskManagerModule = address(new RiskManager(integrations)); + balanceForwarderModule = address(new BalanceForwarder(integrations)); + governanceModule = address(new Governance(integrations)); + modules = Dispatch.DeployedModules({ - initialize: address(new Initialize(integrations)), - token: address(new Token(integrations)), - vault: address(new Vault(integrations)), - borrowing: address(new Borrowing(integrations)), - liquidation: address(new Liquidation(integrations)), - riskManager: address(new RiskManager(integrations)), - balanceForwarder: address(new BalanceForwarder(integrations)), - governance: address(new Governance(integrations)) + initialize: initializeModule, + token: tokenModule, + vault: vaultModule, + borrowing: borrowingModule, + liquidation: liquidationModule, + riskManager: riskManagerModule, + balanceForwarder: balanceForwarderModule, + governance: governanceModule }); address evaultImpl = address(new EVault(integrations, modules)); From 49966fad1a203a581cccf9ae6c3f5c042f8c9ed0 Mon Sep 17 00:00:00 2001 From: dglowinski Date: Wed, 20 Mar 2024 15:14:37 +0100 Subject: [PATCH 2/3] formatting --- src/EVault/IEVault.sol | 32 +++++++++---------- src/EVault/modules/Dispatch.sol | 16 +++++----- test/unit/evault/Dispatch.t.sol | 2 -- test/unit/evault/EVaultTestBase.t.sol | 2 -- test/unit/evault/modules/Vault/skim.t.sol | 1 - test/unit/evault/modules/Vault/withdraw.t.sol | 1 - 6 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/EVault/IEVault.sol b/src/EVault/IEVault.sol index 1948e5d6..bb4cb9cb 100644 --- a/src/EVault/IEVault.sol +++ b/src/EVault/IEVault.sol @@ -416,20 +416,20 @@ interface IEVault is IBalanceForwarder, IGovernance { - /// @notice Fetch address of the `Initialize` module - function MODULE_INITIALIZE() external view returns(address); - /// @notice Fetch address of the `Token` module - function MODULE_TOKEN() external view returns(address); - /// @notice Fetch address of the `Vault` module - function MODULE_VAULT() external view returns(address); - /// @notice Fetch address of the `Borrowing` module - function MODULE_BORROWING() external view returns(address); - /// @notice Fetch address of the `Liquidation` module - function MODULE_LIQUIDATION() external view returns(address); - /// @notice Fetch address of the `RiskManager` module - function MODULE_RISKMANAGER() external view returns(address); - /// @notice Fetch address of the `BalanceForwarder` module - function MODULE_BALANCE_FORWARDER() external view returns(address); - /// @notice Fetch address of the `Governance` module - function MODULE_GOVERNANCE() external view returns(address); + /// @notice Fetch address of the `Initialize` module + function MODULE_INITIALIZE() external view returns (address); + /// @notice Fetch address of the `Token` module + function MODULE_TOKEN() external view returns (address); + /// @notice Fetch address of the `Vault` module + function MODULE_VAULT() external view returns (address); + /// @notice Fetch address of the `Borrowing` module + function MODULE_BORROWING() external view returns (address); + /// @notice Fetch address of the `Liquidation` module + function MODULE_LIQUIDATION() external view returns (address); + /// @notice Fetch address of the `RiskManager` module + function MODULE_RISKMANAGER() external view returns (address); + /// @notice Fetch address of the `BalanceForwarder` module + function MODULE_BALANCE_FORWARDER() external view returns (address); + /// @notice Fetch address of the `Governance` module + function MODULE_GOVERNANCE() external view returns (address); } diff --git a/src/EVault/modules/Dispatch.sol b/src/EVault/modules/Dispatch.sol index 8040454f..26b6bb61 100644 --- a/src/EVault/modules/Dispatch.sol +++ b/src/EVault/modules/Dispatch.sol @@ -26,14 +26,14 @@ abstract contract Dispatch is BalanceForwarderModule, GovernanceModule { - address immutable public MODULE_INITIALIZE; - address immutable public MODULE_TOKEN; - address immutable public MODULE_VAULT; - address immutable public MODULE_BORROWING; - address immutable public MODULE_LIQUIDATION; - address immutable public MODULE_RISKMANAGER; - address immutable public MODULE_BALANCE_FORWARDER; - address immutable public MODULE_GOVERNANCE; + address public immutable MODULE_INITIALIZE; + address public immutable MODULE_TOKEN; + address public immutable MODULE_VAULT; + address public immutable MODULE_BORROWING; + address public immutable MODULE_LIQUIDATION; + address public immutable MODULE_RISKMANAGER; + address public immutable MODULE_BALANCE_FORWARDER; + address public immutable MODULE_GOVERNANCE; struct DeployedModules { address initialize; diff --git a/test/unit/evault/Dispatch.t.sol b/test/unit/evault/Dispatch.t.sol index d4dd95e7..013b3177 100644 --- a/test/unit/evault/Dispatch.t.sol +++ b/test/unit/evault/Dispatch.t.sol @@ -4,8 +4,6 @@ pragma solidity ^0.8.0; import "./EVaultTestBase.t.sol"; -import { console2 as console } from "forge-std/console2.sol"; - contract DispatchTest is EVaultTestBase { function test_Dispatch_moduleGetters() public view { assertEq(eTST.MODULE_INITIALIZE(), initializeModule); diff --git a/test/unit/evault/EVaultTestBase.t.sol b/test/unit/evault/EVaultTestBase.t.sol index 1284203a..4324e300 100644 --- a/test/unit/evault/EVaultTestBase.t.sol +++ b/test/unit/evault/EVaultTestBase.t.sol @@ -55,7 +55,6 @@ contract EVaultTestBase is AssertionsCustomTypes, Test, DeployPermit2 { IEVault public eTST; IEVault public eTST2; - address initializeModule; address tokenModule; address vaultModule; @@ -65,7 +64,6 @@ contract EVaultTestBase is AssertionsCustomTypes, Test, DeployPermit2 { address balanceForwarderModule; address governanceModule; - function setUp() public virtual { admin = vm.addr(1000); feeReceiver = makeAddr("feeReceiver"); diff --git a/test/unit/evault/modules/Vault/skim.t.sol b/test/unit/evault/modules/Vault/skim.t.sol index 84d376dc..448e8b0d 100644 --- a/test/unit/evault/modules/Vault/skim.t.sol +++ b/test/unit/evault/modules/Vault/skim.t.sol @@ -2,7 +2,6 @@ pragma solidity ^0.8.0; -import {console2} from "forge-std/Test.sol"; import {EVaultTestBase} from "../../EVaultTestBase.t.sol"; import "src/EVault/shared/types/Types.sol"; diff --git a/test/unit/evault/modules/Vault/withdraw.t.sol b/test/unit/evault/modules/Vault/withdraw.t.sol index 8c8b90b8..6045667e 100644 --- a/test/unit/evault/modules/Vault/withdraw.t.sol +++ b/test/unit/evault/modules/Vault/withdraw.t.sol @@ -2,7 +2,6 @@ pragma solidity ^0.8.0; -import {console2} from "forge-std/Test.sol"; import {EVaultTestBase} from "../../EVaultTestBase.t.sol"; import {Events} from "src/EVault/shared/Events.sol"; import {SafeERC20Lib} from "src/EVault/shared/lib/SafeERC20Lib.sol"; From f4ee8bcc1b249434c1dc56d8126159abe6beaffd Mon Sep 17 00:00:00 2001 From: dglowinski Date: Thu, 21 Mar 2024 10:24:10 +0100 Subject: [PATCH 3/3] move Dispatch out of /modules --- src/EVault/{modules => }/Dispatch.sol | 24 ++++++++++++------------ src/EVault/EVault.sol | 2 +- test/unit/evault/EVaultTestBase.t.sol | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) rename src/EVault/{modules => }/Dispatch.sol (90%) diff --git a/src/EVault/modules/Dispatch.sol b/src/EVault/Dispatch.sol similarity index 90% rename from src/EVault/modules/Dispatch.sol rename to src/EVault/Dispatch.sol index 26b6bb61..fc425819 100644 --- a/src/EVault/modules/Dispatch.sol +++ b/src/EVault/Dispatch.sol @@ -2,18 +2,18 @@ pragma solidity ^0.8.0; -import {Base} from "../shared/Base.sol"; - -import {TokenModule} from "./Token.sol"; -import {VaultModule} from "./Vault.sol"; -import {BorrowingModule} from "./Borrowing.sol"; -import {LiquidationModule} from "./Liquidation.sol"; -import {InitializeModule} from "./Initialize.sol"; -import {BalanceForwarderModule} from "./BalanceForwarder.sol"; -import {GovernanceModule} from "./Governance.sol"; -import {RiskManagerModule} from "./RiskManager.sol"; - -import "../shared/Constants.sol"; +import {Base} from "./shared/Base.sol"; + +import {TokenModule} from "./modules/Token.sol"; +import {VaultModule} from "./modules/Vault.sol"; +import {BorrowingModule} from "./modules/Borrowing.sol"; +import {LiquidationModule} from "./modules/Liquidation.sol"; +import {InitializeModule} from "./modules/Initialize.sol"; +import {BalanceForwarderModule} from "./modules/BalanceForwarder.sol"; +import {GovernanceModule} from "./modules/Governance.sol"; +import {RiskManagerModule} from "./modules/RiskManager.sol"; + +import "./shared/Constants.sol"; abstract contract Dispatch is Base, diff --git a/src/EVault/EVault.sol b/src/EVault/EVault.sol index 358ffa87..b3504bd1 100644 --- a/src/EVault/EVault.sol +++ b/src/EVault/EVault.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; -import {Dispatch} from "./modules/Dispatch.sol"; +import {Dispatch} from "./Dispatch.sol"; contract EVault is Dispatch { constructor(Integrations memory integrations, DeployedModules memory modules) Dispatch(integrations, modules) {} diff --git a/test/unit/evault/EVaultTestBase.t.sol b/test/unit/evault/EVaultTestBase.t.sol index 4324e300..a0bf6ed3 100644 --- a/test/unit/evault/EVaultTestBase.t.sol +++ b/test/unit/evault/EVaultTestBase.t.sol @@ -9,7 +9,7 @@ import {GenericFactory} from "src/GenericFactory/GenericFactory.sol"; import {EVault} from "src/EVault/EVault.sol"; import {ProtocolConfig} from "src/ProtocolConfig/ProtocolConfig.sol"; -import {Dispatch} from "src/EVault/modules/Dispatch.sol"; +import {Dispatch} from "src/EVault/Dispatch.sol"; import {Initialize} from "src/EVault/modules/Initialize.sol"; import {Token} from "src/EVault/modules/Token.sol";