-
Notifications
You must be signed in to change notification settings - Fork 169
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
feat: adjust interest rate algorithm and associated token param rules #2388
Conversation
WalkthroughThe recent update introduces changes to the interest rate algorithm and associated token parameter validation rules. It aims to improve the accuracy of the borrow annual percentage yield (APY) calculation based on token utilization and supply limits, ensuring a more responsive and logical relationship between utilization and APY. Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (5)
- CHANGELOG.md (1 hunks)
- x/leverage/keeper/interest.go (1 hunks)
- x/leverage/keeper/interest_test.go (1 hunks)
- x/leverage/keeper/msg_server_test.go (2 hunks)
- x/leverage/types/token.go (1 hunks)
Additional comments: 6
x/leverage/keeper/interest_test.go (1)
- 72-84: The
TestDynamicInterest
function has been updated to reflect the new interest rate calculations. The test now includes scenarios for borrowing at 85% and 90% utilization, which correspond to the new logic for calculating interest rates between kink and max utilization, and at max utilization respectively. Ensure that these tests align with the expected behavior of the updated interest rate algorithm.x/leverage/keeper/interest.go (1)
- 25-40: The
DeriveBorrowAPY
function has been updated to handle scenarios where the token utilization reaches or exceeds certain thresholds. The logic now includes conditions to use the max borrow APY when the utilization is greater than or equal to theMaxSupplyUtilization
, and to interpolate between the kink and max borrow rates when the utilization is between theKinkUtilization
andMaxSupplyUtilization
. This change is crucial for handling tokens like UMEE that have a maximum supply utilization below their kink utilization. Ensure that the new logic is consistent with the intended behavior described in the PR objectives.x/leverage/types/token.go (1)
- 56-82: The validation logic for kink utilization rates has been modified to allow inclusive ranges and ensure the continuity of the utilization-to-APY graph. The changes enforce that the kink utilization cannot be greater than the max supply utilization, and if they are equal, the kink borrow rate must equal the max borrow rate. Additionally, if the kink utilization is zero, the kink borrow rate must equal the base borrow rate, and similarly for the max supply utilization. These rules are important to prevent discontinuities in the utilization-to-APY graph and ensure that the financial model behaves as expected. Confirm that these changes align with the new rules for token parameter validation as intended in the PR objectives.
CHANGELOG.md (1)
- 49-51: The changelog entry for PR feat: adjust interest rate algorithm and associated token param rules #2388 is correctly formatted and provides a clear description of the changes introduced.
x/leverage/keeper/msg_server_test.go (2)
- 1979-1982: The changes to the UMEE token settings in this test case include setting
MinCollateralLiquidity
to 0.2,KinkUtilization
to 0.6, andMaxSupplyUtilization
to 0.7. Ensure that these values align with the new interest rate algorithm and token parameter validation rules. Additionally, verify that theKinkUtilization
is less thanMaxSupplyUtilization
as per the new logic.Verification successful
The verification script encountered an issue due to the
paste
command not being available in the execution environment, which prevented the comparison ofKinkUtilization
andMaxSupplyUtilization
values. To proceed, I will generate a new script that performs the comparison without relying on thepaste
command.
The verification script did not produce any output, which suggests that there are no instances in the
msg_server_test.go
file whereKinkUtilization
is not less thanMaxSupplyUtilization
. This aligns with the expected behavior as per the PR objectives and review comment. Therefore, it can be concluded that the changes to the UMEE token settings in the test cases are consistent with the new interest rate algorithm and token parameter validation rules.* 2026-2029: The changes to the UMEE token settings in this test case include setting `MinCollateralLiquidity` to 0.2, `KinkUtilization` to 0.45, and `MaxSupplyUtilization` to 0.5. It is important to ensure that the `KinkUtilization` is appropriately set below the `MaxSupplyUtilization` to reflect the intended behavior of the updated interest rate algorithm. The values seem to be consistent with the new rules, but this should be verified across all test cases.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the KinkUtilization is always less than MaxSupplyUtilization in all configurations. rg --type go 'KinkUtilization = sdk.MustNewDecFromStr' x/leverage/keeper/msg_server_test.go | gawk '{ print $5 }' | sed 's/"//g' > kink_values.txt rg --type go 'MaxSupplyUtilization = sdk.MustNewDecFromStr' x/leverage/keeper/msg_server_test.go | gawk '{ print $5 }' | sed 's/"//g' > max_supply_values.txt paste -d',' kink_values.txt max_supply_values.txt | awk -F',' '{ if ($1 >= $2) print "KinkUtilization is not less than MaxSupplyUtilization at: Kink=" $1 ", MaxSupply=" $2; }'Length of output: 513
Script:
#!/bin/bash # Extract KinkUtilization and MaxSupplyUtilization values and compare them directly using awk # Extract KinkUtilization values kink_values=$(rg --type go 'KinkUtilization = sdk.MustNewDecFromStr' x/leverage/keeper/msg_server_test.go | gawk '{ print $5 }' | sed 's/"//g') # Extract MaxSupplyUtilization values max_supply_values=$(rg --type go 'MaxSupplyUtilization = sdk.MustNewDecFromStr' x/leverage/keeper/msg_server_test.go | gawk '{ print $5 }' | sed 's/"//g') # Combine the extracted values into pairs and compare them awk -v kinks="$kink_values" -v max_supplies="$max_supply_values" 'BEGIN { split(kinks, kink_arr, "\n"); split(max_supplies, max_supply_arr, "\n"); for (i in kink_arr) { if (kink_arr[i] >= max_supply_arr[i]) print "KinkUtilization is not less than MaxSupplyUtilization at: Kink=" kink_arr[i] ", MaxSupply=" max_supply_arr[i]; } }'Length of output: 624
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #2388 +/- ##
==========================================
- Coverage 75.38% 68.45% -6.94%
==========================================
Files 100 180 +80
Lines 8025 13362 +5337
==========================================
+ Hits 6050 9147 +3097
- Misses 1589 3606 +2017
- Partials 386 609 +223
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- app/upgrades.go (1 hunks)
Additional comments: 2
app/upgrades.go (2)
- 50-72: The addition of
registerUpgrade6_4
method introduces logic to adjust token settings during an upgrade to version "v6.4". It includes a check to alignKinkUtilization
withMaxSupplyUtilization
if the former is greater than or equal to the latter, and then updates the token settings accordingly. This change seems to be in line with the PR objectives to refine the interest rate algorithm and token parameter validation rules.However, there are a few points to consider:
- Ensure that the logic within the upgrade handler is thoroughly tested, especially the conditional logic that adjusts token settings.
- Confirm that the
SetTokenSettings
method handles all necessary validation and error handling since it's being used to persist changes to the token settings.- Verify that the migration does not negatively impact any existing data or configurations, particularly for tokens that do not require adjustments.
- 47-75: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-49]
The structure of the upgrade registration methods appears consistent with the existing pattern in the file. Each upgrade version has a corresponding registration method, and outdated upgrades are handled by placeholder functions that panic if called, preventing accidental state migrations on old versions. This consistency is important for maintainability and understanding the upgrade path of the application.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- app/upgrades.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- app/upgrades.go
This will also require a migration on mainnet and canon to make existing tokens valid. The migration has been added to
upgrades.go
asv6.4
For example, mainnet UMEE has a max supply utilization below its kink utilization
Summary by CodeRabbit
New Features
Refactor
Tests