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

REST API Migration #3049

Merged
merged 5 commits into from
Aug 29, 2024
Merged

REST API Migration #3049

merged 5 commits into from
Aug 29, 2024

Conversation

Defi-Moses
Copy link
Collaborator

@Defi-Moses Defi-Moses commented Aug 22, 2024

Migrates from heroku to the new server provider which enables auto-deploys from the target branch.

Also restructured the api:

  • standardized constants to be the same as the widget so that updates are relatively easy
  • added fallbacks for rpcs which was preventing quotes
  • fixed all linting errors and simplified code.

The existing code in the repo is not connected to the live deployment so overwriting does not cause any issues.

@aureliusbtc can you setup api.synapseprotocol.com to put the finishing touches on this? Should drastically improve maintenence/cleanliness.

Summary by CodeRabbit

  • New Features

    • Introduced new token entries, including 'JEWEL' and 'SPEC,' to enhance token interactions.
    • Added comprehensive constants defining various blockchain networks to improve accessibility.
  • Improvements

    • Enhanced type safety and clarity in token definitions and API response handling.
    • Updated build and lint scripts for better project management and consistency.
  • Bug Fixes

    • Improved query parameter handling across multiple endpoints for better input validation.
  • Documentation

    • Enhanced TypeScript configuration comments for better clarity on compiler options.

@Defi-Moses Defi-Moses requested a review from aureliusbtc August 22, 2024 18:10
@Defi-Moses Defi-Moses requested a review from trajan0x as a code owner August 22, 2024 18:10
Copy link
Contributor

coderabbitai bot commented Aug 22, 2024

Walkthrough

The project has undergone updates that include modifications to the package.json scripts, enhancements to type safety, and changes in constants defining blockchain networks and tokens. New dependencies have been added, several functions and constants have been refactored for clarity, and a new TypeScript definition file has been introduced to standardize token and chain definitions.

Changes

File(s) Change Summary
packages/rest-api/package.json Updated script commands, added lodash to dependencies, and introduced @types/supertest in devDependencies.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant API
    participant Token
    participant BridgeMap
    participant Chain

    User->>API: Request Token Info
    API->>Token: Retrieve Token Data
    Token->>BridgeMap: Check Bridgeable Tokens
    BridgeMap->>Token: Return Token Data
    API->>User: Respond with Token Info
Loading

🐰 In the code we hop and play,
With tokens bright and scripts astray,
A bridge to chain, a map so clear,
Our project blooms, let's give a cheer!
With types refined and imports neat,
Together we code, oh what a treat!


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.

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, codebase verification and nitpick comments (1)
packages/rest-api/package.json (1)

26-33: Remove lodash from devDependencies in rest-api package

The lodash library is used in the runtime code of the rest-api package, specifically in src/constants/chains.ts. Therefore, it should remain in dependencies. However, there is no evidence of its usage in a development context within this package, making its presence in devDependencies unnecessary.

  • Remove lodash from devDependencies in packages/rest-api/package.json.
Analysis chain

Verify the necessity of lodash in both dependencies and devDependencies.

Ensure that lodash is required in both sections, as it might be redundant.

Run the following script to verify the usage of lodash in the codebase:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of lodash in the codebase.

# Test: Search for lodash usage. Expect: Occurrences in both runtime and development contexts.
rg --type js --type ts 'lodash'

Length of output: 7172


Script:

#!/bin/bash
# Description: Verify the usage of lodash specifically within the rest-api package.

# Test: Search for lodash usage in the rest-api package to determine the context.
rg --type js --type ts 'lodash' packages/rest-api

Length of output: 114

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ead107f and b49f7cd.

Files selected for processing (7)
  • packages/rest-api/package.json (2 hunks)
  • packages/rest-api/src/app.ts (13 hunks)
  • packages/rest-api/src/constants/bridgeMap.ts (39 hunks)
  • packages/rest-api/src/constants/bridgeable.ts (17 hunks)
  • packages/rest-api/src/constants/chains.ts (1 hunks)
  • packages/rest-api/src/types/index.d.ts (1 hunks)
  • packages/rest-api/tsconfig.json (2 hunks)
Additional context used
Biome
packages/rest-api/src/types/index.d.ts

[error] 2-2: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 3-3: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

Additional comments not posted (14)
packages/rest-api/tsconfig.json (1)

3-4: LGTM! Inclusion of ./src/config/**/* and comments improve clarity.

The expansion of the include array and the addition of comments enhance the project structure and documentation.

Also applies to: 14-14

packages/rest-api/package.json (1)

9-15: LGTM! Script changes enhance the build and linting process.

The reorganization and addition of scripts streamline the build and linting processes.

packages/rest-api/src/app.ts (6)

5-10: LGTM! Import restructuring.

The import statements have been updated to reflect new paths, aligning with the project's reorganization.


12-12: LGTM! Simplified chains variable.

The chains variable is now directly assigned from CHAINS_ARRAY, simplifying the code.


Line range hint 13-28: LGTM! Converted to arrow function.

The findTokenInfo function has been converted to an arrow function, improving consistency with modern JavaScript practices.


32-43: LGTM! Refactored HTML generation.

The logic for generating HTML for tokens has been refactored to utilize template literals and Object.entries, enhancing readability and maintainability.


88-88: LGTM! Improved query parameter handling.

Query parameters are explicitly converted to strings, improving robustness against unexpected input types.

Also applies to: 177-178, 276-276, 371-372


237-247: LGTM! Optimized asynchronous operations.

The use of Promise.all optimizes performance by allowing concurrent execution of asynchronous tasks. Consider improving error handling for better user feedback.

Also applies to: 436-452

packages/rest-api/src/constants/chains.ts (2)

5-491: LGTM! Comprehensive chain definitions.

Each chain is defined with detailed properties, ensuring consistency and completeness.


493-495: LGTM! Flexible export statements.

The chains are exported as CHAINS, CHAINS_ARRAY, and CHAINS_BY_ID, providing flexibility in accessing chain data.

packages/rest-api/src/constants/bridgeable.ts (1)

Line range hint 6-1391: LGTM! Detailed token definitions.

Each token is defined as a BridgeableToken with detailed properties, ensuring consistency and completeness.

packages/rest-api/src/constants/bridgeMap.ts (3)

24-30: New entry for 'JEWEL' added.

The new entry for the token 'JEWEL' with address 0x12f79f8c1A6e47a9b5F0796FDb008Bdc182fa19e has been added correctly with appropriate properties.


218-224: New entry for 'SPEC' added.

The new entry for the token 'SPEC' with address 0xAdF7C35560035944e805D98fF17d58CDe2449389 has been added correctly with appropriate properties.


34-42: Inclusion of 'RFQ.USDC' in origin and destination arrays.

The inclusion of 'RFQ.USDC' in the origin and destination arrays for multiple tokens enhances the flexibility of token interactions, aligning with the broader integration of the RFQ mechanism.

Also applies to: 71-79, 101-109, 124-132, 161-169, 191-199, 256-264, 286-294, 311-312, 355-363, 368-376, 391-399, 404-412, 424-432, 444-452, 876-882, 1113-1121, 1250-1258, 1279-1287, 1298-1306, 1317-1325, 1349-1357, 1384-1392, 1397-1405, 1417-1425, 1441-1449, 1472-1480, 1485-1493, 1495-1503, 1508-1516, 1528-1536, 1796-1804, 1826-1834, 1880-1888

Comment on lines +2 to +3
addresses: {}
decimals: {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid using {} as a type.

Prefer explicitly defining the object shape for better type safety.

Apply this diff to define the object shape:

 export interface BridgeableToken {
-  addresses: {}
-  decimals: {}
+  addresses: { [key: string]: string }
+  decimals: { [key: string]: number }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
addresses: {}
decimals: {}
addresses: { [key: string]: string }
decimals: { [key: string]: number }
Tools
Biome

[error] 2-2: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 3-3: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 25.29498%. Comparing base (0e64a98) to head (e0758ac).
Report is 13 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (0e64a98) and HEAD (e0758ac). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (0e64a98) HEAD (e0758ac)
promexporter 1 0
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #3049         +/-   ##
===================================================
- Coverage   32.92244%   25.29498%   -7.62747%     
===================================================
  Files            533         781        +248     
  Lines          33099       56869      +23770     
  Branches          82          82                 
===================================================
+ Hits           10897       14385       +3488     
- Misses         21231       40999      +19768     
- Partials         971        1485        +514     
Flag Coverage Δ
packages 90.56974% <ø> (ø)
promexporter ?

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 27, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: e0758ac
Status: ✅  Deploy successful!
Preview URL: https://fd0df7d4.sanguine-fe.pages.dev
Branch Preview URL: https://api-migration.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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b49f7cd and e0758ac.

Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (1)
  • packages/rest-api/package.json (2 hunks)
Files skipped from review due to trivial changes (1)
  • packages/rest-api/package.json

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.

3 participants