Skip to content

Move rust logic to /crates and typescript logic to /packages #3

Open

Description

@findolor
No description provided.

Activity

  1. self-assigned this
    on Aug 26, 2025
  2. 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
  3. Jatkingmodern commented on Sep 14, 2025

    @Jatkingmodern

    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.

  4. Jatkingmodern commented on Sep 14, 2025

    @Jatkingmodern

    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");
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions