diff --git a/addresses/euler-addresses-mainnet.json b/addresses/euler-addresses-mainnet.json index bf471060..5368de10 100644 --- a/addresses/euler-addresses-mainnet.json +++ b/addresses/euler-addresses-mainnet.json @@ -38,6 +38,7 @@ "SwapHandlerUniswapV3": "0x7527E082300fb8D189B3c07dB3BEcc990B5037E7" }, "eulerGeneralView": "0xACC25c4d40651676FEEd43a3467F3169e3E68e42", + "eulerLensV1": "0xACC25c4d40651676FEEd43a3467F3169e3E68e42", "eulerSimpleLens": "0x5077B7642abF198b4a5b7C4BdCE4f03016C7089C", "euler": "0x27182842E098f60e3D576794A5bFFb0777E025d3", "installer": "0x055DE1CCbCC9Bc5291569a0b6aFFdF8b5707aB16", diff --git a/contracts/Constants.sol b/contracts/Constants.sol index b0dd4fa9..0a524352 100644 --- a/contracts/Constants.sol +++ b/contracts/Constants.sol @@ -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 diff --git a/contracts/IRiskManager.sol b/contracts/IRiskManager.sol index ba71ee4b..b5c9cc17 100644 --- a/contracts/IRiskManager.sol +++ b/contracts/IRiskManager.sol @@ -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); } diff --git a/contracts/modules/Liquidation.sol b/contracts/modules/Liquidation.sol index d927fd86..f1478e65 100644 --- a/contracts/modules/Liquidation.sol +++ b/contracts/modules/Liquidation.sol @@ -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; @@ -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) { @@ -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)); - } } diff --git a/contracts/modules/RiskManager.sol b/contracts/modules/RiskManager.sol index 8380446f..5ecdacd3 100644 --- a/contracts/modules/RiskManager.sol +++ b/contracts/modules/RiskManager.sol @@ -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; @@ -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_; } @@ -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; } } diff --git a/tasks/debug.js b/tasks/debug.js index 121d9d63..6025c1d7 100644 --- a/tasks/debug.js +++ b/tasks/debug.js @@ -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]), }) @@ -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)); diff --git a/test/lib/eTestLib.js b/test/lib/eTestLib.js index 4c802e08..d21b2167 100644 --- a/test/lib/eTestLib.js +++ b/test/lib/eTestLib.js @@ -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, @@ -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(); @@ -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();