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: use alchemy_requestGasAndPaymasterAndData when using alchemy paymaster #1310

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

jakehobbs
Copy link
Member

@jakehobbs jakehobbs commented Jan 30, 2025

Pull Request Checklist


PR-Codex overview

This PR introduces new functionality for handling gas requests and paymaster data in the Alchemy transport layer, enhancing middleware capabilities and ensuring compliance with the ERC-7677 protocol.

Detailed summary

  • Added alchemy_requestGasAndPaymasterAndData method to alchemyTransport.
  • Updated AlchemyTransportConfig to include new methods.
  • Introduced alchemyGasAndPaymasterAndDataMiddleware for custom gas and paymaster handling.
  • Deprecated old paymaster address resolution method.
  • Enhanced test cases to cover new functionalities.

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

Copy link

vercel bot commented Jan 30, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
aa-sdk-site ❌ Failed (Inspect) Feb 22, 2025 2:44am
aa-sdk-ui-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 22, 2025 2:44am

Copy link

graphite-app bot commented Jan 30, 2025

How to use the Graphite Merge Queue

Add the label graphite-merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

* @param {UserOperationRequest<TEntryPointVersion>} userOperation the user operation request
* @returns {Hex | Multiplier | undefined} the overridden field value
*/
const overrideField = <
Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -144,6 +144,12 @@ export function createAlchemySmartAccountClient({
const feeOptions =
opts?.feeOptions ?? getDefaultUserOperationFeeOptions(chain);

// If we have a policyId, then it's safe to assume that
Copy link
Member Author

Choose a reason for hiding this comment

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

is this true? i think it is, but i'd like confirmation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

not really. unless they use alchmey provider, otherwise a policyId only means they have created a policy with that paymaster.

Copy link
Member Author

@jakehobbs jakehobbs Jan 31, 2025

Choose a reason for hiding this comment

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

is it okay to do this here? the current implementation was also only including the gas manager middleware here based on the policyId, i.e.

...(policyId && alchemyGasManagerMiddleware(policyId))

Copy link
Member Author

Choose a reason for hiding this comment

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

wondering if it's actually better to include an "experimental" option (at least for now) instead of forcing everyone on to the other rpc method?

Copy link
Collaborator

Choose a reason for hiding this comment

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

is it okay to do this here? the current implementation was also only including the gas manager middleware here based on the policyId, i.e.

...(policyId && alchemyGasManagerMiddleware(policyId))

it is because without policyId, it doesn't make sense to involve a paymaster middleware, by any format.

return noopMiddleware(uo, args);
}

const paymaster = getAlchemyPaymasterAddress(args.client.chain); // throws if unsupported chain
Copy link
Member Author

Choose a reason for hiding this comment

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

❗ ❗ ❗ this is problematic b/c this function only supports 15 chains & throws if it's an unsupported chain.

@andysim3d do you think we should fall back to using pm_getPaymasterStubData here so we don't have to maintain this list of chains & paymaster addresses?

Copy link
Collaborator

@moldy530 moldy530 left a comment

Choose a reason for hiding this comment

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

we will need to update our paymaster mocks in the vitest setup to account for using this endpoint, otherwise paymaster tests won't work (I think?)

or maybe we actually don't have any coverage of the alchemyGasManagerMiddleware being used in tests

moldy530
moldy530 previously approved these changes Feb 21, 2025
Copy link
Collaborator

@moldy530 moldy530 left a comment

Choose a reason for hiding this comment

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

LGTM only a couple nits

Comment on lines +41 to +42
*
* @deprecated This chain list in this function is no longer maintained since the ERC-7677 middleware is typically used to resolve the paymaster address
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this what's used in the new (old) middleware too?

Copy link
Member Author

Choose a reason for hiding this comment

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

the old version of the middleware that used alchemy_requestGasAndPaymasterAndData was using this for building the dummy paymaster data.. i discovered it's an issue when the chains team was testing this in ws-tools, b/c it would fail for any other chain.

in order to prevent having to maintain this, the new version of the alchemy_requestGasAndPaymasterAndData middleware will fall back to using the 7677 dummyPaymasterAndData middleware (calling pm_getPaymasterStubData) if there is a gasEstimator or feeEstimator override, otherwise it just does a no-op since it's not actually needed.

Comment on lines +72 to +75
* ...alchemyGasAndPaymasterAndDataMiddleware({
* policyId: "policyId",
* transport: alchemy({ apiKey: "your-api-key" }),
* })
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this how we intend it to be used as well? Ideally the change to this middleware happens invisibily to users.

Currently, you just pass a policyId to createAlchemySmartAccountClient and under the hood that makes this call

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh just saw the impl above does do that, then I'd update this example to use createSmartAccountClient instead of createAlchemySmartAccountClient

also worth calling out in the description that someone shouldn't have to use this method directly since the alchemy client will handle this for you

Copy link
Member Author

@jakehobbs jakehobbs Feb 21, 2025

Choose a reason for hiding this comment

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

oops, great call-out! def should just enable it here by passing the policyId. i missed that this example was using createAlchemySmartAccountClient and not just createSmartAccountClient. 👌

* the `alchemy_requestGasAndPaymasterAndData` method instead of standard ERC-7677 methods.
*
* @example
* ```ts
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit:

Suggested change
* ```ts
* ```ts twoslash

}

// Fall back to the default 7677 dummyPaymasterAndData middleware.
return alchemyGasManagerMiddleware(policyId).dummyPaymasterAndData!(
Copy link
Collaborator

Choose a reason for hiding this comment

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

oh nice

@jakehobbs
Copy link
Member Author

jakehobbs commented Feb 22, 2025

@moldy530 re: tests, we were not using the currentalchemyGasManagerMiddleware or the "new" alchemyGasAndPaymasterAndDataMiddleware in any tests... only the erc7677Middleware directly (w/o a policyId).

i've almost got mocks working for it, but stumbling around a bit trying to find the best way to do the gas estimation.

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.

5 participants