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

Making address (origin and dest) mandated in rest API #3459

Merged
merged 3 commits into from
Dec 16, 2024
Merged

Conversation

Defi-Moses
Copy link
Collaborator

@Defi-Moses Defi-Moses commented Dec 12, 2024

Change was made to mandate origin and dest addresses in /bridge requests (if call data is to be returned). This is in advance of some of the SIN changes (complex destination chain actions)

Summary by CodeRabbit

  • New Features

    • Introduced new API endpoints: /destinationTokens, /destinationTx, and /synapseTxId.
  • Improvements

    • Updated documentation for the /bridge endpoint to clarify parameter requirements.
    • Enhanced error handling for invalid addresses in the bridge route.
    • Standardized error responses across several endpoints.
  • Bug Fixes

    • Adjusted logic to require both originUserAddress and destAddress for bridge operations.
  • Documentation

    • Updated OpenAPI documentation for clarity and consistency across endpoints.
    • Marked /bridgeTxInfo and /swapTxInfo endpoints as deprecated.
    • Updated Synapse REST API documentation to reflect changes in parameter requirements for the /bridge endpoint.

c46ada8: docs preview link
770d6d9: docs preview link

Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Walkthrough

The pull request introduces changes to the bridgeController, bridgeRoute, and associated test files. The bridgeController now requires both destAddress and originUserAddress to invoke the Synapse.bridge method. The OpenAPI documentation for the /bridge endpoint has been updated to reflect these requirements. Test cases have been modified to ensure they align with the new logic, including additional checks for invalid addresses. Furthermore, the swagger.json file has been updated with new endpoints and modifications to existing ones, enhancing the API's functionality and documentation.

Changes

File Path Change Summary
packages/rest-api/src/controllers/bridgeController.ts Updated logic in bridgeController to require both destAddress and originUserAddress for Synapse.bridge method invocation. Error handling remains unchanged.
packages/rest-api/src/routes/bridgeRoute.ts Modified OpenAPI documentation for /bridge endpoint to clarify that originUserAddress and destAddress are required for callData generation.
packages/rest-api/src/tests/bridgeRoute.test.ts Updated test cases to require both originUserAddress and destAddress. Added new test for missing originUserAddress and enhanced error handling for invalid addresses.
packages/rest-api/swagger.json Added new endpoints (/destinationTokens, /destinationTx, /synapseTxId), modified /bridge endpoint's destAddress requirement, and marked some endpoints as deprecated.
docs/bridge/docs/02-Bridge/02-REST-API.md Updated documentation for /bridge endpoint to reflect the requirement for both originUserAddress and destAddress parameters.

Possibly related PRs

Suggested labels

size/l

Suggested reviewers

  • trajan0x
  • abtestingalpha

Poem

🐇 In the meadow where bridges gleam,
Two addresses now form a team.
With originUser and dest in sight,
Our bridge will soar, oh what a flight!
So hop along, let’s make it right,
Together we’ll code through day and night! 🌟

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. This feature will be included in our Pro Plan when released.


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. (Experiment)
  • @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

🧹 Outside diff range and nitpick comments (6)
packages/rest-api/swagger.json (3)

Line range hint 204-209: Update parameter description to reflect requirement

The parameter description should be updated to indicate that this is a required field for generating call data.

Apply this diff to clarify the requirement:

-            "description": "The destination address of the user on the destination chain"
+            "description": "The destination address of the user on the destination chain. Required when call data needs to be generated."

Line range hint 1-1200: Consider adding request/response examples for error cases

The API documentation would benefit from examples showing error responses when required addresses are missing or invalid.

Add example error responses like:

{
  "error": {
    "value": "",
    "message": "destAddress is required for generating call data",
    "field": "destAddress",
    "location": "query"
  }
}

Line range hint 1-1200: Document migration path from deprecated endpoints

While /bridgeTxInfo is marked as deprecated in favor of /bridge, the documentation should provide a clear migration guide for users.

Add a migration guide section in the description:

-        "description": "[Deprecated] Originally used to get Bridge transaction information",
+        "description": "[Deprecated] Originally used to get Bridge transaction information. To migrate, use the /bridge endpoint with destAddress and originUserAddress parameters to receive call data in the response.",
packages/rest-api/src/controllers/bridgeController.ts (1)

56-68: Consider improving the conditional logic readability

While the logic is correct, the nested ternary operator could be made more readable using an if statement, especially since it involves multiple conditions and a complex function call.

Consider this alternative implementation:

-        const callData =
-          destAddress && originUserAddress
-            ? await Synapse.bridge(
-                destAddress,
-                quote.routerAddress,
-                Number(fromChain),
-                Number(toChain),
-                fromToken,
-                amountInWei,
-                quote.originQuery,
-                quote.destQuery
-              )
-            : null
+        let callData = null;
+        if (destAddress && originUserAddress) {
+          callData = await Synapse.bridge(
+            destAddress,
+            quote.routerAddress,
+            Number(fromChain),
+            Number(toChain),
+            fromToken,
+            amountInWei,
+            quote.originQuery,
+            quote.destQuery
+          );
+        }
packages/rest-api/src/tests/bridgeRoute.test.ts (2)

177-185: Use different addresses for origin and destination

Using the same address for both originUserAddress and destAddress might mask potential issues. Consider using different valid addresses to ensure the system handles distinct addresses correctly.

-      destAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
-      originUserAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
+      destAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
+      originUserAddress: '0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199',

Line range hint 177-211: Add test cases for edge scenarios

The test suite should include additional edge cases:

  1. When destAddress is provided but originUserAddress is missing
  2. When addresses are provided but in an incorrect format (e.g., wrong checksum)

Here's a suggested test case:

it('should return bridge quotes without callData when only destAddress is provided', async () => {
  const response = await request(app).get('/bridge').query({
    fromChain: '1',
    toChain: '10',
    fromToken: USDC.addresses[1],
    toToken: USDC.addresses[10],
    amount: '1000',
    destAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
  });

  expect(response.status).toBe(200);
  expect(response.body[0].callData).toBeNull();
});
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f09d28b and 18be26f.

📒 Files selected for processing (4)
  • packages/rest-api/src/controllers/bridgeController.ts (1 hunks)
  • packages/rest-api/src/routes/bridgeRoute.ts (1 hunks)
  • packages/rest-api/src/tests/bridgeRoute.test.ts (2 hunks)
  • packages/rest-api/swagger.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/rest-api/src/routes/bridgeRoute.ts
🔇 Additional comments (1)
packages/rest-api/src/controllers/bridgeController.ts (1)

56-68: Verify impact on API consumers

The change requires both destAddress and originUserAddress for callData generation, which might affect existing API consumers that only provide destAddress.

Let's check for potential API consumers:

packages/rest-api/swagger.json Show resolved Hide resolved
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

🧹 Outside diff range and nitpick comments (1)
docs/bridge/docs/02-Bridge/02-REST-API.md (1)

Line range hint 1-100: Update the endpoint documentation sections

The commented-out endpoint documentation sections need to be updated to reflect:

  1. The deprecation of /bridgeTxInfo endpoint
  2. The new mandatory parameters for /bridge endpoint

Please update the /bridge endpoint documentation to:

  1. Mark originUserAddress and destAddress as required parameters
  2. Add a note about /bridgeTxInfo being consolidated into this endpoint
  3. Update the example URL to include both addresses
 ### `/bridge`
 
 Get a token bridge quote.
 
 #### Parameters
 
 * `fromChain` (int): `chainId` of origin chain
 * `toChain` (int): `chainId` of destination chain
 * `fromToken` (string): Token address to bridge
 * `toToken` (string): Token address to bridge to
 * `amount` (int): Amount to bridge
-* **Optional**`originUserAddress` (string): Address of the user bridging the token
+* `originUserAddress` (string): Address of the user bridging the token (required)
+* `destAddress` (string): Address to receive the bridged tokens (required)
+
+> Note: As of December 12, 2024, both `originUserAddress` and `destAddress` are required parameters to generate call data.
 
 #### Example
 
-[`/bridge?fromChain=1&toChain=10&fromToken=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&toToken=0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85&amount=1000000`]
+[`/bridge?fromChain=1&toChain=10&fromToken=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&toToken=0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85&amount=1000000&originUserAddress=0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5&destAddress=0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5`]

Also, remove or update the /bridgeTxInfo section to indicate its deprecation:

-### `/bridgeTxInfo`
-Used to get transaction data for executing a bridge.
+### `/bridgeTxInfo` (Deprecated)
+
+> Note: This endpoint has been deprecated as of November 19, 2024. Please use the `/bridge` endpoint instead, which now returns call data when both `originUserAddress` and `destAddress` are provided.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 18be26f and 171720c.

📒 Files selected for processing (1)
  • docs/bridge/docs/02-Bridge/02-REST-API.md (1 hunks)
🔇 Additional comments (1)
docs/bridge/docs/02-Bridge/02-REST-API.md (1)

29-30: LGTM on the version history updates!

The changes clearly document:

  1. The consolidation of /bridgeTxInfo into /bridge endpoint
  2. The new requirement for both addresses in /bridge endpoint

Copy link

cloudflare-workers-and-pages bot commented Dec 12, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5fe94c1
Status: ✅  Deploy successful!
Preview URL: https://e5a7a80a.sanguine-fe.pages.dev
Branch Preview URL: https://api-fix-tests.sanguine-fe.pages.dev

View logs

Copy link

codecov bot commented Dec 12, 2024

Bundle Report

Changes will decrease total bundle size by 3.05MB (-8.56%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
sdk-router-@synapsecns/sdk-router-esm* 255.26kB 609 bytes (0.24%) ⬆️
sdk-router-@synapsecns/sdk-router-cjs* 117.55kB 312 bytes (0.27%) ⬆️
explorer-ui-server-cjs* 724.31kB 141.75kB (-16.37%) ⬇️
explorer-ui-client-array-push* 2.17MB 146.63kB (-6.34%) ⬇️
synapse-interface-client-array-push* 7.41MB 132.5kB (1.82%) ⬆️
synapse-interface-server-cjs* 1.66MB 160.56kB (10.74%) ⬆️
widget-cjs-esm* 271.27kB 2.03kB (-0.74%) ⬇️
docs-bridge-client-array-push 7.51MB 393.18kB (-4.98%) ⬇️
docs-bridge-server-cjs 11.86MB 3.01MB (-20.25%) ⬇️
synapse-constants-esm-cjs* 174.63kB 174.63kB (100%) ⬆️
synapse-constants-cjs-esm* 174.18kB 174.18kB (100%) ⬆️

ℹ️ *Bundle size includes cached data from a previous commit

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.

Changes LGTM - let's add a new unit test though.

@github-actions github-actions bot added size/s and removed size/xs labels Dec 14, 2024
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

🧹 Outside diff range and nitpick comments (2)
packages/rest-api/src/tests/bridgeRoute.test.ts (2)

177-185: Consider using different addresses for origin and destination

While the test correctly validates the presence of both addresses, using the same address for both originUserAddress and destAddress might not catch potential edge cases where the handling differs between the two parameters.

-      destAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
-      originUserAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
+      destAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
+      originUserAddress: '0x1234567890123456789012345678901234567890',

Line range hint 177-242: Consider adding tests for additional edge cases

To improve test coverage, consider adding test cases for:

  1. Empty string addresses
  2. Addresses with incorrect checksum
  3. Zero address (0x0000...0000)

These edge cases would help ensure robust input validation.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 171720c and 5fe94c1.

📒 Files selected for processing (1)
  • packages/rest-api/src/tests/bridgeRoute.test.ts (2 hunks)
🔇 Additional comments (3)
packages/rest-api/src/tests/bridgeRoute.test.ts (3)

204-211: Add complementary test case as requested

While this test case verifies behavior when only originUserAddress is provided, we should also add the complementary test case where only destAddress is supplied, as suggested in the previous review.


213-220: LGTM!

The test case properly validates that callData is null when originUserAddress is not provided.


Line range hint 229-242: LGTM!

The test case properly validates error handling for invalid destAddress input.

@Defi-Moses Defi-Moses merged commit 31003b0 into master Dec 16, 2024
36 of 38 checks passed
@Defi-Moses Defi-Moses deleted the api/fix-tests branch December 16, 2024 19:34
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