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(synapse-interface): validate rfq quotes #2971

Merged
merged 12 commits into from
Aug 8, 2024

Conversation

bigboydiamonds
Copy link
Collaborator

@bigboydiamonds bigboydiamonds commented Aug 5, 2024

null
9c76e85: synapse-interface preview link
0fe57cd: synapse-interface preview link
9bc4102: synapse-interface preview link
5c7b8d3: synapse-interface preview link
35b1df0: synapse-interface preview link
9aff122: synapse-interface preview link
7b6206b: synapse-interface preview link

Summary by CodeRabbit

  • New Features

    • Enhanced decision-making process for quote selection in the State Managed Bridge component.
  • Improvements

    • Simplified analytics event tracking by removing user account address, focusing on chain IDs and token details.
  • Chores

    • Streamlined event logging across multiple components by excluding the address from analytics.

d1e3f29: synapse-interface preview link
8081ae0: synapse-interface preview link
beb82df: synapse-interface preview link

Copy link
Contributor

coderabbitai bot commented Aug 5, 2024

Walkthrough

The recent changes across several components primarily focus on removing the useAccount hook and the tracking of user addresses in analytics. This streamlining enhances user privacy by simplifying data collection, shifting the focus to routing information and key transaction details. The modifications optimize the event logging mechanism while potentially affecting the depth of user insights captured in analytics.

Changes

Files Change Summary
.../components/WipWrapperComponents/Wrapper.tsx Removed useAccount hook and currentAddress variable; updated analytics events to omit the address property, focusing on query and pathname.
.../pages/landing/index.tsx Deleted currentAddress from LandingPage component; modified analytics event to exclude address, simplifying data collection during landing page access.
.../pages/state-managed-bridge/index.tsx Introduced nonRfqQuote variable for quote selection; refined analytics events to remove address property, emphasizing chain IDs and token details.
.../pages/swap/index.tsx Removed address from analytics events for swap initiation and completion, shifting focus to enhance user privacy and streamline captured data.
.../pages/teaser/#index.tsx Eliminated currentAddress from segmentAnalyticsEvent, altering analytics data sent during component mount by excluding user address.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Component
    participant Analytics

    User->>Component: Mounts Component
    Component->>Analytics: Log Event (without address)
    Analytics-->>Component: Acknowledge
Loading

🐇 "In a world where data flows free,
No more addresses, just you and me.
With simpler logs and privacy bright,
Let's hop into analytics, what a delight!
Focus on queries, let the path unwind,
A happier, simpler way to track what we find!" 🐰


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

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This pull request enhances the quote selection logic in the StateManagedBridge component, introducing a comparison between RFQ and SynapseBridge quotes for improved bridge transaction rates.

  • Added comparison logic between RFQ and SynapseBridge quotes in packages/synapse-interface/pages/state-managed-bridge/index.tsx
  • Implemented a 30% threshold for quote selection, favoring RFQ quotes when within the threshold
  • Introduced console logging for all quotes to aid in debugging and monitoring
  • Integrated RFQ module functionality, leveraging the existing Synapse Router infrastructure

1 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

@@ -166,6 +166,8 @@ const StateManagedBridge = () => {
stringToBigInt(debouncedFromValue, fromToken?.decimals[fromChainId])
)

console.log('allQuotes: ', allQuotes)
Copy link

Choose a reason for hiding this comment

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

style: Remove this console.log statement before merging to production

Copy link

codecov bot commented Aug 5, 2024

Bundle Report

Changes will decrease total bundle size by 123.94kB ⬇️

Bundle name Size Change
sdk-router-@synapsecns/sdk-router-esm 254.83kB 2.51kB ⬆️
sdk-router-@synapsecns/sdk-router-cjs 117.19kB 404.76kB ⬇️
widget-cjs-esm 276.17kB 276.17kB ⬆️
widget-esm-cjs 275.25kB 0 bytes
synapse-interface-server-cjs 1.38MB 934 bytes ⬆️
synapse-interface-edge-server-array-push 83 bytes 0 bytes
synapse-interface-client-array-push 7.46MB 1.21kB ⬆️

Copy link

codecov bot commented Aug 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.64961%. Comparing base (e84f0f6) to head (ebf52df).
Report is 35 commits behind head on master.

