@@ -307,6 +307,7 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
307
307
redeemer,
308
308
ICErc20 (cToken),
309
309
redeemTokens,
310
+ 0 ,
310
311
0
311
312
);
312
313
if (err != Error.NO_ERROR) {
@@ -371,6 +372,7 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
371
372
account,
372
373
isBorrow ? cTokenModify : ICErc20 (address (0 )),
373
374
0 ,
375
+ 0 ,
374
376
0
375
377
);
376
378
require (err == Error.NO_ERROR, "!liquidity " );
@@ -482,7 +484,7 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
482
484
flywheelPreBorrowerAction (cToken, borrower);
483
485
484
486
// Perform a hypothetical liquidity check to guard against shortfall
485
- (uint256 err , , , uint256 shortfall ) = this .getHypotheticalAccountLiquidity (borrower, cToken, 0 , borrowAmount);
487
+ (uint256 err , , , uint256 shortfall ) = this .getHypotheticalAccountLiquidity (borrower, cToken, 0 , borrowAmount, 0 );
486
488
if (err != uint256 (Error.NO_ERROR)) {
487
489
return err;
488
490
}
@@ -573,7 +575,13 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
573
575
require (borrowBalance >= repayAmount, "!borrow>repay " );
574
576
} else {
575
577
/* The borrower must have shortfall in order to be liquidateable */
576
- (Error err , , , uint256 shortfall ) = getHypotheticalAccountLiquidityInternal (borrower, ICErc20 (address (0 )), 0 , 0 );
578
+ (Error err , , , uint256 shortfall ) = getHypotheticalAccountLiquidityInternal (
579
+ borrower,
580
+ ICErc20 (address (0 )),
581
+ 0 ,
582
+ 0 ,
583
+ 0
584
+ );
577
585
if (err != Error.NO_ERROR) {
578
586
return uint256 (err);
579
587
}
@@ -714,6 +722,7 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
714
722
Exp tokensToDenom;
715
723
uint256 borrowCapForCollateral;
716
724
uint256 borrowedAssetPrice;
725
+ uint256 assetAsCollateralValueCap;
717
726
}
718
727
719
728
function getAccountLiquidity (address account )
@@ -732,7 +741,7 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
732
741
uint256 collateralValue ,
733
742
uint256 liquidity ,
734
743
uint256 shortfall
735
- ) = getHypotheticalAccountLiquidityInternal (account, ICErc20 (address (0 )), 0 , 0 );
744
+ ) = getHypotheticalAccountLiquidityInternal (account, ICErc20 (address (0 )), 0 , 0 , 0 );
736
745
return (uint256 (err), collateralValue, liquidity, shortfall);
737
746
}
738
747
@@ -750,7 +759,8 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
750
759
address account ,
751
760
address cTokenModify ,
752
761
uint256 redeemTokens ,
753
- uint256 borrowAmount
762
+ uint256 borrowAmount ,
763
+ uint256 repayAmount
754
764
)
755
765
public
756
766
view
@@ -766,7 +776,13 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
766
776
uint256 collateralValue ,
767
777
uint256 liquidity ,
768
778
uint256 shortfall
769
- ) = getHypotheticalAccountLiquidityInternal (account, ICErc20 (cTokenModify), redeemTokens, borrowAmount);
779
+ ) = getHypotheticalAccountLiquidityInternal (
780
+ account,
781
+ ICErc20 (cTokenModify),
782
+ redeemTokens,
783
+ borrowAmount,
784
+ repayAmount
785
+ );
770
786
return (uint256 (err), collateralValue, liquidity, shortfall);
771
787
}
772
788
@@ -785,7 +801,8 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
785
801
address account ,
786
802
ICErc20 cTokenModify ,
787
803
uint256 redeemTokens ,
788
- uint256 borrowAmount
804
+ uint256 borrowAmount ,
805
+ uint256 repayAmount
789
806
)
790
807
internal
791
808
view
@@ -833,7 +850,7 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
833
850
}
834
851
{
835
852
// Exclude the asset-to-be-borrowed from the liquidity, except for when redeeming
836
- uint256 assetAsCollateralValueCap = asComptrollerExtension ().getAssetAsCollateralValueCap (
853
+ vars. assetAsCollateralValueCap = asComptrollerExtension ().getAssetAsCollateralValueCap (
837
854
vars.asset,
838
855
cTokenModify,
839
856
redeemTokens > 0 ,
@@ -842,7 +859,8 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
842
859
843
860
// accumulate the collateral value to sumCollateral
844
861
uint256 assetCollateralValue = mul_ScalarTruncate (vars.tokensToDenom, vars.cTokenBalance);
845
- if (assetCollateralValue > assetAsCollateralValueCap) assetCollateralValue = assetAsCollateralValueCap;
862
+ if (assetCollateralValue > vars.assetAsCollateralValueCap)
863
+ assetCollateralValue = vars.assetAsCollateralValueCap;
846
864
vars.sumCollateral += assetCollateralValue;
847
865
}
848
866
@@ -870,6 +888,13 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
870
888
borrowAmount,
871
889
vars.sumBorrowPlusEffects
872
890
);
891
+
892
+ uint256 repayEffect = mul_ScalarTruncate (vars.oraclePrice, repayAmount);
893
+ if (repayEffect >= vars.sumBorrowPlusEffects) {
894
+ vars.sumBorrowPlusEffects = 0 ;
895
+ } else {
896
+ vars.sumBorrowPlusEffects -= repayEffect;
897
+ }
873
898
}
874
899
}
875
900
0 commit comments