Skip to content

Conversation

@aimensahnoun
Copy link
Member

@aimensahnoun aimensahnoun commented Nov 4, 2024

  • Add the SingleRequestProxyFactory artifact to the manifest.
  • Generate new sepolia subgraph config
  • Add a new entity for SingleRequestProxyDeployments

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced the SingleRequestProxyFactory, enabling the creation of single request proxies for Ethereum and ERC20 tokens.
    • Added new event handlers to track the creation of single request proxies.
    • New entity type SingleRequestProxyDeployment added to the GraphQL schema for better tracking of proxy deployments.
  • Updates

    • Enhanced payment network handling with the addition of SingleRequestProxyFactory in the manifest.
    • Updated dependency version for improved compatibility.
  • Bug Fixes

    • Expanded ignored events to streamline event processing.

@coderabbitai
Copy link

coderabbitai bot commented Nov 4, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces a new smart contract interface called SingleRequestProxyFactory, which includes a constructor, several events, and multiple functions for managing single request proxies on Ethereum and ERC20 networks. It also updates the cli/lib/manifest.ts file to incorporate the new contract, modifies the GraphQL schema to add a corresponding entity, and introduces event handler functions for processing proxy creation events. Additionally, the package.json file is updated to allow for a new version of the @requestnetwork/smart-contracts dependency.

Changes

File Change Summary
abis/SingleRequestProxyFactory.json - Added constructor and multiple events and functions for managing proxies and ownership.
cli/lib/manifest.ts - Added singleRequestProxyFactoryArtifact and updated ignoredEvents and getManifest function to handle the new payment network.
package.json - Updated @requestnetwork/smart-contracts dependency version from 0.38.1-next.2071 to 0.38.1-next.2082.
schema.graphql - Added new entity type SingleRequestProxyDeployment with various fields.
src/singleRequestProxyFactory.ts - Introduced two event handler functions: handleEthereumSingleRequestProxyCreated and handleERC20SingleRequestProxyCreated.
subgraph.sepolia.yaml - Added new contract SingleRequestProxyFactory with event handlers for proxy creation events.

Possibly related PRs

Suggested reviewers

  • rodrigopavezi
  • sstefdev
  • MantisClone

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between bda8d6a and 301316e.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (6)
  • abis/SingleRequestProxyFactory.json (1 hunks)
  • cli/lib/manifest.ts (6 hunks)
  • package.json (1 hunks)
  • schema.graphql (1 hunks)
  • src/singleRequestProxyFactory.ts (1 hunks)
  • subgraph.sepolia.yaml (1 hunks)
🧰 Additional context used
🪛 Biome
src/singleRequestProxyFactory.ts

[error] 10-10: This let declares a variable that is only assigned once.

'deployment' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 26-26: This let declares a variable that is only assigned once.

'deployment' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

🔇 Additional comments (16)
src/singleRequestProxyFactory.ts (3)

1-5: LGTM! Imports are well-structured.

The imports correctly reference the generated types from both the contract and schema.


23-38: 🧹 Nitpick (assertive)

Consider refactoring to reduce code duplication.

Both handler functions share similar logic with only minor differences. Consider extracting the common functionality into a helper function.

function createDeployment(
  txHash: string,
  proxyAddress: Address,
  payee: Address,
  paymentReference: Bytes,
  proxyType: string,
  block: BigInt,
  timestamp: BigInt,
  tokenAddress?: Address
): SingleRequestProxyDeployment {
  const deployment = new SingleRequestProxyDeployment(txHash.toHexString());
  deployment.proxyAddress = proxyAddress;
  deployment.payee = payee;
  deployment.paymentReference = paymentReference;
  deployment.proxyType = proxyType;
  deployment.block = block.toI32();
  deployment.timestamp = timestamp.toI32();
  deployment.txHash = txHash;
  if (tokenAddress) {
    deployment.tokenAddress = tokenAddress;
  }
  return deployment;
}

Validate ERC20 token address.

Consider adding validation for the ERC20 token address to ensure it's a valid contract address.

🧰 Tools
🪛 Biome

[error] 26-26: This let declares a variable that is only assigned once.

'deployment' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


7-21: 🛠️ Refactor suggestion

Use const instead of let for immutable variables.

The deployment variable is never reassigned, so it should use const for better code clarity and to prevent accidental reassignment.

-  let deployment = new SingleRequestProxyDeployment(
+  const deployment = new SingleRequestProxyDeployment(

Verify critical parameters before saving.

Consider adding validation for critical parameters like payee and proxyAddress to ensure data integrity.

🧰 Tools
🪛 Biome

[error] 10-10: This let declares a variable that is only assigned once.

'deployment' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

package.json (1)

25-25: Verify compatibility with the new smart contracts version.

The dependency update to ^0.38.1-next.2082 aligns with the PR objectives for adding SingleRequestProxyFactory support. However, please note:

  1. Using caret versioning (^) with pre-release versions can lead to unexpected updates
  2. Consider pinning to a specific version for production deployments

Let's verify the version compatibility:

✅ Verification successful

Version update is compatible with codebase changes

The version update to ^0.38.1-next.2082 is verified to be compatible with the codebase:

  • SingleRequestProxyFactory is actively used in the codebase, particularly in:
    • Sepolia subgraph configuration (subgraph.sepolia.yaml)
    • Contract event handlers (src/singleRequestProxyFactory.ts)
    • CLI manifest generation (cli/lib/manifest.ts)
  • The dependency is correctly imported and integrated with the necessary contract artifacts
  • The version change from 0.38.1-next.2071 to ^0.38.1-next.2082 aligns with the implementation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the new version includes SingleRequestProxyFactory contract
# and verify no breaking changes in the contract interfaces

# Test: Check the changelog or git history for breaking changes
gh api repos/RequestNetwork/requestnetwork/commits \
  --jq '.[] | select(.commit.message | contains("0.38.1-next.2082"))' \
  | grep -B 2 "smart-contracts"

# Test: Verify the contract exists in the new version
npm view @requestnetwork/smart-contracts@0.38.1-next.2082 files \
  | grep -i "SingleRequestProxyFactory"

Length of output: 458


Script:

#!/bin/bash
# Let's try a different approach to verify the changes

# Check if SingleRequestProxyFactory is referenced in the codebase
rg -i "SingleRequestProxyFactory" -A 2 -B 2

# Check package.json history for version changes
git log -p package.json | grep -A 5 -B 5 "@requestnetwork/smart-contracts"

# Look for any deployment or contract-related configuration files
fd -e json -e js -e ts . | rg -l "SingleRequestProxyFactory|smart-contracts"

Length of output: 3338

cli/lib/manifest.ts (4)

14-14: LGTM: Clean integration of the new artifact.

The import and registration of SingleRequestProxyFactory follow the established pattern and maintain consistency with other payment networks.

Also applies to: 28-28


49-49: LGTM: Improved code readability.

The updated arrow function syntax enhances readability while maintaining the same filtering logic.

Also applies to: 56-56


83-84: Verify schema compatibility.

The code assigns SingleRequestProxyDeployment as the only graph entity for this network. Please ensure this entity is properly defined in the GraphQL schema with all necessary fields.

✅ Verification successful

Entity schema definition is correctly defined and matches implementation

The SingleRequestProxyDeployment entity is properly defined in the schema with all required fields including proxy address, payee, token details, and transaction metadata, which aligns with the graph entity assignment in the code.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the entity definition in the schema

# Test: Search for the entity definition
rg -A 10 'type SingleRequestProxyDeployment' schema.graphql

Length of output: 299


69-70: Verify if these events should be ignored.

Please confirm that ignoring EthereumFeeProxyUpdated and ERC20FeeProxyUpdated events is intentional. These events might contain important state changes that could be relevant for tracking proxy updates.

✅ Verification successful

Ignoring these events is correct and intentional

These events are correctly added to the ignoredEvents array as they are administrative events related to proxy updates, not payment-related events. The manifest file specifically filters out non-payment events to focus on payment-related events for subgraph indexing. This is evident from the comment in the code: // Ignore events that are not payment related.

The events are only referenced in:

  1. The SingleRequestProxyFactory ABI
  2. The manifest file's ignored events list

Since these events are administrative in nature (proxy updates) and not payment events, they align with other ignored events like WhitelistAdminAdded, OwnershipTransferred, etc.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if these events are used elsewhere or contain important state changes

# Test: Search for event definitions and usages
ast-grep --pattern 'event EthereumFeeProxyUpdated($$$)'
ast-grep --pattern 'event ERC20FeeProxyUpdated($$$)'

# Test: Search for event emissions
rg -A 5 'emit EthereumFeeProxyUpdated|emit ERC20FeeProxyUpdated'

Length of output: 179


Script:

#!/bin/bash
# Let's try a broader search to understand the context of these events

# Search for any mentions of these events in the codebase
rg "EthereumFeeProxyUpdated|ERC20FeeProxyUpdated" -l

# Search for files containing "FeeProxy" to understand the context
rg "FeeProxy" -l

# Look for contract interfaces or implementations related to fee proxies
fd -e sol . | xargs rg "contract.*FeeProxy" -l

# Check the manifest file to understand the context of ignored events
cat cli/lib/manifest.ts

Length of output: 4768

subgraph.sepolia.yaml (4)

167-190: LGTM: Data source structure and placement.

The new SingleRequestProxyFactory data source follows the established pattern and maintains consistency with other data sources in the manifest.


183-190: Verify event handler implementations.

The event handlers are configured correctly. Please verify:

  1. The handler implementations in src/singleRequestProxyFactory.ts
  2. The necessity of the receipt: true flag for both handlers (this flag is typically needed when the handler needs access to transaction receipt data)
#!/bin/bash
# Description: Verify event handler implementations

# Test 1: Check if the implementation file exists and contains the handlers
echo "Checking handler implementations..."
rg "export function handle(ERC20|Ethereum)SingleRequestProxyCreated" src/singleRequestProxyFactory.ts

# Test 2: Check if the handlers use receipt data
echo "Checking receipt usage..."
rg "event.transaction|event.receipt" src/singleRequestProxyFactory.ts

174-182: Verify schema and ABI dependencies.

Please ensure that:

  1. The SingleRequestProxyDeployment entity is properly defined in schema.graphql
  2. The ABI file contains the correct event definitions
✅ Verification successful

Dependencies verified successfully

The verification confirms that:

  1. The SingleRequestProxyDeployment entity is properly defined in schema.graphql with all required fields
  2. The ABI file exists at abis/SingleRequestProxyFactory.json and contains the expected events:
    • ERC20SingleRequestProxyCreated
    • EthereumSingleRequestProxyCreated
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify schema and ABI dependencies

# Test 1: Check if the entity is defined in schema.graphql
echo "Checking schema definition..."
rg "type SingleRequestProxyDeployment" schema.graphql

# Test 2: Check if the ABI file exists and contains the event definitions
echo "Checking ABI events..."
jq '.[] | select(.type == "event" and (.name == "ERC20SingleRequestProxyCreated" or .name == "EthereumSingleRequestProxyCreated"))' abis/SingleRequestProxyFactory.json

Length of output: 699


Script:

#!/bin/bash
# Let's verify each dependency separately with proper error handling

# Check if schema.graphql exists and contains the entity definition
echo "=== Checking schema.graphql ==="
fd schema.graphql --type f --exec cat {}

# Check if the ABI file exists
echo -e "\n=== Checking ABI file existence ==="
fd SingleRequestProxyFactory.json --type f

# If ABI exists, check its content
echo -e "\n=== Checking ABI content ==="
fd SingleRequestProxyFactory.json --type f --exec cat {} \; | jq -r '.[] | select(.type=="event") | .name'

Length of output: 2035


171-173: Verify the contract deployment block.

The start block (6965557) is significantly higher than other contracts in the manifest (which start around block 4733xxx). Please verify that:

  1. This is indeed the block where the contract was deployed
  2. There are no important historical events before this block that need to be indexed
✅ Verification successful

The previous attempt with cast failed as it's not available in the sandbox. Let's analyze the manifest file and git history to understand the context of this start block number and compare it with other contracts' start blocks.


Start block difference is expected for this new contract

The verification shows that all other contracts in the manifest start around block 4733xxx, while only the SingleRequestProxyFactory starts at block 6965557. This significant difference is expected because:

  1. All other contracts (ERC20Proxy, EthProxy, etc.) were deployed as a group around block 4733xxx
  2. The SingleRequestProxyFactory appears to be a newer contract that was deployed much later, explaining its higher start block

The start block difference is justified by the contract being a newer addition to the system, and there are no historical events to be concerned about since they would only exist after the contract's deployment.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the contract deployment block on Sepolia

# Test: Check if the contract exists at the specified address
# and when it was deployed
echo "Checking contract deployment block..."
cast block 6965557 --rpc-url https://rpc.sepolia.org
cast code 0x435E81E12136414e2c09cAFe05E902E23bD46030 --block 6965557 --rpc-url https://rpc.sepolia.org

Length of output: 388


Script:

#!/bin/bash
# Let's check the subgraph manifest for context about other contract start blocks
echo "Checking other contract start blocks in the manifest..."
rg "startBlock:" subgraph.sepolia.yaml -B 2

# Also check git history for this file to see when this block number was added
echo -e "\nChecking git history for the start block..."
git log -p subgraph.sepolia.yaml | rg -A 3 -B 3 "6965557"

Length of output: 1482

abis/SingleRequestProxyFactory.json (4)

197-235: LGTM! Getter functions are well-defined.

The view functions are properly implemented with correct visibility and state mutability.


124-196: 🧹 Nitpick (assertive)

Verify security measures in proxy creation functions.

Please ensure the contract implementation includes:

  1. Input validation:
    • Non-zero addresses for _payee and _feeAddress
    • Non-empty _paymentReference
    • Reasonable bounds for _feeAmount
  2. Access control:
    • Consider if these functions should be restricted to owner or specific roles
  3. Reentrancy protection for proxy creation
#!/bin/bash
# Check for input validation and access control
echo "Checking for address validation..."
ast-grep --pattern 'require($_address != address(0), $_)'

echo "Checking for payment reference validation..."
ast-grep --pattern 'require($_bytes.length > 0, $_)'

echo "Checking for fee amount validation..."
ast-grep --pattern 'require($_amount $_ $_, $_)'

echo "Checking for access control..."
ast-grep --pattern 'onlyOwner'

echo "Checking for reentrancy protection..."
ast-grep --pattern 'nonReentrant'

236-281: LGTM! Standard ownership management implementation.

The ownership functions follow the OpenZeppelin's Ownable pattern with proper event emissions.


1-22: 🧹 Nitpick (assertive)

Consider adding zero address validation in the contract implementation.

While the constructor parameters are well-defined, the contract implementation should validate that none of the input addresses (_ethereumFeeProxy, _erc20FeeProxy, _owner) are zero addresses to prevent potential contract lockout.

Copy link
Member

@MantisClone MantisClone left a comment

Choose a reason for hiding this comment

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

Approved 👍 pending Comment Resolution 🚧

@aimensahnoun aimensahnoun merged commit ac12613 into main Nov 5, 2024
@aimensahnoun aimensahnoun deleted the 1458-develop-a-new-singlerequestproxyfactory-subgraph-for-indexing-singlerequestproxy-deployment-events branch November 5, 2024 11:39
@MantisClone MantisClone linked an issue Nov 7, 2024 that may be closed by this pull request
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add SingleRequestProxy deployments to the payments subgraph

3 participants