diff --git a/contracts/src/BorrowerOperations.sol b/contracts/src/BorrowerOperations.sol index ba5f462d..7c5fac10 100644 --- a/contracts/src/BorrowerOperations.sol +++ b/contracts/src/BorrowerOperations.sol @@ -551,11 +551,9 @@ contract BorrowerOperations is LiquityBase, Ownable, CheckContract, IBorrowerOpe /** * Claim remaining collateral from a redemption or from a liquidation with ICR > MCR in Recovery Mode */ - function claimCollateral(uint256 _troveId) external override { - _requireIsOwner(_troveId); - + function claimCollateral() external override { // send ETH from CollSurplus Pool to owner - collSurplusPool.claimColl(msg.sender, _troveId); + collSurplusPool.claimColl(msg.sender); } // --- Helper functions --- diff --git a/contracts/src/CollSurplusPool.sol b/contracts/src/CollSurplusPool.sol index 9c9b246c..8d3c763f 100644 --- a/contracts/src/CollSurplusPool.sol +++ b/contracts/src/CollSurplusPool.sol @@ -20,7 +20,7 @@ contract CollSurplusPool is Ownable, ICollSurplusPool { // deposited ether tracker uint256 internal ETHBalance; // Collateral surplus claimable by trove owners - mapping(uint256 => uint256) internal balances; + mapping(address => uint256) internal balances; // --- Events --- @@ -28,7 +28,7 @@ contract CollSurplusPool is Ownable, ICollSurplusPool { event TroveManagerAddressChanged(address _newTroveManagerAddress); event ActivePoolAddressChanged(address _newActivePoolAddress); - event CollBalanceUpdated(uint256 indexed _troveId, uint256 _newBalance); + event CollBalanceUpdated(address indexed _account, uint256 _newBalance); event EtherSent(address _to, uint256 _amount); constructor(address _ETHAddress) { @@ -59,29 +59,29 @@ contract CollSurplusPool is Ownable, ICollSurplusPool { return ETHBalance; } - function getCollateral(uint256 _troveId) external view override returns (uint256) { - return balances[_troveId]; + function getCollateral(address _account) external view override returns (uint256) { + return balances[_account]; } // --- Pool functionality --- - function accountSurplus(uint256 _troveId, uint256 _amount) external override { + function accountSurplus(address _account, uint256 _amount) external override { _requireCallerIsTroveManager(); - uint256 newAmount = balances[_troveId] + _amount; - balances[_troveId] = newAmount; + uint256 newAmount = balances[_account] + _amount; + balances[_account] = newAmount; ETHBalance = ETHBalance + _amount; - emit CollBalanceUpdated(_troveId, newAmount); + emit CollBalanceUpdated(_account, newAmount); } - function claimColl(address _account, uint256 _troveId) external override { + function claimColl(address _account) external override { _requireCallerIsBorrowerOperations(); - uint256 claimableColl = balances[_troveId]; + uint256 claimableColl = balances[_account]; require(claimableColl > 0, "CollSurplusPool: No collateral available to claim"); - balances[_troveId] = 0; - emit CollBalanceUpdated(_troveId, 0); + balances[_account] = 0; + emit CollBalanceUpdated(_account, 0); ETHBalance = ETHBalance - claimableColl; emit EtherSent(_account, claimableColl); diff --git a/contracts/src/Interfaces/IBorrowerOperations.sol b/contracts/src/Interfaces/IBorrowerOperations.sol index e1929725..75f9ee51 100644 --- a/contracts/src/Interfaces/IBorrowerOperations.sol +++ b/contracts/src/Interfaces/IBorrowerOperations.sol @@ -56,7 +56,7 @@ interface IBorrowerOperations is ILiquityBase { ) external; function adjustUnredeemableTrove( - uint256 _troveId, + uint256 _troveId, uint256 _maxFeePercentage, uint256 _collChange, bool _isCollIncrease, @@ -65,8 +65,8 @@ interface IBorrowerOperations is ILiquityBase { uint256 _upperHint, uint256 _lowerHint ) external; - - function claimCollateral(uint256 _troveId) external; + + function claimCollateral() external; function setAddManager(uint256 _troveId, address _manager) external; function setRemoveManager(uint256 _troveId, address _manager) external; diff --git a/contracts/src/Interfaces/ICollSurplusPool.sol b/contracts/src/Interfaces/ICollSurplusPool.sol index bfb2866c..43a0d058 100644 --- a/contracts/src/Interfaces/ICollSurplusPool.sol +++ b/contracts/src/Interfaces/ICollSurplusPool.sol @@ -8,9 +8,9 @@ interface ICollSurplusPool { function getETHBalance() external view returns (uint256); - function getCollateral(uint256 _troveId) external view returns (uint256); + function getCollateral(address _account) external view returns (uint256); - function accountSurplus(uint256 _troveId, uint256 _amount) external; + function accountSurplus(address _account, uint256 _amount) external; - function claimColl(address _account, uint256 _troveId) external; + function claimColl(address _account) external; } diff --git a/contracts/src/TroveManager.sol b/contracts/src/TroveManager.sol index d277f67a..01d1f620 100644 --- a/contracts/src/TroveManager.sol +++ b/contracts/src/TroveManager.sol @@ -334,6 +334,8 @@ contract TroveManager is ERC721, LiquityBase, Ownable, ITroveManager { uint256 _boldInStabPool, uint256 _price ) internal returns (LiquidationValues memory singleLiquidation) { + address owner = ownerOf(_troveId); + LocalVariables_InnerSingleLiquidateFunction memory vars; ( singleLiquidation.entireTroveDebt, @@ -369,7 +371,7 @@ contract TroveManager is ERC721, LiquityBase, Ownable, ITroveManager { // Differencen between liquidation penalty and liquidation threshold if (singleLiquidation.collSurplus > 0) { - collSurplusPool.accountSurplus(_troveId, singleLiquidation.collSurplus); + collSurplusPool.accountSurplus(owner, singleLiquidation.collSurplus); } emit TroveLiquidated( @@ -433,6 +435,8 @@ contract TroveManager is ERC721, LiquityBase, Ownable, ITroveManager { // If 100% < ICR < MCR, offset as much as possible, and redistribute the remainder } else if ((_ICR > _100pct) && (_ICR < MCR)) { + address owner = ownerOf(_troveId); + _movePendingTroveRewardsToActivePool( _activePool, _defaultPool, singleLiquidation.pendingDebtReward, vars.pendingCollReward ); @@ -452,7 +456,7 @@ contract TroveManager is ERC721, LiquityBase, Ownable, ITroveManager { // Differencen between liquidation penalty and liquidation threshold if (singleLiquidation.collSurplus > 0) { - collSurplusPool.accountSurplus(_troveId, singleLiquidation.collSurplus); + collSurplusPool.accountSurplus(owner, singleLiquidation.collSurplus); } emit TroveLiquidated( @@ -469,6 +473,8 @@ contract TroveManager is ERC721, LiquityBase, Ownable, ITroveManager { * The remainder due to the capped rate will be claimable as collateral surplus. */ } else if ((_ICR >= MCR) && (_ICR < _TCR) && (singleLiquidation.entireTroveDebt <= _boldInStabPool)) { + address owner = ownerOf(_troveId); + _movePendingTroveRewardsToActivePool( _activePool, _defaultPool, singleLiquidation.pendingDebtReward, vars.pendingCollReward ); @@ -485,7 +491,7 @@ contract TroveManager is ERC721, LiquityBase, Ownable, ITroveManager { _closeTrove(_troveId, Status.closedByLiquidation); if (singleLiquidation.collSurplus > 0) { - collSurplusPool.accountSurplus(_troveId, singleLiquidation.collSurplus); + collSurplusPool.accountSurplus(owner, singleLiquidation.collSurplus); } emit TroveLiquidated( diff --git a/contracts/src/test/liquidations.t.sol b/contracts/src/test/liquidations.t.sol index 9d607dec..3f69815c 100644 --- a/contracts/src/test/liquidations.t.sol +++ b/contracts/src/test/liquidations.t.sol @@ -65,7 +65,7 @@ contract LiquidationsTest is DevTestSetup { "CollSurplusPoll should have received collateral" ); vm.startPrank(A); - borrowerOperations.claimCollateral(ATroveId); + borrowerOperations.claimCollateral(); vm.stopPrank(); assertEq(WETH.balanceOf(A) - AInitialETHBalance, collSurplusAmount, "A collateral balance mismatch"); }