Skip to content

Fix/mainnet-usdt #382

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 7 commits into from
Mar 20, 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/real-chefs-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"permissionless": patch
---

Added flow to handle USDT approval flow on mainnet in prepareUserOperationForErc20Paymaster
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
import { getTokenQuotes } from "../../../actions/pimlico.js"
import { erc20BalanceOverride } from "../../../utils/erc20BalanceOverride.js"

const MAINNET_USDT_ADDRESS = getAddress(
"0xdAC17F958D2ee523a2206206994597C13D831ec7"
)

export const prepareUserOperationForErc20Paymaster =
(
pimlicoClient: Client,
Expand Down Expand Up @@ -127,6 +131,7 @@
calls = await account.decodeCalls(parameters.callData)
}

// Create basic approval call array with max approval
const callsWithDummyApproval = [
{
abi: erc20Abi,
Expand All @@ -137,6 +142,16 @@
...(calls ? calls : [])
]

// For USDT on mainnet, add zero approval at the beginning
if (token === MAINNET_USDT_ADDRESS) {
callsWithDummyApproval.unshift({
abi: erc20Abi,
functionName: "approve",
args: [paymasterERC20Address, 0n],
to: MAINNET_USDT_ADDRESS
})
}

Check warning on line 153 in packages/permissionless/experimental/pimlico/utils/prepareUserOperationForErc20Paymaster.ts

View check run for this annotation

Codecov / codecov/patch

packages/permissionless/experimental/pimlico/utils/prepareUserOperationForErc20Paymaster.ts#L147-L153

Added lines #L147 - L153 were not covered by tests

////////////////////////////////////////////////////////////////////////////////
// Call prepareUserOperation
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -243,17 +258,26 @@

const hasSufficientApproval = allowance >= maxCostInToken

const finalCalls = hasSufficientApproval
? (calls ?? [])
: [
{
abi: erc20Abi,
functionName: "approve",
args: [paymasterERC20Address, maxCostInToken],
to: paymasterContext.token
},
...(calls ?? [])
]
const finalCalls: unknown[] = calls ? [...calls] : []

if (!hasSufficientApproval) {
finalCalls.unshift({
abi: erc20Abi,
functionName: "approve",
args: [paymasterERC20Address, maxCostInToken],
to: paymasterContext.token
})
}

// For USDT on mainnet, add zero approval at the beginning
if (token === MAINNET_USDT_ADDRESS) {
finalCalls.unshift({
abi: erc20Abi,
functionName: "approve",
args: [paymasterERC20Address, 0n],
to: MAINNET_USDT_ADDRESS
})
}

Check warning on line 280 in packages/permissionless/experimental/pimlico/utils/prepareUserOperationForErc20Paymaster.ts

View check run for this annotation

Codecov / codecov/patch

packages/permissionless/experimental/pimlico/utils/prepareUserOperationForErc20Paymaster.ts#L274-L280

Added lines #L274 - L280 were not covered by tests

userOperation.callData = await account.encodeCalls(
finalCalls.map((call_) => {
Expand Down
Loading