0xMiden / 0xMiden/protocol

Prefer using `AssetAmount` instead of `u64` for asset amounts

Offen
#2,781 2 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
rust standards
Vorherrschende Sprache
Rust
Sterne
132
Forks
167
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
110

Beschreibung

We have recently introduced `AssetAmount`, but we're not using it to its full extent yet. A couple of improvements we can make:

- `impl From for Felt` so users can infallibly do this conversion without having to `expect`.
- We can simplify logic like this then:
https://github.com/0xMiden/protocol/blob/c46871a4e2c4028c52fa1a7a5f4eea36514e4374/crates/miden-protocol/src/asset/fungible.rs#L153-L156
- The `FungibleAsset::amount` API should return `AssetAmount` instead of u64 so users can take advantage of the guarantees of `AssetAmount`. This should have a lot of ripple effects to also convert other APIs that deal with asset amounts to use `AssetAmount`.
- After https://github.com/0xMiden/protocol/pull/2636:
- `PswapNote::create_args(account_fill: u64, note_fill: u64)` which deals with asset amounts.
- `PswapNote::calculate_output_amount(offered_total: u64, requested_total: u64, fill_amount: u64) -> u64` can use `AssetAmount`.

These are just examples. We should explore the codebase to see where similar patterns can be improved / simplified.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.