diff --git a/.changeset/small-bulldogs-press.md b/.changeset/small-bulldogs-press.md new file mode 100644 index 00000000..c0f12124 --- /dev/null +++ b/.changeset/small-bulldogs-press.md @@ -0,0 +1,5 @@ +--- +"permissionless": patch +--- + +fix getAction for cases where minifier changes function names diff --git a/.size-limit.json b/.size-limit.json index b2305a09..6ad6af73 100644 --- a/.size-limit.json +++ b/.size-limit.json @@ -2,18 +2,18 @@ { "name": "permissionless (esm)", "path": "./packages/permissionless/_esm/index.js", - "limit": "35 kB", + "limit": "40 kB", "import": "*" }, { "name": "permissionless (cjs)", "path": "./packages/permissionless/_cjs/index.js", - "limit": "150 kB" + "limit": "160 kB" }, { "name": "permissionless (minimal surface - tree-shaking)", "path": "./packages/permissionless/_esm/index.js", - "limit": "15 kB", + "limit": "20 kB", "import": "{ bundlerActions }" } ] diff --git a/bun.lockb b/bun.lockb index 66db1e89..09ec32a0 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/packages/permissionless-test/package.json b/packages/permissionless-test/package.json index bfced29d..c2958c28 100644 --- a/packages/permissionless-test/package.json +++ b/packages/permissionless-test/package.json @@ -20,6 +20,6 @@ "execa": "^8.0.1", "get-port": "^7.0.0", "permissionless": "workspace:packages/permissionless", - "viem": "^2.0.0" + "viem": "2.9.17" } } diff --git a/packages/permissionless/actions/bundler/waitForUserOperationReceipt.ts b/packages/permissionless/actions/bundler/waitForUserOperationReceipt.ts index 717d5e4a..f8945da3 100644 --- a/packages/permissionless/actions/bundler/waitForUserOperationReceipt.ts +++ b/packages/permissionless/actions/bundler/waitForUserOperationReceipt.ts @@ -7,8 +7,8 @@ import { type Transport, stringify } from "viem" +import { getAction } from "viem/utils" import type { Prettify } from "../../types/" -import { getAction } from "../../utils/getAction" import { observe } from "../../utils/observe" import { type GetUserOperationReceiptReturnType, @@ -94,7 +94,8 @@ export const waitForUserOperationReceipt = < try { const _userOperationReceipt = await getAction( bundlerClient, - getUserOperationReceipt + getUserOperationReceipt, + "getUserOperationReceipt" )({ hash }) if (_userOperationReceipt !== null) { diff --git a/packages/permissionless/actions/public/getAccountNonce.ts b/packages/permissionless/actions/public/getAccountNonce.ts index 5b0ecd8d..218f4299 100644 --- a/packages/permissionless/actions/public/getAccountNonce.ts +++ b/packages/permissionless/actions/public/getAccountNonce.ts @@ -1,8 +1,8 @@ import type { Address, Chain, Client, Transport } from "viem" import { readContract } from "viem/actions" +import { getAction } from "viem/utils" import type { Prettify } from "../../types/" import type { EntryPoint } from "../../types/entrypoint" -import { getAction } from "../../utils/getAction" export type GetAccountNonceParams = { sender: Address @@ -47,7 +47,8 @@ export const getAccountNonce = async < return await getAction( client, - readContract + readContract, + "readContract" )({ address: entryPoint, abi: [ diff --git a/packages/permissionless/actions/public/getSenderAddress.ts b/packages/permissionless/actions/public/getSenderAddress.ts index 191ea768..d8ade9d8 100644 --- a/packages/permissionless/actions/public/getSenderAddress.ts +++ b/packages/permissionless/actions/public/getSenderAddress.ts @@ -14,12 +14,12 @@ import { } from "viem" import { simulateContract } from "viem/actions" +import { getAction } from "viem/utils" import type { Prettify } from "../../types/" import type { ENTRYPOINT_ADDRESS_V06_TYPE, EntryPoint } from "../../types/entrypoint" -import { getAction } from "../../utils/getAction" export type GetSenderAddressParams = entryPoint extends ENTRYPOINT_ADDRESS_V06_TYPE @@ -98,7 +98,8 @@ export const getSenderAddress = async < try { await getAction( client, - simulateContract + simulateContract, + "simulateContract" )({ address: entryPoint, abi: [ diff --git a/packages/permissionless/actions/smartAccount/deployContract.ts b/packages/permissionless/actions/smartAccount/deployContract.ts index 315654c1..8539e873 100644 --- a/packages/permissionless/actions/smartAccount/deployContract.ts +++ b/packages/permissionless/actions/smartAccount/deployContract.ts @@ -7,11 +7,11 @@ import type { Hash, Transport } from "viem" +import { getAction } from "viem/utils" import type { SmartAccount } from "../../accounts/types" import type { Prettify } from "../../types/" import type { EntryPoint } from "../../types/entrypoint" import { parseAccount } from "../../utils/" -import { getAction } from "../../utils/getAction" import { AccountOrClientNotFoundError } from "../../utils/signUserOperationHashWithECDSA" import { waitForUserOperationReceipt } from "../bundler/waitForUserOperationReceipt" import { type Middleware } from "./prepareUserOperationRequest" @@ -84,7 +84,8 @@ export async function deployContract< const userOpHash = await getAction( client, - sendUserOperation + sendUserOperation, + "sendUserOperation" )({ userOperation: { sender: account.address, @@ -102,7 +103,8 @@ export async function deployContract< const userOperationReceipt = await getAction( client, - waitForUserOperationReceipt + waitForUserOperationReceipt, + "waitForUserOperationReceipt" )({ hash: userOpHash }) diff --git a/packages/permissionless/actions/smartAccount/prepareUserOperationRequest.ts b/packages/permissionless/actions/smartAccount/prepareUserOperationRequest.ts index a370ec1c..edfc8d82 100644 --- a/packages/permissionless/actions/smartAccount/prepareUserOperationRequest.ts +++ b/packages/permissionless/actions/smartAccount/prepareUserOperationRequest.ts @@ -1,5 +1,6 @@ import type { Chain, Client, Transport } from "viem" import { estimateFeesPerGas } from "viem/actions" +import { getAction } from "viem/utils" import type { SmartAccount } from "../../accounts/types" import type { GetAccountParameter, @@ -15,7 +16,6 @@ import type { GetEntryPointVersion } from "../../types/entrypoint" import { AccountOrClientNotFoundError, parseAccount } from "../../utils/" -import { getAction } from "../../utils/getAction" import { getEntryPointVersion } from "../../utils/getEntryPointVersion" import { estimateUserOperationGas } from "../bundler/estimateUserOperationGas" @@ -211,7 +211,11 @@ async function prepareUserOperationRequestForEntryPointV06< !userOperation.verificationGasLimit || !userOperation.preVerificationGas ) { - const gasParameters = await getAction(client, estimateUserOperationGas)( + const gasParameters = await getAction( + client, + estimateUserOperationGas, + "estimateUserOperationGas" + )( { userOperation, entryPoint: account.entryPoint @@ -219,6 +223,7 @@ async function prepareUserOperationRequestForEntryPointV06< userOperation: UserOperation> entryPoint: entryPoint }, + // @ts-ignore getAction takes only two params but when compiled this will work stateOverrides ) @@ -365,12 +370,14 @@ async function prepareUserOperationRequestEntryPointV07< ) { const gasParameters = await getAction( client, - estimateUserOperationGas + estimateUserOperationGas, + "estimateUserOperationGas" )( { userOperation, entryPoint: account.entryPoint }, + // @ts-ignore getAction takes only two params but when compiled this will work stateOverrides ) diff --git a/packages/permissionless/actions/smartAccount/sendTransaction.ts b/packages/permissionless/actions/smartAccount/sendTransaction.ts index dd15f0dc..a3a415f4 100644 --- a/packages/permissionless/actions/smartAccount/sendTransaction.ts +++ b/packages/permissionless/actions/smartAccount/sendTransaction.ts @@ -5,11 +5,11 @@ import type { SendTransactionParameters, Transport } from "viem" +import { getAction } from "viem/utils" import { type SmartAccount } from "../../accounts/types" import type { Prettify } from "../../types/" import type { EntryPoint } from "../../types/entrypoint" import { AccountOrClientNotFoundError, parseAccount } from "../../utils/" -import { getAction } from "../../utils/getAction" import { waitForUserOperationReceipt } from "../bundler/waitForUserOperationReceipt" import { type Middleware } from "./prepareUserOperationRequest" import { sendUserOperation } from "./sendUserOperation" @@ -119,7 +119,8 @@ export async function sendTransaction< const userOpHash = await getAction( client, - sendUserOperation + sendUserOperation, + "sendUserOperation" )({ userOperation: { sender: account.address, @@ -134,7 +135,8 @@ export async function sendTransaction< const userOperationReceipt = await getAction( client, - waitForUserOperationReceipt + waitForUserOperationReceipt, + "waitForUserOperationReceipt" )({ hash: userOpHash }) diff --git a/packages/permissionless/actions/smartAccount/sendTransactions.ts b/packages/permissionless/actions/smartAccount/sendTransactions.ts index 1955f404..7189c3af 100644 --- a/packages/permissionless/actions/smartAccount/sendTransactions.ts +++ b/packages/permissionless/actions/smartAccount/sendTransactions.ts @@ -7,11 +7,11 @@ import type { SendTransactionParameters, Transport } from "viem" +import { getAction } from "viem/utils" import { type SmartAccount } from "../../accounts/types" import type { GetAccountParameter, Prettify } from "../../types/" import type { EntryPoint } from "../../types/entrypoint" import { AccountOrClientNotFoundError, parseAccount } from "../../utils/" -import { getAction } from "../../utils/getAction" import { waitForUserOperationReceipt } from "../bundler/waitForUserOperationReceipt" import { type Middleware } from "./prepareUserOperationRequest" import { sendUserOperation } from "./sendUserOperation" @@ -120,7 +120,8 @@ export async function sendTransactions< const userOpHash = await getAction( client, - sendUserOperation + sendUserOperation, + "sendUserOperation" )({ userOperation: { sender: account.address, @@ -135,7 +136,8 @@ export async function sendTransactions< const userOperationReceipt = await getAction( client, - waitForUserOperationReceipt + waitForUserOperationReceipt, + "waitForUserOperationReceipt" )({ hash: userOpHash }) diff --git a/packages/permissionless/actions/smartAccount/sendUserOperation.ts b/packages/permissionless/actions/smartAccount/sendUserOperation.ts index 3b168cbc..84e9afc5 100644 --- a/packages/permissionless/actions/smartAccount/sendUserOperation.ts +++ b/packages/permissionless/actions/smartAccount/sendUserOperation.ts @@ -1,4 +1,5 @@ import type { Chain, Client, Hash, Transport } from "viem" +import { getAction } from "viem/utils" import type { SmartAccount } from "../../accounts/types" import type { GetAccountParameter, @@ -12,7 +13,6 @@ import type { GetEntryPointVersion } from "../../types/entrypoint" import { AccountOrClientNotFoundError, parseAccount } from "../../utils/" -import { getAction } from "../../utils/getAction" import { sendUserOperation as sendUserOperationBundler } from "../bundler/sendUserOperation" import { type Middleware, @@ -77,7 +77,8 @@ export async function sendUserOperation< const userOperation = await getAction( client, - prepareUserOperationRequest + prepareUserOperationRequest, + "prepareUserOperationRequest" )(args) userOperation.signature = await account.signUserOperation( diff --git a/packages/permissionless/actions/smartAccount/writeContract.ts b/packages/permissionless/actions/smartAccount/writeContract.ts index 3a0058d7..8e29d521 100644 --- a/packages/permissionless/actions/smartAccount/writeContract.ts +++ b/packages/permissionless/actions/smartAccount/writeContract.ts @@ -10,9 +10,9 @@ import { type WriteContractParameters, encodeFunctionData } from "viem" +import { getAction } from "viem/utils" import { type SmartAccount } from "../../accounts/types" import type { EntryPoint } from "../../types/entrypoint" -import { getAction } from "../../utils/getAction" import { type Middleware } from "./prepareUserOperationRequest" import { type SendTransactionWithPaymasterParameters, @@ -138,7 +138,8 @@ export async function writeContract< } as EncodeFunctionDataParameters) const hash = await getAction( client, - sendTransaction + sendTransaction, + "sendTransaction" )({ data: `${data}${dataSuffix ? dataSuffix.replace("0x", "") : ""}`, to: address, diff --git a/packages/permissionless/package.json b/packages/permissionless/package.json index 1fb2790e..1d52b2e0 100644 --- a/packages/permissionless/package.json +++ b/packages/permissionless/package.json @@ -82,6 +82,6 @@ } }, "peerDependencies": { - "viem": "^2.0.0" + "viem": "^2.9.17" } } diff --git a/packages/permissionless/utils/getAction.ts b/packages/permissionless/utils/getAction.ts deleted file mode 100644 index 66ac9a74..00000000 --- a/packages/permissionless/utils/getAction.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type { Client } from "viem" - -// biome-ignore lint/suspicious/noExplicitAny: it's a generic function, so it's hard to type -export function getAction( - client: Client, - // biome-ignore lint/suspicious/noExplicitAny: it's a recursive function, so it's hard to type - action: (_: any, ...params: params) => returnType, - actionName: string = action.name -) { - return (...params: params): returnType => - ( - client as Client & { - [key: string]: (...params: params) => returnType - } - )[actionName]?.(...params) ?? action(client, ...params) -} diff --git a/packages/permissionless/utils/index.ts b/packages/permissionless/utils/index.ts index c8adb0bf..99d5896c 100644 --- a/packages/permissionless/utils/index.ts +++ b/packages/permissionless/utils/index.ts @@ -1,6 +1,5 @@ import type { Account, Address } from "viem" import { deepHexlify, transactionReceiptStatus } from "./deepHexlify" -import { getAction } from "./getAction" import { getAddressFromInitCodeOrPaymasterAndData } from "./getAddressFromInitCodeOrPaymasterAndData" import { type GetRequiredPrefundReturnType, @@ -35,7 +34,6 @@ import { getPackedUserOperation } from "./getPackedUserOperation" export { transactionReceiptStatus, deepHexlify, - getAction, getUserOperationHash, getRequiredPrefund, walletClientToSmartAccountSigner, diff --git a/packages/wagmi-test-demo/package.json b/packages/wagmi-test-demo/package.json index c577dd1a..56f6792d 100644 --- a/packages/wagmi-test-demo/package.json +++ b/packages/wagmi-test-demo/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "wagmi": "^2.5.1", - "viem": "^2.0.0", + "viem": "2.9.17", "@tanstack/react-query": "5.0.5", "react": "^18.2.0", "permissionless": "0.0.36", diff --git a/packages/wagmi/package.json b/packages/wagmi/package.json index fad4764f..22ff9e4e 100644 --- a/packages/wagmi/package.json +++ b/packages/wagmi/package.json @@ -25,6 +25,6 @@ }, "peerDependencies": { "wagmi": "^2.5.1", - "viem": "^2.0.0" + "viem": "2.9.17" } }