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

fix: Integrate Morpho issues #6492

Merged
merged 8 commits into from
Jan 13, 2025
Merged

fix: Integrate Morpho issues #6492

merged 8 commits into from
Jan 13, 2025

Conversation

originalix
Copy link
Contributor

@originalix originalix commented Jan 11, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced staking reward calculations with support for multiple token rewards.
    • Added support for USDC staking.
  • Improvements

    • Refined provider name handling for staking protocols.
    • Improved logic for displaying estimated rewards and claimable badges.
    • Added support for Morpho and Lido staking providers.
  • Technical Updates

    • Updated type definitions for staking providers and investments.
    • Introduced new utility functions for provider name and rate management.

These updates improve the flexibility and accuracy of staking-related features across the application.

Copy link

codesandbox bot commented Jan 11, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link
Contributor

coderabbitai bot commented Jan 11, 2025

Walkthrough

The pull request introduces significant updates to the staking functionality across various files. Key changes enhance reward calculations, improve provider name handling, and expand support for staking providers like Lido and Morpho. A new utility module, earnUtils, centralizes provider-related logic, while type definitions are updated to accommodate more detailed staking and investment information. These modifications aim to improve the flexibility and accuracy of staking features.

Changes

File Path Change Summary
packages/kit/src/views/Staking/components/ApproveBaseStake/index.tsx Added ITokenAnnualReward type; enhanced reward calculation logic to support multiple reward types.
packages/kit/src/views/Staking/components/ProtocolDetails/ProviderSection.tsx Added earnUtils import; updated conditions for rendering pool fee.
packages/kit/src/views/Staking/pages/ApproveBaseStake/index.tsx Introduced estReceiveTokenRate; updated provider name and rate handling.
packages/kit/src/views/Staking/pages/Claim/index.tsx Added earnUtils import; modified protocol name retrieval.
packages/kit/src/views/Staking/pages/ClaimOptions/index.tsx Added earnUtils import; updated protocol name assignment.
packages/kit/src/views/Staking/pages/InvestmentDetails/index.tsx Added hasPositiveReward function; improved logic for displaying reward badge.
packages/kit/src/views/Staking/pages/ProtocolDetails/index.tsx Added earnUtils import; updated protocol name retrieval in claim process.
packages/kit/src/views/Staking/pages/Stake/index.tsx Introduced estReceiveTokenRate; expanded checks for providers.
packages/kit/src/views/Staking/pages/Withdraw/index.tsx Added payWithTokenRate; updated provider name and rate handling.
packages/shared/src/utils/earnUtils.ts Added getEarnProviderName utility function.
packages/shared/types/earn/earnProvider.constants.ts Updated isSupportStaking to include USDC.
packages/shared/types/staking.ts Added morphoTokenRate and rewardNum properties.
packages/kit-bg/src/services/ServiceStaking.ts Updated transaction methods to include morphoVault parameter.
packages/kit/src/views/Staking/hooks/useUniversalHooks.ts Added optional morphoVault parameter to relevant hooks.

Sequence Diagram

sequenceDiagram
    participant User
    participant StakingComponent
    participant EarnUtils
    participant Provider

    User->>StakingComponent: Initiate Staking
    StakingComponent->>EarnUtils: Get Provider Name
    EarnUtils-->>StakingComponent: Normalized Provider Name
    StakingComponent->>Provider: Fetch Staking Details
    Provider-->>StakingComponent: Return Staking Info
    StakingComponent->>StakingComponent: Calculate Rewards
    StakingComponent->>User: Display Staking Options
Loading

Finishing Touches

  • 📝 Generate Docstrings (Beta)

🪧 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 or 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.

@originalix originalix enabled auto-merge (squash) January 11, 2025 11:18
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: 10

🔭 Outside diff range comments (1)
packages/kit/src/views/Staking/components/ApproveBaseStake/index.tsx (1)

Line range hint 493-499: Ensure daysSpent is Defined When Used

When passing daysSpent to showEstimateGasAlert, make sure it's defined to prevent potential issues.

Provide a default value if daysSpent is undefined:

onPress={() => {
  showEstimateGasAlert({
    daysConsumed: daysSpent ?? 0,
    estFiatValue: estimateFeeResp.feeFiatValue,
  });
}}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between afef291 and be9c265.

📒 Files selected for processing (12)
  • packages/kit/src/views/Staking/components/ApproveBaseStake/index.tsx (7 hunks)
  • packages/kit/src/views/Staking/components/ProtocolDetails/ProviderSection.tsx (2 hunks)
  • packages/kit/src/views/Staking/pages/ApproveBaseStake/index.tsx (4 hunks)
  • packages/kit/src/views/Staking/pages/Claim/index.tsx (2 hunks)
  • packages/kit/src/views/Staking/pages/ClaimOptions/index.tsx (2 hunks)
  • packages/kit/src/views/Staking/pages/InvestmentDetails/index.tsx (3 hunks)
  • packages/kit/src/views/Staking/pages/ProtocolDetails/index.tsx (2 hunks)
  • packages/kit/src/views/Staking/pages/Stake/index.tsx (4 hunks)
  • packages/kit/src/views/Staking/pages/Withdraw/index.tsx (4 hunks)
  • packages/shared/src/utils/earnUtils.ts (1 hunks)
  • packages/shared/types/earn/earnProvider.constants.ts (1 hunks)
  • packages/shared/types/staking.ts (2 hunks)
🔇 Additional comments (14)
packages/kit/src/views/Staking/components/ApproveBaseStake/index.tsx (2)

264-267: 🧹 Nitpick (assertive)

Implement the TODO for Fiat Value Calculation

There's a TODO to add fiat value for extra rewards. Completing this will provide users with comprehensive reward information.

Would you like assistance in calculating and displaying the fiat value for extra rewards?


349-351: ⚠️ Potential issue

Check for Undefined daySpent Before Comparison

The variable daySpent might be undefined if calcDaysSpent returns undefined. Add a check before comparing it to avoid runtime errors.

Update the condition:

- if (daySpent && daySpent > 5) {
+ if (daySpent !== undefined && daySpent > 5) {

Likely invalid or redundant comment.

packages/shared/types/earn/earnProvider.constants.ts (1)

38-38: Verify USDC Staking Support Throughout the App

You've added 'USDC' to the supported staking symbols. Confirm that all staking functionalities properly support USDC.

Please run the following script to check for USDC staking implementations:

✅ Verification successful

USDC Staking Support Properly Implemented

The codebase shows complete USDC staking support with proper configurations, type definitions, and earn provider implementations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for USDC staking support in the codebase
rg 'USDC' packages/ --type=typescript

Length of output: 72


Script:

#!/bin/bash
# Search for USDC in all files
rg "USDC" packages/

# Search for staking-related files containing USDC
rg -l "staking|earn" packages/ | xargs rg "USDC"

# Look for USDC in configuration files
fd -e ts -e js config packages/ | xargs rg "USDC"

# Search for USDC in earn provider files
fd -e ts "earn.*provider" packages/ | xargs rg "USDC"

Length of output: 12312

packages/kit/src/views/Staking/pages/Claim/index.tsx (1)

52-54: Consistent Use of Provider Name

Good job using earnUtils.getEarnProviderName to standardize the provider name. This ensures consistency across the application.

packages/kit/src/views/Staking/pages/ApproveBaseStake/index.tsx (1)

44-47: Good improvement: Clear labeling for staking actions

Changed from generic 'Unknown' to specific 'Stake' label, improving clarity.

packages/kit/src/views/Staking/pages/Stake/index.tsx (3)

89-91: LGTM! Standardized provider name retrieval.

The change improves consistency by using the centralized earnUtils.getEarnProviderName function.


149-155: LGTM! Enhanced provider type checking.

The condition now properly handles both Lido and Morpho providers for estimated receive information.


159-175: LGTM! Well-structured token rate calculation.

The memoized value properly handles different provider types and includes a safe default.

packages/kit/src/views/Staking/pages/InvestmentDetails/index.tsx (2)

61-72: LGTM! Well-implemented reward check function.

The function safely handles undefined values and uses BigNumber for accurate comparisons.


178-178: LGTM! Enhanced badge visibility logic.

The condition now properly considers both claimable status and positive rewards.

packages/kit/src/views/Staking/pages/ProtocolDetails/index.tsx (1)

203-205: LGTM! Standardized protocol name handling.

The change consistently uses earnUtils.getEarnProviderName for protocol name retrieval.

packages/shared/src/utils/earnUtils.ts (1)

53-53: LGTM! Proper export of the new function.

The function is correctly added to the default export object.

packages/kit/src/views/Staking/pages/ClaimOptions/index.tsx (2)

17-17: Clean import addition!

The earnUtils import follows the project's import organization pattern.


62-64: Good use of centralized provider name handling!

The change standardizes provider name handling through earnUtils.

Let's verify consistent usage across the codebase:

✅ Verification successful

Provider name handling is consistently implemented

All staking-related components use earnUtils.getEarnProviderName for protocol assignment. No inconsistencies found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for direct provider assignments that should use earnUtils
rg -g '*.{ts,tsx}' 'protocol:\s+provider' packages/
# Search for existing earnUtils.getEarnProviderName usage
rg -g '*.{ts,tsx}' 'earnUtils\.getEarnProviderName' packages/

Length of output: 778

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

♻️ Duplicate comments (3)
packages/kit/src/views/Staking/pages/Withdraw/index.tsx (1)

100-116: 🛠️ Refactor suggestion

Extract token rate logic to a shared hook

This token rate logic duplicates the pattern seen elsewhere in the codebase.

As suggested in previous reviews, consider extracting this to a shared hook:

// useProviderTokenRate.ts
export function useProviderTokenRate(provider: IStakeProviderInfo) {
  return useMemo(() => {
    const defaultRate = '1';
    if (earnUtils.isLidoProvider({ providerName: provider.name })) {
      return provider.lidoStTokenRate ?? defaultRate;
    }
    if (earnUtils.isMorphoProvider({ providerName: provider.name })) {
      return provider.morphoTokenRate ?? defaultRate;
    }
    return defaultRate;
  }, [provider]);
}
packages/shared/types/staking.ts (2)

46-46: 🧹 Nitpick (assertive)

Add documentation for morphoTokenRate

The type definition needs documentation for better maintainability.

+ /** Token rate for Morpho protocol, represented as a decimal string */
  morphoTokenRate?: string;

381-381: 🧹 Nitpick (assertive)

Add documentation for rewardNum

The type definition needs documentation for better maintainability.

+ /** Map of token addresses to their reward amounts as decimal strings */
  rewardNum?: Record<string, string>;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be9c265 and d6ca7e5.

📒 Files selected for processing (6)
  • packages/kit-bg/src/services/ServiceStaking.ts (4 hunks)
  • packages/kit/src/views/Staking/hooks/useUniversalHooks.ts (6 hunks)
  • packages/kit/src/views/Staking/pages/ApproveBaseStake/index.tsx (4 hunks)
  • packages/kit/src/views/Staking/pages/Stake/index.tsx (4 hunks)
  • packages/kit/src/views/Staking/pages/Withdraw/index.tsx (4 hunks)
  • packages/shared/types/staking.ts (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: lint (20.x)
🔇 Additional comments (9)
packages/kit/src/views/Staking/pages/ApproveBaseStake/index.tsx (4)

44-47: Good use of utility function for protocol name!

Using earnUtils.getEarnProviderName standardizes protocol name handling across the codebase.


73-79: Clean provider type checking!

The boolean expression clearly handles both Lido and Morpho providers.


83-99: Add type safety for token rates

The token rate logic needs type checking for undefined values.


54-58: 🧹 Nitpick (assertive)

Add type safety for morphoVault

Add type checking to ensure vault property exists when provider is Morpho.

  morphoVault: earnUtils.isMorphoProvider({
    providerName: provider.name,
  })
-   ? provider.vault
+   ? provider.vault ?? undefined
    : undefined,

Likely invalid or redundant comment.

packages/kit/src/views/Staking/pages/Stake/index.tsx (3)

89-91: Consistent use of protocol name utility

Matches the standardization in ApproveBaseStake.


98-102: Type safety needed for morphoVault

Same type safety improvement needed as in ApproveBaseStake.


164-180: Token rate type safety needed

Same type safety concerns as in ApproveBaseStake.

packages/kit/src/views/Staking/pages/Withdraw/index.tsx (2)

51-55: Clean implementation of Morpho vault handling!

The conditional assignment of morphoVault is well-structured and follows best practices.


60-62: Good use of centralized provider name handling!

Using earnUtils.getEarnProviderName ensures consistent provider name handling across the application.

@originalix originalix merged commit 399470c into x Jan 13, 2025
8 checks passed
@originalix originalix deleted the fix/morpho-v3 branch January 13, 2025 01:55
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.

3 participants