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

feat(rfq-relayer): make QuoteWidthBps a token-level param [SLT-354] #3305

Merged
merged 9 commits into from
Oct 22, 2024

Conversation

dwasse
Copy link
Collaborator

@dwasse dwasse commented Oct 17, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced quote calculation by including token-specific parameters.
    • Introduced a new configuration field for quote width in token settings.
  • Bug Fixes

    • Improved error handling for quote retrieval processes, including checks for invalid values.
  • Documentation

    • Updated comments for clarity and consistency in the codebase.
  • Refactor

    • Restructured configuration management for quote width parameters, shifting focus to token-specific settings.
  • Tests

    • Adjusted tests to reflect changes in configuration structure and added new scenarios for quote calculations.

Copy link
Contributor

coderabbitai bot commented Oct 17, 2024

Walkthrough

The pull request introduces a new field, QuoteWidthBps, to the TokenConfig struct while removing the previous definition from the ChainConfig struct. This change restructures where the configuration parameter is stored. Additionally, the GetQuoteWidthBps method has been modified to accept a tokenName parameter, enhancing its functionality. Corresponding updates in the test files reflect these structural changes, including the removal of tests related to the ChainConfig field.

Changes

File Path Change Summary
services/rfq/relayer/quoter/quoter_test.go - Updated tests for GetDestAmount to handle QuoteWidthBps.
- Enhanced tests for quote generation to include gas token requirements and error handling.
services/rfq/relayer/relconfig/config.go - Added QuoteWidthBps field to TokenConfig struct.
- Removed QuoteWidthBps field from ChainConfig struct.
services/rfq/relayer/relconfig/config_test.go - Removed references to QuoteWidthBps from ChainConfig in tests.
- Removed GetQuoteWidthBps test case.
services/rfq/relayer/relconfig/getters.go - Updated DefaultChainConfig to remove QuoteWidthBps.
- Changed GetQuoteWidthBps method signature to accept tokenName parameter and improved error handling.

Possibly related PRs

  • RFQ Relayer: support pointers for config values #2913: This PR modifies the ChainConfig struct to use pointer types for several fields, including QuoteFixedFeeMultiplier, which is relevant to the changes made in the main PR regarding the restructuring of configuration parameters.
  • feat(rfq-relayer): add MaxRelayAmount #3259: This PR introduces new fields MaxQuoteAmount and MaxRelayAmount to the TokenConfig struct, which is directly related to the changes made in the main PR where the TokenConfig struct was modified.
  • fix(rfq-relayer): profitability check accounts for offsets #3288: This PR enhances the profitability check logic in the quoter.go file, which is relevant as it involves adjustments to how quote parameters are processed, similar to the changes in the main PR that involve the QuoteWidthBps parameter.

Suggested reviewers

  • aureliusbtc
  • trajan0x

🐰 In the meadow, where tokens play,
A new field blooms, brightening the day.
Quotes now dance with names in tow,
Configs restructured, watch them grow!
With each little change, we hop with glee,
A world of quotes, as sweet as can be! 🌼


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

cloudflare-workers-and-pages bot commented Oct 17, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 103b5aa
Status: ✅  Deploy successful!
Preview URL: https://111517d2.sanguine-fe.pages.dev
Branch Preview URL: https://feat-quote-width-token.sanguine-fe.pages.dev

View logs

@github-actions github-actions bot added go Pull requests that update Go code size/xs labels Oct 17, 2024
Copy link

codecov bot commented Oct 17, 2024

Codecov Report

Attention: Patch coverage is 9.09091% with 10 lines in your changes missing coverage. Please review.

Project coverage is 24.99048%. Comparing base (112a9ab) to head (103b5aa).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
services/rfq/relayer/relconfig/getters.go 0.00000% 10 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #3305         +/-   ##
===================================================
- Coverage   33.27199%   24.99048%   -8.28151%     
===================================================
  Files            543         198        -345     
  Lines          34777       13125      -21652     
  Branches          82          82                 
===================================================
- Hits           11571        3280       -8291     
+ Misses         22183        9563      -12620     
+ Partials        1023         282        -741     
Flag Coverage Δ
cctp-relayer ?
core ?
ethergo ?
git-changes-action ?
omnirpc ?
opbot 0.48870% <ø> (ø)
packages 90.44834% <ø> (ø)
promexporter 6.81642% <ø> (ø)
rfq 24.59928% <9.09091%> (-0.11174%) ⬇️
screener-api ?
scribe ?
tools ?

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.

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

🧹 Outside diff range and nitpick comments (3)
services/rfq/relayer/relconfig/config.go (2)

142-144: LGTM. Consider adding validation for QuoteWidthBps.

The addition of QuoteWidthBps to the TokenConfig struct allows for more granular control over quote width for individual tokens, which is a good improvement.

Consider adding a validation check in the Validate method to ensure that QuoteWidthBps is always positive, as per the comment. This would prevent configuration errors at runtime.


Add validation for QuoteWidthBps in the Validate method.

The validate method in services/rfq/relayer/relconfig/config.go does not currently include validation for the newly added QuoteWidthBps field in TokenConfig. To ensure configuration integrity, please update the Validate method to include appropriate checks for QuoteWidthBps.

  • File: services/rfq/relayer/relconfig/config.go
  • Lines to Update: Within the Validate method, add validation logic for QuoteWidthBps similar to existing field validations.
🔗 Analysis chain

Line range hint 279-321: Update Validate method and review QuoteWidthBps usage.

With the addition of QuoteWidthBps to TokenConfig, the Validate method of the Config struct may need to be updated to include validation for this new field. Additionally, the usage of QuoteWidthBps throughout the codebase should be reviewed to ensure it's now being accessed from the correct location.

  1. Update the Validate method to include checks for QuoteWidthBps in each TokenConfig.
  2. Review and update any code that previously accessed QuoteWidthBps from ChainConfig to now use it from TokenConfig.

Please run the following script to identify potential areas that need updating:

Review the results and make necessary updates to align with the new configuration structure.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of QuoteWidthBps in the codebase
rg -i 'quotewidthbps' --type go

# Search for the Validate method
rg -i 'func \(c config\) validate' --type go

Length of output: 146


Script:

#!/bin/bash
# Search for QuoteWidthBps within the validate method
rg -i 'func \(c Config\) validate[^}]*quotewidthbps' --type go

# Search for any remaining usages of QuoteWidthBps outside of test files
rg -i 'quotewidthbps' --type go -g '!*.test.go'

Length of output: 1758

services/rfq/relayer/quoter/quoter.go (1)

821-824: LGTM! Consider enhancing error handling.

The changes look good and align with the PR objective of making QuoteWidthBps a token-level parameter. This allows for more granular control over quote widths based on specific tokens.

Consider wrapping the error returned from m.config.GetQuoteWidthBps with additional context:

 quoteWidthBps, err := m.config.GetQuoteWidthBps(input.DestChainID, tokenName)
 if err != nil {
-    return nil, fmt.Errorf("error getting quote width bps: %w", err)
+    return nil, fmt.Errorf("error getting quote width bps for token %s on chain %d: %w", tokenName, input.DestChainID, err)
 }

This will provide more detailed information in case of an error, making debugging easier.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6880ddd and 61ad52d.

📒 Files selected for processing (4)
  • services/rfq/relayer/quoter/quoter.go (1 hunks)
  • services/rfq/relayer/relconfig/config.go (1 hunks)
  • services/rfq/relayer/relconfig/config_test.go (0 hunks)
  • services/rfq/relayer/relconfig/getters.go (1 hunks)
💤 Files with no reviewable changes (1)
  • services/rfq/relayer/relconfig/config_test.go
🧰 Additional context used
🔇 Additional comments (3)
services/rfq/relayer/relconfig/config.go (1)

Line range hint 65-106: Verify usage of QuoteWidthBps in other parts of the codebase.

The QuoteWidthBps field has been removed from the ChainConfig struct and added to the TokenConfig struct. This change allows for more granular control but may require updates in other parts of the codebase.

Please run the following script to check for any remaining references to QuoteWidthBps in the context of ChainConfig:

#!/bin/bash
# Search for references to QuoteWidthBps in the context of ChainConfig
rg -i 'chainconfig.*quotewidthbps' --type go

