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

feat(opbot): add screener to opbot #3076

Merged
merged 7 commits into from
Aug 30, 2024
Merged

feat(opbot): add screener to opbot #3076

merged 7 commits into from
Aug 30, 2024

Conversation

golangisfun123
Copy link
Collaborator

@golangisfun123 golangisfun123 commented Aug 28, 2024

Description
A clear and concise description of the features you're adding in this pull request.

Additional context
Add any other context about the problem you're solving.

Metadata

  • Fixes #[Link to Issue]

Summary by CodeRabbit

  • New Features

    • Enhanced bot functionality to interact with the screener service.
    • Added a new configuration option for the screener URL.
    • Improved API response by including sender information in quote requests.
  • Bug Fixes

    • Enhanced error handling and control flow in the refund and quote request processes.
  • Chores

    • Updated project dependencies for better modularity and local development.

Copy link
Contributor

coderabbitai bot commented Aug 28, 2024

Walkthrough

The changes introduce a new dependency on a screener client, enhancing the bot's functionality to interact with a screener service. Modifications include improved error handling in the refund process and streamlined quote request retrieval. Additionally, a new configuration option for the screener URL is added, and the API response structure is updated to include sender information in quote requests. These changes collectively expand the capabilities and robustness of the bot and related services.

Changes

Files Change Summary
contrib/opbot/botmd/botmd.go, commands.go Added screenerClient dependency, modified rfqRefund for address screening, and streamlined getQuoteRequest.
contrib/opbot/config/config.go Introduced ScreenerURL field to the Config struct for enhanced configuration.
contrib/opbot/go.mod Added screener-api module dependency and updated its replace directive for local development.
services/rfq/relayer/relapi/handler.go, model.go Added Sender field to GetQuoteRequestResponse struct for improved response context.

Sequence Diagram(s)

sequenceDiagram
    participant Bot
    participant ScreenerClient
    participant QuoteRequest

    Bot->>ScreenerClient: Screen Address
    alt Address Valid
        ScreenerClient-->>Bot: Address Validated
        Bot->>QuoteRequest: Process Refund
    else Address Invalid
        ScreenerClient-->>Bot: Address Not Valid
        Bot-->>User: Refund Not Allowed
    end
Loading

🐰 In the meadow, changes bloom,
A screener's grace dispels the gloom.
With refunds checked and quotes refined,
Our bot now dances, well-aligned!
Hops of joy, a new delight,
In code's embrace, we leap tonight! 🌼


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 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.

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.

@github-actions github-actions bot added go Pull requests that update Go code size/s labels Aug 28, 2024
Copy link

codecov bot commented Aug 28, 2024

Codecov Report

Attention: Patch coverage is 0% with 25 lines in your changes missing coverage. Please review.

Project coverage is 23.06899%. Comparing base (eccbfd1) to head (e0923f8).
Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
contrib/opbot/botmd/commands.go 0.00000% 19 Missing ⚠️
contrib/opbot/botmd/botmd.go 0.00000% 6 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #3076         +/-   ##
===================================================
- Coverage   23.09876%   23.06899%   -0.02977%     
===================================================
  Files            193         193                 
  Lines          11624       11639         +15     
  Branches          82          82                 
===================================================
  Hits            2685        2685                 
- Misses          8697        8712         +15     
  Partials         242         242                 
Flag Coverage Δ
opbot 0.49906% <0.00000%> (-0.00473%) ⬇️
promexporter 6.92368% <ø> (ø)

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between eccbfd1 and 0152661.

Files selected for processing (7)
  • contrib/opbot/botmd/botmd.go (3 hunks)
  • contrib/opbot/botmd/commands.go (2 hunks)
  • contrib/opbot/cmd/commands.go (1 hunks)
  • contrib/opbot/config/config.go (1 hunks)
  • contrib/opbot/go.mod (2 hunks)
  • services/rfq/relayer/relapi/handler.go (2 hunks)
  • services/rfq/relayer/relapi/model.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • contrib/opbot/cmd/commands.go
Additional context used
GitHub Check: codecov/patch
contrib/opbot/botmd/botmd.go

[warning] 94-99: contrib/opbot/botmd/botmd.go#L94-L99
Added lines #L94 - L99 were not covered by tests

contrib/opbot/botmd/commands.go

[warning] 302-308: contrib/opbot/botmd/commands.go#L302-L308
Added lines #L302 - L308 were not covered by tests


[warning] 311-316: contrib/opbot/botmd/commands.go#L311-L316
Added lines #L311 - L316 were not covered by tests


[warning] 410-412: contrib/opbot/botmd/commands.go#L410-L412
Added lines #L410 - L412 were not covered by tests


[warning] 416-417: contrib/opbot/botmd/commands.go#L416-L417
Added lines #L416 - L417 were not covered by tests


[warning] 420-420: contrib/opbot/botmd/commands.go#L420
Added line #L420 was not covered by tests

Additional comments not posted (7)
services/rfq/relayer/relapi/model.go (1)

20-20: LGTM! Verify impact on consuming services and documentation.

The addition of the Sender field enhances the response structure by providing information about the sender of the quote request. Ensure that all consuming services and documentation are updated accordingly.

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

Verification successful

Integration of Sender Field Verified. Ensure Documentation and Consuming Services are Updated.

The Sender field has been successfully integrated into the GetQuoteRequestResponse struct and is being utilized in the codebase. Please verify that all relevant documentation and consuming services are updated to handle this new field appropriately.

Scripts executed

The following scripts were executed for the analysis:

Script:

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

# Test: Search for the struct usage. Expect: Occurrences of the new field.
rg --type go -A 5 $'GetQuoteRequestResponse'

Length of output: 8568

contrib/opbot/config/config.go (1)

36-37: LGTM! Verify impact on configuration files and documentation.

The addition of the ScreenerURL field enhances the configuration capabilities by allowing it to include a URL for a screener. Ensure that all configuration files and documentation are updated accordingly.

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

contrib/opbot/botmd/botmd.go (1)

32-32: LGTM! Verify impact on bot's initialization and usage.

The addition of the screener field enhances the bot's functionality by allowing it to utilize the screener client for its operations. Ensure that all initialization and usage of the bot are updated accordingly.

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

Verification successful

Screener Field Integration Verified

The screener field of type screenerClient.ScreenerClient is properly integrated into the codebase. It is initialized and used in contrib/opbot/botmd/botmd.go and utilized in contrib/opbot/botmd/commands.go for address screening. Ensure that all related initialization and usage are updated accordingly.

  • contrib/opbot/botmd/botmd.go: Initialization and usage of screener.
  • contrib/opbot/botmd/commands.go: Usage of screener for address screening.
Scripts executed

The following scripts were executed for the analysis:

Script:

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

# Test: Search for the field usage. Expect: Occurrences of the new field.
rg --type go -A 5 $'screener'

Length of output: 37044

services/rfq/relayer/relapi/handler.go (2)

115-115: LGTM!

The function is correctly implemented and the new field Sender is properly added to the response object.

The code changes are approved.


145-145: LGTM!

The function is correctly implemented and the new field Sender is properly added to the response object.

The code changes are approved.

contrib/opbot/go.mod (2)

25-25: LGTM!

The addition of the new dependency is correctly implemented.

The code changes are approved.


298-298: LGTM!

The update of the replace directive is correctly implemented.

The code changes are approved.

Comment on lines +94 to +99
screenerClient, err := screenerClient.NewClient(b.handler, b.cfg.ScreenerURL)
if err != nil {
return fmt.Errorf("could not create screener client: %w", err)
}
b.screener = screenerClient

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM! Add tests to cover the new lines.

The new lines in the Start method enhance the bot's functionality by creating a screenerClient and assigning it to the screener field. However, these lines are not covered by tests, which may impact the reliability of the new functionality.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 94-99: contrib/opbot/botmd/botmd.go#L94-L99
Added lines #L94 - L99 were not covered by tests

Comment on lines +301 to +317

canRefund, err := b.screener.ScreenAddress(ctx.Context(), rawRequest.Sender)
if err != nil {
_, err := ctx.Response().Reply("error screening address")
if err != nil {
log.Println(err)
}
return
}

if !canRefund {
_, err := ctx.Response().Reply("address cannot be refunded")
if err != nil {
log.Println(err)
}
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM! But add tests for the new logic.

The function is correctly implemented and the new logic enhances the robustness of the refund process. However, test coverage is missing for the new lines.

The code changes are approved.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 302-308: contrib/opbot/botmd/commands.go#L302-L308
Added lines #L302 - L308 were not covered by tests


[warning] 311-316: contrib/opbot/botmd/commands.go#L311-L316
Added lines #L311 - L316 were not covered by tests

Comment on lines +410 to +420
func getQuoteRequest(ctx context.Context, client relapi.RelayerClient, tx string) (qr *relapi.GetQuoteRequestResponse, err error) {
if qr, err = client.GetQuoteRequestByTxHash(ctx, tx); err == nil {
return qr, nil
}

// look up quote request
qr, err := client.GetQuoteRequestByTXID(ctx, tx)
if err != nil {
return nil, fmt.Errorf("error fetching quote request: %w", err)
if qr, err = client.GetQuoteRequestByTXID(ctx, tx); err == nil {
return qr, nil
}

return qr, nil
return nil, fmt.Errorf("error fetching quote request: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM! But add tests for the new logic.

The function is correctly implemented and the error handling has been improved. However, test coverage is missing for the new lines.

The code changes are approved.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 410-412: contrib/opbot/botmd/commands.go#L410-L412
Added lines #L410 - L412 were not covered by tests


[warning] 416-417: contrib/opbot/botmd/commands.go#L416-L417
Added lines #L416 - L417 were not covered by tests


[warning] 420-420: contrib/opbot/botmd/commands.go#L420
Added line #L420 was not covered by tests

Copy link

cloudflare-workers-and-pages bot commented Aug 28, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: e0923f8
Status:⚡️  Build in progress...

View logs

@trajan0x trajan0x merged commit a6e1781 into master Aug 30, 2024
31 of 34 checks passed
@trajan0x trajan0x deleted the opbot-buffs branch August 30, 2024 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code size/s
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants