Skip to content

Make fields of execution mode optional with defaults #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,59 @@ describe.each(getCoreSmartAccounts())(
supportsExecutionModeBatchCallBeforeDeployPostDeploy
).toBe(true)

expect(supportsExecutionModeBatchCallBeforeDeploy).toBe(
supportsExecutionModeBatchCallBeforeDeployPostDeploy
)
}
)
testWithRpc.skipIf(!getErc7579SmartAccountClient)(
"supportsExecutionMode",
async ({ rpc }) => {
const { anvilRpc, altoRpc, paymasterRpc } = rpc

if (!getErc7579SmartAccountClient) {
throw new Error("getErc7579SmartAccountClient not defined")
}

const smartClient = await getErc7579SmartAccountClient({
entryPoint: ENTRYPOINT_ADDRESS_V07,
privateKey: generatePrivateKey(),
altoRpc: altoRpc,
anvilRpc: anvilRpc,
paymasterClient: getPimlicoPaymasterClient({
entryPoint: ENTRYPOINT_ADDRESS_V07,
paymasterRpc
})
})

const supportsExecutionModeBatchCallBeforeDeploy =
await supportsExecutionMode(smartClient as any, {
account: smartClient.account as any,
type: "delegatecall"
})

expect(supportsExecutionModeBatchCallBeforeDeploy).toBe(true)

// deploy account
await smartClient.sendTransaction({
to: zeroAddress,
value: 0n,
data: "0x"
})

const supportsExecutionModeBatchCallBeforeDeployPostDeploy =
await supportsExecutionMode(smartClient as any, {
account: smartClient.account as any,
type: "batchcall",
revertOnError: false,
selector: "0x0",
context: "0x"
})

expect(
supportsExecutionModeBatchCallBeforeDeployPostDeploy
).toBe(true)

expect(supportsExecutionModeBatchCallBeforeDeploy).toBe(
supportsExecutionModeBatchCallBeforeDeployPostDeploy
)
Expand Down
14 changes: 7 additions & 7 deletions packages/permissionless/actions/erc7579/supportsExecutionMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export type CallType = "call" | "delegatecall" | "batchcall"

export type ExecutionMode<callType extends CallType> = {
type: callType
revertOnError: boolean
selector: Hex
context: Hex
revertOnError?: boolean
selector?: Hex
context?: Hex
}

export type SupportsExecutionModeParameters<
Expand All @@ -33,8 +33,8 @@ export type SupportsExecutionModeParameters<
callType extends CallType = CallType
> = GetAccountParameter<TEntryPoint, TSmartAccount> & ExecutionMode<callType>

function parseCallType(executionMode: CallType) {
switch (executionMode) {
function parseCallType(callType: CallType) {
switch (callType) {
case "call":
return "0x00"
case "delegatecall":
Expand All @@ -56,8 +56,8 @@ export function encodeExecutionMode<callType extends CallType>({
toHex(toBytes(parseCallType(type), { size: 1 })),
toHex(toBytes(revertOnError ? "0x01" : "0x00", { size: 1 })),
toHex(toBytes("0x0", { size: 4 })),
toHex(toBytes(selector, { size: 4 })),
toHex(toBytes(context, { size: 22 }))
toHex(toBytes(selector ?? "0x", { size: 4 })),
toHex(toBytes(context ?? "0x", { size: 22 }))
]
)
}
Expand Down
198 changes: 198 additions & 0 deletions packages/permissionless/actions/smartAccount.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
import type {
Abi,
Account,
Address,
Chain,
Client,
Hash,
Hex,
SignTypedDataParameters,
Transport,
TypedData
} from "viem"
import type { SignMessageParameters } from "viem"
import { describe, expectTypeOf, test } from "vitest"
import type { SmartAccount } from "../accounts"
import type { BundlerRpcSchema } from "../types/bundler"
import type {
ENTRYPOINT_ADDRESS_V06_TYPE,
EntryPoint
} from "../types/entrypoint"
import {
type DeployContractParametersWithPaymaster,
type PrepareUserOperationRequestParameters,
type PrepareUserOperationRequestReturnType,
type SendTransactionWithPaymasterParameters,
type SendTransactionsWithPaymasterParameters,
type SendUserOperationParameters,
type WriteContractWithPaymasterParameters,
deployContract,
prepareUserOperationRequest,
sendTransaction,
sendTransactions,
sendUserOperation,
signMessage,
signTypedData,
writeContract
} from "./smartAccount"

describe("index", () => {
test("sendUserOperation", () => {
expectTypeOf(deployContract).toBeFunction()
expectTypeOf(deployContract)
.parameter(0)
.toMatchTypeOf<
Client<
Transport,
Chain | undefined,
Account | undefined,
BundlerRpcSchema<EntryPoint>
>
>()
expectTypeOf(deployContract)
.parameter(1)
.toMatchTypeOf<DeployContractParametersWithPaymaster<EntryPoint>>()
expectTypeOf(deployContract).returns.toMatchTypeOf<Promise<Hash>>()
})
test("prepareUserOperationRequest", () => {
expectTypeOf(prepareUserOperationRequest).toBeFunction()
expectTypeOf(prepareUserOperationRequest)
.parameter(0)
.toMatchTypeOf<
Client<
Transport,
Chain | undefined,
Account | undefined,
BundlerRpcSchema<EntryPoint>
>
>()
expectTypeOf(prepareUserOperationRequest)
.parameter(1)
.toMatchTypeOf<PrepareUserOperationRequestParameters<EntryPoint>>()
expectTypeOf(prepareUserOperationRequest).returns.toMatchTypeOf<
Promise<PrepareUserOperationRequestReturnType<EntryPoint>>
>()
})
test("sendTransaction", () => {
expectTypeOf(sendTransaction).toBeFunction()
expectTypeOf(sendTransaction)
.parameter(0)
.toMatchTypeOf<
Client<
Transport,
Chain | undefined,
Account | undefined,
BundlerRpcSchema<EntryPoint>
>
>()
expectTypeOf(sendTransaction)
.parameter(1)
.toMatchTypeOf<SendTransactionWithPaymasterParameters<EntryPoint>>()
expectTypeOf(sendTransaction).returns.toMatchTypeOf<Promise<Hex>>()
})
test("sendTransactions", () => {
expectTypeOf(sendTransactions).toBeFunction()
expectTypeOf(sendTransactions)
.parameter(0)
.toMatchTypeOf<
Client<
Transport,
Chain | undefined,
Account | undefined,
BundlerRpcSchema<EntryPoint>
>
>()
expectTypeOf(sendTransactions)
.parameter(1)
.toMatchTypeOf<
SendTransactionsWithPaymasterParameters<EntryPoint>
>()
expectTypeOf(sendTransactions).returns.toMatchTypeOf<Promise<Hex>>()
})
test("writeContract", () => {
expectTypeOf(writeContract).toBeFunction()
expectTypeOf(writeContract)
.parameter(0)
.toMatchTypeOf<
Client<
Transport,
Chain | undefined,
Account | undefined,
BundlerRpcSchema<EntryPoint>
>
>()
expectTypeOf(
writeContract<
ENTRYPOINT_ADDRESS_V06_TYPE,
Chain,
SmartAccount<ENTRYPOINT_ADDRESS_V06_TYPE>,
Abi
>
)
.parameter(1)
.toMatchTypeOf<
WriteContractWithPaymasterParameters<
ENTRYPOINT_ADDRESS_V06_TYPE,
Chain,
SmartAccount<ENTRYPOINT_ADDRESS_V06_TYPE>,
Abi
>
>()
expectTypeOf(writeContract).returns.toMatchTypeOf<Promise<Hex>>()
})
test("sendUserOperation", () => {
expectTypeOf(sendUserOperation).toBeFunction()
expectTypeOf(sendUserOperation)
.parameter(0)
.toMatchTypeOf<
Client<
Transport,
Chain | undefined,
Account | undefined,
BundlerRpcSchema<EntryPoint>
>
>()
expectTypeOf(sendUserOperation)
.parameter(1)
.toMatchTypeOf<SendUserOperationParameters<EntryPoint>>()
expectTypeOf(sendUserOperation).returns.toMatchTypeOf<Promise<Hex>>()
})
test("signMessage", () => {
expectTypeOf(signMessage).toBeFunction()
expectTypeOf(signMessage)
.parameter(0)
.toMatchTypeOf<
Client<
Transport,
Chain | undefined,
Account | undefined,
BundlerRpcSchema<EntryPoint>
>
>()
expectTypeOf(signMessage)
.parameter(1)
.toMatchTypeOf<SignMessageParameters<SmartAccount<EntryPoint>>>()
expectTypeOf(signMessage).returns.toMatchTypeOf<Promise<Hex>>()
})
test("signTypedData", () => {
expectTypeOf(signTypedData).toBeFunction()
expectTypeOf(signTypedData)
.parameter(0)
.toMatchTypeOf<
Client<
Transport,
Chain | undefined,
Account | undefined,
BundlerRpcSchema<EntryPoint>
>
>()
expectTypeOf(
signTypedData<EntryPoint, TypedData, string, undefined, undefined>
)
.parameter(1)
.toMatchTypeOf<
SignTypedDataParameters<TypedData, string, undefined>
>()
expectTypeOf(signTypedData).returns.toMatchTypeOf<Promise<Hex>>()
})
})
Loading
Loading