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

Rfq api/cli #2826

Merged
merged 22 commits into from
Jul 2, 2024
Merged

Rfq api/cli #2826

merged 22 commits into from
Jul 2, 2024

Conversation

golangisfun123
Copy link
Collaborator

@golangisfun123 golangisfun123 commented Jun 30, 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

    • Introduced withdrawal functionality in the relayer client, including a new Withdraw method and corresponding WithdrawRequest and WithdrawResponse structs.
    • Added a command-line tool for initiating withdrawals via the relayer.
    • Implemented new API routes and handlers for processing withdrawal requests.
  • Enhancements

    • Updated RelayerAPIServer and Handler structures to support the new withdrawal functionalities.
    • Added new test functions to ensure the accuracy of withdrawal processes for Ethereum and ERC20 tokens.
  • Configuration

    • Added new configuration options to enable API withdrawals and manage withdrawal whitelists.

Copy link
Contributor

coderabbitai bot commented Jun 30, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Base branches to auto review (3)
  • feat/.*
  • master
  • fe-release

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This update implements several enhancements across the ethergo and services/rfq packages. Key changes include updating constants, adding new methods to interfaces, expanding API capabilities to handle token withdrawals, modifying configurations and handlers to support these new functions, and introducing new command-line tools for these operations. Comprehensive tests ensure robustness and reliability.

Changes

File(s) Change Summary
ethergo/submitter/submitter.go Updated constant and added Address() method to TransactionSubmitter interface.
services/rfq/relayer/relapi/client.go Added Withdraw method to RelayerClient interface and implemented it.
services/rfq/relayer/relapi/handler.go Enhanced Handler struct, added Withdraw function, helper functions, new imports, and WithdrawRequest struct.
services/rfq/relayer/relapi/handler_test.go Added test for marshaling and unmarshaling WithdrawRequest struct.
services/rfq/relayer/relapi/server.go Modified RelayerAPIServer to include submitter and added a POST route for withdrawals.
services/rfq/relayer/relapi/server_test.go Added tests for Ethereum and ERC20 token withdrawals.
services/rfq/relayer/relapi/suite_test.go Expanded RelayerServerSuite with new imports, variables, and additional setup logic.
services/rfq/relayer/relconfig/config.go Added new fields to Config struct for withdrawal functionalities and helper function DecodeTokenID.
services/rfq/tools/withdrawal/cmd/cmd.go Introduced command-line tool for handling withdrawal processes.
services/rfq/tools/withdrawal/cmd/commands.go Defined configuration flags and command for running the withdrawal tool.
services/rfq/tools/withdrawal/withdraw/withdraw_test.go Added package declaration for testing withdrawal processes.
contrib/opbot/config/config.go Modified SignozBaseURL field and added comment for RelayerURLS in Config struct.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RelayerAPI
    participant RelayerServer
    participant Submitter
    participant Blockchain

    Client->>RelayerAPI: POST /withdraw (withdrawRequest)
    RelayerAPI->>RelayerServer: Handle withdraw request
    RelayerServer->>Submitter: Submit transaction (submit)
    Submitter->>Blockchain: Send transaction
    Blockchain->>Submitter: Transaction receipt
    Submitter->>RelayerServer: Transaction success
    RelayerServer->>RelayerAPI: Return withdraw response
    RelayerAPI->>Client: WithdrawResponse (nonce)
Loading

Poem

In fields of code, where changes bloom,
We crafted features, lifted gloom.
Withdrawals flow with tokens bright,
API and CLI ignite.
Tests ensure the paths are clear,
For users far and engineers near.
Rejoice, for updates hold the key,
To seamless blockchain harmony! 🌿


Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.
  • OSS projects are currently opted into early access features by default.

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.

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

@github-actions github-actions bot added go Pull requests that update Go code size/m labels Jun 30, 2024
Copy link

cloudflare-workers-and-pages bot commented Jun 30, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 97634de
Status: ✅  Deploy successful!
Preview URL: https://6be918b5.sanguine-fe.pages.dev
Branch Preview URL: https://rfq-api-cli.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: 5

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d0f1508 and fb9b64d.

Files selected for processing (12)
  • ethergo/submitter/submitter.go (3 hunks)
  • services/rfq/relayer/relapi/client.go (2 hunks)
  • services/rfq/relayer/relapi/handler.go (4 hunks)
  • services/rfq/relayer/relapi/handler_test.go (1 hunks)
  • services/rfq/relayer/relapi/server.go (4 hunks)
  • services/rfq/relayer/relapi/server_test.go (2 hunks)
  • services/rfq/relayer/relapi/suite_test.go (7 hunks)
  • services/rfq/relayer/relconfig/config.go (2 hunks)
  • services/rfq/tools/withdrawal/cmd/cmd.go (1 hunks)
  • services/rfq/tools/withdrawal/cmd/commands.go (1 hunks)
  • services/rfq/tools/withdrawal/withdraw/withdraw.go (1 hunks)
  • services/rfq/tools/withdrawal/withdraw/withdraw_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • services/rfq/tools/withdrawal/withdraw/withdraw_test.go
Additional context used
Learnings (2)
services/rfq/relayer/relapi/handler_test.go (2)
Learnt from: trajan0x
PR: synapsecns/sanguine#2815
File: services/rfq/relayer/relapi/handler.go:154-156
Timestamp: 2024-06-29T05:11:50.952Z
Learning: When adding new validation logic in the `Withdraw` function, ensure to cover it with unit tests to handle various scenarios.
Learnt from: trajan0x
PR: synapsecns/sanguine#2815
File: services/rfq/relayer/relapi/handler.go:153-156
Timestamp: 2024-06-29T05:12:50.268Z
Learning: When adding new validation logic in the `Withdraw` function, ensure to cover it with unit tests to handle various scenarios.
services/rfq/relayer/relapi/server_test.go (2)
Learnt from: trajan0x
PR: synapsecns/sanguine#2815
File: services/rfq/relayer/relapi/handler.go:154-156
Timestamp: 2024-06-29T05:11:50.952Z
Learning: When adding new validation logic in the `Withdraw` function, ensure to cover it with unit tests to handle various scenarios.
Learnt from: trajan0x
PR: synapsecns/sanguine#2815
File: services/rfq/relayer/relapi/handler.go:153-156
Timestamp: 2024-06-29T05:12:50.268Z
Learning: When adding new validation logic in the `Withdraw` function, ensure to cover it with unit tests to handle various scenarios.
Additional comments not posted (18)
services/rfq/tools/withdrawal/cmd/cmd.go (2)

12-34: LGTM!


19-19: Clarify the necessity of halting boot due to metrics.

The TODO comment questions whether the boot process should be halted because of metrics setup. This needs to be addressed or clarified.

services/rfq/relayer/relapi/client.go (3)

20-20: LGTM!

The Withdraw method has been added to the RelayerClient interface. Ensure that all implementations of this interface include this method.


105-108: LGTM!

The WithdrawResponse struct has been introduced with a Nonce field.


110-123: LGTM!

The Withdraw method has been implemented in the relayerClient struct. Ensure that all function calls to Withdraw match the new signature.

services/rfq/relayer/relapi/server.go (3)

28-33: LGTM!

The RelayerAPIServer struct now includes a submitter field.


103-103: LGTM!

The new POST route postWithdrawRoute has been added.


Line range hint 111-124: LGTM!

The new route postWithdrawRoute has been conditionally added based on cfg.EnableAPIWithdrawals.

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

208-240: LGTM!

The TestEthWithdraw function has been added to test Ethereum withdrawals.


242-276: LGTM!

The TestERC20Withdraw function has been added to test ERC20 token withdrawals.

Verification successful

LGTM!

The TestERC20Withdraw and TestEthWithdraw functions provide adequate test coverage for ERC20 token and ETH withdrawals, respectively.

  • TestERC20Withdraw tests ERC20 token withdrawals.
  • TestEthWithdraw tests ETH withdrawals.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the test coverage for the `Withdraw` function.

# Test: Search for the test functions. Expect: Coverage for all scenarios.
rg --type go $'TestEthWithdraw|TestERC20Withdraw'

Length of output: 236



Script:

#!/bin/bash
# Extract the content of the TestEthWithdraw function from the server_test.go file.
ast-grep --lang go --pattern $'func (c *$_) TestEthWithdraw() {
  $$$
}' services/rfq/relayer/relapi/server_test.go

Length of output: 2641

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

144-206: LGTM!

The Withdraw function has been added to handle withdrawal requests. Ensure proper validation and error handling.

services/rfq/relayer/relconfig/config.go (2)

54-57: LGTM!

The new fields EnableAPIWithdrawals and WithdrawalWhitelist are well integrated into the Config struct.


163-181: LGTM!

The DecodeTokenID function is well-implemented with proper validation and error handling.

services/rfq/relayer/relapi/suite_test.go (3)

58-59: LGTM!

The new variable testWithdrawalAddress is well integrated and seems to be used for testing withdrawals.


100-118: LGTM!

The new configurations for EnableAPIWithdrawals and WithdrawalWhitelist are well integrated into the SetupTest method.


Line range hint 167-261: LGTM!

The new configurations and setups for mock chains and backends are well integrated into the SetupSuite method.

ethergo/submitter/submitter.go (2)

42-42: LGTM!

The meterName constant definition is straightforward and appropriate for metrics.


54-55: LGTM!

The Address method addition to the TransactionSubmitter interface and its implementation in txSubmitterImpl are straightforward and appropriate.

Also applies to: 688-690

Comment on lines 28 to 36
for _, req := range withdrawRequests {
res, err := w.client.Withdraw(ctx, &req)
if err != nil {
return nil, err
}
responses = append(responses, res)
}

return responses, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using goroutines for concurrent withdrawals.

To improve performance, consider using goroutines to handle multiple withdrawal requests concurrently.

var (
  responses []*relapi.WithdrawResponse
  wg sync.WaitGroup
  mu sync.Mutex
  errChan = make(chan error, len(withdrawRequests))
)

for _, req := range withdrawRequests {
  wg.Add(1)
  go func(req relapi.WithdrawRequest) {
    defer wg.Done()
    res, err := w.client.Withdraw(ctx, &req)
    if err != nil {
      errChan <- fmt.Errorf("withdrawal failed for request: %+v, error: %w", req, err)
      return
    }
    mu.Lock()
    responses = append(responses, res)
    mu.Unlock()
  }(req)
}

wg.Wait()
close(errChan)

if len(errChan) > 0 {
  return nil, <-errChan
}

return responses, nil

