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

Refactor to use repo token utils #21

Merged
merged 4 commits into from
Sep 10, 2024
Merged

Refactor to use repo token utils #21

merged 4 commits into from
Sep 10, 2024

Conversation

aazhou1
Copy link

@aazhou1 aazhou1 commented Sep 10, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a discountRateAdapter to enhance financial calculations related to repo tokens.
    • Added functionality to manage repo redemption haircuts dynamically with role-based access control.
  • Bug Fixes

    • Improved accuracy of calculations for repo tokens by incorporating haircut adjustments.
  • Documentation

    • Updated function signatures and descriptions to reflect new parameters and functionalities.
  • Refactor

    • Streamlined calculations by centralizing discount rate logic and improving code maintainability.
  • Tests

    • Adjusted test setups to accommodate changes in the TermDiscountRateAdapter constructor.

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

coderabbitai bot commented Sep 10, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces significant changes across multiple Solidity files, primarily focusing on the integration of a discountRateAdapter parameter into various functions. This addition allows for improved management of discount rates and repo token calculations. The modifications include updates to function signatures, internal logic adjustments to incorporate redemption haircuts, and enhancements to access control within the TermDiscountRateAdapter contract.

Changes

File Change Summary
src/RepoTokenList.sol Added discountRateAdapter parameter to getCumulativeRepoTokenData and getPresentValue functions; refactored logic to utilize the adapter for discount rate calculations.
src/RepoTokenUtils.sol Modified getNormalizedRepoTokenAmount to include repoRedemptionHaircut parameter, affecting normalization calculations.
src/Strategy.sol Refactored repoTokenAmountInBaseAssetPrecision calculation to use RepoTokenUtils.getNormalizedRepoTokenAmount with new parameters; changed getDiscountRate visibility from external to public.
src/TermAuctionList.sol Added discountRateAdapter parameter in getCumulativeOfferData; updated calculations to incorporate haircut values.
src/TermDiscountRateAdapter.sol Introduced role-based access control with ORACLE_ROLE; added mapping for repoRedemptionHaircut and a function to set it.
src/interfaces/term/ITermDiscountRateAdapter.sol Added repoRedemptionHaircut function to retrieve haircut values for specific tokens.
src/test/utils/Setup.sol Updated instantiation of TermDiscountRateAdapter to include adminWallet parameter; added oracleWallet variable.

Possibly related PRs

🐰 In the meadow where tokens play,
A discount adapter brightens the day.
With haircuts and rates, they dance in delight,
Calculations now shine, oh what a sight!
So hop along, let the numbers align,
In the world of finance, everything's fine!
🌼✨


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 47bb445 and 9dc10e4.

Files selected for processing (7)
  • src/RepoTokenList.sol (6 hunks)
  • src/RepoTokenUtils.sol (1 hunks)
  • src/Strategy.sol (9 hunks)
  • src/TermAuctionList.sol (4 hunks)
  • src/TermDiscountRateAdapter.sol (2 hunks)
  • src/interfaces/term/ITermDiscountRateAdapter.sol (1 hunks)
  • src/test/utils/Setup.sol (1 hunks)
Additional comments not posted (24)
src/interfaces/term/ITermDiscountRateAdapter.sol (1)

5-5: LGTM!

The code changes are approved.

src/TermDiscountRateAdapter.sol (6)

7-7: LGTM!

The code changes are approved.


14-14: LGTM!

The code changes are approved.


16-16: LGTM!

The code changes are approved.


19-19: LGTM!

The code changes are approved.


24-28: LGTM!

The code changes are approved.


47-54: LGTM!

The code changes are approved.

src/RepoTokenUtils.sol (1)

81-94: LGTM!

The code changes are approved.

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

98-98: LGTM!

The code change is approved. Passing the adminWallet to the TermDiscountRateAdapter constructor aligns with the PR objective of refactoring to use repo token utils and likely enables additional functionality in the contract.

src/TermAuctionList.sol (3)

