Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Remove self collateral factor configuration from risk manager
Browse files Browse the repository at this point in the history
  • Loading branch information
dglowinski committed Mar 9, 2023
1 parent e3b1e3b commit 967a7ce
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 21 deletions.
1 change: 1 addition & 0 deletions contracts/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ abstract contract Constants {
uint16 internal constant MIN_UNISWAP3_OBSERVATION_CARDINALITY = 144;
uint24 internal constant DEFAULT_TWAP_WINDOW_SECONDS = 30 * 60;
uint32 internal constant DEFAULT_BORROW_FACTOR = uint32(0.28 * 4_000_000_000);
uint32 internal constant SELF_COLLATERAL_FACTOR = uint32(0.95 * 4_000_000_000);


// Implementation internals
Expand Down
2 changes: 0 additions & 2 deletions contracts/IRiskManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,4 @@ 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 selfCollateralFactor() external view returns (uint32);
}
9 changes: 2 additions & 7 deletions contracts/modules/Liquidation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "../BaseLogic.sol";

/// @notice Liquidate users who are in collateral violation to protect lenders
contract Liquidation is BaseLogic {
constructor(bytes32 moduleGitCommit_, uint32 selfCollateralFactor_) BaseLogic(MODULEID__LIQUIDATION, moduleGitCommit_) {}
constructor(bytes32 moduleGitCommit_) BaseLogic(MODULEID__LIQUIDATION, moduleGitCommit_) {}

// How much of a liquidation is credited to the underlying's reserves.
uint public constant UNDERLYING_RESERVES_FEE = 0.02 * 1e18;
Expand Down Expand Up @@ -145,7 +145,7 @@ contract Liquidation is BaseLogic {
// self-collateralization is an implicit override
if (!overrideConfig.enabled && liqLocs.underlying == liqLocs.collateral) {
overrideConfig.enabled = true;
overrideConfig.collateralFactor = getSelfCollateralFactor();
overrideConfig.collateralFactor = SELF_COLLATERAL_FACTOR;
}
// the liquidated collateral has active override with liability
if (overrideConfig.enabled) {
Expand Down Expand Up @@ -395,9 +395,4 @@ contract Liquidation is BaseLogic {
function emitLiquidationLog(LiquidationLocals memory liqLocs, uint repay, uint yield) private {
emit Liquidation(liqLocs.liquidator, liqLocs.violator, liqLocs.underlying, liqLocs.collateral, repay, yield, liqLocs.liqOpp.healthScore, liqLocs.liqOpp.baseDiscount, liqLocs.liqOpp.discount);
}

function getSelfCollateralFactor() private returns (uint32) {
bytes memory result = callInternalModule(MODULEID__RISK_MANAGER, abi.encodeWithSelector(IRiskManager.selfCollateralFactor.selector));
return abi.decode(result, (uint32));
}
}
8 changes: 2 additions & 6 deletions contracts/modules/RiskManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ interface IChainlinkAggregatorV2V3 {

contract RiskManager is IRiskManager, BaseLogic {
// Construction
uint32 immutable public selfCollateralFactor;

address immutable referenceAsset; // Token must have 18 decimals
address immutable uniswapFactory;
bytes32 immutable uniswapPoolInitCodeHash;
Expand All @@ -37,12 +35,10 @@ contract RiskManager is IRiskManager, BaseLogic {
bytes32 uniswapPoolInitCodeHash;
}

constructor(bytes32 moduleGitCommit_, RiskManagerSettings memory settings, uint32 selfCollateralFactor_) BaseLogic(MODULEID__RISK_MANAGER, moduleGitCommit_) {
constructor(bytes32 moduleGitCommit_, RiskManagerSettings memory settings) BaseLogic(MODULEID__RISK_MANAGER, moduleGitCommit_) {
referenceAsset = settings.referenceAsset;
uniswapFactory = settings.uniswapFactory;
uniswapPoolInitCodeHash = settings.uniswapPoolInitCodeHash;

selfCollateralFactor = selfCollateralFactor_;
}


Expand Down Expand Up @@ -349,7 +345,7 @@ contract RiskManager is IRiskManager, BaseLogic {
// self-collateralization is an implicit override
if (!overrideConfig.enabled && singleLiability == underlying) {
overrideConfig.enabled = true;
overrideConfig.collateralFactor = selfCollateralFactor;
overrideConfig.collateralFactor = SELF_COLLATERAL_FACTOR;
}
}

Expand Down
10 changes: 4 additions & 6 deletions test/lib/eTestLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const { verifyBatch } = require("./deployLib");
Error.stackTraceLimit = 10000;
let conf;

const SELF_COLLATERAL_FACTOR = 0.95 * 4e9

const moduleIds = {
// Public single-proxy modules
INSTALLER: 1,
Expand Down Expand Up @@ -895,9 +893,9 @@ async function deployContracts(provider, wallets, tokenSetupName, verify = null)
address: ctx.contracts.modules.markets.address, args: [gitCommit], contractPath: "contracts/modules/Markets.sol:Markets"
};

ctx.contracts.modules.liquidation = await (await ctx.factories.Liquidation.deploy(gitCommit, SELF_COLLATERAL_FACTOR)).deployed();
ctx.contracts.modules.liquidation = await (await ctx.factories.Liquidation.deploy(gitCommit)).deployed();
verification.contracts.modules.liquidation = {
address: ctx.contracts.modules.liquidation.address, args: [gitCommit, SELF_COLLATERAL_FACTOR], contractPath: "contracts/modules/Liquidation.sol:Liquidation"
address: ctx.contracts.modules.liquidation.address, args: [gitCommit], contractPath: "contracts/modules/Liquidation.sol:Liquidation"
};

ctx.contracts.modules.governance = await (await ctx.factories.Governance.deploy(gitCommit)).deployed();
Expand Down Expand Up @@ -930,9 +928,9 @@ async function deployContracts(provider, wallets, tokenSetupName, verify = null)
address: ctx.contracts.modules.dToken.address, args: [gitCommit], contractPath: "contracts/modules/DToken.sol:DToken"
};

ctx.contracts.modules.riskManager = await (await ctx.factories.RiskManager.deploy(gitCommit, riskManagerSettings, SELF_COLLATERAL_FACTOR)).deployed();
ctx.contracts.modules.riskManager = await (await ctx.factories.RiskManager.deploy(gitCommit, riskManagerSettings)).deployed();
verification.contracts.modules.riskManager = {
address: ctx.contracts.modules.riskManager.address, args: [gitCommit, riskManagerSettings, SELF_COLLATERAL_FACTOR], contractPath: "contracts/modules/RiskManager.sol:RiskManager"
address: ctx.contracts.modules.riskManager.address, args: [gitCommit, riskManagerSettings], contractPath: "contracts/modules/RiskManager.sol:RiskManager"
};

ctx.contracts.modules.irmDefault = await (await ctx.factories.IRMDefault.deploy(gitCommit)).deployed();
Expand Down

0 comments on commit 967a7ce

Please sign in to comment.