Additional details and impacted files
@@                 Coverage Diff                  @@
##              master       #2971          +/-   ##
====================================================
+ Coverage   25.70802%   90.64961%   +64.94158%     
====================================================
  Files            771          54         -717     
  Lines          55613        1016       -54597     
  Branches          80          82           +2     
====================================================
- Hits           14297         921       -13376     
+ Misses         39830          93       -39737     
+ Partials        1486           2        -1484     
Flag Coverage Δ
agents ?
cctp-relayer ?
core ?
ethergo ?
explorer ?
git-changes-action ?
omnirpc ?
opbot ?
packages 90.64961% <ø> (+0.16397%) ⬆️
rfq ?
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

cloudflare-workers-and-pages bot commented Aug 6, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: ebf52df
Status: ✅  Deploy successful!
Preview URL: https://c62f6c15.sanguine-fe.pages.dev
Branch Preview URL: https://fe-validate-rfq-quotes.sanguine-fe.pages.dev

View logs

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This update refines the quote selection process in the StateManagedBridge component, focusing on improved efficiency and clarity in handling RFQ and non-RFQ quotes.

  • Renamed 'bridgeQuote' to 'nonRfqQuote' in packages/synapse-interface/pages/state-managed-bridge/index.tsx for better clarity
  • Removed unnecessary console.log statement, reducing clutter in the code
  • Adjusted quote selection logic to ensure more accurate comparisons between RFQ and non-RFQ quotes

1 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

Copy link

cloudflare-workers-and-pages bot commented Aug 6, 2024

Deploying sanguine with  Cloudflare Pages  Cloudflare Pages

Latest commit: ebf52df
Status: ✅  Deploy successful!
Preview URL: https://f66495e3.sanguine.pages.dev
Branch Preview URL: https://fe-validate-rfq-quotes.sanguine.pages.dev

View logs

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

The recent changes further refine the RFQ and non-RFQ quote selection process in the StateManagedBridge component, enhancing decision-making and logging.

  • Updated packages/synapse-interface/pages/state-managed-bridge/index.tsx to compare maxAmountOut values between RFQ and non-RFQ quotes.
  • Introduced logging to capture events when a non-RFQ quote is chosen over an RFQ quote.
  • Set a hardcoded maxAmountOut value for RFQ quotes for testing purposes.
  • Added additional logging for debugging, which should be reviewed for removal before production.

1 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

The PR introduces validation logic for RFQ quotes in the StateManagedBridge component, enhancing the accuracy and reliability of the bridge quote selection process.

  • Removed console log statement and hardcoded value for rfqQuote.maxAmountOut in /packages/synapse-interface/pages/state-managed-bridge/index.tsx.
  • Added logic to validate and compare RFQ and non-RFQ quotes, ensuring the best quote is selected based on a 30% difference threshold.
  • Improved logging to capture events when a non-RFQ quote is chosen over an RFQ quote.
  • Potential performance impacts due to added complexity in the quote selection logic should be reviewed.

1 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

Comment on lines 206 to 214
`[Bridge] use non-RFQ quote over RFQ`,
{
address,
rfqQuote,
nonRfqQuote,
timestamp: currentTimestamp,
},
true
)
Copy link

Choose a reason for hiding this comment

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

logic: The condition here still references 'bridgeQuote' which was renamed to 'nonRfqQuote'. This might cause unexpected behavior.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

The PR enhances the StateManagedBridge component by adding validation logic for RFQ quotes, ensuring more accurate and reliable bridge quote selection.

  • Removed timestamp field from segment analytics event when using non-RFQ quotes.
  • Updated logic to validate and compare RFQ and non-RFQ quotes, selecting the best quote based on a 30% difference threshold.
  • Improved logging to capture events when a non-RFQ quote is chosen over an RFQ quote.
  • Removed console log statement and hardcoded value for rfqQuote.maxAmountOut in /packages/synapse-interface/pages/state-managed-bridge/index.tsx.
  • Potential performance impacts due to added complexity in the quote selection logic should be reviewed.

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

The PR enhances the StateManagedBridge component by adding validation logic for RFQ quotes, ensuring more accurate and reliable bridge quote selection.

  • Removed address field from several segmentAnalyticsEvent calls.
  • Updated bridge quote fetching logic to handle RFQ and non-RFQ quotes more accurately.
  • Improved error handling and state management during the bridge transaction process.
  • Enhanced logging to capture events when a non-RFQ quote is chosen over an RFQ quote.
  • Removed console log statement and hardcoded value for rfqQuote.maxAmountOut in /packages/synapse-interface/pages/state-managed-bridge/index.tsx.

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

The PR focuses on refining the StateManagedBridge component by adding validation logic for RFQ quotes and removing the address field from analytics events.

  • Removed useAccount hook and address parameter from segmentAnalyticsEvent in packages/synapse-interface/components/WipWrapperComponents/Wrapper.tsx.
  • Simplified packages/synapse-interface/pages/landing/index.tsx by removing useAccount and address from analytics events.
  • Updated packages/synapse-interface/pages/swap/index.tsx to exclude address from swap-related analytics events.
  • Removed useAccount and address from segmentAnalyticsEvent in packages/synapse-interface/pages/teaser/index.tsx.

Ensure analytics tracking remains accurate without the address parameter.

4 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

@bigboydiamonds bigboydiamonds changed the title [wip] feat(synapse-interface): validate rfq quotes feat(synapse-interface): validate rfq quotes Aug 6, 2024
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

The PR enhances the StateManagedBridge component by refining the logic for selecting between RFQ and non-RFQ quotes and updating the segmentAnalyticsEvent call to include more detailed information.

  • Updated packages/synapse-interface/pages/state-managed-bridge/index.tsx to capture specific details in segmentAnalyticsEvent when a non-RFQ quote is chosen over an RFQ quote.
  • Ensures analytics event now includes bridge module name, origin and destination chain IDs, token symbols, and quote amounts.
  • Aims to improve tracking and analysis of quote selection decisions for better optimization of bridge functionality.

1 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

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 48de090 and 1e634a8.

Files selected for processing (5)
  • packages/synapse-interface/components/WipWrapperComponents/Wrapper.tsx (2 hunks)
  • packages/synapse-interface/pages/landing/index.tsx (1 hunks)
  • packages/synapse-interface/pages/state-managed-bridge/index.tsx (4 hunks)
  • packages/synapse-interface/pages/swap/index.tsx (2 hunks)
  • packages/synapse-interface/pages/teaser/#index.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/synapse-interface/pages/swap/index.tsx
Additional comments not posted (7)
packages/synapse-interface/pages/teaser/#index.tsx (1)

11-13: Simplification of Analytics Event Tracking.

The removal of currentAddress from the analytics event simplifies the code and enhances user privacy by not tracking the user's address.

packages/synapse-interface/pages/landing/index.tsx (1)

20-22: Consistent Simplification of Analytics Tracking.

The removal of the currentAddress from the analytics payload aligns with the goal of simplifying data collection and enhancing privacy.

packages/synapse-interface/components/WipWrapperComponents/Wrapper.tsx (1)

9-11: Focus on Routing Information for Analytics.

By removing the currentAddress, the analytics event now focuses solely on routing information, which simplifies the event logging mechanism.

packages/synapse-interface/pages/state-managed-bridge/index.tsx (4)

190-192: LGTM! The introduction of nonRfqQuote is logical.

The addition of nonRfqQuote effectively differentiates between RFQ and non-RFQ quotes, aligning with the PR objectives.


196-219: Verify the default behavior for selecting the first active quote.

The fallback to selecting the first active quote when neither RFQ nor non-RFQ quotes are available is reasonable. Ensure this is a valid default behavior.


202-206: Verify the business requirement for the 30% variance.

The logic correctly compares the RFQ and non-RFQ quotes with a 30% variance. Ensure that this variance aligns with business requirements.


207-217: Ensure no sensitive data is logged in analytics events.

The analytics event logs relevant information when a non-RFQ quote is selected. Ensure that no sensitive data is inadvertently included.

Comment on lines 196 to 218
if (rfqQuote && nonRfqQuote) {
const rfqMaxAmountOut = BigInt(rfqQuote.maxAmountOut.toString())
const nonRfqMaxAmountOut = BigInt(nonRfqQuote.maxAmountOut.toString())

const maxDifference = (nonRfqMaxAmountOut * 30n) / 100n

if (rfqMaxAmountOut > nonRfqMaxAmountOut - maxDifference) {
quote = rfqQuote
} else {
quote = nonRfqQuote

segmentAnalyticsEvent(`[Bridge] use non-RFQ quote over RFQ`, {
bridgeModuleName: nonRfqQuote.bridgeModuleName,
originChainId: fromChainId,
originToken: fromToken.symbol,
originTokenAddress: fromToken.addresses[fromChainId],
destinationChainId: toChainId,
destinationToken: toToken.symbol,
destinationTokenAddress: toToken.addresses[toChainId],
rfqQuoteAmountOut: rfqQuote.maxAmountOut.toString(),
nonRfqMaxAmountOut: nonRfqQuote.maxAmountOut.toString(),
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider extracting quote selection logic into a separate function.

The logic for selecting between RFQ and non-RFQ quotes could be extracted into a separate function for improved readability and testability.

function selectQuote(rfqQuote, nonRfqQuote) {
  const rfqMaxAmountOut = BigInt(rfqQuote.maxAmountOut.toString());
  const nonRfqMaxAmountOut = BigInt(nonRfqQuote.maxAmountOut.toString());
  const maxDifference = (nonRfqMaxAmountOut * 30n) / 100n;

  if (rfqMaxAmountOut > nonRfqMaxAmountOut - maxDifference) {
    return rfqQuote;
  } else {
    segmentAnalyticsEvent(`[Bridge] use non-RFQ quote over RFQ`, {
      bridgeModuleName: nonRfqQuote.bridgeModuleName,
      originChainId: fromChainId,
      originToken: fromToken.symbol,
      originTokenAddress: fromToken.addresses[fromChainId],
      destinationChainId: toChainId,
      destinationToken: toToken.symbol,
      destinationTokenAddress: toToken.addresses[toChainId],
      rfqQuoteAmountOut: rfqQuote.maxAmountOut.toString(),
      nonRfqMaxAmountOut: nonRfqQuote.maxAmountOut.toString(),
    });
    return nonRfqQuote;
  }
}

Copy link
Collaborator

@ChiTimesChi ChiTimesChi left a comment

Choose a reason for hiding this comment

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

LGTM with a few minor nits

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

The PR enhances the logic in the State Managed Bridge component to validate RFQ quotes more effectively. It introduces a percentile difference for comparing RFQ and non-RFQ quotes and updates the selection logic accordingly.

  • Updated packages/synapse-interface/pages/state-managed-bridge/index.tsx to refine the logic for selecting between RFQ and non-RFQ quotes.
  • Introduced a percentile difference for comparing RFQ and non-RFQ quotes.
  • Simplified analytics event tracking by removing user account address, focusing on routing and transaction details.
  • Corrected the logic for comparing quotes to ensure accurate selection.
  • Enhanced error handling and logging for better debugging and user feedback.

1 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

const maxDifference =
(nonRfqMaxAmountOut * BigInt(allowedPercentileDifference)) / 100n

if (rfqMaxAmountOut > nonRfqMaxAmountOut - maxDifference) {
Copy link

Choose a reason for hiding this comment

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

logic: The condition here still references 'bridgeQuote' which was renamed to 'nonRfqQuote'. This might cause unexpected behavior.

Comment on lines +209 to +219
segmentAnalyticsEvent(`[Bridge] use non-RFQ quote over RFQ`, {
bridgeModuleName: nonRfqQuote.bridgeModuleName,
originChainId: fromChainId,
originToken: fromToken.symbol,
originTokenAddress: fromToken.addresses[fromChainId],
destinationChainId: toChainId,
destinationToken: toToken.symbol,
destinationTokenAddress: toToken.addresses[toChainId],
rfqQuoteAmountOut: rfqQuote.maxAmountOut.toString(),
nonRfqMaxAmountOut: nonRfqQuote.maxAmountOut.toString(),
})
Copy link

Choose a reason for hiding this comment

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

style: Consider extracting this quote selection logic into a separate function for better readability and testability

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1e634a8 and 8c1e247.

Files selected for processing (1)
  • packages/synapse-interface/pages/state-managed-bridge/index.tsx (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/synapse-interface/pages/state-managed-bridge/index.tsx

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

The recent changes in the state-managed-bridge/index.tsx file focus on refining the decision-making process for selecting between RFQ and non-RFQ quotes, ensuring the most favorable quote is chosen based on a 30% allowable difference.

  • Introduced percentile difference check for quote selection.
  • Enhanced logging for analytics events.
  • Adjusted logic for setting bridge quotes.
  • Improved error handling and user feedback.
  • Simplified analytics event tracking by removing user account address.

Ensure thorough testing of the quote selection logic to avoid unexpected behavior.

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings

Comment on lines +209 to +219
segmentAnalyticsEvent(`[Bridge] use non-RFQ quote over RFQ`, {
bridgeModuleName: nonRfqQuote.bridgeModuleName,
originChainId: fromChainId,
originToken: fromToken.symbol,
originTokenAddress: fromToken.addresses[fromChainId],
destinationChainId: toChainId,
destinationToken: toToken.symbol,
destinationTokenAddress: toToken.addresses[toChainId],
rfqQuoteAmountOut: rfqQuote.maxAmountOut.toString(),
nonRfqMaxAmountOut: nonRfqQuote.maxAmountOut.toString(),
})
Copy link

Choose a reason for hiding this comment

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

style: Consider extracting this quote selection logic into a separate function for better readability and testability.

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 8c1e247 and ebf52df.

Files selected for processing (1)
  • packages/synapse-interface/pages/state-managed-bridge/index.tsx (4 hunks)
Additional comments not posted (4)
packages/synapse-interface/pages/state-managed-bridge/index.tsx (4)

190-192: LGTM!

The introduction of nonRfqQuote aligns well with the RFQ handling logic.


209-219: LGTM!

The analytics event captures relevant details when a non-RFQ quote is selected.


222-222: LGTM!

The use of the nullish coalescing operator (??) simplifies the fallback logic for quote selection.


Line range hint 108-108: Remove console.log statement.

Ensure that this console.log statement is removed before merging to production.

Comment on lines +196 to +220
if (rfqQuote && nonRfqQuote) {
const rfqMaxAmountOut = BigInt(rfqQuote.maxAmountOut.toString())
const nonRfqMaxAmountOut = BigInt(nonRfqQuote.maxAmountOut.toString())

const allowedPercentileDifference = 30n
const maxDifference =
(nonRfqMaxAmountOut * allowedPercentileDifference) / 100n

if (rfqMaxAmountOut > nonRfqMaxAmountOut - maxDifference) {
quote = rfqQuote
} else {
quote = nonRfqQuote

segmentAnalyticsEvent(`[Bridge] use non-RFQ quote over RFQ`, {
bridgeModuleName: nonRfqQuote.bridgeModuleName,
originChainId: fromChainId,
originToken: fromToken.symbol,
originTokenAddress: fromToken.addresses[fromChainId],
destinationChainId: toChainId,
destinationToken: toToken.symbol,
destinationTokenAddress: toToken.addresses[toChainId],
rfqQuoteAmountOut: rfqQuote.maxAmountOut.toString(),
nonRfqMaxAmountOut: nonRfqQuote.maxAmountOut.toString(),
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider extracting quote selection logic into a separate function.

The logic for selecting between RFQ and non-RFQ quotes is sound. Extracting it into a separate function could improve readability and testability.

function selectQuote(rfqQuote, nonRfqQuote) {
  const rfqMaxAmountOut = BigInt(rfqQuote.maxAmountOut.toString());
  const nonRfqMaxAmountOut = BigInt(nonRfqQuote.maxAmountOut.toString());
  const allowedPercentileDifference = 30n;
  const maxDifference = (nonRfqMaxAmountOut * allowedPercentileDifference) / 100n;

  if (rfqMaxAmountOut > nonRfqMaxAmountOut - maxDifference) {
    return rfqQuote;
  } else {
    segmentAnalyticsEvent(`[Bridge] use non-RFQ quote over RFQ`, {
      bridgeModuleName: nonRfqQuote.bridgeModuleName,
      originChainId: fromChainId,
      originToken: fromToken.symbol,
      originTokenAddress: fromToken.addresses[fromChainId],
      destinationChainId: toChainId,
      destinationToken: toToken.symbol,
      destinationTokenAddress: toToken.addresses[toChainId],
      rfqQuoteAmountOut: rfqQuote.maxAmountOut.toString(),
      nonRfqMaxAmountOut: nonRfqQuote.maxAmountOut.toString(),
    });
    return nonRfqQuote;
  }
}

@bigboydiamonds bigboydiamonds merged commit f8a0e13 into master Aug 8, 2024
29 checks passed
@bigboydiamonds bigboydiamonds deleted the fe/validate-rfq-quotes branch August 8, 2024 18:58
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