# Utils Utility functions for blockchain operations, value conversion, and data handling. ## Conversion Functions ### to_wei ```rust fn to_wei(amount: &str, decimals: U256) -> Result ``` Converts a decimal amount to wei based on token decimals. ```rust let wei = to_wei("1.5", U256::from(18))?; // "1500000000000000000" ``` ### wei_to_eth ```rust fn wei_to_eth(wei: U256) -> f32 ``` Converts wei amount to ETH with decimal precision. ```rust let eth = wei_to_eth(U256::from(1500000000000000000)); // 1.5 ``` ## Blockchain Data Functions ### fetch_kuru_order_id ```rust fn fetch_kuru_order_id(logs: &[Log]) -> U256 ``` Extracts order ID from transaction logs (first value from first log). ### tx_hash_to_id ```rust fn tx_hash_to_id(tx_hash: FixedBytes<32>) -> i32 ``` Converts transaction hash to numeric ID using first 4 bytes. ## Solidity Type Conversion ### uint_to_dyn_sol_val ```rust fn uint_to_dyn_sol_val(sol_type: &str, value: &str) -> DynSolValue ``` Converts string value to Solidity dynamic value type. ```rust let value = uint_to_dyn_sol_val("uint40", "123"); ``` ### convert_dynsolvalue ```rust fn convert_dynsolvalue(value: &DynSolValue) -> Option where T: TryFrom ``` Generic conversion from DynSolValue to target type. Supports: - Uint (24, 40, 96, 256 bits) - Address - Bool - Int256 - Bytes - String ### convert_dynsolvalue_to_u96 ```rust fn convert_dynsolvalue_to_u96(value: &DynSolValue) -> Result ``` Specialized conversion from DynSolValue to U96. ## Usage Examples ```rust // Converting token amounts let wei_amount = to_wei("1.5", U256::from(18))?; let eth_amount = wei_to_eth(U256::from_str(&wei_amount)?); // Working with transaction data let order_id = fetch_kuru_order_id(&tx_receipt.logs); let tx_id = tx_hash_to_id(tx_receipt.transaction_hash); // Solidity type conversions let sol_value = uint_to_dyn_sol_val("uint96", "1000000"); if let Some(value) = convert_dynsolvalue::(&sol_value) { println!("Converted value: {}", value); } ``` ## Notes - All amount conversions handle decimal precision - Numeric conversions check for valid ranges - DynSolValue conversions return None for incompatible types - Wei/ETH conversions use 18 decimal places