use super::types::{
BundlerStateOverride, GasEstimation, UserOperation, UserOperationByHash, UserOperationReceipt,
};
use crate::client::Client;
use crate::error::Result;
pub struct BundlerApi<'a> {
client: &'a Client,
}
impl<'a> BundlerApi<'a> {
pub(crate) fn new(client: &'a Client) -> Self {
Self { client }
}
pub async fn supported_entry_points(&self) -> Result<Vec<String>> {
self.client.rpc("eth_supportedEntryPoints", ()).await
}
pub async fn send_user_operation(
&self,
user_op: &UserOperation,
entry_point: &str,
) -> Result<String> {
self.client
.rpc("eth_sendUserOperation", (user_op, entry_point))
.await
}
pub async fn estimate_user_operation_gas(
&self,
user_op: &UserOperation,
entry_point: &str,
) -> Result<GasEstimation> {
self.client
.rpc("eth_estimateUserOperationGas", (user_op, entry_point))
.await
}
pub async fn estimate_user_operation_gas_with_overrides(
&self,
user_op: &UserOperation,
entry_point: &str,
state_overrides: &std::collections::HashMap<String, BundlerStateOverride>,
) -> Result<GasEstimation> {
self.client
.rpc(
"eth_estimateUserOperationGas",
(user_op, entry_point, state_overrides),
)
.await
}
pub async fn get_user_operation_by_hash(
&self,
user_op_hash: &str,
) -> Result<Option<UserOperationByHash>> {
self.client
.rpc("eth_getUserOperationByHash", vec![user_op_hash])
.await
}
pub async fn get_user_operation_receipt(
&self,
user_op_hash: &str,
) -> Result<Option<UserOperationReceipt>> {
self.client
.rpc("eth_getUserOperationReceipt", vec![user_op_hash])
.await
}
pub async fn max_priority_fee_per_gas(&self) -> Result<String> {
self.client.rpc("rundler_maxPriorityFeePerGas", ()).await
}
}