-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add BalanceToAssetBalance Conversion Type #8776
Conversation
converts based on a given existential deposit and the assets min_balance
frame/assets/src/types.rs
Outdated
impl<T: Config, Balance, ED> BalanceToAssetBalance<T, Balance, ED> | ||
where | ||
Balance: Into<<T as Config>::Balance> + FixedPointOperand + Ord + One, | ||
<T as Config>::Balance: FixedPointOperand, | ||
ED: Get<Balance>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
impl<T: Config, Balance, ED> BalanceToAssetBalance<T, Balance, ED> | |
where | |
Balance: Into<<T as Config>::Balance> + FixedPointOperand + Ord + One, | |
<T as Config>::Balance: FixedPointOperand, | |
ED: Get<Balance>, | |
impl<T, Balance, ED> BalanceToAssetBalance<T, Balance, ED> | |
where | |
T: Config, | |
<T as Config>::Balance: FixedPointOperand, | |
Balance: Into<<T as Config>::Balance> + FixedPointOperand + Ord + One, | |
ED: Get<Balance>, |
frame/assets/src/types.rs
Outdated
/// deposit and the minimum asset balance. | ||
/// | ||
/// Will return `Err` if the asset is not found or not sufficient. | ||
pub fn to_asset_balance(balance: Balance, asset_id: <T as Config>::AssetId) -> Result<<T as Config>::Balance, ConversionError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there's no trait to be fulfilled, you might as well just expose a function rather than a struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Why does this need to be here in substrate? seems like the type of thing that should live where it is used.
-
If so, I'd rewrite it as:
/// Convert from the native balance of a currency (e.g. an instance of [`pallet_balances`])
/// to the native balance of an asset pallet.
fn balance_to_asset<Balance: Currency, Asset: Config>(from: Balances::Balance, to: Asset::AssetId)
where
Balances::Balance: ...,
T::Balance: ...,
{
let ed = Balances::minimum_balance();
// blah blah
}
Because it accesses private state (namely the |
I could access |
Can you provide a branch where this is used in it? or pseudo code of how it should fit in the mentioned PR. |
(branch does not compile yet) |
superseded by #9076 |
This PR adds the
BalanceToAssetBalance
type topallet_assets
to allow converting native balances to asset specific ones.This is a "low resolution" conversion based on the existential deposit (of the native currency) and the
min_balance
(of the asset).needed (AFAICT) for paritytech/statemint#51
Questions: