Skip to content

Commit

Permalink
Merge pull request #172 from pimlicolabs/fix/getAction
Browse files Browse the repository at this point in the history
Use viem's getAction
  • Loading branch information
plusminushalf authored Apr 15, 2024
2 parents 7e23e4f + 0cd6428 commit 277dcac
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 47 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-bulldogs-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"permissionless": patch
---

fix getAction for cases where minifier changes function names
6 changes: 3 additions & 3 deletions .size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 }"
}
]
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/permissionless-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -94,7 +94,8 @@ export const waitForUserOperationReceipt = <
try {
const _userOperationReceipt = await getAction(
bundlerClient,
getUserOperationReceipt
getUserOperationReceipt,
"getUserOperationReceipt"
)({ hash })

if (_userOperationReceipt !== null) {
Expand Down
5 changes: 3 additions & 2 deletions packages/permissionless/actions/public/getAccountNonce.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -47,7 +47,8 @@ export const getAccountNonce = async <

return await getAction(
client,
readContract
readContract,
"readContract"
)({
address: entryPoint,
abi: [
Expand Down
5 changes: 3 additions & 2 deletions packages/permissionless/actions/public/getSenderAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> =
entryPoint extends ENTRYPOINT_ADDRESS_V06_TYPE
Expand Down Expand Up @@ -98,7 +98,8 @@ export const getSenderAddress = async <
try {
await getAction(
client,
simulateContract
simulateContract,
"simulateContract"
)({
address: entryPoint,
abi: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -84,7 +84,8 @@ export async function deployContract<

const userOpHash = await getAction(
client,
sendUserOperation<entryPoint>
sendUserOperation<entryPoint>,
"sendUserOperation"
)({
userOperation: {
sender: account.address,
Expand All @@ -102,7 +103,8 @@ export async function deployContract<

const userOperationReceipt = await getAction(
client,
waitForUserOperationReceipt
waitForUserOperationReceipt,
"waitForUserOperationReceipt"
)({
hash: userOpHash
})
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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"

Expand Down Expand Up @@ -211,14 +211,19 @@ async function prepareUserOperationRequestForEntryPointV06<
!userOperation.verificationGasLimit ||
!userOperation.preVerificationGas
) {
const gasParameters = await getAction(client, estimateUserOperationGas)(
const gasParameters = await getAction(
client,
estimateUserOperationGas,
"estimateUserOperationGas"
)(
{
userOperation,
entryPoint: account.entryPoint
} as {
userOperation: UserOperation<GetEntryPointVersion<entryPoint>>
entryPoint: entryPoint
},
// @ts-ignore getAction takes only two params but when compiled this will work
stateOverrides
)

Expand Down Expand Up @@ -365,12 +370,14 @@ async function prepareUserOperationRequestEntryPointV07<
) {
const gasParameters = await getAction(
client,
estimateUserOperationGas<ENTRYPOINT_ADDRESS_V07_TYPE>
estimateUserOperationGas<ENTRYPOINT_ADDRESS_V07_TYPE>,
"estimateUserOperationGas"
)(
{
userOperation,
entryPoint: account.entryPoint
},
// @ts-ignore getAction takes only two params but when compiled this will work
stateOverrides
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -119,7 +119,8 @@ export async function sendTransaction<

const userOpHash = await getAction(
client,
sendUserOperation<entryPoint>
sendUserOperation<entryPoint>,
"sendUserOperation"
)({
userOperation: {
sender: account.address,
Expand All @@ -134,7 +135,8 @@ export async function sendTransaction<

const userOperationReceipt = await getAction(
client,
waitForUserOperationReceipt
waitForUserOperationReceipt,
"waitForUserOperationReceipt"
)({
hash: userOpHash
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -120,7 +120,8 @@ export async function sendTransactions<

const userOpHash = await getAction(
client,
sendUserOperation<entryPoint>
sendUserOperation<entryPoint>,
"sendUserOperation"
)({
userOperation: {
sender: account.address,
Expand All @@ -135,7 +136,8 @@ export async function sendTransactions<

const userOperationReceipt = await getAction(
client,
waitForUserOperationReceipt
waitForUserOperationReceipt,
"waitForUserOperationReceipt"
)({
hash: userOpHash
})
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -77,7 +77,8 @@ export async function sendUserOperation<

const userOperation = await getAction(
client,
prepareUserOperationRequest<entryPoint, TTransport, TChain, TAccount>
prepareUserOperationRequest<entryPoint, TTransport, TChain, TAccount>,
"prepareUserOperationRequest"
)(args)

userOperation.signature = await account.signUserOperation(
Expand Down
5 changes: 3 additions & 2 deletions packages/permissionless/actions/smartAccount/writeContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -138,7 +138,8 @@ export async function writeContract<
} as EncodeFunctionDataParameters<TAbi, TFunctionName>)
const hash = await getAction(
client,
sendTransaction<TChain, TAccount, entryPoint, TChainOverride>
sendTransaction<TChain, TAccount, entryPoint, TChainOverride>,
"sendTransaction"
)({
data: `${data}${dataSuffix ? dataSuffix.replace("0x", "") : ""}`,
to: address,
Expand Down
2 changes: 1 addition & 1 deletion packages/permissionless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@
}
},
"peerDependencies": {
"viem": "^2.0.0"
"viem": "^2.9.17"
}
}
16 changes: 0 additions & 16 deletions packages/permissionless/utils/getAction.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/permissionless/utils/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -35,7 +34,6 @@ import { getPackedUserOperation } from "./getPackedUserOperation"
export {
transactionReceiptStatus,
deepHexlify,
getAction,
getUserOperationHash,
getRequiredPrefund,
walletClientToSmartAccountSigner,
Expand Down
2 changes: 1 addition & 1 deletion packages/wagmi-test-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/wagmi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
},
"peerDependencies": {
"wagmi": "^2.5.1",
"viem": "^2.0.0"
"viem": "2.9.17"
}
}

0 comments on commit 277dcac

Please sign in to comment.