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): Add precompile to the EVM that enables transfers of ERC20 tokens to "nibi" accounts as Ethereum transactions #1959

Merged
merged 26 commits into from
Jul 8, 2024

Conversation

Unique-Divine
Copy link
Member

@Unique-Divine Unique-Divine commented Jul 8, 2024

Purpose / Abstract


Summary by CodeRabbit

  • New Features

    • Added support for transfers of ERC20 tokens to "nibi" accounts as regular Ethereum transactions.
    • Introduced a new precompileFunToken contract to handle ERC20 token operations.
  • Bug Fixes

    • Replaced SetupTest function in x/oracle/keeper/app_test.go to improve test reliability.
  • Documentation

    • Added a README.md in the x/evm/precompile directory with instructions for a sample Hardhat project.
  • Chores

    • Added a .gitignore to the x/evm/precompile directory to exclude various development-related files and folders.
  • Refactor

    • Refactored precompiled contract management in the EVM module for improved handling and initialization.
    • Updated function signatures and adjusted keeper logic in app/keepers.go.
  • Tests

    • Introduced test cases for FunToken precompile functionality including ERC20 operations and token transfers.

Squashed commit of the following:

commit 51071dad60c12e02093d92d1311d33b70b81304f
Author: Unique-Divine <[email protected]>
Date:   Mon Jun 10 12:32:00 2024 -0500

    refactor(e2e-evm): unused vars and better type hint

commit 6729b97
Author: Unique-Divine <[email protected]>
Date:   Fri Jun 7 22:46:14 2024 -0500

    test(e2e-evm): more type safety

commit 25c1557
Author: Unique-Divine <[email protected]>
Date:   Fri Jun 7 22:01:21 2024 -0500

    Squashed commit of the following:

    commit 021d161d176112cf24e28780ad64f61155f70ea2
    Author: Unique-Divine <[email protected]>
    Date:   Fri Jun 7 22:00:10 2024 -0500

        test(e2e): (1) Generated smart contract types for ethers. (2) TypeScript support. (3) Formatter

    commit af7e7b3
    Author: Unique-Divine <[email protected]>
    Date:   Fri Jun 7 16:11:45 2024 -0500

        chore: another issue ticket

    commit 36745fd
    Author: Unique-Divine <[email protected]>
    Date:   Fri Jun 7 16:07:20 2024 -0500

        chore: add issue number for TODO comment

    commit 8a76c0e
    Author: Unique-Divine <[email protected]>
    Date:   Fri Jun 7 15:54:07 2024 -0500

        refactor(evm): Remove dead code and document non-EVM ante handler

    commit e4e11df
    Author: Unique-Divine <[email protected]>
    Date:   Fri Jun 7 15:52:38 2024 -0500

        refactor: remove dead code

    commit cad00c0
    Merge: dc5f4dd 359e310
    Author: Unique-Divine <[email protected]>
    Date:   Fri Jun 7 15:41:53 2024 -0500

        Merge branch 'main' into ud/ante-test

    commit dc5f4dd
    Author: Unique-Divine <[email protected]>
    Date:   Fri Jun 7 15:28:53 2024 -0500

        refactor: ante handler and evm cleanup

    commit f73cdc3
    Merge: d3a6ea9 290c372
    Author: Unique-Divine <[email protected]>
    Date:   Wed Jun 5 20:59:39 2024 -0500

        Merge branch 'test/evm-grpc-query' of https://github.com/NibiruChain/nibiru into test/evm-grpc-query

    commit d3a6ea9
    Merge: 376596d 70ee1bf
    Author: Unique-Divine <[email protected]>
    Date:   Wed Jun 5 20:59:30 2024 -0500

        Merge branch 'main' into test/evm-grpc-query

    commit 376596d
    Author: Unique-Divine <[email protected]>
    Date:   Wed Jun 5 20:58:40 2024 -0500

        Squashed commit of the following:

        commit b5687130ff5f3d020a3b14d219fec3a816579c30
        Author: Unique-Divine <[email protected]>
        Date:   Wed Jun 5 20:57:44 2024 -0500

            chore: run tidy

        commit 1f1f938
        Merge: 3e3cc83 bbcc6f8
        Author: Unique-Divine <[email protected]>
        Date:   Wed Jun 5 19:16:30 2024 -0500

            Merge branch 'main' into ud/fix-race-condition

        commit 3e3cc83
        Author: Unique-Divine <[email protected]>
        Date:   Wed Jun 5 19:15:40 2024 -0500

            chore: changelog

        commit 3876ccb
        Author: Unique-Divine <[email protected]>
        Date:   Wed Jun 5 19:04:00 2024 -0500

            refactor: more consistent test names

        commit aaa0a19
        Author: Unique-Divine <[email protected]>
        Date:   Wed Jun 5 18:53:09 2024 -0500

            test(oracle): Fix missing tear down step for oracle integration test

        commit 8c3c35e
        Author: Unique-Divine <[email protected]>
        Date:   Wed Jun 5 17:55:56 2024 -0500

            chore: add test comands to justfile

        commit 4916282
        Merge: 64ed0a2 e7e708d
        Author: Unique-Divine <[email protected]>
        Date:   Fri May 31 09:35:33 2024 -0500

            Merge branch 'main' into ud/fix-race-condition

        commit 64ed0a2
        Author: Unique-Divine <[email protected]>
        Date:   Fri May 31 01:44:55 2024 -0500

            fix(gosdk): tests parallel race condition

    commit 290c372
    Merge: 0d1c894 70ee1bf
    Author: Unique Divine <[email protected]>
    Date:   Wed Jun 5 20:05:19 2024 -0500

        Merge branch 'main' into test/evm-grpc-query

    commit 0d1c894
    Merge: 9170835 ad173e9
    Author: Unique Divine <[email protected]>
    Date:   Wed Jun 5 19:34:38 2024 -0500

        Merge branch 'main' into test/evm-grpc-query

    commit 9170835
    Author: Oleg Nikonychev <[email protected]>
    Date:   Wed Jun 5 13:55:14 2024 +0400

        fix: removed hardcoded gas value in grpc_query test

    commit 4337858
    Author: Oleg Nikonychev <[email protected]>
    Date:   Wed Jun 5 13:14:34 2024 +0400

        chore: refactored eth util methods

    commit 7df84e2
    Merge: 8918498 bbcc6f8
    Author: Oleg Nikonychev <[email protected]>
    Date:   Wed Jun 5 12:23:51 2024 +0400

        chore: resolve conflicts

    commit 8918498
    Merge: 3fd45ce e7e708d
    Author: Oleg Nikonychev <[email protected]>
    Date:   Mon Jun 3 21:56:39 2024 +0400

        Merge branch 'main' into test/evm-grpc-query

    commit 3fd45ce
    Author: Oleg Nikonychev <[email protected]>
    Date:   Mon Jun 3 21:56:23 2024 +0400

        chore: changelog update

    commit 3348876
    Author: Oleg Nikonychev <[email protected]>
    Date:   Mon Jun 3 21:53:54 2024 +0400

        test(evm): grpc_query full coverage
Copy link
Contributor

coderabbitai bot commented Jul 8, 2024

Warning

Review failed

The pull request is closed.

Walkthrough

The changes refactor the Nibiru EVM module to enhance the management and functionality of precompiled contracts. Key elements include the introduction of a FunToken precompile for ERC20 token transfers, new methods in the Keeper struct, removal of the HasCustomPrecompiles function, and the addition of tests for FunToken functionalities. These alterations streamline the process of sending ERC20 tokens to Nibiru base accounts as bank coins.

Changes

File / Group Change Summary
x/evm/keeper/precompiles.go Refactor precompile management by replacing AvailablePrecompiles with PrecompileSet and AddPrecompiles. Update function signatures to use gethcommon.Address.
x/evm/params.go Remove the HasCustomPrecompiles function.
x/evm/precompile/.gitignore Add exclusions for various files and folders related to Hardhat and TypeChain.
x/evm/precompile/README.md Add sample Hardhat project showcasing basic use cases and instructions.
x/evm/precompile/funtoken.go Introduce FunToken precompiled contract for handling ERC20 token transfers to Nibiru sdk.AccAddress as bank coins.
x/evm/precompile/funtoken_test.go Add test cases for the FunToken precompile, including creation, existence checks, ERC20 operations, and token transfers.
x/evm/precompile/precompile.go Add functionality for initializing and managing precompiled contracts, combining Ethereum and Nibiru precompiles.
x/oracle/keeper/app_test.go Change package name to keeper_test and replace WaitForHeight with WaitForNextBlock.
CHANGELOG.md Document the new feature enabling ERC20 transfers to Nibiru accounts as Ethereum transactions.
app/app.go Add import for precompile and initialize/add precompiles to the EvmKeeper.
app/keepers.go Refactor AppKeepers struct to include keepers.PublicKeepers and modify the keepers list.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant NibiruEVM
    participant FunTokenPrecompile
    participant EVM
    participant Bank

    User->>NibiruEVM: Submit EthereumTx (ERC20 transfer)
    NibiruEVM->>FunTokenPrecompile: Invoke FunToken precompile run method
    FunTokenPrecompile->>EVM: Execute contract logic
    EVM->>Bank: Send ERC20 token as Nibiru bank coin
    Bank->>User: Receive confirmation of transfer
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement a way to send ERC20 tokens to a Nibiru base account as bank coins (#1944).
Prerequisite: Requires completing FunToken creation methods (#1941, #1942).

Poem

In the world of code, where bytes transact,
FunTokens bridge, in smart contract act.
From Ethereum realms, to Nibiru's might,
Coins now transfer, guided by code's light.
Precompiles woven, magic unfolds,
ERC20's journey, to new realms it beholds. 🪄


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

@Unique-Divine Unique-Divine added type: enhancement x: evm Relates to Nibiru EVM or the EVM Module labels Jul 8, 2024
Copy link

codecov bot commented Jul 8, 2024

Codecov Report

Attention: Patch coverage is 53.10345% with 136 lines in your changes missing coverage. Please review.

Project coverage is 65.31%. Comparing base (5bc18fe) to head (71f0f4e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1959      +/-   ##
==========================================
- Coverage   65.34%   65.31%   -0.03%     
==========================================
  Files         253      256       +3     
  Lines       16092    16295     +203     
==========================================
+ Hits        10515    10643     +128     
- Misses       4805     4857      +52     
- Partials      772      795      +23     
Files Coverage Δ
app/app.go 56.49% <100.00%> (+0.57%) ⬆️
app/keepers.go 99.17% <ø> (ø)
x/evm/keeper/erc20_from_coin.go 75.51% <100.00%> (-0.49%) ⬇️
x/evm/keeper/keeper.go 75.00% <ø> (ø)
x/evm/params.go 31.57% <ø> (+0.65%) ⬆️
x/evm/evmtest/tx.go 0.00% <0.00%> (ø)
x/evm/embeds/embeds.go 67.60% <75.00%> (+1.42%) ⬆️
x/evm/keeper/msg_server.go 66.53% <80.00%> (+3.54%) ⬆️
x/common/set/set.go 86.36% <0.00%> (-13.64%) ⬇️
x/evm/evmtest/erc20.go 0.00% <0.00%> (ø)
... and 4 more

... and 2 files with indirect coverage changes

@Unique-Divine Unique-Divine changed the title feat(evm): Add precompile to the EVM that enables trasnfers of ERC20 tokens to "nibi" accounts as regular Ethereum transactions feat(evm): Add precompile to the EVM that enables transfers of ERC20 tokens to "nibi" accounts as Ethereum transactions Jul 8, 2024
@Unique-Divine Unique-Divine marked this pull request as ready for review July 8, 2024 20:39
@Unique-Divine Unique-Divine requested a review from a team as a code owner July 8, 2024 20:39
@Unique-Divine Unique-Divine merged commit a5ff022 into main Jul 8, 2024
17 checks passed
@Unique-Divine Unique-Divine deleted the ud/evm-2 branch July 8, 2024 20:45
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
None yet
Development

Successfully merging this pull request may close these issues.

feat(evm): Impl a way to send ERC20 tokens to a Nibiru base account as bank coins using the FunToken mapping
2 participants