diff --git a/CHANGELOG.md b/CHANGELOG.md index 98553bb..23e9154 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [0.32.0](https://github.com/propeller-heads/tycho-execution/compare/0.31.0...0.32.0) (2025-02-06) + + +### Features + +* Accept any struct that implements Into in Swap ([cb14022](https://github.com/propeller-heads/tycho-execution/commit/cb140226814add4f8141f3ad36784379a80d656c)) + ## [0.31.0](https://github.com/propeller-heads/tycho-execution/compare/0.30.1...0.31.0) (2025-02-05) diff --git a/Cargo.lock b/Cargo.lock index c4b3b90..510642d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4231,7 +4231,7 @@ dependencies = [ [[package]] name = "tycho-execution" -version = "0.31.0" +version = "0.32.0" dependencies = [ "alloy", "alloy-primitives", diff --git a/Cargo.toml b/Cargo.toml index c97d285..9b5ab1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tycho-execution" -version = "0.31.0" +version = "0.32.0" edition = "2021" [dependencies] diff --git a/src/encoding/models.rs b/src/encoding/models.rs index 77e115a..d0f8e9d 100644 --- a/src/encoding/models.rs +++ b/src/encoding/models.rs @@ -59,6 +59,17 @@ pub struct Swap { pub split: f64, } +impl Swap { + pub fn new>( + component: T, + token_in: Bytes, + token_out: Bytes, + split: f64, + ) -> Self { + Self { component: component.into(), token_in, token_out, split } + } +} + #[derive(Clone, Debug)] pub struct Transaction { // Address of the contract to call with the calldata @@ -131,3 +142,42 @@ impl Chain { } } } + +mod tests { + use super::*; + + struct MockProtocolComponent { + id: String, + protocol_system: String, + } + + impl From for ProtocolComponent { + fn from(component: MockProtocolComponent) -> Self { + ProtocolComponent { + id: component.id, + protocol_system: component.protocol_system, + tokens: vec![], + protocol_type_name: "".to_string(), + chain: Default::default(), + contract_ids: vec![], + static_attributes: Default::default(), + change: Default::default(), + creation_tx: Default::default(), + created_at: Default::default(), + } + } + } + + #[test] + fn test_swap_new() { + let component = MockProtocolComponent { + id: "i-am-an-id".to_string(), + protocol_system: "uniswap_v2".to_string(), + }; + let swap = Swap::new(component, Bytes::from("0x12"), Bytes::from("34"), 0.5); + assert_eq!(swap.token_in, Bytes::from("0x12")); + assert_eq!(swap.token_out, Bytes::from("0x34")); + assert_eq!(swap.component.protocol_system, "uniswap_v2"); + assert_eq!(swap.component.id, "i-am-an-id"); + } +}