Skip to content

remove allowance override in prepareUserOperationForErc20 #380

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 2 commits into from
Mar 17, 2025
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
5 changes: 5 additions & 0 deletions .changeset/popular-mangos-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"permissionless": patch
---

Removed allowance override in prepareUserOperationForErc20Paymaster
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,17 @@ import { getChainId as getChainId_ } from "viem/actions"
import { readContract } from "viem/actions"
import { getAction, parseAccount } from "viem/utils"
import { getTokenQuotes } from "../../../actions/pimlico.js"
import { erc20AllowanceOverride } from "../../../utils/erc20AllowanceOverride.js"
import { erc20BalanceOverride } from "../../../utils/erc20BalanceOverride.js"

export const prepareUserOperationForErc20Paymaster =
(
pimlicoClient: Client,
{
balanceOverride = false,
balanceSlot: _balanceSlot,
allowanceSlot: _allowanceSlot
balanceSlot: _balanceSlot
}: {
balanceOverride?: boolean
balanceSlot?: bigint
allowanceSlot?: bigint
} = {}
) =>
async <
Expand Down Expand Up @@ -144,15 +141,10 @@ export const prepareUserOperationForErc20Paymaster =
// Call prepareUserOperation
////////////////////////////////////////////////////////////////////////////////

const allowanceSlot = _allowanceSlot ?? quotes[0].allowanceSlot
const balanceSlot = _balanceSlot ?? quotes[0].balanceSlot

const hasAllowanceSlot = allowanceSlot !== undefined
const hasBalanceSlot = balanceSlot !== undefined

const hasSlot = hasAllowanceSlot && hasBalanceSlot

if (!hasSlot && balanceOverride) {
if (!hasBalanceSlot && balanceOverride) {
throw new Error(
`balanceOverride is not supported for token ${token}, provide custom slot for balance & allowance overrides`
)
Expand All @@ -167,25 +159,12 @@ export const prepareUserOperationForErc20Paymaster =
})[0]
: undefined

const allowanceStateOverride =
balanceOverride && hasAllowanceSlot
? erc20AllowanceOverride({
token,
owner: account.address,
spender: paymasterERC20Address,
slot: allowanceSlot
})[0]
: undefined

parameters.stateOverride =
balanceOverride &&
balanceStateOverride &&
allowanceStateOverride // allowanceSlot && balanceSlot is cuz of TypeScript :/
balanceOverride && balanceStateOverride
? (parameters.stateOverride ?? []).concat([
{
address: token,
stateDiff: [
...(allowanceStateOverride.stateDiff ?? []),
...(balanceStateOverride.stateDiff ?? [])
]
}
Expand Down
Loading