weweswap / app-backend

Utils and APR backend
https://app-backend-production-676d.up.railway.app/docs
MIT License
0 stars 0 forks source link

Feature/wip/zap in #11

Closed masterjacy01 closed 2 weeks ago

masterjacy01 commented 3 weeks ago

Summary by CodeRabbit

Release Notes

coderabbitai[bot] commented 3 weeks ago

Walkthrough

The pull request introduces several updates to the weweswap-backend project, including new dependencies in package.json, the addition of a new smart contract ABI in abi.ts, and the implementation of a ZapInController and ZapInService for handling zap-in operations. It also includes a new DTO for request handling, enhancements to error management in existing services, and the introduction of several TypeScript interfaces related to KyberSwap functionality. Additionally, configuration changes have been made to support the new features.

Changes

File Path Change Summary
package.json Added dependencies: axios-retry (^4.5.0), nestjs-axios-retry (^1.0.7).
src/abis/abi.ts Added new constant arrakisResolverAbi defining a smart contract ABI.
src/api/zap-in/zap-in.controller.spec.ts Introduced a test suite for ZapInController with a single test case.
src/api/zap-in/zap-in.controller.ts Added ZapInController class with a POST method getZapInRoute.
src/api/zap-in/zap-in.module.ts Created ZapInModule to encapsulate zap-in functionality, importing necessary modules.
src/api/zap-in/zap-in.service.spec.ts Introduced a test suite for ZapInService with a single test case.
src/api/zap-in/zap-in.service.ts Added ZapInService class with methods for handling zap-in logic and error management.
src/app.module.ts Integrated ZapInModule and AxiosRetryModule into the application.
src/config/configuration.ts Added arrakisResolverAddress property to configuration object.
src/config/wewe-data-aggregator-config.service.ts Added getter method arrakisResolverAddress in WeweConfigService.
src/contract-connectors/arrakis-contracts/arrakis-contracts.service.ts Added getMintAmounts method and getArrakisResolverContract method in ArrakisContractsService.
src/contract-connectors/erc-20/erc-20.service.ts Updated return type and error handling in getErc20TokenTotalSupply method.
src/dto/GetZapInRouteBodyDto.ts Introduced GetZapInRouteBodyDto class for zap-in request data transfer.
src/shared/class/WeweDataAggregatorConfig.ts Added arrakisResolverAddress property and updated constructor in WeweConfig.
src/shared/types/common.ts Removed ArrakisUnderlyingAmounts interface and ranges type; added ArrakisResolverInput class.
src/shared/types/kyberswap.ts Added several interfaces related to KyberSwap functionality.

Possibly related PRs

Suggested labels

enhancement

Poem

In the garden of code, new blooms arise,
With zap-ins and retries, we reach for the skies.
A hop here, a skip there, our functions take flight,
With contracts and services, all shining so bright!
From ABIs to modules, our work is a treat,
A rabbit's delight, as we code to the beat! 🐇✨


📜 Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
📥 Commits Files that changed from the base of the PR and between c85cdb25c71b6f1458d96b8ca322afb43da67875 and 51be485eeed50fd6d01ac6b6c8db4be62604ee71.
⛔ Files ignored due to path filters (1) * `package-lock.json` is excluded by `!**/package-lock.json`
📒 Files selected for processing (16) * package.json (1 hunks) * src/abis/abi.ts (1 hunks) * src/api/zap-in/zap-in.controller.spec.ts (1 hunks) * src/api/zap-in/zap-in.controller.ts (1 hunks) * src/api/zap-in/zap-in.module.ts (1 hunks) * src/api/zap-in/zap-in.service.spec.ts (1 hunks) * src/api/zap-in/zap-in.service.ts (1 hunks) * src/app.module.ts (2 hunks) * src/config/configuration.ts (1 hunks) * src/config/wewe-data-aggregator-config.service.ts (1 hunks) * src/contract-connectors/arrakis-contracts/arrakis-contracts.service.ts (4 hunks) * src/contract-connectors/erc-20/erc-20.service.ts (3 hunks) * src/dto/GetZapInRouteBodyDto.ts (1 hunks) * src/shared/class/WeweDataAggregatorConfig.ts (2 hunks) * src/shared/types/common.ts (1 hunks) * src/shared/types/kyberswap.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (27)
src/shared/types/common.ts (1)
`1-15`: **Verify the impact of removed entities.** The AI summary mentions the removal of `ArrakisUnderlyingAmounts` interface and `ranges` type. Please ensure that all references to these removed entities have been updated or removed throughout the codebase to maintain consistency. Run the following script to check for any remaining references to the removed entities: If any unexpected references are found, please update or remove them accordingly.
src/dto/GetZapInRouteBodyDto.ts (2)
`1-2`: **LGTM: Imports are appropriate and necessary.** The imports for ApiProperty and IsEthereumAddress are correctly included and are essential for the functionality of this DTO. --- `1-14`: **Overall assessment: Good structure with room for minor enhancements.** The `GetZapInRouteBodyDto` class is well-structured and serves its purpose effectively. The use of decorators for the `vaultAddress` property is commendable. With the suggested improvements for the `inputToken` and `tokenInAmount` properties, this DTO will provide robust input validation and clear API documentation, enhancing the overall quality and maintainability of the codebase.
src/api/zap-in/zap-in.service.spec.ts (2)
`1-2`: **LGTM: Imports are correct and necessary.** The imports for NestJS testing utilities and the ZapInService are appropriate for this test file. --- `4-13`: **LGTM: Test suite setup follows NestJS best practices.** The test suite is well-structured, with proper initialization of the ZapInService in the `beforeEach` block using NestJS's `Test.createTestingModule()`.
src/api/zap-in/zap-in.controller.spec.ts (1)
`1-2`: **LGTM: Import statements are correct and concise.** The necessary testing utilities from NestJS and the ZapInController are properly imported.
src/api/zap-in/zap-in.controller.ts (2)
`5-6`: **LGTM: Controller declaration follows NestJS conventions.** The `@Controller("api/zap-in")` decorator and the exported `ZapInController` class are well-defined and follow NestJS best practices. --- `1-3`: **Verify the import path for GetZapInRouteBodyDto.** The relative import path `"../../dto/GetZapInRouteBodyDto"` seems correct, but it's good practice to ensure it's consistent with your project structure. Run the following script to verify the import path:
✅ Verification successful **Import path for GetZapInRouteBodyDto is correct.**
🏁 Scripts executed The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Description: Verify the existence of GetZapInRouteBodyDto.ts file # Test: Check if the file exists fd -p 'src/dto/GetZapInRouteBodyDto.ts' ``` Length of output: 71
src/api/zap-in/zap-in.module.ts (2)
`1-7`: **LGTM! Good practice with HttpModule configuration.** The imports are well-organized and relevant to the module's functionality. It's particularly good to see the HttpModule being imported with a specific timeout configuration, which is a best practice for managing network requests. --- `1-22`: **LGTM! Clean and well-structured module definition.** The overall structure of the ZapInModule is excellent. It adheres to NestJS module conventions, is concise, and focuses solely on defining the module. The code is clean, well-organized, and consistently formatted.
src/config/configuration.ts (1)
`18-18`: **Verify usage of new configuration property** The addition of `arrakisResolverAddress` to the configuration is straightforward. To ensure its proper integration: 1. Verify that `WeweConfigService` and `WeweConfig` classes have been updated to include this new property, as mentioned in the AI summary. 2. Check that any components using this configuration are properly updated to handle potential undefined values. Run the following script to verify the usage of `arrakisResolverAddress`:
✅ Verification successful **Usage of `arrakisResolverAddress` Verified** The `arrakisResolverAddress` property is properly integrated and consistently used across the relevant classes. All usages handle the property correctly, ensuring no undefined values are unaddressed.
🏁 Scripts executed The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Description: Verify the usage of arrakisResolverAddress across the codebase # Test 1: Check for updates in WeweConfigService echo "Checking WeweConfigService:" rg -A 5 "class WeweConfigService" src/config/wewe-data-aggregator-config.service.ts # Test 2: Check for updates in WeweConfig echo "Checking WeweConfig:" rg -A 10 "class WeweConfig" src/shared/class/WeweDataAggregatorConfig.ts # Test 3: Check for usage of arrakisResolverAddress echo "Checking usage of arrakisResolverAddress:" rg "arrakisResolverAddress" src/ ``` Length of output: 1689
src/shared/types/kyberswap.ts (5)
`1-6`: **LGTM: KyberSwapResponse interface looks good.** The `KyberSwapResponse` interface is well-structured and follows a standard API response format. It includes all necessary fields with appropriate types. --- `8-11`: **LGTM: KyberSwapData interface is well-defined.** The `KyberSwapData` interface correctly encapsulates the main data returned by the KyberSwap API, including the route summary and router address. --- `29-34`: **LGTM: ExtraFee interface is well-defined.** The `ExtraFee` interface comprehensively covers all aspects of additional fees in the swap process. The inclusion of the `isInBps` property is particularly noteworthy, as it allows for flexible fee representation. --- `50-52`: **LGTM: PoolExtra interface is concise and clear.** The `PoolExtra` interface is well-defined with a single, appropriately typed property. It effectively captures the additional context (block number) for a pool. --- `1-52`: **Overall, the KyberSwap type definitions are well-structured and comprehensive.** This file provides a robust type system for KyberSwap-related data, which will greatly enhance type safety and developer experience when working with the KyberSwap API. The interfaces are clear, organized, and cover all necessary aspects of the swap process. A few minor suggestions were made to further improve the code: 1. Adding a comment to explain the nested array structure of the `route` property in `RouteSummary`. 2. Considering a more specific type for the `extra` property in `RouteStep`. These changes would enhance the readability and type safety of the code, but the current implementation is already of high quality.
src/app.module.ts (3)
`11-11`: **LGTM: ZapInModule import added correctly.** The import of ZapInModule aligns with the PR objectives and follows the project's structure convention. --- `40-40`: **LGTM: ZapInModule added to imports array.** The ZapInModule is correctly added to the imports array, which is consistent with the new import statement and the PR objectives. --- Line range hint `1-46`: **Overall, the changes to app.module.ts look good.** The additions of ZapInModule and AxiosRetryModule are well-implemented and align with the PR objectives. The code structure follows NestJS best practices. Consider the minor suggestions for import organization and retry count justification to further improve the code quality.
package.json (2)
`31-31`: **LGTM: Addition of axios-retry dependency.** The addition of `axios-retry` (version ^4.5.0) is appropriate for enhancing HTTP request retry functionality. It's compatible with the existing `@nestjs/axios` dependency and aligns with the PR objectives. --- `31-31`: **Summary: Appropriate additions for HTTP request enhancement.** The additions of `axios-retry` and `nestjs-axios-retry` are well-suited for enhancing HTTP request functionality and retry mechanisms within the NestJS framework. These changes align with the PR objectives and are minimal in scope, focusing solely on the required dependencies for the new feature. To ensure these dependencies are properly utilized, please run the following script to check for their usage in the codebase: Also applies to: 39-39
✅ Verification successful **Verification Successful: Dependencies are properly utilized.** The `axios-retry` and `nestjs-axios-retry` dependencies are correctly imported and configured within `src/app.module.ts`.
🏁 Scripts executed The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Description: Verify the usage of newly added dependencies # Test: Search for imports or uses of axios-retry and nestjs-axios-retry echo "Searching for axios-retry usage:" rg -i 'axios-retry' echo "\nSearching for nestjs-axios-retry usage:" rg -i 'nestjs-axios-retry' echo "\nSearching for AxiosRetryModule in app.module.ts:" rg 'AxiosRetryModule' src/app.module.ts ``` Length of output: 1514
src/shared/class/WeweDataAggregatorConfig.ts (1)
`128-128`: **LGTM! Constructor updated correctly.** The `arrakisResolverAddress` parameter has been properly added to the constructor signature and initialized in the constructor body. The order of parameters is consistent with the property declarations in the class. Also applies to: 135-135
src/contract-connectors/erc-20/erc-20.service.ts (1)
Line range hint `90-99`: **Ensure all callers handle the updated return type of 'getErc20TokenTotalSupply'** The method `getErc20TokenTotalSupply` now returns `Promise` instead of `Promise`. Verify that all parts of the codebase that call this method are updated to accommodate this change and no longer expect an `undefined` return value. Run the following script to find and review all usages of `getErc20TokenTotalSupply`:
✅ Verification successful **** All callers correctly handle the updated return type of `getErc20TokenTotalSupply` without expecting `undefined`.
🏁 Scripts executed The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Description: Find all usages of getErc20TokenTotalSupply to ensure callers handle the updated return type. # Test: Search for all occurrences of getErc20TokenTotalSupply in the codebase. # Expectation: Callers should not check for undefined return values. rg 'getErc20TokenTotalSupply\(' -A 5 ``` Length of output: 1429
src/contract-connectors/arrakis-contracts/arrakis-contracts.service.ts (2)
`14-14`: **Import Statement Confirmed** The import of `ArrakisResolverInput` from `"../../shared/types/common"` is necessary for the new `getMintAmounts` method and is correctly added. --- `5-5`: **Updated ABI Imports Verified** The addition of `arrakisResolverAbi` to the imports from `"../../abis/abi"` is appropriate, as it supports interacting with the Arrakis Resolver contract in the new methods.
src/api/zap-in/zap-in.service.ts (1)
`250-255`: **Verify calculation logic for `calculatedAmount`** The computation of `calculatedAmount` in `calculateSwapAmounts` may lead to precision loss or incorrect amounts due to floating-point arithmetic and order of operations. Consider revising the calculation to ensure accurate results, especially when working with BigInt and decimals.
src/abis/abi.ts (1)
`2206-2348`: **LGTM!** The addition of `arrakisResolverAbi` is consistent with the existing codebase, and the ABI definitions appear to be correctly structured.
--- 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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
🪧 Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , 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 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. ### 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.