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

Track wallet txs in OP and Base #23

Merged
merged 1 commit into from
Aug 16, 2024
Merged

Track wallet txs in OP and Base #23

merged 1 commit into from
Aug 16, 2024

Conversation

Inkvi
Copy link
Collaborator

@Inkvi Inkvi commented Aug 12, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced wallet processing with specific commands for Ethereum, Base, and Optimism wallets.
    • Introduced new processing modules for Ethereum, Base, and Optimism, improving transaction handling capabilities.
    • Added a transaction handler for efficient processing and storage of blockchain transaction data.
  • Bug Fixes

    • Improved command configurations for better clarity and organization in wallet-related processes.
  • Documentation

    • Updated documentation to reflect changes in wallet processing and command structures, ensuring consistency across blockchain platforms.

@Inkvi Inkvi requested a review from dshiell August 12, 2024 23:22
Copy link

coderabbitai bot commented Aug 12, 2024

Walkthrough

The recent updates enhance the organization and specificity of wallet processing commands across multiple blockchain environments, including Ethereum, Base, and Optimism. This restructuring improves clarity and management of wallet-related functionalities, while new modules for each blockchain enable robust transaction processing and database interactions. The changes aim to streamline transaction handling and improve overall efficiency within the system.

Changes

File Change Summary
commands.json Renamed process:wallets to process:eth:wallets; added process:base:wallets and process:optimism:wallets; updated production commands similarly.
src/chains/wallets/base.ts, eth.ts, optimism.ts Introduced new wallet processing modules for Base, Ethereum, and Optimism, configuring IbcProcessor for transaction handling with specific environment settings.
src/handlers/wallets.ts Implemented a transaction handler that processes and stores transaction data from blockchain interactions.
src/utils/ibc-processor.ts Modified the IbcProcessor function to include a new status property in its object structure for enhanced processing state management.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant IbcProcessor
    participant Database
    participant Handler

    Client->>IbcProcessor: Initiate transaction processing
    IbcProcessor->>Handler: Retrieve transaction data
    Handler->>Database: Store processed transactions
    Database-->>Handler: Confirm storage
    Handler-->>IbcProcessor: Acknowledge completion
    IbcProcessor-->>Client: Confirm transaction processing complete
Loading

Poem

🐇 In the world of wallets, oh so bright,
Transactions hop with pure delight.
Ethereum, Base, and Optimism too,
All join the dance, a blockchain crew.
With every change, our hearts take flight,
A rabbit's cheer for code done right! 🎉


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

@Inkvi Inkvi force-pushed the inkvi/track-base-op-txs branch 2 times, most recently from e85eb8a to 65e6a23 Compare August 13, 2024 18:56
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

Outside diff range, codebase verification and nitpick comments (6)
src/chains/wallets/base.ts (2)

6-8: Environment Variable BASE_FEE_VAULT Not Set

The environment variable BASE_FEE_VAULT is currently not set, which could lead to issues if your application depends on it. Please ensure that this variable is correctly configured in your deployment or runtime environment.

Analysis chain

Verify environment variable usage for ADDRESSES.

Ensure that the environment variable BASE_FEE_VAULT is correctly set and used.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the presence of the environment variable `BASE_FEE_VAULT`.

# Test: Check if the environment variable is set. Expect: Non-empty value.
echo "BASE_FEE_VAULT: ${BASE_FEE_VAULT}"

Length of output: 42


10-15: Environment variables BASE_RPC and RPC_RATE_LIMIT are not set.

The environment variables BASE_RPC and RPC_RATE_LIMIT are not set in the current environment and are required for the RPC endpoint configuration. Ensure these variables are properly configured in your deployment environment to avoid potential runtime issues.

  • BASE_RPC is used in:

    • src/chains/wallets/base.ts
    • src/chains/base.ts
  • RPC_RATE_LIMIT is used in:

    • src/chains/wallets/base.ts
    • src/chains/base.ts
    • src/chains/wallets/optimism.ts
    • src/chains/wallets/eth.ts
    • src/chains/backfill.ts
    • src/chains/optimism.ts
Analysis chain

Verify the RPC endpoint configuration.

Ensure that the RPC endpoint is correctly configured with the environment variables BASE_RPC and RPC_RATE_LIMIT.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the presence of environment variables `BASE_RPC` and `RPC_RATE_LIMIT`.

# Test: Check if the environment variables are set. Expect: Non-empty values.
echo "BASE_RPC: ${BASE_RPC}"
echo "RPC_RATE_LIMIT: ${RPC_RATE_LIMIT}"

Length of output: 73


Script:

