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

Add borrower-chosen interest rate ordering #63

Merged
merged 9 commits into from
Feb 20, 2024
Merged

Conversation

RickGriff
Copy link
Collaborator

@RickGriff RickGriff commented Jan 25, 2024

  • Adds an annualInterestRate property to Troves and orders the SortedList by it.
  • A borrower initially sets their interest rate in openTrove, and changes it later with the dedicated adjustTroveInterestRate function. Interest rate is not changed in adjustTrove - which only alters collateral and/or debt
  • We store the annual rate so that the getter returns the exact chosen rate, and will later calculate a per-unit-time (second, block, etc) rate from this when applying pending interest

Potential gas optimizations:

  • Store the rate directly on the node in the SortedList to reduce costs of any on-chain traversals needed (though would make some TroveManager ops more expensive - e.g. liquidations)

@bingen
Copy link
Collaborator

bingen commented Jan 25, 2024

Closes #54

@RickGriff RickGriff marked this pull request as ready for review January 25, 2024 13:09
@RickGriff RickGriff requested a review from bingen January 25, 2024 13:09
Copy link
Collaborator

@bingen bingen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice progress!!

_adjustTrove(msg.sender, _collWithdrawal, _boldChange, _isDebtIncrease, _maxFeePercentage);
}

function adjustTroveInterestRate(uint _newAnnualInterestRate, address _upperHint, address _lowerHint) external {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t this function be permissioned? Either trove owner or the delegate. We may add a TODO and add it when we do delegation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this one is implicitly permissioned by _requireTroveIsActive, and the function only acts on the Trove owned by msg.sender.

The delegate functionality is TODO.

contracts/src/TroveManager.sol Show resolved Hide resolved
contracts/src/BorrowerOperations.sol Show resolved Hide resolved
@@ -1282,470 +1282,6 @@ contract("Gas compensation tests", async (accounts) => {
assert.isAtMost(th.getDifference(expectedGasComp_B, loggedGasComp_B), 1000);
});

// liquidateTroves - full offset
it("liquidateTroves(): full offset. Compensates the correct amount, and liquidates the remainder", async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we removing these ones because they use liquidate(n) function? Maybe we can translate them to batchLiquidateTroves. Happy to add a commit for that myself if you want me to.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, right. Some could be translated, most don't seem to have an equivalent batchLiquidateTroves test.

@@ -56,7 +56,46 @@ contract BaseTest is Test {
accountsList = tempAccounts;
}

function logContractAddresses() view public {
function openTroveNoHints100pctMaxFee(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the 100pctMaxFee mean here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a helper function that puts the max fee at 100%. Though we're not using the maxFeePercentage for anything now, so it could even be removed as an input param for openTrove.

I guess under the current scope there's no need for it as the borrow fee would purely depend on the user chosen interest rate, rather than other user actions or time decay.

// --- batchLiquidateTroves() ---
// TODO: revisit the relevance of this test since it relies on liquidateTroves(), which now no longer works due to ordering by interest rate.
// Can we achieve / test the same thing using another liquidation function?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it seems the test is wrong, right? It should do batchLiquidateTroves([B,C]) instead of liquidateTroves(2).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, yeah! I had test fatigue by this point

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, totally understand!!

@@ -265,77 +265,5 @@ contract(
assert.equal((await troveManager.Troves(carol))[3], "1");
});
});

context("Sequential liquidations", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can translate these ones too. Or comment them out and put a TODO, so that we do if we finally leave Recovery Mode.

@@ -2426,1949 +2425,6 @@ contract("TroveManager - in Recovery Mode", async (accounts) => {
);
});

// --- liquidateTroves ---
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can translate these ones too. Or comment them out and put a TODO, so that we do if we finally leave Recovery Mode.

contracts/utils/testHelpers.js Outdated Show resolved Hide resolved
contracts/utils/testHelpers.js Show resolved Hide resolved
@RickGriff RickGriff merged commit 987d847 into main Feb 20, 2024
5 checks passed
@danielattilasimon danielattilasimon deleted the interest_rate_basics branch April 12, 2024 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants