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

add afflaiteReferredMakerRebates field to response #2473

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

jerryfan01234
Copy link
Contributor

@jerryfan01234 jerryfan01234 commented Oct 4, 2024

Changelist

modify response according to discussion with Fuul

Test Plan

[Describe how this PR was tested (if applicable)]

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Summary by CodeRabbit

  • New Features

    • Enhanced API responses with the addition of affiliateReferredMakerRebates in affiliate snapshots.
  • Bug Fixes

    • Updated error message for addressFilter validation to clarify input requirements.
  • Documentation

    • Updated API documentation to reflect new Testnet URL and example responses, including the new affiliateReferredMakerRebates field.
  • Tests

    • Introduced comprehensive tests for various API endpoints related to affiliates to ensure proper functionality.

Copy link
Contributor

coderabbitai bot commented Oct 4, 2024

Walkthrough

This pull request introduces extensive testing for the affiliates-controller in version 4 of the API, focusing on various endpoints such as /metadata, /address, /snapshot, and /total_volume. It also updates the API documentation to reflect a new Testnet base URL and enhances the swagger.json schema by adding a new property, affiliateReferredMakerRebates, to the AffiliateSnapshotResponseObject. Additionally, the getSnapshot method within the AffiliatesController is modified to include this new property, along with clarifications to validation error messages.

Changes

File Change Summary
indexer/services/comlink/__tests__/controllers/api/v4/affiliates-controller.test.ts Added tests for /metadata, /address, /snapshot, and /total_volume endpoints; introduced helper function affiliateInfoCreateToResponseObject.
indexer/services/comlink/public/api-documentation.md Updated Testnet base URL from https://indexer.v4testnet.dydx.exchange/v4 to https://dydx-testnet.imperator.co/v4 across multiple endpoints.
indexer/services/comlink/public/swagger.json Updated AffiliateSnapshotResponseObject schema to include new property affiliateReferredMakerRebates of type number.
indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts Added affiliateReferredMakerRebates property to getSnapshot method; updated error message for addressFilter validation.
indexer/services/comlink/src/types.ts Added affiliateReferredMakerRebates: number to AffiliateSnapshotResponseObject interface.

Possibly related PRs

Suggested labels

protocol, proto

Suggested reviewers

  • affanv14
  • Christopher-Li

Poem

🐰 In the realm of code so bright,
New tests emerge, a joyful sight!
With affiliates now well-defined,
Their snapshots clear, no need to mind.
A URL change, a schema's grace,
In our code, we find our place! 🌟


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 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 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 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: 0

🧹 Outside diff range and nitpick comments (5)
indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts (1)

178-178: LGTM with a minor suggestion.

The addition of affiliateReferredMakerRebates to the response object aligns with the PR objective. Good job on using Number() to ensure type consistency.

Consider updating the PR description to correct the spelling from 'afflaiteReferredMakerRebates' to 'affiliateReferredMakerRebates' for consistency with the implemented code.

indexer/services/comlink/__tests__/controllers/api/v4/affiliates-controller.test.ts (1)

383-383: Typo in PR objective

There's a typo in the PR objective. It mentions "afflaiteReferredMakerRebates" instead of "affiliateReferredMakerRebates". Please update the PR description to correct this typo for clarity.

indexer/services/comlink/src/types.ts (1)

736-736: LGTM! Consider addressing the typo in the PR objective.

The addition of the affiliateReferredMakerRebates property to the AffiliateSnapshotResponseObject interface is correct and aligns with the PR objective. The property name follows the existing naming convention, and the number type is appropriate for representing rebates.

There appears to be a typo in the PR objective: 'afflaiteReferredMakerRebates' should be 'affiliateReferredMakerRebates'. Consider updating the PR description for clarity.

indexer/services/comlink/public/swagger.json (1)

Line range hint 314-331: LGTM! Consider adding a description for the new property.

The addition of the affiliateReferredMakerRebates property to the AffiliateSnapshotResponseObject schema is well-integrated and consistent with the existing structure. The type, format, and inclusion in the required fields are appropriate.

Consider adding a description for the new affiliateReferredMakerRebates property to provide more context about its purpose and usage. This would improve the API documentation and make it easier for consumers to understand the meaning of this field.

indexer/services/comlink/public/api-documentation.md (1)

4252-4253: New fields added to AffiliateSnapshotResponseObject. Please provide documentation.

Two new fields, affiliateReferredTakerFees and affiliateReferredMakerRebates, have been added to the AffiliateSnapshotResponseObject. This addition aligns with the PR objectives.

Could you please add a brief description for these new fields in the documentation? This will help API users understand the purpose and content of these fields.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between eefff67 and 415518c.

📒 Files selected for processing (5)
  • indexer/services/comlink/tests/controllers/api/v4/affiliates-controller.test.ts (1 hunks)
  • indexer/services/comlink/public/api-documentation.md (79 hunks)
  • indexer/services/comlink/public/swagger.json (2 hunks)
  • indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts (1 hunks)
  • indexer/services/comlink/src/types.ts (1 hunks)
🔇 Additional comments (12)
indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts (2)

Line range hint 321-321: Improved error message clarity.

The updated error message for addressFilter provides clearer guidance on the expected input format. This change enhances the API's user-friendliness and aligns with best practices for clear error messages.


Line range hint 1-424: Overall assessment: Changes look good and align with PR objectives.

The modifications to add the affiliateReferredMakerRebates field to the response and update the error message for addressFilter have been implemented correctly. These changes enhance the functionality and user experience of the API without introducing any apparent issues.

To ensure the changes are properly integrated, please run the existing test suite and consider adding new tests to cover the added affiliateReferredMakerRebates field in the response.

indexer/services/comlink/__tests__/controllers/api/v4/affiliates-controller.test.ts (3)

383-383: LGTM: New field added correctly

The new field affiliateReferredMakerRebates has been correctly added to the response object in the affiliateInfoCreateToResponseObject helper function. This change aligns with the PR objective to include this information in the response.


Line range hint 1-385: Summary of review findings

  1. The new field affiliateReferredMakerRebates has been correctly added to the affiliateInfoCreateToResponseObject helper function.
  2. Existing snapshot tests may need to be updated to include assertions for the new field. Please verify and update if necessary.
  3. There's a typo in the PR objective ("afflaiteReferredMakerRebates" instead of "affiliateReferredMakerRebates").

Next steps:

  1. Verify and update snapshot tests if needed.
  2. Correct the typo in the PR description.
  3. Ensure that the changes are tested thoroughly, as the "Test Plan" section in the PR description is empty.

Once these points are addressed, the changes look good to merge.


Line range hint 136-307: Verify impact of helper function changes on snapshot tests

The affiliateInfoCreateToResponseObject helper function has been modified to include a new field affiliateReferredMakerRebates. Please ensure that the snapshot tests in this section accurately reflect this change and that the expected responses include the new field where appropriate.

To verify this, you can run the following script:

If the script doesn't return any results, consider updating the relevant test cases to include assertions for the new field.

✅ Verification successful

Action Required: Update Shell Script to Search TypeScript Files

Please run the following script to check if the affiliateReferredMakerRebates field is included in the snapshot tests:


Snapshot Tests Updated Correctly

The snapshot tests now include the affiliateReferredMakerRebates field as required.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if snapshot tests include the new affiliateReferredMakerRebates field

# Test: Search for affiliateReferredMakerRebates in snapshot tests
rg --type typescript 'affiliateReferredMakerRebates' indexer/services/comlink/__tests__/controllers/api/v4/affiliates-controller.test.ts

Length of output: 171


Script:

# 
#!/bin/bash
# Description: Check if snapshot tests include the new affiliateReferredMakerRebates field

# Search for affiliateReferredMakerRebates in TypeScript test files
rg 'affiliateReferredMakerRebates' --glob '*.ts' --glob '*.tsx' indexer/services/comlink/__tests__/controllers/api/v4/affiliates-controller.test.ts

Length of output: 222

indexer/services/comlink/src/types.ts (2)

736-736: Confirm database schema changes and migration plan

The addition of affiliateReferredMakerRebates to the AffiliateSnapshotResponseObject interface might require corresponding changes in the database schema. To ensure data consistency and avoid potential issues:

  1. Verify if a database schema update is needed to store this new information.
  2. If a schema change is required, ensure a data migration plan is in place.
  3. Update the PR description to include information about any necessary database changes and migration steps.

Could you please confirm if any database schema changes are needed for this new field? If so, please outline the migration plan in the PR description.


736-736: Verify integration of the new property in the codebase

While the addition of affiliateReferredMakerRebates to the AffiliateSnapshotResponseObject interface is correct, we should ensure proper integration across the codebase:

  1. Update any code constructing or using AffiliateSnapshotResponseObject to include the new property.
  2. Revise API documentation to reflect this new field.
  3. Adjust any serialization/deserialization logic for this object if necessary.
  4. Update or add test cases to cover the new property.

To help verify the integration, you can run the following script:

indexer/services/comlink/public/swagger.json (1)

Line range hint 1-2893: Summary: API specification updated with new affiliate-related field

The changes to the Swagger/OpenAPI specification are focused and well-implemented. The addition of the affiliateReferredMakerRebates field to the AffiliateSnapshotResponseObject schema enhances the API's capability to provide more detailed affiliate-related information.

This update aligns with the PR objectives to modify the response structure based on discussions with Fuul. The change is backwards-compatible and should not break existing integrations. However, API consumers should be notified of this addition to take advantage of the new field.

To ensure the new field is properly implemented, please run the following verification script:

This script will help verify that the new field is properly implemented in handlers, services, and tests, as well as check for any related database changes.

indexer/services/comlink/public/api-documentation.md (4)

31-31: Python code sample updated correctly.

The base URL in the Python code sample has been properly updated to match the new Testnet URL.


49-49: JavaScript code sample updated correctly.

The base URL in the JavaScript code sample has been properly updated to match the new Testnet URL.


4294-4295: AffiliateSnapshotResponse updated consistently.

The new fields affiliateReferredTakerFees and affiliateReferredMakerRebates have been correctly added to the AffiliateSnapshotResponse schema, maintaining consistency with the AffiliateSnapshotResponseObject changes.


9-9: Testnet base URL updated. Please verify the new endpoint.

The base URL for the Testnet environment has been updated. This change aligns with the PR objectives.

Please run the following script to verify that the new Testnet URL is accessible and returns a valid response:

Ensure that the response includes a 200 OK status code, indicating that the endpoint is functional.

✅ Verification successful

Testnet URL is accessible and functional.

The new Testnet endpoint was successfully reached and returns a valid response.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the new Testnet URL
curl -I https://dydx-testnet.imperator.co/v4/height

Length of output: 945

@jerryfan01234 jerryfan01234 force-pushed the add-comlink-affiliates-snapshot-makerRebate branch from 415518c to 47c909e Compare October 4, 2024 18:18
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: 2

🧹 Outside diff range and nitpick comments (4)
indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts (1)

178-178: LGTM! Consider adding a comment for clarity.

The implementation of affiliateReferredMakerRebates looks correct and aligns with the PR objectives. Good job on enhancing the response object with this additional information.

A couple of suggestions:

  1. There seems to be a typo in the PR description: "afflaiteReferredMakerRebates" vs "affiliateReferredMakerRebates" in the code. Consider updating the PR description for consistency.
  2. It might be helpful to add a brief comment explaining the purpose of this field for future maintainers.

Consider adding a comment above this line to explain the purpose of the affiliateReferredMakerRebates field:

// Total maker rebates earned by users referred by this affiliate
affiliateReferredMakerRebates: Number(info.totalReferredMakerRebates),
indexer/services/comlink/__tests__/controllers/api/v4/affiliates-controller.test.ts (2)

383-383: LGTM with a minor suggestion.

The addition of the affiliateReferredMakerRebates field to the response object is correct and aligns with the PR objective. The field is properly derived from info.totalReferredMakerRebates and is consistent in type (Number) with other fields in the response object.

Consider adding a test case in the /snapshot endpoint tests to verify that this new field is correctly included in the response. This would ensure that the change is properly reflected in the API output.


Line range hint 1-383: Enhance test coverage for the new field.

While the addition of the affiliateReferredMakerRebates field to the response object is correct, the existing test cases have not been updated to verify this new field. To ensure comprehensive test coverage:

  1. Update the should return snapshots when all params specified test in the /snapshot endpoint to include an assertion for the new affiliateReferredMakerRebates field.
  2. Consider adding a new test case that specifically focuses on scenarios where the affiliateReferredMakerRebates value is non-zero, to ensure it's being calculated and returned correctly.

These additions will help validate that the new field is correctly integrated into the API responses and behaves as expected under various conditions.

indexer/services/comlink/public/api-documentation.md (1)

Line range hint 1-1000: Base URL for Testnet environment has been updated.

The Testnet base URL has been changed from https://indexer.v4testnet.dydx.exchange/v4 to https://dydx-testnet.imperator.co/v4 throughout the documentation. This change is consistent across all code samples.

Please ensure that:

  1. All Testnet users are notified of this change.
  2. There's a migration plan or grace period for users still using the old URL.
  3. The new URL is properly set up and functioning as expected.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 415518c and 47c909e.

📒 Files selected for processing (5)
  • indexer/services/comlink/tests/controllers/api/v4/affiliates-controller.test.ts (1 hunks)
  • indexer/services/comlink/public/api-documentation.md (4 hunks)
  • indexer/services/comlink/public/swagger.json (2 hunks)
  • indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts (1 hunks)
  • indexer/services/comlink/src/types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • indexer/services/comlink/public/swagger.json
  • indexer/services/comlink/src/types.ts
🔇 Additional comments (2)
indexer/services/comlink/__tests__/controllers/api/v4/affiliates-controller.test.ts (1)

Line range hint 1-383: Overall assessment: LGTM with suggestions for improved test coverage.

The changes to add the affiliateReferredMakerRebates field are implemented correctly in the affiliateInfoCreateToResponseObject function. The existing test structure is well-organized and comprehensive for the current functionality.

To further improve the quality of this PR:

  1. Implement the suggested additions to test coverage for the new field.
  2. Ensure that the changes are reflected in any relevant documentation or API specifications.

Once these suggestions are addressed, the PR will be ready for merging.

indexer/services/comlink/public/api-documentation.md (1)

Line range hint 1-1000: Summary of changes to the API documentation

  1. The Testnet base URL has been updated throughout the document.
  2. A new field affiliateReferredMakerRebates has been added to affiliate-related responses.

These changes appear to be intentional and consistently applied. However, they may have the following impacts:

  1. Existing Testnet users will need to update their API endpoint URLs.
  2. Systems consuming affiliate data will need to be updated to handle the new affiliateReferredMakerRebates field.

To ensure these changes are properly implemented and documented, please run the following verification steps:

Please review the output of these commands to ensure all changes are correctly implemented and no unintended modifications remain.

@@ -175,6 +175,7 @@ class AffiliatesController extends Controller {
affiliateReferredTotalVolume: Number(info.referredTotalVolume),
affiliateReferredMakerFees: Number(info.totalReferredMakerFees),
affiliateReferredTakerFees: Number(info.totalReferredTakerFees),
affiliateReferredMakerRebates: Number(info.totalReferredMakerRebates),
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Missing AffiliateSnapshotResponseObject type definition

The type AffiliateSnapshotResponseObject is not defined in the codebase. Please add this type definition and include the new affiliateReferredMakerRebates field to ensure type consistency.

Additionally, ensure that unit tests properly assert the affiliateReferredMakerRebates field.

🔗 Analysis chain

Verify consistency across related files

While the change looks good, please ensure that:

  1. Any related type definitions or interfaces (e.g., AffiliateSnapshotResponseObject) are updated to include this new field.
  2. API documentation or OpenAPI/Swagger specifications are updated to reflect this change in the response structure.
  3. Any unit tests covering the getSnapshot method are updated to include assertions for this new field.

To check for related type definitions, you can run:

To check for API documentation updates:

To check for relevant test files:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for AffiliateSnapshotResponseObject type definition
rg --type typescript "type AffiliateSnapshotResponseObject" -A 20

Length of output: 102


Script:

#!/bin/bash
# Search for API documentation mentioning affiliate snapshots
rg --type markdown "affiliate.*snapshot" -A 10

Length of output: 6638


Script:

#!/bin/bash
# Search for test files related to AffiliatesController
fd -e test.ts affiliates-controller

Length of output: 121


Script:

#!/bin/bash
# Corrected search for AffiliateSnapshotResponseObject type definition using file extensions
rg "type AffiliateSnapshotResponseObject" --glob "*.ts" -A 20

Length of output: 63


Script:

#!/bin/bash
# Search within test files for assertions related to affiliateReferredMakerRebates
rg "affiliateReferredMakerRebates" indexer/services/comlink/__tests__/controllers/api/v4/affiliates-controller.test.ts

Length of output: 193

Comment on lines +658 to +659
"affiliateReferredTakerFees": 0.1,
"affiliateReferredMakerRebates": 0.1
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

New field affiliateReferredMakerRebates added to affiliate responses.

A new field affiliateReferredMakerRebates has been added to the AffiliateSnapshotResponseObject and is included in the example response for AffiliateSnapshotResponse.

Please ensure that:

  1. The purpose and meaning of this new field are clearly documented.
  2. Any relevant calculations or business logic related to this field are explained.
  3. The API versioning is updated if this change is not backward compatible.
  4. The change is reflected in all relevant sections of the documentation, including any schema definitions or data models.

Also applies to: 4252-4253, 4272-4272, 4294-4295

@jerryfan01234 jerryfan01234 merged commit 264cb06 into main Oct 4, 2024
12 checks passed
@jerryfan01234 jerryfan01234 deleted the add-comlink-affiliates-snapshot-makerRebate branch October 4, 2024 18:38
@jerryfan01234
Copy link
Contributor Author

@Mergifyio release/indexer/v7.x

Copy link
Contributor

mergify bot commented Oct 4, 2024

release /indexer/v7.x

❌ Sorry but I didn't understand the command. Please consult the commands documentation 📚.

@jerryfan01234
Copy link
Contributor Author

@Mergifyio backport release/indexer/v7.x

Copy link
Contributor

mergify bot commented Oct 4, 2024

backport release/indexer/v7.x

✅ Backports have been created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants