Skip to content

Commit

Permalink
thirdweb_getUserOperationGasPrice (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xFirekeeper authored Apr 1, 2024
1 parent ff672fe commit 380eaf0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public static async Task<EthEstimateUserOperationGasResponse> EthEstimateUserOpe
return JsonConvert.DeserializeObject<EthEstimateUserOperationGasResponse>(response.Result.ToString());
}

public static async Task<ThirdwebGetUserOperationGasPriceResponse> ThirdwebGetUserOperationGasPrice(string bundlerUrl, string apiKey, object requestId)
{
var response = await BundlerRequest(bundlerUrl, apiKey, requestId, "thirdweb_getUserOperationGasPrice");
return JsonConvert.DeserializeObject<ThirdwebGetUserOperationGasPriceResponse>(response.Result.ToString());
}

// Paymaster requests

public static async Task<PMSponsorOperationResponse> PMSponsorUserOperation(string paymasterUrl, string apiKey, object requestId, UserOperationHexified userOp, string entryPoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,20 @@ internal async Task<RpcResponseMessage> Request(RpcRequestMessage requestMessage

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

var gasPrices = await Utils.GetGasPriceAsync(ThirdwebManager.Instance.SDK.Session.ChainId);
BigInteger maxFee;
BigInteger maxPriorityFee;
if (new Uri(Config.bundlerUrl).Host.EndsWith(".thirdweb.com"))
{
var fees = await BundlerClient.ThirdwebGetUserOperationGasPrice(Config.bundlerUrl, apiKey, requestId);
maxFee = new HexBigInteger(fees.maxFeePerGas).Value;
maxPriorityFee = new HexBigInteger(fees.maxPriorityFeePerGas).Value;
}
else
{
var fees = await Utils.GetGasPriceAsync(ThirdwebManager.Instance.SDK.Session.ChainId);
maxFee = fees.MaxFeePerGas;
maxPriorityFee = fees.MaxPriorityFeePerGas;
}

var partialUserOp = new EntryPointContract.UserOperation()
{
Expand All @@ -222,8 +235,8 @@ internal async Task<RpcResponseMessage> Request(RpcRequestMessage requestMessage
CallGasLimit = 0,
VerificationGasLimit = 0,
PreVerificationGas = 0,
MaxFeePerGas = gasPrices.MaxFeePerGas,
MaxPriorityFeePerGas = gasPrices.MaxPriorityFeePerGas,
MaxFeePerGas = maxFee,
MaxPriorityFeePerGas = maxPriorityFee,
PaymasterAndData = new byte[] { },
Signature = Constants.DUMMY_SIG.HexStringToByteArray(),
};
Expand Down
6 changes: 6 additions & 0 deletions Assets/Thirdweb/Core/Scripts/AccountAbstraction/Core/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ public class PMSponsorOperationResponse
{
public string paymasterAndData { get; set; }
}

public class ThirdwebGetUserOperationGasPriceResponse
{
public string maxFeePerGas { get; set; }
public string maxPriorityFeePerGas { get; set; }
}
}

0 comments on commit 380eaf0

Please sign in to comment.