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

feat: evm gas refund #1211

Merged
merged 1 commit into from
Jan 29, 2025
Merged

feat: evm gas refund #1211

merged 1 commit into from
Jan 29, 2025

Conversation

songwongtp
Copy link
Collaborator

@songwongtp songwongtp commented Jan 29, 2025

Summary by CodeRabbit

  • New Features

    • Implemented EVM gas refund logic
    • Added gas refund percentage display in transaction details
  • Improvements

    • Enhanced transaction fee calculation to include gas refund ratio
    • Updated UI components to support gas refund information
  • Technical Updates

    • Added new validation schema for EVM parameters
    • Introduced new utility function for computing Cosmos fees

Copy link

vercel bot commented Jan 29, 2025

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

Name Status Preview Comments Updated (UTC)
celatone-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 29, 2025 6:55am
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
celatone-frontend-main ⬜️ Ignored (Inspect) Jan 29, 2025 6:55am
initia-celatone-frontend ⬜️ Ignored (Inspect) Jan 29, 2025 6:55am
neutron-celatone-frontend ⬜️ Ignored (Inspect) Jan 29, 2025 6:55am
osmosis-celatone-frontend ⬜️ Ignored (Inspect) Jan 29, 2025 6:55am
sei-celatone-frontend ⬜️ Ignored (Inspect) Jan 29, 2025 6:55am
terra-celatone-frontend ⬜️ Ignored (Inspect) Jan 29, 2025 6:55am

Copy link

coderabbitai bot commented Jan 29, 2025

Walkthrough

This pull request implements EVM gas refund logic across multiple components and services. The changes introduce a new gasRefundRatio property to various interfaces and components, enabling the calculation and display of gas refund percentages in transaction details. The modifications span several files, including data services, utility functions, and UI components, to support the new gas refund feature comprehensively.

Changes

File Change Summary
CHANGELOG.md Added feature entry for EVM gas refund logic
src/lib/pages/evm-tx-details/components/EvmTxGasReceipt.tsx Added gas refund percentage display using formatPrettyPercent
src/lib/pages/evm-tx-details/data.ts Added gasRefundRatio to GasInfo interface and updated gas calculation logic
src/lib/pages/tx-details/components/TxInfo.tsx Updated to include gasRefundRatio in props and display
src/lib/pages/tx-details/components/TxInfoMobile.tsx Added gasRefundRatio to props and display logic
src/lib/pages/tx-details/index.tsx Integrated EVM params fetching and gasRefundRatio
src/lib/services/types/evm/params.ts Added gas_refund_ratio to EVM params schema
src/lib/utils/fee.ts Introduced computeCosmosFee function to handle gas refund calculations

Sequence Diagram

sequenceDiagram
    participant User
    participant TxDetailsPage
    participant EVMService
    participant FeeCalculator

    User->>TxDetailsPage: View Transaction Details
    TxDetailsPage->>EVMService: Fetch EVM Params
    EVMService-->>TxDetailsPage: Return Params with gasRefundRatio
    TxDetailsPage->>FeeCalculator: Compute Fee with gasRefundRatio
    FeeCalculator-->>TxDetailsPage: Calculate Adjusted Fee
    TxDetailsPage->>User: Display Transaction Details with Gas Refund
Loading

Possibly related PRs

Suggested reviewers

  • evilpeach

Poem

🐰 Gas refunds, oh what a treat!
Ethereum's logic now complete
Percentages dancing with glee
Transactions flow more efficiently
A rabbit's code hops with delight! 🚀

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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

🧹 Nitpick comments (7)
src/lib/pages/tx-details/components/TxInfo.tsx (1)

76-80: Consider adding a tooltip to explain gas refund.

The gas refund percentage display could benefit from a tooltip explaining how it affects the final transaction fee.

       {gasRefundRatio && (
-        <LabelText label="Gas Refund Percentage">
+        <LabelText 
+          label="Gas Refund Percentage"
+          tooltip="Percentage of unused gas that will be refunded, reducing the final transaction fee"
+        >
           {`${formatPrettyPercent(gasRefundRatio, 2, true)}`}
         </LabelText>
       )}
src/lib/pages/tx-details/components/TxInfoMobile.tsx (1)

85-89: Consider adding a tooltip to explain gas refund (mobile).

For consistency with the desktop version, consider adding a tooltip here as well.

       {gasRefundRatio && (
-        <LabelText flex={1} label="Gas Refund Percentage">
+        <LabelText 
+          flex={1}
+          label="Gas Refund Percentage"
+          tooltip="Percentage of unused gas that will be refunded, reducing the final transaction fee"
+        >
           {`${formatPrettyPercent(gasRefundRatio, 2, true)}`}
         </LabelText>
       )}
src/lib/pages/evm-tx-details/data.ts (1)

54-56: Ensure safe type conversion for gasRefundRatio.

The fallback to 0 using type assertion might hide potential type issues. Consider using a more explicit conversion.

-  const gasRefundRatio =
-    evmParams?.params.gasRefundRatio ?? (0 as Ratio<number>);
+  const gasRefundRatio: Ratio<number> =
+    evmParams?.params.gasRefundRatio ?? 0;
src/lib/services/evm/index.ts (1)

30-33: Consider using a custom error type for EVM-related errors.

Instead of using generic Error, create a custom error type for better error handling and type safety.

+class EvmError extends Error {
+  constructor(hook: string) {
+    super(`EVM is not enabled (${hook})`);
+    this.name = 'EvmError';
+  }
+}

-      if (!evm.enabled) throw new Error("EVM is not enabled (useEvmParams)");
+      if (!evm.enabled) throw new EvmError("useEvmParams");
src/lib/pages/evm-tx-details/components/EvmTxGasReceipt.tsx (1)

25-41: Consider adding aria-labels for better accessibility.

The grid layout should have appropriate ARIA attributes for screen readers.

-      <SimpleGrid columns={{ base: 2, md: 1 }} gap={4}>
+      <SimpleGrid 
+        columns={{ base: 2, md: 1 }} 
+        gap={4}
+        role="group"
+        aria-label="Transaction gas details">
src/lib/pages/tx-details/index.tsx (1)

77-83: Consider memoizing child components for better performance.

The gas refund ratio prop updates might cause unnecessary re-renders.

+const MemoizedTxInfoMobile = memo(TxInfoMobile);
+const MemoizedTxInfo = memo(TxInfo);

-            <TxInfoMobile txData={data} gasRefundRatio={gasRefundRatio} />
+            <MemoizedTxInfoMobile txData={data} gasRefundRatio={gasRefundRatio} />

-              <TxInfo txData={data} gasRefundRatio={gasRefundRatio} />
+              <MemoizedTxInfo txData={data} gasRefundRatio={gasRefundRatio} />
CHANGELOG.md (1)

42-42: Consider adding more details about the EVM gas refund feature.

While the entry correctly follows the changelog format, it would be helpful to provide more context about:

  • The purpose and benefits of the gas refund feature
  • Any configuration options or requirements
  • Impact on existing functionality

Consider expanding the entry like this:

-[#1211](https://github.com/alleslabs/celatone-frontend/pull/1211) Implement evm gas refund logic
+[#1211](https://github.com/alleslabs/celatone-frontend/pull/1211) Implement EVM gas refund logic - Adds support for calculating and displaying gas refund percentages in transaction details, introduces gasRefundRatio property across components, and enhances the UI to show refund information
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 944d128 and 904c8f7.

📒 Files selected for processing (9)
  • CHANGELOG.md (1 hunks)
  • src/lib/pages/evm-tx-details/components/EvmTxGasReceipt.tsx (2 hunks)
  • src/lib/pages/evm-tx-details/data.ts (5 hunks)
  • src/lib/pages/tx-details/components/TxInfo.tsx (4 hunks)
  • src/lib/pages/tx-details/components/TxInfoMobile.tsx (4 hunks)
  • src/lib/pages/tx-details/index.tsx (4 hunks)
  • src/lib/services/evm/index.ts (1 hunks)
  • src/lib/services/types/evm/params.ts (2 hunks)
  • src/lib/utils/fee.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (9)
src/lib/services/types/evm/params.ts (1)

13-13: LGTM! Clean addition of gas refund ratio parameter.

The implementation follows the schema's naming convention and ensures type safety using zRatio with number coercion.

src/lib/pages/tx-details/components/TxInfo.tsx (1)

20-20: LGTM! Clean implementation of gas refund display.

The changes correctly integrate the gas refund calculation and display:

  • Props interface is properly typed
  • Fee calculation uses the new computeCosmosFee function
  • Gas refund percentage is conditionally rendered

Also applies to: 32-52

src/lib/pages/tx-details/components/TxInfoMobile.tsx (1)

19-19: LGTM! Mobile implementation matches desktop version.

The changes correctly mirror the desktop implementation:

  • Props interface is properly typed
  • Fee calculation uses the new computeCosmosFee function

Also applies to: 33-53

src/lib/pages/evm-tx-details/data.ts (2)

73-75: LGTM: Transaction fee calculation using actual gas amount.

The implementation correctly uses the adjusted gas amount (after refund) for calculating the transaction fee.


68-71: Verify gas refund calculation for edge cases.

The gas refund calculation needs additional validation:

  1. Ensure gasRefund doesn't exceed the total gas used
  2. Handle potential negative values
✅ Verification successful

Gas refund calculation is properly implemented and handles edge cases

The implementation is safe because:

  • Gas refund is limited to unused gas only
  • Refund ratio is controlled by chain parameters
  • Default value of 0 ensures graceful handling when parameters are unavailable
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any existing gas refund validation logic
rg -A 5 "gasRefund" --type ts --type tsx

Length of output: 68


Script:

#!/bin/bash
# Search for gas refund related logic with correct file type
rg -t ts "gasRefund" -B 5 -A 5

# Search specifically for gasRefundRatio to understand how it's defined
rg -t ts "gasRefundRatio" -B 2 -A 2

Length of output: 21769

src/lib/services/evm/index.ts (1)

Line range hint 35-41: LGTM: Query configuration for EVM params.

The query configuration is well-optimized with appropriate caching settings:

  • Infinity stale time for static params
  • No refetch on window focus
  • No retry on mount
src/lib/pages/evm-tx-details/components/EvmTxGasReceipt.tsx (1)

38-40: Verify the precision of gas refund percentage formatting.

The format precision of 2 decimal places might not be sufficient for all cases.

✅ Verification successful

Gas refund percentage formatting precision is appropriate

The current 2 decimal place precision is consistent with other gas-related metrics in the codebase and provides sufficient accuracy for gas refund representation. The implementation includes proper handling of edge cases, including very small percentages.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other percentage formatting instances
rg "formatPrettyPercent.*" --type ts --type tsx

Length of output: 77


Script:

#!/bin/bash
# Search for formatPrettyPercent usage with correct file types
echo "=== Searching in .ts files ==="
rg "formatPrettyPercent" --type ts

echo -e "\n=== Searching in .tsx files ==="
rg "formatPrettyPercent" -g "*.tsx"

echo -e "\n=== Looking for function implementation ==="
ast-grep --pattern 'function formatPrettyPercent($_) {
  $$$
}'

echo -e "\n=== Looking for const implementation ==="
ast-grep --pattern 'const formatPrettyPercent = $_'

Length of output: 16742

src/lib/pages/tx-details/index.tsx (1)

56-61: LGTM: Comprehensive loading state handling.

The loading state correctly accounts for all async operations:

  • Redirect checking
  • Data loading
  • Related EVM transaction fetching
  • EVM params fetching
CHANGELOG.md (1)

Line range hint 1-41: LGTM! Well-structured changelog header.

The header section properly follows the Keep a Changelog format, providing clear guidelines for:

  • Changelog principles and usage
  • Types of changes categorization
  • Version and section linking requirements

@songwongtp songwongtp merged commit 46bc928 into develop Jan 29, 2025
13 checks passed
@songwongtp songwongtp deleted the feat/evm-gas-refund branch January 29, 2025 09:45
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