#!/bin/bash
# Search for any references to BASE_RPC and RPC_RATE_LIMIT in the codebase.
rg 'BASE_RPC|RPC_RATE_LIMIT'

Length of output: 601

src/handlers/wallets.ts (1)

5-5: Add Error Handling for eth_chainId Call

The eth_chainId call in src/handlers/wallets.ts lacks error handling. Consider wrapping the call in a try-catch block or using promise error handling to manage potential errors gracefully.

  • Location: src/handlers/wallets.ts, line with ctx._chain.client.call("eth_chainId")
Analysis chain

Verify the chain ID retrieval.

Ensure that the eth_chainId call returns a valid chain ID. Consider adding error handling for this asynchronous operation.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the `eth_chainId` call in the handler function.

# Test: Search for the `eth_chainId` call. Expect: Proper error handling around the call.
rg --type typescript -A 5 $'ctx._chain.client.call("eth_chainId")'

Length of output: 102


Script:

#!/bin/bash
# Description: Verify the `eth_chainId` call in the handler function.

# Test: Search for the `eth_chainId` call in TypeScript files by specifying the file extension.
rg 'ctx._chain.client.call("eth_chainId")' --glob '*.ts' -A 5

Length of output: 63


Script:

#!/bin/bash
# Description: Search for any usage of `eth_chainId` in TypeScript files to gather context.

rg 'eth_chainId' --glob '*.ts' -A 5

Length of output: 386

commands.json (3)

67-71: Missing Script for process:base:wallets Command

The script lib/chains/wallets/base.js specified in the process:base:wallets command configuration is missing. Please ensure that this file exists in the repository. The dependencies build and migration:apply are correctly defined.

  • Check the existence of lib/chains/wallets/base.js.
Analysis chain

Ensure the Base wallets command is correctly configured.

Verify that the process:base:wallets command points to the correct script and that all dependencies are accurate.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the `process:base:wallets` command configuration.

# Test: Check if the command points to the correct script and dependencies. Expect: Correct file path and dependencies.
rg --type json -A 3 $'"process:base:wallets"'

Length of output: 340


Script:

#!/bin/bash
# Check if the script file exists
fd 'base.js' -e js

# Verify the definitions of the dependencies in commands.json
rg --type json -A 3 '"build"' commands.json
rg --type json -A 3 '"migration:apply"' commands.json

Length of output: 2766


62-65: Missing Script for Ethereum Wallets Command

The process:eth:wallets command is configured with correct dependencies, but the script lib/chains/wallets/eth.js does not exist in the repository. Please verify the file path or ensure the script is added to the repository.

  • Missing file: lib/chains/wallets/eth.js
Analysis chain

Ensure the Ethereum wallets command is correctly configured.

Verify that the process:eth:wallets command points to the correct script and that all dependencies are accurate.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the `process:eth:wallets` command configuration.

# Test: Check if the command points to the correct script and dependencies. Expect: Correct file path and dependencies.
rg --type json -A 3 $'"process:eth:wallets"'

Length of output: 332


Script:

#!/bin/bash
# Check if the script `lib/chains/wallets/eth.js` exists.
fd --type f 'eth.js' --exec echo "File found: {}"

# Verify if the dependencies `build` and `migration:apply` are defined in the same or related configuration files.
rg --type json '"build"' -A 2
rg --type json '"migration:apply"' -A 2

Length of output: 3138


72-75: Missing script file for process:optimism:wallets command

The script file lib/chains/wallets/optimism.js specified in the process:optimism:wallets command does not exist in the repository. Please ensure that the file is added or the path is corrected. The dependencies build and migration:apply are correctly defined.

Analysis chain

Ensure the Optimism wallets command is correctly configured.

Verify that the process:optimism:wallets command points to the correct script and that all dependencies are accurate.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the `process:optimism:wallets` command configuration.

# Test: Check if the command points to the correct script and dependencies. Expect: Correct file path and dependencies.
rg --type json -A 3 $'"process:optimism:wallets"'

Length of output: 356


Script:

#!/bin/bash
# Check if the script file exists at the specified path
fd 'optimism.js' --glob 'lib/chains/wallets/optimism.js'

# Check for the existence of dependencies in the configuration
rg '"build"' --type json
rg '"migration:apply"' --type json

Length of output: 1226

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7243809 and 65e6a23.

Files selected for processing (6)
  • commands.json (2 hunks)
  • src/chains/wallets/base.ts (1 hunks)
  • src/chains/wallets/eth.ts (1 hunks)
  • src/chains/wallets/optimism.ts (1 hunks)
  • src/handlers/wallets.ts (1 hunks)
  • src/utils/ibc-processor.ts (1 hunks)
Additional comments not posted (6)
src/utils/ibc-processor.ts (1)

30-30: Verify the integration of the status property.

The addition of the status property enhances the data structure. Ensure that this change is correctly integrated and utilized in the processing logic.

Verification successful

Integration of status Property in IbcProcessor

The status property is correctly integrated as part of the configuration for the EvmBatchProcessor in the IbcProcessor function. This integration ensures that the status field is included in the transaction fields processed by the batch processor. Further verification of its usage would require inspecting the EvmBatchProcessor implementation or documentation, which is outside the current codebase.

  • File: src/utils/ibc-processor.ts
  • Function: IbcProcessor
Scripts executed

The following scripts were executed for the analysis:

Script:

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

# Test: Search for occurrences of the `status` property. Expect: Proper usage in processing logic.
rg --type ts 'status: true'

Length of output: 78


Script:

#!/bin/bash
# Extract more context around the usage of `status: true` in the file to understand its integration.
rg --type ts -A 10 -B 10 'status: true' src/utils/ibc-processor.ts

Length of output: 354


Script:

#!/bin/bash
# Search for the function or method definition that contains the 'status: true' object in the file.
rg --type ts 'function ' -A 20 -B 5 src/utils/ibc-processor.ts

Length of output: 697

src/chains/wallets/eth.ts (3)

6-9: Verify environment variable usage for ADDRESSES.

Ensure that the environment variables BATCHER_ADDRESS and PROPOSER_ADDRESS are correctly set and used.


11-16: Verify the RPC endpoint configuration.

Ensure that the RPC endpoint is correctly configured with the environment variables TXS_RPC and RPC_RATE_LIMIT.


28-35: Verify the processor run configuration.

Ensure that the processor is correctly set up to run with the TypeormDatabase and the handler function.

Verification successful

Processor run configuration is correctly set up.

The handler function and TypeormDatabase are correctly imported and configured in src/chains/wallets/eth.ts. The handler function from src/handlers/wallets.ts is used, which aligns with the intended functionality. No issues found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the processor run configuration with `TypeormDatabase` and `handler`.

# Test: Search for the `handler` function definition. Expect: Correct implementation.
ast-grep --lang typescript --pattern $'async function handler(ctx) { $$$ }'

Length of output: 8948


Script:

#!/bin/bash
# Check imports in src/chains/wallets/eth.ts to verify the handler function and TypeormDatabase setup.

# Search for imports in the eth.ts file
rg '^import' src/chains/wallets/eth.ts -A 3

Length of output: 334

src/chains/wallets/base.ts (1)

30-37: Verify the processor run configuration.

Ensure that the processor is correctly set up to run with the TypeormDatabase and the handler function.

Verification successful

Let's verify the imports in src/chains/wallets/base.ts to confirm which handler function is being used, and check the setup of TypeormDatabase. This will help ensure the processor is correctly configured.


Processor run configuration is correctly set up.

The processor.run function in src/chains/wallets/base.ts is correctly configured with the TypeormDatabase and the appropriate handler function from ../../handlers/wallets. The database setup parameters are consistent with expected configurations for transaction handling. No issues found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the processor run configuration with `TypeormDatabase` and `handler`.

# Test: Search for the `handler` function definition. Expect: Correct implementation.
ast-grep --lang typescript --pattern $'async function handler(ctx) { $$$ }'

Length of output: 8948


Script:

#!/bin/bash
# Check imports in src/chains/wallets/base.ts to identify the handler being used
rg 'import .* from' src/chains/wallets/base.ts

# Verify the setup of TypeormDatabase in the codebase
ast-grep --lang typescript --pattern 'new TypeormDatabase({ $$$ })'

Length of output: 2100

src/chains/wallets/optimism.ts (1)

6-8: Verify the presence of environment variables.

Ensure that the environment variables OPTIMISM_FEE_VAULT and OPTIMISM_RPC are defined and valid. Missing or incorrect values could lead to runtime errors.

Comment on lines +10 to +29
let processor = IbcProcessor()
.setRpcEndpoint({
url: process.env.OPTIMISM_RPC!,
rateLimit: Number(process.env.RPC_RATE_LIMIT!),
maxBatchCallSize: MAX_BATCH_CALL_SIZE,
})
.setBlockRange({
from: Number(process.env.DISPATCHER_ADDRESS_OPTIMISM_START_BLOCK!),
})
.addTransaction({
from: ADDRESSES,
})
.addTransaction({
to: ADDRESSES,
})

if (process.env.OPTIMISM_TXS_GATEWAY) {
processor = processor.setGateway(process.env.OPTIMISM_TXS_GATEWAY)
}
Copy link

Choose a reason for hiding this comment

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

Enhance error handling for processor setup.

Consider adding error handling for the processor setup, especially for RPC endpoint and block range configurations. This can prevent potential issues if the environment variables are missing or incorrect.

try {
  processor = IbcProcessor()
    .setRpcEndpoint({
      url: process.env.OPTIMISM_RPC!,
      rateLimit: Number(process.env.RPC_RATE_LIMIT!),
      maxBatchCallSize: MAX_BATCH_CALL_SIZE,
    })
    .setBlockRange({
      from: Number(process.env.DISPATCHER_ADDRESS_OPTIMISM_START_BLOCK!),
    })
    .addTransaction({
      from: ADDRESSES,
    })
    .addTransaction({
      to: ADDRESSES,
    });

  if (process.env.OPTIMISM_TXS_GATEWAY) {
    processor = processor.setGateway(process.env.OPTIMISM_TXS_GATEWAY);
  }
} catch (error) {
  console.error("Error setting up processor:", error);
  process.exit(1);
}

Comment on lines +10 to +26
txs.push(new Transaction({
id: tx.hash,
transactionHash: tx.hash,
blockNumber: BigInt(block.header.height),
blockTimestamp: BigInt(block.header.timestamp),
chainId: chainId,
from: tx.from,
to: tx.to,
value: BigInt(tx.value),
gas: BigInt(tx.gas),
gasPrice: BigInt(tx.gasPrice),
maxFeePerGas: tx.maxFeePerGas ? BigInt(tx.maxFeePerGas) : null,
maxPriorityFeePerGas: tx.maxPriorityFeePerGas ? BigInt(tx.maxPriorityFeePerGas) : null,
gasUsed: BigInt(tx.gasUsed),
cumulativeGasUsed: BigInt(tx.cumulativeGasUsed),
transactionType: tx.type,
}))
Copy link

Choose a reason for hiding this comment

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

Optimize transaction processing.

Consider using a map or reduce function to process transactions more efficiently, especially if the number of transactions is large.

const txs = ctx.blocks.flatMap(block =>
  block.transactions.map(tx => new Transaction({
    id: tx.hash,
    transactionHash: tx.hash,
    blockNumber: BigInt(block.header.height),
    blockTimestamp: BigInt(block.header.timestamp),
    chainId: chainId,
    from: tx.from,
    to: tx.to,
    value: BigInt(tx.value),
    gas: BigInt(tx.gas),
    gasPrice: BigInt(tx.gasPrice),
    maxFeePerGas: tx.maxFeePerGas ? BigInt(tx.maxFeePerGas) : null,
    maxPriorityFeePerGas: tx.maxPriorityFeePerGas ? BigInt(tx.maxPriorityFeePerGas) : null,
    gasUsed: BigInt(tx.gasUsed),
    cumulativeGasUsed: BigInt(tx.cumulativeGasUsed),
    transactionType: tx.type,
  }))
);

@Inkvi Inkvi force-pushed the inkvi/track-base-op-txs branch from 65e6a23 to f8a4582 Compare August 13, 2024 23:31
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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 65e6a23 and f8a4582.

Files selected for processing (6)
  • commands.json (2 hunks)
  • src/chains/wallets/base.ts (1 hunks)
  • src/chains/wallets/eth.ts (1 hunks)
  • src/chains/wallets/optimism.ts (1 hunks)
  • src/handlers/wallets.ts (1 hunks)
  • src/utils/ibc-processor.ts (1 hunks)
Files skipped from review as they are similar to previous changes (6)
  • commands.json
  • src/chains/wallets/base.ts
  • src/chains/wallets/eth.ts
  • src/chains/wallets/optimism.ts
  • src/handlers/wallets.ts
  • src/utils/ibc-processor.ts

@Inkvi Inkvi force-pushed the inkvi/track-base-op-txs branch from f8a4582 to f07b02a Compare August 13, 2024 23:36
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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f8a4582 and f07b02a.

Files selected for processing (6)
  • commands.json (2 hunks)
  • src/chains/wallets/base.ts (1 hunks)
  • src/chains/wallets/eth.ts (1 hunks)
  • src/chains/wallets/optimism.ts (1 hunks)
  • src/handlers/wallets.ts (1 hunks)
  • src/utils/ibc-processor.ts (1 hunks)
Files skipped from review as they are similar to previous changes (6)
  • commands.json
  • src/chains/wallets/base.ts
  • src/chains/wallets/eth.ts
  • src/chains/wallets/optimism.ts
  • src/handlers/wallets.ts
  • src/utils/ibc-processor.ts

@Inkvi Inkvi merged commit 16cba40 into main Aug 16, 2024
4 checks passed
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.

1 participant