Skip to content

Commit

Permalink
fix: alchemy gas manager 0x check for user op overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
denniswon committed Nov 29, 2023
1 parent 1647615 commit 4f5d49f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 23 deletions.
10 changes: 3 additions & 7 deletions packages/alchemy/e2e-tests/simple-account.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import type {
PublicErc4337Client,
UserOperationOverrides,
} from "@alchemy/aa-core";
import type { UserOperationOverrides } from "@alchemy/aa-core";
import {
LogLevel,
Logger,
Expand All @@ -20,7 +17,6 @@ import {
} from "viem";
import { mnemonicToAccount } from "viem/accounts";
import { sepolia } from "viem/chains";
import type { SimulateUserOperationAssetChangesResponse } from "../src/middleware/types/index.js";
import { AlchemyProvider } from "../src/provider.js";
import { API_KEY, OWNER_MNEMONIC, PAYMASTER_POLICY_ID } from "./constants.js";

Expand Down Expand Up @@ -254,7 +250,7 @@ describe("Simple Account Tests", () => {
chain,
});

const simulatedAssetChanges: SimulateUserOperationAssetChangesResponse =
const simulatedAssetChanges =
await provider.simulateUserOperationAssetChanges({
target: provider.getEntryPointAddress(),
data: "0x",
Expand Down Expand Up @@ -326,7 +322,7 @@ const givenConnectedProvider = ({
},
},
}).connect(
(provider: PublicErc4337Client) =>
(provider) =>
new SimpleSmartContractAccount({
chain,
owner,
Expand Down
6 changes: 3 additions & 3 deletions packages/alchemy/src/middleware/gas-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const withAlchemyGasManager = <P extends AlchemyProvider>(
.withGasEstimator(async (struct, overrides, feeOptions) => {
// but if user is bypassing paymaster to fallback to having the account to pay the gas (one-off override),
// we cannot delegate gas estimation to the bundler because paymaster middleware will not be called
if (overrides?.paymasterAndData != null) {
if (overrides?.paymasterAndData === "0x") {
const result = await fallbackGasEstimator(
struct,
overrides,
Expand All @@ -80,7 +80,7 @@ export const withAlchemyGasManager = <P extends AlchemyProvider>(

// but if user is bypassing paymaster to fallback to having the account to pay the gas (one-off override),
// we cannot delegate gas estimation to the bundler because paymaster middleware will not be called
if (overrides?.paymasterAndData != null) {
if (overrides?.paymasterAndData === "0x") {
const result = await fallbackFeeDataGetter(
struct,
overrides,
Expand Down Expand Up @@ -160,7 +160,7 @@ const withAlchemyPaymasterAndDataMiddleware = <P extends AlchemyProvider>(
const withAlchemyGasAndPaymasterAndDataMiddleware = <P extends AlchemyProvider>(
provider: P,
config: AlchemyGasManagerConfig
): Parameters<AlchemyProvider["withPaymasterMiddleware"]>["0"] => ({
): Parameters<P["withPaymasterMiddleware"]>["0"] => ({
paymasterDataMiddleware: async (struct, overrides, feeOptions) => {
const userOperation: UserOperationRequest = deepHexlify(
await resolveProperties(struct)
Expand Down
11 changes: 3 additions & 8 deletions packages/core/src/provider/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,6 @@ export class SmartAccountProvider<
signature: uoToDrop.signature,
} as UserOperationStruct;

Logger.debug(
"[SmartAccountProvider] dropAndReplaceUserOperation uoToSubmit",
uoToSubmit
);

// Run once to get the fee estimates
// This can happen at any part of the middleware stack, so we want to run it all
const { maxFeePerGas, maxPriorityFeePerGas } =
Expand Down Expand Up @@ -530,9 +525,9 @@ export class SmartAccountProvider<
overrides ?? {};

if (
callGasLimit === undefined ||
verificationGasLimit === undefined ||
preVerificationGas === undefined
callGasLimit == null ||
verificationGasLimit == null ||
preVerificationGas == null
) {
const request = deepHexlify(await resolveProperties(struct));
const estimates = await this.rpcClient.estimateUserOperationGas(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/provider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export interface ISmartAccountProvider<
* Overrides the feeDataGetter middleware which is used for setting the fee fields on the UserOperation
* prior to execution.
*
* @param override - a function for overriding the default feeDataGetter middleware
* @param override - a function for overriding the default feeDataGetter middleware
* @param feeOptions - optional FeeDataFeeOptions to set at the global level of the provider.
* @returns
*/
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/utils/bigint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import type { BigNumberish } from "../types";
* @param args a list of bigints to get the max of
* @returns the max bigint in the list
*/
export const bigIntMax = (...args: bigint[]) => {
export const bigIntMax = (...args: bigint[]): bigint => {
if (!args.length) {
return undefined;
throw new Error("bigIntMax requires at least one argument");
}

return args.reduce((m, c) => (m > c ? m : c));
Expand All @@ -20,9 +20,9 @@ export const bigIntMax = (...args: bigint[]) => {
* @param args a list of bigints to get the max of
* @returns the min bigint in the list
*/
export const bigIntMin = (...args: bigint[]) => {
export const bigIntMin = (...args: bigint[]): bigint => {
if (!args.length) {
return undefined;
throw new Error("bigIntMin requires at least one argument");
}

return args.reduce((m, c) => (m < c ? m : c));
Expand Down

0 comments on commit 4f5d49f

Please sign in to comment.