Skip to content

Commit

Permalink
chore: prep user op fix (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
joepegler authored Jan 15, 2025
1 parent 24bded1 commit d3305a0
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @biconomy/sdk

## 0.0.26

### Patch Changes

- Remove signature from prepareUserOperation flow

## 0.0.25

### Patch Changes
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@biconomy/sdk",
"version": "0.0.25",
"version": "0.0.26",
"author": "Biconomy",
"repository": "github:bcnmy/sdk",
"main": "./dist/_cjs/index.js",
Expand Down
17 changes: 15 additions & 2 deletions src/sdk/clients/createBundlerClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const COMPETITORS = [
name: "Pimlico",
chain: baseSepolia,
bundlerUrl: `https://api.pimlico.io/v2/${baseSepolia.id}/rpc?apikey=${process.env.PIMLICO_API_KEY}`
},
{
name: "Biconomy",
bundlerUrl: `https://bundler.biconomy.io/api/v3/${baseSepolia.id}/nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44`,
chain: baseSepolia
}
]

Expand Down Expand Up @@ -93,7 +98,7 @@ describe.each(COMPETITORS)(
})

// Send user operation
const hash = await bundlerClient.sendTransaction({
const userOp = await bundlerClient.prepareUserOperation({
calls: [
{
to: recipientAddress,
Expand All @@ -102,8 +107,16 @@ describe.each(COMPETITORS)(
]
})

const userOpHash = await bundlerClient.sendUserOperation(userOp)

const userOpReceipt = await bundlerClient.waitForUserOperationReceipt({
hash: userOpHash
})

// Wait for the transaction to be mined
const receipt = await publicClient.waitForTransactionReceipt({ hash })
const receipt = await publicClient.waitForTransactionReceipt({
hash: userOpReceipt.receipt.transactionHash
})
expect(receipt.status).toBe("success")

// Get final balance
Expand Down
4 changes: 2 additions & 2 deletions src/sdk/clients/decorators/smartAccount/debugUserOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
type UserOperationRequest,
formatUserOperationRequest,
getUserOperationError,
prepareUserOperation,
toPackedUserOperation
} from "viem/account-abstraction"
import { prepareUserOperationWithoutSignature } from "./prepareUserOperationWithoutSignature"

import type {
Assign,
Expand Down Expand Up @@ -132,7 +132,7 @@ export async function debugUserOperation<
const request = account
? await getAction(
client,
prepareUserOperation,
prepareUserOperationWithoutSignature,
"prepareUserOperation"
)(parameters as unknown as PrepareUserOperationParameters)
: parameters
Expand Down
24 changes: 22 additions & 2 deletions src/sdk/clients/decorators/smartAccount/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import type {
WaitForTransactionReceiptReturnType,
WriteContractParameters
} from "viem"
import type { SmartAccount, UserOperation } from "viem/account-abstraction"
import type {
PrepareUserOperationParameters,
PrepareUserOperationReturnType,
SmartAccount,
UserOperation
} from "viem/account-abstraction"
import type { AnyData } from "../../../modules/utils/Types"
import {
type DebugUserOperationReturnType,
Expand All @@ -22,6 +27,7 @@ import {
type PrepareTokenPaymasterUserOpParameters,
prepareTokenPaymasterUserOp
} from "./prepareTokenPaymasterUserOp"
import { prepareUserOperationWithoutSignature } from "./prepareUserOperationWithoutSignature"
import {
type SendTokenPaymasterUserOpParameters,
sendTokenPaymasterUserOp
Expand Down Expand Up @@ -370,6 +376,18 @@ export type SmartAccountActions<
debugUserOperation: (
params: DebugUserOperationParameters
) => Promise<DebugUserOperationReturnType>
/**
* Prepares a user operation
* @param params - {@link PrepareUserOperationParameters}
* @returns The user operation. {@link PrepareUserOperationReturnType}
* @example
* const userOp = await prepareUserOperation({
* calls: [{to: '0x...', value: 1n, data: '0x...'}]
* })
*/
prepareUserOperation: (
params: PrepareUserOperationParameters
) => Promise<ReturnType<typeof prepareUserOperationWithoutSignature>>
}

export function smartAccountActions() {
Expand All @@ -388,6 +406,8 @@ export function smartAccountActions() {
writeContract: (args) => writeContract(client, args),
waitForTransactionReceipt: (args) =>
waitForTransactionReceipt(client, args),
debugUserOperation: (args) => debugUserOperation(client, args)
debugUserOperation: (args) => debugUserOperation(client, args),
prepareUserOperation: (args) =>
prepareUserOperationWithoutSignature(client, args)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import {
maxUint256
} from "viem"
import { encodeFunctionData } from "viem"
import {
type SmartAccount,
type UserOperation,
prepareUserOperation
} from "viem/account-abstraction"
import type { SmartAccount, UserOperation } from "viem/account-abstraction"
import { getAction } from "viem/utils"
import { BICONOMY_TOKEN_PAYMASTER } from "../../../account/utils/Constants"
import { prepareUserOperationWithoutSignature } from "./prepareUserOperationWithoutSignature"

export type Transaction = {
to: Address
Expand Down Expand Up @@ -75,7 +72,7 @@ export async function prepareTokenPaymasterUserOp<

const userOp = await getAction(
client,
prepareUserOperation,
prepareUserOperationWithoutSignature,
"prepareUserOperation"
)({
calls: [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { prepareUserOperation } from "viem/account-abstraction"

import type { Chain, Client, Transport } from "viem"
import type {
PrepareUserOperationParameters,
PrepareUserOperationRequest,
PrepareUserOperationReturnType,
SmartAccount
} from "viem/account-abstraction"
import { getAction } from "viem/utils"

export async function prepareUserOperationWithoutSignature<
account extends SmartAccount | undefined,
const calls extends readonly unknown[],
const request extends PrepareUserOperationRequest<
account,
accountOverride,
calls
>,
accountOverride extends SmartAccount | undefined = undefined
>(
client: Client<Transport, Chain | undefined, account>,
args: PrepareUserOperationParameters<account, accountOverride, calls, request>
): Promise<
Omit<
PrepareUserOperationReturnType<account, accountOverride, calls, request>,
"signature"
>
> {
const userOp = await getAction(
client,
prepareUserOperation,
"prepareUserOperation"
)(args)

// Remove signature from userOp if it exists
// @ts-ignore
const { signature, ...userOpWithoutSignature } = userOp

return userOpWithoutSignature
}

0 comments on commit d3305a0

Please sign in to comment.