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-678 | InGivenOut APIs for Cosmwasm pool #606

Merged
merged 5 commits into from
Jan 30, 2025
Merged

BE-678 | InGivenOut APIs for Cosmwasm pool #606

merged 5 commits into from
Jan 30, 2025

Conversation

deividaspetraitis
Copy link
Collaborator

@deividaspetraitis deividaspetraitis commented Jan 27, 2025

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

  • CalculateTokenInByTokenOut
  • ChargeTakerFeeExactOut

Additionally new APIs ( and existing ) were covered with unit tests.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a mock WASM client for testing purposes
    • Enhanced routing capabilities for concentrated and CosmWasm pools
  • Improvements

    • Updated token calculation methods in pool routing
    • Improved error handling for token conversions
  • Technical Updates

    • Refined method signatures for more accurate token processing
    • Added support for transmuter pool calculations

@deividaspetraitis deividaspetraitis self-assigned this Jan 27, 2025
@deividaspetraitis
Copy link
Collaborator Author

Note for reviewer: SonarCloud is complaining since introduced wasm client mock does not have coverage.

@deividaspetraitis deividaspetraitis marked this pull request as ready for review January 27, 2025 12:09
Base automatically changed from BE-677 to v28.x January 28, 2025 07:57
Copy link

Quality Gate Failed Quality Gate failed

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

See analysis details on SonarQube Cloud

Copy link
Contributor

coderabbitai bot commented Jan 28, 2025

Walkthrough

This pull request introduces a new mock WASM client in the domain/mocks package and modifies routing-related methods in pool implementations. The WasmClient mock provides comprehensive testing capabilities for WASM-related queries, with methods for various contract interactions. In the routing layer, changes focus on token calculation methods, particularly for concentrated and CosmWasm pools, updating how token inputs and fees are handled during routing calculations.

Changes

File Change Summary
domain/mocks/wasm_client.go Added new WasmClient struct with multiple mock methods for WASM-related queries, including contract info, state, history, and parameter retrieval
router/usecase/pools/routable_concentrated_pool.go Updated ChargeTakerFeeExactOut method to accept tokenIn instead of tokenOut
router/usecase/pools/routable_cw_pool.go Added CalculateTokenInByTokenOut method, modified ChargeTakerFeeExactOut, and introduced calculateTokenInByTokenOut private method

Sequence Diagram

sequenceDiagram
    participant Router
    participant Pool
    participant WasmContract
    
    Router->>Pool: CalculateTokenInByTokenOut(tokenOut)
    Pool->>WasmContract: Query token input calculation
    WasmContract-->>Pool: Return calculated token input
    Pool-->>Router: Return token input amount
Loading

Possibly related PRs

Suggested reviewers

  • p0mvn

Poem

🐰 Hops of Code, Mocks so Bright
WASM queries taking flight
Routing tokens with such grace
Fees and calculations embrace
Mock client dancing in the light! 🌟

✨ 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: 0

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

184-187: Revise Documentation for Zero Fees

The docstring states “does not charge any fee for transmuter pools,” but the code calls poolmanager.CalcTakerFeeExactOut. If the TakerFee is non-zero, fees will be applied. Either ensure TakerFee is always zero for transmuter pools or update the docstring to clarify how/when fees are actually waived.

domain/mocks/wasm_client.go (1)

1-116: Consider Returning Errors Instead of Panicking

The mocking approach is thorough and flexible. However, panicking on unimplemented methods can make partial testing difficult. Consider returning a descriptive error instead of panicking, to make your tests more flexible and avoid abrupt terminations.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bdcbb21 and fb6a296.

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

88-96: Clarify Transmuter vs. CosmWasm Pool Check

Your docstrings mention errors for non-transmuter pools, yet the code checks only for CosmWasm pool type. Please verify that CosmWasm pool type is strictly the correct indicator for a transmuter pool, or introduce a dedicated transmuter check if they are distinct concepts.


98-116: Validate Sufficient Liquidity Checks

Although the inline comments indicate that no slippage swaps require adequate liquidity, the function defers all checks to the contract query. Confirm the external contract consistently enforces these liquidity constraints, since the docstring suggests local checks for balances but the code relies on remote contract calls.

router/usecase/pools/routable_concentrated_pool.go (1)

342-344: 🛠️ Refactor suggestion

Rename Parameter in “ChargeTakerFeeExactOut”

The method doc references “token out,” but the parameter is tokenIn. This may confuse readers. Either rename the parameter to tokenOut or update the doc to clarify its purpose.

Proposed fix:

-func (r *routableConcentratedPoolImpl) ChargeTakerFeeExactOut(tokenIn sdk.Coin) (tokenOutAfterFee sdk.Coin) {
-   tokenInAfterTakerFee, _ := poolmanager.CalcTakerFeeExactOut(tokenIn, r.GetTakerFee())
-   return tokenInAfterTakerFee
+func (r *routableConcentratedPoolImpl) ChargeTakerFeeExactOut(tokenOut sdk.Coin) (tokenOutAfterFee sdk.Coin) {
+   tokenOutAfterTakerFee, _ := poolmanager.CalcTakerFeeExactOut(tokenOut, r.GetTakerFee())
+   return tokenOutAfterTakerFee
}

Likely invalid or redundant comment.

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.

A bit unsure about the taker fee situation - please double check, lgtm otherwise

Comment on lines +342 to +344
func (r *routableConcentratedPoolImpl) ChargeTakerFeeExactOut(tokenIn sdk.Coin) (tokenOutAfterFee sdk.Coin) {
tokenInAfterTakerFee, _ := poolmanager.CalcTakerFeeExactOut(tokenIn, r.GetTakerFee())
return tokenInAfterTakerFee
Copy link
Member

Choose a reason for hiding this comment

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

Could you please link where this is being called for a CL pool? I'm not seeing where.

I believe the same problem might be present for other pools - please check, create a task, and do a follow-up if applicable

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right, at the moment it is just APIs, there will be a follow up PRs with code calling those, actually I have already started working on this huge PR #607 and will open follow up smaller PRs from it later.

func (r *routableCosmWasmPoolImpl) ChargeTakerFeeExactOut(tokenOut sdk.Coin) (outAmountAfterFee sdk.Coin) {
return sdk.Coin{}
// Returns tokenInAmount and does not charge any fee for transmuter pools.
func (r *routableCosmWasmPoolImpl) ChargeTakerFeeExactOut(tokenIn sdk.Coin) (inAmountAfterFee sdk.Coin) {
Copy link
Member

Choose a reason for hiding this comment

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

Where is this being called?

@deividaspetraitis deividaspetraitis merged commit fb5ce38 into v28.x Jan 30, 2025
8 of 9 checks passed
@deividaspetraitis deividaspetraitis deleted the BE-678 branch January 30, 2025 11:14
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