Skip to content

Consider transmuter with more priority#682

Merged
p0mvn merged 1 commit intov28.xfrom
boss/fix-alloyed-routing
Oct 2, 2025
Merged

Consider transmuter with more priority#682
p0mvn merged 1 commit intov28.xfrom
boss/fix-alloyed-routing

Conversation

@iboss-ptk
Copy link
Contributor

@iboss-ptk iboss-ptk commented Oct 1, 2025

Closes: BE-782

Summary by CodeRabbit

  • New Features

    • Prioritizes transmuter and orderbook pools in routing, improving route quality and pricing.
    • Allows transmuter pools to participate even when below the standard minimum liquidity cap, increasing route availability.
  • Refactor

    • Simplified and unified pool rating logic for more consistent and predictable pool ranking during routing.

@iboss-ptk iboss-ptk requested review from ValarDragon and p0mvn October 1, 2025 03:53
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 1, 2025

Walkthrough

Adjusts candidate pool filtering to exempt AlloyTransmuter pools from minimum liquidity checks and refactors pool rating in sorting to use explicit transmuter/orderbook detection with fixed TVL-based boosts.

Changes

Cohort / File(s) Summary of changes
Liquidity filter update
router/usecase/candidate_routes.go
Skip low-liquidity pools only if below min cap and not AlloyTransmuter; AlloyTransmuter pools bypass the min-liquidity cap check.
Rating and sorting refactor
router/usecase/router.go
Introduces isTransmuterPool/isOrderbookPool checks; applies uniform rating boosts (transmuter: TVL×10, orderbook: TVL×2); removes prior mixed boosting logic and type-cast branches; centralizes boosting before sorting.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant C as CandidateSelector
    participant P as Pool
    participant R as RatingEngine (sortPools)

    C->>P: Evaluate pool
    alt Liquidity < Min
        alt P is AlloyTransmuter
            Note right of C: Exempt from min-liquidity check
            C-->>P: Keep as candidate
        else Not AlloyTransmuter
            C-->>P: Skip pool
        end
    else Liquidity >= Min
        C-->>P: Keep as candidate
    end

    C->>R: Submit candidate pools
    loop For each pool
        R->>P: Detect type (isTransmuterPool / isOrderbookPool)
        alt Transmuter
            Note over R: rating += TVL × 10
        else Orderbook
            Note over R: rating += TVL × 2
        else Neither
            Note over R: Use base rating
        end
        R-->>R: Append to rated list
    end
    R-->>C: Sorted pools by rating
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

A rabbit taps the router rails, hop-hop, no myths,
Transmuters leap the cap, through liquidity mists.
Orderbooks get a tidy boost, ranked in the line,
TVL sprinkles starlight—ratings align.
Two files, one tune: bounce, sort, and go—
Carrots of code in a well-ordered flow.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly captures the primary intent of the changeset by indicating that transmuter pools will be given higher priority in routing, which aligns directly with the updated boost logic and liquidity-filter exemption for alloy transmuters. It is concise, focused on the main change, and avoids unnecessary detail or noise.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch boss/fix-alloyed-routing

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 75e0ccc and 7b8f92a.

📒 Files selected for processing (2)
  • router/usecase/candidate_routes.go (1 hunks)
  • router/usecase/router.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: test
  • GitHub Check: build
  • GitHub Check: test_routes
  • GitHub Check: test_coingecko_prices
  • GitHub Check: Run linter
  • GitHub Check: test_prices

Comment on lines +129 to +145
if pool.GetType() == poolmanagertypes.CosmWasm {
cosmWasmPoolModel := pool.GetSQSPoolModel().CosmWasmPoolModel
if cosmWasmPoolModel != nil {
if cosmWasmPoolModel.IsAlloyTransmuter() {
isTransmuterPool = true
} else if cosmWasmPoolModel.IsOrderbook() {
isOrderbookPool = true
}
} else {
cosmWasmPool, ok := pool.GetUnderlyingPool().(cosmwasmpooltypes.CosmWasmExtension)
if ok {
_, isTransmuter := transmuterCodeIDs[cosmWasmPool.GetCodeId()]
if isTransmuter {
isTransmuterPool = true
}
}
}
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 1, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Transmuter detection regresses non-alloy pools
When CosmWasmPoolModel is populated we now only set isTransmuterPool if IsAlloyTransmuter() returns true. Plain transmuters report PoolType = transmuter (or expose IsTransmuter()), so they fall through this branch, never get the 10× TVL boost, and sink back below orderbooks/regular pools—the exact routing failure BE-782 calls out. Please use the generic transmuter flag (or pool type) and still fall back to the code-ID map so every transmuter, alloyed or not, is flagged. Example fix:

-		if pool.GetType() == poolmanagertypes.CosmWasm {
-			cosmWasmPoolModel := pool.GetSQSPoolModel().CosmWasmPoolModel
-			if cosmWasmPoolModel != nil {
-				if cosmWasmPoolModel.IsAlloyTransmuter() {
-					isTransmuterPool = true
-				} else if cosmWasmPoolModel.IsOrderbook() {
-					isOrderbookPool = true
-				}
-			} else {
+		if pool.GetType() == poolmanagertypes.CosmWasm {
+			cosmWasmPoolModel := pool.GetSQSPoolModel().CosmWasmPoolModel
+			if cosmWasmPoolModel != nil {
+				if cosmWasmPoolModel.IsTransmuter() || cosmWasmPoolModel.IsAlloyTransmuter() {
+					isTransmuterPool = true
+				}
+				if cosmWasmPoolModel.IsOrderbook() {
+					isOrderbookPool = true
+				}
+			}
+			if !isTransmuterPool {
 				cosmWasmPool, ok := pool.GetUnderlyingPool().(cosmwasmpooltypes.CosmWasmExtension)
 				if ok {
 					_, isTransmuter := transmuterCodeIDs[cosmWasmPool.GetCodeId()]
 					if isTransmuter {
 						isTransmuterPool = true
 					}
 				}
 			}
 		}
🤖 Prompt for AI Agents
In router/usecase/router.go around lines 129 to 145, transmuter detection
currently only marks pools as transmuters when
CosmWasmPoolModel.IsAlloyTransmuter() is true, which misses plain (non-alloy)
transmuters; update the logic to first check the generic transmuter flag or pool
type (e.g., CosmWasmPoolModel.IsTransmuter() or PoolType == transmuter) and set
isTransmuterPool when present, keep the existing alloy-specific check, and still
fall back to the code-ID map lookup on the underlying CosmWasm pool when the
model is nil so all transmuters (alloyed or not) are flagged.

Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem valid, but @iboss-ptk please double-check

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This shouldn't have any issue. Even if it does, non-alloyed are not being used anymore anyway.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 1, 2025

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.

Logic makes sense to me

Comment on lines +128 to +131
// Skip pools with insufficient liquidity, except for transmuter pools
// Transmuter pools should always be considered regardless of liquidity cap
// because they provide no-slippage swaps and we want them prioritized
if pool.GetPoolLiquidityCap() < options.MinPoolLiquidityCap && !pool.IsAlloyTransmuter {
Copy link
Member

Choose a reason for hiding this comment

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

What if transmuter liquidity is zero? Should we define a minimum as $1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If user would like to swap $0.5 I think we should pick transmuter first still. I feel like arbitrary min here wouldn't give much benefit.

Comment on lines +129 to +145
if pool.GetType() == poolmanagertypes.CosmWasm {
cosmWasmPoolModel := pool.GetSQSPoolModel().CosmWasmPoolModel
if cosmWasmPoolModel != nil {
if cosmWasmPoolModel.IsAlloyTransmuter() {
isTransmuterPool = true
} else if cosmWasmPoolModel.IsOrderbook() {
isOrderbookPool = true
}
} else {
cosmWasmPool, ok := pool.GetUnderlyingPool().(cosmwasmpooltypes.CosmWasmExtension)
if ok {
_, isTransmuter := transmuterCodeIDs[cosmWasmPool.GetCodeId()]
if isTransmuter {
isTransmuterPool = true
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem valid, but @iboss-ptk please double-check

@p0mvn p0mvn merged commit e7b5a38 into v28.x Oct 2, 2025
9 checks passed
@p0mvn p0mvn deleted the boss/fix-alloyed-routing branch October 2, 2025 03:06
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