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 usdc recurring donation problem #4867

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

MohammadPCh
Copy link
Collaborator

@MohammadPCh MohammadPCh commented Nov 12, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced decimal precision logic for token amounts, ensuring accurate representations.
    • Updated blockchain network configurations for improved handling of token parameters.
  • Bug Fixes

    • Adjusted the decimal precision for the Super USD Coin from 18 to 6, improving calculation accuracy.
  • Chores

    • Added default values for gas preferences in multiple blockchain configurations.

Copy link

vercel bot commented Nov 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
giveth-dapps-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 12, 2024 9:29am

Copy link
Contributor

coderabbitai bot commented Nov 12, 2024

Walkthrough

The changes in this pull request primarily involve updates to the logic for determining decimal precision in the RecurringDonationModal component and modifications to the blockchain network configurations in the production.tsx file. The Item.tsx file now includes a more comprehensive method for selecting decimal precision, while the production.tsx file reflects a change in the decimal precision for the Super USD Coin token and introduces new properties for various blockchain configurations.

Changes

File Path Change Summary
src/components/views/donate/Recurring/RecurringDonationModal/Item.tsx Updated logic for decimal precision in formatUnits calls, adding a fallback to token.decimals.
src/config/production.tsx Changed decimals for Super USD Coin from 18 to 6; added farmStartTimeMS for ZKEVM_CONFIG.GIVPOWER; updated gas preference settings.

Possibly related PRs

  • Main #4340: This PR involves changes to donation-related components, which may indirectly relate to the decimal precision logic in the main PR, as both deal with donation functionalities.
  • fix/recurring donation amount display #4654: This PR modifies how recurring donation amounts are displayed, which is closely related to the changes in decimal precision for formatting donation amounts in the main PR.
  • Merge main into develop #4709: This PR includes changes to donation components, which may have overlapping concerns with the decimal precision adjustments made in the main PR.

Suggested labels

Code Review

Suggested reviewers

  • Meriem-BM
  • lovelgeorge99

Poem

In the fields where tokens play,
Decimal dances lead the way.
With changes made, our paths align,
To donate with precision fine.
Hooray for updates, bright and true,
For every gift, a clearer view! 🐇✨


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

🧹 Outside diff range and nitpick comments (1)
src/components/views/donate/Recurring/RecurringDonationModal/Item.tsx (1)

34-36: Consider extracting decimal precision logic to a utility function.

The decimal precision selection logic is duplicated. Consider extracting it to a reusable utility function to improve maintainability and ensure consistency.

+const getTokenDecimals = (token: IToken) => 
+  token.underlyingToken?.decimals || token.decimals || 18;

 // Then use it in both places:
-formatUnits(
-  amount,
-  token.underlyingToken?.decimals ||
-    token.decimals ||
-    18,
-)
+formatUnits(amount, getTokenDecimals(token))

Also applies to: 52-54

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 02a85a3 and 4194db6.

📒 Files selected for processing (2)
  • src/components/views/donate/Recurring/RecurringDonationModal/Item.tsx (2 hunks)
  • src/config/production.tsx (1 hunks)
🔇 Additional comments (5)
src/components/views/donate/Recurring/RecurringDonationModal/Item.tsx (2)

34-36: LGTM! Verify token decimal handling across different token types.

The additional fallback to token.decimals improves the robustness of decimal precision handling, particularly for tokens like USDC that don't use the standard 18 decimals.

Let's verify the token configurations to ensure we handle all cases correctly:

#!/bin/bash
# Description: Check token decimal configurations across the codebase
# Expected: Find token configurations to verify decimal handling

# Search for token decimal configurations
rg -A 5 "decimals.*[0-9]+" --type typescript

# Search for formatUnits usage to ensure consistent decimal handling
ast-grep --pattern 'formatUnits($_, $decimals)'

52-54: Verify USD calculation accuracy with the new decimal handling.

The decimal precision change is consistent with the token amount display. However, since this affects USD value calculations, we should ensure the price conversion remains accurate across different token decimals.

Let's verify the price calculations:

✅ Verification successful

Based on the search results, I can now verify the decimal precision handling in the USD calculation. The code shows consistent decimal handling across the codebase:

USD calculation is correctly implemented with the new decimal handling

The price calculation is properly implemented with the token's decimal precision:

  • The amount is correctly formatted using formatUnits with the token's decimals (either from underlyingToken?.decimals, token.decimals, or fallback to 18)
  • The USD value is calculated by multiplying the formatted amount with the token price
  • This approach is consistently used across both one-time and recurring donations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check price calculation implementations
# Expected: Find related price conversion logic to verify consistency

# Search for price calculation patterns
rg -B 5 -A 5 "price.*multipliedBy" --type typescript

# Look for other formatUnits usage with price calculations
ast-grep --pattern 'formatUnits($amount, $decimals)'

Length of output: 131


Script:

#!/bin/bash
# Let's try different search patterns to find price calculation logic

# Search for price-related calculations
rg -l "price.*format" 

# Search for formatUnits usage
rg -B 3 -A 3 "formatUnits"

# Search for decimal precision handling
rg -B 2 -A 2 "\.decimals"

# Search specifically in the component directory
rg -B 3 -A 3 "price|formatUnits|decimals" "src/components/views/donate"

Length of output: 99710

src/config/production.tsx (3)

Line range hint 947-949: LGTM! Consistent use of automatic gas configuration.

The empty gasPreference objects with explicit comments across multiple network configurations indicate a deliberate choice to use automatic gas configuration. This is a good practice as it allows for dynamic gas pricing based on network conditions.

Also applies to: 965-967, 983-985, 1001-1003


533-533: LGTM! Decimal precision matches the underlying USDC token.

The decimal precision of 6 for USDCx is correct as it matches the underlying USDC token's decimal precision. This is crucial for accurate token amount calculations in the SuperFluid protocol.

Let's verify the decimal precision consistency across the codebase:

#!/bin/bash
# Description: Verify USDC/USDCx decimal precision consistency across configurations
# Test: Search for USDC/USDCx decimal configurations. Expect: All instances should show 6 decimals

# Search for USDC decimal configurations
echo "Checking USDC decimal configurations:"
rg -B 2 -A 2 "decimals.*[^x]USDC"

# Search for USDCx decimal configurations
echo "Checking USDCx decimal configurations:"
rg -B 2 -A 2 "decimals.*USDCx"

Line range hint 1012-1012: Verify the farming start time configuration.

The farming start time is set to September 3, 2024, 6:00:00 PM. This is a future configuration that will affect when users can start farming GIV tokens on the ZKEVM network.

Let's verify there are no conflicting start times in the codebase:

✅ Verification successful

Based on the search results, I can now generate the final response:

The farming start time configuration for ZKEVM (1725386400000 - September 3, 2024) is unique and doesn't conflict with other farming configurations.

The search results show several farmStartTimeMS configurations across different networks:

  • Gnosis: 1651345200000, 1659625200000
  • Optimism: 1655218800000, 1668691800000
  • Development configs: 1655997000000, 1646306818206, 1685460000000
  • ZKEVM: 1725386400000 (the one we're verifying)

Each network has its own distinct farming start time, and the ZKEVM configuration is properly set for a future date without any conflicts with other network configurations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify farming start time configurations
# Test: Search for farmStartTimeMS configurations. Expect: No conflicting times for ZKEVM farming

# Search for farmStartTimeMS configurations
echo "Checking farming start time configurations:"
rg "farmStartTimeMS.*1725386400000"

# Search for any ZKEVM farming configurations
echo "Checking ZKEVM farming configurations:"
rg -B 5 -A 5 "ZKEVM.*farm.*Time"

Length of output: 240


Script:

#!/bin/bash
# Let's try a different approach to search for farming configurations

# Search for any farming start time configurations
echo "Checking all farming start time configurations:"
rg -i "farmstart.*time"

# Search specifically in config files
echo "Checking config files for farming configurations:"
fd "config" --type f --exec rg -l "farm.*time"

# Search for ZKEVM configurations
echo "Checking ZKEVM configurations:"
rg "ZKEVM_CONFIG" -A 10 -B 10

Length of output: 18540

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant