From f446041c73d9b2f8d6101e88181e235012383c65 Mon Sep 17 00:00:00 2001 From: Michael De Luca <35537333+deluca-mike@users.noreply.github.com> Date: Sun, 12 Dec 2021 18:32:09 -0500 Subject: [PATCH] fix: `handleClaimOfRepossessed` gas optimization (C4 #66) (#44) * 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 --- contracts/DebtLocker.sol | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contracts/DebtLocker.sol b/contracts/DebtLocker.sol index 21cb141..5c2b0ca 100644 --- a/contracts/DebtLocker.sol +++ b/contracts/DebtLocker.sol @@ -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; @@ -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"); } /**********************/