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

FeePricer: use different multipliers for quote / relay #2663

Merged
merged 7 commits into from
Jun 5, 2024

Conversation

dwasse
Copy link
Collaborator

@dwasse dwasse commented Jun 4, 2024

Summary by CodeRabbit

  • New Features

    • Introduced separate fee multipliers for quotes and relays, allowing more granular control over fee calculations.
  • Refactor

    • Updated methods to use isQuote parameter instead of useMultiplier for fee calculations.
    • Split FixedFeeMultiplier into QuoteFixedFeeMultiplier and RelayFixedFeeMultiplier in configuration settings.
  • Tests

    • Adjusted test cases to reflect changes in fee multiplier logic and configuration fields.

Copy link
Contributor

coderabbitai bot commented Jun 4, 2024

Walkthrough

The recent updates involve modifying the FeePricer interface to replace the useMultiplier parameter with isQuote. This change is reflected across multiple methods and their internal logic. Additionally, the FixedFeeMultiplier field in the ChainConfig struct has been split into QuoteFixedFeeMultiplier and RelayFixedFeeMultiplier for more precise control over fee multipliers. Corresponding test files have been updated to reflect these changes.

Changes

File Path Change Summary
services/rfq/relayer/pricer/fee_pricer.go Replaced useMultiplier with isQuote in method signatures and internal logic adjustments.
services/rfq/relayer/pricer/fee_pricer_test.go Updated test scenarios to use QuoteFixedFeeMultiplier and RelayFixedFeeMultiplier.
services/rfq/relayer/relconfig/config.go Split FixedFeeMultiplier into QuoteFixedFeeMultiplier and RelayFixedFeeMultiplier.
services/rfq/relayer/relconfig/config_test.go Renamed FixedFeeMultiplier to QuoteFixedFeeMultiplier in tests.
services/rfq/relayer/relconfig/getters.go Renamed FixedFeeMultiplier to QuoteFixedFeeMultiplier and added RelayFixedFeeMultiplier.

Poem

In the land where code does dance,
Fees now split, a fine romance.
Quotes and relays, each their own,
Multiplier seeds are freshly sown.
Tests align, the future bright,
Relayer's path now clear in sight.
🌟✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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 Jun 4, 2024
Copy link

cloudflare-workers-and-pages bot commented Jun 4, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 15e1f73
Status: ✅  Deploy successful!
Preview URL: https://cb5b740b.sanguine-fe.pages.dev
Branch Preview URL: https://feat-profitability-multiplie.sanguine-fe.pages.dev

View logs

Copy link

codecov bot commented Jun 4, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 22 lines in your changes missing coverage. Please review.

Project coverage is 39.75471%. Comparing base (48e1015) to head (15e1f73).

Files Patch % Lines
services/rfq/relayer/relconfig/getters.go 14.28571% 18 Missing ⚠️
services/rfq/relayer/pricer/fee_pricer.go 82.60870% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #2663         +/-   ##
===================================================
- Coverage   40.13990%   39.75471%   -0.38519%     
===================================================
  Files            184         180          -4     
  Lines          14868       14758        -110     
  Branches          80          80                 
===================================================
- Hits            5968        5867        -101     
+ Misses          8130        8124          -6     
+ Partials         770         767          -3     
Flag Coverage Δ
promexporter ?
rfq 31.51319% <50.00000%> (-0.12825%) ⬇️
stiprelayer 3.33333% <ø> (ø)

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8721ba0 and 9a19005.

Files selected for processing (5)
  • services/rfq/relayer/pricer/fee_pricer.go (9 hunks)
  • services/rfq/relayer/pricer/fee_pricer_test.go (3 hunks)
  • services/rfq/relayer/relconfig/config.go (1 hunks)
  • services/rfq/relayer/relconfig/config_test.go (3 hunks)
  • services/rfq/relayer/relconfig/getters.go (2 hunks)
Additional context used
GitHub Check: codecov/patch
services/rfq/relayer/pricer/fee_pricer.go

[warning] 248-249: services/rfq/relayer/pricer/fee_pricer.go#L248-L249
Added lines #L248 - L249 were not covered by tests


[warning] 253-253: services/rfq/relayer/pricer/fee_pricer.go#L253
Added line #L253 was not covered by tests

services/rfq/relayer/relconfig/getters.go

[warning] 327-327: services/rfq/relayer/relconfig/getters.go#L327
Added line #L327 was not covered by tests


[warning] 330-331: services/rfq/relayer/relconfig/getters.go#L330-L331
Added lines #L330 - L331 were not covered by tests


[warning] 336-340: services/rfq/relayer/relconfig/getters.go#L336-L340
Added lines #L336 - L340 were not covered by tests


[warning] 342-351: services/rfq/relayer/relconfig/getters.go#L342-L351
Added lines #L342 - L351 were not covered by tests

Additional comments not posted (12)
services/rfq/relayer/relconfig/config.go (1)

89-92: The addition of QuoteFixedFeeMultiplier and RelayFixedFeeMultiplier in ChainConfig is consistent with the PR's objective to differentiate fee multipliers for quoting and relaying. This change should provide the intended flexibility in fee calculations. Ensure that these new fields are properly integrated and used in the fee calculation logic throughout the system.

services/rfq/relayer/pricer/fee_pricer.go (5)

