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-api): active api schema changes #3248

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dwasse
Copy link
Collaborator

@dwasse dwasse commented Oct 7, 2024

Summary by CodeRabbit

  • New Features
    • Enhanced quote handling by incorporating fee deductions into the final amounts submitted.
  • Improvements
    • Updated logic for determining quote types in requests, refining how clients interpret responses.
    • Added error handling for parsing fixed fees and destination amounts to improve reliability.
  • Bug Fixes
    • Removed unnecessary QuoteRequest struct to simplify the model without affecting existing structures.

Copy link
Contributor

coderabbitai bot commented Oct 7, 2024

Walkthrough

The changes in this pull request involve the removal of the QuoteRequest struct from the model package and modifications to the PutRFQRequest method within the QuoterAPIServer struct. The logic for determining the quoteType has been updated to default to quoteTypePassive, changing only when a specific condition is met. Additionally, the generateActiveRFQ method in the Manager struct has been enhanced to calculate a net destination amount, accounting for a fixed fee. Error handling for parsing has also been introduced.

Changes

File Path Change Summary
services/rfq/api/model/request.go Removed QuoteRequest struct, simplifying the model.
services/rfq/api/rest/server.go Updated logic in PutRFQRequest method to determine quoteType.
services/rfq/relayer/quoter/quoter.go Modified generateActiveRFQ method to calculate net destination amount after deducting a fixed fee; added error handling for parsing.

Possibly related PRs

Suggested labels

size/m, M-docs

Suggested reviewers

  • aureliusbtc
  • trajan0x

Poem

In the meadow where quotes do play,
A struct was removed, brightening the day.
With fees now accounted, the numbers align,
A simpler model, oh how it does shine!
Hopping along, we cheer and we say,
"To clearer paths, hip-hip-hooray!" 🐇✨


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.

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

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

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 994cd52
Status: ✅  Deploy successful!
Preview URL: https://07a346d0.sanguine-fe.pages.dev
Branch Preview URL: https://feat-active-api-fixes.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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4b49879 and 994cd52.

📒 Files selected for processing (3)
  • services/rfq/api/model/request.go (0 hunks)
  • services/rfq/api/rest/server.go (1 hunks)
  • services/rfq/relayer/quoter/quoter.go (1 hunks)
💤 Files with no reviewable changes (1)
  • services/rfq/api/model/request.go
🧰 Additional context used
🔇 Additional comments (1)
services/rfq/api/rest/server.go (1)

560-562: Improved logic for determining quote type. Verify impact on dependent systems.

The changes improve the accuracy of determining the quote type by setting it to "passive" by default and only changing to "active" when the selected quote matches the active quote. This is a more precise approach.

To ensure this change doesn't negatively impact other parts of the system, please run the following verification steps:

Please review the output of these commands to ensure that all related code and tests are updated accordingly.

✅ Verification successful

Quote type determination logic verified. No impact found on dependent systems or tests.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any code that might be relying on the previous quote type determination logic

# Test 1: Search for usages of quoteTypeActive and quoteTypePassive
echo "Searching for usages of quoteTypeActive and quoteTypePassive:"
rg --type go "quoteTypeActive|quoteTypePassive"

# Test 2: Search for any code that might be making assumptions about how quote types are determined
echo "Searching for potential assumptions about quote type determination:"
rg --type go "quote.*type|type.*quote"

# Test 3: Check for any tests that might need updating due to this change
echo "Checking for tests that might need updating:"
rg --type go -t test "quoteType|quote.*type|type.*quote"

Length of output: 1244


Script:

#!/bin/bash
# Description: Check for any tests that might need updating due to this change

# Test 3: Check for any tests that might need updating due to this change
echo "Checking for tests that might need updating:"
rg --glob "*_test.go" "quoteType|quote.*type|type.*quote"

Length of output: 158

Comment on lines +343 to +360
fixedFee, ok := new(big.Int).SetString(rawQuote.FixedFee, 10)
if !ok {
return nil, fmt.Errorf("error parsing fixed fee: %s", rawQuote.FixedFee)
}
rawDestAmount, ok := new(big.Int).SetString(rawQuote.DestAmount, 10)
if !ok {
return nil, fmt.Errorf("error parsing dest amount: %s", rawQuote.DestAmount)
}
destAmountNet := new(big.Int).Sub(rawDestAmount, fixedFee)
span.SetAttributes(
attribute.String("dest_amount", rawQuote.DestAmount),
attribute.String("fixed_fee", rawQuote.FixedFee),
attribute.String("dest_amount_net", destAmountNet.String()),
)

rfqResp := model.WsRFQResponse{
RequestID: rfqRequest.RequestID,
DestAmount: rawQuote.DestAmount,
DestAmount: destAmountNet.String(),
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

Improve error handling and consider using decimal arithmetic for financial calculations.

The changes introduce logic to calculate the net destination amount after deducting a fixed fee. While the implementation is generally correct, there are a few areas that could be improved:

  1. Error handling: The code uses if !ok checks for parsing strings to big.Int. Consider using more descriptive error messages or custom errors for better debugging.

  2. Precision concerns: Financial calculations often require high precision. Consider using a decimal arithmetic library like shopspring/decimal for more accurate calculations, especially when dealing with fees and amounts.

  3. Negative amount check: There's no check to ensure that the destAmountNet doesn't become negative after subtracting the fixed fee. This could lead to unexpected behavior.

Here's a suggested refactoring using the shopspring/decimal library:

import (
    "github.com/shopspring/decimal"
    // ... other imports
)

// ... inside generateActiveRFQ method
fixedFee, err := decimal.NewFromString(rawQuote.FixedFee)
if err != nil {
    return nil, fmt.Errorf("error parsing fixed fee: %w", err)
}

rawDestAmount, err := decimal.NewFromString(rawQuote.DestAmount)
if err != nil {
    return nil, fmt.Errorf("error parsing dest amount: %w", err)
}

destAmountNet := rawDestAmount.Sub(fixedFee)
if destAmountNet.IsNegative() {
    return nil, fmt.Errorf("net destination amount is negative: %s", destAmountNet)
}

span.SetAttributes(
    attribute.String("dest_amount", rawQuote.DestAmount),
    attribute.String("fixed_fee", rawQuote.FixedFee),
    attribute.String("dest_amount_net", destAmountNet.String()),
)

rfqResp := model.WsRFQResponse{
    RequestID:  rfqRequest.RequestID,
    DestAmount: destAmountNet.String(),
}

This refactoring improves precision, error handling, and adds a check for negative net amounts.

Copy link

codecov bot commented Oct 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (master@b9198f9). Learn more about missing BASE report.
Report is 33 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master       #3248   +/-   ##
============================================
  Coverage          ?   25.79828%           
============================================
  Files             ?          97           
  Lines             ?        3946           
  Branches          ?          82           
============================================
  Hits              ?        1018           
  Misses            ?        2920           
  Partials          ?           8           
Flag Coverage Δ
opbot 0.48870% <ø> (?)
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.

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.

1 participant