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

reduced origin min gas balance when quoting a route w/ origin gas token #3487

Open
wants to merge 1 commit into
base: feat/relayer-arb-call
Choose a base branch
from

Conversation

parodime
Copy link
Collaborator

@parodime parodime commented Jan 9, 2025

as origin chain gets critically low on gas, this change should discourage the relayer from quoting most routes involving that chain except those that will replenish the deficit gas

Summary by CodeRabbit

  • New Features

    • Enhanced gas sufficiency checks with a flexible threshold multiplier
    • Improved handling of native gas tokens in quote generation
  • Bug Fixes

    • Refined gas calculation logic to better support route quoting
    • Added validation for threshold multiplier range
  • Improvements

    • More nuanced approach to gas management across different token types
    • Streamlined error messaging for gas-related checks

Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

Walkthrough

The pull request introduces a new method HasSufficientGasWithMult in the inventory manager, which allows for a flexible gas threshold check with an optional multiplier. The changes enhance gas sufficiency validation by enabling dynamic threshold adjustments. The quoter's getOriginAmount method is updated to handle native gas tokens with a specific multiplier, potentially improving route quoting for scenarios involving native tokens.

Changes

File Change Summary
services/rfq/relayer/inventory/manager.go - Added HasSufficientGasWithMult method
- Modified HasSufficientGas to use new method
- Enhanced error handling and validation
services/rfq/relayer/inventory/mocks/manager.go - Added mock implementation for HasSufficientGasWithMult
services/rfq/relayer/quoter/quoter.go - Updated getOriginAmount to apply 0.65 multiplier for native gas tokens

Sequence Diagram

sequenceDiagram
    participant Quoter
    participant InventoryManager
    Quoter->>InventoryManager: HasSufficientGasWithMult(ctx, chainID, gasValue, multiplier)
    InventoryManager-->>Quoter: Returns (sufficient, error)
    alt Is Native Token
        Quoter->>InventoryManager: Check with 0.65 multiplier
    else Standard Token
        Quoter->>InventoryManager: Check with default multiplier
    end
Loading

Poem

🐰 A Rabbit's Ode to Gas Management 🚀

With multipliers light and fleet,
Our gas checks now are quite a treat
Native tokens dance with grace
Thresholds bend at our embrace
Efficiency hops, our code's delight! 🌟

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.

@github-actions github-actions bot added go Pull requests that update Go code size/s labels Jan 9, 2025
Copy link

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8b05383
Status: ✅  Deploy successful!
Preview URL: https://eef95d50.sanguine-fe.pages.dev
Branch Preview URL: https://parod-minquoteamt.sanguine-fe.pages.dev

View logs

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)
services/rfq/relayer/inventory/manager.go (1)

Line range hint 446-474: Consider using constants for the multiplier range.

The implementation is solid, but the magic numbers 0 and 2 for the multiplier range could be defined as constants for better maintainability and documentation.

+const (
+    minThresholdMultiplier = 0.0
+    maxThresholdMultiplier = 2.0
+)

 func (i *inventoryManagerImpl) HasSufficientGasWithMult(parentCtx context.Context, chainID int, gasValue *big.Int, thresholdMultiplier *float64) (sufficient bool, err error) {
     // ...
-    if *thresholdMultiplier < 0 || *thresholdMultiplier > 2 {
+    if *thresholdMultiplier < minThresholdMultiplier || *thresholdMultiplier > maxThresholdMultiplier {
         return false, fmt.Errorf("thresholdMultiplier out of range: %f", *thresholdMultiplier)
     }
     // ...
 }
services/rfq/relayer/quoter/quoter.go (1)

775-784: Improve code maintainability with constants.

Consider the following improvements:

  1. Define the 0.65 multiplier as a named constant
  2. Use util.EthAddress instead of the hardcoded address
+const nativeGasTokenMultiplier = 0.65
+
 // if the origin token is native gas, require less minimum gas on the origin chain.
 // as origin gas gets critically low, this will discourage the relayer from quoting most routes *except* those that will replenish the deficit gas.
 var sufficentGasOrigin bool
-if input.OriginTokenAddr.Hex() == "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" {
-    multiplier := 0.65
+if input.OriginTokenAddr == util.EthAddress {
+    multiplier := nativeGasTokenMultiplier
     sufficentGasOrigin, err = m.inventoryManager.HasSufficientGasWithMult(ctx, input.OriginChainID, nil, &multiplier)
 } else {
     sufficentGasOrigin, err = m.inventoryManager.HasSufficientGas(ctx, input.OriginChainID, nil)
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 15c2598 and 8b05383.

📒 Files selected for processing (3)
  • services/rfq/relayer/inventory/manager.go (3 hunks)
  • services/rfq/relayer/inventory/mocks/manager.go (1 hunks)
  • services/rfq/relayer/quoter/quoter.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Go Generate (Module Changes) (services/rfq)
  • GitHub Check: Go Generate (Module Changes) (contrib/promexporter)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (3)
services/rfq/relayer/inventory/mocks/manager.go (1)

139-159: Clean mock implementation!

The mock method follows the established mockery pattern and correctly handles all parameters and return values.

services/rfq/relayer/inventory/manager.go (2)

51-52: Well-documented interface addition!

The new method is clearly documented and follows the interface's documentation style.


443-444: Good refactoring to reuse logic!

The implementation maintains backward compatibility by delegating to the new method with a nil multiplier.

Copy link

codecov bot commented Jan 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 21.98636%. Comparing base (15c2598) to head (8b05383).
Report is 8 commits behind head on feat/relayer-arb-call.

Additional details and impacted files
@@                    Coverage Diff                    @@
##           feat/relayer-arb-call       #3487   +/-   ##
=========================================================
  Coverage               21.98636%   21.98636%           
=========================================================
  Files                        502         502           
  Lines                      41926       41926           
=========================================================
  Hits                        9218        9218           
  Misses                     31772       31772           
  Partials                     936         936           
Flag Coverage Δ
opbot 0.18282% <ø> (ø)
promexporter 6.81642% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

// if the origin token is native gas, require less minimum gas on the origin chain.
// as origin gas gets critically low, this will discourage the relayer from quoting most routes *except* those that will replenish the deficit gas.
var sufficentGasOrigin bool
if input.OriginTokenAddr.Hex() == "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can use util.IsGasToken() here instead of manual check

// as origin gas gets critically low, this will discourage the relayer from quoting most routes *except* those that will replenish the deficit gas.
var sufficentGasOrigin bool
if input.OriginTokenAddr.Hex() == "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" {
multiplier := 0.65
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would say this should probably be configurable, and we can default to 0.65 or some other sensible value

@@ -48,6 +48,8 @@ type Manager interface {
ApproveAllTokens(ctx context.Context) error
// HasSufficientGas checks if there is sufficient gas for a given route.
HasSufficientGas(ctx context.Context, chainID int, gasValue *big.Int) (bool, error)
// HasSufficientGasWithMult checks if there is sufficient gas for a given route with an optional threshold multiplier applied.
HasSufficientGasWithMult(ctx context.Context, chainID int, gasValue *big.Int, thresholdMultiplier *float64) (bool, error)
Copy link
Collaborator

Choose a reason for hiding this comment

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

My suggestion here would be to add the thresholdMultiplier param to HasSufficientGas and remove HasSufficientGasWithMult- since you already have thresholdMultiplier as a pointer, it serves as optional param. This way we can keep the interface simple

Copy link

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants