0xMiden / 0xMiden/protocol

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

Abierto
#2,781 2 comentarios 2 reacciones 0 asignados Ver en GitHub
rust standards
Lenguaje dominante
Rust
Estrellas
132
Forks
167
Merge medio
1 d 23 h
PR fusionados (30 d)
110

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.