Skip to content

Commit

Permalink
Merge pull request #30 from propeller-heads/lp/ENG-3764-VMPoolState-d…
Browse files Browse the repository at this point in the history
…ecoder

feat(vm_pool): Create tycho decoder
  • Loading branch information
louise-poole authored Nov 6, 2024
2 parents d17c530 + 72f4028 commit a18bbfe
Show file tree
Hide file tree
Showing 9 changed files with 394 additions and 145 deletions.
12 changes: 10 additions & 2 deletions src/protocol/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Protocol generic errors
use thiserror::Error;

use super::models::GetAmountOutResult;
use super::{models::GetAmountOutResult, vm::errors::TychoSimulationError};

/// Enumeration of possible errors that can occur during a trade simulation.
#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -42,10 +42,18 @@ pub enum TransitionError<T> {
InvalidEventType(),
}

#[derive(Debug, PartialEq, Error)]
#[derive(Debug, Error)]
pub enum InvalidSnapshotError {
#[error("Missing attributes {0}")]
MissingAttribute(String),
#[error("Value error {0}")]
ValueError(String),
#[error("Unable to set up vm state on the engine: {0}")]
VMError(TychoSimulationError),
}

impl From<TychoSimulationError> for InvalidSnapshotError {
fn from(error: TychoSimulationError) -> Self {
InvalidSnapshotError::VMError(error)
}
}
11 changes: 4 additions & 7 deletions src/protocol/uniswap_v2/tycho_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ mod tests {
.unwrap()
.naive_utc(); //Sample timestamp

let mut static_attributes: HashMap<String, Bytes> = HashMap::new();
static_attributes.insert("attr1".to_string(), "0x000012".into());
static_attributes.insert("attr2".to_string(), "0x000005".into());

ProtocolComponent {
id: "State1".to_string(),
protocol_system: "system1".to_string(),
Expand Down Expand Up @@ -110,9 +106,10 @@ mod tests {
let result = UniswapV2State::try_from(snapshot);

assert!(result.is_err());
assert_eq!(

assert!(matches!(
result.err().unwrap(),
InvalidSnapshotError::MissingAttribute("reserve1".to_string())
);
InvalidSnapshotError::MissingAttribute(attr) if attr == *"reserve1"
));
}
}
12 changes: 6 additions & 6 deletions src/protocol/uniswap_v3/tycho_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ mod tests {
let result = UniswapV3State::try_from(snapshot);

assert!(result.is_err());
assert_eq!(
assert!(matches!(
result.err().unwrap(),
InvalidSnapshotError::MissingAttribute(missing_attribute)
);
InvalidSnapshotError::MissingAttribute(attr) if attr == missing_attribute
));
}

#[test]
Expand All @@ -295,10 +295,10 @@ mod tests {
let result = UniswapV3State::try_from(snapshot);

assert!(result.is_err());
assert_eq!(
assert!(matches!(
result.err().unwrap(),
InvalidSnapshotError::ValueError("Unsupported fee amount".to_string())
);
InvalidSnapshotError::ValueError(err) if err == *"Unsupported fee amount"
));
}

#[test]
Expand Down
5 changes: 3 additions & 2 deletions src/protocol/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ mod adapter_contract;
mod constants;
mod engine;
mod erc20_overwrite_factory;
mod errors;
pub mod errors;
mod models;
mod state;
pub mod state;
pub mod tycho_decoder;
mod tycho_simulation_contract;
pub mod utils;
Loading

0 comments on commit a18bbfe

Please sign in to comment.