Skip to content

Commit

Permalink
fix: Allow owner to set any interest rate even if trove has delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
bingen committed Sep 20, 2024
1 parent 3d7d4ce commit a2fcb51
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
22 changes: 12 additions & 10 deletions contracts/src/BorrowerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ contract BorrowerOperations is LiquityBase, AddRemoveManagers, IBorrowerOperatio
_requireIsNotInBatch(_troveId);
address owner = troveNFT.ownerOf(_troveId);
_requireSenderIsOwnerOrInterestManager(_troveId, owner);
_requireInterestRateInDelegateRange(_troveId, _newAnnualInterestRate);
_requireInterestRateInDelegateRange(_troveId, _newAnnualInterestRate, owner);
_requireTroveIsActive(troveManagerCached, _troveId);

LatestTroveData memory trove = troveManagerCached.getLatestTroveData(_troveId);
Expand Down Expand Up @@ -1287,6 +1287,17 @@ contract BorrowerOperations is LiquityBase, AddRemoveManagers, IBorrowerOperatio
}
}

function _requireInterestRateInDelegateRange(uint256 _troveId, uint256 _annualInterestRate, address _owner) internal view {
InterestIndividualDelegate memory individualDelegate = interestIndividualDelegateOf[_troveId];
// We have previously checked that sender is either owner or delegate
// If it’s owner, this restriction doesn’t apply
if (individualDelegate.account == msg.sender) {
_requireInterestRateInRange(
_annualInterestRate, individualDelegate.minInterestRate, individualDelegate.maxInterestRate
);
}
}

function _requireIsNotInBatch(uint256 _troveId) internal view {
if (interestBatchManagerOf[_troveId] != address(0)) {
revert TroveInBatch();
Expand Down Expand Up @@ -1442,15 +1453,6 @@ contract BorrowerOperations is LiquityBase, AddRemoveManagers, IBorrowerOperatio
if (_minInterestRate >= _maxInterestRate) revert MinGeMax();
}

function _requireInterestRateInDelegateRange(uint256 _troveId, uint256 _annualInterestRate) internal view {
InterestIndividualDelegate memory individualDelegate = interestIndividualDelegateOf[_troveId];
if (individualDelegate.account != address(0)) {
_requireInterestRateInRange(
_annualInterestRate, individualDelegate.minInterestRate, individualDelegate.maxInterestRate
);
}
}

function _requireInterestRateInBatchManagerRange(address _interestBatchManagerAddress, uint256 _annualInterestRate)
internal
view
Expand Down
16 changes: 16 additions & 0 deletions contracts/src/test/interestIndividualDelegation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ contract InterestIndividualDelegationTest is DevTestSetup {
vm.stopPrank();
}

function testOwnerCanSetInterestBelowMin() public {
uint256 troveId = openTroveAndSetIndividualDelegate();

vm.startPrank(A);
borrowerOperations.adjustTroveInterestRate(troveId, MIN_ANNUAL_INTEREST_RATE, 0, 0, 1e24);
vm.stopPrank();
}

function testOwnerCanSetInterestAboveMax() public {
uint256 troveId = openTroveAndSetIndividualDelegate();

vm.startPrank(A);
borrowerOperations.adjustTroveInterestRate(troveId, 50e16, 0, 0, 1e24);
vm.stopPrank();
}

function testSetDelegateRevertsIfTroveIsClosed() public {
vm.startPrank(B);
borrowerOperations.registerBatchManager(1e16, 20e16, 5e16, 25e14, MIN_INTEREST_RATE_CHANGE_PERIOD);
Expand Down

0 comments on commit a2fcb51

Please sign in to comment.