0xMiden / 0xMiden/protocol

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

未關閉
#2,781 2 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視
rust standards
主要語言
Rust
星號
132
分支
167
平均合併
1 天 23 小時
30 天內合併 PR
110

描述

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.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。