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(evm): clean up EVM module address #1989

Merged
merged 2 commits into from
Aug 8, 2024

Conversation

k-yang
Copy link
Member

@k-yang k-yang commented Aug 8, 2024

Purpose / Abstract

Simplifies the EVM module address initialization

Summary by CodeRabbit

  • New Features

    • Updated the handling of wei units to utilize the atto denomination, clarifying that 1 ether equals 1 NIBI.
    • Introduced a new constraint for transactions, restricting amounts to micronibi (unibi) only.
  • Bug Fixes

    • Adjusted error messages related to ERC20 token transfers and minting to align with the updated module address references.
  • Refactor

    • Streamlined access to the EVM module address by replacing method calls with constant references throughout the codebase, enhancing performance and readability.

Copy link
Contributor

coderabbitai bot commented Aug 8, 2024

Walkthrough

The recent changes in the Nibiru project introduce a new feature for the Ethereum Virtual Machine (EVM), specifically utilizing the atto denomination for wei units. This means 1 NIBI is treated as equivalent to 1 ether, facilitating clearer transaction processes for clients. Additionally, there has been a refactoring of the EVM module address handling, shifting from function calls to constant references, enhancing code readability and performance.

Changes

Files Change Summary
x/evm/const.go, x/evm/evm_test.go Refactored module address handling; replaced function call ModuleAddressEVM() with constant EVM_MODULE_ADDRESS.
x/evm/keeper/erc20.go, x/evm/keeper/erc20_test.go, x/evm/keeper/funtoken_from_coin.go, x/evm/keeper/msg_server.go, x/evm/precompile/funtoken.go, x/evm/precompile/funtoken_test.go Updated references to module address across multiple functions to use EVM_MODULE_ADDRESS constant instead of function calls.

Possibly related issues

🐇 Hop along with joy, so swift and spry,
In the code garden, we dance and fly.
With NIBI as ether, our path is bright,
Constantly shining, like stars at night.
Code's easy and clear, no more fuss,
Let's celebrate change, come join us! 🎉


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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@k-yang k-yang self-assigned this Aug 8, 2024
@k-yang k-yang added the x: evm Relates to Nibiru EVM or the EVM Module label Aug 8, 2024
@k-yang k-yang marked this pull request as ready for review August 8, 2024 00:08
@k-yang k-yang requested a review from a team as a code owner August 8, 2024 00:08
@k-yang k-yang enabled auto-merge (squash) August 8, 2024 00:08
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d71d67d and 8e643b3.

Files selected for processing (9)
  • CHANGELOG.md (1 hunks)
  • x/evm/const.go (1 hunks)
  • x/evm/evm_test.go (1 hunks)
  • x/evm/keeper/erc20.go (3 hunks)
  • x/evm/keeper/erc20_test.go (2 hunks)
  • x/evm/keeper/funtoken_from_coin.go (1 hunks)
  • x/evm/keeper/msg_server.go (1 hunks)
  • x/evm/precompile/funtoken.go (3 hunks)
  • x/evm/precompile/funtoken_test.go (2 hunks)
Files skipped from review due to trivial changes (4)
  • x/evm/evm_test.go
  • x/evm/keeper/erc20.go
  • x/evm/keeper/erc20_test.go
  • x/evm/precompile/funtoken_test.go
Additional comments not posted (6)
x/evm/keeper/funtoken_from_coin.go (1)

83-83: Use of Constant Improves Readability and Performance

Replacing the function call evm.ModuleAddressEVM() with the constant evm.EVM_MODULE_ADDRESS improves readability and potentially enhances performance by eliminating the function call overhead. This change is well-aligned with the refactoring goals.

x/evm/const.go (1)

79-83: Simplified Initialization of EVM Module Address

The introduction of the constant EVM_MODULE_ADDRESS and the removal of the lazy initialization pattern streamline the code. This change enhances clarity and reduces complexity by ensuring the module address is initialized once and is immediately available. This approach also minimizes the risk of accessing an uninitialized address.

x/evm/precompile/funtoken.go (1)

Line range hint 156-187: Consistent Use of Constant for EVM Module Address

The replacement of evm.ModuleAddressEVM() with evm.EVM_MODULE_ADDRESS across multiple instances in the bankSend function aligns with the refactoring goals. This change improves readability and potentially enhances performance by reducing function call overhead. The error messages have been updated accordingly, maintaining their informativeness and accuracy.

x/evm/keeper/msg_server.go (1)

615-615: Simplify module address access.

The change from evm.ModuleAddressEVM() to evm.EVM_MODULE_ADDRESS simplifies the code and may improve performance by reducing function call overhead.

Ensure that evm.EVM_MODULE_ADDRESS is correctly defined and used consistently across the codebase.

Verification successful

Consistent use of EVM_MODULE_ADDRESS verified.

The constant evm.EVM_MODULE_ADDRESS is correctly defined and consistently used across the codebase. This change simplifies the code and is correctly implemented.

  • Definition found in x/evm/const.go.
  • Consistent usage in files like x/evm/keeper/msg_server.go, x/evm/keeper/erc20.go, and others.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition and usage of `evm.EVM_MODULE_ADDRESS`.

# Test: Search for the constant definition. Expect: A single definition.
rg --type go --word-regexp 'EVM_MODULE_ADDRESS'

# Test: Search for all occurrences of `EVM_MODULE_ADDRESS`. Expect: Consistent usage across the codebase.
rg --type go --word-regexp 'EVM_MODULE_ADDRESS'

Length of output: 2221

CHANGELOG.md (2)

103-103: Verify the simplification of the EVM module address.

Ensure that the changelog entry accurately reflects the simplification made in the codebase regarding the EVM module address.


101-101: Verify the accuracy of the denomination changes.

Ensure that the changelog entry accurately reflects the changes made in the codebase regarding the atto denomination for wei units and the constraints for NIBI, unibi, and wei.

Copy link

codecov bot commented Aug 8, 2024

Codecov Report

Attention: Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.

Project coverage is 65.75%. Comparing base (d71d67d) to head (8e643b3).

Files Patch % Lines
x/evm/precompile/funtoken.go 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1989      +/-   ##
==========================================
- Coverage   65.76%   65.75%   -0.01%     
==========================================
  Files         261      261              
  Lines       16475    16471       -4     
==========================================
- Hits        10834    10830       -4     
  Misses       4837     4837              
  Partials      804      804              
Files Coverage Δ
x/evm/const.go 80.95% <100.00%> (-3.05%) ⬇️
x/evm/keeper/erc20.go 82.05% <100.00%> (ø)
x/evm/keeper/funtoken_from_coin.go 75.51% <100.00%> (ø)
x/evm/keeper/msg_server.go 73.55% <100.00%> (ø)
x/evm/precompile/funtoken.go 54.83% <50.00%> (ø)

@k-yang k-yang merged commit be07667 into main Aug 8, 2024
20 checks passed
@k-yang k-yang deleted the refactor/evm/evm-module-address branch August 8, 2024 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
x: evm Relates to Nibiru EVM or the EVM Module
Projects
Status: ✅ Completed
Development

Successfully merging this pull request may close these issues.

None yet

2 participants