24-28: The method signatures in FeePricer interface have been correctly updated to replace useMultiplier with isQuote. This change aligns with the PR's objective and should help in applying different fee multipliers based on the transaction type (quote or relay).


Line range hint 84-109: The implementation of GetOriginFee method correctly utilizes the isQuote parameter to determine the appropriate fee multiplier. This method also handles the addition of L1 fees when applicable, which is a good practice for ensuring fee accuracy across different network conditions.


Line range hint 120-144: The GetDestinationFee method follows a similar pattern to GetOriginFee, correctly using the isQuote parameter. The method also handles L1 fees, which is crucial for transactions that span multiple layers or chains.


155-174: GetTotalFee method effectively combines the origin and destination fees to compute the total fee, considering whether the transaction is a quote or a relay. This method is central to the fee calculation logic and is implemented as expected.


Line range hint 190-265: The getFee method is the core function where the actual fee calculation logic is implemented. It correctly uses the isQuote parameter to fetch the appropriate multiplier. However, there are lines of code here that are not covered by tests, which could lead to potential issues in production.

- // Current implementation
+ // Suggested addition: Include unit tests covering the scenarios when `isQuote` is both true and false.
Tools
GitHub Check: codecov/patch

[warning] 248-249: services/rfq/relayer/pricer/fee_pricer.go#L248-L249
Added lines #L248 - L249 were not covered by tests


[warning] 253-253: services/rfq/relayer/pricer/fee_pricer.go#L253
Added line #L253 was not covered by tests

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

21-35: The test configurations have been updated to reflect the new QuoteFixedFeeMultiplier field in the ChainConfig struct. This is necessary to ensure that the unit tests are aligned with the new configuration structure and can validate the behavior correctly.

Also applies to: 39-53, 59-73


281-292: The test for GetQuoteFixedFeeMultiplier correctly checks the retrieval of the multiplier from the configuration. This ensures that the new configuration fields are not only correctly implemented but also retrievable as expected in different scenarios (default, base, and specific chain configurations).

services/rfq/relayer/pricer/fee_pricer_test.go (3)

264-265: Ensure that the new multipliers are correctly applied in the tests.


281-295: Verify that the fee calculations with the new multipliers are correct.


Line range hint 298-317: Check the behavior when the multiplier is set to negative or zero. Ensure it defaults to 1 as expected.

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

335-351: Check the GetRelayFixedFeeMultiplier function for correct fallback behavior to QuoteFixedFeeMultiplier when the relay multiplier is not set or is less than or equal to zero.

- return value, fmt.Errorf("failed to cast RelayFixedFeeMultiplier to int")
+ return value, fmt.Errorf("failed to cast RelayFixedFeeMultiplier to float64")
Tools
GitHub Check: codecov/patch

[warning] 336-340: services/rfq/relayer/relconfig/getters.go#L336-L340
Added lines #L336 - L340 were not covered by tests


[warning] 342-351: services/rfq/relayer/relconfig/getters.go#L342-L351
Added lines #L342 - L351 were not covered by tests

Comment on lines +318 to +333
// GetQuoteFixedFeeMultiplier returns the QuoteFixedFeeMultiplier for the given chainID.
func (c Config) GetQuoteFixedFeeMultiplier(chainID int) (value float64, err error) {
rawValue, err := c.getChainConfigValue(chainID, "QuoteFixedFeeMultiplier")
if err != nil {
return value, err
}

value, ok := rawValue.(float64)
if !ok {
return value, fmt.Errorf("failed to cast FixedFeeMultiplier to int")
return value, fmt.Errorf("failed to cast QuoteFixedFeeMultiplier to int")
}
if value <= 0 {
value = DefaultChainConfig.FixedFeeMultiplier
value = DefaultChainConfig.QuoteFixedFeeMultiplier
}
return value, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The GetQuoteFixedFeeMultiplier function is covered by tests in services/rfq/relayer/relconfig/config_test.go. However, there is a minor issue in the error message within the function.

  • Change the error message from "failed to cast QuoteFixedFeeMultiplier to int" to "failed to cast QuoteFixedFeeMultiplier to float64".

Analysis chain

Ensure that the GetQuoteFixedFeeMultiplier function correctly handles cases where the multiplier is not set or is less than or equal to zero.

- return value, fmt.Errorf("failed to cast QuoteFixedFeeMultiplier to int")
+ return value, fmt.Errorf("failed to cast QuoteFixedFeeMultiplier to float64")
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the `GetQuoteFixedFeeMultiplier` function is covered by tests.

# Test: Search for the function usage in test files. Expect: At least one occurrence.
rg --type go $'GetQuoteFixedFeeMultiplier' --files-with-matches tests/

Length of output: 116



Script:

#!/bin/bash
# Description: Verify that the `GetQuoteFixedFeeMultiplier` function is covered by tests.

# Test: Search for the function usage in Go files across the entire codebase. Expect: At least one occurrence.
rg --type go $'GetQuoteFixedFeeMultiplier'

Length of output: 949

Tools
GitHub Check: codecov/patch

[warning] 327-327: services/rfq/relayer/relconfig/getters.go#L327
Added line #L327 was not covered by tests


[warning] 330-331: services/rfq/relayer/relconfig/getters.go#L330-L331
Added lines #L330 - L331 were not covered by tests

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 size/s
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant