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: add all data to deployment events #1487

Merged
merged 9 commits into from
Nov 8, 2024

Conversation

aimensahnoun
Copy link
Member

@aimensahnoun aimensahnoun commented Nov 8, 2024

Towards #1283

Problem

The payment-subgraph could not index the feeAmount, feeAddress, and feeProxyUsed because they were not included in the deployment event.

Description of the changes

  • feat: add all data to deployment events

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced event emissions for proxy creation now include detailed fee information (feeAddress, feeAmount, feeProxyUsed).
    • Introduced a new public variable paymentReference in the ERC20SingleRequestProxy contract for better payment tracking.
  • Bug Fixes

    • Improved event validation in tests to ensure all relevant parameters are correctly emitted during proxy creation.
    • Enhanced error handling in tests for unsupported payment networks and invalid configurations.
  • Chores

    • Updated deployment details for the sepolia network in the artifact configuration.

Copy link

coderabbitai bot commented Nov 8, 2024

Walkthrough

The pull request introduces modifications to the SingleRequestProxyFactory contract, specifically updating the event declarations and emissions in the createEthereumSingleRequestProxy and createERC20SingleRequestProxy functions. The events now include additional parameters related to fees. The sepolia deployment details have been updated in the artifact configuration. The test suites have been enhanced to validate the new event parameters, ensuring comprehensive checks during proxy creation. Changes also include enhancements to the ERC20SingleRequestProxy and EthereumSingleRequestProxy contracts regarding payment references and constructor parameter order.

Changes

File Change Summary
packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol Updated event declarations for EthereumSingleRequestProxyCreated and ERC20SingleRequestProxyCreated to include feeAddress, feeAmount, and feeProxyUsed.
packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/index.ts Updated sepolia deployment details in singleRequestProxyFactoryArtifact.
packages/smart-contracts/test/contracts/SingleRequestProxyFactory.test.ts Expanded event emission checks in tests for createEthereumSingleRequestProxy and createERC20SingleRequestProxy to validate new parameters.
packages/payment-processor/test/payment/single-request-proxy.test.ts Updated event data decoding logic in tests to include new parameters and enhanced error handling for deployment scenarios.
packages/smart-contracts/src/contracts/ERC20SingleRequestProxy.sol Added paymentReference variable and updated constructor to initialize it; modified payment processing logic to include paymentReference.
packages/smart-contracts/src/contracts/EthereumSingleRequestProxy.sol Changed constructor parameter order and updated nonReentrant modifier to include checks for ethereumFeeProxy; adjusted receive function for fee handling.
packages/smart-contracts/test/contracts/ERC20SingleRequestProxy.test.ts Updated constructor parameter order in tests for ERC20SingleRequestProxy and UsdtFake to match changes in the contract.
packages/smart-contracts/test/contracts/EthereumSingleRequestProxy.test.ts Adjusted deployment parameters in tests for EthereumSingleRequestProxy to consistently include ethereumFeeProxy.

Possibly related PRs

Suggested reviewers

  • rodrigopavezi
  • alexandre-abrioux
  • kevindavee
  • yomarion
  • sstefdev

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between b61d1ed and 93279f2.

📒 Files selected for processing (4)
  • packages/payment-processor/src/payment/single-request-proxy.ts (1 hunks)
  • packages/payment-processor/test/payment/single-request-proxy.test.ts (3 hunks)
  • packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/0.1.0.json (2 hunks)
  • packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/index.ts (1 hunks)
🧰 Additional context used
📓 Learnings (3)
packages/payment-processor/src/payment/single-request-proxy.ts (6)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1487
File: packages/payment-processor/test/payment/single-request-proxy.test.ts:237-246
Timestamp: 2024-11-08T18:24:06.144Z
Learning: In `packages/payment-processor/test/payment/single-request-proxy.test.ts`, when asserting the `feeProxyUsed` in emitted events from `SingleRequestProxyFactory`, retrieve the `erc20FeeProxy` (or `ethereumFeeProxy`) public variable from the `SingleRequestProxyFactory` contract instead of using `wallet.address`.
Learnt from: aimensahnoun
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/src/payment/single-request-proxy.ts:202-209
Timestamp: 2024-10-29T09:00:54.169Z
Learning: In the `packages/payment-processor/src/payment/single-request-proxy.ts` file, within the `payWithEthereumSingleRequestProxy` function, the current error handling is acceptable as per the project's expectations.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/src/payment/single-request-proxy.ts:156-160
Timestamp: 2024-10-28T15:52:05.032Z
Learning: When determining if a `SingleRequestProxy` is an `ERC20SingleRequestProxy` or an `EthereumSingleRequestProxy`, include a comment explaining that the presence of `tokenAddress` distinguishes between the two.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1487
File: packages/payment-processor/src/payment/single-request-proxy.ts:0-0
Timestamp: 2024-11-08T20:01:10.313Z
Learning: In `packages/payment-processor/src/payment/single-request-proxy.ts`, when decoding event data, the team prefers not to include documentation of the event data structure if maintaining it would be difficult.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1487
File: packages/payment-processor/test/payment/single-request-proxy.test.ts:198-206
Timestamp: 2024-11-08T18:24:19.095Z
Learning: In tests for `SingleRequestProxyFactory`, the `feeProxyUsed` in events should be verified by retrieving the `ethereumFeeProxy` public variable from the `SingleRequestProxyFactory` contract, not `wallet.address`.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/src/payment/single-request-proxy.ts:156-160
Timestamp: 2024-10-28T15:52:05.032Z
Learning: In the `payRequestWithSingleRequestProxy` function of `single-request-proxy.ts`, failing to retrieve `tokenAddress()` is expected for `EthereumSingleRequestProxy` contracts and is not an error.
packages/payment-processor/test/payment/single-request-proxy.test.ts (6)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1487
File: packages/payment-processor/test/payment/single-request-proxy.test.ts:237-246
Timestamp: 2024-11-08T18:24:06.144Z
Learning: In `packages/payment-processor/test/payment/single-request-proxy.test.ts`, when asserting the `feeProxyUsed` in emitted events from `SingleRequestProxyFactory`, retrieve the `erc20FeeProxy` (or `ethereumFeeProxy`) public variable from the `SingleRequestProxyFactory` contract instead of using `wallet.address`.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/test/payment/single-request-proxy.test.ts:251-270
Timestamp: 2024-10-28T16:03:33.215Z
Learning: When testing the payment-processor module, specifically in `packages/payment-processor/test/payment/single-request-proxy.test.ts`, it's acceptable to omit tests for partial payments if they have already been covered at the smart-contract level.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1487
File: packages/payment-processor/test/payment/single-request-proxy.test.ts:198-206
Timestamp: 2024-11-08T18:24:19.095Z
Learning: In tests for `SingleRequestProxyFactory`, the `feeProxyUsed` in events should be verified by retrieving the `ethereumFeeProxy` public variable from the `SingleRequestProxyFactory` contract, not `wallet.address`.
Learnt from: aimensahnoun
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/src/payment/single-request-proxy.ts:202-209
Timestamp: 2024-10-29T09:00:54.169Z
Learning: In the `packages/payment-processor/src/payment/single-request-proxy.ts` file, within the `payWithEthereumSingleRequestProxy` function, the current error handling is acceptable as per the project's expectations.
Learnt from: aimensahnoun
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/test/payment/single-request-proxy.test.ts:225-228
Timestamp: 2024-10-29T08:03:10.464Z
Learning: In 'packages/payment-processor/test/payment/single-request-proxy.test.ts' (TypeScript), when testing with an invalid proxy address, we should not use the zero address.
Learnt from: aimensahnoun
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/test/payment/single-request-proxy.test.ts:138-139
Timestamp: 2024-10-29T08:02:02.600Z
Learning: When testing invalid requests in `packages/payment-processor/test/payment/single-request-proxy.test.ts`, it's acceptable to use `@ts-expect-error` to suppress TypeScript errors when the request intentionally lacks required properties.
packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/0.1.0.json (1)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1474
File: packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/0.1.0.json:24-124
Timestamp: 2024-10-28T20:00:53.026Z
Learning: In our smart contracts, we should remove the `indexed` keyword from all event parameters except for `paymentReference`, as we use the payment-subgraph for indexing and this reduces gas costs.
🔇 Additional comments (9)
packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/index.ts (2)

17-18: LGTM: Deployment artifact updates are consistent with contract changes.

The updated Sepolia deployment details reflect the new contract deployment required for the enhanced event signatures that include fee-related parameters.


17-18: Verify the new contract deployment on Sepolia.

Let's verify that the new contract deployment is properly set up:

Please ensure:

  1. The contract is verified on Sepolia block explorer
  2. The deployed bytecode includes the new event signatures
  3. The contract is functioning as expected with the updated events
packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/0.1.0.json (2)

119-136: LGTM! Event parameter additions maintain consistency.

The fee-related parameters mirror those added to the ERC20 event, maintaining a consistent structure across both event types. The non-indexed status of these parameters aligns with our gas optimization practices.

Let's verify the event emission implementation:

✅ Verification successful

Event implementation is correctly updated with fee parameters

The event emission in createEthereumSingleRequestProxy() function correctly includes all the new fee-related parameters (feeAddress, feeAmount, feeProxyUsed) in the correct order, matching the event definition. The implementation is consistent with both the ABI changes and maintains parity with the ERC20 event structure.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the event emission includes all new parameters
# Expected: Find event emission with all parameters in the implementation

ast-grep --pattern 'emit EthereumSingleRequestProxyCreated($$$, feeAddress, feeAmount, feeProxyUsed)'

Length of output: 103


Script:

#!/bin/bash
# Let's first find all files that might contain the event emission
fd -e sol -e js -e ts | xargs rg "EthereumSingleRequestProxyCreated" -B 2 -A 2

Length of output: 3143


Script:

#!/bin/bash
# Let's check the actual event emission in the contract implementation
cat packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol

Length of output: 4406


63-80: LGTM! Event parameter additions align with requirements.

The new fee-related parameters (feeAddress, feeAmount, feeProxyUsed) are correctly added to the event and properly typed. The non-indexed status of these parameters aligns with our gas optimization practices.

Let's verify the event emission implementation:

✅ Verification successful

Event emissions correctly include all new fee-related parameters

The implementation in SingleRequestProxyFactory.sol shows that both events (ERC20SingleRequestProxyCreated and EthereumSingleRequestProxyCreated) are properly emitting all the required parameters including the new fee-related ones (_feeAddress, _feeAmount, and the respective fee proxy addresses) in the correct order.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the event emission includes all new parameters
# Expected: Find event emission with all parameters in the implementation

ast-grep --pattern 'emit ERC20SingleRequestProxyCreated($$$, feeAddress, feeAmount, feeProxyUsed)'

Length of output: 103


Script:

#!/bin/bash
# Let's try to find the contract implementation file first
fd "SingleRequestProxyFactory" --type f --extension sol

# Then we'll search for the event emission in the implementation
rg "emit (ERC20|Ethereum)SingleRequestProxyCreated" -A 5

Length of output: 1298


Script:

#!/bin/bash
# Let's get more context around the event emissions to see all parameters
rg "emit (ERC20|Ethereum)SingleRequestProxyCreated" -B 2 -A 8 packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol

Length of output: 559

packages/payment-processor/src/payment/single-request-proxy.ts (2)

104-104: LGTM! Safe event data extraction.

The implementation safely extracts the proxy address using optional chaining with a fallback mechanism.


94-98: LGTM! Robust event handling implementation.

The event handling implementation is more reliable now, using explicit event type checking based on the proxy type.

Let's verify the event names match the contract:

✅ Verification successful

Event names match the contract implementation perfectly

The verification confirms that both event names EthereumSingleRequestProxyCreated and ERC20SingleRequestProxyCreated are correctly defined in the SingleRequestProxyFactory.sol contract, matching exactly with the event names being checked in the TypeScript code.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify event names in SingleRequestProxyFactory contract
# Expected: Events named 'ERC20SingleRequestProxyCreated' and 'EthereumSingleRequestProxyCreated'

rg -A 2 'event (ERC20|Ethereum)SingleRequestProxyCreated'

Length of output: 649

packages/payment-processor/test/payment/single-request-proxy.test.ts (3)

173-173: LGTM: Improved event filtering with block tracking.

The change from event count to block-based filtering is a more reliable approach for event verification.

Also applies to: 184-184


190-202: LGTM: Comprehensive event verification for EthereumSingleRequestProxy.

The event verification now properly checks all parameters including the fee-related data. The feeProxyUsed is correctly retrieved from the contract's ethereumFeeProxy.


208-208: LGTM: Comprehensive event verification for ERC20SingleRequestProxy.

The event verification follows the same pattern as the Ethereum proxy, with proper verification of all parameters including token address and fee-related data. The feeProxyUsed is correctly retrieved from the contract's erc20FeeProxy.

Also applies to: 219-219, 225-238


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

@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 comments (1)
packages/smart-contracts/test/contracts/SingleRequestProxyFactory.test.ts (1)

Line range hint 1-217: Consider adding edge case tests for fee parameters.

While the current test coverage is good, consider adding the following test cases to ensure robust validation of the fee-related functionality:

  1. Creation with zero fee amount
  2. Creation with zero address for fee recipient
  3. Creation when fee amount exceeds reasonable limits

Would you like me to provide example test implementations for these cases?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 3df13d5 and 593701f.

📒 Files selected for processing (3)
  • packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol (3 hunks)
  • packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/index.ts (0 hunks)
  • packages/smart-contracts/test/contracts/SingleRequestProxyFactory.test.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/index.ts
🧰 Additional context used
📓 Learnings (2)
packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol (3)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol:0-0
Timestamp: 2024-09-27T11:42:01.062Z
Learning: In the `createEthereumSingleRequestProxy` function, it's acceptable for `_feeAddress` to be the zero address, as setting the fee address to zero is a common practice. Adding zero address checks is unnecessary and adds extra gas cost.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/src/contracts/EthereumSingleRequestProxy.sol:11-15
Timestamp: 2024-10-05T14:43:14.816Z
Learning: In the `EthereumSingleRequestProxy` contract, the state variables `payee`, `paymentReference`, `feeAddress`, `feeAmount`, and `ethereumFeeProxy` should remain public, as they need to be accessed externally.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol:22-27
Timestamp: 2024-10-15T07:50:58.094Z
Learning: In the `SingleRequestProxyFactory` contract, the `paymentReference` parameter in events should remain `indexed`, even if removing `indexed` could reduce gas costs.
packages/smart-contracts/test/contracts/SingleRequestProxyFactory.test.ts (1)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/test/contracts/EthereumSingleRequestProxy.test.ts:0-0
Timestamp: 2024-10-17T18:33:41.124Z
Learning: In the `EthereumSingleRequestProxy` contract, the custom reentrancy guard is nearly identical to OpenZeppelin's ReentrancyGuard, except that it allows the first reentrancy call from the `ERC20FeeProxy`. We assume it works correctly without needing further tests.
🔇 Additional comments (5)
packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol (3)

24-27: LGTM! Event declarations enhanced with fee-related parameters.

The addition of feeAddress, feeAmount, and feeProxyUsed parameters to both events improves transparency by including all relevant fee data. The paymentReference correctly remains indexed for efficient event filtering.

Also applies to: 34-37


73-80: LGTM! Event emission includes all required parameters.

The event emission correctly includes all fee-related data and maintains proper parameter ordering.


24-37: Verify test coverage for new event parameters.

The AI summary mentions test updates, but let's verify the test coverage for the new event parameters.

✅ Verification successful

The previous search failed because we need to locate the test files first and ensure we're using the correct test assertion patterns for the framework being used. Let's cast a wider net to find relevant test coverage.


Let's specifically look for the test coverage of the SingleRequestProxy events to verify how the new event parameters are tested.


Based on the test coverage shown in the output, I can now provide a final response:

Test coverage verified for new event parameters

The test files show complete coverage for both events' parameters:

  • EthereumSingleRequestProxyCreated event is tested with all parameters including feeAddress, feeAmount, and feeProxyUsed in SingleRequestProxyFactory.test.ts
  • ERC20SingleRequestProxyCreated event is similarly tested with all parameters including the new fee-related fields

The tests verify both event emission and parameter correctness through expect().to.emit().withArgs() assertions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for event parameter assertions in tests
rg -A 5 "expect.*event.*SingleRequestProxy(Created|Event)" test/

Length of output: 112


Script:

#!/bin/bash
# First, let's find the test files in the repository
fd -e sol -e js -e ts "test|spec"

# Then search for event assertions in test files
rg -A 5 "emit.*SingleRequestProxy" 

# Also search for event parameter testing patterns
rg -A 5 "expectEmit|expect.*event" 

Length of output: 119984


Script:

#!/bin/bash
# Search for SingleRequestProxy test files and their event testing
fd -e ts "SingleRequestProxy.*test"

# Search for event testing in SingleRequestProxy tests
rg -A 10 "emit.*SingleRequestProxy|expect.*SingleRequestProxy" packages/smart-contracts/test/

Length of output: 19398

packages/smart-contracts/test/contracts/SingleRequestProxyFactory.test.ts (2)

88-95: LGTM! Event assertion properly validates fee parameters.

The updated event assertion correctly validates all parameters including the new fee-related fields (feeRecipientAddress, feeAmount, ethereumFeeProxy.address). This aligns with the contract changes to include fee information in deployment events.


130-138: LGTM! Event assertion properly validates ERC20 proxy parameters.

The updated event assertion correctly validates all parameters including token address and fee-related fields. The test provides good coverage by checking both the event emission and the resulting proxy state.

@MantisClone MantisClone changed the title refactor: add all data to deployment events feat: add all data to deployment events Nov 8, 2024
Copy link

@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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 593701f and c2e4d1b.

📒 Files selected for processing (1)
  • packages/payment-processor/test/payment/single-request-proxy.test.ts (2 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/payment-processor/test/payment/single-request-proxy.test.ts (4)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/test/payment/single-request-proxy.test.ts:251-270
Timestamp: 2024-10-28T16:03:33.215Z
Learning: When testing the payment-processor module, specifically in `packages/payment-processor/test/payment/single-request-proxy.test.ts`, it's acceptable to omit tests for partial payments if they have already been covered at the smart-contract level.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/src/payment/single-request-proxy.ts:156-160
Timestamp: 2024-10-28T15:52:05.032Z
Learning: When determining if a `SingleRequestProxy` is an `ERC20SingleRequestProxy` or an `EthereumSingleRequestProxy`, include a comment explaining that the presence of `tokenAddress` distinguishes between the two.
Learnt from: aimensahnoun
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/src/payment/single-request-proxy.ts:202-209
Timestamp: 2024-10-29T09:00:54.169Z
Learning: In the `packages/payment-processor/src/payment/single-request-proxy.ts` file, within the `payWithEthereumSingleRequestProxy` function, the current error handling is acceptable as per the project's expectations.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/test/contracts/ERC20SingleRequestProxy.test.ts:150-152
Timestamp: 2024-10-17T18:30:55.410Z
Learning: In `packages/smart-contracts/test/contracts/ERC20SingleRequestProxy.test.ts`, the skipped test `'should process a partial payment correctly'` exists intentionally to show that partial payments are supported without duplicating previous happy-path tests.

Copy link

@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 UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between c2e4d1b and 74281b6.

📒 Files selected for processing (4)
  • packages/payment-processor/test/payment/single-request-proxy.test.ts (2 hunks)
  • packages/smart-contracts/src/contracts/ERC20SingleRequestProxy.sol (1 hunks)
  • packages/smart-contracts/src/contracts/EthereumSingleRequestProxy.sol (1 hunks)
  • packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol (3 hunks)
🧰 Additional context used
📓 Learnings (4)
packages/payment-processor/test/payment/single-request-proxy.test.ts (5)
Learnt from: aimensahnoun
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/test/contracts/EthereumSingleRequestProxy.test.ts:0-0
Timestamp: 2024-10-17T16:01:47.326Z
Learning: The `rescueFunds` function in `EthereumSingleRequestProxy` does not emit any events.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/test/payment/single-request-proxy.test.ts:251-270
Timestamp: 2024-10-28T16:03:33.215Z
Learning: When testing the payment-processor module, specifically in `packages/payment-processor/test/payment/single-request-proxy.test.ts`, it's acceptable to omit tests for partial payments if they have already been covered at the smart-contract level.
Learnt from: aimensahnoun
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/src/payment/single-request-proxy.ts:202-209
Timestamp: 2024-10-29T09:00:54.169Z
Learning: In the `packages/payment-processor/src/payment/single-request-proxy.ts` file, within the `payWithEthereumSingleRequestProxy` function, the current error handling is acceptable as per the project's expectations.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/src/payment/single-request-proxy.ts:156-160
Timestamp: 2024-10-28T15:52:05.032Z
Learning: When determining if a `SingleRequestProxy` is an `ERC20SingleRequestProxy` or an `EthereumSingleRequestProxy`, include a comment explaining that the presence of `tokenAddress` distinguishes between the two.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/test/contracts/ERC20SingleRequestProxy.test.ts:150-152
Timestamp: 2024-10-17T18:30:55.410Z
Learning: In `packages/smart-contracts/test/contracts/ERC20SingleRequestProxy.test.ts`, the skipped test `'should process a partial payment correctly'` exists intentionally to show that partial payments are supported without duplicating previous happy-path tests.
packages/smart-contracts/src/contracts/ERC20SingleRequestProxy.sol (2)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/src/contracts/EthereumSingleRequestProxy.sol:11-15
Timestamp: 2024-10-05T14:43:14.816Z
Learning: In the `EthereumSingleRequestProxy` contract, the state variables `payee`, `paymentReference`, `feeAddress`, `feeAmount`, and `ethereumFeeProxy` should remain public, as they need to be accessed externally.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol:22-27
Timestamp: 2024-10-15T07:50:58.094Z
Learning: In the `SingleRequestProxyFactory` contract, the `paymentReference` parameter in events should remain `indexed`, even if removing `indexed` could reduce gas costs.
packages/smart-contracts/src/contracts/EthereumSingleRequestProxy.sol (5)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/src/contracts/EthereumSingleRequestProxy.sol:11-15
Timestamp: 2024-10-05T14:43:14.816Z
Learning: In the `EthereumSingleRequestProxy` contract, the state variables `payee`, `paymentReference`, `feeAddress`, `feeAmount`, and `ethereumFeeProxy` should remain public, as they need to be accessed externally.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/src/contracts/EthereumSingleRequestProxy.sol:19-23
Timestamp: 2024-10-05T14:43:07.965Z
Learning: In the `EthereumSingleRequestProxy` contract, a custom reentrancy guard is used instead of OpenZeppelin's `ReentrancyGuard`, with minor edits to allow reentrancy by the `ethereumFeeProxy`.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/src/contracts/EthereumSingleRequestProxy.sol:77-78
Timestamp: 2024-10-15T07:50:54.734Z
Learning: In the `receive()` function of the `EthereumSingleRequestProxy` contract (`packages/smart-contracts/src/contracts/EthereumSingleRequestProxy.sol`), the current error handling for the call to `ethereumFeeProxy` is considered sufficient, and no additional error handling is required.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol:0-0
Timestamp: 2024-09-27T11:42:01.062Z
Learning: In the `createEthereumSingleRequestProxy` function, it's acceptable for `_feeAddress` to be the zero address, as setting the fee address to zero is a common practice. Adding zero address checks is unnecessary and adds extra gas cost.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/test/contracts/EthereumSingleRequestProxy.test.ts:0-0
Timestamp: 2024-10-17T18:33:41.124Z
Learning: In the `EthereumSingleRequestProxy` contract, the custom reentrancy guard is nearly identical to OpenZeppelin's ReentrancyGuard, except that it allows the first reentrancy call from the `ERC20FeeProxy`. We assume it works correctly without needing further tests.
packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol (3)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol:0-0
Timestamp: 2024-09-27T11:42:01.062Z
Learning: In the `createEthereumSingleRequestProxy` function, it's acceptable for `_feeAddress` to be the zero address, as setting the fee address to zero is a common practice. Adding zero address checks is unnecessary and adds extra gas cost.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/src/contracts/EthereumSingleRequestProxy.sol:11-15
Timestamp: 2024-10-05T14:43:14.816Z
Learning: In the `EthereumSingleRequestProxy` contract, the state variables `payee`, `paymentReference`, `feeAddress`, `feeAmount`, and `ethereumFeeProxy` should remain public, as they need to be accessed externally.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol:22-27
Timestamp: 2024-10-15T07:50:58.094Z
Learning: In the `SingleRequestProxyFactory` contract, the `paymentReference` parameter in events should remain `indexed`, even if removing `indexed` could reduce gas costs.
🔇 Additional comments (8)
packages/smart-contracts/src/contracts/ERC20SingleRequestProxy.sol (2)

16-16: LGTM! Public visibility maintained for external access.

The addition of bytes public paymentReference follows the established pattern of public state variables, which is correct as per previous implementations.


16-16: Verify event emission in factory contract.

These changes support the PR objective of adding data to deployment events, but we should verify that the factory contract properly emits events with this data.

Also applies to: 24-24, 31-31

✅ Verification successful

Event emission is properly implemented

The factory contract (SingleRequestProxyFactory.sol) correctly defines and emits the ERC20SingleRequestProxyCreated event with the paymentReference parameter. The event is emitted in the createERC20SingleRequestProxy function with all required parameters, including the payment reference data from the proxy contract.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the factory contract properly emits events with the new payment reference
ast-grep --pattern 'event ERC20SingleRequestProxyCreated(
  $$$
  bytes indexed paymentReference,
  $$$
)'

Length of output: 108


Script:

#!/bin/bash
# Let's try a broader search for the event definition and its emission
rg -A 5 "event ERC20SingleRequestProxyCreated"

# Also search for any emit statements related to this event
rg -A 5 "emit ERC20SingleRequestProxyCreated"

# Let's also check the factory contract implementation
fd -e sol "Factory" --exec cat {}

Length of output: 5605

packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol (4)

24-27: LGTM: Event declarations properly enhanced with fee parameters.

The addition of feeAddress, feeAmount, and feeProxyUsed parameters to both events aligns with the PR objectives and will enable proper indexing by the payment-subgraph. The indexed keyword is correctly maintained on paymentReference as required.

Also applies to: 34-37


70-79: LGTM: Proxy creation and event emission properly updated.

The changes correctly:

  • Update constructor parameters to match the proxy's signature
  • Emit the event with all required fee-related data

109-117: LGTM: Event emission properly includes fee parameters.

The ERC20SingleRequestProxyCreated event emission correctly includes all necessary parameters, maintaining consistency with the Ethereum proxy implementation.


Line range hint 24-117: Verify completeness of event emission updates.

Let's ensure no other event emissions were missed in the codebase.

✅ Verification successful

Event emissions are complete and correctly implemented

After reviewing the code, I can confirm that:

  1. The SingleRequestProxyFactory contract correctly emits both EthereumSingleRequestProxyCreated and ERC20SingleRequestProxyCreated events with all required parameters when creating respective proxies.
  2. The proxy contracts themselves (EthereumSingleRequestProxy and ERC20SingleRequestProxy) don't need to emit these events as they are correctly emitted by the factory.
  3. All event parameters match the contract state and function parameters.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any other event emissions that might need similar updates
rg -A 2 "emit (Ethereum|ERC20)SingleRequestProxyCreated" --type sol

Length of output: 97


Script:

#!/bin/bash
# Search for event emissions in Solidity files using a more generic pattern
rg -t solidity -A 2 "emit (Ethereum|ERC20)SingleRequestProxyCreated"

Length of output: 103


Script:

#!/bin/bash
# List all Solidity files to ensure we're searching in the right place
fd -e sol

Length of output: 2739


Script:

#!/bin/bash
# Alternative search using ast-grep for event emissions
ast-grep --pattern 'emit $_ ($$$)'

Length of output: 36


Script:

#!/bin/bash
# Search for event emissions in the SingleRequestProxyFactory.sol file
cat packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol

Length of output: 4406


Script:

#!/bin/bash
# Also check the proxy contracts for any related event emissions
cat packages/smart-contracts/src/contracts/EthereumSingleRequestProxy.sol
cat packages/smart-contracts/src/contracts/ERC20SingleRequestProxy.sol

Length of output: 6639

packages/payment-processor/test/payment/single-request-proxy.test.ts (2)

192-195: LGTM! Event data decoding is correctly implemented.

The decoder parameters correctly match the expected event structure for EthereumSingleRequestProxyCreated, including the fee-related fields.


231-234: LGTM! Event data decoding is correctly implemented.

The decoder parameters correctly match the expected event structure for ERC20SingleRequestProxyCreated, including the fee-related fields.

Copy link

@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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 35e327c and b61d1ed.

📒 Files selected for processing (1)
  • packages/payment-processor/src/payment/single-request-proxy.ts (1 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/payment-processor/src/payment/single-request-proxy.ts (5)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/src/payment/single-request-proxy.ts:156-160
Timestamp: 2024-10-28T15:52:05.032Z
Learning: When determining if a `SingleRequestProxy` is an `ERC20SingleRequestProxy` or an `EthereumSingleRequestProxy`, include a comment explaining that the presence of `tokenAddress` distinguishes between the two.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1487
File: packages/payment-processor/test/payment/single-request-proxy.test.ts:237-246
Timestamp: 2024-11-08T18:24:06.144Z
Learning: In `packages/payment-processor/test/payment/single-request-proxy.test.ts`, when asserting the `feeProxyUsed` in emitted events from `SingleRequestProxyFactory`, retrieve the `erc20FeeProxy` (or `ethereumFeeProxy`) public variable from the `SingleRequestProxyFactory` contract instead of using `wallet.address`.
Learnt from: aimensahnoun
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/src/payment/single-request-proxy.ts:202-209
Timestamp: 2024-10-29T09:00:54.169Z
Learning: In the `packages/payment-processor/src/payment/single-request-proxy.ts` file, within the `payWithEthereumSingleRequestProxy` function, the current error handling is acceptable as per the project's expectations.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/src/payment/single-request-proxy.ts:156-160
Timestamp: 2024-10-28T15:52:05.032Z
Learning: In the `payRequestWithSingleRequestProxy` function of `single-request-proxy.ts`, failing to retrieve `tokenAddress()` is expected for `EthereumSingleRequestProxy` contracts and is not an error.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1487
File: packages/payment-processor/test/payment/single-request-proxy.test.ts:198-206
Timestamp: 2024-11-08T18:24:19.095Z
Learning: In tests for `SingleRequestProxyFactory`, the `feeProxyUsed` in events should be verified by retrieving the `ethereumFeeProxy` public variable from the `SingleRequestProxyFactory` contract, not `wallet.address`.

@aimensahnoun aimensahnoun force-pushed the update-srp-to-index-all-public-variables branch from b61d1ed to 93279f2 Compare November 8, 2024 19:57
@aimensahnoun aimensahnoun enabled auto-merge (squash) November 8, 2024 20:14
@aimensahnoun aimensahnoun merged commit e004515 into master Nov 8, 2024
25 checks passed
@aimensahnoun aimensahnoun deleted the update-srp-to-index-all-public-variables branch November 8, 2024 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Support SingleRequestProxy in the Request Network SDK
3 participants