@@ -15,6 +15,7 @@ import {
15
15
import { Transaction , getDynamicFeeData } from "@thirdweb-dev/sdk" ;
16
16
import { HttpRpcClient } from "./http-rpc-client" ;
17
17
import type { BaseApiParams , PaymasterAPI , UserOpOptions } from "../types" ;
18
+ import { isTwUrl } from "../../../utils/url" ;
18
19
19
20
const DUMMY_SIGNATURE =
20
21
"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c" ;
@@ -191,24 +192,34 @@ export abstract class BaseAccountAPI {
191
192
tx . encode ( ) ,
192
193
) ;
193
194
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 ,
197
201
) ;
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 ;
205
215
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
+ }
212
223
}
213
224
}
214
225
}
0 commit comments