Skip to content

Commit 00be583

Browse files
chore(v4): get gas price from bundler for userOps (#2622)
1 parent 8c9def7 commit 00be583

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

.changeset/grumpy-doors-grow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/wallets": patch
3+
---
4+
5+
Get gas price from bundler for userOperations

legacy_packages/wallets/src/evm/connectors/smart-wallet/lib/base-api.ts

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import { Transaction, getDynamicFeeData } from "@thirdweb-dev/sdk";
1616
import { HttpRpcClient } from "./http-rpc-client";
1717
import type { BaseApiParams, PaymasterAPI, UserOpOptions } from "../types";
18+
import { isTwUrl } from "../../../utils/url";
1819

1920
const DUMMY_SIGNATURE =
2021
"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
@@ -191,24 +192,34 @@ export abstract class BaseAccountAPI {
191192
tx.encode(),
192193
);
193194
let { maxFeePerGas, maxPriorityFeePerGas } = info;
194-
if (!maxFeePerGas || !maxPriorityFeePerGas) {
195-
const feeData = await getDynamicFeeData(
196-
this.provider as providers.JsonRpcProvider,
195+
// get fees from bundler if available
196+
if (isTwUrl(httpRpcClient.bundlerUrl)) {
197+
const bundlerFeeData = await httpRpcClient.getUserOperationGasPrice();
198+
maxFeePerGas = BigNumber.from(bundlerFeeData.maxFeePerGas);
199+
maxPriorityFeePerGas = BigNumber.from(
200+
bundlerFeeData.maxPriorityFeePerGas,
197201
);
198-
if (!maxPriorityFeePerGas) {
199-
maxPriorityFeePerGas = feeData.maxPriorityFeePerGas ?? undefined;
200-
}
201-
if (!maxFeePerGas) {
202-
maxFeePerGas = feeData.maxFeePerGas ?? undefined;
203-
const network = await this.provider.getNetwork();
204-
const chainId = network.chainId;
202+
} else {
203+
// if bundler is not available, try to get fees from the network if not passed explicitly
204+
if (!maxFeePerGas || !maxPriorityFeePerGas) {
205+
const feeData = await getDynamicFeeData(
206+
this.provider as providers.JsonRpcProvider,
207+
);
208+
if (!maxPriorityFeePerGas) {
209+
maxPriorityFeePerGas = feeData.maxPriorityFeePerGas ?? undefined;
210+
}
211+
if (!maxFeePerGas) {
212+
maxFeePerGas = feeData.maxFeePerGas ?? undefined;
213+
const network = await this.provider.getNetwork();
214+
const chainId = network.chainId;
205215

206-
if (
207-
chainId === Celo.chainId ||
208-
chainId === CeloAlfajoresTestnet.chainId ||
209-
chainId === CeloBaklavaTestnet.chainId
210-
) {
211-
maxPriorityFeePerGas = maxFeePerGas;
216+
if (
217+
chainId === Celo.chainId ||
218+
chainId === CeloAlfajoresTestnet.chainId ||
219+
chainId === CeloBaklavaTestnet.chainId
220+
) {
221+
maxPriorityFeePerGas = maxFeePerGas;
222+
}
212223
}
213224
}
214225
}

legacy_packages/wallets/src/evm/connectors/smart-wallet/lib/http-rpc-client.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ export class HttpRpcClient {
134134
);
135135
}
136136

137+
async getUserOperationGasPrice(): Promise<{
138+
maxFeePerGas: string;
139+
maxPriorityFeePerGas: string;
140+
}> {
141+
await this.initializing;
142+
return await this.userOpJsonRpcProvider.send(
143+
"thirdweb_getUserOperationGasPrice",
144+
[],
145+
);
146+
}
147+
137148
async getUserOperationReceipt(userOpHash: string): Promise<any> {
138149
await this.initializing;
139150
return await this.userOpJsonRpcProvider.send(

0 commit comments

Comments
 (0)