Conversation
WalkthroughIntroduced a quote-based abstraction for EVM swap providers. Added Changes
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/recurring/consumer.go (1)
1102-1105:⚠️ Potential issue | 🟡 MinorPre-existing bug:
%wwraps a stale/nilerrinstead of reporting the unparseable value.
SetStringsignals failure viaok == false, not an error. At this pointerrholds the result from a prior unrelated call (or isnil), so the formatted message will be misleading (e.g.,"failed to parse fromAmountStr: <nil>").🐛 Proposed fix
fromAmountTyped, ok := new(big.Int).SetString(fromAmount, 10) if !ok { - return fmt.Errorf("failed to parse fromAmountStr: %w", err) + return fmt.Errorf("failed to parse fromAmount: %s", fromAmount) }
🤖 Fix all issues with AI agents
In `@internal/evm/swap_service.go`:
- Around line 83-93: The code accesses result.quote.AmountOut without ensuring
result.quote is non-nil, which can panic if a provider returns (nil, nil);
update the logic in the function handling provider results to first check if
result.quote != nil before logging AmountOut or comparing AmountOut to
bestAmountOut, and skip or treat the result as invalid when result.quote is nil;
ensure you also avoid calling result.quote.AmountOut.Cmp when AmountOut is nil
by checking both result.quote != nil and result.quote.AmountOut != nil before
updating bestAmountOut, bestQuote, bestProvider, and bestProviderName, and
adjust the Debug log to safely include amountOut only when quote is present.
In `@internal/thorchain/provider_evm.go`:
- Around line 156-159: The THORChain provider currently calls strconv.ParseUint
on quote.DustThreshold unguarded, which will error if the string is empty;
mirror the Mayachain provider's behavior by checking quote.DustThreshold != ""
before parsing and defaulting dustThreshold to 0 when empty. Update the logic
around dustThreshold (and related variables) so that if quote.DustThreshold ==
"" you set dustThreshold = 0, otherwise parse with strconv.ParseUint and return
the existing wrapped error on parse failure.
🧹 Nitpick comments (3)
internal/oneinch/provider.go (1)
98-117: Double API call:Quote+MakeTxboth hit the 1inch swap endpoint.
resolveSwapcallsGetSwap(the actual swap resolution endpoint). When the consumer flow callsQuoteduringFindBestQuoteand thenMakeTxon the winner, 1inch's swap endpoint is invoked twice for the winning provider. This is functionally correct but worth noting — swap parameters (price, route) may shift between the two calls.Additionally, consider whether the spender could be derived from
rs.resp.Tx.To(the router address already returned in the swap response) instead of a separateGetSpenderRPC, saving one API round-trip.internal/mayachain/provider_evm.go (2)
228-288:MakeTxcallsresolveQuoteagain, making a second API request to Mayachain.In the consumer flow,
Quoteis called first (duringFindBestQuote), and thenMakeTxis called on the winner. Both invokeresolveQuote, which fetches a fresh quote from the Mayachain API. The second quote may return different amounts or parameters. Additionally,convertExpectedOut(line 282) may trigger an RPC call for token decimals a second time.This is inherent to the two-phase design and functionally correct, but be aware that the
amountOutreturned byMakeTxcan differ from whatFindBestQuoteselected.
74-93: Significant code duplication withinternal/thorchain/provider_evm.go.
convertDecimals,convertExpectedOut,resolvedQuote,resolveQuote,getTokenDecimals,getTokenDecimalsWithRpc, andgetTargetChainRpcare nearly identical between the Mayachain and Thorchain EVM providers. Consider extracting shared logic into a common helper package (e.g.,internal/evm/dexchain) to reduce maintenance burden.Also applies to: 178-205
Summary by CodeRabbit
Release Notes