Ensure that all occurrences are updated to use the new TokenConfig.QuoteWidthBps instead.

services/rfq/relayer/relconfig/getters.go (2)

442-458: Function implementation looks good

The updated GetQuoteWidthBps function correctly retrieves the QuoteWidthBps value from the token configuration based on the provided chainID and tokenName. Error handling is appropriately managed for missing chain or token configurations, and negative width values.


442-458: Ensure all calls to GetQuoteWidthBps are updated with the new parameter

The method GetQuoteWidthBps now includes an additional parameter tokenName string in its signature. Please verify that all invocations of this method throughout the codebase have been updated to pass both chainID and tokenName to prevent any potential runtime errors.

Run the following script to identify any usages of GetQuoteWidthBps that may not have been updated:

@github-actions github-actions bot added size/s and removed size/xs labels Oct 17, 2024
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: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 61ad52d and 0823e7e.

📒 Files selected for processing (1)
  • services/rfq/relayer/quoter/quoter_test.go (2 hunks)
🧰 Additional context used
🔇 Additional comments (1)
services/rfq/relayer/quoter/quoter_test.go (1)

401-404: Test correctly validates error handling for negative QuoteWidthBps

The test case appropriately verifies that setting QuoteWidthBps to a negative value results in an error from GetDestAmount. This strengthens the validation logic by ensuring that invalid configuration values are properly handled, enhancing the robustness of the system.

tokenCfg := s.config.Chains[origin].Tokens["USDC"]
tokenCfg.QuoteOffsetBps = originQuoteOffsetBps
s.config.Chains[origin].Tokens["USDC"] = tokenCfg
tokenCfg = s.config.Chains[dest].Tokens["USDC"]
tokenCfg.QuoteOffsetBps = destQuoteOffsetBps
tokenCfg.QuoteWidthBps = quoteWidthBps
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider setting QuoteWidthBps for the origin token configuration

In the setQuoteParams function, QuoteWidthBps is being set only for the destination token configuration. If QuoteWidthBps is a token-level parameter that affects both origin and destination tokens, consider setting it for the origin token configuration as well. This ensures comprehensive testing and consistent behavior across all tokens.


🛠️ Refactor suggestion

Use integer types for basis points parameters

The setQuoteParams function accepts basis points parameters (originQuoteOffsetBps, destQuoteOffsetBps, quoteWidthBps) as float64. Since basis points represent integer values (1 basis point = 0.01%), consider using integer types (e.g., int or uint) for these parameters. This prevents potential floating-point precision issues and more accurately represents the discrete nature of basis points.

@dwasse dwasse changed the title feat(rfq-relayer): make QuoteWidthBps a token-level param feat(rfq-relayer): make QuoteWidthBps a token-level param [SLT-354] Oct 17, 2024
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

🧹 Outside diff range and nitpick comments (1)
services/rfq/relayer/quoter/quoter_test.go (1)

Line range hint 251-326: Add tests for QuoteWidthBps in TestGetOriginAmount

Currently, the TestGetOriginAmount function does not include test cases that assess the impact of QuoteWidthBps on origin amount calculations. Adding such tests would enhance coverage and verify that QuoteWidthBps is consistently applied in both origin and destination amount computations.

Would you like assistance in adding these test cases?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0823e7e and 103b5aa.

📒 Files selected for processing (1)
  • services/rfq/relayer/quoter/quoter_test.go (2 hunks)
🧰 Additional context used
🔇 Additional comments (2)
services/rfq/relayer/quoter/quoter_test.go (2)

362-365: Consider setting QuoteWidthBps for the origin token configuration

Currently, QuoteWidthBps is being set only for the destination token configuration in the setQuoteParams function. If QuoteWidthBps should also affect the origin token calculations, consider setting it for the origin token configuration to ensure consistent behavior across both origin and destination tokens.


401-405: Proper error handling for negative QuoteWidthBps values

The test case correctly verifies that a negative QuoteWidthBps value results in an error. This ensures that the system robustly handles invalid input for QuoteWidthBps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code needs-go-generate-services/rfq size/s
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant