Skip to content

Commit

Permalink
refactor: removed all permissionless mentions + stackup
Browse files Browse the repository at this point in the history
  • Loading branch information
GabiDev45 committed Mar 20, 2024
1 parent 9e9e1f9 commit 658b871
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 91 deletions.
4 changes: 2 additions & 2 deletions src/bundler/actions/getUserOperationByHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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,
Expand Down
68 changes: 0 additions & 68 deletions src/bundler/actions/getUserOperationGasPrice.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/bundler/actions/getUserOperationReceipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions src/bundler/actions/getUserOperationStatus.ts
Original file line number Diff line number Diff line change
@@ -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<TTransport, TChain, TAccount, BundlerRpcSchema>,
userOpHash: Hash
): Promise<UserOpStatus> => {
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.")
}
}
4 changes: 2 additions & 2 deletions src/bundler/actions/sendUserOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ 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}.
* @returns UserOpHash that you can use to track user operation as {@link Hash}.
*
* @example
* import { createClient } from "viem"
* import { sendUserOperation } from "permissionless/actions"
* import { sendUserOperation } from "@biconomy/sdk" // TODO
*
* const bundlerClient = createClient({
* chain: goerli,
Expand Down
7 changes: 4 additions & 3 deletions src/bundler/actions/waitForUserOperationRceipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
13 changes: 12 additions & 1 deletion src/bundler/utils/types.ts
Original file line number Diff line number Diff line change
@@ -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 = [
{
Expand Down Expand Up @@ -60,6 +60,11 @@ export type BundlerRpcSchema = [
Method: "biconomy_getGasFeeValues"
Parameters: []
ReturnType: GasFeeValues
},
{
Method: "biconomy_getUserOperationStatus"
Parameters: [userOpHash: Hash]
ReturnType: UserOpStatus
}
]

Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion src/client/createSmartAccountClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
9 changes: 7 additions & 2 deletions src/client/decorators/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
type GetUserOperationReceiptParameters,
getUserOperationReceipt
} from "../../bundler/actions/getUserOperationReceipt"
import { getUserOpStatus } from "../../bundler/actions/getUserOperationStatus"
import {
type SendUserOperationParameters,
sendUserOperation
Expand All @@ -25,6 +26,7 @@ import type {
GetUserOperationByHashParameters,
StateOverrides,
UserOpReceipt,
UserOpStatus,
WaitForUserOperationReceiptParameters
} from "../../bundler/utils/types"

Expand Down Expand Up @@ -186,7 +188,7 @@ export type BundlerActions = {
) => Promise<Prettify<UserOpReceipt> | 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
*
Expand All @@ -212,6 +214,7 @@ export type BundlerActions = {
) => Promise<Prettify<UserOpReceipt>>

getGasFeeValues: () => Promise<GetGasFeeValuesReturnType>
getUserOpStatus: (userOpHash: Hash) => Promise<UserOpStatus>
}

const bundlerActions =
Expand Down Expand Up @@ -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 }
14 changes: 6 additions & 8 deletions src/client/decorators/paymaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tests/ep6/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 () => {
Expand Down
9 changes: 9 additions & 0 deletions tests/ep6/bundler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

0 comments on commit 658b871

Please sign in to comment.