From cb140226814add4f8141f3ad36784379a80d656c Mon Sep 17 00:00:00 2001 From: Diana Carvalho Date: Wed, 5 Feb 2025 18:02:43 +0000 Subject: [PATCH 1/2] feat: Accept any struct that implements Into in Swap --- don't change below this line --- ENG-4213 Took 27 minutes --- src/encoding/models.rs | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/encoding/models.rs b/src/encoding/models.rs index 24c7c9d..3b42e14 100644 --- a/src/encoding/models.rs +++ b/src/encoding/models.rs @@ -53,6 +53,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 @@ -68,3 +79,42 @@ pub struct EncodingContext { pub exact_out: bool, pub router_address: Bytes, } + +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"); + } +} From 6ed23db4490e08334ea87cae5a344ce1c43bb269 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 6 Feb 2025 09:21:59 +0000 Subject: [PATCH 2/2] chore(release): 0.32.0 [skip ci] ## [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)) --- CHANGELOG.md | 7 +++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) 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 21b6199..9741512 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 8a363ac..6aaf1d3 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]