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

fix(rest-api): apply default slippage #3489

Merged
merged 1 commit into from
Jan 14, 2025
Merged

Conversation

ChiTimesChi
Copy link
Collaborator

@ChiTimesChi ChiTimesChi commented Jan 13, 2025

Description
Isolated changes from #3479 wrt default slippage settings in rest-api.

Summary by CodeRabbit

  • New Features
    • Enhanced bridge quote processing with slippage adjustments
  • Improvements
    • Refined bridge quote handling to optimize transaction parameters before execution

Copy link
Contributor

coderabbitai bot commented Jan 13, 2025

Walkthrough

The changes modify the bridge controller in the REST API to introduce a new step for applying slippage adjustments to bridge quotes. The implementation now uses the applyBridgeSlippage method from the Synapse service to process quote parameters before bridging. This adds an additional preprocessing step to handle quote modifications, potentially improving the accuracy of bridge transactions by dynamically adjusting the quote parameters.

Changes

File Change Summary
packages/rest-api/src/controllers/bridgeController.ts Added slippage adjustment step using Synapse.applyBridgeSlippage() method before bridge execution

Poem

🐰 A bridge quote hops with grace,
Slippage adjusted, finding its place
Parameters dance, numbers realign
Through Synapse's magical design
A rabbit's leap of financial might! 🌉

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.

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
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aaf6978 and 03d55bf.

📒 Files selected for processing (1)
  • packages/rest-api/src/controllers/bridgeController.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: test
  • GitHub Check: SonarCloud
  • GitHub Check: lint
  • GitHub Check: changesets-integrity-checker
  • GitHub Check: label-statuses
  • GitHub Check: lint
  • GitHub Check: test
🔇 Additional comments (1)
packages/rest-api/src/controllers/bridgeController.ts (1)

71-72: Verify the impact of slippage adjustments on bridge operations.

Since this change affects the critical path handling user funds, please ensure:

  1. The adjusted queries maintain backward compatibility.
  2. Comprehensive testing is in place, especially for edge cases.
  3. The changes have been tested with different bridge modules.

Run the following script to check for existing tests:

✅ Verification successful

Slippage adjustments are safely implemented and well-tested

The changes to the bridge controller correctly utilize the SDK's comprehensive slippage adjustment system, which:

  • Has thorough test coverage across multiple bridge modules
  • Implements specific safety mechanisms for different bridge types
  • Preserves query integrity during adjustments
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for relevant test coverage

# Look for bridge-related tests
rg -l "bridge.*test" --type ts

# Look for specific test cases related to slippage
rg "describe.*slippage|test.*slippage" --type ts

Length of output: 1244


Script:

#!/bin/bash
# Check for imports and usage of bridge controller in test files
rg -A 5 "bridgeController|BridgeController" --type ts

# Look for the specific query parameters in the codebase
rg -A 3 "originQuery|destQuery" --type ts

Length of output: 65794

Comment on lines +56 to +60
const { originQuery, destQuery } = Synapse.applyBridgeSlippage(
quote.bridgeModuleName,
quote.originQuery,
quote.destQuery
)
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

Add error handling and type safety for slippage application.

The new slippage adjustment logic should include:

  1. Error handling for potential failures in applyBridgeSlippage.
  2. Type annotations for the destructured values.
  3. Validation of the returned queries before use.
+        let adjustedQueries;
+        try {
           const { originQuery, destQuery } = Synapse.applyBridgeSlippage(
             quote.bridgeModuleName,
             quote.originQuery,
             quote.destQuery
           );
+          // Validate the returned queries
+          if (!originQuery?.tokenOut || !destQuery?.tokenOut) {
+            throw new Error('Invalid queries returned from slippage adjustment');
+          }
+          adjustedQueries = { originQuery, destQuery };
+        } catch (error) {
+          logger.error('Failed to apply bridge slippage', {
+            error: error.message,
+            bridgeModule: quote.bridgeModuleName,
+          });
+          // Fallback to original queries
+          adjustedQueries = {
+            originQuery: quote.originQuery,
+            destQuery: quote.destQuery,
+          };
+        }
+        const { originQuery, destQuery } = adjustedQueries;

Committable suggestion skipped: line range outside the PR's diff.

Copy link

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 03d55bf
Status: ✅  Deploy successful!
Preview URL: https://27b47957.sanguine-fe.pages.dev
Branch Preview URL: https://fix-rest-api-slippage.sanguine-fe.pages.dev

View logs

@ChiTimesChi ChiTimesChi merged commit f647a1c into master Jan 14, 2025
33 of 35 checks passed
@ChiTimesChi ChiTimesChi deleted the fix/rest-api-slippage branch January 14, 2025 18:20
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