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): Deduct a fee during the creation of a FunToken mapping. Implemented by `deductCreateFunTokenFee` inside of the `eth.evm.v1.MsgCreateFunToken` transaction. #1963

Closed Unique-Divine closed 3 months ago

Unique-Divine commented 3 months ago

Purpose / Abstract

  1. Completes a TODO comment inside the "eth.evm.v1.MsgCreateFunToken" transaction
  2. Organizes the code in the "erc20.go" file more since the file was becoming quite large. Now, the functionality specific to FunToken creation is in "funtoken_from_erc20.go" and "funtoken_from_coin.go", while the ERC20 call functions live inside "erc20.go".

Part of #1898 and #1836

Summary by CodeRabbit

coderabbitai[bot] commented 3 months ago

Walkthrough

In a significant update to the Nibiru project, the Ethereum Virtual Machine (EVM) functionalities have been enhanced with new fee deduction methods for FunToken creation and several updates to ERC20 token management. Key changes include the introduction of deductCreateFunTokenFee, modifications to contract and transaction parameters, and improved testing for fee coverage. Additionally, the ERC20 minting and burning processes have been restructured, and various improvements have been made to comments, imports, and error handling.

Changes

Files/Paths Change Summaries
CHANGELOG.md Documented new feature for fee deduction during FunToken creation.
proto/eth/evm/v1/evm.proto Added fee deduction field and updated comments for contract-related parameters.
proto/eth/evm/v1/tx.proto Updated MsgUpdateParams message field declaration.
x/evm/embeds/ERC20Minter.sol Replaced MINTER_ROLE with "owner" role and updated related functionality and comments.
x/evm/embeds/ERC20MinterCompiled.json Renamed burnCoins function to burnFromAuthority.
x/evm/errors.go Added ErrOwnable error constant.
x/evm/evmtest/erc20.go Updated function signature and added logic to fund accounts before creating tokens.
x/evm/evmtest/eth_test.go Modified AssertERC20BalanceEqual function call.
x/evm/keeper/erc20.go Replaced FindERC20Metadata with ERC20 and added ERC20 methods like Mint, Transfer, etc.
x/evm/keeper/erc20_test.go Added functionality for funding accounts for fees before operations.
x/evm/keeper/funtoken_from_coin.go Added comment for validation requirements in CreateFunTokenFromCoin.
x/evm/keeper/funtoken_from_erc20.go Introduced methods for creating FunToken from ERC20 and finding ERC20 metadata.
x/evm/keeper/msg_server.go Updated CreateFunToken to include fee deduction logic and added related functions.
x/evm/keeper/precompiles.go Removed AddEVMExtensions function and related imports.
x/evm/params.go Added imports, replaced constant value, and introduced CreateFuntokenFee parameter.
x/evm/precompile/funtoken.go Updated function call from OnStart to OnRunStart.
x/evm/precompile/precompile.go Renamed function OnStart to OnRunStart.
x/common/testutil/testnetwork/network.go Increased maxRetries value for validator stoppage check.
x/common/testutil/testnetwork/validator_node.go Added error logging for gRPC web server closure.

Poem

In the realm of code so vast, FunTokens now have fees amassed. ERC20 tokens reshaped anew, Mint and burn with ease, it's true. Nibiru's path, ever bright, In a coder's heart, pure delight.


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 83.89831% with 19 lines in your changes missing coverage. Please review.

Project coverage is 65.91%. Comparing base (187ad82) to head (2c8f323). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1963 +/- ## ========================================== + Coverage 65.64% 65.91% +0.27% ========================================== Files 257 258 +1 Lines 16434 16397 -37 ========================================== + Hits 10788 10808 +20 + Misses 4841 4780 -61 - Partials 805 809 +4 ``` | [Files](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1963?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain) | Coverage Δ | | |---|---|---| | [x/common/testutil/testnetwork/network.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1963?src=pr&el=tree&filepath=x%2Fcommon%2Ftestutil%2Ftestnetwork%2Fnetwork.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-eC9jb21tb24vdGVzdHV0aWwvdGVzdG5ldHdvcmsvbmV0d29yay5nbw==) | `74.43% <100.00%> (ø)` | | | [x/evm/errors.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1963?src=pr&el=tree&filepath=x%2Fevm%2Ferrors.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-eC9ldm0vZXJyb3JzLmdv) | `0.00% <ø> (ø)` | | | [x/evm/evmtest/erc20.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1963?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==) | `86.79% <100.00%> (+2.00%)` | :arrow_up: | | [x/evm/keeper/funtoken\_from\_coin.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1963?src=pr&el=tree&filepath=x%2Fevm%2Fkeeper%2Ffuntoken_from_coin.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-eC9ldm0va2VlcGVyL2Z1bnRva2VuX2Zyb21fY29pbi5nbw==) | `75.51% <ø> (ø)` | | | [x/evm/keeper/precompiles.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1963?src=pr&el=tree&filepath=x%2Fevm%2Fkeeper%2Fprecompiles.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-eC9ldm0va2VlcGVyL3ByZWNvbXBpbGVzLmdv) | `65.21% <ø> (+24.67%)` | :arrow_up: | | [x/evm/params.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1963?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) | `35.63% <100.00%> (+4.05%)` | :arrow_up: | | [x/evm/precompile/funtoken.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1963?src=pr&el=tree&filepath=x%2Fevm%2Fprecompile%2Ffuntoken.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-eC9ldm0vcHJlY29tcGlsZS9mdW50b2tlbi5nbw==) | `54.83% <100.00%> (ø)` | | | [x/evm/precompile/precompile.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1963?src=pr&el=tree&filepath=x%2Fevm%2Fprecompile%2Fprecompile.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-eC9ldm0vcHJlY29tcGlsZS9wcmVjb21waWxlLmdv) | `76.00% <ø> (ø)` | | | [x/common/testutil/testnetwork/validator\_node.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1963?src=pr&el=tree&filepath=x%2Fcommon%2Ftestutil%2Ftestnetwork%2Fvalidator_node.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-eC9jb21tb24vdGVzdHV0aWwvdGVzdG5ldHdvcmsvdmFsaWRhdG9yX25vZGUuZ28=) | `75.36% <50.00%> (-2.25%)` | :arrow_down: | | [x/evm/keeper/erc20.go](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1963?src=pr&el=tree&filepath=x%2Fevm%2Fkeeper%2Ferc20.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain#diff-eC9ldm0va2VlcGVyL2VyYzIwLmdv) | `82.05% <86.95%> (-1.13%)` | :arrow_down: | | ... and [2 more](https://app.codecov.io/gh/NibiruChain/nibiru/pull/1963?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NibiruChain) | |