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

Repo redemption haircut #14

Closed
wants to merge 5 commits into from
Closed

Repo redemption haircut #14

wants to merge 5 commits into from

Conversation

aazhou1
Copy link

@aazhou1 aazhou1 commented Sep 4, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new mapping to manage haircut values for repo tokens, enhancing redemption processes.
    • Added a function for management to set haircut values for specific repo tokens, allowing for dynamic adjustments.
  • Improvements

    • Updated redemption value calculations to incorporate haircut values, ensuring consistent application across transactions.
    • Enhanced the present value calculation to reflect adjustments in handling repo token values, improving accuracy.
    • Streamlined the logic for calculating present values, improving clarity and efficiency.
  • Access Control

    • Implemented role-based access control for managing haircut values, enhancing security and governance.

@aazhou1 aazhou1 self-assigned this Sep 4, 2024
Copy link

coderabbitai bot commented Sep 4, 2024

Walkthrough

The changes introduce a new variable repoRedemptionHaircutMantissa across multiple contracts to manage haircut values associated with repo tokens. The Strategy.sol contract now includes a public mapping for haircut values and a function to set them. The RepoTokenList.sol library's calculations have been updated to reflect these haircuts, enhancing the precision of financial computations involving repo tokens.

Changes

Files Change Summary
src/Strategy.sol Introduced repoRedemptionHaircutMantissa variable, added a public mapping for haircut values, and modified redemption value calculations to incorporate haircuts. Updated functions to accept haircut parameters.
src/RepoTokenList.sol Modified getPresentValue function to accept repoRedemptionHaircutMantissa, affecting present value calculations. Streamlined internal logic for improved clarity and efficiency.
src/TermDiscountRateAdapter.sol Added access control with DEVOPS_ROLE, introduced a public mapping for haircut values, and created a function to set haircut values for repo tokens.
src/interfaces/term/ITermDiscountRateAdapter.sol Added a new function to retrieve haircut values associated with repo tokens.
src/test/utils/Setup.sol Updated instantiation of TermDiscountRateAdapter to include a new parameter for devopsWallet.

Poem

🐰 In the meadow where tokens play,
A haircut's set to brighten the day.
With values trimmed, they dance and twirl,
In the world of finance, watch them swirl!
So hop along, let the numbers sing,
For every repo, joy they'll bring! 🌼


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2272739 and aa9067e.

Files selected for processing (1)
  • src/Strategy.sol (5 hunks)
Additional comments not posted (4)
src/Strategy.sol (4)

68-68: LGTM!

The new repoRedemptionHaircut mapping is correctly declared to store haircut values for repo tokens.


133-140: LGTM!

The new setRepoRedemptionHaircut function is correctly implemented to allow management to set the haircut value for a specific repo token. It follows the required access control using the onlyManagement modifier.


366-373: LGTM!

The changes correctly incorporate the haircut value into the calculation of the repo token amount in base asset precision. The default value of 1e18 is used when no haircut is set, ensuring consistent behavior. The haircut is applied as expected during the redemption value calculation.


1041-1046: LGTM!

The changes correctly incorporate the haircut value into the calculation of the repo token amount in base asset precision, consistent with the previous code segment. The default value of 1e18 is used when no haircut is set, ensuring consistent behavior. The haircut is applied as expected during the redemption value calculation.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between aa9067e and c041557.

Files selected for processing (2)
  • src/RepoTokenList.sol (2 hunks)
  • src/Strategy.sol (7 hunks)
Additional comments not posted (7)
src/RepoTokenList.sol (1)

190-191: Verify the parameter usage in the codebase.

Ensure that all calls to getPresentValue provide the new parameter repoRedemptionHaircutMantissa.

Run the following script to verify the parameter usage:

Verification successful

Parameter usage verified successfully.

All calls to the getPresentValue function in src/RepoTokenList.sol correctly include the new parameter repoRedemptionHaircutMantissa. No issues were found with the parameter usage in the codebase.

  • Verified in src/Strategy.sol with correct arguments.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all calls to `getPresentValue` provide the new parameter.

# Test: Search for the function usage. Expect: Only occurrences with 4 arguments.
rg --type solidity -A 5 $'getPresentValue'

Length of output: 74


Script:

#!/bin/bash
# Description: Verify all calls to `getPresentValue` provide the new parameter.

# Test: Search for the function usage. Expect: Only occurrences with 4 arguments.
rg -A 5 'getPresentValue'

Length of output: 1971

src/Strategy.sol (6)

68-68: LGTM!

The code changes are approved.


133-140: LGTM!

The code changes are approved.


366-373: LGTM!

The code changes are approved.


416-421: LGTM!

The code changes are approved.


443-450: LGTM!

The code changes are approved.


1045-1050: LGTM!

The code changes are approved.

Comment on lines 214 to 215
(ITermRepoToken(current).redemptionValue() * repoRedemptionHaircutMantissa * repoTokenBalance * purchaseTokenPrecision) /
(repoTokenPrecision * RepoTokenUtils.RATE_PRECISION * 1e18);
Copy link

Choose a reason for hiding this comment

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

LGTM!

The calculation looks good and aligns with the AI-generated summary.

Refactor suggestion: Use constants for precision values.

Consider defining constants for the precision values to improve readability and maintainability.

Apply this diff to define and use constants:

+uint256 private constant REPO_TOKEN_UTILS_RATE_PRECISION = 1e18;
+uint256 private constant PRECISION_FACTOR = 1e18;

 uint256 repoTokenBalanceInBaseAssetPrecision = 
-    (ITermRepoToken(current).redemptionValue() * repoRedemptionHaircutMantissa * repoTokenBalance * purchaseTokenPrecision) / 
-    (repoTokenPrecision * RepoTokenUtils.RATE_PRECISION * 1e18);
+    (ITermRepoToken(current).redemptionValue() * repoRedemptionHaircutMantissa * repoTokenBalance * purchaseTokenPrecision) / 
+    (repoTokenPrecision * REPO_TOKEN_UTILS_RATE_PRECISION * PRECISION_FACTOR);

Committable suggestion was skipped due to low confidence.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c041557 and 160545f.

Files selected for processing (1)
  • src/RepoTokenList.sol (1 hunks)
Additional comments not posted (5)
src/RepoTokenList.sol (5)

190-191: LGTM!

The function signature change aligns with the AI-generated summary and appears to be intentional.


196-202: LGTM!

The changes to the internal logic align with the AI-generated summary and enhance the clarity and efficiency of the code.


213-245: LGTM!

The new _getTotalPresentValue function aligns with the AI-generated summary and promotes code reuse and maintainability. The incorporation of the repoRedemptionHaircutMantissa parameter in the calculation reflects the changes made to the getPresentValue function.


234-236: Refactor suggestion: Use constants for precision values.

The past review comment suggesting the use of constants for precision values is still valid and applicable to the updated calculation.


241-242: LGTM!

The function call to RepoTokenUtils.calculatePresentValue appears to be correct and consistent with the changes made to the calculation of repoTokenBalanceInBaseAssetPrecision.

Copy link

@orthogonalglobal orthogonalglobal left a comment

Choose a reason for hiding this comment

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

@aazhou1 this is not correct, we need to do this in the discountRateAdapter

  1. we (term) needs to be the one that sets haircut by keeper
  2. we are not the Manager here
  3. this is useable across all vaults
    ==> centralize shortfall haircut keeper method to the discountRateAdapater

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 160545f and 19bb70d.

