@@ -4,9 +4,13 @@ import { isContractDeployed } from "../../../utils/bytecode/is-contract-deployed
4
4
import type { ThirdwebContract } from "../../../contract/contract.js" ;
5
5
import { encode } from "../../../transaction/actions/encode.js" ;
6
6
import { getDefaultGasOverrides } from "../../../gas/fee-data.js" ;
7
- import { DUMMY_SIGNATURE , ENTRYPOINT_ADDRESS } from "./constants.js" ;
7
+ import {
8
+ DUMMY_SIGNATURE ,
9
+ ENTRYPOINT_ADDRESS ,
10
+ getDefaultBundlerUrl ,
11
+ } from "./constants.js" ;
8
12
import { getPaymasterAndData } from "./paymaster.js" ;
9
- import { estimateUserOpGas } from "./bundler.js" ;
13
+ import { estimateUserOpGas , getUserOpGasPrice } from "./bundler.js" ;
10
14
import { randomNonce } from "./utils.js" ;
11
15
import { prepareCreateAccount } from "./calls.js" ;
12
16
import type { Account } from "../../interfaces/wallet.js" ;
@@ -17,6 +21,7 @@ import { hexToBytes } from "../../../utils/encoding/to-bytes.js";
17
21
import type { Hex } from "../../../utils/encoding/hex.js" ;
18
22
import { encodeAbiParameters } from "../../../utils/abi/encodeAbiParameters.js" ;
19
23
import type { ThirdwebClient } from "../../../client/client.js" ;
24
+ import { isThirdwebUrl } from "../../../utils/fetch.js" ;
20
25
21
26
/**
22
27
* Create an unsigned user operation
@@ -44,17 +49,30 @@ export async function createUnsignedUserOp(args: {
44
49
options,
45
50
} ) ;
46
51
const callData = await encode ( executeTx ) ;
52
+
47
53
let { maxFeePerGas, maxPriorityFeePerGas } = executeTx ;
48
- if ( ! maxFeePerGas || ! maxPriorityFeePerGas ) {
49
- const feeData = await getDefaultGasOverrides (
50
- factoryContract . client ,
51
- factoryContract . chain ,
52
- ) ;
53
- if ( ! maxPriorityFeePerGas ) {
54
- maxPriorityFeePerGas = feeData . maxPriorityFeePerGas ?? undefined ;
55
- }
56
- if ( ! maxFeePerGas ) {
57
- maxFeePerGas = feeData . maxFeePerGas ?? undefined ;
54
+ const bundlerUrl =
55
+ options . overrides ?. bundlerUrl ?? getDefaultBundlerUrl ( options . chain ) ;
56
+ if ( isThirdwebUrl ( bundlerUrl ) ) {
57
+ // get gas prices from bundler
58
+ const bundlerGasPrice = await getUserOpGasPrice ( {
59
+ options,
60
+ } ) ;
61
+ maxFeePerGas = bundlerGasPrice . maxFeePerGas ;
62
+ maxPriorityFeePerGas = bundlerGasPrice . maxPriorityFeePerGas ;
63
+ } else {
64
+ // otherwise fallback to RPC gas prices if not passed in explicitely
65
+ if ( ! maxFeePerGas || ! maxPriorityFeePerGas ) {
66
+ const feeData = await getDefaultGasOverrides (
67
+ factoryContract . client ,
68
+ factoryContract . chain ,
69
+ ) ;
70
+ if ( ! maxPriorityFeePerGas ) {
71
+ maxPriorityFeePerGas = feeData . maxPriorityFeePerGas ?? undefined ;
72
+ }
73
+ if ( ! maxFeePerGas ) {
74
+ maxFeePerGas = feeData . maxFeePerGas ?? undefined ;
75
+ }
58
76
}
59
77
}
60
78
0 commit comments