Skip to content

Conversation

@jmg-duarte
Copy link
Contributor

Description

Migrate get_total_surplus_endpoint to alloy

Changes

  • Migrate get_total_surplus_endpoint to alloy
  • Refactor where needed

How to test

Existing tests

@jmg-duarte jmg-duarte requested a review from a team as a code owner November 7, 2025 16:20
@jmg-duarte jmg-duarte changed the base branch from main to jmgd/alloy/get_token_metadata November 7, 2025 16:21
Comment on lines -98 to +99
let surplus = fetch_total_surplus(&mut ex, &ByteArray(user.0)).await?;
Ok(U256::from_f64_lossy(surplus))
let surplus = fetch_total_surplus(&mut ex, &ByteArray(user.0.0)).await?;
Ok(U256::from(surplus))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can You provide more information backing this is a drop-in replacement? I looked around alloy's docs but couldn't untangle it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use alloy::primitives::U256;

fn main() {
    let mut buffer = vec![0; 32];
    ethcontract::U256::from_f64_lossy(3.3).to_big_endian(&mut buffer);

    assert_eq!(U256::from(3.3f64).to_be_bytes_vec(), buffer);

    println!(
        "{} {}",
        U256::from(3.3f64),
        ethcontract::U256::from_f64_lossy(3.3)
    );
}

I think that in ethcontract they explicitly state that the conversion is lossy because you're bound to lose decimals, in alloy they make it implicit because you shouldn't really expect the decimals to keep when converting to an integer type.

Hope this helps

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! Thanks!

Copy link
Contributor

@m-sz m-sz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Base automatically changed from jmgd/alloy/get_token_metadata to main November 10, 2025 15:54
@jmg-duarte jmg-duarte added this pull request to the merge queue Nov 10, 2025
Merged via the queue into main with commit 6764b80 Nov 10, 2025
16 checks passed
@jmg-duarte jmg-duarte deleted the jmgd/alloy/get_total_surplus branch November 10, 2025 16:17
@github-actions github-actions bot locked and limited conversation to collaborators Nov 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants