Skip to content

Commit

Permalink
Merge pull request #90 from pimlicolabs/feat/sendCompressedUserOperation
Browse files Browse the repository at this point in the history
sendCompressedUserOperation
  • Loading branch information
kristofgazso authored Jan 21, 2024
2 parents 217776e + 1069679 commit 57dcb53
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/sour-fans-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"permissionless": patch
---

Added support for sendCompressedUserOperation Pimlico bundler action
Binary file modified bun.lockb
Binary file not shown.
12 changes: 12 additions & 0 deletions packages/create-permissionless-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "create-permissionless-app",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
16 changes: 11 additions & 5 deletions packages/permissionless/actions/pimlico.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import {
type GetUserOperationStatusReturnType,
getUserOperationStatus
} from "./pimlico/getUserOperationStatus.js"
import {
type SendCompressedUserOperationParameters,
sendCompressedUserOperation
} from "./pimlico/sendCompressedUserOperation.js"
import {
type PimlicoSponsorUserOperationParameters,
type SponsorUserOperationReturnType,
Expand All @@ -32,19 +36,21 @@ export type {
GetUserOperationGasPriceReturnType,
GetUserOperationStatusParameters,
GetUserOperationStatusReturnType,
PimlicoSponsorUserOperationParameters,
SponsorUserOperationReturnType,
PimlicoBundlerActions,
PimlicoPaymasterClientActions,
ValidateSponsorshipPoliciesParameters,
ValidateSponsorshipPolicies
PimlicoSponsorUserOperationParameters,
SendCompressedUserOperationParameters,
SponsorUserOperationReturnType,
ValidateSponsorshipPolicies,
ValidateSponsorshipPoliciesParameters
}

export {
getUserOperationGasPrice,
getUserOperationStatus,
sponsorUserOperation,
pimlicoBundlerActions,
pimlicoPaymasterActions,
sendCompressedUserOperation,
sponsorUserOperation,
validateSponsorshipPolicies
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ export type GetUserOperationStatusReturnType = PimlicoUserOperationStatus
* @example
* import { createClient } from "viem"
* import { getUserOperationStatus } from "permissionless/actions/pimlico"
* import { pimlicoBundlerActions } from 'permissionless/actions/pimlico'
*
* const bundlerClient = createClient({
* chain: goerli,
* transport: http("https://api.pimlico.io/v2/goerli/rpc?apikey=YOUR_API_KEY_HERE")
* })
* }).extend(pimlicoBundlerActions)
*
* await getUserOperationStatus(bundlerClient, { hash: userOpHash })
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type {
Account,
Address,
Chain,
Client,
Hash,
Hex,
Transport
} from "viem"
import type { Prettify } from "../../types/index.js"
import { type PimlicoBundlerRpcSchema } from "../../types/pimlico.js"

export type SendCompressedUserOperationParameters = {
compressedUserOperation: Hex
inflatorAddress: Address
entryPoint: Address
}

/**
* Sends a compressed user operation to the bundler
*
* - Docs: https://docs.pimlico.io/permissionless/reference/pimlico-bundler-actions/sendCompressedUserOperation
*
* @param client {@link PimlicoBundlerClient} that you created using viem's createClient whose transport url is pointing to the Pimlico's bundler.
* @param args {@link SendCompressedUserOperationParameters}.
* @returns UserOpHash that you can use to track user operation as {@link Hash}.
*
* @example
* import { pimlicoBundlerActions, sendCompressedUserOperation } from 'permissionless/actions/pimlico'
* import { createClient } from "viem"
*
* const bundlerClient = createClient({
* chain: goerli,
* transport: http("https://api.pimlico.io/v2/goerli/rpc?apikey=YOUR_API_KEY_HERE")
* }).extend(pimlicoBundlerActions)
*
* const userOpHash = await sendCompressedUserOperation(bundlerClient, {
* compressedUserOperation,
* inflatorAddress,
* entryPoint
* })
* // Return '0xe9fad2cd67f9ca1d0b7a6513b2a42066784c8df938518da2b51bb8cc9a89ea34'
*/
export const sendCompressedUserOperation = async <
TTransport extends Transport = Transport,
TChain extends Chain | undefined = Chain | undefined,
TAccount extends Account | undefined = Account | undefined
>(
client: Client<TTransport, TChain, TAccount, PimlicoBundlerRpcSchema>,
args: Prettify<SendCompressedUserOperationParameters>
): Promise<Hash> => {
const { compressedUserOperation, inflatorAddress, entryPoint } = args

return client.request({
method: "pimlico_sendCompressedUserOperation",
params: [
compressedUserOperation as Hex,
inflatorAddress as Address,
entryPoint as Address
]
})
}
34 changes: 33 additions & 1 deletion packages/permissionless/clients/decorators/pimlico.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { Client, Hash } from "viem"
import {
type SendCompressedUserOperationParameters,
type ValidateSponsorshipPolicies,
type ValidateSponsorshipPoliciesParameters,
sendCompressedUserOperation,
validateSponsorshipPolicies
} from "../../actions/pimlico.js"
import {
Expand Down Expand Up @@ -69,6 +71,33 @@ export type PimlicoBundlerActions = {
getUserOperationStatus: (
args: Prettify<GetUserOperationStatusParameters>
) => Promise<Prettify<GetUserOperationStatusReturnType>>
/**
* Sends a compressed user operation to the bundler
*
* - Docs: https://docs.pimlico.io/permissionless/reference/pimlico-bundler-actions/sendCompressedUserOperation
*
* @param args {@link SendCompressedUserOperationParameters}.
* @returns UserOpHash that you can use to track user operation as {@link Hash}.
*
* @example
* import { createClient } from "viem"
* import { pimlicoBundlerActions } from "permissionless/actions/pimlico"
*
* const bundlerClient = createClient({
* chain: goerli,
* transport: http("https://api.pimlico.io/v1/goerli/rpc?apikey=YOUR_API_KEY_HERE")
* }).extend(pimlicoBundlerActions)
*
* const userOpHash = await bundlerClient.sendCompressedUserOperation({
* compressedUserOperation,
* inflatorAddress,
* entryPoint
* })
* // Return '0xe9fad2cd67f9ca1d0b7a6513b2a42066784c8df938518da2b51bb8cc9a89ea34'
*/
sendCompressedUserOperation: (
args: Prettify<SendCompressedUserOperationParameters>
) => Promise<Hash>
}

export const pimlicoBundlerActions = (
Expand All @@ -77,7 +106,10 @@ export const pimlicoBundlerActions = (
getUserOperationGasPrice: async () =>
getUserOperationGasPrice(client as PimlicoBundlerClient),
getUserOperationStatus: async (args: GetUserOperationStatusParameters) =>
getUserOperationStatus(client as PimlicoBundlerClient, args)
getUserOperationStatus(client as PimlicoBundlerClient, args),
sendCompressedUserOperation: async (
args: SendCompressedUserOperationParameters
) => sendCompressedUserOperation(client as PimlicoBundlerClient, args)
})

export type PimlicoPaymasterClientActions = {
Expand Down
9 changes: 9 additions & 0 deletions packages/permissionless/types/pimlico.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ export type PimlicoBundlerRpcSchema = [
Method: "pimlico_getUserOperationStatus"
Parameters: [hash: Hash]
ReturnType: PimlicoUserOperationStatus
},
{
Method: "pimlico_sendCompressedUserOperation"
Parameters: [
compressedUserOperation: Hex,
inflatorAddress: Address,
entryPoint: Address
]
ReturnType: Hash
}
]

Expand Down

0 comments on commit 57dcb53

Please sign in to comment.