0xMiden / 0xMiden/protocol

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

Aperta
#2,781 2 commenti 2 reazioni 0 assegnatari Vedi su GitHub
rust standards
Lingua principale
Rust
Stelle
132
Fork
167
Merge medio
1g 23h
PR unite (30g)
110

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.