Skip to content

Commit 380eaf0

Browse files
authored
thirdweb_getUserOperationGasPrice (#166)
1 parent ff672fe commit 380eaf0

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

Assets/Thirdweb/Core/Scripts/AccountAbstraction/Core/BundlerClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public static async Task<EthEstimateUserOperationGasResponse> EthEstimateUserOpe
3434
return JsonConvert.DeserializeObject<EthEstimateUserOperationGasResponse>(response.Result.ToString());
3535
}
3636

37+
public static async Task<ThirdwebGetUserOperationGasPriceResponse> ThirdwebGetUserOperationGasPrice(string bundlerUrl, string apiKey, object requestId)
38+
{
39+
var response = await BundlerRequest(bundlerUrl, apiKey, requestId, "thirdweb_getUserOperationGasPrice");
40+
return JsonConvert.DeserializeObject<ThirdwebGetUserOperationGasPriceResponse>(response.Result.ToString());
41+
}
42+
3743
// Paymaster requests
3844

3945
public static async Task<PMSponsorOperationResponse> PMSponsorUserOperation(string paymasterUrl, string apiKey, object requestId, UserOperationHexified userOp, string entryPoint)

Assets/Thirdweb/Core/Scripts/AccountAbstraction/Core/SmartWallet.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,20 @@ internal async Task<RpcResponseMessage> Request(RpcRequestMessage requestMessage
211211

212212
var (initCode, gas) = await GetInitCode();
213213

214-
var gasPrices = await Utils.GetGasPriceAsync(ThirdwebManager.Instance.SDK.Session.ChainId);
214+
BigInteger maxFee;
215+
BigInteger maxPriorityFee;
216+
if (new Uri(Config.bundlerUrl).Host.EndsWith(".thirdweb.com"))
217+
{
218+
var fees = await BundlerClient.ThirdwebGetUserOperationGasPrice(Config.bundlerUrl, apiKey, requestId);
219+
maxFee = new HexBigInteger(fees.maxFeePerGas).Value;
220+
maxPriorityFee = new HexBigInteger(fees.maxPriorityFeePerGas).Value;
221+
}
222+
else
223+
{
224+
var fees = await Utils.GetGasPriceAsync(ThirdwebManager.Instance.SDK.Session.ChainId);
225+
maxFee = fees.MaxFeePerGas;
226+
maxPriorityFee = fees.MaxPriorityFeePerGas;
227+
}
215228

216229
var partialUserOp = new EntryPointContract.UserOperation()
217230
{
@@ -222,8 +235,8 @@ internal async Task<RpcResponseMessage> Request(RpcRequestMessage requestMessage
222235
CallGasLimit = 0,
223236
VerificationGasLimit = 0,
224237
PreVerificationGas = 0,
225-
MaxFeePerGas = gasPrices.MaxFeePerGas,
226-
MaxPriorityFeePerGas = gasPrices.MaxPriorityFeePerGas,
238+
MaxFeePerGas = maxFee,
239+
MaxPriorityFeePerGas = maxPriorityFee,
227240
PaymasterAndData = new byte[] { },
228241
Signature = Constants.DUMMY_SIG.HexStringToByteArray(),
229242
};

Assets/Thirdweb/Core/Scripts/AccountAbstraction/Core/Types.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@ public class PMSponsorOperationResponse
3131
{
3232
public string paymasterAndData { get; set; }
3333
}
34+
35+
public class ThirdwebGetUserOperationGasPriceResponse
36+
{
37+
public string maxFeePerGas { get; set; }
38+
public string maxPriorityFeePerGas { get; set; }
39+
}
3440
}

0 commit comments

Comments
 (0)