feat: Fetch proper block header for simulation
- Similarly to the way it was done in the python package.
This commit is contained in:
@@ -4,6 +4,7 @@ use alloy::{
|
|||||||
eips::eip1898::BlockId,
|
eips::eip1898::BlockId,
|
||||||
primitives::{address, Address, U256},
|
primitives::{address, Address, U256},
|
||||||
providers::{Provider, ProviderBuilder},
|
providers::{Provider, ProviderBuilder},
|
||||||
|
rpc::types::Block,
|
||||||
transports::http::reqwest::Url,
|
transports::http::reqwest::Url,
|
||||||
};
|
};
|
||||||
use miette::{IntoDiagnostic, WrapErr};
|
use miette::{IntoDiagnostic, WrapErr};
|
||||||
|
|||||||
@@ -365,8 +365,9 @@ fn validate_state(
|
|||||||
|
|
||||||
let state = protocol_states_by_id
|
let state = protocol_states_by_id
|
||||||
.get(component_id)
|
.get(component_id)
|
||||||
.wrap_err("Failed to get state for component"
|
.wrap_err(format!(
|
||||||
)?
|
"Component {id} does not exist in protocol_states_by_id {protocol_states_by_id:?}"
|
||||||
|
))?
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
let component_with_state = ComponentWithState {
|
let component_with_state = ComponentWithState {
|
||||||
@@ -387,6 +388,15 @@ fn validate_state(
|
|||||||
|
|
||||||
let bytes = [0u8; 32];
|
let bytes = [0u8; 32];
|
||||||
|
|
||||||
|
// Get block header to extract the timestamp
|
||||||
|
let rpc_url = env::var("RPC_URL")
|
||||||
|
.into_diagnostic()
|
||||||
|
.wrap_err("Missing RPC_URL in environment")?;
|
||||||
|
let rpc_provider = RPCProvider::new(rpc_url);
|
||||||
|
let block_header = rt
|
||||||
|
.block_on(rpc_provider.get_block_header(stop_block))
|
||||||
|
.wrap_err("Failed to get block header")?;
|
||||||
|
|
||||||
let state_msgs: HashMap<String, StateSyncMessage<BlockHeader>> = HashMap::from([(
|
let state_msgs: HashMap<String, StateSyncMessage<BlockHeader>> = HashMap::from([(
|
||||||
String::from("test_protocol"),
|
String::from("test_protocol"),
|
||||||
StateSyncMessage {
|
StateSyncMessage {
|
||||||
@@ -395,7 +405,7 @@ fn validate_state(
|
|||||||
number: stop_block,
|
number: stop_block,
|
||||||
parent_hash: Bytes::from(bytes),
|
parent_hash: Bytes::from(bytes),
|
||||||
revert: false,
|
revert: false,
|
||||||
timestamp: 0, // TODO
|
timestamp: block_header.header.timestamp,
|
||||||
},
|
},
|
||||||
snapshots: snapshot,
|
snapshots: snapshot,
|
||||||
deltas: None,
|
deltas: None,
|
||||||
@@ -481,9 +491,9 @@ fn validate_state(
|
|||||||
})
|
})
|
||||||
.into_diagnostic()
|
.into_diagnostic()
|
||||||
.wrap_err(format!(
|
.wrap_err(format!(
|
||||||
"Error calculating amount out for Pool {:?} at {:.1}%.",
|
"Error calculating amount out for Pool {id:?} at {:.1}% with input of {amount_in} {}.",
|
||||||
id,
|
|
||||||
percentage * 100.0,
|
percentage * 100.0,
|
||||||
|
&tokens[0].symbol,
|
||||||
))?;
|
))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user