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

Commit e9a6ca6

Browse files
committed
remove self collateral config from risk manager
1 parent e3b1e3b commit e9a6ca6

File tree

7 files changed

+36
-23
lines changed

7 files changed

+36
-23
lines changed

addresses/euler-addresses-mainnet.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"SwapHandlerUniswapV3": "0x7527E082300fb8D189B3c07dB3BEcc990B5037E7"
3939
},
4040
"eulerGeneralView": "0xACC25c4d40651676FEEd43a3467F3169e3E68e42",
41+
"eulerLensV1": "0xACC25c4d40651676FEEd43a3467F3169e3E68e42",
4142
"eulerSimpleLens": "0x5077B7642abF198b4a5b7C4BdCE4f03016C7089C",
4243
"euler": "0x27182842E098f60e3D576794A5bFFb0777E025d3",
4344
"installer": "0x055DE1CCbCC9Bc5291569a0b6aFFdF8b5707aB16",

contracts/Constants.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ abstract contract Constants {
2525
uint16 internal constant MIN_UNISWAP3_OBSERVATION_CARDINALITY = 144;
2626
uint24 internal constant DEFAULT_TWAP_WINDOW_SECONDS = 30 * 60;
2727
uint32 internal constant DEFAULT_BORROW_FACTOR = uint32(0.28 * 4_000_000_000);
28+
uint32 internal constant SELF_COLLATERAL_FACTOR = uint32(0.95 * 4_000_000_000);
2829

2930

3031
// Implementation internals

contracts/IRiskManager.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,4 @@ interface IRiskManager {
3535

3636
function getPrice(address underlying) external view returns (uint twap, uint twapPeriod);
3737
function getPriceFull(address underlying) external view returns (uint twap, uint twapPeriod, uint currPrice);
38-
39-
function selfCollateralFactor() external view returns (uint32);
4038
}

contracts/modules/Liquidation.sol

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import "../BaseLogic.sol";
77

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

1212
// How much of a liquidation is credited to the underlying's reserves.
1313
uint public constant UNDERLYING_RESERVES_FEE = 0.02 * 1e18;
@@ -145,7 +145,7 @@ contract Liquidation is BaseLogic {
145145
// self-collateralization is an implicit override
146146
if (!overrideConfig.enabled && liqLocs.underlying == liqLocs.collateral) {
147147
overrideConfig.enabled = true;
148-
overrideConfig.collateralFactor = getSelfCollateralFactor();
148+
overrideConfig.collateralFactor = SELF_COLLATERAL_FACTOR;
149149
}
150150
// the liquidated collateral has active override with liability
151151
if (overrideConfig.enabled) {
@@ -395,9 +395,4 @@ contract Liquidation is BaseLogic {
395395
function emitLiquidationLog(LiquidationLocals memory liqLocs, uint repay, uint yield) private {
396396
emit Liquidation(liqLocs.liquidator, liqLocs.violator, liqLocs.underlying, liqLocs.collateral, repay, yield, liqLocs.liqOpp.healthScore, liqLocs.liqOpp.baseDiscount, liqLocs.liqOpp.discount);
397397
}
398-
399-
function getSelfCollateralFactor() private returns (uint32) {
400-
bytes memory result = callInternalModule(MODULEID__RISK_MANAGER, abi.encodeWithSelector(IRiskManager.selfCollateralFactor.selector));
401-
return abi.decode(result, (uint32));
402-
}
403398
}

contracts/modules/RiskManager.sol

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ interface IChainlinkAggregatorV2V3 {
2525

2626
contract RiskManager is IRiskManager, BaseLogic {
2727
// Construction
28-
uint32 immutable public selfCollateralFactor;
29-
3028
address immutable referenceAsset; // Token must have 18 decimals
3129
address immutable uniswapFactory;
3230
bytes32 immutable uniswapPoolInitCodeHash;
@@ -37,12 +35,10 @@ contract RiskManager is IRiskManager, BaseLogic {
3735
bytes32 uniswapPoolInitCodeHash;
3836
}
3937

40-
constructor(bytes32 moduleGitCommit_, RiskManagerSettings memory settings, uint32 selfCollateralFactor_) BaseLogic(MODULEID__RISK_MANAGER, moduleGitCommit_) {
38+
constructor(bytes32 moduleGitCommit_, RiskManagerSettings memory settings) BaseLogic(MODULEID__RISK_MANAGER, moduleGitCommit_) {
4139
referenceAsset = settings.referenceAsset;
4240
uniswapFactory = settings.uniswapFactory;
4341
uniswapPoolInitCodeHash = settings.uniswapPoolInitCodeHash;
44-
45-
selfCollateralFactor = selfCollateralFactor_;
4642
}
4743

4844

@@ -349,7 +345,7 @@ contract RiskManager is IRiskManager, BaseLogic {
349345
// self-collateralization is an implicit override
350346
if (!overrideConfig.enabled && singleLiability == underlying) {
351347
overrideConfig.enabled = true;
352-
overrideConfig.collateralFactor = selfCollateralFactor;
348+
overrideConfig.collateralFactor = SELF_COLLATERAL_FACTOR;
353349
}
354350
}
355351

tasks/debug.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ task("debug:swap-contracts", "Replace contract code for all euler contracts on m
7272
await hre.run('debug:set-code', {
7373
compile: false,
7474
name: 'EulerLensV1',
75-
address: ctx.addressManifest.eulerGeneralView, // TODO update this address post deployment
75+
address: ctx.addressManifest.eulerLensV1,
7676
args: stringifyArgs([gitCommit]),
7777
})
7878

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

87+
console.log('swapping', 'SwapHandler1Inch');
88+
await hre.run('debug:set-code', {
89+
compile: false,
90+
name: 'SwapHandler1Inch',
91+
address: ctx.addressManifest.swapHandlers.SwapHandler1Inch,
92+
args: stringifyArgs([ctx.tokenSetup.existingContracts.oneInch, ctx.tokenSetup.existingContracts.swapRouterV2, ctx.tokenSetup.existingContracts.swapRouterV3]),
93+
})
94+
95+
console.log('swapping', 'SwapHandlerUniAutoRouter');
96+
await hre.run('debug:set-code', {
97+
compile: false,
98+
name: 'SwapHandlerUniAutoRouter',
99+
address: ctx.addressManifest.swapHandlers.SwapHandlerUniAutoRouter,
100+
args: stringifyArgs([ctx.tokenSetup.existingContracts.swapRouter02, ctx.tokenSetup.existingContracts.swapRouterV2, ctx.tokenSetup.existingContracts.swapRouterV3]),
101+
})
102+
103+
console.log('swapping', 'SwapHandlerUniswapV3');
104+
await hre.run('debug:set-code', {
105+
compile: false,
106+
name: 'SwapHandlerUniswapV3',
107+
address: ctx.addressManifest.swapHandlers.SwapHandlerUniswapV3,
108+
args: stringifyArgs([ctx.tokenSetup.existingContracts.swapRouterV3]),
109+
})
110+
87111
for (const [module, address] of Object.entries(ctx.addressManifest.modules)) {
88112
const args = [gitCommit];
89-
if (module === 'riskManager') args.push(ctx.tokenSetup.riskManagerSettings, 0.95 * 4e9);
113+
if (module === 'riskManager') args.push(ctx.tokenSetup.riskManagerSettings);
90114
if (module === 'swap') continue;
91115

92116
console.log('swapping', capitalize(module));

test/lib/eTestLib.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ const { verifyBatch } = require("./deployLib");
1717
Error.stackTraceLimit = 10000;
1818
let conf;
1919

20-
const SELF_COLLATERAL_FACTOR = 0.95 * 4e9
21-
2220
const moduleIds = {
2321
// Public single-proxy modules
2422
INSTALLER: 1,
@@ -895,9 +893,9 @@ async function deployContracts(provider, wallets, tokenSetupName, verify = null)
895893
address: ctx.contracts.modules.markets.address, args: [gitCommit], contractPath: "contracts/modules/Markets.sol:Markets"
896894
};
897895

898-
ctx.contracts.modules.liquidation = await (await ctx.factories.Liquidation.deploy(gitCommit, SELF_COLLATERAL_FACTOR)).deployed();
896+
ctx.contracts.modules.liquidation = await (await ctx.factories.Liquidation.deploy(gitCommit)).deployed();
899897
verification.contracts.modules.liquidation = {
900-
address: ctx.contracts.modules.liquidation.address, args: [gitCommit, SELF_COLLATERAL_FACTOR], contractPath: "contracts/modules/Liquidation.sol:Liquidation"
898+
address: ctx.contracts.modules.liquidation.address, args: [gitCommit], contractPath: "contracts/modules/Liquidation.sol:Liquidation"
901899
};
902900

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

933-
ctx.contracts.modules.riskManager = await (await ctx.factories.RiskManager.deploy(gitCommit, riskManagerSettings, SELF_COLLATERAL_FACTOR)).deployed();
931+
ctx.contracts.modules.riskManager = await (await ctx.factories.RiskManager.deploy(gitCommit, riskManagerSettings)).deployed();
934932
verification.contracts.modules.riskManager = {
935-
address: ctx.contracts.modules.riskManager.address, args: [gitCommit, riskManagerSettings, SELF_COLLATERAL_FACTOR], contractPath: "contracts/modules/RiskManager.sol:RiskManager"
933+
address: ctx.contracts.modules.riskManager.address, args: [gitCommit, riskManagerSettings], contractPath: "contracts/modules/RiskManager.sol:RiskManager"
936934
};
937935

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

0 commit comments

Comments
 (0)