Skip to content

Commit

Permalink
Merge pull request #62 from pimlicolabs/feat/allow-more-modification
Browse files Browse the repository at this point in the history
add more exports, change sponsorUserOperation return type, pass userO…
  • Loading branch information
plusminushalf authored Dec 27, 2023
2 parents af6160f + 7c68b39 commit 3a401ad
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 84 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-cats-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"permissionless": patch
---

Export all actions, sponsorUserOperation now returns complete UserOperation, we pass userOperation to getDummySignature
2 changes: 1 addition & 1 deletion src/accounts/biconomy/signerToBiconomySmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export async function signerToBiconomySmartAccount<
},

// Get simple dummy signature for ECDSA module authorization
async getDummySignature() {
async getDummySignature(_userOperation) {
const moduleAddress =
BICONOMY_ADDRESSES.ECDSA_OWNERSHIP_REGISTRY_MODULE
const dynamicPart = moduleAddress.substring(2).padEnd(40, "0")
Expand Down
3 changes: 3 additions & 0 deletions src/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
signerToBiconomySmartAccount
} from "./biconomy/signerToBiconomySmartAccount.js"

import { privateKeyToBiconomySmartAccount } from "./biconomy/privateKeyToBiconomySmartAccount.js"

import {
SignTransactionNotSupportedBySmartAccount,
type SmartAccount,
Expand All @@ -37,6 +39,7 @@ export {
type SimpleSmartAccount,
signerToSimpleSmartAccount,
SignTransactionNotSupportedBySmartAccount,
privateKeyToBiconomySmartAccount,
privateKeyToSimpleSmartAccount,
type SmartAccount,
privateKeyToSafeSmartAccount,
Expand Down
2 changes: 1 addition & 1 deletion src/accounts/kernel/signerToEcdsaKernelSmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export async function signerToEcdsaKernelSmartAccount<
},

// Get simple dummy signature
async getDummySignature() {
async getDummySignature(_userOperation) {
return "0x00000000fffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/accounts/signerToSafeSmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ export async function signerToSafeSmartAccount<
args: [to, value, data, 0]
})
},
async getDummySignature() {
async getDummySignature(_userOperation) {
return "0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/accounts/signerToSimpleSmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export async function signerToSimpleSmartAccount<
args: [to, value, data]
})
},
async getDummySignature() {
async getDummySignature(_userOperation) {
return "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c"
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/accounts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ export type SmartAccount<
data: Hex
}[]
) => Promise<Hex>
getDummySignature(): Promise<Hex>
getDummySignature(userOperation: UserOperation): Promise<Hex>
encodeDeployCallData: <TAbi extends Abi | readonly unknown[] = Abi>({
abi,
args,
bytecode
}: { abi: TAbi; bytecode: Hex } & GetConstructorArgs<TAbi>) => Promise<Hex>
signUserOperation: (UserOperation: UserOperation) => Promise<Hex>
signUserOperation: (userOperation: UserOperation) => Promise<Hex>
}

export type SmartAccountSigner<
Expand Down
14 changes: 6 additions & 8 deletions src/actions/pimlico/sponsorUserOperation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Account, Address, Chain, Client, Hex, Transport } from "viem"
import type { Account, Address, Chain, Client, Transport } from "viem"
import type { PartialBy } from "viem/types/utils"
import type { PimlicoPaymasterRpcSchema } from "../../types/pimlico.js"
import type {
Expand All @@ -19,12 +19,7 @@ export type PimlocoSponsorUserOperationParameters = {
sponsorshipPolicyId?: string
}

export type SponsorUserOperationReturnType = {
paymasterAndData: Hex
preVerificationGas: bigint
verificationGasLimit: bigint
callGasLimit: bigint
}
export type SponsorUserOperationReturnType = UserOperation

/**
* Returns paymasterAndData & updated gas parameters required to sponsor a userOperation.
Expand Down Expand Up @@ -79,10 +74,13 @@ export const sponsorUserOperation = async <
]
})

return {
const userOperation: UserOperation = {
...args.userOperation,
paymasterAndData: response.paymasterAndData,
preVerificationGas: BigInt(response.preVerificationGas),
verificationGasLimit: BigInt(response.verificationGasLimit),
callGasLimit: BigInt(response.callGasLimit)
}

return userOperation
}
9 changes: 8 additions & 1 deletion src/actions/smartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ import {
sendTransactions
} from "./smartAccount/sendTransactions.js"

import {
type WriteContractWithPaymasterParameters,
writeContract
} from "./smartAccount/writeContract.js"

export {
deployContract,
type DeployContractParametersWithPaymaster,
Expand All @@ -45,5 +50,7 @@ export {
type SendTransactionWithPaymasterParameters,
type SponsorUserOperationMiddleware,
sendTransactions,
type SendTransactionsWithPaymasterParameters
type SendTransactionsWithPaymasterParameters,
type WriteContractWithPaymasterParameters,
writeContract
}
33 changes: 10 additions & 23 deletions src/actions/smartAccount/prepareUserOperationRequest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Address, Chain, Client, Hex, Transport } from "viem"
import type { Address, Chain, Client, Transport } from "viem"
import { estimateFeesPerGas } from "viem/actions"
import type { SmartAccount } from "../../accounts/types.js"
import type {
Expand All @@ -17,12 +17,7 @@ export type SponsorUserOperationMiddleware = {
sponsorUserOperation?: (args: {
userOperation: UserOperation
entryPoint: Address
}) => Promise<{
paymasterAndData: Hex
preVerificationGas: bigint
verificationGasLimit: bigint
callGasLimit: bigint
}>
}) => Promise<UserOperation>
}

export type PrepareUserOperationRequestParameters<
Expand Down Expand Up @@ -63,26 +58,25 @@ export async function prepareUserOperationRequest<

const account = parseAccount(account_) as SmartAccount

const [sender, nonce, initCode, signature, callData, gasEstimation] =
const [sender, nonce, initCode, callData, gasEstimation] =
await Promise.all([
partialUserOperation.sender || account.address,
partialUserOperation.nonce || account.getNonce(),
partialUserOperation.initCode || account.getInitCode(),
partialUserOperation.signature || account.getDummySignature(),
partialUserOperation.callData,
!partialUserOperation.maxFeePerGas ||
!partialUserOperation.maxPriorityFeePerGas
? estimateFeesPerGas(account.client)
: undefined
])

const userOperation: UserOperation = {
let userOperation: UserOperation = {
sender,
nonce,
initCode,
signature,
callData,
paymasterAndData: "0x",
signature: partialUserOperation.signature || "0x",
maxFeePerGas:
partialUserOperation.maxFeePerGas ||
gasEstimation?.maxFeePerGas ||
Expand All @@ -96,22 +90,15 @@ export async function prepareUserOperationRequest<
preVerificationGas: partialUserOperation.preVerificationGas || 0n
}

if (userOperation.signature === "0x") {
userOperation.signature = await account.getDummySignature(userOperation)
}

if (sponsorUserOperation) {
const {
callGasLimit,
verificationGasLimit,
preVerificationGas,
paymasterAndData
} = await sponsorUserOperation({
userOperation = await sponsorUserOperation({
userOperation,
entryPoint: account.entryPoint
})
userOperation.paymasterAndData = paymasterAndData
userOperation.callGasLimit = userOperation.callGasLimit || callGasLimit
userOperation.verificationGasLimit =
userOperation.verificationGasLimit || verificationGasLimit
userOperation.preVerificationGas =
userOperation.preVerificationGas || preVerificationGas
} else if (
!userOperation.callGasLimit ||
!userOperation.verificationGasLimit ||
Expand Down
14 changes: 6 additions & 8 deletions src/actions/stackup/sponsorUserOperation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Address, Hex } from "viem"
import type { Address } from "viem"
import type { PartialBy } from "viem/types/utils"
import { type StackupPaymasterClient } from "../../clients/stackup.js"
import type { StackupPaymasterContext } from "../../types/stackup.js"
Expand All @@ -20,12 +20,7 @@ export type SponsorUserOperationParameters = {
context: StackupPaymasterContext
}

export type SponsorUserOperationReturnType = {
paymasterAndData: Hex
preVerificationGas: bigint
verificationGasLimit: bigint
callGasLimit: bigint
}
export type SponsorUserOperationReturnType = UserOperation

/**
* Returns paymasterAndData & updated gas parameters required to sponsor a userOperation.
Expand Down Expand Up @@ -65,10 +60,13 @@ export const sponsorUserOperation = async (
]
})

return {
const userOperation: UserOperation = {
...args.userOperation,
paymasterAndData: response.paymasterAndData,
preVerificationGas: BigInt(response.preVerificationGas),
verificationGasLimit: BigInt(response.verificationGasLimit),
callGasLimit: BigInt(response.callGasLimit)
}

return userOperation
}
35 changes: 0 additions & 35 deletions src/utils/deepHexlify.test.ts

This file was deleted.

7 changes: 7 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { Account, Address } from "viem"
import { deepHexlify, transactionReceiptStatus } from "./deepHexlify.js"
import { getAction } from "./getAction.js"
import {
type GetRequiredPrefundReturnType,
getRequiredPrefund
Expand All @@ -9,6 +11,7 @@ import {
} from "./getUserOperationHash.js"
import {
AccountOrClientNotFoundError,
type SignUserOperationHashWithECDSAParams,
signUserOperationHashWithECDSA
} from "./signUserOperationHashWithECDSA.js"
import { walletClientToCustomSigner } from "./walletClientToCustomSigner.js"
Expand All @@ -20,11 +23,15 @@ export function parseAccount(account: Address | Account): Account {
}

export {
transactionReceiptStatus,
deepHexlify,
getAction,
getUserOperationHash,
getRequiredPrefund,
walletClientToCustomSigner,
type GetRequiredPrefundReturnType,
type GetUserOperationHashParams,
signUserOperationHashWithECDSA,
type SignUserOperationHashWithECDSAParams,
AccountOrClientNotFoundError
}
4 changes: 2 additions & 2 deletions src/utils/signUserOperationHashWithECDSA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { UserOperation } from "../types/userOperation.js"
import { getUserOperationHash } from "./getUserOperationHash.js"
import { parseAccount } from "./index.js"

export type signUserOperationHashWithECDSAParams<
export type SignUserOperationHashWithECDSAParams<
TTransport extends Transport = Transport,
TChain extends Chain | undefined = Chain | undefined,
TAccount extends Account | undefined = Account | undefined
Expand Down Expand Up @@ -83,7 +83,7 @@ export const signUserOperationHashWithECDSA = async <
userOperation,
chainId,
entryPoint
}: signUserOperationHashWithECDSAParams<
}: SignUserOperationHashWithECDSAParams<
TTransport,
TChain,
TAccount
Expand Down
22 changes: 21 additions & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { beforeAll, describe, expect, test } from "bun:test"
import dotenv from "dotenv"
import { getSenderAddress, getUserOperationHash } from "permissionless"
import {
deepHexlify,
getSenderAddress,
getUserOperationHash
} from "permissionless"
import {
getRequiredPrefund,
signUserOperationHashWithECDSA
Expand Down Expand Up @@ -32,6 +36,22 @@ beforeAll(() => {
})

describe("test public actions and utils", () => {
test("Test deep Hexlify", async () => {
expect(deepHexlify("abcd")).toBe("abcd")
expect(deepHexlify(null)).toBe(null)
expect(deepHexlify(true)).toBe(true)
expect(deepHexlify(false)).toBe(false)
expect(deepHexlify(1n)).toBe("0x1")
expect(
deepHexlify({
name: "Garvit",
balance: 1n
})
).toEqual({
name: "Garvit",
balance: "0x1"
})
})
test("get sender address", async () => {
const eoaWalletClient = getEoaWalletClient()
const factoryAddress = getFactoryAddress()
Expand Down

0 comments on commit 3a401ad

Please sign in to comment.