-
-
Notifications
You must be signed in to change notification settings - Fork 40
test: infura bundler + delegation toolkit #59
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dd273e8
test: infura bundler + delegation toolkit
hanzel98 f623648
feat: added infura bundler client
hanzel98 b653187
fix: command name in package.json
hanzel98 8e5a81e
chore: renamed external folder, and types
hanzel98 9030af5
test: new e2e test for infura bundler local environment
hanzel98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
114 changes: 114 additions & 0 deletions
114
packages/delegation-toolkit/src/actions/infuraBundlerClient.ts
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import type { Transport, Chain, Hex } from 'viem'; | ||
| import { | ||
| createBundlerClient, | ||
| type BundlerClientConfig, | ||
| type SmartAccount, | ||
| } from 'viem/account-abstraction'; | ||
|
|
||
| /** | ||
| * Gas price tiers returned by pimlico_getUserOperationGasPrice | ||
| */ | ||
| export type GasPriceTier = { | ||
| /** Maximum fee per gas in hex format */ | ||
| maxFeePerGas: Hex; | ||
| /** Maximum priority fee per gas in hex format */ | ||
| maxPriorityFeePerGas: Hex; | ||
| }; | ||
|
|
||
| /** | ||
| * Response from pimlico_getUserOperationGasPrice RPC method | ||
| */ | ||
| export type UserOperationGasPriceResponse = { | ||
| /** Slow gas price tier */ | ||
| slow: GasPriceTier; | ||
| /** Standard gas price tier */ | ||
| standard: GasPriceTier; | ||
| /** Fast gas price tier */ | ||
| fast: GasPriceTier; | ||
| }; | ||
|
|
||
| /** | ||
| * Infura bundler actions for extending bundler clients. | ||
| * | ||
| * @returns A function that takes a bundler client and returns the client extension with Infura bundler actions. | ||
| */ | ||
| const infuraBundlerActions = () => (client: any) => ({ | ||
| /** | ||
| * Get user operation gas prices from Infura bundler. | ||
| * Calls the pimlico_getUserOperationGasPrice RPC method. | ||
| * | ||
| * @returns Promise resolving to gas price tiers (slow, standard, fast). | ||
| * @example | ||
| * ```typescript | ||
| * const gasPrices = await bundlerClient.getUserOperationGasPrice(); | ||
| * console.log(gasPrices.standard.maxFeePerGas); | ||
| * ``` | ||
| */ | ||
| async getUserOperationGasPrice(): Promise<UserOperationGasPriceResponse> { | ||
| const response = await client.request({ | ||
|
hanzel98 marked this conversation as resolved.
Outdated
|
||
| method: 'pimlico_getUserOperationGasPrice' as any, | ||
| params: [] as any, | ||
| }); | ||
|
|
||
| return response as unknown as UserOperationGasPriceResponse; | ||
| }, | ||
| }); | ||
|
|
||
| /** | ||
| * Type for bundler client extended with Infura bundler actions. | ||
| */ | ||
| export type InfuraBundlerClient< | ||
| TTransport extends Transport = Transport, | ||
| TChain extends Chain | undefined = Chain | undefined, | ||
| TAccount extends SmartAccount | undefined = SmartAccount | undefined, | ||
| > = ReturnType<typeof createBundlerClient<TTransport, TChain, TAccount>> & | ||
|
hanzel98 marked this conversation as resolved.
Outdated
|
||
| ReturnType<ReturnType<typeof infuraBundlerActions>>; | ||
|
|
||
| /** | ||
| * Creates an Infura bundler client extended with Infura bundler actions. | ||
| * | ||
| * This is a wrapper around viem's createBundlerClient that extends it with | ||
| * the getUserOperationGasPrice method for retrieving gas prices from Pimlico's | ||
| * bundler infrastructure via Infura's proxy. | ||
| * | ||
| * @param config - Configuration for the bundler client. | ||
| * @returns Extended bundler client with Infura bundler actions. | ||
| * @example | ||
| * ```typescript | ||
| * import { createPublicClient, http } from 'viem'; | ||
| * import { sepolia } from 'viem/chains'; | ||
| * import { createInfuraBundlerClient } from '@metamask/delegation-toolkit'; | ||
| * | ||
| * const publicClient = createPublicClient({ | ||
| * chain: sepolia, | ||
| * transport: http('https://sepolia.infura.io/v3/YOUR_API_KEY'), | ||
| * }); | ||
| * | ||
| * const bundlerClient = createInfuraBundlerClient({ | ||
| * client: publicClient, | ||
| * transport: http('https://sepolia.infura.io/v3/YOUR_API_KEY'), | ||
| * chain: sepolia, | ||
| * }); | ||
| * | ||
| * // Use standard bundler methods | ||
| * const userOpHash = await bundlerClient.sendUserOperation({...}); | ||
| * | ||
| * // Use Infura specific methods | ||
| * const gasPrices = await bundlerClient.getUserOperationGasPrice(); | ||
| * ``` | ||
| */ | ||
| export function createInfuraBundlerClient< | ||
| TTransport extends Transport, | ||
| TChain extends Chain | undefined = undefined, | ||
| TAccount extends SmartAccount | undefined = undefined, | ||
| >( | ||
| config: BundlerClientConfig<TTransport, TChain, TAccount>, | ||
| ): InfuraBundlerClient<TTransport, TChain, TAccount> { | ||
| // Create the base bundler client using viem's function | ||
| const baseBundlerClient = createBundlerClient(config); | ||
|
|
||
| // Extend the client with Infura bundler actions | ||
| return baseBundlerClient.extend( | ||
| infuraBundlerActions(), | ||
| ) as unknown as InfuraBundlerClient<TTransport, TChain, TAccount>; | ||
|
hanzel98 marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.