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 redis caching for account factory address #639

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

d4mr
Copy link
Member

@d4mr d4mr commented Sep 3, 2024

PR-Codex overview

This PR focuses on enhancing the generateSignedUserOperation function in userOperation.ts by introducing a caching mechanism to retrieve the Factory Contract Address more efficiently.

Detailed summary

  • Added getAddress function
  • Introduced caching for Factory Contract Address retrieval
  • Improved error handling for missing Factory Contract Address

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

const cachedFactoryAddress = await redis.get(
`account-factory:${accountAddress.toLowerCase()}`,
);
accountFactoryAddress = getAddress(cachedFactoryAddress ?? "");
Copy link
Contributor

Choose a reason for hiding this comment

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

This is indirect to what you want:

  • if cachedFactoryAddress exists, set accountFactoryAddress to the checksum version of it
  • else accountFactoryAddress is undefined or null

Write the code that way. The current way has some unexpected behavior (what does getAddress("") do? You have to read the code to find out):

  let accountFactoryAddress: Address | undefined;

  try {
    const cached = await redis.get(
      `account-factory:${accountAddress.toLowerCase()}`,
    );
    if (cached) {
      accountFactoryAddress = getAddress(cached);
    }
  } catch {}

});

if (!accountFactoryAddress) {
const onchainFactoryResult = (await readContract({
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless I'm missing something, shouldn't you just set the response directly to accountFactoryAddress instead of declaring a new var?

method: "function factory() view returns (address)",
params: [],
})) as Address;
accountFactoryAddress = onchainFactoryResult;
Copy link
Contributor

Choose a reason for hiding this comment

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

You're missing a line here to set the cache after retrieving it.

Copy link

This PR is stale because it has been open for 7 days with no activity. Remove stale label or comment or this PR will be closed in 3 days.

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.

3 participants