From 7dd59dbe3450ad15b4dc7eb4478b0422c18a6575 Mon Sep 17 00:00:00 2001 From: royvardhan Date: Thu, 20 Feb 2025 21:52:46 +0530 Subject: [PATCH] fix: add decode_hex to models --- src/encoding/evm/utils.rs | 7 ------- src/encoding/models.rs | 20 +++++++++++++------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/encoding/evm/utils.rs b/src/encoding/evm/utils.rs index 6a88964..a59abff 100644 --- a/src/encoding/evm/utils.rs +++ b/src/encoding/evm/utils.rs @@ -120,10 +120,3 @@ pub fn get_static_attribute(swap: &Swap, attribute_name: &str) -> Result })? .to_vec()) } - -/// Decodes a hex string to a `Bytes` object. -pub fn decode_hex(hex_str: &str, err_msg: &str) -> Result { - Ok(Bytes::from( - hex::decode(hex_str).map_err(|_| EncodingError::FatalError(err_msg.to_string()))?, - )) -} diff --git a/src/encoding/models.rs b/src/encoding/models.rs index 4e1eb23..957cd8f 100644 --- a/src/encoding/models.rs +++ b/src/encoding/models.rs @@ -1,3 +1,4 @@ +use hex; use num_bigint::BigUint; use serde::{Deserialize, Serialize}; use tycho_core::{ @@ -5,7 +6,6 @@ use tycho_core::{ Bytes, }; -use super::evm::utils::decode_hex; use crate::encoding::{ errors::EncodingError, serde_primitives::{biguint_string, biguint_string_option}, @@ -138,13 +138,19 @@ impl From for Chain { } impl Chain { + fn decode_hex(&self, hex_str: &str, err_msg: &str) -> Result { + Ok(Bytes::from( + hex::decode(hex_str).map_err(|_| EncodingError::FatalError(err_msg.to_string()))?, + )) + } + pub fn native_token(&self) -> Result { let decode_err_msg = "Failed to decode native token"; match self.id { 1 | 8453 | 42161 => { - decode_hex("0000000000000000000000000000000000000000", decode_err_msg) + self.decode_hex("0000000000000000000000000000000000000000", decode_err_msg) } - 324 => decode_hex("000000000000000000000000000000000000800A", decode_err_msg), + 324 => self.decode_hex("000000000000000000000000000000000000800A", decode_err_msg), _ => Err(EncodingError::InvalidInput(format!( "Native token not set for chain {:?}. Double check the chain is supported.", self.name @@ -155,10 +161,10 @@ impl Chain { pub fn wrapped_token(&self) -> Result { let decode_err_msg = "Failed to decode wrapped token"; match self.id { - 1 => decode_hex("C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", decode_err_msg), - 8453 => decode_hex("4200000000000000000000000000000000000006", decode_err_msg), - 324 => decode_hex("5AEa5775959fBC2557Cc8789bC1bf90A239D9a91", decode_err_msg), - 42161 => decode_hex("82aF49447D8a07e3bd95BD0d56f35241523fBab1", decode_err_msg), + 1 => self.decode_hex("C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", decode_err_msg), + 8453 => self.decode_hex("4200000000000000000000000000000000000006", decode_err_msg), + 324 => self.decode_hex("5AEa5775959fBC2557Cc8789bC1bf90A239D9a91", decode_err_msg), + 42161 => self.decode_hex("82aF49447D8a07e3bd95BD0d56f35241523fBab1", decode_err_msg), _ => Err(EncodingError::InvalidInput(format!( "Wrapped token not set for chain {:?}. Double check the chain is supported.", self.name