NibiruChain / nibiru

Nibiru Chain: The breakthrough smart contract platform ushering in the next era of money. Nibiru powers an ecosystem of dApps including perps, RWAs, and more.
https://nibiru.fi
Apache License 2.0
183 stars 201 forks source link

feat(evm): Add precompile to the EVM that enables transfers of ERC20 tokens to "nibi" accounts as Ethereum transactions #1959

Closed Unique-Divine closed 3 months ago

Unique-Divine commented 3 months ago

Purpose / Abstract


Summary by CodeRabbit

coderabbitai[bot] commented 3 months ago

[!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

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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
codecov[bot] commented 3 months ago

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 ```diff @@ 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](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1959?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain) | Coverage Δ | | |---|---|---| | [app/app.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1959?src=pr&el=tree&filepath=app%2Fapp.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-YXBwL2FwcC5nbw==) | `56.49% <100.00%> (+0.57%)` | :arrow_up: | | [app/keepers.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1959?src=pr&el=tree&filepath=app%2Fkeepers.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-YXBwL2tlZXBlcnMuZ28=) | `99.17% <ø> (ø)` | | | [x/evm/keeper/erc20\_from\_coin.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1959?src=pr&el=tree&filepath=x%2Fevm%2Fkeeper%2Ferc20_from_coin.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-eC9ldm0va2VlcGVyL2VyYzIwX2Zyb21fY29pbi5nbw==) | `75.51% <100.00%> (-0.49%)` | :arrow_down: | | [x/evm/keeper/keeper.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1959?src=pr&el=tree&filepath=x%2Fevm%2Fkeeper%2Fkeeper.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-eC9ldm0va2VlcGVyL2tlZXBlci5nbw==) | `75.00% <ø> (ø)` | | | [x/evm/params.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1959?src=pr&el=tree&filepath=x%2Fevm%2Fparams.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-eC9ldm0vcGFyYW1zLmdv) | `31.57% <ø> (+0.65%)` | :arrow_up: | | [x/evm/evmtest/tx.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1959?src=pr&el=tree&filepath=x%2Fevm%2Fevmtest%2Ftx.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-eC9ldm0vZXZtdGVzdC90eC5nbw==) | `0.00% <0.00%> (ø)` | | | [x/evm/embeds/embeds.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1959?src=pr&el=tree&filepath=x%2Fevm%2Fembeds%2Fembeds.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-eC9ldm0vZW1iZWRzL2VtYmVkcy5nbw==) | `67.60% <75.00%> (+1.42%)` | :arrow_up: | | [x/evm/keeper/msg\_server.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1959?src=pr&el=tree&filepath=x%2Fevm%2Fkeeper%2Fmsg_server.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-eC9ldm0va2VlcGVyL21zZ19zZXJ2ZXIuZ28=) | `66.53% <80.00%> (+3.54%)` | :arrow_up: | | [x/common/set/set.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1959?src=pr&el=tree&filepath=x%2Fcommon%2Fset%2Fset.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-eC9jb21tb24vc2V0L3NldC5nbw==) | `86.36% <0.00%> (-13.64%)` | :arrow_down: | | [x/evm/evmtest/erc20.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1959?src=pr&el=tree&filepath=x%2Fevm%2Fevmtest%2Ferc20.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-eC9ldm0vZXZtdGVzdC9lcmMyMC5nbw==) | `0.00% <0.00%> (ø)` | | | ... and [4 more](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1959?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain) | | ... and [2 files with indirect coverage changes](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1959/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain)