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

TxManager.fromChainId #41

Merged
merged 2 commits into from
Sep 14, 2024
Merged

TxManager.fromChainId #41

merged 2 commits into from
Sep 14, 2024

Conversation

bh2smith
Copy link
Collaborator

@bh2smith bh2smith commented Sep 14, 2024

User description

Slightly cleaner interface (demonstrated by example scripts).


PR Type

Enhancement, Tests


Description

  • Replaced the managerForChainId function with a new static method TransactionManager.fromChainId to streamline the creation of TransactionManager instances.
  • Simplified the setup of nearAdapter in example scripts using the setupAdapter function.
  • Added logging in ContractSuite to display initialized contract addresses.

Changes walkthrough 📝

Relevant files
Enhancement
load-manager.ts
Simplify transaction manager setup in load-manager example

examples/load-manager.ts

  • Replaced managerForChainId with TransactionManager.fromChainId.
  • Simplified the setup of nearAdapter using setupAdapter.
  • Removed unnecessary console logs.
  • +12/-16 
    send-tx.ts
    Simplify transaction manager setup in send-tx example       

    examples/send-tx.ts

  • Replaced managerForChainId with TransactionManager.fromChainId.
  • Simplified the setup of nearAdapter using setupAdapter.
  • Streamlined argument extraction and usage.
  • +16/-25 
    safe.ts
    Add logging for initialized contract addresses                     

    src/lib/safe.ts

    • Added console logs to display initialized contract addresses.
    +7/-0     
    tx-manager.ts
    Introduce fromChainId method in TransactionManager             

    src/tx-manager.ts

  • Removed managerForChainId function.
  • Added TransactionManager.fromChainId static method.
  • +13/-12 

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @mintbase-codium-pr-agent
    Copy link

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Environment Variable Usage
    The use of process.env.PIMLICO_KEY! assumes the environment variable is always set. Consider adding a check or default value to prevent runtime errors if the variable is missing.

    Hardcoded Value
    The chainId is hardcoded in the TransactionManager.fromChainId call. This might limit flexibility if the script is used for different networks. Consider parameterizing this value.

    @mintbase-codium-pr-agent
    Copy link

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add a check for the existence of the PIMLICO_KEY environment variable

    Consider checking the existence of the environment variable PIMLICO_KEY before using
    it to avoid runtime errors if it's not set.

    examples/load-manager.ts [21]

    -pimlicoKey: process.env.PIMLICO_KEY!,
    +pimlicoKey: process.env.PIMLICO_KEY ?? throw new Error("PIMLICO_KEY environment variable is not set."),
     
    Suggestion importance[1-10]: 10

    Why: This suggestion prevents potential runtime errors by ensuring that the PIMLICO_KEY environment variable is set before it is used, which is crucial for the stability of the application.

    10
    Check for the existence of the NEAR_ACCOUNT_PRIVATE_KEY environment variable

    Ensure that the NEAR_ACCOUNT_PRIVATE_KEY environment variable is checked for
    existence before usage to prevent runtime errors.

    examples/send-tx.ts [17]

    -privateKey: process.env.NEAR_ACCOUNT_PRIVATE_KEY,
    +privateKey: process.env.NEAR_ACCOUNT_PRIVATE_KEY ?? throw new Error("NEAR_ACCOUNT_PRIVATE_KEY environment variable is not set."),
     
    Suggestion importance[1-10]: 10

    Why: This suggestion is important to prevent runtime errors by ensuring that the NEAR_ACCOUNT_PRIVATE_KEY environment variable is set before it is used, which is essential for the correct functioning of the application.

    10
    Security
    Remove console log statements that could expose sensitive information

    Remove the console log statements to avoid exposing potentially sensitive contract
    addresses in production logs.

    src/lib/safe.ts [69-75]

    -console.log("Initialized ERC4337 & Safe Module Contracts:", {
    -  singleton: await singleton.getAddress(),
    -  proxyFactory: await proxyFactory.getAddress(),
    -  m4337: await m4337.getAddress(),
    -  moduleSetup: await moduleSetup.getAddress(),
    -  entryPoint: await entryPoint.getAddress(),
    -});
    +// Removed console.log for security reasons
     
    Suggestion importance[1-10]: 9

    Why: Removing console log statements that expose sensitive contract addresses enhances security by preventing potential leaks of critical information in production logs.

    9
    Enhancement
    Add a check to ensure recoveryAddress is not empty before processing

    Use a conditional check to ensure recoveryAddress is not empty or undefined before
    adding a recovery transaction.

    examples/send-tx.ts [32-35]

    -if (txManager.safeNotDeployed && recoveryAddress) {
    +if (txManager.safeNotDeployed && recoveryAddress && recoveryAddress.trim() !== "") {
       const recoveryTx = txManager.addOwnerTx(recoveryAddress);
       transactions.push(recoveryTx);
     }
     
    Suggestion importance[1-10]: 8

    Why: This suggestion improves the robustness of the code by ensuring that the recoveryAddress is not empty or undefined before adding a recovery transaction, thus preventing potential errors.

    8

    @bh2smith bh2smith merged commit 98a00a0 into main Sep 14, 2024
    1 check passed
    @bh2smith bh2smith deleted the more-cleanup branch September 14, 2024 10:38
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant