osmosis icon indicating copy to clipboard operation
osmosis copied to clipboard

perf: charge taker fees only once at the end on multi hops / split routes

Open czarcas7ic opened this issue 1 year ago • 2 comments

Closes: #XXX

What is the purpose of the change

We currently charge taker fees at every hop in a multi hop. We can instead just tally the taker fees and charge it once at the very end.

This change does have the slight negative effect of, if someone doesn't have enough for the taker fees on, lets say, the first hop (but enough for the swap itself), the method wont fail early and instead will fail after all hops are complete when the method attempts to charge the user for the taker fees. IMO this is worth the small overhead for the reduced number of swaps and event emissions. Note that this would only happen if someone inputted more than what they have, since the taker fees are taken off the initial input, so this scenario won't be run into in normal circumstances.

czarcas7ic avatar Jun 05 '24 20:06 czarcas7ic

Walkthrough

The update introduces a feature to charge taker fees once at the end of multi-hop/split-route swaps within the Osmosis project, enhancing efficiency. It includes renaming and restructuring functions and tests to support this feature, refining the logic to calculate and charge taker fees. Changes also include updates to the governance parameter, trading pair overrides, a bug fix related to fee charging in smart accounts, and enforced constraints on sub-authenticators.

Changes

File Path Change Summary
CHANGELOG.md Summarized changes including support for charging taker fees, SDK v50 upgrade, and various fixes.
x/poolmanager/msg_server_test.go Adjusted expectedMessageEvents values in tests to reflect the new logic.
x/poolmanager/router.go Introduced methods to handle taker fees, renamed and refactored existing methods.
x/poolmanager/router_test.go Renamed and added test functions to test internal routing logic.
x/poolmanager/taker_fee.go Restructured taker fee functions into separate calculation and charging functions.

Sequence Diagrams

Multi-Hop/Route Swap with Taker Fees

sequenceDiagram
    participant User
    participant Router
    participant TakerFeeModule
    participant Pools

    User->>Router: Initiate Multi-Hop Swap
    Router->>Pools: Perform Swaps
    loop Per Swap
        Pools-->>Router: Return Swap Result
        Router->>Router: Accumulate Taker Fees
    end
    Router->>TakerFeeModule: Charge Accumulated Taker Fees
    TakerFeeModule-->>Router: Confirm Fee Charging
    Router-->>User: Return Final Swap Result

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

coderabbitai[bot] avatar Jun 06 '24 00:06 coderabbitai[bot]

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

github-actions[bot] avatar Jun 25 '24 00:06 github-actions[bot]

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

github-actions[bot] avatar Jul 07 '24 00:07 github-actions[bot]

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

github-actions[bot] avatar Jul 26 '24 00:07 github-actions[bot]

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

github-actions[bot] avatar Aug 04 '24 00:08 github-actions[bot]

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

github-actions[bot] avatar Aug 13 '24 00:08 github-actions[bot]

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

github-actions[bot] avatar Aug 22 '24 00:08 github-actions[bot]

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

github-actions[bot] avatar Aug 31 '24 00:08 github-actions[bot]

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

github-actions[bot] avatar Sep 11 '24 00:09 github-actions[bot]

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

github-actions[bot] avatar Sep 25 '24 00:09 github-actions[bot]

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

github-actions[bot] avatar Oct 14 '24 00:10 github-actions[bot]