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

Implement Taker Fee Burn Mechanism #9022

Closed
wants to merge 9 commits into from

Conversation

VolodymyrBg
Copy link

@VolodymyrBg VolodymyrBg commented Mar 7, 2025

What is the purpose of the change

This PR implements a new burn mechanism for taker fees as requested by the community. Currently, taker fees are distributed between staking rewards and the community pool. This change adds a third option to burn a portion of the taker fees by sending them to a null address, providing a more significant burn mechanism than the existing ProtoRev feature.
Closes #8921

Key changes:

  • Added "burn" field to the TakerFeeDistributionPercentage proto and Go structs
  • Added taker_fees_burned field to TakerFeesTracker
  • Added functions to track burned taker fees in the poolmanager module
  • Created a new TakerFeeBurnName module account for handling non-whitelisted taker fees
  • Updated the fee distribution logic in hooks.go to handle burning of:
    • OSMO taker fees
    • Whitelisted non-OSMO taker fees
    • Non-whitelisted non-OSMO taker fees (with swapping to OSMO first)

Testing and Verifying

This change can be verified as follows:

  • Unit tests can be added to test the burn mechanism by setting a burn percentage in the parameters and verifying tokens are sent to the null address
  • Integration tests can verify that the correct amounts are burned during epoch distribution
  • Manually verified by setting up a local testnet, configuring taker fee distribution params with a burn portion, and verifying the funds are properly sent to the null address

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes?
  • Changelog entry added to Unreleased section of CHANGELOG.md?

Where is the change documented?

  • Specification (x/poolmanager/README.md) - Documentation will be updated to describe the burn mechanism
  • Osmosis documentation site
  • Code comments? - Added comments explaining the burn mechanism implementation
  • N/A

Copy link
Contributor

coderabbitai bot commented Mar 7, 2025

Walkthrough

This pull request introduces changes to support burning of taker fees. A new module account is added in the permissions map, new fields are incorporated in protocol buffer definitions to handle burn percentages and track burned fees, and additional keeper methods facilitate fee tracking and updates. New constants and variables are introduced for tracking and telemetry, and the fee distribution logic has been extended with conditional checks, swapping, and direct burn transfers for both OSMO and non-OSMO fees.

Changes

File(s) Change Summary
app/modules.go Added new entry txfeestypes.TakerFeeBurnName: nil to the moduleAccountPermissions map.
proto/osmosis/.../genesis.proto Added burn field to TakerFeeDistributionPercentage and taker_fees_burned field to TakerFeesTracker messages.
x/poolmanager/protorev.go Introduced methods: GetTakerFeeTrackerForBurn, GetTakerFeeTrackerForBurnByDenom, and UpdateTakerFeeTrackerForBurnByDenom.
x/poolmanager/types/keys.go Added variable KeyTakerFeeBurnProtoRevArray with value []byte{0x0B}.
x/txfees/keeper/hooks.go Updated fee distribution logic to check for non-zero burn amounts and perform conditional transfers to a burn address, including swap logic for non-native tokens.
x/txfees/types/expected_keepers.go Added method UpdateTakerFeeTrackerForBurnByDenom in the PoolManager interface.
x/txfees/types/keys.go Added constant TakerFeeBurnName = "non_native_fee_collector_burn".
x/txfees/types/telemetry.go Added counter metric TakerFeeFailedBurnUpdateMetricName for tracking failed burn updates.

Sequence Diagram(s)

sequenceDiagram
    participant FC as Fee Calculation (hooks)
    participant MA as Taker Fee Module Account
    participant BA as Burn Address
    participant SW as Swap Module (Non-OSMO)

    FC->>MA: Check fee balance & Burn parameter
    alt OSMO fees available
        FC->>MA: Calculate burn amount for OSMO
        FC->>BA: Transfer OSMO coins for burn
        MA-->>FC: Update module account balance
    else Non-OSMO fees
        FC->>MA: Verify fee balance and whitelist status
        alt Denom is whitelisted
            FC->>BA: Execute direct burn transfer for non-OSMO
        else Non-whitelisted denom
            FC->>MA: Track fees intended for burn
            FC->>SW: Initiate swap to OSMO
            SW->>BA: Swap & transfer coins to burn address
        end
    end
Loading

Suggested labels

C:x/txfees, C:x/poolmanager, V:state/breaking

Suggested reviewers

  • czarcas7ic
  • nicolaslara
  • PaddyMc
  • AlpinYukseloglu
  • ValarDragon
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

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: 1

🧹 Nitpick comments (3)
x/txfees/types/expected_keepers.go (1)

57-57: Missing method documentation.

Unlike other similar methods in this interface, UpdateTakerFeeTrackerForBurnByDenom lacks a comment explaining its purpose and behavior. This is inconsistent with the codebase style.

Add a descriptive comment following the pattern of the similar methods:

+ // UpdateTakerFeeTrackerForBurnByDenom updates the taker fee tracker for burn by increasing the amount for a specific denom
 UpdateTakerFeeTrackerForBurnByDenom(ctx sdk.Context, denom string, increasedAmt osmomath.Int) error
x/txfees/keeper/hooks.go (2)

167-200: Non-OSMO burn logic properly differentiates whitelisted vs. non-whitelisted assets.

This approach effectively handles direct burn of whitelisted assets and defers unwhitelisted assets for a later swap. Ensure robust coverage in test cases for edge scenarios (e.g., zero or extremely small amounts, or no liquidity for swap).


262-277: Final burn after swapping non-whitelisted assets is well-structured.

The logic mirrors the earlier direct-burn steps for whitelisted assets but includes the final swap step. Be sure to handle potential failures (e.g., no pool found, partial swap). Logging is already present; consider including the exact reason in logs if available.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0da1096 and df97df0.

⛔ Files ignored due to path filters (1)
  • x/poolmanager/types/genesis.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
📒 Files selected for processing (8)
  • app/modules.go (1 hunks)
  • proto/osmosis/poolmanager/v1beta1/genesis.proto (2 hunks)
  • x/poolmanager/protorev.go (1 hunks)
  • x/poolmanager/types/keys.go (1 hunks)
  • x/txfees/keeper/hooks.go (4 hunks)
  • x/txfees/types/expected_keepers.go (1 hunks)
  • x/txfees/types/keys.go (1 hunks)
  • x/txfees/types/telemetry.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (10)
app/modules.go (1)

137-137: LGTM! Addition of TakerFeeBurnName to moduleAccountPermissions.

The new module account for taker fee burning is correctly added to the permissions map with nil permissions, consistent with other fee collector module accounts.

x/txfees/types/telemetry.go (1)

38-44: LGTM! New telemetry metric for failed burn operations.

The telemetry implementation correctly follows the established pattern for other taker fee metrics, providing appropriate labels for tracking failed burn operations.

x/txfees/types/keys.go (1)

28-31: New module account constant looks consistent and well-documented.

The addition of TakerFeeBurnName aligns with the existing pattern of TakerFeeCommunityPoolName and TakerFeeStakersName. The docstring clearly explains the routing for scenarios where a swap fails, ensuring funds designated for burning remain isolated.

proto/osmosis/poolmanager/v1beta1/genesis.proto (2)

126-131: Ensure total ratio validations for the new 'burn' field.

The new burn field fits well with the existing distribution fields. Consider verifying in downstream logic or validations that staking_rewards + community_pool + burn does not exceed 1 (100%) if there's an expectation for these distributions to be within a bounded ratio.


139-140: Consistent addition of taker_fees_burned field.

This repeated coin field provides clarity in tracking burned fees. Ensure there's robust testing in place to confirm correct accumulation and usage of these coins.

x/poolmanager/protorev.go (3)

46-50: Retrieve burn fees method replicates existing patterns.

This new getter mirrors the approach used for community pool and stakers. Ensure that any routes calling this method handle empty slices gracefully.


52-56: Getter by denom method is consistent with stakers/community versions.

Returning a zero coin when not found is a sound approach. Confirm all error callers handle the returned nil error correctly.


58-61: Fee update method looks correct.

The function properly increases coin amounts for burning. Double-check any inbound negative or zero values in upstream calls to avoid unexpected increases.

x/txfees/keeper/hooks.go (2)

106-129: Burning OSMO taker fees logic is coherent.

The added check for osmoTakerFeeDistribution.Burn and subsequent calculation is straightforward. Sending coins to a fixed burn address is a valid approach for chain-based burns. However, consider verifying the reliability of this "null address" (osmo1qqq...mcn030) in tests or mainnet docs.


239-245: Isolation of non-native, non-whitelisted burn amounts is clear.

Sending coins to TakerFeeBurnName for subsequent swapping is a clean pattern. Check that the associated account is set with the correct permissions to avoid accidental interactions.

Comment on lines +52 to +53
// KeyTakerFeeBurnProtoRevArray defines key to store the taker fee for burn tracker coin array.
KeyTakerFeeBurnProtoRevArray = []byte{0x0B}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential key collision detected.

The new KeyTakerFeeBurnProtoRevArray is using byte value 0x0B, but this same value is already used for KeyTakerFeeShare defined on line 59. This could cause key collisions in storage, potentially leading to data corruption or unexpected behavior.

Consider using a different byte value that is not currently in use, such as 0x0D or higher.

@PaddyMc
Copy link
Collaborator

PaddyMc commented Mar 11, 2025

Thanks for this PR @VolodymyrBg, great work.

We would prefer this work be done in house with proper discussion and designs. I am closing this for now, but this PR will be referenced in the issue.

@PaddyMc PaddyMc closed this Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add optional Taker Fee Burn mechanic for OSMO collection
2 participants