You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This PR allows users to skip specifying chainId until the time of the transaction. This works because of the deterministic addresses across all EVM networks (except for zkEVMs - which we will have to manually block). There are some minor inconveniences remaining that I hope to tackle before merge.
User must specify chainId for both "build" and "execute" transaction. This is because the "UserOperation" does not have a "chainId" internally.
We will eliminate the requirement for "ethRPC" in the constructor by internally using sepolia for Safe Contract Reads. Would be even better to emulate the contracts and produce the computations instead of reading from the EVM. However this will take much more work.
Error Handling The function loadEnv throws generic errors without specific details which might make debugging difficult. Consider adding more specific error messages or handling different types of errors separately.
Chain ID Handling The method executeTransaction updates deployedChains without checking the result of safeDeployed, which might lead to incorrect tracking of deployed chains.
Error Handling The method buildTransaction does not handle the case where transactions array might be empty. This could lead to unhandled exceptions when trying to access properties of undefined.
Add error handling to the executeTransaction method to manage exceptions
Implement error handling for the executeTransaction method to manage exceptions that may occur during the transaction execution, improving the robustness of the method.
-const userOpReceipt = await bundler.getUserOpReceipt(userOpHash);+let userOpReceipt;+try {+ userOpReceipt = await bundler.getUserOpReceipt(userOpHash);+} catch (error) {+ console.error("Failed to get user operation receipt:", error);+ throw error;+}
Suggestion importance[1-10]: 9
Why: Implementing error handling in the executeTransaction method significantly improves the robustness and reliability of the code by ensuring that exceptions are properly managed and logged.
9
Possible issue
Add a check for the presence of NEAR_ACCOUNT_PRIVATE_KEY in the environment variables
Consider checking for the presence of NEAR_ACCOUNT_PRIVATE_KEY in the environment variables and throw an error if it is not provided. This is important for ensuring that all necessary credentials are available before proceeding with operations that require them.
if (!NEAR_ACCOUNT_ID) {
throw new Error("Must provide env var NEAR_ACCOUNT_ID");
+}+if (!NEAR_ACCOUNT_PRIVATE_KEY) {+ throw new Error("Must provide env var NEAR_ACCOUNT_PRIVATE_KEY");
}
if (!PIMLICO_KEY) {
throw new Error("Must provide env var PIMLICO_KEY");
}
Suggestion importance[1-10]: 8
Why: This suggestion improves the robustness of the script by ensuring that all necessary environment variables are present before proceeding. This is crucial for preventing runtime errors due to missing credentials.
8
Enhancement
Use a dynamic chainId from the environment variables instead of a hardcoded value
Replace the hardcoded chainId with a dynamic value retrieved from the environment or configuration to make the script more flexible and chain agnostic.
Why: This suggestion enhances the flexibility and reusability of the script by allowing the chainId to be configured via environment variables, making it more adaptable to different environments.
7
Performance
Cache the provider instances in the Erc4337Bundler class to improve performance
Refactor the client method in the Erc4337Bundler class to use a cached provider instance instead of creating a new one every time to improve performance and resource utilization.
-return new ethers.JsonRpcProvider(bundlerUrl(chainId, this.apiKey));+if (!this.providerCache[chainId]) {+ this.providerCache[chainId] = new ethers.JsonRpcProvider(bundlerUrl(chainId, this.apiKey));+}+return this.providerCache[chainId];
Suggestion importance[1-10]: 6
Why: Caching provider instances can improve performance by reducing the overhead of creating new instances repeatedly. However, the suggestion assumes the existence of a providerCache which is not shown in the provided code.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
This PR allows users to skip specifying chainId until the time of the transaction. This works because of the deterministic addresses across all EVM networks (except for zkEVMs - which we will have to manually block). There are some minor inconveniences remaining that I hope to tackle before merge.
chainId
for both "build" and "execute" transaction. This is because the "UserOperation" does not have a "chainId" internally.closes #42
PR Type
Enhancement, Bug fix
Description
ScriptEnv
interface andloadEnv
function to load environment variables inexamples/cli.ts
.examples/load-manager.ts
script.examples/send-tx.ts
to use new environment loading and includechainId
parameter in method calls.Erc4337Bundler
with dynamic bundler URL generation and chain ID support.m4337Deployment
insrc/lib/safe.ts
and refactoredgetOpHash
.TransactionManager
to support chain-agnostic operations, added methods for dynamic bundler and safe deployment checks.Changes walkthrough 📝
cli.ts
Add environment variable loading for NEAR and Pimlico keys
examples/cli.ts
ScriptEnv
interface andloadEnv
function to load environmentvariables.
nearAccountId
,nearAccountPrivateKey
, andpimlicoKey
in theenvironment variables.
send-tx.ts
Update send-tx example to use new environment loading and chainId
examples/send-tx.ts
loadEnv
for environment variables.TransactionManager
creation to usecreate
method.chainId
parameter to various method calls.bundler.ts
Enhance Erc4337Bundler with dynamic bundler URL and chainId support
src/lib/bundler.ts
bundlerUrl
function to generate the bundler URL.Erc4337Bundler
to includeapiKey
andchainId
.client
method to get a JSON RPC provider for a specific chainID.
safe.ts
Simplify m4337Deployment and refactor getOpHash
src/lib/safe.ts
m4337Deployment
to use a single version.getOpHash
to use destructuredunsignedUserOp
properties.tx-manager.ts
Refactor TransactionManager for chain-agnostic support and dynamic
bundler
src/tx-manager.ts
TransactionManager
to removechainId
property.entryPointAddress
andpimlicoKey
properties.bundlerForChainId
method to get a bundler for a specificchain ID.
safeDeployed
method to check if the safe is deployed on aspecific chain.
chainId
parameter.load-manager.ts
Remove load-manager example script
examples/load-manager.ts
TransactionManager
for multiple chain IDs.