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

Update APY calculations for SKY #4030

Merged
merged 1 commit into from
Sep 23, 2024
Merged

Conversation

marcinciarka
Copy link
Member

@marcinciarka marcinciarka commented Sep 23, 2024

Added proper APY calc for SKY (portfolio, product hub, position page)

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced staking details functionality with the ability to compute Annual Percentage Yield (APY) based on MKR price input.
    • Updated display of staking rewards from raw rates to user-friendly APY format.
  • Bug Fixes

    • Improved handling of price data across various components to ensure accurate calculations and displays.
  • Documentation

    • Updated function signatures to reflect new parameters and return structures for better clarity and usability.

These changes collectively improve the user experience by providing clearer and more relevant staking information.

Copy link
Contributor

coderabbitai bot commented Sep 23, 2024

Walkthrough

The changes primarily enhance the skyUsdsStakeDetails function across multiple files, allowing it to accept an optional mkrPrice parameter for calculating the annual percentage yield (APY) based on MKR price. This update affects the data structures and display logic in components and handlers, transitioning from a raw reward rate to a more user-friendly APY format. The modifications improve the integration of price data and overall data handling within the application.

Changes

Files Change Summary
blockchain/better-calls/sky.ts Updated skyUsdsStakeDetails to accept an optional mkrPrice parameter, added skyPrice calculation, and modified APY computation.
features/sky/components/stake/SkyStakePositionView.tsx Changed skyStakeData type from rewardRate to apy, updated display logic to format apy as a percentage.
handlers/portfolio/positions/handlers/sky/index.ts Modified skyPositionsHandler to include prices parameter, updated call to skyUsdsStakeDetails with mkrPrice, and changed APY formatting.
handlers/product-hub/update-handlers/sky/skyHandler.ts Updated getSkyData function to accept tickers parameter, utilized mkrPrice from tickers when calling skyUsdsStakeDetails, and altered return structure to include weeklyNetApy.
helpers/context/ProductContext.ts Modified skyUsdsStakeDetails$ function to accept an optional mkrPrice parameter, enabling contextual data retrieval.
pages/earn/srr/[wallet].tsx Updated tempSkyStakeData state to include apy instead of rewardRate, adjusted observable to pass tokenPrices?.MKR, and modified update conditions to reflect new property structure.

Possibly related PRs

  • Sky USDS staking view #4027: Introduces a basic staking view for Sky USDS, directly relating to the enhancements made in the skyUsdsStakeDetails function.
  • Sky changes #4028: Simplifies the skyUsdsWalletStakeDetails function, relevant to the updates in the main PR that enhance skyUsdsStakeDetails.

Suggested reviewers

  • halaprix
  • piekczyk

Poem

🐰 In the meadow where the bunnies play,
New features hop in, brightening the day.
With APY shining, rewards now clear,
Staking's a joy, come gather near!
Let's celebrate changes, both big and small,
For a brighter future, we’ll all stand tall! 🌼


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>, please review it.
    -- 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @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
Contributor

@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: 7

Outside diff range and nitpick comments (2)
features/sky/components/stake/SkyStakePositionView.tsx (1)

306-306: LGTM! Consider adjusting percent formatting.

The change from formatCryptoBalance(skyStakeData.rewardRate) to formatDecimalAsPercent(skyStakeData.apy, { noPercentSign: true }) is consistent with the type definition update and more appropriate for displaying APY.

Consider removing the noPercentSign: true option from formatDecimalAsPercent and updating the unit prop:

-value={`${formatDecimalAsPercent(skyStakeData.apy, { noPercentSign: true })}`}
-unit="%"
+value={formatDecimalAsPercent(skyStakeData.apy)}
+unit=""

This change would let formatDecimalAsPercent handle the percent sign, ensuring consistent formatting across the application.

helpers/context/ProductContext.ts (1)

692-693: LGTM! Consider adding a comment for clarity.

The change to skyUsdsStakeDetails$ function looks good. It now accepts an optional mkrPrice parameter, which allows for more flexibility in APY calculations for SKY.

Consider adding a brief comment explaining the purpose of the mkrPrice parameter and its impact on the stake details calculation. This would improve code readability and maintainability. For example:

// mkrPrice: Optional parameter to provide current MKR price for more accurate APY calculations
const skyUsdsStakeDetails$ = (mkrPrice?: BigNumber) =>
  onEveryBlock$.pipe(() => fromPromise(skyUsdsStakeDetails({ mkrPrice })))
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1ec5453 and 8fe2395.

Files selected for processing (6)
  • blockchain/better-calls/sky.ts (3 hunks)
  • features/sky/components/stake/SkyStakePositionView.tsx (3 hunks)
  • handlers/portfolio/positions/handlers/sky/index.ts (2 hunks)
  • handlers/product-hub/update-handlers/sky/skyHandler.ts (3 hunks)
  • helpers/context/ProductContext.ts (1 hunks)
  • pages/earn/srr/[wallet].tsx (4 hunks)
Additional comments not posted (11)
handlers/portfolio/positions/handlers/sky/index.ts (4)

9-9: LGTM: Function signature updated correctly.

The skyPositionsHandler function signature has been updated to include the prices parameter, which is used later in the function to access price data.

To ensure all calls to this function have been updated, please run the following script:

#!/bin/bash
# Description: Verify all calls to skyPositionsHandler include the prices parameter

# Test: Search for calls to skyPositionsHandler
rg --type typescript -A 5 'skyPositionsHandler\('

14-14: LGTM: APY calculation and formatting updated.

The changes in the function body look good:

  1. mkrPrice is now passed as a BigNumber instance using prices.MKR.
  2. APY formatting now uses formatDecimalAsPercent instead of formatPercent.

These updates should provide more accurate APY calculations and formatting.

To ensure these changes produce the expected results, please:

  1. Add unit tests for the skyPositionsHandler function, focusing on the APY calculation and formatting.
  2. Perform integration tests to verify the correct display of APY values in the UI.

Run the following script to check for existing tests:

#!/bin/bash
# Description: Check for existing tests for skyPositionsHandler

# Test: Search for test files related to skyPositionsHandler
fd -e test.ts -e spec.ts | xargs rg 'describe.*skyPositionsHandler'

If no tests are found, consider adding them to ensure the correctness of the APY calculations and formatting.

Also applies to: 35-35


Line range hint 1-52: Summary: APY calculations for SKY have been successfully updated.

The changes in this file align well with the PR objectives. The skyPositionsHandler function has been updated to:

  1. Accept a prices parameter for accessing price data.
  2. Use BigNumber for mkrPrice calculation.
  3. Implement a new APY formatting method.

These modifications should improve the accuracy of APY metrics for the SKY asset across various components of the application.

To ensure the changes are fully integrated and functioning as expected:

  1. Verify that all components using skyPositionsHandler (portfolio view, product hub, and position page) are updated to pass the required prices parameter.
  2. Conduct end-to-end tests to confirm the correct display of updated APY values in the UI.
  3. Monitor the production environment after deployment to ensure there are no unexpected issues with APY calculations or display.

Run the following script to identify components that might need updates:

#!/bin/bash
# Description: Find components that might need updates due to skyPositionsHandler changes

# Test: Search for files importing skyPositionsHandler
rg --type typescript 'import.*skyPositionsHandler'

Review the identified files to ensure they're correctly using the updated skyPositionsHandler.


6-6: LGTM: Import statement updated correctly.

The import statement has been updated to use formatDecimalAsPercent instead of formatPercent, which aligns with the changes in APY formatting later in the code.

To ensure the new formatter function is correctly implemented, please run the following script:

Verification successful

LGTM: Verified implementation of formatDecimalAsPercent.

The function formatDecimalAsPercent is correctly implemented in helpers/formatters/format.ts, and the import statement in handlers/portfolio/positions/handlers/sky/index.ts accurately references this function.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of formatDecimalAsPercent

# Test: Search for the implementation of formatDecimalAsPercent
rg --type typescript -A 10 'export function formatDecimalAsPercent'

Length of output: 181


Script:

#!/bin/bash
# Description: Verify the implementation of formatDecimalAsPercent

# Test: Search for the implementation of formatDecimalAsPercent with corrected file type
rg --type ts -A 10 'export function formatDecimalAsPercent'

Length of output: 642

handlers/product-hub/update-handlers/sky/skyHandler.ts (4)

4-4: LGTM: Import statement for Tickers type

The addition of the import statement for the Tickers type is appropriate and consistent with the changes made to the function signatures in this file.


12-15: LGTM: Updated getSkyData function signature

The addition of the tickers parameter to the getSkyData function signature is appropriate and consistent with the changes made within the function body. The return type remains unchanged, which maintains consistency with the existing codebase.


46-47: LGTM: Updated default export function

The changes to the default export function are appropriate and consistent with the updates made to the getSkyData function. The addition of the tickers parameter and its propagation to the getSkyData function call ensures that the necessary data is available throughout the execution flow.


Line range hint 17-34: Verify the impact of replacing 'fee' with 'weeklyNetApy'

The changes to the getSkyData function look good overall. The use of tickers to get the mkrPrice is consistent with the function signature change, and the fallback option for mkrPrice is a good practice.

However, the replacement of fee with weeklyNetApy in the return structure might affect other parts of the codebase that expect the fee property. Please ensure that all consumers of this data are updated accordingly.

To verify the impact of this change, you can run the following script:

This will help identify any potential areas that need to be updated due to this change.

Verification successful

Verified: No external usages of 'fee' found

The replacement of fee with weeklyNetApy in the getSkyData function has been successfully verified. No external usages of the fee property from skyHandler.ts were found in the codebase, ensuring that this change does not impact other parts of the application.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usages of 'fee' property from skyHandler
rg --type typescript -g '!**/skyHandler.ts' 'fee.*skyHandler'

Length of output: 98


Script:

#!/bin/bash
# Description: Search for usages of 'fee' property from skyHandler
rg --type ts -g '!**/skyHandler.ts' 'fee.*skyHandler'

Length of output: 55

features/sky/components/stake/SkyStakePositionView.tsx (1)

Line range hint 1-342: Overall assessment: Changes look good and align with PR objectives.

The modifications to update APY calculations for SKY have been implemented correctly. The changes are focused and maintain good code quality. Here's a summary of the key points:

  1. The skyStakeData type has been updated to use apy instead of rewardRate.
  2. The display of the APY has been updated to use formatDecimalAsPercent.

These changes improve the accuracy and clarity of the APY representation in the Sky Stake Position View.

pages/earn/srr/[wallet].tsx (2)

33-35: Updated state property to 'apy'

The tempSkyStakeData state now includes an apy property. This aligns with the shift from using rewardRate to apy, as per the PR objectives.


68-70: State update condition correctly reflects 'apy'

The useEffect condition now compares skyStakeData.apy with tempSkyStakeData?.apy, which is consistent with the change from rewardRate to apy.

blockchain/better-calls/sky.ts Show resolved Hide resolved
blockchain/better-calls/sky.ts Show resolved Hide resolved
blockchain/better-calls/sky.ts Show resolved Hide resolved
blockchain/better-calls/sky.ts Show resolved Hide resolved
pages/earn/srr/[wallet].tsx Show resolved Hide resolved
pages/earn/srr/[wallet].tsx Show resolved Hide resolved
@marcinciarka marcinciarka merged commit c718669 into dev Sep 23, 2024
25 of 26 checks passed
@marcinciarka marcinciarka deleted the marcinciarka/sky-proper-apy branch September 23, 2024 15:07
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