From 658b871b375623ecb2988f83ffa9b2d5694bd77a Mon Sep 17 00:00:00 2001 From: GabiDev Date: Wed, 20 Mar 2024 12:26:29 +0200 Subject: [PATCH] refactor: removed all permissionless mentions + stackup --- src/bundler/actions/getUserOperationByHash.ts | 4 +- .../actions/getUserOperationGasPrice.ts | 68 ------------------- .../actions/getUserOperationReceipt.ts | 4 +- src/bundler/actions/getUserOperationStatus.ts | 26 +++++++ src/bundler/actions/sendUserOperation.ts | 4 +- .../actions/waitForUserOperationRceipt.ts | 7 +- src/bundler/utils/types.ts | 13 +++- src/client/createSmartAccountClient.ts | 2 +- src/client/decorators/bundler.ts | 9 ++- src/client/decorators/paymaster.ts | 14 ++-- tests/ep6/account.test.ts | 5 +- tests/ep6/bundler.test.ts | 9 +++ 12 files changed, 74 insertions(+), 91 deletions(-) delete mode 100644 src/bundler/actions/getUserOperationGasPrice.ts create mode 100644 src/bundler/actions/getUserOperationStatus.ts diff --git a/src/bundler/actions/getUserOperationByHash.ts b/src/bundler/actions/getUserOperationByHash.ts index 3facef5a9..0a295c122 100644 --- a/src/bundler/actions/getUserOperationByHash.ts +++ b/src/bundler/actions/getUserOperationByHash.ts @@ -18,7 +18,7 @@ export type GetUserOperationByHashReturnType = { /** * Returns the user operation from userOpHash * - * - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/getUserOperationByHash + * - Docs: https://docs.biconomy.io/ ... // TODO * * @param client {@link BundlerClient} that you created using viem's createClient and extended it with bundlerActions. * @param args {@link GetUserOperationByHashParameters} UserOpHash that was returned by {@link sendUserOperation} @@ -27,7 +27,7 @@ export type GetUserOperationByHashReturnType = { * * @example * import { createClient } from "viem" - * import { getUserOperationByHash } from "permissionless/actions" + * import { getUserOperationByHash } from "@biconomy/sdk" // TODO * * const bundlerClient = createClient({ * chain: goerli, diff --git a/src/bundler/actions/getUserOperationGasPrice.ts b/src/bundler/actions/getUserOperationGasPrice.ts deleted file mode 100644 index 345bbe6cd..000000000 --- a/src/bundler/actions/getUserOperationGasPrice.ts +++ /dev/null @@ -1,68 +0,0 @@ -// import type { Account, Chain, Client, Transport } from "viem" -// import { BigNumberish } from "../../accounts/utils/types" -// import { BundlerRpcSchema } from "../utils/types" -// import { Prettify } from "viem/chains" - -// export type GetUserOperationGasPriceReturnType = { -// slow: { -// maxFeePerGas: BigNumberish -// maxPriorityFeePerGas: BigNumberish -// } -// standard: { -// maxFeePerGas: BigNumberish -// maxPriorityFeePerGas: BigNumberish -// } -// fast: { -// maxFeePerGas: BigNumberish -// maxPriorityFeePerGas: BigNumberish -// } -// } - -// /** -// * Returns the live gas prices that you can use to send a user operation. -// * -// * - Docs: https://docs.pimlico.io/permissionless/reference/pimlico-bundler-actions/getUserOperationGasPrice -// * -// * @param client that you created using viem's createClient whose transport url is pointing to the Pimlico's bundler. -// * @returns slow, standard & fast values for maxFeePerGas & maxPriorityFeePerGas -// * -// * -// * @example -// * import { createClient } from "viem" -// * import { getUserOperationGasPrice } from "permissionless/actions/pimlico" -// * -// * const bundlerClient = createClient({ -// * chain: goerli, -// * transport: http("https://api.pimlico.io/v2/goerli/rpc?apikey=YOUR_API_KEY_HERE") -// * }) -// * -// * await getUserOperationGasPrice(bundlerClient) -// * -// */ -// export const getUserOperationGasPrice = async < -// TTransport extends Transport = Transport, -// TChain extends Chain | undefined = Chain | undefined, -// TAccount extends Account | undefined = Account | undefined -// >( -// client: Client -// ): Promise> => { -// const gasPrice = await client.request({ -// method: "pimlico_getUserOperationGasPrice", -// params: [] -// }) - -// return { -// slow: { -// maxFeePerGas: BigInt(gasPrice.slow.maxFeePerGas), -// maxPriorityFeePerGas: BigInt(gasPrice.slow.maxPriorityFeePerGas) -// }, -// standard: { -// maxFeePerGas: BigInt(gasPrice.standard.maxFeePerGas), -// maxPriorityFeePerGas: BigInt(gasPrice.standard.maxPriorityFeePerGas) -// }, -// fast: { -// maxFeePerGas: BigInt(gasPrice.fast.maxFeePerGas), -// maxPriorityFeePerGas: BigInt(gasPrice.fast.maxPriorityFeePerGas) -// } -// } -// } diff --git a/src/bundler/actions/getUserOperationReceipt.ts b/src/bundler/actions/getUserOperationReceipt.ts index 68a7bd430..134deb0c3 100644 --- a/src/bundler/actions/getUserOperationReceipt.ts +++ b/src/bundler/actions/getUserOperationReceipt.ts @@ -9,7 +9,7 @@ export type GetUserOperationReceiptParameters = { /** * Returns the user operation receipt from userOpHash * - * - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/getUserOperationReceipt + * - Docs: https://docs.biconomy.io/ ... // TODO * * @param client {@link BundlerClient} that you created using viem's createClient and extended it with bundlerActions. * @param args {@link GetUserOperationReceiptParameters} UserOpHash that was returned by {@link sendUserOperation} @@ -18,7 +18,7 @@ export type GetUserOperationReceiptParameters = { * * @example * import { createClient } from "viem" - * import { getUserOperationReceipt } from "permissionless/actions" + * import { getUserOperationReceipt } from "@biconomy/sdk" * * const bundlerClient = createClient({ * chain: goerli, diff --git a/src/bundler/actions/getUserOperationStatus.ts b/src/bundler/actions/getUserOperationStatus.ts new file mode 100644 index 000000000..446e43492 --- /dev/null +++ b/src/bundler/actions/getUserOperationStatus.ts @@ -0,0 +1,26 @@ +import type { Account, Chain, Client, Hash, Transport } from "viem" +import type { BundlerRpcSchema, UserOpStatus } from "../utils/types" + +export const getUserOpStatus = async < + TTransport extends Transport = Transport, + TChain extends Chain | undefined = Chain | undefined, + TAccount extends Account | undefined = Account | undefined +>( + client: Client, + userOpHash: Hash +): Promise => { + try { + const response = await client.request({ + method: "biconomy_getUserOperationStatus", + params: [userOpHash] + }) + + return { + state: response.state, + transactionHash: response.transactionHash, + userOperationReceipt: response.userOperationReceipt + } as UserOpStatus + } catch (err) { + throw new Error("Error estimating gas fee values.") + } +} diff --git a/src/bundler/actions/sendUserOperation.ts b/src/bundler/actions/sendUserOperation.ts index 732e35244..7b1929fec 100644 --- a/src/bundler/actions/sendUserOperation.ts +++ b/src/bundler/actions/sendUserOperation.ts @@ -11,7 +11,7 @@ export type SendUserOperationParameters = { /** * Sends user operation to the bundler * - * - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/sendUserOperation + * - Docs: https://docs.biconomy.io/ ... // TODO * * @param client {@link BundlerClient} that you created using viem's createClient and extended it with bundlerActions. * @param args {@link SendUserOperationParameters}. @@ -19,7 +19,7 @@ export type SendUserOperationParameters = { * * @example * import { createClient } from "viem" - * import { sendUserOperation } from "permissionless/actions" + * import { sendUserOperation } from "@biconomy/sdk" // TODO * * const bundlerClient = createClient({ * chain: goerli, diff --git a/src/bundler/actions/waitForUserOperationRceipt.ts b/src/bundler/actions/waitForUserOperationRceipt.ts index aba798134..0e2a70f9e 100644 --- a/src/bundler/actions/waitForUserOperationRceipt.ts +++ b/src/bundler/actions/waitForUserOperationRceipt.ts @@ -36,16 +36,17 @@ export type WaitForUserOperationReceiptParameters = { } /** - * Waits for the User Operation to be included on a [Block](https://viem.sh/docs/glossary/terms.html#block) (one confirmation), and then returns the [User Operation Receipt](https://docs.pimlico.io/permissionless/reference/bundler-actions/getUserOperationReceipt). + * Waits for the User Operation to be included on a [Block](https://viem.sh/docs/glossary/terms.html#block) (one confirmation), and then returns the [User Operation Receipt]. * - * - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/waitForUserOperationReceipt + * - Docs: https://docs.biconomy.io/ ... // TODO * * @param client - Bundler Client to use * @param parameters - {@link WaitForUserOperationReceiptParameters} * @returns The transaction receipt. {@link GetUserOperationReceiptReturnType} * * @example - * import { createBundlerClient, waitForUserOperationReceipt, http } from 'viem' + * import { waitForUserOperationReceipt, http } from 'viem' + * import { createBundlerClient } from "@biconomy/sdk" // TODO * import { mainnet } from 'viem/chains' * * const client = createBundlerClient({ diff --git a/src/bundler/utils/types.ts b/src/bundler/utils/types.ts index 07cf33944..fa2a518f9 100644 --- a/src/bundler/utils/types.ts +++ b/src/bundler/utils/types.ts @@ -1,7 +1,7 @@ -import type { ENTRYPOINT_ADDRESS_V06_TYPE } from "permissionless/types/entrypoint" import type { Address, Hash, Hex } from "viem" import type { PartialBy } from "viem/chains" import type { UserOperationStruct } from "../../accounts" +import type { ENTRYPOINT_ADDRESS_V06_TYPE } from "../../accounts/utils/types" export type BundlerRpcSchema = [ { @@ -60,6 +60,11 @@ export type BundlerRpcSchema = [ Method: "biconomy_getGasFeeValues" Parameters: [] ReturnType: GasFeeValues + }, + { + Method: "biconomy_getUserOperationStatus" + Parameters: [userOpHash: Hash] + ReturnType: UserOpStatus } ] @@ -143,3 +148,9 @@ export type SendUserOpResponse = { /** The error if the request failed */ error?: JsonRpcError } + +export type UserOpStatus = { + state: string // for now // could be an enum + transactionHash?: string + userOperationReceipt?: UserOpReceipt +} diff --git a/src/client/createSmartAccountClient.ts b/src/client/createSmartAccountClient.ts index 014a3e3bc..4814b7c39 100644 --- a/src/client/createSmartAccountClient.ts +++ b/src/client/createSmartAccountClient.ts @@ -26,7 +26,7 @@ export type SmartAccountClient< /** * Creates a EIP-4337 compliant Bundler Client with a given [Transport](https://viem.sh/docs/clients/intro.html) configured for a [Chain](https://viem.sh/docs/clients/chains.html). * - * - Docs: https://docs.pimlico.io/permissionless/reference/clients/smartAccountClient + * - Docs: * * A Bundler Client is an interface to "erc 4337" [JSON-RPC API](https://eips.ethereum.org/EIPS/eip-4337#rpc-methods-eth-namespace) methods such as sending user operation, estimating gas for a user operation, get user operation receipt, etc through Bundler Actions. * diff --git a/src/client/decorators/bundler.ts b/src/client/decorators/bundler.ts index 56cbe8ba0..67bce8f18 100644 --- a/src/client/decorators/bundler.ts +++ b/src/client/decorators/bundler.ts @@ -13,6 +13,7 @@ import { type GetUserOperationReceiptParameters, getUserOperationReceipt } from "../../bundler/actions/getUserOperationReceipt" +import { getUserOpStatus } from "../../bundler/actions/getUserOperationStatus" import { type SendUserOperationParameters, sendUserOperation @@ -25,6 +26,7 @@ import type { GetUserOperationByHashParameters, StateOverrides, UserOpReceipt, + UserOpStatus, WaitForUserOperationReceiptParameters } from "../../bundler/utils/types" @@ -186,7 +188,7 @@ export type BundlerActions = { ) => Promise | null> /** - * Waits for the User Operation to be included on a [Block](https://viem.sh/docs/glossary/terms.html#block) (one confirmation), and then returns the [User Operation Receipt](https://docs.pimlico.io/permissionless/reference/bundler-actions/getUserOperationReceipt). + * Waits for the User Operation to be included on a [Block](https://viem.sh/docs/glossary/terms.html#block) (one confirmation), and then returns the [User Operation Receipt] * * - Docs: https://docs.biconomy.io/... // TODO * @@ -212,6 +214,7 @@ export type BundlerActions = { ) => Promise> getGasFeeValues: () => Promise + getUserOpStatus: (userOpHash: Hash) => Promise } const bundlerActions = @@ -242,7 +245,9 @@ const bundlerActions = waitForUserOperationReceipt: ( args: WaitForUserOperationReceiptParameters ) => waitForUserOperationReceipt(client as BundlerClient, args), - getGasFeeValues: () => getGasFeeValues(client as BundlerClient) + getGasFeeValues: () => getGasFeeValues(client as BundlerClient), + getUserOpStatus: (userOpHash: Hash) => + getUserOpStatus(client as BundlerClient, userOpHash) }) export { bundlerActions } diff --git a/src/client/decorators/paymaster.ts b/src/client/decorators/paymaster.ts index b2e86592b..7ab56fd1e 100644 --- a/src/client/decorators/paymaster.ts +++ b/src/client/decorators/paymaster.ts @@ -10,19 +10,18 @@ export type PaymasterClientActions = { /** * Returns paymasterAndData & updated gas parameters required to sponsor a userOperation. * - * https://docs.stackup.sh/docs/paymaster-api-rpc-methods#pm_sponsoruseroperation * * @param args {@link SponsorUserOperationParameters} UserOperation you want to sponsor & entryPoint. * @returns paymasterAndData & updated gas parameters, see {@link SponsorUserOperationReturnType} * * @example * import { createClient } from "viem" - * import { stackupPaymasterActions } from "permissionless/actions/stackup" + * import { paymasterActions } from "@biconomy/sdk" // TODO * * const bundlerClient = createClient({ * chain: goerli, - * transport: http("https://api.stackup.sh/v1/paymaster/YOUR_API_KEY_HERE") - * }).extend(stackupPaymasterActions) + * transport: http(paymasterUrl) + * }).extend(paymasterActions) * * await bundlerClient.sponsorUserOperation(bundlerClient, { * userOperation: userOperationWithDummySignature, @@ -37,19 +36,18 @@ export type PaymasterClientActions = { /** * Returns all the Paymaster addresses associated with an EntryPoint that’s owned by this service. * - * https://docs.stackup.sh/docs/paymaster-api-rpc-methods#pm_accounts * * @param args {@link AccountsParameters} entryPoint for which you want to get list of supported paymasters. * @returns paymaster addresses * * @example * import { createClient } from "viem" - * import { stackupPaymasterActions } from "permissionless/actions/stackup" + * import { paymasterActions } from "@biconomy/sdk" // TODO * * const bundlerClient = createClient({ * chain: goerli, - * transport: http("https://api.stackup.sh/v1/paymaster/YOUR_API_KEY_HERE") - * }).extend(stackupPaymasterActions) + * transport: http(paymasterUrl) + * }).extend(paymasterActions) * * await bundlerClient.accounts(bundlerClient, { * entryPoint: entryPoint diff --git a/tests/ep6/account.test.ts b/tests/ep6/account.test.ts index 72a405110..6db21e300 100644 --- a/tests/ep6/account.test.ts +++ b/tests/ep6/account.test.ts @@ -12,7 +12,6 @@ import { import type { Client, Hex, PublicClient } from "viem" import { privateKeyToAccount } from "viem/accounts" -import { SignTransactionNotSupportedBySmartAccount } from "permissionless/accounts" import type { UserOperationStruct } from "../../src/accounts/index.js" import { DEFAULT_ECDSA_OWNERSHIP_MODULE } from "../../src/accounts/utils/constants.js" import { @@ -248,7 +247,9 @@ describe("Biconomy Smart Account V2 EP v6 tests", () => { value: 0n, data: "0x" }) - expect(response).rejects.toThrow(SignTransactionNotSupportedBySmartAccount) + expect(response).rejects.toThrow( + "Sign transaction not supported by smart account" + ) }) test("Should build a user operation manually and send it", async () => { diff --git a/tests/ep6/bundler.test.ts b/tests/ep6/bundler.test.ts index 97d1fb5ad..0005d709d 100644 --- a/tests/ep6/bundler.test.ts +++ b/tests/ep6/bundler.test.ts @@ -25,4 +25,13 @@ describe("Bundler tests", () => { }) expect(await bundlerClient.chainId()).toBe(chainId) }) + + it("Should get user operation status", async () => { + const bundlerClient = createBundlerClient({ + chain, + transport: http(bundlerUrl) + }) + + expect(await bundlerClient.chainId()).toBe(chainId) + }) })