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(rfq-relayer): regenerate with updated fastbridgev2 and zap terminology [SLT-442] #3394

Merged
merged 5 commits into from
Nov 14, 2024

Conversation

dwasse
Copy link
Collaborator

@dwasse dwasse commented Nov 14, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new zap function in the RecipientMock contract, enhancing token transfer capabilities.
    • Added support for new parameters ZapNative and ZapData in the bridging process.
  • Bug Fixes

    • Updated transaction handling to correctly calculate gas amounts based on the new ZapNative field.
  • Refactor

    • Renamed and restructured contract bindings to align with the new IZapRecipient interface.
    • Modified the RequestForQuote structure to replace CallValue and CallParams with ZapNative and ZapData.
  • Tests

    • Updated test cases to reflect changes in function names and parameters related to the new zap functionality.

Copy link
Contributor

coderabbitai bot commented Nov 14, 2024

Caution

Review failed

The head commit changed during the review from f409d18 to 6dfb170.

Warning

Rate limit exceeded

@dwasse has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 44 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 6dfb170 and f409d18.

Walkthrough

The changes in this pull request involve a comprehensive refactoring of the Ethereum contract bindings within the recipientmock package. The contract has been renamed from IFastBridgeRecipient to IZapRecipient, and the associated metadata, function signatures, and transaction methods have been updated accordingly. A new function, zap, replaces the previous fastBridgeTransferReceived. Additionally, the RequestForQuote struct has been modified to incorporate new fields, ZapNative and ZapData, while removing the old CallValue and CallParams. Changes also extend to the test suite and related files.

Changes

File Path Change Summary
services/rfq/contracts/testcontracts/recipientmock/recipientmock.abigen.go Renamed contract and metadata from IFastBridgeRecipient to IZapRecipient, updated function signatures, and modified transaction methods.
services/rfq/contracts/testcontracts/recipientmock/recipientmock.contractinfo.json Updated contract to implement IZapRecipient, replaced fastBridgeTransferReceived with zap, added testRecipientMock function, and updated ABI.
services/rfq/e2e/rfq_test.go Renamed TestArbitraryCall to TestZap, updated parameters from CallParams and CallValue to ZapData and ZapNative.
services/rfq/relayer/chain/chain.go Modified SubmitRelay method to determine gasAmount based on ZapNative instead of CallValue.
services/rfq/relayer/reldb/base/model.go Removed CallValue and CallParams from RequestForQuote, added ZapNative and ZapData, and updated related functions.
services/rfq/relayer/relapi/server_test.go Updated getTestQuoteRequest to reflect changes in Transaction structure, replacing CallValue and CallParams with ZapNative and ZapData.
services/rfq/relayer/reldb/base/model_test.go Modified QuoteRequest in tests to remove CallValue and CallParams, adding ZapNative and ZapData.

Possibly related PRs

Suggested labels

size/m

Suggested reviewers

  • aureliusbtc
  • parodime
  • trajan0x
  • ChiTimesChi

🐰 In the meadow where contracts play,
A zap was born to light the way.
With functions new and names so bright,
We leap through code, a joyful sight!
From fast to zap, we dance and cheer,
In the world of contracts, we hold dear! 🌼

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 golangci-lint

level=warning msg="[config_reader] The configuration option run.skip-files is deprecated, please use issues.exclude-files."
level=warning msg="[config_reader] The configuration option run.skip-dirs is deprecated, please use issues.exclude-dirs."
level=warning msg="[config_reader] The configuration option run.skip-dirs-use-default is deprecated, please use issues.exclude-dirs-use-default."
level=warning msg="[lintersdb] The linter "maligned" is deprecated (step 2) and deactivated. It should be removed from the list of disabled linters. https://golangci-lint.run/product/roadmap/#linter-deprecation-cycle"
level=warning msg="[lintersdb] The linter "exhaustivestruct" is deprecated (step 2) and deactivated. It should be removed from the list of disabled linters. https://golangci-lint.run/product/roadmap/#linter-deprecation-cycle"
level=warning msg="[lintersdb] The linter "ifshort" is deprecated (step 2) and deactivated. It should be removed from the list of disabled linters. https://golangci-lint.run/product/roadmap/#linter-deprecation-cycle"
level=warning msg="[lintersdb] The linter "interfacer" is deprecated (step 2) and deactivated. It should be removed from the list of disabled linters. https://golangci-lint.run/product/roadmap/#linter-deprecation-cycle"
level=warning msg="[lintersdb] The linter "nosnakecase" is deprecated (step 2) and deactivated. It should be removed from the list of disabled linters. https://golangci-lint.run/product/roadmap/#linter-deprecation-cycle"
level=warning msg="[lintersdb] The name "goerr113" is deprecated. The linter has been renamed to: err113."
level=warning msg="The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar."
level=warning msg="The linter 'execinquery' is deprecated (since v1.58.0) due to: The repository of the linter has been archived by the owner. "


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.

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/l labels Nov 14, 2024
Copy link