Comment on lines 30 to 32
if err != nil {
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Enhance error handling with more context.

The error handling in the Withdraw method can be improved by providing more context about which request failed.

- if err != nil {
-   return nil, err
+ if err != nil {
+   return nil, fmt.Errorf("withdrawal failed for request: %+v, error: %w", req, err)
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
if err != nil {
return nil, err
}
if err != nil {
return nil, fmt.Errorf("withdrawal failed for request: %+v, error: %w", req, err)
}

Comment on lines 11 to 34
func TestWithdrawRequestJSON(t *testing.T) {
original := relapi.WithdrawRequest{
ChainID: 1,
Amount: "100",
TokenAddress: common.HexToAddress("0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"),
To: common.HexToAddress("0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF"),
}

// Marshal to JSON
data, err := json.Marshal(original)
assert.NoError(t, err)

// Unmarshal back to struct
var unmarshalled relapi.WithdrawRequest
err = json.Unmarshal(data, &unmarshalled)
assert.NoError(t, err)

// Check if the original and unmarshalled structs are the same
assert.Equal(t, original, unmarshalled)

// Check the JSON string explicitly
expectedJSON := `{"chain_id":1,"amount":"100","token_address":"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","to":"0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"}`
assert.JSONEq(t, expectedJSON, string(data))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add more test cases to cover edge cases and invalid inputs.

The current test covers basic JSON marshaling and unmarshaling. Consider adding more test cases to cover edge cases and invalid inputs.

func TestWithdrawRequestJSON(t *testing.T) {
  testCases := []struct {
    name          string
    original      relapi.WithdrawRequest
    expectedJSON  string
    expectError   bool
  }{
    {
      name: "valid request",
      original: relapi.WithdrawRequest{
        ChainID:      1,
        Amount:       "100",
        TokenAddress: common.HexToAddress("0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"),
        To:           common.HexToAddress("0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF"),
      },
      expectedJSON: `{"chain_id":1,"amount":"100","token_address":"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","to":"0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"}`,
      expectError:  false,
    },
    {
      name: "invalid amount",
      original: relapi.WithdrawRequest{
        ChainID:      1,
        Amount:       "invalid",
        TokenAddress: common.HexToAddress("0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"),
        To:           common.HexToAddress("0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF"),
      },
      expectedJSON: `{"chain_id":1,"amount":"invalid","token_address":"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","to":"0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"}`,
      expectError:  true,
    },
  }

  for _, tc := range testCases {
    t.Run(tc.name, func(t *testing.T) {
      data, err := json.Marshal(tc.original)
      if tc.expectError {
        assert.Error(t, err)
        return
      }
      assert.NoError(t, err)
      assert.JSONEq(t, tc.expectedJSON, string(data))

      var unmarshalled relapi.WithdrawRequest
      err = json.Unmarshal(data, &unmarshalled)
      assert.NoError(t, err)
      assert.Equal(t, tc.original, unmarshalled)
    })
  }
}

Comment on lines 59 to 64
withdrawRequest := relapi.WithdrawRequest{
ChainID: uint32(c.Uint(chainIDFlag.Name)),
Amount: c.String(amountFlag.Name),
TokenAddress: common.HexToAddress(c.String(tokenAddressFlag.Name)),
To: common.HexToAddress(toFlag.Name),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Validate CLI flag inputs.

Add validation for CLI flag inputs to ensure they are not empty and are in the correct format.

if c.String(relayerURLFlag.Name) == "" {
  return fmt.Errorf("relayer URL is required")
}

chainID := c.Uint(chainIDFlag.Name)
if chainID == 0 {
  return fmt.Errorf("valid chain ID is required")
}

amount := c.String(amountFlag.Name)
if amount == "" {
  return fmt.Errorf("amount is required")
}

tokenAddress := c.String(tokenAddressFlag.Name)
if !common.IsHexAddress(tokenAddress) {
  return fmt.Errorf("valid token address is required")
}

to := c.String(toFlag.Name)
if !common.IsHexAddress(to) {
  return fmt.Errorf("valid recipient address is required")
}

Comment on lines 67 to 69
if err != nil {
return fmt.Errorf("could not start relayer: %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.

Improve error handling.

The error message should indicate that the withdrawal request failed, not that the relayer could not start.

- return fmt.Errorf("could not start relayer: %w", err)
+ return fmt.Errorf("withdrawal request failed: %w", err)
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
if err != nil {
return fmt.Errorf("could not start relayer: %w", err)
}
if err != nil {
return fmt.Errorf("withdrawal request failed: %w", err)
}

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 fb9b64d and 59036b2.

Files ignored due to path filters (1)
  • go.work.sum is excluded by !**/*.sum
Files selected for processing (2)
  • contrib/opbot/config/config.go (1 hunks)
  • services/rfq/tools/withdrawal/withdraw/withdraw.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • services/rfq/tools/withdrawal/withdraw/withdraw.go
Additional comments not posted (2)
contrib/opbot/config/config.go (2)

18-18: Ensure consistent formatting of YAML tags.

The alignment of the YAML tag for SignozBaseURL has been corrected. This enhances readability and consistency.


20-20: Ensure consistent formatting of YAML tags.

The alignment of the YAML tag for RelayerURLS has been corrected. This enhances readability and consistency.

@golangisfun123 golangisfun123 changed the base branch from master to fix/rfq-api June 30, 2024 20:32
@github-actions github-actions bot added size/s and removed size/m labels Jun 30, 2024
Copy link

codecov bot commented Jun 30, 2024

Codecov Report

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

Project coverage is 25.72228%. Comparing base (484a9a3) to head (c4b5ce5).

Files Patch % Lines
services/rfq/relayer/cmd/commands.go 0.00000% 36 Missing ⚠️
services/rfq/relayer/relapi/handler.go 0.00000% 5 Missing ⚠️
services/rfq/relayer/cmd/cmd.go 0.00000% 1 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                  @@
##           fix/rfq-api       #2826         +/-   ##
=====================================================
+ Coverage     25.60195%   25.72228%   +0.12033%     
=====================================================
  Files              765         708         -57     
  Lines            54863       52196       -2667     
  Branches            80          80                 
=====================================================
- Hits             14046       13426        -620     
+ Misses           39368       37390       -1978     
+ Partials          1449        1380         -69     
Flag Coverage Δ
cctp-relayer ?
opbot 0.21067% <ø> (ø)
promexporter ?
rfq 27.64428% <0.00000%> (-0.17270%) ⬇️

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

@trajan0x trajan0x left a comment

Choose a reason for hiding this comment

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

lint failing

@golangisfun123 golangisfun123 marked this pull request as ready for review July 1, 2024 17:41
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

  • Added comments to SignozBaseURL and RelayerURLS fields in /contrib/opbot/config/config.go
  • Introduced runWithdrawCommand in /services/rfq/relayer/cmd/cmd.go
  • New CLI tool for withdrawals in /services/rfq/relayer/cmd/commands.go
  • Added Withdraw method in /services/rfq/relayer/relapi/handler.go
  • New test functions for withdrawals in /services/rfq/relayer/relapi/server_test.go

7 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Updated services/rfq/relayer/cmd/commands.go to align withdrawal functionality with relapi package.
  • Introduced Withdrawer interface in services/rfq/relayer/relapi/suite_test.go and updated test setup for withdrawals.
  • Moved withdraw.go to services/rfq/relayer/relapi, centralizing withdrawal functionality within relapi package.

3 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Introduced Withdrawer interface in services/rfq/relayer/relapi/withdraw.go
  • Implemented NewWithdrawer constructor and Withdraw method
  • Enhanced relapi package with ERC20 and native token withdrawal functionalities

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings

func (w *withdrawerImpl) Withdraw(ctx context.Context, withdrawRequest WithdrawRequest) (*WithdrawResponse, error) {
res, err := w.client.Withdraw(ctx, &withdrawRequest)
if err != nil {
return nil, fmt.Errorf("could not withdraw: %w", err)
Copy link

Choose a reason for hiding this comment

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

🪶 style: Error message could be more descriptive.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Added runWithdrawCommand for initiating withdrawals via CLI in services/rfq/relayer/cmd/commands.go
  • Introduced necessary flags and validation checks for the withdrawal process
  • Created Withdrawer client to handle withdrawal requests

1 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Added runWithdrawCommand for initiating withdrawals via CLI in services/rfq/relayer/cmd/commands.go
  • Introduced flags for relayer URL, chain ID, amount, token address, and recipient address
  • Implemented input validation for withdrawal requests
  • Created Withdrawer client to handle withdrawal requests

1 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings


// runCommand runs the rfq relayer.
var runWithdrawCommand = &cli.Command{
Name: "widthdraw",
Copy link

Choose a reason for hiding this comment

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

📚 spelling: Typo in command name 'widthdraw'.

Suggested change
Name: "widthdraw",
Name: "withdraw",

Comment on lines 85 to 88
withdrawer := relapi.NewWithdrawer(relapi.NewRelayerClient(metrics.Get(), c.String(relayerURLFlag.Name)))
if err != nil {
return fmt.Errorf("could not create relayer: %w", err)
}
Copy link

Choose a reason for hiding this comment

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

🧠 logic: The error check here is redundant since withdrawer is always created successfully.

Comment on lines +81 to +83
if c.String(relayerURLFlag.Name) == "" {
return fmt.Errorf("relayer URL is required")
}
Copy link

Choose a reason for hiding this comment

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

🪶 style: Consider moving this check before creating the withdrawer to avoid unnecessary object creation.


// TODO: support multiple withdraw requests in one cli command (via config?)
// Withdraw withdraws the given amount of tokens to the given address.
func (w *withdrawerImpl) Withdraw(ctx context.Context, withdrawRequest WithdrawRequest) (*WithdrawResponse, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the point of abstracting this out? Even if you were going to do a seperate interface still no reason for this

@trajan0x trajan0x mentioned this pull request Jul 2, 2024
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Introduced withdrawCommand in services/rfq/relayer/cmd/cmd.go for CLI withdrawals
  • Added Withdraw method, WithdrawRequest, and WithdrawResponse structs in services/rfq/relayer/cmd/commands.go
  • Removed withdrawer field from RelayerClientSuite in services/rfq/relayer/relapi/suite_test.go
  • Deleted services/rfq/relayer/relapi/withdraw.go and restructured withdrawal functionality

4 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings


// runCommand runs the rfq relayer.
var withdrawCommand = &cli.Command{
Name: "widthdraw",
Copy link

Choose a reason for hiding this comment

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

📚 spelling: Typo in command name 'widthdraw'.

Suggested change
Name: "widthdraw",
Name: "withdraw",

Comment on lines +86 to +88
if err != nil {
return fmt.Errorf("could not create relayer: %w", err)
}
Copy link

Choose a reason for hiding this comment

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

🧠 logic: The error check here is redundant since withdrawer is always created successfully.

Comment on lines +81 to +83
if c.String(relayerURLFlag.Name) == "" {
return fmt.Errorf("relayer URL is required")
}
Copy link

Choose a reason for hiding this comment

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

🪶 style: Consider moving this check before creating the withdrawer to avoid unnecessary object creation.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Updated Withdraw method calls in services/rfq/relayer/relapi/server_test.go to use Client object instead of withdrawer object.
  • Ensure alignment with new withdrawal functionality in relayer client.

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

@trajan0x trajan0x merged commit e83dd9d into fix/rfq-api Jul 2, 2024
30 of 31 checks passed
@trajan0x trajan0x deleted the rfq-api/cli branch July 2, 2024 14:32
@trajan0x trajan0x mentioned this pull request Jul 2, 2024
3 tasks
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 M-deps size/s
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants