diff --git a/.changeset/sour-fans-report.md b/.changeset/sour-fans-report.md new file mode 100644 index 00000000..f0b67ec7 --- /dev/null +++ b/.changeset/sour-fans-report.md @@ -0,0 +1,5 @@ +--- +"permissionless": patch +--- + +Added support for sendCompressedUserOperation Pimlico bundler action diff --git a/bun.lockb b/bun.lockb index e60d4f80..f824c170 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/packages/create-permissionless-app/package.json b/packages/create-permissionless-app/package.json new file mode 100644 index 00000000..93a8527d --- /dev/null +++ b/packages/create-permissionless-app/package.json @@ -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" +} diff --git a/packages/permissionless/actions/pimlico.ts b/packages/permissionless/actions/pimlico.ts index b9dd5935..c9fdd948 100644 --- a/packages/permissionless/actions/pimlico.ts +++ b/packages/permissionless/actions/pimlico.ts @@ -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, @@ -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 } diff --git a/packages/permissionless/actions/pimlico/getUserOperationStatus.ts b/packages/permissionless/actions/pimlico/getUserOperationStatus.ts index 44daed7b..d1688af0 100644 --- a/packages/permissionless/actions/pimlico/getUserOperationStatus.ts +++ b/packages/permissionless/actions/pimlico/getUserOperationStatus.ts @@ -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 }) * diff --git a/packages/permissionless/actions/pimlico/sendCompressedUserOperation.ts b/packages/permissionless/actions/pimlico/sendCompressedUserOperation.ts new file mode 100644 index 00000000..e6b9dc31 --- /dev/null +++ b/packages/permissionless/actions/pimlico/sendCompressedUserOperation.ts @@ -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, + args: Prettify +): Promise => { + const { compressedUserOperation, inflatorAddress, entryPoint } = args + + return client.request({ + method: "pimlico_sendCompressedUserOperation", + params: [ + compressedUserOperation as Hex, + inflatorAddress as Address, + entryPoint as Address + ] + }) +} diff --git a/packages/permissionless/clients/decorators/pimlico.ts b/packages/permissionless/clients/decorators/pimlico.ts index b47f7e7f..85436606 100644 --- a/packages/permissionless/clients/decorators/pimlico.ts +++ b/packages/permissionless/clients/decorators/pimlico.ts @@ -1,7 +1,9 @@ import type { Client, Hash } from "viem" import { + type SendCompressedUserOperationParameters, type ValidateSponsorshipPolicies, type ValidateSponsorshipPoliciesParameters, + sendCompressedUserOperation, validateSponsorshipPolicies } from "../../actions/pimlico.js" import { @@ -69,6 +71,33 @@ export type PimlicoBundlerActions = { getUserOperationStatus: ( args: Prettify ) => Promise> + /** + * 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 + ) => Promise } export const pimlicoBundlerActions = ( @@ -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 = { diff --git a/packages/permissionless/types/pimlico.ts b/packages/permissionless/types/pimlico.ts index 61827a75..f24a6267 100644 --- a/packages/permissionless/types/pimlico.ts +++ b/packages/permissionless/types/pimlico.ts @@ -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 } ]