codecov bot commented Nov 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 24.82483%. Comparing base (95ea295) to head (6dfb170).
Report is 1 commits behind head on feat/relayer-arb-call.

Additional details and impacted files
@@                       Coverage Diff                       @@
##           feat/relayer-arb-call       #3394         +/-   ##
===============================================================
- Coverage               26.64515%   24.82483%   -1.82033%     
===============================================================
  Files                        214         208          -6     
  Lines                      13631       13273        -358     
  Branches                      82          82                 
===============================================================
- Hits                        3632        3295        -337     
+ Misses                      9715        9692         -23     
- Partials                     284         286          +2     
Flag Coverage Δ
opbot 0.18337% <ø> (ø)
promexporter 6.81642% <ø> (ø)
solidity ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

cloudflare-workers-and-pages bot commented Nov 14, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6dfb170
Status: ✅  Deploy successful!
Preview URL: https://01aa3e63.sanguine-fe.pages.dev
Branch Preview URL: https://feat-relayer-arb-call-zap-me.sanguine-fe.pages.dev

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (6)
services/rfq/relayer/chain/chain.go (1)

80-81: Update comments to reflect the new ZapNative condition

The existing comment "Check to see if ETH should be sent to destination" doesn't accurately describe all the conditions for setting gasAmount. Consider updating the comments to clearly document each case.

 	// Check to see if ETH should be sent to destination
 	if util.IsGasToken(request.Transaction.DestToken) {
 		gasAmount = request.Transaction.DestAmount
-	} else if request.Transaction.ZapNative != nil {
+	} else if request.Transaction.ZapNative != nil { // Handle native token amount for Zap operations
 		gasAmount = request.Transaction.ZapNative
services/rfq/contracts/testcontracts/recipientmock/recipientmock.contractinfo.json (1)

1-1: Consider aligning Solidity version requirements

There's a discrepancy between the source code pragma (^0.8.4) and the actual compiler version used (0.8.20). While this works due to semantic versioning, it's better to align these versions to prevent potential compatibility issues.

Consider updating the pragma to match the compiler version:

-pragma solidity ^0.8.4;
+pragma solidity ^0.8.20;
services/rfq/relayer/reldb/base/model.go (2)

81-82: Consider enhancing field documentation

The comments for the new fields could be more descriptive to better explain their purpose:

  • What does the "native value" represent in the context of zap operations?
  • What kind of data is expected in the ZapData byte array?

Also applies to: 94-95


242-243: LGTM! Consider caching pow10 calculations

The conversion logic is correct and maintains symmetry with FromQuoteRequest. However, since math.Pow10 is used multiple times with the same values, consider caching these calculations to improve performance.

 func (r RequestForQuote) ToQuoteRequest() (*reldb.QuoteRequest, error) {
+    // Cache pow10 calculations
+    originPow10 := big.NewInt(int64(math.Pow10(int(r.OriginTokenDecimals))))
+    destPow10 := big.NewInt(int64(math.Pow10(int(r.DestTokenDecimals))))
+    nativePow10 := big.NewInt(int64(math.Pow10(int(nativeTokenDecimals))))
+
     // ... existing code ...
 
     return &reldb.QuoteRequest{
         // ... existing fields ...
-        OriginAmount:    new(big.Int).Div(r.OriginAmount.BigInt(), big.NewInt(int64(math.Pow10(int(r.OriginTokenDecimals))))),
-        DestAmount:      new(big.Int).Div(r.DestAmount.BigInt(), big.NewInt(int64(math.Pow10(int(r.DestTokenDecimals))))),
-        OriginFeeAmount: new(big.Int).Div(r.OriginFeeAmount.BigInt(), big.NewInt(int64(math.Pow10(int(r.OriginTokenDecimals))))),
-        ZapNative:       new(big.Int).Div(r.ZapNative.BigInt(), big.NewInt(int64(math.Pow10(int(nativeTokenDecimals))))),
+        OriginAmount:    new(big.Int).Div(r.OriginAmount.BigInt(), originPow10),
+        DestAmount:      new(big.Int).Div(r.DestAmount.BigInt(), destPow10),
+        OriginFeeAmount: new(big.Int).Div(r.OriginFeeAmount.BigInt(), originPow10),
+        ZapNative:       new(big.Int).Div(r.ZapNative.BigInt(), nativePow10),
         // ... remaining fields ...
     }, nil
 }
services/rfq/contracts/testcontracts/recipientmock/recipientmock.abigen.go (1)

415-417: Consider using consistent parameter naming.

The zap function parameters are named differently across implementations:

  • IZapRecipient uses descriptive names: token, amount, zapData
  • RecipientMock uses generic names: arg0, arg1, arg2

Consider using consistent parameter names for better maintainability.

- func (_RecipientMock *RecipientMockTransactor) Zap(opts *bind.TransactOpts, arg0 common.Address, arg1 *big.Int, arg2 []byte) (*types.Transaction, error) {
+ func (_RecipientMock *RecipientMockTransactor) Zap(opts *bind.TransactOpts, token common.Address, amount *big.Int, zapData []byte) (*types.Transaction, error) {

Also applies to: 422-424, 429-431

services/rfq/e2e/rfq_test.go (1)

478-479: Consider adding test assertions for Zap parameters.

While the test includes the new ZapData and ZapNative parameters, it doesn't verify if these values are correctly processed by the recipient contract. Consider adding assertions to validate that the recipient contract correctly receives and processes these parameters.

 	i.Eventually(func() bool {
 		destUSDCBalance, err := destUSDCHandle.BalanceOf(&bind.CallOpts{Context: i.GetTestContext()}, destRecipient.Address())
 		i.NoError(err)
-		return destUSDCBalance.Cmp(big.NewInt(0)) > 0
+		if destUSDCBalance.Cmp(big.NewInt(0)) <= 0 {
+			return false
+		}
+		
+		// Verify that the recipient received the correct zap parameters
+		lastZapData, err := destRecipient.LastZapData(&bind.CallOpts{Context: i.GetTestContext()})
+		i.NoError(err)
+		if !bytes.Equal(lastZapData, []byte("Hello, world!")) {
+			return false
+		}
+		
+		lastZapNative, err := destRecipient.LastZapNative(&bind.CallOpts{Context: i.GetTestContext()})
+		i.NoError(err)
+		return lastZapNative.Cmp(big.NewInt(1_337_420)) == 0
 	})
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 95ea295 and 3a281aa.

📒 Files selected for processing (5)
  • services/rfq/contracts/testcontracts/recipientmock/recipientmock.abigen.go (3 hunks)
  • services/rfq/contracts/testcontracts/recipientmock/recipientmock.contractinfo.json (1 hunks)
  • services/rfq/e2e/rfq_test.go (2 hunks)
  • services/rfq/relayer/chain/chain.go (1 hunks)
  • services/rfq/relayer/reldb/base/model.go (4 hunks)
🔇 Additional comments (8)
services/rfq/relayer/chain/chain.go (1)

80-81: Consider reordering conditions for better maintainability

The current order mixes new (Zap) and legacy (TransactionV1) functionality. Consider grouping related conditions together and documenting the migration path.

Let's verify the usage of these fields across the codebase:

services/rfq/contracts/testcontracts/recipientmock/recipientmock.contractinfo.json (2)

1-1: Interface changes look good!

The renamed interface IZapRecipient with the new zap function is well-designed:

  • Proper parameter typing and naming
  • Payable modifier allows ETH transfers
  • Clear bytes4 return type for selector-based verification

1-1: Implementation provides good test coverage

The RecipientMock implementation is well-structured for testing:

  • Correctly implements the IZapRecipient interface
  • Includes receive() for ETH handling
  • Returns correct selector in zap()
  • Smart addition of testRecipientMock() to exclude from coverage
services/rfq/relayer/reldb/base/model.go (1)

151-152: Consider adding validation for ZapData

The ZapData is assigned directly without any validation. Consider adding checks for:

  • Maximum size limits to prevent excessive data storage
  • Data format validation if specific encoding is expected
services/rfq/contracts/testcontracts/recipientmock/recipientmock.abigen.go (3)

32-46: LGTM: Contract metadata and ABI definitions are consistent.

The contract metadata correctly defines the zap function interface with appropriate parameters and payable modifier.


48-89: Verify the contract interface renaming impact.

The contract interface has been consistently renamed from IFastBridgeRecipient to IZapRecipient. Let's verify that all dependent contracts have been updated accordingly.

#!/bin/bash
# Search for any remaining references to the old interface name
rg "IFastBridgeRecipient" -l

# Search for potential interface implementations
ast-grep --pattern 'contract $_ is IZapRecipient'

Line range hint 1-1: Note: This is an auto-generated file.

As indicated by the header comment, this file is auto-generated. Any manual changes should be made to the source contract instead of this file.

✅ Verification successful

Auto-generated file correctly reflects its source contract

The auto-generated file is properly derived from packages/contracts-rfq/test/mocks/RecipientMock.sol, which implements the IZapRecipient interface. The source contract and its generated bindings are consistently using the updated Zap terminology. No manual changes are needed in the generated file.

  • Source location: packages/contracts-rfq/test/mocks/RecipientMock.sol
  • Used in test files across rfq and core packages
  • Implements IZapRecipient interface correctly
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the source contract exists
fd -t f "RecipientMock.sol"

Length of output: 567


Script:

#!/bin/bash
# Check the content of the source contract to verify inheritance and interface usage
cat packages/contracts-rfq/test/mocks/RecipientMock.sol

# Also check for any other files that might be using this mock
rg "RecipientMock" -l

Length of output: 1597

services/rfq/e2e/rfq_test.go (1)

397-397: LGTM! Test name updated to reflect new terminology.

The test function has been appropriately renamed from TestArbitraryCall to TestZap to align with the updated FastBridgeV2 terminology.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
services/rfq/relayer/reldb/base/model_test.go (1)

39-40: Verify test coverage for new fields

The test initializes the new fields with zero values. Consider adding test cases with non-zero values to ensure proper handling of the new fields.

-			ZapNative:          big.NewInt(0),
-			ZapData:            []byte{},
+			ZapNative:          big.NewInt(1000000),
+			ZapData:            []byte{0x1, 0x2, 0x3},
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3a281aa and 6dfb170.

📒 Files selected for processing (2)
  • services/rfq/relayer/relapi/server_test.go (1 hunks)
  • services/rfq/relayer/reldb/base/model_test.go (1 hunks)

Comment on lines +214 to +215
ZapNative: big.NewInt(0),
ZapData: []byte{},
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance test coverage for new Zap fields

The test data initializes ZapNative to zero and ZapData to empty, which might not adequately exercise the new functionality. Consider adding test cases that cover:

  • Non-zero ZapNative values
  • Non-empty ZapData payloads
  • Edge cases for both fields

Here's a suggested enhancement to the test data:

 func (c *RelayerServerSuite) getTestQuoteRequest(status reldb.QuoteRequestStatus) reldb.QuoteRequest {
+    // Add test cases with different ZapNative and ZapData values
+    testCases := []struct {
+        zapNative *big.Int
+        zapData   []byte
+    }{
+        {big.NewInt(0), []byte{}},                    // Current case
+        {big.NewInt(1000), []byte{0x1, 0x2, 0x3}},   // Non-zero values
+        {big.NewInt(1e18), []byte("test payload")},   // Large number and string payload
+    }
     // ... rest of the function
 }

Committable suggestion skipped: line range outside the PR's diff.

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 needs-go-generate-services/rfq size/l
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant