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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/rest-api/src/controllers/bridgeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ export const bridgeController = async (req, res) => {
quote.originQuery.tokenOut
)

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


const callData =
destAddress && originUserAddress
? await Synapse.bridge(
Expand All @@ -62,8 +68,8 @@ export const bridgeController = async (req, res) => {
Number(toChain),
fromToken,
amountInWei,
quote.originQuery,
quote.destQuery
originQuery,
destQuery
)
: null

Expand Down
Loading