diff --git a/contracts/IRiskManager.sol b/contracts/IRiskManager.sol index b13d33f1..b95417ca 100644 --- a/contracts/IRiskManager.sol +++ b/contracts/IRiskManager.sol @@ -26,6 +26,12 @@ interface IRiskManager { LiquidityStatus status; } + struct RiskManagerSettings { + address referenceAsset; + address uniswapFactory; + bytes32 uniswapPoolInitCodeHash; + } + function getNewMarketParameters(address underlying) external returns (NewMarketParameters memory); function requireLiquidity(address account) external view; @@ -34,4 +40,5 @@ interface IRiskManager { function getPrice(address underlying) external view returns (uint twap, uint twapPeriod); function getPriceFull(address underlying) external view returns (uint twap, uint twapPeriod, uint currPrice); + function getRiskManagerSettings() external view returns (RiskManagerSettings memory settings); } diff --git a/contracts/modules/Exec.sol b/contracts/modules/Exec.sol index dbc3a40e..6ca765f5 100644 --- a/contracts/modules/Exec.sol +++ b/contracts/modules/Exec.sol @@ -80,6 +80,15 @@ contract Exec is BaseLogic { (twap, twapPeriod, currPrice) = abi.decode(result, (uint, uint, uint)); } + /// @notice Retrieve Risk Manager Settings as per its constructor arguments used + /// @return settings RiskManagerSettings struct + function getRiskManagerSettings() external staticDelegate returns (IRiskManager.RiskManagerSettings memory settings) { + bytes memory result = callInternalModule(MODULEID__RISK_MANAGER, + abi.encodeWithSelector(IRiskManager.getRiskManagerSettings.selector)); + + (settings) = abi.decode(result, (IRiskManager.RiskManagerSettings)); + } + // Custom execution methods diff --git a/contracts/modules/RiskManager.sol b/contracts/modules/RiskManager.sol index 7b5a1dd9..3c678698 100644 --- a/contracts/modules/RiskManager.sol +++ b/contracts/modules/RiskManager.sol @@ -32,12 +32,6 @@ contract RiskManager is IRiskManager, BaseLogic { address immutable uniswapFactory; bytes32 immutable uniswapPoolInitCodeHash; - struct RiskManagerSettings { - address referenceAsset; - address uniswapFactory; - bytes32 uniswapPoolInitCodeHash; - } - constructor(bytes32 moduleGitCommit_, RiskManagerSettings memory settings) BaseLogic(MODULEID__RISK_MANAGER, moduleGitCommit_) { referenceAsset = settings.referenceAsset; uniswapFactory = settings.uniswapFactory; @@ -284,6 +278,11 @@ contract RiskManager is IRiskManager, BaseLogic { } } + // Returns Risk Manager settings as per constructor arguments + + function getRiskManagerSettings() external view override returns (RiskManagerSettings memory settings) { + settings = RiskManagerSettings(referenceAsset, uniswapFactory, uniswapPoolInitCodeHash); + } // Liquidity diff --git a/contracts/views/EulerGeneralView.sol b/contracts/views/EulerGeneralView.sol index 1cf4d1fd..22650c12 100644 --- a/contracts/views/EulerGeneralView.sol +++ b/contracts/views/EulerGeneralView.sol @@ -8,12 +8,22 @@ import "../modules/EToken.sol"; import "../modules/Markets.sol"; import "../BaseIRMLinearKink.sol"; import "../vendor/RPow.sol"; +import "../IRiskManager.sol"; interface IExec { function getPriceFull(address underlying) external view returns (uint twap, uint twapPeriod, uint currPrice); function getPrice(address underlying) external view returns (uint twap, uint twapPeriod); function detailedLiquidity(address account) external view returns (IRiskManager.AssetLiquidity[] memory assets); function liquidity(address account) external view returns (IRiskManager.LiquidityStatus memory status); + function getRiskManagerSettings() external view returns (IRiskManager.RiskManagerSettings memory settings); +} + +interface IInstaller { + function getUpgradeAdmin() external view returns (address); +} + +interface IGovernance { + function getGovernorAdmin() external view returns (address); } contract EulerGeneralView is Constants { @@ -84,10 +94,54 @@ contract EulerGeneralView is Constants { address[] enteredMarkets; } + struct ResponseModule { + uint moduleId; + address proxyAddress; + bytes32 gitCommit; + } + + struct ResponseConfig { + uint defaultReserveFee; + uint defaultTWAPWindowSeconds; + uint defaultBorrowFactor; + address upgradeAdmin; + address governorAdmin; + IRiskManager.RiskManagerSettings riskManagerSettings; + + ResponseModule[] modules; + } // Implementation + function doQueryEulerConfig(address eulerContract) external view returns (ResponseConfig memory r) { + uint[7] memory moduleIds = [ + MODULEID__INSTALLER, + MODULEID__MARKETS, + MODULEID__LIQUIDATION, + MODULEID__GOVERNANCE, + MODULEID__EXEC, + MODULEID__SWAP, + MODULEID__SWAPHUB + ]; + + r.defaultReserveFee = DEFAULT_RESERVE_FEE; + r.defaultTWAPWindowSeconds = DEFAULT_TWAP_WINDOW_SECONDS; + r.defaultBorrowFactor = DEFAULT_BORROW_FACTOR; + r.modules = new ResponseModule[](moduleIds.length); + + Euler eulerProxy = Euler(eulerContract); + for (uint i = 0; i < moduleIds.length; ++i) { + address currentProxy = eulerProxy.moduleIdToProxy(moduleIds[i]); + bytes32 currentGitCommit = BaseModule(currentProxy).moduleGitCommit(); + r.modules[i] = ResponseModule(moduleIds[i], currentProxy, currentGitCommit); + } + + r.upgradeAdmin = IInstaller(r.modules[0].proxyAddress).getUpgradeAdmin(); + r.governorAdmin = IGovernance(r.modules[3].proxyAddress).getGovernorAdmin(); + r.riskManagerSettings = IExec(r.modules[4].proxyAddress).getRiskManagerSettings(); + } + function doQueryBatch(Query[] memory qs) external view returns (Response[] memory r) { r = new Response[](qs.length);