Skip to content

Commit

Permalink
fix: handleClaimOfRepossessed gas optimization (C4 #66) (#44)
Browse files Browse the repository at this point in the history
* chore: Remove TODO on pullFunds (c4 #10)

* chore: strict 0.8.7 (c4 #23)

* fix: Add named returns where missing (c4 #25)

* fix: `handleClaimOfRepossessed` gas optimization (c4 #66)

Co-authored-by: Lucas Manuel <[email protected]>
  • Loading branch information
deluca-mike and Lucas Manuel authored Dec 12, 2021
1 parent 2ffdc24 commit f446041
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions contracts/DebtLocker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,11 @@ contract DebtLocker is IDebtLocker, DebtLockerStorage, MapleProxied {
// Funds recovered from liquidation and any unclaimed previous payment amounts
uint256 recoveredFunds = IERC20Like(fundsAsset).balanceOf(address(this)) - fundsCaptured;

uint256 totalClaimed = recoveredFunds + fundsCaptured;

// If `recoveredFunds` is greater than `principalToCover`, the remaining amount is treated as interest in the context of the pool.
// If `recoveredFunds` is less than `principalToCover`, the difference is registered as a shortfall.
details_[0] = recoveredFunds + fundsCaptured;
details_[0] = totalClaimed;
details_[1] = recoveredFunds > principalToCover ? recoveredFunds - principalToCover : 0;
details_[2] = fundsCaptured;
details_[5] = recoveredFunds > principalToCover ? principalToCover : recoveredFunds;
Expand All @@ -210,7 +212,7 @@ contract DebtLocker is IDebtLocker, DebtLockerStorage, MapleProxied {
_fundsToCapture = uint256(0);
_repossessed = false;

require(ERC20Helper.transfer(fundsAsset, _pool, recoveredFunds + fundsCaptured), "DL:HCOR:TRANSFER");
require(ERC20Helper.transfer(fundsAsset, _pool, totalClaimed), "DL:HCOR:TRANSFER");
}

/**********************/
Expand Down

0 comments on commit f446041

Please sign in to comment.