320-320: LGTM!

The code change is approved. Adding the discountRateAdapter parameter to the getCumulativeOfferData function signature aligns with the PR objective and enables the function to utilize discount rate information.


294-295: LGTM!

The code change is approved. Utilizing the discountRateAdapter to retrieve the repoRedemptionHaircut value and factoring it into the calculation of repoTokenAmountInBaseAssetPrecision aligns with the PR objective and enhances the accuracy of the total value computation.


367-368: LGTM!

The code change is approved. Utilizing the discountRateAdapter to retrieve the repoRedemptionHaircut value and factoring it into the calculation of offerAmount aligns with the PR objective and enhances the accuracy of the offer amount computation.

src/RepoTokenList.sol (6)

116-116: LGTM!

The code change is approved. Adding the discountRateAdapter parameter to the getCumulativeRepoTokenData function signature aligns with the PR objective and enables the function to utilize an external discount rate adapter.


131-131: LGTM!

The code change is approved. Adding the discountRateAdapter parameter to the getCumulativeRepoTokenData function implementation aligns with the addition of the parameter to the function signature and enables the function to utilize the discount rate adapter.


154-156: LGTM!

The code change is approved. Refactoring the calculation of repoTokenBalanceInBaseAssetPrecision to use RepoTokenUtils.getNormalizedRepoTokenAmount and incorporating the discount rate and redemption haircut from the discountRateAdapter aligns with the PR objective and streamlines the calculation logic.


176-176: LGTM!

The code change is approved. Adding the discountRateAdapter parameter to the getPresentValue function signature aligns with the PR objective and enables the function to utilize an external discount rate adapter.


190-190: LGTM!

The code change is approved. Adding the discountRateAdapter parameter to the getPresentValue function implementation aligns with the addition of the parameter to the function signature and enables the function to utilize the discount rate adapter.


209-216: LGTM!

The code changes are approved. Modifying the calculation of discountRate to use discountRateAdapter.getDiscountRate(current) and refactoring the calculation of repoTokenBalanceInBaseAssetPrecision to use RepoTokenUtils.getNormalizedRepoTokenAmount with the redemption haircut from the discountRateAdapter align with the PR objective and centralize the discount rate logic, improving maintainability.

src/Strategy.sol (6)

400-409: LGTM!

The code changes are approved. The function now correctly uses the discountRateAdapter to get the repo redemption haircut when normalizing the repoToken amount.


431-433: LGTM!

The code changes are approved. The function now correctly passes the discountRateAdapter to the getPresentValue functions.


493-493: LGTM!

The code changes are approved. The function now correctly passes the discountRateAdapter to the getPresentValue functions.


601-601: LGTM!

The code changes are approved. The function now correctly:

  • Passes the discountRateAdapter to the getCumulativeRepoTokenData and getCumulativeOfferData functions.
  • Uses the discountRateAdapter to get the repo redemption haircut when normalizing the repoToken amount.

Also applies to: 617-617, 632-638


1014-1014: LGTM!

The code changes are approved. The function now correctly uses the discountRateAdapter to:

  • Get the discount rate for the repoToken.
  • Get the repo redemption haircut when normalizing the repoToken amount.

Also applies to: 1029-1037


354-361: LGTM!

The code changes are approved. The function now correctly uses the discountRateAdapter to:

  • Get the discount rate for the repoToken.
  • Get the repo redemption haircut when normalizing the repoToken amount.

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 9dc10e4 and a127c5c.

Files selected for processing (1)
  • src/test/utils/Setup.sol (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/test/utils/Setup.sol

@aazhou1 aazhou1 changed the base branch from master to runtime-fv September 10, 2024 02:36
@aazhou1 aazhou1 merged commit f593f02 into runtime-fv Sep 10, 2024
0 of 4 checks passed
@aazhou1 aazhou1 deleted the refactor branch September 10, 2024 02:36
This was referenced Sep 12, 2024
This was referenced Oct 2, 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.

1 participant