@@ -1068,4 +1068,73 @@ contract SpokeRiskPremiumEdgeCasesTest is SpokeBase {
10681068 'Bob user risk premium after supplying lower LP collateral '
10691069 );
10701070 }
1071+
1072+ /// Initially debt is covered by 2 collaterals, then due to price change, debt is covered by 1 collateral
1073+ function test_riskPremium_priceChangeReducesRP (uint256 daiSupplyAmount , uint256 newPrice ) public {
1074+ daiSupplyAmount = bound (daiSupplyAmount, 1e18 , MAX_SUPPLY_AMOUNT);
1075+ uint256 startingPrice = spoke2.getReservePrice (_daiReserveId (spoke2));
1076+ newPrice = bound (newPrice, startingPrice + 1 , 1e16 );
1077+
1078+ // Supply dai and dai2 collaterals to cover weth debt. Dai increases in price to fully cover weth debt
1079+ uint256 dai2SupplyAmount = MAX_SUPPLY_AMOUNT;
1080+ uint256 borrowAmount = _calcEquivalentAssetAmount (daiAssetId, daiSupplyAmount, wethAssetId) + 1 ; // Borrow more than dai supply value so 2 collaterals cover debt
1081+
1082+ // Deploy liquidity for weth borrow
1083+ _deployLiquidity (spoke2, _wethReserveId (spoke2), MAX_SUPPLY_AMOUNT);
1084+
1085+ // Deal bob dai to cover dai and dai2 supply
1086+ deal (address (tokenList.dai), bob, MAX_SUPPLY_AMOUNT * 2 );
1087+
1088+ // Bob supplies dai and dai2 collaterals
1089+ Utils.supplyCollateral ({
1090+ spoke: spoke2,
1091+ reserveId: _daiReserveId (spoke2),
1092+ user: bob,
1093+ amount: daiSupplyAmount,
1094+ onBehalfOf: bob
1095+ });
1096+ Utils.supplyCollateral ({
1097+ spoke: spoke2,
1098+ reserveId: _dai2ReserveId (spoke2),
1099+ user: bob,
1100+ amount: dai2SupplyAmount,
1101+ onBehalfOf: bob
1102+ });
1103+
1104+ // Bob borrows weth
1105+ Utils.borrow ({
1106+ spoke: spoke2,
1107+ reserveId: _wethReserveId (spoke2),
1108+ user: bob,
1109+ amount: borrowAmount,
1110+ onBehalfOf: bob
1111+ });
1112+
1113+ // Bob's current risk premium should be greater than or equal to liquidity premium of dai, since debt is not fully covered by it (and due to rounding)
1114+ assertLt (
1115+ _getValueInBaseCurrency (daiAssetId, daiSupplyAmount),
1116+ _getValueInBaseCurrency (wethAssetId, borrowAmount),
1117+ 'Bob dai collateral less than weth debt '
1118+ );
1119+ assertGe (
1120+ spoke2.getUserRiskPremium (bob),
1121+ spoke2.getLiquidityPremium (_daiReserveId (spoke2)),
1122+ 'Bob user rp greater than or equal dai lp '
1123+ );
1124+
1125+ // Now change the price of dai
1126+ oracle.setAssetPrice (daiAssetId, newPrice);
1127+
1128+ // Now risk premium should equal LP of dai since debt is fully covered by it
1129+ assertGe (
1130+ _getValueInBaseCurrency (daiAssetId, daiSupplyAmount),
1131+ _getValueInBaseCurrency (wethAssetId, borrowAmount),
1132+ 'Bob dai collateral greater than weth debt '
1133+ );
1134+ assertEq (
1135+ spoke2.getUserRiskPremium (bob),
1136+ spoke2.getLiquidityPremium (_daiReserveId (spoke2)),
1137+ 'Bob user risk premium matches dai lp after price change '
1138+ );
1139+ }
10711140}
0 commit comments