You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Move rust logic to /crates and typescript logic to /packages #3
changed the title [-]Move rust logic to be under `/crates` and typescript logic to be under `/packages`[/-][+]Move rust logic to `/crates` and typescript logic to `/packages`[/+]on Aug 26, 2025
use alloy::primitives::Bytes;
use alloy::sol_types::SolInterface;
use crate::{DecimalFloat, FloatError};
use crate::evm::execute_call; // reuse your execute_call helper
/// Convert a Rust integer into a DecimalFloat by calling the contract.
///
/// # Arguments
/// * value - The integer value to convert (i128 supports negatives).
///
/// # Returns
/// * DecimalFloat representation stored inside the contract.
pub fn int_to_float(value: i128) -> Result<DecimalFloat::DecimalFloat, FloatError> {
// Build ABI-encoded calldata for the contract function fromInt(int256)
let calldata: Bytes = DecimalFloat::DecimalFloatCalls::fromInt(value).abi_encode().into();
// Execute call to DecimalFloat contract
execute_call(calldata, |output| {
// Decode the returned DecimalFloat struct
let result = DecimalFloat::DecimalFloat::abi_decode(&output, true)
.map_err(|_| FloatError::AbiDecode(output.clone()))?;
Ok(result)
})
}
#[test]
fn test_int_to_float_positive() {
let f = int_to_float(42).expect("conversion should succeed");
assert_eq!(f.to_string(), "42.0");
}
#[test]
fn test_int_to_float_negative() {
let f = int_to_float(-7).expect("conversion should succeed");
assert_eq!(f.to_string(), "-7.0");
}
#[test]
fn test_int_to_float_positive() {
let f = int_to_float(42).expect("conversion should succeed");
assert_eq!(f.to_string(), "42.0");
}
#[test]
fn test_int_to_float_negative() {
let f = int_to_float(-7).expect("conversion should succeed");
assert_eq!(f.to_string(), "-7.0");
}
Activity
[-]Move rust logic to be under `/crates` and typescript logic to be under `/packages`[/-][+]Move rust logic to `/crates` and typescript logic to `/packages`[/+]Jatkingmodern commentedon Sep 14, 2025
Proposed action (implementation checklist)
Create directory structure:
/crates/ # All Rust crates
crate1/
crate2/
/packages/ # All TypeScript packages
package1/
package2/
Move code:
Relocate Rust source trees (src/, Cargo.toml, etc.) under /crates/*.
Relocate TS source trees (src/, package.json, etc.) under /packages/*.
Update build configs:
Update Cargo workspace root to include /crates/*.
Update TypeScript monorepo tooling (pnpm/yarn/npm workspaces) to include /packages/*.
Update CI/CD:
Split Rust build/test steps into a cargo job using /crates.
Split TS build/test steps into a node job using /packages.
Update docs:
Add a short section in README.md describing the new layout.
Include example commands:
build Rust crates
cargo build --workspace --manifest-path crates/Cargo.toml
build TS packages
pnpm install && pnpm build --filter ./packages/*
Migration step:
Ensure imports/paths in both ecosystems are updated.
Run tests for both ecosystems after restructuring.
Jatkingmodern commentedon Sep 14, 2025
use alloy::primitives::Bytes;
use alloy::sol_types::SolInterface;
use crate::{DecimalFloat, FloatError};
use crate::evm::execute_call; // reuse your execute_call helper
/// Convert a Rust integer into a DecimalFloat by calling the contract.
///
/// # Arguments
/// *
value- The integer value to convert (i128 supports negatives).///
/// # Returns
/// *
DecimalFloatrepresentation stored inside the contract.pub fn int_to_float(value: i128) -> Result<DecimalFloat::DecimalFloat, FloatError> {
// Build ABI-encoded calldata for the contract function
fromInt(int256)let calldata: Bytes = DecimalFloat::DecimalFloatCalls::fromInt(value).abi_encode().into();
}
#[test]
fn test_int_to_float_positive() {
let f = int_to_float(42).expect("conversion should succeed");
assert_eq!(f.to_string(), "42.0");
}
#[test]
fn test_int_to_float_negative() {
let f = int_to_float(-7).expect("conversion should succeed");
assert_eq!(f.to_string(), "-7.0");
}
#[test]
fn test_int_to_float_positive() {
let f = int_to_float(42).expect("conversion should succeed");
assert_eq!(f.to_string(), "42.0");
}
#[test]
fn test_int_to_float_negative() {
let f = int_to_float(-7).expect("conversion should succeed");
assert_eq!(f.to_string(), "-7.0");
}