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(inflation): add burn method #1823

Merged
merged 4 commits into from
Mar 19, 2024
Merged

feat(inflation): add burn method #1823

merged 4 commits into from
Mar 19, 2024

Conversation

k-yang
Copy link
Member

@k-yang k-yang commented Mar 19, 2024

Purpose / Abstract

Allows x/inflation to burn any coin. We are currently missing this feature on Nibiru Chain.

There are plans to expose it on the native cosmos-sdk x/bank module, but it's not released yet.

Note that it requires adding the authtypes.Burner permission to the inflation module account, since that's the account that receives the coins from the user and burns it.

Summary by CodeRabbit

  • New Features
    • Introduced the ability to burn tokens within the app, enhancing control over token supply.
  • Enhancements
    • Updated permissions for inflation module to include token burning capabilities.
  • Tests
    • Added comprehensive tests for the new token burning functionality, ensuring reliability and performance.

Copy link
Contributor

coderabbitai bot commented Mar 19, 2024

Walkthrough

The recent updates focus on enhancing the inflation module of the Nibiru blockchain application by introducing a token burning capability. This includes adding permissions for burning tokens, introducing new protobuf definitions for the burn functionality, and implementing the burn method across various components. The changes aim to allow users to burn tokens, thereby affecting the token supply and potentially influencing inflation rates.

Changes

Files Change Summary
app/keepers.go Updated permissions for inflationtypes.ModuleName to include authtypes.Burner.
proto/nibiru/inflation/v1/tx.proto Added imports, MsgBurn method, and messages for token burning.
x/inflation/keeper/... Implemented and tested the new Burn method.
x/inflation/types/interfaces.go Added SendCoinsFromAccountToModule method to the BankKeeper interface.
x/inflation/types/msgs.go Updated MsgBurn to implement LegacyMsg interface with additional methods.
CHANGELOG.md Added a new feature related to inflation: a burn method was introduced.
x/inflation/keeper/keeper_test.go Contains test cases for the Burn function in the inflation module.
x/inflation/keeper/msg_server_test.go Added a new test function TestMsgBurn to test the burning functionality.

🐰✨
In the realm of code, where tokens flow,
A change was made, to let some go.
Burn, burn, in the digital fire,
Reducing supply, is what we desire.
With each line of code, carefully spun,
We've added a way, for tokens to be undone. 🌟🔥

  • @coderabbitai 🐇💻

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-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@k-yang k-yang marked this pull request as ready for review March 19, 2024 08:17
@k-yang k-yang requested a review from a team as a code owner March 19, 2024 08:17
@k-yang k-yang enabled auto-merge (squash) March 19, 2024 08:21
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.

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between dbdf02d and 1553012.
Files ignored due to path filters (2)
  • x/inflation/types/tx.pb.go is excluded by: !**/*.pb.go
  • x/inflation/types/tx.pb.gw.go is excluded by: !**/*.pb.gw.go
Files selected for processing (8)
  • app/keepers.go (1 hunks)
  • proto/nibiru/inflation/v1/tx.proto (3 hunks)
  • x/inflation/keeper/keeper.go (1 hunks)
  • x/inflation/keeper/keeper_test.go (1 hunks)
  • x/inflation/keeper/msg_server.go (1 hunks)
  • x/inflation/keeper/msg_server_test.go (1 hunks)
  • x/inflation/types/interfaces.go (1 hunks)
  • x/inflation/types/msgs.go (3 hunks)
Additional comments: 3
x/inflation/keeper/msg_server.go (1)
  • 50-62: The implementation of the Burn method in the msgServer struct correctly unwraps the context, validates the sender address, and calls the Burn method on the keeper. However, there's no explicit validation for the msg.Coin field within this method. While ValidateBasic on the message likely covers this, relying solely on message validation for critical checks can be risky, especially if the message structure or validation logic changes in the future.

Consider adding explicit validation for the msg.Coin field within the Burn method to ensure robustness.

proto/nibiru/inflation/v1/tx.proto (1)
  • 4-28: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [7-75]

The protobuf definitions for the new burn functionality are correctly structured and include all necessary components for the feature. However, it's important to ensure that the cosmos/base/v1beta1/coin.proto import is used consistently across the project to avoid version mismatches or deprecation issues in the future.

Verification successful

The verification process has confirmed that the import statement import "cosmos/base/v1beta1/coin.proto" is used consistently across various protobuf files within the project. This consistency is crucial for maintaining compatibility and avoiding version mismatches or deprecation issues with the cosmos/base/v1beta1/coin.proto file. Therefore, the original review comment regarding the need to ensure consistent use of this import across the project is validated by the evidence gathered from the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that `cosmos/base/v1beta1/coin.proto` is used consistently across all protobuf files.
rg "import \"cosmos/base/v1beta1/coin.proto\"" --type proto

Length of output: 89



Script:

#!/bin/bash
# Verify that `cosmos/base/v1beta1/coin.proto` is used consistently across all protobuf files by including .proto files explicitly in the search.
rg "import \"cosmos/base/v1beta1/coin.proto\"" --glob "*.proto"

Length of output: 1583

app/keepers.go (1)
  • 797-797: The update to include authtypes.Burner permission for inflationtypes.ModuleName is correctly implemented and aligns with the PR's objective to introduce a coin burning feature. This change enables the x/inflation module to burn coins, enhancing the Nibiru Chain's capabilities in managing its monetary policy.

x/inflation/keeper/keeper_test.go Outdated Show resolved Hide resolved
Comment on lines +24 to +26
SendCoinsFromAccountToModule(
ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins,
) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition of SendCoinsFromAccountToModule to the BankKeeper interface is crucial for the burn functionality. However, the method lacks documentation. It's important for interface methods, especially those that are part of public APIs, to have clear, concise documentation explaining their purpose, parameters, and expected behavior.

Add documentation to the SendCoinsFromAccountToModule method to improve code readability and maintainability.

x/inflation/keeper/msg_server_test.go Outdated Show resolved Hide resolved
Comment on lines +93 to +100
func (k Keeper) Burn(ctx sdk.Context, coins sdk.Coins, sender sdk.AccAddress) error {
if err := k.bankKeeper.SendCoinsFromAccountToModule(
ctx, sender, types.ModuleName, coins,
); err != nil {
return err
}

return k.bankKeeper.BurnCoins(ctx, types.ModuleName, coins)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Burn method in the Keeper struct correctly transfers coins from an account to the module before burning them. This method should ensure that the coins are indeed transferred to a "burn" account or somehow marked as burned to prevent their reuse. Additionally, consider adding more detailed logging for auditability, especially for operations like burning coins which are critical to the monetary policy.

Enhance the Burn method with detailed logging to improve traceability and auditability of burn operations.

x/inflation/types/msgs.go Outdated Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 1553012 and 595c976.
Files selected for processing (1)
  • CHANGELOG.md (2 hunks)
Additional comments: 1
CHANGELOG.md (1)
  • 67-67: The documentation of the addition of the burn method to the inflation module is clear and follows the conventions of Keep a Changelog. It's correctly placed under the "State Machine Breaking" section, indicating its impact on the state machine.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 595c976 and 2e99e3f.
Files selected for processing (2)
  • x/inflation/keeper/keeper_test.go (1 hunks)
  • x/inflation/keeper/msg_server_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • x/inflation/keeper/keeper_test.go
  • x/inflation/keeper/msg_server_test.go

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2e99e3f and d91a509.
Files selected for processing (1)
  • x/inflation/types/msgs.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/inflation/types/msgs.go

return err
}

return k.bankKeeper.BurnCoins(ctx, types.ModuleName, coins)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there logging done in the bank keeper so this can be picked up by heart monitor?

Copy link
Member

@Unique-Divine Unique-Divine Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the query of the supply from the bank module

nibid q bank total

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is one thing missing from the tests. They don't check if the total supply response changes after burning

@k-yang k-yang merged commit db4ee51 into main Mar 19, 2024
13 checks passed
@k-yang k-yang deleted the feat/inflation/burn-command branch March 19, 2024 19:35
k-yang added a commit that referenced this pull request Mar 28, 2024
* feat(inflation): add burn method

* Update CHANGELOG.md
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.

3 participants