use super::types::*;
use crate::client::Client;
use crate::error::Result;
pub struct SimulationApi<'a> {
client: &'a Client,
}
impl<'a> SimulationApi<'a> {
pub(crate) fn new(client: &'a Client) -> Self {
Self { client }
}
pub async fn simulate_asset_changes(
&self,
tx: &SimulationTransaction,
) -> Result<SimulateAssetChangesResponse> {
self.client
.rpc("alchemy_simulateAssetChanges", vec![tx])
.await
}
pub async fn simulate_asset_changes_bundle(
&self,
txs: &[SimulationTransaction],
) -> Result<Vec<SimulateAssetChangesResponse>> {
self.client
.rpc("alchemy_simulateAssetChangesBundle", vec![txs])
.await
}
pub async fn simulate_execution(
&self,
tx: &SimulationTransaction,
format: ExecutionFormat,
block_tag: &str,
) -> Result<SimulateExecutionResponse> {
let params = serde_json::json!({
"format": format,
"transaction": tx,
"blockTag": block_tag
});
self.client
.rpc("alchemy_simulateExecution", vec![params])
.await
}
pub async fn simulate_execution_nested(
&self,
tx: &SimulationTransaction,
) -> Result<SimulateExecutionResponse> {
self.simulate_execution(tx, ExecutionFormat::Nested, "latest")
.await
}
pub async fn simulate_execution_flat(
&self,
tx: &SimulationTransaction,
) -> Result<SimulateExecutionResponse> {
self.simulate_execution(tx, ExecutionFormat::Flat, "latest")
.await
}
pub async fn simulate_execution_bundle(
&self,
txs: &[SimulationTransaction],
) -> Result<Vec<SimulateExecutionResponse>> {
self.client
.rpc("alchemy_simulateExecutionBundle", vec![txs])
.await
}
}