Files selected for processing (4)
  • src/Strategy.sol (6 hunks)
  • src/TermDiscountRateAdapter.sol (2 hunks)
  • src/interfaces/term/ITermDiscountRateAdapter.sol (1 hunks)
  • src/test/utils/Setup.sol (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/Strategy.sol
Additional comments not posted (7)
src/interfaces/term/ITermDiscountRateAdapter.sol (1)

6-6: Existing function getDiscountRate remains unchanged and correctly implemented.

The function getDiscountRate is appropriately declared with the correct modifiers and parameter names, and remains unchanged in this pull request.

src/TermDiscountRateAdapter.sol (5)

7-7: Approved: Import of AccessControlUpgradeable.

The import statement for AccessControlUpgradeable is correct and necessary for the added functionality.


14-14: Approved: Contract inheritance change.

The contract now correctly inherits from both ITermDiscountRateAdapter and AccessControlUpgradeable, aligning with the PR's objectives to introduce access control.


16-16: Approved: Definition of DEVOPS_ROLE.

The constant DEVOPS_ROLE is defined using a keccak256 hash, which is a standard practice for defining roles in Solidity contracts using the AccessControl library.


19-19: Approved: New mapping for repoRedemptionHaircut.

The introduction of the repoRedemptionHaircut mapping is well-implemented. It allows the storage of haircut values associated with specific repo tokens, which is crucial for the new functionality.


26-28: Review: Constructor updates.

The constructor now accepts an additional parameter devopsWallet_ and correctly grants the DEVOPS_ROLE to this address. Ensure that the address provided during deployment is correct and that the role assignment aligns with your access control policies.

Verification successful

Constructor usage verified.

The deployment script correctly uses the updated constructor signature for TermDiscountRateAdapter, including the devopsWallet_ parameter. Ensure that the devopsWallet address provided aligns with your access control policies.

  • Constructor usage: discountRateAdapter = new TermDiscountRateAdapter(address(termController), devopsWallet);
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correct usage of the `devopsWallet_` parameter in deployment scripts.

# Test: Search for the constructor usage in deployment scripts. Expect: Correct usage of the new constructor signature.
rg --type solidity -A 5 $'new TermDiscountRateAdapter'

Length of output: 88


Script:

#!/bin/bash
# Find all Solidity files and search for the constructor usage of TermDiscountRateAdapter
fd --extension sol --exec rg 'new TermDiscountRateAdapter' {}

Length of output: 163

src/test/utils/Setup.sol (1)

98-98: Verify the updated constructor usage of TermDiscountRateAdapter.

The change to include devopsWallet in the constructor of TermDiscountRateAdapter suggests an enhancement in functionality. It is crucial to:

  • Ensure that the TermDiscountRateAdapter contract has been appropriately updated to handle this new parameter.
  • Verify that devopsWallet is being used correctly within the TermDiscountRateAdapter.
  • Assess the impact of this change on other parts of the system, especially where TermDiscountRateAdapter is utilized.

Run the following script to verify the constructor usage and the handling of devopsWallet within the TermDiscountRateAdapter:

Verification successful

Constructor update for TermDiscountRateAdapter verified successfully.

The constructor of TermDiscountRateAdapter has been updated to include the devopsWallet parameter, and it is used to grant a role within the contract. This change is consistent with the instantiation in Setup.sol and appears to be implemented correctly.

  • The constructor in src/TermDiscountRateAdapter.sol includes devopsWallet_ and uses it appropriately.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the constructor usage and handling of `devopsWallet` in `TermDiscountRateAdapter`.

# Test: Search for the constructor definition and usage. Expect: Constructor should include `devopsWallet`.
ast-grep --lang solidity --pattern $'contract TermDiscountRateAdapter {
  constructor($_, $_) {
    $$$
  }
}'

Length of output: 228


Script:

#!/bin/bash
# Use ripgrep to search for the constructor definition of TermDiscountRateAdapter in Solidity files.
rg 'constructor\(' --glob '*.sol' -A 5

Length of output: 4637

@@ -2,5 +2,6 @@
pragma solidity ^0.8.18;

interface ITermDiscountRateAdapter {
function repoRedemptionHaircut(address) external view returns (uint256);
Copy link

Choose a reason for hiding this comment

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

Specify parameter name for clarity in repoRedemptionHaircut.

The function repoRedemptionHaircut lacks a parameter name, which could lead to confusion or errors when implementing the interface. It is recommended to specify a parameter name to improve readability and maintainability.

Consider modifying the function declaration as follows:

-function repoRedemptionHaircut(address) external view returns (uint256);
+function repoRedemptionHaircut(address repoAddress) external view returns (uint256);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function repoRedemptionHaircut(address) external view returns (uint256);
function repoRedemptionHaircut(address repoAddress) external view returns (uint256);

Comment on lines +52 to +54
function setRepoRedemptionHaircut(address repoToken, uint256 haircut) external onlyRole(DEVOPS_ROLE) {
repoRedemptionHaircut[repoToken] = haircut;
}
Copy link

Choose a reason for hiding this comment

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

Review: New function setRepoRedemptionHaircut.

The function setRepoRedemptionHaircut is correctly implemented with role-based access control using onlyRole(DEVOPS_ROLE). This ensures that only authorized users can modify the haircut values. However, consider adding input validation for the haircut parameter to ensure it falls within expected ranges, especially since it represents financial data.

Consider adding input validation for the haircut parameter:

require(haircut <= 100 * 10**18, "Haircut value is too high"); // Assuming 100% is the maximum valid haircut

@aazhou1 aazhou1 closed this Sep 10, 2024
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