Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow owner to set any interest rate even if trove has delegate #428

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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