Skip to content

Commit

Permalink
make undefined check (#310)
Browse files Browse the repository at this point in the history
* make undefined check

* add changeset

* Update wild-files-whisper.md

* fix failing tests

* fix failing test

* fix failing tests

* fix failing tests

---------

Co-authored-by: mouseless <[email protected]>
Co-authored-by: Garvit Khatri <[email protected]>
  • Loading branch information
3 people authored Oct 25, 2024
1 parent 9bc3b34 commit 6a7b673
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-files-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"permissionless": patch
---

Fixed when slot overrides returned from pimlico_getTokenQuotes are zero
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,15 @@ const handleMethod = async (
[getAddress("0xffffffffffffffffffffffffffffffffffffffff")]: {
exchangeRateNativeToUsd: "0x1a2b3c4d5e6f7890abcdef",
exchangeRate: "0x3a7b9c8d6e5f4321",
balanceSlot: "0x0",
allowanceSlot: "0x1",
postOpGas: "0x1a2b3c"
},
[ERC20_ADDRESS]: {
exchangeRateNativeToUsd: "0x5cc717fbb3450c0000000",
exchangeRate: "0x5cc717fbb3450c0000",
balanceSlot: "0x5",
allowanceSlot: "0x0",
postOpGas: "0xc350"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ describe.each(getCoreSmartAccounts())(
)

testWithRpc.skipIf(!supportsEntryPointV07)(
"prepareUserOperationForErc20Paymaster_v07",
"prepareUserOperationForErc20Paymaster_v07 (balanceOverride enabled)",
async ({ rpc }) => {
const { anvilRpc } = rpc

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ export const prepareUserOperationForErc20Paymaster =
const allowanceSlot = _allowanceSlot ?? quotes[0].allowanceSlot
const balanceSlot = _balanceSlot ?? quotes[0].balanceSlot

const hasSlot = allowanceSlot && balanceSlot
const hasSlot =
allowanceSlot !== undefined && balanceSlot !== undefined

if (!hasSlot && balanceOverride) {
throw new Error(
Expand Down
12 changes: 6 additions & 6 deletions packages/permissionless/utils/erc20AllowanceOverride.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
describe("erc20AllowanceOverride", () => {
test("should return the correct structure for valid inputs", () => {
const params = {
token: "0xTokenAddress",
owner: "0xOwnerAddress",
spender: "0xSpenderAddress",
token: "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF",
owner: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
spender: "0xDDdDddDdDdddDDddDDddDDDDdDdDDdDDdDDDDDDd",
slot: BigInt(1),
amount: BigInt(100)
} as const
Expand All @@ -32,9 +32,9 @@ describe("erc20AllowanceOverride", () => {

test("should use the default amount when none is provided", () => {
const params: Erc20AllowanceOverrideParameters = {
token: "0xTokenAddress",
owner: "0xOwnerAddress",
spender: "0xSpenderAddress",
token: "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF",
owner: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
spender: "0xDDdDddDdDdddDDddDDddDDDDdDdDDdDDdDDDDDDd",
slot: BigInt(1)
}

Expand Down
8 changes: 4 additions & 4 deletions packages/permissionless/utils/erc20BalanceOverride.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
describe("erc20BalanceOverride", () => {
test("should return the correct structure for valid inputs", () => {
const params = {
token: "0xTokenAddress",
owner: "0xOwnerAddress",
token: "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF",
owner: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
slot: BigInt(1),
balance: BigInt(1000)
} as const
Expand All @@ -31,8 +31,8 @@ describe("erc20BalanceOverride", () => {

test("should use the default balance when none is provided", () => {
const params: Erc20BalanceOverrideParameters = {
token: "0xTokenAddress",
owner: "0xOwnerAddress",
token: "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF",
owner: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
slot: BigInt(1)
}

Expand Down

0 comments on commit 6a7b673

Please sign in to comment.