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 config 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 e9a6ca6
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 23 deletions.
1 change: 1 addition & 0 deletions addresses/euler-addresses-mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"SwapHandlerUniswapV3": "0x7527E082300fb8D189B3c07dB3BEcc990B5037E7"
},
"eulerGeneralView": "0xACC25c4d40651676FEEd43a3467F3169e3E68e42",
"eulerLensV1": "0xACC25c4d40651676FEEd43a3467F3169e3E68e42",
"eulerSimpleLens": "0x5077B7642abF198b4a5b7C4BdCE4f03016C7089C",
"euler": "0x27182842E098f60e3D576794A5bFFb0777E025d3",
"installer": "0x055DE1CCbCC9Bc5291569a0b6aFFdF8b5707aB16",
Expand Down
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
28 changes: 26 additions & 2 deletions tasks/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ task("debug:swap-contracts", "Replace contract code for all euler contracts on m
await hre.run('debug:set-code', {
compile: false,
name: 'EulerLensV1',
address: ctx.addressManifest.eulerGeneralView, // TODO update this address post deployment
address: ctx.addressManifest.eulerLensV1,
args: stringifyArgs([gitCommit]),
})

Expand All @@ -84,9 +84,33 @@ task("debug:swap-contracts", "Replace contract code for all euler contracts on m
args: stringifyArgs([ctx.addressManifest.euler, ctx.addressManifest.exec, ctx.addressManifest.markets]),
})

console.log('swapping', 'SwapHandler1Inch');
await hre.run('debug:set-code', {
compile: false,
name: 'SwapHandler1Inch',
address: ctx.addressManifest.swapHandlers.SwapHandler1Inch,
args: stringifyArgs([ctx.tokenSetup.existingContracts.oneInch, ctx.tokenSetup.existingContracts.swapRouterV2, ctx.tokenSetup.existingContracts.swapRouterV3]),
})

console.log('swapping', 'SwapHandlerUniAutoRouter');
await hre.run('debug:set-code', {
compile: false,
name: 'SwapHandlerUniAutoRouter',
address: ctx.addressManifest.swapHandlers.SwapHandlerUniAutoRouter,
args: stringifyArgs([ctx.tokenSetup.existingContracts.swapRouter02, ctx.tokenSetup.existingContracts.swapRouterV2, ctx.tokenSetup.existingContracts.swapRouterV3]),
})

console.log('swapping', 'SwapHandlerUniswapV3');
await hre.run('debug:set-code', {
compile: false,
name: 'SwapHandlerUniswapV3',
address: ctx.addressManifest.swapHandlers.SwapHandlerUniswapV3,
args: stringifyArgs([ctx.tokenSetup.existingContracts.swapRouterV3]),
})

for (const [module, address] of Object.entries(ctx.addressManifest.modules)) {
const args = [gitCommit];
if (module === 'riskManager') args.push(ctx.tokenSetup.riskManagerSettings, 0.95 * 4e9);
if (module === 'riskManager') args.push(ctx.tokenSetup.riskManagerSettings);
if (module === 'swap') continue;

console.log('swapping', capitalize(module));
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 e9a6ca6

Please sign in to comment.