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

BE-677 | InGivenOut APIs for Alloyed pool #605

Open
wants to merge 1 commit into
base: v28.x
Choose a base branch
from

Conversation

deividaspetraitis
Copy link
Collaborator

@deividaspetraitis deividaspetraitis commented Jan 24, 2025

This PR implements InGivenOut APIs for Alloyed pool, more specifically following methods:

  • CalculateTokenInByTokenOut
  • ChargeTakerFeeExactOut

New APIs were covered with unit tests. Additionally it updates ChargeTakerFeeExactOut APIs for other pools by renaming parameter from tokenOut to tokenIn since taker fees are calculated always for tokenIn.

Summary by CodeRabbit

  • Refactor

    • Updated method signatures for ChargeTakerFeeExactOut across multiple pool implementations
    • Changed parameter from tokenOut to tokenIn in various pool-related interfaces and structs
    • Added new methods for token calculation in Alloy Transmuter pool
  • New Features

    • Implemented CalculateTokenInByTokenOut method for Alloy Transmuter pool
    • Added CalcTokenInAmt method to support token calculations

These changes appear to be part of a broader refactoring effort to standardize token fee calculation methods across different pool types.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
44.0% Coverage on New Code (required ≥ 50%)

See analysis details on SonarQube Cloud

Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

Walkthrough

The pull request introduces a systematic modification across multiple files in the domain and router packages, focusing on changing the ChargeTakerFeeExactOut method's signature. The primary change involves shifting the method parameter from tokenOut to tokenIn across various pool implementations, including mock, concentrated, orderbook, result, and alloy transmuter pools. Additionally, the alloy transmuter pool implementation introduces new methods for token calculation and enhanced error handling.

Changes

File Change Summary
domain/mocks/pool_mock.go Updated ChargeTakerFeeExactOut method signature from tokenOut to tokenIn
domain/routable_pool.go Modified ChargeTakerFeeExactOut interface method signature
router/usecase/pools/routable_concentrated_pool.go Updated method signature and renamed return variable
router/usecase/pools/routable_cw_alloy_transmuter_pool.go Added CalculateTokenInByTokenOut and CalcTokenInAmt methods, updated ChargeTakerFeeExactOut signature
router/usecase/pools/routable_cw_orderbook_pool.go Updated ChargeTakerFeeExactOut method signature
router/usecase/pools/routable_result_pool.go Updated ChargeTakerFeeExactOut method signature

Sequence Diagram

sequenceDiagram
    participant Caller
    participant Pool
    Caller->>Pool: ChargeTakerFeeExactOut(tokenIn)
    Pool-->>Caller: tokenInAfterFee
Loading

Possibly related PRs

Suggested reviewers

  • p0mvn

Poem

🐰 Hopping through code with glee,
Tokens in, fees set free!
From out to in, we shift the way,
Pools dance to a new ballet 🌈
CodeRabbit's magic, clean and bright! 🚀

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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>, 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. (Beta)
  • @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.

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

🧹 Nitpick comments (2)
router/usecase/pools/routable_cw_alloy_transmuter_pool.go (2)

132-133: Clarify zero-taker-fee behavior in doc comment.
The doc comment says the pool does not charge a fee, but this implementation still calls CalcTakerFeeExactOut. If r.TakerFee is non-zero, a fee is charged. It may be worth clarifying that any fee is zero only if TakerFee is zero.


134-135: Parameter name and method name are conceptually mismatched.
The method is named ChargeTakerFeeExactOut but its parameter is tokenIn. Consider clarifying which side of the swap the fee is calculated upon for consistent semantics.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f4e918c and 996cec0.

⛔ Files ignored due to path filters (1)
  • router/usecase/pools/routable_cw_alloy_transmuter_pool_test.go is excluded by !**/*_test.go
📒 Files selected for processing (6)
  • domain/mocks/pool_mock.go (1 hunks)
  • domain/routable_pool.go (1 hunks)
  • router/usecase/pools/routable_concentrated_pool.go (1 hunks)
  • router/usecase/pools/routable_cw_alloy_transmuter_pool.go (3 hunks)
  • router/usecase/pools/routable_cw_orderbook_pool.go (1 hunks)
  • router/usecase/pools/routable_result_pool.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (5)
router/usecase/pools/routable_cw_alloy_transmuter_pool.go (3)

233-236: Doc comment is correct and well-structured.
The explanation of normalization factors and formula is thorough and matches the code that follows.


237-263: Looks good, recommend boundary tests.
CalcTokenInAmt properly checks zero normalization factors and rate limiters before computing the amount. Consider adding explicit unit tests for edge cases (e.g., zero tokenOut.Amount, maximum tokenOut.Amount) to ensure correctness under boundary conditions.


92-106: Verify correctness of parameter usage.
Inside CalculateTokenInByTokenOut, the call to CalcTokenInAmt(tokenIn, r.TokenOutDenom) passes tokenIn as the first argument, but CalcTokenInAmt expects a tokenOut sdk.Coin. The mismatch in naming can cause confusion or logical errors.

Run the following script to locate all references of CalculateTokenInByTokenOut and confirm they are passing the correct “token out” coin:

domain/routable_pool.go (1)

65-65: Parameter rename aligns with the rest of the PR changes.
Renaming the parameter from tokenOut to tokenIn is consistent with the new design, but the method name ChargeTakerFeeExactOut can be slightly confusing now. If feasible, clarify in the interface doc that “ExactOut” refers to the swap mode, not the parameter name.

domain/mocks/pool_mock.go (1)

204-205: Ensure consistent interpretation of the fee addition.

Here, you’re adding the fee to the original token amount, which is typical for an “exact-out” scenario (the cost to the user is increased). Confirm that the rest of the codebase aligns with this design for exact-out fees.

router/usecase/pools/routable_result_pool.go Show resolved Hide resolved
@@ -224,7 +224,7 @@ func (r *routableConcentratedPoolImpl) ChargeTakerFeeExactIn(tokenIn sdk.Coin) (

// ChargeTakerFee implements domain.RoutablePool.
// Charges the taker fee for the given token out and returns the token out after the fee has been charged.
func (r *routableConcentratedPoolImpl) ChargeTakerFeeExactOut(tokenOut sdk.Coin) (tokenOutAfterFee sdk.Coin) {
func (r *routableConcentratedPoolImpl) ChargeTakerFeeExactOut(tokenIn sdk.Coin) (tokenInAfterFee sdk.Coin) {
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

Implement or remove the placeholder logic.

Currently, this function always returns an empty coin and does not charge the taker fee. If it’s meant to implement exact-out taker fee logic, consider basing it on your mock or adding a dedicated helper, for example:

-	return sdk.Coin{}
+	takerFee := r.TakerFee.Mul(tokenIn.Amount.ToLegacyDec())
+	tokenInAfterFee = tokenIn.Add(sdk.NewCoin(tokenIn.Denom, takerFee.TruncateInt()))
+	return tokenInAfterFee

Committable suggestion skipped: line range outside the PR's diff.

@deividaspetraitis
Copy link
Collaborator Author

Note for reviewer: Sonar is complaining about code coverage since this PR touches a few other places in the code.

Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

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

LGTM

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.

2 participants